@1mill/cloudevents 4.1.0 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +77 -13
- package/src/utils/setAttribute/unit.test.js +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
# Changelog for @1mill/cloudevents
|
|
2
2
|
|
|
3
|
+
## 4.1.1
|
|
4
|
+
|
|
5
|
+
* Improve formatting of code.
|
|
6
|
+
* Update `README.md`.
|
|
7
|
+
|
|
3
8
|
## 4.1.0
|
|
4
9
|
|
|
5
10
|
* Add new optional `originatorid` attribute.
|
|
6
11
|
* Add unit tests for every Cloudevent attribute (e.g. `id`, `data`, `originid`, etc.) using `mocha`, `sinon`, and `chai`.
|
|
12
|
+
* Update `nanoid@^3.3.4`
|
|
7
13
|
|
|
8
14
|
## 4.0.1
|
|
9
15
|
|
package/README.md
CHANGED
|
@@ -4,11 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
This is an implementation and extention of the [CloudEvents v1 specification](https://github.com/cloudevents/spec) to easily build cloudevents with origin history.
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
## Install
|
|
9
8
|
|
|
10
9
|
```html
|
|
11
|
-
<script src="https://unpkg.com/@1mill/cloudevents@4.
|
|
10
|
+
<script src="https://unpkg.com/@1mill/cloudevents@4.1.1/dist/index.umd.js">
|
|
12
11
|
```
|
|
13
12
|
|
|
14
13
|
or
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t}) {\r\n\t\tconst cloudevent = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t}) {\r\n\t\tconst cloudevent = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tconst origintimeValue = origintime || timeValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue\r\n\t\t})\r\n\r\n\t\tconst originidValue = originid || idValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || sourceValue\r\n\t\tsetAttribute({ cloudevent, name: 'originsource', types: ['string'], value: originsourceValue })\r\n\r\n\t\tconst origintypeValue = origintype || typeValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n}\r\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","setAttribute","cloudevent","types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","this","idValue","nanoid","sourceValue","typeValue","timeValue","Date","toISOString"],"mappings":"wBAAaA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ECHYG,EAAe,gBAAGC,IAAAA,WAAYL,IAAAA,SAAMM,MAAAA,aAAQ,KAAIC,IAAAA,MAC5D,GAAID,EAAME,OAAS,IAAMF,EAAMG,gBAAgBF,GAAQ,CACtD,IAAMG,iBAAyBV,uBAAyBM,EAAMK,IAAI,SAAAC,UAAKA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,YACpG,UAAUC,MAAMN,EAChB,CACDL,EAAWL,GAAQO,CACnB,qBCDA,gBACCU,IAAAA,KACAC,IAAAA,gBACAC,IAAAA,WACAC,IAAAA,aACAC,IAAAA,SACAC,IAAAA,aACAC,IAAAA,WACAC,IAAAA,WACAC,IAAAA,OACAC,IAAAA,YACAC,IAAAA,QACAC,IAAAA,KAEMvB,EAAawB,KAIbC,EAAUC,SAAOhC,EAAa,iCAAkC,KACtEK,EAAa,CACZC,WAAAA,EACAL,KAAM,KACNM,MAAO,CAAC,UACRC,MAAOuB,IAGR,IAAME,EAAcP,GAAU1B,EAAa,2BAC3CK,EAAa,CACZC,WAAAA,EACAL,KAAM,SACNM,MAAO,CAAC,UACRC,MAAOyB,IAGR,IAAMC,EAAYL,EAClBxB,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAO0B,IAIR7B,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNM,MAAO,CAAC,UACRC,MALwBmB,GAAe,QAQxC,IAAMQ,GAAY,IAAIC,MAAOC,cAC7BhC,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAO2B,IAMR9B,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNO,MAAOU,IAMRb,EAAa,CACZC,WAAAA,EACAL,KAAM,kBACNM,MAAO,CAAC,SAAU,aAClBC,WAP4C,IAATU,EACjCC,GAAmB,mBACnBA,IAQHd,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,SAAU,aAClBC,MAAOY,IAGRf,EAAa,CACZC,WAAAA,EACAL,KAAM,UACNM,MAAO,CAAC,SAAU,aAClBC,MAAOoB,IAORvB,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBgB,GAAcW,IAStC9B,EAAa,CACZC,WAAAA,EACAL,KAAM,WACNM,MAAO,CAAC,UACRC,MALqBc,GAAYS,IASlC1B,EAAa,CAAEC,WAAAA,EAAYL,KAAM,eAAgBM,MAAO,CAAC,UAAWC,MAD1Ce,GAAgBU,IAI1C5B,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBiB,GAAcS,IAWtC7B,EAAa,CACZC,WAAAA,EACAL,KAAM,eACNM,MAAO,CAAC,SAAU,aAClBC,MAAOa,GAGR"}
|
package/dist/index.modern.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.modern.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js","../node_modules/nanoid/index.browser.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t}) {\r\n\t\tconst cloudevent = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({
|
|
1
|
+
{"version":3,"file":"index.modern.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js","../node_modules/nanoid/index.browser.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t}) {\r\n\t\tconst cloudevent = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tconst origintimeValue = origintime || timeValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue\r\n\t\t})\r\n\r\n\t\tconst originidValue = originid || idValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || sourceValue\r\n\t\tsetAttribute({ cloudevent, name: 'originsource', types: ['string'], value: originsourceValue })\r\n\r\n\t\tconst origintypeValue = origintype || typeValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nlet customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nlet nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","setAttribute","cloudevent","types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","Cloudevent","constructor","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","this","idValue","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","sourceValue","typeValue","timeValue","Date","toISOString"],"mappings":"MAAaA,EAAe,CAACC,EAAMC,KAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,GCFhBG,EAAe,EAAGC,aAAYL,OAAMM,MAAAA,EAAQ,GAAIC,YAC5D,GAAID,EAAME,OAAS,IAAMF,EAAMG,gBAAgBF,GAAQ,CACtD,MAAMG,EAAW,eAAcV,sBAAyBM,EAAMK,IAAIC,GAAKA,EAAEC,eAAeC,OAAOC,KAAK,WACpG,UAAUC,MAAMN,EAChB,CACDL,EAAWL,GAAQO,SCDPU,EACZC,aAAYC,KACXA,EADWC,gBAEXA,EAFWC,WAGXA,EAHWC,aAIXA,EAJWC,SAKXA,EALWC,aAMXA,EANWC,WAOXA,EAPWC,WAQXA,EARWC,OASXA,EATWC,YAUXA,EAVWC,QAWXA,EAXWC,KAYXA,IAEA,MAAMzB,EAAa0B,KAIbC,ECJK,EAACC,EAAO,KACnBC,OAAOC,gBAAgB,IAAIC,WAAWH,IAAOI,OAAO,CAACC,EAAIC,IAGrDD,IAFFC,GAAQ,IACG,GACHA,EAAKC,SAAS,IACXD,EAAO,IACTA,EAAO,IAAIC,SAAS,IAAI3B,cACtB0B,EAAO,GACV,IAEA,KAGP,IDTaE,CAAO1C,EAAa,iCAAkC,KACtEK,EAAa,CACZC,aACAL,KAAM,KACNM,MAAO,CAAC,UACRC,MAAOyB,IAGR,MAAMU,EAAcf,GAAU5B,EAAa,2BAC3CK,EAAa,CACZC,aACAL,KAAM,SACNM,MAAO,CAAC,UACRC,MAAOmC,IAGR,MAAMC,EAAYb,EAClB1B,EAAa,CACZC,aACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAOoC,IAIRvC,EAAa,CACZC,aACAL,KAAM,cACNM,MAAO,CAAC,UACRC,MALwBqB,GAAe,QAQxC,MAAMgB,GAAY,IAAIC,MAAOC,cAC7B1C,EAAa,CACZC,aACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAOqC,IAMRxC,EAAa,CACZC,aACAL,KAAM,OACNO,MAAOY,IAMRf,EAAa,CACZC,aACAL,KAAM,kBACNM,MAAO,CAAC,SAAU,aAClBC,WAP4C,IAATY,EACjCC,GAAmB,mBACnBA,IAQHhB,EAAa,CACZC,aACAL,KAAM,aACNM,MAAO,CAAC,SAAU,aAClBC,MAAOc,IAGRjB,EAAa,CACZC,aACAL,KAAM,UACNM,MAAO,CAAC,SAAU,aAClBC,MAAOsB,IAORzB,EAAa,CACZC,aACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBkB,GAAcmB,IAStCxC,EAAa,CACZC,aACAL,KAAM,WACNM,MAAO,CAAC,UACRC,MALqBgB,GAAYS,IASlC5B,EAAa,CAAEC,aAAYL,KAAM,eAAgBM,MAAO,CAAC,UAAWC,MAD1CiB,GAAgBkB,IAI1CtC,EAAa,CACZC,aACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBmB,GAAciB,IAWtCvC,EAAa,CACZC,aACAL,KAAM,eACNM,MAAO,CAAC,SAAU,aAClBC,MAAOe,GAGR"}
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.module.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t}) {\r\n\t\tconst cloudevent = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({
|
|
1
|
+
{"version":3,"file":"index.module.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t}) {\r\n\t\tconst cloudevent = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tconst origintimeValue = origintime || timeValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue\r\n\t\t})\r\n\r\n\t\tconst originidValue = originid || idValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || sourceValue\r\n\t\tsetAttribute({ cloudevent, name: 'originsource', types: ['string'], value: originsourceValue })\r\n\r\n\t\tconst origintypeValue = origintype || typeValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n}\r\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","setAttribute","cloudevent","types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","Cloudevent","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","this","idValue","nanoid","sourceValue","typeValue","timeValue","Date","toISOString"],"mappings":"oCAAaA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ECHYG,EAAe,gBAAGC,IAAAA,WAAYL,IAAAA,SAAMM,MAAAA,aAAQ,KAAIC,IAAAA,MAC5D,GAAID,EAAME,OAAS,IAAMF,EAAMG,gBAAgBF,GAAQ,CACtD,IAAMG,iBAAyBV,uBAAyBM,EAAMK,IAAI,SAAAC,UAAKA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,YACpG,UAAUC,MAAMN,EAChB,CACDL,EAAWL,GAAQO,CACnB,ECFYU,EACZ,gBACCC,IAAAA,KACAC,IAAAA,gBACAC,IAAAA,WACAC,IAAAA,aACAC,IAAAA,SACAC,IAAAA,aACAC,IAAAA,WACAC,IAAAA,WACAC,IAAAA,OACAC,IAAAA,YACAC,IAAAA,QACAC,IAAAA,KAEMxB,EAAayB,KAIbC,EAAUC,EAAOjC,EAAa,iCAAkC,KACtEK,EAAa,CACZC,WAAAA,EACAL,KAAM,KACNM,MAAO,CAAC,UACRC,MAAOwB,IAGR,IAAME,EAAcP,GAAU3B,EAAa,2BAC3CK,EAAa,CACZC,WAAAA,EACAL,KAAM,SACNM,MAAO,CAAC,UACRC,MAAO0B,IAGR,IAAMC,EAAYL,EAClBzB,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAO2B,IAIR9B,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNM,MAAO,CAAC,UACRC,MALwBoB,GAAe,QAQxC,IAAMQ,GAAY,IAAIC,MAAOC,cAC7BjC,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAO4B,IAMR/B,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNO,MAAOW,IAMRd,EAAa,CACZC,WAAAA,EACAL,KAAM,kBACNM,MAAO,CAAC,SAAU,aAClBC,WAP4C,IAATW,EACjCC,GAAmB,mBACnBA,IAQHf,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,SAAU,aAClBC,MAAOa,IAGRhB,EAAa,CACZC,WAAAA,EACAL,KAAM,UACNM,MAAO,CAAC,SAAU,aAClBC,MAAOqB,IAORxB,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBiB,GAAcW,IAStC/B,EAAa,CACZC,WAAAA,EACAL,KAAM,WACNM,MAAO,CAAC,UACRC,MALqBe,GAAYS,IASlC3B,EAAa,CAAEC,WAAAA,EAAYL,KAAM,eAAgBM,MAAO,CAAC,UAAWC,MAD1CgB,GAAgBU,IAI1C7B,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBkB,GAAcS,IAWtC9B,EAAa,CACZC,WAAAA,EACAL,KAAM,eACNM,MAAO,CAAC,SAAU,aAClBC,MAAOc,GAGR"}
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js","../node_modules/nanoid/index.browser.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t}) {\r\n\t\tconst cloudevent = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/utils/fetchNodeEnv/index.js","../src/utils/setAttribute/index.js","../src/index.js","../node_modules/nanoid/index.browser.js"],"sourcesContent":["export const fetchNodeEnv = (name, fallbackValue) => {\r\n\tif (typeof process === 'undefined') { return }\r\n\treturn process.env[name] || fallbackValue\r\n}\r\n","export const setAttribute = ({ cloudevent, name, types = [], value }) => {\r\n\tif (types.length > 0 && !types.includes(typeof value)) {\r\n\t\tconst message = `Cloudevent \"${name}\" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`\r\n\t\tthrow new Error(message)\r\n\t}\r\n\tcloudevent[name] = value\r\n}\r\n","import { fetchNodeEnv } from './utils/fetchNodeEnv/index.js'\r\nimport { nanoid } from 'nanoid'\r\nimport { setAttribute } from './utils/setAttribute/index.js'\r\n\r\nexport class Cloudevent {\r\n\tconstructor({\r\n\t\tdata,\r\n\t\tdatacontenttype,\r\n\t\tdataschema,\r\n\t\toriginatorid,\r\n\t\toriginid,\r\n\t\toriginsource,\r\n\t\torigintime,\r\n\t\torigintype,\r\n\t\tsource,\r\n\t\tspecversion,\r\n\t\tsubject,\r\n\t\ttype,\r\n\t}) {\r\n\t\tconst cloudevent = this\r\n\r\n\t\t// *******\r\n\t\t// * Required fields by Cloudevent v1 specification\r\n\t\tconst idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'id',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: idValue\r\n\t\t})\r\n\r\n\t\tconst sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'source',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: sourceValue\r\n\t\t})\r\n\r\n\t\tconst typeValue = type\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'type',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: typeValue\r\n\t\t})\r\n\r\n\t\tconst specversionValue = specversion || '1.0'\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'specversion',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: specversionValue\r\n\t\t})\r\n\r\n\t\tconst timeValue = new Date().toISOString()\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'time',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: timeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional fields by Cloudevent v1 specification\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'data',\r\n\t\t\tvalue: data\r\n\t\t})\r\n\r\n\t\tconst datacontenttypeValue = typeof data !== 'undefined'\r\n\t\t\t? datacontenttype || 'application/json'\r\n\t\t\t: datacontenttype\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'datacontenttype',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: datacontenttypeValue\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'dataschema',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: dataschema\r\n\t\t})\r\n\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'subject',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: subject\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Required in-house extentions\r\n\t\tconst origintimeValue = origintime || timeValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'origintime',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintimeValue\r\n\t\t})\r\n\r\n\t\tconst originidValue = originid || idValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'originid',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: originidValue\r\n\t\t})\r\n\r\n\t\tconst originsourceValue = originsource || sourceValue\r\n\t\tsetAttribute({ cloudevent, name: 'originsource', types: ['string'], value: originsourceValue })\r\n\r\n\t\tconst origintypeValue = origintype || typeValue\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'origintype',\r\n\t\t\ttypes: ['string'],\r\n\t\t\tvalue: origintypeValue\r\n\t\t})\r\n\t\t// *******\r\n\r\n\t\t// *******\r\n\t\t// * Optional in-house extentions\r\n\t\tsetAttribute({\r\n\t\t\tcloudevent,\r\n\t\t\tname: 'originatorid',\r\n\t\t\ttypes: ['string', 'undefined'],\r\n\t\t\tvalue: originatorid\r\n\t\t})\r\n\t\t// *******\r\n\t}\r\n}\r\n","import { urlAlphabet } from './url-alphabet/index.js'\nlet random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nlet customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length === size) return id\n }\n }\n }\n}\nlet customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size, random)\nlet nanoid = (size = 21) =>\n crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {\n byte &= 63\n if (byte < 36) {\n id += byte.toString(36)\n } else if (byte < 62) {\n id += (byte - 26).toString(36).toUpperCase()\n } else if (byte > 62) {\n id += '-'\n } else {\n id += '_'\n }\n return id\n }, '')\nexport { nanoid, customAlphabet, customRandom, urlAlphabet, random }\n"],"names":["fetchNodeEnv","name","fallbackValue","process","env","setAttribute","cloudevent","types","value","length","includes","message","map","s","toUpperCase","sort","join","Error","data","datacontenttype","dataschema","originatorid","originid","originsource","origintime","origintype","source","specversion","subject","type","this","idValue","size","crypto","getRandomValues","Uint8Array","reduce","id","byte","toString","nanoid","sourceValue","typeValue","timeValue","Date","toISOString"],"mappings":"yOAAaA,EAAe,SAACC,EAAMC,GAClC,GAAuB,oBAAZC,QACX,OAAOA,QAAQC,IAAIH,IAASC,CAC5B,ECHYG,EAAe,gBAAGC,IAAAA,WAAYL,IAAAA,SAAMM,MAAAA,aAAQ,KAAIC,IAAAA,MAC5D,GAAID,EAAME,OAAS,IAAMF,EAAMG,gBAAgBF,GAAQ,CACtD,IAAMG,iBAAyBV,uBAAyBM,EAAMK,IAAI,SAAAC,UAAKA,EAAEC,aAAN,GAAqBC,OAAOC,KAAK,YACpG,UAAUC,MAAMN,EAChB,CACDL,EAAWL,GAAQO,CACnB,eCDA,gBACCU,IAAAA,KACAC,IAAAA,gBACAC,IAAAA,WACAC,IAAAA,aACAC,IAAAA,SACAC,IAAAA,aACAC,IAAAA,WACAC,IAAAA,WACAC,IAAAA,OACAC,IAAAA,YACAC,IAAAA,QACAC,IAAAA,KAEMvB,EAAawB,KAIbC,ECJK,EAACC,EAAO,KACnBC,OAAOC,gBAAgB,IAAIC,WAAWH,IAAOI,OAAO,CAACC,EAAIC,IAGrDD,IAFFC,GAAQ,IACG,GACHA,EAAKC,SAAS,IACXD,EAAO,IACTA,EAAO,IAAIC,SAAS,IAAIzB,cACtBwB,EAAO,GACV,IAEA,KAGP,IDTaE,CAAOxC,EAAa,iCAAkC,KACtEK,EAAa,CACZC,WAAAA,EACAL,KAAM,KACNM,MAAO,CAAC,UACRC,MAAOuB,IAGR,IAAMU,EAAcf,GAAU1B,EAAa,2BAC3CK,EAAa,CACZC,WAAAA,EACAL,KAAM,SACNM,MAAO,CAAC,UACRC,MAAOiC,IAGR,IAAMC,EAAYb,EAClBxB,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAOkC,IAIRrC,EAAa,CACZC,WAAAA,EACAL,KAAM,cACNM,MAAO,CAAC,UACRC,MALwBmB,GAAe,QAQxC,IAAMgB,GAAY,IAAIC,MAAOC,cAC7BxC,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNM,MAAO,CAAC,UACRC,MAAOmC,IAMRtC,EAAa,CACZC,WAAAA,EACAL,KAAM,OACNO,MAAOU,IAMRb,EAAa,CACZC,WAAAA,EACAL,KAAM,kBACNM,MAAO,CAAC,SAAU,aAClBC,WAP4C,IAATU,EACjCC,GAAmB,mBACnBA,IAQHd,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,SAAU,aAClBC,MAAOY,IAGRf,EAAa,CACZC,WAAAA,EACAL,KAAM,UACNM,MAAO,CAAC,SAAU,aAClBC,MAAOoB,IAORvB,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBgB,GAAcmB,IAStCtC,EAAa,CACZC,WAAAA,EACAL,KAAM,WACNM,MAAO,CAAC,UACRC,MALqBc,GAAYS,IASlC1B,EAAa,CAAEC,WAAAA,EAAYL,KAAM,eAAgBM,MAAO,CAAC,UAAWC,MAD1Ce,GAAgBkB,IAI1CpC,EAAa,CACZC,WAAAA,EACAL,KAAM,aACNM,MAAO,CAAC,UACRC,MALuBiB,GAAciB,IAWtCrC,EAAa,CACZC,WAAAA,EACAL,KAAM,eACNM,MAAO,CAAC,SAAU,aAClBC,MAAOa,GAGR"}
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -22,53 +22,117 @@ export class Cloudevent {
|
|
|
22
22
|
// *******
|
|
23
23
|
// * Required fields by Cloudevent v1 specification
|
|
24
24
|
const idValue = nanoid(fetchNodeEnv('MILL_CLOUDEVENTS_NANOID_LENGTH', 21))
|
|
25
|
-
setAttribute({
|
|
25
|
+
setAttribute({
|
|
26
|
+
cloudevent,
|
|
27
|
+
name: 'id',
|
|
28
|
+
types: ['string'],
|
|
29
|
+
value: idValue
|
|
30
|
+
})
|
|
26
31
|
|
|
27
32
|
const sourceValue = source || fetchNodeEnv('MILL_CLOUDEVENTS_SOURCE')
|
|
28
|
-
setAttribute({
|
|
33
|
+
setAttribute({
|
|
34
|
+
cloudevent,
|
|
35
|
+
name: 'source',
|
|
36
|
+
types: ['string'],
|
|
37
|
+
value: sourceValue
|
|
38
|
+
})
|
|
29
39
|
|
|
30
40
|
const typeValue = type
|
|
31
|
-
setAttribute({
|
|
41
|
+
setAttribute({
|
|
42
|
+
cloudevent,
|
|
43
|
+
name: 'type',
|
|
44
|
+
types: ['string'],
|
|
45
|
+
value: typeValue
|
|
46
|
+
})
|
|
32
47
|
|
|
33
48
|
const specversionValue = specversion || '1.0'
|
|
34
|
-
setAttribute({
|
|
49
|
+
setAttribute({
|
|
50
|
+
cloudevent,
|
|
51
|
+
name: 'specversion',
|
|
52
|
+
types: ['string'],
|
|
53
|
+
value: specversionValue
|
|
54
|
+
})
|
|
35
55
|
|
|
36
56
|
const timeValue = new Date().toISOString()
|
|
37
|
-
setAttribute({
|
|
57
|
+
setAttribute({
|
|
58
|
+
cloudevent,
|
|
59
|
+
name: 'time',
|
|
60
|
+
types: ['string'],
|
|
61
|
+
value: timeValue
|
|
62
|
+
})
|
|
38
63
|
// *******
|
|
39
64
|
|
|
40
65
|
// *******
|
|
41
66
|
// * Optional fields by Cloudevent v1 specification
|
|
42
|
-
setAttribute({
|
|
67
|
+
setAttribute({
|
|
68
|
+
cloudevent,
|
|
69
|
+
name: 'data',
|
|
70
|
+
value: data
|
|
71
|
+
})
|
|
43
72
|
|
|
44
73
|
const datacontenttypeValue = typeof data !== 'undefined'
|
|
45
74
|
? datacontenttype || 'application/json'
|
|
46
75
|
: datacontenttype
|
|
47
|
-
setAttribute({
|
|
76
|
+
setAttribute({
|
|
77
|
+
cloudevent,
|
|
78
|
+
name: 'datacontenttype',
|
|
79
|
+
types: ['string', 'undefined'],
|
|
80
|
+
value: datacontenttypeValue
|
|
81
|
+
})
|
|
48
82
|
|
|
49
|
-
setAttribute({
|
|
83
|
+
setAttribute({
|
|
84
|
+
cloudevent,
|
|
85
|
+
name: 'dataschema',
|
|
86
|
+
types: ['string', 'undefined'],
|
|
87
|
+
value: dataschema
|
|
88
|
+
})
|
|
50
89
|
|
|
51
|
-
setAttribute({
|
|
90
|
+
setAttribute({
|
|
91
|
+
cloudevent,
|
|
92
|
+
name: 'subject',
|
|
93
|
+
types: ['string', 'undefined'],
|
|
94
|
+
value: subject
|
|
95
|
+
})
|
|
52
96
|
// *******
|
|
53
97
|
|
|
54
98
|
// *******
|
|
55
99
|
// * Required in-house extentions
|
|
56
100
|
const origintimeValue = origintime || timeValue
|
|
57
|
-
setAttribute({
|
|
101
|
+
setAttribute({
|
|
102
|
+
cloudevent,
|
|
103
|
+
name: 'origintime',
|
|
104
|
+
types: ['string'],
|
|
105
|
+
value: origintimeValue
|
|
106
|
+
})
|
|
58
107
|
|
|
59
108
|
const originidValue = originid || idValue
|
|
60
|
-
setAttribute({
|
|
109
|
+
setAttribute({
|
|
110
|
+
cloudevent,
|
|
111
|
+
name: 'originid',
|
|
112
|
+
types: ['string'],
|
|
113
|
+
value: originidValue
|
|
114
|
+
})
|
|
61
115
|
|
|
62
116
|
const originsourceValue = originsource || sourceValue
|
|
63
117
|
setAttribute({ cloudevent, name: 'originsource', types: ['string'], value: originsourceValue })
|
|
64
118
|
|
|
65
119
|
const origintypeValue = origintype || typeValue
|
|
66
|
-
setAttribute({
|
|
120
|
+
setAttribute({
|
|
121
|
+
cloudevent,
|
|
122
|
+
name: 'origintype',
|
|
123
|
+
types: ['string'],
|
|
124
|
+
value: origintypeValue
|
|
125
|
+
})
|
|
67
126
|
// *******
|
|
68
127
|
|
|
69
128
|
// *******
|
|
70
129
|
// * Optional in-house extentions
|
|
71
|
-
setAttribute({
|
|
130
|
+
setAttribute({
|
|
131
|
+
cloudevent,
|
|
132
|
+
name: 'originatorid',
|
|
133
|
+
types: ['string', 'undefined'],
|
|
134
|
+
value: originatorid
|
|
135
|
+
})
|
|
72
136
|
// *******
|
|
73
137
|
}
|
|
74
138
|
}
|
|
@@ -9,6 +9,15 @@ describe('setAttribute', () => {
|
|
|
9
9
|
cloudevent = {}
|
|
10
10
|
})
|
|
11
11
|
|
|
12
|
+
describe('when #types is empty', () => {
|
|
13
|
+
[1234, '1234', undefined].forEach(value => {
|
|
14
|
+
it('sets cloudevent[#name] to the input #value', () => {
|
|
15
|
+
setAttribute({ cloudevent, name, value })
|
|
16
|
+
expect(cloudevent[name]).to.eq(value)
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
|
|
12
21
|
describe('when #types is not empty', () => {
|
|
13
22
|
describe('when the type of #value is not in #types', () => {
|
|
14
23
|
it('throws the proper error', () => {
|
|
@@ -31,13 +40,4 @@ describe('setAttribute', () => {
|
|
|
31
40
|
})
|
|
32
41
|
})
|
|
33
42
|
})
|
|
34
|
-
|
|
35
|
-
describe('when #types is empty', () => {
|
|
36
|
-
[1234, '1234', undefined].forEach(value => {
|
|
37
|
-
it('sets cloudevent[#name] to the input #value', () => {
|
|
38
|
-
setAttribute({ cloudevent, name, value })
|
|
39
|
-
expect(cloudevent[name]).to.eq(value)
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
43
|
})
|