@fougere/core 0.4.0-alpha.0 → 0.5.0-alpha.0
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/dist/boot/Emissions.js +1 -1
- package/dist/boot/Emissions.js.map +1 -1
- package/dist/boot/binding.d.ts +1 -1
- package/dist/boot/binding.d.ts.map +1 -1
- package/dist/boot/bootstrap.d.ts.map +1 -1
- package/dist/boot/bootstrap.js +12 -4
- package/dist/boot/bootstrap.js.map +1 -1
- package/dist/boot/hosted.d.ts +29 -0
- package/dist/boot/hosted.d.ts.map +1 -0
- package/dist/boot/hosted.js +38 -0
- package/dist/boot/hosted.js.map +1 -0
- package/dist/boot/ownership.d.ts +0 -3
- package/dist/boot/ownership.d.ts.map +1 -1
- package/dist/boot/ownership.js.map +1 -1
- package/dist/boot/remote.d.ts +1 -1
- package/dist/boot/remote.d.ts.map +1 -1
- package/dist/boot/remote.js +1 -1
- package/dist/boot/remote.js.map +1 -1
- package/dist/boot/statement-drift.d.ts +24 -0
- package/dist/boot/statement-drift.d.ts.map +1 -0
- package/dist/boot/statement-drift.js +38 -0
- package/dist/boot/statement-drift.js.map +1 -0
- package/dist/boot/types.d.ts +15 -2
- package/dist/boot/types.d.ts.map +1 -1
- package/dist/contract/CallLog.d.ts +57 -0
- package/dist/contract/CallLog.d.ts.map +1 -0
- package/dist/contract/CallLog.js +2 -0
- package/dist/contract/CallLog.js.map +1 -0
- package/dist/contract.d.ts +8 -3
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +9 -2
- package/dist/contract.js.map +1 -1
- package/dist/dispatch/DispatchLifecycle.d.ts +9 -1
- package/dist/dispatch/DispatchLifecycle.d.ts.map +1 -1
- package/dist/dispatch/DispatchLifecycle.js +17 -2
- package/dist/dispatch/DispatchLifecycle.js.map +1 -1
- package/dist/dispatch/InFlight.d.ts +0 -1
- package/dist/dispatch/InFlight.d.ts.map +1 -1
- package/dist/dispatch/InFlight.js +0 -3
- package/dist/dispatch/InFlight.js.map +1 -1
- package/dist/effective-operation.d.ts.map +1 -1
- package/dist/effective-operation.js +4 -0
- package/dist/effective-operation.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +2 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +2 -0
- package/dist/node.js.map +1 -1
- package/dist/scan/bundling.d.ts +14 -0
- package/dist/scan/bundling.d.ts.map +1 -0
- package/dist/scan/bundling.js +26 -0
- package/dist/scan/bundling.js.map +1 -0
- package/dist/scan/declare.d.ts +71 -0
- package/dist/scan/declare.d.ts.map +1 -0
- package/dist/scan/declare.js +125 -0
- package/dist/scan/declare.js.map +1 -0
- package/dist/scan/handler-parser.js +0 -1
- package/dist/scan/handler-parser.js.map +1 -1
- package/dist/scan/scanner.d.ts.map +1 -1
- package/dist/scan/scanner.js +0 -1
- package/dist/scan/scanner.js.map +1 -1
- package/dist/scan/statement.d.ts +4 -0
- package/dist/scan/statement.d.ts.map +1 -0
- package/dist/scan/statement.js +112 -0
- package/dist/scan/statement.js.map +1 -0
- package/dist/wire/call.d.ts +12 -1
- package/dist/wire/call.d.ts.map +1 -1
- package/dist/wire/call.js +11 -0
- package/dist/wire/call.js.map +1 -1
- package/dist/wire/drift.d.ts +55 -0
- package/dist/wire/drift.d.ts.map +1 -0
- package/dist/wire/drift.js +121 -0
- package/dist/wire/drift.js.map +1 -0
- package/dist/wire/middleware.d.ts +1 -1
- package/dist/wire/middleware.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/boot/Emissions.ts +1 -1
- package/src/boot/HandlerFacade.ts +1 -1
- package/src/boot/binding.ts +1 -1
- package/src/boot/bootstrap.ts +12 -4
- package/src/boot/hosted.ts +77 -0
- package/src/boot/ownership.ts +1 -4
- package/src/boot/remote.ts +1 -1
- package/src/boot/statement-drift.ts +60 -0
- package/src/boot/types.ts +15 -2
- package/src/contract/CallLog.ts +55 -0
- package/src/contract.ts +12 -3
- package/src/dispatch/DispatchLifecycle.ts +22 -2
- package/src/dispatch/InFlight.ts +0 -4
- package/src/effective-operation.ts +4 -0
- package/src/index.ts +16 -2
- package/src/node.ts +2 -0
- package/src/scan/bundling.ts +25 -0
- package/src/scan/declare.ts +188 -0
- package/src/scan/handler-parser.ts +0 -1
- package/src/scan/scanner.ts +0 -1
- package/src/scan/statement.ts +126 -0
- package/src/wire/call.ts +13 -1
- package/src/wire/drift.ts +131 -0
- package/src/wire/middleware.ts +1 -1
- package/dist/boot/Lifecycle.d.ts +0 -4
- package/dist/boot/Lifecycle.d.ts.map +0 -1
- package/dist/boot/Lifecycle.js +0 -3
- package/dist/boot/Lifecycle.js.map +0 -1
- package/dist/scan/scan-cache.d.ts +0 -16
- package/dist/scan/scan-cache.d.ts.map +0 -1
- package/dist/scan/scan-cache.js +0 -99
- package/dist/scan/scan-cache.js.map +0 -1
- package/dist/wire/invocation.d.ts +0 -4
- package/dist/wire/invocation.d.ts.map +0 -1
- package/dist/wire/invocation.js +0 -3
- package/dist/wire/invocation.js.map +0 -1
- package/src/boot/Lifecycle.ts +0 -3
- package/src/scan/scan-cache.ts +0 -115
- package/src/wire/invocation.ts +0 -10
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type Change } from '@fougere/schema';
|
|
2
|
+
import type { IdentityCard } from './call.js';
|
|
3
|
+
/**
|
|
4
|
+
* What separates the copy a consumer holds from what the producer actually serves.
|
|
5
|
+
*
|
|
6
|
+
* It lives beside `IdentityCard` and not in `@fougere/testing` for the reason the card
|
|
7
|
+
* itself does: the subject is the card, and a second reader arrived — the dev panel, which
|
|
8
|
+
* must not drag a 426 KB faker in to compare two of them.
|
|
9
|
+
*/
|
|
10
|
+
export interface CardDrift {
|
|
11
|
+
frond: string;
|
|
12
|
+
/** A door the consumer calls that the producer no longer serves. */
|
|
13
|
+
missingDoors: string[];
|
|
14
|
+
/** An operation the consumer calls that the door no longer has. */
|
|
15
|
+
missingOps: {
|
|
16
|
+
door: string;
|
|
17
|
+
ops: string[];
|
|
18
|
+
}[];
|
|
19
|
+
/** A shape that moved under a door the consumer still calls. */
|
|
20
|
+
shapes: {
|
|
21
|
+
door: string;
|
|
22
|
+
changes: Change[];
|
|
23
|
+
}[];
|
|
24
|
+
/** A fact the consumer subscribes to whose shape moved, or that is gone. */
|
|
25
|
+
facts: {
|
|
26
|
+
fact: string;
|
|
27
|
+
changes: Change[] | 'gone';
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* What a consumer's synced copy no longer matches in what the producer serves.
|
|
32
|
+
*
|
|
33
|
+
* The gap TypeScript cannot see, and the only place the gradient genuinely lies: the code
|
|
34
|
+
* is identical in-process and split, but one side may have aged. `fougere sync` wrote the
|
|
35
|
+
* consumer's copy three weeks ago, the producer moved on, and it still compiles —
|
|
36
|
+
* production is where that is found today. This is what Pact sells; the material was
|
|
37
|
+
* already here, in `rpc.discover` and in `Card.diff`.
|
|
38
|
+
*
|
|
39
|
+
* Read in ONE direction on purpose: what the consumer holds, checked against what is
|
|
40
|
+
* served. A producer serving MORE than the consumer knows is not drift — it is a producer
|
|
41
|
+
* that moved forward without breaking anyone, which is the whole point of the order the
|
|
42
|
+
* repo already states (re-sync the readers, then deploy the sender).
|
|
43
|
+
*/
|
|
44
|
+
export declare function driftOf(mine: IdentityCard, theirs: IdentityCard, frond: string): CardDrift;
|
|
45
|
+
/** Whether anything at all separates the two cards. */
|
|
46
|
+
export declare function agrees(drift: CardDrift): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The drift, in the words a deploy needs.
|
|
49
|
+
*
|
|
50
|
+
* A fact says the order out loud, because the repo already states it as a rule and
|
|
51
|
+
* nothing enforced it: a fact is judged strictly, so a reader that has not been re-synced
|
|
52
|
+
* refuses what the sender now announces.
|
|
53
|
+
*/
|
|
54
|
+
export declare function explain(drift: CardDrift): string[];
|
|
55
|
+
//# sourceMappingURL=drift.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drift.d.ts","sourceRoot":"","sources":["../../src/wire/drift.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,MAAM,EAAyB,MAAM,iBAAiB,CAAC;AAC3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,mEAAmE;IACnE,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;IAC9C,gEAAgE;IAChE,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;IAC9C,4EAA4E;IAC5E,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;KAAE,EAAE,CAAC;CACvD;AAuBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAgC1F;AAED,uDAAuD;AACvD,wBAAgB,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAKhD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,EAAE,CAYlD"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Card } from '@fougere/schema';
|
|
2
|
+
/** Every door of a card, by name. */
|
|
3
|
+
function doorsOf(card, frond) {
|
|
4
|
+
const found = new Map();
|
|
5
|
+
for (const one of card.fronds) {
|
|
6
|
+
if (one.name !== frond)
|
|
7
|
+
continue;
|
|
8
|
+
for (const door of one.doors) {
|
|
9
|
+
found.set(door.name, { ops: new Set(door.ops.map((op) => op.name)), schema: door.schema });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return found;
|
|
13
|
+
}
|
|
14
|
+
function factsOf(card, frond) {
|
|
15
|
+
const found = new Map();
|
|
16
|
+
for (const one of card.fronds) {
|
|
17
|
+
if (one.name !== frond)
|
|
18
|
+
continue;
|
|
19
|
+
for (const fact of one.facts ?? [])
|
|
20
|
+
found.set(fact.name, fact.schema);
|
|
21
|
+
}
|
|
22
|
+
return found;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* What a consumer's synced copy no longer matches in what the producer serves.
|
|
26
|
+
*
|
|
27
|
+
* The gap TypeScript cannot see, and the only place the gradient genuinely lies: the code
|
|
28
|
+
* is identical in-process and split, but one side may have aged. `fougere sync` wrote the
|
|
29
|
+
* consumer's copy three weeks ago, the producer moved on, and it still compiles —
|
|
30
|
+
* production is where that is found today. This is what Pact sells; the material was
|
|
31
|
+
* already here, in `rpc.discover` and in `Card.diff`.
|
|
32
|
+
*
|
|
33
|
+
* Read in ONE direction on purpose: what the consumer holds, checked against what is
|
|
34
|
+
* served. A producer serving MORE than the consumer knows is not drift — it is a producer
|
|
35
|
+
* that moved forward without breaking anyone, which is the whole point of the order the
|
|
36
|
+
* repo already states (re-sync the readers, then deploy the sender).
|
|
37
|
+
*/
|
|
38
|
+
export function driftOf(mine, theirs, frond) {
|
|
39
|
+
const held = doorsOf(mine, frond);
|
|
40
|
+
const served = doorsOf(theirs, frond);
|
|
41
|
+
const drift = { frond, missingDoors: [], missingOps: [], shapes: [], facts: [] };
|
|
42
|
+
for (const [name, door] of held) {
|
|
43
|
+
const there = served.get(name);
|
|
44
|
+
if (!there) {
|
|
45
|
+
drift.missingDoors.push(name);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const missing = [...door.ops].filter((op) => !there.ops.has(op));
|
|
49
|
+
if (missing.length > 0)
|
|
50
|
+
drift.missingOps.push({ door: name, ops: missing.sort() });
|
|
51
|
+
if (door.schema && there.schema) {
|
|
52
|
+
// `Card.diff` never guesses a rename — a field gone plus a field appeared lands in
|
|
53
|
+
// `ambiguous`, and only a declaration settles it. Here nobody can declare one, so
|
|
54
|
+
// the pair is reported as it is and a human reads it.
|
|
55
|
+
const moved = Card.fromDescriptor(door.schema).diff(Card.fromDescriptor(there.schema));
|
|
56
|
+
if (moved.changes.length > 0)
|
|
57
|
+
drift.shapes.push({ door: name, changes: moved.changes });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const heldFacts = factsOf(mine, frond);
|
|
61
|
+
const servedFacts = factsOf(theirs, frond);
|
|
62
|
+
for (const [name, shape] of heldFacts) {
|
|
63
|
+
if (!servedFacts.has(name)) {
|
|
64
|
+
drift.facts.push({ fact: name, changes: 'gone' });
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const there = servedFacts.get(name);
|
|
68
|
+
if (!shape || !there)
|
|
69
|
+
continue;
|
|
70
|
+
const moved = Card.fromDescriptor(shape).diff(Card.fromDescriptor(there));
|
|
71
|
+
if (moved.changes.length > 0)
|
|
72
|
+
drift.facts.push({ fact: name, changes: moved.changes });
|
|
73
|
+
}
|
|
74
|
+
return drift;
|
|
75
|
+
}
|
|
76
|
+
/** Whether anything at all separates the two cards. */
|
|
77
|
+
export function agrees(drift) {
|
|
78
|
+
return drift.missingDoors.length === 0
|
|
79
|
+
&& drift.missingOps.length === 0
|
|
80
|
+
&& drift.shapes.length === 0
|
|
81
|
+
&& drift.facts.length === 0;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The drift, in the words a deploy needs.
|
|
85
|
+
*
|
|
86
|
+
* A fact says the order out loud, because the repo already states it as a rule and
|
|
87
|
+
* nothing enforced it: a fact is judged strictly, so a reader that has not been re-synced
|
|
88
|
+
* refuses what the sender now announces.
|
|
89
|
+
*/
|
|
90
|
+
export function explain(drift) {
|
|
91
|
+
const lines = [];
|
|
92
|
+
for (const door of drift.missingDoors)
|
|
93
|
+
lines.push(`${drift.frond}.${door} — you call it, it is not served`);
|
|
94
|
+
for (const { door, ops } of drift.missingOps)
|
|
95
|
+
lines.push(`${drift.frond}.${door} — gone: ${ops.join(', ')}`);
|
|
96
|
+
for (const { door, changes } of drift.shapes) {
|
|
97
|
+
for (const change of changes)
|
|
98
|
+
lines.push(`${drift.frond}.${door} — ${describe(change)}`);
|
|
99
|
+
}
|
|
100
|
+
for (const { fact, changes } of drift.facts) {
|
|
101
|
+
if (changes === 'gone') {
|
|
102
|
+
lines.push(`${fact} — you subscribe to it, it is no longer announced`);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
for (const change of changes)
|
|
106
|
+
lines.push(`${fact} — ${describe(change)} → re-sync and deploy the readers, THEN the sender`);
|
|
107
|
+
}
|
|
108
|
+
return lines;
|
|
109
|
+
}
|
|
110
|
+
function describe(change) {
|
|
111
|
+
switch (change.kind) {
|
|
112
|
+
case 'added': return `+ ${change.field}${change.required ? ' (required)' : ''}`;
|
|
113
|
+
case 'removed': return `- ${change.field}`;
|
|
114
|
+
case 'renamed': return `${change.from} → ${change.to}`;
|
|
115
|
+
case 'retyped': return `${change.field}: ${[...change.from].join('|')} → ${[...change.to].join('|')}`;
|
|
116
|
+
case 'reshaped': return `${change.field}: its bounds moved`;
|
|
117
|
+
case 'required': return `${change.field}: ${change.from ? 'no longer' : 'now'} required`;
|
|
118
|
+
case 'restated': return `${change.field}: its ${change.axis} moved`;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=drift.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drift.js","sourceRoot":"","sources":["../../src/wire/drift.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAsC,MAAM,iBAAiB,CAAC;AAsB3E,qCAAqC;AACrC,SAAS,OAAO,CAAC,IAAkB,EAAE,KAAa;IAChD,MAAM,KAAK,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CAAC;QACvD,KAAK,SAAS,CAAC,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,KAAK,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACtG,KAAK,UAAU,CAAC,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,oBAAoB,CAAC;QAC5D,KAAK,UAAU,CAAC,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC;QACzF,KAAK,UAAU,CAAC,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,SAAS,MAAM,CAAC,IAAI,QAAQ,CAAC;IACtE,CAAC;AACH,CAAC"}
|
|
@@ -18,7 +18,7 @@ export interface OperationContext {
|
|
|
18
18
|
/** Extensible bag — middlewares deposit data here (user, permissions, etc.). */
|
|
19
19
|
state: Record<string, unknown>;
|
|
20
20
|
/** Transport-agnostic invocation context (params, query, body, state). */
|
|
21
|
-
invocation?: import('
|
|
21
|
+
invocation?: import('../contract/Invocation.js').InvocationContext;
|
|
22
22
|
}
|
|
23
23
|
export type AppNext = () => Promise<unknown>;
|
|
24
24
|
export type AppMiddleware = (ctx: OperationContext, next: AppNext) => Promise<unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/wire/middleware.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,MAAM,WAAW,gBAAgB;IAC/B,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,SAAS,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,0EAA0E;IAC1E,UAAU,CAAC,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/wire/middleware.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,MAAM,WAAW,gBAAgB;IAC/B,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,SAAS,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,0EAA0E;IAC1E,UAAU,CAAC,EAAE,OAAO,2BAA2B,EAAE,iBAAiB,CAAC;CACpE;AAED,MAAM,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;AAC7C,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAIvF;;GAEG;AACH,wBAAgB,cAAc,CAC5B,WAAW,EAAE,aAAa,EAAE,EAC5B,GAAG,EAAE,gBAAgB,EACrB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,OAAO,CAAC,CASlB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fougere/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-alpha.0",
|
|
4
4
|
"description": "The core — scan, call contract, façades, remote stand-ins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fougere",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@typescript/typescript6": "^6.0.2",
|
|
58
58
|
"dequal": "^2.0.3",
|
|
59
|
-
"@fougere/container": "0.
|
|
60
|
-
"@fougere/schema": "0.
|
|
59
|
+
"@fougere/container": "0.5.0-alpha.0",
|
|
60
|
+
"@fougere/schema": "0.5.0-alpha.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/node": "^22.0.0"
|
package/src/boot/Emissions.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Container } from '@fougere/container';
|
|
|
3
3
|
import { validationErrorsOf } from '../wire/errors.js';
|
|
4
4
|
import { emitKeyOf, factsAnnouncedBy } from '../emit.js';
|
|
5
5
|
import { ambient } from '#ambient';
|
|
6
|
-
import { EMPTY_INVOCATION } from '../
|
|
6
|
+
import { EMPTY_INVOCATION } from '../contract/Invocation.js';
|
|
7
7
|
import type { Logger } from '../builtins/logger.js';
|
|
8
8
|
import type { Fronds } from '../scan/Fronds.js';
|
|
9
9
|
import type { OperationsMap } from '../wire/operation.js';
|
|
@@ -8,7 +8,7 @@ import { repositoryKeyOf } from '../prefab/repository.js';
|
|
|
8
8
|
import { targetOf } from '../prefab/prefab.js';
|
|
9
9
|
import type { OperationContract, OperationsMap } from '../wire/operation.js';
|
|
10
10
|
import type { EffectiveOperation, EffectiveOperationsMap } from '../effective-operation.js';
|
|
11
|
-
import type { InvocationContext } from '../
|
|
11
|
+
import type { InvocationContext } from '../contract/Invocation.js';
|
|
12
12
|
import type { Emissions } from './Emissions.js';
|
|
13
13
|
import type { Logger } from '../builtins/logger.js';
|
|
14
14
|
import type { EntityEntry, HandlerEntry, PresenterEntry } from '../scan/frond.js';
|
package/src/boot/binding.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* load-bearing, since the fall-through would otherwise hand it the caller's body.
|
|
8
8
|
*/
|
|
9
9
|
import type { ParsedParam } from '../scan/handler-parser.js';
|
|
10
|
-
import type { InvocationContext } from '../
|
|
10
|
+
import type { InvocationContext } from '../contract/Invocation.js';
|
|
11
11
|
import { lowerFirst } from '@fougere/schema';
|
|
12
12
|
|
|
13
13
|
// ── Types ─────────────────────────────────────
|
package/src/boot/bootstrap.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Container } from '@fougere/container';
|
|
2
2
|
import { lowerFirst, type SchemaView } from '@fougere/schema';
|
|
3
3
|
import type { EntityEntry, HandlerEntry, PresenterEntry } from '../scan/frond.js';
|
|
4
|
+
import { hostedBy } from './hosted.js';
|
|
4
5
|
import type { AuthRuntime } from './auth.js';
|
|
5
6
|
import type { CreateAppOptions, App } from './types.js';
|
|
6
7
|
import type { AppMiddleware } from '../wire/middleware.js';
|
|
@@ -106,11 +107,11 @@ export async function createApp(options: CreateAppOptions): Promise<App> {
|
|
|
106
107
|
container.register('Config', Config, { lifetime: 'singleton' });
|
|
107
108
|
log.debug('builtins registered (Logger, Config)');
|
|
108
109
|
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
//
|
|
110
|
+
// What this app hosts is HANDED IN — stated, scanned, or both (`hostedBy`). Producing
|
|
111
|
+
// it may read a disk; consuming it never does, which is the whole reason this file names
|
|
112
|
+
// no builtin and a Worker can run what it builds.
|
|
112
113
|
const scanStart = performance.now();
|
|
113
|
-
const { fronds, diagnostics } = await (
|
|
114
|
+
const { fronds, diagnostics } = await hostedBy(options);
|
|
114
115
|
const operationModel = resolveEffectiveOperations(fronds, {
|
|
115
116
|
diagnostics,
|
|
116
117
|
remotes: options.remotes,
|
|
@@ -786,6 +787,10 @@ export async function createApp(options: CreateAppOptions): Promise<App> {
|
|
|
786
787
|
// What this app publishes, straight from fougere.config.ts — the doors read it,
|
|
787
788
|
// so an undeclared adapter serves nothing whatever a host mounted.
|
|
788
789
|
adapters: options.adapters ?? {},
|
|
790
|
+
// Where a call goes, as DECLARED. Kept because a reader needs it beside what the
|
|
791
|
+
// runtime OBSERVED — `rpc.topology` calls a frond remote because it answered, never
|
|
792
|
+
// because a key said so, and the two disagree exactly when something is misconfigured.
|
|
793
|
+
remotes: Object.freeze({ ...(options.remotes ?? {}) }),
|
|
789
794
|
dispatch: (call) => dispatcher.dispatch(call),
|
|
790
795
|
local: localDispatcher,
|
|
791
796
|
resolve,
|
|
@@ -814,6 +819,9 @@ export async function createApp(options: CreateAppOptions): Promise<App> {
|
|
|
814
819
|
));
|
|
815
820
|
},
|
|
816
821
|
extensions: () => appLifecycle.names(),
|
|
822
|
+
observe(observer) {
|
|
823
|
+
return dispatchLifecycle.add(observer);
|
|
824
|
+
},
|
|
817
825
|
use(...args: [AppMiddleware] | [string, AppMiddleware]): void {
|
|
818
826
|
if (typeof args[0] === 'string') {
|
|
819
827
|
const [entity, mw] = args as [string, AppMiddleware];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What this app hosts — what it STATED, or what a scan FOUND.
|
|
3
|
+
*
|
|
4
|
+
* The PRESENCE of the key is the decision, the way `remotes:` states a topology: an app
|
|
5
|
+
* that passes `fronds:` is saying "do not scan", and one that passes `scan:` is handing
|
|
6
|
+
* over what a scanner read. There is no mode to configure because there is no third
|
|
7
|
+
* behaviour to name.
|
|
8
|
+
*
|
|
9
|
+
* Both may arrive, and then they MERGE — but only where a scan costs nothing at runtime.
|
|
10
|
+
* Under Nuxt the scan is a build artifact, so an app may state the frond it wants to own
|
|
11
|
+
* and leave the rest to what the build found. Anywhere the scan would run at START, half a
|
|
12
|
+
* statement buys nothing the whole one does: the disk is read either way.
|
|
13
|
+
*
|
|
14
|
+
* Merging is per frond NAME and per member. A stated frond wins outright on the members it
|
|
15
|
+
* names — stating `entities: [Post]` where a scan found `[Post, Author]` yields `[Post]`,
|
|
16
|
+
* because the point of stating is to decide. Empty is what "I named none" looks like, and
|
|
17
|
+
* `frond()` builds every member, so an empty one is filled rather than enforced.
|
|
18
|
+
*/
|
|
19
|
+
import type { FrondDescriptor, ScanResult } from '../scan/frond.js';
|
|
20
|
+
import { Fronds } from '../scan/Fronds.js';
|
|
21
|
+
|
|
22
|
+
/** Where an app's fronds come from — either, or both. */
|
|
23
|
+
export interface HostedSources {
|
|
24
|
+
/** What the app states. No disk was read, so no diagnostic can come from it. */
|
|
25
|
+
fronds?: readonly FrondDescriptor[];
|
|
26
|
+
/** What a scanner found, and what it could not do. */
|
|
27
|
+
scan?: ScanResult | (() => Promise<ScanResult> | ScanResult);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The members a stated frond takes from a scan when it named none of its own. */
|
|
31
|
+
type Fillable = 'providers' | 'entities' | 'handlers' | 'presenters' | 'collectors' | 'seeds';
|
|
32
|
+
|
|
33
|
+
/** A stated frond, completed by what a scan found under the same name. */
|
|
34
|
+
function completed(stated: FrondDescriptor, found: FrondDescriptor | undefined): FrondDescriptor {
|
|
35
|
+
if (!found) return stated;
|
|
36
|
+
|
|
37
|
+
// Written out rather than looped: a loop over the key union asks TypeScript to prove
|
|
38
|
+
// `found[k]` fits `stated[k]` for every k at once, which it cannot — and the cast that
|
|
39
|
+
// silences it would also silence a member added to the descriptor and forgotten here.
|
|
40
|
+
const fill = <K extends Fillable>(member: K): FrondDescriptor[K] =>
|
|
41
|
+
(stated[member].length === 0 ? found[member] : stated[member]);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
...found,
|
|
45
|
+
...stated,
|
|
46
|
+
providers: fill('providers'),
|
|
47
|
+
entities: fill('entities'),
|
|
48
|
+
handlers: fill('handlers'),
|
|
49
|
+
presenters: fill('presenters'),
|
|
50
|
+
collectors: fill('collectors'),
|
|
51
|
+
seeds: fill('seeds'),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** What the app hosts, and what the scan — if it ran — could not do. */
|
|
56
|
+
export async function hostedBy(sources: HostedSources): Promise<ScanResult> {
|
|
57
|
+
const scanned = sources.scan
|
|
58
|
+
? await (typeof sources.scan === 'function' ? sources.scan() : sources.scan)
|
|
59
|
+
: undefined;
|
|
60
|
+
|
|
61
|
+
if (!sources.fronds) {
|
|
62
|
+
if (!scanned) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
'createApp needs `fronds:` (what this app states) or `scan:` (what a scanner found). '
|
|
65
|
+
+ 'Neither was given, so nothing is hosted.',
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return scanned;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const found = scanned?.fronds ?? [];
|
|
73
|
+
const stated = sources.fronds.map((f) => completed(f, found.find((s) => s.name === f.name)));
|
|
74
|
+
const unstated = found.filter((f) => !sources.fronds!.some((s) => s.name === f.name));
|
|
75
|
+
|
|
76
|
+
return { fronds: Fronds.scanned([...stated, ...unstated]), diagnostics: scanned?.diagnostics ?? [] };
|
|
77
|
+
}
|
package/src/boot/ownership.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { lowerFirst
|
|
1
|
+
import { lowerFirst } from '@fougere/schema';
|
|
2
2
|
import type { FrondDescriptor, ProviderEntry } from '../scan/frond.js';
|
|
3
3
|
import { targetOf } from '../prefab/prefab.js';
|
|
4
4
|
import { ownedBy, repositoryKeyOf } from '../prefab/repository.js';
|
|
@@ -135,6 +135,3 @@ function entityOfOrmKey(dep: string): string | undefined {
|
|
|
135
135
|
const entity = lowerFirst(dep.slice(0, -'Orm'.length));
|
|
136
136
|
return ormKeyOf(entity) === dep ? entity : undefined;
|
|
137
137
|
}
|
|
138
|
-
|
|
139
|
-
/** Placeholder so the module's imports stay honest if a caller wants the entity list. */
|
|
140
|
-
export type { EntityConstructor };
|
package/src/boot/remote.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import type { FrondCall, Transport } from '../wire/call.js';
|
|
12
12
|
import { assertIdentityCard, RPC_ENTITY } from '../wire/call.js';
|
|
13
13
|
import { runMiddlewares, type AppMiddleware, type OperationContext } from '../wire/middleware.js';
|
|
14
|
-
import { EMPTY_INVOCATION, type InvocationContext } from '../
|
|
14
|
+
import { EMPTY_INVOCATION, type InvocationContext } from '../contract/Invocation.js';
|
|
15
15
|
import { FougereError, ErrorCode } from '../wire/errors.js';
|
|
16
16
|
import { Card, type SchemaView, type SchemaDescriptor } from '@fougere/schema';
|
|
17
17
|
import { DynamicFacade } from '../entry/DynamicFacade.js';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a STATED contract and the signature it is about have stopped agreeing.
|
|
3
|
+
*
|
|
4
|
+
* `frond.config.ts` states an operation's contract and wins over the scan — that order is
|
|
5
|
+
* deliberate, and it is the only answer for a method inherited from an installed base class
|
|
6
|
+
* the workspace scan cannot see. But winning silently is how a statement made about
|
|
7
|
+
* `publish(id: string)` keeps applying after the parameter was renamed to `postId`: the
|
|
8
|
+
* façade binds what the config said, the method receives `undefined`, and nothing anywhere
|
|
9
|
+
* says the two disagree.
|
|
10
|
+
*
|
|
11
|
+
* So this compares, and only where BOTH exist — a statement about a signature the scan
|
|
12
|
+
* never read is not drift, it is the case config was built for. It is a `warning` and not
|
|
13
|
+
* a refusal: the statement is still the author's word, and a boot that ran yesterday must
|
|
14
|
+
* not stop running because a parameter moved. What it must not do is stay quiet.
|
|
15
|
+
*/
|
|
16
|
+
import type { FrondDescriptor, HandlerEntry, ScanDiagnostic } from '../scan/frond.js';
|
|
17
|
+
import type { BindingPlan } from './binding.js';
|
|
18
|
+
import type { ParsedMethod } from '../scan/handler-parser.js';
|
|
19
|
+
|
|
20
|
+
/** The parameters a stated binding names, against the ones the method declares. */
|
|
21
|
+
function namesDisagreeing(stated: BindingPlan, signature: ParsedMethod): string[] {
|
|
22
|
+
const declared = new Set(signature.params.map((p: { name: string }) => p.name));
|
|
23
|
+
|
|
24
|
+
return stated.map((b) => b.name).filter((name) => !declared.has(name));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* What a frond's stated contracts no longer match.
|
|
29
|
+
*
|
|
30
|
+
* Read by `resolveEffectiveOperations`, so the same answer reaches `fougere check` and a
|
|
31
|
+
* boot — one comparison, two readers, no second opinion to drift on its own.
|
|
32
|
+
*/
|
|
33
|
+
export function statementDrift(frond: FrondDescriptor, handler: HandlerEntry): ScanDiagnostic[] {
|
|
34
|
+
const found: ScanDiagnostic[] = [];
|
|
35
|
+
|
|
36
|
+
for (const [name, override] of Object.entries(frond.operationsOverrides ?? {})) {
|
|
37
|
+
if (!override.binding) continue;
|
|
38
|
+
|
|
39
|
+
// The scan's own reading of this method. Absent means config is stating what nothing
|
|
40
|
+
// read — an installed base class, a handler outside the workspace — which is legal.
|
|
41
|
+
const signature = handler.operations.get(name)?.signature;
|
|
42
|
+
if (!signature) continue;
|
|
43
|
+
|
|
44
|
+
const orphans = namesDisagreeing(override.binding, signature);
|
|
45
|
+
if (orphans.length === 0) continue;
|
|
46
|
+
|
|
47
|
+
found.push({
|
|
48
|
+
severity: 'warning',
|
|
49
|
+
code: 'stated-binding-drifted',
|
|
50
|
+
filePath: handler.filePath,
|
|
51
|
+
frond: frond.name,
|
|
52
|
+
subject: `${handler.ctor.name}.${name}`,
|
|
53
|
+
message: `frond.config.ts binds ${orphans.map((o) => `\`${o}\``).join(', ')} on `
|
|
54
|
+
+ `${handler.ctor.name}.${name}, which declares (${signature.params.map((p: { name: string }) => p.name).join(', ')}). `
|
|
55
|
+
+ `The statement wins, so those parameters receive nothing.`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return found;
|
|
60
|
+
}
|
package/src/boot/types.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { Container } from '@fougere/container';
|
|
9
9
|
import type { Fronds } from '../scan/Fronds.js';
|
|
10
|
-
import type { ScanResult } from '../scan/frond.js';
|
|
10
|
+
import type { FrondDescriptor, ScanResult } from '../scan/frond.js';
|
|
11
11
|
import type { SchemaView } from '@fougere/schema';
|
|
12
12
|
import type { OrmFactory } from '../orm.js';
|
|
13
13
|
import type { AppMiddleware } from '../wire/middleware.js';
|
|
@@ -55,7 +55,16 @@ export interface CreateAppOptions {
|
|
|
55
55
|
* apart, and that is the point: it names no builtin, so a runtime without `node:fs`
|
|
56
56
|
* runs it. `root` and `fronds` used to live here — both were arguments to the scan.
|
|
57
57
|
*/
|
|
58
|
-
scan
|
|
58
|
+
scan?: ScanResult | (() => Promise<ScanResult> | ScanResult);
|
|
59
|
+
/**
|
|
60
|
+
* What this app STATES it hosts — `frond('blog', { entities: [Post] })`.
|
|
61
|
+
*
|
|
62
|
+
* Passing this and not `scan:` is how an app says "do not scan": nothing reads a disk,
|
|
63
|
+
* nothing loads `typescript`, and what was not named does not exist. Passing both fills
|
|
64
|
+
* the members left unnamed from what the scan found — the app's word wins, the way
|
|
65
|
+
* `frond.config.ts` wins over the scan one level down.
|
|
66
|
+
*/
|
|
67
|
+
fronds?: readonly FrondDescriptor[];
|
|
59
68
|
/**
|
|
60
69
|
* Remote fronds — label → address. What each remote hosts is discovered
|
|
61
70
|
* at the first miss (rpc.discover), never declared here.
|
|
@@ -140,6 +149,8 @@ export interface App extends DispatchPort {
|
|
|
140
149
|
* the answer is still "not here".
|
|
141
150
|
*/
|
|
142
151
|
adapters: Record<string, boolean | undefined>;
|
|
152
|
+
/** Where a call goes, as the config declared it — frond name to address. */
|
|
153
|
+
remotes: Readonly<Record<string, string>>;
|
|
143
154
|
/** Discovered fronds metadata. */
|
|
144
155
|
fronds: Fronds;
|
|
145
156
|
/** Resolve from root container (shortcut). */
|
|
@@ -253,6 +264,8 @@ export interface App extends DispatchPort {
|
|
|
253
264
|
*/
|
|
254
265
|
serveRpc(op: string, answer: RpcAnswer): void;
|
|
255
266
|
/** Register a global app middleware (runs on every operation). */
|
|
267
|
+
/** Watch every dispatch transition; the returned function unsubscribes. */
|
|
268
|
+
observe(observer: DispatchObserver): () => void;
|
|
256
269
|
use(middleware: AppMiddleware): void;
|
|
257
270
|
/** Register an app middleware scoped to a specific entity. */
|
|
258
271
|
use(entity: string, middleware: AppMiddleware): void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { DispatchEvent } from '../dispatch/DispatchEvent.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What crosses the door: the address, the route it took, and the verdict.
|
|
5
|
+
*
|
|
6
|
+
* It lives here rather than beside its producer for the reason `TopologyReport` does: it
|
|
7
|
+
* crosses a process boundary, so a reader that never installed `@fougere/calls` — the CLI
|
|
8
|
+
* — needs its shape, and putting it there is what produces a hand-copied duplicate.
|
|
9
|
+
*
|
|
10
|
+
* Never the body. Same rule the topology report states — a remote destination is named,
|
|
11
|
+
* not disclosed — and it holds here for the same reason: this answer leaves the process.
|
|
12
|
+
*/
|
|
13
|
+
export interface CallRecord {
|
|
14
|
+
/** Monotonic, and the whole cursor protocol: a reader asks for what is above its own. */
|
|
15
|
+
seq: number;
|
|
16
|
+
frond?: string;
|
|
17
|
+
entity: string;
|
|
18
|
+
operation: string;
|
|
19
|
+
surface?: string;
|
|
20
|
+
/** Known at `resolved`, so absent on a call that never found a route. */
|
|
21
|
+
route?: NonNullable<DispatchEvent['routeKind']>;
|
|
22
|
+
/**
|
|
23
|
+
* The traceparent the invocation carried, when one did.
|
|
24
|
+
*
|
|
25
|
+
* One panel reads one process, so this is what lets two of them be sewn: the process
|
|
26
|
+
* that sent and the process that executed share it, and the gap between their two
|
|
27
|
+
* durations IS the cost of the wire rather than a deduction.
|
|
28
|
+
*/
|
|
29
|
+
trace?: string;
|
|
30
|
+
/**
|
|
31
|
+
* The peer that established this call, when one did.
|
|
32
|
+
*
|
|
33
|
+
* A hosted frond serves several consumers, so its own ring mixes them: this is what
|
|
34
|
+
* separates them. Absent on a call nobody signed — a loopback dev boot has no identity.
|
|
35
|
+
*/
|
|
36
|
+
caller?: string;
|
|
37
|
+
startedAt: number;
|
|
38
|
+
/** Known at `settled`. */
|
|
39
|
+
ms?: number;
|
|
40
|
+
verdict: 'running' | 'ok' | 'failed';
|
|
41
|
+
refusal?: { code?: string; message: string };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* One page of the ring.
|
|
46
|
+
*
|
|
47
|
+
* `dropped` is what the ring could not keep — an absence is named rather than left to
|
|
48
|
+
* look like a quiet period.
|
|
49
|
+
*/
|
|
50
|
+
export interface CallPage {
|
|
51
|
+
calls: CallRecord[];
|
|
52
|
+
cursor: number;
|
|
53
|
+
inFlight: number;
|
|
54
|
+
dropped: number;
|
|
55
|
+
}
|
package/src/contract.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* is allowed in — measured, it imports no node builtin either.
|
|
10
10
|
*/
|
|
11
11
|
import { lowerFirst } from '@fougere/schema';
|
|
12
|
-
import { canonicalInvocation, type InvocationContext } from './
|
|
12
|
+
import { canonicalInvocation, type InvocationContext } from './contract/Invocation.js';
|
|
13
13
|
import type { FrondCall } from './wire/call.js';
|
|
14
14
|
|
|
15
15
|
export { FougereError, ErrorCode, validationErrorsOf } from './wire/errors.js';
|
|
@@ -17,14 +17,23 @@ export { FougereError, ErrorCode, validationErrorsOf } from './wire/errors.js';
|
|
|
17
17
|
// core's boot — reaching it through the main entry dragged the scanner into a bundle.
|
|
18
18
|
export { toPublicError } from './wire/http-error.js';
|
|
19
19
|
export type { FougereErrorOptions } from './wire/errors.js';
|
|
20
|
-
export { canonicalInvocation, EMPTY_INVOCATION } from './
|
|
21
|
-
export type { InvocationContext } from './
|
|
20
|
+
export { canonicalInvocation, EMPTY_INVOCATION } from './contract/Invocation.js';
|
|
21
|
+
export type { InvocationContext } from './contract/Invocation.js';
|
|
22
22
|
export { Invocation } from './contract/Invocation.js';
|
|
23
23
|
export type { InvocationInput } from './contract/Invocation.js';
|
|
24
24
|
export { Call } from './contract/Call.js';
|
|
25
25
|
export { RouteAddress } from './contract/RouteAddress.js';
|
|
26
26
|
export type { RouteAddressInput } from './contract/RouteAddress.js';
|
|
27
27
|
export type { FrondCall, Transport, SignedCall } from './wire/call.js';
|
|
28
|
+
export { MAX_BODY_BYTES } from './wire/call.js';
|
|
29
|
+
// The reserved entity, VALUE and not type: a consumer that wants to leave it alone — a
|
|
30
|
+
// call log ignoring its own reader — has to be able to name it.
|
|
31
|
+
export { RPC_ENTITY } from './wire/call.js';
|
|
32
|
+
export type { CallPage, CallRecord } from './contract/CallLog.js';
|
|
33
|
+
// The comparison of two cards, which a consumer runs about a producer — browser-safe on
|
|
34
|
+
// purpose: a panel showing the drift holds only the two cards, never the app.
|
|
35
|
+
export { driftOf, agrees, explain } from './wire/drift.js';
|
|
36
|
+
export type { CardDrift } from './wire/drift.js';
|
|
28
37
|
|
|
29
38
|
/**
|
|
30
39
|
* What `rpc.discover` answers. It belongs here and not to the runtime: the
|
|
@@ -2,10 +2,30 @@ import type { DispatchEvent, DispatchObserver } from './DispatchEvent.js';
|
|
|
2
2
|
|
|
3
3
|
/** Publishes dispatch transitions without participating in dispatch decisions. */
|
|
4
4
|
export class DispatchLifecycle {
|
|
5
|
+
private readonly observers: DispatchObserver[];
|
|
6
|
+
|
|
5
7
|
constructor(
|
|
6
|
-
|
|
8
|
+
observers: readonly DispatchObserver[] = [],
|
|
7
9
|
private readonly diagnose: (error: unknown, event: DispatchEvent) => void = () => {},
|
|
8
|
-
) {
|
|
10
|
+
) {
|
|
11
|
+
this.observers = [...observers];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Subscribe after the dispatcher was built, and get the unsubscription back.
|
|
16
|
+
*
|
|
17
|
+
* The list used to be settled at construction, so only the caller of `createApp` could
|
|
18
|
+
* observe — an extension, which runs in `up(app)`, could not. `app.use` already adds a
|
|
19
|
+
* middleware this late; this is its dual, and the pair is *participate* / *watch*.
|
|
20
|
+
*/
|
|
21
|
+
add(observer: DispatchObserver): () => void {
|
|
22
|
+
this.observers.push(observer);
|
|
23
|
+
|
|
24
|
+
return () => {
|
|
25
|
+
const at = this.observers.indexOf(observer);
|
|
26
|
+
if (at !== -1) this.observers.splice(at, 1);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
9
29
|
|
|
10
30
|
publish(event: DispatchEvent): void {
|
|
11
31
|
for (const observer of this.observers) {
|
package/src/dispatch/InFlight.ts
CHANGED