Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use CloudEvents not cloudevents everywhere #101

Merged
merged 2 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Checkout the new expressive additions.
> There is full example: [typescript-ex](./examples/typescript-ex)

```ts
import Cloudevent, {
import CloudEvent, {
event,
StructuredHTTPEmitter,
BinaryHTTPEmitter,
Expand All @@ -51,7 +51,7 @@ import Cloudevent, {
BinaryHTTPReceiver
} from 'cloudevents-sdk/v1';

let myevent: Cloudevent = event()
let myevent: CloudEvent = event()
.source('/source')
.type('type')
.dataContentType('text/plain')
Expand Down Expand Up @@ -231,7 +231,7 @@ app.post("/", (req, res) => {
- `ext`: external stuff, e.g, Cloud Events JSONSchema
- `lib/bindings`: every 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/specs/`: every spec implementation goes here

Expand All @@ -245,18 +245,18 @@ npm test

## The API

### `Cloudevent` class
### `CloudEvent` class

```js
/*
* Format the payload and return an Object.
*/
Object Cloudevent.format()
Object CloudEvent.format()

/*
* Format the payload as String.
*/
String Cloudevent.toString()
String CloudEvent.toString()
```

### `Formatter` classes
Expand All @@ -265,12 +265,12 @@ Every formatter class must implement these methods to work properly.

```js
/*
* Format the Cloudevent payload argument and return an Object.
* Format the CloudEvent payload argument and return an Object.
*/
Object Formatter.format(Object)

/*
* Format the Cloudevent payload as String.
* Format the CloudEvent payload as String.
*/
String Formatter.toString(Object)
```
Expand All @@ -297,9 +297,9 @@ Every Spec class must implement these methods to work properly.

