@1mill/cloudevents 4.5.0 → 4.6.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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog for @1mill/cloudevents
2
2
 
3
+ ## 4.6.1
4
+
5
+ * Fix spelling in `README.md`
6
+
7
+ ## 4.6.0
8
+
9
+ * Add `cloudevent.originactor` attribute and support in `cloudevent.origin({...})` instance method.
10
+ * Depricate `cloudevent.originator({...})` instance method.
11
+ * Depricate `cloudevent.originatorid` attribute.
12
+
3
13
  ## 4.5.0
4
14
 
5
15
  * Add `cloudevent.originator({...})` instance method.
package/README.md CHANGED
@@ -21,55 +21,57 @@ const { Cloudevent } = require('@1mill/cloudevents') // CommonJs
21
21
  import { Cloudevent } from '@1mill/cloudevents' // EMS
22
22
 
23
23
  const cloudevent = new Cloudevent({
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' })
24
+ data: JSON.stringify({ some: 'payload' }),
25
+ source: 'https://github.com/1mill/cloudevents',
26
+ type: 'cmd.do-this-command.v0',
27
+ originactor: 'user:admin#id=1234',
28
+ })
28
29
 
29
30
  console.log(cloudevent)
30
31
  // {
31
- // id: 'g-wea_sYvxmvsGeL3YCSM',
32
+ // id: 'v76ZvDVhbcCwD5M_NQ1FS',
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-21T04:27:10.729Z',
36
+ // time: '2022-09-22T01:44:31.717Z',
36
37
  // data: '{"some":"payload"}',
37
38
  // datacontenttype: 'application/json',
38
39
  // dataschema: undefined,
39
40
  // subject: undefined,
40
- // originid: 'g-wea_sYvxmvsGeL3YCSM',
41
+ // originactor: 'user:admin#id=1234',
42
+ // originid: 'v76ZvDVhbcCwD5M_NQ1FS',
41
43
  // originsource: 'https://github.com/1mill/cloudevents',
42
- // origintime: '2022-09-21T04:27:10.729Z',
44
+ // origintime: '2022-09-22T01:44:31.717Z',
43
45
  // origintype: 'cmd.do-this-command.v0',
44
- // originatorid: 'user.id.1234',
46
+ // originatorid: undefined,
45
47
  // wschannelid: undefined
46
48
  // }
47
49
 
48
50
  const enrichedCloudevent = new Cloudevent({
49
- data: JSON.stringify({ new: 'payload', value: true }),
50
- source: 'https://www.erikekberg.com/',
51
- type: 'fct.this-thing-happened.v0',
51
+ data: JSON.stringify({ new: 'payload', value: true }),
52
+ source: 'https://www.erikekberg.com/',
53
+ type: 'fct.this-thing-happened.v0',
52
54
  })
53
55
  .origin({ cloudevent })
54
- .originator({ cloudevent })
55
56
  .wschannel({ wschannelid: 'some-prefix:my-resource-name#id=12345' })
56
57
 
57
58
  console.log(enrichedCloudevent)
58
59
  // {
59
- // id: 'zojPIW1eMm_JsvQI5VnfR',
60
+ // id: '-RIl1_Dr_uNh6Q4Oa3Ifq',
60
61
  // source: 'https://www.erikekberg.com/',
61
62
  // type: 'fct.this-thing-happened.v0',
62
63
  // specversion: '1.0',
63
- // time: '2022-09-21T04:27:10.740Z',
64
+ // time: '2022-09-22T01:44:31.747Z',
64
65
  // data: '{"new":"payload","value":true}',
65
66
  // datacontenttype: 'application/json',
66
67
  // dataschema: undefined,
67
68
  // subject: undefined,
68
- // originid: 'g-wea_sYvxmvsGeL3YCSM',
69
+ // originactor: 'user:admin#id=1234',
70
+ // originid: 'v76ZvDVhbcCwD5M_NQ1FS',
69
71
  // originsource: 'https://github.com/1mill/cloudevents',
70
- // origintime: '2022-09-21T04:27:10.729Z',
72
+ // origintime: '2022-09-22T01:44:31.717Z',
71
73
  // origintype: 'cmd.do-this-command.v0',
72
- // originatorid: 'user.id.1234',
74
+ // originatorid: undefined,
73
75
  // wschannelid: 'some-prefix:my-resource-name#id=12345'
74
76
  // }
75
77
  ```
@@ -83,11 +85,12 @@ console.log(enrichedCloudevent)
83
85
  | specversion | | String | 1.0 | Cloudevent specification version |
84
86
  | subject | | String | | |
85
87
  | type | yes | String | | |
88
+ | originactor | | String | | |
86
89
  | originid | | String | "id" property | "id" property is internally generated as part of the package |
87
90
  | originsource | | String | "source" property | |
88
91
  | origintime | | String | "time" property | "time" property is internally generated as part of the package |
89
92
  | origintype | | String | "type" property | |
90
- | originatorid | | String | | |
93
+ | originatorid | | String | | Deprecated in favor of "originactor" |
91
94
  | wschannelid | | String | | |
92
95
 
93
96
  ### origin
@@ -100,6 +103,7 @@ const cloudevent = new Cloudevent({
100
103
  type: 'my-type',
101
104
  })
102
105
  .origin({
106
+ originactor: 'my-origin-actor',
103
107
  originid: 'my-origin-id',
104
108
  originsource: 'my-origin-source',
105
109
  origintime: 'my-origin-time',
@@ -112,7 +116,8 @@ or populate them automatically by passing in an existing Cloudevent
112
116
  ```node
