@1mill/cloudevents 4.2.1 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +93 -28
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.modern.js +1 -1
  6. package/dist/index.modern.js.map +1 -1
  7. package/dist/index.module.js +1 -1
  8. package/dist/index.module.js.map +1 -1
  9. package/dist/index.umd.js +1 -1
  10. package/dist/index.umd.js.map +1 -1
  11. package/package.json +1 -1
  12. package/src/index.js +53 -23
  13. package/src/tests/{data.test.js → constructor/data.test.js} +1 -1
  14. package/src/tests/{datacontenttype.test.js → constructor/datacontenttype.test.js} +1 -1
  15. package/src/tests/{dataschema.test.js → constructor/dataschema.test.js} +1 -1
  16. package/src/tests/{id.test.js → constructor/id.test.js} +1 -1
  17. package/src/tests/{originatorid.test.js → constructor/originatorid.test.js} +1 -1
  18. package/src/tests/{originid.test.js → constructor/originid.test.js} +1 -1
  19. package/src/tests/{originsource.test.js → constructor/originsource.test.js} +1 -1
  20. package/src/tests/{origintime.test.js → constructor/origintime.test.js} +1 -1
  21. package/src/tests/{origintype.test.js → constructor/origintype.test.js} +1 -1
  22. package/src/tests/{source.test.js → constructor/source.test.js} +1 -1
  23. package/src/tests/{specversion.test.js → constructor/specversion.test.js} +1 -1
  24. package/src/tests/{subjest.test.js → constructor/subjest.test.js} +1 -1
  25. package/src/tests/{time.test.js → constructor/time.test.js} +1 -1
  26. package/src/tests/{type.test.js → constructor/type.test.js} +1 -1
  27. package/src/tests/{wschannelid.test.js → constructor/wschannelid.test.js} +1 -1
  28. package/src/tests/methods/origin/originid.test.js +85 -0
  29. package/src/tests/methods/origin/originsource.test.js +85 -0
  30. package/src/tests/methods/origin/origintime.test.js +85 -0
  31. package/src/tests/methods/origin/origintype.test.js +85 -0
  32. package/src/tests/methods/origin/unit.test.js +13 -0
  33. package/src/tests/methods/wschannel/unit.test.js +13 -0
  34. package/src/tests/methods/wschannel/wschannelid.test.js +51 -0
  35. package/src/unit.test.js +13 -17
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog for @1mill/cloudevents
2
2
 
3
+ ## 4.4.0
4
+
5
+ * Add `cloudevent.wschannel({...})` instance method
6
+ * Update `README.md`
7
+
8
+ ## 4.3.0
9
+
10
+ * Add `cloudevent.origin({...})` instance method
11
+ * Update `README.md`
12
+
3
13
  ## 4.2.1
4
14
 
5
15
  * Upgrade to `microbundle@^0.15.1`
