@toa.io/core 1.0.0-alpha.29 → 1.0.0-alpha.291
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 +35 -0
- package/package.json +22 -12
- package/source/assignment.ts +27 -0
- package/source/call.ts +63 -0
- package/source/cascade.ts +32 -0
- package/source/component.ts +83 -0
- package/source/composition.ts +27 -0
- package/source/connector.ts +217 -0
- package/source/context.ts +68 -0
- package/source/contract/contract.ts +23 -0
- package/source/contract/index.ts +2 -0
- package/source/contract/reply.ts +56 -0
- package/source/contract/request.ts +140 -0
- package/source/contract/schemas.ts +39 -0
- package/source/discovery.ts +53 -0
- package/source/effect.ts +14 -0
- package/source/emission.ts +21 -0
- package/source/entities/changeset.ts +37 -0
- package/source/entities/entity.ts +137 -0
- package/source/entities/factory.ts +52 -0
- package/source/entities/index.ts +4 -0
- package/source/entities/newid.ts +9 -0
- package/source/entities/set.ts +27 -0
- package/source/event.ts +57 -0
- package/source/exceptions.ts +133 -0
- package/source/exposition.ts +33 -0
- package/source/guard.ts +16 -0
- package/source/index.ts +36 -0
- package/source/locator.ts +37 -0
- package/source/observation.ts +16 -0
- package/source/operation.ts +139 -0
- package/source/outbox/index.ts +1 -0
- package/source/outbox/outbox.ts +341 -0
- package/source/query/criteria.ts +90 -0
- package/source/query/options.ts +35 -0
- package/source/query.ts +67 -0
- package/source/receiver.ts +120 -0
- package/source/reflection.ts +20 -0
- package/source/remote.ts +20 -0
- package/source/state.ts +179 -0
- package/source/transition.ts +79 -0
- package/source/transmission.ts +38 -0
- package/source/types/atomicity.ts +63 -0
- package/source/types/bindings.ts +59 -0
- package/source/types/bridges.ts +54 -0
- package/source/types/extensions.ts +89 -0
- package/source/types/index.ts +14 -0
- package/{types/message.d.ts → source/types/message.ts} +2 -0
- package/source/types/operations.ts +31 -0
- package/source/types/outbox.ts +35 -0
- package/source/types/receiver.ts +10 -0
- package/source/types/request.ts +54 -0
- package/source/types/state.ts +9 -0
- package/source/types/storages.ts +134 -0
- package/source/unmanaged.ts +8 -0
- package/test/call.fixtures.js +10 -12
- package/test/call.test.js +42 -9
- package/test/component.fixtures.js +5 -8
- package/test/component.test.js +27 -10
- package/test/connector.fixtures.js +29 -13
- package/test/connector.test.js +128 -38
- package/test/context.fixtures.js +8 -12
- package/test/context.test.js +19 -8
- package/test/contract/conditions.test.js +15 -9
- package/test/contract/contract.fixtures.js +11 -16
- package/test/contract/request.test.js +130 -46
- package/test/discovery.test.js +71 -0
- package/test/emission.fixtures.js +6 -10
- package/test/emission.test.js +37 -12
- package/test/entities/entity.fixtures.js +11 -16
- package/test/entities/entity.test.js +105 -50
- package/test/entities/factory.fixtures.js +26 -13
- package/test/entities/factory.test.js +68 -17
- package/test/entities/set.fixtures.js +6 -8
- package/test/entities/set.test.js +6 -5
- package/test/event.fixtures.js +9 -14
- package/test/event.test.js +78 -34
- package/test/locator.test.js +32 -25
- package/test/outbox.test.js +202 -0
- package/test/query.fixtures.js +1 -5
- package/test/query.test.js +111 -14
- package/test/receiver.fixtures.js +9 -12
- package/test/receiver.test.js +80 -31
- package/test/reflection.test.js +9 -8
- package/test/state.fixtures.js +33 -31
- package/test/state.test.js +135 -19
- package/test/transmission.fixtures.js +4 -6
- package/test/transmission.test.js +47 -16
- package/transpiled/assignment.d.ts +6 -0
- package/transpiled/assignment.js +20 -0
- package/transpiled/assignment.js.map +1 -0
- package/transpiled/call.d.ts +10 -0
- package/transpiled/call.js +52 -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 +15 -0
- package/transpiled/component.js +61 -0
- package/transpiled/component.js.map +1 -0
- package/transpiled/composition.d.ts +6 -0
- package/transpiled/composition.js +23 -0
- package/transpiled/composition.js.map +1 -0
- package/transpiled/connector.d.ts +47 -0
- package/transpiled/connector.js +185 -0
- package/transpiled/connector.js.map +1 -0
- package/transpiled/context.d.ts +18 -0
- package/transpiled/context.js +42 -0
- package/transpiled/context.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 +2 -0
- package/transpiled/contract/index.js +3 -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 +29 -0
- package/transpiled/contract/request.js +103 -0
- package/transpiled/contract/request.js.map +1 -0
- package/transpiled/contract/schemas.d.ts +4 -0
- package/transpiled/contract/schemas.js +36 -0
- package/transpiled/contract/schemas.js.map +1 -0
- package/transpiled/discovery.d.ts +12 -0
- package/transpiled/discovery.js +34 -0
- package/transpiled/discovery.js.map +1 -0
- package/transpiled/effect.d.ts +5 -0
- package/transpiled/effect.js +11 -0
- package/transpiled/effect.js.map +1 -0
- package/transpiled/emission.d.ts +8 -0
- package/transpiled/emission.js +14 -0
- package/transpiled/emission.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 +109 -0
- package/transpiled/entities/entity.js.map +1 -0
- package/transpiled/entities/factory.d.ts +22 -0
- package/transpiled/entities/factory.js +34 -0
- package/transpiled/entities/factory.js.map +1 -0
- package/transpiled/entities/index.d.ts +4 -0
- package/transpiled/entities/index.js +5 -0
- package/transpiled/entities/index.js.map +1 -0
- package/transpiled/entities/newid.d.ts +1 -0
- package/transpiled/entities/newid.js +7 -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 +14 -0
- package/transpiled/event.js +38 -0
- package/transpiled/event.js.map +1 -0
- package/transpiled/exceptions.d.ts +61 -0
- package/transpiled/exceptions.js +93 -0
- package/transpiled/exceptions.js.map +1 -0
- package/transpiled/exposition.d.ts +18 -0
- package/transpiled/exposition.js +18 -0
- package/transpiled/exposition.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/index.d.ts +35 -0
- package/transpiled/index.js +29 -0
- package/transpiled/index.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/observation.d.ts +5 -0
- package/transpiled/observation.js +12 -0
- package/transpiled/observation.js.map +1 -0
- package/transpiled/operation.d.ts +49 -0
- package/transpiled/operation.js +78 -0
- package/transpiled/operation.js.map +1 -0
- package/transpiled/outbox/index.d.ts +1 -0
- package/transpiled/outbox/index.js +2 -0
- package/transpiled/outbox/index.js.map +1 -0
- package/transpiled/outbox/outbox.d.ts +46 -0
- package/transpiled/outbox/outbox.js +268 -0
- package/transpiled/outbox/outbox.js.map +1 -0
- package/transpiled/query/criteria.d.ts +6 -0
- package/transpiled/query/criteria.js +74 -0
- package/transpiled/query/criteria.js.map +1 -0
- package/transpiled/query/options.d.ts +3 -0
- package/transpiled/query/options.js +27 -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 +92 -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/remote.d.ts +10 -0
- package/transpiled/remote.js +12 -0
- package/transpiled/remote.js.map +1 -0
- package/transpiled/state.d.ts +33 -0
- package/transpiled/state.js +126 -0
- package/transpiled/state.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 +56 -0
- package/transpiled/types/atomicity.js +2 -0
- package/transpiled/types/atomicity.js.map +1 -0
- package/transpiled/types/bindings.d.ts +42 -0
- package/transpiled/types/bindings.js +2 -0
- package/transpiled/types/bindings.js.map +1 -0
- package/transpiled/types/bridges.d.ts +38 -0
- package/transpiled/types/bridges.js +2 -0
- package/transpiled/types/bridges.js.map +1 -0
- package/transpiled/types/extensions.d.ts +62 -0
- package/transpiled/types/extensions.js +2 -0
- package/transpiled/types/extensions.js.map +1 -0
- package/transpiled/types/index.d.ts +13 -0
- package/transpiled/types/index.js +8 -0
- package/transpiled/types/index.js.map +1 -0
- package/transpiled/types/message.d.ts +5 -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 +28 -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 +55 -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 +111 -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/tsconfig.json +10 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/assignment.js +0 -31
- package/src/call.js +0 -42
- package/src/cascade.js +0 -36
- 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 -43
- package/src/entities/entity.js +0 -73
- 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 -65
- package/src/reflection.js +0 -28
- package/src/remote.js +0 -17
- package/src/state.js +0 -99
- package/src/transition.js +0 -73
- package/src/transmission.js +0 -33
- 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/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/query.test.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { describe, it, beforeEach } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
import { Query } from '../source/query.js'
|
|
5
|
+
import * as fixtures from './query.fixtures.js'
|
|
5
6
|
|
|
6
7
|
beforeEach(() => {
|
|
7
|
-
|
|
8
|
+
resetCalls()
|
|
8
9
|
})
|
|
9
10
|
|
|
10
11
|
describe('criteria', () => {
|
|
@@ -12,34 +13,110 @@ describe('criteria', () => {
|
|
|
12
13
|
const instance = new Query(fixtures.samples.simple.properties)
|
|
13
14
|
const query = instance.parse({})
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
assert.strictEqual(query.criteria, undefined)
|
|
16
17
|
})
|
|
17
18
|
|
|
18
19
|
it('should parse criteria', () => {
|
|
19
20
|
const instance = new Query(fixtures.samples.simple.properties)
|
|
20
21
|
const query = instance.parse(fixtures.samples.simple.query)
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
assert.deepStrictEqual(query.criteria, fixtures.samples.simple.parsed.criteria)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('should coerce every value of a list', () => {
|
|
27
|
+
const instance = new Query({ n: { type: 'integer' } })
|
|
28
|
+
const query = instance.parse({ criteria: 'n=in=(1,2,3)' })
|
|
29
|
+
|
|
30
|
+
assert.deepStrictEqual(query.criteria.right.value, [1, 2, 3])
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('should keep a parsed criteria', () => {
|
|
34
|
+
const instance = new Query(fixtures.samples.simple.properties)
|
|
35
|
+
|
|
36
|
+
const first = instance.parse(fixtures.samples.simple.query).criteria
|
|
37
|
+
const second = instance.parse(fixtures.samples.simple.query).criteria
|
|
38
|
+
|
|
39
|
+
assert.strictEqual(second, first)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should not keep an invalid criteria', () => {
|
|
43
|
+
const instance = new Query(fixtures.samples.simple.properties)
|
|
44
|
+
const query = { criteria: 'nonexistent==1' }
|
|
45
|
+
|
|
46
|
+
assert.throws(() => instance.parse(query))
|
|
47
|
+
assert.throws(() => instance.parse(query))
|
|
23
48
|
})
|
|
24
49
|
|
|
25
50
|
it('should parse criteria with type coercion', () => {
|
|
26
51
|
const instance = new Query(fixtures.samples.extended.properties)
|
|
27
52
|
const query = instance.parse(fixtures.samples.extended.query)
|
|
28
53
|
|
|
29
|
-
|
|
54
|
+
assert.deepStrictEqual(query.criteria, fixtures.samples.extended.parsed.criteria)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('should refuse a value the property cannot hold', () => {
|
|
58
|
+
const strict = new Query({
|
|
59
|
+
volume: { type: 'number' },
|
|
60
|
+
count: { type: 'integer' },
|
|
61
|
+
booked: { type: 'boolean' }
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const refused = [
|
|
65
|
+
['volume>abc', /takes a number/],
|
|
66
|
+
['volume==1.5kg', /takes a number/],
|
|
67
|
+
['count==1.5', /takes an integer/],
|
|
68
|
+
['count==12kg', /takes an integer/],
|
|
69
|
+
['booked==yes', /takes a boolean/],
|
|
70
|
+
['booked==TRUE', /takes a boolean/],
|
|
71
|
+
['volume=in=(1,two)', /'two' is not one/]
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
for (const [criteria, message] of refused)
|
|
75
|
+
assert.throws(
|
|
76
|
+
() => strict.parse({ criteria }),
|
|
77
|
+
(error) => message.test(error.message),
|
|
78
|
+
criteria
|
|
79
|
+
)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('should read a value the property can hold', () => {
|
|
83
|
+
const strict = new Query({
|
|
84
|
+
volume: { type: 'number' },
|
|
85
|
+
count: { type: 'integer' },
|
|
86
|
+
booked: { type: 'boolean' },
|
|
87
|
+
title: { type: 'string' }
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const read = [
|
|
91
|
+
['volume>1.5', 1.5],
|
|
92
|
+
['volume>-1.5', -1.5],
|
|
93
|
+
['count==12', 12],
|
|
94
|
+
['booked==false', false],
|
|
95
|
+
['title==12kg', '12kg']
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
for (const [criteria, value] of read)
|
|
99
|
+
assert.deepStrictEqual(
|
|
100
|
+
strict.parse({ criteria }).criteria.right.value,
|
|
101
|
+
value,
|
|
102
|
+
criteria
|
|
103
|
+
)
|
|
30
104
|
})
|
|
31
105
|
|
|
32
106
|
it('should throw on unknown properties', () => {
|
|
33
107
|
const instance = new Query(fixtures.samples.simple.properties)
|
|
34
108
|
|
|
35
|
-
|
|
109
|
+
assert.throws(
|
|
110
|
+
() => instance.parse({ criteria: 'lastname==Johnson' }),
|
|
111
|
+
(error) => /not defined/.test(error.message)
|
|
112
|
+
)
|
|
36
113
|
})
|
|
37
114
|
|
|
38
115
|
it('should parse id', () => {
|
|
39
116
|
const instance = new Query(fixtures.samples.id.properties)
|
|
40
117
|
const query = instance.parse({ ...fixtures.samples.id.query })
|
|
41
118
|
|
|
42
|
-
|
|
119
|
+
assert.deepStrictEqual(query, fixtures.samples.id.parsed)
|
|
43
120
|
})
|
|
44
121
|
})
|
|
45
122
|
|
|
@@ -49,7 +126,7 @@ describe('options', () => {
|
|
|
49
126
|
it('should not throw if no options', () => {
|
|
50
127
|
const query = instance.parse({})
|
|
51
128
|
|
|
52
|
-
|
|
129
|
+
assert.strictEqual(query.options, undefined)
|
|
53
130
|
})
|
|
54
131
|
|
|
55
132
|
describe('omit, limit', () => {
|
|
@@ -57,7 +134,7 @@ describe('options', () => {
|
|
|
57
134
|
const input = { omit: 1, limit: 1 }
|
|
58
135
|
const query = instance.parse(input)
|
|
59
136
|
|
|
60
|
-
|
|
137
|
+
assert.deepStrictEqual(query.options, input)
|
|
61
138
|
})
|
|
62
139
|
})
|
|
63
140
|
|
|
@@ -66,13 +143,20 @@ describe('options', () => {
|
|
|
66
143
|
const sort = ['a', 'b:desc', 'c']
|
|
67
144
|
const query = instance.parse({ sort })
|
|
68
145
|
|
|
69
|
-
|
|
146
|
+
assert.deepStrictEqual(query.options.sort, [
|
|
147
|
+
['a', 'asc'],
|
|
148
|
+
['b', 'desc'],
|
|
149
|
+
['c', 'asc']
|
|
150
|
+
])
|
|
70
151
|
})
|
|
71
152
|
|
|
72
153
|
it('should throw on unknown properties', () => {
|
|
73
154
|
const sort = ['d:asc']
|
|
74
155
|
|
|
75
|
-
|
|
156
|
+
assert.throws(
|
|
157
|
+
() => instance.parse({ sort }),
|
|
158
|
+
(error) => /not defined/.test(error.message)
|
|
159
|
+
)
|
|
76
160
|
})
|
|
77
161
|
})
|
|
78
162
|
|
|
@@ -80,7 +164,20 @@ describe('options', () => {
|
|
|
80
164
|
it('should throw on unknown properties', () => {
|
|
81
165
|
const projection = ['a', 'b', 'c', 'd']
|
|
82
166
|
|
|
83
|
-
|
|
167
|
+
assert.throws(
|
|
168
|
+
() => instance.parse({ projection }),
|
|
169
|
+
(error) => /not defined/.test(error.message)
|
|
170
|
+
)
|
|
84
171
|
})
|
|
85
172
|
})
|
|
86
173
|
})
|
|
174
|
+
|
|
175
|
+
function resetCalls(target = [assert, fixtures], seen = new Set()) {
|
|
176
|
+
if (target === null || typeof target !== 'object' || seen.has(target)) return
|
|
177
|
+
|
|
178
|
+
seen.add(target)
|
|
179
|
+
|
|
180
|
+
for (const value of Object.values(target))
|
|
181
|
+
if (typeof value === 'function' && value.mock !== undefined) value.mock.resetCalls()
|
|
182
|
+
else resetCalls(value, seen)
|
|
183
|
+
}
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import { mock } from 'node:test'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { generate } from 'randomstring'
|
|
4
4
|
|
|
5
|
-
const definition = /** @type {toa.norm.component.Receiver} */ {
|
|
5
|
+
export const definition = /** @type {toa.norm.component.Receiver} */ {
|
|
6
6
|
operation: generate(),
|
|
7
7
|
conditioned: false,
|
|
8
8
|
adaptive: false
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
const local = /** @type {toa.core.Component} */ {
|
|
12
|
-
|
|
11
|
+
export const local = /** @type {import('@toa.io/core').Component} */ {
|
|
12
|
+
locator: { id: 'default.dummy' },
|
|
13
|
+
invoke: mock.fn()
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
// noinspection JSCheckFunctionSignatures
|
|
16
|
-
const bridge = /** @type {toa.core.bridges.Event} */ {
|
|
17
|
-
condition:
|
|
18
|
-
request:
|
|
17
|
+
export const bridge = /** @type {import('@toa.io/core/types').bridges.Event} */ {
|
|
18
|
+
condition: mock.fn(async (payload) => !(payload.reject === true)),
|
|
19
|
+
request: mock.fn(async () => ({ input: generate() }))
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
exports.definition = definition
|
|
22
|
-
exports.local = local
|
|
23
|
-
exports.bridge = bridge
|
package/test/receiver.test.js
CHANGED
|
@@ -1,32 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
import { describe, it, beforeEach, mock } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { isDeepStrictEqual } from 'node:util'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
import clone from 'clone-deep'
|
|
6
|
+
import { generate } from 'randomstring'
|
|
7
|
+
import { merge } from '@toa.io/generic'
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
import { Connector } from '../source/connector.js'
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
// the fixtures are not connectors, so a dependency is recorded rather than linked
|
|
12
|
+
const depends = mock.method(Connector.prototype, 'depends', () => undefined)
|
|
10
13
|
|
|
11
|
-
const
|
|
12
|
-
|
|
14
|
+
const dependencies = (instance) =>
|
|
15
|
+
depends.mock.calls
|
|
16
|
+
.filter((call) => call.this === instance)
|
|
17
|
+
.map((call) => call.arguments[0])
|
|
13
18
|
|
|
14
|
-
|
|
19
|
+
import { Receiver } from '../source/receiver.js'
|
|
20
|
+
import * as fixtures from './receiver.fixtures.js'
|
|
21
|
+
|
|
22
|
+
/** @type {import('@toa.io/core/types').Receiver} */
|
|
15
23
|
let receiver
|
|
16
24
|
|
|
17
25
|
/** @type {toa.norm.component.Receiver} */
|
|
18
26
|
let definition
|
|
19
27
|
|
|
20
28
|
beforeEach(() => {
|
|
21
|
-
|
|
29
|
+
resetCalls()
|
|
30
|
+
depends.mock.resetCalls()
|
|
22
31
|
|
|
23
32
|
definition = clone(fixtures.definition)
|
|
24
33
|
receiver = new Receiver(fixtures.definition, fixtures.local, fixtures.bridge)
|
|
25
34
|
})
|
|
26
35
|
|
|
27
36
|
it('should depend on local, bridge', () => {
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
assert.ok(dependencies(receiver).some((one) => isDeepStrictEqual(one, fixtures.local)))
|
|
38
|
+
assert.ok(dependencies(receiver).some((one) => isDeepStrictEqual(one, fixtures.bridge)))
|
|
30
39
|
})
|
|
31
40
|
|
|
32
41
|
it('should apply', async () => {
|
|
@@ -34,28 +43,38 @@ it('should apply', async () => {
|
|
|
34
43
|
|
|
35
44
|
await receiver.receive({ payload })
|
|
36
45
|
|
|
37
|
-
|
|
46
|
+
assert.ok(
|
|
47
|
+
fixtures.local.invoke.mock.calls.some(
|
|
48
|
+
(call) =>
|
|
49
|
+
call.arguments.length === 2 &&
|
|
50
|
+
isDeepStrictEqual(call.arguments[0], definition.operation) &&
|
|
51
|
+
isDeepStrictEqual(call.arguments[1], { input: payload })
|
|
52
|
+
)
|
|
53
|
+
)
|
|
38
54
|
})
|
|
39
55
|
|
|
40
|
-
|
|
41
|
-
|
|
56
|
+
for (const [adaptive] of [[false], [true]])
|
|
57
|
+
it(`should pass UI extensions (adaptive: ${adaptive})`, async () => {
|
|
58
|
+
resetCalls()
|
|
42
59
|
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
definition.adaptive = adaptive
|
|
61
|
+
receiver = new Receiver(definition, fixtures.local, fixtures.bridge)
|
|
45
62
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
63
|
+
const payload = { foo: generate() }
|
|
64
|
+
const extension = { [generate()]: generate() }
|
|
65
|
+
const message = { payload, ...extension }
|
|
49
66
|
|
|
50
|
-
|
|
67
|
+
await receiver.receive(message)
|
|
51
68
|
|
|
52
|
-
|
|
53
|
-
|
|
69
|
+
const request = adaptive
|
|
70
|
+
? await fixtures.bridge.request.mock.calls[0].result
|
|
71
|
+
: { input: payload }
|
|
72
|
+
const expected = merge(clone(request), extension)
|
|
54
73
|
|
|
55
|
-
|
|
74
|
+
const argument = fixtures.local.invoke.mock.calls[0].arguments[1]
|
|
56
75
|
|
|
57
|
-
|
|
58
|
-
})
|
|
76
|
+
assert.deepStrictEqual(argument, expected)
|
|
77
|
+
})
|
|
59
78
|
|
|
60
79
|
describe('conditioned', () => {
|
|
61
80
|
beforeEach(() => {
|
|
@@ -67,15 +86,27 @@ describe('conditioned', () => {
|
|
|
67
86
|
const payload = { foo: 'bar' }
|
|
68
87
|
await receiver.receive({ payload })
|
|
69
88
|
|
|
70
|
-
|
|
71
|
-
|
|
89
|
+
assert.ok(
|
|
90
|
+
fixtures.bridge.condition.mock.calls.some(
|
|
91
|
+
(call) =>
|
|
92
|
+
call.arguments.length === 1 && isDeepStrictEqual(call.arguments[0], payload)
|
|
93
|
+
)
|
|
94
|
+
)
|
|
95
|
+
assert.ok(
|
|
96
|
+
fixtures.local.invoke.mock.calls.some(
|
|
97
|
+
(call) =>
|
|
98
|
+
call.arguments.length === 2 &&
|
|
99
|
+
isDeepStrictEqual(call.arguments[0], definition.operation) &&
|
|
100
|
+
isDeepStrictEqual(call.arguments[1], { input: payload })
|
|
101
|
+
)
|
|
102
|
+
)
|
|
72
103
|
})
|
|
73
104
|
|
|
74
105
|
it('should not apply if condition is false', async () => {
|
|
75
106
|
const payload = { reject: true }
|
|
76
107
|
await receiver.receive({ payload })
|
|
77
108
|
|
|
78
|
-
|
|
109
|
+
assert.strictEqual(fixtures.local.invoke.mock.callCount(), 0)
|
|
79
110
|
})
|
|
80
111
|
})
|
|
81
112
|
|
|
@@ -89,7 +120,25 @@ describe('adaptive', () => {
|
|
|
89
120
|
const payload = { reject: true }
|
|
90
121
|
await receiver.receive({ payload })
|
|
91
122
|
|
|
92
|
-
|
|
93
|
-
|
|
123
|
+
const request = await fixtures.bridge.request.mock.calls[0].result
|
|
124
|
+
|
|
125
|
+
assert.ok(
|
|
126
|
+
fixtures.local.invoke.mock.calls.some(
|
|
127
|
+
(call) =>
|
|
128
|
+
call.arguments.length === 2 &&
|
|
129
|
+
isDeepStrictEqual(call.arguments[0], definition.operation) &&
|
|
130
|
+
isDeepStrictEqual(call.arguments[1], request)
|
|
131
|
+
)
|
|
132
|
+
)
|
|
94
133
|
})
|
|
95
134
|
})
|
|
135
|
+
|
|
136
|
+
function resetCalls(target = [assert, clone, fixtures], seen = new Set()) {
|
|
137
|
+
if (target === null || typeof target !== 'object' || seen.has(target)) return
|
|
138
|
+
|
|
139
|
+
seen.add(target)
|
|
140
|
+
|
|
141
|
+
for (const value of Object.values(target))
|
|
142
|
+
if (typeof value === 'function' && value.mock !== undefined) value.mock.resetCalls()
|
|
143
|
+
else resetCalls(value, seen)
|
|
144
|
+
}
|
package/test/reflection.test.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import { it, beforeEach } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
import { generate } from 'randomstring'
|
|
5
|
+
import { Reflection, Connector } from '../source/index.js'
|
|
5
6
|
|
|
6
7
|
it('should export', () => {
|
|
7
|
-
|
|
8
|
+
assert.notStrictEqual(Reflection, undefined)
|
|
8
9
|
})
|
|
9
10
|
|
|
10
|
-
/** @type {toa.core.Reflection<string>} */
|
|
11
|
+
/** @type {import('@toa.io/core').Reflection<string>} */
|
|
11
12
|
let reflection
|
|
12
13
|
|
|
13
14
|
const value = generate()
|
|
14
15
|
|
|
15
|
-
/** @type {toa.core.
|
|
16
|
+
/** @type {import('@toa.io/core').ReflectionSource<string>} */
|
|
16
17
|
const source = async () => value
|
|
17
18
|
|
|
18
19
|
beforeEach(() => {
|
|
@@ -20,11 +21,11 @@ beforeEach(() => {
|
|
|
20
21
|
})
|
|
21
22
|
|
|
22
23
|
it('should be a Connector', () => {
|
|
23
|
-
|
|
24
|
+
assert.ok(reflection instanceof Connector)
|
|
24
25
|
})
|
|
25
26
|
|
|
26
27
|
it('should reflect', async () => {
|
|
27
28
|
await reflection.connect()
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
assert.deepStrictEqual(reflection.value, value)
|
|
30
31
|
})
|
package/test/state.fixtures.js
CHANGED
|
@@ -1,47 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
import { mock } from 'node:test'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { generate } from 'randomstring'
|
|
4
4
|
|
|
5
|
-
const storage = {
|
|
5
|
+
export const storage = {
|
|
6
6
|
name: 'dummy',
|
|
7
|
-
get:
|
|
8
|
-
find:
|
|
9
|
-
add:
|
|
10
|
-
set:
|
|
11
|
-
store:
|
|
7
|
+
get: mock.fn(() => ({ id: generate() })),
|
|
8
|
+
find: mock.fn(() => [{ id: generate() }]),
|
|
9
|
+
add: mock.fn(() => true),
|
|
10
|
+
set: mock.fn(() => true),
|
|
11
|
+
store: mock.fn(() => true),
|
|
12
|
+
massStore: mock.fn(() => true),
|
|
13
|
+
upsert: mock.fn(() => ({ id: generate() })),
|
|
14
|
+
ensure: mock.fn((query, properties, state) => state)
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
const factory = {
|
|
15
|
-
object:
|
|
16
|
-
objects:
|
|
17
|
+
export const factory = {
|
|
18
|
+
object: mock.fn(() => ({ [generate()]: generate() })),
|
|
19
|
+
objects: mock.fn(() => ({ [generate()]: generate() }))
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
const query = generate()
|
|
22
|
+
export const query = generate()
|
|
20
23
|
|
|
21
|
-
const entity = {
|
|
22
|
-
get:
|
|
23
|
-
event:
|
|
24
|
-
state: { [generate()]: generate() }, changeset: { [generate()]: generate() }
|
|
25
|
-
}))
|
|
24
|
+
export const entity = {
|
|
25
|
+
get: mock.fn(() => ({ [generate()]: generate() })),
|
|
26
|
+
event: mock.fn(() => ({ state: { [generate()]: generate() } }))
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
const initial = {
|
|
29
|
-
initial: true,
|
|
29
|
+
export const initial = {
|
|
30
|
+
initial: true,
|
|
31
|
+
...entity
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
const unchanged = {
|
|
34
|
+
export const unchanged = {
|
|
33
35
|
...entity,
|
|
34
|
-
event:
|
|
36
|
+
event: mock.fn(() => ({ state: { [generate()]: generate() } }))
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
// a legacy outbox: no storage capability, so `publish` emits inline
|
|
40
|
+
export const outbox = {
|
|
41
|
+
row: mock.fn((event) => ({
|
|
42
|
+
id: generate(),
|
|
43
|
+
lane: 0,
|
|
44
|
+
published: false,
|
|
45
|
+
pending: 0,
|
|
46
|
+
event
|
|
47
|
+
})),
|
|
48
|
+
publish: mock.fn()
|
|
39
49
|
}
|
|
40
|
-
|
|
41
|
-
exports.storage = storage
|
|
42
|
-
exports.factory = factory
|
|
43
|
-
exports.emitter = emitter
|
|
44
|
-
exports.query = query
|
|
45
|
-
exports.entity = entity
|
|
46
|
-
exports.initial = initial
|
|
47
|
-
exports.unchanged = unchanged
|