@toa.io/core 1.0.0-alpha.29 → 1.0.0-alpha.291
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/CHANGELOG.md +35 -0
- package/package.json +22 -12
- package/source/assignment.ts +27 -0
- package/source/call.ts +63 -0
- package/source/cascade.ts +32 -0
- package/source/component.ts +83 -0
- package/source/composition.ts +27 -0
- package/source/connector.ts +217 -0
- package/source/context.ts +68 -0
- package/source/contract/contract.ts +23 -0
- package/source/contract/index.ts +2 -0
- package/source/contract/reply.ts +56 -0
- package/source/contract/request.ts +140 -0
- package/source/contract/schemas.ts +39 -0
- package/source/discovery.ts +53 -0
- package/source/effect.ts +14 -0
- package/source/emission.ts +21 -0
- package/source/entities/changeset.ts +37 -0
- package/source/entities/entity.ts +137 -0
- package/source/entities/factory.ts +52 -0
- package/source/entities/index.ts +4 -0
- package/source/entities/newid.ts +9 -0
- package/source/entities/set.ts +27 -0
- package/source/event.ts +57 -0
- package/source/exceptions.ts +133 -0
- package/source/exposition.ts +33 -0
- package/source/guard.ts +16 -0
- package/source/index.ts +36 -0
- package/source/locator.ts +37 -0
- package/source/observation.ts +16 -0
- package/source/operation.ts +139 -0
- package/source/outbox/index.ts +1 -0
- package/source/outbox/outbox.ts +341 -0
- package/source/query/criteria.ts +90 -0
- package/source/query/options.ts +35 -0
- package/source/query.ts +67 -0
- package/source/receiver.ts +120 -0
- package/source/reflection.ts +20 -0
- package/source/remote.ts +20 -0
- package/source/state.ts +179 -0
- package/source/transition.ts +79 -0
- package/source/transmission.ts +38 -0
- package/source/types/atomicity.ts +63 -0
- package/source/types/bindings.ts +59 -0
- package/source/types/bridges.ts +54 -0
- package/source/types/extensions.ts +89 -0
- package/source/types/index.ts +14 -0
- package/{types/message.d.ts → source/types/message.ts} +2 -0
- package/source/types/operations.ts +31 -0
- package/source/types/outbox.ts +35 -0
- package/source/types/receiver.ts +10 -0
- package/source/types/request.ts +54 -0
- package/source/types/state.ts +9 -0
- package/source/types/storages.ts +134 -0
- package/source/unmanaged.ts +8 -0
- package/test/call.fixtures.js +10 -12
- package/test/call.test.js +42 -9
- package/test/component.fixtures.js +5 -8
- package/test/component.test.js +27 -10
- package/test/connector.fixtures.js +29 -13
- package/test/connector.test.js +128 -38
- package/test/context.fixtures.js +8 -12
- package/test/context.test.js +19 -8
- package/test/contract/conditions.test.js +15 -9
- package/test/contract/contract.fixtures.js +11 -16
- package/test/contract/request.test.js +130 -46
- package/test/discovery.test.js +71 -0
- package/test/emission.fixtures.js +6 -10
- package/test/emission.test.js +37 -12
- package/test/entities/entity.fixtures.js +11 -16
- package/test/entities/entity.test.js +105 -50
- package/test/entities/factory.fixtures.js +26 -13
- package/test/entities/factory.test.js +68 -17
- package/test/entities/set.fixtures.js +6 -8
- package/test/entities/set.test.js +6 -5
- package/test/event.fixtures.js +9 -14
- package/test/event.test.js +78 -34
- package/test/locator.test.js +32 -25
- package/test/outbox.test.js +202 -0
- package/test/query.fixtures.js +1 -5
- package/test/query.test.js +111 -14
- package/test/receiver.fixtures.js +9 -12
- package/test/receiver.test.js +80 -31
- package/test/reflection.test.js +9 -8
- package/test/state.fixtures.js +33 -31
- package/test/state.test.js +135 -19
- package/test/transmission.fixtures.js +4 -6
- package/test/transmission.test.js +47 -16
- package/transpiled/assignment.d.ts +6 -0
- package/transpiled/assignment.js +20 -0
- package/transpiled/assignment.js.map +1 -0
- package/transpiled/call.d.ts +10 -0
- package/transpiled/call.js +52 -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 +61 -0
- package/transpiled/component.js.map +1 -0
- package/transpiled/composition.d.ts +6 -0
- package/transpiled/composition.js +23 -0
- package/transpiled/composition.js.map +1 -0
- package/transpiled/connector.d.ts +47 -0
- package/transpiled/connector.js +185 -0
- package/transpiled/connector.js.map +1 -0
- package/transpiled/context.d.ts +18 -0
- package/transpiled/context.js +42 -0
- package/transpiled/context.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 +2 -0
- package/transpiled/contract/index.js +3 -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 +29 -0
- package/transpiled/contract/request.js +103 -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/discovery.d.ts +12 -0
- package/transpiled/discovery.js +34 -0
- package/transpiled/discovery.js.map +1 -0
- package/transpiled/effect.d.ts +5 -0
- package/transpiled/effect.js +11 -0
- package/transpiled/effect.js.map +1 -0
- package/transpiled/emission.d.ts +8 -0
- package/transpiled/emission.js +14 -0
- package/transpiled/emission.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 +109 -0
- package/transpiled/entities/entity.js.map +1 -0
- package/transpiled/entities/factory.d.ts +22 -0
- package/transpiled/entities/factory.js +34 -0
- package/transpiled/entities/factory.js.map +1 -0
- package/transpiled/entities/index.d.ts +4 -0
- package/transpiled/entities/index.js +5 -0
- package/transpiled/entities/index.js.map +1 -0
- package/transpiled/entities/newid.d.ts +1 -0
- package/transpiled/entities/newid.js +7 -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 +38 -0
- package/transpiled/event.js.map +1 -0
- package/transpiled/exceptions.d.ts +61 -0
- package/transpiled/exceptions.js +93 -0
- package/transpiled/exceptions.js.map +1 -0
- package/transpiled/exposition.d.ts +18 -0
- package/transpiled/exposition.js +18 -0
- package/transpiled/exposition.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/index.d.ts +35 -0
- package/transpiled/index.js +29 -0
- package/transpiled/index.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/observation.d.ts +5 -0
- package/transpiled/observation.js +12 -0
- package/transpiled/observation.js.map +1 -0
- package/transpiled/operation.d.ts +49 -0
- package/transpiled/operation.js +78 -0
- package/transpiled/operation.js.map +1 -0
- package/transpiled/outbox/index.d.ts +1 -0
- package/transpiled/outbox/index.js +2 -0
- package/transpiled/outbox/index.js.map +1 -0
- package/transpiled/outbox/outbox.d.ts +46 -0
- package/transpiled/outbox/outbox.js +268 -0
- package/transpiled/outbox/outbox.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 +27 -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 +92 -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 +12 -0
- package/transpiled/remote.js.map +1 -0
- package/transpiled/state.d.ts +33 -0
- package/transpiled/state.js +126 -0
- package/transpiled/state.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 +56 -0
- package/transpiled/types/atomicity.js +2 -0
- package/transpiled/types/atomicity.js.map +1 -0
- package/transpiled/types/bindings.d.ts +42 -0
- package/transpiled/types/bindings.js +2 -0
- package/transpiled/types/bindings.js.map +1 -0
- package/transpiled/types/bridges.d.ts +38 -0
- package/transpiled/types/bridges.js +2 -0
- package/transpiled/types/bridges.js.map +1 -0
- package/transpiled/types/extensions.d.ts +62 -0
- package/transpiled/types/extensions.js +2 -0
- package/transpiled/types/extensions.js.map +1 -0
- package/transpiled/types/index.d.ts +13 -0
- package/transpiled/types/index.js +8 -0
- package/transpiled/types/index.js.map +1 -0
- package/transpiled/types/message.d.ts +5 -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 +28 -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 +55 -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 +111 -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/tsconfig.json +10 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/assignment.js +0 -31
- package/src/call.js +0 -42
- package/src/cascade.js +0 -36
- 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 -43
- package/src/entities/entity.js +0 -73
- 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 -65
- package/src/reflection.js +0 -28
- package/src/remote.js +0 -17
- package/src/state.js +0 -99
- package/src/transition.js +0 -73
- package/src/transmission.js +0 -33
- 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/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
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { console } from 'openspan';
|
|
2
|
+
import { environment } from '@toa.io/generic';
|
|
3
|
+
/** Abstract connections hierarchy */
|
|
4
|
+
export class Connector {
|
|
5
|
+
#dependencies = [];
|
|
6
|
+
#links = [];
|
|
7
|
+
#connecting;
|
|
8
|
+
#disconnecting;
|
|
9
|
+
#discarded = false;
|
|
10
|
+
id;
|
|
11
|
+
connected = false;
|
|
12
|
+
constructor() {
|
|
13
|
+
this.id = this.constructor.name + '#' + Math.random().toString(36).substring(2, 8);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a dependency and backlink with another Connector or a set of Connectors
|
|
17
|
+
*
|
|
18
|
+
* See .connect() and .disconnect()
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
depends(connector) {
|
|
22
|
+
let next;
|
|
23
|
+
if (connector instanceof Array) {
|
|
24
|
+
if (connector.length === 0)
|
|
25
|
+
throw new Error('Connectors array must not be empty');
|
|
26
|
+
if (connector.length > 1) {
|
|
27
|
+
next = new Connector();
|
|
28
|
+
for (const item of connector) {
|
|
29
|
+
this.#dependencies.push(item);
|
|
30
|
+
item.depends(next);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else
|
|
34
|
+
next = connector[0];
|
|
35
|
+
}
|
|
36
|
+
else
|
|
37
|
+
next = connector;
|
|
38
|
+
this.#dependencies.push(next);
|
|
39
|
+
next.link(this);
|
|
40
|
+
// See .#discard()
|
|
41
|
+
if (this.#disconnecting !== undefined)
|
|
42
|
+
next.#discard();
|
|
43
|
+
return next;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Disconnects, now and again if a connection is still to land.
|
|
47
|
+
*
|
|
48
|
+
* A dependency taken on after its dependant was disconnected — a lookup that returns
|
|
49
|
+
* once the teardown walk has gone by — is one nothing is left to take down, as the
|
|
50
|
+
* walk that would have reached it is over. One that stays connected holds open
|
|
51
|
+
* everything it depends on with it: a dependency reads `connected` of every dependant
|
|
52
|
+
* before it closes, and a dependant that is connected for good is a dependency that
|
|
53
|
+
* never closes.
|
|
54
|
+
*/
|
|
55
|
+
#discard() {
|
|
56
|
+
this.#discarded = true;
|
|
57
|
+
// one that is up already, or on its way, is taken down here; one that is not is
|
|
58
|
+
// taken down by the connection when it comes, and until then there is nothing to do
|
|
59
|
+
if (this.#connecting !== undefined)
|
|
60
|
+
void this.#drop();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Creates a backlink to another Connector
|
|
64
|
+
*
|
|
65
|
+
* See .connect() and .disconnect()
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
link(connector) {
|
|
69
|
+
this.#links.push(connector);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Connects dependants then self
|
|
73
|
+
*
|
|
74
|
+
* In case of exception disconnects with current connection interruption
|
|
75
|
+
*
|
|
76
|
+
* Method is idempotent
|
|
77
|
+
*
|
|
78
|
+
*/
|
|
79
|
+
async connect() {
|
|
80
|
+
if (this.#connecting)
|
|
81
|
+
return this.#connecting;
|
|
82
|
+
this.#disconnecting = undefined;
|
|
83
|
+
const work = async () => {
|
|
84
|
+
await Promise.all(this.#dependencies.map((connector) => connector.connect()));
|
|
85
|
+
await this.open();
|
|
86
|
+
};
|
|
87
|
+
// anonymous grouping nodes are not worth a span
|
|
88
|
+
const connecting = TRACE_BOOT && this.constructor.name !== 'Connector'
|
|
89
|
+
? console.span({
|
|
90
|
+
name: `connect ${this.constructor.name}`,
|
|
91
|
+
// a connector that has a locator is named by it; a grouping node has none
|
|
92
|
+
attributes: { id: this.locator?.id ?? this.id }
|
|
93
|
+
}, work)
|
|
94
|
+
: work();
|
|
95
|
+
this.#connecting = connecting;
|
|
96
|
+
try {
|
|
97
|
+
await connecting;
|
|
98
|
+
/*
|
|
99
|
+
* A disconnection that did not wait for this connection emptied `#connecting` to
|
|
100
|
+
* say so. Reporting `connected` now would report it of a connector nothing takes
|
|
101
|
+
* down again — its `#disconnecting` has settled, so a later call returns at once —
|
|
102
|
+
* and what it depends on reads that of every dependant before it closes.
|
|
103
|
+
*/
|
|
104
|
+
if (this.#connecting === connecting)
|
|
105
|
+
this.connected = true;
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
await this.disconnect(true);
|
|
109
|
+
throw e;
|
|
110
|
+
}
|
|
111
|
+
// a connection asked for before this one was discarded, landing after. See .#discard()
|
|
112
|
+
if (this.#discarded)
|
|
113
|
+
await this.#drop();
|
|
114
|
+
}
|
|
115
|
+
/** Disconnects a discarded connector, saying so rather than throwing at whoever is not waiting. */
|
|
116
|
+
async #drop() {
|
|
117
|
+
this.#discarded = false;
|
|
118
|
+
try {
|
|
119
|
+
await this.disconnect();
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.error('Discarded connector failed to disconnect', { id: this.id, error });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Disconnects self then dependants
|
|
127
|
+
*
|
|
128
|
+
* Does nothing if there are connected linked Connectors
|
|
129
|
+
*
|
|
130
|
+
* Method is idempotent
|
|
131
|
+
*
|
|
132
|
+
*/
|
|
133
|
+
async disconnect(interrupt) {
|
|
134
|
+
// a connector that has not finished connecting has nothing to close, and
|
|
135
|
+
// awaiting a connection that may never settle outlives any grace period
|
|
136
|
+
const pending = interrupt === true || this.connected === false;
|
|
137
|
+
if (!pending)
|
|
138
|
+
await this.#connecting;
|
|
139
|
+
if (this.#disconnecting)
|
|
140
|
+
return this.#disconnecting;
|
|
141
|
+
const linked = this.#links.reduce((acc, parent) => acc || parent.connected, false);
|
|
142
|
+
if (linked && interrupt !== true)
|
|
143
|
+
return;
|
|
144
|
+
this.#disconnecting = (async () => {
|
|
145
|
+
const start = +new Date();
|
|
146
|
+
const interval = setInterval(() => {
|
|
147
|
+
const delay = +new Date() - start;
|
|
148
|
+
if (delay > DELAY)
|
|
149
|
+
console.warn(`Connector ${this.id} still disconnecting (${delay})`);
|
|
150
|
+
}, DELAY);
|
|
151
|
+
if (!pending)
|
|
152
|
+
await this.close();
|
|
153
|
+
// said once the closing is done rather than when it starts: a dependant that is
|
|
154
|
+
// still closing is still using what it depends on, and the check above reads this
|
|
155
|
+
// of every dependant. Saying it early lets the first to start tear down a shared
|
|
156
|
+
// dependency under the others.
|
|
157
|
+
this.connected = false;
|
|
158
|
+
this.#connecting = undefined;
|
|
159
|
+
clearInterval(interval);
|
|
160
|
+
await Promise.all(this.#dependencies.map((connector) => connector.disconnect()));
|
|
161
|
+
await this.dispose();
|
|
162
|
+
})();
|
|
163
|
+
await this.#disconnecting;
|
|
164
|
+
}
|
|
165
|
+
async reconnect() {
|
|
166
|
+
await this.disconnect();
|
|
167
|
+
await this.connect();
|
|
168
|
+
}
|
|
169
|
+
debug(node = {}) {
|
|
170
|
+
node[this.id] = { connected: this.connected };
|
|
171
|
+
if (this.#dependencies.length > 0)
|
|
172
|
+
for (const connector of this.#dependencies)
|
|
173
|
+
connector.debug?.(node[this.id]);
|
|
174
|
+
return node;
|
|
175
|
+
}
|
|
176
|
+
/** Called on connection */
|
|
177
|
+
open() { }
|
|
178
|
+
/** Called on disconnection */
|
|
179
|
+
close() { }
|
|
180
|
+
/** Called after self and dependants disconnection is complete */
|
|
181
|
+
dispose() { }
|
|
182
|
+
}
|
|
183
|
+
const DELAY = 5000;
|
|
184
|
+
const TRACE_BOOT = environment.get('TOA_BOOT_TRACE') === '1';
|
|
185
|
+
//# sourceMappingURL=connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector.js","sourceRoot":"","sources":["../source/connector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAG7C,qCAAqC;AACrC,MAAM,OAAO,SAAS;IACpB,aAAa,GAAgB,EAAE,CAAA;IAC/B,MAAM,GAAgB,EAAE,CAAA;IACxB,WAAW,CAA2B;IACtC,cAAc,CAA2B;IACzC,UAAU,GAAY,KAAK,CAAA;IAEX,EAAE,CAAQ;IACnB,SAAS,GAAY,KAAK,CAAA;IAEjC;QACE,IAAI,CAAC,EAAE,GAAG,IAA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|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Connector } from './connector.js';
|
|
2
|
+
import type { Locator } from './locator.js';
|
|
3
|
+
import type { Component } from './component.js';
|
|
4
|
+
import type { Remote } from './remote.js';
|
|
5
|
+
import type { Aspect } from './types/extensions.js';
|
|
6
|
+
import type { Request } from './types/request.js';
|
|
7
|
+
type Discover = (namespace: string, name: string) => Promise<Remote>;
|
|
8
|
+
export declare class Context extends Connector {
|
|
9
|
+
#private;
|
|
10
|
+
readonly env: string | undefined;
|
|
11
|
+
readonly name: string | undefined;
|
|
12
|
+
readonly aspects: Aspect[];
|
|
13
|
+
readonly locator: Locator;
|
|
14
|
+
constructor(local: Component, discover: Discover, aspects?: Aspect[]);
|
|
15
|
+
apply(endpoint: string, request: Request): Promise<any>;
|
|
16
|
+
call(namespace: string, name: string, endpoint: string, request: Request): Promise<any>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Connector } from './connector.js';
|
|
2
|
+
import { environment } from '@toa.io/generic';
|
|
3
|
+
export class Context extends Connector {
|
|
4
|
+
env;
|
|
5
|
+
name;
|
|
6
|
+
aspects;
|
|
7
|
+
locator;
|
|
8
|
+
#local;
|
|
9
|
+
#discover;
|
|
10
|
+
#remotes = {};
|
|
11
|
+
constructor(local, discover, aspects = []) {
|
|
12
|
+
super();
|
|
13
|
+
this.env = environment.get('TOA_ENV');
|
|
14
|
+
this.name = environment.get('TOA_CONTEXT');
|
|
15
|
+
this.aspects = aspects;
|
|
16
|
+
this.locator = local?.locator;
|
|
17
|
+
this.#local = local;
|
|
18
|
+
this.#discover = discover;
|
|
19
|
+
this.depends(local);
|
|
20
|
+
if (aspects.length > 0)
|
|
21
|
+
this.depends(aspects);
|
|
22
|
+
}
|
|
23
|
+
async apply(endpoint, request) {
|
|
24
|
+
return this.#local.invoke(endpoint, request);
|
|
25
|
+
}
|
|
26
|
+
// eslint-disable-next-line max-params
|
|
27
|
+
async call(namespace, name, endpoint, request) {
|
|
28
|
+
const remote = await this.#remote(namespace, name);
|
|
29
|
+
return remote.invoke(endpoint, request);
|
|
30
|
+
}
|
|
31
|
+
async #remote(namespace, name) {
|
|
32
|
+
const key = namespace + '.' + name;
|
|
33
|
+
this.#remotes[key] ??= this.#connect(namespace, name);
|
|
34
|
+
return this.#remotes[key];
|
|
35
|
+
}
|
|
36
|
+
async #connect(namespace, name) {
|
|
37
|
+
const remote = await this.#discover(namespace, name);
|
|
38
|
+
this.depends(remote);
|
|
39
|
+
return remote;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../source/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAS7C,MAAM,OAAO,OAAQ,SAAQ,SAAS;IACpB,GAAG,CAAoB;IACvB,IAAI,CAAoB;IACxB,OAAO,CAAU;IACjB,OAAO,CAAS;IAEvB,MAAM,CAAW;IACjB,SAAS,CAAU;IACnB,QAAQ,GAAoC,EAAE,CAAA;IAEvD,YAAmB,KAAgB,EAAE,QAAkB,EAAE,OAAO,GAAa,EAAE;QAC7E,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QACrC,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,KAAK,EAAE,OAAO,CAAA;QAE7B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;QAEzB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAEnB,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;YAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/C,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,QAAgB,EAAE,OAAgB;QACnD,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAC9C,CAAC;IAED,sCAAsC;IAC/B,KAAK,CAAC,IAAI,CACf,SAAiB,EACjB,IAAY,EACZ,QAAgB,EAChB,OAAgB;QAEhB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;QAElD,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACzC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,SAAiB,EAAE,IAAY;QAC3C,MAAM,GAAG,GAAG,SAAS,GAAG,GAAG,GAAG,IAAI,CAAA;QAElC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;QAErD,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;IAC3B,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,SAAiB,EAAE,IAAY;QAC5C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;QAEpD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAEpB,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Schema, SchemaError } from '@toa.io/schemas';
|
|
2
|
+
import type { Exception } from '../exceptions.js';
|
|
3
|
+
/** What a contract throws with, stated by the subclass. */
|
|
4
|
+
export type Refusal = new (error: SchemaError, cause?: unknown) => Exception;
|
|
5
|
+
export declare class Contract {
|
|
6
|
+
readonly schema: Schema;
|
|
7
|
+
static Exception: Refusal;
|
|
8
|
+
constructor(schema: Schema);
|
|
9
|
+
fit(value: unknown): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SystemException } from '../exceptions.js';
|
|
2
|
+
export class Contract {
|
|
3
|
+
schema;
|
|
4
|
+
static Exception = SystemException;
|
|
5
|
+
constructor(schema) {
|
|
6
|
+
this.schema = schema;
|
|
7
|
+
}
|
|
8
|
+
fit(value) {
|
|
9
|
+
const error = this.schema.fit(value);
|
|
10
|
+
if (error !== null)
|
|
11
|
+
throw new this.constructor.Exception(error, value);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../source/contract/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAOlD,MAAM,OAAO,QAAQ;IACH,MAAM,CAAQ;IAEvB,MAAM,CAAC,SAAS,GAAY,eAAqC,CAAA;IAExE,YAAmB,MAAc;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAEM,GAAG,CAAC,KAAc;QACvB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAEpC,IAAI,KAAK,KAAK,IAAI;YAChB,MAAM,IAAK,IAAI,CAAC,WAA+B,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IAC3E,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/contract/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Contract } from './contract.js';
|
|
2
|
+
import type { Refusal } from './contract.js';
|
|
3
|
+
import type { JSONSchema } from './schemas.js';
|
|
4
|
+
export declare class Reply extends Contract {
|
|
5
|
+
static Exception: Refusal;
|
|
6
|
+
static schema(output?: JSONSchema, errors?: Array<string | number>): JSONSchema;
|
|
7
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Contract } from './contract.js';
|
|
2
|
+
import { ResponseContractException } from '../exceptions.js';
|
|
3
|
+
export class Reply extends Contract {
|
|
4
|
+
static Exception = ResponseContractException;
|
|
5
|
+
static schema(output, errors) {
|
|
6
|
+
const schema = {
|
|
7
|
+
type: 'object',
|
|
8
|
+
properties: {},
|
|
9
|
+
additionalProperties: false
|
|
10
|
+
};
|
|
11
|
+
if (output !== undefined) {
|
|
12
|
+
/*
|
|
13
|
+
* A reply carries more than the operation declares — `VERSION` and the rest of the
|
|
14
|
+
* record's own fields — so what it is validated against is the declaration relaxed.
|
|
15
|
+
* On a copy: the declaration itself is what a component publishes when asked to
|
|
16
|
+
* explain, and relaxing that would publish a contract nobody wrote.
|
|
17
|
+
*/
|
|
18
|
+
output = structuredClone(output);
|
|
19
|
+
if (output.type === 'object')
|
|
20
|
+
output.additionalProperties = true;
|
|
21
|
+
else if (output.type === 'array' && output.items?.type === 'object')
|
|
22
|
+
output.items.additionalProperties = true;
|
|
23
|
+
schema.properties.output = output;
|
|
24
|
+
}
|
|
25
|
+
/*
|
|
26
|
+
* An error a caller is meant to handle is one the operation states. Where none are
|
|
27
|
+
* stated, an error is not a reply this operation makes — it is a mistake, and the
|
|
28
|
+
* contract says so rather than passing an undeclared code on to whoever called.
|
|
29
|
+
*/
|
|
30
|
+
schema.properties.error =
|
|
31
|
+
errors === undefined
|
|
32
|
+
? false
|
|
33
|
+
: {
|
|
34
|
+
type: 'object',
|
|
35
|
+
properties: {
|
|
36
|
+
code: {
|
|
37
|
+
enum: errors
|
|
38
|
+
},
|
|
39
|
+
message: {
|
|
40
|
+
type: 'string'
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
required: ['code']
|
|
44
|
+
};
|
|
45
|
+
return schema;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=reply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reply.js","sourceRoot":"","sources":["../../source/contract/reply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAA;AAI5D,MAAM,OAAO,KAAM,SAAQ,QAAQ;IAC1B,MAAM,CAAU,SAAS,GAC9B,yBAA+C,CAAA;IAE1C,MAAM,CAAC,MAAM,CAAC,MAAmB,EAAE,MAA+B;QACvE,MAAM,MAAM,GAAe;YACzB,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE;YACd,oBAAoB,EAAE,KAAK;SAC5B,CAAA;QAED,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB;;;;;eAKG;YACH,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAA;YAEhC,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ;gBAAE,MAAM,CAAC,oBAAoB,GAAG,IAAI,CAAA;iBAC3D,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,IAAI,MAAM,CAAC,KAAK,EAAE,IAAI,KAAK,QAAQ;gBACjE,MAAM,CAAC,KAAK,CAAC,oBAAoB,GAAG,IAAI,CAAA;YAE1C,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,MAAM,CAAA;QACnC,CAAC;QAED;;;;WAIG;QACH,MAAM,CAAC,UAAU,CAAC,KAAK;YACrB,MAAM,KAAK,SAAS;gBAClB,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC;oBACE,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE;wBACV,IAAI,EAAE;4BACJ,IAAI,EAAE,MAAM;yBACb;wBACD,OAAO,EAAE;4BACP,IAAI,EAAE,QAAQ;yBACf;qBACF;oBACD,QAAQ,EAAE,CAAC,MAAM,CAAC;iBACnB,CAAA;QAEP,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Contract } from './contract.js';
|
|
2
|
+
import type { Schema } from '@toa.io/schemas';
|
|
3
|
+
import type { Refusal } from './contract.js';
|
|
4
|
+
import type { JSONSchema } from './schemas.js';
|
|
5
|
+
/** What an operation states about itself, and answers when asked to explain. */
|
|
6
|
+
export interface Explanation {
|
|
7
|
+
description?: string;
|
|
8
|
+
input?: JSONSchema | null;
|
|
9
|
+
output?: JSONSchema | null;
|
|
10
|
+
errors?: Array<string | number>;
|
|
11
|
+
}
|
|
12
|
+
export interface Definition extends Explanation {
|
|
13
|
+
type?: string;
|
|
14
|
+
scope?: string;
|
|
15
|
+
query?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** What the operation works on, as the manifest declares it. */
|
|
18
|
+
export interface Entity {
|
|
19
|
+
properties: Record<string, JSONSchema>;
|
|
20
|
+
required?: string[];
|
|
21
|
+
}
|
|
22
|
+
export declare class Request extends Contract {
|
|
23
|
+
readonly discovery: Explanation;
|
|
24
|
+
static Exception: Refusal;
|
|
25
|
+
constructor(schema: Schema, definition: Definition, entity?: Entity);
|
|
26
|
+
static schema(definition: Definition, entity?: {
|
|
27
|
+
properties: Record<string, JSONSchema>;
|
|
28
|
+
}): JSONSchema;
|
|
29
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import * as schemas from './schemas.js';
|
|
2
|
+
import { RequestContractException } from '../exceptions.js';
|
|
3
|
+
import { Contract } from './contract.js';
|
|
4
|
+
export class Request extends Contract {
|
|
5
|
+
discovery = {};
|
|
6
|
+
static Exception = RequestContractException;
|
|
7
|
+
constructor(schema, definition, entity) {
|
|
8
|
+
super(schema);
|
|
9
|
+
for (const key of ['description', 'input', 'output', 'errors'])
|
|
10
|
+
if (definition[key] !== undefined)
|
|
11
|
+
this.discovery[key] = definition[key];
|
|
12
|
+
/*
|
|
13
|
+
* An operation that states no output states an empty schema, which every reply fits —
|
|
14
|
+
* and which says nothing to whoever reads it. What its type answers does, so that is
|
|
15
|
+
* said here instead. Here and not in the definition, because the definition is what a
|
|
16
|
+
* reply is held to: a projection is a lawful answer, and describing one is not the same
|
|
17
|
+
* as requiring it.
|
|
18
|
+
*/
|
|
19
|
+
if (empty(this.discovery.output)) {
|
|
20
|
+
const answered = answers(definition, entity);
|
|
21
|
+
if (answered !== undefined)
|
|
22
|
+
this.discovery.output = answered;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
static schema(definition, entity) {
|
|
26
|
+
// `source` is not among these: the framework stamps it and whoever reads it takes the keys
|
|
27
|
+
// it knows, so holding it to a schema would only fail calls from a peer that stamps one more
|
|
28
|
+
const schema = {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: {
|
|
31
|
+
authentic: { type: 'boolean' },
|
|
32
|
+
task: { type: 'boolean' }
|
|
33
|
+
},
|
|
34
|
+
additionalProperties: true
|
|
35
|
+
};
|
|
36
|
+
const required = [];
|
|
37
|
+
if (definition.input !== undefined) {
|
|
38
|
+
schema.properties.input = definition.input;
|
|
39
|
+
required.push('input');
|
|
40
|
+
}
|
|
41
|
+
else
|
|
42
|
+
schema.properties.input = { type: 'null' };
|
|
43
|
+
if (entity === undefined)
|
|
44
|
+
definition.query = false;
|
|
45
|
+
if (definition.query === true)
|
|
46
|
+
required.push('query');
|
|
47
|
+
if (definition.query === false)
|
|
48
|
+
schema.properties.query = { type: 'null' };
|
|
49
|
+
if (definition.query !== false) {
|
|
50
|
+
const query = structuredClone(schemas.query);
|
|
51
|
+
query.properties.id = entity?.properties.id;
|
|
52
|
+
if (definition.type === 'observation')
|
|
53
|
+
delete query.properties.version;
|
|
54
|
+
else
|
|
55
|
+
delete query.properties.projection;
|
|
56
|
+
if (definition.type !== 'observation' || definition.scope !== 'objects') {
|
|
57
|
+
delete query.properties.omit;
|
|
58
|
+
delete query.properties.limit;
|
|
59
|
+
}
|
|
60
|
+
else if (query.required === undefined)
|
|
61
|
+
query.required = ['limit'];
|
|
62
|
+
else
|
|
63
|
+
query.required.push('limit');
|
|
64
|
+
schema.properties.query = query;
|
|
65
|
+
}
|
|
66
|
+
if (required.length > 0)
|
|
67
|
+
schema.required = required;
|
|
68
|
+
return schema;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* What an operation of this type answers, where it did not say.
|
|
73
|
+
*
|
|
74
|
+
* A transition, an observation and an assignment work on the Entity Object, so that is what
|
|
75
|
+
* they answer — a set of them where the scope is a set. A computation neither uses the scope
|
|
76
|
+
* nor produces one, and an effect answers whatever it computed, so neither is guessed at.
|
|
77
|
+
* A stream is not a value with a schema, and is not one either.
|
|
78
|
+
*
|
|
79
|
+
* What the entity requires is said as well. It is a description and nothing is held to it —
|
|
80
|
+
* an operation answering a projection says so by declaring its own output — and a shape
|
|
81
|
+
* whose every property reads as optional says less than it knows.
|
|
82
|
+
*/
|
|
83
|
+
function answers(definition, entity) {
|
|
84
|
+
if (entity === undefined || !ENTITY.has(definition.type))
|
|
85
|
+
return undefined;
|
|
86
|
+
const object = {
|
|
87
|
+
type: 'object',
|
|
88
|
+
properties: entity.properties,
|
|
89
|
+
...(entity.required === undefined ? {} : { required: entity.required })
|
|
90
|
+
};
|
|
91
|
+
if (definition.scope === 'objects')
|
|
92
|
+
return { type: 'array', items: object };
|
|
93
|
+
return definition.scope === 'object' || definition.scope === 'changeset'
|
|
94
|
+
? object
|
|
95
|
+
: undefined;
|
|
96
|
+
}
|
|
97
|
+
/** The types whose subject is the Entity Object; see `documentation/design.md`. */
|
|
98
|
+
const ENTITY = new Set(['transition', 'observation', 'assignment']);
|
|
99
|
+
/** A schema that states nothing, which is what an operation saying nothing normalizes to. */
|
|
100
|
+
function empty(schema) {
|
|
101
|
+
return schema === undefined || schema === null || Object.keys(schema).length === 0;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../source/contract/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAyBxC,MAAM,OAAO,OAAQ,SAAQ,QAAQ;IACnB,SAAS,GAAgB,EAAE,CAAA;IAEpC,MAAM,CAAU,SAAS,GAC9B,wBAA8C,CAAA;IAEhD,YAAmB,MAAc,EAAE,UAAsB,EAAE,MAAe;QACxE,KAAK,CAAC,MAAM,CAAC,CAAA;QAEb,KAAK,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAU;YACrE,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,SAAS;gBAC9B,IAAI,CAAC,SAAqC,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAA;QAEtE;;;;;;WAMG;QACH,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;YACjC,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;YAE5C,IAAI,QAAQ,KAAK,SAAS;gBAAE,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAA;QAC9D,CAAC;IACH,CAAC;IAEM,MAAM,CAAC,MAAM,CAClB,UAAsB,EACtB,MAAmD;QAEnD,2FAA2F;QAC3F,6FAA6F;QAC7F,MAAM,MAAM,GAAe;YACzB,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,SAAS,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;gBAC9B,IAAI,EAAE,EAA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MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,CAAA;AACpF,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const query = {
|
|
2
|
+
type: 'object',
|
|
3
|
+
properties: {
|
|
4
|
+
id: { type: 'string' },
|
|
5
|
+
ids: { type: 'array', uniqueItems: true, minItems: 1, items: { type: 'string' } },
|
|
6
|
+
version: { type: 'integer', minimum: 0 },
|
|
7
|
+
criteria: { type: 'string' },
|
|
8
|
+
search: { type: 'string' },
|
|
9
|
+
sample: { type: 'number' },
|
|
10
|
+
omit: { type: 'integer', minimum: 0 },
|
|
11
|
+
limit: { type: 'integer', minimum: 0 },
|
|
12
|
+
sort: {
|
|
13
|
+
type: 'array',
|
|
14
|
+
uniqueItems: true,
|
|
15
|
+
minItems: 1,
|
|
16
|
+
items: { type: 'string', pattern: '^\\w{1,32}(?::(?:asc|desc))?$' }
|
|
17
|
+
},
|
|
18
|
+
projection: {
|
|
19
|
+
type: 'array',
|
|
20
|
+
uniqueItems: true,
|
|
21
|
+
minItems: 1,
|
|
22
|
+
items: { type: 'string', not: { const: 'id' } }
|
|
23
|
+
},
|
|
24
|
+
deleted: { type: 'boolean' }
|
|
25
|
+
},
|
|
26
|
+
additionalProperties: false
|
|
27
|
+
};
|
|
28
|
+
export const error = {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: {
|
|
31
|
+
code: { anyOf: [{ type: 'integer' }, { type: 'string' }] },
|
|
32
|
+
message: { type: 'string' }
|
|
33
|
+
},
|
|
34
|
+
required: ['code']
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../source/contract/schemas.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,KAAK,GAAe;IAC/B,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,EAAE,EAAE,EAAE,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AAQ,EAAE;KAC5B;IACD,QAAQ,EAAE,CAAC,MAAM,CAAC;CACnB,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Connector } from './connector.js';
|
|
2
|
+
import type { Locator } from './locator.js';
|
|
3
|
+
interface Lookup extends Connector {
|
|
4
|
+
invoke: () => Promise<any>;
|
|
5
|
+
}
|
|
6
|
+
export declare class Discovery extends Connector {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(lookup: (locator: Locator) => Promise<Lookup>);
|
|
9
|
+
protected open(): Promise<void>;
|
|
10
|
+
lookup(locator: Locator): Promise<any>;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { console } from 'openspan';
|
|
2
|
+
import { Connector } from './connector.js';
|
|
3
|
+
export class Discovery extends Connector {
|
|
4
|
+
#lookup;
|
|
5
|
+
#lookups = {};
|
|
6
|
+
constructor(lookup) {
|
|
7
|
+
super();
|
|
8
|
+
this.#lookup = lookup;
|
|
9
|
+
}
|
|
10
|
+
async open() {
|
|
11
|
+
this.#lookups = {};
|
|
12
|
+
}
|
|
13
|
+
async lookup(locator) {
|
|
14
|
+
const id = locator.id;
|
|
15
|
+
if (this.#lookups[id] === undefined) {
|
|
16
|
+
const lookup = await this.#lookup(locator);
|
|
17
|
+
this.#lookups[id] = Promise.resolve(lookup);
|
|
18
|
+
this.depends(lookup);
|
|
19
|
+
}
|
|
20
|
+
const since = Date.now();
|
|
21
|
+
// the wait is unbounded by design, as a dependency may still be starting,
|
|
22
|
+
// so repeating is the only way a component stuck on one stays visible
|
|
23
|
+
const warning = setInterval(() => {
|
|
24
|
+
const waiting = Math.round((Date.now() - since) / 1000);
|
|
25
|
+
console.warn('Waiting for lookup response', { component: id, waiting });
|
|
26
|
+
}, INTERVAL);
|
|
27
|
+
warning.unref();
|
|
28
|
+
const output = await (await this.#lookups[id]).invoke();
|
|
29
|
+
clearInterval(warning);
|
|
30
|
+
return output;
|
|
31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,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;QACzE,CAAC,EAAE,QAAQ,CAAC,CAAA;QAEZ,OAAO,CAAC,KAAK,EAAE,CAAA;QAEf,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAA;QAEvD,aAAa,CAAC,OAAO,CAAC,CAAA;QAEtB,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAED,MAAM,QAAQ,GAAG,IAAI,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Observation } from './observation.js';
|
|
2
|
+
export class Effect extends Observation {
|
|
3
|
+
async acquire(store) {
|
|
4
|
+
const { query, entity, input } = store.request;
|
|
5
|
+
if (entity === undefined)
|
|
6
|
+
return super.acquire(store);
|
|
7
|
+
store.scope = await this.scope.ensure(query, entity, input);
|
|
8
|
+
store.state = store.scope.get();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=effect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effect.js","sourceRoot":"","sources":["../source/effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAI9C,MAAM,OAAO,MAAO,SAAQ,WAAW;IAClB,KAAK,CAAC,OAAO,CAAC,KAAY;QAC3C,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,OAAO,CAAA;QAE9C,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAErD,KAAK,CAAC,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAY,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;QAClE,KAAK,CAAC,KAAK,GAAI,KAAK,CAAC,KAAgB,CAAC,GAAG,EAAE,CAAA;IAC7C,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Connector } from './connector.js';
|
|
2
|
+
import type { Event } from './event.js';
|
|
3
|
+
import type { Event as StateEvent } from './types/state.js';
|
|
4
|
+
export declare class Emission extends Connector {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(events: Event[]);
|
|
7
|
+
emit(event: StateEvent): Promise<void>;
|
|
8
|
+
}
|