8000 New definition for cloudevent · lance/sdk-javascript@76b8a42 · GitHub
[go: up one dir, main page]

Skip to content

Commit 76b8a42

Browse files
committed
New definition for cloudevent
Signed-off-by: Fabio José <fabiojose@gmail.com>
1 parent 06927a9 commit 76b8a42

File tree

4 files changed

+2639
-0
lines changed

4 files changed

+2639
-0
lines changed

lib/v02/builder.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*!
2+
* cloudevents.io
3+
* Apache-2.0 Licensed
4+
*/
5+
6+
"use strict";
7+
8+
/**
9+
* Builder prototype
10+
*/
11+
function Builder() {
12+
13+
}
14+
15+
Builder.prototype.withId = (id) => {
16+
17+
return this;
18+
};
19+
20+
Builder.prototype.withSource = (source) => {
21+
22+
return this;
23+
};
24+
25+
Builder.prototype.withSpecversion = (specversion) => {
26+
27+
return this;
28+
};
29+
30+
Builder.prototype.withType = (type) => {
31+
32+
return this;
33+
};
34+
35+
Builder.prototype.withExtensions = (extensions) => {
36+
37+
return this;
38+
};
39+
40+
/**
41+
* Builds a brand new immutable instance of CloudEvent.
42+
* @return {CloudEvent}
43+
* @public
44+
*/
45+
Builder.prototype.build = () => {
46+
47+
};
48+
49+
module.exports = Builder;

lib/v02/cloudevent.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*!
2+
* cloudevents.io
3+
* Apache-2.0 Licensed
4+
*/
5+
6+
"use strict";
7+
8+
/**
9+
* CloudEvent prototype
10+
*
11+
* @example
12+
* let event = new CloudEvent("A234-1234-1234", "https://github.com/cloudevents/spec/pull", "com.github.pull.create", {
13+
* "comexampleextension1" : "value",
14+
* "comexampleextension2" : {
15+
* "othervalue" : 5
16+
* }
17+
* });
18+
*
19+
* @constructor
20+
* @class
21+
* @param {String} id - Identifies the event
22+
* @param {String} source - Identifies the context in which an event happened
23+
* @param {String} type - The originating occurrence
24+
* @param {Object} extensions - Custom additional context attributes
25+
26+
* @param {Object} data - Data attribute
27+
* @public
28+
*/
29+
function CloudEvent(id, source, type, extensions, data) {
30+
31+
}
32+
33+
CloudEvent.prototype.id = () => {
34+
35+
};
36+
37+
CloudEvent.prototype.source = () => {
38+
39+
};
40+
41+
/**
42+
* The CloudEvents Spec version
43+
* @public
44+
* @return {String} Always set to '0.2'
45+
*/
46+
CloudEvent.prototype.specversion = () => {
47+
return "0.2";
48+
};
49+
50+
CloudEvent.prototype.type = () => {
51+
52+
};
53+
54+
CloudEvent.prototype.get = (extension) => {
55+
56+
};
57+
58+
CloudEvent.prototype.data = (data) => {
59+
60+
};
61+
62+
/**
63+
* Returns the internal representation of context attributes, extension
64+
* attribute and data attribute.
65+
*
66+
* @example
67+
* let event = new CloudEvent("A234-1234-1234", "https://github.com/cloudevents/spec/pull", "com.github.pull.create");
68+
* event
69+
* .then((payload) => {
70+
* // use the event payload, which is valid
71+
* payload.id;
72+
* payload.source;
73+
* payload.specversion;
74+
* })
75+
* .catch((err) => {
76+
* // threat the err reporting an invalid payload
77+
* });
78+
*
79+
* @return {Promise} To resolve the event as object notation
80+
* @public
81+
*/
82+
CloudEvent.prototype.asObject = () => {
83+
84+
};
85+
86+
/**
87+
* Validates the payload against the definitions, but if something
88+
* is wrong throws and exception.
89+
*
90+
*/
91+
CloudEvent.prototype.validate = () => {
92+
93+
};
94+
95+
module.exports = CloudEvent;

0 commit comments

Comments
 (0)
0