@1mill/cloudevents 4.3.0 → 4.4.1
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 +14 -0
- package/README.md +55 -23
- 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 +28 -17
- package/src/tests/methods/wschannel/unit.test.js +13 -0
- package/src/tests/methods/wschannel/wschannelid.test.js +51 -0
- package/src/unit.test.js +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog for @1mill/cloudevents
|
|
2
2
|
|
|
3
|
+
## 4.4.1
|
|
4
|
+
|
|
5
|
+
* Use `const ce = this` in constructor to cosmetically match instance method declarations.
|
|
6
|
+
|
|
7
|
+
## 4.4.0
|
|
8
|
+
|
|
9
|
+
* Add `cloudevent.wschannel({...})` instance method
|
|
10
|
+
* Update `README.md`
|
|
11
|
+
|
|
12
|
+
## 4.3.0
|
|
13
|
+
|
|
14
|
+
* Add `cloudevent.origin({...})` instance method
|
|
15
|
+
* Update `README.md`
|
|
16
|
+
|
|
3
17
|
## 4.2.1
|
|
4
18
|
|
|
5
19
|
* Upgrade to `microbundle@^0.15.1`
|
package/README.md
CHANGED
|
@@ -26,20 +26,21 @@ const cloudevent = new Cloudevent({
|
|
|
26
26
|
type: 'cmd.do-this-command.v0',
|
|
27
27
|
originatorid: 'user.id.1234',
|
|
28
28
|
})
|
|
29
|
+
|
|
29
30
|
console.log(cloudevent)
|
|
30
31
|
// {
|
|
31
|
-
// id: '
|
|
32
|
+
// id: 'tEzBztYRlPAaGY3uWIVWI',
|
|
32
33
|
// source: 'https://github.com/1mill/cloudevents',
|
|
33
34
|
// type: 'cmd.do-this-command.v0',
|
|
34
35
|
// specversion: '1.0',
|
|
35
|
-
// time: '2022-09-
|
|
36
|
+
// time: '2022-09-21T03:58:36.995Z',
|
|
36
37
|
// data: '{"some":"payload"}',
|
|
37
38
|
// datacontenttype: 'application/json',
|
|
38
39
|
// dataschema: undefined,
|
|
39
40
|
// subject: undefined,
|
|
40
|
-
// originid: '
|
|
41
|
+
// originid: 'tEzBztYRlPAaGY3uWIVWI',
|
|
41
42
|
// originsource: 'https://github.com/1mill/cloudevents',
|
|
42
|
-
// origintime: '2022-09-
|
|
43
|
+
// origintime: '2022-09-21T03:58:36.995Z',
|
|
43
44
|
// origintype: 'cmd.do-this-command.v0',
|
|
44
45
|
// originatorid: 'user.id.1234',
|
|
45
46
|
// wschannelid: undefined
|
|
@@ -49,24 +50,27 @@ const enrichedCloudevent = new Cloudevent({
|
|
|
49
50
|
data: JSON.stringify({ new: 'payload', value: true }),
|
|
50
51
|
source: 'https://www.erikekberg.com/',
|
|
51
52
|
type: 'fct.this-thing-happened.v0',
|
|
52
|
-
})
|
|
53
|
+
})
|
|
54
|
+
.origin({ cloudevent })
|
|
55
|
+
.wschannel({ wschannelid: 'some-prefix:my-resource-name#id=12345' })
|
|
56
|
+
|
|
53
57
|
console.log(enrichedCloudevent)
|
|
54
58
|
// {
|
|
55
|
-
// id: '
|
|
59
|
+
// id: '4_7YyYMjm-YPE3f20B1Ow',
|
|
56
60
|
// source: 'https://www.erikekberg.com/',
|
|
57
61
|
// type: 'fct.this-thing-happened.v0',
|
|
58
62
|
// specversion: '1.0',
|
|
59
|
-
// time: '2022-09-
|
|
63
|
+
// time: '2022-09-21T03:58:37.005Z',
|
|
60
64
|
// data: '{"new":"payload","value":true}',
|
|
61
65
|
// datacontenttype: 'application/json',
|
|
62
66
|
// dataschema: undefined,
|
|
63
67
|
// subject: undefined,
|
|
64
|
-
// originid: '
|
|
68
|
+
// originid: 'tEzBztYRlPAaGY3uWIVWI',
|
|
65
69
|
// originsource: 'https://github.com/1mill/cloudevents',
|
|
66
|
-
// origintime: '2022-09-
|
|
70
|
+
// origintime: '2022-09-21T03:58:36.995Z',
|
|
67
71
|
// origintype: 'cmd.do-this-command.v0',
|
|
68
72
|
// originatorid: undefined,
|
|
69
|
-
// wschannelid:
|
|
73
|
+
// wschannelid: 'some-prefix:my-resource-name#id=12345'
|
|
70
74
|
// }
|
|
71
75
|
```
|
|
72
76
|
|
|
@@ -76,31 +80,58 @@ console.log(enrichedCloudevent)
|
|
|
76
80
|
| datacontenttype | | String | | If "data" is present, defaults to "application/json" unless specified otherwise |
|
|
77
81
|
| dataschema | | String | | |
|
|
78
82
|
| source | yes | String | process.env.MILL_CLOUDEVENTS_SOURCE | Recommended to use universal identifier (e.g. <https://my-domain.com/my/feature/path/123>)|
|
|
79
|
-
| specversion |
|
|
83
|
+
| specversion | | String | 1.0 | Cloudevent specification version |
|
|
80
84
|
| subject | | String | | |
|
|
81
85
|
| type | yes | String | | |
|
|
82
|
-
| originid |
|
|
83
|
-
| originsource |
|
|
84
|
-
| origintime |
|
|
85
|
-
| origintype |
|
|
86
|
+
| originid | | String | "id" property | "id" property is internally generated as part of the package |
|
|
87
|
+
| originsource | | String | "source" property | |
|
|
88
|
+
| origintime | | String | "time" property | "time" property is internally generated as part of the package |
|
|
89
|
+
| origintype | | String | "type" property | |
|
|
86
90
|
| originatorid | | String | | |
|
|
87
91
|
| wschannelid | | String | | |
|
|
88
92
|
|
|
89
93
|
### origin
|
|
90
94
|
|
|
91
|
-
Add origin attributes to a Cloudevent manually
|
|
95
|
+
Add `origin` attributes to a Cloudevent manually
|
|
96
|
+
|
|
97
|
+
```node
|
|
98
|
+
const cloudevent = new Cloudevent({
|
|
99
|
+
source: 'my-source',
|
|
100
|
+
type: 'my-type',
|
|
101
|
+
})
|
|
102
|
+
.origin({
|
|
103
|
+
originid: 'my-origin-id',
|
|
104
|
+
originsource: 'my-origin-source',
|
|
105
|
+
origintime: 'my-origin-time',
|
|
106
|
+
origintype: 'my-origin-type',
|
|
107
|
+
})
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
or populate them automatically by passing in an existing Cloudevent
|
|
111
|
+
|
|
112
|
+
```node
|
|
113
|
+
const originCloudevent = new Cloudevent({
|
|
114
|
+
source: 'my-origin-cloudevent',
|
|
115
|
+
type: 'cmd.say-hello.v0'
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
const cloudevent = new Cloudevent({
|
|
119
|
+
data: JSON.stringify({ message: 'Hello world!' }),
|
|
120
|
+
source: 'my-enrichment-service',
|
|
121
|
+
type: 'fct.said-hello.v0',
|
|
122
|
+
}).origin({ cloudevent: originCloudevent })
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### wschannel
|
|
126
|
+
|
|
127
|
+
Add `wschannel` attributes to a Cloudevent manually
|
|
92
128
|
|
|
93
129
|
```node
|
|
94
130
|
const cloudevent = new Cloudevent({
|
|
95
131
|
source: 'my-source',
|
|
96
132
|
type: 'my-type',
|
|
97
133
|
})
|
|
98
|
-
.
|
|
99
|
-
originid: 'my-origin-id',
|
|
100
|
-
originsource: 'my-origin-source',
|
|
101
|
-
origintime: 'my-origin-time',
|
|
102
|
-
origintype: 'my-origin-type',
|
|
103
|
-
})
|
|
134
|
+
.wschannel({ wschannelid: 'my-unique-channel-name })
|
|
104
135
|
```
|
|
105
136
|
|
|
106
137
|
or populate them automatically by passing in an existing Cloudevent
|
|
@@ -110,12 +141,13 @@ const originCloudevent = new Cloudevent({
|
|
|
110
141
|
source: 'my-origin-cloudevent',
|
|
111
142
|
type: 'cmd.say-hello.v0'
|
|
112
143
|
})
|
|
144
|
+
.wschannel({ wschannelid: 'my-unique-channel-name })
|
|
113
145
|
|
|
114
146
|
const cloudevent = new Cloudevent({
|
|
115
147
|
data: JSON.stringify({ message: 'Hello world!' }),
|
|
116
148
|
source: 'my-enrichment-service',
|
|
117
149
|
type: 'fct.said-hello.v0',
|
|
118
|
-
}).
|
|
150
|
+
}).wschannel({ cloudevent: originCloudevent })
|
|
119
151
|
```
|
|
120
152
|
|
|
121
153
|
## Release new version
|
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,s=t.dataschema,u=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,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.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.nanoid(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:m}),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:y}),this.origin({cloudevent:h,originid:d,originsource:v,origintime:c,origintype:l}),i({cloudevent:h,name:"originatorid",types:["string","undefined"],value:u}),this.wschannel({cloudevent:h,wschannelid:f})};
|
|
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
|
|
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\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"],"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","nanoid","sourceValue","timeValue","Date","toISOString"],"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,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,qBCDA,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,CAC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M,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"}
|
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:s,originid:r,originsource:a,origintime:u,origintype:c,source:d,specversion:l,subject:g,type:p,wschannelid:v}){this.origin=({cloudevent:e={},originid:t,originsource:i,origintime:o,origintype:s})=>{const r=this;return n({cloudevent:r,name:"originid",types:["string"],value:t||e.originid||e.id}),n({cloudevent:r,name:"originsource",types:["string"],value:i||e.originsource||e.source}),n({cloudevent:r,name:"origintime",types:["string"],value:o||e.origintime||e.time}),n({cloudevent:r,name:"origintype",types:["string"],value:s||e.origintype||e.type}),r},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=d||e("MILL_CLOUDEVENTS_SOURCE");n({cloudevent:y,name:"source",types:["string"],value:h}),n({cloudevent:y,name:"type",types:["string"],value:p}),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:r,originsource:a,origintime:u,origintype:c}),n({cloudevent:y,name:"originatorid",types:["string","undefined"],value:s}),this.wschannel({cloudevent:y,wschannelid:v})}}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
|
|
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\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","types","value","length","includes","message","map","s","toUpperCase","sort","join","Cloudevent","constructor","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","origin","ce","this","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,GCDPS,MAAAA,EACZC,aAAYC,KACXA,EADWC,gBAEXA,EAFWC,WAGXA,EAHWC,aAIXA,EACAC,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,EARWC,OASXA,EATWC,YAUXA,EAVWC,QAWXA,EAXWC,KAYXA,EACAC,YAAAA,SA2GDC,OAAS,EAAG1B,WAAAA,EAAa,CAAf,EAAmBiB,WAAUC,eAAcC,aAAYC,iBAChE,MAAQO,EAAGC,KAkCX,OA/BA7B,EAAa,CACZC,WAAY2B,EACZhC,KAAM,WACNM,MAAO,CAAC,UACRC,MALqBe,GAAYjB,EAAU,UAAgBA,EAAU,KAStED,EAAa,CACZC,WAAY2B,EACZhC,KAAM,eACNM,MAAO,CAAC,UACRC,MALyBgB,GAAgBlB,EAAU,cAAoBA,EAAU,SASlFD,EAAa,CACZC,WAAY2B,EACZhC,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBiB,GAAcnB,EAAU,YAAkBA,EAAU,OAS5ED,EAAa,CACZC,WAAY2B,EACZhC,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBkB,GAAcpB,EAAU,YAAkBA,EAAU,OAQrE2B,GA7ILC,KAgJHC,UAAY,EAAG7B,WAAAA,EAAa,CAAA,EAAIyB,kBAG/B1B,EAAa,CACZC,WAHU4B,KAIVjC,KAAM,c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M,eACNM,MAAO,CAAC,SAAU,aAClBC,MAAOc,IAGRY,KAAKC,UAAU,CACd7B,WAAY2B,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.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,
|
|
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,c=t.originsource,v=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.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:c,origintime:v,origintype:l}),i({cloudevent:h,name:"originatorid",types:["string","undefined"],value: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
|
|
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\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"],"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","nanoid","sourceValue","timeValue","Date","toISOString"],"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,ICDA,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,EAA7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,EACZnC,KAAM,OACNS,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"}
|
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},t=function(e){var n=e.cloudevent,t=e.name,i=e.types,o=void 0===i?[]:i,r=e.value;if(o.length>0&&!o.includes(typeof r)){var
|
|
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},t=function(e){var n=e.cloudevent,t=e.name,i=e.types,o=void 0===i?[]:i,r=e.value;if(o.length>0&&!o.includes(typeof r)){var s='Cloudevent "'+t+'" must be of type '+o.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(s)}n[t]=r};e.Cloudevent=function(e){var i=this,o=e.data,r=e.datacontenttype,s=e.dataschema,a=e.originatorid,u=e.originid,d=e.originsource,c=e.origintime,l=e.origintype,v=e.source,p=e.specversion,g=e.subject,y=e.type,f=e.wschannelid;this.origin=function(e){var n=e.cloudevent,o=void 0===n?{}:n,r=e.originsource,s=e.origintime,a=e.origintype,u=i;return t({cloudevent:u,name:"originid",types:["string"],value:e.originid||o.originid||o.id}),t({cloudevent:u,name:"originsource",types:["string"],value:r||o.originsource||o.source}),t({cloudevent:u,name:"origintime",types:["string"],value:s||o.origintime||o.time}),t({cloudevent:u,name:"origintype",types:["string"],value:a||o.origintype||o.type}),u},this.wschannel=function(e){var n=e.cloudevent,o=i;return t({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));t({cloudevent:m,name:"id",types:["string"],value:h});var w=v||n("MILL_CLOUDEVENTS_SOURCE");t({cloudevent:m,name:"source",types:["string"],value:w}),t({cloudevent:m,name:"type",types:["string"],value:y}),t({cloudevent:m,name:"specversion",types:["string"],value:p||"1.0"});var C=(new Date).toISOString();t({cloudevent:m,name:"time",types:["string"],value:C}),t({cloudevent:m,name:"data",value:o}),t({cloudevent:m,name:"datacontenttype",types:["string","undefined"],value:void 0!==o?r||"application/json":r}),t({cloudevent:m,name:"dataschema",types:["string","undefined"],value:s}),t({cloudevent:m,name:"subject",types:["string","undefined"],value:g}),this.origin({cloudevent:m,originid:u,originsource:d,origintime:c,origintype:l}),t({cloudevent:m,name:"originatorid",types:["string","undefined"],value:a}),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
|
|
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,aA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iBqB,IASlB1B,EAAa,CACZC,WAAY8B,EACZnC,KAAM,cACNO,MAAO,CAAC,UACRE,MALwBmB,GAAe,QAQxC,IAAMwB,GAAY,IAAIC,MAAOC,cAC7BlD,EAAa,CACZC,WAAY8B,EACZnC,KAAM,OACNO,MAAO,CAAC,UACRE,MAAO2C,IAMRhD,EAAa,CACZC,WAAY8B,EACZnC,KAAM,OACNS,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"}
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -18,13 +18,13 @@ export class Cloudevent {
|
|
|
18
18
|
type,
|
|
19
19
|
wschannelid,
|
|
20
20
|
}) {
|
|
21
|
-
const
|
|
21
|
+
const ce = this
|
|
22
22
|
|
|
23
23
|
// *******
|
|
24
24
|
// * Required fields by Cloudevent v1 specification
|
|
25
25
|
const idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))
|
|
26
26
|
setAttribute({
|
|
27
|
-
cloudevent,
|
|
27
|
+
cloudevent: ce,
|
|
28
28
|
name: 'id',
|
|
29
29
|
types: ['string'],
|
|
30
30
|
value: idValue
|
|
@@ -32,7 +32,7 @@ export class Cloudevent {
|
|
|
32
32
|
|
|
33
33
|
const sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')
|
|
34
34
|
setAttribute({
|
|
35
|
-
cloudevent,
|
|
35
|
+
cloudevent: ce,
|
|
36
36
|
name: 'source',
|
|
37
37
|
types: ['string'],
|
|
38
38
|
value: sourceValue
|
|
@@ -40,7 +40,7 @@ export class Cloudevent {
|
|
|
40
40
|
|
|
41
41
|
const typeValue = type
|
|
42
42
|
setAttribute({
|
|
43
|
-
cloudevent,
|
|
43
|
+
cloudevent: ce,
|
|
44
44
|
name: 'type',
|
|
45
45
|
types: ['string'],
|
|
46
46
|
value: typeValue
|
|
@@ -48,7 +48,7 @@ export class Cloudevent {
|
|
|
48
48
|
|
|
49
49
|
const specversionValue = specversion || '1.0'
|
|
50
50
|
setAttribute({
|
|
51
|
-
cloudevent,
|
|
51
|
+
cloudevent: ce,
|
|
52
52
|
name: 'specversion',
|
|
53
53
|
types: ['string'],
|
|
54
54
|
value: specversionValue
|
|
@@ -56,7 +56,7 @@ export class Cloudevent {
|
|
|
56
56
|
|
|
57
57
|
const timeValue = new Date().toISOString()
|
|
58
58
|
setAttribute({
|
|
59
|
-
cloudevent,
|
|
59
|
+
cloudevent: ce,
|
|
60
60
|
name: 'time',
|
|
61
61
|
types: ['string'],
|
|
62
62
|
value: timeValue
|
|
@@ -66,7 +66,7 @@ export class Cloudevent {
|
|
|
66
66
|
// *******
|
|
67
67
|
// * Optional fields by Cloudevent v1 specification
|
|
68
68
|
setAttribute({
|
|
69
|
-
cloudevent,
|
|
69
|
+
cloudevent: ce,
|
|
70
70
|
name: 'data',
|
|
71
71
|
value: data
|
|
72
72
|
})
|
|
@@ -75,21 +75,21 @@ export class Cloudevent {
|
|
|
75
75
|
? datacontenttype || 'application/json'
|
|
76
76
|
: datacontenttype
|
|
77
77
|
setAttribute({
|
|
78
|
-
cloudevent,
|
|
78
|
+
cloudevent: ce,
|
|
79
79
|
name: 'datacontenttype',
|
|
80
80
|
types: ['string', 'undefined'],
|
|
81
81
|
value: datacontenttypeValue
|
|
82
82
|
})
|
|
83
83
|
|
|
84
84
|
setAttribute({
|
|
85
|
-
cloudevent,
|
|
85
|
+
cloudevent: ce,
|
|
86
86
|
name: 'dataschema',
|
|
87
87
|
types: ['string', 'undefined'],
|
|
88
88
|
value: dataschema
|
|
89
89
|
})
|
|
90
90
|
|
|
91
91
|
setAttribute({
|
|
92
|
-
cloudevent,
|
|
92
|
+
cloudevent: ce,
|
|
93
93
|
name: 'subject',
|
|
94
94
|
types: ['string', 'undefined'],
|
|
95
95
|
value: subject
|
|
@@ -99,7 +99,7 @@ export class Cloudevent {
|
|
|
99
99
|
// *******
|
|
100
100
|
// * Required in-house extentions
|
|
101
101
|
this.origin({
|
|
102
|
-
cloudevent,
|
|
102
|
+
cloudevent: ce,
|
|
103
103
|
originid,
|
|
104
104
|
originsource,
|
|
105
105
|
origintime,
|
|
@@ -110,17 +110,15 @@ export class Cloudevent {
|
|
|
110
110
|
// *******
|
|
111
111
|
// * Optional in-house extentions
|
|
112
112
|
setAttribute({
|
|
113
|
-
cloudevent,
|
|
113
|
+
cloudevent: ce,
|
|
114
114
|
name: 'originatorid',
|
|
115
115
|
types: ['string', 'undefined'],
|
|
116
116
|
value: originatorid
|
|
117
117
|
})
|
|
118
118
|
|
|
119
|
-
|
|
120
|
-
cloudevent,
|
|
121
|
-
|
|
122
|
-
types: ['string', 'undefined'],
|
|
123
|
-
value: wschannelid
|
|
119
|
+
this.wschannel({
|
|
120
|
+
cloudevent: ce,
|
|
121
|
+
wschannelid,
|
|
124
122
|
})
|
|
125
123
|
// *******
|
|
126
124
|
}
|
|
@@ -162,4 +160,17 @@ export class Cloudevent {
|
|
|
162
160
|
|
|
163
161
|
return ce
|
|
164
162
|
}
|
|
163
|
+
|
|
164
|
+
wschannel = ({ cloudevent = {}, wschannelid }) => {
|
|
165
|
+
const ce = this
|
|
166
|
+
|
|
167
|
+
setAttribute({
|
|
168
|
+
cloudevent: ce,
|
|
169
|
+
name: 'wschannelid',
|
|
170
|
+
types: ['string', 'undefined'],
|
|
171
|
+
value: wschannelid || cloudevent['wschannelid'],
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
return ce
|
|
175
|
+
}
|
|
165
176
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Cloudevent } from '../../../index.js'
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
|
|
4
|
+
describe('cloudevent.wschannel', () => {
|
|
5
|
+
it('returns itself', () => {
|
|
6
|
+
const ce = new Cloudevent({ source: 'some-source', type: 'some-type' })
|
|
7
|
+
const origin = new Cloudevent({ source: 'source-of-origin', type: 'type-of-origin' })
|
|
8
|
+
|
|
9
|
+
const result = ce.wschannel({ cloudevent: origin })
|
|
10
|
+
|
|
11
|
+
expect(result).to.eq(ce)
|
|
12
|
+
})
|
|
13
|
+
})
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Cloudevent } from '../../../index.js'
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
|
|
4
|
+
describe('cloudevent.wschannel#wschannelid', () => {
|
|
5
|
+
let ce
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
ce = new Cloudevent({
|
|
9
|
+
source: 'some-source',
|
|
10
|
+
type: 'some-type',
|
|
11
|
+
})
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
describe('when #wschannelid is not input', () => {
|
|
15
|
+
describe('when #cloudevent is not input', () => {
|
|
16
|
+
it('returns undefined', () => {
|
|
17
|
+
ce.wschannel({})
|
|
18
|
+
expect(ce.wschannelid).to.be.undefined
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
describe('when #cloudevent is input', () => {
|
|
23
|
+
describe('when #cloudevent#wschannelid does not exist', () => {
|
|
24
|
+
it('returns undefined', () => {
|
|
25
|
+
const cloudevent = {}
|
|
26
|
+
ce.wschannel({ cloudevent })
|
|
27
|
+
expect(ce.wschannelid).to.be.undefined
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
describe('when #cloudevent#wschannelid does exist', () => {
|
|
32
|
+
it('returns #cloudevent#wschannelid', () => {
|
|
33
|
+
const expected = 'some-wschannel-id'
|
|
34
|
+
|
|
35
|
+
const cloudevent = { wschannelid: expected }
|
|
36
|
+
ce.wschannel({ cloudevent })
|
|
37
|
+
|
|
38
|
+
expect(ce.wschannelid).to.eq(expected)
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
describe('when #wschannelid is input', () => {
|
|
45
|
+
it('returns the input value', () => {
|
|
46
|
+
const expected = 'some-wschannel-id'
|
|
47
|
+
ce.wschannel({ wschannelid: expected })
|
|
48
|
+
expect(ce.wschannelid).to.eq(expected)
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
})
|
package/src/unit.test.js
CHANGED
|
@@ -60,8 +60,11 @@ describe('new Cloudevent', () => {
|
|
|
60
60
|
const source = 'some-enrichment-source'
|
|
61
61
|
const time = new Date().toISOString()
|
|
62
62
|
const type = 'some-enrichment-type'
|
|
63
|
+
const wschannelid = 'some-wschannel-id'
|
|
63
64
|
|
|
64
|
-
const cloudevent = new Cloudevent({ source, type })
|
|
65
|
+
const cloudevent = new Cloudevent({ source, type })
|
|
66
|
+
.origin({ cloudevent: origin })
|
|
67
|
+
.wschannel({ wschannelid })
|
|
65
68
|
|
|
66
69
|
clock.tick(987654321) // * Jump into the future
|
|
67
70
|
|
|
@@ -78,6 +81,7 @@ describe('new Cloudevent', () => {
|
|
|
78
81
|
subject: undefined,
|
|
79
82
|
time,
|
|
80
83
|
type,
|
|
84
|
+
wschannelid,
|
|
81
85
|
})
|
|
82
86
|
})
|
|
83
87
|
})
|