@1mill/cloudevents 4.6.3 → 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.
Files changed (73) hide show
  1. package/README.md +43 -108
  2. package/dist/bundle-browser/cloudevents.esm.js +2 -0
  3. package/dist/bundle-browser/cloudevents.esm.js.map +1 -0
  4. package/dist/bundle-browser/cloudevents.umd.js +2 -0
  5. package/dist/bundle-browser/cloudevents.umd.js.map +1 -0
  6. package/dist/bundle-node/cloudevents.cjs +2 -0
  7. package/dist/bundle-node/cloudevents.cjs.map +1 -0
  8. package/dist/bundle-node/cloudevents.esm.js +2 -0
  9. package/dist/bundle-node/cloudevents.esm.js.map +1 -0
  10. package/dist/index.d.ts +1 -0
  11. package/dist/tests/constructor/actor.test.d.ts +1 -0
  12. package/dist/tests/constructor/data.test.d.ts +1 -0
  13. package/dist/tests/constructor/datacontenttype.test.d.ts +1 -0
  14. package/dist/tests/constructor/dataschema.test.d.ts +1 -0
  15. package/dist/tests/constructor/id.test.d.ts +1 -0
  16. package/dist/tests/constructor/originid.test.d.ts +1 -0
  17. package/dist/tests/constructor/originsource.test.d.ts +1 -0
  18. package/dist/tests/constructor/origintime.test.d.ts +1 -0
  19. package/dist/tests/constructor/origintype.test.d.ts +1 -0
  20. package/dist/tests/constructor/source.test.d.ts +1 -0
  21. package/dist/tests/constructor/specversion.test.d.ts +1 -0
  22. package/dist/tests/constructor/subjest.test.d.ts +1 -0
  23. package/dist/tests/constructor/time.test.d.ts +1 -0
  24. package/dist/tests/constructor/type.test.d.ts +1 -0
  25. package/dist/tests/constructor/wschannelid.test.d.ts +1 -0
  26. package/dist/utils/cloudevent.d.ts +30 -0
  27. package/dist/utils/cloudevent.test.d.ts +1 -0
  28. package/dist/utils/fetchNodeEnv.d.ts +1 -0
  29. package/dist/utils/fetchNodeEnv.test.d.ts +1 -0
  30. package/dist/utils/validateAttribute.d.ts +13 -0
  31. package/dist/utils/validateAttribute.test.d.ts +1 -0
  32. package/package.json +32 -16
  33. package/CHANGELOG.md +0 -70
  34. package/dist/index.cjs +0 -2
  35. package/dist/index.cjs.map +0 -1
  36. package/dist/index.modern.js +0 -2
  37. package/dist/index.modern.js.map +0 -1
  38. package/dist/index.module.js +0 -2
  39. package/dist/index.module.js.map +0 -1
  40. package/dist/index.umd.js +0 -2
  41. package/dist/index.umd.js.map +0 -1
  42. package/src/index.js +0 -197
  43. package/src/tests/constructor/data.test.js +0 -29
  44. package/src/tests/constructor/datacontenttype.test.js +0 -77
  45. package/src/tests/constructor/dataschema.test.js +0 -39
  46. package/src/tests/constructor/id.test.js +0 -45
  47. package/src/tests/constructor/originactor.test.js +0 -39
  48. package/src/tests/constructor/originatorid.test.js +0 -39
  49. package/src/tests/constructor/originid.test.js +0 -40
  50. package/src/tests/constructor/originsource.test.js +0 -40
  51. package/src/tests/constructor/origintime.test.js +0 -39
  52. package/src/tests/constructor/origintype.test.js +0 -40
  53. package/src/tests/constructor/source.test.js +0 -63
  54. package/src/tests/constructor/specversion.test.js +0 -41
  55. package/src/tests/constructor/subjest.test.js +0 -39
  56. package/src/tests/constructor/time.test.js +0 -36
  57. package/src/tests/constructor/type.test.js +0 -39
  58. package/src/tests/constructor/wschannelid.test.js +0 -39
  59. package/src/tests/methods/origin/originactor.test.js +0 -74
  60. package/src/tests/methods/origin/originid.test.js +0 -85
  61. package/src/tests/methods/origin/originsource.test.js +0 -85
  62. package/src/tests/methods/origin/origintime.test.js +0 -85
  63. package/src/tests/methods/origin/origintype.test.js +0 -85
  64. package/src/tests/methods/origin/unit.test.js +0 -13
  65. package/src/tests/methods/originator/originatorid.test.js +0 -51
  66. package/src/tests/methods/originator/unit.test.js +0 -10
  67. package/src/tests/methods/wschannel/unit.test.js +0 -10
  68. package/src/tests/methods/wschannel/wschannelid.test.js +0 -51
  69. package/src/unit.test.js +0 -91
  70. package/src/utils/fetchNodeEnv/index.js +0 -4
  71. package/src/utils/fetchNodeEnv/unit.test.js +0 -55
  72. package/src/utils/setAttribute/index.js +0 -10
  73. package/src/utils/setAttribute/unit.test.js +0 -67
