@toa.io/core 1.0.0-alpha.30 → 1.0.0-alpha.301
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 +146 -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 +93 -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 +54 -0
- package/transpiled/connector.js +193 -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/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 +39 -0
- package/transpiled/contract/request.js +111 -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 +19 -0
- package/transpiled/discovery.js +52 -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 +10 -0
- package/transpiled/emission.js +16 -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 +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 +10 -0
- package/transpiled/entities/newid.js +35 -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 +51 -0
- package/transpiled/event.js.map +1 -0
- package/transpiled/exceptions.d.ts +89 -0
- package/transpiled/exceptions.js +180 -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 +37 -0
- package/transpiled/index.js +31 -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/observation.d.ts +5 -0
- package/transpiled/observation.js +12 -0
- package/transpiled/observation.js.map +1 -0
- package/transpiled/operation.d.ts +67 -0
- package/transpiled/operation.js +127 -0
- package/transpiled/operation.js.map +1 -0
- package/transpiled/outbox.d.ts +45 -0
- package/transpiled/outbox.js +430 -0
- package/transpiled/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 +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/state.d.ts +36 -0
- package/transpiled/state.js +131 -0
- package/transpiled/state.js.map +1 -0
- package/transpiled/trail.d.ts +71 -0
- package/transpiled/trail.js +110 -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 +56 -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 +38 -0
- package/transpiled/types/bridges.js +2 -0
- package/transpiled/types/bridges.js.map +1 -0
- package/transpiled/types/extensions.d.ts +92 -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 +103 -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 -65
- 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
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
import { Connector } from './connector.js';
|
|
3
|
+
import { codes, SystemException, RequestContractException } from './exceptions.js';
|
|
4
|
+
import { environment } from '@toa.io/generic';
|
|
5
|
+
export class Operation extends Connector {
|
|
6
|
+
scope;
|
|
7
|
+
/**
|
|
8
|
+
* Whether what this operation acquires may be modified and committed. Only a
|
|
9
|
+
* transition commits, and only a commit needs the pre-image an entity keeps
|
|
10
|
+
* to diff the new state against.
|
|
11
|
+
*
|
|
12
|
+
* @protected
|
|
13
|
+
*/
|
|
14
|
+
mutable = false;
|
|
15
|
+
#cascade;
|
|
16
|
+
#contracts;
|
|
17
|
+
#query;
|
|
18
|
+
#scope;
|
|
19
|
+
#once;
|
|
20
|
+
// eslint-disable-next-line max-params
|
|
21
|
+
constructor(cascade, scope, contracts, query, definition) {
|
|
22
|
+
super();
|
|
23
|
+
this.scope = scope;
|
|
24
|
+
this.#cascade = cascade;
|
|
25
|
+
this.#contracts = contracts;
|
|
26
|
+
this.#query = query;
|
|
27
|
+
this.#scope = definition.scope;
|
|
28
|
+
this.#once = definition.once === true;
|
|
29
|
+
this.depends(cascade);
|
|
30
|
+
}
|
|
31
|
+
async invoke(request) {
|
|
32
|
+
try {
|
|
33
|
+
if (request.authentic !== true)
|
|
34
|
+
this.#contracts.request.fit(request);
|
|
35
|
+
// the request carries the query onward in its parsed form: what a storage is given,
|
|
36
|
+
// not what the caller sent
|
|
37
|
+
if ('query' in request)
|
|
38
|
+
request.query = this.#query.parse(request.query);
|
|
39
|
+
// validate entity
|
|
40
|
+
if ('entity' in request)
|
|
41
|
+
this.scope.fit(request.entity);
|
|
42
|
+
const store = { request };
|
|
43
|
+
if (this.#once)
|
|
44
|
+
return await this.once(store);
|
|
45
|
+
return await this.process(store);
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
const exception = e instanceof Error ? new SystemException(e) : e;
|
|
49
|
+
return { exception };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The call, once. What it answered is recorded with what it changed, in one transaction, so a
|
|
54
|
+
* second arrival of the same identity finds the key taken, changes nothing, and is answered
|
|
55
|
+
* with what the first one answered.
|
|
56
|
+
*
|
|
57
|
+
* The read in front of it is not what makes that true — the key is — but it is what keeps the
|
|
58
|
+
* ordinary duplicate from running the algorithm at all, and the ordinary duplicate is a
|
|
59
|
+
* retransmission that arrives after the first call has finished.
|
|
60
|
+
*/
|
|
61
|
+
async once(store) {
|
|
62
|
+
const { id } = store.request;
|
|
63
|
+
if (id === undefined)
|
|
64
|
+
throw new RequestContractException('a request to an operation declared `once` carries no id');
|
|
65
|
+
const recalled = await this.scope.recall(id);
|
|
66
|
+
if (recalled !== null)
|
|
67
|
+
return recalled;
|
|
68
|
+
try {
|
|
69
|
+
return await this.process(store);
|
|
70
|
+
}
|
|
71
|
+
catch (exception) {
|
|
72
|
+
if (exception?.code !== codes.DuplicateCall)
|
|
73
|
+
throw exception;
|
|
74
|
+
/*
|
|
75
|
+
* It was made between the read and the write — a duplicate that arrived while the first
|
|
76
|
+
* was still running, and lost. Nothing of this one was committed, so what is answered is
|
|
77
|
+
* the other one's reply. Absent only if the record expired in between, which is the
|
|
78
|
+
* window closing on a call nobody is waiting on any more.
|
|
79
|
+
*/
|
|
80
|
+
return (await this.scope.recall(id)) ?? { exception };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* What is recorded with the write. Read where the write is made, which is after the algorithm
|
|
85
|
+
* has run, because the reply is what a duplicate is answered with.
|
|
86
|
+
*/
|
|
87
|
+
call(store) {
|
|
88
|
+
if (!this.#once)
|
|
89
|
+
return undefined;
|
|
90
|
+
/*
|
|
91
|
+
* A copy: an assignment fills its output in after the write it is recorded by returns, and
|
|
92
|
+
* what is recorded must be what was known when the record was made rather than whatever the
|
|
93
|
+
* reply became afterwards.
|
|
94
|
+
*/
|
|
95
|
+
return { id: store.request.id, reply: { ...store.reply } };
|
|
96
|
+
}
|
|
97
|
+
async process(store) {
|
|
98
|
+
await this.acquire(store);
|
|
99
|
+
await this.run(store);
|
|
100
|
+
await this.commit(store);
|
|
101
|
+
return store.reply;
|
|
102
|
+
}
|
|
103
|
+
async acquire(store) {
|
|
104
|
+
if (this.#scope === 'none')
|
|
105
|
+
return;
|
|
106
|
+
const scope = await this.query(store.request.query);
|
|
107
|
+
const raw = scope === null || scope instanceof Readable;
|
|
108
|
+
store.scope = scope;
|
|
109
|
+
store.state = raw ? scope : scope.get();
|
|
110
|
+
}
|
|
111
|
+
async run(store) {
|
|
112
|
+
const { request, state } = store;
|
|
113
|
+
const reply = await this.#cascade.run(request.input, state);
|
|
114
|
+
// validate reply only on local environments
|
|
115
|
+
if (environment.get('TOA_ENV') === 'local' && !(reply instanceof Readable))
|
|
116
|
+
this.#contracts.reply.fit(reply);
|
|
117
|
+
store.reply = reply;
|
|
118
|
+
}
|
|
119
|
+
async commit(_store) { }
|
|
120
|
+
async query(query) {
|
|
121
|
+
if (query === undefined)
|
|
122
|
+
throw new RequestContractException('Request query is required');
|
|
123
|
+
const acquire = this.scope[this.#scope];
|
|
124
|
+
return acquire.call(this.scope, query, this.mutable);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation.js","sourceRoot":"","sources":["../source/operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAqC7C,MAAM,OAAO,SAAU,SA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AM,IAAI,wBAAwB,CAAC,2BAA2B,CAAC,CAAA;QAEjE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAGlB,CAAA;QAEpB,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;IACtD,CAAC;CACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Connector } from './connector.ts';
|
|
2
|
+
import type { Atom } from './types/atomicity.ts';
|
|
3
|
+
import type { Storage } from './types/storages.ts';
|
|
4
|
+
import type { Destination, Row } from './types/outbox.ts';
|
|
5
|
+
import type { Event } from './types/state.ts';
|
|
6
|
+
export interface Options {
|
|
7
|
+
interval?: number;
|
|
8
|
+
batch?: number;
|
|
9
|
+
gap?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Owns the intent to publish. A row is built before the write so that the storage can commit
|
|
13
|
+
* it in the same transaction as the entity; publication then happens off the operation's path,
|
|
14
|
+
* and anything that fails to publish is recovered from the row.
|
|
15
|
+
*
|
|
16
|
+
* The mechanism is a safety net: in a healthy system the row is written, published within
|
|
17
|
+
* milliseconds by the same process, and marked published on that process's next tick.
|
|
18
|
+
*
|
|
19
|
+
* A storage that cannot commit a row atomically has no outbox, and this degrades to the
|
|
20
|
+
* inline emission it replaces.
|
|
21
|
+
*/
|
|
22
|
+
export declare class Outbox extends Connector {
|
|
23
|
+
#private;
|
|
24
|
+
constructor(destinations: Destination[], storage: Storage | undefined, atom: Atom, options?: Options);
|
|
25
|
+
/** whether the storage can commit a row atomically with the entity */
|
|
26
|
+
get durable(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* An assignment's images are the write's own, so it hands over an event with neither, and
|
|
29
|
+
* the storage fills them in.
|
|
30
|
+
*/
|
|
31
|
+
row(event: Partial<Event>): Row;
|
|
32
|
+
/**
|
|
33
|
+
* Hands a committed row over. Awaited by the caller only on the legacy path — with an
|
|
34
|
+
* outbox this returns at once and the broker leaves the operation's path.
|
|
35
|
+
*/
|
|
36
|
+
publish(row: Row): Promise<void> | void;
|
|
37
|
+
protected open(): Promise<void>;
|
|
38
|
+
protected close(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Constant, never configuration: rows carry their lane, so lowering this would leave rows in
|
|
42
|
+
* lanes nobody reads any more. It is also the ceiling on replicas of one component, and a
|
|
43
|
+
* power of two so that the common replica counts divide evenly.
|
|
44
|
+
*/
|
|
45
|
+
export declare const LANES = 128;
|
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import { console } from 'openspan';
|
|
2
|
+
import { Connector } from './connector.js';
|
|
3
|
+
import { newid } from './entities/newid.js';
|
|
4
|
+
import * as trail from './trail.js';
|
|
5
|
+
import { environment } from '@toa.io/generic';
|
|
6
|
+
/**
|
|
7
|
+
* Owns the intent to publish. A row is built before the write so that the storage can commit
|
|
8
|
+
* it in the same transaction as the entity; publication then happens off the operation's path,
|
|
9
|
+
* and anything that fails to publish is recovered from the row.
|
|
10
|
+
*
|
|
11
|
+
* The mechanism is a safety net: in a healthy system the row is written, published within
|
|
12
|
+
* milliseconds by the same process, and marked published on that process's next tick.
|
|
13
|
+
*
|
|
14
|
+
* A storage that cannot commit a row atomically has no outbox, and this degrades to the
|
|
15
|
+
* inline emission it replaces.
|
|
16
|
+
*/
|
|
17
|
+
export class Outbox extends Connector {
|
|
18
|
+
#destinations;
|
|
19
|
+
#storage;
|
|
20
|
+
#atom;
|
|
21
|
+
#gap;
|
|
22
|
+
#interval;
|
|
23
|
+
#batch;
|
|
24
|
+
#defer;
|
|
25
|
+
/*
|
|
26
|
+
* Everything a destination is answerable for is held per destination, which is what keeps
|
|
27
|
+
* one from delaying another: a dead one fills its own in-flight cap and the cycle stops
|
|
28
|
+
* handing it rows, while the rest go on being published and settled.
|
|
29
|
+
*/
|
|
30
|
+
/** ids this process has published, by destination, held until a cycle marks them */
|
|
31
|
+
#published = new Map();
|
|
32
|
+
/** in-flight publications, by destination, awaited (with a bound) on close */
|
|
33
|
+
#inflight = new Map();
|
|
34
|
+
/** rows this replica is publishing right now, so a cycle does not pick them up again */
|
|
35
|
+
#publishing = new Map();
|
|
36
|
+
#timer;
|
|
37
|
+
#off;
|
|
38
|
+
#pumping = false;
|
|
39
|
+
/** cycles in a row this replica has been assigned no lane */
|
|
40
|
+
#unassigned = 0;
|
|
41
|
+
#closing = false;
|
|
42
|
+
// eslint-disable-next-line max-params
|
|
43
|
+
constructor(destinations, storage, atom, options = {}) {
|
|
44
|
+
super();
|
|
45
|
+
this.#destinations = destinations;
|
|
46
|
+
this.#storage = storage;
|
|
47
|
+
this.#atom = atom;
|
|
48
|
+
for (const destination of destinations) {
|
|
49
|
+
this.#published.set(destination.name, new Set());
|
|
50
|
+
this.#inflight.set(destination.name, new Set());
|
|
51
|
+
this.#publishing.set(destination.name, new Set());
|
|
52
|
+
}
|
|
53
|
+
this.#interval = number('TOA_OUTBOX_INTERVAL', options.interval, INTERVAL);
|
|
54
|
+
this.#batch = number('TOA_OUTBOX_BATCH', options.batch, BATCH);
|
|
55
|
+
this.#gap = options.gap ?? this.#interval * K;
|
|
56
|
+
this.#defer = environment.get('TOA_OUTBOX_DEFER') === '1';
|
|
57
|
+
// one at a time: an array would link the group it makes rather than its members
|
|
58
|
+
for (const destination of destinations)
|
|
59
|
+
this.depends(destination);
|
|
60
|
+
this.depends(atom);
|
|
61
|
+
if (storage !== undefined)
|
|
62
|
+
this.depends(storage);
|
|
63
|
+
}
|
|
64
|
+
/** whether the storage can commit a row atomically with the entity */
|
|
65
|
+
get durable() {
|
|
66
|
+
return this.#storage?.outbox !== undefined;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* An assignment's images are the write's own, so it hands over an event with neither, and
|
|
70
|
+
* the storage fills them in.
|
|
71
|
+
*/
|
|
72
|
+
row(event) {
|
|
73
|
+
const row = {
|
|
74
|
+
id: newid(),
|
|
75
|
+
lane: this.#lane(),
|
|
76
|
+
published: false,
|
|
77
|
+
pending: Date.now() + this.#gap,
|
|
78
|
+
outstanding: this.#destinations.map((destination) => destination.name),
|
|
79
|
+
event: event
|
|
80
|
+
};
|
|
81
|
+
/*
|
|
82
|
+
* This runs on the operation's own path, which is the only moment the chain is in scope:
|
|
83
|
+
* the pump that publishes the row may be another replica, an hour later. A row that had
|
|
84
|
+
* no chain stores no field.
|
|
85
|
+
*/
|
|
86
|
+
const hops = trail.current()?.hops;
|
|
87
|
+
if (hops !== undefined)
|
|
88
|
+
row.trail = hops;
|
|
89
|
+
return row;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Hands a committed row over. Awaited by the caller only on the legacy path — with an
|
|
93
|
+
* outbox this returns at once and the broker leaves the operation's path.
|
|
94
|
+
*/
|
|
95
|
+
publish(row) {
|
|
96
|
+
// without a durable outbox this is the inline path, and the caller awaits every destination
|
|
97
|
+
if (!this.durable)
|
|
98
|
+
return this.#inline(row);
|
|
99
|
+
/*
|
|
100
|
+
* A publication started while the pump is closing would outlive the emitters it needs,
|
|
101
|
+
* and `comq` waits on a connection that is going rather than failing. The row is already
|
|
102
|
+
* durable, so leaving it is exactly what it is for.
|
|
103
|
+
*/
|
|
104
|
+
if (this.#closing || this.#defer)
|
|
105
|
+
return;
|
|
106
|
+
this.#publish(row);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The inline path, where there is no row to come back to: every destination is attempted and
|
|
110
|
+
* the operation waits for all of them, so a failure reaches whoever wrote.
|
|
111
|
+
*/
|
|
112
|
+
async #inline(row) {
|
|
113
|
+
const sending = this.#destinations
|
|
114
|
+
.filter((destination) => row.outstanding.includes(destination.name))
|
|
115
|
+
.map(async (destination) => destination.emit(row));
|
|
116
|
+
await Promise.all(sending);
|
|
117
|
+
}
|
|
118
|
+
async open() {
|
|
119
|
+
if (!this.durable)
|
|
120
|
+
return;
|
|
121
|
+
if (this.#defer)
|
|
122
|
+
console.warn('Outbox immediate publication is deferred; events are published by the pump only');
|
|
123
|
+
this.#timer = setInterval(() => {
|
|
124
|
+
this.#tick();
|
|
125
|
+
}, this.#interval);
|
|
126
|
+
this.#timer.unref();
|
|
127
|
+
/*
|
|
128
|
+
* A lane changing hands is exactly when rows stranded in it become this replica's to
|
|
129
|
+
* publish, and the cycle would not notice for up to an interval. Being told costs a cycle
|
|
130
|
+
* that finds nothing in the usual case, where the claim arrives once and never changes.
|
|
131
|
+
*/
|
|
132
|
+
this.#off = this.#atom.onassigned(() => {
|
|
133
|
+
this.#tick();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
async close() {
|
|
137
|
+
this.#closing = true;
|
|
138
|
+
this.#off?.();
|
|
139
|
+
if (this.#timer !== undefined)
|
|
140
|
+
clearInterval(this.#timer);
|
|
141
|
+
await this.#drain();
|
|
142
|
+
await this.#mark();
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Publishes one row and swallows the failure: the row stays unpublished and comes back on a
|
|
146
|
+
* later cycle, which is the whole point of having written it.
|
|
147
|
+
*
|
|
148
|
+
* There is no timeout here on purpose. A publication is a confirmed write to a durable
|
|
149
|
+
* exchange, and `comq` waits for the broker to come back rather than failing — abandoning
|
|
150
|
+
* it would not stop it, it would only mean the row is published twice once it lands. What
|
|
151
|
+
* bounds this instead is the in-flight cap and the drain on close.
|
|
152
|
+
*
|
|
153
|
+
*/
|
|
154
|
+
/** @returns what it started, so a cycle can wait for it before marking */
|
|
155
|
+
#publish(row) {
|
|
156
|
+
const started = [];
|
|
157
|
+
for (const destination of this.#destinations)
|
|
158
|
+
if (this.#due(row, destination.name))
|
|
159
|
+
started.push(this.#send(row, destination));
|
|
160
|
+
return started;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Whether this row is still this process's to send to that destination. A destination the
|
|
164
|
+
* row names and this process does not have is not its to send, and is left where it is.
|
|
165
|
+
*/
|
|
166
|
+
#due(row, destination) {
|
|
167
|
+
if (!row.outstanding.includes(destination))
|
|
168
|
+
return false;
|
|
169
|
+
const published = this.#published.get(destination);
|
|
170
|
+
if (published === undefined)
|
|
171
|
+
return false;
|
|
172
|
+
return !published.has(row.id) && !this.#publishing.get(destination).has(row.id);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Publishes one row to one destination and swallows the failure: the row stays outstanding
|
|
176
|
+
* for it and comes back on a later cycle, which is the whole point of having written it.
|
|
177
|
+
* Nothing here reaches the other destinations of the same row.
|
|
178
|
+
*
|
|
179
|
+
* There is no timeout on purpose. A publication is a confirmed write to a durable exchange,
|
|
180
|
+
* and `comq` waits for the broker to come back rather than failing — abandoning it would not
|
|
181
|
+
* stop it, it would only mean the row is published twice once it lands. What bounds this
|
|
182
|
+
* instead is the in-flight cap, which is per destination so that a dead one cannot stop the
|
|
183
|
+
* cycle from feeding the others, and the drain on close.
|
|
184
|
+
*/
|
|
185
|
+
async #send(row, destination) {
|
|
186
|
+
const name = destination.name;
|
|
187
|
+
const published = this.#published.get(name);
|
|
188
|
+
const publishing = this.#publishing.get(name);
|
|
189
|
+
const inflight = this.#inflight.get(name);
|
|
190
|
+
if (inflight.size >= INFLIGHT || published.size >= PUBLISHED)
|
|
191
|
+
return;
|
|
192
|
+
publishing.add(row.id);
|
|
193
|
+
const sending = destination.emit(row);
|
|
194
|
+
inflight.add(sending);
|
|
195
|
+
try {
|
|
196
|
+
await sending;
|
|
197
|
+
published.add(row.id);
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
// the message, not the error: an `Error` has no enumerable own properties, so what
|
|
201
|
+
// reached the log was `{}` and a publication that keeps failing said nothing about why
|
|
202
|
+
console.warn('Outbox publication failed', {
|
|
203
|
+
row: row.id,
|
|
204
|
+
destination: name,
|
|
205
|
+
message: error?.message
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
finally {
|
|
209
|
+
inflight.delete(sending);
|
|
210
|
+
publishing.delete(row.id);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* `comq` retries a publish for as long as the broker is down rather than rejecting, so an
|
|
215
|
+
* unbounded drain outlives any grace period.
|
|
216
|
+
*
|
|
217
|
+
*/
|
|
218
|
+
async #drain() {
|
|
219
|
+
const inflight = [...this.#inflight.values()].flatMap((set) => [...set]);
|
|
220
|
+
if (inflight.length === 0)
|
|
221
|
+
return;
|
|
222
|
+
await Promise.race([Promise.allSettled(inflight), delay(DRAIN)]);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Reads what is due, publishes it, and marks everything this process has sent — what it just
|
|
226
|
+
* published and what the immediate path published since the last cycle. One cycle at a time.
|
|
227
|
+
*
|
|
228
|
+
*/
|
|
229
|
+
#tick() {
|
|
230
|
+
if (this.#pumping)
|
|
231
|
+
return;
|
|
232
|
+
this.#pumping = true;
|
|
233
|
+
void this.#pump().finally(() => (this.#pumping = false));
|
|
234
|
+
}
|
|
235
|
+
async #pump() {
|
|
236
|
+
this.#assignment();
|
|
237
|
+
let page;
|
|
238
|
+
let after;
|
|
239
|
+
do {
|
|
240
|
+
page = await this.#read(after);
|
|
241
|
+
if (page.length === 0)
|
|
242
|
+
break;
|
|
243
|
+
// so a page is never read twice
|
|
244
|
+
after = page[page.length - 1]?.id;
|
|
245
|
+
/*
|
|
246
|
+
* A row is unpublished in the database until a cycle marks it, so a page includes what
|
|
247
|
+
* this replica is sending right now and what a failed marking left behind. Only this
|
|
248
|
+
* process knows either.
|
|
249
|
+
*/
|
|
250
|
+
const rows = page.filter((row) => this.#destinations.some((destination) => this.#due(row, destination.name)));
|
|
251
|
+
if (rows.length > 0) {
|
|
252
|
+
console.debug('Outbox recovering unpublished rows', { count: rows.length });
|
|
253
|
+
// every row is given its chance, at every destination it is still outstanding for;
|
|
254
|
+
// what a broker refused stays outstanding there and comes back on a later cycle
|
|
255
|
+
await this.#awaited(rows.flatMap((row) => this.#publish(row)));
|
|
256
|
+
}
|
|
257
|
+
// a full page is a page that may have been cut short
|
|
258
|
+
} while (page.length === this.#batch);
|
|
259
|
+
await this.#mark();
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Says when this replica has owned nothing for long enough that nothing is going to assign
|
|
263
|
+
* it anything.
|
|
264
|
+
*
|
|
265
|
+
* Owning no lane is ordinary for a moment — a replica that has just started has not been
|
|
266
|
+
* told yet — and is why nothing here refuses at boot: one cycle of it cannot be told from an
|
|
267
|
+
* atomicity that is absent. Ten in a row can, and what it means is that this outbox recovers
|
|
268
|
+
* nothing: a publication that failed is never retried, and that change is lost with the
|
|
269
|
+
* process that failed to make it.
|
|
270
|
+
*
|
|
271
|
+
* Said every ten cycles rather than once, so that it is still there to be found in a log
|
|
272
|
+
* read long after the deployment that broke it, and once when it is over.
|
|
273
|
+
*/
|
|
274
|
+
#assignment() {
|
|
275
|
+
const lanes = this.#atom.slots(LANES);
|
|
276
|
+
if (lanes !== null && lanes.length > 0) {
|
|
277
|
+
if (this.#unassigned >= UNASSIGNED)
|
|
278
|
+
console.info('Outbox lanes assigned, recovery resumed');
|
|
279
|
+
this.#unassigned = 0;
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
this.#unassigned++;
|
|
283
|
+
if (this.#unassigned % UNASSIGNED === 0)
|
|
284
|
+
console.warn('Outbox owns no lane and recovers nothing', {
|
|
285
|
+
cycles: this.#unassigned,
|
|
286
|
+
interval: this.#interval
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* One page of what is due. In a healthy system the first one is empty, every cycle — a row is
|
|
291
|
+
* due only if the process that wrote it failed to publish or died before marking it.
|
|
292
|
+
*
|
|
293
|
+
* Reading is suspended, not stopped, while this replica does not know which lanes are its
|
|
294
|
+
* own: the cycle keeps running and keeps marking, and reading resumes as soon as an
|
|
295
|
+
* assignment arrives. Reading without an assignment would be a different guarantee, where
|
|
296
|
+
* every replica publishes every stranded row.
|
|
297
|
+
*
|
|
298
|
+
* @param after the last id of the page before, so a page is never read twice
|
|
299
|
+
*/
|
|
300
|
+
async #read(after) {
|
|
301
|
+
const lanes = this.#atom.slots(LANES);
|
|
302
|
+
if (lanes === null || lanes.length === 0)
|
|
303
|
+
return [];
|
|
304
|
+
return this.#storage
|
|
305
|
+
.outbox.pending(lanes, Date.now(), this.#batch, after)
|
|
306
|
+
.catch((error) => {
|
|
307
|
+
console.warn('Outbox read failed', { error });
|
|
308
|
+
return [];
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Waits for what this cycle started, so that it marks what it sent rather than leaving it to
|
|
313
|
+
* the next one — but not past its own interval. A publication is never abandoned: it stays in
|
|
314
|
+
* flight, `#publishing` keeps a later cycle from sending it again, and the drain on close
|
|
315
|
+
* still waits for it. What is bounded is only how long a cycle waits before marking the rest,
|
|
316
|
+
* so that one destination with nothing to say cannot hold up the settling of another.
|
|
317
|
+
*/
|
|
318
|
+
async #awaited(started) {
|
|
319
|
+
if (started.length === 0)
|
|
320
|
+
return;
|
|
321
|
+
await Promise.race([Promise.allSettled(started), delay(this.#interval)]);
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* One batched write for many rows, which is why the ids are held in memory rather than
|
|
325
|
+
* marked one by one. Ids that fail to be marked are kept and retried; a row that is never
|
|
326
|
+
* marked is simply published again, which is within the contract.
|
|
327
|
+
*
|
|
328
|
+
* Rows are grouped by the destinations that completed for them, so the ordinary case — every
|
|
329
|
+
* destination landing in the same window — is one group and one write, as it was when there
|
|
330
|
+
* was only ever one. A second write happens where the destinations diverged, which is the
|
|
331
|
+
* failure this exists for.
|
|
332
|
+
*/
|
|
333
|
+
async #mark() {
|
|
334
|
+
for (const [destinations, ids] of this.#groups())
|
|
335
|
+
await this.#settle(destinations, ids);
|
|
336
|
+
}
|
|
337
|
+
/** @private */
|
|
338
|
+
async #settle(destinations, ids) {
|
|
339
|
+
try {
|
|
340
|
+
await this.#storage.outbox.settle(ids, destinations);
|
|
341
|
+
}
|
|
342
|
+
catch (error) {
|
|
343
|
+
console.warn('Outbox marking failed', { count: ids.length, error });
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
for (const destination of destinations) {
|
|
347
|
+
const published = this.#published.get(destination);
|
|
348
|
+
for (const id of ids)
|
|
349
|
+
published.delete(id);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* What has been published since the last cycle, as rows sharing the destinations that
|
|
354
|
+
* completed for them.
|
|
355
|
+
*/
|
|
356
|
+
#groups() {
|
|
357
|
+
/** the destinations that completed for an id, in the order the destinations are held */
|
|
358
|
+
const completed = new Map();
|
|
359
|
+
for (const [destination, ids] of this.#published)
|
|
360
|
+
for (const id of ids) {
|
|
361
|
+
const names = completed.get(id);
|
|
362
|
+
if (names === undefined)
|
|
363
|
+
completed.set(id, [destination]);
|
|
364
|
+
else
|
|
365
|
+
names.push(destination);
|
|
366
|
+
}
|
|
367
|
+
const groups = new Map();
|
|
368
|
+
for (const [id, destinations] of completed) {
|
|
369
|
+
const key = destinations.join(SEPARATOR);
|
|
370
|
+
const group = groups.get(key);
|
|
371
|
+
if (group === undefined)
|
|
372
|
+
groups.set(key, [destinations, [id]]);
|
|
373
|
+
else
|
|
374
|
+
group[1].push(id);
|
|
375
|
+
}
|
|
376
|
+
return [...groups.values()];
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* A lane this replica currently owns, so that in steady state it settles its own rows
|
|
380
|
+
* before it ever reads them. Any lane at all when it owns none: the row still has to be
|
|
381
|
+
* written, and whoever ends up owning that lane will pump it.
|
|
382
|
+
*
|
|
383
|
+
*/
|
|
384
|
+
#lane() {
|
|
385
|
+
const owned = this.#atom.slots(LANES);
|
|
386
|
+
return owned === null || owned.length === 0
|
|
387
|
+
? Math.floor(Math.random() * LANES)
|
|
388
|
+
: owned[Math.floor(Math.random() * owned.length)];
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
function number(variable, declared, fallback) {
|
|
392
|
+
if (declared !== undefined)
|
|
393
|
+
return declared;
|
|
394
|
+
const value = Number(environment.get(variable));
|
|
395
|
+
return Number.isNaN(value) || value <= 0 ? fallback : value;
|
|
396
|
+
}
|
|
397
|
+
async function delay(ms) {
|
|
398
|
+
return new Promise((resolve) => {
|
|
399
|
+
setTimeout(resolve, ms).unref();
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Constant, never configuration: rows carry their lane, so lowering this would leave rows in
|
|
404
|
+
* lanes nobody reads any more. It is also the ceiling on replicas of one component, and a
|
|
405
|
+
* power of two so that the common replica counts divide evenly.
|
|
406
|
+
*/
|
|
407
|
+
export const LANES = 128;
|
|
408
|
+
/** one cycle reads, publishes and marks; in steady state it finds nothing to read */
|
|
409
|
+
/**
|
|
410
|
+
* Cycles owning nothing before that is said out loud, and between one saying and the next.
|
|
411
|
+
* Long enough that a replica which has just started, or one whose assignment is being redrawn,
|
|
412
|
+
* says nothing at all.
|
|
413
|
+
*/
|
|
414
|
+
const UNASSIGNED = 10;
|
|
415
|
+
const INTERVAL = 5000;
|
|
416
|
+
/**
|
|
417
|
+
* `gap = interval * K`. Not a steady-state necessity — a replica writes into a lane it owns
|
|
418
|
+
* and marks what it published — but a guard for when a lane changes hands between the write
|
|
419
|
+
* and the settle. Two cycles of separation, plus one of margin.
|
|
420
|
+
*/
|
|
421
|
+
const K = 3;
|
|
422
|
+
/** how many rows one read brings back; the pump reads on while a page comes back full */
|
|
423
|
+
const BATCH = 200;
|
|
424
|
+
const DRAIN = 10_000;
|
|
425
|
+
/** publications in flight at once, per destination */
|
|
426
|
+
const INFLIGHT = 1000;
|
|
427
|
+
const PUBLISHED = 10_000;
|
|
428
|
+
/** what a group of destinations is keyed by; no name can hold it */
|
|
429
|
+
const SEPARATOR = '\u0000';
|
|
430
|
+
//# sourceMappingURL=outbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outbox.js","sourceRoot":"","sources":["../source/outbox.ts"],"names":[],"mapp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
|
|
1
|
+
import type { Node } from '../types/storages.ts';
|
|
2
|
+
/** What a component declares about the properties a criteria may select on. */
|
|
3
|
+
export type Properties = Record<string, {
|
|
4
|
+
type: string;
|
|
5
|
+
}>;
|
|
6
|
+
export declare function criteria(expression: string, properties?: Properties): Node;
|