package/README.md CHANGED
@@ -7,84 +7,149 @@ This is an implementation and extention of the [CloudEvents v1 specification](ht
7
7
  ## Install
8
8
 
9
9
  ```html
10
- <script src="https://unpkg.com/@1mill/cloudevents@4.1.1/dist/index.umd.js">
10
+ <script src="https://unpkg.com/@1mill/cloudevents@4/dist/index.umd.js">
11
11
  ```
12
12
 
13
13
  or
14
14
 
15
15
  ```bash
16
- npm install @1mill/cloudevents@^4
16
+ npm install @1mill/cloudevents
17
17
  ```
18
18
 
19
19
  ```node
20
20
  const { Cloudevent } = require('@1mill/cloudevents') // CommonJs
21
21
  import { Cloudevent } from '@1mill/cloudevents' // EMS
22
22
 
23
- const originCloudevent = new Cloudevent({
24
- data: JSON.stringify({ some: 'payload' }),
25
- source: 'https://github.com/1mill/cloudevents',
26
- type: 'cmd.do-this-command.v0',
27
- originatorid: 'user.id.1234',
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
+ originatorid: 'user.id.1234',
28
28
  })
29
- console.log(originCloudevent)
29
+
30
+ console.log(cloudevent)
30
31
  // {
31
- // id: 'f_2R8OyOtfYW4YPs2SOdv',
32
+ // id: 'tEzBztYRlPAaGY3uWIVWI',
32
33
  // source: 'https://github.com/1mill/cloudevents',
33
34
  // type: 'cmd.do-this-command.v0',
34
35
  // specversion: '1.0',
35
- // time: '2022-09-16T03:47:47.310Z',
36
+ // time: '2022-09-21T03:58:36.995Z',
36
37
  // data: '{"some":"payload"}',
37
38
  // datacontenttype: 'application/json',
38
39
  // dataschema: undefined,
39
40
  // subject: undefined,
40
- // origintime: '2022-09-16T03:47:47.310Z',
41
- // originid: 'f_2R8OyOtfYW4YPs2SOdv',
41
+ // originid: 'tEzBztYRlPAaGY3uWIVWI',
42
42
  // originsource: 'https://github.com/1mill/cloudevents',
43
+ // origintime: '2022-09-21T03:58:36.995Z',
43
44
  // origintype: 'cmd.do-this-command.v0',
44
- // originatorid: 'user.id.1234'
45
+ // originatorid: 'user.id.1234',
46
+ // wschannelid: undefined
45
47
  // }
46
48
 
47
49
  const enrichedCloudevent = new Cloudevent({
48
- ...originCloudevent,
49
- data: JSON.stringify({ new: 'payload', value: true }),
50
- source: 'https://www.erikekberg.com/',
51
- type: 'fct.this-thing-happened.v0',
50
+ data: JSON.stringify({ new: 'payload', value: true }),
51
+ source: 'https://www.erikekberg.com/',
52
+ type: 'fct.this-thing-happened.v0',
52
53
  })
54
+ .origin({ cloudevent })
55
+ .wschannel({ wschannelid: 'some-prefix:my-resource-name#id=12345' })
56
+
53
57
  console.log(enrichedCloudevent)
54
58
  // {
55
- // id: 'mux85XsamwvGkDFgeElQy',
59
+ // id: '4_7YyYMjm-YPE3f20B1Ow',
56
60
  // source: 'https://www.erikekberg.com/',
57
61
  // type: 'fct.this-thing-happened.v0',
58
62
  // specversion: '1.0',
59
- // time: '2022-09-16T03:47:47.320Z',
63
+ // time: '2022-09-21T03:58:37.005Z',
60
64
  // data: '{"new":"payload","value":true}',
61
65
  // datacontenttype: 'application/json',
62
66
  // dataschema: undefined,
63
67
  // subject: undefined,
64
- // origintime: '2022-09-16T03:47:47.310Z',
65
- // originid: 'f_2R8OyOtfYW4YPs2SOdv',
68
+ // originid: 'tEzBztYRlPAaGY3uWIVWI',
66
69
  // originsource: 'https://github.com/1mill/cloudevents',
70
+ // origintime: '2022-09-21T03:58:36.995Z',
67
71
  // origintype: 'cmd.do-this-command.v0',
68
- // originatorid: 'user.id.1234'
72
+ // originatorid: undefined,
73
+ // wschannelid: 'some-prefix:my-resource-name#id=12345'
69
74
  // }
70
75
  ```
71
76
 
72
- | | Required | Type | Default | Notes |
77
+ | Attribute | Required | Type | Default | Notes |
73
78
  |----------------- |---------- |-------- |------------------------------------- |------------------------------------------------------------------------------------------ |
74
79
  | data | | Any | | |
75
80
  | datacontenttype | | String | | If "data" is present, defaults to "application/json" unless specified otherwise |
76
81
  | dataschema | | String | | |
77
82
  | source | yes | String | process.env.MILL_CLOUDEVENTS_SOURCE | Recommended to use universal identifier (e.g. <https://my-domain.com/my/feature/path/123>)|
78
- | specversion | yes | String | 1.0 | Cloudevent specification version |
83
+ | specversion | | String | 1.0 | Cloudevent specification version |
79
84
  | subject | | String | | |
80
85
  | type | yes | String | | |
81
- | originid | yes | String | "id" property | "id" property is internally generated as part of the package |
82
- | originsource | yes | String | "source" property | |
83
- | origintime | yes | String | "time" property | "time" property is internally generated as part of the package |
84
- | origintype | yes | String | "type" property | |
86
+ | originid | | String | "id" property | "id" property is internally generated as part of the package |
87
+ | originsource | | String | "source" property | |
88
+ | origintime | | String | "time" property | "time" property is internally generated as part of the package |
89
+ | origintype | | String | "type" property | |
85
90
  | originatorid | | String | | |
86
91
  | wschannelid | | String | | |
87
92
 
93
+ ### origin
94
+
95
+ Add `origin` attributes to a Cloudevent manually
96
+
97
+ ```node
98
+ const cloudevent = new Cloudevent({
99
+ source: 'my-source',
100
+ type: 'my-type',
101
+ })
102
+ .origin({
103
+ originid: 'my-origin-id',
104
+ originsource: 'my-origin-source',
105
+ origintime: 'my-origin-time',
106
+ origintype: 'my-origin-type',
107
+ })
108
+ ```
109
+
110
+ or populate them automatically by passing in an existing Cloudevent
111
+
112
+ ```node
113
+ const originCloudevent = new Cloudevent({
114
+ source: 'my-origin-cloudevent',
115
+ type: 'cmd.say-hello.v0'
116
+ })
117
+
118
+ const cloudevent = new Cloudevent({
119
+ data: JSON.stringify({ message: 'Hello world!' }),
120
+ source: 'my-enrichment-service',
121
+ type: 'fct.said-hello.v0',
122
+ }).origin({ cloudevent: originCloudevent })
123
+ ```
124
+
125
+ ### wschannel
126
+
127
+ Add `wschannel` attributes to a Cloudevent manually
128
+
129
+ ```node
130
+ const cloudevent = new Cloudevent({
131
+ source: 'my-source',
132
+ type: 'my-type',
133
+ })
134
+ .wschannel({ wschannelid: 'my-unique-channel-name })
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
+ .wschannel({ wschannelid: 'my-unique-channel-name })
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
+ }).wschannel({ cloudevent: originCloudevent })
151
+ ```
152
+
88
153
  ## Release new version
89
154
 
90
155
  ```bash
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},t=function(e){var n=e.cloudevent,t=e.name,i=e.types,a=void 0===i?[]:i,o=e.value;if(a.length>0&&!a.includes(typeof o)){var r='Cloudevent "'+t+'" must be of type '+a.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(r)}n[t]=o};exports.Cloudevent=function(i){var a=i.data,o=i.datacontenttype,r=i.dataschema,u=i.originatorid,s=i.originid,d=i.originsource,v=i.origintime,l=i.origintype,c=i.source,p=i.specversion,g=i.subject,y=i.type,m=i.wschannelid,f=this,h=e.nanoid(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));t({cloudevent:f,name:"id",types:["string"],value:h});var E=c||n("MILL_CLOUDEVENTS_SOURCE");t({cloudevent:f,name:"source",types:["string"],value:E});var L=y;t({cloudevent:f,name:"type",types:["string"],value:L}),t({cloudevent:f,name:"specversion",types:["string"],value:p||"1.0"});var C=(new Date).toISOString();t({cloudevent:f,name:"time",types:["string"],value:C}),t({cloudevent:f,name:"data",value:a}),t({cloudevent:f,name:"datacontenttype",types:["string","undefined"],value:void 0!==a?o||"application/json":o}),t({cloudevent:f,name:"dataschema",types:["string","undefined"],value:r}),t({cloudevent:f,name:"subject",types:["string","undefined"],value:g}),t({cloudevent:f,name:"origintime",types:["string"],value:v||C}),t({cloudevent:f,name:"originid",types:["string"],value:s||h}),t({cloudevent:f,name:"originsource",types:["string"],value:d||E}),t({cloudevent:f,name:"origintype",types:["string"],value:l||L}),t({cloudevent:f,name:"originatorid",types:["string","undefined"],value:u}),t({cloudevent:f,name:"wschannelid",types:["string","undefined"],value:m})};
1
+ var e=require("nanoid"),n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},i=function(e){var n=e.cloudevent,i=e.name,t=e.types,o=void 0===t?[]:t,r=e.value;if(o.length>0&&!o.includes(typeof r)){var a='Cloudevent "'+i+'" must be of type '+o.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(a)}n[i]=r};exports.Cloudevent=function(t){var o=this,r=t.data,a=t.datacontenttype,s=t.dataschema,u=t.originatorid,d=t.originid,v=t.originsource,c=t.origintime,l=t.origintype,g=t.source,p=t.specversion,y=t.subject,m=t.type,f=t.wschannelid;this.origin=function(e){var n=e.cloudevent,t=void 0===n?{}:n,r=e.originsource,a=e.origintime,s=e.origintype,u=o;return i({cloudevent:u,name:"originid",types:["string"],value:e.originid||t.originid||t.id}),i({cloudevent:u,name:"originsource",types:["string"],value:r||t.originsource||t.source}),i({cloudevent:u,name:"origintime",types:["string"],value:a||t.origintime||t.time}),i({cloudevent:u,name:"origintype",types:["string"],value:s||t.origintype||t.type}),u},this.wschannel=function(e){var n=e.cloudevent,t=o;return i({cloudevent:t,name:"wschannelid",types:["string","undefined"],value:e.wschannelid||(void 0===n?{}:n).wschannelid}),t};var h=this,w=e.nanoid(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));i({cloudevent:h,name:"id",types:["string"],value:w});var E=g||n("MILL_CLOUDEVENTS_SOURCE");i({cloudevent:h,name:"source",types:["string"],value:E}),i({cloudevent:h,name:"type",types:["string"],value:m}),i({cloudevent:h,name:"specversion",types:["string"],value:p||"1.0"});var L=(new Date).toISOString();i({cloudevent:h,name:"time",types:["string"],value:L}),i({cloudevent:h,name:"data",value:r}),i({cloudevent:h,name:"datacontenttype",types:["string","undefined"],value:void 0!==r?a||"application/json":a}),i({cloudevent:h,name:"dataschema",types:["string","undefined"],value:s}),i({cloudevent:h,name:"subject",types:["string","undefined"],value:y}),this.origin({cloudevent:h,originid:d,originsource:v,origintime:c,origintype:l}),i({cloudevent:h,name:"originatorid",types:["string","undefined"],value:u}),this.wschannel({cloudevent:h,wschannelid:f})};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -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 cloudevent = 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,\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,\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,\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,\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,\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,\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,\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,\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,\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\tconst origintimeValue = origintime || timeValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\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 originidValue = originid || idValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\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 || sourceValue\r\n\t\tsetAttribute({ cloudevent, name: 'originsource', types: ['string'], value: originsourceValue })\r\n\r\n\t\tconst origintypeValue = origintype || typeValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n}\r\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","setAttribute","cloudevent","_ref","types","_ref$types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","this","idValue","nanoid","sourceValue","typeValue","timeValue","Date","toISOString"],"mappings":"wBAAaA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ECHwBG,EAAG,YAAGC,IAAAA,EAAAA,EAAAA,WAAYL,EAA8BM,EAA9BN,KAAMO,EAAAA,EAAAA,MAAAA,OAAwB,IAAAC,EAAhB,GAAgBA,EAAZC,EAAAA,EAAAA,MAC5D,GAAIF,EAAMG,OAAS,IAAMH,EAAMI,gBAANF,GAA8B,CACtD,IAAaG,EAAA,eAAkBZ,EAAlB,qBAA2CO,EAAMM,IAAI,SAAAC,GAAKA,OAAAA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,YACpG,UAAMC,MAAUN,EAChB,CACDP,EAAWL,GAAQS,CACnB,qBCDA,SAAAH,GACCa,IAAAA,EAAAA,EAAAA,KACAC,EAAAA,EAAAA,gBACAC,EAAAA,EAAAA,WACAC,EAAAA,EAAAA,aACAC,EAAAA,EAAAA,SACAC,EAAAA,EAAAA,aACAC,EAAAA,EAAAA,WACAC,EAAAA,EAAAA,WACAC,EAAAA,EAAAA,OACAC,EAAAA,EAAAA,YACAC,EAAAA,EAAAA,QACAC,EAAAA,EAAAA,KACAC,EAAAA,EAAAA,YAEgB1B,EAAG2B,KAIbC,EAAUC,EAAMA,OAACnC,EAAa,iCAAkC,KACtEK,EAAa,CACZC,WAAAA,EACAL,KAAM,KACNO,MAAO,CAAC,UACRE,MAAOwB,IAGR,IAAME,EAAcR,GAAU5B,EAAa,2BAC3CK,EAAa,CACZC,WAAAA,EACAL,KAAM,SACNO,MAAO,CAAC,UACRE,MAAO0B,IAGR,IAAeC,EAAGN,EAClB1B,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNO,MAAO,CAAC,UACRE,MAAO2B,IAIRhC,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNO,MAAO,CAAC,UACRE,MALwBmB,GAAe,QAQxC,IAAeS,GAAG,IAAIC,MAAOC,cAC7BnC,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNO,MAAO,CAAC,UACRE,MAAO4B,IAMRjC,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNS,MAAOU,IAMRf,EAAa,CACZC,WAAAA,EACAL,KAAM,kBACNO,MAAO,CAAC,SAAU,aAClBE,WAP4C,IAATU,EACjCC,GAAmB,mBACnBA,IAQHhB,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNO,MAAO,CAAC,SAAU,aAClBE,MAAOY,IAGRjB,EAAa,CACZC,WAAAA,EACAL,KAAM,UACNO,MAAO,CAAC,SAAU,aAClBE,MAAOoB,IAORzB,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNO,MAAO,CAAC,UACRE,MALuBgB,GAAcY,IAStCjC,EAAa,CACZC,WAAAA,EACAL,KAAM,WACNO,MAAO,CAAC,UACRE,MALqBc,GAAYU,IASlC7B,EAAa,CAAEC,WAAAA,EAAYL,KAAM,eAAgBO,MAAO,CAAC,UAAWE,MAD1Ce,GAAgBW,IAI1C/B,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNO,MAAO,CAAC,UACRE,MALuBiB,GAAcU,IAWtChC,EAAa,CACZC,WAAAA,EACAL,KAAM,eACNO,MAAO,CAAC,SAAU,aAClBE,MAAOa,IAGRlB,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNO,MAAO,CAAC,SAAU,aAClBE,MAAOsB,GAGR"}
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 cloudevent = 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,\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,\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,\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,\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,\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,\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,\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,\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,\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,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","setAttribute","cloudevent","_ref","types","_ref$types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","origin","_ref2$cloudevent","_ref2","ce","_this","this","wschannel","_ref3","_ref3$cloudevent","idValue","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"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"}
@@ -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:o})=>{if(t.length>0&&!t.includes(typeof o)){const e=`Cloudevent "${n}" must be of type ${t.map(e=>e.toUpperCase()).sort().join(" or ")}.`;throw new Error(e)}e[n]=o};class t{constructor({data:t,datacontenttype:o,dataschema:i,originatorid:s,originid:a,originsource:r,origintime:u,origintype:d,source:c,specversion:l,subject:p,type:v,wschannelid:g}){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 f=c||e("MILL_CLOUDEVENTS_SOURCE");n({cloudevent:y,name:"source",types:["string"],value:f});const h=v;n({cloudevent:y,name:"type",types:["string"],value:h}),n({cloudevent:y,name:"specversion",types:["string"],value:l||"1.0"});const E=(new Date).toISOString();n({cloudevent:y,name:"time",types:["string"],value:E}),n({cloudevent:y,name:"data",value:t}),n({cloudevent:y,name:"datacontenttype",types:["string","undefined"],value:void 0!==t?o||"application/json":o}),n({cloudevent:y,name:"dataschema",types:["string","undefined"],value:i}),n({cloudevent:y,name:"subject",types:["string","undefined"],value:p}),n({cloudevent:y,name:"origintime",types:["string"],value:u||E}),n({cloudevent:y,name:"originid",types:["string"],value:a||m}),n({cloudevent:y,name:"originsource",types:["string"],value:r||f}),n({cloudevent:y,name:"origintype",types:["string"],value:d||h}),n({cloudevent:y,name:"originatorid",types:["string","undefined"],value:s}),n({cloudevent:y,name:"wschannelid",types:["string","undefined"],value:g})}}export{t as Cloudevent};
1
+ const e=(e,n)=>{if("undefined"!=typeof process)return process.env[e]||n},n=({cloudevent:e,name:n,types:t=[],value:i})=>{if(t.length>0&&!t.includes(typeof i)){const e=`Cloudevent "${n}" must be of type ${t.map(e=>e.toUpperCase()).sort().join(" or ")}.`;throw new Error(e)}e[n]=i};class t{constructor({data:t,datacontenttype:i,dataschema:o,originatorid:s,originid:r,originsource:a,origintime:u,origintype:c,source:d,specversion:l,subject:g,type:p,wschannelid:v}){this.origin=({cloudevent:e={},originid:t,originsource:i,origintime:o,origintype:s})=>{const r=this;return n({cloudevent:r,name:"originid",types:["string"],value:t||e.originid||e.id}),n({cloudevent:r,name:"originsource",types:["string"],value:i||e.originsource||e.source}),n({cloudevent:r,name:"origintime",types:["string"],value:o||e.origintime||e.time}),n({cloudevent:r,name:"origintype",types:["string"],value:s||e.origintype||e.type}),r},this.wschannel=({cloudevent:e={},wschannelid:t})=>(n({cloudevent:this,name:"wschannelid",types:["string","undefined"],value:t||e.wschannelid}),this);const y=this,m=((e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((e,n)=>e+((n&=63)<36?n.toString(36):n<62?(n-26).toString(36).toUpperCase():n>62?"-":"_"),""))(e("MILL_CLOUDEVENTS_NANOID_LENGTH",21));n({cloudevent:y,name:"id",types:["string"],value:m});const h=d||e("MILL_CLOUDEVENTS_SOURCE");n({cloudevent:y,name:"source",types:["string"],value:h}),n({cloudevent:y,name:"type",types:["string"],value:p}),n({cloudevent:y,name:"specversion",types:["string"],value:l||"1.0"});const f=(new Date).toISOString();n({cloudevent:y,name:"time",types:["string"],value:f}),n({cloudevent:y,name:"data",value:t}),n({cloudevent:y,name:"datacontenttype",types:["string","undefined"],value:void 0!==t?i||"application/json":i}),n({cloudevent:y,name:"dataschema",types:["string","undefined"],value:o}),n({cloudevent:y,name:"subject",types:["string","undefined"],value:g}),this.origin({cloudevent:y,originid:r,originsource:a,origintime:u,origintype:c}),n({cloudevent:y,name:"originatorid",types:["string","undefined"],value:s}),this.wschannel({cloudevent:y,wschannelid:v})}}export{t as Cloudevent};
2
2
  //# sourceMappingURL=index.modern.js.map
@@ -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 cloudevent = 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,\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,\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,\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,\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,\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,\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,\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,\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,\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\tconst origintimeValue = origintime || timeValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\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 originidValue = originid || idValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\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 || sourceValue\r\n\t\tsetAttribute({ cloudevent, name: 'originsource', types: ['string'], value: originsourceValue })\r\n\r\n\t\tconst origintypeValue = origintype || typeValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nlet customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nlet nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","setAttribute","cloudevent","types","value","length","includes","message","map","s","toUpperCase","sort","join","Cloudevent","constructor","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","this","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","idValue","sourceValue","typeValue","timeValue","Date","toISOString"],"mappings":"AAAO,MAAkBA,EAAG,CAACC,EAAMC,KAClC,GAAuB,oBAAnBC,QACJ,OAAOA,QAAQC,IAAIH,IAASC,GCFhBG,EAAe,EAAGC,aAAYL,OAAMM,MAAAA,EAAQ,GAAIC,YAC5D,GAAID,EAAME,OAAS,IAAMF,EAAMG,gBAANF,GAA8B,CACtD,MAAaG,EAAI,eAAcV,sBAAyBM,EAAMK,IAAIC,GAAKA,EAAEC,eAAeC,OAAOC,KAAK,WACpG,MAAM,UAAUL,EAChB,CACDL,EAAWL,GAAQO,GCDPS,MAAAA,EACZC,aAAYC,KACXA,EADWC,gBAEXA,EAFWC,WAGXA,EAHWC,aAIXA,EAJWC,SAKXA,EALWC,aAMXA,EANWC,WAOXA,EAPWC,WAQXA,EARWC,OASXA,EATWC,YAUXA,EAVWC,QAWXA,EAXWC,KAYXA,EAZWC,YAaXA,IAEA,MAAMzB,EAAa0B,OCDR,EAACC,EAAO,KACnBC,OAAOC,gBAAgB,IAAIC,WAAWH,IAAOI,OAAO,CAACC,EAAIC,IAGrDD,IAFFC,GAAQ,IACG,GACHA,EAAKC,SAAS,IACXD,EAAO,IACTA,EAAO,IAAIC,SAAS,IAAI1B,cACtByB,EAAO,GACV,IAEA,KAGP,IDRaE,CAAOzC,EAAa,iCAAkC,KACtEK,EAAa,CACZC,aACAL,KAAM,KACNM,MAAO,CAAC,UACRC,MAAOkC,IAGR,MAAiBC,EAAGhB,GAAU3B,EAAa,2BAC3CK,EAAa,CACZC,aACAL,KAAM,SACNM,MAAO,CAAC,UACRC,MAAOmC,IAGR,QAAkBb,EAClBzB,EAAa,CACZC,aACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAOoC,IAIRvC,EAAa,CACZC,aACAL,KAAM,cACNM,MAAO,CAAC,UACRC,MALwBoB,GAAe,QAQxC,MAAeiB,GAAG,IAAIC,MAAOC,cAC7B1C,EAAa,CACZC,aACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAOqC,IAMRxC,EAAa,CACZC,aACAL,KAAM,OACNO,MAAOW,IAMRd,EAAa,CACZC,aACAL,KAAM,kBACNM,MAAO,CAAC,SAAU,aAClBC,WAP4C,IAATW,EACjCC,GAAmB,mBACnBA,IAQHf,EAAa,CACZC,aACAL,KAAM,aACNM,MAAO,CAAC,SAAU,aAClBC,MAAOa,IAGRhB,EAAa,CACZC,aACAL,KAAM,UACNM,MAAO,CAAC,SAAU,aAClBC,MAAOqB,IAORxB,EAAa,CACZC,aACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBiB,GAAcoB,IAStCxC,EAAa,CACZC,aACAL,KAAM,WACNM,MAAO,CAAC,UACRC,MALqBe,GAAYmB,IASlCrC,EAAa,CAAEC,aAAYL,KAAM,eAAgBM,MAAO,CAAC,UAAWC,MAD1CgB,GAAgBmB,IAI1CtC,EAAa,CACZC,aACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBkB,GAAckB,IAWtCvC,EAAa,CACZC,aACAL,KAAM,eACNM,MAAO,CAAC,SAAU,aAClBC,MAAOc,IAGRjB,EAAa,CACZC,aACAL,KAAM,cACNM,MAAO,CAAC,SAAU,aAClBC,MAAOuB,GAGR"}
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 cloudevent = 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,\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,\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,\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,\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,\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,\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,\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,\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,\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,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nlet customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nlet nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","setAttribute","cloudevent","types","value","length","includes","message","map","s","toUpperCase","sort","join","Cloudevent","constructor","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","origin","ce","this","wschannel","idValue","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"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"}
@@ -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},t=function(e){var n=e.cloudevent,t=e.name,i=e.types,a=void 0===i?[]:i,o=e.value;if(a.length>0&&!a.includes(typeof o)){var r='Cloudevent "'+t+'" must be of type '+a.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(r)}n[t]=o},i=function(i){var a=i.data,o=i.datacontenttype,r=i.dataschema,s=i.originatorid,u=i.originid,d=i.originsource,v=i.origintime,c=i.origintype,l=i.source,p=i.specversion,g=i.subject,m=i.type,y=i.wschannelid,f=this,h=e(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));t({cloudevent:f,name:"id",types:["string"],value:h});var E=l||n("MILL_CLOUDEVENTS_SOURCE");t({cloudevent:f,name:"source",types:["string"],value:E});var L=m;t({cloudevent:f,name:"type",types:["string"],value:L}),t({cloudevent:f,name:"specversion",types:["string"],value:p||"1.0"});var w=(new Date).toISOString();t({cloudevent:f,name:"time",types:["string"],value:w}),t({cloudevent:f,name:"data",value:a}),t({cloudevent:f,name:"datacontenttype",types:["string","undefined"],value:void 0!==a?o||"application/json":o}),t({cloudevent:f,name:"dataschema",types:["string","undefined"],value:r}),t({cloudevent:f,name:"subject",types:["string","undefined"],value:g}),t({cloudevent:f,name:"origintime",types:["string"],value:v||w}),t({cloudevent:f,name:"originid",types:["string"],value:u||h}),t({cloudevent:f,name:"originsource",types:["string"],value:d||E}),t({cloudevent:f,name:"origintype",types:["string"],value:c||L}),t({cloudevent:f,name:"originatorid",types:["string","undefined"],value:s}),t({cloudevent:f,name:"wschannelid",types:["string","undefined"],value:y})};export{i 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.name,t=e.types,o=void 0===t?[]:t,r=e.value;if(o.length>0&&!o.includes(typeof r)){var a='Cloudevent "'+i+'" must be of type '+o.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(a)}n[i]=r},t=function(t){var o=this,r=t.data,a=t.datacontenttype,s=t.dataschema,u=t.originatorid,d=t.originid,c=t.originsource,v=t.origintime,l=t.origintype,g=t.source,p=t.specversion,m=t.subject,y=t.type,f=t.wschannelid;this.origin=function(e){var n=e.cloudevent,t=void 0===n?{}:n,r=e.originsource,a=e.origintime,s=e.origintype,u=o;return i({cloudevent:u,name:"originid",types:["string"],value:e.originid||t.originid||t.id}),i({cloudevent:u,name:"originsource",types:["string"],value:r||t.originsource||t.source}),i({cloudevent:u,name:"origintime",types:["string"],value:a||t.origintime||t.time}),i({cloudevent:u,name:"origintype",types:["string"],value:s||t.origintype||t.type}),u},this.wschannel=function(e){var n=e.cloudevent,t=o;return i({cloudevent:t,name:"wschannelid",types:["string","undefined"],value:e.wschannelid||(void 0===n?{}:n).wschannelid}),t};var h=this,w=e(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));i({cloudevent:h,name:"id",types:["string"],value:w});var E=g||n("MILL_CLOUDEVENTS_SOURCE");i({cloudevent:h,name:"source",types:["string"],value:E}),i({cloudevent:h,name:"type",types:["string"],value:y}),i({cloudevent:h,name:"specversion",types:["string"],value:p||"1.0"});var L=(new Date).toISOString();i({cloudevent:h,name:"time",types:["string"],value:L}),i({cloudevent:h,name:"data",value:r}),i({cloudevent:h,name:"datacontenttype",types:["string","undefined"],value:void 0!==r?a||"application/json":a}),i({cloudevent:h,name:"dataschema",types:["string","undefined"],value:s}),i({cloudevent:h,name:"subject",types:["string","undefined"],value:m}),this.origin({cloudevent:h,originid:d,originsource:c,origintime:v,origintype:l}),i({cloudevent:h,name:"originatorid",types:["string","undefined"],value:u}),this.wschannel({cloudevent:h,wschannelid:f})};export{t as Cloudevent};
2
2
  //# sourceMappingURL=index.module.js.map
@@ -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 cloudevent = 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,\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,\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,\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,\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,\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,\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,\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,\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,\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\tconst origintimeValue = origintime || timeValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\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 originidValue = originid || idValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\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 || sourceValue\r\n\t\tsetAttribute({ cloudevent, name: 'originsource', types: ['string'], value: originsourceValue })\r\n\r\n\t\tconst origintypeValue = origintype || typeValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid\r\n\t\t})\r\n\t\t// *******\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","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","this","idValue","nanoid","sourceValue","typeValue","timeValue","Date","toISOString"],"mappings":"gCAAaA,IAAAA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ECHwBG,EAAG,YAAGC,IAAAA,EAAAA,EAAAA,WAAYL,EAA8BM,EAA9BN,KAAMO,EAAAA,EAAAA,MAAAA,OAAwB,IAAAC,EAAhB,GAAgBA,EAAZC,EAAAA,EAAAA,MAC5D,GAAIF,EAAMG,OAAS,IAAMH,EAAMI,gBAANF,GAA8B,CACtD,IAAaG,EAAA,eAAkBZ,EAAlB,qBAA2CO,EAAMM,IAAI,SAAAC,GAAKA,OAAAA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,YACpG,UAAMC,MAAUN,EAChB,CACDP,EAAWL,GAAQS,CACnB,ECFYU,EACZ,SAAAb,GACCc,IAAAA,EAAAA,EAAAA,KACAC,EAAAA,EAAAA,gBACAC,EAAAA,EAAAA,WACAC,EAAAA,EAAAA,aACAC,EAAAA,EAAAA,SACAC,EAAAA,EAAAA,aACAC,EAAAA,EAAAA,WACAC,EAAAA,EAAAA,WACAC,EAAAA,EAAAA,OACAC,EAAAA,EAAAA,YACAC,EAAAA,EAAAA,QACAC,EAAAA,EAAAA,KACAC,EAAAA,EAAAA,YAEgB3B,EAAG4B,KAIbC,EAAUC,EAAOpC,EAAa,iCAAkC,KACtEK,EAAa,CACZC,WAAAA,EACAL,KAAM,KACNO,MAAO,CAAC,UACRE,MAAOyB,IAGR,IAAME,EAAcR,GAAU7B,EAAa,2BAC3CK,EAAa,CACZC,WAAAA,EACAL,KAAM,SACNO,MAAO,CAAC,UACRE,MAAO2B,IAGR,IAAeC,EAAGN,EAClB3B,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNO,MAAO,CAAC,UACRE,MAAO4B,IAIRjC,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNO,MAAO,CAAC,UACRE,MALwBoB,GAAe,QAQxC,IAAeS,GAAG,IAAIC,MAAOC,cAC7BpC,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNO,MAAO,CAAC,UACRE,MAAO6B,IAMRlC,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNS,MAAOW,IAMRhB,EAAa,CACZC,WAAAA,EACAL,KAAM,kBACNO,MAAO,CAAC,SAAU,aAClBE,WAP4C,IAATW,EACjCC,GAAmB,mBACnBA,IAQHjB,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNO,MAAO,CAAC,SAAU,aAClBE,MAAOa,IAGRlB,EAAa,CACZC,WAAAA,EACAL,KAAM,UACNO,MAAO,CAAC,SAAU,aAClBE,MAAOqB,IAOR1B,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNO,MAAO,CAAC,UACRE,MALuBiB,GAAcY,IAStClC,EAAa,CACZC,WAAAA,EACAL,KAAM,WACNO,MAAO,CAAC,UACRE,MALqBe,GAAYU,IASlC9B,EAAa,CAAEC,WAAAA,EAAYL,KAAM,eAAgBO,MAAO,CAAC,UAAWE,MAD1CgB,GAAgBW,IAI1ChC,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNO,MAAO,CAAC,UACRE,MALuBkB,GAAcU,IAWtCjC,EAAa,CACZC,WAAAA,EACAL,KAAM,eACNO,MAAO,CAAC,SAAU,aAClBE,MAAOc,IAGRnB,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNO,MAAO,CAAC,SAAU,aAClBE,MAAOuB,GAGR"}
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 cloudevent = 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,\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,\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,\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,\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,\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,\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,\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,\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,\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,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","setAttribute","cloudevent","_ref","types","_ref$types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","origin","_ref2$cloudevent","_ref2","ce","_this","this","wschannel","_ref3","_ref3$cloudevent","idValue","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"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"}
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).cloudevents={})}(this,function(e){var n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},t=function(e){var n=e.cloudevent,t=e.name,i=e.types,o=void 0===i?[]:i,a=e.value;if(o.length>0&&!o.includes(typeof a)){var r='Cloudevent "'+t+'" must be of type '+o.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(r)}n[t]=a};e.Cloudevent=function(e){var i=e.data,o=e.datacontenttype,a=e.dataschema,r=e.originatorid,s=e.originid,u=e.originsource,d=e.origintime,l=e.origintype,v=e.source,c=e.specversion,p=e.subject,g=e.type,y=e.wschannelid,f=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?"-":"_"),""))(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));t({cloudevent:f,name:"id",types:["string"],value:m});var h=v||n("MILL_CLOUDEVENTS_SOURCE");t({cloudevent:f,name:"source",types:["string"],value:h});var C=g;t({cloudevent:f,name:"type",types:["string"],value:C}),t({cloudevent:f,name:"specversion",types:["string"],value:c||"1.0"});var E=(new Date).toISOString();t({cloudevent:f,name:"time",types:["string"],value:E}),t({cloudevent:f,name:"data",value:i}),t({cloudevent:f,name:"datacontenttype",types:["string","undefined"],value:void 0!==i?o||"application/json":o}),t({cloudevent:f,name:"dataschema",types:["string","undefined"],value:a}),t({cloudevent:f,name:"subject",types:["string","undefined"],value:p}),t({cloudevent:f,name:"origintime",types:["string"],value:d||E}),t({cloudevent:f,name:"originid",types:["string"],value:s||m}),t({cloudevent:f,name:"originsource",types:["string"],value:u||h}),t({cloudevent:f,name:"origintype",types:["string"],value:l||C}),t({cloudevent:f,name:"originatorid",types:["string","undefined"],value:r}),t({cloudevent:f,name:"wschannelid",types:["string","undefined"],value:y})}});
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).cloudevents={})}(this,function(e){var n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},t=function(e){var n=e.cloudevent,t=e.name,i=e.types,o=void 0===i?[]:i,r=e.value;if(o.length>0&&!o.includes(typeof r)){var s='Cloudevent "'+t+'" must be of type '+o.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(s)}n[t]=r};e.Cloudevent=function(e){var i=this,o=e.data,r=e.datacontenttype,s=e.dataschema,a=e.originatorid,u=e.originid,d=e.originsource,c=e.origintime,l=e.origintype,v=e.source,p=e.specversion,g=e.subject,y=e.type,f=e.wschannelid;this.origin=function(e){var n=e.cloudevent,o=void 0===n?{}:n,r=e.originsource,s=e.origintime,a=e.origintype,u=i;return t({cloudevent:u,name:"originid",types:["string"],value:e.originid||o.originid||o.id}),t({cloudevent:u,name:"originsource",types:["string"],value:r||o.originsource||o.source}),t({cloudevent:u,name:"origintime",types:["string"],value:s||o.origintime||o.time}),t({cloudevent:u,name:"origintype",types:["string"],value:a||o.origintype||o.type}),u},this.wschannel=function(e){var n=e.cloudevent,o=i;return t({cloudevent:o,name:"wschannelid",types:["string","undefined"],value:e.wschannelid||(void 0===n?{}:n).wschannelid}),o};var m=this,h=((e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((e,n)=>e+((n&=63)<36?n.toString(36):n<62?(n-26).toString(36).toUpperCase():n>62?"-":"_"),""))(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));t({cloudevent:m,name:"id",types:["string"],value:h});var w=v||n("MILL_CLOUDEVENTS_SOURCE");t({cloudevent:m,name:"source",types:["string"],value:w}),t({cloudevent:m,name:"type",types:["string"],value:y}),t({cloudevent:m,name:"specversion",types:["string"],value:p||"1.0"});var C=(new Date).toISOString();t({cloudevent:m,name:"time",types:["string"],value:C}),t({cloudevent:m,name:"data",value:o}),t({cloudevent:m,name:"datacontenttype",types:["string","undefined"],value:void 0!==o?r||"application/json":r}),t({cloudevent:m,name:"dataschema",types:["string","undefined"],value:s}),t({cloudevent:m,name:"subject",types:["string","undefined"],value:g}),this.origin({cloudevent:m,originid:u,originsource:d,origintime:c,origintype:l}),t({cloudevent:m,name:"originatorid",types:["string","undefined"],value:a}),this.wschannel({cloudevent:m,wschannelid:f})}});
2
2
  //# sourceMappingURL=index.umd.js.map
@@ -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 cloudevent = 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,\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,\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,\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,\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,\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,\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,\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,\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,\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\tconst origintimeValue = origintime || timeValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\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 originidValue = originid || idValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\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 || sourceValue\r\n\t\tsetAttribute({ cloudevent, name: 'originsource', types: ['string'], value: originsourceValue })\r\n\r\n\t\tconst origintypeValue = origintype || typeValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nlet customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nlet nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","setAttribute","cloudevent","_ref","types","_ref$types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","this","idValue","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","sourceValue","typeValue","timeValue","Date","toISOString"],"mappings":"qOAAaA,IAAAA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ECHwBG,EAAG,YAAGC,IAAAA,EAAAA,EAAAA,WAAYL,EAA8BM,EAA9BN,KAAMO,EAAAA,EAAAA,MAAAA,OAAwB,IAAAC,EAAhB,GAAgBA,EAAZC,EAAAA,EAAAA,MAC5D,GAAIF,EAAMG,OAAS,IAAMH,EAAMI,gBAANF,GAA8B,CACtD,IAAaG,EAAA,eAAkBZ,EAAlB,qBAA2CO,EAAMM,IAAI,SAAAC,GAAKA,OAAAA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,YACpG,UAAMC,MAAUN,EAChB,CACDP,EAAWL,GAAQS,CACnB,eCDA,SAAAH,GACCa,IAAAA,EAAAA,EAAAA,KACAC,EAAAA,EAAAA,gBACAC,EAAAA,EAAAA,WACAC,EAAAA,EAAAA,aACAC,EAAAA,EAAAA,SACAC,EAAAA,EAAAA,aACAC,EAAAA,EAAAA,WACAC,EAAAA,EAAAA,WACAC,EAAAA,EAAAA,OACAC,EAAAA,EAAAA,YACAC,EAAAA,EAAAA,QACAC,EAAAA,EAAAA,KACAC,EAAAA,EAAAA,YAEgB1B,EAAG2B,KAIbC,ECLK,EAACC,EAAO,KACnBC,OAAOC,gBAAgB,IAAIC,WAAWH,IAAOI,OAAO,CAACC,EAAIC,IAGrDD,IAFFC,GAAQ,IACG,GACHA,EAAKC,SAAS,IACXD,EAAO,IACTA,EAAO,IAAIC,SAAS,IAAI1B,cACtByB,EAAO,GACV,IAEA,KAGP,IDRaE,CAAO3C,EAAa,iCAAkC,KACtEK,EAAa,CACZC,WAAAA,EACAL,KAAM,KACNO,MAAO,CAAC,UACRE,MAAOwB,IAGR,IAAMU,EAAchB,GAAU5B,EAAa,2BAC3CK,EAAa,CACZC,WAAAA,EACAL,KAAM,SACNO,MAAO,CAAC,UACRE,MAAOkC,IAGR,IAAeC,EAAGd,EAClB1B,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNO,MAAO,CAAC,UACRE,MAAOmC,IAIRxC,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNO,MAAO,CAAC,UACRE,MALwBmB,GAAe,QAQxC,IAAeiB,GAAG,IAAIC,MAAOC,cAC7B3C,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNO,MAAO,CAAC,UACRE,MAAOoC,IAMRzC,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNS,MAAOU,IAMRf,EAAa,CACZC,WAAAA,EACAL,KAAM,kBACNO,MAAO,CAAC,SAAU,aAClBE,WAP4C,IAATU,EACjCC,GAAmB,mBACnBA,IAQHhB,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNO,MAAO,CAAC,SAAU,aAClBE,MAAOY,IAGRjB,EAAa,CACZC,WAAAA,EACAL,KAAM,UACNO,MAAO,CAAC,SAAU,aAClBE,MAAOoB,IAORzB,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNO,MAAO,CAAC,UACRE,MALuBgB,GAAcoB,IAStCzC,EAAa,CACZC,WAAAA,EACAL,KAAM,WACNO,MAAO,CAAC,UACRE,MALqBc,GAAYU,IASlC7B,EAAa,CAAEC,WAAAA,EAAYL,KAAM,eAAgBO,MAAO,CAAC,UAAWE,MAD1Ce,GAAgBmB,IAI1CvC,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNO,MAAO,CAAC,UACRE,MALuBiB,GAAckB,IAWtCxC,EAAa,CACZC,WAAAA,EACAL,KAAM,eACNO,MAAO,CAAC,SAAU,aAClBE,MAAOa,IAGRlB,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNO,MAAO,CAAC,SAAU,aAClBE,MAAOsB,GAGR"}
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 cloudevent = 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,\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,\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,\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,\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,\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,\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,\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,\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,\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,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nlet customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nlet nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","setAttribute","cloudevent","_ref","types","_ref$types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","origin","_ref2$cloudevent","_ref2","ce","_this","this","wschannel","_ref3","_ref3$cloudevent","idValue","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1mill/cloudevents",
3
- "version": "4.2.1",
3
+ "version": "4.4.0",
4
4
  "description": "Node cloudevents specification and helper",
5
5
  "jsnext:main": "dist/index.module.js",
6
6
  "main": "dist/index.cjs",
package/src/index.js CHANGED
@@ -98,49 +98,79 @@ export class Cloudevent {
98
98
 
99
99
  // *******
100
100
  // * Required in-house extentions
101
- const origintimeValue = origintime || timeValue
102
- setAttribute({
101
+ this.origin({
103
102
  cloudevent,
104
- name: 'origintime',
105
- types: ['string'],
106
- value: origintimeValue
103
+ originid,
104
+ originsource,
105
+ origintime,
106
+ origintype,
107
107
  })
108
+ // *******
108
109
 
109
- const originidValue = originid || idValue
110
+ // *******
111
+ // * Optional in-house extentions
110
112
  setAttribute({
111
113
  cloudevent,
114
+ name: 'originatorid',
115
+ types: ['string', 'undefined'],
116
+ value: originatorid
117
+ })
118
+
119
+ this.wschannel({
120
+ cloudevent,
121
+ wschannelid,
122
+ })
123
+ // *******
124
+ }
125
+
126
+ origin = ({ cloudevent = {}, originid, originsource, origintime, origintype }) => {
127
+ const ce = this
128
+
129
+ const originidValue = originid || cloudevent['originid'] || cloudevent['id']
130
+ setAttribute({
131
+ cloudevent: ce,
112
132
  name: 'originid',
113
133
  types: ['string'],
114
- value: originidValue
134
+ value: originidValue,
115
135
  })
116
136
 
117
- const originsourceValue = originsource || sourceValue
118
- setAttribute({ cloudevent, name: 'originsource', types: ['string'], value: originsourceValue })
137
+ const originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']
138
+ setAttribute({
139
+ cloudevent: ce,
140
+ name: 'originsource',
141
+ types: ['string'],
142
+ value: originsourceValue,
143
+ })
119
144
 
120
- const origintypeValue = origintype || typeValue
145
+ const origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']
121
146
  setAttribute({
122
- cloudevent,
123
- name: 'origintype',
147
+ cloudevent: ce,
148
+ name: 'origintime',
124
149
  types: ['string'],
125
- value: origintypeValue
150
+ value: origintimeValue,
126
151
  })
127
- // *******
128
152
 
129
- // *******
130
- // * Optional in-house extentions
153
+ const origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']
131
154
  setAttribute({
132
- cloudevent,
133
- name: 'originatorid',
134
- types: ['string', 'undefined'],
135
- value: originatorid
155
+ cloudevent: ce,
156
+ name: 'origintype',
157
+ types: ['string'],
158
+ value: origintypeValue,
136
159
  })
137
160
 
161
+ return ce
162
+ }
163
+
164
+ wschannel = ({ cloudevent = {}, wschannelid }) => {
165
+ const ce = this
166
+
138
167
  setAttribute({
139
- cloudevent,
168
+ cloudevent: ce,
140
169
  name: 'wschannelid',
141
170
  types: ['string', 'undefined'],
142
- value: wschannelid
171
+ value: wschannelid || cloudevent['wschannelid'],
143
172
  })
144
- // *******
173
+
174
+ return ce
145
175
  }
146
176
  }
@@ -1,4 +1,4 @@
1
- import { Cloudevent } from '../index.js'
1
+ import { Cloudevent } from '../../index.js'
2
2
  import { expect } from 'chai'
3
3
 
4
4
  describe('cloudevent#data', () => {
@@ -1,4 +1,4 @@
1
- import { Cloudevent } from '../index.js'
1
+ import { Cloudevent } from '../../index.js'
2
2
  import { expect } from 'chai'
3
3
 
4
4
  describe('cloudevent#datacontenttype', () => {
@@ -1,4 +1,4 @@
1
- import { Cloudevent } from '../index.js'
1
+ import { Cloudevent } from '../../index.js'
2
2
  import { expect } from 'chai'
3
3
 
4
4
  describe('cloudevent#dataschema', () => {
@@ -1,4 +1,4 @@
1
- import { Cloudevent } from '../index.js'
1
+ import { Cloudevent } from '../../index.js'
2
2
  import { createSandbox } from 'sinon'
3
3
  import { expect } from 'chai'
4
4
 
@@ -1,4 +1,4 @@
1
- import { Cloudevent } from '../index.js'
1
+ import { Cloudevent } from '../../index.js'
2
2
  import { expect } from 'chai'
3
3
 
4
4
  describe('cloudevent#originatorid', () => {
@@ -1,4 +1,4 @@
1
- import { Cloudevent } from '../index.js'
1
+ import { Cloudevent } from '../../index.js'
2
2
  import { expect } from 'chai'
3
3
 
4
4
  describe('cloudevent#originid', () => {
@@ -1,4 +1,4 @@
1
- import { Cloudevent } from '../index.js'
1
+ import { Cloudevent } from '../../index.js'
2
2
  import { expect } from 'chai'
3
3
 
4
4
  describe('cloudevent#originsource', () => {
@@ -1,4 +1,4 @@
1
- import { Cloudevent } from '../index.js'
1
+ import { Cloudevent } from '../../index.js'
2
2
  import { expect } from 'chai'
3
3
 
4
4
  describe('cloudevent#origintime', () => {
@@ -1,4 +1,4 @@
1
- import { Cloudevent } from '../index.js'
1
+ import { Cloudevent } from '../../index.js'
2
2
  import { expect } from 'chai'
3
3
 
4
4
  describe('cloudevent#origintype', () => {
@@ -1,4 +1,4 @@
1
- import { Cloudevent } from '../index.js'
1
+ import { Cloudevent } from '../../index.js'
2
2
  import { createSandbox } from 'sinon'
3
3
  import { expect } from 'chai'
4
4
 
@@ -1,4 +1,4 @@
1
- import { Cloudevent } from '../index.js'
1
+ import { Cloudevent } from '../../index.js'
2
2
  import { expect } from 'chai'
3
3
 
4
4
  describe('cloudevent#specversion', () => {
@@ -1,4 +1,4 @@
1
- import { Cloudevent } from '../index.js'
1
+ import { Cloudevent } from '../../index.js'
2
2
  import { expect } from 'chai'
3
3
 
4
4
  describe('cloudevent#subject', () => {
@@ -1,6 +1,6 @@
1
1
  import chai, { expect } from 'chai'
2
2
  import chaiIso8601 from 'chai-iso8601'
3
- import { Cloudevent } from '../index.js'
3
+ import { Cloudevent } from '../../index.js'
4
4
  import { useFakeTimers } from 'sinon'
5
5
 
6
6
  chai.use(chaiIso8601())
@@ -1,4 +1,4 @@
1
- import { Cloudevent } from '../index.js'
1
+ import { Cloudevent } from '../../index.js'
2
2
  import { expect } from 'chai'
3
3
 
4
4
  describe('cloudevent#type', () => {
@@ -1,4 +1,4 @@
1
- import { Cloudevent } from '../index.js'
1
+ import { Cloudevent } from '../../index.js'
2
2
  import { expect } from 'chai'
3
3
 
4
4
  describe('cloudevent#wschannelid', () => {
@@ -0,0 +1,85 @@
1
+ import { Cloudevent } from '../../../index.js'
2
+ import { expect } from 'chai'
3
+
4
+ describe('cloudevent.origin#originid', () => {
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
+ describe('when #originid is not input', () => {
32
+ beforeEach(() => {
33
+ params.originid = undefined
34
+ })
35
+
36
+ describe('when #cloudevent is not input', () => {
37
+ it('throws the proper error', () => {
38
+ params.cloudevent = undefined
39
+ const expected = 'Cloudevent "originid" must be of type STRING'
40
+ expect(() => ce.origin(params)).to.throw(expected)
41
+ })
42
+ })
43
+
44
+ describe('when #cloudevent is input', () => {
45
+ describe('when #cloudevent#originid does not exist', () => {
46
+ beforeEach(() => {
47
+ cloudevent.originid = undefined
48
+ })
49
+
50
+ describe('when #cloudevent#id does not exist', () => {
51
+ it('throws the proper error', () => {
52
+ cloudevent.id = undefined
53
+ const expected = 'Cloudevent "originid" must be of type STRING'
54
+ expect(() => ce.origin(params)).to.throw(expected)
55
+ })
56
+ })
57
+
58
+ describe('when #cloudevent#id does exist', () => {
59
+ it('returns the input #cloudevent#id', () => {
60
+ ce.origin(params)
61
+ expect(ce.originid).to.eq(cloudevent.id)
62
+ })
63
+ })
64
+ })
65
+
66
+ describe('when #cloudevent#originid exists', () => {
67
+ it('returns the input #cloudevent#originid', () => {
68
+ const expected = 'some-new-origin-id'
69
+
70
+ cloudevent.originid = expected
71
+ ce.origin(params)
72
+
73
+ expect(ce.originid).to.eq(expected)
74
+ })
75
+ })
76
+ })
77
+ })
78
+
79
+ describe('when #originid is input', () => {
80
+ it('returns the input value', () => {
81
+ ce.origin(params)
82
+ expect(ce.originid).to.eq(params.originid)
83
+ })
84
+ })
85
+ })
@@ -0,0 +1,85 @@
1
+ import { Cloudevent } from '../../../index.js'
2
+ import { expect } from 'chai'
3
+
4
+ describe('cloudevent.origin#originsource', () => {
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
+ describe('when #originsource is not input', () => {
32
+ beforeEach(() => {
33
+ params.originsource = undefined
34
+ })
35
+
36
+ describe('when #cloudevent is not input', () => {
37
+ it('throws the proper error', () => {
38
+ const expected = 'Cloudevent "originsource" must be of type STRING'
39
+ params.cloudevent = undefined
40
+ expect(() => ce.origin(params)).to.throw(expected)
41
+ })
42
+ })
43
+
44
+ describe('when #cloudevent is input', () => {
45
+ describe('when #cloudevent#originsource does not exist', () => {
46
+ beforeEach(() => {
47
+ cloudevent.originsource = undefined
48
+ })
49
+
50
+ describe('when #cloudevent#source does not exist', () => {
51
+ it('throws the proper error', () => {
52
+ cloudevent.source = undefined
53
+ const expected = 'Cloudevent "originsource" must be of type STRING'
54
+ expect(() => ce.origin(params)).to.throw(expected)
55
+ })
56
+ })
57
+
58
+ describe('when #cloudevent#source does exist', () => {
59
+ it('returns the input #cloudevent#source', () => {
60
+ ce.origin(params)
61
+ expect(ce.originsource).to.eq(cloudevent.source)
62
+ })
63
+ })
64
+ })
65
+
66
+ describe('when #cloudevent#originsource exists', () => {
67
+ it('returns the input #cloudevent#originsource', () => {
68
+ const expected = 'some-new-origin-source'
69
+
70
+ cloudevent.originsource = expected
71
+ ce.origin(params)
72
+
73
+ expect(ce.originsource).to.eq(expected)
74
+ })
75
+ })
76
+ })
77
+ })
78
+
79
+ describe('when #originsource is input', () => {
80
+ it('returns the input value', () => {
81
+ ce.origin(params)
82
+ expect(ce.originsource).to.eq(params.originsource)
83
+ })
84
+ })
85
+ })
@@ -0,0 +1,85 @@
1
+ import { Cloudevent } from '../../../index.js'
2
+ import { expect } from 'chai'
3
+
4
+ describe('cloudevent.origin#origintime', () => {
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
+ describe('when #origintime is not input', () => {
32
+ beforeEach(() => {
33
+ params.origintime = undefined
34
+ })
35
+
36
+ describe('when #cloudevent is not input', () => {
37
+ it('throws the proper error', () => {
38
+ const expected = 'Cloudevent "origintime" must be of type STRING'
39
+ params.cloudevent = undefined
40
+ expect(() => ce.origin(params)).to.throw(expected)
41
+ })
42
+ })
43
+
44
+ describe('when #cloudevent is input', () => {
45
+ describe('when #cloudevent#origintime does not exist', () => {
46
+ beforeEach(() => {
47
+ cloudevent.origintime = undefined
48
+ })
49
+
50
+ describe('when #cloudevent#time does not exist', () => {
51
+ it('throws the proper error', () => {
52
+ cloudevent.time = undefined
53
+ const expected = 'Cloudevent "origintime" must be of type STRING'
54
+ expect(() => ce.origin(params)).to.throw(expected)
55
+ })
56
+ })
57
+
58
+ describe('when #cloudevent#time does exist', () => {
59
+ it('returns the input #cloudevent#time', () => {
60
+ ce.origin(params)
61
+ expect(ce.origintime).to.eq(cloudevent.time)
62
+ })
63
+ })
64
+ })
65
+
66
+ describe('when #cloudevent#origintime exists', () => {
67
+ it('returns the input #cloudevent#origintime', () => {
68
+ const expected = 'some-new-origin-time'
69
+
70
+ cloudevent.origintime = expected
71
+ ce.origin(params)
72
+
73
+ expect(ce.origintime).to.eq(expected)
74
+ })
75
+ })
76
+ })
77
+ })
78
+
79
+ describe('when #origintime is input', () => {
80
+ it('returns the input value', () => {
81
+ ce.origin(params)
82
+ expect(ce.origintime).to.eq(params.origintime)
83
+ })
84
+ })
85
+ })
@@ -0,0 +1,85 @@
1
+ import { Cloudevent } from '../../../index.js'
2
+ import { expect } from 'chai'
3
+
4
+ describe('cloudevent.origin#origintype', () => {
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
+ describe('when #origintype is not input', () => {
32
+ beforeEach(() => {
33
+ params.origintype = undefined
34
+ })
35
+
36
+ describe('when #cloudevent is not input', () => {
37
+ it('throws the proper error', () => {
38
+ params.cloudevent = undefined
39
+ const expected = 'Cloudevent "origintype" must be of type STRING'
40
+ expect(() => ce.origin(params)).to.throw(expected)
41
+ })
42
+ })
43
+
44
+ describe('when #cloudevent is input', () => {
45
+ describe('when #cloudevent#origintype does not exist', () => {
46
+ beforeEach(() => {
47
+ cloudevent.origintype = undefined
48
+ })
49
+
50
+ describe('when #cloudevent#type does not exist', () => {
51
+ it('throws the proper error', () => {
52
+ cloudevent.type = undefined
53
+ const expected = 'Cloudevent "origintype" must be of type STRING'
54
+ expect(() => ce.origin(params)).to.throw(expected)
55
+ })
56
+ })
57
+
58
+ describe('when #cloudevent#type does exist', () => {
59
+ it('returns the input #cloudevent#type', () => {
60
+ ce.origin(params)
61
+ expect(ce.origintype).to.eq(cloudevent.type)
62
+ })
63
+ })
64
+ })
65
+
66
+ describe('when #cloudevent#origintype exists', () => {
67
+ it('returns the input #cloudevent#origintype', () => {
68
+ const expected = 'some-new-origin-type'
69
+
70
+ cloudevent.origintype = expected
71
+ ce.origin(params)
72
+
73
+ expect(ce.origintype).to.eq(expected)
74
+ })
75
+ })
76
+ })
77
+ })
78
+
79
+ describe('when #origintype is input', () => {
80
+ it('returns the input value', () => {
81
+ ce.origin(params)
82
+ expect(ce.origintype).to.eq(params.origintype)
83
+ })
84
+ })
85
+ })
@@ -0,0 +1,13 @@
1
+ import { Cloudevent } from '../../../index.js'
2
+ import { expect } from 'chai'
3
+
4
+ describe('cloudevent.origin', () => {
5
+ it('returns itself', () => {
6
+ const ce = new Cloudevent({ source: 'some-source', type: 'some-type' })
7
+ const origin = new Cloudevent({ source: 'source-of-origin', type: 'type-of-origin' })
8
+
9
+ const result = ce.origin({ cloudevent: origin })
10
+
11
+ expect(result).to.eq(ce)
12
+ })
13
+ })
@@ -0,0 +1,13 @@
1
+ import { Cloudevent } from '../../../index.js'
2
+ import { expect } from 'chai'
3
+
4
+ describe('cloudevent.wschannel', () => {
5
+ it('returns itself', () => {
6
+ const ce = new Cloudevent({ source: 'some-source', type: 'some-type' })
7
+ const origin = new Cloudevent({ source: 'source-of-origin', type: 'type-of-origin' })
8
+
9
+ const result = ce.wschannel({ cloudevent: origin })
10
+
11
+ expect(result).to.eq(ce)
12
+ })
13
+ })
@@ -0,0 +1,51 @@
1
+ import { Cloudevent } from '../../../index.js'
2
+ import { expect } from 'chai'
3
+
4
+ describe('cloudevent.wschannel#wschannelid', () => {
5
+ let ce
6
+
7
+ beforeEach(() => {
8
+ ce = new Cloudevent({
9
+ source: 'some-source',
10
+ type: 'some-type',
11
+ })
12
+ })
13
+
14
+ describe('when #wschannelid is not input', () => {
15
+ describe('when #cloudevent is not input', () => {
16
+ it('returns undefined', () => {
17
+ ce.wschannel({})
18
+ expect(ce.wschannelid).to.be.undefined
19
+ })
20
+ })
21
+
22
+ describe('when #cloudevent is input', () => {
23
+ describe('when #cloudevent#wschannelid does not exist', () => {
24
+ it('returns undefined', () => {
25
+ const cloudevent = {}
26
+ ce.wschannel({ cloudevent })
27
+ expect(ce.wschannelid).to.be.undefined
28
+ })
29
+ })
30
+
31
+ describe('when #cloudevent#wschannelid does exist', () => {
32
+ it('returns #cloudevent#wschannelid', () => {
33
+ const expected = 'some-wschannel-id'
34
+
35
+ const cloudevent = { wschannelid: expected }
36
+ ce.wschannel({ cloudevent })
37
+
38
+ expect(ce.wschannelid).to.eq(expected)
39
+ })
40
+ })
41
+ })
42
+ })
43
+
44
+ describe('when #wschannelid is input', () => {
45
+ it('returns the input value', () => {
46
+ const expected = 'some-wschannel-id'
47
+ ce.wschannel({ wschannelid: expected })
48
+ expect(ce.wschannelid).to.eq(expected)
49
+ })
50
+ })
51
+ })
package/src/unit.test.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import chai, { expect } from 'chai'
2
2
  import chaiIso8601 from 'chai-iso8601'
3
3
  import chaiSubset from 'chai-subset'
4
- import { Cloudevent } from '../dist/index.cjs'
4
+ import { Cloudevent } from './index.js'
5
5
  import { useFakeTimers } from 'sinon'
6
6
 
7
7
  chai.use(chaiIso8601)
@@ -49,7 +49,7 @@ describe('new Cloudevent', () => {
49
49
  it('returns the expected cloudevent', () => {
50
50
  clock.tick(987654321) // * Jump into the future
51
51
 
52
- const originCloudevent = new Cloudevent({
52
+ const origin = new Cloudevent({
53
53
  data: JSON.stringify({ some: 'data' }),
54
54
  source: 'some-origin-source',
55
55
  type: 'some-origin-type',
@@ -57,35 +57,31 @@ describe('new Cloudevent', () => {
57
57
 
58
58
  clock.tick(123456789) // * Jump into the future
59
59
 
60
- const data = undefined
61
- const datacontenttype = undefined
62
60
  const source = 'some-enrichment-source'
63
61
  const time = new Date().toISOString()
64
62
  const type = 'some-enrichment-type'
63
+ const wschannelid = 'some-wschannel-id'
65
64
 
66
- const cloudevent = new Cloudevent({
67
- ...originCloudevent,
68
- data,
69
- datacontenttype,
70
- source,
71
- type,
72
-
73
- })
65
+ const cloudevent = new Cloudevent({ source, type })
66
+ .origin({ cloudevent: origin })
67
+ .wschannel({ wschannelid })
74
68
 
75
69
  clock.tick(987654321) // * Jump into the future
70
+
76
71
  expect(cloudevent).to.containSubset({
77
- data,
72
+ data: undefined,
78
73
  datacontenttype: undefined,
79
74
  dataschema: undefined,
80
- originid: originCloudevent.id,
81
- originsource: originCloudevent.source,
82
- origintime: originCloudevent.time,
83
- origintype: originCloudevent.type,
75
+ originid: origin.id,
76
+ originsource: origin.source,
77
+ origintime: origin.time,
78
+ origintype: origin.type,
84
79
  source,
85
80
  specversion: '1.0',
86
81
  subject: undefined,
87
82
  time,
88
83
  type,
84
+ wschannelid,
89
85
  })
90
86
  })
91
87
  })