@toa.io/core 1.0.0-alpha.32 → 1.0.0-alpha.321
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/package.json +28 -12
- package/transpiled/abandon.d.ts +9 -0
- package/transpiled/abandon.js +37 -0
- package/transpiled/abandon.js.map +1 -0
- package/transpiled/assignment.d.ts +6 -0
- package/transpiled/assignment.js +25 -0
- package/transpiled/assignment.js.map +1 -0
- package/transpiled/call.d.ts +10 -0
- package/transpiled/call.js +187 -0
- package/transpiled/call.js.map +1 -0
- package/transpiled/cascade.d.ts +7 -0
- package/transpiled/cascade.js +28 -0
- package/transpiled/cascade.js.map +1 -0
- package/transpiled/component.d.ts +17 -0
- package/transpiled/component.js +151 -0
- package/transpiled/component.js.map +1 -0
- package/transpiled/composition.d.ts +6 -0
- package/transpiled/composition.js +20 -0
- package/transpiled/composition.js.map +1 -0
- package/transpiled/connector.d.ts +71 -0
- package/transpiled/connector.js +248 -0
- package/transpiled/connector.js.map +1 -0
- package/transpiled/context.d.ts +25 -0
- package/transpiled/context.js +55 -0
- package/transpiled/context.js.map +1 -0
- package/transpiled/contract/component.d.ts +37 -0
- package/transpiled/contract/component.js +94 -0
- package/transpiled/contract/component.js.map +1 -0
- package/transpiled/contract/contract.d.ts +10 -0
- package/transpiled/contract/contract.js +14 -0
- package/transpiled/contract/contract.js.map +1 -0
- package/transpiled/contract/index.d.ts +4 -0
- package/transpiled/contract/index.js +5 -0
- package/transpiled/contract/index.js.map +1 -0
- package/transpiled/contract/reply.d.ts +7 -0
- package/transpiled/contract/reply.js +48 -0
- package/transpiled/contract/reply.js.map +1 -0
- package/transpiled/contract/request.d.ts +49 -0
- package/transpiled/contract/request.js +152 -0
- package/transpiled/contract/request.js.map +1 -0
- package/transpiled/contract/schemas.d.ts +4 -0
- package/transpiled/contract/schemas.js +38 -0
- package/transpiled/contract/schemas.js.map +1 -0
- package/transpiled/contract/system.d.ts +33 -0
- package/transpiled/contract/system.js +76 -0
- package/transpiled/contract/system.js.map +1 -0
- package/transpiled/deliveries.d.ts +22 -0
- package/transpiled/deliveries.js +31 -0
- package/transpiled/deliveries.js.map +1 -0
- package/transpiled/effect.d.ts +7 -0
- package/transpiled/effect.js +13 -0
- package/transpiled/effect.js.map +1 -0
- package/transpiled/emission.d.ts +10 -0
- package/transpiled/emission.js +16 -0
- package/transpiled/emission.js.map +1 -0
- package/transpiled/encoded.d.ts +16 -0
- package/transpiled/encoded.js +25 -0
- package/transpiled/encoded.js.map +1 -0
- package/transpiled/entities/changeset.d.ts +10 -0
- package/transpiled/entities/changeset.js +27 -0
- package/transpiled/entities/changeset.js.map +1 -0
- package/transpiled/entities/entity.d.ts +19 -0
- package/transpiled/entities/entity.js +137 -0
- package/transpiled/entities/entity.js.map +1 -0
- package/transpiled/entities/factory.d.ts +27 -0
- package/transpiled/entities/factory.js +38 -0
- package/transpiled/entities/factory.js.map +1 -0
- package/transpiled/entities/index.d.ts +5 -0
- package/transpiled/entities/index.js +6 -0
- package/transpiled/entities/index.js.map +1 -0
- package/transpiled/entities/newid.d.ts +11 -0
- package/transpiled/entities/newid.js +41 -0
- package/transpiled/entities/newid.js.map +1 -0
- package/transpiled/entities/set.d.ts +10 -0
- package/transpiled/entities/set.js +19 -0
- package/transpiled/entities/set.js.map +1 -0
- package/transpiled/event.d.ts +20 -0
- package/transpiled/event.js +65 -0
- package/transpiled/event.js.map +1 -0
- package/transpiled/exceptions.d.ts +110 -0
- package/transpiled/exceptions.js +215 -0
- package/transpiled/exceptions.js.map +1 -0
- package/transpiled/gate.d.ts +40 -0
- package/transpiled/gate.js +84 -0
- package/transpiled/gate.js.map +1 -0
- package/transpiled/guard.d.ts +7 -0
- package/transpiled/guard.js +12 -0
- package/transpiled/guard.js.map +1 -0
- package/transpiled/halting.d.ts +16 -0
- package/transpiled/halting.js +25 -0
- package/transpiled/halting.js.map +1 -0
- package/transpiled/index.d.ts +45 -0
- package/transpiled/index.js +37 -0
- package/transpiled/index.js.map +1 -0
- package/transpiled/instance.d.ts +10 -0
- package/transpiled/instance.js +30 -0
- package/transpiled/instance.js.map +1 -0
- package/transpiled/locator.d.ts +12 -0
- package/transpiled/locator.js +32 -0
- package/transpiled/locator.js.map +1 -0
- package/transpiled/measurements.d.ts +20 -0
- package/transpiled/measurements.js +40 -0
- package/transpiled/measurements.js.map +1 -0
- package/transpiled/observation.d.ts +7 -0
- package/transpiled/observation.js +14 -0
- package/transpiled/observation.js.map +1 -0
- package/transpiled/operation.d.ts +77 -0
- package/transpiled/operation.js +216 -0
- package/transpiled/operation.js.map +1 -0
- package/transpiled/outbox.d.ts +45 -0
- package/transpiled/outbox.js +448 -0
- package/transpiled/outbox.js.map +1 -0
- package/transpiled/outbox.measurements.d.ts +4 -0
- package/transpiled/outbox.measurements.js +38 -0
- package/transpiled/outbox.measurements.js.map +1 -0
- package/transpiled/parts.d.ts +20 -0
- package/transpiled/parts.js +23 -0
- package/transpiled/parts.js.map +1 -0
- package/transpiled/query/criteria.d.ts +6 -0
- package/transpiled/query/criteria.js +177 -0
- package/transpiled/query/criteria.js.map +1 -0
- package/transpiled/query/options.d.ts +3 -0
- package/transpiled/query/options.js +34 -0
- package/transpiled/query/options.js.map +1 -0
- package/transpiled/query.d.ts +9 -0
- package/transpiled/query.js +57 -0
- package/transpiled/query.js.map +1 -0
- package/transpiled/receiver.d.ts +20 -0
- package/transpiled/receiver.js +113 -0
- package/transpiled/receiver.js.map +1 -0
- package/transpiled/reflection.d.ts +9 -0
- package/transpiled/reflection.js +13 -0
- package/transpiled/reflection.js.map +1 -0
- package/transpiled/regional.d.ts +22 -0
- package/transpiled/regional.js +55 -0
- package/transpiled/regional.js.map +1 -0
- package/transpiled/remote.d.ts +10 -0
- package/transpiled/remote.js +11 -0
- package/transpiled/remote.js.map +1 -0
- package/transpiled/rendering.d.ts +13 -0
- package/transpiled/rendering.js +21 -0
- package/transpiled/rendering.js.map +1 -0
- package/transpiled/safety.d.ts +5 -0
- package/transpiled/safety.js +26 -0
- package/transpiled/safety.js.map +1 -0
- package/transpiled/state.d.ts +36 -0
- package/transpiled/state.js +131 -0
- package/transpiled/state.js.map +1 -0
- package/transpiled/trail.d.ts +78 -0
- package/transpiled/trail.js +112 -0
- package/transpiled/trail.js.map +1 -0
- package/transpiled/transition.d.ts +14 -0
- package/transpiled/transition.js +51 -0
- package/transpiled/transition.js.map +1 -0
- package/transpiled/transmission.d.ts +8 -0
- package/transpiled/transmission.js +30 -0
- package/transpiled/transmission.js.map +1 -0
- package/transpiled/types/atomicity.d.ts +58 -0
- package/transpiled/types/atomicity.js +2 -0
- package/transpiled/types/atomicity.js.map +1 -0
- package/transpiled/types/bindings.d.ts +82 -0
- package/transpiled/types/bindings.js +2 -0
- package/transpiled/types/bindings.js.map +1 -0
- package/transpiled/types/bridges.d.ts +41 -0
- package/transpiled/types/bridges.js +2 -0
- package/transpiled/types/bridges.js.map +1 -0
- package/transpiled/types/extensions.d.ts +121 -0
- package/transpiled/types/extensions.js +2 -0
- package/transpiled/types/extensions.js.map +1 -0
- package/transpiled/types/inbox.d.ts +27 -0
- package/transpiled/types/inbox.js +2 -0
- package/transpiled/types/inbox.js.map +1 -0
- package/transpiled/types/index.d.ts +14 -0
- package/transpiled/types/index.js +9 -0
- package/transpiled/types/index.js.map +1 -0
- package/transpiled/types/message.d.ts +16 -0
- package/transpiled/types/message.js +2 -0
- package/transpiled/types/message.js.map +1 -0
- package/transpiled/types/operations.d.ts +15 -0
- package/transpiled/types/operations.js +2 -0
- package/transpiled/types/operations.js.map +1 -0
- package/transpiled/types/outbox.d.ts +93 -0
- package/transpiled/types/outbox.js +2 -0
- package/transpiled/types/outbox.js.map +1 -0
- package/transpiled/types/receiver.d.ts +9 -0
- package/transpiled/types/receiver.js +2 -0
- package/transpiled/types/receiver.js.map +1 -0
- package/transpiled/types/request.d.ts +119 -0
- package/transpiled/types/request.js +2 -0
- package/transpiled/types/request.js.map +1 -0
- package/transpiled/types/state.d.ts +9 -0
- package/transpiled/types/state.js +2 -0
- package/transpiled/types/state.js.map +1 -0
- package/transpiled/types/storages.d.ts +158 -0
- package/transpiled/types/storages.js +2 -0
- package/transpiled/types/storages.js.map +1 -0
- package/transpiled/unmanaged.d.ts +5 -0
- package/transpiled/unmanaged.js +7 -0
- package/transpiled/unmanaged.js.map +1 -0
- package/src/assignment.js +0 -31
- package/src/call.js +0 -42
- package/src/cascade.js +0 -35
- package/src/component.js +0 -41
- package/src/composition.js +0 -25
- package/src/connector.js +0 -183
- package/src/context.js +0 -55
- package/src/contract/conditions.js +0 -21
- package/src/contract/index.js +0 -7
- package/src/contract/reply.js +0 -25
- package/src/contract/request.js +0 -67
- package/src/contract/schemas/error.yaml +0 -9
- package/src/contract/schemas/index.js +0 -7
- package/src/contract/schemas/query.yaml +0 -30
- package/src/discovery.js +0 -44
- package/src/emission.js +0 -23
- package/src/entities/changeset.js +0 -38
- package/src/entities/entity.js +0 -74
- package/src/entities/factory.js +0 -33
- package/src/entities/index.js +0 -5
- package/src/entities/set.js +0 -15
- package/src/event.js +0 -40
- package/src/exceptions.js +0 -100
- package/src/exposition.js +0 -27
- package/src/index.js +0 -47
- package/src/locator.js +0 -54
- package/src/observation.js +0 -20
- package/src/operation.js +0 -69
- package/src/query/criteria.js +0 -41
- package/src/query/options.js +0 -40
- package/src/query.js +0 -41
- package/src/receiver.js +0 -61
- package/src/reflection.js +0 -28
- package/src/remote.js +0 -17
- package/src/state.js +0 -99
- package/src/transition.js +0 -67
- package/src/transmission.js +0 -33
- package/test/call.fixtures.js +0 -27
- package/test/call.test.js +0 -46
- package/test/component.fixtures.js +0 -21
- package/test/component.test.js +0 -40
- package/test/connector.fixtures.js +0 -40
- package/test/connector.test.js +0 -176
- package/test/context.fixtures.js +0 -18
- package/test/context.test.js +0 -29
- package/test/contract/conditions.test.js +0 -26
- package/test/contract/contract.fixtures.js +0 -33
- package/test/contract/request.test.js +0 -112
- package/test/emission.fixtures.js +0 -17
- package/test/emission.test.js +0 -35
- package/test/entities/entity.fixtures.js +0 -29
- package/test/entities/entity.test.js +0 -65
- package/test/entities/factory.fixtures.js +0 -18
- package/test/entities/factory.test.js +0 -48
- package/test/entities/set.fixtures.js +0 -11
- package/test/entities/set.test.js +0 -12
- package/test/event.fixtures.js +0 -29
- package/test/event.test.js +0 -118
- package/test/locator.test.js +0 -113
- package/test/query.fixtures.js +0 -100
- package/test/query.test.js +0 -86
- package/test/receiver.fixtures.js +0 -23
- package/test/receiver.test.js +0 -95
- package/test/reflection.test.js +0 -30
- package/test/state.fixtures.js +0 -47
- package/test/state.test.js +0 -46
- package/test/transmission.fixtures.js +0 -15
- package/test/transmission.test.js +0 -46
- package/types/bindings.d.ts +0 -40
- package/types/bridges.ts +0 -30
- package/types/component.d.ts +0 -9
- package/types/connector.d.ts +0 -18
- package/types/context.d.ts +0 -21
- package/types/entity.d.ts +0 -46
- package/types/event.d.ts +0 -11
- package/types/exception.d.ts +0 -4
- package/types/extensions.d.ts +0 -29
- package/types/index.ts +0 -14
- package/types/locator.d.ts +0 -13
- package/types/message.d.ts +0 -3
- package/types/operations.d.ts +0 -2
- package/types/query.d.ts +0 -15
- package/types/receiver.d.ts +0 -12
- package/types/reflection.d.ts +0 -14
- package/types/request.d.ts +0 -23
- package/types/state.d.ts +0 -35
- package/types/storages.d.ts +0 -71
package/test/connector.test.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const fixtures = require('./connector.fixtures')
|
|
4
|
-
|
|
5
|
-
let sequence
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
sequence = []
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
describe('callbacks', () => {
|
|
12
|
-
let a
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
a = new fixtures.TestConnector('a', sequence)
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
it('should call connection', async () => {
|
|
19
|
-
await a.connect()
|
|
20
|
-
expect(sequence).toEqual(['+a'])
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('should call disconnection', async () => {
|
|
24
|
-
await a.connect()
|
|
25
|
-
await a.disconnect()
|
|
26
|
-
|
|
27
|
-
expect(sequence.indexOf('+a')).toBeLessThan(sequence.indexOf('-a'))
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('should reconnect', async () => {
|
|
31
|
-
await a.connect()
|
|
32
|
-
await a.reconnect()
|
|
33
|
-
await a.reconnect()
|
|
34
|
-
|
|
35
|
-
expect(sequence).toEqual(['+a', '-a', '*a', '+a', '-a', '*a', '+a'])
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
describe('dependencies', () => {
|
|
40
|
-
let a
|
|
41
|
-
let b
|
|
42
|
-
let c
|
|
43
|
-
let d
|
|
44
|
-
|
|
45
|
-
beforeEach(() => {
|
|
46
|
-
a = new fixtures.TestConnector('a', sequence)
|
|
47
|
-
b = new fixtures.TestConnector('b', sequence)
|
|
48
|
-
c = new fixtures.TestConnector('c', sequence)
|
|
49
|
-
d = new fixtures.TestConnector('d', sequence)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it('should wait dependencies on connection', async () => {
|
|
53
|
-
a.depends(b).depends(c)
|
|
54
|
-
a.depends(d)
|
|
55
|
-
|
|
56
|
-
await a.connect()
|
|
57
|
-
|
|
58
|
-
expect(sequence.indexOf('+c')).toBeLessThan(sequence.indexOf('+b'))
|
|
59
|
-
expect(sequence.indexOf('+b')).toBeLessThan(sequence.indexOf('+a'))
|
|
60
|
-
expect(sequence.indexOf('+d')).toBeLessThan(sequence.indexOf('+a'))
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('should wait array of connectors', async () => {
|
|
64
|
-
a.depends([b, d])
|
|
65
|
-
b.depends(c)
|
|
66
|
-
d.depends(c)
|
|
67
|
-
|
|
68
|
-
await a.connect()
|
|
69
|
-
|
|
70
|
-
expect(sequence.indexOf('+c')).toBeLessThan(sequence.indexOf('+b'))
|
|
71
|
-
expect(sequence.indexOf('+c')).toBeLessThan(sequence.indexOf('+d'))
|
|
72
|
-
expect(sequence.indexOf('+b')).toBeLessThan(sequence.indexOf('+a'))
|
|
73
|
-
expect(sequence.indexOf('+d')).toBeLessThan(sequence.indexOf('+a'))
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
it('should wait array(1) of connectors', async () => {
|
|
77
|
-
a.depends([b])
|
|
78
|
-
b.depends(c)
|
|
79
|
-
|
|
80
|
-
await a.connect()
|
|
81
|
-
|
|
82
|
-
expect(sequence.indexOf('+c')).toBeLessThan(sequence.indexOf('+b'))
|
|
83
|
-
expect(sequence.indexOf('+b')).toBeLessThan(sequence.indexOf('+a'))
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
it('should throw on empty array', async () => {
|
|
87
|
-
expect(() => a.depends([])).toThrow(/must not be empty/)
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
it('should await 2-way dependencies', async () => {
|
|
91
|
-
a.depends([b, c, d])
|
|
92
|
-
d.depends([b, c])
|
|
93
|
-
|
|
94
|
-
await a.connect()
|
|
95
|
-
|
|
96
|
-
expect(sequence.indexOf('+b')).toBeLessThan(sequence.indexOf('+a'))
|
|
97
|
-
expect(sequence.indexOf('+c')).toBeLessThan(sequence.indexOf('+a'))
|
|
98
|
-
expect(sequence.indexOf('+d')).toBeLessThan(sequence.indexOf('+a'))
|
|
99
|
-
|
|
100
|
-
expect(sequence.indexOf('+b')).toBeLessThan(sequence.indexOf('+d'))
|
|
101
|
-
expect(sequence.indexOf('+c')).toBeLessThan(sequence.indexOf('+d'))
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
it('should disconnect before dependencies', async () => {
|
|
105
|
-
a.depends(b).depends(c)
|
|
106
|
-
b.depends(d)
|
|
107
|
-
|
|
108
|
-
await a.disconnect()
|
|
109
|
-
|
|
110
|
-
expect(sequence.indexOf('-a')).toBeLessThan(sequence.indexOf('-b'))
|
|
111
|
-
expect(sequence.indexOf('-b')).toBeLessThan(sequence.indexOf('-c'))
|
|
112
|
-
expect(sequence.indexOf('-b')).toBeLessThan(sequence.indexOf('-d'))
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
it('should call disconnected', async () => {
|
|
116
|
-
a.depends(b).depends(c)
|
|
117
|
-
b.depends(d)
|
|
118
|
-
|
|
119
|
-
await a.disconnect()
|
|
120
|
-
|
|
121
|
-
expect(sequence.indexOf('*c')).toBeLessThan(sequence.indexOf('*b'))
|
|
122
|
-
expect(sequence.indexOf('*b')).toBeLessThan(sequence.indexOf('*a'))
|
|
123
|
-
expect(sequence.indexOf('*d')).toBeLessThan(sequence.indexOf('*b'))
|
|
124
|
-
expect(sequence.indexOf('*a')).toBe(sequence.length - 1)
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
it('should disconnect if no parents left', async () => {
|
|
128
|
-
a.depends(c)
|
|
129
|
-
b.depends(c)
|
|
130
|
-
|
|
131
|
-
await a.connect()
|
|
132
|
-
await b.connect()
|
|
133
|
-
|
|
134
|
-
expect(sequence).toEqual(['+c', '+a', '+b'])
|
|
135
|
-
|
|
136
|
-
await a.disconnect()
|
|
137
|
-
|
|
138
|
-
expect(sequence).toEqual(['+c', '+a', '+b', '-a', '*a'])
|
|
139
|
-
|
|
140
|
-
await b.disconnect()
|
|
141
|
-
|
|
142
|
-
expect(sequence).toEqual(['+c', '+a', '+b', '-a', '*a', '-b', '-c', '*c', '*b'])
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
it('should throw if depends not on Connector', async () => {
|
|
146
|
-
expect(() => a.depends({})).toThrow()
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
describe('errors', () => {
|
|
150
|
-
let f
|
|
151
|
-
|
|
152
|
-
beforeEach(() => {
|
|
153
|
-
f = new fixtures.FailingConnector()
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
it('should disconnect on fail', async () => {
|
|
157
|
-
f.depends(b).depends(c)
|
|
158
|
-
|
|
159
|
-
await expect(f.connect()).rejects.toThrow('FailingConnector')
|
|
160
|
-
expect(sequence).toEqual(['+c', '+b', '-b', '-c', '*c', '*b'])
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
it('should interrupt connection chain', async () => {
|
|
164
|
-
a.depends(f).depends(c)
|
|
165
|
-
f.depends(d)
|
|
166
|
-
|
|
167
|
-
await expect(a.connect()).rejects.toThrow('FailingConnector')
|
|
168
|
-
|
|
169
|
-
expect(sequence.indexOf('+c')).toBeLessThan(sequence.indexOf('-c'))
|
|
170
|
-
expect(sequence.indexOf('+d')).toBeLessThan(sequence.indexOf('-d'))
|
|
171
|
-
|
|
172
|
-
expect(sequence.indexOf('+a')).toBe(-1)
|
|
173
|
-
expect(sequence.indexOf('-a')).toBe(-1)
|
|
174
|
-
})
|
|
175
|
-
})
|
|
176
|
-
})
|
package/test/context.fixtures.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Connector } = require('../src/connector')
|
|
4
|
-
|
|
5
|
-
const local = {
|
|
6
|
-
link: jest.fn()
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const discover = jest.fn(() => ({
|
|
10
|
-
invoke: jest.fn(),
|
|
11
|
-
link: jest.fn()
|
|
12
|
-
}))
|
|
13
|
-
|
|
14
|
-
const aspects = [new Connector(), new Connector()]
|
|
15
|
-
|
|
16
|
-
exports.local = local
|
|
17
|
-
exports.discover = discover
|
|
18
|
-
exports.aspects = aspects
|
package/test/context.test.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const fixtures = require('./context.fixtures')
|
|
4
|
-
const { Context } = require('../src/context')
|
|
5
|
-
|
|
6
|
-
/** @type {toa.core.Context} */
|
|
7
|
-
let context
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
jest.clearAllMocks()
|
|
11
|
-
|
|
12
|
-
context = new Context(fixtures.local, fixtures.discover, fixtures.aspects)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
it('should expose aspects', () => {
|
|
16
|
-
expect(context.aspects).toBeDefined()
|
|
17
|
-
expect(context.aspects).toStrictEqual(fixtures.aspects)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
describe('call', () => {
|
|
21
|
-
it('should discover once', async () => {
|
|
22
|
-
const request = {}
|
|
23
|
-
|
|
24
|
-
await context.call('a', 'b', 'c', request)
|
|
25
|
-
await context.call('a', 'b', 'c', request)
|
|
26
|
-
|
|
27
|
-
expect(fixtures.discover).toHaveBeenCalledTimes(1)
|
|
28
|
-
})
|
|
29
|
-
})
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
4
|
-
|
|
5
|
-
const { Conditions } = require('../../src/contract/conditions')
|
|
6
|
-
const fixtures = require('./contract.fixtures')
|
|
7
|
-
|
|
8
|
-
let conditions
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
conditions = new Conditions(fixtures.schema)
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it('should fit value', () => {
|
|
15
|
-
const value = { foo: generate() }
|
|
16
|
-
|
|
17
|
-
conditions.fit(value)
|
|
18
|
-
|
|
19
|
-
expect(fixtures.schema.fit).toHaveBeenCalledWith(value)
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('should throw on invalid value', () => {
|
|
23
|
-
const value = { invalid: true }
|
|
24
|
-
|
|
25
|
-
expect(() => conditions.fit(value)).toThrow()
|
|
26
|
-
})
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
4
|
-
const { load } = require('@toa.io/yaml')
|
|
5
|
-
const { resolve } = require('path')
|
|
6
|
-
|
|
7
|
-
// noinspection JSCheckFunctionSignatures
|
|
8
|
-
const schema = {
|
|
9
|
-
fit: jest.fn((input) => (input.invalid ? { message: generate() } : null))
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const query = {
|
|
13
|
-
parse: jest.fn(() => ({ [generate()]: generate() }))
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const declaration = {}
|
|
17
|
-
|
|
18
|
-
const schemas = {
|
|
19
|
-
request: {
|
|
20
|
-
type: 'object',
|
|
21
|
-
properties: {
|
|
22
|
-
input: { type: 'null' },
|
|
23
|
-
query: load.sync(resolve(__dirname, '../../src/contract/schemas/query.yaml')),
|
|
24
|
-
authentic: { type: 'boolean' }
|
|
25
|
-
},
|
|
26
|
-
additionalProperties: true
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
exports.schema = schema
|
|
31
|
-
exports.query = query
|
|
32
|
-
exports.declaration = declaration
|
|
33
|
-
exports.schemas = schemas
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const clone = require('clone-deep')
|
|
4
|
-
const { generate } = require('randomstring')
|
|
5
|
-
|
|
6
|
-
jest.mock('../../src/contract/conditions')
|
|
7
|
-
|
|
8
|
-
const { Request } = require('../../src/contract/request')
|
|
9
|
-
const { Conditions } = require('../../src/contract/conditions')
|
|
10
|
-
const fixtures = require('./contract.fixtures')
|
|
11
|
-
|
|
12
|
-
let contract
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
jest.clearAllMocks()
|
|
16
|
-
|
|
17
|
-
contract = new Request(fixtures.schema)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const dummy = { schema: { properties: {} } }
|
|
21
|
-
|
|
22
|
-
it('should extend Conditions', () => {
|
|
23
|
-
expect(contract).toBeInstanceOf(Conditions)
|
|
24
|
-
expect(Conditions).toHaveBeenCalledWith(fixtures.schema)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it('should fit request', () => {
|
|
28
|
-
const request = { [generate()]: generate() }
|
|
29
|
-
|
|
30
|
-
contract.fit(request)
|
|
31
|
-
|
|
32
|
-
expect(Conditions.mock.instances[0].fit).toHaveBeenCalledWith(request)
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
describe('schema', () => {
|
|
36
|
-
let schema
|
|
37
|
-
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
schema = clone(fixtures.schemas.request)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
it('should provide schema', () => {
|
|
43
|
-
expect(Request.schema({}, dummy)).toBeDefined()
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it('should add required input if defined', () => {
|
|
47
|
-
const input = { type: 'number' }
|
|
48
|
-
|
|
49
|
-
expect(Request.schema({ input }, dummy).properties.input).toStrictEqual(input)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it('should set input as null if undefined', async () => {
|
|
53
|
-
expect(Request.schema({}, dummy).properties.input).toStrictEqual({ type: 'null' })
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('should contain query if declaration.query is not defined', () => {
|
|
57
|
-
expect(Request.schema({}, dummy).properties.query).toBeDefined()
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it('should not contain query if declaration.query is false', () => {
|
|
61
|
-
schema.properties.query = { type: 'null' }
|
|
62
|
-
expect(Request.schema({ query: false }, dummy)).toStrictEqual(schema)
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
it('should require query if declaration.query is true', () => {
|
|
66
|
-
schema.required = ['query']
|
|
67
|
-
expect(Request.schema({ query: true }, dummy).required).toStrictEqual(expect.arrayContaining(['query']))
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
it('should forbid projection for non observations', () => {
|
|
71
|
-
expect(Request.schema({ type: 'transition' }, dummy).properties.query.properties.projection)
|
|
72
|
-
.toBe(undefined)
|
|
73
|
-
|
|
74
|
-
expect(Request.schema({ type: 'assignment' }, dummy).properties.query.properties.projection)
|
|
75
|
-
.toBe(undefined)
|
|
76
|
-
|
|
77
|
-
expect(Request.schema({ type: 'observation' }, dummy).properties.query.properties.projection)
|
|
78
|
-
.toBeDefined()
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
it('should forbid version for observations', () => {
|
|
82
|
-
expect(Request.schema({ type: 'transition' }, dummy).properties.query.properties.version)
|
|
83
|
-
.toBeDefined()
|
|
84
|
-
|
|
85
|
-
expect(Request.schema({ type: 'observation' }, dummy).properties.query.properties.version)
|
|
86
|
-
.toBe(undefined)
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('should allow omit, limit only for set observations', () => {
|
|
90
|
-
const schema = Request.schema({ type: 'transition' }, dummy)
|
|
91
|
-
const transition = schema.properties.query.properties
|
|
92
|
-
|
|
93
|
-
expect(transition.omit).toBeUndefined()
|
|
94
|
-
expect(transition.limit).toBeUndefined()
|
|
95
|
-
|
|
96
|
-
const object = Request.schema({
|
|
97
|
-
type: 'observation',
|
|
98
|
-
scope: 'object'
|
|
99
|
-
}, dummy).properties.query.properties
|
|
100
|
-
|
|
101
|
-
expect(object.omit).toBeUndefined()
|
|
102
|
-
expect(object.limit).toBeUndefined()
|
|
103
|
-
|
|
104
|
-
const objects = Request.schema({
|
|
105
|
-
type: 'observation',
|
|
106
|
-
scope: 'objects'
|
|
107
|
-
}, dummy).properties.query.properties
|
|
108
|
-
|
|
109
|
-
expect(objects.omit).toBeDefined()
|
|
110
|
-
expect(objects.limit).toBeDefined()
|
|
111
|
-
})
|
|
112
|
-
})
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
4
|
-
|
|
5
|
-
// noinspection JSCheckFunctionSignatures
|
|
6
|
-
const events = [0, 1, 2].map((index) => ({
|
|
7
|
-
emit: jest.fn(async (state) => ({ ...state, event: index }))
|
|
8
|
-
}))
|
|
9
|
-
|
|
10
|
-
const event = {
|
|
11
|
-
origin: { [generate()]: generate() },
|
|
12
|
-
state: { [generate()]: generate() },
|
|
13
|
-
changeset: { [generate()]: generate() }
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
exports.events = events
|
|
17
|
-
exports.event = event
|
package/test/emission.test.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
jest.mock('../src/connector')
|
|
4
|
-
|
|
5
|
-
const clone = require('clone-deep')
|
|
6
|
-
|
|
7
|
-
const { Connector } = require('../src/connector')
|
|
8
|
-
const { Emission } = require('../src/emission')
|
|
9
|
-
const fixtures = require('./emission.fixtures')
|
|
10
|
-
|
|
11
|
-
let emission, event
|
|
12
|
-
|
|
13
|
-
beforeEach(async () => {
|
|
14
|
-
jest.clearAllMocks()
|
|
15
|
-
|
|
16
|
-
emission = new Emission(fixtures.events)
|
|
17
|
-
event = clone(fixtures.event)
|
|
18
|
-
|
|
19
|
-
await emission.open()
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('should depend on events', () => {
|
|
23
|
-
expect(emission).toBeInstanceOf(Connector)
|
|
24
|
-
expect(Connector.mock.instances[0].depends).toHaveBeenCalledWith(fixtures.events)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it('should emit events', async () => {
|
|
28
|
-
expect.assertions(fixtures.events.length)
|
|
29
|
-
|
|
30
|
-
await emission.emit(event)
|
|
31
|
-
|
|
32
|
-
for (const evt of fixtures.events) {
|
|
33
|
-
expect(evt.emit).toHaveBeenCalledWith(event)
|
|
34
|
-
}
|
|
35
|
-
})
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
4
|
-
|
|
5
|
-
// noinspection JSCheckFunctionSignatures
|
|
6
|
-
const schema = {
|
|
7
|
-
fit: jest.fn((object) =>
|
|
8
|
-
(object.fail ? { [generate()]: generate() } : null)),
|
|
9
|
-
|
|
10
|
-
defaults: jest.fn(() => ({ [generate()]: generate() }))
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const state = () => ({
|
|
14
|
-
id: generate(),
|
|
15
|
-
foo: generate(),
|
|
16
|
-
_created: generate(),
|
|
17
|
-
_updated: generate(),
|
|
18
|
-
_deleted: generate(),
|
|
19
|
-
_version: 0
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
const failed = () => ({
|
|
23
|
-
...state(),
|
|
24
|
-
fail: true
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
exports.schema = schema
|
|
28
|
-
exports.state = state
|
|
29
|
-
exports.failed = failed
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Entity } = require('../../src/entities/entity')
|
|
4
|
-
const fixtures = require('./entity.fixtures')
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
jest.clearAllMocks()
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
describe('new', () => {
|
|
11
|
-
it('should throw on schema error', () => {
|
|
12
|
-
const entity = new Entity(fixtures.schema)
|
|
13
|
-
|
|
14
|
-
expect(() => entity.set(fixtures.failed())).toThrow()
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it('should provide state', () => {
|
|
18
|
-
const entity = new Entity(fixtures.schema)
|
|
19
|
-
const state = fixtures.state()
|
|
20
|
-
|
|
21
|
-
entity.set(state)
|
|
22
|
-
|
|
23
|
-
expect(entity.get()).toEqual(state)
|
|
24
|
-
})
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
describe('argument', () => {
|
|
28
|
-
it('should provide initial state if no argument passed', () => {
|
|
29
|
-
const entity = new Entity(fixtures.schema)
|
|
30
|
-
const defaults = fixtures.schema.defaults.mock.results[0].value
|
|
31
|
-
const expected = {
|
|
32
|
-
...defaults,
|
|
33
|
-
_version: 0
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
expect(entity.get()).toStrictEqual(expect.objectContaining(expected))
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('should set state', () => {
|
|
40
|
-
const state = fixtures.state()
|
|
41
|
-
const entity = new Entity(fixtures.schema, state)
|
|
42
|
-
|
|
43
|
-
expect(entity.get()).toEqual(state)
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it('should provide event', () => {
|
|
48
|
-
const origin = fixtures.state()
|
|
49
|
-
const entity = new Entity(fixtures.schema, origin)
|
|
50
|
-
const state = entity.get()
|
|
51
|
-
|
|
52
|
-
state.foo = 'new value'
|
|
53
|
-
entity.set(state)
|
|
54
|
-
|
|
55
|
-
const event = entity.event()
|
|
56
|
-
|
|
57
|
-
expect(event).toEqual(expect.objectContaining({
|
|
58
|
-
state,
|
|
59
|
-
origin,
|
|
60
|
-
changeset: expect.objectContaining({
|
|
61
|
-
foo: 'new value',
|
|
62
|
-
_version: 1
|
|
63
|
-
})
|
|
64
|
-
}))
|
|
65
|
-
})
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const randomstring = require('randomstring')
|
|
4
|
-
|
|
5
|
-
const schema = { [randomstring.generate()]: randomstring.generate() }
|
|
6
|
-
const storage = { id: jest.fn(() => randomstring.generate()) }
|
|
7
|
-
const entity = { [randomstring.generate()]: randomstring.generate() }
|
|
8
|
-
const set = Array.from(Array(5))
|
|
9
|
-
.map((_, index) => ({ id: index, [randomstring.generate()]: randomstring.generate() }))
|
|
10
|
-
|
|
11
|
-
const Entity = jest.fn().mockImplementation(function () { this.id = randomstring.generate() })
|
|
12
|
-
const EntitySet = jest.fn().mockImplementation(function () {})
|
|
13
|
-
|
|
14
|
-
exports.schema = schema
|
|
15
|
-
exports.storage = storage
|
|
16
|
-
exports.entity = entity
|
|
17
|
-
exports.set = set
|
|
18
|
-
exports.mock = { Entity, EntitySet }
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
4
|
-
|
|
5
|
-
const fixtures = require('./factory.fixtures')
|
|
6
|
-
const mock = fixtures.mock
|
|
7
|
-
|
|
8
|
-
jest.mock('../../src/entities/entity', () => ({ Entity: mock.Entity }))
|
|
9
|
-
jest.mock('../../src/entities/set', () => ({ EntitySet: mock.EntitySet }))
|
|
10
|
-
|
|
11
|
-
const { Factory } = require('../../src/entities/factory')
|
|
12
|
-
|
|
13
|
-
let factory
|
|
14
|
-
|
|
15
|
-
beforeEach(async () => {
|
|
16
|
-
jest.clearAllMocks()
|
|
17
|
-
|
|
18
|
-
factory = new Factory(fixtures.schema, () => fixtures.storage.id())
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('should create initial', () => {
|
|
22
|
-
const id = generate()
|
|
23
|
-
const initial = factory.init(id)
|
|
24
|
-
|
|
25
|
-
expect(initial).toBeInstanceOf(mock.Entity)
|
|
26
|
-
expect(initial.constructor).toHaveBeenCalledWith(fixtures.schema, id)
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('should create instance', () => {
|
|
30
|
-
const object = factory.object(fixtures.entity)
|
|
31
|
-
|
|
32
|
-
expect(object).toBeInstanceOf(mock.Entity)
|
|
33
|
-
expect(object.constructor).toHaveBeenCalledWith(fixtures.schema, fixtures.entity)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('should create set', () => {
|
|
37
|
-
const objects = factory.objects(fixtures.set)
|
|
38
|
-
|
|
39
|
-
expect(objects).toBeInstanceOf(mock.EntitySet)
|
|
40
|
-
|
|
41
|
-
const instances = fixtures.set.map((entity, index) => {
|
|
42
|
-
expect(mock.Entity).toHaveBeenNthCalledWith(index + 1, fixtures.schema, entity)
|
|
43
|
-
|
|
44
|
-
return mock.Entity.mock.instances[index]
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
expect(objects.constructor).toHaveBeenCalledWith(instances)
|
|
48
|
-
})
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
4
|
-
|
|
5
|
-
const set = [
|
|
6
|
-
{ get: jest.fn(() => ({ [generate()]: generate() })) },
|
|
7
|
-
{ get: jest.fn(() => ({ [generate()]: generate() })) },
|
|
8
|
-
{ get: jest.fn(() => ({ [generate()]: generate() })) }
|
|
9
|
-
]
|
|
10
|
-
|
|
11
|
-
exports.set = set
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { EntitySet } = require('../../src/entities/set')
|
|
4
|
-
const fixtures = require('./set.fixtures')
|
|
5
|
-
|
|
6
|
-
it('should provide state', () => {
|
|
7
|
-
const set = new EntitySet(fixtures.set)
|
|
8
|
-
const state = set.get()
|
|
9
|
-
const expected = fixtures.set.map((entity) => entity.get.mock.results[0].value)
|
|
10
|
-
|
|
11
|
-
expect(state).toStrictEqual(expected)
|
|
12
|
-
})
|
package/test/event.fixtures.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
4
|
-
|
|
5
|
-
const definition = {
|
|
6
|
-
conditioned: true,
|
|
7
|
-
subjective: true
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// noinspection JSCheckFunctionSignatures
|
|
11
|
-
const bridge = {
|
|
12
|
-
condition: jest.fn(async (origin) => !origin.falsy),
|
|
13
|
-
payload: jest.fn(async () => ({ [generate()]: generate() }))
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const binding = {
|
|
17
|
-
emit: jest.fn()
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const event = {
|
|
21
|
-
origin: { [generate()]: generate() },
|
|
22
|
-
state: { [generate()]: generate() },
|
|
23
|
-
changeset: { [generate()]: generate() }
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
exports.bridge = bridge
|
|
27
|
-
exports.binding = binding
|
|
28
|
-
exports.definition = definition
|
|
29
|
-
exports.event = event
|