@toa.io/core 1.0.0-alpha.293 → 1.0.0-alpha.299

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.
Files changed (49) hide show
  1. package/package.json +3 -3
  2. package/transpiled/call.js +12 -0
  3. package/transpiled/call.js.map +1 -1
  4. package/transpiled/component.js +31 -4
  5. package/transpiled/component.js.map +1 -1
  6. package/transpiled/context.d.ts +5 -0
  7. package/transpiled/context.js +6 -0
  8. package/transpiled/context.js.map +1 -1
  9. package/transpiled/emission.d.ts +4 -2
  10. package/transpiled/emission.js +4 -2
  11. package/transpiled/emission.js.map +1 -1
  12. package/transpiled/entities/entity.js +34 -6
  13. package/transpiled/entities/entity.js.map +1 -1
  14. package/transpiled/entities/factory.d.ts +5 -0
  15. package/transpiled/entities/factory.js +6 -2
  16. package/transpiled/entities/factory.js.map +1 -1
  17. package/transpiled/event.d.ts +2 -2
  18. package/transpiled/event.js +6 -1
  19. package/transpiled/event.js.map +1 -1
  20. package/transpiled/exceptions.d.ts +19 -0
  21. package/transpiled/exceptions.js +74 -2
  22. package/transpiled/exceptions.js.map +1 -1
  23. package/transpiled/index.d.ts +2 -1
  24. package/transpiled/index.js +2 -1
  25. package/transpiled/index.js.map +1 -1
  26. package/transpiled/{outbox/outbox.d.ts → outbox.d.ts} +6 -7
  27. package/transpiled/outbox.js +424 -0
  28. package/transpiled/outbox.js.map +1 -0
  29. package/transpiled/query/options.js +1 -1
  30. package/transpiled/query/options.js.map +1 -1
  31. package/transpiled/receiver.js +14 -1
  32. package/transpiled/receiver.js.map +1 -1
  33. package/transpiled/remote.js +2 -3
  34. package/transpiled/remote.js.map +1 -1
  35. package/transpiled/state.d.ts +1 -1
  36. package/transpiled/trail.d.ts +49 -0
  37. package/transpiled/trail.js +98 -0
  38. package/transpiled/trail.js.map +1 -0
  39. package/transpiled/types/bindings.d.ts +22 -0
  40. package/transpiled/types/extensions.d.ts +13 -2
  41. package/transpiled/types/message.d.ts +5 -0
  42. package/transpiled/types/outbox.d.ts +29 -3
  43. package/transpiled/types/request.d.ts +5 -0
  44. package/transpiled/types/storages.d.ts +20 -0
  45. package/transpiled/outbox/index.d.ts +0 -1
  46. package/transpiled/outbox/index.js +0 -2
  47. package/transpiled/outbox/index.js.map +0 -1
  48. package/transpiled/outbox/outbox.js +0 -268
  49. package/transpiled/outbox/outbox.js.map +0 -1
