Commit Graph

28 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 2c469efaf5
build: add tsc type checks and emit declarations in the ci/test pipeline (#155)
This commit introduces TypeScript checks and generates type declarations
for the existing JavaScript codebase using `tsc` prior to running the linter task.

Ref: https://github.com/cloudevents/sdk-javascript/issues/9

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-18 14:56:01 -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
Lance Ball b283583c0c
docs: add JSDocs for top level API objects (#140)
This commit add JSDoc documentation to the CloudEvent and HTTPReceiver
objects exposed by the API when using the top level imports, specifically
`CloudEvent` and `HTTPReceiver`.

This adds a `generate-docs` npm script to generate site and API documentation
for GitHub pages in `./docs`.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-12 17:27:11 -04:00
Grant Timmerman 12ac181300
chore: use es6 for cloudevents.js (#73)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
2020-04-29 13:17:51 -07:00
Lance Ball 5110ad4c67 src,fix: drop support for v0.2 and clean up contenttype
This commit removes support for the v0.2 specification. It also removes the
`contenttype` attribute from the `CloudEvent` object. While the HTTP protocol
binding specifies that in binary mode, the `datacontenttype` attribute should
map to the HTTP Content-Type header, that doesn't mean that the `CloudEvent`
object should have a `contenttype` property.

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

Signed-off-by: Lance Ball <lball@redhat.com>
2020-04-28 17:37:49 -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é 8b39902910 Calling getData() to apply some internal state
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 13:13:47 -03:00
Fabio José 7024876e49 Specversion placebo
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-06-25 10:30:25 -03:00
Fabio José 043a4a8072 Http binary binding with constants
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-06-11 13:13:44 -03:00
Fabio José 0f9fadb718 Fix the json format import
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-06-09 20:58:01 -03:00
Fabio José 8b46c25588 Arrangements to receiver impl
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-06-06 19:56:01 -03:00
Fabio José a0484d9e5b Arrangements to receiver impl
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-06-06 19:52:41 -03:00
Fabio José ba2d47fcda Fix code style issues
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-01-18 23:48:30 -02:00
Fabio José 1a81e6e7e1 Test the extensions
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-01-18 23:42:43 -02:00
Fabio José b976273260 HTTP Binding Structured 0.2 impl
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-01-18 22:44:44 -02:00
Fabio José e3b2ce6b52 Binary 0.2 impl
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-01-18 22:39:00 -02:00
Fabio José 4d79e11284 http binary wip
Signed-off-by: Fabio José <fabiojose@gmail.com>
2018-12-17 21:10:12 -02:00
Fabio José 23887763e5 WIP: http binary binding
Signed-off-by: Fabio José <fabiojose@gmail.com>
2018-12-16 20:20:15 -02:00
Fabio José 409be307cb missing semi colon
Signed-off-by: Fabio José <fabiojose@gmail.com>
2018-12-15 13:03:31 -02:00
Fabio José fc03bf37a3 Camel case
Signed-off-by: Fabio José <fabiojose@gmail.com>
2018-12-15 11:57:30 -02:00
Fabio José 471e80ca16 Double quotes
Signed-off-by: Fabio José <fabiojose@gmail.com>
2018-12-15 11:21:37 -02:00
Fabio José 83131ad36a All required and optional attributes
Signed-off-by: Fabio José <fabiojose@gmail.com>
2018-12-05 22:52:54 -02:00
Fabio José 903891e3d9 id and time attributes
Signed-off-by: Fabio José <fabiojose@gmail.com>
2018-11-14 22:03:01 -02:00
Fabio José 7aa757015a imports of bindings
Signed-off-by: Fabio José <fabiojose@gmail.com>
2018-11-14 21:17:03 -02:00
Fabio José 268233fce7 Project start
Signed-off-by: Fabio José <fabiojose@gmail.com>
2018-11-09 16:20:29 -02:00