@1mill/cloudevents 3.0.1 → 4.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/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- 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 +9 -5
- package/src/index.js +3 -5
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t=require("nanoid"),i=function(t){return"undefined"!=typeof process&&process&&process.env&&process.env[t]};exports.Cloudevent=function(e){var r=e.data,o=e.datacontenttype,s=e.dataschema,n=e.originid,h=e.originsource,u=e.origintime,d=e.origintype,a=e.source,g=e.specversion,p=e.subject,c=e.type;if(this.id=t.nanoid(i("MILL_CLOUDEVENTS_NANOID_LENGTH")||21),!this.id)throw new Error('Cloudevent "id" is required');if("string"!=typeof this.id)throw new Error('Cloudevent "id" must be a string');if(this.source=a||i("MILL_CLOUDEVENTS_SOURCE"),!this.source)throw new Error('Cloudevent "source" is required');if("string"!=typeof this.source)throw new Error('Cloudevent "source" must be a string');if(this.type=c,!this.type)throw new Error('Cloudevent "type" is required');if("string"!=typeof this.type)throw new Error('Cloudevent "type" must be a string');if(this.specversion=g||"1.0",!this.specversion)throw new Error('Cloudevent "specversion" is required');if("string"!=typeof this.specversion)throw new Error('Cloudevent "specversion" must be a string');if(this.data=r,this.datacontenttype=void 0!==this.data?o||"application/json":o,this.datacontenttype&&"string"!=typeof this.datacontenttype)throw new Error('Cloudevent "datacontenttype" must be a string');if(this.dataschema=s,this.dataschema&&"string"!=typeof this.dataschema)throw new Error('Cloudevent "dataschema" must be a string');if(this.subject=p,this.subject&&"string"!=typeof this.subject)throw new Error('Cloudevent "subject" must be a string');if(this.time=(new Date).toISOString(),this.origintime=u||this.time,!this.origintime)throw new Error('Cloudevent "origintime" is required');if("string"!=typeof this.origintime)throw new Error('Cloudevent "origintime" must be a string');if(this.originid=n||this.id,!this.originid)throw new Error('Cloudevent "originid" is required');if("string"!=typeof this.originid)throw new Error('Cloudevent "originid" must be a string');if(this.originsource=h||this.source,!this.originsource)throw new Error('Cloudevent "originsource" is required');if("string"!=typeof this.originsource)throw new Error('Cloudevent "originsource" must be a string');if(this.origintype=d||this.type,!this.origintype)throw new Error('Cloudevent "origintype" is required');if("string"!=typeof this.origintype)throw new Error('Cloudevent "origintype" must be a string')};
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/index.js"],"sourcesContent":["import { nanoid } from 'nanoid'\r\n\r\nconst fetchNodeEnv = name => (typeof process !== 'undefined') && process && process.env && process.env[name]\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\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\t// * Required fields by CloudEvent specification\r\n\t\tthis.id = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH') || 21)\r\n\t\tif (!this.id) throw new Error('Cloudevent \"id\" is required')\r\n\t\tif (typeof this.id !== 'string') throw new Error('Cloudevent \"id\" must be a string')\r\n\r\n\t\tthis.source = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tif (!this.source) throw new Error('Cloudevent \"source\" is required')\r\n\t\tif (typeof this.source !== 'string') throw new Error('Cloudevent \"source\" must be a string')\r\n\r\n\t\tthis.type = type\r\n\t\tif (!this.type) throw new Error('Cloudevent \"type\" is required')\r\n\t\tif (typeof this.type !== 'string') throw new Error('Cloudevent \"type\" must be a string')\r\n\r\n\t\tthis.specversion = specversion || '1.0'\r\n\t\tif (!this.specversion) throw new Error('Cloudevent \"specversion\" is required')\r\n\t\tif (typeof this.specversion !== 'string') throw new Error('Cloudevent \"specversion\" must be a string')\r\n\r\n\t\t// * Optional fields by CloudEvent specification\r\n\t\tthis.data = data\r\n\r\n\t\tthis.datacontenttype = typeof this.data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tif (this.datacontenttype && typeof this.datacontenttype !== 'string') throw new Error('Cloudevent \"datacontenttype\" must be a string')\r\n\r\n\t\tthis.dataschema = dataschema\r\n\t\tif (this.dataschema && typeof this.dataschema !== 'string') throw new Error('Cloudevent \"dataschema\" must be a string')\r\n\r\n\t\tthis.subject = subject\r\n\t\tif (this.subject && typeof this.subject !== 'string') throw new Error('Cloudevent \"subject\" must be a string')\r\n\r\n\t\tthis.time = new Date().toISOString()\r\n\r\n\t\t// * In-house extentions\r\n\t\tthis.origintime = origintime || this.time\r\n\t\tif (!this.origintime) throw new Error('Cloudevent \"origintime\" is required')\r\n\t\tif (typeof this.origintime !== 'string') throw new Error('Cloudevent \"origintime\" must be a string')\r\n\r\n\t\tthis.originid = originid || this.id\r\n\t\tif (!this.originid) throw new Error('Cloudevent \"originid\" is required')\r\n\t\tif (typeof this.originid !== 'string') throw new Error('Cloudevent \"originid\" must be a string')\r\n\r\n\t\tthis.originsource = originsource || this.source\r\n\t\tif (!this.originsource) throw new Error('Cloudevent \"originsource\" is required')\r\n\t\tif (typeof this.originsource !== 'string') throw new Error('Cloudevent \"originsource\" must be a string')\r\n\r\n\t\tthis.origintype = origintype || this.type\r\n\t\tif (!this.origintype) throw new Error('Cloudevent \"origintype\" is required')\r\n\t\tif (typeof this.origintype !== 'string') throw new Error('Cloudevent \"origintype\" must be a string')\r\n\t}\r\n}\r\n"],"names":["fetchNodeEnv","name","process","env","data","datacontenttype","dataschema","originid","originsource","origintime","origintype","source","specversion","subject","type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AKC,IAC5BD,KAAKR,SAAU,UAAUW,MAAM,qCACpC,GAA6B,sBAAbX,SAAuB,UAAUW,MAAM,0CAGvD,GADAH,KAAKP,aAAeA,GAAgBO,KAAKJ,QACpCI,KAAKP,aAAc,UAAUU,MAAM,yCACxC,GAAiC,sBAAjBV,aAA2B,UAAUU,MAAM,8CAG3D,GADAH,KAAKL,WAAaA,GAAcK,KAAKD,MAChCC,KAAKL,WAAY,UAAUQ,MAAM,uCACtC,GAA+B,sBAAfR,WAAyB,UAAUQ,MAAM"}
|
package/dist/index.modern.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const
|
|
1
|
+
const t=t=>"undefined"!=typeof process&&process&&process.env&&process.env[t];class e{constructor({data:e,datacontenttype:i,dataschema:r,originid:o,originsource:s,origintime:n,origintype:h,source:u,specversion:d,subject:a,type:g}){if(this.id=((t=21)=>{let e="",i=crypto.getRandomValues(new Uint8Array(t));for(;t--;){let r=63&i[t];e+=r<36?r.toString(36):r<62?(r-26).toString(36).toUpperCase():r<63?"_":"-"}return e})(t("MILL_CLOUDEVENTS_NANOID_LENGTH")||21),!this.id)throw new Error('Cloudevent "id" is required');if("string"!=typeof this.id)throw new Error('Cloudevent "id" must be a string');if(this.source=u||t("MILL_CLOUDEVENTS_SOURCE"),!this.source)throw new Error('Cloudevent "source" is required');if("string"!=typeof this.source)throw new Error('Cloudevent "source" must be a string');if(this.type=g,!this.type)throw new Error('Cloudevent "type" is required');if("string"!=typeof this.type)throw new Error('Cloudevent "type" must be a string');if(this.specversion=d||"1.0",!this.specversion)throw new Error('Cloudevent "specversion" is required');if("string"!=typeof this.specversion)throw new Error('Cloudevent "specversion" must be a string');if(this.data=e,this.datacontenttype=void 0!==this.data?i||"application/json":i,this.datacontenttype&&"string"!=typeof this.datacontenttype)throw new Error('Cloudevent "datacontenttype" must be a string');if(this.dataschema=r,this.dataschema&&"string"!=typeof this.dataschema)throw new Error('Cloudevent "dataschema" must be a string');if(this.subject=a,this.subject&&"string"!=typeof this.subject)throw new Error('Cloudevent "subject" must be a string');if(this.time=(new Date).toISOString(),this.origintime=n||this.time,!this.origintime)throw new Error('Cloudevent "origintime" is required');if("string"!=typeof this.origintime)throw new Error('Cloudevent "origintime" must be a string');if(this.originid=o||this.id,!this.originid)throw new Error('Cloudevent "originid" is required');if("string"!=typeof this.originid)throw new Error('Cloudevent "originid" must be a string');if(this.originsource=s||this.source,!this.originsource)throw new Error('Cloudevent "originsource" is required');if("string"!=typeof this.originsource)throw new Error('Cloudevent "originsource" must be a string');if(this.origintype=h||this.type,!this.origintype)throw new Error('Cloudevent "origintype" is required');if("string"!=typeof this.origintype)throw new Error('Cloudevent "origintype" must be a string')}}export{e 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/index.js"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.modern.js","sources":["../src/index.js","../node_modules/nanoid/index.prod.js"],"sourcesContent":["import { nanoid } from 'nanoid'\r\n\r\nconst fetchNodeEnv = name => (typeof process !== 'undefined') && process && process.env && process.env[name]\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\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\t// * Required fields by CloudEvent specification\r\n\t\tthis.id = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH') || 21)\r\n\t\tif (!this.id) throw new Error('Cloudevent \"id\" is required')\r\n\t\tif (typeof this.id !== 'string') throw new Error('Cloudevent \"id\" must be a string')\r\n\r\n\t\tthis.source = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tif (!this.source) throw new Error('Cloudevent \"source\" is required')\r\n\t\tif (typeof this.source !== 'string') throw new Error('Cloudevent \"source\" must be a string')\r\n\r\n\t\tthis.type = type\r\n\t\tif (!this.type) throw new Error('Cloudevent \"type\" is required')\r\n\t\tif (typeof this.type !== 'string') throw new Error('Cloudevent \"type\" must be a string')\r\n\r\n\t\tthis.specversion = specversion || '1.0'\r\n\t\tif (!this.specversion) throw new Error('Cloudevent \"specversion\" is required')\r\n\t\tif (typeof this.specversion !== 'string') throw new Error('Cloudevent \"specversion\" must be a string')\r\n\r\n\t\t// * Optional fields by CloudEvent specification\r\n\t\tthis.data = data\r\n\r\n\t\tthis.datacontenttype = typeof this.data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tif (this.datacontenttype && typeof this.datacontenttype !== 'string') throw new Error('Cloudevent \"datacontenttype\" must be a string')\r\n\r\n\t\tthis.dataschema = dataschema\r\n\t\tif (this.dataschema && typeof this.dataschema !== 'string') throw new Error('Cloudevent \"dataschema\" must be a string')\r\n\r\n\t\tthis.subject = subject\r\n\t\tif (this.subject && typeof this.subject !== 'string') throw new Error('Cloudevent \"subject\" must be a string')\r\n\r\n\t\tthis.time = new Date().toISOString()\r\n\r\n\t\t// * In-house extentions\r\n\t\tthis.origintime = origintime || this.time\r\n\t\tif (!this.origintime) throw new Error('Cloudevent \"origintime\" is required')\r\n\t\tif (typeof this.origintime !== 'string') throw new Error('Cloudevent \"origintime\" must be a string')\r\n\r\n\t\tthis.originid = originid || this.id\r\n\t\tif (!this.originid) throw new Error('Cloudevent \"originid\" is required')\r\n\t\tif (typeof this.originid !== 'string') throw new Error('Cloudevent \"originid\" must be a string')\r\n\r\n\t\tthis.originsource = originsource || this.source\r\n\t\tif (!this.originsource) throw new Error('Cloudevent \"originsource\" is required')\r\n\t\tif (typeof this.originsource !== 'string') throw new Error('Cloudevent \"originsource\" must be a string')\r\n\r\n\t\tthis.origintype = origintype || this.type\r\n\t\tif (!this.origintype) throw new Error('Cloudevent \"origintype\" is required')\r\n\t\tif (typeof this.origintype !== 'string') throw new Error('Cloudevent \"origintype\" must be a string')\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nif (false) {\n if (\n typeof navigator !== 'undefined' &&\n navigator.product === 'ReactNative' &&\n typeof crypto === 'undefined'\n ) {\n throw new Error(\n 'React Native does not have a built-in secure random generator. ' +\n 'If you don’t need unpredictable IDs use `nanoid/non-secure`. ' +\n 'For secure IDs, import `react-native-get-random-values` ' +\n 'before Nano ID.'\n )\n }\n if (typeof msCrypto !== 'undefined' && typeof crypto === 'undefined') {\n throw new Error(\n 'Import file with `if (!window.crypto) window.crypto = window.msCrypto`' +\n ' before importing Nano ID to fix IE 11 support'\n )\n }\n if (typeof crypto === 'undefined') {\n throw new Error(\n 'Your browser does not have secure random generator. ' +\n 'If you don’t need unpredictable IDs, you can use nanoid/non-secure.'\n )\n }\n}\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, size, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * size) / alphabet.length)\n return () => {\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) => customRandom(alphabet, size, random)\nlet nanoid = (size = 21) => {\n let id = ''\n let bytes = crypto.getRandomValues(new Uint8Array(size))\n while (size--) {\n let byte = bytes[size] & 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 < 63) {\n id += '_'\n } else {\n id += '-'\n }\n }\n return id\n}\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","process","env","Cloudevent","constructor","data","datacontenttype","dataschema","originid","originsource","origintime","origintype","source","specversion","subject","type","this","id","size","bytes","crypto","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WAAyB,UAAUoB,MAAM,4CAG5E,GADAX,KAAKF,QAAUA,EACXE,KAAKF,SAAmC,sBAAZA,QAAsB,UAAUa,MAAM,yCAMtE,GAJAX,KAAKY,MAAO,IAAIC,MAAOC,cAGvBd,KAAKN,WAAaA,GAAcM,KAAKY,MAChCZ,KAAKN,WAAY,UAAUiB,MAAM,uCACtC,GAA+B,sBAAfjB,WAAyB,UAAUiB,MAAM,4CAGzD,GADAX,KAAKR,SAAWA,GAAYQ,KAAKC,IAC5BD,KAAKR,SAAU,UAAUmB,MAAM,qCACpC,GAA6B,sBAAbnB,SAAuB,UAAUmB,MAAM,0CAGvD,GADAX,KAAKP,aAAeA,GAAgBO,KAAKJ,QACpCI,KAAKP,aAAc,UAAUkB,MAAM,yCACxC,GAAiC,sBAAjBlB,aAA2B,UAAUkB,MAAM,8CAG3D,GADAX,KAAKL,WAAaA,GAAcK,KAAKD,MAChCC,KAAKL,WAAY,UAAUgB,MAAM,uCACtC,GAA+B,sBAAfhB,WAAyB,UAAUgB,MAAM"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{nanoid as t}from"nanoid";var i=function(t){return"undefined"!=typeof process&&process&&process.env&&process.env[t]},e=function(e){var r=e.data,o=e.datacontenttype,s=e.dataschema,n=e.originid,h=e.originsource,u=e.origintime,d=e.origintype,a=e.source,g=e.specversion,p=e.subject,c=e.type;if(this.id=t(i("MILL_CLOUDEVENTS_NANOID_LENGTH")||21),!this.id)throw new Error('Cloudevent "id" is required');if("string"!=typeof this.id)throw new Error('Cloudevent "id" must be a string');if(this.source=a||i("MILL_CLOUDEVENTS_SOURCE"),!this.source)throw new Error('Cloudevent "source" is required');if("string"!=typeof this.source)throw new Error('Cloudevent "source" must be a string');if(this.type=c,!this.type)throw new Error('Cloudevent "type" is required');if("string"!=typeof this.type)throw new Error('Cloudevent "type" must be a string');if(this.specversion=g||"1.0",!this.specversion)throw new Error('Cloudevent "specversion" is required');if("string"!=typeof this.specversion)throw new Error('Cloudevent "specversion" must be a string');if(this.data=r,this.datacontenttype=void 0!==this.data?o||"application/json":o,this.datacontenttype&&"string"!=typeof this.datacontenttype)throw new Error('Cloudevent "datacontenttype" must be a string');if(this.dataschema=s,this.dataschema&&"string"!=typeof this.dataschema)throw new Error('Cloudevent "dataschema" must be a string');if(this.subject=p,this.subject&&"string"!=typeof this.subject)throw new Error('Cloudevent "subject" must be a string');if(this.time=(new Date).toISOString(),this.origintime=u||this.time,!this.origintime)throw new Error('Cloudevent "origintime" is required');if("string"!=typeof this.origintime)throw new Error('Cloudevent "origintime" must be a string');if(this.originid=n||this.id,!this.originid)throw new Error('Cloudevent "originid" is required');if("string"!=typeof this.originid)throw new Error('Cloudevent "originid" must be a string');if(this.originsource=h||this.source,!this.originsource)throw new Error('Cloudevent "originsource" is required');if("string"!=typeof this.originsource)throw new Error('Cloudevent "originsource" must be a string');if(this.origintype=d||this.type,!this.origintype)throw new Error('Cloudevent "origintype" is required');if("string"!=typeof this.origintype)throw new Error('Cloudevent "origintype" must be a string')};export{e 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/index.js"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.module.js","sources":["../src/index.js"],"sourcesContent":["import { nanoid } from 'nanoid'\r\n\r\nconst fetchNodeEnv = name => (typeof process !== 'undefined') && process && process.env && process.env[name]\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\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\t// * Required fields by CloudEvent specification\r\n\t\tthis.id = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH') || 21)\r\n\t\tif (!this.id) throw new Error('Cloudevent \"id\" is required')\r\n\t\tif (typeof this.id !== 'string') throw new Error('Cloudevent \"id\" must be a string')\r\n\r\n\t\tthis.source = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tif (!this.source) throw new Error('Cloudevent \"source\" is required')\r\n\t\tif (typeof this.source !== 'string') throw new Error('Cloudevent \"source\" must be a string')\r\n\r\n\t\tthis.type = type\r\n\t\tif (!this.type) throw new Error('Cloudevent \"type\" is required')\r\n\t\tif (typeof this.type !== 'string') throw new Error('Cloudevent \"type\" must be a string')\r\n\r\n\t\tthis.specversion = specversion || '1.0'\r\n\t\tif (!this.specversion) throw new Error('Cloudevent \"specversion\" is required')\r\n\t\tif (typeof this.specversion !== 'string') throw new Error('Cloudevent \"specversion\" must be a string')\r\n\r\n\t\t// * Optional fields by CloudEvent specification\r\n\t\tthis.data = data\r\n\r\n\t\tthis.datacontenttype = typeof this.data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tif (this.datacontenttype && typeof this.datacontenttype !== 'string') throw new Error('Cloudevent \"datacontenttype\" must be a string')\r\n\r\n\t\tthis.dataschema = dataschema\r\n\t\tif (this.dataschema && typeof this.dataschema !== 'string') throw new Error('Cloudevent \"dataschema\" must be a string')\r\n\r\n\t\tthis.subject = subject\r\n\t\tif (this.subject && typeof this.subject !== 'string') throw new Error('Cloudevent \"subject\" must be a string')\r\n\r\n\t\tthis.time = new Date().toISOString()\r\n\r\n\t\t// * In-house extentions\r\n\t\tthis.origintime = origintime || this.time\r\n\t\tif (!this.origintime) throw new Error('Cloudevent \"origintime\" is required')\r\n\t\tif (typeof this.origintime !== 'string') throw new Error('Cloudevent \"origintime\" must be a string')\r\n\r\n\t\tthis.originid = originid || this.id\r\n\t\tif (!this.originid) throw new Error('Cloudevent \"originid\" is required')\r\n\t\tif (typeof this.originid !== 'string') throw new Error('Cloudevent \"originid\" must be a string')\r\n\r\n\t\tthis.originsource = originsource || this.source\r\n\t\tif (!this.originsource) throw new Error('Cloudevent \"originsource\" is required')\r\n\t\tif (typeof this.originsource !== 'string') throw new Error('Cloudevent \"originsource\" must be a string')\r\n\r\n\t\tthis.origintype = origintype || this.type\r\n\t\tif (!this.origintype) throw new Error('Cloudevent \"origintype\" is required')\r\n\t\tif (typeof this.origintype !== 'string') throw new Error('Cloudevent \"origintype\" must be a string')\r\n\t}\r\n}\r\n"],"names":["fetchNodeEnv","name","process","env","Cloudevent","data","datacontenttype","dataschema","originid","originsource","origintime","origintype","source","specversion","subject","type","this","id","nanoid","Error","time","Date","toISOString"],"mappings":"gCAEA,IAAMA,EAAe,SAAAC,SAA4B,oBAAZC,SAA4BA,SAAWA,QAAQC,KAAOD,QAAQC,IAAIF,IAE1FG,EACZ,gBACCC,IAAAA,KACAC,IAAAA,gBACAC,IAAAA,WACAC,IAAAA,SACAC,IAAAA,aACAC,IAAAA,WACAC,IAAAA,WACAC,IAAAA,OACAC,IAAAA,YACAC,IAAAA,QACAC,IAAAA,KAIA,GADAC,KAAKC,GAAKC,EAAOlB,EAAa,mCAAqC,KAC9DgB,KAAKC,GAAI,UAAUE,MAAM,+BAC9B,GAAuB,sBAAPF,GAAiB,UAAUE,MAAM,oCAGjD,GADAH,KAAKJ,OAASA,GAAUZ,EAAa,4BAChCgB,KAAKJ,OAAQ,UAAUO,MAAM,mCAClC,GAA2B,sBAAXP,OAAqB,UAAUO,MAAM,wCAGrD,GADAH,KAAKD,KAAOA,GACPC,KAAKD,KAAM,UAAUI,MAAM,iCAChC,GAAyB,sBAATJ,KAAmB,UAAUI,MAAM,sCAGnD,GADAH,KAAKH,YAAcA,GAAe,OAC7BG,KAAKH,YAAa,UAAUM,MAAM,wCACvC,GAAgC,sBAAhBN,YAA0B,UAAUM,MAAM,6CAQ1D,GALAH,KAAKX,KAAOA,EAEZW,KAAKV,qBAAuC,SAATD,KAChCC,GAAmB,mBACnBA,EACCU,KAAKV,iBAAmD,sBAApBA,gBAA8B,UAAUa,MAAM,iDAGtF,GADAH,KAAKT,WAAaA,EACdS,KAAKT,YAAyC,sBAAfA,WAAyB,UAAUY,MAAM,4CAG5E,GADAH,KAAKF,QAAUA,EACXE,KAAKF,SAAmC,sBAAZA,QAAsB,UAAUK,MAAM,yCAMtE,GAJAH,KAAKI,MAAO,IAAIC,MAAOC,cAGvBN,KAAKN,WAAaA,GAAcM,KAAKI,MAChCJ,KAAKN,WAAY,UAAUS,MAAM,uCACtC,GAA+B,sBAAfT,WAAyB,UAAUS,MAAM,4CAGzD,GADAH,KAAKR,SAAWA,GAAYQ,KAAKC,IAC5BD,KAAKR,SAAU,UAAUW,MAAM,qCACpC,GAA6B,sBAAbX,SAAuB,UAAUW,MAAM,0CAGvD,GADAH,KAAKP,aAAeA,GAAgBO,KAAKJ,QACpCI,KAAKP,aAAc,UAAUU,MAAM,yCACxC,GAAiC,sBAAjBV,aAA2B,UAAUU,MAAM,8CAG3D,GADAH,KAAKL,WAAaA,GAAcK,KAAKD,MAChCC,KAAKL,WAAY,UAAUQ,MAAM,uCACtC,GAA+B,sBAAfR,WAAyB,UAAUQ,MAAM"}
|
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t){"function"==typeof define&&define.amd?define(
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).cloudevents={})}(this,function(t){var e=function(t){return"undefined"!=typeof process&&process&&process.env&&process.env[t]};t.Cloudevent=function(t){var i=t.data,r=t.datacontenttype,o=t.dataschema,s=t.originid,n=t.originsource,u=t.origintime,d=t.origintype,h=t.source,a=t.specversion,g=t.subject,p=t.type;if(this.id=((t=21)=>{let e="",i=crypto.getRandomValues(new Uint8Array(t));for(;t--;){let r=63&i[t];e+=r<36?r.toString(36):r<62?(r-26).toString(36).toUpperCase():r<63?"_":"-"}return e})(e("MILL_CLOUDEVENTS_NANOID_LENGTH")||21),!this.id)throw new Error('Cloudevent "id" is required');if("string"!=typeof this.id)throw new Error('Cloudevent "id" must be a string');if(this.source=h||e("MILL_CLOUDEVENTS_SOURCE"),!this.source)throw new Error('Cloudevent "source" is required');if("string"!=typeof this.source)throw new Error('Cloudevent "source" must be a string');if(this.type=p,!this.type)throw new Error('Cloudevent "type" is required');if("string"!=typeof this.type)throw new Error('Cloudevent "type" must be a string');if(this.specversion=a||"1.0",!this.specversion)throw new Error('Cloudevent "specversion" is required');if("string"!=typeof this.specversion)throw new Error('Cloudevent "specversion" must be a string');if(this.data=i,this.datacontenttype=void 0!==this.data?r||"application/json":r,this.datacontenttype&&"string"!=typeof this.datacontenttype)throw new Error('Cloudevent "datacontenttype" must be a string');if(this.dataschema=o,this.dataschema&&"string"!=typeof this.dataschema)throw new Error('Cloudevent "dataschema" must be a string');if(this.subject=g,this.subject&&"string"!=typeof this.subject)throw new Error('Cloudevent "subject" must be a string');if(this.time=(new Date).toISOString(),this.origintime=u||this.time,!this.origintime)throw new Error('Cloudevent "origintime" is required');if("string"!=typeof this.origintime)throw new Error('Cloudevent "origintime" must be a string');if(this.originid=s||this.id,!this.originid)throw new Error('Cloudevent "originid" is required');if("string"!=typeof this.originid)throw new Error('Cloudevent "originid" must be a string');if(this.originsource=n||this.source,!this.originsource)throw new Error('Cloudevent "originsource" is required');if("string"!=typeof this.originsource)throw new Error('Cloudevent "originsource" must be a string');if(this.origintype=d||this.type,!this.origintype)throw new Error('Cloudevent "origintype" is required');if("string"!=typeof this.origintype)throw new Error('Cloudevent "origintype" must be a string')}});
|
|
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/index.js"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/index.js","../node_modules/nanoid/index.prod.js"],"sourcesContent":["import { nanoid } from 'nanoid'\r\n\r\nconst fetchNodeEnv = name => (typeof process !== 'undefined') && process && process.env && process.env[name]\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\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\t// * Required fields by CloudEvent specification\r\n\t\tthis.id = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH') || 21)\r\n\t\tif (!this.id) throw new Error('Cloudevent \"id\" is required')\r\n\t\tif (typeof this.id !== 'string') throw new Error('Cloudevent \"id\" must be a string')\r\n\r\n\t\tthis.source = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tif (!this.source) throw new Error('Cloudevent \"source\" is required')\r\n\t\tif (typeof this.source !== 'string') throw new Error('Cloudevent \"source\" must be a string')\r\n\r\n\t\tthis.type = type\r\n\t\tif (!this.type) throw new Error('Cloudevent \"type\" is required')\r\n\t\tif (typeof this.type !== 'string') throw new Error('Cloudevent \"type\" must be a string')\r\n\r\n\t\tthis.specversion = specversion || '1.0'\r\n\t\tif (!this.specversion) throw new Error('Cloudevent \"specversion\" is required')\r\n\t\tif (typeof this.specversion !== 'string') throw new Error('Cloudevent \"specversion\" must be a string')\r\n\r\n\t\t// * Optional fields by CloudEvent specification\r\n\t\tthis.data = data\r\n\r\n\t\tthis.datacontenttype = typeof this.data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tif (this.datacontenttype && typeof this.datacontenttype !== 'string') throw new Error('Cloudevent \"datacontenttype\" must be a string')\r\n\r\n\t\tthis.dataschema = dataschema\r\n\t\tif (this.dataschema && typeof this.dataschema !== 'string') throw new Error('Cloudevent \"dataschema\" must be a string')\r\n\r\n\t\tthis.subject = subject\r\n\t\tif (this.subject && typeof this.subject !== 'string') throw new Error('Cloudevent \"subject\" must be a string')\r\n\r\n\t\tthis.time = new Date().toISOString()\r\n\r\n\t\t// * In-house extentions\r\n\t\tthis.origintime = origintime || this.time\r\n\t\tif (!this.origintime) throw new Error('Cloudevent \"origintime\" is required')\r\n\t\tif (typeof this.origintime !== 'string') throw new Error('Cloudevent \"origintime\" must be a string')\r\n\r\n\t\tthis.originid = originid || this.id\r\n\t\tif (!this.originid) throw new Error('Cloudevent \"originid\" is required')\r\n\t\tif (typeof this.originid !== 'string') throw new Error('Cloudevent \"originid\" must be a string')\r\n\r\n\t\tthis.originsource = originsource || this.source\r\n\t\tif (!this.originsource) throw new Error('Cloudevent \"originsource\" is required')\r\n\t\tif (typeof this.originsource !== 'string') throw new Error('Cloudevent \"originsource\" must be a string')\r\n\r\n\t\tthis.origintype = origintype || this.type\r\n\t\tif (!this.origintype) throw new Error('Cloudevent \"origintype\" is required')\r\n\t\tif (typeof this.origintype !== 'string') throw new Error('Cloudevent \"origintype\" must be a string')\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nif (false) {\n if (\n typeof navigator !== 'undefined' &&\n navigator.product === 'ReactNative' &&\n typeof crypto === 'undefined'\n ) {\n throw new Error(\n 'React Native does not have a built-in secure random generator. ' +\n 'If you don’t need unpredictable IDs use `nanoid/non-secure`. ' +\n 'For secure IDs, import `react-native-get-random-values` ' +\n 'before Nano ID.'\n )\n }\n if (typeof msCrypto !== 'undefined' && typeof crypto === 'undefined') {\n throw new Error(\n 'Import file with `if (!window.crypto) window.crypto = window.msCrypto`' +\n ' before importing Nano ID to fix IE 11 support'\n )\n }\n if (typeof crypto === 'undefined') {\n throw new Error(\n 'Your browser does not have secure random generator. ' +\n 'If you don’t need unpredictable IDs, you can use nanoid/non-secure.'\n )\n }\n}\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, size, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * size) / alphabet.length)\n return () => {\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) => customRandom(alphabet, size, random)\nlet nanoid = (size = 21) => {\n let id = ''\n let bytes = crypto.getRandomValues(new Uint8Array(size))\n while (size--) {\n let byte = bytes[size] & 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 < 63) {\n id += '_'\n } else {\n id += '-'\n }\n }\n return id\n}\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","process","env","data","datacontenttype","dataschema","originid","originsource","origintime","origintype","source","specversion","subject","type","this","id","size","bytes","crypto","getRandomValues","Uint8Array","byte","toString","toUpperCase","nanoid","Error","time","Date","toISOString"],"mappings":"qOAEA,IAAMA,EAAe,SAAAC,SAA4B,oBAAZC,SAA4BA,SAAWA,QAAQC,KAAOD,QAAQC,IAAIF,iBAGtG,gBACCG,IAAAA,KACAC,IAAAA,gBACAC,IAAAA,WACAC,IAAAA,SACAC,IAAAA,aACAC,IAAAA,WACAC,IAAAA,WACAC,IAAAA,OACAC,IAAAA,YACAC,IAAAA,QACAC,IAAAA,KAIA,GADAC,KAAKC,GCyBM,EAACC,EAAO,MACnB,IAAID,EAAK,GACLE,EAAQC,OAAOC,gBAAgB,IAAIC,WAAWJ,IAClD,KAAOA,KAAQ,CACb,IAAIK,EAAqB,GAAdJ,EAAMD,GAEfD,GADEM,EAAO,GACHA,EAAKC,SAAS,IACXD,EAAO,IACTA,EAAO,IAAIC,SAAS,IAAIC,cACtBF,EAAO,GACV,IAEA,IAGV,OAAON,GDxCGS,CAAOzB,EAAa,mCAAqC,KAC9De,KAAKC,GAAI,UAAUU,MAAM,+BAC9B,GAAuB,sBAAPV,GAAiB,UAAUU,MAAM,oC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|
2
2
|
"name": "@1mill/cloudevents",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Node cloudevents specification and helper",
|
|
5
5
|
"jsnext:main": "dist/index.module.js",
|
|
6
|
-
"main": "dist/index.
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.module.js",
|
|
8
8
|
"source": "src/index.js",
|
|
9
9
|
"umd:main": "dist/index.umd.js",
|
|
10
|
+
"unpkg": "dist/index.umd.js",
|
|
11
|
+
"type": "module",
|
|
10
12
|
"files": [
|
|
11
13
|
"dist",
|
|
12
14
|
"src"
|
|
13
15
|
],
|
|
14
16
|
"scripts": {
|
|
15
|
-
"build": "rm -rf ./dist &&
|
|
17
|
+
"build": "rm -rf ./dist && npm run build:browser && npm run build:node",
|
|
18
|
+
"build:browser": "microbundle --format modern,umd --external none",
|
|
19
|
+
"build:node": "microbundle --format cjs,esm",
|
|
16
20
|
"deploy": "npm run build && npm publish",
|
|
17
21
|
"dev": "microbundle watch"
|
|
18
22
|
},
|
|
@@ -26,9 +30,9 @@
|
|
|
26
30
|
"url": "https://github.com/1mill/cloudevents.git"
|
|
27
31
|
},
|
|
28
32
|
"dependencies": {
|
|
29
|
-
"nanoid": "^3.
|
|
33
|
+
"nanoid": "^3.2.0"
|
|
30
34
|
},
|
|
31
35
|
"devDependencies": {
|
|
32
|
-
"microbundle": "^0.
|
|
36
|
+
"microbundle": "^0.14.2"
|
|
33
37
|
}
|
|
34
38
|
}
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { nanoid } from 'nanoid'
|
|
2
2
|
|
|
3
|
-
const fetchNodeEnv = name => process && process.env && process.env[name]
|
|
3
|
+
const fetchNodeEnv = name => (typeof process !== 'undefined') && process && process.env && process.env[name]
|
|
4
4
|
|
|
5
|
-
class Cloudevent {
|
|
5
|
+
export class Cloudevent {
|
|
6
6
|
constructor({
|
|
7
7
|
data,
|
|
8
8
|
datacontenttype,
|
|
@@ -67,5 +67,3 @@ class Cloudevent {
|
|
|
67
67
|
if (typeof this.origintype !== 'string') throw new Error('Cloudevent "origintype" must be a string')
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
|
|
71
|
-
module.exports = Object.freeze({ Cloudevent })
|
package/dist/index.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var t=require("nanoid").nanoid,i=function(t){return process&&process.env&&process.env[t]};module.exports=Object.freeze({Cloudevent:function(e){var r=e.data,o=e.datacontenttype,s=e.dataschema,n=e.originid,h=e.originsource,u=e.origintime,d=e.origintype,a=e.source,g=e.specversion,c=e.subject,p=e.type;if(this.id=t(i("MILL_CLOUDEVENTS_NANOID_LENGTH")||21),!this.id)throw new Error('Cloudevent "id" is required');if("string"!=typeof this.id)throw new Error('Cloudevent "id" must be a string');if(this.source=a||i("MILL_CLOUDEVENTS_SOURCE"),!this.source)throw new Error('Cloudevent "source" is required');if("string"!=typeof this.source)throw new Error('Cloudevent "source" must be a string');if(this.type=p,!this.type)throw new Error('Cloudevent "type" is required');if("string"!=typeof this.type)throw new Error('Cloudevent "type" must be a string');if(this.specversion=g||"1.0",!this.specversion)throw new Error('Cloudevent "specversion" is required');if("string"!=typeof this.specversion)throw new Error('Cloudevent "specversion" must be a string');if(this.data=r,this.datacontenttype=void 0!==this.data?o||"application/json":o,this.datacontenttype&&"string"!=typeof this.datacontenttype)throw new Error('Cloudevent "datacontenttype" must be a string');if(this.dataschema=s,this.dataschema&&"string"!=typeof this.dataschema)throw new Error('Cloudevent "dataschema" must be a string');if(this.subject=c,this.subject&&"string"!=typeof this.subject)throw new Error('Cloudevent "subject" must be a string');if(this.time=(new Date).toISOString(),this.origintime=u||this.time,!this.origintime)throw new Error('Cloudevent "origintime" is required');if("string"!=typeof this.origintime)throw new Error('Cloudevent "origintime" must be a string');if(this.originid=n||this.id,!this.originid)throw new Error('Cloudevent "originid" is required');if("string"!=typeof this.originid)throw new Error('Cloudevent "originid" must be a string');if(this.originsource=h||this.source,!this.originsource)throw new Error('Cloudevent "originsource" is required');if("string"!=typeof this.originsource)throw new Error('Cloudevent "originsource" must be a string');if(this.origintype=d||this.type,!this.origintype)throw new Error('Cloudevent "origintype" is required');if("string"!=typeof this.origintype)throw new Error('Cloudevent "origintype" must be a string')}});
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["const { nanoid } = require('nanoid')\r\n\r\nconst fetchNodeEnv = name => process && process.env && process.env[name]\r\n\r\nclass Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\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\t// * Required fields by CloudEvent specification\r\n\t\tthis.id = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH') || 21)\r\n\t\tif (!this.id) throw new Error('Cloudevent \"id\" is required')\r\n\t\tif (typeof this.id !== 'string') throw new Error('Cloudevent \"id\" must be a string')\r\n\r\n\t\tthis.source = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tif (!this.source) throw new Error('Cloudevent \"source\" is required')\r\n\t\tif (typeof this.source !== 'string') throw new Error('Cloudevent \"source\" must be a string')\r\n\r\n\t\tthis.type = type\r\n\t\tif (!this.type) throw new Error('Cloudevent \"type\" is required')\r\n\t\tif (typeof this.type !== 'string') throw new Error('Cloudevent \"type\" must be a string')\r\n\r\n\t\tthis.specversion = specversion || '1.0'\r\n\t\tif (!this.specversion) throw new Error('Cloudevent \"specversion\" is required')\r\n\t\tif (typeof this.specversion !== 'string') throw new Error('Cloudevent \"specversion\" must be a string')\r\n\r\n\t\t// * Optional fields by CloudEvent specification\r\n\t\tthis.data = data\r\n\r\n\t\tthis.datacontenttype = typeof this.data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tif (this.datacontenttype && typeof this.datacontenttype !== 'string') throw new Error('Cloudevent \"datacontenttype\" must be a string')\r\n\r\n\t\tthis.dataschema = dataschema\r\n\t\tif (this.dataschema && typeof this.dataschema !== 'string') throw new Error('Cloudevent \"dataschema\" must be a string')\r\n\r\n\t\tthis.subject = subject\r\n\t\tif (this.subject && typeof this.subject !== 'string') throw new Error('Cloudevent \"subject\" must be a string')\r\n\r\n\t\tthis.time = new Date().toISOString()\r\n\r\n\t\t// * In-house extentions\r\n\t\tthis.origintime = origintime || this.time\r\n\t\tif (!this.origintime) throw new Error('Cloudevent \"origintime\" is required')\r\n\t\tif (typeof this.origintime !== 'string') throw new Error('Cloudevent \"origintime\" must be a string')\r\n\r\n\t\tthis.originid = originid || this.id\r\n\t\tif (!this.originid) throw new Error('Cloudevent \"originid\" is required')\r\n\t\tif (typeof this.originid !== 'string') throw new Error('Cloudevent \"originid\" must be a string')\r\n\r\n\t\tthis.originsource = originsource || this.source\r\n\t\tif (!this.originsource) throw new Error('Cloudevent \"originsource\" is required')\r\n\t\tif (typeof this.originsource !== 'string') throw new Error('Cloudevent \"originsource\" must be a string')\r\n\r\n\t\tthis.origintype = origintype || this.type\r\n\t\tif (!this.origintype) throw new Error('Cloudevent \"origintype\" is required')\r\n\t\tif (typeof this.origintype !== 'string') throw new Error('Cloudevent \"origintype\" must be a string')\r\n\t}\r\n}\r\n\r\nmodule.exports = Object.freeze({ Cloudevent })\r\n"],"names":["nanoid","require","fetchNodeEnv","name","process","env","module","exports","Object","freeze","Cloudevent","data","datacontenttype","dataschema","originid","originsource","origintime","origintype","source","specversion","subject","type","this","id","Error","time","Date","toISOString"],"mappings":"AAAA,IAAQA,EAAWC,QAAQ,UAAnBD,OAEFE,EAAe,SAAAC,UAAQC,SAAWA,QAAQC,KA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