@@ -0,0 +1,424 @@
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();
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
+ console.warn('Outbox publication failed', { row: row.id, destination: name, error });
201
+ }
202
+ finally {
203
+ inflight.delete(sending);
204
+ publishing.delete(row.id);
205
+ }
206
+ }
207
+ /**
208
+ * `comq` retries a publish for as long as the broker is down rather than rejecting, so an
209
+ * unbounded drain outlives any grace period.
210
+ *
211
+ */
212
+ async #drain() {
213
+ const inflight = [...this.#inflight.values()].flatMap((set) => [...set]);
214
+ if (inflight.length === 0)
215
+ return;
216
+ await Promise.race([Promise.allSettled(inflight), delay(DRAIN)]);
217
+ }
218
+ /**
219
+ * Reads what is due, publishes it, and marks everything this process has sent — what it just
220
+ * published and what the immediate path published since the last cycle. One cycle at a time.
221
+ *
222
+ */
223
+ #tick() {
224
+ if (this.#pumping)
225
+ return;
226
+ this.#pumping = true;
227
+ void this.#pump().finally(() => (this.#pumping = false));
228
+ }
229
+ async #pump() {
230
+ this.#assignment();
231
+ let page;
232
+ let after;
233
+ do {
234
+ page = await this.#read(after);
235
+ if (page.length === 0)
236
+ break;
237
+ // so a page is never read twice
238
+ after = page[page.length - 1]?.id;
239
+ /*
240
+ * A row is unpublished in the database until a cycle marks it, so a page includes what
241
+ * this replica is sending right now and what a failed marking left behind. Only this
242
+ * process knows either.
243
+ */
244
+ const rows = page.filter((row) => this.#destinations.some((destination) => this.#due(row, destination.name)));
245
+ if (rows.length > 0) {
246
+ console.debug('Outbox recovering unpublished rows', { count: rows.length });
247
+ // every row is given its chance, at every destination it is still outstanding for;
248
+ // what a broker refused stays outstanding there and comes back on a later cycle
249
+ await this.#awaited(rows.flatMap((row) => this.#publish(row)));
250
+ }
251
+ // a full page is a page that may have been cut short
252
+ } while (page.length === this.#batch);
253
+ await this.#mark();
254
+ }
255
+ /**
256
+ * Says when this replica has owned nothing for long enough that nothing is going to assign
257
+ * it anything.
258
+ *
259
+ * Owning no lane is ordinary for a moment — a replica that has just started has not been
260
+ * told yet — and is why nothing here refuses at boot: one cycle of it cannot be told from an
261
+ * atomicity that is absent. Ten in a row can, and what it means is that this outbox recovers
262
+ * nothing: a publication that failed is never retried, and that change is lost with the
263
+ * process that failed to make it.
264
+ *
265
+ * Said every ten cycles rather than once, so that it is still there to be found in a log
266
+ * read long after the deployment that broke it, and once when it is over.
267
+ */
268
+ #assignment() {
269
+ const lanes = this.#atom.slots(LANES);
270
+ if (lanes !== null && lanes.length > 0) {
271
+ if (this.#unassigned >= UNASSIGNED)
272
+ console.info('Outbox lanes assigned, recovery resumed');
273
+ this.#unassigned = 0;
274
+ return;
275
+ }
276
+ this.#unassigned++;
277
+ if (this.#unassigned % UNASSIGNED === 0)
278
+ console.warn('Outbox owns no lane and recovers nothing', {
279
+ cycles: this.#unassigned,
280
+ interval: this.#interval
281
+ });
282
+ }
283
+ /**
284
+ * One page of what is due. In a healthy system the first one is empty, every cycle — a row is
285
+ * due only if the process that wrote it failed to publish or died before marking it.
286
+ *
287
+ * Reading is suspended, not stopped, while this replica does not know which lanes are its
288
+ * own: the cycle keeps running and keeps marking, and reading resumes as soon as an
289
+ * assignment arrives. Reading without an assignment would be a different guarantee, where
290
+ * every replica publishes every stranded row.
291
+ *
292
+ * @param after the last id of the page before, so a page is never read twice
293
+ */
294
+ async #read(after) {
295
+ const lanes = this.#atom.slots(LANES);
296
+ if (lanes === null || lanes.length === 0)
297
+ return [];
298
+ return this.#storage
299
+ .outbox.pending(lanes, Date.now(), this.#batch, after)
300
+ .catch((error) => {
301
+ console.warn('Outbox read failed', { error });
302
+ return [];
303
+ });
304
+ }
305
+ /**
306
+ * Waits for what this cycle started, so that it marks what it sent rather than leaving it to
307
+ * the next one — but not past its own interval. A publication is never abandoned: it stays in
308
+ * flight, `#publishing` keeps a later cycle from sending it again, and the drain on close
309
+ * still waits for it. What is bounded is only how long a cycle waits before marking the rest,
310
+ * so that one destination with nothing to say cannot hold up the settling of another.
311
+ */
312
+ async #awaited(started) {
313
+ if (started.length === 0)
314
+ return;
315
+ await Promise.race([Promise.allSettled(started), delay(this.#interval)]);
316
+ }
317
+ /**
318
+ * One batched write for many rows, which is why the ids are held in memory rather than
319
+ * marked one by one. Ids that fail to be marked are kept and retried; a row that is never
320
+ * marked is simply published again, which is within the contract.
321
+ *
322
+ * Rows are grouped by the destinations that completed for them, so the ordinary case — every
323
+ * destination landing in the same window — is one group and one write, as it was when there
324
+ * was only ever one. A second write happens where the destinations diverged, which is the
325
+ * failure this exists for.
326
+ */
327
+ async #mark() {
328
+ for (const [destinations, ids] of this.#groups())
329
+ await this.#settle(destinations, ids);
330
+ }
331
+ /** @private */
332
+ async #settle(destinations, ids) {
333
+ try {
334
+ await this.#storage.outbox.settle(ids, destinations);
335
+ }
336
+ catch (error) {
337
+ console.warn('Outbox marking failed', { count: ids.length, error });
338
+ return;
339
+ }
340
+ for (const destination of destinations) {
341
+ const published = this.#published.get(destination);
342
+ for (const id of ids)
343
+ published.delete(id);
344
+ }
345
+ }
346
+ /**
347
+ * What has been published since the last cycle, as rows sharing the destinations that
348
+ * completed for them.
349
+ */
350
+ #groups() {
351
+ /** the destinations that completed for an id, in the order the destinations are held */
352
+ const completed = new Map();
353
+ for (const [destination, ids] of this.#published)
354
+ for (const id of ids) {
355
+ const names = completed.get(id);
356
+ if (names === undefined)
357
+ completed.set(id, [destination]);
358
+ else
359
+ names.push(destination);
360
+ }
361
+ const groups = new Map();
362
+ for (const [id, destinations] of completed) {
363
+ const key = destinations.join(SEPARATOR);
364
+ const group = groups.get(key);
365
+ if (group === undefined)
366
+ groups.set(key, [destinations, [id]]);
367
+ else
368
+ group[1].push(id);
369
+ }
370
+ return [...groups.values()];
371
+ }
372
+ /**
373
+ * A lane this replica currently owns, so that in steady state it settles its own rows
374
+ * before it ever reads them. Any lane at all when it owns none: the row still has to be
375
+ * written, and whoever ends up owning that lane will pump it.
376
+ *
377
+ */
378
+ #lane() {
379
+ const owned = this.#atom.slots(LANES);
380
+ return owned === null || owned.length === 0
381
+ ? Math.floor(Math.random() * LANES)
382
+ : owned[Math.floor(Math.random() * owned.length)];
383
+ }
384
+ }
385
+ function number(variable, declared, fallback) {
386
+ if (declared !== undefined)
387
+ return declared;
388
+ const value = Number(environment.get(variable));
389
+ return Number.isNaN(value) || value <= 0 ? fallback : value;
390
+ }
391
+ async function delay(ms) {
392
+ return new Promise((resolve) => {
393
+ setTimeout(resolve, ms).unref();
394
+ });
395
+ }
396
+ /**
397
+ * Constant, never configuration: rows carry their lane, so lowering this would leave rows in
398
+ * lanes nobody reads any more. It is also the ceiling on replicas of one component, and a
399
+ * power of two so that the common replica counts divide evenly.
400
+ */
401
+ export const LANES = 128;
402
+ /** one cycle reads, publishes and marks; in steady state it finds nothing to read */
403
+ /**
404
+ * Cycles owning nothing before that is said out loud, and between one saying and the next.
405
+ * Long enough that a replica which has just started, or one whose assignment is being redrawn,
406
+ * says nothing at all.
407
+ */
408
+ const UNASSIGNED = 10;
409
+ const INTERVAL = 5000;
410
+ /**
411
+ * `gap = interval * K`. Not a steady-state necessity — a replica writes into a lane it owns
412
+ * and marks what it published — but a guard for when a lane changes hands between the write
413
+ * and the settle. Two cycles of separation, plus one of margin.
414
+ */
415
+ const K = 3;
416
+ /** how many rows one read brings back; the pump reads on while a page comes back full */
417
+ const BATCH = 200;
418
+ const DRAIN = 10_000;
419
+ /** publications in flight at once, per destination */
420
+ const INFLIGHT = 1000;
421
+ const PUBLISHED = 10_000;
422
+ /** what a group of destinations is keyed by; no name can hold it */
423
+ const SEPARATOR = '\u0000';
424
+ //# sourceMappingURL=outbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outbox.js","sourceRoot":"","sources":["../source/outbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAY7C;;;;;;;;;;GAUG;AACH,MAAM,OAAO,MAAO,SAAQ,SAAS;IAC1B,aAAa,CAAe;IAC5B,QAAQ,CAAqB;IAC7B,KAAK,CAAM;IAEX,IAAI,CAAQ;IACZ,SAAS,CAAQ;IACjB,MAAM,CAAQ;IACd,MAAM,CAAS;IAE1B;;;;SAIK;IAEH,oFAAoF;IAC3E,UAAU,GAAG,IAAI,GAAG,EAAuB,CAAA;IAEpD,8EAA8E;IACrE,SAAS,GAAG,IAAI,GAAG,EAA8B,CAAA;IAE1D,wFAAwF;IAC/E,WAAW,GAAG,IAAI,GAAG,EAAuB,CAAA;IAErD,MAAM,CAA4B;IAClC,IAAI,CAA0B;IAC9B,QAAQ,GAAG,KAAK,CAAA;IAEhB,6DAA6D;IAC7D,WAAW,GAAG,CAAC,CAAA;IACf,QAAQ,GAAG,KAAK,CAAA;IAEhB,sCAAsC;IACtC,YACE,YAA2B,EAC3B,OAA4B,EAC5B,IAAU,EACV,OAAO,GAAY,EAAE;QAErB,KAAK,EAAE,CAAA;QAEP,IAAI,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AA;AAEX,yFAAyF;AACzF,MAAM,KAAK,GAAG,GAAG,CAAA;AAEjB,MAAM,KAAK,GAAG,MAAM,CAAA;AAEpB,sDAAsD;AACtD,MAAM,QAAQ,GAAG,IAAI,CAAA;AACrB,MAAM,SAAS,GAAG,MAAM,CAAA;AAExB,oEAAoE;AACpE,MAAM,SAAS,GAAG,QAAQ,CAAA"}
@@ -20,7 +20,7 @@ function projection(projection, properties) {
20
20
  for (const property of projection)
21
21
  if (properties[property] === undefined)
22
22
  throw new QuerySyntaxException(`Projection property '${property}' is not defined`);
23
- for (const property of ['VERSION', 'CREATED', 'UPDATED', 'DELETED'])
23
+ for (const property of ['VERSION', 'CREATED', 'UPDATED', 'DELETED', 'REGION'])
24
24
  if (!projection.includes(property))
25
25
  projection.push(property);
26
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../../source/query/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAIvD,MAAM,UAAU,OAAO,CAAC,KAA0B,EAAE,UAAsB;IACxE,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;IAEvE,IAAI,KAAK,CAAC,UAAU,KAAK,SAAS;QAAE,UAAU,CAAC,KAAK,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;IAE5E,OAAO,KAAgB,CAAA;AACzB,CAAC;AAED,SAAS,IAAI,CAAC,IAAc,EAAE,UAAsB;IAClD,MAAM,MAAM,GAA4B,EAAE,CAAA;IAE1C,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;QAC3B,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAEhD,IAAI,UAAU,CAAC,QAAQ,CAAC,KAAK,SAAS;YACpC,MAAM,I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CAAC,GAAG,CAAC,CAAA;QAEhD,IAAI,UAAU,CAAC,QAAQ,CAAC,KAAK,SAAS;YACpC,MAAM,IAAI,oBAAoB,CAAC,kBAAkB,QAAQ,kBAAkB,CAAC,CAAA;QAE9E,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,SAAS,IAAI,KAAK,CAAC,CAAC,CAAA;IAC7C,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,SAAS,UAAU,CAAC,UAAoB,EAAE,UAAsB;IAC9D,KAAK,MAAM,QAAQ,IAAI,UAAU;QAC/B,IAAI,UAAU,CAAC,QAAQ,CAAC,KAAK,SAAS;YACpC,MAAM,IAAI,oBAAoB,CAAC,wBAAwB,QAAQ,kBAAkB,CAAC,CAAA;IAEtF,KAAK,MAAM,QAAQ,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC;QAC3E,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAAE,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AACjE,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { console, decode, run } from 'openspan';
2
2
  import { add } from '@toa.io/generic';
3
3
  import { Connector } from './connector.js';
4
+ import * as trail from './trail.js';
4
5
  export class Receiver extends Connector {
5
6
  #conditioned;
6
7
  #adaptive;
@@ -50,7 +51,12 @@ export class Receiver extends Connector {
50
51
  }
51
52
  /** @hot */
52
53
  async receive(message) {
53
- const { payload, telemetry, ...extensions } = message;
54
+ /*
55
+ * `trail` is taken out by name rather than left to `add`, which leaves an array the
56
+ * request already has alone and shares the deserialized one by reference where it does
57
+ * not — and validates neither.
58
+ */
59
+ const { payload, telemetry, trail: inbound, ...extensions } = message;
54
60
  if (this.#conditioned === true && (await this.#bridge?.condition(payload)) === false)
55
61
  return;
56
62
  const request = await this.#request(payload);
@@ -58,6 +64,13 @@ export class Receiver extends Connector {
58
64
  // set after `add`, so that a message field can not spoof the origin
59
65
  if (this.#origin !== undefined)
60
66
  request.source = this.#origin;
67
+ /*
68
+ * The event is a hop of its own. What an operator rewires to break a cycle is the
69
+ * subscription rather than the operation, so a chain that named only operations would not
70
+ * say how a component was re-entered. Refusing is left to `Component.invoke`, one hop
71
+ * later, which acquires and commits nothing before it.
72
+ */
73
+ request.trail = [...trail.received(inbound), trail.event(this.#destination)];
61
74
  // continue the trace from the producer span
62
75
  const remote = telemetry === undefined ? null : decode(telemetry);
63
76
  const task = async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"receiver.js","sourceRoot":"","sources":["../source/receiver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAoB,MAAM,UAAU,CAAA;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAgB1C,MAAM,OAAO,QAAS,SAAQ,SAAS;IAC5B,YAAY,CAAqB;IACjC,SAAS,CAAqB;IAC9B,SAAS,CAAQ;IACjB,MAAM,CAAQ;IACd,YAAY,CAAQ;IACpB,UAAU,CAAuB;IACjC,OAAO,CAAoB;IAC3B,MAAM,CAAW;IACjB,OAAO,CAAoB;IAC3B,SAAS,CAAa;IACtB,WAAW,CAAa;IAEjC,YAAmB,UAAsB,EAAE,KAAgB,EAAE,MAAe;QAC1E,KAAK,EAAE,CAAA;QAEP,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,UAAU,CAAA;QAEvD,IAAI,CAAC,YAAY,GAAG,WAAW,CAAA;QAC/B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,KAAK,IAAI,SAAS,CAAA;QAC3C,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,WAAW,IAAI,IAAI,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AE,CAAC,CAAC;YAClE,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;IACxB,CAAC;CACF"}
@@ -1,11 +1,10 @@
1
- import assert from 'node:assert';
2
1
  import { Component } from './component.js';
2
+ import { EndpointException } from './exceptions.js';
3
3
  export class Remote extends Component {
4
4
  kind = 'client';
5
5
  explain(endpoint) {
6
6
  if (!(endpoint in this.operations))
7
- // `assert.fail`, not `assert.ok`: the message is built only when it is needed
8
- assert.fail(`Endpoint '${endpoint}' is not provided by '${this.locator.id}'`);
7
+ throw new EndpointException(`'${endpoint}' is not provided by '${this.locator.id}'`);
9
8
  return this.operations[endpoint].explain();
10
9
  }
11
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"remote.js","sourceRoot":"","sources":["../source/remote.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAQ1C,MAAM,OAAO,MAAO,SAAQ,SAAqB;IAC5B,IAAI,GAAG,QAAiB,CAAA;IAEpC,OAAO,CAAC,QAAgB;QAC7B,IAAI,CAAC,CAAC,QAAQ,IAAI,IAAI,CAAC,UAAU,CAAC;YAChC,8EAA8E;YAC9E,MAAM,CAAC,IAAI,CAAC,aAAa,QAAQ,yBAAyB,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAA;QAE/E,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAA;IAC5C,CAAC;CACF"}
1
+ {"version":3,"file":"remote.js","sourceRoot":"","sources":["../source/remote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAQnD,MAAM,OAAO,MAAO,SAAQ,SAAqB;IAC5B,IAAI,GAAG,QAAiB,CAAA;IAEpC,OAAO,CAAC,QAAgB;QAC7B,IAAI,CAAC,CAAC,QAAQ,IAAI,IAAI,CAAC,UAAU,CAAC;YAChC,MAAM,IAAI,iBAAiB,CAAC,IAAI,QAAQ,yBAAyB,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAA;QAEtF,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAA;IAC5C,CAAC;CACF"}
@@ -3,7 +3,7 @@ import type { Readable } from 'node:stream';
3
3
  import type { Factory } from './entities/factory.js';
4
4
  import type { Entity } from './entities/entity.js';
5
5
  import type { Changeset } from './entities/changeset.js';
6
- import type { Outbox } from './outbox/outbox.js';
6
+ import type { Outbox } from './outbox.js';
7
7
  import type { Query, Record, Storage } from './types/storages.js';
8
8
  /**
9
9
  * What an operation acquires and commits. One method per scope a manifest may declare, which
@@ -0,0 +1,49 @@
1
+ /**
2
+ * How many times one hop may appear before the call is refused, and how long a chain may grow
3
+ * at all. Repetition is the signal and names the cycle; depth is the backstop for a chain that
4
+ * grows without repeating a hop, and it is what bounds the array on the wire.
5
+ */
6
+ export interface Limits {
7
+ repeats: number;
8
+ depth: number;
9
+ }
10
+ /**
11
+ * What the environment says, read where a component is built rather than once for the process,
12
+ * as the outbox reads its own — so a composition booted after a variable was set sees it.
13
+ *
14
+ * `TOA_TRAIL_REPEATS=0` refuses nothing: the chain is still stamped, carried and bounded. It is
15
+ * the off switch, and it exists because this refuses calls an application may be making today —
16
+ * a handshake written as `a > b > a > b > a` is three occurrences of one hop. A breaker with no
17
+ * way to open it is itself the outage.
18
+ */
19
+ export declare function limits(): Limits;
20
+ /** The chain that led to the invocation running now, where there is one. */
21
+ export declare function current(): string[] | undefined;
22
+ /** Runs `task` as the hop the chain now ends with. */
23
+ export declare function follow<T>(hops: string[], task: () => Promise<T>): Promise<T>;
24
+ /**
25
+ * The chain this hop makes, or a raise where it is one hop too many: a hop already taken
26
+ * `repeats` times is a cycle, and a chain past `depth` is one nothing meant to make. Both are
27
+ * permanent, so what hits one is set aside rather than tried again into the same loop.
28
+ *
29
+ * The chain is copied rather than appended to, which is what makes it a path down the call
30
+ * tree rather than a log of everything that happened — an operation calling one endpoint fifty
31
+ * times makes fifty chains of one hop, not one chain of fifty.
32
+ */
33
+ export declare function extend(inbound: unknown, hop: string, limits: Limits): string[];
34
+ /**
35
+ * How an event is named in a chain. The sigil is what tells it from an operation: the two are
36
+ * the same shape, a component may declare one of each under a single name, and `sync` is both
37
+ * the event every component inherits and an ordinary name for an operation.
38
+ *
39
+ * What an operator rewires to break a cycle is the subscription rather than the operation, so a
40
+ * chain that named only operations would not say how a component was re-entered.
41
+ */
42
+ export declare function event(destination: string): string;
43
+ /**
44
+ * What came off the wire, as a chain and nothing else. Neither the request contract nor a
45
+ * message validates this — a request is not validated at all once it is `authentic` — so a
46
+ * malformed one would otherwise become a `TypeError` where a named exception was contracted
47
+ * for. Bounding it is `extend`'s, one hop later, which is the only place the limits are known.
48
+ */
49
+ export declare function received(value: unknown): string[];