113
117
  const originCloudevent = new Cloudevent({
114
118
  source: 'my-origin-cloudevent',
115
- type: 'cmd.say-hello.v0'
119
+ type: 'cmd.say-hello.v0',
120
+ originactor: 'my-origin-actor',
116
121
  })
117
122
 
118
123
  const cloudevent = new Cloudevent({
@@ -122,34 +127,6 @@ const cloudevent = new Cloudevent({
122
127
  }).origin({ cloudevent: originCloudevent })
123
128
  ```
124
129
 
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
-
153
130
  ### wschannel
154
131
 
155
132
  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,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})};
1
+ var e=require("nanoid"),n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},i=function(e){var n=e.cloudevent,i=e.deprecated,t=e.name,o=e.types,r=void 0===o?[]:o,a=e.value;if(void 0!==i&&i&&console.warn('Cloudevent "'+t+'" is depricated'),r.length>0&&!r.includes(typeof a)){var d='Cloudevent "'+t+'" must be of type '+r.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(d)}n[t]=a};exports.Cloudevent=function(t){var o=this,r=t.data,a=t.datacontenttype,d=t.dataschema,u=t.originactor,s=t.originatorid,c=t.originid,v=t.originsource,l=t.origintime,g=t.origintype,p=t.source,y=t.specversion,m=t.subject,f=t.type,h=t.wschannelid;this.origin=function(e){var n=e.cloudevent,t=void 0===n?{}:n,r=e.originid,a=e.originsource,d=e.origintime,u=e.origintype,s=o;return i({cloudevent:s,name:"originactor",types:["string","undefined"],value:e.originactor||t.originactor}),i({cloudevent:s,name:"originid",types:["string"],value:r||t.originid||t.id}),i({cloudevent:s,name:"originsource",types:["string"],value:a||t.originsource||t.source}),i({cloudevent:s,name:"origintime",types:["string"],value:d||t.origintime||t.time}),i({cloudevent:s,name:"origintype",types:["string"],value:u||t.origintype||t.type}),s},this.originator=function(e){var n=e.cloudevent,t=o;return i({cloudevent:t,name:"originatorid",types:["string","undefined"],value:e.originatorid||(void 0===n?{}:n).originatorid}),t},this.wschannel=function(e){var n=e.cloudevent,t=o;return i({cloudevent:t,name:"wschannelid",types:["string","undefined"],value:e.wschannelid||(void 0===n?{}:n).wschannelid}),t};var w=this,C=e.nanoid(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));i({cloudevent:w,name:"id",types:["string"],value:C});var E=p||n("MILL_CLOUDEVENTS_SOURCE");i({cloudevent:w,name:"source",types:["string"],value:E}),i({cloudevent:w,name:"type",types:["string"],value:f}),i({cloudevent:w,name:"specversion",types:["string"],value:y||"1.0"});var L=(new Date).toISOString();i({cloudevent:w,name:"time",types:["string"],value:L}),i({cloudevent:w,name:"data",value:r}),i({cloudevent:w,name:"datacontenttype",types:["string","undefined"],value:void 0!==r?a||"application/json":a}),i({cloudevent:w,name:"dataschema",types:["string","undefined"],value:d}),i({cloudevent:w,name:"subject",types:["string","undefined"],value:m}),this.origin({cloudevent:w,originactor:u,originid:c,originsource:v,origintime:l,origintype:g}),this.originator({cloudevent:w,originatorid:s}),this.wschannel({cloudevent:w,wschannelid:h})};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -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\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,MAAAA,OAAwB,IAAAC,EAAhB,GAAgBA,EAAZC,EAAAA,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KkB,WAAW,CACfjC,WAAYgC,EACZb,aAAAA,IAGDJ,KAAKqB,UAAU,CACdpC,WAAYgC,EACZJ,YAAAA,GAGD"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, deprecated = false, name, types = [], value }) => {\r\n\tif (deprecated) { console.warn(`Cloudevent \"${name}\" is depricated`) }\r\n\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginactor,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst ce = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tthis.origin({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginactor,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tthis.originator({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginatorid,\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent: ce,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originactor, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originactorValue = originactor || cloudevent['originactor']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originactor',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originactorValue,\r\n\t\t})\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\toriginator = ({ cloudevent = {}, originatorid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid || cloudevent['originatorid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","_ref","cloudevent","deprecated","_ref$types","types","value","_ref$deprecated","console","warn","length","includes","message","map","s","toUpperCase","sort","join","data","datacontenttype","dataschema","originactor","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","this","origin","_ref2","_ref2$cloudevent","ce","_this","setAttribute","originator","_ref3","_ref3$cloudevent","wschannel","_ref4","_ref4$cloudevent","idValue","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"wBAAaA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ICH2B,SAAiEG,GAAA,MAA9DC,EAAAA,eAAYC,WAAoBN,EAA8BI,EAA9BJ,KAA8BO,EAAAH,EAAxBI,MAAAA,OAAQ,IAAAD,EAAA,KAAIE,EAAYL,EAAZK,MAGhF,QAHuD,IAAAC,MACrCC,QAAQC,KAAR,eAA4BZ,EAAwB,mBAElEQ,EAAMK,OAAS,IAAML,EAAMM,mBAAwB,CACtD,IAAMC,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kC,EACZf,YAAAA,EACAE,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDM,KAAKO,WAAW,CACfrC,WAAYkC,EACZd,aAAAA,IAGDU,KAAKU,UAAU,CACdxC,WAAYkC,EACZL,YAAAA,GAGD"}
@@ -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: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};
1
+ const e=(e,n)=>{if("undefined"!=typeof process)return process.env[e]||n},n=({cloudevent:e,deprecated:n=!1,name:t,types:i=[],value:o})=>{if(n&&console.warn(`Cloudevent "${t}" is depricated`),i.length>0&&!i.includes(typeof o)){const e=`Cloudevent "${t}" must be of type ${i.map(e=>e.toUpperCase()).sort().join(" or ")}.`;throw new Error(e)}e[t]=o};class t{constructor({data:t,datacontenttype:i,dataschema:o,originactor:r,originatorid:s,originid:a,originsource:d,origintime:c,origintype:u,source:l,specversion:g,subject:v,type:p,wschannelid:y}){this.origin=({cloudevent:e={},originactor:t,originid:i,originsource:o,origintime:r,origintype:s})=>{const a=this;return n({cloudevent:a,name:"originactor",types:["string","undefined"],value:t||e.originactor}),n({cloudevent:a,name:"originid",types:["string"],value:i||e.originid||e.id}),n({cloudevent:a,name:"originsource",types:["string"],value:o||e.originsource||e.source}),n({cloudevent:a,name:"origintime",types:["string"],value:r||e.origintime||e.time}),n({cloudevent:a,name:"origintype",types:["string"],value:s||e.origintype||e.type}),a},this.originator=({cloudevent:e={},originatorid:t})=>(n({cloudevent:this,name:"originatorid",types:["string","undefined"],value:t||e.originatorid}),this),this.wschannel=({cloudevent:e={},wschannelid:t})=>(n({cloudevent:this,name:"wschannelid",types:["string","undefined"],value:t||e.wschannelid}),this);const m=this,h=((e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((e,n)=>e+((n&=63)<36?n.toString(36):n<62?(n-26).toString(36).toUpperCase():n>62?"-":"_"),""))(e("MILL_CLOUDEVENTS_NANOID_LENGTH",21));n({cloudevent:m,name:"id",types:["string"],value:h});const f=l||e("MILL_CLOUDEVENTS_SOURCE");n({cloudevent:m,name:"source",types:["string"],value:f}),n({cloudevent:m,name:"type",types:["string"],value:p}),n({cloudevent:m,name:"specversion",types:["string"],value:g||"1.0"});const w=(new Date).toISOString();n({cloudevent:m,name:"time",types:["string"],value:w}),n({cloudevent:m,name:"data",value:t}),n({cloudevent:m,name:"datacontenttype",types:["string","undefined"],value:void 0!==t?i||"application/json":i}),n({cloudevent:m,name:"dataschema",types:["string","undefined"],value:o}),n({cloudevent:m,name:"subject",types:["string","undefined"],value:v}),this.origin({cloudevent:m,originactor:r,originid:a,originsource:d,origintime:c,origintype:u}),this.originator({cloudevent:m,originatorid:s}),this.wschannel({cloudevent:m,wschannelid:y})}}export{t as Cloudevent};
2
2
  //# sourceMappingURL=index.modern.js.map
@@ -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\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,KAStED,EAAa,CACZC,WAAY2B,EACZhC,KAAM,eACNM,MAAO,CAAC,UACRC,MALyBe,GAAgBjB,EAAU,cAAoBA,EAAU,SASlF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1C,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"}
1
+ {"version":3,"file":"index.modern.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js","../node_modules/nanoid/index.browser.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, deprecated = false, name, types = [], value }) => {\r\n\tif (deprecated) { console.warn(`Cloudevent \"${name}\" is depricated`) }\r\n\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginactor,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst ce = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tthis.origin({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginactor,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tthis.originator({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginatorid,\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent: ce,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originactor, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originactorValue = originactor || cloudevent['originactor']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originactor',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originactorValue,\r\n\t\t})\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\toriginator = ({ cloudevent = {}, originatorid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid || cloudevent['originatorid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nlet customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nlet nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","cloudevent","deprecated","types","value","console","warn","length","includes","message","map","s","toUpperCase","sort","join","Cloudevent","constructor","data","datacontenttype","dataschema","originactor","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","origin","ce","this","setAttribute","originator","wschannel","_ce","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","idValue","sourceValue","timeValue","Date","toISOString"],"mappings":"AAAO,MAAkBA,EAAG,CAACC,EAAMC,KAClC,GAAuB,oBAAnBC,QACJ,OAAOA,QAAQC,IAAIH,IAASC,KCFD,EAAGG,aAAYC,WAAAA,GAAa,EAAOL,OAAMM,MAAAA,EAAQ,GAAIC,YAGhF,GAFIF,GAAcG,QAAQC,KAAM,eAAcT,oBAE1CM,EAAMI,OAAS,IAAMJ,EAAMK,gBAAgBJ,GAAQ,CACtD,MAAaK,EAAI,eAAcZ,sBAAyBM,EAAMO,IAAIC,GAAKA,EAAEC,eAAeC,OAAOC,KAAK,WACpG,MAAM,UAAUL,EAChB,CAEDR,EAAWJ,GAAQO,CAAAA,ECJPW,MAAAA,EACZC,aAAYC,KACXA,EADWC,gBAEXA,EAFWC,WAGXA,EACAC,YAAAA,EACAC,aAAAA,EACAC,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,EATWC,OAUXA,EAVWC,YAWXA,EAX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P,IDPaE,CAAOlD,EAAa,iCAAkC,KACtEsC,EAAa,CACZjC,WAAY+B,EACZnC,KAAM,KACNM,MAAO,CAAC,UACRC,MAAO2C,IAGR,QAAoBrB,GAAU9B,EAAa,2BAC3CsC,EAAa,CACZjC,WAAY+B,EACZnC,KAAM,SACNM,MAAO,CAAC,UACRC,MAAO4C,IAIRd,EAAa,CACZjC,WAAY+B,EACZnC,KAAM,OACNM,MAAO,CAAC,UACRC,MALiByB,IASlBK,EAAa,CACZjC,WAAY+B,EACZnC,KAAM,cACNM,MAAO,CAAC,UACRC,MALwBuB,GAAe,QAQxC,MAAesB,GAAG,IAAAC,MAAWC,cAC7BjB,EAAa,CACZjC,WAAY+B,EACZnC,KAAM,OACNM,MAAO,CAAC,UACRC,MAAO6C,IAMRf,EAAa,CACZjC,WAAY+B,EACZnC,KAAM,OACNO,MAAOa,IAMRiB,EAAa,CACZjC,WAAY+B,EACZnC,KAAM,kBACNM,MAAO,CAAC,SAAU,aAClBC,WAP4C,IAATa,EACjCC,GAAmB,mBACnBA,IAQHgB,EAAa,CACZjC,WAAY+B,EACZnC,KAAM,aACNM,MAAO,CAAC,SAAU,aAClBC,MAAOe,IAGRe,EAAa,CACZjC,WAAY+B,EACZnC,KAAM,UACNM,MAAO,CAAC,SAAU,aAClBC,MAAOwB,IAMRK,KAAKF,OAAO,CACX9B,WAAY+B,EACZZ,YAAAA,EACAE,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDQ,KAAKE,WAAW,CACflC,WAAY+B,EACZX,aAAAA,IAGDY,KAAKG,UAAU,CACdnC,WAAY+B,EACZF,YAAAA,GAGD"}
@@ -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,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};
1
+ import{nanoid as e}from"nanoid";var n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},i=function(e){var n=e.cloudevent,i=e.deprecated,t=e.name,o=e.types,r=void 0===o?[]:o,a=e.value;if(void 0!==i&&i&&console.warn('Cloudevent "'+t+'" is depricated'),r.length>0&&!r.includes(typeof a)){var d='Cloudevent "'+t+'" must be of type '+r.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(d)}n[t]=a},t=function(t){var o=this,r=t.data,a=t.datacontenttype,d=t.dataschema,s=t.originactor,u=t.originatorid,c=t.originid,v=t.originsource,l=t.origintime,g=t.origintype,p=t.source,m=t.specversion,y=t.subject,f=t.type,h=t.wschannelid;this.origin=function(e){var n=e.cloudevent,t=void 0===n?{}:n,r=e.originid,a=e.originsource,d=e.origintime,s=e.origintype,u=o;return i({cloudevent:u,name:"originactor",types:["string","undefined"],value:e.originactor||t.originactor}),i({cloudevent:u,name:"originid",types:["string"],value:r||t.originid||t.id}),i({cloudevent:u,name:"originsource",types:["string"],value:a||t.originsource||t.source}),i({cloudevent:u,name:"origintime",types:["string"],value:d||t.origintime||t.time}),i({cloudevent:u,name:"origintype",types:["string"],value:s||t.origintype||t.type}),u},this.originator=function(e){var n=e.cloudevent,t=o;return i({cloudevent:t,name:"originatorid",types:["string","undefined"],value:e.originatorid||(void 0===n?{}:n).originatorid}),t},this.wschannel=function(e){var n=e.cloudevent,t=o;return i({cloudevent:t,name:"wschannelid",types:["string","undefined"],value:e.wschannelid||(void 0===n?{}:n).wschannelid}),t};var w=this,E=e(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));i({cloudevent:w,name:"id",types:["string"],value:E});var L=p||n("MILL_CLOUDEVENTS_SOURCE");i({cloudevent:w,name:"source",types:["string"],value:L}),i({cloudevent:w,name:"type",types:["string"],value:f}),i({cloudevent:w,name:"specversion",types:["string"],value:m||"1.0"});var C=(new Date).toISOString();i({cloudevent:w,name:"time",types:["string"],value:C}),i({cloudevent:w,name:"data",value:r}),i({cloudevent:w,name:"datacontenttype",types:["string","undefined"],value:void 0!==r?a||"application/json":a}),i({cloudevent:w,name:"dataschema",types:["string","undefined"],value:d}),i({cloudevent:w,name:"subject",types:["string","undefined"],value:y}),this.origin({cloudevent:w,originactor:s,originid:c,originsource:v,origintime:l,origintype:g}),this.originator({cloudevent:w,originatorid:u}),this.wschannel({cloudevent:w,wschannelid:h})};export{t as Cloudevent};
2
2
  //# sourceMappingURL=index.module.js.map
