@1mill/cloudevents 4.4.1 → 4.5.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 +5 -0
- package/README.md +45 -17
- 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 +1 -1
- package/src/index.js +15 -4
- 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 +8 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog for @1mill/cloudevents
|
|
2
2
|
|
|
3
|
+
## 4.5.0
|
|
4
|
+
|
|
5
|
+
* Add `cloudevent.originator({...})` instance method.
|
|
6
|
+
* Improve unit tests for `cloudevent.wschannel({...})`.
|
|
7
|
+
|
|
3
8
|
## 4.4.1
|
|
4
9
|
|
|
5
10
|
* Use `const ce = this` in constructor to cosmetically match instance method declarations.
|
package/README.md
CHANGED
|
@@ -21,55 +21,55 @@ const { Cloudevent } = require('@1mill/cloudevents') // CommonJs
|
|
|
21
21
|
import { Cloudevent } from '@1mill/cloudevents' // EMS
|
|
22
22
|
|
|
23
23
|
const cloudevent = new Cloudevent({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})
|
|
24
|
+
data: JSON.stringify({ some: 'payload' }),
|
|
25
|
+
source: 'https://github.com/1mill/cloudevents',
|
|
26
|
+
type: 'cmd.do-this-command.v0',
|
|
27
|
+
}).originator({ originatorid: 'user.id.1234' })
|
|
29
28
|
|
|
30
29
|
console.log(cloudevent)
|
|
31
30
|
// {
|
|
32
|
-
// id: '
|
|
31
|
+
// id: 'g-wea_sYvxmvsGeL3YCSM',
|
|
33
32
|
// source: 'https://github.com/1mill/cloudevents',
|
|
34
33
|
// type: 'cmd.do-this-command.v0',
|
|
35
34
|
// specversion: '1.0',
|
|
36
|
-
// time: '2022-09-
|
|
35
|
+
// time: '2022-09-21T04:27:10.729Z',
|
|
37
36
|
// data: '{"some":"payload"}',
|
|
38
37
|
// datacontenttype: 'application/json',
|
|
39
38
|
// dataschema: undefined,
|
|
40
39
|
// subject: undefined,
|
|
41
|
-
// originid: '
|
|
40
|
+
// originid: 'g-wea_sYvxmvsGeL3YCSM',
|
|
42
41
|
// originsource: 'https://github.com/1mill/cloudevents',
|
|
43
|
-
// origintime: '2022-09-
|
|
42
|
+
// origintime: '2022-09-21T04:27:10.729Z',
|
|
44
43
|
// origintype: 'cmd.do-this-command.v0',
|
|
45
44
|
// originatorid: 'user.id.1234',
|
|
46
45
|
// wschannelid: undefined
|
|
47
46
|
// }
|
|
48
47
|
|
|
49
48
|
const enrichedCloudevent = new Cloudevent({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
data: JSON.stringify({ new: 'payload', value: true }),
|
|
50
|
+
source: 'https://www.erikekberg.com/',
|
|
51
|
+
type: 'fct.this-thing-happened.v0',
|
|
53
52
|
})
|
|
54
53
|
.origin({ cloudevent })
|
|
54
|
+
.originator({ cloudevent })
|
|
55
55
|
.wschannel({ wschannelid: 'some-prefix:my-resource-name#id=12345' })
|
|
56
56
|
|
|
57
57
|
console.log(enrichedCloudevent)
|
|
58
58
|
// {
|
|
59
|
-
// id: '
|
|
59
|
+
// id: 'zojPIW1eMm_JsvQI5VnfR',
|
|
60
60
|
// source: 'https://www.erikekberg.com/',
|
|
61
61
|
// type: 'fct.this-thing-happened.v0',
|
|
62
62
|
// specversion: '1.0',
|
|
63
|
-
// time: '2022-09-
|
|
63
|
+
// time: '2022-09-21T04:27:10.740Z',
|
|
64
64
|
// data: '{"new":"payload","value":true}',
|
|
65
65
|
// datacontenttype: 'application/json',
|
|
66
66
|
// dataschema: undefined,
|
|
67
67
|
// subject: undefined,
|
|
68
|
-
// originid: '
|
|
68
|
+
// originid: 'g-wea_sYvxmvsGeL3YCSM',
|
|
69
69
|
// originsource: 'https://github.com/1mill/cloudevents',
|
|
70
|
-
// origintime: '2022-09-
|
|
70
|
+
// origintime: '2022-09-21T04:27:10.729Z',
|
|
71
71
|
// origintype: 'cmd.do-this-command.v0',
|
|
72
|
-
// originatorid:
|
|
72
|
+
// originatorid: 'user.id.1234',
|
|
73
73
|
// wschannelid: 'some-prefix:my-resource-name#id=12345'
|
|
74
74
|
// }
|
|
75
75
|
```
|
|
@@ -122,6 +122,34 @@ const cloudevent = new Cloudevent({
|
|
|
122
122
|
}).origin({ cloudevent: originCloudevent })
|
|
123
123
|
```
|
|
124
124
|
|
|
125
|
+
### originator
|
|
126
|
+
|
|
127
|
+
Add `originator` attributes to a Cloudevent manually
|
|
128
|
+
|
|
129
|
+
```node
|
|
130
|
+
const cloudevent = new Cloudevent({
|
|
131
|
+
source: 'my-source',
|
|
132
|
+
type: 'my-type',
|
|
133
|
+
})
|
|
134
|
+
.originator({ originatorid: 'employee#id=12345' })
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
or populate them automatically by passing in an existing Cloudevent
|
|
138
|
+
|
|
139
|
+
```node
|
|
140
|
+
const originCloudevent = new Cloudevent({
|
|
141
|
+
source: 'my-origin-cloudevent',
|
|
142
|
+
type: 'cmd.say-hello.v0'
|
|
143
|
+
})
|
|
144
|
+
.originator({ originatorid: 'employee#id=12345' })
|
|
145
|
+
|
|
146
|
+
const cloudevent = new Cloudevent({
|
|
147
|
+
data: JSON.stringify({ message: 'Hello world!' }),
|
|
148
|
+
source: 'my-enrichment-service',
|
|
149
|
+
type: 'fct.said-hello.v0',
|
|
150
|
+
}).originator({ cloudevent: originCloudevent })
|
|
151
|
+
```
|
|
152
|
+
|
|
125
153
|
### wschannel
|
|
126
154
|
|
|
127
155
|
Add `wschannel` attributes to a Cloudevent manually
|
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.name,t=e.types,o=void 0===t?[]:t,r=e.value;if(o.length>0&&!o.includes(typeof r)){var a='Cloudevent "'+i+'" must be of type '+o.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(a)}n[i]=r};exports.Cloudevent=function(t){var o=this,r=t.data,a=t.datacontenttype,
|
|
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.name,t=e.types,o=void 0===t?[]:t,r=e.value;if(o.length>0&&!o.includes(typeof r)){var a='Cloudevent "'+i+'" must be of type '+o.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(a)}n[i]=r};exports.Cloudevent=function(t){var o=this,r=t.data,a=t.datacontenttype,u=t.dataschema,s=t.originatorid,d=t.originid,v=t.originsource,c=t.origintime,l=t.origintype,g=t.source,p=t.specversion,y=t.subject,m=t.type,h=t.wschannelid;this.origin=function(e){var n=e.cloudevent,t=void 0===n?{}:n,r=e.originsource,a=e.origintime,u=e.origintype,s=o;return i({cloudevent:s,name:"originid",types:["string"],value:e.originid||t.originid||t.id}),i({cloudevent:s,name:"originsource",types:["string"],value:r||t.originsource||t.source}),i({cloudevent:s,name:"origintime",types:["string"],value:a||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 f=this,w=e.nanoid(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));i({cloudevent:f,name:"id",types:["string"],value:w});var E=g||n("MILL_CLOUDEVENTS_SOURCE");i({cloudevent:f,name:"source",types:["string"],value:E}),i({cloudevent:f,name:"type",types:["string"],value:m}),i({cloudevent:f,name:"specversion",types:["string"],value:p||"1.0"});var L=(new Date).toISOString();i({cloudevent:f,name:"time",types:["string"],value:L}),i({cloudevent:f,name:"data",value:r}),i({cloudevent:f,name:"datacontenttype",types:["string","undefined"],value:void 0!==r?a||"application/json":a}),i({cloudevent:f,name:"dataschema",types:["string","undefined"],value:u}),i({cloudevent:f,name:"subject",types:["string","undefined"],value:y}),this.origin({cloudevent:f,originid:d,originsource:v,origintime:c,origintype:l}),this.originator({cloudevent:f,originatorid:s}),this.wschannel({cloudevent:f,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, 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\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 = {}, 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\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","setAttribute","cloudevent","_ref","types","_ref$types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","_this","this","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","origin","_ref2","_ref2$cloudevent","ce","originator","_ref3","_ref3$cloudevent","wschannel","_ref4","_ref4$cloudevent","idValue","nanoid","sourceValue","toISOString","timeValue"],"mappings":"wBAAaA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ECHwBG,EAAG,YAAGC,IAAAA,EAAAA,EAAAA,WAAYL,EAA8BM,EAA9BN,KAAMO,EAAAA,EAAAA,MAAA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C,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDR,KAAKkB,WAAW,CACfjC,WAAYgC,EACZb,aAAAA,IAGDJ,KAAKqB,UAAU,CACdpC,WAAYgC,EACZJ,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,name:n,types:t=[],value:i})=>{if(t.length>0&&!t.includes(typeof i)){const e=`Cloudevent "${n}" must be of type ${t.map(e=>e.toUpperCase()).sort().join(" or ")}.`;throw new Error(e)}e[n]=i};class t{constructor({data:t,datacontenttype:i,dataschema:o,originatorid:
|
|
1
|
+
const e=(e,n)=>{if("undefined"!=typeof process)return process.env[e]||n},n=({cloudevent:e,name:n,types:t=[],value:i})=>{if(t.length>0&&!t.includes(typeof i)){const e=`Cloudevent "${n}" must be of type ${t.map(e=>e.toUpperCase()).sort().join(" or ")}.`;throw new Error(e)}e[n]=i};class t{constructor({data:t,datacontenttype:i,dataschema:o,originatorid:r,originid:s,originsource:a,origintime:d,origintype:u,source:c,specversion:l,subject:g,type:v,wschannelid:p}){this.origin=({cloudevent:e={},originid:t,originsource:i,origintime:o,origintype:r})=>{const s=this;return n({cloudevent:s,name:"originid",types:["string"],value:t||e.originid||e.id}),n({cloudevent:s,name:"originsource",types:["string"],value:i||e.originsource||e.source}),n({cloudevent:s,name:"origintime",types:["string"],value:o||e.origintime||e.time}),n({cloudevent:s,name:"origintype",types:["string"],value:r||e.origintype||e.type}),s},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 y=this,m=((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:y,name:"id",types:["string"],value:m});const h=c||e("MILL_CLOUDEVENTS_SOURCE");n({cloudevent:y,name:"source",types:["string"],value:h}),n({cloudevent:y,name:"type",types:["string"],value:v}),n({cloudevent:y,name:"specversion",types:["string"],value:l||"1.0"});const f=(new Date).toISOString();n({cloudevent:y,name:"time",types:["string"],value:f}),n({cloudevent:y,name:"data",value:t}),n({cloudevent:y,name:"datacontenttype",types:["string","undefined"],value:void 0!==t?i||"application/json":i}),n({cloudevent:y,name:"dataschema",types:["string","undefined"],value:o}),n({cloudevent:y,name:"subject",types:["string","undefined"],value:g}),this.origin({cloudevent:y,originid:s,originsource:a,origintime:d,origintype:u}),this.originator({cloudevent:y,originatorid:r}),this.wschannel({cloudevent:y,wschannelid:p})}}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, 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\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 = {}, 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\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","setAttribute","cloudevent","types","value","length","includes","message","map","s","toUpperCase","sort","join","constructor","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","this","origin","ce","originator","wschannel","idValue","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"AAAO,MAAkBA,EAAG,CAACC,EAAMC,KAClC,GAAuB,oBAAnBC,QACJ,OAAOA,QAAQC,IAAIH,IAASC,GCFhBG,EAAe,EAAGC,aAAYL,OAAMM,MAAAA,EAAQ,GAAIC,YAC5D,GAAID,EAAME,OAAS,IAAMF,EAAMG,gBAANF,GAA8B,CACtD,MAAaG,EAAI,eAAcV,sBAAyBM,EAAMK,IAAIC,GAAKA,EAAEC,eAAeC,OAAOC,KAAK,WACpG,MAAM,UAAUL,EAChB,CACDL,EAAWL,GAAQO,GCDb,QACNS,aAAYC,KACXA,EADWC,gBAEXA,EAFWC,WAGXA,EACAC,aAAAA,EACAC,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,EARWC,OASXA,EATWC,YAUXA,EAVWC,QAWXA,EAXWC,KAYXA,EACAC,YAAAA,IACEC,KAwGHC,OAAS,EAAG1B,WAAAA,EAAa,CAAf,EAAmBgB,WAAUC,eAAcC,aAAYC,iBAChE,MAAQQ,EAAGF,KAkCX,OA/BA1B,EAAa,CACZC,WAAY2B,EACZhC,KAAM,WACNM,MAAO,CAAC,UACRC,MALqBc,GAAYhB,EAAU,UAAgBA,EAAU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AeoB,GAAG,IAAAC,MAAWC,cAC7B5C,EAAa,CACZC,WAAY2B,EACZhC,KAAM,OACNM,MAAO,CAAC,UACRC,MAAOuC,IAMR1C,EAAa,CACZC,WAAY2B,EACZhC,KAAM,OACNO,MAAOU,IAMRb,EAAa,CACZC,WAAY2B,EACZhC,KAAM,kBACNM,MAAO,CAAC,SAAU,aAClBC,WAP4C,IAAhBU,EAC1BC,GAAmB,mBACnBA,IAQHd,EAAa,CACZC,WAAY2B,EACZhC,KAAM,aACNM,MAAO,CAAC,SAAU,aAClBC,MAAOY,IAGRf,EAAa,CACZC,WAAY2B,EACZhC,KAAM,UACNM,MAAO,CAAC,SAAU,aAClBC,MAAOoB,IAMRG,KAAKC,OAAO,CACX1B,WAAY2B,EACZX,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDM,KAAKG,WAAW,CACf5B,WAAY2B,EACZZ,aAAAA,IAGDU,KAAKI,UAAU,CACd7B,WAAY2B,EACZH,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.name,t=e.types,o=void 0===t?[]:t,r=e.value;if(o.length>0&&!o.includes(typeof r)){var a='Cloudevent "'+i+'" must be of type '+o.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(a)}n[i]=r},t=function(t){var o=this,r=t.data,a=t.datacontenttype,s=t.dataschema,u=t.originatorid,d=t.originid,
|
|
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.name,t=e.types,o=void 0===t?[]:t,r=e.value;if(o.length>0&&!o.includes(typeof r)){var a='Cloudevent "'+i+'" must be of type '+o.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(a)}n[i]=r},t=function(t){var o=this,r=t.data,a=t.datacontenttype,s=t.dataschema,u=t.originatorid,d=t.originid,v=t.originsource,c=t.origintime,l=t.origintype,g=t.source,p=t.specversion,m=t.subject,y=t.type,f=t.wschannelid;this.origin=function(e){var n=e.cloudevent,t=void 0===n?{}:n,r=e.originsource,a=e.origintime,s=e.origintype,u=o;return i({cloudevent:u,name:"originid",types:["string"],value:e.originid||t.originid||t.id}),i({cloudevent:u,name:"originsource",types:["string"],value:r||t.originsource||t.source}),i({cloudevent:u,name:"origintime",types:["string"],value:a||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 h=this,w=e(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));i({cloudevent:h,name:"id",types:["string"],value:w});var E=g||n("MILL_CLOUDEVENTS_SOURCE");i({cloudevent:h,name:"source",types:["string"],value:E}),i({cloudevent:h,name:"type",types:["string"],value:y}),i({cloudevent:h,name:"specversion",types:["string"],value:p||"1.0"});var L=(new Date).toISOString();i({cloudevent:h,name:"time",types:["string"],value:L}),i({cloudevent:h,name:"data",value:r}),i({cloudevent:h,name:"datacontenttype",types:["string","undefined"],value:void 0!==r?a||"application/json":a}),i({cloudevent:h,name:"dataschema",types:["string","undefined"],value:s}),i({cloudevent:h,name:"subject",types:["string","undefined"],value:m}),this.origin({cloudevent:h,originid:d,originsource:v,origintime:c,origintype:l}),this.originator({cloudevent:h,originatorid:u}),this.wschannel({cloudevent:h,wschannelid:f})};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, 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\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 = {}, 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\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","setAttribute","cloudevent","_ref","types","_ref$types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","Cloudevent","_this","this","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","origin","_ref2","_ref2$cloudevent","ce","originator","_ref3","_ref3$cloudevent","wschannel","_ref4","_ref4$cloudevent","idValue","nanoid","sourceValue","toISOString","timeValue"],"mappings":"gCAAaA,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,ECFYU,EACZ,SAcGb,GAAA,IAAAc,EAAAC,KAAAC,EAAAhB,EAbFgB,KACAC,IAAAA,gBACAC,EAAAA,EAAAA,WACAC,IAAAA,aACAC,EAAAA,EAAAA,SACAC,EAQErB,EARFqB,aACAC,EAAAA,EAAAA,WACAC,IAAAA,WACAC,EAKExB,EALFwB,OACAC,IAAAA,YACAC,EAAAA,EAAAA,QACAC,IAAAA,KACAC,EAAAA,EAAAA,iBAyGDC,OAAS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O,MAAO,CAAC,UACRE,MAAOsC,IAIR3C,EAAa,CACZC,WAAYiC,EACZtC,KAAM,OACNO,MAAO,CAAC,UACRE,MALiBwB,IASlB7B,EAAa,CACZC,WAAYiC,EACZtC,KAAM,cACNO,MAAO,CAAC,UACRE,MALwBsB,GAAe,QAQxC,OAAkB,UAAWiB,cAC7B5C,EAAa,CACZC,WAAYiC,EACZtC,KAAM,OACNO,MAAO,CAAC,UACRE,MAAOwC,IAMR7C,EAAa,CACZC,WAAYiC,EACZtC,KAAM,OACNS,MAAOa,IAMRlB,EAAa,CACZC,WAAYiC,EACZtC,KAAM,kBACNO,MAAO,CAAC,SAAU,aAClBE,WAP4C,IAAhBa,EAC1BC,GAAmB,mBACnBA,IAQHnB,EAAa,CACZC,WAAYiC,EACZtC,KAAM,aACNO,MAAO,CAAC,SAAU,aAClBE,MAAOe,IAGRpB,EAAa,CACZC,WAAYiC,EACZtC,KAAM,UACNO,MAAO,CAAC,SAAU,aAClBE,MAAOuB,IAMRX,KAAKc,OAAO,CACX9B,WAAYiC,EACZZ,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDR,KAAKkB,WAAW,CACflC,WAAYiC,EACZb,aAAAA,IAGDJ,KAAKqB,UAAU,CACdrC,WAAYiC,EACZJ,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.name,t=e.types,o=void 0===t?[]:t,r=e.value;if(o.length>0&&!o.includes(typeof r)){var a='Cloudevent "'+i+'" must be of type '+o.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(a)}n[i]=r};e.Cloudevent=function(e){var t=this,o=e.data,r=e.datacontenttype,a=e.dataschema,s=e.originatorid,u=e.originid,d=e.originsource,c=e.origintime,v=e.origintype,l=e.source,g=e.specversion,p=e.subject,y=e.type,f=e.wschannelid;this.origin=function(e){var n=e.cloudevent,o=void 0===n?{}:n,r=e.originsource,a=e.origintime,s=e.origintype,u=t;return i({cloudevent:u,name:"originid",types:["string"],value:e.originid||o.originid||o.id}),i({cloudevent:u,name:"originsource",types:["string"],value:r||o.originsource||o.source}),i({cloudevent:u,name:"origintime",types:["string"],value:a||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 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?"-":"_"),""))(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));i({cloudevent:m,name:"id",types:["string"],value:h});var w=l||n("MILL_CLOUDEVENTS_SOURCE");i({cloudevent:m,name:"source",types:["string"],value:w}),i({cloudevent:m,name:"type",types:["string"],value:y}),i({cloudevent:m,name:"specversion",types:["string"],value:g||"1.0"});var C=(new Date).toISOString();i({cloudevent:m,name:"time",types:["string"],value:C}),i({cloudevent:m,name:"data",value:o}),i({cloudevent:m,name:"datacontenttype",types:["string","undefined"],value:void 0!==o?r||"application/json":r}),i({cloudevent:m,name:"dataschema",types:["string","undefined"],value:a}),i({cloudevent:m,name:"subject",types:["string","undefined"],value:p}),this.origin({cloudevent:m,originid:u,originsource:d,origintime:c,origintype:v}),this.originator({cloudevent:m,originatorid:s}),this.wschannel({cloudevent:m,wschannelid:f})}});
|
|
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\
|
|
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\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 = {}, 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\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","setAttribute","cloudevent","_ref","types","_ref$types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","_this","this","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","origin","_ref2","_ref2$cloudevent","ce","originator","_ref3","_ref3$cloudevent","wschannel","_ref4","_ref4$cloudevent","idValue","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","sourceValue","toISOString","timeValue"],"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,SAcGH,GAAA,IAAAa,EAAAC,KAAAC,EAAAf,EAbFe,KACAC,IAAAA,gBACAC,EAAAA,EAAAA,WACAC,IAAAA,aACAC,EAAAA,EAAAA,SACAC,EAQEpB,EARFoB,aACAC,EAAAA,EAAAA,WACAC,IAAAA,WACAC,EAKEvB,EALFuB,OACAC,IAAAA,YACAC,EAAAA,EAAAA,QACAC,IAAAA,KACAC,EAAAA,EAAAA,iBAyGDC,OAAS,SAAyEC,GAAA,IAAAC,EAAAD,EAAtE9B,WAAAA,aAAa,CAAA,EAAyD+B,EAA3CV,IAAAA,aAAcC,EAA6BQ,EAA7BR,WAAYC,EAAAA,EAAAA,WAC1DS,EAAKlB,EAkCX,OA/BAf,EAAa,CACZC,WAAYgC,EACZrC,KAAM,WACNO,MAAO,CAAC,UACRE,MAR2BgB,EAAAA,UAGMpB,EAAU,UAAgBA,EAAU,KAStED,EAAa,CACZC,WAAYgC,EACZrC,KAAM,eACNO,MAAO,CAAC,UACRE,MALyBiB,GAAgBrB,EA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AAO,CAAC,UACRE,MALwBqB,GAAe,QAQxC,OAAkB,UAAWyB,cAC7BnD,EAAa,CACZC,WAAYgC,EACZrC,KAAM,OACNO,MAAO,CAAC,UACRE,MAAO+C,IAMRpD,EAAa,CACZC,WAAYgC,EACZrC,KAAM,OACNS,MAAOY,IAMRjB,EAAa,CACZC,WAAYgC,EACZrC,KAAM,kBACNO,MAAO,CAAC,SAAU,aAClBE,WAP4C,IAAhBY,EAC1BC,GAAmB,mBACnBA,IAQHlB,EAAa,CACZC,WAAYgC,EACZrC,KAAM,aACNO,MAAO,CAAC,SAAU,aAClBE,MAAOc,IAGRnB,EAAa,CACZC,WAAYgC,EACZrC,KAAM,UACNO,MAAO,CAAC,SAAU,aAClBE,MAAOsB,IAMRX,KAAKc,OAAO,CACX7B,WAAYgC,EACZZ,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDR,KAAKkB,WAAW,CACfjC,WAAYgC,EACZb,aAAAA,IAGDJ,KAAKqB,UAAU,CACdpC,WAAYgC,EACZJ,YAAAA,GAGD"}
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -109,11 +109,9 @@ export class Cloudevent {
|
|
|
109
109
|
|
|
110
110
|
// *******
|
|
111
111
|
// * Optional in-house extentions
|
|
112
|
-
|
|
112
|
+
this.originator({
|
|
113
113
|
cloudevent: ce,
|
|
114
|
-
|
|
115
|
-
types: ['string', 'undefined'],
|
|
116
|
-
value: originatorid
|
|
114
|
+
originatorid,
|
|
117
115
|
})
|
|
118
116
|
|
|
119
117
|
this.wschannel({
|
|
@@ -161,6 +159,19 @@ export class Cloudevent {
|
|
|
161
159
|
return ce
|
|
162
160
|
}
|
|
163
161
|
|
|
162
|
+
originator = ({ cloudevent = {}, originatorid }) => {
|
|
163
|
+
const ce = this
|
|
164
|
+
|
|
165
|
+
setAttribute({
|
|
166
|
+
cloudevent: ce,
|
|
167
|
+
name: 'originatorid',
|
|
168
|
+
types: ['string', 'undefined'],
|
|
169
|
+
value: originatorid || cloudevent['originatorid'],
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
return ce
|
|
173
|
+
}
|
|
174
|
+
|
|
164
175
|
wschannel = ({ cloudevent = {}, wschannelid }) => {
|
|
165
176
|
const ce = this
|
|
166
177
|
|
|
@@ -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,32 @@ describe('new Cloudevent', () => {
|
|
|
50
50
|
clock.tick(987654321) // * Jump into the future
|
|
51
51
|
|
|
52
52
|
const origin = new Cloudevent({
|
|
53
|
-
data: JSON.stringify({ some: 'data' }),
|
|
54
53
|
source: 'some-origin-source',
|
|
55
54
|
type: 'some-origin-type',
|
|
56
55
|
})
|
|
57
56
|
|
|
58
57
|
clock.tick(123456789) // * Jump into the future
|
|
59
58
|
|
|
59
|
+
const data = JSON.stringify({ some: 'data' })
|
|
60
|
+
const originatorid = 'some-originator-id'
|
|
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 })
|
|
68
|
+
.originator({ originatorid })
|
|
67
69
|
.wschannel({ wschannelid })
|
|
68
70
|
|
|
71
|
+
|
|
69
72
|
clock.tick(987654321) // * Jump into the future
|
|
70
73
|
|
|
71
74
|
expect(cloudevent).to.containSubset({
|
|
72
|
-
data
|
|
73
|
-
datacontenttype:
|
|
75
|
+
data,
|
|
76
|
+
datacontenttype: 'application/json',
|
|
74
77
|
dataschema: undefined,
|
|
78
|
+
originatorid,
|
|
75
79
|
originid: origin.id,
|
|
76
80
|
originsource: origin.source,
|
|
77
81
|
origintime: origin.time,
|