@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/emission.test.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
jest.mock('../src/connector')
|
|
4
|
-
|
|
5
|
-
const clone = require('clone-deep')
|
|
6
|
-
|
|
7
|
-
const { Connector } = require('../src/connector')
|
|
8
|
-
const { Emission } = require('../src/emission')
|
|
9
|
-
const fixtures = require('./emission.fixtures')
|
|
10
|
-
|
|
11
|
-
let emission, event
|
|
12
|
-
|
|
13
|
-
beforeEach(async () => {
|
|
14
|
-
jest.clearAllMocks()
|
|
15
|
-
|
|
16
|
-
emission = new Emission(fixtures.events)
|
|
17
|
-
event = clone(fixtures.event)
|
|
18
|
-
|
|
19
|
-
await emission.open()
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('should depend on events', () => {
|
|
23
|
-
expect(emission).toBeInstanceOf(Connector)
|
|
24
|
-
expect(Connector.mock.instances[0].depends).toHaveBeenCalledWith(fixtures.events)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it('should emit events', async () => {
|
|
28
|
-
expect.assertions(fixtures.events.length)
|
|
29
|
-
|
|
30
|
-
await emission.emit(event)
|
|
31
|
-
|
|
32
|
-
for (const evt of fixtures.events) {
|
|
33
|
-
expect(evt.emit).toHaveBeenCalledWith(event)
|
|
34
|
-
}
|
|
35
|
-
})
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
4
|
-
|
|
5
|
-
// noinspection JSCheckFunctionSignatures
|
|
6
|
-
const schema = {
|
|
7
|
-
fit: jest.fn((object) =>
|
|
8
|
-
(object.fail ? { [generate()]: generate() } : null)),
|
|
9
|
-
|
|
10
|
-
defaults: jest.fn(() => ({ [generate()]: generate() }))
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const state = () => ({
|
|
14
|
-
id: generate(),
|
|
15
|
-
foo: generate(),
|
|
16
|
-
_created: generate(),
|
|
17
|
-
_updated: generate(),
|
|
18
|
-
_deleted: generate(),
|
|
19
|
-
_version: 0
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
const failed = () => ({
|
|
23
|
-
...state(),
|
|
24
|
-
fail: true
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
exports.schema = schema
|
|
28
|
-
exports.state = state
|
|
29
|
-
exports.failed = failed
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Entity } = require('../../src/entities/entity')
|
|
4
|
-
const fixtures = require('./entity.fixtures')
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
jest.clearAllMocks()
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
describe('new', () => {
|
|
11
|
-
it('should throw on schema error', () => {
|
|
12
|
-
const entity = new Entity(fixtures.schema)
|
|
13
|
-
|
|
14
|
-
expect(() => entity.set(fixtures.failed())).toThrow()
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it('should provide state', () => {
|
|
18
|
-
const entity = new Entity(fixtures.schema)
|
|
19
|
-
const state = fixtures.state()
|
|
20
|
-
|
|
21
|
-
entity.set(state)
|
|
22
|
-
|
|
23
|
-
expect(entity.get()).toEqual(state)
|
|
24
|
-
})
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
describe('argument', () => {
|
|
28
|
-
it('should provide initial state if no argument passed', () => {
|
|
29
|
-
const entity = new Entity(fixtures.schema)
|
|
30
|
-
const defaults = fixtures.schema.defaults.mock.results[0].value
|
|
31
|
-
const expected = {
|
|
32
|
-
...defaults,
|
|
33
|
-
_version: 0
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
expect(entity.get()).toStrictEqual(expect.objectContaining(expected))
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('should set state', () => {
|
|
40
|
-
const state = fixtures.state()
|
|
41
|
-
const entity = new Entity(fixtures.schema, state)
|
|
42
|
-
|
|
43
|
-
expect(entity.get()).toEqual(state)
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it('should provide event', () => {
|
|
48
|
-
const origin = fixtures.state()
|
|
49
|
-
const entity = new Entity(fixtures.schema, origin)
|
|
50
|
-
const state = entity.get()
|
|
51
|
-
|
|
52
|
-
state.foo = 'new value'
|
|
53
|
-
entity.set(state)
|
|
54
|
-
|
|
55
|
-
const event = entity.event()
|
|
56
|
-
|
|
57
|
-
expect(event).toEqual(expect.objectContaining({
|
|
58
|
-
state,
|
|
59
|
-
origin,
|
|
60
|
-
changeset: expect.objectContaining({
|
|
61
|
-
foo: 'new value',
|
|
62
|
-
_version: 1
|
|
63
|
-
})
|
|
64
|
-
}))
|
|
65
|
-
})
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const randomstring = require('randomstring')
|
|
4
|
-
|
|
5
|
-
const schema = { [randomstring.generate()]: randomstring.generate() }
|
|
6
|
-
const storage = { id: jest.fn(() => randomstring.generate()) }
|
|
7
|
-
const entity = { [randomstring.generate()]: randomstring.generate() }
|
|
8
|
-
const set = Array.from(Array(5))
|
|
9
|
-
.map((_, index) => ({ id: index, [randomstring.generate()]: randomstring.generate() }))
|
|
10
|
-
|
|
11
|
-
const Entity = jest.fn().mockImplementation(function () { this.id = randomstring.generate() })
|
|
12
|
-
const EntitySet = jest.fn().mockImplementation(function () {})
|
|
13
|
-
|
|
14
|
-
exports.schema = schema
|
|
15
|
-
exports.storage = storage
|
|
16
|
-
exports.entity = entity
|
|
17
|
-
exports.set = set
|
|
18
|
-
exports.mock = { Entity, EntitySet }
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
4
|
-
|
|
5
|
-
const fixtures = require('./factory.fixtures')
|
|
6
|
-
const mock = fixtures.mock
|
|
7
|
-
|
|
8
|
-
jest.mock('../../src/entities/entity', () => ({ Entity: mock.Entity }))
|
|
9
|
-
jest.mock('../../src/entities/set', () => ({ EntitySet: mock.EntitySet }))
|
|
10
|
-
|
|
11
|
-
const { Factory } = require('../../src/entities/factory')
|
|
12
|
-
|
|
13
|
-
let factory
|
|
14
|
-
|
|
15
|
-
beforeEach(async () => {
|
|
16
|
-
jest.clearAllMocks()
|
|
17
|
-
|
|
18
|
-
factory = new Factory(fixtures.schema, () => fixtures.storage.id())
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('should create initial', () => {
|
|
22
|
-
const id = generate()
|
|
23
|
-
const initial = factory.init(id)
|
|
24
|
-
|
|
25
|
-
expect(initial).toBeInstanceOf(mock.Entity)
|
|
26
|
-
expect(initial.constructor).toHaveBeenCalledWith(fixtures.schema, id)
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('should create instance', () => {
|
|
30
|
-
const object = factory.object(fixtures.entity)
|
|
31
|
-
|
|
32
|
-
expect(object).toBeInstanceOf(mock.Entity)
|
|
33
|
-
expect(object.constructor).toHaveBeenCalledWith(fixtures.schema, fixtures.entity)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('should create set', () => {
|
|
37
|
-
const objects = factory.objects(fixtures.set)
|
|
38
|
-
|
|
39
|
-
expect(objects).toBeInstanceOf(mock.EntitySet)
|
|
40
|
-
|
|
41
|
-
const instances = fixtures.set.map((entity, index) => {
|
|
42
|
-
expect(mock.Entity).toHaveBeenNthCalledWith(index + 1, fixtures.schema, entity)
|
|
43
|
-
|
|
44
|
-
return mock.Entity.mock.instances[index]
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
expect(objects.constructor).toHaveBeenCalledWith(instances)
|
|
48
|
-
})
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
4
|
-
|
|
5
|
-
const set = [
|
|
6
|
-
{ get: jest.fn(() => ({ [generate()]: generate() })) },
|
|
7
|
-
{ get: jest.fn(() => ({ [generate()]: generate() })) },
|
|
8
|
-
{ get: jest.fn(() => ({ [generate()]: generate() })) }
|
|
9
|
-
]
|
|
10
|
-
|
|
11
|
-
exports.set = set
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { EntitySet } = require('../../src/entities/set')
|
|
4
|
-
const fixtures = require('./set.fixtures')
|
|
5
|
-
|
|
6
|
-
it('should provide state', () => {
|
|
7
|
-
const set = new EntitySet(fixtures.set)
|
|
8
|
-
const state = set.get()
|
|
9
|
-
const expected = fixtures.set.map((entity) => entity.get.mock.results[0].value)
|
|
10
|
-
|
|
11
|
-
expect(state).toStrictEqual(expected)
|
|
12
|
-
})
|
package/test/event.fixtures.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { generate } = require('randomstring')
|
|
4
|
-
|
|
5
|
-
const definition = {
|
|
6
|
-
conditioned: true,
|
|
7
|
-
subjective: true
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// noinspection JSCheckFunctionSignatures
|
|
11
|
-
const bridge = {
|
|
12
|
-
condition: jest.fn(async (origin) => !origin.falsy),
|
|
13
|
-
payload: jest.fn(async () => ({ [generate()]: generate() }))
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const binding = {
|
|
17
|
-
emit: jest.fn()
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const event = {
|
|
21
|
-
origin: { [generate()]: generate() },
|
|
22
|
-
state: { [generate()]: generate() },
|
|
23
|
-
changeset: { [generate()]: generate() }
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
exports.bridge = bridge
|
|
27
|
-
exports.binding = binding
|
|
28
|
-
exports.definition = definition
|
|
29
|
-
exports.event = event
|
package/test/event.test.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const clone = require('clone-deep')
|
|
4
|
-
|
|
5
|
-
jest.mock('../src/connector')
|
|
6
|
-
|
|
7
|
-
const { Connector } = require('../src/connector')
|
|
8
|
-
const { Event } = require('../src/event')
|
|
9
|
-
const fixtures = require('./event.fixtures')
|
|
10
|
-
|
|
11
|
-
let event, emit
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
jest.clearAllMocks()
|
|
15
|
-
|
|
16
|
-
event = new Event(fixtures.definition, fixtures.binding, fixtures.bridge)
|
|
17
|
-
emit = () => event.emit(fixtures.event)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
it('should depend on binding', () => {
|
|
21
|
-
expect(event).toBeInstanceOf(Connector)
|
|
22
|
-
expect(Connector.mock.instances[0].depends).toHaveBeenCalledWith(fixtures.binding)
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it('should depend on bridge if provided', () => {
|
|
26
|
-
expect(Connector.mock.instances[0].depends).toHaveBeenCalledWith(fixtures.bridge)
|
|
27
|
-
|
|
28
|
-
event = new Event(fixtures.definition, fixtures.binding)
|
|
29
|
-
expect(Connector.mock.instances[1].depends).not.toHaveBeenCalledWith(fixtures.bridge)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
describe('condition', () => {
|
|
33
|
-
describe('conditioned', () => {
|
|
34
|
-
it('should call condition', async () => {
|
|
35
|
-
await emit()
|
|
36
|
-
|
|
37
|
-
expect(fixtures.bridge.condition).toHaveBeenCalledWith(fixtures.event)
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('should emit if condition returns true', async () => {
|
|
41
|
-
await emit()
|
|
42
|
-
|
|
43
|
-
const payload = await fixtures.bridge.payload.mock.results[0].value
|
|
44
|
-
const message = { payload }
|
|
45
|
-
expect(fixtures.binding.emit).toHaveBeenCalledWith(message)
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('should not emit if condition returns false', async () => {
|
|
49
|
-
const origin = clone(fixtures.event.origin)
|
|
50
|
-
|
|
51
|
-
origin.falsy = true
|
|
52
|
-
|
|
53
|
-
await event.emit(origin, fixtures.event.changeset, fixtures.event.state)
|
|
54
|
-
|
|
55
|
-
expect(fixtures.binding.emit).not.toHaveBeenCalled()
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
describe('unconditioned', () => {
|
|
60
|
-
beforeEach(() => {
|
|
61
|
-
const definition = clone(fixtures.definition)
|
|
62
|
-
|
|
63
|
-
definition.conditioned = false
|
|
64
|
-
|
|
65
|
-
event = new Event(definition, fixtures.binding, fixtures.bridge)
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
it('should not call condition', async () => {
|
|
69
|
-
await event.emit(fixtures.event.origin, fixtures.event.changeset, fixtures.event.state)
|
|
70
|
-
|
|
71
|
-
expect(fixtures.bridge.condition).not.toHaveBeenCalledWith()
|
|
72
|
-
|
|
73
|
-
const payload = await fixtures.bridge.payload.mock.results[0].value
|
|
74
|
-
const message = { payload }
|
|
75
|
-
|
|
76
|
-
expect(fixtures.binding.emit).toHaveBeenCalledWith(message)
|
|
77
|
-
})
|
|
78
|
-
})
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
describe('payload', () => {
|
|
82
|
-
describe('subjective', () => {
|
|
83
|
-
it('should emit payload', async () => {
|
|
84
|
-
await emit()
|
|
85
|
-
|
|
86
|
-
const payload = await fixtures.bridge.payload.mock.results[0].value
|
|
87
|
-
const message = { payload }
|
|
88
|
-
|
|
89
|
-
expect(fixtures.binding.emit).toHaveBeenCalledWith(message)
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
describe('objective', () => {
|
|
94
|
-
beforeEach(() => {
|
|
95
|
-
const definition = clone(fixtures.definition)
|
|
96
|
-
|
|
97
|
-
definition.subjective = false
|
|
98
|
-
|
|
99
|
-
event = new Event(definition, fixtures.binding, fixtures.bridge)
|
|
100
|
-
emit = () => event.emit(fixtures.event)
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('should not call payload', async () => {
|
|
104
|
-
await emit()
|
|
105
|
-
|
|
106
|
-
expect(fixtures.bridge.payload).not.toHaveBeenCalled()
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('should return state as payload', async () => {
|
|
110
|
-
await emit()
|
|
111
|
-
|
|
112
|
-
const payload = fixtures.event.state
|
|
113
|
-
const message = { payload }
|
|
114
|
-
|
|
115
|
-
expect(fixtures.binding.emit).toHaveBeenCalledWith(message)
|
|
116
|
-
})
|
|
117
|
-
})
|
|
118
|
-
})
|
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
|