@toa.io/core 1.0.0-alpha.32 → 1.0.0-alpha.320
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +28 -12
- package/transpiled/abandon.d.ts +9 -0
- package/transpiled/abandon.js +37 -0
- package/transpiled/abandon.js.map +1 -0
- package/transpiled/assignment.d.ts +6 -0
- package/transpiled/assignment.js +25 -0
- package/transpiled/assignment.js.map +1 -0
- package/transpiled/call.d.ts +10 -0
- package/transpiled/call.js +187 -0
- package/transpiled/call.js.map +1 -0
- package/transpiled/cascade.d.ts +7 -0
- package/transpiled/cascade.js +28 -0
- package/transpiled/cascade.js.map +1 -0
- package/transpiled/component.d.ts +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 +37 -0
- package/transpiled/contract/component.js +94 -0
- package/transpiled/contract/component.js.map +1 -0
- package/transpiled/contract/contract.d.ts +10 -0
- package/transpiled/contract/contract.js +14 -0
- package/transpiled/contract/contract.js.map +1 -0
- package/transpiled/contract/index.d.ts +4 -0
- package/transpiled/contract/index.js +5 -0
- package/transpiled/contract/index.js.map +1 -0
- package/transpiled/contract/reply.d.ts +7 -0
- package/transpiled/contract/reply.js +48 -0
- package/transpiled/contract/reply.js.map +1 -0
- package/transpiled/contract/request.d.ts +49 -0
- package/transpiled/contract/request.js +152 -0
- package/transpiled/contract/request.js.map +1 -0
- package/transpiled/contract/schemas.d.ts +4 -0
- package/transpiled/contract/schemas.js +38 -0
- package/transpiled/contract/schemas.js.map +1 -0
- package/transpiled/contract/system.d.ts +33 -0
- package/transpiled/contract/system.js +76 -0
- package/transpiled/contract/system.js.map +1 -0
- package/transpiled/deliveries.d.ts +22 -0
- package/transpiled/deliveries.js +31 -0
- package/transpiled/deliveries.js.map +1 -0
- package/transpiled/effect.d.ts +7 -0
- package/transpiled/effect.js +13 -0
- package/transpiled/effect.js.map +1 -0
- package/transpiled/emission.d.ts +10 -0
- package/transpiled/emission.js +16 -0
- package/transpiled/emission.js.map +1 -0
- package/transpiled/encoded.d.ts +16 -0
- package/transpiled/encoded.js +25 -0
- package/transpiled/encoded.js.map +1 -0
- package/transpiled/entities/changeset.d.ts +10 -0
- package/transpiled/entities/changeset.js +27 -0
- package/transpiled/entities/changeset.js.map +1 -0
- package/transpiled/entities/entity.d.ts +19 -0
- package/transpiled/entities/entity.js +137 -0
- package/transpiled/entities/entity.js.map +1 -0
- package/transpiled/entities/factory.d.ts +27 -0
- package/transpiled/entities/factory.js +38 -0
- package/transpiled/entities/factory.js.map +1 -0
- package/transpiled/entities/index.d.ts +5 -0
- package/transpiled/entities/index.js +6 -0
- package/transpiled/entities/index.js.map +1 -0
- package/transpiled/entities/newid.d.ts +11 -0
- package/transpiled/entities/newid.js +41 -0
- package/transpiled/entities/newid.js.map +1 -0
- package/transpiled/entities/set.d.ts +10 -0
- package/transpiled/entities/set.js +19 -0
- package/transpiled/entities/set.js.map +1 -0
- package/transpiled/event.d.ts +20 -0
- package/transpiled/event.js +65 -0
- package/transpiled/event.js.map +1 -0
- package/transpiled/exceptions.d.ts +110 -0
- package/transpiled/exceptions.js +215 -0
- package/transpiled/exceptions.js.map +1 -0
- package/transpiled/gate.d.ts +40 -0
- package/transpiled/gate.js +84 -0
- package/transpiled/gate.js.map +1 -0
- package/transpiled/guard.d.ts +7 -0
- package/transpiled/guard.js +12 -0
- package/transpiled/guard.js.map +1 -0
- package/transpiled/halting.d.ts +16 -0
- package/transpiled/halting.js +25 -0
- package/transpiled/halting.js.map +1 -0
- package/transpiled/index.d.ts +44 -0
- package/transpiled/index.js +36 -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 +73 -0
- package/transpiled/operation.js +213 -0
- package/transpiled/operation.js.map +1 -0
- package/transpiled/outbox.d.ts +45 -0
- package/transpiled/outbox.js +448 -0
- package/transpiled/outbox.js.map +1 -0
- package/transpiled/outbox.measurements.d.ts +4 -0
- package/transpiled/outbox.measurements.js +38 -0
- package/transpiled/outbox.measurements.js.map +1 -0
- package/transpiled/parts.d.ts +20 -0
- package/transpiled/parts.js +23 -0
- package/transpiled/parts.js.map +1 -0
- package/transpiled/query/criteria.d.ts +6 -0
- package/transpiled/query/criteria.js +177 -0
- package/transpiled/query/criteria.js.map +1 -0
- package/transpiled/query/options.d.ts +3 -0
- package/transpiled/query/options.js +34 -0
- package/transpiled/query/options.js.map +1 -0
- package/transpiled/query.d.ts +9 -0
- package/transpiled/query.js +57 -0
- package/transpiled/query.js.map +1 -0
- package/transpiled/receiver.d.ts +20 -0
- package/transpiled/receiver.js +113 -0
- package/transpiled/receiver.js.map +1 -0
- package/transpiled/reflection.d.ts +9 -0
- package/transpiled/reflection.js +13 -0
- package/transpiled/reflection.js.map +1 -0
- package/transpiled/remote.d.ts +10 -0
- package/transpiled/remote.js +11 -0
- package/transpiled/remote.js.map +1 -0
- package/transpiled/rendering.d.ts +13 -0
- package/transpiled/rendering.js +21 -0
- package/transpiled/rendering.js.map +1 -0
- package/transpiled/safety.d.ts +5 -0
- package/transpiled/safety.js +26 -0
- package/transpiled/safety.js.map +1 -0
- package/transpiled/state.d.ts +36 -0
- package/transpiled/state.js +131 -0
- package/transpiled/state.js.map +1 -0
- package/transpiled/trail.d.ts +78 -0
- package/transpiled/trail.js +112 -0
- package/transpiled/trail.js.map +1 -0
- package/transpiled/transition.d.ts +14 -0
- package/transpiled/transition.js +51 -0
- package/transpiled/transition.js.map +1 -0
- package/transpiled/transmission.d.ts +8 -0
- package/transpiled/transmission.js +30 -0
- package/transpiled/transmission.js.map +1 -0
- package/transpiled/types/atomicity.d.ts +58 -0
- package/transpiled/types/atomicity.js +2 -0
- package/transpiled/types/atomicity.js.map +1 -0
- package/transpiled/types/bindings.d.ts +82 -0
- package/transpiled/types/bindings.js +2 -0
- package/transpiled/types/bindings.js.map +1 -0
- package/transpiled/types/bridges.d.ts +41 -0
- package/transpiled/types/bridges.js +2 -0
- package/transpiled/types/bridges.js.map +1 -0
- package/transpiled/types/extensions.d.ts +121 -0
- package/transpiled/types/extensions.js +2 -0
- package/transpiled/types/extensions.js.map +1 -0
- package/transpiled/types/inbox.d.ts +27 -0
- package/transpiled/types/inbox.js +2 -0
- package/transpiled/types/inbox.js.map +1 -0
- package/transpiled/types/index.d.ts +14 -0
- package/transpiled/types/index.js +9 -0
- package/transpiled/types/index.js.map +1 -0
- package/transpiled/types/message.d.ts +16 -0
- package/transpiled/types/message.js +2 -0
- package/transpiled/types/message.js.map +1 -0
- package/transpiled/types/operations.d.ts +15 -0
- package/transpiled/types/operations.js +2 -0
- package/transpiled/types/operations.js.map +1 -0
- package/transpiled/types/outbox.d.ts +68 -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 +154 -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/locator.test.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
4
|
-
const { Locator } = require('../src/locator')
|
|
5
|
-
|
|
6
|
-
/** @type {string} */
|
|
7
|
-
let name
|
|
8
|
-
|
|
9
|
-
/** @type {string} */
|
|
10
|
-
let namespace
|
|
11
|
-
|
|
12
|
-
/** @type {toa.core.Locator} */
|
|
13
|
-
let locator
|
|
14
|
-
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
name = generate()
|
|
17
|
-
namespace = generate()
|
|
18
|
-
|
|
19
|
-
locator = new Locator(name, namespace)
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('should expose name and namespace', () => {
|
|
23
|
-
expect(locator.name).toStrictEqual(name)
|
|
24
|
-
expect(locator.namespace).toStrictEqual(namespace)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it('should expose id, label', () => {
|
|
28
|
-
const id = locator.namespace + '.' + locator.name
|
|
29
|
-
const label = locator.namespace.toLowerCase() + '-' + locator.name.toLowerCase()
|
|
30
|
-
|
|
31
|
-
expect(locator.id).toStrictEqual(id)
|
|
32
|
-
expect(locator.label).toStrictEqual(label)
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('should expose uppercase', () => {
|
|
36
|
-
expect(locator.uppercase).toStrictEqual((locator.namespace + '_' + locator.name).toUpperCase())
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('should throw if name is undefined', () => {
|
|
40
|
-
expect(() => new Locator(undefined, namespace)).toThrow(TypeError)
|
|
41
|
-
|
|
42
|
-
// noinspection JSCheckFunctionSignatures
|
|
43
|
-
expect(() => new Locator()).toThrow(TypeError)
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it('should expose host', () => {
|
|
47
|
-
expect(locator.hostname()).toStrictEqual((namespace + '-' + name).toLowerCase())
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it('should expose host with given prefix', () => {
|
|
51
|
-
const prefix = generate()
|
|
52
|
-
|
|
53
|
-
expect(locator.hostname(prefix)).toStrictEqual((prefix + '-' + namespace + '-' + name).toLowerCase())
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
describe('global', () => {
|
|
57
|
-
beforeEach(() => {
|
|
58
|
-
locator = new Locator(name)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it('should not throw', () => undefined)
|
|
62
|
-
|
|
63
|
-
it('should expose id', () => {
|
|
64
|
-
expect(locator.id).toStrictEqual(name)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('should expose label', () => {
|
|
68
|
-
expect(locator.label).toStrictEqual(name.toLowerCase())
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('should expose uppercase', () => {
|
|
72
|
-
expect(locator.uppercase).toStrictEqual(name.toUpperCase())
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('should expose hostname', () => {
|
|
76
|
-
const type = generate()
|
|
77
|
-
|
|
78
|
-
expect(locator.hostname(type)).toStrictEqual((type + '-' + name).toLowerCase())
|
|
79
|
-
expect(locator.hostname()).toStrictEqual(name.toLowerCase())
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
describe('parse', () => {
|
|
84
|
-
it('should be', async () => {
|
|
85
|
-
expect(Locator.parse).toBeInstanceOf(Function)
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
const namespace = generate()
|
|
89
|
-
const name = generate()
|
|
90
|
-
const id = `${namespace}.${name}`
|
|
91
|
-
|
|
92
|
-
it('should parse id', async () => {
|
|
93
|
-
const locator = Locator.parse(id)
|
|
94
|
-
|
|
95
|
-
expect(locator.namespace).toStrictEqual(namespace)
|
|
96
|
-
expect(locator.name).toStrictEqual(name)
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
it('should parse endpoint', async () => {
|
|
100
|
-
const endpoint = `${id}.${generate()}`
|
|
101
|
-
const locator = Locator.parse(endpoint)
|
|
102
|
-
|
|
103
|
-
expect(locator.namespace).toStrictEqual(namespace)
|
|
104
|
-
expect(locator.name).toStrictEqual(name)
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
it('should parse token as global', async () => {
|
|
108
|
-
const locator = Locator.parse(name)
|
|
109
|
-
|
|
110
|
-
expect(locator.namespace).toBeUndefined()
|
|
111
|
-
expect(locator.name).toStrictEqual(name)
|
|
112
|
-
})
|
|
113
|
-
})
|
package/test/query.fixtures.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const samples = {
|
|
4
|
-
simple: {
|
|
5
|
-
query: {
|
|
6
|
-
criteria: 'name==Eddie'
|
|
7
|
-
},
|
|
8
|
-
parsed: {
|
|
9
|
-
criteria: {
|
|
10
|
-
type: 'COMPARISON',
|
|
11
|
-
left: { type: 'SELECTOR', selector: 'name' },
|
|
12
|
-
operator: '==',
|
|
13
|
-
right: { type: 'VALUE', value: 'Eddie' }
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
properties: {
|
|
17
|
-
name: {
|
|
18
|
-
type: 'string'
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
extended: {
|
|
24
|
-
query: {
|
|
25
|
-
criteria: 'flag==true;volume>2.1'
|
|
26
|
-
},
|
|
27
|
-
parsed: {
|
|
28
|
-
criteria: {
|
|
29
|
-
type: 'LOGIC',
|
|
30
|
-
left: {
|
|
31
|
-
type: 'COMPARISON',
|
|
32
|
-
left: { type: 'SELECTOR', selector: 'flag' },
|
|
33
|
-
operator: '==',
|
|
34
|
-
right: { type: 'VALUE', value: true }
|
|
35
|
-
},
|
|
36
|
-
operator: ';',
|
|
37
|
-
right: {
|
|
38
|
-
type: 'COMPARISON',
|
|
39
|
-
left: { type: 'SELECTOR', selector: 'volume' },
|
|
40
|
-
operator: '>',
|
|
41
|
-
right: { type: 'VALUE', value: 2.1 }
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
properties: {
|
|
46
|
-
flag: {
|
|
47
|
-
type: 'boolean'
|
|
48
|
-
},
|
|
49
|
-
volume: {
|
|
50
|
-
type: 'number'
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
abc: {
|
|
56
|
-
properties: {
|
|
57
|
-
a: {
|
|
58
|
-
type: 'string'
|
|
59
|
-
},
|
|
60
|
-
b: {
|
|
61
|
-
type: 'string'
|
|
62
|
-
},
|
|
63
|
-
c: {
|
|
64
|
-
type: 'string'
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
id: {
|
|
70
|
-
properties: {
|
|
71
|
-
id: {
|
|
72
|
-
type: 'string'
|
|
73
|
-
},
|
|
74
|
-
name: {
|
|
75
|
-
type: 'string'
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
query: {
|
|
79
|
-
id: '123',
|
|
80
|
-
criteria: 'name==Eddie'
|
|
81
|
-
},
|
|
82
|
-
parsed: {
|
|
83
|
-
id: '123',
|
|
84
|
-
criteria: {
|
|
85
|
-
type: 'COMPARISON',
|
|
86
|
-
left: {
|
|
87
|
-
type: 'SELECTOR',
|
|
88
|
-
selector: 'name'
|
|
89
|
-
},
|
|
90
|
-
operator: '==',
|
|
91
|
-
right: {
|
|
92
|
-
type: 'VALUE',
|
|
93
|
-
value: 'Eddie'
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
exports.samples = samples
|
package/test/query.test.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Query } = require('../src/query')
|
|
4
|
-
const fixtures = require('./query.fixtures')
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
jest.clearAllMocks()
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
describe('criteria', () => {
|
|
11
|
-
it('should not throw if no criteria', () => {
|
|
12
|
-
const instance = new Query(fixtures.samples.simple.properties)
|
|
13
|
-
const query = instance.parse({})
|
|
14
|
-
|
|
15
|
-
expect(query.criteria).toBeUndefined()
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
it('should parse criteria', () => {
|
|
19
|
-
const instance = new Query(fixtures.samples.simple.properties)
|
|
20
|
-
const query = instance.parse(fixtures.samples.simple.query)
|
|
21
|
-
|
|
22
|
-
expect(query.criteria).toEqual(fixtures.samples.simple.parsed.criteria)
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it('should parse criteria with type coercion', () => {
|
|
26
|
-
const instance = new Query(fixtures.samples.extended.properties)
|
|
27
|
-
const query = instance.parse(fixtures.samples.extended.query)
|
|
28
|
-
|
|
29
|
-
expect(query.criteria).toEqual(fixtures.samples.extended.parsed.criteria)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('should throw on unknown properties', () => {
|
|
33
|
-
const instance = new Query(fixtures.samples.simple.properties)
|
|
34
|
-
|
|
35
|
-
expect(() => instance.parse({ criteria: 'lastname==Johnson' })).toThrow(/not defined/)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('should parse id', () => {
|
|
39
|
-
const instance = new Query(fixtures.samples.id.properties)
|
|
40
|
-
const query = instance.parse({ ...fixtures.samples.id.query })
|
|
41
|
-
|
|
42
|
-
expect(query).toStrictEqual(fixtures.samples.id.parsed)
|
|
43
|
-
})
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
describe('options', () => {
|
|
47
|
-
const instance = new Query(fixtures.samples.abc.properties)
|
|
48
|
-
|
|
49
|
-
it('should not throw if no options', () => {
|
|
50
|
-
const query = instance.parse({})
|
|
51
|
-
|
|
52
|
-
expect(query.options).toBeUndefined()
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
describe('omit, limit', () => {
|
|
56
|
-
it('should pass', () => {
|
|
57
|
-
const input = { omit: 1, limit: 1 }
|
|
58
|
-
const query = instance.parse(input)
|
|
59
|
-
|
|
60
|
-
expect(query.options).toStrictEqual(input)
|
|
61
|
-
})
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
describe('sort', () => {
|
|
65
|
-
it('should set default values', () => {
|
|
66
|
-
const sort = ['a', 'b:desc', 'c']
|
|
67
|
-
const query = instance.parse({ sort })
|
|
68
|
-
|
|
69
|
-
expect(query.options.sort).toStrictEqual([['a', 'asc'], ['b', 'desc'], ['c', 'asc']])
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
it('should throw on unknown properties', () => {
|
|
73
|
-
const sort = ['d:asc']
|
|
74
|
-
|
|
75
|
-
expect(() => instance.parse({ sort })).toThrow(/not defined/)
|
|
76
|
-
})
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
describe('projection', () => {
|
|
80
|
-
it('should throw on unknown properties', () => {
|
|
81
|
-
const projection = ['a', 'b', 'c', 'd']
|
|
82
|
-
|
|
83
|
-
expect(() => instance.parse({ projection })).toThrow(/not defined/)
|
|
84
|
-
})
|
|
85
|
-
})
|
|
86
|
-
})
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
4
|
-
|
|
5
|
-
const definition = /** @type {toa.norm.component.Receiver} */ {
|
|
6
|
-
operation: generate(),
|
|
7
|
-
conditioned: false,
|
|
8
|
-
adaptive: false
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const local = /** @type {toa.core.Component} */ {
|
|
12
|
-
invoke: jest.fn()
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// noinspection JSCheckFunctionSignatures
|
|
16
|
-
const bridge = /** @type {toa.core.bridges.Event} */ {
|
|
17
|
-
condition: jest.fn(async (payload) => !(payload.reject === true)),
|
|
18
|
-
request: jest.fn(async () => ({ input: generate() }))
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
exports.definition = definition
|
|
22
|
-
exports.local = local
|
|
23
|
-
exports.bridge = bridge
|
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