@toa.io/core 1.0.0-alpha.8 → 1.0.0-alpha.81
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 +6 -9
- package/src/call.js +4 -0
- package/src/cascade.js +2 -3
- package/src/component.js +15 -18
- package/src/composition.js +1 -1
- package/src/connector.js +3 -8
- package/src/contract/contract.js +23 -0
- package/src/contract/reply.js +26 -9
- package/src/contract/request.js +15 -5
- package/src/contract/schemas/query.yaml +1 -2
- package/src/discovery.js +2 -5
- package/src/effect.js +19 -0
- package/src/entities/changeset.js +8 -15
- package/src/entities/entity.js +26 -19
- package/src/entities/factory.js +6 -0
- package/src/exceptions.js +20 -19
- package/src/exposition.js +3 -2
- package/src/index.js +2 -0
- package/src/locator.js +7 -2
- package/src/observation.js +1 -9
- package/src/operation.js +29 -7
- package/src/receiver.js +13 -10
- package/src/remote.js +5 -7
- package/src/state.js +49 -35
- package/src/transition.js +9 -23
- package/src/transmission.js +12 -3
- package/test/component.test.js +2 -1
- package/test/contract/conditions.test.js +5 -5
- package/test/contract/request.test.js +7 -7
- package/test/entities/entity.test.js +4 -49
- package/types/bindings.d.ts +7 -5
- package/types/component.d.ts +4 -1
- package/types/extensions.d.ts +4 -3
- package/types/index.ts +1 -0
- package/types/locator.d.ts +2 -1
- package/types/operations.d.ts +6 -0
- package/types/remote.d.ts +18 -0
- package/types/request.d.ts +1 -0
- package/src/contract/conditions.js +0 -21
package/src/operation.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { console } = require('openspan')
|
|
3
4
|
const { Connector } = require('./connector')
|
|
4
|
-
const { SystemException } = require('./exceptions')
|
|
5
|
+
const { SystemException, RequestContractException } = require('./exceptions')
|
|
6
|
+
const { Readable } = require('node:stream')
|
|
5
7
|
|
|
6
8
|
class Operation extends Connector {
|
|
7
9
|
scope
|
|
@@ -26,8 +28,15 @@ class Operation extends Connector {
|
|
|
26
28
|
|
|
27
29
|
async invoke (request) {
|
|
28
30
|
try {
|
|
29
|
-
if (request.authentic !== true)
|
|
30
|
-
|
|
31
|
+
if (request.authentic !== true)
|
|
32
|
+
this.#contracts.request.fit(request)
|
|
33
|
+
|
|
34
|
+
if ('query' in request)
|
|
35
|
+
request.query = this.#query.parse(request.query)
|
|
36
|
+
|
|
37
|
+
// validate entity
|
|
38
|
+
if ('entity' in request)
|
|
39
|
+
this.scope.fit(request.entity)
|
|
31
40
|
|
|
32
41
|
const store = { request }
|
|
33
42
|
|
|
@@ -47,14 +56,24 @@ class Operation extends Connector {
|
|
|
47
56
|
return store.reply
|
|
48
57
|
}
|
|
49
58
|
|
|
50
|
-
async acquire () {
|
|
59
|
+
async acquire (store) {
|
|
60
|
+
if (this.#scope === 'none')
|
|
61
|
+
return
|
|
62
|
+
|
|
63
|
+
const scope = await this.query(store.request.query)
|
|
64
|
+
const raw = scope === null || scope instanceof Readable
|
|
65
|
+
|
|
66
|
+
store.scope = scope
|
|
67
|
+
store.state = raw ? scope : scope.get()
|
|
68
|
+
}
|
|
51
69
|
|
|
52
70
|
async run (store) {
|
|
53
71
|
const { request, state } = store
|
|
54
|
-
|
|
55
|
-
const reply = await this.#cascade.run(request.input, state) || {}
|
|
72
|
+
const reply = await this.#cascade.run(request.input, state)
|
|
56
73
|
|
|
57
|
-
//
|
|
74
|
+
// validate reply only on local environments
|
|
75
|
+
if (process.env.TOA_ENV === 'local' && !(reply instanceof Readable))
|
|
76
|
+
this.#contracts.reply.fit(reply)
|
|
58
77
|
|
|
59
78
|
store.reply = reply
|
|
60
79
|
}
|
|
@@ -62,6 +81,9 @@ class Operation extends Connector {
|
|
|
62
81
|
async commit () {}
|
|
63
82
|
|
|
64
83
|
async query (query) {
|
|
84
|
+
if (query === undefined)
|
|
85
|
+
throw new RequestContractException('Request query is required')
|
|
86
|
+
|
|
65
87
|
return this.scope[this.#scope](query)
|
|
66
88
|
}
|
|
67
89
|
}
|
package/src/receiver.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { console } = require('openspan')
|
|
3
4
|
const { add } = require('@toa.io/generic')
|
|
4
5
|
const { Connector } = require('./connector')
|
|
5
6
|
|
|
@@ -16,18 +17,13 @@ class Receiver extends Connector {
|
|
|
16
17
|
/** @type {string} */
|
|
17
18
|
#endpoint
|
|
18
19
|
|
|
19
|
-
/** @type {
|
|
20
|
+
/** @type {unknown[]} */
|
|
21
|
+
#arguments
|
|
22
|
+
|
|
20
23
|
#local
|
|
21
24
|
|
|
22
|
-
/** @type {toa.core.bridges.Receiver} */
|
|
23
25
|
#bridge
|
|
24
26
|
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
* @param {toa.norm.component.Receiver} definition
|
|
28
|
-
* @param {toa.core.Component} local
|
|
29
|
-
* @param {toa.core.bridges.Receiver} bridge
|
|
30
|
-
*/
|
|
31
27
|
constructor (definition, local, bridge) {
|
|
32
28
|
super()
|
|
33
29
|
|
|
@@ -36,6 +32,7 @@ class Receiver extends Connector {
|
|
|
36
32
|
this.#conditioned = conditioned
|
|
37
33
|
this.#adaptive = adaptive
|
|
38
34
|
this.#endpoint = operation
|
|
35
|
+
this.#arguments = definition.arguments
|
|
39
36
|
|
|
40
37
|
this.#local = local
|
|
41
38
|
this.#bridge = bridge
|
|
@@ -54,11 +51,17 @@ class Receiver extends Connector {
|
|
|
54
51
|
|
|
55
52
|
add(request, extensions)
|
|
56
53
|
|
|
57
|
-
|
|
54
|
+
try {
|
|
55
|
+
await this.#local.invoke(this.#endpoint, request)
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error('Receiver error', error)
|
|
58
|
+
|
|
59
|
+
throw error
|
|
60
|
+
}
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
async #request (payload) {
|
|
61
|
-
return this.#adaptive ? await this.#bridge.request(payload) : { input: payload }
|
|
64
|
+
return this.#adaptive ? await this.#bridge.request(payload, ...(this.#arguments ?? [])) : { input: payload }
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
|
package/src/remote.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
3
|
+
const assert = require('node:assert')
|
|
5
4
|
const { Component } = require('./component')
|
|
6
5
|
|
|
7
6
|
class Remote extends Component {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
explain (endpoint) {
|
|
8
|
+
assert.ok(endpoint in this.operations,
|
|
9
|
+
`Endpoint '${endpoint}' is not provided by '${this.locator.id}'`)
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
console.info(`Remote '${this.locator.id}' disconnected`)
|
|
11
|
+
return this.operations[endpoint].explain()
|
|
14
12
|
}
|
|
15
13
|
}
|
|
16
14
|
|
package/src/state.js
CHANGED
|
@@ -1,61 +1,83 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { empty } = require('@toa.io/generic')
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
StatePreconditionException,
|
|
7
|
-
StateNotFoundException
|
|
8
|
-
} = require('./exceptions')
|
|
3
|
+
const { empty, newid } = require('@toa.io/generic')
|
|
4
|
+
const { StatePreconditionException, StateNotFoundException } = require('./exceptions')
|
|
9
5
|
|
|
10
6
|
class State {
|
|
11
|
-
#
|
|
7
|
+
#associated
|
|
12
8
|
#storage
|
|
13
|
-
#
|
|
9
|
+
#entities
|
|
14
10
|
#emission
|
|
15
11
|
|
|
16
|
-
constructor (storage, entity, emission,
|
|
12
|
+
constructor (storage, entity, emission, associated) {
|
|
17
13
|
this.#storage = storage
|
|
18
|
-
this.#
|
|
14
|
+
this.#entities = entity
|
|
19
15
|
this.#emission = emission
|
|
20
|
-
this.#
|
|
16
|
+
this.#associated = associated === true
|
|
21
17
|
}
|
|
22
18
|
|
|
23
19
|
init (id) {
|
|
24
|
-
return this.#
|
|
20
|
+
return this.#entities.init(id)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
fit (values) {
|
|
24
|
+
return this.#entities.fit(values)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
async object (query) {
|
|
28
28
|
const record = await this.#storage.get(query)
|
|
29
29
|
|
|
30
30
|
if (record === null) {
|
|
31
|
-
if (this.#
|
|
31
|
+
if (this.#associated && query.id !== undefined && query.version === undefined)
|
|
32
32
|
return this.init(query.id)
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
else if (query.version !== undefined)
|
|
34
|
+
throw new StatePreconditionException()
|
|
35
35
|
|
|
36
|
-
if (record === null) {
|
|
37
36
|
return null
|
|
38
|
-
} else
|
|
39
|
-
return this.#
|
|
40
|
-
}
|
|
37
|
+
} else
|
|
38
|
+
return this.#entities.object(record)
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
async objects (query) {
|
|
44
42
|
const recordset = await this.#storage.find(query)
|
|
45
43
|
|
|
46
|
-
return this.#
|
|
44
|
+
return this.#entities.objects(recordset)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async stream (query) {
|
|
48
|
+
return this.#storage.stream(query)
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
changeset (query) {
|
|
50
|
-
return this.#
|
|
52
|
+
return this.#entities.changeset(query)
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
none () {
|
|
54
56
|
return null
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
async
|
|
58
|
-
const
|
|
59
|
+
async ensure (query, properties, input) {
|
|
60
|
+
const object = this.#entities.init()
|
|
61
|
+
const blank = object.get()
|
|
62
|
+
|
|
63
|
+
Object.assign(blank, properties)
|
|
64
|
+
|
|
65
|
+
object.set(blank)
|
|
66
|
+
|
|
67
|
+
const record = await this.#storage.ensure(query, properties, object.get())
|
|
68
|
+
|
|
69
|
+
if (record.id !== blank.id) // exists
|
|
70
|
+
return this.#entities.object(record)
|
|
71
|
+
|
|
72
|
+
const event = object.event(input)
|
|
73
|
+
|
|
74
|
+
await this.#emission.emit(event)
|
|
75
|
+
|
|
76
|
+
return object
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async commit (state, input) {
|
|
80
|
+
const event = state.event(input)
|
|
59
81
|
|
|
60
82
|
let ok = true
|
|
61
83
|
|
|
@@ -65,25 +87,17 @@ class State {
|
|
|
65
87
|
ok = await this.#storage.store(object)
|
|
66
88
|
|
|
67
89
|
// #20
|
|
68
|
-
|
|
90
|
+
if (ok === true)
|
|
91
|
+
await this.#emission.emit(event)
|
|
69
92
|
}
|
|
70
93
|
|
|
71
94
|
return ok
|
|
72
95
|
}
|
|
73
96
|
|
|
74
97
|
async apply (state) {
|
|
75
|
-
const
|
|
76
|
-
changeset,
|
|
77
|
-
insert
|
|
78
|
-
} = state.export()
|
|
79
|
-
|
|
80
|
-
let upsert
|
|
81
|
-
|
|
82
|
-
if (this.#dependent && state.query.id !== undefined && state.query.version === undefined) {
|
|
83
|
-
upsert = insert
|
|
84
|
-
}
|
|
98
|
+
const changeset = state.export()
|
|
85
99
|
|
|
86
|
-
const result = await this.#storage.upsert(state.query, changeset
|
|
100
|
+
const result = await this.#storage.upsert(state.query, changeset)
|
|
87
101
|
|
|
88
102
|
if (result === null) {
|
|
89
103
|
if (state.query.version !== undefined) {
|
package/src/transition.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { retry } = require('@toa.io/generic')
|
|
4
|
-
|
|
5
4
|
const { Operation } = require('./operation')
|
|
6
|
-
const {
|
|
7
|
-
StateConcurrencyException,
|
|
8
|
-
StateNotFoundException,
|
|
9
|
-
DuplicateException,
|
|
10
|
-
Exception
|
|
11
|
-
} = require('./exceptions')
|
|
5
|
+
const { StateConcurrencyException, StateNotFoundException } = require('./exceptions')
|
|
12
6
|
|
|
13
7
|
class Transition extends Operation {
|
|
14
8
|
#concurrency
|
|
@@ -28,35 +22,27 @@ class Transition extends Operation {
|
|
|
28
22
|
|
|
29
23
|
store.scope = request.query ? await this.query(request.query) : this.scope.init()
|
|
30
24
|
|
|
31
|
-
if (store.scope === null
|
|
25
|
+
if (store.scope === null || store.scope.deleted === true)
|
|
26
|
+
throw new StateNotFoundException()
|
|
32
27
|
|
|
33
28
|
store.state = store.scope.get()
|
|
34
29
|
}
|
|
35
30
|
|
|
36
31
|
async commit (store) {
|
|
37
|
-
const {
|
|
38
|
-
scope,
|
|
39
|
-
state,
|
|
40
|
-
reply,
|
|
41
|
-
retry
|
|
42
|
-
} = store
|
|
32
|
+
const { scope, state, reply, retry } = store
|
|
43
33
|
|
|
44
34
|
if (reply.error !== undefined) return
|
|
45
35
|
|
|
46
36
|
scope.set(state)
|
|
47
37
|
|
|
48
|
-
const result = await this.scope.commit(scope)
|
|
38
|
+
const result = await this.scope.commit(scope, store.request.input)
|
|
49
39
|
|
|
50
|
-
if (result === false
|
|
51
|
-
(
|
|
52
|
-
if (this.#concurrency === 'retry') {
|
|
40
|
+
if (result === false) {
|
|
41
|
+
if (this.#concurrency === 'retry')
|
|
53
42
|
return retry()
|
|
54
|
-
|
|
43
|
+
else
|
|
55
44
|
throw new StateConcurrencyException()
|
|
56
|
-
}
|
|
57
45
|
}
|
|
58
|
-
|
|
59
|
-
if (result instanceof Exception) throw result
|
|
60
46
|
}
|
|
61
47
|
|
|
62
48
|
async #retry (store, retry) {
|
|
@@ -70,7 +56,7 @@ const RETRY = {
|
|
|
70
56
|
base: 10,
|
|
71
57
|
max: 5000,
|
|
72
58
|
dispersion: 1,
|
|
73
|
-
retries:
|
|
59
|
+
retries: 32
|
|
74
60
|
}
|
|
75
61
|
|
|
76
62
|
exports.Transition = Transition
|
package/src/transmission.js
CHANGED
|
@@ -18,13 +18,22 @@ class Transmission extends Connector {
|
|
|
18
18
|
let i = 0
|
|
19
19
|
|
|
20
20
|
while (reply === false && i < this.#bindings.length) {
|
|
21
|
-
|
|
21
|
+
const binding = this.#bindings[i]
|
|
22
|
+
|
|
22
23
|
i++
|
|
24
|
+
|
|
25
|
+
if (request?.task === true) {
|
|
26
|
+
if (binding.task === undefined)
|
|
27
|
+
continue
|
|
28
|
+
|
|
29
|
+
await binding.task(request)
|
|
30
|
+
reply = null
|
|
31
|
+
} else
|
|
32
|
+
reply = await binding.request(request)
|
|
23
33
|
}
|
|
24
34
|
|
|
25
|
-
if (reply === false)
|
|
35
|
+
if (reply === false)
|
|
26
36
|
throw new TransmissionException(`All (${this.#bindings.length}) bindings rejected.`)
|
|
27
|
-
}
|
|
28
37
|
|
|
29
38
|
return reply
|
|
30
39
|
}
|
package/test/component.test.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const { Component } = require('../src/component')
|
|
4
4
|
const { codes } = require('../src/exceptions')
|
|
5
5
|
const fixtures = require('./component.fixtures')
|
|
6
|
+
const { AssertionError } = require('node:assert')
|
|
6
7
|
|
|
7
8
|
describe('Invocations', () => {
|
|
8
9
|
const name = ['foo', 'bar'][Math.floor(2 * Math.random())]
|
|
@@ -21,7 +22,7 @@ describe('Invocations', () => {
|
|
|
21
22
|
|
|
22
23
|
it('should throw on unknown invocation name', async () => {
|
|
23
24
|
await expect(() => component.invoke('baz'))
|
|
24
|
-
.rejects.
|
|
25
|
+
.rejects.toThrow(AssertionError)
|
|
25
26
|
})
|
|
26
27
|
|
|
27
28
|
it('should invoke input and query', async () => {
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
const { generate } = require('randomstring')
|
|
4
4
|
|
|
5
|
-
const {
|
|
5
|
+
const { Contract } = require('../../src/contract/contract')
|
|
6
6
|
const fixtures = require('./contract.fixtures')
|
|
7
7
|
|
|
8
|
-
let
|
|
8
|
+
let contract
|
|
9
9
|
|
|
10
10
|
beforeEach(() => {
|
|
11
|
-
|
|
11
|
+
contract = new Contract(fixtures.schema)
|
|
12
12
|
})
|
|
13
13
|
|
|
14
14
|
it('should fit value', () => {
|
|
15
15
|
const value = { foo: generate() }
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
contract.fit(value)
|
|
18
18
|
|
|
19
19
|
expect(fixtures.schema.fit).toHaveBeenCalledWith(value)
|
|
20
20
|
})
|
|
@@ -22,5 +22,5 @@ it('should fit value', () => {
|
|
|
22
22
|
it('should throw on invalid value', () => {
|
|
23
23
|
const value = { invalid: true }
|
|
24
24
|
|
|
25
|
-
expect(() =>
|
|
25
|
+
expect(() => contract.fit(value)).toThrow()
|
|
26
26
|
})
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
const clone = require('clone-deep')
|
|
4
4
|
const { generate } = require('randomstring')
|
|
5
5
|
|
|
6
|
-
jest.mock('../../src/contract/
|
|
6
|
+
jest.mock('../../src/contract/contract')
|
|
7
7
|
|
|
8
8
|
const { Request } = require('../../src/contract/request')
|
|
9
|
-
const {
|
|
9
|
+
const { Contract } = require('../../src/contract/contract')
|
|
10
10
|
const fixtures = require('./contract.fixtures')
|
|
11
11
|
|
|
12
12
|
let contract
|
|
@@ -14,14 +14,14 @@ let contract
|
|
|
14
14
|
beforeEach(() => {
|
|
15
15
|
jest.clearAllMocks()
|
|
16
16
|
|
|
17
|
-
contract = new Request(fixtures.schema)
|
|
17
|
+
contract = new Request(fixtures.schema, {})
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
const dummy = { schema: { properties: {} } }
|
|
21
21
|
|
|
22
22
|
it('should extend Conditions', () => {
|
|
23
|
-
expect(contract).toBeInstanceOf(
|
|
24
|
-
expect(
|
|
23
|
+
expect(contract).toBeInstanceOf(Contract)
|
|
24
|
+
expect(Contract).toHaveBeenCalledWith(fixtures.schema)
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
it('should fit request', () => {
|
|
@@ -29,7 +29,7 @@ it('should fit request', () => {
|
|
|
29
29
|
|
|
30
30
|
contract.fit(request)
|
|
31
31
|
|
|
32
|
-
expect(
|
|
32
|
+
expect(Contract.mock.instances[0].fit).toHaveBeenCalledWith(request)
|
|
33
33
|
})
|
|
34
34
|
|
|
35
35
|
describe('schema', () => {
|
|
@@ -59,7 +59,7 @@ describe('schema', () => {
|
|
|
59
59
|
|
|
60
60
|
it('should not contain query if declaration.query is false', () => {
|
|
61
61
|
schema.properties.query = { type: 'null' }
|
|
62
|
-
expect(Request.schema({ query: false }, dummy)).
|
|
62
|
+
expect(Request.schema({ query: false }, dummy)).toMatchObject(schema)
|
|
63
63
|
})
|
|
64
64
|
|
|
65
65
|
it('should require query if declaration.query is true', () => {
|
|
@@ -7,35 +7,7 @@ beforeEach(() => {
|
|
|
7
7
|
jest.clearAllMocks()
|
|
8
8
|
})
|
|
9
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
10
|
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(expected)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
11
|
it('should set state', () => {
|
|
40
12
|
const state = fixtures.state()
|
|
41
13
|
const entity = new Entity(fixtures.schema, state)
|
|
@@ -54,29 +26,12 @@ it('should provide event', () => {
|
|
|
54
26
|
|
|
55
27
|
const event = entity.event()
|
|
56
28
|
|
|
57
|
-
expect(event).toEqual({
|
|
29
|
+
expect(event).toEqual(expect.objectContaining({
|
|
58
30
|
state,
|
|
59
31
|
origin,
|
|
60
|
-
changeset: {
|
|
32
|
+
changeset: expect.objectContaining({
|
|
61
33
|
foo: 'new value',
|
|
62
34
|
_version: 1
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('should define `id` as readonly', async () => {
|
|
68
|
-
const origin = fixtures.state()
|
|
69
|
-
const entity = new Entity(fixtures.schema, origin)
|
|
70
|
-
const state = entity.get()
|
|
71
|
-
|
|
72
|
-
expect(() => (state.id = 1)).toThrow('assign to read only property')
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('should seal id', async () => {
|
|
76
|
-
const origin = fixtures.state()
|
|
77
|
-
const entity = new Entity(fixtures.schema, origin)
|
|
78
|
-
const state = entity.get()
|
|
79
|
-
const redefine = () => Object.defineProperty(state, 'id', { writable: true })
|
|
80
|
-
|
|
81
|
-
expect(redefine).toThrow('redefine property')
|
|
35
|
+
})
|
|
36
|
+
}))
|
|
82
37
|
})
|
package/types/bindings.d.ts
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import * as _core from './index'
|
|
2
2
|
|
|
3
|
-
declare namespace toa.core.bindings{
|
|
3
|
+
declare namespace toa.core.bindings {
|
|
4
4
|
|
|
5
5
|
type Properties = {
|
|
6
6
|
async?: boolean
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
interface Consumer extends _core.Connector{
|
|
9
|
+
interface Consumer extends _core.Connector {
|
|
10
10
|
request (request: Request): Promise<_core.Reply>
|
|
11
|
+
|
|
12
|
+
task (request: Request): Promise<void>
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
interface Emitter extends _core.Connector{
|
|
15
|
+
interface Emitter extends _core.Connector {
|
|
14
16
|
emit (message: _core.Message): Promise<void>
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
interface Broadcast<L> extends _core.Connector{
|
|
19
|
+
interface Broadcast<L> extends _core.Connector {
|
|
18
20
|
transmit<T> (label: L, payload: T): Promise<void>
|
|
19
21
|
|
|
20
22
|
receive<T> (label: L, callback: (payload: T) => void | Promise<void>): Promise<void>
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
interface Factory{
|
|
25
|
+
interface Factory {
|
|
24
26
|
producer? (locator: _core.Locator, endpoints: Array<string>, producer: _core.Component): _core.Connector
|
|
25
27
|
|
|
26
28
|
consumer? (locator: _core.Locator, endpoint: string): Consumer
|
package/types/component.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Connector } from './connector'
|
|
2
2
|
import { Locator } from './locator'
|
|
3
3
|
import { Request } from './request'
|
|
4
|
+
import { Operation } from './operations'
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
+
export class Component extends Connector {
|
|
6
7
|
locator: Locator
|
|
7
8
|
|
|
9
|
+
constructor (locator: Locator, operations: Record<string, Operation>)
|
|
10
|
+
|
|
8
11
|
invoke<T = any> (endpoint: string, request: Request): Promise<T>
|
|
9
12
|
}
|
package/types/extensions.d.ts
CHANGED
|
@@ -3,9 +3,10 @@ import * as _component from './component'
|
|
|
3
3
|
import * as _context from './context'
|
|
4
4
|
import * as _storages from './storages'
|
|
5
5
|
import * as _bindings from './bindings'
|
|
6
|
+
import { Manifest } from '@toa.io/norm'
|
|
6
7
|
|
|
7
|
-
export interface Factory{
|
|
8
|
-
tenant? (locator: _core.Locator, manifest: object): _core.Connector
|
|
8
|
+
export interface Factory {
|
|
9
|
+
tenant? (locator: _core.Locator, manifest: object, component: Manifest): _core.Connector
|
|
9
10
|
|
|
10
11
|
aspect? (locator: _core.Locator, manifest: object | null): Aspect | Aspect[]
|
|
11
12
|
|
|
@@ -22,7 +23,7 @@ export interface Factory{
|
|
|
22
23
|
receiver? (receiver: _core.Receiver, locator: _core.Locator): _core.Receiver
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
export interface Aspect extends _core.Connector{
|
|
26
|
+
export interface Aspect extends _core.Connector {
|
|
26
27
|
name: string
|
|
27
28
|
|
|
28
29
|
invoke (...args: any[]): any
|
package/types/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * as bridges from './bridges'
|
|
|
5
5
|
export * as operations from './operations'
|
|
6
6
|
|
|
7
7
|
export type { Component } from './component'
|
|
8
|
+
export type { Remote } from './remote'
|
|
8
9
|
export { Connector } from './connector'
|
|
9
10
|
export type { Context } from './context'
|
|
10
11
|
export type { Exception } from './exception'
|
package/types/locator.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export class Locator
|
|
1
|
+
export class Locator{
|
|
2
2
|
public readonly name: string
|
|
3
3
|
public readonly namespace: string
|
|
4
4
|
|
|
5
5
|
public readonly id: string
|
|
6
6
|
public readonly label: string
|
|
7
7
|
public readonly uppercase: string
|
|
8
|
+
public readonly lowercase: string
|
|
8
9
|
|
|
9
10
|
constructor (name: string, namespace?: string)
|
|
10
11
|
|
package/types/operations.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
import { Request } from './request'
|
|
2
|
+
|
|
1
3
|
export type type = 'transition' | 'observation' | 'assignment' | 'computation' | 'effect'
|
|
2
4
|
export type scope = 'object' | 'objects' | 'changeset'
|
|
5
|
+
|
|
6
|
+
export class Operation {
|
|
7
|
+
invoke<T = any> (request: Request): Promise<T>
|
|
8
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Component } from './component'
|
|
2
|
+
|
|
3
|
+
export class Remote extends Component {
|
|
4
|
+
explain (endpoint: string): Promise<Explanation>
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface Explanation {
|
|
8
|
+
input: Schema | null
|
|
9
|
+
output: Schema | null
|
|
10
|
+
errors?: string[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface Schema {
|
|
14
|
+
type: string
|
|
15
|
+
properties: {
|
|
16
|
+
[key: string]: Schema
|
|
17
|
+
}
|
|
18
|
+
}
|