@nwire/hooks 0.8.0 → 0.9.1
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 +58 -637
- package/dist/hook.d.ts.map +1 -1
- package/dist/hook.js +60 -11
- package/dist/hook.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js.map +1 -1
- package/dist/types.d.ts +26 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,687 +1,108 @@
|
|
|
1
1
|
# @nwire/hooks
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
> subscription, plugin extension, and dev-tool tap in Nwire is built from one
|
|
5
|
-
> shape: a named hook that runs a koa-compose chain first, then fans out
|
|
6
|
-
> parallel listeners. Auditable, traceable, replayable, topology-aware.
|
|
3
|
+
The universal dispatch primitive. One `hook()` accepts both a sequential chain (`.use`) and parallel listeners (`.on`); every run is observable end-to-end and cancellable via `AbortSignal`.
|
|
7
4
|
|
|
8
5
|
```bash
|
|
9
6
|
pnpm add @nwire/hooks
|
|
10
7
|
```
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
## Why
|
|
13
10
|
|
|
14
|
-
|
|
11
|
+
Every framework reinvents the same three patterns: middleware chains, event listeners, lifecycle hooks. They all need ordering, cancellation, tracing, and replay. `@nwire/hooks` is the one substrate the rest of Nwire builds on — handlers, transports, plugin lifecycle, framework events all use the same primitive.
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
import { hook } from "@nwire/hooks";
|
|
18
|
-
|
|
19
|
-
const request = hook<{ url: string; user?: string }>("http.request");
|
|
20
|
-
|
|
21
|
-
request.use(async (ctx, next) => { ctx.user = await auth(ctx); await next(); });
|
|
22
|
-
request.use(async (ctx, next) => { /* metrics */ await next(); }, { priority: 100 });
|
|
23
|
-
request.on((ctx) => analytics.track(ctx), { when: "success" });
|
|
24
|
-
|
|
25
|
-
await request.run({ url: "/api/x" });
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Two attachment kinds, one primitive:
|
|
29
|
-
|
|
30
|
-
- **`.use(fn)`** — chain step. koa-compose-shaped `(ctx, next)`. Can mutate ctx.
|
|
31
|
-
Can short-circuit by not calling `next()`. Throws bubble up.
|
|
32
|
-
- **`.on(fn)`** — listener. Observer `(ctx)`. Cannot mutate. Cannot bail.
|
|
33
|
-
Fired in parallel via `Promise.allSettled` after the chain settles.
|
|
34
|
-
|
|
35
|
-
Everything else — telemetry taps, source capture, run-id linkage, recording,
|
|
36
|
-
priorities, success/failure filters — sits on top of those two without
|
|
37
|
-
changing them.
|
|
38
|
-
|
|
39
|
-
---
|
|
40
|
-
|
|
41
|
-
## Why this exists
|
|
42
|
-
|
|
43
|
-
The Nwire stack used to ship six overlapping middleware/hook substrates —
|
|
44
|
-
one per package, each with its own composer, error policy, and observability
|
|
45
|
-
story. `@nwire/hooks` is the single primitive they all reduce to:
|
|
13
|
+
About 100 lines of surface; sub-microsecond per-step overhead; standalone.
|
|
46
14
|
|
|
47
|
-
|
|
48
|
-
| -------------------------------------------- | ------------------------------------------------------ |
|
|
49
|
-
| `@nwire/handler` `defineMiddleware` + `pipe` | chain via `.use()` |
|
|
50
|
-
| `@nwire/handler` `defineHook("after", fn)` | listener via `.on(fn, { when: "success" })` |
|
|
51
|
-
| `@nwire/forge` `runtime.use(mw)` | chain via `.use()` on the dispatch hook |
|
|
52
|
-
| `@nwire/http` `httpInterface().use()` | chain via `.use()` on the http-request hook |
|
|
53
|
-
| `@nwire/http` per-route `middleware: […]` | per-route hook + chain |
|
|
54
|
-
| `definePlugin({ middleware, actorHooks })` | chain (middleware) + listener (actorHooks) |
|
|
55
|
-
| `definePlugin({ before, after })` | chain veto (`before`) + filtered listener (`after`) |
|
|
56
|
-
| `@nwire/app` framework events — `parallel` | listener fan-out |
|
|
57
|
-
| `@nwire/app` framework events — `series` | chain without bail |
|
|
58
|
-
| `@nwire/app` framework events — `series-bail`| chain with `.runDetailed()` reading `outcome === "prevented"` |
|
|
59
|
-
|
|
60
|
-
If you're building a new extension point: it's a hook.
|
|
61
|
-
|
|
62
|
-
---
|
|
63
|
-
|
|
64
|
-
## The contract — behavior matrix
|
|
65
|
-
|
|
66
|
-
| Question | Answer |
|
|
67
|
-
| ----------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
68
|
-
| Chain ordering | Higher `priority` first (outermost). Stable on ties — equal priority preserves insertion order. |
|
|
69
|
-
| Listener ordering | Higher `priority` first. Listeners run in parallel; ordering is *attempt* order only. |
|
|
70
|
-
| What if a chain step doesn't call `next()`? | Chain short-circuits. `outcome === "prevented"`. Listeners still fire (subject to `when`). |
|
|
71
|
-
| What if a chain step throws? | `.run()` rejects with the error. `outcome === "failed"`. Listeners still fire (subject to `when`). `ctx.error` is set. |
|
|
72
|
-
| What if a listener throws? | Reported via `onListenerError` (default: `console.error`). The run does **not** fail. Opt in with `strictListeners: true`. |
|
|
73
|
-
| Can a listener cancel the run? | No. |
|
|
74
|
-
| Can a chain step mutate ctx? | Yes. Listeners see the post-chain ctx. |
|
|
75
|
-
| Can listeners run before the chain finishes? | No. |
|
|
76
|
-
| Is `next()` allowed to be called twice? | No — throws `Error("next() called multiple times in @nwire/hooks chain")`. |
|
|
77
|
-
| Are taps observers or participants? | Observers. Tap throws are swallowed. |
|
|
78
|
-
| Run-id propagation across nested `.run()` calls? | Automatic via `AsyncLocalStorage`. Inner run's `parentRunId` = outer run's `runId`. |
|
|
79
|
-
| Is recording side-effect free? | No — it executes the hook normally and snapshots ctx before + after. Replay re-executes the chain. |
|
|
80
|
-
|
|
81
|
-
---
|
|
82
|
-
|
|
83
|
-
## Core API
|
|
84
|
-
|
|
85
|
-
### `hook(name, options?)`
|
|
15
|
+
## Surface
|
|
86
16
|
|
|
87
17
|
```ts
|
|
88
18
|
import { hook } from "@nwire/hooks";
|
|
89
19
|
|
|
90
|
-
const
|
|
91
|
-
strictListeners: false, // default
|
|
92
|
-
onListenerError: (err, ctx, hookName) => logger.error(...),
|
|
93
|
-
});
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
Creates a fresh hook. Captures the call-site source location for Studio +
|
|
97
|
-
`nwire scan`. Adds it to the process-wide registry so `listHooks()` sees it.
|
|
98
|
-
|
|
99
|
-
### `Hook<Ctx>` surface
|
|
100
|
-
|
|
101
|
-
```ts
|
|
102
|
-
interface Hook<Ctx> {
|
|
103
|
-
readonly name: string;
|
|
104
|
-
readonly id: string; // process-unique
|
|
105
|
-
|
|
106
|
-
use(fn: ChainFn<Ctx>, opts?: UseOptions): this; // chain step
|
|
107
|
-
on (fn: ListenerFn<Ctx>, opts?: OnOptions): this; // listener
|
|
108
|
-
off(fn): this; // detach
|
|
109
|
-
|
|
110
|
-
run(ctx: Ctx, opts?: RunOptions): Promise<Ctx>;
|
|
111
|
-
runDetailed(ctx, opts?): Promise<RunResult<Ctx>>;
|
|
112
|
-
|
|
113
|
-
tap(observer): () => void; // per-step trace
|
|
114
|
-
stepCounts(): { chain: number; listeners: number };
|
|
115
|
-
}
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
#### `UseOptions` / `OnOptions`
|
|
119
|
-
|
|
120
|
-
```ts
|
|
121
|
-
interface UseOptions {
|
|
122
|
-
name?: string; // human label — shown in taps, OTel, Studio
|
|
123
|
-
priority?: number; // higher = earlier in chain (default 0)
|
|
124
|
-
}
|
|
125
|
-
interface OnOptions extends UseOptions {
|
|
126
|
-
when?: "always" | "success" | "failure"; // default "always"
|
|
127
|
-
}
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
#### `RunOptions`
|
|
131
|
-
|
|
132
|
-
```ts
|
|
133
|
-
interface RunOptions {
|
|
134
|
-
signal?: AbortSignal; // injects onto ctx.signal too; thrown if aborted before next step
|
|
135
|
-
parentRunId?: string; // override the ambient parent
|
|
136
|
-
}
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
#### `RunResult<Ctx>`
|
|
140
|
-
|
|
141
|
-
```ts
|
|
142
|
-
interface RunResult<Ctx> {
|
|
143
|
-
ctx: Ctx;
|
|
144
|
-
outcome: "completed" | "prevented" | "failed";
|
|
145
|
-
runId: string;
|
|
146
|
-
parentRunId?: string;
|
|
147
|
-
steps: StepObservation[];
|
|
148
|
-
durationMs: number;
|
|
149
|
-
error?: unknown; // set when outcome === "failed"
|
|
150
|
-
}
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
`run(ctx)` is the simple form. It returns the (mutated) ctx and throws on
|
|
154
|
-
failure — the way every existing call site has worked for years.
|
|
155
|
-
`runDetailed(ctx)` returns the structured result instead. Use it when you
|
|
156
|
-
need the outcome distinction (e.g. framework events that need to know
|
|
157
|
-
"was this prevented?").
|
|
158
|
-
|
|
159
|
-
### `compose(fns)` / `pipe(...fns)` / `withTimeout(ms, fn)` / `withRetry(opts, fn)`
|
|
160
|
-
|
|
161
|
-
Helpers for assembling reusable chain pieces before attaching them to a hook.
|
|
20
|
+
const onRequest = hook<RequestCtx>("app.onRequest");
|
|
162
21
|
|
|
163
|
-
|
|
164
|
-
|
|
22
|
+
onRequest.use(fn, { priority?, name? }); // chain middleware — sequential, can short-circuit
|
|
23
|
+
onRequest.on(fn, { when?, priority? }); // listener — parallel, observes final ctx
|
|
24
|
+
onRequest.off(fn); // detach
|
|
25
|
+
onRequest.tap(observer); // subscribe to per-step observations
|
|
165
26
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
withRetry({ attempts: 3, delayMs: 100 }, callExternalApi),
|
|
169
|
-
withTimeout(5_000, persistResult),
|
|
170
|
-
);
|
|
171
|
-
hook.use(protected);
|
|
27
|
+
await onRequest.run(ctx, { signal? }); // run chain + listeners
|
|
28
|
+
await onRequest.runDetailed(ctx, opts); // same + return full step trace
|
|
172
29
|
```
|
|
173
30
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
## Observability — what every hook surfaces for free
|
|
177
|
-
|
|
178
|
-
Every hook emits a stream of `StepObservation` events. Subscribe with
|
|
179
|
-
`.tap(observer)` to wire it into:
|
|
180
|
-
|
|
181
|
-
- structured logs (`logger.info(obs)`)
|
|
182
|
-
- Studio Live (push over SSE)
|
|
183
|
-
- `nwire scan` (write to `.nwire/observations.json`)
|
|
184
|
-
- OTel adapter (one span per `start → end` pair)
|
|
31
|
+
Every ctx that flows through a hook gets two fields injected (non-enumerable, so `structuredClone` walks past them):
|
|
185
32
|
|
|
186
33
|
```ts
|
|
187
|
-
interface
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
runId: string;
|
|
191
|
-
parentRunId?: string;
|
|
192
|
-
stepId: number;
|
|
193
|
-
stepKind: "chain" | "listener";
|
|
194
|
-
stepName?: string; // from UseOptions.name / OnOptions.name
|
|
195
|
-
phase: "start" | "end" | "error";
|
|
196
|
-
ts: number; // performance.now()
|
|
197
|
-
durationMs?: number; // set on end + error
|
|
198
|
-
error?: unknown; // set on error
|
|
34
|
+
interface BaseHookCtx {
|
|
35
|
+
readonly signal: AbortSignal; // caller-supplied or non-aborting placeholder
|
|
36
|
+
set<K, V>(key: K, value: V): asserts this is this & { [P in K]: V };
|
|
199
37
|
}
|
|
200
38
|
```
|
|
201
39
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
`AsyncLocalStorage` propagates the active `runId` through the chain. When
|
|
205
|
-
your chain step calls `await otherHook.run(...)`, the nested run picks up
|
|
206
|
-
the outer `runId` as its `parentRunId` automatically — no plumbing.
|
|
207
|
-
|
|
208
|
-
```ts
|
|
209
|
-
import { hook, currentRun } from "@nwire/hooks";
|
|
210
|
-
|
|
211
|
-
const outer = hook<{}>("outer");
|
|
212
|
-
const inner = hook<{}>("inner");
|
|
213
|
-
|
|
214
|
-
outer.use(async (_, next) => {
|
|
215
|
-
await inner.run({}); // inner's parentRunId === outer's runId
|
|
216
|
-
await next();
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
inner.use(async () => {
|
|
220
|
-
console.log(currentRun()); // { runId, hookId, parentRunId }
|
|
221
|
-
});
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
This is the substrate Studio's Trace page uses to render the causal tree.
|
|
225
|
-
|
|
226
|
-
### Source location
|
|
227
|
-
|
|
228
|
-
`hook()` captures its call site at construction. `listHooks()` exposes it
|
|
229
|
-
to `nwire scan` and Studio so every hook in the manifest has a click-to-open
|
|
230
|
-
pill — same UX as actions/events/projections.
|
|
231
|
-
|
|
232
|
-
```ts
|
|
233
|
-
import { listHooks } from "@nwire/hooks";
|
|
234
|
-
|
|
235
|
-
console.log(listHooks());
|
|
236
|
-
// [
|
|
237
|
-
// { id: "h1", name: "endpoint.boot", chain: 2, listeners: 1, source: { file, line } },
|
|
238
|
-
// { id: "h2", name: "http.request", chain: 4, listeners: 0, source: { file, line } },
|
|
239
|
-
// ]
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
### Recording + replay
|
|
243
|
-
|
|
244
|
-
```ts
|
|
245
|
-
import { record, replay } from "@nwire/hooks";
|
|
246
|
-
|
|
247
|
-
// Production: capture the full trace from one run.
|
|
248
|
-
const recording = await record(myHook, ctx);
|
|
249
|
-
await fetch("/__nwire/recordings", { method: "POST", body: JSON.stringify(recording) });
|
|
250
|
-
|
|
251
|
-
// Dev / debug: replay against the same hook and assert on drift.
|
|
252
|
-
const result = await replay(myHook, recording);
|
|
253
|
-
if (!result.matches) console.warn("drift:", result.drift);
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
`record` runs the hook once, snapshots `ctxIn`/`ctxOut` (via `structuredClone`
|
|
257
|
-
by default), and returns a self-contained, JSON-serializable trace. `replay`
|
|
258
|
-
re-runs the hook with the captured `ctxIn` (cloned) and compares step
|
|
259
|
-
sequences — flagging drift in step count, names, order, or outcome.
|
|
260
|
-
|
|
261
|
-
This is observational, not stubbing. Pure / idempotent chains match
|
|
262
|
-
deterministically; non-deterministic chains report exactly what diverged.
|
|
263
|
-
|
|
264
|
-
---
|
|
265
|
-
|
|
266
|
-
## Consumer APIs — the surfaces every nwire package presents
|
|
40
|
+
`signal` is the cooperative cancellation contract — every async step can forward it (`fetch(url, { signal })`, `pg.query(…, { signal })`) and react via `signal.throwIfAborted()`.
|
|
267
41
|
|
|
268
|
-
|
|
269
|
-
Internally they all reduce to `hook()`, but the public API stays familiar
|
|
270
|
-
and ergonomic. This table is the source of truth — anything outside it is
|
|
271
|
-
not a public API of that package.
|
|
42
|
+
`.set()` is the typed widening primitive — middleware contributes a new field, the TS assertion narrows `ctx` for downstream steps.
|
|
272
43
|
|
|
273
|
-
|
|
44
|
+
## Consumer example
|
|
274
45
|
|
|
275
46
|
```ts
|
|
276
|
-
|
|
277
|
-
runtime.use(mw: DispatchMiddleware): void;
|
|
278
|
-
type DispatchMiddleware = (
|
|
279
|
-
next: () => Promise<EventMessage | EventMessage[] | void>,
|
|
280
|
-
action: ActionDefinition,
|
|
281
|
-
input: unknown,
|
|
282
|
-
ctx: HandlerContext,
|
|
283
|
-
) => Promise<EventMessage | EventMessage[] | void>;
|
|
284
|
-
// → forge.action.dispatch hook · chain · priority by registration order
|
|
285
|
-
|
|
286
|
-
// Actor transition hook — observable, fires after every state change.
|
|
287
|
-
runtime.actorHook(fn: ActorTransitionHook): void;
|
|
288
|
-
type ActorTransitionHook = (
|
|
289
|
-
actor: ActorDefinition,
|
|
290
|
-
key: string,
|
|
291
|
-
fromState: string,
|
|
292
|
-
toState: string,
|
|
293
|
-
event: EventMessage,
|
|
294
|
-
envelope: MessageEnvelope,
|
|
295
|
-
) => Promise<void> | void;
|
|
296
|
-
// → forge.actor.transition hook · listener · when=always
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
### `@nwire/forge` — plugin builder (closure form)
|
|
300
|
-
|
|
301
|
-
```ts
|
|
302
|
-
definePlugin("name", ({ bind, resolve, on, before, after, middleware, actorHook, boot, shutdown }) => {
|
|
303
|
-
// — Generic framework event subscription.
|
|
304
|
-
on<TPayload>(event, handler, priority?): void;
|
|
305
|
-
// → underlying framework-event hook · chain or listener per event.mode
|
|
306
|
-
|
|
307
|
-
// — Action-scoped sugar.
|
|
308
|
-
before(actionName, fn): void;
|
|
309
|
-
// fn returns void | false. false short-circuits ("prevented"); throw fails.
|
|
310
|
-
// → action.before:<name> hook · chain · use+next bail
|
|
311
|
-
after(actionName, fn): void;
|
|
312
|
-
// fn observes result + durationMs. Errors logged, not fatal.
|
|
313
|
-
// → action.after:<name> hook · listener · when=success
|
|
314
|
-
|
|
315
|
-
// — Dispatch middleware (same shape as runtime.use).
|
|
316
|
-
middleware(mw: DispatchMiddleware): void;
|
|
317
|
-
// → forge.action.dispatch hook · chain
|
|
318
|
-
|
|
319
|
-
// — Actor transitions (same shape as runtime.actorHook).
|
|
320
|
-
actorHook(fn: ActorTransitionHook): void;
|
|
321
|
-
// → forge.actor.transition hook · listener
|
|
322
|
-
|
|
323
|
-
// — Plugin lifecycle. Run order = registration; shutdown is reverse.
|
|
324
|
-
boot(fn: () => Promise<void> | void): void;
|
|
325
|
-
shutdown(fn: () => Promise<void> | void): void;
|
|
326
|
-
});
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
### `@nwire/app` — framework events (3 dispatch modes)
|
|
330
|
-
|
|
331
|
-
```ts
|
|
332
|
-
// Subscribe (priority desc; default 0).
|
|
333
|
-
bus.on(event, handler, priority?): () => void;
|
|
334
|
-
|
|
335
|
-
// Fire. Returns false only when a series-bail handler vetoed.
|
|
336
|
-
bus.fire(event, payload): Promise<boolean>;
|
|
337
|
-
|
|
338
|
-
// Per-firing observer — sees every event, cannot veto. For dev-logger,
|
|
339
|
-
// Studio Live, OTel.
|
|
340
|
-
bus.onFire(observer): () => void;
|
|
341
|
-
type FrameworkEventObservation = {
|
|
342
|
-
eventName: string;
|
|
343
|
-
payload: unknown;
|
|
344
|
-
mode: "parallel" | "series" | "series-bail";
|
|
345
|
-
phase: "fired" | "prevented";
|
|
346
|
-
ts: string;
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
// Modes — set when defining the event.
|
|
350
|
-
defineFrameworkEvent<TPayload>(name, mode: "parallel" | "series" | "series-bail");
|
|
351
|
-
// parallel → listener fan-out (Promise.allSettled, errors logged)
|
|
352
|
-
// series → chain without bail (sequential await; throw stops)
|
|
353
|
-
// series-bail → chain with bail (sequential await; return false short-circuits)
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
### `@nwire/handler` — resolver middleware
|
|
357
|
-
|
|
358
|
-
```ts
|
|
359
|
-
defineMiddleware(name?, fn: (ctx, next) => Promise<void> | void): MiddlewareDefinition;
|
|
360
|
-
// → resolver hook · chain
|
|
361
|
-
|
|
362
|
-
defineHook("before", name?, fn: (ctx) => Promise<void> | void): HookDefinition;
|
|
363
|
-
// → resolver hook · listener · when=always · runs before handler
|
|
364
|
-
defineHook("after", name?, fn: (ctx, result) => Promise<void> | void): HookDefinition;
|
|
365
|
-
// → resolver hook · listener · when=success · runs after handler
|
|
366
|
-
|
|
367
|
-
pipe(...steps: PipeStep[]): MiddlewarePipe;
|
|
368
|
-
// compose middlewares + hooks; transports unwind into chain + listeners
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
### `@nwire/http` — request pipeline
|
|
372
|
-
|
|
373
|
-
```ts
|
|
374
|
-
httpInterface(opts?)
|
|
375
|
-
.use(mw: KoaMiddleware): this;
|
|
376
|
-
// → http.request hook · chain · global to this interface
|
|
377
|
-
.provide(container): this;
|
|
378
|
-
.wire(route: RouteBinding, handler: HttpHandler): this;
|
|
379
|
-
// per-route middleware lives on the binding:
|
|
380
|
-
// route = post("/path", { body, middleware: [mw1, mw2], openapi })
|
|
381
|
-
// → http.request:<METHOD> <path> hook · chain · scoped to this route
|
|
382
|
-
.compile(): KoaApp;
|
|
383
|
-
.toExpress(): ExpressMiddleware;
|
|
384
|
-
```
|
|
385
|
-
|
|
386
|
-
### `@nwire/auth` — canonical resolvers + middleware
|
|
387
|
-
|
|
388
|
-
```ts
|
|
389
|
-
// All canonical auth operations are resolvers (SignIn, SignOut, Refresh,
|
|
390
|
-
// Register, Me) and run through the @nwire/handler pipeline above.
|
|
391
|
-
identityPlugin({ adapter, scopes? }): PluginDefinition;
|
|
392
|
-
// contributes:
|
|
393
|
-
// middleware → forge.action.dispatch · chain · enriches ctx.envelope.user
|
|
394
|
-
// resolvers → /auth/*
|
|
395
|
-
```
|
|
396
|
-
|
|
397
|
-
### `@nwire/rbac`
|
|
398
|
-
|
|
399
|
-
```ts
|
|
400
|
-
defineAbility((user, { allow, deny }) => { ... }): AbilityFactory;
|
|
401
|
-
rbacPlugin({ ability }): PluginDefinition;
|
|
402
|
-
// contributes:
|
|
403
|
-
// middleware → forge.action.dispatch · chain · enforces action.policy
|
|
404
|
-
|
|
405
|
-
// Resolver-level:
|
|
406
|
-
can(action: string, subject: string | Subject): MiddlewareDefinition;
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
### `@nwire/observability` (tracing + auth-as-plugin)
|
|
410
|
-
|
|
411
|
-
```ts
|
|
412
|
-
tracingPlugin({ tracer? }): PluginDefinition;
|
|
413
|
-
// wires OTel via .tap() on the dispatch + framework-event hooks.
|
|
414
|
-
|
|
415
|
-
// Application code rarely calls hooks directly — observability plugs in
|
|
416
|
-
// at boot, taps every hook in listHooks(), and emits spans / logs.
|
|
417
|
-
```
|
|
418
|
-
|
|
419
|
-
### Test surface — `@nwire/test-kit`
|
|
420
|
-
|
|
421
|
-
```ts
|
|
422
|
-
const harness = createTestHarness({ app });
|
|
423
|
-
// Every hook the app creates is .tap()-able through harness.observe():
|
|
424
|
-
harness.observe(hookName, (obs) => { ... });
|
|
425
|
-
// Recordings can be captured + diffed in tests:
|
|
426
|
-
const rec = await harness.record(hookName, ctx);
|
|
427
|
-
expect(rec.steps.map((s) => s.stepName)).toEqual([...]);
|
|
428
|
-
```
|
|
429
|
-
|
|
430
|
-
### Studio + scan
|
|
431
|
-
|
|
432
|
-
`nwire scan` emits `.nwire/hooks.json`:
|
|
433
|
-
|
|
434
|
-
```json
|
|
435
|
-
[
|
|
436
|
-
{ "id": "h1", "name": "forge.action.dispatch", "chain": 4, "listeners": 0, "source": { "file": "...", "line": 12 } },
|
|
437
|
-
{ "id": "h2", "name": "nwire.app.booting", "chain": 2, "listeners": 0, "source": { "file": "...", "line": 8 } },
|
|
438
|
-
{ "id": "h3", "name": "action.after:CreateStation", "chain": 0, "listeners": 2, "source": { "file": "...", "line": 23 } }
|
|
439
|
-
]
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
Studio surfaces a **Hooks** page that lists these with source pills, a per-hook
|
|
443
|
-
inspector showing attached chain + listeners with their names + priorities,
|
|
444
|
-
and a Trace mode that overlays live `.tap()` observations onto the causation
|
|
445
|
-
tree using `runId` / `parentRunId`.
|
|
446
|
-
|
|
447
|
-
---
|
|
448
|
-
|
|
449
|
-
## Recipes — wiring the substrate
|
|
450
|
-
|
|
451
|
-
### 1. Forge — `runtime.use(middleware)`
|
|
452
|
-
|
|
453
|
-
```ts
|
|
454
|
-
const dispatch = hook<DispatchCtx>("forge.action.dispatch");
|
|
455
|
-
|
|
456
|
-
dispatch.use(async (ctx, next) => {
|
|
457
|
-
const span = tracer.startSpan(ctx.action.name);
|
|
458
|
-
try { await next(); span.end(); } catch (err) { span.recordException(err); throw err; }
|
|
459
|
-
}, { name: "tracing", priority: 100 });
|
|
460
|
-
|
|
461
|
-
// `runtime.use(mw)` is sugar:
|
|
462
|
-
runtime.use = (mw) => dispatch.use(adaptDispatchMiddleware(mw));
|
|
463
|
-
```
|
|
464
|
-
|
|
465
|
-
### 2. HTTP — global `.use()` + per-route `middleware: [...]`
|
|
466
|
-
|
|
467
|
-
```ts
|
|
468
|
-
const httpRequest = hook<KoaCtx>("http.request"); // global
|
|
469
|
-
const routeRequest = (route) =>
|
|
470
|
-
hook<KoaCtx>(`http.request:${route.method} ${route.path}`); // per route
|
|
471
|
-
|
|
472
|
-
httpRequest.use(cors());
|
|
473
|
-
httpRequest.use(bodyParser());
|
|
474
|
-
const routeHook = routeRequest(route);
|
|
475
|
-
for (const mw of route.middleware) routeHook.use(mw);
|
|
476
|
-
routeHook.use(invokeHandler(route));
|
|
477
|
-
|
|
478
|
-
// At dispatch:
|
|
479
|
-
await httpRequest.run(ctx);
|
|
480
|
-
await routeHook.run(ctx);
|
|
481
|
-
```
|
|
482
|
-
|
|
483
|
-
### 3. Handler — `defineMiddleware` + `defineHook("after", ...)`
|
|
484
|
-
|
|
485
|
-
```ts
|
|
486
|
-
// Migrate:
|
|
487
|
-
const authenticate = defineMiddleware(async (ctx, next) => { ... });
|
|
488
|
-
const auditLog = defineHook("after", async (ctx, result) => { ... });
|
|
489
|
-
|
|
490
|
-
// To:
|
|
491
|
-
resolverHook.use(authenticate.fn, { name: "authenticate" });
|
|
492
|
-
resolverHook.on((ctx) => auditLog.fn(ctx, ctx.result), { when: "success", name: "audit-log" });
|
|
493
|
-
```
|
|
494
|
-
|
|
495
|
-
### 4. Plugin — `before(actionName, fn)` (series-bail)
|
|
47
|
+
import { hook } from "@nwire/hooks";
|
|
496
48
|
|
|
497
|
-
|
|
498
|
-
const
|
|
49
|
+
type ReqCtx = { url: string; method: string; status?: number };
|
|
50
|
+
const onRequest = hook<ReqCtx>("app.onRequest");
|
|
499
51
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
52
|
+
// Logger — plain async fn, wraps + measures
|
|
53
|
+
onRequest.use(async (ctx, next) => {
|
|
54
|
+
const t = performance.now();
|
|
55
|
+
console.log(`→ ${ctx.method} ${ctx.url}`);
|
|
503
56
|
await next();
|
|
57
|
+
console.log(`← ${ctx.status} (${(performance.now() - t).toFixed(1)}ms)`);
|
|
504
58
|
});
|
|
505
59
|
|
|
506
|
-
//
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
```ts
|
|
521
|
-
const actorTransition = hook<TransitionCtx>("actor.transition");
|
|
522
|
-
actorTransition.on((ctx) => userHook(ctx.actor, ctx.key, ctx.from, ctx.to, ctx.event));
|
|
523
|
-
|
|
524
|
-
// runtime emits on every transition:
|
|
525
|
-
await actorTransition.run({ actor, key, from, to, event, envelope });
|
|
526
|
-
```
|
|
527
|
-
|
|
528
|
-
### 7. App framework events — three modes
|
|
529
|
-
|
|
530
|
-
```ts
|
|
531
|
-
const ev = hook<Payload>("nwire.app.booting", {
|
|
532
|
-
// strictListeners=false matches "parallel mode" — handler errors are logged.
|
|
533
|
-
strictListeners: false,
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
// parallel:
|
|
537
|
-
ev.on(handler, { priority });
|
|
538
|
-
|
|
539
|
-
// series:
|
|
540
|
-
ev.use(async (ctx, next) => { await handler(ctx); await next(); }, { priority });
|
|
541
|
-
|
|
542
|
-
// series-bail:
|
|
543
|
-
ev.use(async (ctx, next) => {
|
|
544
|
-
const ret = await handler(ctx);
|
|
545
|
-
if (ret === false) return; // short-circuit
|
|
546
|
-
await next();
|
|
547
|
-
}, { priority });
|
|
548
|
-
|
|
549
|
-
const r = await ev.runDetailed(payload);
|
|
550
|
-
const prevented = r.outcome === "prevented";
|
|
551
|
-
```
|
|
552
|
-
|
|
553
|
-
### 8. Studio / scan integration
|
|
60
|
+
// Auth — contributes via typed .set, short-circuits on rejection
|
|
61
|
+
onRequest.use(
|
|
62
|
+
async (ctx, next) => {
|
|
63
|
+
const token = readToken(ctx.url);
|
|
64
|
+
if (!token) {
|
|
65
|
+
ctx.set("status", 401); // short-circuit (no next())
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
ctx.set("userId", await verify(token)); // ctx widened to include userId
|
|
69
|
+
await next();
|
|
70
|
+
},
|
|
71
|
+
{ priority: 100 },
|
|
72
|
+
);
|
|
554
73
|
|
|
555
|
-
|
|
556
|
-
|
|
74
|
+
// Metrics — listener, never mutates
|
|
75
|
+
onRequest.on((ctx) => metrics.tick(`http.${ctx.method}.${ctx.status}`));
|
|
557
76
|
|
|
558
|
-
|
|
559
|
-
const manifest = listHooks().map((h) => ({
|
|
560
|
-
id: h.id, name: h.name, chain: h.chain, listeners: h.listeners, source: h.source,
|
|
561
|
-
}));
|
|
77
|
+
await onRequest.run({ url: "/api/orders", method: "GET" });
|
|
562
78
|
```
|
|
563
79
|
|
|
564
|
-
|
|
80
|
+
## Cancellation in practice
|
|
565
81
|
|
|
566
82
|
```ts
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
const tracer = trace.getTracer("nwire");
|
|
570
|
-
const spans = new Map<string, ReturnType<typeof tracer.startSpan>>();
|
|
571
|
-
|
|
572
|
-
myHook.tap((obs) => {
|
|
573
|
-
const key = `${obs.runId}:${obs.stepId}:${obs.stepKind}`;
|
|
574
|
-
if (obs.phase === "start") {
|
|
575
|
-
spans.set(key, tracer.startSpan(`${obs.hookName}.${obs.stepName ?? obs.stepKind}`));
|
|
576
|
-
} else if (obs.phase === "end") {
|
|
577
|
-
spans.get(key)?.end(); spans.delete(key);
|
|
578
|
-
} else if (obs.phase === "error") {
|
|
579
|
-
const s = spans.get(key);
|
|
580
|
-
if (s) { s.recordException(obs.error as Error); s.end(); spans.delete(key); }
|
|
581
|
-
}
|
|
582
|
-
});
|
|
583
|
-
```
|
|
584
|
-
|
|
585
|
-
### 10. Structured logger tap
|
|
83
|
+
const ac = new AbortController();
|
|
84
|
+
setTimeout(() => ac.abort(new Error("user cancelled")), 5000);
|
|
586
85
|
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
msg: "hook.step",
|
|
591
|
-
hook: obs.hookName,
|
|
592
|
-
runId: obs.runId,
|
|
593
|
-
parentRun: obs.parentRunId,
|
|
594
|
-
step: obs.stepName ?? `#${obs.stepId}`,
|
|
595
|
-
phase: obs.phase,
|
|
596
|
-
durationMs: obs.durationMs,
|
|
597
|
-
error: obs.error && (obs.error as Error).message,
|
|
598
|
-
});
|
|
599
|
-
});
|
|
86
|
+
await onRequest.run(ctx, { signal: ac.signal });
|
|
87
|
+
// inside any step: signal.throwIfAborted() bails;
|
|
88
|
+
// the abort propagates through nested .run() calls too
|
|
600
89
|
```
|
|
601
90
|
|
|
602
|
-
|
|
91
|
+
Combine with timeouts:
|
|
603
92
|
|
|
604
93
|
```ts
|
|
605
|
-
const
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
await myHook.run(ctx, { signal: ac.signal });
|
|
609
|
-
// ctx.signal is set so inner code can poll:
|
|
610
|
-
// if (ctx.signal?.aborted) return;
|
|
94
|
+
const timeout = AbortSignal.timeout(2000);
|
|
95
|
+
await onRequest.run(ctx, { signal: AbortSignal.any([userSignal, timeout]) });
|
|
611
96
|
```
|
|
612
97
|
|
|
613
|
-
|
|
98
|
+
## Observability
|
|
614
99
|
|
|
615
|
-
|
|
100
|
+
`.tap(observer)` emits a `StepObservation` per chain/listener phase (`start` / `end` / `error`) with timing, runId, parentRunId. `runDetailed()` returns the full trace + outcome. Used by `@nwire/scan` to emit `.nwire/hooks.json` and by Studio for live tap streams.
|
|
616
101
|
|
|
617
|
-
|
|
618
|
-
import { createHooks, hook } from "@nwire/hooks";
|
|
102
|
+
## Used by
|
|
619
103
|
|
|
620
|
-
|
|
621
|
-
registering: hook<RegisteringCtx>("nwire.app.registering"),
|
|
622
|
-
booting: hook<BootingCtx> ("nwire.app.booting"),
|
|
623
|
-
ready: hook<ReadyCtx> ("nwire.app.ready"),
|
|
624
|
-
shutdown: hook<ShutdownCtx> ("nwire.app.shutdown"),
|
|
625
|
-
});
|
|
104
|
+
`@nwire/handler` is built on `hook<HandlerRunCtx>()`. `@nwire/forge` runtime, framework-event bus, plugin lifecycle, and every transport in Nwire share the same substrate.
|
|
626
105
|
|
|
627
|
-
|
|
628
|
-
lifecycle.use({
|
|
629
|
-
booting: async (ctx, next) => { logger.info("booting"); await next(); },
|
|
630
|
-
ready: { on: (ctx) => logger.info("ready", { port: ctx.port }) },
|
|
631
|
-
shutdown: async (ctx, next) => { await flushOutbox(); await next(); },
|
|
632
|
-
});
|
|
633
|
-
```
|
|
634
|
-
|
|
635
|
-
`.hooks` is the underlying record — spread it to compose hosts:
|
|
636
|
-
|
|
637
|
-
```ts
|
|
638
|
-
const full = createHooks({ ...lifecycle.hooks, request: hook<...>("http.request") });
|
|
639
|
-
```
|
|
106
|
+
## Scope
|
|
640
107
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
## Production guidance
|
|
644
|
-
|
|
645
|
-
- **Hot paths.** A `.use()` step adds one wrapper closure + one observation
|
|
646
|
-
emit. Per-request HTTP middleware on a busy server: ~250 ns/step in our
|
|
647
|
-
microbench. If you have a 100k-rps inner loop and don't need observability,
|
|
648
|
-
prefer a hand-rolled compose.
|
|
649
|
-
- **Listener errors.** Default policy is log + continue. This matches Node's
|
|
650
|
-
`EventEmitter` and Koa's "don't crash because metrics broke." Opt into
|
|
651
|
-
`strictListeners: true` for testing and any place where listener failure
|
|
652
|
-
must surface.
|
|
653
|
-
- **Taps.** Taps fire synchronously inside `.run()`. Don't do blocking I/O.
|
|
654
|
-
Buffer + flush async.
|
|
655
|
-
- **AbortSignal.** Aborting throws between steps. A long-running step that
|
|
656
|
-
never `await`s won't notice. Plumb `ctx.signal` into your I/O calls.
|
|
657
|
-
- **Topology.** `AsyncLocalStorage` survives microtasks and timers. It does
|
|
658
|
-
*not* survive `setImmediate` if you escape the await chain. Stay in
|
|
659
|
-
`await` land if you care about parent linkage.
|
|
660
|
-
- **Recording size.** A recording grows linearly with step count; ctx
|
|
661
|
-
snapshots dominate the size. Use a custom `clone` to redact PII before
|
|
662
|
-
persisting.
|
|
663
|
-
|
|
664
|
-
---
|
|
665
|
-
|
|
666
|
-
## When NOT to use a hook
|
|
667
|
-
|
|
668
|
-
- A single, hard-coded step that has no extension point. Just call the
|
|
669
|
-
function.
|
|
670
|
-
- A synchronous calculation that never spans I/O. The async overhead is
|
|
671
|
-
wasted.
|
|
672
|
-
- Something that's fundamentally request/response with no observers and no
|
|
673
|
-
cancellability. A normal function is fine.
|
|
674
|
-
|
|
675
|
-
Hooks are for extension. If nobody will ever attach to it, don't make it
|
|
676
|
-
one.
|
|
677
|
-
|
|
678
|
-
---
|
|
679
|
-
|
|
680
|
-
## Versioning + stability
|
|
681
|
-
|
|
682
|
-
`@nwire/hooks` follows the framework's semver. The contract matrix in this
|
|
683
|
-
README is the law — changing any row is a major bump.
|
|
684
|
-
|
|
685
|
-
Already locked: `Hook<Ctx>` surface, `RunResult`, `StepObservation`,
|
|
686
|
-
`Recording`. New optional capabilities (more `RunOptions`, more tap fields)
|
|
687
|
-
are minor bumps; never breaking.
|
|
108
|
+
Standalone, in-process. Cross-process dispatch lives in `@nwire/bus`. Use this for middleware chains, lifecycle hooks, and pub-sub-within-process.
|
package/dist/hook.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../src/hook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAaH,OAAO,KAAK,EACV,OAAO,EACP,WAAW,EACX,UAAU,EACV,SAAS,EACT,UAAU,EAEV,SAAS,EAET,KAAK,EACL,UAAU,EACX,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../src/hook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAaH,OAAO,KAAK,EACV,OAAO,EACP,WAAW,EACX,UAAU,EACV,SAAS,EACT,UAAU,EAEV,SAAS,EAET,KAAK,EACL,UAAU,EACX,MAAM,SAAS,CAAC;AAWjB;;;;;;GAMG;AACH,MAAM,WAAW,IAAI,CAAC,GAAG;IACvB,iDAAiD;IACjD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB,iEAAiE;IACjE,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAE/C,uEAAuE;IACvE,EAAE,CAAC,EAAE,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IAEhD,6EAA6E;IAC7E,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAE9C,8EAA8E;IAC9E,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAE/C,0EAA0E;IAC1E,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAElE,yEAAyE;IACzE,GAAG,CAAC,QAAQ,EAAE,KAAK,GAAG,MAAM,IAAI,CAAC;IAEjC,0EAA0E;IAC1E,UAAU,IAAI;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CACtE;AAED,yBAAyB;AACzB,wBAAgB,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,WAAW,CAAC,GAAG,CAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAKjF"}
|
package/dist/hook.js
CHANGED
|
@@ -19,6 +19,12 @@ import Emittery from "emittery";
|
|
|
19
19
|
import { compose } from "./compose.js";
|
|
20
20
|
import { captureSourceLocation, nextHookId, nextRunId, registerHook, withRunContext, currentRun, } from "./registry.js";
|
|
21
21
|
const RUN_EVENT = "__nwire_hooks_run__";
|
|
22
|
+
/**
|
|
23
|
+
* A non-aborting placeholder signal. Used when `.run()` is called without
|
|
24
|
+
* `opts.signal` — every chain ctx is guaranteed to have `ctx.signal`, so
|
|
25
|
+
* domain code can forward it (to fetch, pg, etc.) without null-guarding.
|
|
26
|
+
*/
|
|
27
|
+
const NEVER_ABORTS = new AbortController().signal;
|
|
22
28
|
/** Create a new hook. */
|
|
23
29
|
export function hook(name, options = {}) {
|
|
24
30
|
const source = captureSourceLocation(2);
|
|
@@ -66,7 +72,9 @@ class HookImpl {
|
|
|
66
72
|
on(fn, opts) {
|
|
67
73
|
if (this.listeners.find((l) => l.fn === fn))
|
|
68
74
|
return this;
|
|
69
|
-
const adapter = async (ctx) => {
|
|
75
|
+
const adapter = async (ctx) => {
|
|
76
|
+
await fn(ctx);
|
|
77
|
+
};
|
|
70
78
|
const entry = {
|
|
71
79
|
fn,
|
|
72
80
|
stepId: this.stepCounter++,
|
|
@@ -96,7 +104,9 @@ class HookImpl {
|
|
|
96
104
|
}
|
|
97
105
|
tap(observer) {
|
|
98
106
|
this.taps.add(observer);
|
|
99
|
-
return () => {
|
|
107
|
+
return () => {
|
|
108
|
+
this.taps.delete(observer);
|
|
109
|
+
};
|
|
100
110
|
}
|
|
101
111
|
async run(ctx, opts) {
|
|
102
112
|
const result = await this.runDetailed(ctx, opts);
|
|
@@ -117,14 +127,44 @@ class HookImpl {
|
|
|
117
127
|
try {
|
|
118
128
|
tap(obs);
|
|
119
129
|
}
|
|
120
|
-
catch {
|
|
130
|
+
catch {
|
|
131
|
+
/* tap throws are swallowed */
|
|
132
|
+
}
|
|
121
133
|
}
|
|
122
134
|
};
|
|
123
|
-
//
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
|
|
135
|
+
// Ensure ctx carries the two BaseHookCtx fields by the time any chain
|
|
136
|
+
// step runs. `signal` is sourced from opts.signal, falling back to a
|
|
137
|
+
// non-aborting placeholder so steps can pass it through without
|
|
138
|
+
// null-guarding. `.set(key, value)` is a typed setter that mutates ctx
|
|
139
|
+
// in place; its assertion-function signature widens the ctx type for
|
|
140
|
+
// the rest of the chain (see `BaseHookCtx` in types.ts).
|
|
141
|
+
//
|
|
142
|
+
// Both fields are defined as NON-ENUMERABLE own properties so
|
|
143
|
+
// `structuredClone` and JSON.stringify (used by record/replay + tracing)
|
|
144
|
+
// walk past them — `signal` (an AbortSignal) and `set` (a function) are
|
|
145
|
+
// not serializable, but they're framework-internal, not domain state.
|
|
146
|
+
// User-provided values on ctx win — we never overwrite.
|
|
147
|
+
if (ctx && typeof ctx === "object") {
|
|
148
|
+
const obj = ctx;
|
|
149
|
+
const desc = Object.getOwnPropertyDescriptor;
|
|
150
|
+
if (!desc(obj, "signal")) {
|
|
151
|
+
Object.defineProperty(obj, "signal", {
|
|
152
|
+
value: signal ?? NEVER_ABORTS,
|
|
153
|
+
enumerable: false,
|
|
154
|
+
writable: false,
|
|
155
|
+
configurable: true,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (!desc(obj, "set")) {
|
|
159
|
+
Object.defineProperty(obj, "set", {
|
|
160
|
+
value: function set(key, value) {
|
|
161
|
+
obj[key] = value;
|
|
162
|
+
},
|
|
163
|
+
enumerable: false,
|
|
164
|
+
writable: false,
|
|
165
|
+
configurable: true,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
128
168
|
}
|
|
129
169
|
const composed = compose(this.chain.map((entry) => wrapChain(this, entry, runId, parentRunId, signal, emit)));
|
|
130
170
|
// A chain step that doesn't call its `next()` short-circuits — the tail
|
|
@@ -135,11 +175,18 @@ class HookImpl {
|
|
|
135
175
|
let reachedTail = false;
|
|
136
176
|
await withRunContext({ runId, hookId: this.id, parentRunId }, async () => {
|
|
137
177
|
try {
|
|
138
|
-
await composed(ctx, async () => {
|
|
178
|
+
await composed(ctx, async () => {
|
|
179
|
+
reachedTail = true;
|
|
180
|
+
});
|
|
139
181
|
}
|
|
140
182
|
catch (err) {
|
|
141
183
|
chainError = err;
|
|
142
|
-
|
|
184
|
+
// Record the chain error onto ctx so listeners + observers can see
|
|
185
|
+
// it. Guard against undefined/primitive ctx (some hooks fire with
|
|
186
|
+
// `undefined` payloads — e.g., framework-event lifecycle hooks).
|
|
187
|
+
if (ctx && typeof ctx === "object") {
|
|
188
|
+
ctx.error = err;
|
|
189
|
+
}
|
|
143
190
|
}
|
|
144
191
|
});
|
|
145
192
|
// Empty chain — nothing to short-circuit, treat as completed.
|
|
@@ -201,7 +248,9 @@ class HookImpl {
|
|
|
201
248
|
try {
|
|
202
249
|
this.onListenerError(f.reason, ctx, this.name);
|
|
203
250
|
}
|
|
204
|
-
catch {
|
|
251
|
+
catch {
|
|
252
|
+
/* reporter blew up — swallow */
|
|
253
|
+
}
|
|
205
254
|
}
|
|
206
255
|
}
|
|
207
256
|
}
|
package/dist/hook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../src/hook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,qBAAqB,EACrB,UAAU,EACV,SAAS,EACT,YAAY,EACZ,cAAc,EACd,UAAU,GACX,MAAM,YAAY,CAAC;AAcpB,MAAM,SAAS,GAAG,qBAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../src/hook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,qBAAqB,EACrB,UAAU,EACV,SAAS,EACT,YAAY,EACZ,cAAc,EACd,UAAU,GACX,MAAM,YAAY,CAAC;AAcpB,MAAM,SAAS,GAAG,qBAA8B,CAAC;AAEjD;;;;GAIG;AACH,MAAM,YAAY,GAAgB,IAAI,eAAe,EAAE,CAAC,MAAM,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AAG,OAAO,CAChB,CACF,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,KAAK,GAAG,KAAK,EAAE,CAAC;YACtB,IAAI,CACF,OAAO,CACL,IAAI,EACJ,KAAK,CAAC,MAAM,EACZ,OAAO,EACP,KAAK,CAAC,IAAI,EACV,OAAO,EACP,KAAK,EACL,KAAK,EACL,WAAW,EACX,KAAK,GAAG,OAAO,EACf,GAAG,CACJ,CACF,CAAC;YACF,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CACd,IAAmB,EACnB,MAAc,EACd,QAA8B,EAC9B,QAA4B,EAC5B,KAAgC,EAChC,EAAU,EACV,KAAa,EACb,WAA+B,EAC/B,UAAmB,EACnB,KAAe;IAEf,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,IAAI;QACnB,MAAM,EAAE,IAAI,CAAC,EAAE;QACf,KAAK;QACL,WAAW;QACX,MAAM;QACN,QAAQ;QACR,QAAQ;QACR,KAAK;QACL,EAAE;QACF,UAAU;QACV,KAAK;KACN,CAAC;AACJ,CAAC;AAED,2EAA2E;AAC3E,8CAA8C;AAC9C,MAAM,KAAK,GACT,OAAO,WAAW,KAAK,WAAW,IAAI,OAAO,WAAW,CAAC,GAAG,KAAK,UAAU;IACzE,CAAC,CAAC,GAAW,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE;IACjC,CAAC,CAAC,GAAW,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,6 @@ export { createHooks, type Host, type HookMap, type Plugin, type PluginEntry, }
|
|
|
13
13
|
export { compose } from "./compose.js";
|
|
14
14
|
export { pipe, withTimeout, withRetry } from "./pipe.js";
|
|
15
15
|
export { record, replay, type RecordOptions, type ReplayResult } from "./record.js";
|
|
16
|
-
export { listHooks, currentRun, captureSourceLocation
|
|
17
|
-
export type { ChainFn, HookOptions, ListenerFn, OnOptions, Recording, RetryOpts, RunOptions, RunOutcome, RunResult, SourceLocation, StepKind, StepObservation, StepPhase, TapFn, UseOptions, } from "./types.js";
|
|
16
|
+
export { listHooks, currentRun, captureSourceLocation } from "./registry.js";
|
|
17
|
+
export type { BaseHookCtx, ChainFn, HookOptions, ListenerFn, OnOptions, Recording, RetryOpts, RunOptions, RunOutcome, RunResult, SourceLocation, StepKind, StepObservation, StepPhase, TapFn, UseOptions, } from "./types.js";
|
|
18
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EACL,WAAW,EACX,KAAK,IAAI,EACT,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,WAAW,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AACjF,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EACL,WAAW,EACX,KAAK,IAAI,EACT,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,WAAW,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAC1E,YAAY,EACV,WAAW,EACX,OAAO,EACP,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS,EACT,UAAU,EACV,UAAU,EACV,SAAS,EACT,cAAc,EACd,QAAQ,EACR,eAAe,EACf,SAAS,EACT,KAAK,EACL,UAAU,GACX,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,5 +13,5 @@ export { createHooks, } from "./create-hooks.js";
|
|
|
13
13
|
export { compose } from "./compose.js";
|
|
14
14
|
export { pipe, withTimeout, withRetry } from "./pipe.js";
|
|
15
15
|
export { record, replay } from "./record.js";
|
|
16
|
-
export { listHooks, currentRun, captureSourceLocation
|
|
16
|
+
export { listHooks, currentRun, captureSourceLocation } from "./registry.js";
|
|
17
17
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,IAAI,EAAa,MAAM,QAAQ,CAAC;AACzC,OAAO,EACL,WAAW,GAKZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAyC,MAAM,UAAU,CAAC;AACjF,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,IAAI,EAAa,MAAM,QAAQ,CAAC;AACzC,OAAO,EACL,WAAW,GAKZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAyC,MAAM,UAAU,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/record.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErD,MAAM,WAAW,aAAc,SAAQ,UAAU;IAC/C,sEAAsE;IACtE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;CACnC;AAQD;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAC9B,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,EACf,GAAG,EAAE,GAAG,EACR,IAAI,GAAE,aAAkB,GACvB,OAAO,CAAC,SAAS,CAAC,CAepB;AAED,oDAAoD;AACpD,MAAM,WAAW,YAAY,CAAC,GAAG;IAC/B,QAAQ,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErD,MAAM,WAAW,aAAc,SAAQ,UAAU;IAC/C,sEAAsE;IACtE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;CACnC;AAQD;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAC9B,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,EACf,GAAG,EAAE,GAAG,EACR,IAAI,GAAE,aAAkB,GACvB,OAAO,CAAC,SAAS,CAAC,CAepB;AAED,oDAAoD;AACpD,MAAM,WAAW,YAAY,CAAC,GAAG;IAC/B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;QAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAChG;AAED;;;;;;GAMG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAC9B,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,EACf,SAAS,EAAE,SAAS,EACpB,IAAI,GAAE,aAAkB,GACvB,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAoC5B"}
|
package/dist/record.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.js","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAUH,MAAM,YAAY,GAAG,
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAUH,MAAM,YAAY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KAAK,EAAE,CAC1D,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,MAAM,KAAK,CAAC;QAC3B,KAAK;QACL,QAAQ,EAAE,SAAS;QACnB,QAAQ,EAAE;YACR,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM;YAC9B,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB;KACF,CAAC;AACJ,CAAC"}
|
package/dist/registry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AA6B9C,yDAAyD;AACzD,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,cAAc,GAAG,IAAI,CAE/E;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,aAAa,CAAC;IACzC,QAAQ,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AA6B9C,yDAAyD;AACzD,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,cAAc,GAAG,IAAI,CAE/E;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,aAAa,CAAC;IACzC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC;CAClC,CAAC,CAQD;AAED,sEAAsE;AACtE,wBAAgB,uBAAuB,IAAI,IAAI,CAE9C;AAcD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,SAAI,GAAG,cAAc,GAAG,SAAS,CAehF;AAID,UAAU,UAAU;IAClB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAID,0EAA0E;AAC1E,wBAAgB,SAAS,IAAI,MAAM,CAGlC;AAED,8DAA8D;AAC9D,wBAAgB,UAAU,IAAI,MAAM,CAGnC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAEnF;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,UAAU,GAAG,SAAS,CAEnD"}
|
package/dist/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAYrD,uEAAuE;AACvE,sEAAsE;AACtE,qEAAqE;AACrE,wCAAwC;AACxC,MAAM,UAAU,GAAG,0BAAmC,CAAC;AAQvD,MAAM,CAAC,GAAG,UAA+B,CAAC;AAC1C,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK;IAC9B,QAAQ,
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":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AAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AAC7E,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,UAAU;IACxB,IAAI,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,CAAC;IAC5B,OAAO,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AACnD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAI,GAAe,EAAE,EAAoB;IACrE,OAAO,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AACjC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,UAAU,CAAC,QAAQ,EAAE,CAAC;AAC/B,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -8,6 +8,32 @@
|
|
|
8
8
|
* The observability surface (StepObservation / RunResult / Recording) is the
|
|
9
9
|
* contract every consumer relies on for tracing, scan, Studio, OTel, replay.
|
|
10
10
|
*/
|
|
11
|
+
/**
|
|
12
|
+
* The two fields every hook ctx carries, contributed by the runtime in
|
|
13
|
+
* `.run()`. Consumers extend this shape with whatever their handler / step
|
|
14
|
+
* needs — but `signal` + `set` are always there.
|
|
15
|
+
*
|
|
16
|
+
* - `signal` — Web-standard cooperative cancellation. The runtime sources
|
|
17
|
+
* it from `RunOptions.signal`; if none is provided, a non-aborting
|
|
18
|
+
* placeholder is supplied so handlers can pass it through without
|
|
19
|
+
* null checks.
|
|
20
|
+
* - `set(key, value)` — typed setter for contributing fields mid-chain.
|
|
21
|
+
* Uses a TS assertion function so subsequent steps + the rest of the
|
|
22
|
+
* current step see the widened type:
|
|
23
|
+
*
|
|
24
|
+
* ctx.set("user", user); // ctx now widened to (TCtx & { user: User })
|
|
25
|
+
* await next();
|
|
26
|
+
*
|
|
27
|
+
* Plain reassignment (`ctx.user = x`) still works when the field is
|
|
28
|
+
* declared on TCtx — `.set()` is the *contributing* primitive for cases
|
|
29
|
+
* where the field wasn't pre-declared on the ctx.
|
|
30
|
+
*/
|
|
31
|
+
export interface BaseHookCtx {
|
|
32
|
+
readonly signal: AbortSignal;
|
|
33
|
+
set<K extends string, V>(key: K, value: V): asserts this is this & {
|
|
34
|
+
[P in K]: V;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
11
37
|
/** A single link in a chain — koa-compose-shaped middleware. */
|
|
12
38
|
export type ChainFn<Ctx> = (ctx: Ctx, next: () => Promise<void>) => Promise<void> | void;
|
|
13
39
|
/** A listener — observes the final ctx state, never mutates it. */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,gEAAgE;AAChE,MAAM,MAAM,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAEzF,mEAAmE;AACnE,MAAM,MAAM,UAAU,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAE3E,uEAAuE;AACvE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,GAAG,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,IAAI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9B,kEAAkE;IAClE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,4DAA4D;AAC5D,MAAM,WAAW,SAAS,CAAC,GAAG;IAC5B,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAC/C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,qCAAqC;IACrC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAC/C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nwire/hooks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Nwire — the universal dispatch primitive. One hook() accepts both .use() (sequential koa-compose chain) and .on() (parallel listener) attachments. Built on emittery + a ~30 LOC composer. Standalone, in-process only, ~100 LOC of surface.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dispatch",
|