@toa.io/core 1.0.0-alpha.31 → 1.0.0-alpha.310
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 +165 -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 +148 -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 +24 -0
- package/transpiled/contract/component.js +48 -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 +3 -0
- package/transpiled/contract/index.js +4 -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 +39 -0
- package/transpiled/contract/request.js +115 -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/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 +14 -0
- package/transpiled/event.js +53 -0
- package/transpiled/event.js.map +1 -0
- package/transpiled/exceptions.d.ts +104 -0
- package/transpiled/exceptions.js +205 -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 +41 -0
- package/transpiled/index.js +34 -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 +69 -0
- package/transpiled/operation.js +174 -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/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 +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/remote.d.ts +10 -0
- package/transpiled/remote.js +11 -0
- package/transpiled/remote.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 +77 -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 +116 -0
- package/transpiled/types/extensions.js +2 -0
- package/transpiled/types/extensions.js.map +1 -0
- package/transpiled/types/inbox.d.ts +22 -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 +54 -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 +146 -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/receiver.test.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const clone = require('clone-deep')
|
|
4
|
-
const { generate } = require('randomstring')
|
|
5
|
-
const { merge } = require('@toa.io/generic')
|
|
6
|
-
|
|
7
|
-
jest.mock('../src/connector')
|
|
8
|
-
|
|
9
|
-
const { Connector } = /** @type {{ Connector: jest.Mock<toa.core.Connector>}} */ require('../src/connector')
|
|
10
|
-
|
|
11
|
-
const { Receiver } = require('../src/receiver')
|
|
12
|
-
const fixtures = require('./receiver.fixtures')
|
|
13
|
-
|
|
14
|
-
/** @type {toa.core.Receiver} */
|
|
15
|
-
let receiver
|
|
16
|
-
|
|
17
|
-
/** @type {toa.norm.component.Receiver} */
|
|
18
|
-
let definition
|
|
19
|
-
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
jest.clearAllMocks()
|
|
22
|
-
|
|
23
|
-
definition = clone(fixtures.definition)
|
|
24
|
-
receiver = new Receiver(fixtures.definition, fixtures.local, fixtures.bridge)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it('should depend on local, bridge', () => {
|
|
28
|
-
expect(Connector.mock.instances[0].depends).toHaveBeenCalledWith(fixtures.local)
|
|
29
|
-
expect(Connector.mock.instances[0].depends).toHaveBeenCalledWith(fixtures.bridge)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('should apply', async () => {
|
|
33
|
-
const payload = { foo: 'bar' }
|
|
34
|
-
|
|
35
|
-
await receiver.receive({ payload })
|
|
36
|
-
|
|
37
|
-
expect(fixtures.local.invoke).toHaveBeenCalledWith(definition.operation, { input: payload })
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it.each([[false], [true]])('should pass UI extensions (adaptive: %s)', async (adaptive) => {
|
|
41
|
-
jest.clearAllMocks()
|
|
42
|
-
|
|
43
|
-
definition.adaptive = adaptive
|
|
44
|
-
receiver = new Receiver(definition, fixtures.local, fixtures.bridge)
|
|
45
|
-
|
|
46
|
-
const payload = { foo: generate() }
|
|
47
|
-
const extension = { [generate()]: generate() }
|
|
48
|
-
const message = { payload, ...extension }
|
|
49
|
-
|
|
50
|
-
await receiver.receive(message)
|
|
51
|
-
|
|
52
|
-
const request = adaptive ? await fixtures.bridge.request.mock.results[0].value : { input: payload }
|
|
53
|
-
const expected = merge(clone(request), extension)
|
|
54
|
-
|
|
55
|
-
const argument = fixtures.local.invoke.mock.calls[0][1]
|
|
56
|
-
|
|
57
|
-
expect(argument).toStrictEqual(expected)
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
describe('conditioned', () => {
|
|
61
|
-
beforeEach(() => {
|
|
62
|
-
definition.conditioned = true
|
|
63
|
-
receiver = new Receiver(definition, fixtures.local, fixtures.bridge)
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
it('should test condition', async () => {
|
|
67
|
-
const payload = { foo: 'bar' }
|
|
68
|
-
await receiver.receive({ payload })
|
|
69
|
-
|
|
70
|
-
expect(fixtures.bridge.condition).toHaveBeenCalledWith(payload)
|
|
71
|
-
expect(fixtures.local.invoke).toHaveBeenCalledWith(definition.operation, { input: payload })
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it('should not apply if condition is false', async () => {
|
|
75
|
-
const payload = { reject: true }
|
|
76
|
-
await receiver.receive({ payload })
|
|
77
|
-
|
|
78
|
-
expect(fixtures.local.invoke).not.toHaveBeenCalled()
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
describe('adaptive', () => {
|
|
83
|
-
beforeEach(() => {
|
|
84
|
-
definition.adaptive = true
|
|
85
|
-
receiver = new Receiver(definition, fixtures.local, fixtures.bridge)
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
it('should apply', async () => {
|
|
89
|
-
const payload = { reject: true }
|
|
90
|
-
await receiver.receive({ payload })
|
|
91
|
-
|
|
92
|
-
expect(fixtures.local.invoke)
|
|
93
|
-
.toHaveBeenCalledWith(definition.operation, await fixtures.bridge.request.mock.results[0].value)
|
|
94
|
-
})
|
|
95
|
-
})
|
package/test/reflection.test.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
4
|
-
const { Reflection, Connector } = require('../')
|
|
5
|
-
|
|
6
|
-
it('should export', () => {
|
|
7
|
-
expect(Reflection).toBeDefined()
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
/** @type {toa.core.Reflection<string>} */
|
|
11
|
-
let reflection
|
|
12
|
-
|
|
13
|
-
const value = generate()
|
|
14
|
-
|
|
15
|
-
/** @type {toa.core.reflection.Source<string>} */
|
|
16
|
-
const source = async () => value
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
reflection = new Reflection(source)
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('should be a Connector', () => {
|
|
23
|
-
expect(reflection).toBeInstanceOf(Connector)
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('should reflect', async () => {
|
|
27
|
-
await reflection.connect()
|
|
28
|
-
|
|
29
|
-
expect(reflection.value).toStrictEqual(value)
|
|
30
|
-
})
|
package/test/state.fixtures.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
4
|
-
|
|
5
|
-
const storage = {
|
|
6
|
-
name: 'dummy',
|
|
7
|
-
get: jest.fn(() => ({ id: generate() })),
|
|
8
|
-
find: jest.fn(() => ([{ id: generate() }])),
|
|
9
|
-
add: jest.fn(() => true),
|
|
10
|
-
set: jest.fn(() => true),
|
|
11
|
-
store: jest.fn(() => true)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const factory = {
|
|
15
|
-
object: jest.fn(() => ({ [generate()]: generate() })),
|
|
16
|
-
objects: jest.fn(() => ({ [generate()]: generate() }))
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const query = generate()
|
|
20
|
-
|
|
21
|
-
const entity = {
|
|
22
|
-
get: jest.fn(() => ({ [generate()]: generate() })),
|
|
23
|
-
event: jest.fn(() => ({
|
|
24
|
-
state: { [generate()]: generate() }, changeset: { [generate()]: generate() }
|
|
25
|
-
}))
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const initial = {
|
|
29
|
-
initial: true, ...entity
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const unchanged = {
|
|
33
|
-
...entity,
|
|
34
|
-
event: jest.fn(() => ({ state: { [generate()]: generate() }, changeset: {} }))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const emitter = {
|
|
38
|
-
emit: jest.fn()
|
|
39
|
-
}
|
|
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
|
package/test/state.test.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { State } = require('../src/state')
|
|
4
|
-
const fixtures = require('./state.fixtures')
|
|
5
|
-
|
|
6
|
-
let state
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
jest.clearAllMocks()
|
|
10
|
-
|
|
11
|
-
state = new State(fixtures.storage, fixtures.factory, fixtures.emitter)
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it('should provide object', async () => {
|
|
15
|
-
const entity = await state.object(fixtures.query)
|
|
16
|
-
|
|
17
|
-
expect(fixtures.storage.get).toHaveBeenCalledWith(fixtures.query)
|
|
18
|
-
expect(entity).toStrictEqual(fixtures.factory.object.mock.results[0].value)
|
|
19
|
-
expect(fixtures.factory.object).toHaveBeenCalledWith(fixtures.storage.get.mock.results[0].value)
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('should provide objects', async () => {
|
|
23
|
-
const set = await state.objects(fixtures.query)
|
|
24
|
-
|
|
25
|
-
expect(fixtures.storage.find).toHaveBeenCalledWith(fixtures.query)
|
|
26
|
-
expect(set).toStrictEqual(fixtures.factory.objects.mock.results[0].value)
|
|
27
|
-
expect(fixtures.factory.objects).toHaveBeenCalledWith(fixtures.storage.find.mock.results[0].value)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('should store entity', async () => {
|
|
31
|
-
await state.commit(fixtures.initial)
|
|
32
|
-
|
|
33
|
-
expect(fixtures.storage.store).toHaveBeenCalledWith(fixtures.initial.get.mock.results[0].value)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('should emit', async () => {
|
|
37
|
-
await state.commit(fixtures.entity)
|
|
38
|
-
|
|
39
|
-
expect(fixtures.emitter.emit).toHaveBeenCalledWith(fixtures.entity.event.mock.results[0].value)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
it('should not emit if state has not been changed', async () => {
|
|
43
|
-
await state.commit(fixtures.unchanged)
|
|
44
|
-
|
|
45
|
-
expect(fixtures.emitter.emit).not.toHaveBeenCalled()
|
|
46
|
-
})
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
4
|
-
|
|
5
|
-
const binding = (index) => ({
|
|
6
|
-
request: jest.fn(async (request) => {
|
|
7
|
-
if (request?.pick !== undefined && request.pick !== index) return false
|
|
8
|
-
|
|
9
|
-
return { output: generate() }
|
|
10
|
-
})
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
const bindings = [0, 1, 2, 3, 4].map(binding)
|
|
14
|
-
|
|
15
|
-
exports.bindings = bindings
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
jest.mock('../src/connector')
|
|
4
|
-
|
|
5
|
-
const { Connector } = require('../src/connector')
|
|
6
|
-
const { Transmission } = require('../src/transmission')
|
|
7
|
-
const { codes } = require('../src/exceptions')
|
|
8
|
-
const fixtures = require('./transmission.fixtures')
|
|
9
|
-
|
|
10
|
-
let transmission
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
jest.clearAllMocks()
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
transmission = new Transmission(fixtures.bindings)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
it('should be instance of Connector depending on bindings', () => {
|
|
21
|
-
expect(transmission).toBeInstanceOf(Connector)
|
|
22
|
-
expect(Connector.mock.instances[0].depends).toHaveBeenCalledWith(fixtures.bindings)
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it('should pass arguments and return value', async () => {
|
|
26
|
-
const request = { foo: 'bar' }
|
|
27
|
-
const result = await transmission.request(request)
|
|
28
|
-
|
|
29
|
-
expect(fixtures.bindings[0].request).toHaveBeenCalledWith(request)
|
|
30
|
-
expect(result).toBe(await fixtures.bindings[0].request.mock.results[0].value)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('should pick bindings sequentially', async () => {
|
|
34
|
-
let result = await transmission.request()
|
|
35
|
-
expect(result).toBe(await fixtures.bindings[0].request.mock.results[0].value)
|
|
36
|
-
|
|
37
|
-
result = await transmission.request({ pick: 1 })
|
|
38
|
-
expect(result).toBe(await fixtures.bindings[1].request.mock.results[0]?.value)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('should throw exception if none succeeded', async () => {
|
|
42
|
-
await expect(transmission.request({ pick: 5 })).rejects.toMatchObject({ code: codes.Transmission })
|
|
43
|
-
|
|
44
|
-
fixtures.bindings.forEach((binding) =>
|
|
45
|
-
expect(binding.request).toHaveBeenCalled())
|
|
46
|
-
})
|
package/types/bindings.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import * as _core from './index'
|
|
2
|
-
|
|
3
|
-
declare namespace toa.core.bindings{
|
|
4
|
-
|
|
5
|
-
type Properties = {
|
|
6
|
-
async?: boolean
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface Consumer extends _core.Connector{
|
|
10
|
-
request (request: Request): Promise<_core.Reply>
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface Emitter extends _core.Connector{
|
|
14
|
-
emit (message: _core.Message): Promise<void>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface Broadcast<L> extends _core.Connector{
|
|
18
|
-
transmit<T> (label: L, payload: T): Promise<void>
|
|
19
|
-
|
|
20
|
-
receive<T> (label: L, callback: (payload: T) => void | Promise<void>): Promise<void>
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface Factory{
|
|
24
|
-
producer? (locator: _core.Locator, endpoints: Array<string>, producer: _core.Component): _core.Connector
|
|
25
|
-
|
|
26
|
-
consumer? (locator: _core.Locator, endpoint: string): Consumer
|
|
27
|
-
|
|
28
|
-
emitter? (locator: _core.Locator, label: string): Emitter
|
|
29
|
-
|
|
30
|
-
receiver? (locator: _core.Locator, label: string, group: string, receiver: _core.Receiver): _core.Connector
|
|
31
|
-
|
|
32
|
-
broadcast? (name: string, group?: string): Broadcast
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export type Emitter = toa.core.bindings.Emitter
|
|
38
|
-
export type Factory = toa.core.bindings.Factory
|
|
39
|
-
export type Properties = toa.core.bindings.Properties
|
|
40
|
-
export type Broadcast<L = any> = toa.core.bindings.Broadcast<L>
|
package/types/bridges.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Request, Reply } from './request'
|
|
2
|
-
import type { Context } from './context'
|
|
3
|
-
|
|
4
|
-
export interface Algorithm {
|
|
5
|
-
mount: (context?: Context) => Promise<void>
|
|
6
|
-
|
|
7
|
-
execute: ((input: any, scope: object | object[]) => Promise<Reply>) |
|
|
8
|
-
((input: any) => Promise<Reply>) |
|
|
9
|
-
(() => Promise<Reply>)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface Event {
|
|
13
|
-
condition: (object: object) => Promise<boolean>
|
|
14
|
-
|
|
15
|
-
payload: (object: object) => Promise<object>
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface Receiver {
|
|
19
|
-
condition: (object: object) => Promise<boolean>
|
|
20
|
-
|
|
21
|
-
request: (object: object) => Promise<Request>
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface Factory {
|
|
25
|
-
algorithm?: (path: string, name: string, context: Context) => Algorithm
|
|
26
|
-
|
|
27
|
-
event?: (path: string, label: string) => Event
|
|
28
|
-
|
|
29
|
-
receiver?: (path: string, label: string) => Receiver
|
|
30
|
-
}
|
package/types/component.d.ts
DELETED
package/types/connector.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export class Connector {
|
|
2
|
-
public id: string
|
|
3
|
-
public connected: boolean
|
|
4
|
-
|
|
5
|
-
public connect (): Promise<void>
|
|
6
|
-
|
|
7
|
-
public disconnect (interrupt?: boolean): Promise<void>
|
|
8
|
-
|
|
9
|
-
public depends (connector: Connector | Connector[]): Connector
|
|
10
|
-
|
|
11
|
-
link (connector: Connector): void
|
|
12
|
-
|
|
13
|
-
protected open (): Promise<void> | void
|
|
14
|
-
|
|
15
|
-
protected close (): Promise<void> | void
|
|
16
|
-
|
|
17
|
-
protected dispose (): Promise<void> | void
|
|
18
|
-
}
|
package/types/context.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as _request from './request'
|
|
2
|
-
import * as _reply from './reply'
|
|
3
|
-
import * as _extensions from './extensions'
|
|
4
|
-
import * as _connector from './connector'
|
|
5
|
-
|
|
6
|
-
export interface Context extends _connector.Connector{
|
|
7
|
-
aspects: _extensions.Aspect[]
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Calls local endpoint
|
|
11
|
-
*/
|
|
12
|
-
apply (endpoint: string, request: _request.Request): Promise<_reply.Reply>
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Calls remote endpoint
|
|
16
|
-
*/
|
|
17
|
-
call (namespace: string, name: string, endpoint: string, request: _request.Request): Promise<_reply.Reply>
|
|
18
|
-
|
|
19
|
-
// shortcuts
|
|
20
|
-
[key: string]: any
|
|
21
|
-
}
|
package/types/entity.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import * as _event from './event'
|
|
2
|
-
import * as _storages from './storages'
|
|
3
|
-
|
|
4
|
-
declare namespace toa.core {
|
|
5
|
-
|
|
6
|
-
namespace entity {
|
|
7
|
-
|
|
8
|
-
interface Factory {
|
|
9
|
-
init(id: string): Entity
|
|
10
|
-
|
|
11
|
-
object(record: Object): Entity
|
|
12
|
-
|
|
13
|
-
objects(recordset: Object[]): Entity[]
|
|
14
|
-
|
|
15
|
-
changeset(query: _storages.Query): Changeset
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface Entity {
|
|
21
|
-
get(): _storages.Record
|
|
22
|
-
|
|
23
|
-
set(value: _storages.Record): void
|
|
24
|
-
|
|
25
|
-
event(): _event.Event
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
type Upsert = {
|
|
29
|
-
changeset: Object
|
|
30
|
-
insert: Object
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface Changeset {
|
|
34
|
-
query: _storages.Query
|
|
35
|
-
|
|
36
|
-
get(): Object
|
|
37
|
-
|
|
38
|
-
set(value: Object): void
|
|
39
|
-
|
|
40
|
-
export(): Upsert
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export type Entity = toa.core.Entity
|
|
46
|
-
export type Changeset = toa.core.Changeset
|
package/types/event.d.ts
DELETED
package/types/exception.d.ts
DELETED
package/types/extensions.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as _core from './index'
|
|
2
|
-
import * as _component from './component'
|
|
3
|
-
import * as _context from './context'
|
|
4
|
-
import * as _storages from './storages'
|
|
5
|
-
import * as _bindings from './bindings'
|
|
6
|
-
|
|
7
|
-
export interface Factory{
|
|
8
|
-
tenant? (locator: _core.Locator, manifest: object): _core.Connector
|
|
9
|
-
|
|
10
|
-
aspect? (locator: _core.Locator, manifest: object | null): Aspect | Aspect[]
|
|
11
|
-
|
|
12
|
-
service? (name?: string): _core.Connector | null
|
|
13
|
-
|
|
14
|
-
component? (component: _component.Component): _component.Component
|
|
15
|
-
|
|
16
|
-
context? (context: _context.Context): _context.Context
|
|
17
|
-
|
|
18
|
-
storage? (storage: _storages.Storage): _storages.Storage
|
|
19
|
-
|
|
20
|
-
emitter? (emitter: _bindings.Emitter, label: string): _bindings.Emitter
|
|
21
|
-
|
|
22
|
-
receiver? (receiver: _core.Receiver, locator: _core.Locator): _core.Receiver
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface Aspect extends _core.Connector{
|
|
26
|
-
name: string
|
|
27
|
-
|
|
28
|
-
invoke (...args: any[]): any
|
|
29
|
-
}
|
package/types/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export * as bindings from './bindings'
|
|
2
|
-
export * as extensions from './extensions'
|
|
3
|
-
export * as storages from './storages'
|
|
4
|
-
export * as bridges from './bridges'
|
|
5
|
-
export * as operations from './operations'
|
|
6
|
-
|
|
7
|
-
export type { Component } from './component'
|
|
8
|
-
export { Connector } from './connector'
|
|
9
|
-
export type { Context } from './context'
|
|
10
|
-
export type { Exception } from './exception'
|
|
11
|
-
export { Locator } from './locator'
|
|
12
|
-
export type { Receiver } from './receiver'
|
|
13
|
-
export type { Message } from './message'
|
|
14
|
-
export type { Request, Query, Reply } from './request'
|
package/types/locator.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export class Locator{
|
|
2
|
-
public readonly name: string
|
|
3
|
-
public readonly namespace: string
|
|
4
|
-
|
|
5
|
-
public readonly id: string
|
|
6
|
-
public readonly label: string
|
|
7
|
-
public readonly uppercase: string
|
|
8
|
-
public readonly lowercase: string
|
|
9
|
-
|
|
10
|
-
constructor (name: string, namespace?: string)
|
|
11
|
-
|
|
12
|
-
hostname (type?: string): string
|
|
13
|
-
}
|
package/types/message.d.ts
DELETED
package/types/operations.d.ts
DELETED
package/types/query.d.ts
DELETED
package/types/receiver.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as _message from './message'
|
|
2
|
-
import * as _connector from './connector'
|
|
3
|
-
|
|
4
|
-
declare namespace toa.core {
|
|
5
|
-
|
|
6
|
-
interface Receiver extends _connector.Connector {
|
|
7
|
-
receive(message: _message.Message): Promise<void>
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type Receiver = toa.core.Receiver
|
package/types/reflection.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as _core from './connector'
|
|
2
|
-
|
|
3
|
-
declare namespace toa.core {
|
|
4
|
-
|
|
5
|
-
namespace reflection {
|
|
6
|
-
type Source = () => Promise<any>
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface Reflection<T> extends _core.Connector {
|
|
10
|
-
value: T
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type Source = toa.core.reflection.Source
|
package/types/request.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Exception } from './exception'
|
|
2
|
-
|
|
3
|
-
export interface Query {
|
|
4
|
-
id?: string
|
|
5
|
-
criteria?: string
|
|
6
|
-
omit?: number
|
|
7
|
-
limit?: number
|
|
8
|
-
sort?: Array<string>
|
|
9
|
-
projection?: Array<string>
|
|
10
|
-
version?: number
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface Request {
|
|
14
|
-
input?: any
|
|
15
|
-
query?: Query
|
|
16
|
-
authentic?: boolean
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface Reply {
|
|
20
|
-
output?: any
|
|
21
|
-
error?: object
|
|
22
|
-
exception?: Exception
|
|
23
|
-
}
|
package/types/state.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import * as _entity from './entity'
|
|
2
|
-
import * as _storages from './storages'
|
|
3
|
-
|
|
4
|
-
declare namespace toa.core {
|
|
5
|
-
|
|
6
|
-
namespace transition {
|
|
7
|
-
|
|
8
|
-
type Event = {
|
|
9
|
-
origin: Object
|
|
10
|
-
state: Object
|
|
11
|
-
changeset: Object
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface State {
|
|
17
|
-
init(id: string): _entity.Entity
|
|
18
|
-
|
|
19
|
-
object(query: _storages.Query): Promise<_entity.Entity>
|
|
20
|
-
|
|
21
|
-
objects(query: _storages.Query): Promise<_entity.Entity[]>
|
|
22
|
-
|
|
23
|
-
changeset(query: _storages.Query): _entity.Changeset
|
|
24
|
-
|
|
25
|
-
none(): null
|
|
26
|
-
|
|
27
|
-
commit(entity: _entity.Entity): Promise<boolean>
|
|
28
|
-
|
|
29
|
-
apply(changeset: _entity.Changeset): Promise<void>
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type State = toa.core.State
|
|
35
|
-
export type Event = toa.core.transition.Event
|