Commit Graph

17 Commits

Author SHA1 Message Date
Lance Ball a5befbe0cf
fix: introduce CloudEventV1 and CloudEventV03 interfaces (#194)
This extracts all of the attributes from a `CloudEventVX` that
are not generated by the constructor (id and specversion) into their
own `CloudEventVXAttributes` interface which the `CloudEventVX`
interface extends. This allows TS devs to optionally provide `id`
and `specversion` with proper autocompletion.

Additionally, I have added a union type, `CE` in `cloudevent.ts` which
represents any of `CloudEventV1`, `CloudEventv03`, `CloudEventV1Attributes`
and `CloudEventV03Attributes` interfaces.

Finally, this commit changes all of the user facing API to be `.ts` instead
of `.js` files.

The existing documentation in `./docs` was removed. It should be replaced with generated
HTML from tsdocs, pending some other method of publishing API documentation. That will
come as a separate, docs-only PR.

Fixes: https://github.com/cloudevents/skd-javascript/issues/188

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-29 17:49:02 -04:00
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 250a0a144c
feat!: expose a version agnostic event emitter (#141)
* feat!: expose a version agnostic event emitter

This is a breaking change.

This commit exposes an HTTP based event emitter that simplifes the API.
To use it, simply import the SDK and start emitting. The default spec
version is 1.0, but you can use 0.3 by supplying that to the constructor.

By default, CloudEvents are emitted in binary mode, but this can be changed
by providing the "structured" parameter to the `send()` function.

This commit also eliminates the version specific emitters and receivers
from the `v1` and `v03` exports, and eliminates the explicit usage of
versioned emitters from `lib/bindings/http`.

Finally, the CE headers can be retrieved from the emitter for a given
event by passing the event to the `headers()` function.

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

Signed-off-by: Lance Ball <lball@redhat.com>
2020-05-14 11:37:02 -04: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
Fabio José cf701e423c Remove HTTPUnmarshaller
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 10:13:04 -03:00
Fabio José 43c6bfe9dc Exporting the http unmarshaller spec 1.0
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 10:07:02 -03:00
Fabio José 23b0648a07 Exporting the binary receiber
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-04 09:45:25 -03:00
Fabio José dfd98197ad Comment pendeing stuff
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-02 07:06:38 -03:00
Fabio José 8487b1c76c Sdk tests for spec 1.0
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-11-02 07:05:20 -03:00
Fabio José d399e5abc3 Exporting the HTTPUnmarshaller
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-08-05 09:22:15 -03:00
Fabio José fd119040fc Exporting the receiver and emitter for binary 0.3
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-08-04 13:26:14 -03:00
Fabio José 084d0c1a0b Export the structured emitter for v0.3
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-08-02 09:57:59 -03:00
Fabio José e7b5c833c6 Exporting the v0.3 stuff
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-08-01 17:43:48 -03:00
Fabio José b53d660402 SDK Requirements: exports the receivers
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-07-29 16:38:38 -03:00
Fabio José 6b5a8d1f3e should have the minimum exports
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-07-29 14:46:31 -03:00
Fabio José 375f67952d Test the event() method of SDK Requirements
Signed-off-by: Fabio José <fabiojose@gmail.com>
2019-07-29 13:26:20 -03:00