@@ -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\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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,IAAAU,EAAA,CAAA,EAAIV,GAOE,cAIjCI,CAAA,EArKA,MAAWjB,KAILwB,EAAUC,EAAO/C,EAAa,iCAAkC,KACtEK,EAAa,CACZC,WAAYiC,EACZtC,KAAM,KACNO,MAAO,CAAC,UACRE,MAAOoC,IAGR,IAAiBE,EAAGjB,GAAU/B,EAAa,2BAC3CK,EAAa,CACZC,WAAYiC,EACZtC,KAAM,SACNO,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"}
1
+ {"version":3,"file":"index.module.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, deprecated = false, name, types = [], value }) => {\r\n\tif (deprecated) { console.warn(`Cloudevent \"${name}\" is depricated`) }\r\n\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginactor,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst ce = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tthis.origin({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginactor,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tthis.originator({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginatorid,\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent: ce,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originactor, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originactorValue = originactor || cloudevent['originactor']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originactor',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originactorValue,\r\n\t\t})\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\toriginator = ({ cloudevent = {}, originatorid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid || cloudevent['originatorid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","_ref","cloudevent","deprecated","_ref$types","types","value","_ref$deprecated","console","warn","length","includes","message","map","s","toUpperCase","sort","join","data","datacontenttype","dataschema","originactor","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","this","origin","_ref2","_ref2$cloudevent","ce","_this","setAttribute","originator","_ref3","_ref3$cloudevent","wschannel","_ref4","_ref4$cloudevent","idValue","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"gCAAaA,IAAAA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ICH2B,SAAiEG,GAAA,MAA9DC,EAAAA,eAAYC,WAAoBN,EAA8BI,EAA9BJ,KAA8BO,EAAAH,EAAxBI,MAAAA,OAAQ,IAAAD,EAAA,KAAIE,EAAYL,EAAZK,MAGhF,QAHuD,IAAAC,MACrCC,QAAQC,KAAR,eAA4BZ,EAAwB,mBAElEQ,EAAMK,OAAS,IAAML,EAAMM,mBAAwB,CACtD,IAAMC,iBAAyBf,EAAlB,qBAA2CQ,EAAMQ,IAAI,SAAAC,GAAKA,OAAAA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,QAApG,IACA,MAAM,UAAUL,EAChB,CAEDV,EAAWL,GAAQS,CACnB,ICJA,SAAAL,cAeGiB,EAAAjB,EAdFiB,KACAC,EAAAA,EAAAA,gBACAC,EAYEnB,EAZFmB,WACAC,IAAAA,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):"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})}});
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).cloudevents={})}(this,function(e){var n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},i=function(e){var n=e.cloudevent,i=e.deprecated,t=e.name,o=e.types,r=void 0===o?[]:o,a=e.value;if(void 0!==i&&i&&console.warn('Cloudevent "'+t+'" is depricated'),r.length>0&&!r.includes(typeof a)){var d='Cloudevent "'+t+'" must be of type '+r.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(d)}n[t]=a};e.Cloudevent=function(e){var t=this,o=e.data,r=e.datacontenttype,a=e.dataschema,d=e.originactor,s=e.originatorid,u=e.originid,c=e.originsource,v=e.origintime,l=e.origintype,g=e.source,p=e.specversion,y=e.subject,f=e.type,m=e.wschannelid;this.origin=function(e){var n=e.cloudevent,o=void 0===n?{}:n,r=e.originid,a=e.originsource,d=e.origintime,s=e.origintype,u=t;return i({cloudevent:u,name:"originactor",types:["string","undefined"],value:e.originactor||o.originactor}),i({cloudevent:u,name:"originid",types:["string"],value:r||o.originid||o.id}),i({cloudevent:u,name:"originsource",types:["string"],value:a||o.originsource||o.source}),i({cloudevent:u,name:"origintime",types:["string"],value:d||o.origintime||o.time}),i({cloudevent:u,name:"origintype",types:["string"],value:s||o.origintype||o.type}),u},this.originator=function(e){var n=e.cloudevent,o=t;return i({cloudevent:o,name:"originatorid",types:["string","undefined"],value:e.originatorid||(void 0===n?{}:n).originatorid}),o},this.wschannel=function(e){var n=e.cloudevent,o=t;return i({cloudevent:o,name:"wschannelid",types:["string","undefined"],value:e.wschannelid||(void 0===n?{}:n).wschannelid}),o};var h=this,w=((e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((e,n)=>e+((n&=63)<36?n.toString(36):n<62?(n-26).toString(36).toUpperCase():n>62?"-":"_"),""))(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));i({cloudevent:h,name:"id",types:["string"],value:w});var C=g||n("MILL_CLOUDEVENTS_SOURCE");i({cloudevent:h,name:"source",types:["string"],value:C}),i({cloudevent:h,name:"type",types:["string"],value:f}),i({cloudevent:h,name:"specversion",types:["string"],value:p||"1.0"});var E=(new Date).toISOString();i({cloudevent:h,name:"time",types:["string"],value:E}),i({cloudevent:h,name:"data",value:o}),i({cloudevent:h,name:"datacontenttype",types:["string","undefined"],value:void 0!==o?r||"application/json":r}),i({cloudevent:h,name:"dataschema",types:["string","undefined"],value:a}),i({cloudevent:h,name:"subject",types:["string","undefined"],value:y}),this.origin({cloudevent:h,originactor:d,originid:u,originsource:c,origintime:v,origintype:l}),this.originator({cloudevent:h,originatorid:s}),this.wschannel({cloudevent:h,wschannelid:m})}});
2
2
  //# sourceMappingURL=index.umd.js.map
