Skip to content

Commit e91913f

Browse files
committed
Fix some conflicts
Signed-off-by: Fabio José <[email protected]>
2 parents 8913c37 + 06fc788 commit e91913f

31 files changed

+1817
-106
lines changed

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
examples/
2+
.travis.yml
3+

.travis.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
skip_cleanup: true
1616
on:
1717
tags: true
18+
1819
- stage: npm release
1920
node_js: '6'
2021
deploy:
@@ -25,7 +26,16 @@ jobs:
2526
skip_cleanup: true
2627
on:
2728
tags: true
29+
30+
- stage: coverage
31+
node_js: '6'
32+
deploy:
33+
provider: script
34+
script: npm run coverage
35+
on:
36+
branch: master
37+
on:
38+
branch: develop
2839
env:
2940
global:
3041
secure: t0A5/Fk1Qj8WkAk0ZuQqpFjrpINV6gfL+d1fXgq03EOAG/7FEyyz+AKkYaLT6avp26VWBzLgEoWC3RNmWD0v1/Ruckb95YpQcb5e4JotAce1ZsHgGTgx0UO146tkyGvXBw6MmO2nX2O/sHzkmyR6rlKkBi9LEKokJ9OFd6fi9nNtksgUDxkqNlNTu100fIQAV2RcN47C6iUx+gJIa+H/8QX/Cz02MyheXLe8a763wMQapz5GHrk2KuVY6FpylcAlSi2so+PjEGfKq3MWaQnTPkevkRDLtGcecVtFAq/0VbvoKc97PHoVT0x+nf48k1gj2VnQtYj6EVB74yRvqM9KkNOsfAQ0z9zF5wXMRs11SZywSViLQsnD9Ue6eYbYmodOKn4DFlLtoRyLBUspzLuoL76lERGe2cHU+Ebz2Nb9jL88o+SjfGrSJQEJU7SLZLbzJ7T/3SspWcAlo+Fo9UTCOB4/yL22Yge/SWQkdd1orBhohpjpyrU9Z1+IRvVoU1EICr04zSFUwEwn6Yxbt0ArgTZBEf11bf+YpCo+rBXNAd+XbZ79PGOEppFb+Hxrt9i1S1RnesDJnwC0k7cswU55Rv5gcNCo9lC+N4ZwS5y+5r6DsBfB+12YdsFORFyNbClECro1ODv4STf3rBBnjL8+ziPFjP4d4OwiGY+vG8bvLXY=
31-
script: npm run coverage

CONTRIBUTING.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Contributing to CloudEvents' JavaScript SDK
2+
3+
:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
4+
5+
Following you will see some guidelines about how to contribute with
6+
JavaScript SDK.
7+
8+
## Pull Requests
9+
10+
Guidelines about how to perform pull requests.
11+
12+
- before submit the PR, open an issue and link them
13+
14+
### PR to `develop`
15+
16+
- fixes in the documentation (readme, contributors)
17+
- propose new files for the documentation
18+
- implementation of new features
19+
20+
### PR to `master`
21+
22+
- hot fixes
23+
24+
## Style Guide
25+
26+
_TODO_
27+
28+
### JavaScript Style Guide
29+
30+
_TODO_

README.md

Lines changed: 148 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@ Official CloudEvents' SDK for JavaScript.
88

99
<img src="https://github.com/cncf/artwork/blob/master/projects/cloudevents/horizontal/color/cloudevents-horizontal-color.png" width="300" height="58" alt="CloudEvents logo">
1010

11+
## Contributing
12+
13+
Before create an awesome PR, please read our [guidelines](./CONTRIBUTING.md).
14+
15+
## Examples
16+
17+
To see working examples, point to [examples](./examples).
18+
1119
## Versioning
1220

1321
### Before Spec reaches 1.0
1422

15-
- `0.x.p`: where `x` relates to spec version and `p` relates to fixes, see
16-
[semver](https://semver.org/).
23+
- `0.x.p`: where `x` relates to spec version and `p` relates to fixes and releases.
1724

18-
### After Spec reaches 1.0__
25+
### After Spec reaches 1.0
1926

2027
- `x.M.p`: where `x` relates to spec version, `M` relates to minor and `p` relates
2128
to fixes. See [semver](https://semver.org/)
@@ -40,12 +47,22 @@ These are the supported specifications by this version.
4047
| HTTP Transport Binding - Binary | yes | yes |
4148
| JSON Event Format | yes | yes |
4249

50+
### What we can do?
51+
52+
| __What__ | __v0.1__ | __v0.2__ |
53+
|------------------------------------|----------|----------|
54+
| Create events | yes | yes |
55+
| Emit Structured events over HTTP | yes | yes |
56+
| Emit Binary events over HTTP | yes | yes |
57+
| JSON Event Format | yes | yes |
58+
| Receice Structured events over HTTP| no | yes |
59+
| Receice Binary events over HTTP | no | yes |
60+
4361
## How to use
4462

4563
The `Cloudevent` constructor arguments.
4664

4765
```js
48-
4966
/*
5067
* spec : if is null, set the spec 0.1 impl
5168
* format: if is null, set the JSON Format 0.1 impl
@@ -74,11 +91,11 @@ cloudevent01
7491
.source("urn:event:from:myapi/resourse/123");
7592

7693
/*
77-
* Backward compatibility to spec 0.1 by injecting methods from spec implementation
94+
* Backward compatibility to spec 0.1 by injecting methods from spec implementation
7895
* to Cloudevent
7996
*/
8097
cloudevent01
81-
.eventTypeVersion("1.0");
98+
.eventTypeVersion("1.0");
8299

83100
/*
84101
* Constructs an instance with:
@@ -104,7 +121,7 @@ var Cloudevent = require("cloudevents-sdk");
104121
/*
105122
* Creates an instance with default spec and format
106123
*/
107-
var cloudevent =
124+
var cloudevent =
108125
new Cloudevent()
109126
.type("com.github.pull.create")
110127
.source("urn:event:from:myapi/resourse/123");
@@ -113,7 +130,6 @@ var cloudevent =
113130
* Format the payload and return it
114131
*/
115132
var formatted = cloudevent.format();
116-
117133
```
118134

119135
#### Emitting
@@ -122,9 +138,10 @@ var formatted = cloudevent.format();
122138
var Cloudevent = require("cloudevents-sdk");
123139

124140
// The event
125-
var cloudevent = new Cloudevent()
126-
.type("com.github.pull.create")
127-
.source("urn:event:from:myapi/resourse/123");
141+
var cloudevent =
142+
new Cloudevent()
143+
.type("com.github.pull.create")
144+
.source("urn:event:from:myapi/resourse/123");
128145

129146
// The binding configuration using POST
130147
var config = {
@@ -147,49 +164,85 @@ binding.emit(cloudevent)
147164
console.log(response.data);
148165

149166
}).catch(err => {
150-
// Treat the error
167+
// Deal with errors
168+
console.error(err);
169+
});
170+
```
171+
#### Receiving Events
172+
173+
You can choose any framework for port binding. But, use the Unmarshaller
174+
to process the HTTP Payload and HTTP Headers, extracting the CloudEvents.
175+
176+
The Unmarshaller will parse the HTTP Request and decides if it is a binary
177+
or a structured version of transport binding.
178+
179+
__:smiley: Checkout the full working example: [here](./examples/express-ex).__
180+
181+
```js
182+
// some parts were removed //
183+
184+
var Unmarshaller02 = require("cloudevents-sdk/http/unmarshaller/v02");
185+
186+
// some parts were removed //
187+
188+
app.post('/', function (req, res) {
189+
unmarshaller.unmarshall(req.body, req.headers)
190+
.then(cloudevent => {
191+
192+
// TODO use the cloudevent
193+
194+
res.status(201)
195+
.send("Event Accepted");
196+
})
197+
.catch(err => {
151198
console.error(err);
199+
res.status(400)
200+
.header("Content-Type", "application/json")
201+
.send(JSON.stringify(err));
152202
});
203+
});
204+
205+
153206
```
154207

155208
## Repository Structure
156209

157210
```text
158211
├── index.js
212+
├── ext
159213
├── lib
160214
│   ├── bindings
161215
│   │   └── http
162216
│   ├── cloudevent.js
163-
│   ├── format
217+
│   ├── formats
218+
│   │   └── json
164219
│   └── specs
165220
├── LICENSE
166221
├── package.json
167222
├── README.md
168223
```
169224

170225
- `index.js`: library exports
226+
- `ext`: external stuff, e.g, Cloud Events JSONSchema
171227
- `lib/bindings`: every binding implementation goes here
172228
- `lib/bindings/http`: every http binding implementation goes here
173229
- `lib/cloudevent.js`: implementation of Cloudevent, an interface
174-
- `lib/format/`: every format implementation goes here
230+
- `lib/formats/`: every format implementation goes here
175231
- `lib/specs/`: every spec implementation goes here
176232

177233
## Unit Testing
178234

179235
The unit test checks the result of formatted payload and the constraints.
180236

181237
```bash
182-
183238
npm test
184-
185239
```
186240

187241
## The API
188242

189243
### `Cloudevent` class
190244

191245
```js
192-
193246
/*
194247
* Format the payload and return an Object.
195248
*/
@@ -200,49 +253,77 @@ Object Cloudevent.format()
200253
*/
201254
String Cloudevent.toString()
202255

256+
/*
257+
* Create a Cloudevent instance from String.
258+
*/
259+
Cloudevent Cloudevent.fromString(String)
260+
203261
```
204262

205263
### `Formatter` classes
206264

207265
Every formatter class must implement these methods to work properly.
208266

209267
```js
210-
211268
/*
212269
* Format the Cloudevent payload argument and return an Object.
213270
*/
214-
Object Formatter.format(payload)
271+
Object Formatter.format(Object)
215272

216273
/*
217274
* Format the Cloudevent payload as String.
218275
*/
219-
String Formatter.toString(payload)
276+
String Formatter.toString(Object)
277+
```
278+
279+
### `Parser` classes
280+
281+
Every Parser class must implement these methods to work properly.
282+
283+
```js
284+
/*
285+
* The default constructor with Spec as parameter
286+
*/
287+
Parser(Spec)
220288

289+
/*
290+
* Try to parse the payload to some event format
291+
*/
292+
Object Parser.parse(payload)
221293
```
222294

223-
## `Spec` classes
295+
### `Spec` classes
224296

225297
Every Spec class must implement these methods to work properly.
226298

227299
```js
228-
229300
/*
230301
* The constructor must receives the Cloudevent type.
231302
*/
232303
Spec(Cloudevent)
233304

234305
/*
235306
* Checks the spec constraints, throwing an error if do not pass.
307+
* @throws Error when it is an invalid event
236308
*/
237309
Spec.check()
238310

311+
/*
312+
* Checks if the argument pass through the spec constraints
313+
* @throws Error when it is an invalid event
314+
*/
315+
Spec.check(Object)
239316
```
317+
240318
### `Binding` classes
241319

242320
Every Binding class must implement these methods to work properly.
243321

244-
```js
322+
#### Emitter Binding
245323

324+
Following we have the signature for the binding to emit Cloudevents.
325+
326+
```js
246327
/*
247328
* The constructor must receives the map of configurations.
248329
*/
@@ -252,7 +333,51 @@ Binding(config)
252333
* Emits the event using an instance of Cloudevent.
253334
*/
254335
Binding.emit(cloudevent)
336+
```
337+
338+
#### Receiver Binding
339+
340+
Following we have the signature for the binding to receive Cloudevents.
341+
342+
```js
343+
/*
344+
* The constructor must receives the map of configurations.
345+
*/
346+
Receiver(config)
347+
348+
/*
349+
* Checks if some Object and a Map of headers
350+
* follows the binding definition, throwing an error if did not follow
351+
*/
352+
Receiver.check(Object, Map)
353+
354+
/*
355+
* Checks and parse as Cloudevent
356+
*/
357+
Cloudevent Receiver.parse(Object, Map)
358+
```
359+
360+
### `Unmarshaller` classes
255361

362+
The Unmarshaller classes uses the receiver API, abstracting the formats:
363+
364+
- structured
365+
- binary
366+
367+
Choosing the right implementation based on the `headers` map.
368+
369+
```js
370+
/*
371+
* Constructor without arguments
372+
*/
373+
Unmarshaller()
374+
375+
/*
376+
* The method to unmarshall the payload.
377+
* @arg payload could be a string or a object
378+
* @arg headers a map of headers
379+
*/
380+
Promise Unmarshaller.unmarshall(payload, headers)
256381
```
257382

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

0 commit comments

Comments
 (0)