Commit Graph

7 Commits

Author SHA1 Message Date
Lance Ball e334b6eceb
feat: add emitterFactory and friends (#342)
* feat: add emitterFactory and friends

This commit adds an emitterFactory function that returns an EmitterFunction
object. The EmitterFunction may be used to emit events over a supported
network transport layer. Currently, only HTTP is supported.

Parameters provided to the emitterFactory are the transport Binding (only
HTTP supported), the encoding mode (Mode.BINARY or Mode.STRUCTURED), and
a TransportFunction.

The implementation for emitBinary and emitStructured has been replaced
with this simple pattern and those two functions have been removed.

Example:

```js
// The endpoint URL that will receive the event
const sink = 'https://my-event-sink';

// A function that uses Axios to send a message over HTTP
function axiosEmitter(message: Message, options?: Options): Promise<unknown> {
  return axios.post(sink, message.body, { headers: message.headers, ...options });
}

// Create an event emitter
const emit = emitterFactory(HTTP, Mode.BINARY, axiosEmitter);

// Emit an event, sending it to the endpoint URL
emit(new CloudEvent{ source: '/example', type: 'example' });
```

Signed-off-by: Lance Ball <lball@redhat.com>
2020-09-25 17:25:15 -04:00
Lance Ball 6cd310c141
src(event)!: make the event's time property only a string (#330)
Previously, the event's `time` property could be either a string or a date.
this commit modifies that to ensure that the object can only be created with
a timestamp in string format. As long as the string is a valid date, that
can be parsed by `new Date(Date.parse(str))` then whenever the event is
serialized as JSON, the `time` attribute will be formatted as per RFC 3339.

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

Signed-off-by: Lance Ball <lball@redhat.com>
2020-09-01 10:10:16 -04:00
Lance Ball f3953a9a5a
feat: introduce Message, Serializer, Deserializer and Binding interfaces (#324)
* lib(messages): Implement a 4.0 Messages and other supporting interfaces

This commit introduces the Message, Serializer and Deserializer, and Binding
interfaces used to convert a CloudEvent into a Message that can be sent across
a transport protocol. The first protocol implemented for this is HTTP, and some
of the functionality formerly in src/transport/http has been simplified,
reduced and/or moved to /src/messages/http.

Test for V1 and V3 events are in place. Conformance tests have been modified to use
these new interfaces vs. the HTTP Receiver class.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-08-26 18:26:50 -04:00
Lucas Holmquist a5249de487
chore: fix promise tests to break the build when they fail (#305)
* squash: return the promise that is being tested

fixes #303 

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
2020-08-07 09:00:49 -04:00
Lucas Holmquist ad0c4340b2
fix: Add Correct Headers to emitted Binary Event (#302)
* fix: Binary emitter should add a basic application/json header.

fixes #301

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
2020-08-06 10:36:53 -04:00
Lucas Holmquist 3c8273f114
lib: validate extension values (#251)
BREAKING CHANGE:

This validates the value of the cloud event extension based on the spec, 
https://github.com/cloudevents/spec/blob/master/spec.md#type-system

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
2020-07-27 13:19:09 -04:00
Lance Ball dca2811627
test: inplement the cucumber conformance tests from cloudevents/spec (#238)
This commit adds cucumber-js conformance steps and includes the cucumber
tests in 'npm test'.

Signed-off-by: Lance Ball <lball@redhat.com>
2020-07-13 09:47:02 -04:00