@1mill/cloudevents 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -1
- package/README.md +2 -2
- 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 +85 -13
- package/src/tests/datacontenttype.test.js +8 -8
- package/src/tests/dataschema.test.js +1 -1
- package/src/tests/id.test.js +1 -1
- package/src/tests/originatorid.test.js +2 -2
- package/src/tests/originid.test.js +1 -1
- package/src/tests/originsource.test.js +1 -1
- package/src/tests/origintime.test.js +1 -1
- package/src/tests/origintype.test.js +1 -1
- package/src/tests/source.test.js +1 -1
- package/src/tests/subjest.test.js +1 -1
- package/src/tests/time.test.js +1 -1
- package/src/tests/wschannelid.test.js +39 -0
- package/src/utils/setAttribute/unit.test.js +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
# Changelog for @1mill/cloudevents
|
|
2
2
|
|
|
3
|
+
## 4.2.0
|
|
4
|
+
|
|
5
|
+
* Add optional `wschannelid` attribute.
|
|
6
|
+
* Fix unit test description.
|
|
7
|
+
|
|
8
|
+
## 4.1.1
|
|
9
|
+
|
|
10
|
+
* Improve formatting of code.
|
|
11
|
+
* Update `README.md`.
|
|
12
|
+
|
|
3
13
|
## 4.1.0
|
|
4
14
|
|
|
5
|
-
* Add
|
|
15
|
+
* Add optional `originatorid` attribute.
|
|
6
16
|
* Add unit tests for every Cloudevent attribute (e.g. `id`, `data`, `originid`, etc.) using `mocha`, `sinon`, and `chai`.
|
|
17
|
+
* Update `nanoid@^3.3.4`
|
|
7
18
|
|
|
8
19
|
## 4.0.1
|
|
9
20
|
|
package/README.md
CHANGED
|
@@ -4,11 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
This is an implementation and extention of the [CloudEvents v1 specification](https://github.com/cloudevents/spec) to easily build cloudevents with origin history.
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
## Install
|
|
9
8
|
|
|
10
9
|
```html
|
|
11
|
-
<script src="https://unpkg.com/@1mill/cloudevents@4.
|
|
10
|
+
<script src="https://unpkg.com/@1mill/cloudevents@4.1.1/dist/index.umd.js">
|
|
12
11
|
```
|
|
13
12
|
|
|
14
13
|
or
|
|
@@ -84,6 +83,7 @@ console.log(enrichedCloudevent)
|
|
|
84
83
|
| origintime | yes | String | "time" property | "time" property is internally generated as part of the package |
|
|
85
84
|
| origintype | yes | String | "type" property | |
|
|
86
85
|
| originatorid | | String | | |
|
|
86
|
+
| wschannelid | | String | | |
|
|
87
87
|
|
|
88
88
|
## Release new version
|
|
89
89
|
|
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,
|
|
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})};
|
|
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}) {\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({
|
|
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","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,ECHYG,EAAe,gBAAGC,IAAAA,WAAYL,IAAAA,SAAMM,MAAAA,aAAQ,KAAIC,IAAAA,MAC5D,GAAID,EAAME,OAAS,IAAMF,EAAMG,gBAAgBF,GAAQ,CACtD,IAAMG,iBAAyBV,uBAAyBM,EAAMK,IAAI,SAAAC,UAAKA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,YACpG,UAAUC,MAAMN,EAChB,CACDL,EAAWL,GAAQO,CACnB,qBCDA,gBACCU,IAAAA,KACAC,IAAAA,gBACAC,IAAAA,WACAC,IAAAA,aACAC,IAAAA,SACAC,IAAAA,aACAC,IAAAA,WACAC,IAAAA,WACAC,IAAAA,OACAC,IAAAA,YACAC,IAAAA,QACAC,IAAAA,KACAC,IAAAA,YAEMxB,EAAayB,KAIbC,EAAUC,SAAOjC,EAAa,iCAAkC,KACtEK,EAAa,CACZC,WAAAA,EACAL,KAAM,KACNM,MAAO,CAAC,UACRC,MAAOwB,IAGR,IAAME,EAAcR,GAAU1B,EAAa,2BAC3CK,EAAa,CACZC,WAAAA,EACAL,KAAM,SACNM,MAAO,CAAC,UACRC,MAAO0B,IAGR,IAAMC,EAAYN,EAClBxB,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAO2B,IAIR9B,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNM,MAAO,CAAC,UACRC,MALwBmB,GAAe,QAQxC,IAAMS,GAAY,IAAIC,MAAOC,cAC7BjC,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAO4B,IAMR/B,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNO,MAAOU,IAMRb,EAAa,CACZC,WAAAA,EACAL,KAAM,kBACNM,MAAO,CAAC,SAAU,aAClBC,WAP4C,IAATU,EACjCC,GAAmB,mBACnBA,IAQHd,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,SAAU,aAClBC,MAAOY,IAGRf,EAAa,CACZC,WAAAA,EACAL,KAAM,UACNM,MAAO,CAAC,SAAU,aAClBC,MAAOoB,IAORvB,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBgB,GAAcY,IAStC/B,EAAa,CACZC,WAAAA,EACAL,KAAM,WACNM,MAAO,CAAC,UACRC,MALqBc,GAAYU,IASlC3B,EAAa,CAAEC,WAAAA,EAAYL,KAAM,eAAgBM,MAAO,CAAC,UAAWC,MAD1Ce,GAAgBW,IAI1C7B,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBiB,GAAcU,IAWtC9B,EAAa,CACZC,WAAAA,EACAL,KAAM,eACNM,MAAO,CAAC,SAAU,aAClBC,MAAOa,IAGRhB,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNM,MAAO,CAAC,SAAU,aAClBC,MAAOsB,GAGR"}
|
package/dist/index.modern.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=(e,
|
|
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};
|
|
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}) {\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({
|
|
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","Error","Cloudevent","constructor","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":"MAAaA,EAAe,CAACC,EAAMC,KAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,GCFhBG,EAAe,EAAGC,aAAYL,OAAMM,MAAAA,EAAQ,GAAIC,YAC5D,GAAID,EAAME,OAAS,IAAMF,EAAMG,gBAAgBF,GAAQ,CACtD,MAAMG,EAAW,eAAcV,sBAAyBM,EAAMK,IAAIC,GAAKA,EAAEC,eAAeC,OAAOC,KAAK,WACpG,UAAUC,MAAMN,EAChB,CACDL,EAAWL,GAAQO,SCDPU,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,MAAM1B,EAAa2B,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,IAAI5B,cACtB2B,EAAO,GACV,IAEA,KAGP,IDRaE,CAAO3C,EAAa,iCAAkC,KACtEK,EAAa,CACZC,aACAL,KAAM,KACNM,MAAO,CAAC,UACRC,MAAO0B,IAGR,MAAMU,EAAchB,GAAU5B,EAAa,2BAC3CK,EAAa,CACZC,aACAL,KAAM,SACNM,MAAO,CAAC,UACRC,MAAOoC,IAGR,MAAMC,EAAYd,EAClB1B,EAAa,CACZC,aACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAOqC,IAIRxC,EAAa,CACZC,aACAL,KAAM,cACNM,MAAO,CAAC,UACRC,MALwBqB,GAAe,QAQxC,MAAMiB,GAAY,IAAIC,MAAOC,cAC7B3C,EAAa,CACZC,aACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAOsC,IAMRzC,EAAa,CACZC,aACAL,KAAM,OACNO,MAAOY,IAMRf,EAAa,CACZC,aACAL,KAAM,kBACNM,MAAO,CAAC,SAAU,aAClBC,WAP4C,IAATY,EACjCC,GAAmB,mBACnBA,IAQHhB,EAAa,CACZC,aACAL,KAAM,aACNM,MAAO,CAAC,SAAU,aAClBC,MAAOc,IAGRjB,EAAa,CACZC,aACAL,KAAM,UACNM,MAAO,CAAC,SAAU,aAClBC,MAAOsB,IAORzB,EAAa,CACZC,aACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBkB,GAAcoB,IAStCzC,EAAa,CACZC,aACAL,KAAM,WACNM,MAAO,CAAC,UACRC,MALqBgB,GAAYU,IASlC7B,EAAa,CAAEC,aAAYL,KAAM,eAAgBM,MAAO,CAAC,UAAWC,MAD1CiB,GAAgBmB,IAI1CvC,EAAa,CACZC,aACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBmB,GAAckB,IAWtCxC,EAAa,CACZC,aACAL,KAAM,eACNM,MAAO,CAAC,SAAU,aAClBC,MAAOe,IAGRlB,EAAa,CACZC,aACAL,KAAM,cACNM,MAAO,CAAC,SAAU,aAClBC,MAAOwB,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},t=function(e){var n=e.cloudevent,t=e.name,i=e.types,
|
|
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};
|
|
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}) {\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({
|
|
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","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":"oCAAaA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ECHYG,EAAe,gBAAGC,IAAAA,WAAYL,IAAAA,SAAMM,MAAAA,aAAQ,KAAIC,IAAAA,MAC5D,GAAID,EAAME,OAAS,IAAMF,EAAMG,gBAAgBF,GAAQ,CACtD,IAAMG,iBAAyBV,uBAAyBM,EAAMK,IAAI,SAAAC,UAAKA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,YACpG,UAAUC,MAAMN,EAChB,CACDL,EAAWL,GAAQO,CACnB,ECFYU,EACZ,gBACCC,IAAAA,KACAC,IAAAA,gBACAC,IAAAA,WACAC,IAAAA,aACAC,IAAAA,SACAC,IAAAA,aACAC,IAAAA,WACAC,IAAAA,WACAC,IAAAA,OACAC,IAAAA,YACAC,IAAAA,QACAC,IAAAA,KACAC,IAAAA,YAEMzB,EAAa0B,KAIbC,EAAUC,EAAOlC,EAAa,iCAAkC,KACtEK,EAAa,CACZC,WAAAA,EACAL,KAAM,KACNM,MAAO,CAAC,UACRC,MAAOyB,IAGR,IAAME,EAAcR,GAAU3B,EAAa,2BAC3CK,EAAa,CACZC,WAAAA,EACAL,KAAM,SACNM,MAAO,CAAC,UACRC,MAAO2B,IAGR,IAAMC,EAAYN,EAClBzB,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAO4B,IAIR/B,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNM,MAAO,CAAC,UACRC,MALwBoB,GAAe,QAQxC,IAAMS,GAAY,IAAIC,MAAOC,cAC7BlC,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAO6B,IAMRhC,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNO,MAAOW,IAMRd,EAAa,CACZC,WAAAA,EACAL,KAAM,kBACNM,MAAO,CAAC,SAAU,aAClBC,WAP4C,IAATW,EACjCC,GAAmB,mBACnBA,IAQHf,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,SAAU,aAClBC,MAAOa,IAGRhB,EAAa,CACZC,WAAAA,EACAL,KAAM,UACNM,MAAO,CAAC,SAAU,aAClBC,MAAOqB,IAORxB,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBiB,GAAcY,IAStChC,EAAa,CACZC,WAAAA,EACAL,KAAM,WACNM,MAAO,CAAC,UACRC,MALqBe,GAAYU,IASlC5B,EAAa,CAAEC,WAAAA,EAAYL,KAAM,eAAgBM,MAAO,CAAC,UAAWC,MAD1CgB,GAAgBW,IAI1C9B,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBkB,GAAcU,IAWtC/B,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.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,
|
|
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})}});
|
|
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}) {\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({
|
|
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","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":"yOAAaA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ECHYG,EAAe,gBAAGC,IAAAA,WAAYL,IAAAA,SAAMM,MAAAA,aAAQ,KAAIC,IAAAA,MAC5D,GAAID,EAAME,OAAS,IAAMF,EAAMG,gBAAgBF,GAAQ,CACtD,IAAMG,iBAAyBV,uBAAyBM,EAAMK,IAAI,SAAAC,UAAKA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,YACpG,UAAUC,MAAMN,EAChB,CACDL,EAAWL,GAAQO,CACnB,eCDA,gBACCU,IAAAA,KACAC,IAAAA,gBACAC,IAAAA,WACAC,IAAAA,aACAC,IAAAA,SACAC,IAAAA,aACAC,IAAAA,WACAC,IAAAA,WACAC,IAAAA,OACAC,IAAAA,YACAC,IAAAA,QACAC,IAAAA,KACAC,IAAAA,YAEMxB,EAAayB,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,CAAOzC,EAAa,iCAAkC,KACtEK,EAAa,CACZC,WAAAA,EACAL,KAAM,KACNM,MAAO,CAAC,UACRC,MAAOwB,IAGR,IAAMU,EAAchB,GAAU1B,EAAa,2BAC3CK,EAAa,CACZC,WAAAA,EACAL,KAAM,SACNM,MAAO,CAAC,UACRC,MAAOkC,IAGR,IAAMC,EAAYd,EAClBxB,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAOmC,IAIRtC,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNM,MAAO,CAAC,UACRC,MALwBmB,GAAe,QAQxC,IAAMiB,GAAY,IAAIC,MAAOC,cAC7BzC,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAOoC,IAMRvC,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNO,MAAOU,IAMRb,EAAa,CACZC,WAAAA,EACAL,KAAM,kBACNM,MAAO,CAAC,SAAU,aAClBC,WAP4C,IAATU,EACjCC,GAAmB,mBACnBA,IAQHd,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,SAAU,aAClBC,MAAOY,IAGRf,EAAa,CACZC,WAAAA,EACAL,KAAM,UACNM,MAAO,CAAC,SAAU,aAClBC,MAAOoB,IAORvB,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBgB,GAAcoB,IAStCvC,EAAa,CACZC,WAAAA,EACAL,KAAM,WACNM,MAAO,CAAC,UACRC,MALqBc,GAAYU,IASlC3B,EAAa,CAAEC,WAAAA,EAAYL,KAAM,eAAgBM,MAAO,CAAC,UAAWC,MAD1Ce,GAAgBmB,IAI1CrC,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBiB,GAAckB,IAWtCtC,EAAa,CACZC,WAAAA,EACAL,KAAM,eACNM,MAAO,CAAC,SAAU,aAClBC,MAAOa,IAGRhB,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNM,MAAO,CAAC,SAAU,aAClBC,MAAOsB,GAGR"}
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -16,59 +16,131 @@ export class Cloudevent {
|
|
|
16
16
|
specversion,
|
|
17
17
|
subject,
|
|
18
18
|
type,
|
|
19
|
+
wschannelid,
|
|
19
20
|
}) {
|
|
20
21
|
const cloudevent = this
|
|
21
22
|
|
|
22
23
|
// *******
|
|
23
24
|
// * Required fields by Cloudevent v1 specification
|
|
24
25
|
const idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))
|
|
25
|
-
setAttribute({
|
|
26
|
+
setAttribute({
|
|
27
|
+
cloudevent,
|
|
28
|
+
name: 'id',
|
|
29
|
+
types: ['string'],
|
|
30
|
+
value: idValue
|
|
31
|
+
})
|
|
26
32
|
|
|
27
33
|
const sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')
|
|
28
|
-
setAttribute({
|
|
34
|
+
setAttribute({
|
|
35
|
+
cloudevent,
|
|
36
|
+
name: 'source',
|
|
37
|
+
types: ['string'],
|
|
38
|
+
value: sourceValue
|
|
39
|
+
})
|
|
29
40
|
|
|
30
41
|
const typeValue = type
|
|
31
|
-
setAttribute({
|
|
42
|
+
setAttribute({
|
|
43
|
+
cloudevent,
|
|
44
|
+
name: 'type',
|
|
45
|
+
types: ['string'],
|
|
46
|
+
value: typeValue
|
|
47
|
+
})
|
|
32
48
|
|
|
33
49
|
const specversionValue = specversion || '1.0'
|
|
34
|
-
setAttribute({
|
|
50
|
+
setAttribute({
|
|
51
|
+
cloudevent,
|
|
52
|
+
name: 'specversion',
|
|
53
|
+
types: ['string'],
|
|
54
|
+
value: specversionValue
|
|
55
|
+
})
|
|
35
56
|
|
|
36
57
|
const timeValue = new Date().toISOString()
|
|
37
|
-
setAttribute({
|
|
58
|
+
setAttribute({
|
|
59
|
+
cloudevent,
|
|
60
|
+
name: 'time',
|
|
61
|
+
types: ['string'],
|
|
62
|
+
value: timeValue
|
|
63
|
+
})
|
|
38
64
|
// *******
|
|
39
65
|
|
|
40
66
|
// *******
|
|
41
67
|
// * Optional fields by Cloudevent v1 specification
|
|
42
|
-
setAttribute({
|
|
68
|
+
setAttribute({
|
|
69
|
+
cloudevent,
|
|
70
|
+
name: 'data',
|
|
71
|
+
value: data
|
|
72
|
+
})
|
|
43
73
|
|
|
44
74
|
const datacontenttypeValue = typeof data !== 'undefined'
|
|
45
75
|
? datacontenttype || 'application/json'
|
|
46
76
|
: datacontenttype
|
|
47
|
-
setAttribute({
|
|
77
|
+
setAttribute({
|
|
78
|
+
cloudevent,
|
|
79
|
+
name: 'datacontenttype',
|
|
80
|
+
types: ['string', 'undefined'],
|
|
81
|
+
value: datacontenttypeValue
|
|
82
|
+
})
|
|
48
83
|
|
|
49
|
-
setAttribute({
|
|
84
|
+
setAttribute({
|
|
85
|
+
cloudevent,
|
|
86
|
+
name: 'dataschema',
|
|
87
|
+
types: ['string', 'undefined'],
|
|
88
|
+
value: dataschema
|
|
89
|
+
})
|
|
50
90
|
|
|
51
|
-
setAttribute({
|
|
91
|
+
setAttribute({
|
|
92
|
+
cloudevent,
|
|
93
|
+
name: 'subject',
|
|
94
|
+
types: ['string', 'undefined'],
|
|
95
|
+
value: subject
|
|
96
|
+
})
|
|
52
97
|
// *******
|
|
53
98
|
|
|
54
99
|
// *******
|
|
55
100
|
// * Required in-house extentions
|
|
56
101
|
const origintimeValue = origintime || timeValue
|
|
57
|
-
setAttribute({
|
|
102
|
+
setAttribute({
|
|
103
|
+
cloudevent,
|
|
104
|
+
name: 'origintime',
|
|
105
|
+
types: ['string'],
|
|
106
|
+
value: origintimeValue
|
|
107
|
+
})
|
|
58
108
|
|
|
59
109
|
const originidValue = originid || idValue
|
|
60
|
-
setAttribute({
|
|
110
|
+
setAttribute({
|
|
111
|
+
cloudevent,
|
|
112
|
+
name: 'originid',
|
|
113
|
+
types: ['string'],
|
|
114
|
+
value: originidValue
|
|
115
|
+
})
|
|
61
116
|
|
|
62
117
|
const originsourceValue = originsource || sourceValue
|
|
63
118
|
setAttribute({ cloudevent, name: 'originsource', types: ['string'], value: originsourceValue })
|
|
64
119
|
|
|
65
120
|
const origintypeValue = origintype || typeValue
|
|
66
|
-
setAttribute({
|
|
121
|
+
setAttribute({
|
|
122
|
+
cloudevent,
|
|
123
|
+
name: 'origintype',
|
|
124
|
+
types: ['string'],
|
|
125
|
+
value: origintypeValue
|
|
126
|
+
})
|
|
67
127
|
// *******
|
|
68
128
|
|
|
69
129
|
// *******
|
|
70
130
|
// * Optional in-house extentions
|
|
71
|
-
setAttribute({
|
|
131
|
+
setAttribute({
|
|
132
|
+
cloudevent,
|
|
133
|
+
name: 'originatorid',
|
|
134
|
+
types: ['string', 'undefined'],
|
|
135
|
+
value: originatorid
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
setAttribute({
|
|
139
|
+
cloudevent,
|
|
140
|
+
name: 'wschannelid',
|
|
141
|
+
types: ['string', 'undefined'],
|
|
142
|
+
value: wschannelid
|
|
143
|
+
})
|
|
72
144
|
// *******
|
|
73
145
|
}
|
|
74
146
|
}
|
|
@@ -55,6 +55,14 @@ describe('cloudevent#datacontenttype', () => {
|
|
|
55
55
|
describe('when #datacontenttype is input', () => {
|
|
56
56
|
const validValues = ['some-string', undefined]
|
|
57
57
|
|
|
58
|
+
describe(`when #datacontenttype is not of type ${validValues.map(item => typeof item).join(' or ')}`, () => {
|
|
59
|
+
it('throws the proper error', () => {
|
|
60
|
+
const expected = `Cloudevent "datacontenttype" must be of type STRING or UNDEFINED`
|
|
61
|
+
params.datacontenttype = 1234
|
|
62
|
+
expect(() => new Cloudevent(params)).to.throw(expected)
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
|
|
58
66
|
validValues.forEach(value => {
|
|
59
67
|
describe(`when #datacontenttype is a ${typeof value}`, () => {
|
|
60
68
|
it('returns the input value', () => {
|
|
@@ -64,14 +72,6 @@ describe('cloudevent#datacontenttype', () => {
|
|
|
64
72
|
})
|
|
65
73
|
})
|
|
66
74
|
})
|
|
67
|
-
|
|
68
|
-
describe(`when #datacontenttype is not of type ${validValues.map(item => typeof item).join(' or ')}`, () => {
|
|
69
|
-
it('throws the proper error', () => {
|
|
70
|
-
const expected = `Cloudevent "datacontenttype" must be of type STRING or UNDEFINED`
|
|
71
|
-
params.datacontenttype = 1234
|
|
72
|
-
expect(() => new Cloudevent(params)).to.throw(expected)
|
|
73
|
-
})
|
|
74
|
-
})
|
|
75
75
|
})
|
|
76
76
|
})
|
|
77
77
|
})
|
|
@@ -29,7 +29,7 @@ describe('cloudevent#dataschema', () => {
|
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
describe('when the input value is valid', () => {
|
|
32
|
-
it('
|
|
32
|
+
it('returns the input value', () => {
|
|
33
33
|
params.dataschema = 'some-string'
|
|
34
34
|
const { dataschema } = new Cloudevent(params)
|
|
35
35
|
expect(dataschema).to.eq(params.dataschema)
|
package/src/tests/id.test.js
CHANGED
|
@@ -33,7 +33,7 @@ describe('cloudevent#id', () => {
|
|
|
33
33
|
|
|
34
34
|
describe('when process.env.MILL_CLOUDEVENTS_NANOID_LENGTH is input', () => {
|
|
35
35
|
it('returns a string with the proper length', () => {
|
|
36
|
-
const expected =
|
|
36
|
+
const expected = 123
|
|
37
37
|
|
|
38
38
|
const env = { MILL_CLOUDEVENTS_NANOID_LENGTH: expected }
|
|
39
39
|
sandbox.stub(process, 'env').value(env)
|
|
@@ -13,7 +13,7 @@ describe('cloudevent#originatorid', () => {
|
|
|
13
13
|
})
|
|
14
14
|
|
|
15
15
|
describe('when #originatorid is not input', () => {
|
|
16
|
-
it('returns
|
|
16
|
+
it('returns undefined', () => {
|
|
17
17
|
const { originatorid } = new Cloudevent(params)
|
|
18
18
|
expect(originatorid).to.be.undefined
|
|
19
19
|
})
|
|
@@ -29,7 +29,7 @@ describe('cloudevent#originatorid', () => {
|
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
describe('when the input value is valid', () => {
|
|
32
|
-
it('
|
|
32
|
+
it('returns the input value', () => {
|
|
33
33
|
params.originatorid = 'some-originator-id'
|
|
34
34
|
const { originatorid } = new Cloudevent(params)
|
|
35
35
|
expect(originatorid).to.eq(params.originatorid)
|
|
@@ -30,7 +30,7 @@ describe('cloudevent#originid', () => {
|
|
|
30
30
|
})
|
|
31
31
|
|
|
32
32
|
describe('when the input value is valid', () => {
|
|
33
|
-
it('
|
|
33
|
+
it('returns the input value', () => {
|
|
34
34
|
params.originid = 'some-origin-id'
|
|
35
35
|
const { originid } = new Cloudevent(params)
|
|
36
36
|
expect(originid).to.eq(params.originid)
|
|
@@ -30,7 +30,7 @@ describe('cloudevent#originsource', () => {
|
|
|
30
30
|
})
|
|
31
31
|
|
|
32
32
|
describe('when the input value is valid', () => {
|
|
33
|
-
it('
|
|
33
|
+
it('returns the input value', () => {
|
|
34
34
|
params.originsource = 'some-origin-source'
|
|
35
35
|
const { originsource } = new Cloudevent(params)
|
|
36
36
|
expect(originsource).to.eq(params.originsource)
|
|
@@ -29,7 +29,7 @@ describe('cloudevent#origintime', () => {
|
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
describe('when the input value is valid', () => {
|
|
32
|
-
it('
|
|
32
|
+
it('returns the input value', () => {
|
|
33
33
|
params.origintime = new Date().toISOString()
|
|
34
34
|
const { origintime } = new Cloudevent(params)
|
|
35
35
|
expect(origintime).to.eq(params.origintime)
|
|
@@ -30,7 +30,7 @@ describe('cloudevent#origintype', () => {
|
|
|
30
30
|
})
|
|
31
31
|
|
|
32
32
|
describe('when the input value is valtype', () => {
|
|
33
|
-
it('
|
|
33
|
+
it('returns the input value', () => {
|
|
34
34
|
params.origintype = 'some-origin-type'
|
|
35
35
|
const { origintype } = new Cloudevent(params)
|
|
36
36
|
expect(origintype).to.eq(params.origintype)
|
package/src/tests/source.test.js
CHANGED
|
@@ -32,7 +32,7 @@ describe('cloudevent#source', () => {
|
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
describe('when process.env.MILL_CLOUDEVENTS_SOURCE is input', () => {
|
|
35
|
-
it('returns the input
|
|
35
|
+
it('returns the input value', () => {
|
|
36
36
|
const expected = 'some-env-var-value'
|
|
37
37
|
|
|
38
38
|
const env = { MILL_CLOUDEVENTS_SOURCE: expected }
|
|
@@ -29,7 +29,7 @@ describe('cloudevent#subject', () => {
|
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
describe('when the input value is valid', () => {
|
|
32
|
-
it('
|
|
32
|
+
it('returns the input value', () => {
|
|
33
33
|
params.subject = 'some-string'
|
|
34
34
|
const { subject } = new Cloudevent(params)
|
|
35
35
|
expect(subject).to.eq(params.subject)
|
package/src/tests/time.test.js
CHANGED
|
@@ -21,7 +21,7 @@ describe('cloudevent#time', () => {
|
|
|
21
21
|
expect(time).to.be.a('string')
|
|
22
22
|
})
|
|
23
23
|
|
|
24
|
-
it('returns the current
|
|
24
|
+
it('returns the current datetime in ISO8601 format', () => {
|
|
25
25
|
const clock = useFakeTimers()
|
|
26
26
|
|
|
27
27
|
clock.tick(987654321) // * Jump into the future
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Cloudevent } from '../index.js'
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
|
|
4
|
+
describe('cloudevent#wschannelid', () => {
|
|
5
|
+
let params
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
params = {
|
|
9
|
+
// * Required base defaults
|
|
10
|
+
source: 'some-source',
|
|
11
|
+
type: 'some-type',
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
describe('when #wschannelid is not input', () => {
|
|
16
|
+
it('returns undefined', () => {
|
|
17
|
+
const { wschannelid } = new Cloudevent(params)
|
|
18
|
+
expect(wschannelid).to.be.undefined
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
describe('when #wschannelid is input', () => {
|
|
23
|
+
describe('when the input value is invalid', () => {
|
|
24
|
+
it('throws the proper error', () => {
|
|
25
|
+
const expected = 'Cloudevent "wschannelid" must be of type STRING or UNDEFINED'
|
|
26
|
+
params.wschannelid = 1234
|
|
27
|
+
expect(() => new Cloudevent(params)).to.throw(expected)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
describe('when the input value is valid', () => {
|
|
32
|
+
it('returns the input value', () => {
|
|
33
|
+
params.wschannelid = 'some-wschannel-id'
|
|
34
|
+
const { wschannelid } = new Cloudevent(params)
|
|
35
|
+
expect(wschannelid).to.eq(params.wschannelid)
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
})
|
|
@@ -9,6 +9,15 @@ describe('setAttribute', () => {
|
|
|
9
9
|
cloudevent = {}
|
|
10
10
|
})
|
|
11
11
|
|
|
12
|
+
describe('when #types is empty', () => {
|
|
13
|
+
[1234, '1234', undefined].forEach(value => {
|
|
14
|
+
it('sets cloudevent[#name] to the input #value', () => {
|
|
15
|
+
setAttribute({ cloudevent, name, value })
|
|
16
|
+
expect(cloudevent[name]).to.eq(value)
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
|
|
12
21
|
describe('when #types is not empty', () => {
|
|
13
22
|
describe('when the type of #value is not in #types', () => {
|
|
14
23
|
it('throws the proper error', () => {
|
|
@@ -31,13 +40,4 @@ describe('setAttribute', () => {
|
|
|
31
40
|
})
|
|
32
41
|
})
|
|
33
42
|
})
|
|
34
|
-
|
|
35
|
-
describe('when #types is empty', () => {
|
|
36
|
-
[1234, '1234', undefined].forEach(value => {
|
|
37
|
-
it('sets cloudevent[#name] to the input #value', () => {
|
|
38
|
-
setAttribute({ cloudevent, name, value })
|
|
39
|
-
expect(cloudevent[name]).to.eq(value)
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
43
|
})
|