@nwire/app 0.8.0 → 0.9.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/README.md +29 -27
- package/dist/__tests__/create-app.test.d.ts +6 -0
- package/dist/__tests__/create-app.test.d.ts.map +1 -0
- package/dist/__tests__/create-app.test.js +130 -0
- package/dist/__tests__/create-app.test.js.map +1 -0
- package/dist/__tests__/define-plugin.test.js +2 -2
- package/dist/__tests__/define-plugin.test.js.map +1 -1
- package/dist/app.d.ts +2 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +2 -0
- package/dist/app.js.map +1 -1
- package/dist/create-app.d.ts +87 -0
- package/dist/create-app.d.ts.map +1 -0
- package/dist/create-app.js +231 -0
- package/dist/create-app.js.map +1 -0
- package/dist/framework-event-bus.d.ts +34 -22
- package/dist/framework-event-bus.d.ts.map +1 -1
- package/dist/framework-event-bus.js +80 -81
- package/dist/framework-event-bus.js.map +1 -1
- package/dist/framework-events.d.ts.map +1 -1
- package/dist/runtime.d.ts +185 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +197 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +6 -6
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createApp` — generic plugin-lifecycle composition root.
|
|
3
|
+
*
|
|
4
|
+
* Boots a Container + a FrameworkEventBus with the supplied plugins.
|
|
5
|
+
* Lightweight: no forge concepts (no Runtime, no actors, no workflows,
|
|
6
|
+
* no module dep graph). For the full forge experience use `createApp`
|
|
7
|
+
* from `@nwire/forge`, which composes on top of this primitive.
|
|
8
|
+
*
|
|
9
|
+
* What this does, in order, during `start()`:
|
|
10
|
+
*
|
|
11
|
+
* 1. Register every plugin synchronously — `setup(ctx)` runs; bindings
|
|
12
|
+
* declared via `ctx.provide()` are collected; framework subscriptions
|
|
13
|
+
* via `ctx.on()` are wired on the bus; boot/shutdown callbacks are
|
|
14
|
+
* captured into ordered lists.
|
|
15
|
+
* 2. Fire `AppRegistering` (series-bail). A vetoing subscriber aborts.
|
|
16
|
+
* 3. Boot every provided binding: call `lifecycle.boot()`, register the
|
|
17
|
+
* value on the container under its declared name. Failures abort.
|
|
18
|
+
* 4. Fire `AppBooting` (series-bail). A vetoing subscriber aborts.
|
|
19
|
+
* 5. Run each plugin's accumulated `boot` callbacks in registration order.
|
|
20
|
+
* 6. Fire `AppBooted` (parallel).
|
|
21
|
+
*
|
|
22
|
+
* `stop(reason?)`:
|
|
23
|
+
*
|
|
24
|
+
* 1. Fire `AppShuttingDown` (series-bail).
|
|
25
|
+
* 2. Run plugin `shutdown` callbacks in REVERSE registration order.
|
|
26
|
+
* 3. Call `lifecycle.shutdown(value)` on each provided binding (reverse).
|
|
27
|
+
* 4. Fire `AppShutdown` (parallel).
|
|
28
|
+
*
|
|
29
|
+
* The returned `App` satisfies `AppServable` from `@nwire/endpoint`, so
|
|
30
|
+
* `endpoint("api").serve(app).run()` works without any glue.
|
|
31
|
+
*/
|
|
32
|
+
import { createContainer } from "@nwire/container";
|
|
33
|
+
import { NoopLogger } from "@nwire/logger";
|
|
34
|
+
import { AppRegistering, AppBooting, AppBooted, AppReady, AppShuttingDown, AppShutdown, PluginRegistered, PluginBooting, PluginBooted, PluginShuttingDown, PluginShutdown, } from "./framework-events.js";
|
|
35
|
+
import { FrameworkEventBus } from "./framework-event-bus.js";
|
|
36
|
+
/**
|
|
37
|
+
* Build a generic Nwire app from plugin definitions. No forge concepts —
|
|
38
|
+
* use `@nwire/forge`'s `createApp` for the rich CQRS / actor / workflow
|
|
39
|
+
* surface.
|
|
40
|
+
*
|
|
41
|
+
* const app = createApp({
|
|
42
|
+
* appName: "users",
|
|
43
|
+
* plugins: [authPlugin, dbPlugin],
|
|
44
|
+
* });
|
|
45
|
+
* await app.start();
|
|
46
|
+
* // app.container.cradle.db is now resolvable
|
|
47
|
+
* await app.stop();
|
|
48
|
+
*/
|
|
49
|
+
export function createApp(options) {
|
|
50
|
+
const appName = options.appName;
|
|
51
|
+
const container = options.container ?? createContainer();
|
|
52
|
+
const logger = options.logger ?? new NoopLogger();
|
|
53
|
+
const bus = options.bus ?? new FrameworkEventBus(logger);
|
|
54
|
+
const plugins = options.plugins ?? [];
|
|
55
|
+
/**
|
|
56
|
+
* Captured per plugin during setup. Indexed by the plugin's position in
|
|
57
|
+
* `plugins` so the start/stop loops can re-associate.
|
|
58
|
+
*/
|
|
59
|
+
const provides = [];
|
|
60
|
+
const boots = [];
|
|
61
|
+
const shutdowns = [];
|
|
62
|
+
/** Booted provider values, indexed by their `name`. Populated in start(). */
|
|
63
|
+
const bootedValues = new Map();
|
|
64
|
+
// ─── 1. Synchronous register: run each plugin's setup closure now ─────
|
|
65
|
+
// Plugins contribute container bindings, framework subscriptions, and
|
|
66
|
+
// boot/shutdown callbacks via the captured-builder pattern.
|
|
67
|
+
plugins.forEach((plugin, pluginIdx) => {
|
|
68
|
+
const ctx = {
|
|
69
|
+
container,
|
|
70
|
+
bus,
|
|
71
|
+
provide(name, lifecycle) {
|
|
72
|
+
provides.push({
|
|
73
|
+
pluginIdx,
|
|
74
|
+
name,
|
|
75
|
+
lifecycle: lifecycle,
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
on(event, handler, priority) {
|
|
79
|
+
bus.on(event, handler, priority);
|
|
80
|
+
},
|
|
81
|
+
boot(fn) {
|
|
82
|
+
boots.push({ pluginIdx, fn });
|
|
83
|
+
},
|
|
84
|
+
shutdown(fn) {
|
|
85
|
+
shutdowns.push({ pluginIdx, fn });
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
// setup may be sync or async — we await during start(), not here, so
|
|
89
|
+
// the constructor returns immediately. Defer the call: setup returns
|
|
90
|
+
// a value/promise that start() awaits.
|
|
91
|
+
plugin.setup(ctx);
|
|
92
|
+
});
|
|
93
|
+
let started = false;
|
|
94
|
+
let stopped = false;
|
|
95
|
+
const start = async () => {
|
|
96
|
+
if (started)
|
|
97
|
+
return;
|
|
98
|
+
started = true;
|
|
99
|
+
// Per-plugin registered event — observable; no veto.
|
|
100
|
+
for (const plugin of plugins) {
|
|
101
|
+
await bus.fire(PluginRegistered, {
|
|
102
|
+
appName,
|
|
103
|
+
pluginName: plugin.name,
|
|
104
|
+
kind: "plugin",
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
// AppRegistering — interceptable.
|
|
108
|
+
const okReg = await bus.fire(AppRegistering, { appName });
|
|
109
|
+
if (!okReg) {
|
|
110
|
+
throw new Error(`createApp("${appName}"): AppRegistering vetoed by subscriber`);
|
|
111
|
+
}
|
|
112
|
+
// 2. Boot every provided binding; register the value on the container.
|
|
113
|
+
for (const { name, lifecycle } of provides) {
|
|
114
|
+
const value = await lifecycle.boot();
|
|
115
|
+
container.register(name, value);
|
|
116
|
+
bootedValues.set(name, value);
|
|
117
|
+
}
|
|
118
|
+
// 3. AppBooting — interceptable.
|
|
119
|
+
const okBoot = await bus.fire(AppBooting, { appName });
|
|
120
|
+
if (!okBoot) {
|
|
121
|
+
throw new Error(`createApp("${appName}"): AppBooting vetoed by subscriber`);
|
|
122
|
+
}
|
|
123
|
+
// 4. Per-plugin boot — interceptable + observed per plugin.
|
|
124
|
+
for (const { pluginIdx, fn } of boots) {
|
|
125
|
+
const plugin = plugins[pluginIdx];
|
|
126
|
+
const okPlug = await bus.fire(PluginBooting, {
|
|
127
|
+
appName,
|
|
128
|
+
pluginName: plugin.name,
|
|
129
|
+
kind: "plugin",
|
|
130
|
+
});
|
|
131
|
+
if (!okPlug) {
|
|
132
|
+
throw new Error(`createApp("${appName}"): plugin "${plugin.name}" boot vetoed by subscriber`);
|
|
133
|
+
}
|
|
134
|
+
const startedAt = performance.now();
|
|
135
|
+
await fn();
|
|
136
|
+
await bus.fire(PluginBooted, {
|
|
137
|
+
appName,
|
|
138
|
+
pluginName: plugin.name,
|
|
139
|
+
durationMs: performance.now() - startedAt,
|
|
140
|
+
kind: "plugin",
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
// 5. AppBooted — parallel observation.
|
|
144
|
+
await bus.fire(AppBooted, {
|
|
145
|
+
appName,
|
|
146
|
+
bootedAt: new Date().toISOString(),
|
|
147
|
+
});
|
|
148
|
+
// 6. AppReady — parallel observation. Endpoint fires this after the
|
|
149
|
+
// wire is listening; we fire here too for the standalone case.
|
|
150
|
+
await bus.fire(AppReady, {
|
|
151
|
+
appName,
|
|
152
|
+
readyAt: new Date().toISOString(),
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
const stop = async (reason) => {
|
|
156
|
+
if (stopped)
|
|
157
|
+
return;
|
|
158
|
+
stopped = true;
|
|
159
|
+
// AppShuttingDown — interceptable. Throwing fails the shutdown; the
|
|
160
|
+
// caller is responsible for hard-timeout SIGKILL via @nwire/endpoint.
|
|
161
|
+
await bus.fire(AppShuttingDown, { appName, reason });
|
|
162
|
+
// 1. Plugin shutdown callbacks (reverse registration order).
|
|
163
|
+
for (let i = shutdowns.length - 1; i >= 0; i--) {
|
|
164
|
+
const { pluginIdx, fn } = shutdowns[i];
|
|
165
|
+
const plugin = plugins[pluginIdx];
|
|
166
|
+
await bus.fire(PluginShuttingDown, {
|
|
167
|
+
appName,
|
|
168
|
+
pluginName: plugin.name,
|
|
169
|
+
kind: "plugin",
|
|
170
|
+
});
|
|
171
|
+
const startedAt = performance.now();
|
|
172
|
+
try {
|
|
173
|
+
await fn();
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
logger.error?.(`plugin "${plugin.name}" shutdown threw`, {
|
|
177
|
+
error: err?.message ?? String(err),
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
await bus.fire(PluginShutdown, {
|
|
181
|
+
appName,
|
|
182
|
+
pluginName: plugin.name,
|
|
183
|
+
durationMs: performance.now() - startedAt,
|
|
184
|
+
kind: "plugin",
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
// 2. Provided-binding shutdowns (reverse boot order).
|
|
188
|
+
for (let i = provides.length - 1; i >= 0; i--) {
|
|
189
|
+
const { name, lifecycle } = provides[i];
|
|
190
|
+
if (!lifecycle.shutdown)
|
|
191
|
+
continue;
|
|
192
|
+
const value = bootedValues.get(name);
|
|
193
|
+
if (value === undefined)
|
|
194
|
+
continue;
|
|
195
|
+
try {
|
|
196
|
+
await lifecycle.shutdown(value);
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
logger.error?.(`provider "${name}" shutdown threw`, {
|
|
200
|
+
error: err?.message ?? String(err),
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// 3. AppShutdown — parallel observation.
|
|
205
|
+
await bus.fire(AppShutdown, { appName });
|
|
206
|
+
};
|
|
207
|
+
return {
|
|
208
|
+
$nwireApp: true,
|
|
209
|
+
appName,
|
|
210
|
+
container,
|
|
211
|
+
bus,
|
|
212
|
+
plugins,
|
|
213
|
+
start,
|
|
214
|
+
stop,
|
|
215
|
+
boot: start,
|
|
216
|
+
shutdown: () => stop(),
|
|
217
|
+
dispatchFrameworkEvent: async (eventName, payload) => {
|
|
218
|
+
// Generic dispatch by name — used by @nwire/endpoint to fire
|
|
219
|
+
// wire-lifecycle events the bus has built-ins for. We look up the
|
|
220
|
+
// event in builtInLifecycleEvents; unknown names fire as parallel.
|
|
221
|
+
const { builtInLifecycleEvents } = await import("./framework-events.js");
|
|
222
|
+
const def = builtInLifecycleEvents.find((e) => e.name === eventName);
|
|
223
|
+
if (def)
|
|
224
|
+
return bus.fire(def, payload);
|
|
225
|
+
// Unknown event name — fire as a synthetic parallel event so observers
|
|
226
|
+
// still see it on the bus.
|
|
227
|
+
return bus.fire({ $kind: "framework-event", name: eventName, mode: "parallel" }, payload);
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=create-app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-app.js","sourceRoot":"","sources":["../src/create-app.ts"],"names":[],"m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,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAC;YACtE,MAAM,GAAG,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;YACrE,IAAI,GAAG;gBAAE,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YACvC,uEAAuE;YACvE,2BAA2B;YAC3B,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,CAAC;QAC5F,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -5,25 +5,29 @@
|
|
|
5
5
|
* and modules subscribe with `bus.on(Event, handler)`; the runtime fires
|
|
6
6
|
* events at the appropriate lifecycle points with `bus.fire(Event, payload)`.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* Internals: every event delegates to a `hook<TPayload>(name)` from
|
|
9
|
+
* `@nwire/hooks`. Subscribers attach as hook chain steps (series /
|
|
10
|
+
* series-bail) or hook listeners (parallel). Dispatch is `hook.run()` —
|
|
11
|
+
* no parallel subscription map. Telemetry, replay, .tap observation,
|
|
12
|
+
* cancellation all come from hooks substrate by construction.
|
|
9
13
|
*
|
|
10
|
-
*
|
|
11
|
-
* others; errors are logged via the supplied logger.
|
|
12
|
-
* series → sequential await; one failing stops the chain and throws.
|
|
13
|
-
* series-bail → sequential await; a handler returning `false` stops the
|
|
14
|
-
* chain cleanly (no throw) and `fire` returns false to
|
|
15
|
-
* signal "prevented". Returning anything else (including
|
|
16
|
-
* undefined/void) is treated as "ok, continue".
|
|
14
|
+
* Dispatch semantics come from the event's `mode`:
|
|
17
15
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* parallel → handlers fire as hook listeners (Promise.allSettled);
|
|
17
|
+
* one failing doesn't affect others; errors are logged.
|
|
18
|
+
* series → handlers fire as chain steps in priority order;
|
|
19
|
+
* one throwing stops the chain.
|
|
20
|
+
* series-bail → handlers fire as chain steps in priority order;
|
|
21
|
+
* returning `false` short-circuits (don't call next()).
|
|
22
|
+
* `fire()` returns false to signal "prevented".
|
|
20
23
|
*
|
|
21
24
|
* The bus lives in `@nwire/app` (the "managed Container with lifecycle"
|
|
22
25
|
* layer). `@nwire/forge` re-exports the same surface so consumers that
|
|
23
26
|
* pull from forge get one import line.
|
|
24
27
|
*/
|
|
25
|
-
import type
|
|
28
|
+
import { type Hook } from "@nwire/hooks";
|
|
26
29
|
import type { Logger } from "@nwire/logger";
|
|
30
|
+
import type { FrameworkEventDefinition } from "./framework-events.js";
|
|
27
31
|
/**
|
|
28
32
|
* Handler signature. The handler MAY:
|
|
29
33
|
* - return nothing → "continue"
|
|
@@ -56,18 +60,14 @@ export type FrameworkEventObserver = (record: FrameworkEventObservation) => void
|
|
|
56
60
|
* focused on the domain pipeline. Designed to be reusable — Studio, the
|
|
57
61
|
* orchestrator, and external plugins all hit the same surface.
|
|
58
62
|
*/
|
|
59
|
-
import { type Hook } from "@nwire/hooks";
|
|
60
63
|
export declare class FrameworkEventBus {
|
|
61
|
-
private readonly subs;
|
|
62
64
|
private readonly observers;
|
|
63
65
|
private readonly logger;
|
|
64
66
|
/**
|
|
65
|
-
* One hook per event name
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* `listHooks()` + scan + Studio see every framework event in the
|
|
70
|
-
* registry, not a replacement for the existing dispatcher.
|
|
67
|
+
* One hook per event name. Each event's subscribers attach as chain
|
|
68
|
+
* steps (series / series-bail) or listeners (parallel) on its hook;
|
|
69
|
+
* dispatch is `hook.run()`. `listHooks()` + scan + Studio see every
|
|
70
|
+
* framework event in the registry by construction.
|
|
71
71
|
*
|
|
72
72
|
* Runtime can pass an `adoptHook` callback in the constructor; each
|
|
73
73
|
* lazily-created hook is adopted so taps flow into the canonical
|
|
@@ -87,7 +87,7 @@ export declare class FrameworkEventBus {
|
|
|
87
87
|
readonly name: string;
|
|
88
88
|
}>;
|
|
89
89
|
});
|
|
90
|
-
/** Lazily create + adopt the per-event hook.
|
|
90
|
+
/** Lazily create + adopt the per-event hook. Bus dispatches through these. */
|
|
91
91
|
private ensureEventHook;
|
|
92
92
|
/**
|
|
93
93
|
* Subscribe to EVERY framework-event firing on this bus. Used by the
|
|
@@ -103,15 +103,27 @@ export declare class FrameworkEventBus {
|
|
|
103
103
|
* series-bail / series modes (higher runs first; default 0). Framework
|
|
104
104
|
* built-ins should subscribe at priority 100+; debug/observer plugins
|
|
105
105
|
* at -100 so they see the final post-mutation state.
|
|
106
|
+
*
|
|
107
|
+
* Attaches to the per-event hook: as a listener (parallel mode) or as
|
|
108
|
+
* a chain step (series / series-bail). The returned handle calls
|
|
109
|
+
* `hook.off()` to detach.
|
|
106
110
|
*/
|
|
107
111
|
on<TPayload>(event: FrameworkEventDefinition<TPayload>, handler: FrameworkEventHandler<TPayload>, priority?: number): () => void;
|
|
108
112
|
/**
|
|
109
113
|
* Fire a framework event. Resolves to `false` when a series-bail handler
|
|
110
114
|
* vetoed; `true` otherwise. The boolean is irrelevant for parallel /
|
|
111
|
-
* series modes and always returns `true` there
|
|
115
|
+
* series modes and always returns `true` there.
|
|
116
|
+
*
|
|
117
|
+
* Internally: delegates to the per-event hook's `.run()` (parallel /
|
|
118
|
+
* series) or `.runDetailed()` (series-bail, to detect "prevented"
|
|
119
|
+
* outcome from short-circuit). The hook's observability surface (.tap,
|
|
120
|
+
* StepObservation) lights up automatically.
|
|
112
121
|
*/
|
|
113
122
|
fire<TPayload>(event: FrameworkEventDefinition<TPayload>, payload: TPayload): Promise<boolean>;
|
|
114
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* Count subscribers for an event — diagnostic surface (Studio, tests).
|
|
125
|
+
* Sums chain steps and listeners attached to the per-event hook.
|
|
126
|
+
*/
|
|
115
127
|
subscriberCount(event: FrameworkEventDefinition): number;
|
|
116
128
|
}
|
|
117
129
|
//# sourceMappingURL=framework-event-bus.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"framework-event-bus.d.ts","sourceRoot":"","sources":["../src/framework-event-bus.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"framework-event-bus.d.ts","sourceRoot":"","sources":["../src/framework-event-bus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAQ,KAAK,IAAI,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAEnE;;;;;;;;;GASG;AACH,MAAM,MAAM,qBAAqB,CAAC,QAAQ,IAAI,CAC5C,OAAO,EAAE,QAAQ,KACd,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC;AAE9C;;;;;;;GAOG;AACH,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,QAAQ,GAAG,aAAa,CAAC;IACrD,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAAC;IACtC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AACD,MAAM,MAAM,sBAAsB,GAAG,CAAC,MAAM,EAAE,yBAAyB,KAAK,IAAI,CAAC;AAEjF;;;;GAIG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgC;IAC1D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;;;;;;;OASG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoC;IAC/D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAA6B;gBAGtD,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;QACP,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;QACvC;;;;;WAKG;QACH,MAAM,CAAC,EAAE,aAAa,CAAC;YAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAC9C;IASR,8EAA8E;IAC9E,OAAO,CAAC,eAAe;IASvB;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,EAAE,sBAAsB,GAAG,MAAM,IAAI;IAQpD,OAAO,CAAC,MAAM;IAgBd;;;;;;;;;OASG;IACH,EAAE,CAAC,QAAQ,EACT,KAAK,EAAE,wBAAwB,CAAC,QAAQ,CAAC,EACzC,OAAO,EAAE,qBAAqB,CAAC,QAAQ,CAAC,EACxC,QAAQ,GAAE,MAAU,GACnB,MAAM,IAAI;IAiCb;;;;;;;;;OASG;IACG,IAAI,CAAC,QAAQ,EACjB,KAAK,EAAE,wBAAwB,CAAC,QAAQ,CAAC,EACzC,OAAO,EAAE,QAAQ,GAChB,OAAO,CAAC,OAAO,CAAC;IAgCnB;;;OAGG;IACH,eAAe,CAAC,KAAK,EAAE,wBAAwB,GAAG,MAAM;CAMzD"}
|
|
@@ -5,40 +5,40 @@
|
|
|
5
5
|
* and modules subscribe with `bus.on(Event, handler)`; the runtime fires
|
|
6
6
|
* events at the appropriate lifecycle points with `bus.fire(Event, payload)`.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* Internals: every event delegates to a `hook<TPayload>(name)` from
|
|
9
|
+
* `@nwire/hooks`. Subscribers attach as hook chain steps (series /
|
|
10
|
+
* series-bail) or hook listeners (parallel). Dispatch is `hook.run()` —
|
|
11
|
+
* no parallel subscription map. Telemetry, replay, .tap observation,
|
|
12
|
+
* cancellation all come from hooks substrate by construction.
|
|
9
13
|
*
|
|
10
|
-
*
|
|
11
|
-
* others; errors are logged via the supplied logger.
|
|
12
|
-
* series → sequential await; one failing stops the chain and throws.
|
|
13
|
-
* series-bail → sequential await; a handler returning `false` stops the
|
|
14
|
-
* chain cleanly (no throw) and `fire` returns false to
|
|
15
|
-
* signal "prevented". Returning anything else (including
|
|
16
|
-
* undefined/void) is treated as "ok, continue".
|
|
14
|
+
* Dispatch semantics come from the event's `mode`:
|
|
17
15
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* parallel → handlers fire as hook listeners (Promise.allSettled);
|
|
17
|
+
* one failing doesn't affect others; errors are logged.
|
|
18
|
+
* series → handlers fire as chain steps in priority order;
|
|
19
|
+
* one throwing stops the chain.
|
|
20
|
+
* series-bail → handlers fire as chain steps in priority order;
|
|
21
|
+
* returning `false` short-circuits (don't call next()).
|
|
22
|
+
* `fire()` returns false to signal "prevented".
|
|
20
23
|
*
|
|
21
24
|
* The bus lives in `@nwire/app` (the "managed Container with lifecycle"
|
|
22
25
|
* layer). `@nwire/forge` re-exports the same surface so consumers that
|
|
23
26
|
* pull from forge get one import line.
|
|
24
27
|
*/
|
|
28
|
+
import { hook } from "@nwire/hooks";
|
|
25
29
|
/**
|
|
26
30
|
* The bus. Subscriptions and dispatch live here so an app's runtime stays
|
|
27
31
|
* focused on the domain pipeline. Designed to be reusable — Studio, the
|
|
28
32
|
* orchestrator, and external plugins all hit the same surface.
|
|
29
33
|
*/
|
|
30
|
-
import { hook } from "@nwire/hooks";
|
|
31
34
|
export class FrameworkEventBus {
|
|
32
|
-
subs = new Map();
|
|
33
35
|
observers = [];
|
|
34
36
|
logger;
|
|
35
37
|
/**
|
|
36
|
-
* One hook per event name
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* `listHooks()` + scan + Studio see every framework event in the
|
|
41
|
-
* registry, not a replacement for the existing dispatcher.
|
|
38
|
+
* One hook per event name. Each event's subscribers attach as chain
|
|
39
|
+
* steps (series / series-bail) or listeners (parallel) on its hook;
|
|
40
|
+
* dispatch is `hook.run()`. `listHooks()` + scan + Studio see every
|
|
41
|
+
* framework event in the registry by construction.
|
|
42
42
|
*
|
|
43
43
|
* Runtime can pass an `adoptHook` callback in the constructor; each
|
|
44
44
|
* lazily-created hook is adopted so taps flow into the canonical
|
|
@@ -53,13 +53,12 @@ export class FrameworkEventBus {
|
|
|
53
53
|
this.ensureEventHook(event.name);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
/** Lazily create + adopt the per-event hook.
|
|
56
|
+
/** Lazily create + adopt the per-event hook. Bus dispatches through these. */
|
|
57
57
|
ensureEventHook(eventName) {
|
|
58
58
|
let h = this.eventHooks.get(eventName);
|
|
59
59
|
if (h)
|
|
60
60
|
return h;
|
|
61
61
|
h = hook(`framework.event:${eventName}`);
|
|
62
|
-
h.use(async (_, next) => { await next(); }, { name: "dispatch" });
|
|
63
62
|
this.eventHooks.set(eventName, h);
|
|
64
63
|
this.adoptHook?.(h);
|
|
65
64
|
return h;
|
|
@@ -100,38 +99,54 @@ export class FrameworkEventBus {
|
|
|
100
99
|
* series-bail / series modes (higher runs first; default 0). Framework
|
|
101
100
|
* built-ins should subscribe at priority 100+; debug/observer plugins
|
|
102
101
|
* at -100 so they see the final post-mutation state.
|
|
102
|
+
*
|
|
103
|
+
* Attaches to the per-event hook: as a listener (parallel mode) or as
|
|
104
|
+
* a chain step (series / series-bail). The returned handle calls
|
|
105
|
+
* `hook.off()` to detach.
|
|
103
106
|
*/
|
|
104
107
|
on(event, handler, priority = 0) {
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
const eventHook = this.ensureEventHook(event.name);
|
|
109
|
+
if (event.mode === "parallel") {
|
|
110
|
+
const listener = async (payload) => {
|
|
111
|
+
try {
|
|
112
|
+
await handler(payload);
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
this.logger.error?.("framework-event handler threw (parallel)", {
|
|
116
|
+
event: event.name,
|
|
117
|
+
error: err?.message ?? String(err),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
eventHook.on(listener, { priority });
|
|
122
|
+
return () => eventHook.off(listener);
|
|
123
|
+
}
|
|
124
|
+
// series + series-bail both run as chain steps; series-bail returning
|
|
125
|
+
// false short-circuits by not calling next().
|
|
126
|
+
const step = async (ctx, next) => {
|
|
127
|
+
const result = await handler(ctx);
|
|
128
|
+
if (event.mode === "series-bail" && result === false) {
|
|
129
|
+
// Don't call next() — short-circuits the chain. fire() sees
|
|
130
|
+
// outcome === "prevented" via runDetailed.
|
|
114
131
|
return;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
current.splice(i, 1);
|
|
132
|
+
}
|
|
133
|
+
await next();
|
|
118
134
|
};
|
|
135
|
+
eventHook.use(step, { priority });
|
|
136
|
+
return () => eventHook.off(step);
|
|
119
137
|
}
|
|
120
138
|
/**
|
|
121
139
|
* Fire a framework event. Resolves to `false` when a series-bail handler
|
|
122
140
|
* vetoed; `true` otherwise. The boolean is irrelevant for parallel /
|
|
123
|
-
* series modes and always returns `true` there
|
|
141
|
+
* series modes and always returns `true` there.
|
|
142
|
+
*
|
|
143
|
+
* Internally: delegates to the per-event hook's `.run()` (parallel /
|
|
144
|
+
* series) or `.runDetailed()` (series-bail, to detect "prevented"
|
|
145
|
+
* outcome from short-circuit). The hook's observability surface (.tap,
|
|
146
|
+
* StepObservation) lights up automatically.
|
|
124
147
|
*/
|
|
125
148
|
async fire(event, payload) {
|
|
126
|
-
const handlers = (this.subs.get(event.name) ?? []);
|
|
127
|
-
// Observation surface — emit start + end taps via the per-event hook.
|
|
128
|
-
// Cheap (one closure invocation per fire) and adds the event to
|
|
129
|
-
// `listHooks()` for scan + Studio + CLI visibility.
|
|
130
149
|
const eventHook = this.ensureEventHook(event.name);
|
|
131
|
-
await eventHook.run(payload);
|
|
132
|
-
// Always notify observers — even when no subscribers exist for this
|
|
133
|
-
// event. The lifecycle is the signal worth recording; subscribers are
|
|
134
|
-
// an orthogonal concern (could be none in dev, several in prod).
|
|
135
150
|
const ts = new Date().toISOString();
|
|
136
151
|
const obsRec = (phase) => ({
|
|
137
152
|
eventName: event.name,
|
|
@@ -140,50 +155,34 @@ export class FrameworkEventBus {
|
|
|
140
155
|
phase,
|
|
141
156
|
ts,
|
|
142
157
|
});
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
for (const r of settled) {
|
|
151
|
-
if (r.status === "rejected") {
|
|
152
|
-
this.logger.error?.("framework-event handler threw (parallel)", {
|
|
153
|
-
event: event.name,
|
|
154
|
-
error: r.reason?.message ?? String(r.reason),
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
this.notify(obsRec("fired"));
|
|
159
|
-
return true;
|
|
160
|
-
}
|
|
161
|
-
case "series": {
|
|
162
|
-
for (const { handler } of handlers) {
|
|
163
|
-
await handler(payload);
|
|
164
|
-
}
|
|
165
|
-
this.notify(obsRec("fired"));
|
|
166
|
-
return true;
|
|
167
|
-
}
|
|
168
|
-
case "series-bail": {
|
|
169
|
-
for (const { handler } of handlers) {
|
|
170
|
-
const result = await handler(payload);
|
|
171
|
-
if (result === false) {
|
|
172
|
-
this.logger.info?.("framework-event prevented by handler", {
|
|
173
|
-
event: event.name,
|
|
174
|
-
});
|
|
175
|
-
this.notify(obsRec("prevented"));
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
this.notify(obsRec("fired"));
|
|
180
|
-
return true;
|
|
158
|
+
if (event.mode === "series-bail") {
|
|
159
|
+
const result = await eventHook.runDetailed(payload);
|
|
160
|
+
const fired = result.outcome === "completed";
|
|
161
|
+
if (!fired) {
|
|
162
|
+
this.logger.info?.("framework-event prevented by handler", {
|
|
163
|
+
event: event.name,
|
|
164
|
+
});
|
|
181
165
|
}
|
|
166
|
+
this.notify(obsRec(fired ? "fired" : "prevented"));
|
|
167
|
+
return fired;
|
|
182
168
|
}
|
|
169
|
+
// parallel + series: hook.run handles dispatch; listener errors in
|
|
170
|
+
// parallel mode are swallowed by the listener wrapper in on(); chain
|
|
171
|
+
// errors in series mode propagate (matches old behaviour).
|
|
172
|
+
await eventHook.run(payload);
|
|
173
|
+
this.notify(obsRec("fired"));
|
|
174
|
+
return true;
|
|
183
175
|
}
|
|
184
|
-
/**
|
|
176
|
+
/**
|
|
177
|
+
* Count subscribers for an event — diagnostic surface (Studio, tests).
|
|
178
|
+
* Sums chain steps and listeners attached to the per-event hook.
|
|
179
|
+
*/
|
|
185
180
|
subscriberCount(event) {
|
|
186
|
-
|
|
181
|
+
const h = this.eventHooks.get(event.name);
|
|
182
|
+
if (!h)
|
|
183
|
+
return 0;
|
|
184
|
+
const counts = h.stepCounts();
|
|
185
|
+
return counts.chain + counts.listeners;
|
|
187
186
|
}
|
|
188
187
|
}
|
|
189
188
|
//# sourceMappingURL=framework-event-bus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"framework-event-bus.js","sourceRoot":"","sources":["../src/framework-event-bus.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"framework-event-bus.js","sourceRoot":"","sources":["../src/framework-event-bus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,IAAI,EAAa,MAAM,cAAc,CAAC;AAmC/C;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IACX,SAAS,GAA6B,EAAE,CAAC;IACzC,MAAM,CAAS;IAEhC;;;;;;;;;OASG;IACc,UAAU,GAAG,IAAI,GAAG,EAAyB,CAAC;IAC9C,SAAS,CAA8B;IAExD,YACE,MAAc,EACd,UASI,EAAE;QAEN,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI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