@@ -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\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,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eEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js","../node_modules/nanoid/index.browser.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, deprecated = false, name, types = [], value }) => {\r\n\tif (deprecated) { console.warn(`Cloudevent \"${name}\" is depricated`) }\r\n\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginactor,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst ce = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tthis.origin({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginactor,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tthis.originator({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginatorid,\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent: ce,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originactor, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originactorValue = originactor || cloudevent['originactor']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originactor',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originactorValue,\r\n\t\t})\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\toriginator = ({ cloudevent = {}, originatorid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid || cloudevent['originatorid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nlet customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nlet nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","_ref","cloudevent","deprecated","_ref$types","types","value","_ref$deprecated","console","warn","length","includes","message","map","s","toUpperCase","sort","join","data","datacontenttype","dataschema","originactor","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","this","origin","_ref2","_ref2$cloudevent","ce","_this","setAttribute","originator","_ref3","_ref3$cloudevent","wschannel","_ref4","_ref4$cloudevent","idValue","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"qOAAaA,IAAAA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ICH2B,SAAiEG,GAAA,MAA9DC,EAAAA,eAAYC,WAAoBN,EAA8BI,EAA9BJ,KAA8BO,EAAAH,EAAxBI,MAAAA,OAAQ,IAAAD,EAAA,KAAIE,EAAYL,EAAZK,MAGhF,QAHuD,IAAAC,MACrCC,QAAQC,KAAR,eAA4BZ,EAAwB,mBAElEQ,EAAMK,OAAS,IAAML,EAAMM,mBAAwB,CACtD,IAAMC,iBAAyBf,EAAlB,qBAA2CQ,EAAMQ,IAAI,SAAAC,GAAKA,OAAAA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,QAApG,IACA,MAAM,UAAUL,EAChB,CAEDV,EAAWL,GAAQS,CACnB,eCJA,SAAAL,cAeGiB,EAAAjB,EAdFiB,KACAC,EAAAA,EAAAA,gBACAC,EAYEnB,EAZFmB,WACAC,IAAAA,YACAC,EAAAA,EAAAA,aACAC,EASEtB,EATFsB,SACAC,EAAAA,EAAAA,aACAC,EAOExB,EAPFwB,WACAC,IAAAA,WACAC,EAAAA,EAAAA,OACAC,EAIE3B,EAJF2B,YACAC,IAAAA,QACAC,EAEE7B,EAFF6B,KACAC,IAAAA,YACEC,KAyGHC,OAAS,SAAAC,WAAGhC,WAAAA,OAAa,IAAAiC,EAAA,CAAsE,IAArDZ,EAAAA,EAAAA,SAAUC,EAA2CU,EAA3CV,aAAcC,IAAAA,WAAYC,EAAAA,EAAAA,WACvEU,EAAKC,EA0CX,OAvCAC,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,cACNQ,MAAO,CAAC,SAAU,aAClBC,MAR6F4B,EAAlEb,aAG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0C,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,SACNQ,MAAO,CAAC,UACRC,MAAOiD,IAIRjB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,OACNQ,MAAO,CAAC,UACRC,MALiBwB,IASlBQ,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,cACNQ,MAAO,CAAC,UACRC,MALwBsB,GAAe,QAQxC,IAAM4B,GAAY,IAAIC,MAAOC,cAC7BpB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,OACNQ,MAAO,CAAC,UACRC,MAAOkD,IAMRlB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,OACNS,MAAOY,IAMRoB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,kBACNQ,MAAO,CAAC,SAAU,aAClBC,WAP4C,IAATY,EACjCC,GAAmB,mBACnBA,IAQHmB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,aACNQ,MAAO,CAAC,SAAU,aAClBC,MAAOc,IAGRkB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,UACNQ,MAAO,CAAC,SAAU,aAClBC,MAAOuB,IAMRG,KAAKC,OAAO,CACX/B,WAAYkC,EACZf,YAAAA,EACAE,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDM,KAAKO,WAAW,CACfrC,WAAYkC,EACZd,aAAAA,IAGDU,KAAKU,UAAU,CACdxC,WAAYkC,EACZL,YAAAA,GAGD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1mill/cloudevents",
3
- "version": "4.5.0",
3
+ "version": "4.6.1",
4
4
  "description": "Node cloudevents specification and helper",
5
5
  "jsnext:main": "dist/index.module.js",
6
6
  "main": "dist/index.cjs",
@@ -31,7 +31,8 @@
31
31
  "url": "https://github.com/1mill/cloudevents.git"
32
32
  },
33
33
  "dependencies": {
34
- "nanoid": "^3.3.4"
34
+ "nanoid": "^3.3.4",
35
+ "sinon-chai": "^3.7.0"
35
36
  },
36
37
  "devDependencies": {
37
38
  "chai": "^4.3.6",
package/src/index.js CHANGED
@@ -7,6 +7,7 @@ export class Cloudevent {
7
7
  data,
8
8
  datacontenttype,
9
9
  dataschema,
10
+ originactor,
10
11
  originatorid,
11
12
  originid,
12
13
  originsource,
@@ -100,6 +101,7 @@ export class Cloudevent {
100
101
  // * Required in-house extentions
101
102
  this.origin({
102
103
  cloudevent: ce,
104
+ originactor,
103
105
  originid,
104
106
  originsource,
105
107
  origintime,
@@ -121,9 +123,17 @@ export class Cloudevent {
121
123
  // *******
122
124
  }
123
125
 
124
- origin = ({ cloudevent = {}, originid, originsource, origintime, origintype }) => {
126
+ origin = ({ cloudevent = {}, originactor, originid, originsource, origintime, origintype }) => {
125
127
  const ce = this
126
128
 
129
+ const originactorValue = originactor || cloudevent['originactor']
130
+ setAttribute({
131
+ cloudevent: ce,
132
+ name: 'originactor',
133
+ types: ['string', 'undefined'],
134
+ value: originactorValue,
135
+ })
136
+
127
137
  const originidValue = originid || cloudevent['originid'] || cloudevent['id']
128
138
  setAttribute({
129
139
  cloudevent: ce,
@@ -0,0 +1,39 @@
1
+ import { Cloudevent } from '../../index.js'
2
+ import { expect } from 'chai'
3
+
4
+ describe('cloudevent#originactor', () => {
5
+ let params
6
+
7
+ beforeEach(() => {
8
+ params = {
9
+ // * Required base defaults
10
+ source: 'some-source',
11
+ type: 'some-type',
12
+ }
13
+ })
14
+
15
+ describe('when #originactor is not input', () => {
16
+ it('returns undefined', () => {
17
+ const { originactor } = new Cloudevent(params)
18
+ expect(originactor).to.be.undefined
19
+ })
20
+ })
21
+
22
+ describe('when #originactor is input', () => {
23
+ describe('when the input value is invalid', () => {
24
+ it('throws the proper error', () => {
25
+ const expected = 'Cloudevent "originactor" must be of type STRING or UNDEFINED'
26
+ params.originactor = 1234
27
+ expect(() => new Cloudevent(params)).to.throw(expected)
28
+ })
29
+ })
30
+
31
+ describe('when the input value is valid', () => {
32
+ it('returns the input value', () => {
33
+ params.originactor = 'some-originactor'
34
+ const { originactor } = new Cloudevent(params)
35
+ expect(originactor).to.eq(params.originactor)
36
+ })
37
+ })
38
+ })
39
+ })
@@ -0,0 +1,74 @@
1
+ import { Cloudevent } from '../../../index.js'
2
+ import { expect } from 'chai'
3
+
4
+ describe('cloudevent.origin#originactor', () => {
5
+ let ce
6
+ let cloudevent
7
+ let params
8
+
9
+ beforeEach(() => {
10
+ // Cloudevent we are acting on
11
+ ce = new Cloudevent({
12
+ source: 'some-source',
13
+ type: 'some-type',
14
+ })
15
+
16
+ // Cloudevent we are treating as the origin
17
+ cloudevent = new Cloudevent({
18
+ source: 'source-of-origin-cloudevent',
19
+ type: 'type-of-origin-cloudevent',
20
+ })
21
+
22
+ params = {
23
+ cloudevent,
24
+ originid: 'some-origin-id',
25
+ originsource: 'some-origin-source',
26
+ origintime: 'some-origin-time',
27
+ origintype: 'some-origin-type',
28
+ }
29
+ })
30
+
31
+
32
+ describe('when #originactor is not input', () => {
33
+ beforeEach(() => {
34
+ params.originactor = undefined
35
+ })
36
+
37
+ describe('when #cloudevent is not input', () => {
38
+ it('returns undefined', () => {
39
+ params.cloudevent = undefined
40
+ ce.origin(params)
41
+ expect(ce.originactor).to.be.undefined
42
+ })
43
+ })
44
+
45
+ describe('when #cloudevent is input', () => {
46
+ describe('when #cloudevent#originactor does not exist', () => {
47
+ it('returns undefined', () => {
48
+ cloudevent.originactor = undefined
49
+ ce.origin({ cloudevent })
50
+ expect(ce.originactor).to.be.undefined
51
+ })
52
+ })
53
+
54
+ describe('when #cloudevent#originactor does exist', () => {
55
+ it('returns #cloudevent#originactor', () => {
56
+ const expected = 'some-originactor'
57
+
58
+ cloudevent.originactor = expected
59
+ ce.origin({ cloudevent })
60
+
61
+ expect(ce.originactor).to.eq(expected)
62
+ })
63
+ })
64
+ })
65
+ })
66
+
67
+ describe('when #originactor is input', () => {
68
+ it('returns the input value', () => {
69
+ const expected = 'some-originactor'
70
+ ce.origin({ cloudevent, originactor: expected })
71
+ expect(ce.originactor).to.eq(expected)
72
+ })
73
+ })
74
+ })
package/src/unit.test.js CHANGED
@@ -50,6 +50,7 @@ describe('new Cloudevent', () => {
50
50
  clock.tick(987654321) // * Jump into the future
51
51
 
52
52
  const origin = new Cloudevent({
53
+ originactor: 'some-originactor',
53
54
  source: 'some-origin-source',
54
55
  type: 'some-origin-type',
55
56
  })
@@ -57,7 +58,6 @@ describe('new Cloudevent', () => {
57
58
  clock.tick(123456789) // * Jump into the future
58
59
 
59
60
  const data = JSON.stringify({ some: 'data' })
60
- const originatorid = 'some-originator-id'
61
61
  const source = 'some-enrichment-source'
62
62
  const time = new Date().toISOString()
63
63
  const type = 'some-enrichment-type'
@@ -65,7 +65,6 @@ describe('new Cloudevent', () => {
65
65
 
66
66
  const cloudevent = new Cloudevent({ data, source, type })
67
67
  .origin({ cloudevent: origin })
68
- .originator({ originatorid })
69
68
  .wschannel({ wschannelid })
70
69
 
71
70
 
@@ -75,7 +74,7 @@ describe('new Cloudevent', () => {
75
74
  data,
76
75
  datacontenttype: 'application/json',
77
76
  dataschema: undefined,
78
- originatorid,
77
+ originactor: origin.originactor,
79
78
  originid: origin.id,
80
79
  originsource: origin.source,
81
80
  origintime: origin.time,
@@ -1,7 +1,10 @@
1
- export const setAttribute = ({ cloudevent, name, types = [], value }) => {
1
+ export const setAttribute = ({ cloudevent, deprecated = false, name, types = [], value }) => {
2
+ if (deprecated) { console.warn(`Cloudevent "${name}" is depricated`) }
3
+
2
4
  if (types.length > 0 && !types.includes(typeof value)) {
3
5
  const message = `Cloudevent "${name}" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`
4
6
  throw new Error(message)
5
7
  }
8
+
6
9
  cloudevent[name] = value
7
10
  }
@@ -1,5 +1,9 @@
1
+ import chai, { expect } from 'chai'
2
+ import sinon from 'sinon'
3
+ import sinonChai from 'sinon-chai'
1
4
  import { setAttribute } from './index.js'
2
- import { expect } from 'chai'
5
+
6
+ chai.use(sinonChai)
3
7
 
4
8
  describe('setAttribute', () => {
5
9
  const name = 'some-name'
@@ -7,6 +11,26 @@ describe('setAttribute', () => {
7
11
 
8
12
  beforeEach(() => {
9
13
  cloudevent = {}
14
+ sinon.spy(console, 'warn')
15
+ })
16
+
17
+ afterEach(() => {
18
+ console.warn.restore()
19
+ })
20
+
21
+ describe('when #deprecated is true', () => {
22
+ it('calls console.warn with the proper warning', () => {
23
+ setAttribute({ cloudevent, deprecated: true, name })
24
+ const expected = `Cloudevent "${name}" is depricated`
25
+ expect(console.warn).to.have.been.calledWith(expected)
26
+ })
27
+ })
28
+
29
+ describe('when #deprecated is false', () => {
30
+ it ('does not call console.warn', () => {
31
+ setAttribute({ cloudevent, deprecated: false, name })
32
+ expect(console.warn).to.have.not.been.called
33
+ })
10
34
  })
11
35
 
12
36
  describe('when #types is empty', () => {