@1mill/cloudevents 4.4.1 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +17 -12
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -2
- package/src/index.js +26 -5
- package/src/tests/constructor/originactor.test.js +39 -0
- package/src/tests/methods/origin/originactor.test.js +74 -0
- package/src/tests/methods/originator/originatorid.test.js +51 -0
- package/src/tests/methods/originator/unit.test.js +10 -0
- package/src/tests/methods/wschannel/unit.test.js +1 -4
- package/src/unit.test.js +7 -4
- package/src/utils/setAttribute/index.js +4 -1
- package/src/utils/setAttribute/unit.test.js +25 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog for @1mill/cloudevents
|
|
2
2
|
|
|
3
|
+
## 4.6.0
|
|
4
|
+
|
|
5
|
+
* Add `cloudevent.originactor` attribute and support in `cloudevent.origin({...})` instance method.
|
|
6
|
+
* Depricate `cloudevent.originator({...})` instance method.
|
|
7
|
+
* Depricate `cloudevent.originatorid` attribute.
|
|
8
|
+
|
|
9
|
+
## 4.5.0
|
|
10
|
+
|
|
11
|
+
* Add `cloudevent.originator({...})` instance method.
|
|
12
|
+
* Improve unit tests for `cloudevent.wschannel({...})`.
|
|
13
|
+
|
|
3
14
|
## 4.4.1
|
|
4
15
|
|
|
5
16
|
* Use `const ce = this` in constructor to cosmetically match instance method declarations.
|
package/README.md
CHANGED
|
@@ -24,25 +24,26 @@ const cloudevent = new Cloudevent({
|
|
|
24
24
|
data: JSON.stringify({ some: 'payload' }),
|
|
25
25
|
source: 'https://github.com/1mill/cloudevents',
|
|
26
26
|
type: 'cmd.do-this-command.v0',
|
|
27
|
-
|
|
27
|
+
originactor: 'user:admin#id=1234',
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
console.log(cloudevent)
|
|
31
31
|
// {
|
|
32
|
-
// id: '
|
|
32
|
+
// id: 'v76ZvDVhbcCwD5M_NQ1FS',
|
|
33
33
|
// source: 'https://github.com/1mill/cloudevents',
|
|
34
34
|
// type: 'cmd.do-this-command.v0',
|
|
35
35
|
// specversion: '1.0',
|
|
36
|
-
// time: '2022-09-
|
|
36
|
+
// time: '2022-09-22T01:44:31.717Z',
|
|
37
37
|
// data: '{"some":"payload"}',
|
|
38
38
|
// datacontenttype: 'application/json',
|
|
39
39
|
// dataschema: undefined,
|
|
40
40
|
// subject: undefined,
|
|
41
|
-
//
|
|
41
|
+
// originactor: 'user:admin#id=1234',
|
|
42
|
+
// originid: 'v76ZvDVhbcCwD5M_NQ1FS',
|
|
42
43
|
// originsource: 'https://github.com/1mill/cloudevents',
|
|
43
|
-
// origintime: '2022-09-
|
|
44
|
+
// origintime: '2022-09-22T01:44:31.717Z',
|
|
44
45
|
// origintype: 'cmd.do-this-command.v0',
|
|
45
|
-
// originatorid:
|
|
46
|
+
// originatorid: undefined,
|
|
46
47
|
// wschannelid: undefined
|
|
47
48
|
// }
|
|
48
49
|
|
|
@@ -56,18 +57,19 @@ const enrichedCloudevent = new Cloudevent({
|
|
|
56
57
|
|
|
57
58
|
console.log(enrichedCloudevent)
|
|
58
59
|
// {
|
|
59
|
-
// id: '
|
|
60
|
+
// id: '-RIl1_Dr_uNh6Q4Oa3Ifq',
|
|
60
61
|
// source: 'https://www.erikekberg.com/',
|
|
61
62
|
// type: 'fct.this-thing-happened.v0',
|
|
62
63
|
// specversion: '1.0',
|
|
63
|
-
// time: '2022-09-
|
|
64
|
+
// time: '2022-09-22T01:44:31.747Z',
|
|
64
65
|
// data: '{"new":"payload","value":true}',
|
|
65
66
|
// datacontenttype: 'application/json',
|
|
66
67
|
// dataschema: undefined,
|
|
67
68
|
// subject: undefined,
|
|
68
|
-
//
|
|
69
|
+
// originactor: 'user:admin#id=1234',
|
|
70
|
+
// originid: 'v76ZvDVhbcCwD5M_NQ1FS',
|
|
69
71
|
// originsource: 'https://github.com/1mill/cloudevents',
|
|
70
|
-
// origintime: '2022-09-
|
|
72
|
+
// origintime: '2022-09-22T01:44:31.717Z',
|
|
71
73
|
// origintype: 'cmd.do-this-command.v0',
|
|
72
74
|
// originatorid: undefined,
|
|
73
75
|
// wschannelid: 'some-prefix:my-resource-name#id=12345'
|
|
@@ -83,11 +85,12 @@ console.log(enrichedCloudevent)
|
|
|
83
85
|
| specversion | | String | 1.0 | Cloudevent specification version |
|
|
84
86
|
| subject | | String | | |
|
|
85
87
|
| type | yes | String | | |
|
|
88
|
+
| originactor | | String | | |
|
|
86
89
|
| originid | | String | "id" property | "id" property is internally generated as part of the package |
|
|
87
90
|
| originsource | | String | "source" property | |
|
|
88
91
|
| origintime | | String | "time" property | "time" property is internally generated as part of the package |
|
|
89
92
|
| origintype | | String | "type" property | |
|
|
90
|
-
| originatorid | | String | |
|
|
93
|
+
| originatorid | | String | | Depricated in favor of "originactor" |
|
|
91
94
|
| wschannelid | | String | | |
|
|
92
95
|
|
|
93
96
|
### origin
|
|
@@ -100,6 +103,7 @@ const cloudevent = new Cloudevent({
|
|
|
100
103
|
type: 'my-type',
|
|
101
104
|
})
|
|
102
105
|
.origin({
|
|
106
|
+
originactor: 'my-origin-actor',
|
|
103
107
|
originid: 'my-origin-id',
|
|
104
108
|
originsource: 'my-origin-source',
|
|
105
109
|
origintime: 'my-origin-time',
|
|
@@ -112,7 +116,8 @@ or populate them automatically by passing in an existing Cloudevent
|
|
|
112
116
|
```node
|
|
113
117
|
const originCloudevent = new Cloudevent({
|
|
114
118
|
source: 'my-origin-cloudevent',
|
|
115
|
-
type: 'cmd.say-hello.v0'
|
|
119
|
+
type: 'cmd.say-hello.v0',
|
|
120
|
+
originactor: 'my-origin-actor',
|
|
116
121
|
})
|
|
117
122
|
|
|
118
123
|
const cloudevent = new Cloudevent({
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("nanoid"),n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},i=function(e){var n=e.cloudevent,i=e.
|
|
1
|
+
var e=require("nanoid"),n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},i=function(e){var n=e.cloudevent,i=e.deprecated,t=e.name,o=e.types,r=void 0===o?[]:o,a=e.value;if(void 0!==i&&i&&console.warn('Cloudevent "'+t+'" is depricated'),r.length>0&&!r.includes(typeof a)){var d='Cloudevent "'+t+'" must be of type '+r.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(d)}n[t]=a};exports.Cloudevent=function(t){var o=this,r=t.data,a=t.datacontenttype,d=t.dataschema,u=t.originactor,s=t.originatorid,c=t.originid,v=t.originsource,l=t.origintime,g=t.origintype,p=t.source,y=t.specversion,m=t.subject,f=t.type,h=t.wschannelid;this.origin=function(e){var n=e.cloudevent,t=void 0===n?{}:n,r=e.originid,a=e.originsource,d=e.origintime,u=e.origintype,s=o;return i({cloudevent:s,name:"originactor",types:["string","undefined"],value:e.originactor||t.originactor}),i({cloudevent:s,name:"originid",types:["string"],value:r||t.originid||t.id}),i({cloudevent:s,name:"originsource",types:["string"],value:a||t.originsource||t.source}),i({cloudevent:s,name:"origintime",types:["string"],value:d||t.origintime||t.time}),i({cloudevent:s,name:"origintype",types:["string"],value:u||t.origintype||t.type}),s},this.originator=function(e){var n=e.cloudevent,t=o;return i({cloudevent:t,name:"originatorid",types:["string","undefined"],value:e.originatorid||(void 0===n?{}:n).originatorid}),t},this.wschannel=function(e){var n=e.cloudevent,t=o;return i({cloudevent:t,name:"wschannelid",types:["string","undefined"],value:e.wschannelid||(void 0===n?{}:n).wschannelid}),t};var w=this,C=e.nanoid(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));i({cloudevent:w,name:"id",types:["string"],value:C});var E=p||n("MILL_CLOUDEVENTS_SOURCE");i({cloudevent:w,name:"source",types:["string"],value:E}),i({cloudevent:w,name:"type",types:["string"],value:f}),i({cloudevent:w,name:"specversion",types:["string"],value:y||"1.0"});var L=(new Date).toISOString();i({cloudevent:w,name:"time",types:["string"],value:L}),i({cloudevent:w,name:"data",value:r}),i({cloudevent:w,name:"datacontenttype",types:["string","undefined"],value:void 0!==r?a||"application/json":a}),i({cloudevent:w,name:"dataschema",types:["string","undefined"],value:d}),i({cloudevent:w,name:"subject",types:["string","undefined"],value:m}),this.origin({cloudevent:w,originactor:u,originid:c,originsource:v,origintime:l,origintype:g}),this.originator({cloudevent:w,originatorid:s}),this.wschannel({cloudevent:w,wschannelid:h})};
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst ce = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tthis.origin({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, deprecated = false, name, types = [], value }) => {\r\n\tif (deprecated) { console.warn(`Cloudevent \"${name}\" is depricated`) }\r\n\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginactor,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst ce = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tthis.origin({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginactor,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tthis.originator({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginatorid,\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent: ce,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originactor, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originactorValue = originactor || cloudevent['originactor']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originactor',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originactorValue,\r\n\t\t})\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\toriginator = ({ cloudevent = {}, originatorid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid || cloudevent['originatorid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","_ref","cloudevent","deprecated","_ref$types","types","value","_ref$deprecated","console","warn","length","includes","message","map","s","toUpperCase","sort","join","data","datacontenttype","dataschema","originactor","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","this","origin","_ref2","_ref2$cloudevent","ce","_this","setAttribute","originator","_ref3","_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ACZpC,WAAYkC,EACZvC,KAAM,OACNQ,MAAO,CAAC,UACRC,MAAO0C,IAMRV,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,OACNS,MAAOY,IAMRoB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,kBACNQ,MAAO,CAAC,SAAU,aAClBC,WAP4C,IAATY,EACjCC,GAAmB,mBACnBA,IAQHmB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,aACNQ,MAAO,CAAC,SAAU,aAClBC,MAAOc,IAGRkB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,UACNQ,MAAO,CAAC,SAAU,aAClBC,MAAOuB,IAMRG,KAAKC,OAAO,CACX/B,WAAYkC,EACZf,YAAAA,EACAE,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDM,KAAKO,WAAW,CACfrC,WAAYkC,EACZd,aAAAA,IAGDU,KAAKU,UAAU,CACdxC,WAAYkC,EACZL,YAAAA,GAGD"}
|
package/dist/index.modern.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=(e,n)=>{if("undefined"!=typeof process)return process.env[e]||n},n=({cloudevent:e,
|
|
1
|
+
const e=(e,n)=>{if("undefined"!=typeof process)return process.env[e]||n},n=({cloudevent:e,deprecated:n=!1,name:t,types:i=[],value:o})=>{if(n&&console.warn(`Cloudevent "${t}" is depricated`),i.length>0&&!i.includes(typeof o)){const e=`Cloudevent "${t}" must be of type ${i.map(e=>e.toUpperCase()).sort().join(" or ")}.`;throw new Error(e)}e[t]=o};class t{constructor({data:t,datacontenttype:i,dataschema:o,originactor:r,originatorid:s,originid:a,originsource:d,origintime:c,origintype:u,source:l,specversion:g,subject:v,type:p,wschannelid:y}){this.origin=({cloudevent:e={},originactor:t,originid:i,originsource:o,origintime:r,origintype:s})=>{const a=this;return n({cloudevent:a,name:"originactor",types:["string","undefined"],value:t||e.originactor}),n({cloudevent:a,name:"originid",types:["string"],value:i||e.originid||e.id}),n({cloudevent:a,name:"originsource",types:["string"],value:o||e.originsource||e.source}),n({cloudevent:a,name:"origintime",types:["string"],value:r||e.origintime||e.time}),n({cloudevent:a,name:"origintype",types:["string"],value:s||e.origintype||e.type}),a},this.originator=({cloudevent:e={},originatorid:t})=>(n({cloudevent:this,name:"originatorid",types:["string","undefined"],value:t||e.originatorid}),this),this.wschannel=({cloudevent:e={},wschannelid:t})=>(n({cloudevent:this,name:"wschannelid",types:["string","undefined"],value:t||e.wschannelid}),this);const m=this,h=((e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((e,n)=>e+((n&=63)<36?n.toString(36):n<62?(n-26).toString(36).toUpperCase():n>62?"-":"_"),""))(e("MILL_CLOUDEVENTS_NANOID_LENGTH",21));n({cloudevent:m,name:"id",types:["string"],value:h});const f=l||e("MILL_CLOUDEVENTS_SOURCE");n({cloudevent:m,name:"source",types:["string"],value:f}),n({cloudevent:m,name:"type",types:["string"],value:p}),n({cloudevent:m,name:"specversion",types:["string"],value:g||"1.0"});const w=(new Date).toISOString();n({cloudevent:m,name:"time",types:["string"],value:w}),n({cloudevent:m,name:"data",value:t}),n({cloudevent:m,name:"datacontenttype",types:["string","undefined"],value:void 0!==t?i||"application/json":i}),n({cloudevent:m,name:"dataschema",types:["string","undefined"],value:o}),n({cloudevent:m,name:"subject",types:["string","undefined"],value:v}),this.origin({cloudevent:m,originactor:r,originid:a,originsource:d,origintime:c,origintype:u}),this.originator({cloudevent:m,originatorid:s}),this.wschannel({cloudevent:m,wschannelid:y})}}export{t as Cloudevent};
|
|
2
2
|
//# sourceMappingURL=index.modern.js.map
|
package/dist/index.modern.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.modern.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js","../node_modules/nanoid/index.browser.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst ce = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tthis.origin({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\
|
|
1
|
+
{"version":3,"file":"index.modern.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js","../node_modules/nanoid/index.browser.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, deprecated = false, name, types = [], value }) => {\r\n\tif (deprecated) { console.warn(`Cloudevent \"${name}\" is depricated`) }\r\n\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginactor,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst ce = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tthis.origin({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginactor,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tthis.originator({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginatorid,\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent: ce,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originactor, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originactorValue = originactor || cloudevent['originactor']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originactor',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originactorValue,\r\n\t\t})\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\toriginator = ({ cloudevent = {}, originatorid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid || cloudevent['originatorid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nlet customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nlet nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","cloudevent","deprecated","types","value","console","warn","length","includes","message","map","s","toUpperCase","sort","join","Cloudevent","constructor","data","datacontenttype","dataschema","originactor","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","origin","ce","this","setAttribute","originator","wschannel","_ce","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","idValue","sourceValue","timeValue","Date","toISOString"],"mappings":"AAAO,MAAkBA,EAAG,CAACC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nC,KAAM,aACNM,MAAO,CAAC,SAAU,aAClBC,MAAOe,IAGRe,EAAa,CACZjC,WAAY+B,EACZnC,KAAM,UACNM,MAAO,CAAC,SAAU,aAClBC,MAAOwB,IAMRK,KAAKF,OAAO,CACX9B,WAAY+B,EACZZ,YAAAA,EACAE,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDQ,KAAKE,WAAW,CACflC,WAAY+B,EACZX,aAAAA,IAGDY,KAAKG,UAAU,CACdnC,WAAY+B,EACZF,YAAAA,GAGD"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{nanoid as e}from"nanoid";var n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},i=function(e){var n=e.cloudevent,i=e.
|
|
1
|
+
import{nanoid as e}from"nanoid";var n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},i=function(e){var n=e.cloudevent,i=e.deprecated,t=e.name,o=e.types,r=void 0===o?[]:o,a=e.value;if(void 0!==i&&i&&console.warn('Cloudevent "'+t+'" is depricated'),r.length>0&&!r.includes(typeof a)){var d='Cloudevent "'+t+'" must be of type '+r.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(d)}n[t]=a},t=function(t){var o=this,r=t.data,a=t.datacontenttype,d=t.dataschema,s=t.originactor,u=t.originatorid,c=t.originid,v=t.originsource,l=t.origintime,g=t.origintype,p=t.source,m=t.specversion,y=t.subject,f=t.type,h=t.wschannelid;this.origin=function(e){var n=e.cloudevent,t=void 0===n?{}:n,r=e.originid,a=e.originsource,d=e.origintime,s=e.origintype,u=o;return i({cloudevent:u,name:"originactor",types:["string","undefined"],value:e.originactor||t.originactor}),i({cloudevent:u,name:"originid",types:["string"],value:r||t.originid||t.id}),i({cloudevent:u,name:"originsource",types:["string"],value:a||t.originsource||t.source}),i({cloudevent:u,name:"origintime",types:["string"],value:d||t.origintime||t.time}),i({cloudevent:u,name:"origintype",types:["string"],value:s||t.origintype||t.type}),u},this.originator=function(e){var n=e.cloudevent,t=o;return i({cloudevent:t,name:"originatorid",types:["string","undefined"],value:e.originatorid||(void 0===n?{}:n).originatorid}),t},this.wschannel=function(e){var n=e.cloudevent,t=o;return i({cloudevent:t,name:"wschannelid",types:["string","undefined"],value:e.wschannelid||(void 0===n?{}:n).wschannelid}),t};var w=this,E=e(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));i({cloudevent:w,name:"id",types:["string"],value:E});var L=p||n("MILL_CLOUDEVENTS_SOURCE");i({cloudevent:w,name:"source",types:["string"],value:L}),i({cloudevent:w,name:"type",types:["string"],value:f}),i({cloudevent:w,name:"specversion",types:["string"],value:m||"1.0"});var C=(new Date).toISOString();i({cloudevent:w,name:"time",types:["string"],value:C}),i({cloudevent:w,name:"data",value:r}),i({cloudevent:w,name:"datacontenttype",types:["string","undefined"],value:void 0!==r?a||"application/json":a}),i({cloudevent:w,name:"dataschema",types:["string","undefined"],value:d}),i({cloudevent:w,name:"subject",types:["string","undefined"],value:y}),this.origin({cloudevent:w,originactor:s,originid:c,originsource:v,origintime:l,origintype:g}),this.originator({cloudevent:w,originatorid:u}),this.wschannel({cloudevent:w,wschannelid:h})};export{t as Cloudevent};
|
|
2
2
|
//# sourceMappingURL=index.module.js.map
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.module.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst ce = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tthis.origin({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\
|
|
1
|
+
{"version":3,"file":"index.module.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, deprecated = false, name, types = [], value }) => {\r\n\tif (deprecated) { console.warn(`Cloudevent \"${name}\" is depricated`) }\r\n\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginactor,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst ce = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tthis.origin({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginactor,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tthis.originator({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginatorid,\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent: ce,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originactor, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originactorValue = originactor || cloudevent['originactor']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originactor',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originactorValue,\r\n\t\t})\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\toriginator = ({ cloudevent = {}, originatorid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid || cloudevent['originatorid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","_ref","cloudevent","deprecated","_ref$types","types","value","_ref$deprecated","console","warn","length","includes","message","map","s","toUpperCase","sort","join","data","datacontenttype","dataschema","originactor","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","this","origin","_ref2","_ref2$cloudevent","ce","_this","setAttribute","originator","_ref3","_ref3$cloudevent","wschannel","_ref4","_ref4$cloudevent","idValue","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"gCAAaA,IAAAA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ICH2B,SAAiEG,GAAA,MAA9DC,EAAAA,eAAYC,WAAoBN,EAA8BI,EAA9BJ,KAA8BO,EAAAH,EAAxBI,MAAAA,OAAQ,IAAAD,EAAA,KAAIE,EAAYL,EAAZK,MAGhF,QAHuD,IAAAC,MACrCC,QAAQC,KAAR,eAA4BZ,EAAwB,mBAElEQ,EAAMK,OAAS,IAAML,EAAMM,mBAAwB,CACtD,IAAMC,iBAAyBf,EAAlB,qBAA2CQ,EAAMQ,IAAI,SAAAC,GAAKA,OAAAA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,QAApG,IACA,MAAM,UAAUL,EAChB,CAEDV,EAAWL,GAAQS,CACnB,ICJA,SAAAL,cAeGiB,EAAAjB,EAdFiB,KACAC,EAAAA,EAAAA,gBACAC,EAYEnB,EAZFmB,WACAC,IAAAA,YACAC,EAAAA,EAAAA,aACAC,EASEtB,EATFsB,SACAC,EAAAA,EAAAA,aACAC,EAOExB,EAPFwB,WACAC,IAAAA,WACAC,EAAAA,EAAAA,OACAC,EAIE3B,EAJF2B,YACAC,IAAAA,QACAC,EAEE7B,EAFF6B,KACAC,IAAAA,YACEC,KAyGHC,OAAS,SAAAC,WAAGhC,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,MAAoBlB,GAAU/B,EAAa,2BAC3C0C,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,SACNQ,MAAO,CAAC,UACRC,MAAOyC,IAIRT,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,OACNQ,MAAO,CAAC,UACRC,MALiBwB,IASlBQ,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,cACNQ,MAAO,CAAC,UACRC,MALwBsB,GAAe,QAQxC,IAAMoB,GAAY,IAAIC,MAAOC,cAC7BZ,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,OACNQ,MAAO,CAAC,UACRC,MAAO0C,IAMRV,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,OACNS,MAAOY,IAMRoB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,kBACNQ,MAAO,CAAC,SAAU,aAClBC,WAP4C,IAATY,EACjCC,GAAmB,mBACnBA,IAQHmB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,aACNQ,MAAO,CAAC,SAAU,aAClBC,MAAOc,IAGRkB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,UACNQ,MAAO,CAAC,SAAU,aAClBC,MAAOuB,IAMRG,KAAKC,OAAO,CACX/B,WAAYkC,EACZf,YAAAA,EACAE,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDM,KAAKO,WAAW,CACfrC,WAAYkC,EACZd,aAAAA,IAGDU,KAAKU,UAAU,CACdxC,WAAYkC,EACZL,YAAAA,GAGD"}
|
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).cloudevents={})}(this,function(e){var n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).cloudevents={})}(this,function(e){var n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},i=function(e){var n=e.cloudevent,i=e.deprecated,t=e.name,o=e.types,r=void 0===o?[]:o,a=e.value;if(void 0!==i&&i&&console.warn('Cloudevent "'+t+'" is depricated'),r.length>0&&!r.includes(typeof a)){var d='Cloudevent "'+t+'" must be of type '+r.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(d)}n[t]=a};e.Cloudevent=function(e){var t=this,o=e.data,r=e.datacontenttype,a=e.dataschema,d=e.originactor,s=e.originatorid,u=e.originid,c=e.originsource,v=e.origintime,l=e.origintype,g=e.source,p=e.specversion,y=e.subject,f=e.type,m=e.wschannelid;this.origin=function(e){var n=e.cloudevent,o=void 0===n?{}:n,r=e.originid,a=e.originsource,d=e.origintime,s=e.origintype,u=t;return i({cloudevent:u,name:"originactor",types:["string","undefined"],value:e.originactor||o.originactor}),i({cloudevent:u,name:"originid",types:["string"],value:r||o.originid||o.id}),i({cloudevent:u,name:"originsource",types:["string"],value:a||o.originsource||o.source}),i({cloudevent:u,name:"origintime",types:["string"],value:d||o.origintime||o.time}),i({cloudevent:u,name:"origintype",types:["string"],value:s||o.origintype||o.type}),u},this.originator=function(e){var n=e.cloudevent,o=t;return i({cloudevent:o,name:"originatorid",types:["string","undefined"],value:e.originatorid||(void 0===n?{}:n).originatorid}),o},this.wschannel=function(e){var n=e.cloudevent,o=t;return i({cloudevent:o,name:"wschannelid",types:["string","undefined"],value:e.wschannelid||(void 0===n?{}:n).wschannelid}),o};var h=this,w=((e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((e,n)=>e+((n&=63)<36?n.toString(36):n<62?(n-26).toString(36).toUpperCase():n>62?"-":"_"),""))(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));i({cloudevent:h,name:"id",types:["string"],value:w});var C=g||n("MILL_CLOUDEVENTS_SOURCE");i({cloudevent:h,name:"source",types:["string"],value:C}),i({cloudevent:h,name:"type",types:["string"],value:f}),i({cloudevent:h,name:"specversion",types:["string"],value:p||"1.0"});var E=(new Date).toISOString();i({cloudevent:h,name:"time",types:["string"],value:E}),i({cloudevent:h,name:"data",value:o}),i({cloudevent:h,name:"datacontenttype",types:["string","undefined"],value:void 0!==o?r||"application/json":r}),i({cloudevent:h,name:"dataschema",types:["string","undefined"],value:a}),i({cloudevent:h,name:"subject",types:["string","undefined"],value:y}),this.origin({cloudevent:h,originactor:d,originid:u,originsource:c,origintime:v,origintype:l}),this.originator({cloudevent:h,originatorid:s}),this.wschannel({cloudevent:h,wschannelid:m})}});
|
|
2
2
|
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js","../node_modules/nanoid/index.browser.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst ce = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tthis.origin({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent: ce,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nlet customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nlet nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","setAttribute","cloudevent","_ref","types","_ref$types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","origin","_ref2$cloudevent","_ref2","ce","_this","this","wschannel","_ref3","_ref3$cloudevent","idValue","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"qOAAaA,IAAAA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ECHwBG,EAAG,YAAGC,IAAAA,EAAAA,EAAAA,WAAYL,EAA8BM,EAA9BN,KAAMO,EAAAA,EAAAA,MAAAA,OAAwB,IAAAC,EAAhB,GAAgBA,EAAZC,EAAAA,EAAAA,MAC5D,GAAIF,EAAMG,OAAS,IAAMH,EAAMI,gBAANF,GAA8B,CACtD,IAAaG,EAAA,eAAkBZ,EAAlB,qBAA2CO,EAAMM,IAAI,SAAAC,GAAKA,OAAAA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,YACpG,UAAMC,MAAUN,EAChB,CACDP,EAAWL,GAAQS,CACnB,eCDA,SAAAH,GACCa,IAAAA,EAAAA,KAAAA,IAAAA,KACAC,EAYEd,EAZFc,gBACAC,EAAAA,EAAAA,WACAC,EAUEhB,EAVFgB,aACAC,EAAAA,EAAAA,SACAC,IAAAA,aACAC,EAOEnB,EAPFmB,WACAC,EAAAA,EAAAA,WACAC,EAKErB,EALFqB,OACAC,EAAAA,EAAAA,YACAC,IAAAA,QACAC,EAEExB,EAFFwB,KACAC,EAAAA,EAAAA,iBA2GDC,OAAS,YAAG3B,IAAAA,EAAAA,EAAAA,WAAAA,OAAsE,IAAA4B,EAAzD,GAAyDA,EAA3CT,IAAAA,aAAcC,EAA6BS,EAA7BT,WAAYC,EAAAA,EAAAA,WAC1DS,EAAKC,EAkCX,OA/BAhC,EAAa,CACZC,WAAY8B,EACZnC,KAAM,WACNO,MAAO,CAAC,UACRE,MAR2Bc,EAAAA,UAGMlB,EAAU,UAAgBA,EAAU,KAStED,EAAa,CACZC,WAAY8B,EACZnC,KAAM,eACNO,MAAO,CAAC,UACRE,M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S,MAAOU,IAMRf,EAAa,CACZC,WAAY8B,EACZnC,KAAM,kBACNO,MAAO,CAAC,SAAU,aAClBE,WAP4C,MAC1CW,GAAmB,mBACnBA,IAQHhB,EAAa,CACZC,WAAY8B,EACZnC,KAAM,aACNO,MAAO,CAAC,SAAU,aAClBE,MAAOY,IAGRjB,EAAa,CACZC,WAAY8B,EACZnC,KAAM,UACNO,MAAO,CAAC,SAAU,aAClBE,MAAOoB,IAMRQ,KAAKL,OAAO,CACX3B,WAAY8B,EACZZ,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDtB,EAAa,CACZC,WAAY8B,EACZnC,KAAM,eACNO,MAAO,CAAC,SAAU,aAClBE,MAAOa,IAGRe,KAAKC,UAAU,CACdjC,WAAY8B,EACZJ,YAAAA,GAGD"}
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js","../node_modules/nanoid/index.browser.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, deprecated = false, name, types = [], value }) => {\r\n\tif (deprecated) { console.warn(`Cloudevent \"${name}\" is depricated`) }\r\n\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginactor,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst ce = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tthis.origin({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginactor,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tthis.originator({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginatorid,\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent: ce,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originactor, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originactorValue = originactor || cloudevent['originactor']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originactor',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originactorValue,\r\n\t\t})\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\toriginator = ({ cloudevent = {}, originatorid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid || cloudevent['originatorid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nlet customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nlet nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","_ref","cloudevent","deprecated","_ref$types","types","value","_ref$deprecated","console","warn","length","includes","message","map","s","toUpperCase","sort","join","data","datacontenttype","dataschema","originactor","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","this","origin","_ref2","_ref2$cloudevent","ce","_this","setAttribute","originator","_ref3","_ref3$cloudevent","wschannel","_ref4","_ref4$cloudevent","idValue","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"qOAAaA,IAAAA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ICH2B,SAAiEG,GAAA,MAA9DC,EAAAA,eAAYC,WAAoBN,EAA8BI,EAA9BJ,KAA8BO,EAAAH,EAAxBI,MAAAA,OAAQ,IAAAD,EAAA,KAAIE,EAAYL,EAAZK,MAGhF,QAHuD,IAAAC,MACrCC,QAAQC,KAAR,eAA4BZ,EAAwB,mBAElEQ,EAAMK,OAAS,IAAML,EAAMM,mBAAwB,CACtD,IAAMC,iBAAyBf,EAAlB,qBAA2CQ,EAAMQ,IAAI,SAAAC,GAAKA,OAAAA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,QAApG,IACA,MAAM,UAAUL,EAChB,CAEDV,EAAWL,GAAQS,CACnB,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,MAAOuB,IAMRG,KAAKC,OAAO,CACX/B,WAAYkC,EACZf,YAAAA,EACAE,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDM,KAAKO,WAAW,CACfrC,WAAYkC,EACZd,aAAAA,IAGDU,KAAKU,UAAU,CACdxC,WAAYkC,EACZL,YAAAA,GAGD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1mill/cloudevents",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "Node cloudevents specification and helper",
|
|
5
5
|
"jsnext:main": "dist/index.module.js",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"url": "https://github.com/1mill/cloudevents.git"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"nanoid": "^3.3.4"
|
|
34
|
+
"nanoid": "^3.3.4",
|
|
35
|
+
"sinon-chai": "^3.7.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"chai": "^4.3.6",
|
package/src/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export class Cloudevent {
|
|
|
7
7
|
data,
|
|
8
8
|
datacontenttype,
|
|
9
9
|
dataschema,
|
|
10
|
+
originactor,
|
|
10
11
|
originatorid,
|
|
11
12
|
originid,
|
|
12
13
|
originsource,
|
|
@@ -100,6 +101,7 @@ export class Cloudevent {
|
|
|
100
101
|
// * Required in-house extentions
|
|
101
102
|
this.origin({
|
|
102
103
|
cloudevent: ce,
|
|
104
|
+
originactor,
|
|
103
105
|
originid,
|
|
104
106
|
originsource,
|
|
105
107
|
origintime,
|
|
@@ -109,11 +111,9 @@ export class Cloudevent {
|
|
|
109
111
|
|
|
110
112
|
// *******
|
|
111
113
|
// * Optional in-house extentions
|
|
112
|
-
|
|
114
|
+
this.originator({
|
|
113
115
|
cloudevent: ce,
|
|
114
|
-
|
|
115
|
-
types: ['string', 'undefined'],
|
|
116
|
-
value: originatorid
|
|
116
|
+
originatorid,
|
|
117
117
|
})
|
|
118
118
|
|
|
119
119
|
this.wschannel({
|
|
@@ -123,9 +123,17 @@ export class Cloudevent {
|
|
|
123
123
|
// *******
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
origin = ({ cloudevent = {}, originid, originsource, origintime, origintype }) => {
|
|
126
|
+
origin = ({ cloudevent = {}, originactor, originid, originsource, origintime, origintype }) => {
|
|
127
127
|
const ce = this
|
|
128
128
|
|
|
129
|
+
const originactorValue = originactor || cloudevent['originactor']
|
|
130
|
+
setAttribute({
|
|
131
|
+
cloudevent: ce,
|
|
132
|
+
name: 'originactor',
|
|
133
|
+
types: ['string', 'undefined'],
|
|
134
|
+
value: originactorValue,
|
|
135
|
+
})
|
|
136
|
+
|
|
129
137
|
const originidValue = originid || cloudevent['originid'] || cloudevent['id']
|
|
130
138
|
setAttribute({
|
|
131
139
|
cloudevent: ce,
|
|
@@ -161,6 +169,19 @@ export class Cloudevent {
|
|
|
161
169
|
return ce
|
|
162
170
|
}
|
|
163
171
|
|
|
172
|
+
originator = ({ cloudevent = {}, originatorid }) => {
|
|
173
|
+
const ce = this
|
|
174
|
+
|
|
175
|
+
setAttribute({
|
|
176
|
+
cloudevent: ce,
|
|
177
|
+
name: 'originatorid',
|
|
178
|
+
types: ['string', 'undefined'],
|
|
179
|
+
value: originatorid || cloudevent['originatorid'],
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
return ce
|
|
183
|
+
}
|
|
184
|
+
|
|
164
185
|
wschannel = ({ cloudevent = {}, wschannelid }) => {
|
|
165
186
|
const ce = this
|
|
166
187
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Cloudevent } from '../../index.js'
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
|
|
4
|
+
describe('cloudevent#originactor', () => {
|
|
5
|
+
let params
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
params = {
|
|
9
|
+
// * Required base defaults
|
|
10
|
+
source: 'some-source',
|
|
11
|
+
type: 'some-type',
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
describe('when #originactor is not input', () => {
|
|
16
|
+
it('returns undefined', () => {
|
|
17
|
+
const { originactor } = new Cloudevent(params)
|
|
18
|
+
expect(originactor).to.be.undefined
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
describe('when #originactor is input', () => {
|
|
23
|
+
describe('when the input value is invalid', () => {
|
|
24
|
+
it('throws the proper error', () => {
|
|
25
|
+
const expected = 'Cloudevent "originactor" must be of type STRING or UNDEFINED'
|
|
26
|
+
params.originactor = 1234
|
|
27
|
+
expect(() => new Cloudevent(params)).to.throw(expected)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
describe('when the input value is valid', () => {
|
|
32
|
+
it('returns the input value', () => {
|
|
33
|
+
params.originactor = 'some-originactor'
|
|
34
|
+
const { originactor } = new Cloudevent(params)
|
|
35
|
+
expect(originactor).to.eq(params.originactor)
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
})
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Cloudevent } from '../../../index.js'
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
|
|
4
|
+
describe('cloudevent.origin#originactor', () => {
|
|
5
|
+
let ce
|
|
6
|
+
let cloudevent
|
|
7
|
+
let params
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
// Cloudevent we are acting on
|
|
11
|
+
ce = new Cloudevent({
|
|
12
|
+
source: 'some-source',
|
|
13
|
+
type: 'some-type',
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
// Cloudevent we are treating as the origin
|
|
17
|
+
cloudevent = new Cloudevent({
|
|
18
|
+
source: 'source-of-origin-cloudevent',
|
|
19
|
+
type: 'type-of-origin-cloudevent',
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
params = {
|
|
23
|
+
cloudevent,
|
|
24
|
+
originid: 'some-origin-id',
|
|
25
|
+
originsource: 'some-origin-source',
|
|
26
|
+
origintime: 'some-origin-time',
|
|
27
|
+
origintype: 'some-origin-type',
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
describe('when #originactor is not input', () => {
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
params.originactor = undefined
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
describe('when #cloudevent is not input', () => {
|
|
38
|
+
it('returns undefined', () => {
|
|
39
|
+
params.cloudevent = undefined
|
|
40
|
+
ce.origin(params)
|
|
41
|
+
expect(ce.originactor).to.be.undefined
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
describe('when #cloudevent is input', () => {
|
|
46
|
+
describe('when #cloudevent#originactor does not exist', () => {
|
|
47
|
+
it('returns undefined', () => {
|
|
48
|
+
cloudevent.originactor = undefined
|
|
49
|
+
ce.origin({ cloudevent })
|
|
50
|
+
expect(ce.originactor).to.be.undefined
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
describe('when #cloudevent#originactor does exist', () => {
|
|
55
|
+
it('returns #cloudevent#originactor', () => {
|
|
56
|
+
const expected = 'some-originactor'
|
|
57
|
+
|
|
58
|
+
cloudevent.originactor = expected
|
|
59
|
+
ce.origin({ cloudevent })
|
|
60
|
+
|
|
61
|
+
expect(ce.originactor).to.eq(expected)
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
describe('when #originactor is input', () => {
|
|
68
|
+
it('returns the input value', () => {
|
|
69
|
+
const expected = 'some-originactor'
|
|
70
|
+
ce.origin({ cloudevent, originactor: expected })
|
|
71
|
+
expect(ce.originactor).to.eq(expected)
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
})
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Cloudevent } from '../../../index.js'
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
|
|
4
|
+
describe('cloudevent.originator#originatorid', () => {
|
|
5
|
+
let ce
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
ce = new Cloudevent({
|
|
9
|
+
source: 'some-source',
|
|
10
|
+
type: 'some-type',
|
|
11
|
+
})
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
describe('when #originatorid is not input', () => {
|
|
15
|
+
describe('when #cloudevent is not input', () => {
|
|
16
|
+
it('returns undefined', () => {
|
|
17
|
+
ce.originator({})
|
|
18
|
+
expect(ce.originatorid).to.be.undefined
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
describe('when #cloudevent is input', () => {
|
|
23
|
+
describe('when #cloudevent#originatorid does not exist', () => {
|
|
24
|
+
it('returns undefined', () => {
|
|
25
|
+
const cloudevent = {}
|
|
26
|
+
ce.originator({ cloudevent })
|
|
27
|
+
expect(ce.originatorid).to.be.undefined
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
describe('when #cloudevent#originatorid does exist', () => {
|
|
32
|
+
it('returns #cloudevent#originatorid', () => {
|
|
33
|
+
const expected = 'some-originator-id'
|
|
34
|
+
|
|
35
|
+
const cloudevent = { originatorid: expected }
|
|
36
|
+
ce.originator({ cloudevent })
|
|
37
|
+
|
|
38
|
+
expect(ce.originatorid).to.eq(expected)
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
describe('when #originatorid is input', () => {
|
|
45
|
+
it('returns the input value', () => {
|
|
46
|
+
const expected = 'some-originator-id'
|
|
47
|
+
ce.originator({ originatorid: expected })
|
|
48
|
+
expect(ce.originatorid).to.eq(expected)
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Cloudevent } from '../../../index.js'
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
|
|
4
|
+
describe('cloudevent.originator', () => {
|
|
5
|
+
it('returns itself', () => {
|
|
6
|
+
const ce = new Cloudevent({ source: 'some-source', type: 'some-type' })
|
|
7
|
+
const result = ce.originator({ originatorid: 'some-originator-id' })
|
|
8
|
+
expect(result).to.eq(ce)
|
|
9
|
+
})
|
|
10
|
+
})
|
|
@@ -4,10 +4,7 @@ import { expect } from 'chai'
|
|
|
4
4
|
describe('cloudevent.wschannel', () => {
|
|
5
5
|
it('returns itself', () => {
|
|
6
6
|
const ce = new Cloudevent({ source: 'some-source', type: 'some-type' })
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const result = ce.wschannel({ cloudevent: origin })
|
|
10
|
-
|
|
7
|
+
const result = ce.wschannel({ wschannelid: 'some-wschannel-id' })
|
|
11
8
|
expect(result).to.eq(ce)
|
|
12
9
|
})
|
|
13
10
|
})
|
package/src/unit.test.js
CHANGED
|
@@ -50,28 +50,31 @@ describe('new Cloudevent', () => {
|
|
|
50
50
|
clock.tick(987654321) // * Jump into the future
|
|
51
51
|
|
|
52
52
|
const origin = new Cloudevent({
|
|
53
|
-
|
|
53
|
+
originactor: 'some-originactor',
|
|
54
54
|
source: 'some-origin-source',
|
|
55
55
|
type: 'some-origin-type',
|
|
56
56
|
})
|
|
57
57
|
|
|
58
58
|
clock.tick(123456789) // * Jump into the future
|
|
59
59
|
|
|
60
|
+
const data = JSON.stringify({ some: 'data' })
|
|
60
61
|
const source = 'some-enrichment-source'
|
|
61
62
|
const time = new Date().toISOString()
|
|
62
63
|
const type = 'some-enrichment-type'
|
|
63
64
|
const wschannelid = 'some-wschannel-id'
|
|
64
65
|
|
|
65
|
-
const cloudevent = new Cloudevent({ source, type })
|
|
66
|
+
const cloudevent = new Cloudevent({ data, source, type })
|
|
66
67
|
.origin({ cloudevent: origin })
|
|
67
68
|
.wschannel({ wschannelid })
|
|
68
69
|
|
|
70
|
+
|
|
69
71
|
clock.tick(987654321) // * Jump into the future
|
|
70
72
|
|
|
71
73
|
expect(cloudevent).to.containSubset({
|
|
72
|
-
data
|
|
73
|
-
datacontenttype:
|
|
74
|
+
data,
|
|
75
|
+
datacontenttype: 'application/json',
|
|
74
76
|
dataschema: undefined,
|
|
77
|
+
originactor: origin.originactor,
|
|
75
78
|
originid: origin.id,
|
|
76
79
|
originsource: origin.source,
|
|
77
80
|
origintime: origin.time,
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
export const setAttribute = ({ cloudevent, name, types = [], value }) => {
|
|
1
|
+
export const setAttribute = ({ cloudevent, deprecated = false, name, types = [], value }) => {
|
|
2
|
+
if (deprecated) { console.warn(`Cloudevent "${name}" is depricated`) }
|
|
3
|
+
|
|
2
4
|
if (types.length > 0 && !types.includes(typeof value)) {
|
|
3
5
|
const message = `Cloudevent "${name}" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`
|
|
4
6
|
throw new Error(message)
|
|
5
7
|
}
|
|
8
|
+
|
|
6
9
|
cloudevent[name] = value
|
|
7
10
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import chai, { expect } from 'chai'
|
|
2
|
+
import sinon from 'sinon'
|
|
3
|
+
import sinonChai from 'sinon-chai'
|
|
1
4
|
import { setAttribute } from './index.js'
|
|
2
|
-
|
|
5
|
+
|
|
6
|
+
chai.use(sinonChai)
|
|
3
7
|
|
|
4
8
|
describe('setAttribute', () => {
|
|
5
9
|
const name = 'some-name'
|
|
@@ -7,6 +11,26 @@ describe('setAttribute', () => {
|
|
|
7
11
|
|
|
8
12
|
beforeEach(() => {
|
|
9
13
|
cloudevent = {}
|
|
14
|
+
sinon.spy(console, 'warn')
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
console.warn.restore()
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
describe('when #deprecated is true', () => {
|
|
22
|
+
it('calls console.warn with the proper warning', () => {
|
|
23
|
+
setAttribute({ cloudevent, deprecated: true, name })
|
|
24
|
+
const expected = `Cloudevent "${name}" is depricated`
|
|
25
|
+
expect(console.warn).to.have.been.calledWith(expected)
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
describe('when #deprecated is false', () => {
|
|
30
|
+
it ('does not call console.warn', () => {
|
|
31
|
+
setAttribute({ cloudevent, deprecated: false, name })
|
|
32
|
+
expect(console.warn).to.have.not.been.called
|
|
33
|
+
})
|
|
10
34
|
})
|
|
11
35
|
|
|
12
36
|
describe('when #types is empty', () => {
|