Commit Graph

21 Commits

Author SHA1 Message Date
Lance Ball abc114b24e
lib!: change CloudEvent to use direct object notation and get/set properties (#172)
This commit makes a substantial change to the API, changing the CloudEvent class
to accept properties as an object in the constructor. For example:

```js
const CloudEvent = require('cloudevents-sdk');

// all event properties except extensions may be set in the constructor
const event = new CloudEvent({
  source: 'http://my.event.source',
  type: 'test-event-type'
});

// get and set all properties standard property notation
console.log(event.time); // the event timestamp
event.subject = 'my event subject';
```

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-22 13:03:36 -04:00
Lance Ball 6f0b5ea5f1
lib!: refactor HTTP bindings and specifications (#165)
This is a breaking change.

This commit makes a number of changes to the HTTP bindings code in an attempt
to simplify its usage and implementation. From a very high level, this inverts
the existing dependencies.

As an example, consider `lib/bindings/http/receiver_structured_1.js`.
https://github.com/cloudevents/sdk-javascript/blob/v1.0.0/lib/bindings/http/receiver_structured_0_3.js

This class instantiates `lib/bindings/http/receiver_structured.js` and delegates
its function invokations to it. This had the effect of requiring a user to know what
event versions they would be receiving. And for me personally was a little confusing
as a maintainer.

The change introduced here reverses that logic, so that the version agnostic receiver
is what the user instantiates. It instantiates the approrpiate version of a specific
receiever and delegates to it - reversing the dependencies.

I've also moved all of the top level directories related to HTTP versions into
`lib/bindings/http/v1` and `lib/bindings/http/v03` and generally done some rearranging
to make the repository structure cleaner and more organized.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-18 11:34:22 -04:00
Lance Ball 09b0c76826
feat: add ValidationError type extending TypeError (#151)
This change adds a `ValidationError` type that extends `TypeError`. Any time a `CloudEvent` cannot be received and created with the given input, this error will be thrown. Tests have all
been updated to check for the error type.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-13 13:27:18 -04:00
Helio Frota cd6a3eec7d
fix: misspelled word (#113)
Signed-off-by: Helio Frota <00hf11@gmail.com>
2020-05-02 08:31:07 -07:00
Grant Timmerman cd6decd749
chore: es6 parser (#98)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-04-30 15:32:37 -07:00
Lance Ball e83db297ae chore: update eslint rules to disallow var usage
Enforce the use of `let` and `const` by using elsint rules.
When creating the eslint configuration, I had assumed that
`extends: eslint:recommended` would have covered this, but
apparently not!

Existing usage of `var` fixed with `npm run lint -- --fix`.

Fixes: https://github.com/cloudevents/sdk-javascript/issues/97

Signed-off-by: Lance Ball <lball@redhat.com>
2020-04-30 12:36:04 -03:00
Lance Ball 3f238a0124
src: add eslint configuration and npm script
Automatically fixed > 2000 issues. The remaining 200+ issues need
to be fixed by hand. Additionally, all strings are double quotes
which is not typically standard and I wonder about fixing that too.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-04-22 10:15:05 -04:00
Daniel Bevenius df85189a64 Use const instead of var where applicable
Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
2020-04-20 09:54:25 +02:00
Fabio José 32a2590665 Implement the decorator pattern
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-08-06 11:17:35 -03:00
Fabio José eb37bf8a69 Code style: missing semicolon
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-07-23 13:44:51 -03:00
Fabio José d568899ce7 Code style: narrow parens
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-07-23 09:22:07 -03:00
Fabio José 7684947e41 change fun name to isStringOrObjectOrThrow
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-07-23 09:04:55 -03:00
Fabio José cb5f0e377e Functions: isValidOrThrow, isDefinedOrThrow
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-07-23 08:57:58 -03:00
Fabio José 8469e04a98 lib with functions for utils
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-07-23 08:49:52 -03:00
Fabio José 6960e42c24 Pretify
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-07-17 13:25:49 -03:00
Fabio José f5e0ce6a84 Removing the cyclomatic complexity
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-07-17 11:27:54 -03:00
Fabio José 789c4adf6d cammelCase insteadof snake_case
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-07-16 14:31:29 -03:00
Fabio José fb92f710ea Remove the responsability of spec checking
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-06-21 10:56:02 -03:00
Fabio José 8915048791 Spec as parser parameter
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-06-10 21:20:04 -03:00
Fabio José 232b39b5b3 Comments, spec0.2
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-06-10 21:14:52 -03:00
Fabio José a24954514a Structure for formats impl
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-06-09 20:56:41 -03:00