@1mill/cloudevents 4.2.1 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -24
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +43 -24
- package/src/tests/{data.test.js → constructor/data.test.js} +1 -1
- package/src/tests/{datacontenttype.test.js → constructor/datacontenttype.test.js} +1 -1
- package/src/tests/{dataschema.test.js → constructor/dataschema.test.js} +1 -1
- package/src/tests/{id.test.js → constructor/id.test.js} +1 -1
- package/src/tests/{originatorid.test.js → constructor/originatorid.test.js} +1 -1
- package/src/tests/{originid.test.js → constructor/originid.test.js} +1 -1
- package/src/tests/{originsource.test.js → constructor/originsource.test.js} +1 -1
- package/src/tests/{origintime.test.js → constructor/origintime.test.js} +1 -1
- package/src/tests/{origintype.test.js → constructor/origintype.test.js} +1 -1
- package/src/tests/{source.test.js → constructor/source.test.js} +1 -1
- package/src/tests/{specversion.test.js → constructor/specversion.test.js} +1 -1
- package/src/tests/{subjest.test.js → constructor/subjest.test.js} +1 -1
- package/src/tests/{time.test.js → constructor/time.test.js} +1 -1
- package/src/tests/{type.test.js → constructor/type.test.js} +1 -1
- package/src/tests/{wschannelid.test.js → constructor/wschannelid.test.js} +1 -1
- package/src/tests/methods/origin/originid.test.js +85 -0
- package/src/tests/methods/origin/originsource.test.js +85 -0
- package/src/tests/methods/origin/origintime.test.js +85 -0
- package/src/tests/methods/origin/origintype.test.js +85 -0
- package/src/tests/methods/origin/unit.test.js +13 -0
- package/src/unit.test.js +9 -17
package/README.md
CHANGED
|
@@ -7,69 +7,70 @@ 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
|
|
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
|
|
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
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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(
|
|
29
|
+
console.log(cloudevent)
|
|
30
30
|
// {
|
|
31
|
-
// id: '
|
|
31
|
+
// id: '4qoAmUHbusWSZh3H9sCYa',
|
|
32
32
|
// source: 'https://github.com/1mill/cloudevents',
|
|
33
33
|
// type: 'cmd.do-this-command.v0',
|
|
34
34
|
// specversion: '1.0',
|
|
35
|
-
// time: '2022-09-
|
|
35
|
+
// time: '2022-09-20T23:29:50.419Z',
|
|
36
36
|
// data: '{"some":"payload"}',
|
|
37
37
|
// datacontenttype: 'application/json',
|
|
38
38
|
// dataschema: undefined,
|
|
39
39
|
// subject: undefined,
|
|
40
|
-
//
|
|
41
|
-
// originid: 'f_2R8OyOtfYW4YPs2SOdv',
|
|
40
|
+
// originid: '4qoAmUHbusWSZh3H9sCYa',
|
|
42
41
|
// originsource: 'https://github.com/1mill/cloudevents',
|
|
42
|
+
// origintime: '2022-09-20T23:29:50.419Z',
|
|
43
43
|
// origintype: 'cmd.do-this-command.v0',
|
|
44
|
-
// originatorid: 'user.id.1234'
|
|
44
|
+
// originatorid: 'user.id.1234',
|
|
45
|
+
// wschannelid: undefined
|
|
45
46
|
// }
|
|
46
47
|
|
|
47
48
|
const enrichedCloudevent = new Cloudevent({
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
})
|
|
49
|
+
data: JSON.stringify({ new: 'payload', value: true }),
|
|
50
|
+
source: 'https://www.erikekberg.com/',
|
|
51
|
+
type: 'fct.this-thing-happened.v0',
|
|
52
|
+
}).origin({ cloudevent })
|
|
53
53
|
console.log(enrichedCloudevent)
|
|
54
54
|
// {
|
|
55
|
-
// id: '
|
|
55
|
+
// id: 'piMl7GmKgY41dDew8_9OK',
|
|
56
56
|
// source: 'https://www.erikekberg.com/',
|
|
57
57
|
// type: 'fct.this-thing-happened.v0',
|
|
58
58
|
// specversion: '1.0',
|
|
59
|
-
// time: '2022-09-
|
|
59
|
+
// time: '2022-09-20T23:29:50.427Z',
|
|
60
60
|
// data: '{"new":"payload","value":true}',
|
|
61
61
|
// datacontenttype: 'application/json',
|
|
62
62
|
// dataschema: undefined,
|
|
63
63
|
// subject: undefined,
|
|
64
|
-
//
|
|
65
|
-
// originid: 'f_2R8OyOtfYW4YPs2SOdv',
|
|
64
|
+
// originid: '4qoAmUHbusWSZh3H9sCYa',
|
|
66
65
|
// originsource: 'https://github.com/1mill/cloudevents',
|
|
66
|
+
// origintime: '2022-09-20T23:29:50.419Z',
|
|
67
67
|
// origintype: 'cmd.do-this-command.v0',
|
|
68
|
-
// originatorid:
|
|
68
|
+
// originatorid: undefined,
|
|
69
|
+
// wschannelid: undefined
|
|
69
70
|
// }
|
|
70
71
|
```
|
|
71
72
|
|
|
72
|
-
|
|
|
73
|
+
| Attribute | Required | Type | Default | Notes |
|
|
73
74
|
|----------------- |---------- |-------- |------------------------------------- |------------------------------------------------------------------------------------------ |
|
|
74
75
|
| data | | Any | | |
|
|
75
76
|
| datacontenttype | | String | | If "data" is present, defaults to "application/json" unless specified otherwise |
|
|
@@ -85,6 +86,38 @@ console.log(enrichedCloudevent)
|
|
|
85
86
|
| originatorid | | String | | |
|
|
86
87
|
| wschannelid | | String | | |
|
|
87
88
|
|
|
89
|
+
### origin
|
|
90
|
+
|
|
91
|
+
Add origin attributes to a Cloudevent manually
|
|
92
|
+
|
|
93
|
+
```node
|
|
94
|
+
const cloudevent = new Cloudevent({
|
|
95
|
+
source: 'my-source',
|
|
96
|
+
type: 'my-type',
|
|
97
|
+
})
|
|
98
|
+
.origin({
|
|
99
|
+
originid: 'my-origin-id',
|
|
100
|
+
originsource: 'my-origin-source',
|
|
101
|
+
origintime: 'my-origin-time',
|
|
102
|
+
origintype: 'my-origin-type',
|
|
103
|
+
})
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
or populate them automatically by passing in an existing Cloudevent
|
|
107
|
+
|
|
108
|
+
```node
|
|
109
|
+
const originCloudevent = new Cloudevent({
|
|
110
|
+
source: 'my-origin-cloudevent',
|
|
111
|
+
type: 'cmd.say-hello.v0'
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const cloudevent = new Cloudevent({
|
|
115
|
+
data: JSON.stringify({ message: 'Hello world!' }),
|
|
116
|
+
source: 'my-enrichment-service',
|
|
117
|
+
type: 'fct.said-hello.v0',
|
|
118
|
+
}).origin({ cloudevent: originCloudevent })
|
|
119
|
+
```
|
|
120
|
+
|
|
88
121
|
## Release new version
|
|
89
122
|
|
|
90
123
|
```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},
|
|
1
|
+
var e=require("nanoid"),n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},i=function(e){var n=e.cloudevent,i=e.name,t=e.types,o=void 0===t?[]:t,r=e.value;if(o.length>0&&!o.includes(typeof r)){var a='Cloudevent "'+i+'" must be of type '+o.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(a)}n[i]=r};exports.Cloudevent=function(t){var o=this,r=t.data,a=t.datacontenttype,u=t.dataschema,s=t.originatorid,d=t.originid,v=t.originsource,c=t.origintime,l=t.origintype,g=t.source,p=t.specversion,y=t.subject,m=t.type,f=t.wschannelid;this.origin=function(e){var n=e.cloudevent,t=void 0===n?{}:n,r=e.originsource,a=e.origintime,u=e.origintype,s=o;return i({cloudevent:s,name:"originid",types:["string"],value:e.originid||t.originid||t.id}),i({cloudevent:s,name:"originsource",types:["string"],value:r||t.originsource||t.source}),i({cloudevent:s,name:"origintime",types:["string"],value:a||t.origintime||t.time}),i({cloudevent:s,name:"origintype",types:["string"],value:u||t.origintype||t.type}),s};var h=this,E=e.nanoid(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));i({cloudevent:h,name:"id",types:["string"],value:E});var L=g||n("MILL_CLOUDEVENTS_SOURCE");i({cloudevent:h,name:"source",types:["string"],value:L}),i({cloudevent:h,name:"type",types:["string"],value:m}),i({cloudevent:h,name:"specversion",types:["string"],value:p||"1.0"});var C=(new Date).toISOString();i({cloudevent:h,name:"time",types:["string"],value:C}),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:u}),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:s}),i({cloudevent:h,name:"wschannelid",types:["string","undefined"],value:f})};
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst 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\
|
|
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\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\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"],"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","_ref2$cloudevent","_this","ce","this","idValue","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"wBAAaA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ECHwBG,EAAG,YAAGC,IAAAA,EAAAA,EAAAA,WAAYL,EAA8BM,EAA9BN,KAAMO,EAAAA,EAAAA,MAAAA,OAAwB,IAAAC,EAAhB,GAAgBA,EAAZC,EAAAA,EAAAA,MAC5D,GAAIF,EAAMG,OAAS,IAAMH,EAA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,GAAU5B,EAAa,2BAC3CK,EAAa,CACZC,WAAAA,EACAL,KAAM,SACNO,MAAO,CAAC,UACRE,MAAO+B,IAIRpC,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNO,MAAO,CAAC,UACRE,MALiBqB,IASlB1B,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNO,MAAO,CAAC,UACRE,MALwBmB,GAAe,QAQxC,IAAMa,GAAY,IAAIC,MAAOC,cAC7BvC,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNO,MAAO,CAAC,UACRE,MAAOgC,IAMRrC,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,IAMRQ,KAAKL,OAAO,CACX3B,WAAAA,EACAkB,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDtB,EAAa,CACZC,WAAAA,EACAL,KAAM,eACNO,MAAO,CAAC,SAAU,aAClBE,MAAOa,IAGRlB,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNO,MAAO,CAAC,SAAU,aAClBE,MAAOsB,GAGR"}
|
package/dist/index.modern.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=(e,n)=>{if("undefined"!=typeof process)return process.env[e]||n},n=({cloudevent:e,name:n,types:t=[],value:
|
|
1
|
+
const e=(e,n)=>{if("undefined"!=typeof process)return process.env[e]||n},n=({cloudevent:e,name:n,types:t=[],value:i})=>{if(t.length>0&&!t.includes(typeof i)){const e=`Cloudevent "${n}" must be of type ${t.map(e=>e.toUpperCase()).sort().join(" or ")}.`;throw new Error(e)}e[n]=i};class t{constructor({data:t,datacontenttype:i,dataschema:o,originatorid:r,originid:s,originsource:a,origintime:u,origintype:d,source:c,specversion:g,subject:l,type:p,wschannelid:v}){this.origin=({cloudevent:e={},originid:t,originsource:i,origintime:o,origintype:r})=>{const s=this;return n({cloudevent:s,name:"originid",types:["string"],value:t||e.originid||e.id}),n({cloudevent:s,name:"originsource",types:["string"],value:i||e.originsource||e.source}),n({cloudevent:s,name:"origintime",types:["string"],value:o||e.origintime||e.time}),n({cloudevent:s,name:"origintype",types:["string"],value:r||e.origintype||e.type}),s};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}),n({cloudevent:y,name:"type",types:["string"],value:p}),n({cloudevent:y,name:"specversion",types:["string"],value:g||"1.0"});const h=(new Date).toISOString();n({cloudevent:y,name:"time",types:["string"],value:h}),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:l}),this.origin({cloudevent:y,originid:s,originsource:a,origintime:u,origintype:d}),n({cloudevent:y,name:"originatorid",types:["string","undefined"],value:r}),n({cloudevent:y,name:"wschannelid",types:["string","undefined"],value:v})}}export{t as Cloudevent};
|
|
2
2
|
//# sourceMappingURL=index.modern.js.map
|
package/dist/index.modern.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.modern.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js","../node_modules/nanoid/index.browser.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst 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\
|
|
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\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\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","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","_cloudevent","idValue","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"AAAO,MAAkBA,EAAG,CAACC,EAAMC,KAClC,GAAuB,oBAAnBC,QACJ,OAAOA,QAAQC,IAAIH,IAASC,GCFhBG,EAAe,EAAGC,aAAYL,OAAMM,MAAAA,EAAQ,GAAIC,YAC5D,GAAID,EAAME,OAAS,IAAMF,EAAMG,gBAANF,GAA8B,CACtD,MAAaG,EAAI,eAAcV,sBAAyBM,EAAMK,IAAIC,GAAKA,EAAEC,eAAeC,OAAOC,KAAK,WACpG,MAAM,UAAUL,EAChB,CACDL,EAAWL,GAAQO,GCDb,MAAiBS,EACvBC,aAAYC,KACXA,EADWC,gBAEXA,EAFWC,WAGXA,EAHWC,aAIXA,EACAC,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,EARWC,OASXA,EATWC,YAUXA,EAVWC,QAWXA,EAXWC,KAYXA,EAZWC,YAaXA,IA6GDC,KAAAA,OAAS,EAAG1B,WAAAA,EAAa,CAAf,EAAmBiB,WAAUC,eAAcC,aAAYC,iBAChE,MAAQO,EAAGC,KAkCX,OA/BA7B,EAAa,CACZC,WAAY2B,EACZhC,KAAM,WACNM,MAAO,CAAC,UACRC,MALqBe,GAAYjB,EAAU,UAAgBA,EAAU,KAStED,EAAa,CACZC,WAAY2B,EACZhC,KAAM,eACNM,MAAO,CAAC,UACRC,MALyBgB,GAAgBlB,EAAU,cAAoB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BC,MAAOqB,IAMRK,KAAKF,OAAO,CACX1B,WAAAA,EACAiB,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDrB,EAAa,CACZC,WAAAA,EACAL,KAAM,eACNM,MAAO,CAAC,SAAU,aAClBC,MAAOc,IAGRjB,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNM,MAAO,CAAC,SAAU,aAClBC,MAAOuB,GAGR"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{nanoid as e}from"nanoid";var n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},
|
|
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,u=t.dataschema,s=t.originatorid,d=t.originid,v=t.originsource,c=t.origintime,g=t.origintype,l=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,u=e.origintype,s=o;return i({cloudevent:s,name:"originid",types:["string"],value:e.originid||t.originid||t.id}),i({cloudevent:s,name:"originsource",types:["string"],value:r||t.originsource||t.source}),i({cloudevent:s,name:"origintime",types:["string"],value:a||t.origintime||t.time}),i({cloudevent:s,name:"origintype",types:["string"],value:u||t.origintype||t.type}),s};var h=this,E=e(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));i({cloudevent:h,name:"id",types:["string"],value:E});var L=l||n("MILL_CLOUDEVENTS_SOURCE");i({cloudevent:h,name:"source",types:["string"],value:L}),i({cloudevent:h,name:"type",types:["string"],value:y}),i({cloudevent:h,name:"specversion",types:["string"],value:p||"1.0"});var w=(new Date).toISOString();i({cloudevent:h,name:"time",types:["string"],value:w}),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:u}),i({cloudevent:h,name:"subject",types:["string","undefined"],value:m}),this.origin({cloudevent:h,originid:d,originsource:v,origintime:c,origintype:g}),i({cloudevent:h,name:"originatorid",types:["string","undefined"],value:s}),i({cloudevent:h,name:"wschannelid",types:["string","undefined"],value:f})};export{t as Cloudevent};
|
|
2
2
|
//# sourceMappingURL=index.module.js.map
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.module.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst 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\
|
|
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\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\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"],"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","origin","_ref2","_ref2$cloudevent","_this","ce","this","idValue","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"gCAAaA,IAAAA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ECHwBG,EAAG,YAAGC,IAAAA,EAAAA,EAAAA,WAAYL,EAA8BM,EAA9BN,KAAMO,EAAAA,EAAAA,MAAAA,OAAwB,IAAAC,EAAhB,GAAgBA,EAAZC,EAAAA,EAAAA,MAC5D,GAAIF,EAAMG,OAAS,IAAMH,EAAMI,gBAANF,GAA8B,CACtD,IAAaG,EAAA,eAAkBZ,EAAlB,qBAA2CO,EAAMM,IAAI,SAAAC,GAAKA,OAAAA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,YACpG,UAAMC,MAAUN,EAChB,CACDP,EAAWL,GAAQS,CACnB,ECFYU,EACZ,SAAAb,GACCc,IAAAA,EAAAA,KAAAA,EAAAA,EAAAA,KACAC,EAYEf,EAZFe,gBACAC,EAAAA,EAAAA,WACAC,IAAAA,aACAC,EASElB,EATFkB,SACAC,EAQEnB,EARFmB,aACAC,EAAAA,EAAAA,WACAC,EAMErB,EANFqB,WACAC,EAAAA,EAAAA,OACAC,EAAAA,EAAAA,YACAC,IAAAA,QACAC,EAEEzB,EAFFyB,KACAC,EAAAA,EAAAA,iBA6GDC,OAAS,SAAyEC,GAAA,IAAAC,EAAAD,EAAtE7B,WAAAA,OAAsE,IAAA8B,EAAzD,GAAIX,EAAUC,EAA2CS,EAA3CT,aAAcC,EAAAA,EAAAA,WAAYC,EAAAA,EAAAA,aACrDS,EAkC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E,MAAOqB,IAMRQ,KAAKL,OAAO,CACX5B,WAAAA,EACAmB,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDvB,EAAa,CACZC,WAAAA,EACAL,KAAM,eACNO,MAAO,CAAC,SAAU,aAClBE,MAAOc,IAGRnB,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNO,MAAO,CAAC,SAAU,aAClBE,MAAOuB,GAGR"}
|
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,
|
|
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 u='Cloudevent "'+t+'" must be of type '+o.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(u)}n[t]=r};e.Cloudevent=function(e){var i=this,o=e.data,r=e.datacontenttype,u=e.dataschema,a=e.originatorid,s=e.originid,d=e.originsource,c=e.origintime,v=e.origintype,l=e.source,p=e.specversion,g=e.subject,y=e.type,m=e.wschannelid;this.origin=function(e){var n=e.cloudevent,o=void 0===n?{}:n,r=e.originsource,u=e.origintime,a=e.origintype,s=i;return t({cloudevent:s,name:"originid",types:["string"],value:e.originid||o.originid||o.id}),t({cloudevent:s,name:"originsource",types:["string"],value:r||o.originsource||o.source}),t({cloudevent:s,name:"origintime",types:["string"],value:u||o.origintime||o.time}),t({cloudevent:s,name:"origintype",types:["string"],value:a||o.origintype||o.type}),s};var f=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:f,name:"id",types:["string"],value:h});var C=l||n("MILL_CLOUDEVENTS_SOURCE");t({cloudevent:f,name:"source",types:["string"],value:C}),t({cloudevent:f,name:"type",types:["string"],value:y}),t({cloudevent:f,name:"specversion",types:["string"],value:p||"1.0"});var E=(new Date).toISOString();t({cloudevent:f,name:"time",types:["string"],value:E}),t({cloudevent:f,name:"data",value:o}),t({cloudevent:f,name:"datacontenttype",types:["string","undefined"],value:void 0!==o?r||"application/json":r}),t({cloudevent:f,name:"dataschema",types:["string","undefined"],value:u}),t({cloudevent:f,name:"subject",types:["string","undefined"],value:g}),this.origin({cloudevent:f,originid:s,originsource:d,origintime:c,origintype:v}),t({cloudevent:f,name:"originatorid",types:["string","undefined"],value:a}),t({cloudevent:f,name:"wschannelid",types:["string","undefined"],value:m})}});
|
|
2
2
|
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js","../node_modules/nanoid/index.browser.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst 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\
|
|
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\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\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","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","_ref2$cloudevent","_this","ce","this","idValue","size","crypto","getRandomValues","Uint8Array","reduce","id","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ACAkB,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDtB,EAAa,CACZC,WAAAA,EACAL,KAAM,eACNO,MAAO,CAAC,SAAU,aAClBE,MAAOa,IAGRlB,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNO,MAAO,CAAC,SAAU,aAClBE,MAAOsB,GAGR"}
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -98,31 +98,12 @@ export class Cloudevent {
|
|
|
98
98
|
|
|
99
99
|
// *******
|
|
100
100
|
// * Required in-house extentions
|
|
101
|
-
|
|
102
|
-
setAttribute({
|
|
103
|
-
cloudevent,
|
|
104
|
-
name: 'origintime',
|
|
105
|
-
types: ['string'],
|
|
106
|
-
value: origintimeValue
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
const originidValue = originid || idValue
|
|
110
|
-
setAttribute({
|
|
101
|
+
this.origin({
|
|
111
102
|
cloudevent,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const originsourceValue = originsource || sourceValue
|
|
118
|
-
setAttribute({ cloudevent, name: 'originsource', types: ['string'], value: originsourceValue })
|
|
119
|
-
|
|
120
|
-
const origintypeValue = origintype || typeValue
|
|
121
|
-
setAttribute({
|
|
122
|
-
cloudevent,
|
|
123
|
-
name: 'origintype',
|
|
124
|
-
types: ['string'],
|
|
125
|
-
value: origintypeValue
|
|
103
|
+
originid,
|
|
104
|
+
originsource,
|
|
105
|
+
origintime,
|
|
106
|
+
origintype,
|
|
126
107
|
})
|
|
127
108
|
// *******
|
|
128
109
|
|
|
@@ -143,4 +124,42 @@ export class Cloudevent {
|
|
|
143
124
|
})
|
|
144
125
|
// *******
|
|
145
126
|
}
|
|
127
|
+
|
|
128
|
+
origin = ({ cloudevent = {}, originid, originsource, origintime, origintype }) => {
|
|
129
|
+
const ce = this
|
|
130
|
+
|
|
131
|
+
const originidValue = originid || cloudevent['originid'] || cloudevent['id']
|
|
132
|
+
setAttribute({
|
|
133
|
+
cloudevent: ce,
|
|
134
|
+
name: 'originid',
|
|
135
|
+
types: ['string'],
|
|
136
|
+
value: originidValue,
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
const originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']
|
|
140
|
+
setAttribute({
|
|
141
|
+
cloudevent: ce,
|
|
142
|
+
name: 'originsource',
|
|
143
|
+
types: ['string'],
|
|
144
|
+
value: originsourceValue,
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
const origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']
|
|
148
|
+
setAttribute({
|
|
149
|
+
cloudevent: ce,
|
|
150
|
+
name: 'origintime',
|
|
151
|
+
types: ['string'],
|
|
152
|
+
value: origintimeValue,
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
const origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']
|
|
156
|
+
setAttribute({
|
|
157
|
+
cloudevent: ce,
|
|
158
|
+
name: 'origintype',
|
|
159
|
+
types: ['string'],
|
|
160
|
+
value: origintypeValue,
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
return ce
|
|
164
|
+
}
|
|
146
165
|
}
|
|
@@ -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
|
+
})
|
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 '
|
|
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
|
|
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,30 +57,22 @@ 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'
|
|
65
63
|
|
|
66
|
-
const cloudevent = new Cloudevent({
|
|
67
|
-
...originCloudevent,
|
|
68
|
-
data,
|
|
69
|
-
datacontenttype,
|
|
70
|
-
source,
|
|
71
|
-
type,
|
|
72
|
-
|
|
73
|
-
})
|
|
64
|
+
const cloudevent = new Cloudevent({ source, type }).origin({ cloudevent: origin })
|
|
74
65
|
|
|
75
66
|
clock.tick(987654321) // * Jump into the future
|
|
67
|
+
|
|
76
68
|
expect(cloudevent).to.containSubset({
|
|
77
|
-
data,
|
|
69
|
+
data: undefined,
|
|
78
70
|
datacontenttype: undefined,
|
|
79
71
|
dataschema: undefined,
|
|
80
|
-
originid:
|
|
81
|
-
originsource:
|
|
82
|
-
origintime:
|
|
83
|
-
origintype:
|
|
72
|
+
originid: origin.id,
|
|
73
|
+
originsource: origin.source,
|
|
74
|
+
origintime: origin.time,
|
|
75
|
+
origintype: origin.type,
|
|
84
76
|
source,
|
|
85
77
|
specversion: '1.0',
|
|
86
78
|
subject: undefined,
|