Skip to content

Commit

Permalink
feat: use CloudEvents not cloudevents everywhere
Browse files Browse the repository at this point in the history
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
  • Loading branch information
grant committed Apr 30, 2020
1 parent 005d532 commit 74c8b53
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 73 deletions.
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
4 changes: 2 additions & 2 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 Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var Cloudevent = require("./lib/cloudevent.js");
var 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
var 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
var 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
var 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
var 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
var 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
var 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
var 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
var 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
var 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
var payload = "The payload is binary data";
var attributes = {
Expand Down
20 changes: 10 additions & 10 deletions test/bindings/http/receiver_binary_1_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
});

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

it("Cloudevent contains 'specversion'", () => {
it("CloudEvent contains 'specversion'", () => {
// setup
var payload = {
data: "dataString"
Expand All @@ -194,7 +194,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
.to.equal("1.0");
});

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

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

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

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

it("Cloudevent contains 'contenttype' (application/json)", () => {
it("CloudEvent contains 'contenttype' (application/json)", () => {
// setup
var payload = {
data: "dataString"
Expand All @@ -309,7 +309,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
.to.equal("application/json");
});

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

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

it("Cloudevent contains 'data' (application/octet-stream)", () => {
it("CloudEvent contains 'data' (application/octet-stream)", () => {
// setup
var payload = "The payload is binary data";
var attributes = {
Expand Down
4 changes: 2 additions & 2 deletions test/bindings/http/receiver_structured_1_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var expect = require("chai").expect;
var v1 = require("../../../v1/index.js");
var Cloudevent = require("../../../index.js");
var CloudEvent = require("../../../index.js");

const { asBase64 } = require("../../../lib/utils/fun.js");

Expand Down Expand Up @@ -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", () => {
// setup
var payload =
new Cloudevent()
new CloudEvent()
.type(type)
.source(source)
.time(now)
Expand Down
6 changes: 3 additions & 3 deletions test/bindings/http/unmarshaller_0_3_tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var expect = require("chai").expect;
var Unmarshaller = require("../../../lib/bindings/http/unmarshaller_0_3.js");
var Cloudevent = require("../../../index.js");
var CloudEvent = require("../../../index.js");
var v03 = require("../../../v03/index.js");

const type = "com.github.pull.create";
Expand Down Expand Up @@ -117,7 +117,7 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
it("Should accept event that follow the spec 0.3", () => {
// setup
var payload =
new Cloudevent(v03.Spec)
new CloudEvent(v03.Spec)
.type(type)
.source(source)
.dataContentType(ceContentType)
Expand Down Expand Up @@ -146,7 +146,7 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
it("Should parse 'data' stringfied json to json object", () => {
// setup
var payload =
new Cloudevent(v03.Spec)
new CloudEvent(v03.Spec)
.type(type)
.source(source)
.dataContentType(ceContentType)
Expand Down
Loading

0 comments on commit 74c8b53

Please sign in to comment.