```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.
Expand All @@ -320,7 +320,7 @@ Every Binding class must implement these methods to work properly.

#### 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
/*
Expand All @@ -329,14 +329,14 @@ Following we have the signature for the binding to emit Cloudevents.
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

Following we have the signature for the binding to receive Cloudevents.
Following we have the signature for the binding to receive CloudEvents.

```js
/*
Expand All @@ -351,9 +351,9 @@ Receiver(config)
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)
Expand Down
24 changes: 12 additions & 12 deletions examples/typescript-ex/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Cloudevent, {
import CloudEvent, {
event,
StructuredHTTPEmitter,
BinaryHTTPEmitter,
Expand All @@ -8,7 +8,7 @@ import Cloudevent, {

export function doSomeStuff() {

const myevent: Cloudevent = event()
const myevent: CloudEvent = event()
.source('/source')
.type('type')
.dataContentType('text/plain')
Expand All @@ -20,13 +20,13 @@ export function doSomeStuff() {
console.log(myevent.toString());
console.log(myevent.getExtensions());

let config = {
const config = {
method: "POST",
url : "https://enu90y24i64jp.x.pipedream.net/"
};

// ------ emitter structured
let structured = new StructuredHTTPEmitter(config);
const structured = new StructuredHTTPEmitter(config);
structured.emit(myevent).then(res => {
// success
console.log("Structured Mode: Success!")
Expand All @@ -37,7 +37,7 @@ export function doSomeStuff() {
});

// ------ emitter binary
let binary = new BinaryHTTPEmitter(config);
const binary = new BinaryHTTPEmitter(config);
binary.emit(myevent).then(res => {
console.log("Binary Mode: Success!");
})
Expand All @@ -46,20 +46,20 @@ export function doSomeStuff() {
});

// ------ receiver structured
let payload = myevent.toString();
let headers = {
const payload = myevent.toString();
const headers = {
"Content-Type":"application/cloudevents+json"
};

let receiverStructured = new StructuredHTTPReceiver();
const receiverStructured = new StructuredHTTPReceiver();
console.log(receiverStructured.parse(payload, headers).toString());

// ------ receiver binary
let extension1 = "mycuston-ext1";
let data = {
const extension1 = "mycuston-ext1";
const data = {
"data" : "dataString"
};
var attributes = {
const attributes = {
"ce-type" : "type",
"ce-specversion" : "1.0",
"ce-source" : "source",
Expand All @@ -70,7 +70,7 @@ export function doSomeStuff() {
"ce-extension1" : extension1
};

let receiverBinary = new BinaryHTTPReceiver();
const receiverBinary = new BinaryHTTPReceiver();
console.log(receiverBinary.parse(data, attributes).toString());

return true;
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const Cloudevent = require("./lib/cloudevent.js");
const CloudEvent = require("./lib/cloudevent.js");

module.exports = Cloudevent;
module.exports = CloudEvent;
4 changes: 2 additions & 2 deletions lib/bindings/http/receiver_binary.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Constants = require("./constants.js");
const Commons = require("./commons.js");
const Cloudevent = require("../../cloudevent.js");
const CloudEvent = require("../../cloudevent.js");

const {
isDefinedOrThrow,
Expand Down Expand Up @@ -88,7 +88,7 @@ BinaryHTTPReceiver.prototype.parse = function(payload, headers) {
const sanityHeaders = Commons.sanityAndClone(headers);

const processedHeaders = [];
const cloudevent = new Cloudevent(this.Spec);
const cloudevent = new CloudEvent(this.Spec);

// dont worry, check() have seen what was required or not
Array.from(Object.keys(this.setterByHeader))
Expand Down
4 changes: 2 additions & 2 deletions lib/bindings/http/receiver_structured.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Constants = require("./constants.js");
const Commons = require("./commons.js");
const Cloudevent = require("../../cloudevent.js");
const CloudEvent = require("../../cloudevent.js");

const {
isDefinedOrThrow,
Expand Down Expand Up @@ -61,7 +61,7 @@ StructuredHTTPReceiver.prototype.parse = function(payload, headers) {
this.spec.check(event);

const processedAttributes = [];
const cloudevent = new Cloudevent(this.Spec);
const cloudevent = new CloudEvent(this.Spec);

Array.from(Object.keys(this.setterByAttribute))
.filter((attribute) => event[attribute])
Expand Down
20 changes: 10 additions & 10 deletions test/bindings/http/receiver_binary_0_3_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
});

describe("Parse", () => {
it("Cloudevent contains 'type'", () => {
it("CloudEvent contains 'type'", () => {
// setup
const payload = {
data: "dataString"
Expand All @@ -170,7 +170,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
.to.equal("type");
});

it("Cloudevent contains 'specversion'", () => {
it("CloudEvent contains 'specversion'", () => {
// setup
const payload = {
data: "dataString"
Expand All @@ -193,7 +193,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
.to.equal("0.3");
});

it("Cloudevent contains 'source'", () => {
it("CloudEvent contains 'source'", () => {
// setup
const payload = {
data: "dataString"
Expand All @@ -216,7 +216,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
.to.equal("/source");
});

it("Cloudevent contains 'id'", () => {
it("CloudEvent contains 'id'", () => {
// setup
const payload = {
data: "dataString"
Expand All @@ -239,7 +239,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
.to.equal("id");
});

it("Cloudevent contains 'time'", () => {
it("CloudEvent contains 'time'", () => {
// setup
const payload = {
data: "dataString"
Expand All @@ -262,7 +262,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
.to.equal("2019-06-16T11:42:00.000Z");
});

it("Cloudevent contains 'schemaurl'", () => {
it("CloudEvent contains 'schemaurl'", () => {
// setup
const payload = {
data: "dataString"
Expand All @@ -285,7 +285,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
.to.equal("http://schema.registry/v1");
});

it("Cloudevent contains 'datacontenttype' (application/json)", () => {
it("CloudEvent contains 'datacontenttype' (application/json)", () => {
// setup
const payload = {
data: "dataString"
Expand All @@ -308,7 +308,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
.to.equal("application/json");
});

it("Cloudevent contains 'datacontenttype' (application/octet-stream)",
it("CloudEvent contains 'datacontenttype' (application/octet-stream)",
() => {
// setup
const payload = "The payload is binary data";
Expand All @@ -330,7 +330,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
.to.equal("application/octet-stream");
});

it("Cloudevent contains 'data' (application/json)", () => {
it("CloudEvent contains 'data' (application/json)", () => {
// setup
const payload = {
data: "dataString"
Expand All @@ -353,7 +353,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
.to.deep.equal(payload);
});

it("Cloudevent contains 'data' (application/octet-stream)", () => {
it("CloudEvent contains 'data' (application/octet-stream)", () => {
// setup
const payload = "The payload is binary data";
const attributes = {
Expand Down
Loading