@toa.io/core 1.0.0-alpha.284 → 1.0.0-alpha.287
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 +1 -185
- package/package.json +19 -7
- package/source/assignment.ts +27 -0
- package/{src/call.js → source/call.ts} +16 -21
- package/{src/cascade.js → source/cascade.ts} +6 -8
- package/{src/component.js → source/component.ts} +27 -25
- package/{src/composition.js → source/composition.ts} +9 -3
- package/{src/connector.js → source/connector.ts} +36 -55
- package/source/context.ts +67 -0
- package/source/contract/contract.ts +23 -0
- package/{src/contract/reply.js → source/contract/reply.ts} +26 -19
- package/source/contract/request.ts +85 -0
- package/source/contract/schemas.ts +39 -0
- package/{src/discovery.js → source/discovery.ts} +15 -8
- package/source/effect.ts +14 -0
- package/{src/emission.js → source/emission.ts} +5 -3
- 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/{src/entities/newid.js → source/entities/newid.ts} +1 -1
- package/{src/entities/set.js → source/entities/set.ts} +8 -5
- package/source/event.ts +57 -0
- package/{src/exceptions.js → source/exceptions.ts} +52 -33
- package/source/exposition.ts +33 -0
- package/source/guard.ts +16 -0
- package/{src/index.js → source/index.ts} +8 -0
- package/{src/locator.js → source/locator.ts} +17 -30
- package/source/observation.ts +16 -0
- package/source/operation.ts +138 -0
- package/{src/outbox/outbox.js → source/outbox/outbox.ts} +87 -53
- package/source/query/criteria.ts +90 -0
- package/source/query/options.ts +35 -0
- package/{src/query.js → source/query.ts} +14 -17
- 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/{src/transmission.js → source/transmission.ts} +8 -8
- 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/{types → source/types}/index.ts +9 -16
- package/{types/message.d.ts → source/types/message.ts} +2 -1
- package/source/types/operations.ts +31 -0
- package/source/types/outbox.ts +35 -0
- package/source/types/receiver.ts +10 -0
- package/{types/request.d.ts → source/types/request.ts} +8 -9
- package/source/types/state.ts +9 -0
- package/source/types/storages.ts +129 -0
- package/source/unmanaged.ts +8 -0
- package/test/call.fixtures.js +3 -1
- package/test/call.test.js +28 -7
- package/test/component.test.js +10 -5
- package/test/connector.fixtures.js +7 -7
- package/test/connector.test.js +15 -2
- package/test/context.fixtures.js +1 -1
- package/test/context.test.js +4 -4
- package/test/contract/conditions.test.js +6 -2
- package/test/contract/contract.fixtures.js +3 -4
- package/test/contract/request.test.js +68 -34
- package/test/discovery.test.js +10 -3
- package/test/emission.test.js +16 -8
- package/test/entities/entity.fixtures.js +5 -6
- package/test/entities/entity.test.js +54 -20
- package/test/entities/factory.fixtures.js +11 -10
- package/test/entities/factory.test.js +47 -10
- package/test/entities/set.test.js +1 -1
- package/test/event.test.js +29 -11
- package/test/locator.test.js +10 -4
- package/test/outbox.test.js +49 -15
- package/test/query.test.js +69 -7
- package/test/receiver.fixtures.js +2 -2
- package/test/receiver.test.js +53 -27
- package/test/reflection.test.js +3 -3
- package/test/state.fixtures.js +10 -3
- package/test/state.test.js +77 -14
- package/test/transmission.test.js +25 -12
- 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 +143 -0
- package/transpiled/connector.js.map +1 -0
- package/transpiled/context.d.ts +18 -0
- package/transpiled/context.js +41 -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 +24 -0
- package/transpiled/contract/request.js +59 -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 +77 -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 +267 -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 +106 -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 -28
- package/src/context.js +0 -57
- package/src/contract/contract.js +0 -18
- package/src/contract/request.js +0 -77
- package/src/contract/schemas/error.yaml +0 -9
- package/src/contract/schemas/index.js +0 -11
- package/src/contract/schemas/query.yaml +0 -43
- package/src/contract/schemas/source.yaml +0 -23
- package/src/effect.js +0 -15
- package/src/entities/changeset.js +0 -36
- package/src/entities/entity.js +0 -119
- package/src/entities/factory.js +0 -40
- package/src/entities/index.js +0 -1
- package/src/event.js +0 -54
- package/src/exposition.js +0 -24
- package/src/guard.js +0 -13
- package/src/observation.js +0 -8
- package/src/operation.js +0 -95
- package/src/query/criteria.js +0 -44
- package/src/query/options.js +0 -37
- package/src/receiver.js +0 -123
- package/src/reflection.js +0 -24
- package/src/remote.js +0 -14
- package/src/state.js +0 -138
- package/src/transition.js +0 -61
- package/src/unmanaged.js +0 -7
- package/types/atomicity.d.ts +0 -79
- package/types/bindings.d.ts +0 -42
- package/types/bridges.ts +0 -33
- package/types/call.d.ts +0 -13
- package/types/component.d.ts +0 -12
- package/types/connector.d.ts +0 -18
- package/types/context.d.ts +0 -24
- 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 -73
- package/types/guard.d.ts +0 -5
- package/types/locator.d.ts +0 -13
- package/types/operations.d.ts +0 -8
- package/types/outbox.d.ts +0 -53
- package/types/query.d.ts +0 -17
- package/types/receiver.d.ts +0 -12
- package/types/reflection.d.ts +0 -14
- package/types/remote.d.ts +0 -19
- package/types/state.d.ts +0 -38
- package/types/storages.d.ts +0 -96
- /package/{src/contract/index.js → source/contract/index.ts} +0 -0
- /package/{src/outbox/index.js → source/outbox/index.ts} +0 -0
package/test/query.test.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { describe, it, beforeEach
|
|
1
|
+
import { describe, it, beforeEach } from 'node:test'
|
|
2
2
|
import assert from 'node:assert/strict'
|
|
3
3
|
|
|
4
|
-
import { Query } from '../
|
|
4
|
+
import { Query } from '../source/query.js'
|
|
5
5
|
import * as fixtures from './query.fixtures.js'
|
|
6
6
|
|
|
7
7
|
beforeEach(() => {
|
|
@@ -54,10 +54,62 @@ describe('criteria', () => {
|
|
|
54
54
|
assert.deepStrictEqual(query.criteria, fixtures.samples.extended.parsed.criteria)
|
|
55
55
|
})
|
|
56
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
|
+
)
|
|
104
|
+
})
|
|
105
|
+
|
|
57
106
|
it('should throw on unknown properties', () => {
|
|
58
107
|
const instance = new Query(fixtures.samples.simple.properties)
|
|
59
108
|
|
|
60
|
-
assert.throws(
|
|
109
|
+
assert.throws(
|
|
110
|
+
() => instance.parse({ criteria: 'lastname==Johnson' }),
|
|
111
|
+
(error) => /not defined/.test(error.message)
|
|
112
|
+
)
|
|
61
113
|
})
|
|
62
114
|
|
|
63
115
|
it('should parse id', () => {
|
|
@@ -91,13 +143,20 @@ describe('options', () => {
|
|
|
91
143
|
const sort = ['a', 'b:desc', 'c']
|
|
92
144
|
const query = instance.parse({ sort })
|
|
93
145
|
|
|
94
|
-
assert.deepStrictEqual(query.options.sort, [
|
|
146
|
+
assert.deepStrictEqual(query.options.sort, [
|
|
147
|
+
['a', 'asc'],
|
|
148
|
+
['b', 'desc'],
|
|
149
|
+
['c', 'asc']
|
|
150
|
+
])
|
|
95
151
|
})
|
|
96
152
|
|
|
97
153
|
it('should throw on unknown properties', () => {
|
|
98
154
|
const sort = ['d:asc']
|
|
99
155
|
|
|
100
|
-
assert.throws(
|
|
156
|
+
assert.throws(
|
|
157
|
+
() => instance.parse({ sort }),
|
|
158
|
+
(error) => /not defined/.test(error.message)
|
|
159
|
+
)
|
|
101
160
|
})
|
|
102
161
|
})
|
|
103
162
|
|
|
@@ -105,12 +164,15 @@ describe('options', () => {
|
|
|
105
164
|
it('should throw on unknown properties', () => {
|
|
106
165
|
const projection = ['a', 'b', 'c', 'd']
|
|
107
166
|
|
|
108
|
-
assert.throws(
|
|
167
|
+
assert.throws(
|
|
168
|
+
() => instance.parse({ projection }),
|
|
169
|
+
(error) => /not defined/.test(error.message)
|
|
170
|
+
)
|
|
109
171
|
})
|
|
110
172
|
})
|
|
111
173
|
})
|
|
112
174
|
|
|
113
|
-
function resetCalls
|
|
175
|
+
function resetCalls(target = [assert, fixtures], seen = new Set()) {
|
|
114
176
|
if (target === null || typeof target !== 'object' || seen.has(target)) return
|
|
115
177
|
|
|
116
178
|
seen.add(target)
|
|
@@ -8,13 +8,13 @@ export const definition = /** @type {toa.norm.component.Receiver} */ {
|
|
|
8
8
|
adaptive: false
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export const local = /** @type {toa.core.Component} */ {
|
|
11
|
+
export const local = /** @type {import('@toa.io/core').Component} */ {
|
|
12
12
|
locator: { id: 'default.dummy' },
|
|
13
13
|
invoke: mock.fn()
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
// noinspection JSCheckFunctionSignatures
|
|
17
|
-
export const bridge = /** @type {toa.core.bridges.Event} */ {
|
|
17
|
+
export const bridge = /** @type {import('@toa.io/core/types').bridges.Event} */ {
|
|
18
18
|
condition: mock.fn(async (payload) => !(payload.reject === true)),
|
|
19
19
|
request: mock.fn(async () => ({ input: generate() }))
|
|
20
20
|
}
|
package/test/receiver.test.js
CHANGED
|
@@ -6,19 +6,20 @@ import clone from 'clone-deep'
|
|
|
6
6
|
import { generate } from 'randomstring'
|
|
7
7
|
import { merge } from '@toa.io/generic'
|
|
8
8
|
|
|
9
|
-
import { Connector } from '../
|
|
9
|
+
import { Connector } from '../source/connector.js'
|
|
10
10
|
|
|
11
11
|
// the fixtures are not connectors, so a dependency is recorded rather than linked
|
|
12
12
|
const depends = mock.method(Connector.prototype, 'depends', () => undefined)
|
|
13
13
|
|
|
14
|
-
const dependencies = (instance) =>
|
|
15
|
-
.
|
|
16
|
-
|
|
14
|
+
const dependencies = (instance) =>
|
|
15
|
+
depends.mock.calls
|
|
16
|
+
.filter((call) => call.this === instance)
|
|
17
|
+
.map((call) => call.arguments[0])
|
|
17
18
|
|
|
18
|
-
import { Receiver } from '../
|
|
19
|
+
import { Receiver } from '../source/receiver.js'
|
|
19
20
|
import * as fixtures from './receiver.fixtures.js'
|
|
20
21
|
|
|
21
|
-
/** @type {toa.core.Receiver} */
|
|
22
|
+
/** @type {import('@toa.io/core/types').Receiver} */
|
|
22
23
|
let receiver
|
|
23
24
|
|
|
24
25
|
/** @type {toa.norm.component.Receiver} */
|
|
@@ -42,29 +43,38 @@ it('should apply', async () => {
|
|
|
42
43
|
|
|
43
44
|
await receiver.receive({ payload })
|
|
44
45
|
|
|
45
|
-
assert.ok(
|
|
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
|
+
)
|
|
46
54
|
})
|
|
47
55
|
|
|
48
56
|
for (const [adaptive] of [[false], [true]])
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
it(`should pass UI extensions (adaptive: ${adaptive})`, async () => {
|
|
58
|
+
resetCalls()
|
|
51
59
|
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
definition.adaptive = adaptive
|
|
61
|
+
receiver = new Receiver(definition, fixtures.local, fixtures.bridge)
|
|
54
62
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
const payload = { foo: generate() }
|
|
64
|
+
const extension = { [generate()]: generate() }
|
|
65
|
+
const message = { payload, ...extension }
|
|
58
66
|
|
|
59
|
-
|
|
67
|
+
await receiver.receive(message)
|
|
60
68
|
|
|
61
|
-
|
|
62
|
-
|
|
69
|
+
const request = adaptive
|
|
70
|
+
? await fixtures.bridge.request.mock.calls[0].result
|
|
71
|
+
: { input: payload }
|
|
72
|
+
const expected = merge(clone(request), extension)
|
|
63
73
|
|
|
64
|
-
|
|
74
|
+
const argument = fixtures.local.invoke.mock.calls[0].arguments[1]
|
|
65
75
|
|
|
66
|
-
|
|
67
|
-
})
|
|
76
|
+
assert.deepStrictEqual(argument, expected)
|
|
77
|
+
})
|
|
68
78
|
|
|
69
79
|
describe('conditioned', () => {
|
|
70
80
|
beforeEach(() => {
|
|
@@ -76,8 +86,20 @@ describe('conditioned', () => {
|
|
|
76
86
|
const payload = { foo: 'bar' }
|
|
77
87
|
await receiver.receive({ payload })
|
|
78
88
|
|
|
79
|
-
assert.ok(
|
|
80
|
-
|
|
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
|
+
)
|
|
81
103
|
})
|
|
82
104
|
|
|
83
105
|
it('should not apply if condition is false', async () => {
|
|
@@ -100,14 +122,18 @@ describe('adaptive', () => {
|
|
|
100
122
|
|
|
101
123
|
const request = await fixtures.bridge.request.mock.calls[0].result
|
|
102
124
|
|
|
103
|
-
assert.ok(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
+
)
|
|
107
133
|
})
|
|
108
134
|
})
|
|
109
135
|
|
|
110
|
-
function resetCalls
|
|
136
|
+
function resetCalls(target = [assert, clone, fixtures], seen = new Set()) {
|
|
111
137
|
if (target === null || typeof target !== 'object' || seen.has(target)) return
|
|
112
138
|
|
|
113
139
|
seen.add(target)
|
package/test/reflection.test.js
CHANGED
|
@@ -2,18 +2,18 @@ import { it, beforeEach } from 'node:test'
|
|
|
2
2
|
import assert from 'node:assert/strict'
|
|
3
3
|
|
|
4
4
|
import { generate } from 'randomstring'
|
|
5
|
-
import { Reflection, Connector } from '../
|
|
5
|
+
import { Reflection, Connector } from '../source/index.js'
|
|
6
6
|
|
|
7
7
|
it('should export', () => {
|
|
8
8
|
assert.notStrictEqual(Reflection, undefined)
|
|
9
9
|
})
|
|
10
10
|
|
|
11
|
-
/** @type {toa.core.Reflection<string>} */
|
|
11
|
+
/** @type {import('@toa.io/core').Reflection<string>} */
|
|
12
12
|
let reflection
|
|
13
13
|
|
|
14
14
|
const value = generate()
|
|
15
15
|
|
|
16
|
-
/** @type {toa.core.
|
|
16
|
+
/** @type {import('@toa.io/core').ReflectionSource<string>} */
|
|
17
17
|
const source = async () => value
|
|
18
18
|
|
|
19
19
|
beforeEach(() => {
|
package/test/state.fixtures.js
CHANGED
|
@@ -5,7 +5,7 @@ import { generate } from 'randomstring'
|
|
|
5
5
|
export const storage = {
|
|
6
6
|
name: 'dummy',
|
|
7
7
|
get: mock.fn(() => ({ id: generate() })),
|
|
8
|
-
find: mock.fn(() =>
|
|
8
|
+
find: mock.fn(() => [{ id: generate() }]),
|
|
9
9
|
add: mock.fn(() => true),
|
|
10
10
|
set: mock.fn(() => true),
|
|
11
11
|
store: mock.fn(() => true),
|
|
@@ -27,7 +27,8 @@ export const entity = {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export const initial = {
|
|
30
|
-
initial: true,
|
|
30
|
+
initial: true,
|
|
31
|
+
...entity
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
export const unchanged = {
|
|
@@ -37,6 +38,12 @@ export const unchanged = {
|
|
|
37
38
|
|
|
38
39
|
// a legacy outbox: no storage capability, so `publish` emits inline
|
|
39
40
|
export const outbox = {
|
|
40
|
-
row: mock.fn((event) => ({
|
|
41
|
+
row: mock.fn((event) => ({
|
|
42
|
+
id: generate(),
|
|
43
|
+
lane: 0,
|
|
44
|
+
published: false,
|
|
45
|
+
pending: 0,
|
|
46
|
+
event
|
|
47
|
+
})),
|
|
41
48
|
publish: mock.fn()
|
|
42
49
|
}
|
package/test/state.test.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { describe, it, beforeEach
|
|
1
|
+
import { describe, it, beforeEach } from 'node:test'
|
|
2
2
|
import assert from 'node:assert/strict'
|
|
3
3
|
import { isDeepStrictEqual } from 'node:util'
|
|
4
4
|
|
|
5
|
-
import { State } from '../
|
|
5
|
+
import { State } from '../source/state.js'
|
|
6
6
|
import * as fixtures from './state.fixtures.js'
|
|
7
7
|
|
|
8
8
|
let state
|
|
@@ -16,34 +16,84 @@ beforeEach(() => {
|
|
|
16
16
|
it('should provide object', async () => {
|
|
17
17
|
const entity = await state.object(fixtures.query)
|
|
18
18
|
|
|
19
|
-
assert.ok(
|
|
19
|
+
assert.ok(
|
|
20
|
+
fixtures.storage.get.mock.calls.some(
|
|
21
|
+
(call) =>
|
|
22
|
+
call.arguments.length === 1 &&
|
|
23
|
+
isDeepStrictEqual(call.arguments[0], fixtures.query)
|
|
24
|
+
)
|
|
25
|
+
)
|
|
20
26
|
assert.deepStrictEqual(entity, fixtures.factory.object.mock.calls[0].result)
|
|
21
|
-
assert.ok(
|
|
27
|
+
assert.ok(
|
|
28
|
+
fixtures.factory.object.mock.calls.some(
|
|
29
|
+
(call) =>
|
|
30
|
+
call.arguments.length === 2 &&
|
|
31
|
+
isDeepStrictEqual(call.arguments[0], fixtures.storage.get.mock.calls[0].result) &&
|
|
32
|
+
isDeepStrictEqual(call.arguments[1], true)
|
|
33
|
+
)
|
|
34
|
+
)
|
|
22
35
|
})
|
|
23
36
|
|
|
24
37
|
it('should provide read-only object', async () => {
|
|
25
38
|
await state.object(fixtures.query, false)
|
|
26
39
|
|
|
27
|
-
assert.ok(
|
|
40
|
+
assert.ok(
|
|
41
|
+
fixtures.factory.object.mock.calls.some(
|
|
42
|
+
(call) =>
|
|
43
|
+
call.arguments.length === 2 &&
|
|
44
|
+
isDeepStrictEqual(call.arguments[0], fixtures.storage.get.mock.calls[0].result) &&
|
|
45
|
+
isDeepStrictEqual(call.arguments[1], false)
|
|
46
|
+
)
|
|
47
|
+
)
|
|
28
48
|
})
|
|
29
49
|
|
|
30
50
|
it('should provide read-only objects', async () => {
|
|
31
51
|
await state.objects(fixtures.query, false)
|
|
32
52
|
|
|
33
|
-
assert.ok(
|
|
53
|
+
assert.ok(
|
|
54
|
+
fixtures.factory.objects.mock.calls.some(
|
|
55
|
+
(call) =>
|
|
56
|
+
call.arguments.length === 3 &&
|
|
57
|
+
isDeepStrictEqual(
|
|
58
|
+
call.arguments[0],
|
|
59
|
+
fixtures.storage.find.mock.calls[0].result
|
|
60
|
+
) &&
|
|
61
|
+
isDeepStrictEqual(call.arguments[1], undefined) &&
|
|
62
|
+
isDeepStrictEqual(call.arguments[2], false)
|
|
63
|
+
)
|
|
64
|
+
)
|
|
34
65
|
})
|
|
35
66
|
|
|
36
67
|
it('should store entity', async () => {
|
|
37
68
|
await state.commit(fixtures.initial)
|
|
38
69
|
|
|
39
|
-
assert.ok(
|
|
70
|
+
assert.ok(
|
|
71
|
+
fixtures.storage.store.mock.calls.some(
|
|
72
|
+
(call) =>
|
|
73
|
+
call.arguments.length === 2 &&
|
|
74
|
+
isDeepStrictEqual(call.arguments[0], fixtures.initial.get.mock.calls[0].result) &&
|
|
75
|
+
isDeepStrictEqual(call.arguments[1], fixtures.outbox.row.mock.calls[0].result)
|
|
76
|
+
)
|
|
77
|
+
)
|
|
40
78
|
})
|
|
41
79
|
|
|
42
80
|
it('should publish the row', async () => {
|
|
43
81
|
await state.commit(fixtures.entity)
|
|
44
82
|
|
|
45
|
-
assert.ok(
|
|
46
|
-
|
|
83
|
+
assert.ok(
|
|
84
|
+
fixtures.outbox.row.mock.calls.some(
|
|
85
|
+
(call) =>
|
|
86
|
+
call.arguments.length === 1 &&
|
|
87
|
+
isDeepStrictEqual(call.arguments[0], fixtures.entity.event.mock.calls[0].result)
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
assert.ok(
|
|
91
|
+
fixtures.outbox.publish.mock.calls.some(
|
|
92
|
+
(call) =>
|
|
93
|
+
call.arguments.length === 1 &&
|
|
94
|
+
isDeepStrictEqual(call.arguments[0], fixtures.outbox.row.mock.calls[0].result)
|
|
95
|
+
)
|
|
96
|
+
)
|
|
47
97
|
})
|
|
48
98
|
|
|
49
99
|
it('should not publish if the write did not happen', async () => {
|
|
@@ -62,7 +112,6 @@ it('should build the row before the write', async () => {
|
|
|
62
112
|
return true
|
|
63
113
|
})
|
|
64
114
|
|
|
65
|
-
|
|
66
115
|
await state.commit(fixtures.entity)
|
|
67
116
|
})
|
|
68
117
|
|
|
@@ -72,9 +121,23 @@ describe('assignment', () => {
|
|
|
72
121
|
it('should pass the row to upsert and publish it', async () => {
|
|
73
122
|
const result = await state.apply(changeset, { foo: 1 })
|
|
74
123
|
|
|
75
|
-
assert.ok(
|
|
76
|
-
|
|
77
|
-
|
|
124
|
+
assert.ok(
|
|
125
|
+
fixtures.storage.upsert.mock.calls.some(
|
|
126
|
+
(call) =>
|
|
127
|
+
call.arguments.length === 3 &&
|
|
128
|
+
isDeepStrictEqual(call.arguments[0], changeset.query) &&
|
|
129
|
+
isDeepStrictEqual(call.arguments[1], { foo: 1 }) &&
|
|
130
|
+
isDeepStrictEqual(call.arguments[2], fixtures.outbox.row.mock.calls[0].result)
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
assert.ok(
|
|
135
|
+
fixtures.outbox.publish.mock.calls.some(
|
|
136
|
+
(call) =>
|
|
137
|
+
call.arguments.length === 1 &&
|
|
138
|
+
isDeepStrictEqual(call.arguments[0], fixtures.outbox.row.mock.calls[0].result)
|
|
139
|
+
)
|
|
140
|
+
)
|
|
78
141
|
assert.deepStrictEqual(result, fixtures.storage.upsert.mock.calls[0].result)
|
|
79
142
|
})
|
|
80
143
|
|
|
@@ -88,7 +151,7 @@ describe('assignment', () => {
|
|
|
88
151
|
})
|
|
89
152
|
})
|
|
90
153
|
|
|
91
|
-
function resetCalls
|
|
154
|
+
function resetCalls(target = [assert, fixtures], seen = new Set()) {
|
|
92
155
|
if (target === null || typeof target !== 'object' || seen.has(target)) return
|
|
93
156
|
|
|
94
157
|
seen.add(target)
|
|
@@ -2,16 +2,17 @@ import { it, beforeEach, mock } from 'node:test'
|
|
|
2
2
|
import assert from 'node:assert/strict'
|
|
3
3
|
import { isDeepStrictEqual } from 'node:util'
|
|
4
4
|
|
|
5
|
-
import { Connector } from '../
|
|
5
|
+
import { Connector } from '../source/connector.js'
|
|
6
6
|
|
|
7
7
|
// the fixtures are not connectors, so a dependency is recorded rather than linked
|
|
8
8
|
const depends = mock.method(Connector.prototype, 'depends', () => undefined)
|
|
9
9
|
|
|
10
|
-
const dependencies = (instance) =>
|
|
11
|
-
.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import {
|
|
10
|
+
const dependencies = (instance) =>
|
|
11
|
+
depends.mock.calls
|
|
12
|
+
.filter((call) => call.this === instance)
|
|
13
|
+
.map((call) => call.arguments[0])
|
|
14
|
+
import { Transmission } from '../source/transmission.js'
|
|
15
|
+
import { codes } from '../source/exceptions.js'
|
|
15
16
|
import * as fixtures from './transmission.fixtures.js'
|
|
16
17
|
|
|
17
18
|
let transmission
|
|
@@ -27,14 +28,21 @@ beforeEach(() => {
|
|
|
27
28
|
|
|
28
29
|
it('should be instance of Connector depending on bindings', () => {
|
|
29
30
|
assert.ok(transmission instanceof Connector)
|
|
30
|
-
assert.ok(
|
|
31
|
+
assert.ok(
|
|
32
|
+
dependencies(transmission).some((one) => isDeepStrictEqual(one, fixtures.bindings))
|
|
33
|
+
)
|
|
31
34
|
})
|
|
32
35
|
|
|
33
36
|
it('should pass arguments and return value', async () => {
|
|
34
37
|
const request = { foo: 'bar' }
|
|
35
38
|
const result = await transmission.request(request)
|
|
36
39
|
|
|
37
|
-
assert.ok(
|
|
40
|
+
assert.ok(
|
|
41
|
+
fixtures.bindings[0].request.mock.calls.some(
|
|
42
|
+
(call) =>
|
|
43
|
+
call.arguments.length === 1 && isDeepStrictEqual(call.arguments[0], request)
|
|
44
|
+
)
|
|
45
|
+
)
|
|
38
46
|
assert.strictEqual(result, await fixtures.bindings[0].request.mock.calls[0].result)
|
|
39
47
|
})
|
|
40
48
|
|
|
@@ -47,13 +55,18 @@ it('should pick bindings sequentially', async () => {
|
|
|
47
55
|
})
|
|
48
56
|
|
|
49
57
|
it('should throw exception if none succeeded', async () => {
|
|
50
|
-
await assert.rejects(transmission.request({ pick: 5 }), (error) => {
|
|
58
|
+
await assert.rejects(transmission.request({ pick: 5 }), (error) => {
|
|
59
|
+
assert.partialDeepStrictEqual(error, { code: codes.Transmission })
|
|
60
|
+
return true
|
|
61
|
+
})
|
|
51
62
|
|
|
52
|
-
fixtures.bindings.forEach((binding) =>
|
|
53
|
-
assert.ok(binding.request.mock.callCount() > 0))
|
|
63
|
+
fixtures.bindings.forEach((binding) => assert.ok(binding.request.mock.callCount() > 0))
|
|
54
64
|
})
|
|
55
65
|
|
|
56
|
-
function resetCalls
|
|
66
|
+
function resetCalls(
|
|
67
|
+
target = [assert, depends, dependencies, fixtures],
|
|
68
|
+
seen = new Set()
|
|
69
|
+
) {
|
|
57
70
|
if (target === null || typeof target !== 'object' || seen.has(target)) return
|
|
58
71
|
|
|
59
72
|
seen.add(target)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Operation } from './operation.js';
|
|
2
|
+
export class Assignment extends Operation {
|
|
3
|
+
async acquire(store) {
|
|
4
|
+
const changeset = this.scope.changeset(store.request.query);
|
|
5
|
+
store.scope = changeset;
|
|
6
|
+
store.state = changeset.get();
|
|
7
|
+
}
|
|
8
|
+
async commit(store) {
|
|
9
|
+
const { scope, state, reply, request } = store;
|
|
10
|
+
if (reply.error !== undefined)
|
|
11
|
+
return;
|
|
12
|
+
const changeset = scope;
|
|
13
|
+
changeset.set(state);
|
|
14
|
+
const output = await this.scope.apply(changeset, request.input);
|
|
15
|
+
// assignment returns new state by default
|
|
16
|
+
if (store.reply.output === undefined)
|
|
17
|
+
store.reply.output = output;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=assignment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assignment.js","sourceRoot":"","sources":["../source/assignment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAI1C,MAAM,OAAO,UAAW,SAAQ,SAAS;IACpB,KAAK,CAAC,OAAO,CAAC,KAAY;QAC3C,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,KAAY,CAAC,CAAA;QAElE,KAAK,CAAC,KAAK,GAAG,SAAS,CAAA;QACvB,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC,GAAG,EAAE,CAAA;IAC/B,CAAC;IAEkB,KAAK,CAAC,MAAM,CAAC,KAAY;QAC1C,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,KAAK,CAAA;QAE9C,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS;YAAE,OAAM;QAErC,MAAM,SAAS,GAAG,KAAkB,CAAA;QAEpC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAEpB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;QAE/D,0CAA0C;QAC1C,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS;YAAE,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAA;IACnE,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Connector } from './connector.js';
|
|
2
|
+
import type { Transmission } from './transmission.js';
|
|
3
|
+
import type { Request as Contract } from './contract/request.js';
|
|
4
|
+
import type { Request, Source } from './types/request.js';
|
|
5
|
+
export declare class Call extends Connector {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(transmitter: Transmission, contract: Contract, source?: Source);
|
|
8
|
+
invoke(request?: Request): Promise<any>;
|
|
9
|
+
explain(): any;
|
|
10
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
import { current, encode } from 'openspan';
|
|
3
|
+
import { Connector } from './connector.js';
|
|
4
|
+
export class Call extends Connector {
|
|
5
|
+
#transmitter;
|
|
6
|
+
#contract;
|
|
7
|
+
#source;
|
|
8
|
+
constructor(transmitter, contract, source) {
|
|
9
|
+
super();
|
|
10
|
+
this.#transmitter = transmitter;
|
|
11
|
+
this.#contract = contract;
|
|
12
|
+
this.#source = source;
|
|
13
|
+
this.depends(transmitter);
|
|
14
|
+
}
|
|
15
|
+
async invoke(request = {}) {
|
|
16
|
+
// the caller may have attributed the call itself, as the node bridge does
|
|
17
|
+
if (this.#source !== undefined)
|
|
18
|
+
request.source ??= this.#source;
|
|
19
|
+
this.#contract.fit(request);
|
|
20
|
+
// an operation that takes no input still has to send an explicit null
|
|
21
|
+
request.input ??= null;
|
|
22
|
+
// avoid validation on the recipient's side
|
|
23
|
+
request.authentic = true;
|
|
24
|
+
const context = current();
|
|
25
|
+
if (context !== undefined)
|
|
26
|
+
request.telemetry = encode(context);
|
|
27
|
+
const reply = await this.#transmitter.request(request);
|
|
28
|
+
if (reply === null)
|
|
29
|
+
return null;
|
|
30
|
+
else if (reply instanceof Readable)
|
|
31
|
+
return reply;
|
|
32
|
+
else {
|
|
33
|
+
if (reply.exception !== undefined)
|
|
34
|
+
throw reply.exception;
|
|
35
|
+
if (reply.error !== undefined)
|
|
36
|
+
return new RemoteError(reply.error);
|
|
37
|
+
else
|
|
38
|
+
return reply.output;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
explain() {
|
|
42
|
+
return this.#contract.discovery;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// the remote error as a value: every property it carries, and nothing else enumerable
|
|
46
|
+
class RemoteError extends Error {
|
|
47
|
+
constructor(error) {
|
|
48
|
+
super();
|
|
49
|
+
Object.assign(this, error);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=call.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call.js","sourceRoot":"","sources":["../source/call.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAK1C,MAAM,OAAO,IAAK,SAAQ,SAAS;IACxB,YAAY,CAAc;IAC1B,SAAS,CAAU;IACnB,OAAO,CAAoB;IAEpC,YAAmB,WAAyB,EAAE,QAAkB,EAAE,MAAe;QAC/E,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,YAAY,GAAG,WAAW,CAAA;QAC/B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;QACzB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QAErB,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IAC3B,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,OAAO,GAAY,EAAE;QACvC,0EAA0E;QAC1E,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;YAAE,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,OAAO,CAAA;QAE/D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAE3B,sEAAsE;QACtE,OAAO,CAAC,KAAK,KAAK,IAAI,CAAA;QAEtB,2CAA2C;QAC3C,OAAO,CAAC,SAAS,GAAG,IAAI,CAAA;QAExB,MAAM,OAAO,GAAG,OAAO,EAAE,CAAA;QAEzB,IAAI,OAAO,KAAK,SAAS;YAAE,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;QAE9D,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAEtD,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,IAAI,CAAA;aAC1B,IAAI,KAAK,YAAY,QAAQ;YAAE,OAAO,KAAK,CAAA;aAC3C,CAAC;YACJ,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS;gBAAE,MAAM,KAAK,CAAC,SAAS,CAAA;YAExD,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS;gBAAE,OAAO,IAAI,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;;gBAC7D,OAAO,KAAK,CAAC,MAAM,CAAA;QAC1B,CAAC;IACH,CAAC;IAEM,OAAO;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAA;IACjC,CAAC;CACF;AAED,sFAAsF;AACtF,MAAM,WAAY,SAAQ,KAAK;IAC7B,YAAmB,KAAa;QAC9B,KAAK,EAAE,CAAA;QAEP,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Connector } from './connector.js';
|
|
2
|
+
import type { Algorithm } from './types/bridges.js';
|
|
3
|
+
export declare class Cascade extends Connector {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(bridges: Algorithm[], preflight?: Connector);
|
|
6
|
+
run(...args: [any, any?]): Promise<any>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Connector } from './connector.js';
|
|
2
|
+
export class Cascade extends Connector {
|
|
3
|
+
#last;
|
|
4
|
+
constructor(bridges, preflight) {
|
|
5
|
+
super();
|
|
6
|
+
// this.#bridges = bridges
|
|
7
|
+
this.#last = bridges[bridges.length - 1];
|
|
8
|
+
if (preflight === undefined)
|
|
9
|
+
this.depends(bridges);
|
|
10
|
+
else
|
|
11
|
+
this.depends(bridges).depends(preflight);
|
|
12
|
+
}
|
|
13
|
+
async run(...args) {
|
|
14
|
+
// const reply = {}
|
|
15
|
+
//
|
|
16
|
+
// for (const bridge of this.#bridges) {
|
|
17
|
+
// const partial = await bridge.execute(...args)
|
|
18
|
+
//
|
|
19
|
+
// if (partial.error) return { error: partial.error }
|
|
20
|
+
//
|
|
21
|
+
// merge(reply, partial)
|
|
22
|
+
// }
|
|
23
|
+
//
|
|
24
|
+
// return reply
|
|
25
|
+
return this.#last.execute(...args);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=cascade.js.map
|