@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/exceptions.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { swap } = require('@toa.io/generic')
|
|
4
|
-
|
|
5
|
-
const codes = {
|
|
6
|
-
System: 0,
|
|
7
|
-
NotImplemented: 10,
|
|
8
|
-
|
|
9
|
-
Contract: 200,
|
|
10
|
-
RequestSyntax: 201,
|
|
11
|
-
RequestContract: 202,
|
|
12
|
-
RequestConflict: 203,
|
|
13
|
-
ResponseContract: 211,
|
|
14
|
-
EntityContract: 212,
|
|
15
|
-
QuerySyntax: 221,
|
|
16
|
-
|
|
17
|
-
State: 300,
|
|
18
|
-
StateNotFound: 302,
|
|
19
|
-
StatePrecondition: 303,
|
|
20
|
-
StateConcurrency: 304,
|
|
21
|
-
StateInitialization: 305,
|
|
22
|
-
Duplicate: 306,
|
|
23
|
-
|
|
24
|
-
Communication: 400,
|
|
25
|
-
Transmission: 401
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @implements {toa.core.Exception}
|
|
30
|
-
*/
|
|
31
|
-
class Exception {
|
|
32
|
-
code
|
|
33
|
-
message
|
|
34
|
-
|
|
35
|
-
constructor (code, message) {
|
|
36
|
-
this.code = code
|
|
37
|
-
this.message = message
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
class SystemException extends Exception {
|
|
42
|
-
stack
|
|
43
|
-
|
|
44
|
-
constructor (error) {
|
|
45
|
-
super(codes.System, error.message)
|
|
46
|
-
|
|
47
|
-
if (error.stack !== undefined) this.stack = error.stack
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
class ContractException extends Exception {
|
|
52
|
-
keyword
|
|
53
|
-
property
|
|
54
|
-
schema
|
|
55
|
-
path
|
|
56
|
-
|
|
57
|
-
constructor (code, error) {
|
|
58
|
-
super(code || codes.Contract, error.message)
|
|
59
|
-
|
|
60
|
-
this.keyword = error.keyword
|
|
61
|
-
this.property = error.property
|
|
62
|
-
this.schema = error.schema
|
|
63
|
-
this.path = error.path
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
class RequestContractException extends ContractException {
|
|
68
|
-
constructor (error) { super(codes.RequestContract, error) }
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
class ResponseContractException extends ContractException {
|
|
72
|
-
constructor (error) { super(codes.ResponseContract, error) }
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
class EntityContractException extends ContractException {
|
|
76
|
-
constructor (error) { super(codes.EntityContract, error) }
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// #region exports
|
|
80
|
-
exports.Exception = Exception
|
|
81
|
-
exports.SystemException = SystemException
|
|
82
|
-
exports.RequestContractException = RequestContractException
|
|
83
|
-
exports.ResponseContractException = ResponseContractException
|
|
84
|
-
exports.EntityContractException = EntityContractException
|
|
85
|
-
|
|
86
|
-
for (const [name, code] of Object.entries(codes)) {
|
|
87
|
-
const classname = name + 'Exception'
|
|
88
|
-
|
|
89
|
-
if (exports[classname] === undefined) {
|
|
90
|
-
exports[classname] = class extends Exception {
|
|
91
|
-
constructor (message) {
|
|
92
|
-
super(code, message ?? classname)
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
exports.codes = codes
|
|
99
|
-
exports.names = swap(codes)
|
|
100
|
-
// #endregion
|
package/src/exposition.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Connector } = require('./connector')
|
|
4
|
-
|
|
5
|
-
class Exposition extends Connector {
|
|
6
|
-
locator
|
|
7
|
-
|
|
8
|
-
#exposition
|
|
9
|
-
|
|
10
|
-
constructor (locator, manifest) {
|
|
11
|
-
super()
|
|
12
|
-
|
|
13
|
-
this.locator = locator
|
|
14
|
-
this.#exposition = expose(manifest)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async invoke () {
|
|
18
|
-
return { output: this.#exposition }
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const expose = (manifest) => {
|
|
23
|
-
const { namespace, name, operations, events, entity } = manifest
|
|
24
|
-
return { namespace, name, operations, events, entity }
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
exports.Exposition = Exposition
|
package/src/index.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
const { Assignment } = require('./assignment')
|
|
2
|
-
const { Call } = require('./call')
|
|
3
|
-
const { Cascade } = require('./cascade')
|
|
4
|
-
const { Composition } = require('./composition')
|
|
5
|
-
const { Connector } = require('./connector')
|
|
6
|
-
const { Context } = require('./context')
|
|
7
|
-
const { Discovery } = require('./discovery')
|
|
8
|
-
const { Emission } = require('./emission')
|
|
9
|
-
const { Event } = require('./event')
|
|
10
|
-
const { Exposition } = require('./exposition')
|
|
11
|
-
const { Locator } = require('./locator')
|
|
12
|
-
const { Observation } = require('./observation')
|
|
13
|
-
const { Operation } = require('./operation')
|
|
14
|
-
const { Query } = require('./query')
|
|
15
|
-
const { Receiver } = require('./receiver')
|
|
16
|
-
const { Reflection } = require('./reflection')
|
|
17
|
-
const { Remote } = require('./remote')
|
|
18
|
-
const { Component } = require('./component')
|
|
19
|
-
const { State } = require('./state')
|
|
20
|
-
const { Transition } = require('./transition')
|
|
21
|
-
const { Transmission } = require('./transmission')
|
|
22
|
-
|
|
23
|
-
exports.entities = require('./entities')
|
|
24
|
-
exports.exceptions = require('./exceptions')
|
|
25
|
-
exports.contract = require('./contract')
|
|
26
|
-
|
|
27
|
-
exports.Assignment = Assignment
|
|
28
|
-
exports.Call = Call
|
|
29
|
-
exports.Cascade = Cascade
|
|
30
|
-
exports.Component = Component
|
|
31
|
-
exports.Composition = Composition
|
|
32
|
-
exports.Connector = Connector
|
|
33
|
-
exports.Context = Context
|
|
34
|
-
exports.Discovery = Discovery
|
|
35
|
-
exports.Emission = Emission
|
|
36
|
-
exports.Event = Event
|
|
37
|
-
exports.Exposition = Exposition
|
|
38
|
-
exports.Locator = Locator
|
|
39
|
-
exports.Observation = Observation
|
|
40
|
-
exports.Operation = Operation
|
|
41
|
-
exports.Query = Query
|
|
42
|
-
exports.Receiver = Receiver
|
|
43
|
-
exports.Reflection = Reflection
|
|
44
|
-
exports.Remote = Remote
|
|
45
|
-
exports.State = State
|
|
46
|
-
exports.Transition = Transition
|
|
47
|
-
exports.Transmission = Transmission
|
package/src/locator.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { concat } = require('@toa.io/generic')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @implements {toa.core.Locator}
|
|
7
|
-
*/
|
|
8
|
-
class Locator {
|
|
9
|
-
name
|
|
10
|
-
namespace
|
|
11
|
-
|
|
12
|
-
id
|
|
13
|
-
label
|
|
14
|
-
uppercase
|
|
15
|
-
lowercase
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @param {string} name
|
|
19
|
-
* @param {string} [namespace]
|
|
20
|
-
*/
|
|
21
|
-
constructor (name, namespace) {
|
|
22
|
-
if (name === undefined) throw new TypeError('Locator name must be defined')
|
|
23
|
-
|
|
24
|
-
this.name = name
|
|
25
|
-
this.namespace = namespace
|
|
26
|
-
|
|
27
|
-
this.id = concat(namespace, '.') + name
|
|
28
|
-
this.label = (concat(namespace, '-') + name).toLowerCase()
|
|
29
|
-
this.uppercase = (concat(namespace, '_') + name).toUpperCase()
|
|
30
|
-
this.lowercase = (concat(namespace, '_') + name).toLowerCase()
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
hostname (prefix) {
|
|
34
|
-
return concat(prefix?.toLowerCase(), '-') + this.label
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @param {string} string
|
|
39
|
-
* @returns {Locator}
|
|
40
|
-
*/
|
|
41
|
-
static parse (string) {
|
|
42
|
-
const [namespace, name] = string.split(DOT)
|
|
43
|
-
|
|
44
|
-
if (name === undefined) {
|
|
45
|
-
return new Locator(namespace)
|
|
46
|
-
} else {
|
|
47
|
-
return new Locator(name, namespace)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const DOT = '.'
|
|
53
|
-
|
|
54
|
-
exports.Locator = Locator
|
package/src/observation.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Operation } = require('./operation')
|
|
4
|
-
|
|
5
|
-
class Observation extends Operation {
|
|
6
|
-
async acquire (store) {
|
|
7
|
-
const scope = await this.query(store.request.query)
|
|
8
|
-
const state = scope === null ? null : scope.get()
|
|
9
|
-
|
|
10
|
-
store.scope = scope
|
|
11
|
-
store.state = state
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async run (store) {
|
|
15
|
-
if (store.scope === null) store.reply = null
|
|
16
|
-
else await super.run(store)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
exports.Observation = Observation
|
package/src/operation.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Connector } = require('./connector')
|
|
4
|
-
const { SystemException } = require('./exceptions')
|
|
5
|
-
|
|
6
|
-
class Operation extends Connector {
|
|
7
|
-
scope
|
|
8
|
-
|
|
9
|
-
#cascade
|
|
10
|
-
#contracts
|
|
11
|
-
#query
|
|
12
|
-
#scope
|
|
13
|
-
|
|
14
|
-
constructor (cascade, scope, contracts, query, definition) {
|
|
15
|
-
super()
|
|
16
|
-
|
|
17
|
-
this.scope = scope
|
|
18
|
-
|
|
19
|
-
this.#cascade = cascade
|
|
20
|
-
this.#contracts = contracts
|
|
21
|
-
this.#query = query
|
|
22
|
-
this.#scope = definition.scope
|
|
23
|
-
|
|
24
|
-
this.depends(cascade)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async invoke (request) {
|
|
28
|
-
try {
|
|
29
|
-
if (request.authentic !== true) this.#contracts.request.fit(request)
|
|
30
|
-
if ('query' in request) request.query = this.#query.parse(request.query)
|
|
31
|
-
|
|
32
|
-
const store = { request }
|
|
33
|
-
|
|
34
|
-
return await this.process(store)
|
|
35
|
-
} catch (e) {
|
|
36
|
-
const exception = e instanceof Error ? new SystemException(e) : e
|
|
37
|
-
|
|
38
|
-
return { exception }
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async process (store) {
|
|
43
|
-
await this.acquire(store)
|
|
44
|
-
await this.run(store)
|
|
45
|
-
await this.commit(store)
|
|
46
|
-
|
|
47
|
-
return store.reply
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async acquire () {}
|
|
51
|
-
|
|
52
|
-
async run (store) {
|
|
53
|
-
const { request, state } = store
|
|
54
|
-
// noinspection UnnecessaryLocalVariableJS
|
|
55
|
-
const reply = await this.#cascade.run(request.input, state) || {}
|
|
56
|
-
|
|
57
|
-
// this.#contracts.reply.fit(reply)
|
|
58
|
-
|
|
59
|
-
store.reply = reply
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async commit () {}
|
|
63
|
-
|
|
64
|
-
async query (query) {
|
|
65
|
-
return this.scope[this.#scope](query)
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
exports.Operation = Operation
|
package/src/query/criteria.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { parse } = require('@rsql/parser')
|
|
4
|
-
const { QuerySyntaxException } = require('../exceptions')
|
|
5
|
-
|
|
6
|
-
const criteria = (criteria, properties) => {
|
|
7
|
-
let ast
|
|
8
|
-
|
|
9
|
-
try {
|
|
10
|
-
ast = parse(criteria)
|
|
11
|
-
} catch (e) {
|
|
12
|
-
throw new QuerySyntaxException(e.message)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (properties !== undefined) coerce(ast, properties)
|
|
16
|
-
|
|
17
|
-
return ast
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const coerce = (node, properties) => {
|
|
21
|
-
if (node.type === 'COMPARISON' && node.left?.type === 'SELECTOR' && node.right?.type === 'VALUE') {
|
|
22
|
-
const property = properties[node.left.selector]
|
|
23
|
-
|
|
24
|
-
if (property === undefined) {
|
|
25
|
-
throw new QuerySyntaxException(`Criteria selector '${node.left.selector}' is not defined`)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (COERCE[property.type] !== undefined) { node.right.value = COERCE[property.type](node.right.value) }
|
|
29
|
-
} else {
|
|
30
|
-
if (node.left !== undefined) coerce(node.left, properties)
|
|
31
|
-
if (node.right !== undefined) coerce(node.right, properties)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const COERCE = {
|
|
36
|
-
number: Number.parseFloat,
|
|
37
|
-
integer: Number.parseInt,
|
|
38
|
-
boolean: (value) => value === 'true'
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
exports.criteria = criteria
|
package/src/query/options.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { QuerySyntaxException } = require('../exceptions')
|
|
4
|
-
|
|
5
|
-
const options = (options, properties, system) => {
|
|
6
|
-
if (options.sort !== undefined) options.sort = sort(options.sort, properties)
|
|
7
|
-
|
|
8
|
-
if (options.projection !== undefined) projection(options.projection, properties)
|
|
9
|
-
|
|
10
|
-
return options
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const sort = (sort, properties) => {
|
|
14
|
-
const result = []
|
|
15
|
-
|
|
16
|
-
for (const sorting of sort) {
|
|
17
|
-
const [property, direction] = sorting.split(':')
|
|
18
|
-
|
|
19
|
-
if (properties[property] === undefined) {
|
|
20
|
-
throw new QuerySyntaxException(`Sort property '${property}' is not defined`)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
result.push([property, direction || 'asc'])
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return result
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const projection = (projection, properties) => {
|
|
30
|
-
for (const property of projection) {
|
|
31
|
-
if (properties[property] === undefined) {
|
|
32
|
-
throw new QuerySyntaxException(`Projection property '${property}' is not defined`)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (projection.includes('_version') === false)
|
|
37
|
-
projection.push('_version')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
exports.options = options
|
package/src/query.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { empty } = require('@toa.io/generic')
|
|
4
|
-
const parse = { ...require('./query/criteria'), ...require('./query/options') }
|
|
5
|
-
|
|
6
|
-
class Query {
|
|
7
|
-
#properties
|
|
8
|
-
#system
|
|
9
|
-
|
|
10
|
-
constructor (properties) {
|
|
11
|
-
this.#properties = properties
|
|
12
|
-
this.#system = Object.keys(properties).filter((key) => properties[key].system === true)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param {toa.core.request.Query} query
|
|
17
|
-
* @returns {toa.core.storages.Query}
|
|
18
|
-
*/
|
|
19
|
-
parse (query) {
|
|
20
|
-
/** @type {toa.core.storages.Query} */
|
|
21
|
-
const result = {}
|
|
22
|
-
const { id, version, criteria, ...rest } = query
|
|
23
|
-
|
|
24
|
-
const options = this.#options(rest)
|
|
25
|
-
|
|
26
|
-
if (id !== undefined) result.id = id
|
|
27
|
-
if (version !== undefined) result.version = version
|
|
28
|
-
if (criteria !== undefined) result.criteria = parse.criteria(criteria, this.#properties)
|
|
29
|
-
if (options !== undefined) result.options = options
|
|
30
|
-
|
|
31
|
-
return result
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
#options (options) {
|
|
35
|
-
if (empty(options)) return
|
|
36
|
-
|
|
37
|
-
return parse.options(options, this.#properties, this.#system)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
exports.Query = Query
|
package/src/receiver.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { add } = require('@toa.io/generic')
|
|
4
|
-
const { Connector } = require('./connector')
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @implements {toa.core.Receiver}
|
|
8
|
-
*/
|
|
9
|
-
class Receiver extends Connector {
|
|
10
|
-
/** @type {boolean} */
|
|
11
|
-
#conditioned
|
|
12
|
-
|
|
13
|
-
/** @type {boolean} */
|
|
14
|
-
#adaptive
|
|
15
|
-
|
|
16
|
-
/** @type {string} */
|
|
17
|
-
#endpoint
|
|
18
|
-
|
|
19
|
-
/** @type {unknown[]} */
|
|
20
|
-
#arguments
|
|
21
|
-
|
|
22
|
-
#local
|
|
23
|
-
|
|
24
|
-
#bridge
|
|
25
|
-
|
|
26
|
-
constructor (definition, local, bridge) {
|
|
27
|
-
super()
|
|
28
|
-
|
|
29
|
-
const { conditioned, adaptive, operation } = definition
|
|
30
|
-
|
|
31
|
-
this.#conditioned = conditioned
|
|
32
|
-
this.#adaptive = adaptive
|
|
33
|
-
this.#endpoint = operation
|
|
34
|
-
this.#arguments = definition.arguments
|
|
35
|
-
|
|
36
|
-
this.#local = local
|
|
37
|
-
this.#bridge = bridge
|
|
38
|
-
|
|
39
|
-
this.depends(local)
|
|
40
|
-
if (bridge !== undefined) this.depends(bridge)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** @hot */
|
|
44
|
-
async receive (message) {
|
|
45
|
-
const { payload, ...extensions } = message
|
|
46
|
-
|
|
47
|
-
if (this.#conditioned && await this.#bridge.condition(payload) === false) return
|
|
48
|
-
|
|
49
|
-
const request = await this.#request(payload)
|
|
50
|
-
|
|
51
|
-
add(request, extensions)
|
|
52
|
-
|
|
53
|
-
await this.#local.invoke(this.#endpoint, request)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async #request (payload) {
|
|
57
|
-
return this.#adaptive ? await this.#bridge.request(payload, ...(this.#arguments ?? [])) : { input: payload }
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
exports.Receiver = Receiver
|
package/src/reflection.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Connector } = require('./connector')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @implements {toa.core.Reflection}
|
|
7
|
-
*/
|
|
8
|
-
class Reflection extends Connector {
|
|
9
|
-
/** @type {toa.core.reflection.Source} */
|
|
10
|
-
#source
|
|
11
|
-
|
|
12
|
-
value
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @param {toa.core.reflection.Source} source
|
|
16
|
-
*/
|
|
17
|
-
constructor (source) {
|
|
18
|
-
super()
|
|
19
|
-
|
|
20
|
-
this.#source = source
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async open () {
|
|
24
|
-
this.value = await this.#source()
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
exports.Reflection = Reflection
|
package/src/remote.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { console } = require('@toa.io/console')
|
|
4
|
-
|
|
5
|
-
const { Component } = require('./component')
|
|
6
|
-
|
|
7
|
-
class Remote extends Component {
|
|
8
|
-
async open () {
|
|
9
|
-
console.info(`Remote '${this.locator.id}' connected`)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async dispose () {
|
|
13
|
-
console.info(`Remote '${this.locator.id}' disconnected`)
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
exports.Remote = Remote
|
package/src/state.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { empty } = require('@toa.io/generic')
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
StatePreconditionException,
|
|
7
|
-
StateNotFoundException
|
|
8
|
-
} = require('./exceptions')
|
|
9
|
-
|
|
10
|
-
class State {
|
|
11
|
-
#associated
|
|
12
|
-
#storage
|
|
13
|
-
#entity
|
|
14
|
-
#emission
|
|
15
|
-
|
|
16
|
-
constructor (storage, entity, emission, associated) {
|
|
17
|
-
this.#storage = storage
|
|
18
|
-
this.#entity = entity
|
|
19
|
-
this.#emission = emission
|
|
20
|
-
this.#associated = associated === true
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
init (id) {
|
|
24
|
-
return this.#entity.init(id)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async object (query) {
|
|
28
|
-
const record = await this.#storage.get(query)
|
|
29
|
-
|
|
30
|
-
if (record === null) {
|
|
31
|
-
if (this.#associated && query.id !== undefined && query.version === undefined) {
|
|
32
|
-
return this.init(query.id)
|
|
33
|
-
} else if (query.version !== undefined) throw new StatePreconditionException()
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (record === null) {
|
|
37
|
-
return null
|
|
38
|
-
} else {
|
|
39
|
-
return this.#entity.object(record)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async objects (query) {
|
|
44
|
-
const recordset = await this.#storage.find(query)
|
|
45
|
-
|
|
46
|
-
return this.#entity.objects(recordset)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
changeset (query) {
|
|
50
|
-
return this.#entity.changeset(query)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
none () {
|
|
54
|
-
return null
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async commit (state) {
|
|
58
|
-
const event = state.event()
|
|
59
|
-
|
|
60
|
-
let ok = true
|
|
61
|
-
|
|
62
|
-
if (!empty(event.changeset)) {
|
|
63
|
-
const object = state.get()
|
|
64
|
-
|
|
65
|
-
ok = await this.#storage.store(object)
|
|
66
|
-
|
|
67
|
-
// #20
|
|
68
|
-
if (ok === true) {
|
|
69
|
-
await this.#emission.emit(event)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return ok
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async apply (state) {
|
|
77
|
-
const changeset = state.export()
|
|
78
|
-
|
|
79
|
-
const result = await this.#storage.upsert(state.query, changeset)
|
|
80
|
-
|
|
81
|
-
if (result === null) {
|
|
82
|
-
if (state.query.version !== undefined) {
|
|
83
|
-
throw new StatePreconditionException()
|
|
84
|
-
} else {
|
|
85
|
-
throw new StateNotFoundException()
|
|
86
|
-
}
|
|
87
|
-
} else {
|
|
88
|
-
// same as above
|
|
89
|
-
await this.#emission.emit({
|
|
90
|
-
changeset,
|
|
91
|
-
state: result
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return result
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
exports.State = State
|