@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/src/connector.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { console } = require('@toa.io/console')
|
|
4
|
-
const { newid } = require('@toa.io/generic')
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Abstract connections hierarchy
|
|
8
|
-
* @implements {toa.core.Connector}
|
|
9
|
-
*/
|
|
10
|
-
class Connector {
|
|
11
|
-
/** @type {Array<Connector>} */
|
|
12
|
-
#dependencies = []
|
|
13
|
-
|
|
14
|
-
/** @type {Array<Connector>} */
|
|
15
|
-
#links = []
|
|
16
|
-
|
|
17
|
-
/** @type {Promise} */
|
|
18
|
-
#connecting
|
|
19
|
-
|
|
20
|
-
/** @type {Promise} */
|
|
21
|
-
#disconnecting
|
|
22
|
-
|
|
23
|
-
/** @type {string} */
|
|
24
|
-
id
|
|
25
|
-
/** @type {boolean} */
|
|
26
|
-
connected = false
|
|
27
|
-
|
|
28
|
-
constructor () {
|
|
29
|
-
this.id = this.constructor.name + '#' + newid().substring(0, 8)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Creates a dependency and backlink with another Connector or a set of Connectors
|
|
34
|
-
*
|
|
35
|
-
* See .connect() and .disconnect()
|
|
36
|
-
*
|
|
37
|
-
* @param connector {Connector | any | Array<Connector | any>}
|
|
38
|
-
* @returns {Connector}
|
|
39
|
-
*/
|
|
40
|
-
depends (connector) {
|
|
41
|
-
/** @type {Connector} */
|
|
42
|
-
let next
|
|
43
|
-
|
|
44
|
-
if (connector instanceof Array) {
|
|
45
|
-
if (connector.length === 0) throw new Error('Connectors array must not be empty')
|
|
46
|
-
|
|
47
|
-
if (connector.length > 1) {
|
|
48
|
-
next = new Connector()
|
|
49
|
-
|
|
50
|
-
for (const item of connector) {
|
|
51
|
-
this.#dependencies.push(item)
|
|
52
|
-
item.depends(next)
|
|
53
|
-
}
|
|
54
|
-
} else next = connector[0]
|
|
55
|
-
} else next = connector
|
|
56
|
-
|
|
57
|
-
this.#dependencies.push(next)
|
|
58
|
-
next.link(this)
|
|
59
|
-
|
|
60
|
-
return next
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Creates a backlink to another Connector
|
|
65
|
-
*
|
|
66
|
-
* See .connect() and .disconnect()
|
|
67
|
-
*
|
|
68
|
-
* @param connector {Connector}
|
|
69
|
-
* @returns {void}
|
|
70
|
-
*/
|
|
71
|
-
link (connector) {
|
|
72
|
-
this.#links.push(connector)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Connects dependants then self
|
|
77
|
-
*
|
|
78
|
-
* In case of exception disconnects with current connection interruption
|
|
79
|
-
*
|
|
80
|
-
* Method is idempotent
|
|
81
|
-
*
|
|
82
|
-
* @returns {Promise<void>}
|
|
83
|
-
*/
|
|
84
|
-
async connect () {
|
|
85
|
-
if (this.#connecting) return this.#connecting
|
|
86
|
-
|
|
87
|
-
this.#disconnecting = undefined
|
|
88
|
-
|
|
89
|
-
console.debug(`Connecting '${this.id}' with ${this.#dependencies.length} dependencies...`)
|
|
90
|
-
|
|
91
|
-
this.#connecting = (async () => {
|
|
92
|
-
await Promise.all(this.#dependencies.map((connector) => connector.connect()))
|
|
93
|
-
await this.open()
|
|
94
|
-
})()
|
|
95
|
-
|
|
96
|
-
try {
|
|
97
|
-
await this.#connecting
|
|
98
|
-
this.connected = true
|
|
99
|
-
} catch (e) {
|
|
100
|
-
await this.disconnect(true)
|
|
101
|
-
throw e
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
console.debug(`Connector '${this.id}' connected`)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Disconnects self then dependants
|
|
109
|
-
*
|
|
110
|
-
* Does nothing if there are connected linked Connectors
|
|
111
|
-
*
|
|
112
|
-
* Method is idempotent
|
|
113
|
-
*
|
|
114
|
-
* @param [interrupt] {boolean}
|
|
115
|
-
* @returns {Promise<void>}
|
|
116
|
-
*/
|
|
117
|
-
async disconnect (interrupt) {
|
|
118
|
-
if (interrupt !== true) await this.#connecting
|
|
119
|
-
|
|
120
|
-
if (this.#disconnecting) return this.#disconnecting
|
|
121
|
-
|
|
122
|
-
const linked = this.#links.reduce((acc, parent) => acc || parent.connected, false)
|
|
123
|
-
|
|
124
|
-
if (linked && interrupt !== true) return
|
|
125
|
-
|
|
126
|
-
this.connected = false
|
|
127
|
-
this.#connecting = undefined
|
|
128
|
-
|
|
129
|
-
this.#disconnecting = (async () => {
|
|
130
|
-
const start = +new Date()
|
|
131
|
-
|
|
132
|
-
const interval = setInterval(() => {
|
|
133
|
-
const delay = +new Date() - start
|
|
134
|
-
|
|
135
|
-
if (delay > DELAY) console.warn(`Connector ${this.id} still disconnecting (${delay})`)
|
|
136
|
-
}, DELAY)
|
|
137
|
-
|
|
138
|
-
if (interrupt !== true) await this.close()
|
|
139
|
-
|
|
140
|
-
clearInterval(interval)
|
|
141
|
-
|
|
142
|
-
await Promise.all(this.#dependencies.map(connector => connector.disconnect()))
|
|
143
|
-
|
|
144
|
-
await this.dispose()
|
|
145
|
-
})()
|
|
146
|
-
|
|
147
|
-
await this.#disconnecting
|
|
148
|
-
|
|
149
|
-
console.debug(`Connector '${this.id}' disconnected`)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
async reconnect () {
|
|
153
|
-
await this.disconnect()
|
|
154
|
-
await this.connect()
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
debug (node = {}) {
|
|
158
|
-
node[this.id] = { connected: this.connected }
|
|
159
|
-
|
|
160
|
-
if (this.#dependencies.length > 0) for (const connector of this.#dependencies) connector.debug?.(node[this.id])
|
|
161
|
-
|
|
162
|
-
return node
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Called on connection
|
|
167
|
-
*/
|
|
168
|
-
async open () {}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Called on disconnection
|
|
172
|
-
*/
|
|
173
|
-
async close () {}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Called after self and dependants disconnection is complete
|
|
177
|
-
*/
|
|
178
|
-
async dispose () {}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const DELAY = 5000
|
|
182
|
-
|
|
183
|
-
exports.Connector = Connector
|
package/src/context.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Connector } = require('./connector')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @implements {toa.core.Context}
|
|
7
|
-
*/
|
|
8
|
-
class Context extends Connector {
|
|
9
|
-
aspects
|
|
10
|
-
|
|
11
|
-
#local
|
|
12
|
-
#discover
|
|
13
|
-
#remotes = {}
|
|
14
|
-
|
|
15
|
-
constructor (local, discover, aspects = []) {
|
|
16
|
-
super()
|
|
17
|
-
|
|
18
|
-
this.aspects = aspects
|
|
19
|
-
|
|
20
|
-
this.#local = local
|
|
21
|
-
this.#discover = discover
|
|
22
|
-
|
|
23
|
-
this.depends(local)
|
|
24
|
-
|
|
25
|
-
if (aspects.length > 0) this.depends(aspects)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async apply (endpoint, request) {
|
|
29
|
-
return this.#local.invoke(endpoint, request)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async call (namespace, name, endpoint, request) {
|
|
33
|
-
const remote = await this.#remote(namespace, name)
|
|
34
|
-
|
|
35
|
-
return remote.invoke(endpoint, request)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async #remote (namespace, name) {
|
|
39
|
-
const key = namespace + '.' + name
|
|
40
|
-
|
|
41
|
-
this.#remotes[key] ??= this.#connect(namespace, name)
|
|
42
|
-
|
|
43
|
-
return this.#remotes[key]
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async #connect (namespace, name) {
|
|
47
|
-
const remote = await this.#discover(namespace, name)
|
|
48
|
-
|
|
49
|
-
this.depends(remote)
|
|
50
|
-
|
|
51
|
-
return remote
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
exports.Context = Context
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { SystemException } = require('../exceptions')
|
|
4
|
-
|
|
5
|
-
class Conditions {
|
|
6
|
-
#schema
|
|
7
|
-
|
|
8
|
-
constructor (schema) {
|
|
9
|
-
this.#schema = schema
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
fit (value) {
|
|
13
|
-
const error = this.#schema.fit(value)
|
|
14
|
-
|
|
15
|
-
if (error !== null) throw new this.constructor.Exception(error)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static Exception = SystemException
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
exports.Conditions = Conditions
|
package/src/contract/index.js
DELETED
package/src/contract/reply.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const schemas = require('./schemas')
|
|
4
|
-
const { Conditions } = require('./conditions')
|
|
5
|
-
const { ResponseContractException } = require('../exceptions')
|
|
6
|
-
|
|
7
|
-
class Reply extends Conditions {
|
|
8
|
-
static Exception = ResponseContractException
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @returns {toa.schema.JSON}
|
|
12
|
-
*/
|
|
13
|
-
static schema (output, error) {
|
|
14
|
-
const schema = { type: 'object', properties: {}, additionalProperties: false }
|
|
15
|
-
|
|
16
|
-
if (output !== undefined) schema.properties.output = output
|
|
17
|
-
|
|
18
|
-
if (error !== undefined) schema.properties.error = error
|
|
19
|
-
else schema.properties.error = schemas.error
|
|
20
|
-
|
|
21
|
-
return schema
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
exports.Reply = Reply
|
package/src/contract/request.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const schemas = require('./schemas')
|
|
4
|
-
const { RequestContractException } = require('../exceptions')
|
|
5
|
-
const { Conditions } = require('./conditions')
|
|
6
|
-
|
|
7
|
-
class Request extends Conditions {
|
|
8
|
-
static Exception = RequestContractException
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @returns {toa.schema.JSON}
|
|
12
|
-
*/
|
|
13
|
-
static schema (definition, entity) {
|
|
14
|
-
const schema = {
|
|
15
|
-
type: 'object',
|
|
16
|
-
properties: { authentic: { type: 'boolean' } },
|
|
17
|
-
additionalProperties: true
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const required = []
|
|
21
|
-
|
|
22
|
-
if (definition.input !== undefined) {
|
|
23
|
-
schema.properties.input = definition.input
|
|
24
|
-
required.push('input')
|
|
25
|
-
} else {
|
|
26
|
-
schema.properties.input = { type: 'null' }
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (entity === undefined)
|
|
30
|
-
definition.query = false
|
|
31
|
-
|
|
32
|
-
if (definition.query === true)
|
|
33
|
-
required.push('query')
|
|
34
|
-
|
|
35
|
-
if (definition.query === false)
|
|
36
|
-
schema.properties.query = { type: 'null' }
|
|
37
|
-
|
|
38
|
-
if (definition.query !== false) {
|
|
39
|
-
const query = structuredClone(schemas.query)
|
|
40
|
-
|
|
41
|
-
query.properties.id = entity.schema.properties.id
|
|
42
|
-
|
|
43
|
-
if (definition.type === 'observation') {
|
|
44
|
-
delete query.properties.version
|
|
45
|
-
} else {
|
|
46
|
-
delete query.properties.projection
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (definition.type !== 'observation' || definition.scope !== 'objects') {
|
|
50
|
-
delete query.properties.omit
|
|
51
|
-
delete query.properties.limit
|
|
52
|
-
} else {
|
|
53
|
-
if (query.required === undefined) query.required = ['limit']
|
|
54
|
-
else query.required.push('limit')
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
schema.properties.query = query
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (required.length > 0)
|
|
61
|
-
schema.required = required
|
|
62
|
-
|
|
63
|
-
return schema
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
exports.Request = Request
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
type: object
|
|
2
|
-
properties:
|
|
3
|
-
id: { }
|
|
4
|
-
version:
|
|
5
|
-
type: integer
|
|
6
|
-
minimum: 0
|
|
7
|
-
criteria:
|
|
8
|
-
type: string
|
|
9
|
-
omit:
|
|
10
|
-
type: integer
|
|
11
|
-
minimum: 0
|
|
12
|
-
limit:
|
|
13
|
-
type: integer
|
|
14
|
-
minimum: 0
|
|
15
|
-
sort:
|
|
16
|
-
type: array
|
|
17
|
-
uniqueItems: true
|
|
18
|
-
minItems: 1
|
|
19
|
-
items:
|
|
20
|
-
type: string
|
|
21
|
-
pattern: ^\w{1,32}(?::(?:asc|desc))?$
|
|
22
|
-
projection:
|
|
23
|
-
type: array
|
|
24
|
-
uniqueItems: true
|
|
25
|
-
minItems: 1
|
|
26
|
-
items:
|
|
27
|
-
type: string
|
|
28
|
-
not:
|
|
29
|
-
const: id
|
|
30
|
-
additionalProperties: false
|
package/src/discovery.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { console } = require('@toa.io/console')
|
|
4
|
-
const { Connector } = require('./connector')
|
|
5
|
-
|
|
6
|
-
class Discovery extends Connector {
|
|
7
|
-
#lookup
|
|
8
|
-
#lookups
|
|
9
|
-
|
|
10
|
-
constructor (lookup) {
|
|
11
|
-
super()
|
|
12
|
-
|
|
13
|
-
this.#lookup = lookup
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async open () {
|
|
17
|
-
this.#lookups = {}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async lookup (locator) {
|
|
21
|
-
const id = locator.id
|
|
22
|
-
|
|
23
|
-
if (this.#lookups[id] === undefined) {
|
|
24
|
-
this.#lookups[id] = await this.#lookup(locator)
|
|
25
|
-
this.depends(this.#lookups[id])
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
console.debug(`Sending lookup request to '${id}'`)
|
|
29
|
-
|
|
30
|
-
const warning = () => console.warn(`Waiting for lookup response from '${id}'...`)
|
|
31
|
-
const timeout = setTimeout(warning, TIMEOUT)
|
|
32
|
-
|
|
33
|
-
const output = await this.#lookups[id].invoke()
|
|
34
|
-
|
|
35
|
-
console.debug(`Lookup response from '${id}' received`)
|
|
36
|
-
clearTimeout(timeout)
|
|
37
|
-
|
|
38
|
-
return output
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const TIMEOUT = 5000
|
|
43
|
-
|
|
44
|
-
exports.Discovery = Discovery
|
package/src/emission.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Connector } = require('./connector')
|
|
4
|
-
|
|
5
|
-
class Emission extends Connector {
|
|
6
|
-
#events
|
|
7
|
-
|
|
8
|
-
constructor (events) {
|
|
9
|
-
super()
|
|
10
|
-
|
|
11
|
-
this.#events = events
|
|
12
|
-
|
|
13
|
-
this.depends(events)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async emit (event) {
|
|
17
|
-
const emission = this.#events.map((e) => e.emit(event))
|
|
18
|
-
|
|
19
|
-
await Promise.all(emission)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
exports.Emission = Emission
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { EntityContractException } = require('../exceptions')
|
|
4
|
-
|
|
5
|
-
class Changeset {
|
|
6
|
-
/** @type {toa.core.Query} */
|
|
7
|
-
query
|
|
8
|
-
|
|
9
|
-
#schema
|
|
10
|
-
#state
|
|
11
|
-
|
|
12
|
-
constructor (schema, query) {
|
|
13
|
-
this.query = query
|
|
14
|
-
|
|
15
|
-
this.#schema = schema
|
|
16
|
-
this.#state = schema.system()
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get () {
|
|
20
|
-
return this.#state
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
set (value) {
|
|
24
|
-
const error = this.#schema.adapt(value)
|
|
25
|
-
|
|
26
|
-
if (error !== null) throw new EntityContractException(error)
|
|
27
|
-
|
|
28
|
-
value._updated = Date.now()
|
|
29
|
-
|
|
30
|
-
this.#state = value
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export () {
|
|
34
|
-
return this.#state
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
exports.Changeset = Changeset
|
package/src/entities/entity.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { difference, newid } = require('@toa.io/generic')
|
|
4
|
-
const { EntityContractException } = require('../exceptions')
|
|
5
|
-
|
|
6
|
-
class Entity {
|
|
7
|
-
#schema
|
|
8
|
-
#origin = null
|
|
9
|
-
#state
|
|
10
|
-
|
|
11
|
-
constructor (schema, argument) {
|
|
12
|
-
this.#schema = schema
|
|
13
|
-
|
|
14
|
-
if (typeof argument === 'object') {
|
|
15
|
-
const object = structuredClone(argument)
|
|
16
|
-
this.set(object)
|
|
17
|
-
this.#origin = argument
|
|
18
|
-
} else {
|
|
19
|
-
const id = argument === undefined ? newid() : argument
|
|
20
|
-
this.#init(id)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
get () {
|
|
25
|
-
return this.#state
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
set (value) {
|
|
29
|
-
const error = this.#schema.fit(value)
|
|
30
|
-
|
|
31
|
-
if (error !== null)
|
|
32
|
-
throw new EntityContractException(error)
|
|
33
|
-
|
|
34
|
-
this.#set(value)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
event () {
|
|
38
|
-
return {
|
|
39
|
-
origin: this.#origin,
|
|
40
|
-
state: this.#state,
|
|
41
|
-
changeset: this.#origin === null ? this.#state : difference(this.#origin, this.#state),
|
|
42
|
-
trailers: this.#state._trailers
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
#init (id) {
|
|
47
|
-
const value = {
|
|
48
|
-
...this.#schema.defaults({ id }),
|
|
49
|
-
_version: 0,
|
|
50
|
-
_created: Date.now()
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
this.#set(value)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
#set (value) {
|
|
57
|
-
if (!('_trailers' in value))
|
|
58
|
-
Object.defineProperty(value, '_trailers', {
|
|
59
|
-
writable: false,
|
|
60
|
-
configurable: false,
|
|
61
|
-
enumerable: false,
|
|
62
|
-
value: {}
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
if (this.#state !== undefined) {
|
|
66
|
-
value._updated = Date.now()
|
|
67
|
-
value._version++
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
this.#state = value
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
exports.Entity = Entity
|
package/src/entities/factory.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Entity } = require('./entity')
|
|
4
|
-
const { EntitySet } = require('./set')
|
|
5
|
-
const { Changeset } = require('./changeset')
|
|
6
|
-
|
|
7
|
-
class Factory {
|
|
8
|
-
#schema
|
|
9
|
-
|
|
10
|
-
constructor (schema) {
|
|
11
|
-
this.#schema = schema
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
init (id) {
|
|
15
|
-
return new Entity(this.#schema, id)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
object (record) {
|
|
19
|
-
return new Entity(this.#schema, record)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
objects (recordset) {
|
|
23
|
-
const set = recordset.map((record) => this.object(record))
|
|
24
|
-
|
|
25
|
-
return new EntitySet(set)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
changeset (query) {
|
|
29
|
-
return new Changeset(this.#schema, query)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
exports.Factory = Factory
|
package/src/entities/index.js
DELETED
package/src/entities/set.js
DELETED
package/src/event.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Connector } = require('./connector')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @implements {toa.core.Event}
|
|
7
|
-
*/
|
|
8
|
-
class Event extends Connector {
|
|
9
|
-
/** @type {toa.core.bindings.Emitter} */
|
|
10
|
-
#emitter
|
|
11
|
-
#bridge
|
|
12
|
-
#conditioned
|
|
13
|
-
#subjective
|
|
14
|
-
|
|
15
|
-
constructor (definition, emitter, bridge = undefined) {
|
|
16
|
-
super()
|
|
17
|
-
|
|
18
|
-
this.#conditioned = definition.conditioned
|
|
19
|
-
this.#subjective = definition.subjective
|
|
20
|
-
this.#emitter = emitter
|
|
21
|
-
this.#bridge = bridge
|
|
22
|
-
|
|
23
|
-
this.depends(emitter)
|
|
24
|
-
|
|
25
|
-
if (bridge !== undefined) this.depends(bridge)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async emit (event) {
|
|
29
|
-
if (this.#conditioned === false || await this.#bridge.condition(event) === true) {
|
|
30
|
-
const payload = this.#subjective ? await this.#bridge.payload(event) : event.state
|
|
31
|
-
|
|
32
|
-
/** @type {toa.core.Message} */
|
|
33
|
-
const message = { payload }
|
|
34
|
-
|
|
35
|
-
await this.#emitter.emit(message)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
exports.Event = Event
|