Skip to content

Commit 05ecbde

Browse files
authored
feat: use CloudEvents not cloudevents everywhere (#101)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
1 parent cd6decd commit 05ecbde

15 files changed

+81
-83
lines changed

Diff for: README.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Checkout the new expressive additions.
4242
> There is full example: [typescript-ex](./examples/typescript-ex)
4343
4444
```ts
45-
import Cloudevent, {
45+
import CloudEvent, {
4646
event,
4747
StructuredHTTPEmitter,
4848
BinaryHTTPEmitter,
@@ -51,7 +51,7 @@ import Cloudevent, {
5151
BinaryHTTPReceiver
5252
} from 'cloudevents-sdk/v1';
5353

54-
let myevent: Cloudevent = event()
54+
let myevent: CloudEvent = event()
5555
.source('/source')
5656
.type('type')
5757
.dataContentType('text/plain')
@@ -231,7 +231,7 @@ app.post("/", (req, res) => {
231231
- `ext`: external stuff, e.g, Cloud Events JSONSchema
232232
- `lib/bindings`: every binding implementation goes here
233233
- `lib/bindings/http`: every http binding implementation goes here
234-
- `lib/cloudevent.js`: implementation of Cloudevent, an interface
234+
- `lib/cloudevent.js`: implementation of CloudEvent, an interface
235235
- `lib/formats/`: every format implementation goes here
236236
- `lib/specs/`: every spec implementation goes here
237237

@@ -245,18 +245,18 @@ npm test
245245

246246
## The API
247247

248-
### `Cloudevent` class
248+
### `CloudEvent` class
249249

250250
```js
251251
/*
252252
* Format the payload and return an Object.
253253
*/
254-
Object Cloudevent.format()
254+
Object CloudEvent.format()
255255

256256
/*
257257
* Format the payload as String.
258258
*/
259-
String Cloudevent.toString()
259+
String CloudEvent.toString()
260260
```
261261

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

266266
```js
267267
/*
268-
* Format the Cloudevent payload argument and return an Object.
268+
* Format the CloudEvent payload argument and return an Object.
269269
*/
270270
Object Formatter.format(Object)
271271

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

298298
```js
299299
/*
300-
* The constructor must receives the Cloudevent type.
300+
* The constructor must receives the CloudEvent type.
301301
*/
302-
Spec(Cloudevent)
302+
Spec(CloudEvent)
303303

304304
/*
305305
* 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.
320320

321321
#### Emitter Binding
322322

323-
Following we have the signature for the binding to emit Cloudevents.
323+
Following we have the signature for the binding to emit CloudEvents.
324324

325325
```js
326326
/*
@@ -329,14 +329,14 @@ Following we have the signature for the binding to emit Cloudevents.
329329
Binding(config)
330330

331331
/*
332-
* Emits the event using an instance of Cloudevent.
332+
* Emits the event using an instance of CloudEvent.
333333
*/
334-
Binding.emit(cloudevent)
334+
Binding.emit(cloudEvent)
335335
```
336336

337337
#### Receiver Binding
338338

339-
Following we have the signature for the binding to receive Cloudevents.
339+
Following we have the signature for the binding to receive CloudEvents.
340340

341341
```js
342342
/*
@@ -351,9 +351,9 @@ Receiver(config)
351351
Receiver.check(Object, Map)
352352

353353
/*
354-
* Checks and parse as Cloudevent
354+
* Checks and parse as CloudEvent
355355
*/
356-
Cloudevent Receiver.parse(Object, Map)
356+
CloudEvent Receiver.parse(Object, Map)
357357
```
358358

359359
> See how to implement the method injection [here](lib/specs/spec_0_1.js#L17)

Diff for: examples/typescript-ex/src/index.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Cloudevent, {
1+
import CloudEvent, {
22
event,
33
StructuredHTTPEmitter,
44
BinaryHTTPEmitter,
@@ -8,7 +8,7 @@ import Cloudevent, {
88

99
export function doSomeStuff() {
1010

11-
const myevent: Cloudevent = event()
11+
const myevent: CloudEvent = event()
1212
.source('/source')
1313
.type('type')
1414
.dataContentType('text/plain')
@@ -20,13 +20,13 @@ export function doSomeStuff() {
2020
console.log(myevent.toString());
2121
console.log(myevent.getExtensions());
2222

23-
let config = {
23+
const config = {
2424
method: "POST",
2525
url : "https://enu90y24i64jp.x.pipedream.net/"
2626
};
2727

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

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

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

54-
let receiverStructured = new StructuredHTTPReceiver();
54+
const receiverStructured = new StructuredHTTPReceiver();
5555
console.log(receiverStructured.parse(payload, headers).toString());
5656

5757
// ------ receiver binary
58-
let extension1 = "mycuston-ext1";
59-
let data = {
58+
const extension1 = "mycuston-ext1";
59+
const data = {
6060
"data" : "dataString"
6161
};
62-
var attributes = {
62+
const attributes = {
6363
"ce-type" : "type",
6464
"ce-specversion" : "1.0",
6565
"ce-source" : "source",
@@ -70,7 +70,7 @@ export function doSomeStuff() {
7070
"ce-extension1" : extension1
7171
};
7272

73-
let receiverBinary = new BinaryHTTPReceiver();
73+
const receiverBinary = new BinaryHTTPReceiver();
7474
console.log(receiverBinary.parse(data, attributes).toString());
7575

7676
return true;

Diff for: index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const Cloudevent = require("./lib/cloudevent.js");
1+
const CloudEvent = require("./lib/cloudevent.js");
22

3-
module.exports = Cloudevent;
3+
module.exports = CloudEvent;

Diff for: lib/bindings/http/receiver_binary.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const Constants = require("./constants.js");
22
const Commons = require("./commons.js");
3-
const Cloudevent = require("../../cloudevent.js");
3+
const CloudEvent = require("../../cloudevent.js");
44

55
const {
66
isDefinedOrThrow,
@@ -88,7 +88,7 @@ BinaryHTTPReceiver.prototype.parse = function(payload, headers) {
8888
const sanityHeaders = Commons.sanityAndClone(headers);
8989

9090
const processedHeaders = [];
91-
const cloudevent = new Cloudevent(this.Spec);
91+
const cloudevent = new CloudEvent(this.Spec);
9292

9393
// dont worry, check() have seen what was required or not
9494
Array.from(Object.keys(this.setterByHeader))

Diff for: lib/bindings/http/receiver_structured.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const Constants = require("./constants.js");
22
const Commons = require("./commons.js");
3-
const Cloudevent = require("../../cloudevent.js");
3+
const CloudEvent = require("../../cloudevent.js");
44

55
const {
66
isDefinedOrThrow,
@@ -61,7 +61,7 @@ StructuredHTTPReceiver.prototype.parse = function(payload, headers) {
6161
this.spec.check(event);
6262

6363
const processedAttributes = [];
64-
const cloudevent = new Cloudevent(this.Spec);
64+
const cloudevent = new CloudEvent(this.Spec);
6565

6666
Array.from(Object.keys(this.setterByAttribute))
6767
.filter((attribute) => event[attribute])

Diff for: test/bindings/http/receiver_binary_0_3_tests.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
147147
});
148148

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

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

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

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

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

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

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

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

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

356-
it("Cloudevent contains 'data' (application/octet-stream)", () => {
356+
it("CloudEvent contains 'data' (application/octet-stream)", () => {
357357
// setup
358358
const payload = "The payload is binary data";
359359
const attributes = {

0 commit comments

Comments
 (0)