@@ -1,40 +0,0 @@
1
- import { Cloudevent } from '../../index.js'
2
- import { expect } from 'chai'
3
-
4
- describe('cloudevent#originsource', () => {
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 #originsource is not input', () => {
16
- it('returns #source', () => {
17
- params.originsource = null
18
- const { source, originsource } = new Cloudevent(params)
19
- expect(originsource).to.eq(source)
20
- })
21
- })
22
-
23
- describe('when #originsource is input', () => {
24
- describe('when the input value is invalid', () => {
25
- it('throws the proper error', () => {
26
- const expected = 'Cloudevent "originsource" must be of type STRING'
27
- params.originsource = 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.originsource = 'some-origin-source'
35
- const { originsource } = new Cloudevent(params)
36
- expect(originsource).to.eq(params.originsource)
37
- })
38
- })
39
- })
40
- })
@@ -1,39 +0,0 @@
1
- import { Cloudevent } from '../../index.js'
2
- import { expect } from 'chai'
3
-
4
- describe('cloudevent#origintime', () => {
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 #origintime is not input', () => {
16
- it('returns #time', () => {
17
- const { origintime, time } = new Cloudevent(params)
18
- expect(origintime).to.eq(time)
19
- })
20
- })
21
-
22
- describe('when #origintime is input', () => {
23
- describe('when the input value is invalid', () => {
24
- it('throws the proper error', () => {
25
- const expected = 'Cloudevent "origintime" must be of type STRING'
26
- params.origintime = 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.origintime = new Date().toISOString()
34
- const { origintime } = new Cloudevent(params)
35
- expect(origintime).to.eq(params.origintime)
36
- })
37
- })
38
- })
39
- })
@@ -1,40 +0,0 @@
1
- import { Cloudevent } from '../../index.js'
2
- import { expect } from 'chai'
3
-
4
- describe('cloudevent#origintype', () => {
5
- let params
6
-
7
- beforeEach(() => {
8
- params = {
9
- // * Required base defaults
10
- type: 'some-type',
11
- source: 'some-source',
12
- }
13
- })
14
-
15
- describe('when #origintype is not input', () => {
16
- it('returns #type', () => {
17
- params.origintype = null
18
- const { type, origintype } = new Cloudevent(params)
19
- expect(origintype).to.eq(type)
20
- })
21
- })
22
-
23
- describe('when #origintype is input', () => {
24
- describe('when the input value is invalid', () => {
25
- it('throws the proper error', () => {
26
- const expected = 'Cloudevent "origintype" must be of type STRING'
27
- params.origintype = 1234
28
- expect(() => new Cloudevent(params)).to.throw(expected)
29
- })
30
- })
31
-
32
- describe('when the input value is valtype', () => {
33
- it('returns the input value', () => {
34
- params.origintype = 'some-origin-type'
35
- const { origintype } = new Cloudevent(params)
36
- expect(origintype).to.eq(params.origintype)
37
- })
38
- })
39
- })
40
- })
@@ -1,63 +0,0 @@
1
- import { Cloudevent } from '../../index.js'
2
- import { createSandbox } from 'sinon'
3
- import { expect } from 'chai'
4
-
5
- describe('cloudevent#source', () => {
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
- describe('when a #source value is not input', () => {
22
- beforeEach(() => {
23
- params.source = null
24
- })
25
-
26
- describe('when process.env.MILL_CLOUDEVENTS_SOURCE is not input', () => {
27
- it('throws the proper error', () => {
28
- const expected = 'Cloudevent "source" must be of type STRING'
29
- sandbox.stub(process, 'env').value({})
30
- expect(() => new Cloudevent(params)).to.throw(expected)
31
- })
32
- })
33
-
34
- describe('when process.env.MILL_CLOUDEVENTS_SOURCE is input', () => {
35
- it('returns the input value', () => {
36
- const expected = 'some-env-var-value'
37
-
38
- const env = { MILL_CLOUDEVENTS_SOURCE: expected }
39
- sandbox.stub(process, 'env').value(env)
40
-
41
- const { source } = new Cloudevent(params)
42
- expect(source).to.eq(expected)
43
- })
44
- })
45
- })
46
-
47
- describe('when a #source value is input', () => {
48
- describe('when the input value is not a string', () => {
49
- it('throws the proper error', () => {
50
- const expected = 'Cloudevent "source" must be of type STRING'
51
- params.source = 1234
52
- expect(() => new Cloudevent(params)).to.throw(expected)
53
- })
54
- })
55
-
56
- describe('when the input value is a string', () => {
57
- it('returns the input value', () => {
58
- const { source } = new Cloudevent(params)
59
- expect(source).to.eq(params.source)
60
- })
61
- })
62
- })
63
- })
@@ -1,41 +0,0 @@
1
- import { Cloudevent } from '../../index.js'
2
- import { expect } from 'chai'
3
-
4
- describe('cloudevent#specversion', () => {
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 #specversion value is not input', () => {
16
- it('returns the proper value', () => {
17
- const expected = '1.0'
18
- const { specversion } = new Cloudevent(params)
19
- expect(specversion).to.eq(expected)
20
- })
21
- })
22
-
23
- describe('when a #specversion value is input', () => {
24
- describe('when the input value is not a string', () => {
25
- it('throws the proper error', () => {
26
- params.specversion = 1234
27
- const expected = 'Cloudevent "specversion" must be of type STRING'
28
- expect(() => new Cloudevent(params)).to.throw(expected)
29
- })
30
- })
31
-
32
- describe('when the input value is a string', () => {
33
- it('returns the input value', () => {
34
- const expected = '4.3.2.1'
35
- params.specversion = expected
36
- const { specversion } = new Cloudevent(params)
37
- expect(specversion).to.eq(expected)
38
- })
39
- })
40
- })
41
- })
@@ -1,39 +0,0 @@
1
- import { Cloudevent } from '../../index.js'
2
- import { expect } from 'chai'
3
-
4
- describe('cloudevent#subject', () => {
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 #subject is not input', () => {
16
- it('returns undefined', () => {
17
- const { subject } = new Cloudevent(params)
18
- expect(subject).to.be.undefined
19
- })
20
- })
21
-
22
- describe('when #subject is not input', () => {
23
- describe('when the input value is invalid', () => {
24
- it('throws the proper error', () => {
25
- const expected = 'Cloudevent "subject" must be of type STRING or UNDEFINED'
26
- params.subject = 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.subject = 'some-string'
34
- const { subject } = new Cloudevent(params)
35
- expect(subject).to.eq(params.subject)
36
- })
37
- })
38
- })
39
- })
@@ -1,36 +0,0 @@
1
- import chai, { expect } from 'chai'
2
- import chaiIso8601 from 'chai-iso8601'
3
- import { Cloudevent } from '../../index.js'
4
- import { useFakeTimers } from 'sinon'
5
-
6
- chai.use(chaiIso8601())
7
-
8
- describe('cloudevent#time', () => {
9
- let params
10
-
11
- beforeEach(() => {
12
- params = {
13
- // * Required base defaults
14
- source: 'some-source',
15
- type: 'some-type',
16
- }
17
- })
18
-
19
- it('returns a string', () => {
20
- const { time } = new Cloudevent(params)
21
- expect(time).to.be.a('string')
22
- })
23
-
24
- it('returns the current datetime in ISO8601 format', () => {
25
- const clock = useFakeTimers()
26
-
27
- clock.tick(987654321) // * Jump into the future
28
- const expected = new Date().toISOString()
29
- const { time } = new Cloudevent(params)
30
-
31
- clock.tick(123456789) // * Jump into the future
32
- expect(time).to.be.iso8601('eq', expected)
33
-
34
- clock.restore()
35
- })
36
- })
@@ -1,39 +0,0 @@
1
- import { Cloudevent } from '../../index.js'
2
- import { expect } from 'chai'
3
-
4
- describe('cloudevent#type', () => {
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 #type value is not input', () => {
16
- it('throws the proper error', () => {
17
- const expected = 'Cloudevent "type" must be of type STRING'
18
- params.type = null
19
- expect(() => new Cloudevent(params)).to.throw(expected)
20
- })
21
- })
22
-
23
- describe('when a #type value is input', () => {
24
- describe('when the input value is not a string', () => {
25
- it('throws the proper error', () => {
26
- const expected = 'Cloudevent "type" must be of type STRING'
27
- params.type = 1234
28
- expect(() => new Cloudevent(params)).to.throw(expected)
29
- })
30
- })
31
-
32
- describe('when the input value is a string', () => {
33
- it('returns the input value', () => {
34
- const { type } = new Cloudevent(params)
35
- expect(type).to.eq(params.type)
36
- })
37
- })
38
- })
39
- })
@@ -1,39 +0,0 @@
1
- import { Cloudevent } from '../../index.js'
2
- import { expect } from 'chai'
3
-
4
- describe('cloudevent#wschannelid', () => {
5
- let params
6
-
7
- beforeEach(() => {
8
- params = {
9
- // * Required base defaults
10
- source: 'some-source',
11
- type: 'some-type',
12
- }
13
- })
14
-
15
- describe('when #wschannelid is not input', () => {
16
- it('returns undefined', () => {
17
- const { wschannelid } = new Cloudevent(params)
18
- expect(wschannelid).to.be.undefined
19
- })
20
- })
21
-
22
- describe('when #wschannelid is input', () => {
23
- describe('when the input value is invalid', () => {
24
- it('throws the proper error', () => {
25
- const expected = 'Cloudevent "wschannelid" must be of type STRING or UNDEFINED'
26
- params.wschannelid = 1234
27
- expect(() => new Cloudevent(params)).to.throw(expected)
28
- })
29
- })
30
-
31
- describe('when the input value is valid', () => {
32
- it('returns the input value', () => {
33
- params.wschannelid = 'some-wschannel-id'
34
- const { wschannelid } = new Cloudevent(params)
35
- expect(wschannelid).to.eq(params.wschannelid)
36
- })
37
- })
38
- })
39
- })
@@ -1,74 +0,0 @@
1
- import { Cloudevent } from '../../../index.js'
2
- import { expect } from 'chai'
3
-
4
- describe('cloudevent.origin#originactor', () => {
5
- let ce
6
- let cloudevent
7
- let params
8
-
9
- beforeEach(() => {
10
- // Cloudevent we are acting on
11
- ce = new Cloudevent({
12
- source: 'some-source',
13
- type: 'some-type',
14
- })
15
-
16
- // Cloudevent we are treating as the origin
17
- cloudevent = new Cloudevent({
18
- source: 'source-of-origin-cloudevent',
19
- type: 'type-of-origin-cloudevent',
20
- })
21
-
22
- params = {
23
- cloudevent,
24
- originid: 'some-origin-id',
25
- originsource: 'some-origin-source',
26
- origintime: 'some-origin-time',
27
- origintype: 'some-origin-type',
28
- }
29
- })
30
-
31
-
32
- describe('when #originactor is not input', () => {
33
- beforeEach(() => {
34
- params.originactor = undefined
35
- })
36
-
37
- describe('when #cloudevent is not input', () => {
38
- it('returns undefined', () => {
39
- params.cloudevent = undefined
40
- ce.origin(params)
41
- expect(ce.originactor).to.be.undefined
42
- })
43
- })
44
-
45
- describe('when #cloudevent is input', () => {
46
- describe('when #cloudevent#originactor does not exist', () => {
47
- it('returns undefined', () => {
48
- cloudevent.originactor = undefined
49
- ce.origin({ cloudevent })
50
- expect(ce.originactor).to.be.undefined
51
- })
52
- })
53
-
54
- describe('when #cloudevent#originactor does exist', () => {
55
- it('returns #cloudevent#originactor', () => {
56
- const expected = 'some-originactor'
57
-
58
- cloudevent.originactor = expected
59
- ce.origin({ cloudevent })
60
-
61
- expect(ce.originactor).to.eq(expected)
62
- })
63
- })
64
- })
65
- })
66
-
67
- describe('when #originactor is input', () => {
68
- it('returns the input value', () => {
69
- const expected = 'some-originactor'
70
- ce.origin({ cloudevent, originactor: expected })
71
- expect(ce.originactor).to.eq(expected)
72
- })
73
- })
74
- })
@@ -1,85 +0,0 @@
1
- import { Cloudevent } from '../../../index.js'
2
- import { expect } from 'chai'
3
-
4
- describe('cloudevent.origin#originid', () => {
5
- let ce
6
- let cloudevent
7
- let params
8
-
9
- beforeEach(() => {
10
- // Cloudevent we are acting on
11
- ce = new Cloudevent({
12
- source: 'some-source',
13
- type: 'some-type',
14
- })
15
-
16
- // Cloudevent we are treating as the origin
17
- cloudevent = new Cloudevent({
18
- source: 'source-of-origin-cloudevent',
19
- type: 'type-of-origin-cloudevent',
20
- })
21
-
22
- params = {
23
- cloudevent,
24
- originid: 'some-origin-id',
25
- originsource: 'some-origin-source',
26
- origintime: 'some-origin-time',
27
- origintype: 'some-origin-type',
28
- }
29
- })
30
-
31
- describe('when #originid is not input', () => {
32
- beforeEach(() => {
33
- params.originid = undefined
34
- })
35
-
36
- describe('when #cloudevent is not input', () => {
37
- it('throws the proper error', () => {
38
- params.cloudevent = undefined
39
- const expected = 'Cloudevent "originid" must be of type STRING'
40
- expect(() => ce.origin(params)).to.throw(expected)
41
- })
42
- })
43
-
44
- describe('when #cloudevent is input', () => {
45
- describe('when #cloudevent#originid does not exist', () => {
46
- beforeEach(() => {
47
- cloudevent.originid = undefined
48
- })
49
-
50
- describe('when #cloudevent#id does not exist', () => {
51
- it('throws the proper error', () => {
52
- cloudevent.id = undefined
53
- const expected = 'Cloudevent "originid" must be of type STRING'
54
- expect(() => ce.origin(params)).to.throw(expected)
55
- })
56
- })
57
-
58
- describe('when #cloudevent#id does exist', () => {
59
- it('returns the input #cloudevent#id', () => {
60
- ce.origin(params)
61
- expect(ce.originid).to.eq(cloudevent.id)
62
- })
63
- })
64
- })
65
-
66
- describe('when #cloudevent#originid exists', () => {
67
- it('returns the input #cloudevent#originid', () => {
68
- const expected = 'some-new-origin-id'
69
-
70
- cloudevent.originid = expected
71
- ce.origin(params)
72
-
73
- expect(ce.originid).to.eq(expected)
74
- })
75
- })
76
- })
77
- })
78
-
79
- describe('when #originid is input', () => {
80
- it('returns the input value', () => {
81
- ce.origin(params)
82
- expect(ce.originid).to.eq(params.originid)
83
- })
84
- })
85
- })
@@ -1,85 +0,0 @@
1
- import { Cloudevent } from '../../../index.js'
2
- import { expect } from 'chai'
3
-
4
- describe('cloudevent.origin#originsource', () => {
5
- let ce
6
- let cloudevent
7
- let params
8
-
9
- beforeEach(() => {
10
- // Cloudevent we are acting on
11
- ce = new Cloudevent({
12
- source: 'some-source',
13
- type: 'some-type',
14
- })
15
-
16
- // Cloudevent we are treating as the origin
17
- cloudevent = new Cloudevent({
18
- source: 'source-of-origin-cloudevent',
19
- type: 'type-of-origin-cloudevent',
20
- })
21
-
22
- params = {
23
- cloudevent,
24
- originid: 'some-origin-id',
25
- originsource: 'some-origin-source',
26
- origintime: 'some-origin-time',
27
- origintype: 'some-origin-type',
28
- }
29
- })
30
-
31
- describe('when #originsource is not input', () => {
32
- beforeEach(() => {
33
- params.originsource = undefined
34
- })
35
-
36
- describe('when #cloudevent is not input', () => {
37
- it('throws the proper error', () => {
38
- const expected = 'Cloudevent "originsource" must be of type STRING'
39
- params.cloudevent = undefined
40
- expect(() => ce.origin(params)).to.throw(expected)
41
- })
42
- })
43
-
44
- describe('when #cloudevent is input', () => {
45
- describe('when #cloudevent#originsource does not exist', () => {
46
- beforeEach(() => {
47
- cloudevent.originsource = undefined
48
- })
49
-
50
- describe('when #cloudevent#source does not exist', () => {
51
- it('throws the proper error', () => {
52
- cloudevent.source = undefined
53
- const expected = 'Cloudevent "originsource" must be of type STRING'
54
- expect(() => ce.origin(params)).to.throw(expected)
55
- })
56
- })
57
-
58
- describe('when #cloudevent#source does exist', () => {
59
- it('returns the input #cloudevent#source', () => {
60
- ce.origin(params)
61
- expect(ce.originsource).to.eq(cloudevent.source)
62
- })
63
- })
64
- })
65
-
66
- describe('when #cloudevent#originsource exists', () => {
67
- it('returns the input #cloudevent#originsource', () => {
68
- const expected = 'some-new-origin-source'
69
-
70
- cloudevent.originsource = expected
71
- ce.origin(params)
72
-
73
- expect(ce.originsource).to.eq(expected)
74
- })
75
- })
76
- })
77
- })
78
-
79
- describe('when #originsource is input', () => {
80
- it('returns the input value', () => {
81
- ce.origin(params)
82
- expect(ce.originsource).to.eq(params.originsource)
83
- })
84
- })
85
- })