@1mill/cloudevents 4.6.2 → 5.0.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 +46 -111
- package/dist/bundle-browser/cloudevents.esm.js +2 -0
- package/dist/bundle-browser/cloudevents.esm.js.map +1 -0
- package/dist/bundle-browser/cloudevents.umd.js +2 -0
- package/dist/bundle-browser/cloudevents.umd.js.map +1 -0
- package/dist/bundle-node/cloudevents.cjs +2 -0
- package/dist/bundle-node/cloudevents.cjs.map +1 -0
- package/dist/bundle-node/cloudevents.esm.js +2 -0
- package/dist/bundle-node/cloudevents.esm.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/tests/constructor/actor.test.d.ts +1 -0
- package/dist/tests/constructor/data.test.d.ts +1 -0
- package/dist/tests/constructor/datacontenttype.test.d.ts +1 -0
- package/dist/tests/constructor/dataschema.test.d.ts +1 -0
- package/dist/tests/constructor/id.test.d.ts +1 -0
- package/dist/tests/constructor/originid.test.d.ts +1 -0
- package/dist/tests/constructor/originsource.test.d.ts +1 -0
- package/dist/tests/constructor/origintime.test.d.ts +1 -0
- package/dist/tests/constructor/origintype.test.d.ts +1 -0
- package/dist/tests/constructor/source.test.d.ts +1 -0
- package/dist/tests/constructor/specversion.test.d.ts +1 -0
- package/dist/tests/constructor/subjest.test.d.ts +1 -0
- package/dist/tests/constructor/time.test.d.ts +1 -0
- package/dist/tests/constructor/type.test.d.ts +1 -0
- package/dist/tests/constructor/wschannelid.test.d.ts +1 -0
- package/dist/utils/cloudevent.d.ts +30 -0
- package/dist/utils/cloudevent.test.d.ts +1 -0
- package/dist/utils/fetchNodeEnv.d.ts +1 -0
- package/dist/utils/fetchNodeEnv.test.d.ts +1 -0
- package/dist/utils/validateAttribute.d.ts +13 -0
- package/dist/utils/validateAttribute.test.d.ts +1 -0
- package/package.json +33 -17
- package/CHANGELOG.md +0 -66
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.modern.js +0 -2
- package/dist/index.modern.js.map +0 -1
- package/dist/index.module.js +0 -2
- package/dist/index.module.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
- package/src/index.js +0 -197
- package/src/tests/constructor/data.test.js +0 -29
- package/src/tests/constructor/datacontenttype.test.js +0 -77
- package/src/tests/constructor/dataschema.test.js +0 -39
- package/src/tests/constructor/id.test.js +0 -45
- package/src/tests/constructor/originactor.test.js +0 -39
- package/src/tests/constructor/originatorid.test.js +0 -39
- package/src/tests/constructor/originid.test.js +0 -40
- package/src/tests/constructor/originsource.test.js +0 -40
- package/src/tests/constructor/origintime.test.js +0 -39
- package/src/tests/constructor/origintype.test.js +0 -40
- package/src/tests/constructor/source.test.js +0 -63
- package/src/tests/constructor/specversion.test.js +0 -41
- package/src/tests/constructor/subjest.test.js +0 -39
- package/src/tests/constructor/time.test.js +0 -36
- package/src/tests/constructor/type.test.js +0 -39
- package/src/tests/constructor/wschannelid.test.js +0 -39
- package/src/tests/methods/origin/originactor.test.js +0 -74
- package/src/tests/methods/origin/originid.test.js +0 -85
- package/src/tests/methods/origin/originsource.test.js +0 -85
- package/src/tests/methods/origin/origintime.test.js +0 -85
- package/src/tests/methods/origin/origintype.test.js +0 -85
- package/src/tests/methods/origin/unit.test.js +0 -13
- package/src/tests/methods/originator/originatorid.test.js +0 -51
- package/src/tests/methods/originator/unit.test.js +0 -10
- package/src/tests/methods/wschannel/unit.test.js +0 -10
- package/src/tests/methods/wschannel/wschannelid.test.js +0 -51
- package/src/unit.test.js +0 -91
- package/src/utils/fetchNodeEnv/index.js +0 -4
- package/src/utils/fetchNodeEnv/unit.test.js +0 -55
- package/src/utils/setAttribute/index.js +0 -10
- package/src/utils/setAttribute/unit.test.js +0 -67
package/dist/index.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var e=require("nanoid"),n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},i=function(e){var n=e.cloudevent,i=e.deprecated,t=e.name,o=e.types,r=void 0===o?[]:o,a=e.value;if(void 0!==i&&i&&console.warn('Cloudevent "'+t+'" is depricated'),r.length>0&&!r.includes(typeof a)){var d='Cloudevent "'+t+'" must be of type '+r.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(d)}n[t]=a};exports.Cloudevent=function(t){var o=this,r=t.data,a=t.datacontenttype,d=t.dataschema,u=t.originactor,s=t.originatorid,c=t.originid,v=t.originsource,l=t.origintime,g=t.origintype,p=t.source,y=t.specversion,m=t.subject,f=t.type,h=t.wschannelid;this.origin=function(e){var n=e.cloudevent,t=void 0===n?{}:n,r=e.originid,a=e.originsource,d=e.origintime,u=e.origintype,s=o;return i({cloudevent:s,name:"originactor",types:["string","undefined"],value:e.originactor||t.originactor}),i({cloudevent:s,name:"originid",types:["string"],value:r||t.originid||t.id}),i({cloudevent:s,name:"originsource",types:["string"],value:a||t.originsource||t.source}),i({cloudevent:s,name:"origintime",types:["string"],value:d||t.origintime||t.time}),i({cloudevent:s,name:"origintype",types:["string"],value:u||t.origintype||t.type}),s},this.originator=function(e){var n=e.cloudevent,t=o;return i({cloudevent:t,name:"originatorid",types:["string","undefined"],value:e.originatorid||(void 0===n?{}:n).originatorid}),t},this.wschannel=function(e){var n=e.cloudevent,t=o;return i({cloudevent:t,name:"wschannelid",types:["string","undefined"],value:e.wschannelid||(void 0===n?{}:n).wschannelid}),t};var w=this,C=e.nanoid(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));i({cloudevent:w,name:"id",types:["string"],value:C});var E=p||n("MILL_CLOUDEVENTS_SOURCE");i({cloudevent:w,name:"source",types:["string"],value:E}),i({cloudevent:w,name:"type",types:["string"],value:f}),i({cloudevent:w,name:"specversion",types:["string"],value:y||"1.0"});var L=(new Date).toISOString();i({cloudevent:w,name:"time",types:["string"],value:L}),i({cloudevent:w,name:"data",value:r}),i({cloudevent:w,name:"datacontenttype",types:["string","undefined"],value:void 0!==r?a||"application/json":a}),i({cloudevent:w,name:"dataschema",types:["string","undefined"],value:d}),i({cloudevent:w,name:"subject",types:["string","undefined"],value:m}),this.origin({cloudevent:w,originactor:u,originid:c,originsource:v,origintime:l,origintype:g}),this.originator({cloudevent:w,originatorid:s}),this.wschannel({cloudevent:w,wschannelid:h})};
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, deprecated = false, name, types = [], value }) => {\r\n\tif (deprecated) { console.warn(`Cloudevent \"${name}\" is depricated`) }\r\n\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginactor,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst ce = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tthis.origin({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginactor,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tthis.originator({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginatorid,\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent: ce,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originactor, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originactorValue = originactor || cloudevent['originactor']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originactor',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originactorValue,\r\n\t\t})\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\toriginator = ({ cloudevent = {}, originatorid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid || cloudevent['originatorid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","_ref","cloudevent","deprecated","_ref$types","types","value","_ref$deprecated","console","warn","length","includes","message","map","s","toUpperCase","sort","join","data","datacontenttype","dataschema","originactor","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","this","origin","_ref2","_ref2$cloudevent","ce","_this","setAttribute","originator","_ref3","_ref3$cloudevent","wschannel","_ref4","_ref4$cloudevent","idValue","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"wBAAaA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ICH2B,SAAiEG,GAAA,MAA9DC,EAAAA,eAAYC,WAAoBN,EAA8BI,EAA9BJ,KAA8BO,EAAAH,EAAxBI,MAAAA,OA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aACNQ,MAAO,CAAC,SAAU,aAClBC,MAAOc,IAGRkB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,UACNQ,MAAO,CAAC,SAAU,aAClBC,MAAOuB,IAMRG,KAAKC,OAAO,CACX/B,WAAYkC,EACZf,YAAAA,EACAE,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDM,KAAKO,WAAW,CACfrC,WAAYkC,EACZd,aAAAA,IAGDU,KAAKU,UAAU,CACdxC,WAAYkC,EACZL,YAAAA,GAGD"}
|
package/dist/index.modern.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=(e,n)=>{if("undefined"!=typeof process)return process.env[e]||n},n=({cloudevent:e,deprecated:n=!1,name:t,types:i=[],value:o})=>{if(n&&console.warn(`Cloudevent "${t}" is depricated`),i.length>0&&!i.includes(typeof o)){const e=`Cloudevent "${t}" must be of type ${i.map(e=>e.toUpperCase()).sort().join(" or ")}.`;throw new Error(e)}e[t]=o};class t{constructor({data:t,datacontenttype:i,dataschema:o,originactor:r,originatorid:s,originid:a,originsource:d,origintime:c,origintype:u,source:l,specversion:g,subject:v,type:p,wschannelid:y}){this.origin=({cloudevent:e={},originactor:t,originid:i,originsource:o,origintime:r,origintype:s})=>{const a=this;return n({cloudevent:a,name:"originactor",types:["string","undefined"],value:t||e.originactor}),n({cloudevent:a,name:"originid",types:["string"],value:i||e.originid||e.id}),n({cloudevent:a,name:"originsource",types:["string"],value:o||e.originsource||e.source}),n({cloudevent:a,name:"origintime",types:["string"],value:r||e.origintime||e.time}),n({cloudevent:a,name:"origintype",types:["string"],value:s||e.origintype||e.type}),a},this.originator=({cloudevent:e={},originatorid:t})=>(n({cloudevent:this,name:"originatorid",types:["string","undefined"],value:t||e.originatorid}),this),this.wschannel=({cloudevent:e={},wschannelid:t})=>(n({cloudevent:this,name:"wschannelid",types:["string","undefined"],value:t||e.wschannelid}),this);const m=this,h=((e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((e,n)=>e+((n&=63)<36?n.toString(36):n<62?(n-26).toString(36).toUpperCase():n>62?"-":"_"),""))(e("MILL_CLOUDEVENTS_NANOID_LENGTH",21));n({cloudevent:m,name:"id",types:["string"],value:h});const f=l||e("MILL_CLOUDEVENTS_SOURCE");n({cloudevent:m,name:"source",types:["string"],value:f}),n({cloudevent:m,name:"type",types:["string"],value:p}),n({cloudevent:m,name:"specversion",types:["string"],value:g||"1.0"});const w=(new Date).toISOString();n({cloudevent:m,name:"time",types:["string"],value:w}),n({cloudevent:m,name:"data",value:t}),n({cloudevent:m,name:"datacontenttype",types:["string","undefined"],value:void 0!==t?i||"application/json":i}),n({cloudevent:m,name:"dataschema",types:["string","undefined"],value:o}),n({cloudevent:m,name:"subject",types:["string","undefined"],value:v}),this.origin({cloudevent:m,originactor:r,originid:a,originsource:d,origintime:c,origintype:u}),this.originator({cloudevent:m,originatorid:s}),this.wschannel({cloudevent:m,wschannelid:y})}}export{t as Cloudevent};
|
|
2
|
-
//# sourceMappingURL=index.modern.js.map
|
package/dist/index.modern.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.modern.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js","../node_modules/nanoid/index.browser.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, deprecated = false, name, types = [], value }) => {\r\n\tif (deprecated) { console.warn(`Cloudevent \"${name}\" is depricated`) }\r\n\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginactor,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst ce = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tthis.origin({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginactor,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tthis.originator({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginatorid,\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent: ce,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originactor, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originactorValue = originactor || cloudevent['originactor']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originactor',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originactorValue,\r\n\t\t})\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\toriginator = ({ cloudevent = {}, originatorid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid || cloudevent['originatorid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nlet customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nlet nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","cloudevent","deprecated","types","value","console","warn","length","includes","message","map","s","toUpperCase","sort","join","Cloudevent","constructor","data","datacontenttype","dataschema","originactor","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","origin","ce","this","setAttribute","originator","wschannel","_ce","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","idValue","sourceValue","timeValue","Date","toISOString"],"mappings":"AAAO,MAAkBA,EAAG,CAACC,EAAMC,KAClC,GAAuB,oBAAnBC,QACJ,OAAOA,QAAQC,IAAIH,IAASC,KCFD,EAAGG,aAAYC,WAAAA,GAAa,EAAOL,OAAMM,MAAAA,EAAQ,GAAIC,YAGhF,GAFIF,GAAcG,QAAQC,KAAM,eAAcT,oBAE1CM,EAAMI,OAAS,IAAMJ,EAAMK,gBAAgBJ,GAAQ,CACtD,MAAaK,EAAI,eAAcZ,sBAAyBM,EAAMO,IAAIC,GAAKA,EAAEC,eAAeC,OAAOC,KAAK,WACpG,MAAM,UAAUL,EAChB,CAEDR,EAAWJ,GAAQO,CAAAA,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,0 @@
|
|
|
1
|
-
import{nanoid as e}from"nanoid";var n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},i=function(e){var n=e.cloudevent,i=e.deprecated,t=e.name,o=e.types,r=void 0===o?[]:o,a=e.value;if(void 0!==i&&i&&console.warn('Cloudevent "'+t+'" is depricated'),r.length>0&&!r.includes(typeof a)){var d='Cloudevent "'+t+'" must be of type '+r.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(d)}n[t]=a},t=function(t){var o=this,r=t.data,a=t.datacontenttype,d=t.dataschema,s=t.originactor,u=t.originatorid,c=t.originid,v=t.originsource,l=t.origintime,g=t.origintype,p=t.source,m=t.specversion,y=t.subject,f=t.type,h=t.wschannelid;this.origin=function(e){var n=e.cloudevent,t=void 0===n?{}:n,r=e.originid,a=e.originsource,d=e.origintime,s=e.origintype,u=o;return i({cloudevent:u,name:"originactor",types:["string","undefined"],value:e.originactor||t.originactor}),i({cloudevent:u,name:"originid",types:["string"],value:r||t.originid||t.id}),i({cloudevent:u,name:"originsource",types:["string"],value:a||t.originsource||t.source}),i({cloudevent:u,name:"origintime",types:["string"],value:d||t.origintime||t.time}),i({cloudevent:u,name:"origintype",types:["string"],value:s||t.origintype||t.type}),u},this.originator=function(e){var n=e.cloudevent,t=o;return i({cloudevent:t,name:"originatorid",types:["string","undefined"],value:e.originatorid||(void 0===n?{}:n).originatorid}),t},this.wschannel=function(e){var n=e.cloudevent,t=o;return i({cloudevent:t,name:"wschannelid",types:["string","undefined"],value:e.wschannelid||(void 0===n?{}:n).wschannelid}),t};var w=this,E=e(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));i({cloudevent:w,name:"id",types:["string"],value:E});var L=p||n("MILL_CLOUDEVENTS_SOURCE");i({cloudevent:w,name:"source",types:["string"],value:L}),i({cloudevent:w,name:"type",types:["string"],value:f}),i({cloudevent:w,name:"specversion",types:["string"],value:m||"1.0"});var C=(new Date).toISOString();i({cloudevent:w,name:"time",types:["string"],value:C}),i({cloudevent:w,name:"data",value:r}),i({cloudevent:w,name:"datacontenttype",types:["string","undefined"],value:void 0!==r?a||"application/json":a}),i({cloudevent:w,name:"dataschema",types:["string","undefined"],value:d}),i({cloudevent:w,name:"subject",types:["string","undefined"],value:y}),this.origin({cloudevent:w,originactor:s,originid:c,originsource:v,origintime:l,origintype:g}),this.originator({cloudevent:w,originatorid:u}),this.wschannel({cloudevent:w,wschannelid:h})};export{t as Cloudevent};
|
|
2
|
-
//# sourceMappingURL=index.module.js.map
|
package/dist/index.module.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.module.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, deprecated = false, name, types = [], value }) => {\r\n\tif (deprecated) { console.warn(`Cloudevent \"${name}\" is depricated`) }\r\n\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginactor,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst ce = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tthis.origin({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginactor,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tthis.originator({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginatorid,\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent: ce,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originactor, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originactorValue = originactor || cloudevent['originactor']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originactor',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originactorValue,\r\n\t\t})\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\toriginator = ({ cloudevent = {}, originatorid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid || cloudevent['originatorid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","_ref","cloudevent","deprecated","_ref$types","types","value","_ref$deprecated","console","warn","length","includes","message","map","s","toUpperCase","sort","join","data","datacontenttype","dataschema","originactor","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","this","origin","_ref2","_ref2$cloudevent","ce","_this","setAttribute","originator","_ref3","_ref3$cloudevent","wschannel","_ref4","_ref4$cloudevent","idValue","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"gCAAaA,IAAAA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,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AAO,CAAC,SAAU,aAClBC,WAP4C,IAATY,EACjCC,GAAmB,mBACnBA,IAQHmB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,aACNQ,MAAO,CAAC,SAAU,aAClBC,MAAOc,IAGRkB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,UACNQ,MAAO,CAAC,SAAU,aAClBC,MAAOuB,IAMRG,KAAKC,OAAO,CACX/B,WAAYkC,EACZf,YAAAA,EACAE,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDM,KAAKO,WAAW,CACfrC,WAAYkC,EACZd,aAAAA,IAGDU,KAAKU,UAAU,CACdxC,WAAYkC,EACZL,YAAAA,GAGD"}
|
package/dist/index.umd.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).cloudevents={})}(this,function(e){var n=function(e,n){if("undefined"!=typeof process)return process.env[e]||n},i=function(e){var n=e.cloudevent,i=e.deprecated,t=e.name,o=e.types,r=void 0===o?[]:o,a=e.value;if(void 0!==i&&i&&console.warn('Cloudevent "'+t+'" is depricated'),r.length>0&&!r.includes(typeof a)){var d='Cloudevent "'+t+'" must be of type '+r.map(function(e){return e.toUpperCase()}).sort().join(" or ")+".";throw new Error(d)}n[t]=a};e.Cloudevent=function(e){var t=this,o=e.data,r=e.datacontenttype,a=e.dataschema,d=e.originactor,s=e.originatorid,u=e.originid,c=e.originsource,v=e.origintime,l=e.origintype,g=e.source,p=e.specversion,y=e.subject,f=e.type,m=e.wschannelid;this.origin=function(e){var n=e.cloudevent,o=void 0===n?{}:n,r=e.originid,a=e.originsource,d=e.origintime,s=e.origintype,u=t;return i({cloudevent:u,name:"originactor",types:["string","undefined"],value:e.originactor||o.originactor}),i({cloudevent:u,name:"originid",types:["string"],value:r||o.originid||o.id}),i({cloudevent:u,name:"originsource",types:["string"],value:a||o.originsource||o.source}),i({cloudevent:u,name:"origintime",types:["string"],value:d||o.origintime||o.time}),i({cloudevent:u,name:"origintype",types:["string"],value:s||o.origintype||o.type}),u},this.originator=function(e){var n=e.cloudevent,o=t;return i({cloudevent:o,name:"originatorid",types:["string","undefined"],value:e.originatorid||(void 0===n?{}:n).originatorid}),o},this.wschannel=function(e){var n=e.cloudevent,o=t;return i({cloudevent:o,name:"wschannelid",types:["string","undefined"],value:e.wschannelid||(void 0===n?{}:n).wschannelid}),o};var h=this,w=((e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((e,n)=>e+((n&=63)<36?n.toString(36):n<62?(n-26).toString(36).toUpperCase():n>62?"-":"_"),""))(n("MILL_CLOUDEVENTS_NANOID_LENGTH",21));i({cloudevent:h,name:"id",types:["string"],value:w});var C=g||n("MILL_CLOUDEVENTS_SOURCE");i({cloudevent:h,name:"source",types:["string"],value:C}),i({cloudevent:h,name:"type",types:["string"],value:f}),i({cloudevent:h,name:"specversion",types:["string"],value:p||"1.0"});var E=(new Date).toISOString();i({cloudevent:h,name:"time",types:["string"],value:E}),i({cloudevent:h,name:"data",value:o}),i({cloudevent:h,name:"datacontenttype",types:["string","undefined"],value:void 0!==o?r||"application/json":r}),i({cloudevent:h,name:"dataschema",types:["string","undefined"],value:a}),i({cloudevent:h,name:"subject",types:["string","undefined"],value:y}),this.origin({cloudevent:h,originactor:d,originid:u,originsource:c,origintime:v,origintype:l}),this.originator({cloudevent:h,originatorid:s}),this.wschannel({cloudevent:h,wschannelid:m})}});
|
|
2
|
-
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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, deprecated = false, name, types = [], value }) => {\r\n\tif (deprecated) { console.warn(`Cloudevent \"${name}\" is depricated`) }\r\n\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginactor,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t\twschannelid,\r\n\t}) {\r\n\t\tconst ce = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tthis.origin({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginactor,\r\n\t\t\toriginid,\r\n\t\t\toriginsource,\r\n\t\t\torigintime,\r\n\t\t\torigintype,\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tthis.originator({\r\n\t\t\tcloudevent: ce,\r\n\t\t\toriginatorid,\r\n\t\t})\r\n\r\n\t\tthis.wschannel({\r\n\t\t\tcloudevent: ce,\r\n\t\t\twschannelid,\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n\r\n\torigin = ({ cloudevent = {}, originactor, originid, originsource, origintime, origintype }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tconst originactorValue = originactor || cloudevent['originactor']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originactor',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originactorValue,\r\n\t\t})\r\n\r\n\t\tconst originidValue = originid || cloudevent['originid'] || cloudevent['id']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue,\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originsource',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originsourceValue,\r\n\t\t})\r\n\r\n\t\tconst origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue,\r\n\t\t})\r\n\r\n\t\tconst origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue,\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\toriginator = ({ cloudevent = {}, originatorid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid || cloudevent['originatorid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n\r\n\twschannel = ({ cloudevent = {}, wschannelid }) => {\r\n\t\tconst ce = this\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent: ce,\r\n\t\t\tname: 'wschannelid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: wschannelid || cloudevent['wschannelid'],\r\n\t\t})\r\n\r\n\t\treturn ce\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nlet customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nlet nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","_ref","cloudevent","deprecated","_ref$types","types","value","_ref$deprecated","console","warn","length","includes","message","map","s","toUpperCase","sort","join","data","datacontenttype","dataschema","originactor","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","wschannelid","this","origin","_ref2","_ref2$cloudevent","ce","_this","setAttribute","originator","_ref3","_ref3$cloudevent","wschannel","_ref4","_ref4$cloudevent","idValue","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","sourceValue","timeValue","Date","toISOString"],"mappings":"qOAAaA,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C,WAAYkC,EACZvC,KAAM,cACNQ,MAAO,CAAC,UACRC,MALwBsB,GAAe,QAQxC,IAAM4B,GAAY,IAAIC,MAAOC,cAC7BpB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,OACNQ,MAAO,CAAC,UACRC,MAAOkD,IAMRlB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,OACNS,MAAOY,IAMRoB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,kBACNQ,MAAO,CAAC,SAAU,aAClBC,WAP4C,IAATY,EACjCC,GAAmB,mBACnBA,IAQHmB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,aACNQ,MAAO,CAAC,SAAU,aAClBC,MAAOc,IAGRkB,EAAa,CACZpC,WAAYkC,EACZvC,KAAM,UACNQ,MAAO,CAAC,SAAU,aAClBC,MAAOuB,IAMRG,KAAKC,OAAO,CACX/B,WAAYkC,EACZf,YAAAA,EACAE,SAAAA,EACAC,aAAAA,EACAC,WAAAA,EACAC,WAAAA,IAMDM,KAAKO,WAAW,CACfrC,WAAYkC,EACZd,aAAAA,IAGDU,KAAKU,UAAU,CACdxC,WAAYkC,EACZL,YAAAA,GAGD"}
|
package/src/index.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'
|
|
2
|
-
import { nanoid } from 'nanoid'
|
|
3
|
-
import { setAttribute } from './utils/setAttribute/index.js'
|
|
4
|
-
|
|
5
|
-
export class Cloudevent {
|
|
6
|
-
constructor({
|
|
7
|
-
data,
|
|
8
|
-
datacontenttype,
|
|
9
|
-
dataschema,
|
|
10
|
-
originactor,
|
|
11
|
-
originatorid,
|
|
12
|
-
originid,
|
|
13
|
-
originsource,
|
|
14
|
-
origintime,
|
|
15
|
-
origintype,
|
|
16
|
-
source,
|
|
17
|
-
specversion,
|
|
18
|
-
subject,
|
|
19
|
-
type,
|
|
20
|
-
wschannelid,
|
|
21
|
-
}) {
|
|
22
|
-
const ce = this
|
|
23
|
-
|
|
24
|
-
// *******
|
|
25
|
-
// * Required fields by Cloudevent v1 specification
|
|
26
|
-
const idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))
|
|
27
|
-
setAttribute({
|
|
28
|
-
cloudevent: ce,
|
|
29
|
-
name: 'id',
|
|
30
|
-
types: ['string'],
|
|
31
|
-
value: idValue
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
const sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')
|
|
35
|
-
setAttribute({
|
|
36
|
-
cloudevent: ce,
|
|
37
|
-
name: 'source',
|
|
38
|
-
types: ['string'],
|
|
39
|
-
value: sourceValue
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
const typeValue = type
|
|
43
|
-
setAttribute({
|
|
44
|
-
cloudevent: ce,
|
|
45
|
-
name: 'type',
|
|
46
|
-
types: ['string'],
|
|
47
|
-
value: typeValue
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
const specversionValue = specversion || '1.0'
|
|
51
|
-
setAttribute({
|
|
52
|
-
cloudevent: ce,
|
|
53
|
-
name: 'specversion',
|
|
54
|
-
types: ['string'],
|
|
55
|
-
value: specversionValue
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
const timeValue = new Date().toISOString()
|
|
59
|
-
setAttribute({
|
|
60
|
-
cloudevent: ce,
|
|
61
|
-
name: 'time',
|
|
62
|
-
types: ['string'],
|
|
63
|
-
value: timeValue
|
|
64
|
-
})
|
|
65
|
-
// *******
|
|
66
|
-
|
|
67
|
-
// *******
|
|
68
|
-
// * Optional fields by Cloudevent v1 specification
|
|
69
|
-
setAttribute({
|
|
70
|
-
cloudevent: ce,
|
|
71
|
-
name: 'data',
|
|
72
|
-
value: data
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
const datacontenttypeValue = typeof data !== 'undefined'
|
|
76
|
-
? datacontenttype || 'application/json'
|
|
77
|
-
: datacontenttype
|
|
78
|
-
setAttribute({
|
|
79
|
-
cloudevent: ce,
|
|
80
|
-
name: 'datacontenttype',
|
|
81
|
-
types: ['string', 'undefined'],
|
|
82
|
-
value: datacontenttypeValue
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
setAttribute({
|
|
86
|
-
cloudevent: ce,
|
|
87
|
-
name: 'dataschema',
|
|
88
|
-
types: ['string', 'undefined'],
|
|
89
|
-
value: dataschema
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
setAttribute({
|
|
93
|
-
cloudevent: ce,
|
|
94
|
-
name: 'subject',
|
|
95
|
-
types: ['string', 'undefined'],
|
|
96
|
-
value: subject
|
|
97
|
-
})
|
|
98
|
-
// *******
|
|
99
|
-
|
|
100
|
-
// *******
|
|
101
|
-
// * Required in-house extentions
|
|
102
|
-
this.origin({
|
|
103
|
-
cloudevent: ce,
|
|
104
|
-
originactor,
|
|
105
|
-
originid,
|
|
106
|
-
originsource,
|
|
107
|
-
origintime,
|
|
108
|
-
origintype,
|
|
109
|
-
})
|
|
110
|
-
// *******
|
|
111
|
-
|
|
112
|
-
// *******
|
|
113
|
-
// * Optional in-house extentions
|
|
114
|
-
this.originator({
|
|
115
|
-
cloudevent: ce,
|
|
116
|
-
originatorid,
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
this.wschannel({
|
|
120
|
-
cloudevent: ce,
|
|
121
|
-
wschannelid,
|
|
122
|
-
})
|
|
123
|
-
// *******
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
origin = ({ cloudevent = {}, originactor, originid, originsource, origintime, origintype }) => {
|
|
127
|
-
const ce = this
|
|
128
|
-
|
|
129
|
-
const originactorValue = originactor || cloudevent['originactor']
|
|
130
|
-
setAttribute({
|
|
131
|
-
cloudevent: ce,
|
|
132
|
-
name: 'originactor',
|
|
133
|
-
types: ['string', 'undefined'],
|
|
134
|
-
value: originactorValue,
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
const originidValue = originid || cloudevent['originid'] || cloudevent['id']
|
|
138
|
-
setAttribute({
|
|
139
|
-
cloudevent: ce,
|
|
140
|
-
name: 'originid',
|
|
141
|
-
types: ['string'],
|
|
142
|
-
value: originidValue,
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
const originsourceValue = originsource || cloudevent['originsource'] || cloudevent['source']
|
|
146
|
-
setAttribute({
|
|
147
|
-
cloudevent: ce,
|
|
148
|
-
name: 'originsource',
|
|
149
|
-
types: ['string'],
|
|
150
|
-
value: originsourceValue,
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
const origintimeValue = origintime || cloudevent['origintime'] || cloudevent['time']
|
|
154
|
-
setAttribute({
|
|
155
|
-
cloudevent: ce,
|
|
156
|
-
name: 'origintime',
|
|
157
|
-
types: ['string'],
|
|
158
|
-
value: origintimeValue,
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
const origintypeValue = origintype || cloudevent['origintype'] || cloudevent['type']
|
|
162
|
-
setAttribute({
|
|
163
|
-
cloudevent: ce,
|
|
164
|
-
name: 'origintype',
|
|
165
|
-
types: ['string'],
|
|
166
|
-
value: origintypeValue,
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
return ce
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
originator = ({ cloudevent = {}, originatorid }) => {
|
|
173
|
-
const ce = this
|
|
174
|
-
|
|
175
|
-
setAttribute({
|
|
176
|
-
cloudevent: ce,
|
|
177
|
-
name: 'originatorid',
|
|
178
|
-
types: ['string', 'undefined'],
|
|
179
|
-
value: originatorid || cloudevent['originatorid'],
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
return ce
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
wschannel = ({ cloudevent = {}, wschannelid }) => {
|
|
186
|
-
const ce = this
|
|
187
|
-
|
|
188
|
-
setAttribute({
|
|
189
|
-
cloudevent: ce,
|
|
190
|
-
name: 'wschannelid',
|
|
191
|
-
types: ['string', 'undefined'],
|
|
192
|
-
value: wschannelid || cloudevent['wschannelid'],
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
return ce
|
|
196
|
-
}
|
|
197
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Cloudevent } from '../../index.js'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
describe('cloudevent#data', () => {
|
|
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 a #data value is not input', () => {
|
|
16
|
-
it('returns undefined', () => {
|
|
17
|
-
const { data } = new Cloudevent(params)
|
|
18
|
-
expect(data).to.be.undefined
|
|
19
|
-
})
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
describe('when a #data value is input', () => {
|
|
23
|
-
it('returns the input value', () => {
|
|
24
|
-
params.data = JSON.stringify({ someData: 'yes' })
|
|
25
|
-
const { data } = new Cloudevent(params)
|
|
26
|
-
expect(data).to.eq(params.data)
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
})
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { Cloudevent } from '../../index.js'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
describe('cloudevent#datacontenttype', () => {
|
|
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 a #data value is not input', () => {
|
|
16
|
-
describe('when #datacontenttype is not input', () => {
|
|
17
|
-
it('returns undefined', () => {
|
|
18
|
-
const { datacontenttype } = new Cloudevent(params)
|
|
19
|
-
expect(datacontenttype).to.be.undefined
|
|
20
|
-
})
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
describe('when #datacontenttype is input', () => {
|
|
24
|
-
const validValues = ['some-string', undefined]
|
|
25
|
-
|
|
26
|
-
validValues.forEach(value => {
|
|
27
|
-
describe(`when #datacontenttype is a ${typeof value}`, () => {
|
|
28
|
-
it('returns the input value', () => {
|
|
29
|
-
params.datacontenttype = value
|
|
30
|
-
const { datacontenttype } = new Cloudevent(params)
|
|
31
|
-
expect(datacontenttype).to.eq(params.datacontenttype)
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
describe(`when #datacontenttype is not of type ${validValues.map(item => typeof item).join(' or ')}`, () => {
|
|
37
|
-
it('throws the proper error', () => {
|
|
38
|
-
const expected = `Cloudevent "datacontenttype" must be of type STRING or UNDEFINED`
|
|
39
|
-
params.datacontenttype = 1234
|
|
40
|
-
expect(() => new Cloudevent(params)).to.throw(expected)
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
describe('when a #data value is input', () => {
|
|
47
|
-
describe('when #datacontenttype is not input', () => {
|
|
48
|
-
it('returns "application/json"', () => {
|
|
49
|
-
params.data = JSON.stringify({ some: 'data' })
|
|
50
|
-
const { datacontenttype } = new Cloudevent(params)
|
|
51
|
-
expect(datacontenttype).to.eq('application/json')
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
describe('when #datacontenttype is input', () => {
|
|
56
|
-
const validValues = ['some-string', undefined]
|
|
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
|
-
|
|
66
|
-
validValues.forEach(value => {
|
|
67
|
-
describe(`when #datacontenttype is a ${typeof value}`, () => {
|
|
68
|
-
it('returns the input value', () => {
|
|
69
|
-
params.datacontenttype = value
|
|
70
|
-
const { datacontenttype } = new Cloudevent(params)
|
|
71
|
-
expect(datacontenttype).to.eq(params.datacontenttype)
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
})
|
|
75
|
-
})
|
|
76
|
-
})
|
|
77
|
-
})
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Cloudevent } from '../../index.js'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
describe('cloudevent#dataschema', () => {
|
|
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 #dataschema is not input', () => {
|
|
16
|
-
it('returns undefined', () => {
|
|
17
|
-
const { dataschema } = new Cloudevent(params)
|
|
18
|
-
expect(dataschema).to.be.undefined
|
|
19
|
-
})
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
describe('when #dataschema is input', () => {
|
|
23
|
-
describe('when the input value is invalid', () => {
|
|
24
|
-
it('throws the proper error', () => {
|
|
25
|
-
const expected = 'Cloudevent "dataschema" must be of type STRING or UNDEFINED'
|
|
26
|
-
params.dataschema = 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.dataschema = 'some-string'
|
|
34
|
-
const { dataschema } = new Cloudevent(params)
|
|
35
|
-
expect(dataschema).to.eq(params.dataschema)
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
})
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Cloudevent } from '../../index.js'
|
|
2
|
-
import { createSandbox } from 'sinon'
|
|
3
|
-
import { expect } from 'chai'
|
|
4
|
-
|
|
5
|
-
describe('cloudevent#id', () => {
|
|
6
|
-
const sandbox = createSandbox()
|
|
7
|
-
let params
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
params = {
|
|
11
|
-
// * Required base defaults
|
|
12
|
-
source: 'some-source',
|
|
13
|
-
type: 'some-type',
|
|
14
|
-
}
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
sandbox.restore()
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('returns a string', () => {
|
|
22
|
-
const { id } = new Cloudevent(params)
|
|
23
|
-
expect(id).to.be.a('string')
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
describe('when process.env.MILL_CLOUDEVENTS_NANOID_LENGTH is not input', () => {
|
|
27
|
-
it('returns a string with the proper length', () => {
|
|
28
|
-
sandbox.stub(process, 'env').value({})
|
|
29
|
-
const { id } = new Cloudevent(params)
|
|
30
|
-
expect(id).to.have.lengthOf(21)
|
|
31
|
-
})
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
describe('when process.env.MILL_CLOUDEVENTS_NANOID_LENGTH is input', () => {
|
|
35
|
-
it('returns a string with the proper length', () => {
|
|
36
|
-
const expected = 123
|
|
37
|
-
|
|
38
|
-
const env = { MILL_CLOUDEVENTS_NANOID_LENGTH: expected }
|
|
39
|
-
sandbox.stub(process, 'env').value(env)
|
|
40
|
-
|
|
41
|
-
const { id } = new Cloudevent(params)
|
|
42
|
-
expect(id).to.have.lengthOf(expected)
|
|
43
|
-
})
|
|
44
|
-
})
|
|
45
|
-
})
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Cloudevent } from '../../index.js'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
describe('cloudevent#originactor', () => {
|
|
5
|
-
let params
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
params = {
|
|
9
|
-
// * Required base defaults
|
|
10
|
-
source: 'some-source',
|
|
11
|
-
type: 'some-type',
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
describe('when #originactor is not input', () => {
|
|
16
|
-
it('returns undefined', () => {
|
|
17
|
-
const { originactor } = new Cloudevent(params)
|
|
18
|
-
expect(originactor).to.be.undefined
|
|
19
|
-
})
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
describe('when #originactor is input', () => {
|
|
23
|
-
describe('when the input value is invalid', () => {
|
|
24
|
-
it('throws the proper error', () => {
|
|
25
|
-
const expected = 'Cloudevent "originactor" must be of type STRING or UNDEFINED'
|
|
26
|
-
params.originactor = 1234
|
|
27
|
-
expect(() => new Cloudevent(params)).to.throw(expected)
|
|
28
|
-
})
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
describe('when the input value is valid', () => {
|
|
32
|
-
it('returns the input value', () => {
|
|
33
|
-
params.originactor = 'some-originactor'
|
|
34
|
-
const { originactor } = new Cloudevent(params)
|
|
35
|
-
expect(originactor).to.eq(params.originactor)
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
})
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Cloudevent } from '../../index.js'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
describe('cloudevent#originatorid', () => {
|
|
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 #originatorid is not input', () => {
|
|
16
|
-
it('returns undefined', () => {
|
|
17
|
-
const { originatorid } = new Cloudevent(params)
|
|
18
|
-
expect(originatorid).to.be.undefined
|
|
19
|
-
})
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
describe('when #originatorid is input', () => {
|
|
23
|
-
describe('when the input value is invalid', () => {
|
|
24
|
-
it('throws the proper error', () => {
|
|
25
|
-
const expected = 'Cloudevent "originatorid" must be of type STRING or UNDEFINED'
|
|
26
|
-
params.originatorid = 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.originatorid = 'some-originator-id'
|
|
34
|
-
const { originatorid } = new Cloudevent(params)
|
|
35
|
-
expect(originatorid).to.eq(params.originatorid)
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
})
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Cloudevent } from '../../index.js'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
describe('cloudevent#originid', () => {
|
|
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 #originid is not input', () => {
|
|
16
|
-
it('returns #id', () => {
|
|
17
|
-
params.originid = null
|
|
18
|
-
const { id, originid } = new Cloudevent(params)
|
|
19
|
-
expect(originid).to.eq(id)
|
|
20
|
-
})
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
describe('when #originid is input', () => {
|
|
24
|
-
describe('when the input value is invalid', () => {
|
|
25
|
-
it('throws the proper error', () => {
|
|
26
|
-
const expected = 'Cloudevent "originid" must be of type STRING'
|
|
27
|
-
params.originid = 1234
|
|
28
|
-
expect(() => new Cloudevent(params)).to.throw(expected)
|
|
29
|
-
})
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
describe('when the input value is valid', () => {
|
|
33
|
-
it('returns the input value', () => {
|
|
34
|
-
params.originid = 'some-origin-id'
|
|
35
|
-
const { originid } = new Cloudevent(params)
|
|
36
|
-
expect(originid).to.eq(params.originid)
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
})
|