feat: use CloudEvents not cloudevents everywhere (#101)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
This commit is contained in:
parent
cd6decd749
commit
05ecbdea4f
32
README.md
32
README.md
|
@ -42,7 +42,7 @@ Checkout the new expressive additions.
|
||||||
> There is full example: [typescript-ex](./examples/typescript-ex)
|
> There is full example: [typescript-ex](./examples/typescript-ex)
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import Cloudevent, {
|
import CloudEvent, {
|
||||||
event,
|
event,
|
||||||
StructuredHTTPEmitter,
|
StructuredHTTPEmitter,
|
||||||
BinaryHTTPEmitter,
|
BinaryHTTPEmitter,
|
||||||
|
@ -51,7 +51,7 @@ import Cloudevent, {
|
||||||
BinaryHTTPReceiver
|
BinaryHTTPReceiver
|
||||||
} from 'cloudevents-sdk/v1';
|
} from 'cloudevents-sdk/v1';
|
||||||
|
|
||||||
let myevent: Cloudevent = event()
|
let myevent: CloudEvent = event()
|
||||||
.source('/source')
|
.source('/source')
|
||||||
.type('type')
|
.type('type')
|
||||||
.dataContentType('text/plain')
|
.dataContentType('text/plain')
|
||||||
|
@ -231,7 +231,7 @@ app.post("/", (req, res) => {
|
||||||
- `ext`: external stuff, e.g, Cloud Events JSONSchema
|
- `ext`: external stuff, e.g, Cloud Events JSONSchema
|
||||||
- `lib/bindings`: every binding implementation goes here
|
- `lib/bindings`: every binding implementation goes here
|
||||||
- `lib/bindings/http`: every http binding implementation goes here
|
- `lib/bindings/http`: every http binding implementation goes here
|
||||||
- `lib/cloudevent.js`: implementation of Cloudevent, an interface
|
- `lib/cloudevent.js`: implementation of CloudEvent, an interface
|
||||||
- `lib/formats/`: every format implementation goes here
|
- `lib/formats/`: every format implementation goes here
|
||||||
- `lib/specs/`: every spec implementation goes here
|
- `lib/specs/`: every spec implementation goes here
|
||||||
|
|
||||||
|
@ -245,18 +245,18 @@ npm test
|
||||||
|
|
||||||
## The API
|
## The API
|
||||||
|
|
||||||
### `Cloudevent` class
|
### `CloudEvent` class
|
||||||
|
|
||||||
```js
|
```js
|
||||||
/*
|
/*
|
||||||
* Format the payload and return an Object.
|
* Format the payload and return an Object.
|
||||||
*/
|
*/
|
||||||
Object Cloudevent.format()
|
Object CloudEvent.format()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Format the payload as String.
|
* Format the payload as String.
|
||||||
*/
|
*/
|
||||||
String Cloudevent.toString()
|
String CloudEvent.toString()
|
||||||
```
|
```
|
||||||
|
|
||||||
### `Formatter` classes
|
### `Formatter` classes
|
||||||
|
@ -265,12 +265,12 @@ Every formatter class must implement these methods to work properly.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
/*
|
/*
|
||||||
* Format the Cloudevent payload argument and return an Object.
|
* Format the CloudEvent payload argument and return an Object.
|
||||||
*/
|
*/
|
||||||
Object Formatter.format(Object)
|
Object Formatter.format(Object)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Format the Cloudevent payload as String.
|
* Format the CloudEvent payload as String.
|
||||||
*/
|
*/
|
||||||
String Formatter.toString(Object)
|
String Formatter.toString(Object)
|
||||||
```
|
```
|
||||||
|
@ -297,9 +297,9 @@ Every Spec class must implement these methods to work properly.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
/*
|
/*
|
||||||
* The constructor must receives the Cloudevent type.
|
* The constructor must receives the CloudEvent type.
|
||||||
*/
|
*/
|
||||||
Spec(Cloudevent)
|
Spec(CloudEvent)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Checks the spec constraints, throwing an error if do not pass.
|
* Checks the spec constraints, throwing an error if do not pass.
|
||||||
|
@ -320,7 +320,7 @@ Every Binding class must implement these methods to work properly.
|
||||||
|
|
||||||
#### Emitter Binding
|
#### Emitter Binding
|
||||||
|
|
||||||
Following we have the signature for the binding to emit Cloudevents.
|
Following we have the signature for the binding to emit CloudEvents.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
/*
|
/*
|
||||||
|
@ -329,14 +329,14 @@ Following we have the signature for the binding to emit Cloudevents.
|
||||||
Binding(config)
|
Binding(config)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Emits the event using an instance of Cloudevent.
|
* Emits the event using an instance of CloudEvent.
|
||||||
*/
|
*/
|
||||||
Binding.emit(cloudevent)
|
Binding.emit(cloudEvent)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Receiver Binding
|
#### Receiver Binding
|
||||||
|
|
||||||
Following we have the signature for the binding to receive Cloudevents.
|
Following we have the signature for the binding to receive CloudEvents.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
/*
|
/*
|
||||||
|
@ -351,9 +351,9 @@ Receiver(config)
|
||||||
Receiver.check(Object, Map)
|
Receiver.check(Object, Map)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Checks and parse as Cloudevent
|
* Checks and parse as CloudEvent
|
||||||
*/
|
*/
|
||||||
Cloudevent Receiver.parse(Object, Map)
|
CloudEvent Receiver.parse(Object, Map)
|
||||||
```
|
```
|
||||||
|
|
||||||
> See how to implement the method injection [here](lib/specs/spec_0_1.js#L17)
|
> See how to implement the method injection [here](lib/specs/spec_0_1.js#L17)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import Cloudevent, {
|
import CloudEvent, {
|
||||||
event,
|
event,
|
||||||
StructuredHTTPEmitter,
|
StructuredHTTPEmitter,
|
||||||
BinaryHTTPEmitter,
|
BinaryHTTPEmitter,
|
||||||
|
@ -8,7 +8,7 @@ import Cloudevent, {
|
||||||
|
|
||||||
export function doSomeStuff() {
|
export function doSomeStuff() {
|
||||||
|
|
||||||
const myevent: Cloudevent = event()
|
const myevent: CloudEvent = event()
|
||||||
.source('/source')
|
.source('/source')
|
||||||
.type('type')
|
.type('type')
|
||||||
.dataContentType('text/plain')
|
.dataContentType('text/plain')
|
||||||
|
@ -20,13 +20,13 @@ export function doSomeStuff() {
|
||||||
console.log(myevent.toString());
|
console.log(myevent.toString());
|
||||||
console.log(myevent.getExtensions());
|
console.log(myevent.getExtensions());
|
||||||
|
|
||||||
let config = {
|
const config = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url : "https://enu90y24i64jp.x.pipedream.net/"
|
url : "https://enu90y24i64jp.x.pipedream.net/"
|
||||||
};
|
};
|
||||||
|
|
||||||
// ------ emitter structured
|
// ------ emitter structured
|
||||||
let structured = new StructuredHTTPEmitter(config);
|
const structured = new StructuredHTTPEmitter(config);
|
||||||
structured.emit(myevent).then(res => {
|
structured.emit(myevent).then(res => {
|
||||||
// success
|
// success
|
||||||
console.log("Structured Mode: Success!")
|
console.log("Structured Mode: Success!")
|
||||||
|
@ -37,7 +37,7 @@ export function doSomeStuff() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// ------ emitter binary
|
// ------ emitter binary
|
||||||
let binary = new BinaryHTTPEmitter(config);
|
const binary = new BinaryHTTPEmitter(config);
|
||||||
binary.emit(myevent).then(res => {
|
binary.emit(myevent).then(res => {
|
||||||
console.log("Binary Mode: Success!");
|
console.log("Binary Mode: Success!");
|
||||||
})
|
})
|
||||||
|
@ -46,20 +46,20 @@ export function doSomeStuff() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// ------ receiver structured
|
// ------ receiver structured
|
||||||
let payload = myevent.toString();
|
const payload = myevent.toString();
|
||||||
let headers = {
|
const headers = {
|
||||||
"Content-Type":"application/cloudevents+json"
|
"Content-Type":"application/cloudevents+json"
|
||||||
};
|
};
|
||||||
|
|
||||||
let receiverStructured = new StructuredHTTPReceiver();
|
const receiverStructured = new StructuredHTTPReceiver();
|
||||||
console.log(receiverStructured.parse(payload, headers).toString());
|
console.log(receiverStructured.parse(payload, headers).toString());
|
||||||
|
|
||||||
// ------ receiver binary
|
// ------ receiver binary
|
||||||
let extension1 = "mycuston-ext1";
|
const extension1 = "mycuston-ext1";
|
||||||
let data = {
|
const data = {
|
||||||
"data" : "dataString"
|
"data" : "dataString"
|
||||||
};
|
};
|
||||||
var attributes = {
|
const attributes = {
|
||||||
"ce-type" : "type",
|
"ce-type" : "type",
|
||||||
"ce-specversion" : "1.0",
|
"ce-specversion" : "1.0",
|
||||||
"ce-source" : "source",
|
"ce-source" : "source",
|
||||||
|
@ -70,7 +70,7 @@ export function doSomeStuff() {
|
||||||
"ce-extension1" : extension1
|
"ce-extension1" : extension1
|
||||||
};
|
};
|
||||||
|
|
||||||
let receiverBinary = new BinaryHTTPReceiver();
|
const receiverBinary = new BinaryHTTPReceiver();
|
||||||
console.log(receiverBinary.parse(data, attributes).toString());
|
console.log(receiverBinary.parse(data, attributes).toString());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
4
index.js
4
index.js
|
@ -1,3 +1,3 @@
|
||||||
const Cloudevent = require("./lib/cloudevent.js");
|
const CloudEvent = require("./lib/cloudevent.js");
|
||||||
|
|
||||||
module.exports = Cloudevent;
|
module.exports = CloudEvent;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const Constants = require("./constants.js");
|
const Constants = require("./constants.js");
|
||||||
const Commons = require("./commons.js");
|
const Commons = require("./commons.js");
|
||||||
const Cloudevent = require("../../cloudevent.js");
|
const CloudEvent = require("../../cloudevent.js");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isDefinedOrThrow,
|
isDefinedOrThrow,
|
||||||
|
@ -88,7 +88,7 @@ BinaryHTTPReceiver.prototype.parse = function(payload, headers) {
|
||||||
const sanityHeaders = Commons.sanityAndClone(headers);
|
const sanityHeaders = Commons.sanityAndClone(headers);
|
||||||
|
|
||||||
const processedHeaders = [];
|
const processedHeaders = [];
|
||||||
const cloudevent = new Cloudevent(this.Spec);
|
const cloudevent = new CloudEvent(this.Spec);
|
||||||
|
|
||||||
// dont worry, check() have seen what was required or not
|
// dont worry, check() have seen what was required or not
|
||||||
Array.from(Object.keys(this.setterByHeader))
|
Array.from(Object.keys(this.setterByHeader))
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const Constants = require("./constants.js");
|
const Constants = require("./constants.js");
|
||||||
const Commons = require("./commons.js");
|
const Commons = require("./commons.js");
|
||||||
const Cloudevent = require("../../cloudevent.js");
|
const CloudEvent = require("../../cloudevent.js");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isDefinedOrThrow,
|
isDefinedOrThrow,
|
||||||
|
@ -61,7 +61,7 @@ StructuredHTTPReceiver.prototype.parse = function(payload, headers) {
|
||||||
this.spec.check(event);
|
this.spec.check(event);
|
||||||
|
|
||||||
const processedAttributes = [];
|
const processedAttributes = [];
|
||||||
const cloudevent = new Cloudevent(this.Spec);
|
const cloudevent = new CloudEvent(this.Spec);
|
||||||
|
|
||||||
Array.from(Object.keys(this.setterByAttribute))
|
Array.from(Object.keys(this.setterByAttribute))
|
||||||
.filter((attribute) => event[attribute])
|
.filter((attribute) => event[attribute])
|
||||||
|
|
|
@ -147,7 +147,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Parse", () => {
|
describe("Parse", () => {
|
||||||
it("Cloudevent contains 'type'", () => {
|
it("CloudEvent contains 'type'", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = {
|
const payload = {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
|
@ -170,7 +170,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
.to.equal("type");
|
.to.equal("type");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'specversion'", () => {
|
it("CloudEvent contains 'specversion'", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = {
|
const payload = {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
|
@ -193,7 +193,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
.to.equal("0.3");
|
.to.equal("0.3");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'source'", () => {
|
it("CloudEvent contains 'source'", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = {
|
const payload = {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
|
@ -216,7 +216,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
.to.equal("/source");
|
.to.equal("/source");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'id'", () => {
|
it("CloudEvent contains 'id'", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = {
|
const payload = {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
|
@ -239,7 +239,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
.to.equal("id");
|
.to.equal("id");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'time'", () => {
|
it("CloudEvent contains 'time'", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = {
|
const payload = {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
|
@ -262,7 +262,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
.to.equal("2019-06-16T11:42:00.000Z");
|
.to.equal("2019-06-16T11:42:00.000Z");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'schemaurl'", () => {
|
it("CloudEvent contains 'schemaurl'", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = {
|
const payload = {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
|
@ -285,7 +285,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
.to.equal("http://schema.registry/v1");
|
.to.equal("http://schema.registry/v1");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'datacontenttype' (application/json)", () => {
|
it("CloudEvent contains 'datacontenttype' (application/json)", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = {
|
const payload = {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
|
@ -308,7 +308,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
.to.equal("application/json");
|
.to.equal("application/json");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'datacontenttype' (application/octet-stream)",
|
it("CloudEvent contains 'datacontenttype' (application/octet-stream)",
|
||||||
() => {
|
() => {
|
||||||
// setup
|
// setup
|
||||||
const payload = "The payload is binary data";
|
const payload = "The payload is binary data";
|
||||||
|
@ -330,7 +330,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
.to.equal("application/octet-stream");
|
.to.equal("application/octet-stream");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'data' (application/json)", () => {
|
it("CloudEvent contains 'data' (application/json)", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = {
|
const payload = {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
|
@ -353,7 +353,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
|
||||||
.to.deep.equal(payload);
|
.to.deep.equal(payload);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'data' (application/octet-stream)", () => {
|
it("CloudEvent contains 'data' (application/octet-stream)", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = "The payload is binary data";
|
const payload = "The payload is binary data";
|
||||||
const attributes = {
|
const attributes = {
|
||||||
|
|
|
@ -148,7 +148,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Parse", () => {
|
describe("Parse", () => {
|
||||||
it("Cloudevent contains 'type'", () => {
|
it("CloudEvent contains 'type'", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = {
|
const payload = {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
|
@ -171,7 +171,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
.to.equal("type");
|
.to.equal("type");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'specversion'", () => {
|
it("CloudEvent contains 'specversion'", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = {
|
const payload = {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
|
@ -194,7 +194,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
.to.equal("1.0");
|
.to.equal("1.0");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'source'", () => {
|
it("CloudEvent contains 'source'", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = {
|
const payload = {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
|
@ -217,7 +217,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
.to.equal("/source");
|
.to.equal("/source");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'id'", () => {
|
it("CloudEvent contains 'id'", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = {
|
const payload = {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
|
@ -240,7 +240,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
.to.equal("id");
|
.to.equal("id");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'time'", () => {
|
it("CloudEvent contains 'time'", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = {
|
const payload = {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
|
@ -263,7 +263,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
.to.equal("2019-06-16T11:42:00.000Z");
|
.to.equal("2019-06-16T11:42:00.000Z");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'dataschema'", () => {
|
it("CloudEvent contains 'dataschema'", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = {
|
const payload = {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
|
@ -286,7 +286,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
.to.equal("http://schema.registry/v1");
|
.to.equal("http://schema.registry/v1");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'contenttype' (application/json)", () => {
|
it("CloudEvent contains 'contenttype' (application/json)", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = {
|
const payload = {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
|
@ -309,7 +309,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
.to.equal("application/json");
|
.to.equal("application/json");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'contenttype' (application/octet-stream)", () => {
|
it("CloudEvent contains 'contenttype' (application/octet-stream)", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = "The payload is binary data";
|
const payload = "The payload is binary data";
|
||||||
const attributes = {
|
const attributes = {
|
||||||
|
@ -330,7 +330,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
.to.equal("application/octet-stream");
|
.to.equal("application/octet-stream");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'data' (application/json)", () => {
|
it("CloudEvent contains 'data' (application/json)", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = {
|
const payload = {
|
||||||
data: "dataString"
|
data: "dataString"
|
||||||
|
@ -353,7 +353,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
|
||||||
.to.deep.equal(payload);
|
.to.deep.equal(payload);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Cloudevent contains 'data' (application/octet-stream)", () => {
|
it("CloudEvent contains 'data' (application/octet-stream)", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload = "The payload is binary data";
|
const payload = "The payload is binary data";
|
||||||
const attributes = {
|
const attributes = {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const expect = require("chai").expect;
|
const expect = require("chai").expect;
|
||||||
const v1 = require("../../../v1/index.js");
|
const v1 = require("../../../v1/index.js");
|
||||||
const Cloudevent = require("../../../index.js");
|
const CloudEvent = require("../../../index.js");
|
||||||
|
|
||||||
const { asBase64 } = require("../../../lib/utils/fun.js");
|
const { asBase64 } = require("../../../lib/utils/fun.js");
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ describe("HTTP Transport Binding Structured Receiver for CloudEvents v1.0",
|
||||||
it("Throw error when the event does not follow the spec", () => {
|
it("Throw error when the event does not follow the spec", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload =
|
const payload =
|
||||||
new Cloudevent()
|
new CloudEvent()
|
||||||
.type(type)
|
.type(type)
|
||||||
.source(source)
|
.source(source)
|
||||||
.time(now)
|
.time(now)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const expect = require("chai").expect;
|
const expect = require("chai").expect;
|
||||||
const Unmarshaller = require("../../../lib/bindings/http/unmarshaller_0_3.js");
|
const Unmarshaller = require("../../../lib/bindings/http/unmarshaller_0_3.js");
|
||||||
const Cloudevent = require("../../../index.js");
|
const CloudEvent = require("../../../index.js");
|
||||||
const v03 = require("../../../v03/index.js");
|
const v03 = require("../../../v03/index.js");
|
||||||
|
|
||||||
const type = "com.github.pull.create";
|
const type = "com.github.pull.create";
|
||||||
|
@ -117,7 +117,7 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
|
||||||
it("Should accept event that follow the spec 0.3", () => {
|
it("Should accept event that follow the spec 0.3", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload =
|
const payload =
|
||||||
new Cloudevent(v03.Spec)
|
new CloudEvent(v03.Spec)
|
||||||
.type(type)
|
.type(type)
|
||||||
.source(source)
|
.source(source)
|
||||||
.dataContentType(ceContentType)
|
.dataContentType(ceContentType)
|
||||||
|
@ -146,7 +146,7 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
|
||||||
it("Should parse 'data' stringfied json to json object", () => {
|
it("Should parse 'data' stringfied json to json object", () => {
|
||||||
// setup
|
// setup
|
||||||
const payload =
|
const payload =
|
||||||
new Cloudevent(v03.Spec)
|
new CloudEvent(v03.Spec)
|
||||||
.type(type)
|
.type(type)
|
||||||
.source(source)
|
.source(source)
|
||||||
.dataContentType(ceContentType)
|
.dataContentType(ceContentType)
|
||||||
|
|
|
@ -2,7 +2,7 @@ const expect = require("chai").expect;
|
||||||
const nock = require("nock");
|
const nock = require("nock");
|
||||||
const BinaryHTTPEmitter =
|
const BinaryHTTPEmitter =
|
||||||
require("../lib/bindings/http/emitter_binary_0_3.js");
|
require("../lib/bindings/http/emitter_binary_0_3.js");
|
||||||
const Cloudevent = require("../lib/cloudevent.js");
|
const CloudEvent = require("../lib/cloudevent.js");
|
||||||
const v03 = require("../v03/index.js");
|
const v03 = require("../v03/index.js");
|
||||||
|
|
||||||
const type = "com.github.pull.create";
|
const type = "com.github.pull.create";
|
||||||
|
@ -25,7 +25,7 @@ const ext2Name = "extension2";
|
||||||
const ext2Value = "acme";
|
const ext2Value = "acme";
|
||||||
|
|
||||||
const cloudevent =
|
const cloudevent =
|
||||||
new Cloudevent(v03.Spec)
|
new CloudEvent(v03.Spec)
|
||||||
.type(type)
|
.type(type)
|
||||||
.source(source)
|
.source(source)
|
||||||
.dataContentType(ceContentType)
|
.dataContentType(ceContentType)
|
||||||
|
@ -37,7 +37,7 @@ const cloudevent =
|
||||||
.addExtension(ext2Name, ext2Value);
|
.addExtension(ext2Name, ext2Value);
|
||||||
|
|
||||||
const cebase64 =
|
const cebase64 =
|
||||||
new Cloudevent(v03.Spec)
|
new CloudEvent(v03.Spec)
|
||||||
.type(type)
|
.type(type)
|
||||||
.source(source)
|
.source(source)
|
||||||
.dataContentType(ceContentType)
|
.dataContentType(ceContentType)
|
||||||
|
|
|
@ -7,7 +7,7 @@ const {
|
||||||
Spec,
|
Spec,
|
||||||
BinaryHTTPEmitter,
|
BinaryHTTPEmitter,
|
||||||
StructuredHTTPEmitter,
|
StructuredHTTPEmitter,
|
||||||
Cloudevent
|
CloudEvent
|
||||||
} = require("../v1/index.js");
|
} = require("../v1/index.js");
|
||||||
|
|
||||||
const type = "com.github.pull.create";
|
const type = "com.github.pull.create";
|
||||||
|
@ -28,7 +28,7 @@ const ext2Name = "extension2";
|
||||||
const ext2Value = "acme";
|
const ext2Value = "acme";
|
||||||
|
|
||||||
const cloudevent =
|
const cloudevent =
|
||||||
new Cloudevent(Spec)
|
new CloudEvent(Spec)
|
||||||
.type(type)
|
.type(type)
|
||||||
.source(source)
|
.source(source)
|
||||||
.dataContentType(ceContentType)
|
.dataContentType(ceContentType)
|
||||||
|
@ -94,7 +94,7 @@ describe("HTTP Transport Binding - Version 1.0", () => {
|
||||||
const bindata = Uint32Array.from(dataString, (c) => c.codePointAt(0));
|
const bindata = Uint32Array.from(dataString, (c) => c.codePointAt(0));
|
||||||
const expected = asBase64(bindata);
|
const expected = asBase64(bindata);
|
||||||
const binevent =
|
const binevent =
|
||||||
new Cloudevent(Spec)
|
new CloudEvent(Spec)
|
||||||
.type(type)
|
.type(type)
|
||||||
.source(source)
|
.source(source)
|
||||||
.dataContentType("text/plain")
|
.dataContentType("text/plain")
|
||||||
|
@ -111,7 +111,7 @@ describe("HTTP Transport Binding - Version 1.0", () => {
|
||||||
|
|
||||||
it("the payload must have 'data_base64' when data is binary", () => {
|
it("the payload must have 'data_base64' when data is binary", () => {
|
||||||
const binevent =
|
const binevent =
|
||||||
new Cloudevent(Spec)
|
new CloudEvent(Spec)
|
||||||
.type(type)
|
.type(type)
|
||||||
.source(source)
|
.source(source)
|
||||||
.dataContentType("text/plain")
|
.dataContentType("text/plain")
|
||||||
|
@ -164,7 +164,7 @@ describe("HTTP Transport Binding - Version 1.0", () => {
|
||||||
const bindata = Uint32Array.from(dataString, (c) => c.codePointAt(0));
|
const bindata = Uint32Array.from(dataString, (c) => c.codePointAt(0));
|
||||||
const expected = asBase64(bindata);
|
const expected = asBase64(bindata);
|
||||||
const binevent =
|
const binevent =
|
||||||
new Cloudevent(Spec)
|
new CloudEvent(Spec)
|
||||||
.type(type)
|
.type(type)
|
||||||
.source(source)
|
.source(source)
|
||||||
.dataContentType("text/plain")
|
.dataContentType("text/plain")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const expect = require("chai").expect;
|
const expect = require("chai").expect;
|
||||||
const Spec03 = require("../lib/specs/spec_0_3.js");
|
const Spec03 = require("../lib/specs/spec_0_3.js");
|
||||||
const Cloudevent = require("../index.js");
|
const CloudEvent = require("../index.js");
|
||||||
const { v4: uuidv4 } = require("uuid");
|
const { v4: uuidv4 } = require("uuid");
|
||||||
|
|
||||||
const id = uuidv4();
|
const id = uuidv4();
|
||||||
|
@ -16,7 +16,7 @@ const data = {
|
||||||
const subject = "subject-x0";
|
const subject = "subject-x0";
|
||||||
|
|
||||||
const cloudevent =
|
const cloudevent =
|
||||||
new Cloudevent(Spec03)
|
new CloudEvent(Spec03)
|
||||||
.id(id)
|
.id(id)
|
||||||
.source(source)
|
.source(source)
|
||||||
.type(type)
|
.type(type)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const expect = require("chai").expect;
|
const expect = require("chai").expect;
|
||||||
const Spec1 = require("../lib/specs/spec_1.js");
|
const Spec1 = require("../lib/specs/spec_1.js");
|
||||||
const Cloudevent = require("../index.js");
|
const CloudEvent = require("../index.js");
|
||||||
const { v4: uuidv4 } = require("uuid");
|
const { v4: uuidv4 } = require("uuid");
|
||||||
const { asBase64 } = require("../lib/utils/fun.js");
|
const { asBase64 } = require("../lib/utils/fun.js");
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ const data = {
|
||||||
const subject = "subject-x0";
|
const subject = "subject-x0";
|
||||||
|
|
||||||
const cloudevent =
|
const cloudevent =
|
||||||
new Cloudevent(Spec1)
|
new CloudEvent(Spec1)
|
||||||
.id(id)
|
.id(id)
|
||||||
.source(source)
|
.source(source)
|
||||||
.type(type)
|
.type(type)
|
||||||
|
|
11
v03/index.js
11
v03/index.js
|
@ -1,4 +1,4 @@
|
||||||
const Cloudevent = require("../lib/cloudevent.js");
|
const CloudEvent = require("../lib/cloudevent.js");
|
||||||
const Spec = require("../lib/specs/spec_0_3.js");
|
const Spec = require("../lib/specs/spec_0_3.js");
|
||||||
const StructuredHTTPEmitter =
|
const StructuredHTTPEmitter =
|
||||||
require("../lib/bindings/http/emitter_structured.js");
|
require("../lib/bindings/http/emitter_structured.js");
|
||||||
|
@ -12,8 +12,8 @@ const BinaryHTTPReceiver =
|
||||||
|
|
||||||
const HTTPUnmarshaller = require("../lib/bindings/http/unmarshaller_0_3.js");
|
const HTTPUnmarshaller = require("../lib/bindings/http/unmarshaller_0_3.js");
|
||||||
|
|
||||||
function event() {
|
function newEvent() {
|
||||||
return new Cloudevent(Spec);
|
return new CloudEvent(Spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -23,7 +23,6 @@ module.exports = {
|
||||||
BinaryHTTPEmitter,
|
BinaryHTTPEmitter,
|
||||||
BinaryHTTPReceiver,
|
BinaryHTTPReceiver,
|
||||||
HTTPUnmarshaller,
|
HTTPUnmarshaller,
|
||||||
Cloudevent,
|
CloudEvent: newEvent,
|
||||||
CloudEvent: Cloudevent,
|
event: newEvent
|
||||||
event
|
|
||||||
};
|
};
|
||||||
|
|
11
v1/index.js
11
v1/index.js
|
@ -1,4 +1,4 @@
|
||||||
const Cloudevent = require("../lib/cloudevent.js");
|
const CloudEvent = require("../lib/cloudevent.js");
|
||||||
const Spec = require("../lib/specs/spec_1.js");
|
const Spec = require("../lib/specs/spec_1.js");
|
||||||
|
|
||||||
const StructuredHTTPEmitter =
|
const StructuredHTTPEmitter =
|
||||||
|
@ -12,8 +12,8 @@ const StructuredHTTPReceiver =
|
||||||
const BinaryHTTPReceiver =
|
const BinaryHTTPReceiver =
|
||||||
require("../lib/bindings/http/receiver_binary_1.js");
|
require("../lib/bindings/http/receiver_binary_1.js");
|
||||||
|
|
||||||
function event() {
|
function newEvent() {
|
||||||
return new Cloudevent(Spec);
|
return new CloudEvent(Spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -22,7 +22,6 @@ module.exports = {
|
||||||
BinaryHTTPEmitter,
|
BinaryHTTPEmitter,
|
||||||
StructuredHTTPReceiver,
|
StructuredHTTPReceiver,
|
||||||
BinaryHTTPReceiver,
|
BinaryHTTPReceiver,
|
||||||
Cloudevent: event,
|
CloudEvent: newEvent,
|
||||||
CloudEvent: event,
|
event: newEvent
|
||||||
event
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue