Skip to content

Commit

Permalink
Fix some conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio José <fabiojose@gmail.com>
  • Loading branch information
fabiojose committed Jun 25, 2019
2 parents 8913c37 + 06fc788 commit e91913f
Show file tree
Hide file tree
Showing 31 changed files with 1,817 additions and 106 deletions.
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
examples/
.travis.yml

12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
skip_cleanup: true
on:
tags: true

- stage: npm release
node_js: '6'
deploy:
Expand All @@ -25,7 +26,16 @@ jobs:
skip_cleanup: true
on:
tags: true

- stage: coverage
node_js: '6'
deploy:
provider: script
script: npm run coverage
on:
branch: master
on:
branch: develop
env:
global:
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=
script: npm run coverage
30 changes: 30 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Contributing to CloudEvents' JavaScript SDK

:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:

Following you will see some guidelines about how to contribute with
JavaScript SDK.

## Pull Requests

Guidelines about how to perform pull requests.

- before submit the PR, open an issue and link them

### PR to `develop`

- fixes in the documentation (readme, contributors)
- propose new files for the documentation
- implementation of new features

### PR to `master`

- hot fixes

## Style Guide

_TODO_

### JavaScript Style Guide

_TODO_
171 changes: 148 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ Official CloudEvents' SDK for JavaScript.

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

## Contributing

Before create an awesome PR, please read our [guidelines](./CONTRIBUTING.md).

## Examples

To see working examples, point to [examples](./examples).

## Versioning

### Before Spec reaches 1.0

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

### After Spec reaches 1.0__
### After Spec reaches 1.0

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

### What we can do?

| __What__ | __v0.1__ | __v0.2__ |
|------------------------------------|----------|----------|
| Create events | yes | yes |
| Emit Structured events over HTTP | yes | yes |
| Emit Binary events over HTTP | yes | yes |
| JSON Event Format | yes | yes |
| Receice Structured events over HTTP| no | yes |
| Receice Binary events over HTTP | no | yes |

## How to use

The `Cloudevent` constructor arguments.

```js

/*
* spec : if is null, set the spec 0.1 impl
* format: if is null, set the JSON Format 0.1 impl
Expand Down Expand Up @@ -74,11 +91,11 @@ cloudevent01
.source("urn:event:from:myapi/resourse/123");

/*
* Backward compatibility to spec 0.1 by injecting methods from spec implementation
* Backward compatibility to spec 0.1 by injecting methods from spec implementation
* to Cloudevent
*/
cloudevent01
.eventTypeVersion("1.0");
.eventTypeVersion("1.0");

/*
* Constructs an instance with:
Expand All @@ -104,7 +121,7 @@ var Cloudevent = require("cloudevents-sdk");
/*
* Creates an instance with default spec and format
*/
var cloudevent =
var cloudevent =
new Cloudevent()
.type("com.github.pull.create")
.source("urn:event:from:myapi/resourse/123");
Expand All @@ -113,7 +130,6 @@ var cloudevent =
* Format the payload and return it
*/
var formatted = cloudevent.format();

```

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

// The event
var cloudevent = new Cloudevent()
.type("com.github.pull.create")
.source("urn:event:from:myapi/resourse/123");
var cloudevent =
new Cloudevent()
.type("com.github.pull.create")
.source("urn:event:from:myapi/resourse/123");

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

}).catch(err => {
// Treat the error
// Deal with errors
console.error(err);
});
```
#### Receiving Events

You can choose any framework for port binding. But, use the Unmarshaller
to process the HTTP Payload and HTTP Headers, extracting the CloudEvents.

The Unmarshaller will parse the HTTP Request and decides if it is a binary
or a structured version of transport binding.

__:smiley: Checkout the full working example: [here](./examples/express-ex).__

```js
// some parts were removed //

var Unmarshaller02 = require("cloudevents-sdk/http/unmarshaller/v02");

// some parts were removed //

app.post('/', function (req, res) {
unmarshaller.unmarshall(req.body, req.headers)
.then(cloudevent => {

// TODO use the cloudevent

res.status(201)
.send("Event Accepted");
})
.catch(err => {
console.error(err);
res.status(400)
.header("Content-Type", "application/json")
.send(JSON.stringify(err));
});
});


```

## Repository Structure

```text
├── index.js
├── ext
├── lib
│   ├── bindings
│   │   └── http
│   ├── cloudevent.js
│   ├── format
│   ├── formats
│   │   └── json
│   └── specs
├── LICENSE
├── package.json
├── README.md
```

- `index.js`: library exports
- `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/format/`: every format implementation goes here
- `lib/formats/`: every format implementation goes here
- `lib/specs/`: every spec implementation goes here

## Unit Testing

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

```bash

npm test

```

## The API

### `Cloudevent` class

```js

/*
* Format the payload and return an Object.
*/
Expand All @@ -200,49 +253,77 @@ Object Cloudevent.format()
*/
String Cloudevent.toString()

/*
* Create a Cloudevent instance from String.
*/
Cloudevent Cloudevent.fromString(String)

```

### `Formatter` classes

Every formatter class must implement these methods to work properly.

```js

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

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

### `Parser` classes

Every Parser class must implement these methods to work properly.

```js
/*
* The default constructor with Spec as parameter
*/
Parser(Spec)

/*
* Try to parse the payload to some event format
*/
Object Parser.parse(payload)
```

## `Spec` classes
### `Spec` classes

Every Spec class must implement these methods to work properly.

```js

/*
* The constructor must receives the Cloudevent type.
*/
Spec(Cloudevent)

/*
* Checks the spec constraints, throwing an error if do not pass.
* @throws Error when it is an invalid event
*/
Spec.check()

/*
* Checks if the argument pass through the spec constraints
* @throws Error when it is an invalid event
*/
Spec.check(Object)
```

### `Binding` classes

Every Binding class must implement these methods to work properly.

```js
#### Emitter Binding

Following we have the signature for the binding to emit Cloudevents.

```js
/*
* The constructor must receives the map of configurations.
*/
Expand All @@ -252,7 +333,51 @@ Binding(config)
* Emits the event using an instance of Cloudevent.
*/
Binding.emit(cloudevent)
```

#### Receiver Binding

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

```js
/*
* The constructor must receives the map of configurations.
*/
Receiver(config)

/*
* Checks if some Object and a Map of headers
* follows the binding definition, throwing an error if did not follow
*/
Receiver.check(Object, Map)

/*
* Checks and parse as Cloudevent
*/
Cloudevent Receiver.parse(Object, Map)
```

### `Unmarshaller` classes

The Unmarshaller classes uses the receiver API, abstracting the formats:

- structured
- binary

Choosing the right implementation based on the `headers` map.

```js
/*
* Constructor without arguments
*/
Unmarshaller()

/*
* The method to unmarshall the payload.
* @arg payload could be a string or a object
* @arg headers a map of headers
*/
Promise Unmarshaller.unmarshall(payload, headers)
```

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

0 comments on commit e91913f

Please sign in to comment.