@nifrajs/core 1.13.0 → 2.1.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 +37 -1
- package/dist/assurance.d.ts +11 -2
- package/dist/assurance.d.ts.map +1 -1
- package/dist/assurance.js +20 -0
- package/dist/assurance.js.map +1 -1
- package/dist/capabilities.d.ts +54 -2
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +240 -5
- package/dist/capabilities.js.map +1 -1
- package/dist/durable-adapters.d.ts +241 -0
- package/dist/durable-adapters.d.ts.map +1 -0
- package/dist/durable-adapters.js +697 -0
- package/dist/durable-adapters.js.map +1 -0
- package/dist/durable-execution.d.ts +349 -0
- package/dist/durable-execution.d.ts.map +1 -0
- package/dist/durable-execution.js +1173 -0
- package/dist/durable-execution.js.map +1 -0
- package/dist/effect-ledger.d.ts +9 -0
- package/dist/effect-ledger.d.ts.map +1 -0
- package/dist/effect-ledger.js +8 -0
- package/dist/effect-ledger.js.map +1 -0
- package/dist/effect-lifecycle.d.ts +42 -0
- package/dist/effect-lifecycle.d.ts.map +1 -0
- package/dist/effect-lifecycle.js +66 -0
- package/dist/effect-lifecycle.js.map +1 -0
- package/dist/effect-scope.d.ts +75 -0
- package/dist/effect-scope.d.ts.map +1 -0
- package/dist/effect-scope.js +177 -0
- package/dist/effect-scope.js.map +1 -0
- package/dist/idempotency-plugin.d.ts +13 -0
- package/dist/idempotency-plugin.d.ts.map +1 -0
- package/dist/idempotency-plugin.js +16 -0
- package/dist/idempotency-plugin.js.map +1 -0
- package/dist/index.d.ts +6 -35
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -31
- package/dist/index.js.map +1 -1
- package/dist/internal/capability-runtime.d.ts +62 -1
- package/dist/internal/capability-runtime.d.ts.map +1 -1
- package/dist/internal/capability-runtime.js +11 -2
- package/dist/internal/capability-runtime.js.map +1 -1
- package/dist/internal/effect-execution.d.ts +16 -0
- package/dist/internal/effect-execution.d.ts.map +1 -0
- package/dist/internal/effect-execution.js +50 -0
- package/dist/internal/effect-execution.js.map +1 -0
- package/dist/internal/safe-equal.d.ts +20 -0
- package/dist/internal/safe-equal.d.ts.map +1 -0
- package/dist/internal/safe-equal.js +31 -0
- package/dist/internal/safe-equal.js.map +1 -0
- package/dist/ledger.d.ts +14 -6
- package/dist/ledger.d.ts.map +1 -1
- package/dist/ledger.js +31 -5
- package/dist/ledger.js.map +1 -1
- package/dist/mcp.d.ts +7 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +56 -0
- package/dist/mcp.js.map +1 -0
- package/dist/node-direct.d.ts +5 -0
- package/dist/node-direct.d.ts.map +1 -0
- package/dist/node-direct.js +27 -0
- package/dist/node-direct.js.map +1 -0
- package/dist/reconciliation-worker.d.ts +108 -0
- package/dist/reconciliation-worker.d.ts.map +1 -0
- package/dist/reconciliation-worker.js +239 -0
- package/dist/reconciliation-worker.js.map +1 -0
- package/dist/reflection.d.ts +5 -0
- package/dist/reflection.d.ts.map +1 -1
- package/dist/reflection.js +2 -0
- package/dist/reflection.js.map +1 -1
- package/dist/server/client-ip.d.ts +35 -0
- package/dist/server/client-ip.d.ts.map +1 -0
- package/dist/server/client-ip.js +42 -0
- package/dist/server/client-ip.js.map +1 -0
- package/dist/server/context.d.ts +47 -2
- package/dist/server/context.d.ts.map +1 -1
- package/dist/server/contract.d.ts +14 -4
- package/dist/server/contract.d.ts.map +1 -1
- package/dist/server/contract.js +8 -2
- package/dist/server/contract.js.map +1 -1
- package/dist/server/http.d.ts +14 -0
- package/dist/server/http.d.ts.map +1 -0
- package/dist/server/http.js +45 -0
- package/dist/server/http.js.map +1 -0
- package/dist/server/idempotency-lane.d.ts +45 -0
- package/dist/server/idempotency-lane.d.ts.map +1 -0
- package/dist/server/idempotency-lane.js +205 -0
- package/dist/server/idempotency-lane.js.map +1 -0
- package/dist/server/install.d.ts +21 -0
- package/dist/server/install.d.ts.map +1 -0
- package/dist/server/install.js +21 -0
- package/dist/server/install.js.map +1 -0
- package/dist/server/ledger-lane.d.ts +53 -0
- package/dist/server/ledger-lane.d.ts.map +1 -0
- package/dist/server/ledger-lane.js +82 -0
- package/dist/server/ledger-lane.js.map +1 -0
- package/dist/server/mcp-hook.d.ts +28 -0
- package/dist/server/mcp-hook.d.ts.map +1 -0
- package/dist/server/mcp-hook.js +2 -0
- package/dist/server/mcp-hook.js.map +1 -0
- package/dist/server/node-outcome-hook.d.ts +9 -0
- package/dist/server/node-outcome-hook.d.ts.map +1 -0
- package/dist/server/node-outcome-hook.js +2 -0
- package/dist/server/node-outcome-hook.js.map +1 -0
- package/dist/server/node-outcome.d.ts +37 -0
- package/dist/server/node-outcome.d.ts.map +1 -0
- package/dist/server/node-outcome.js +75 -0
- package/dist/server/node-outcome.js.map +1 -0
- package/dist/server/plugin.d.ts +78 -0
- package/dist/server/plugin.d.ts.map +1 -0
- package/dist/server/plugin.js +57 -0
- package/dist/server/plugin.js.map +1 -0
- package/dist/server/query.d.ts +18 -0
- package/dist/server/query.d.ts.map +1 -0
- package/dist/server/query.js +102 -0
- package/dist/server/query.js.map +1 -0
- package/dist/server/registry.d.ts +31 -6
- package/dist/server/registry.d.ts.map +1 -1
- package/dist/server/request-context.d.ts +51 -0
- package/dist/server/request-context.d.ts.map +1 -0
- package/dist/server/request-context.js +184 -0
- package/dist/server/request-context.js.map +1 -0
- package/dist/server/respond.d.ts +17 -0
- package/dist/server/respond.d.ts.map +1 -0
- package/dist/server/respond.js +81 -0
- package/dist/server/respond.js.map +1 -0
- package/dist/server/runtime-core.d.ts +36 -0
- package/dist/server/runtime-core.d.ts.map +1 -0
- package/dist/server/runtime-core.js +51 -0
- package/dist/server/runtime-core.js.map +1 -0
- package/dist/server/server-types.d.ts +203 -0
- package/dist/server/server-types.d.ts.map +1 -0
- package/dist/server/server-types.js +2 -0
- package/dist/server/server-types.js.map +1 -0
- package/dist/server/server.d.ts +119 -345
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +247 -833
- package/dist/server/server.js.map +1 -1
- package/dist/server/sse-hook.d.ts +10 -0
- package/dist/server/sse-hook.d.ts.map +1 -0
- package/dist/server/sse-hook.js +2 -0
- package/dist/server/sse-hook.js.map +1 -0
- package/dist/server/sse.d.ts +7 -23
- package/dist/server/sse.d.ts.map +1 -1
- package/dist/server/sse.js +18 -0
- package/dist/server/sse.js.map +1 -1
- package/dist/server/transport-lane.d.ts +28 -0
- package/dist/server/transport-lane.d.ts.map +1 -0
- package/dist/server/transport-lane.js +106 -0
- package/dist/server/transport-lane.js.map +1 -0
- package/dist/server/websocket.d.ts +23 -1
- package/dist/server/websocket.d.ts.map +1 -1
- package/dist/server/websocket.js +10 -1
- package/dist/server/websocket.js.map +1 -1
- package/dist/server/ws-hook.d.ts +8 -11
- package/dist/server/ws-hook.d.ts.map +1 -1
- package/dist/server/ws-hook.js +7 -14
- package/dist/server/ws-hook.js.map +1 -1
- package/dist/server.d.ts +21 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +16 -0
- package/dist/server.js.map +1 -0
- package/dist/transport-codec-rich.d.ts +8 -0
- package/dist/transport-codec-rich.d.ts.map +1 -0
- package/dist/transport-codec-rich.js +14 -0
- package/dist/transport-codec-rich.js.map +1 -0
- package/dist/transport-codec.d.ts +31 -0
- package/dist/transport-codec.d.ts.map +1 -0
- package/dist/transport-codec.js +190 -0
- package/dist/transport-codec.js.map +1 -0
- package/dist/transport-plugin.d.ts +3 -0
- package/dist/transport-plugin.d.ts.map +1 -0
- package/dist/transport-plugin.js +3 -0
- package/dist/transport-plugin.js.map +1 -0
- package/dist/wire.d.ts +58 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +445 -0
- package/dist/wire.js.map +1 -0
- package/dist/ws.d.ts +16 -7
- package/dist/ws.d.ts.map +1 -1
- package/dist/ws.js +25 -10
- package/dist/ws.js.map +1 -1
- package/package.json +122 -6
- package/src/assurance.ts +36 -1
- package/src/capabilities.ts +306 -5
- package/src/durable-adapters.ts +1039 -0
- package/src/durable-execution.ts +1676 -0
- package/src/effect-ledger.ts +9 -0
- package/src/effect-lifecycle.ts +120 -0
- package/src/effect-scope.ts +267 -0
- package/src/idempotency-plugin.ts +17 -0
- package/src/index.ts +6 -133
- package/src/internal/capability-runtime.ts +87 -1
- package/src/internal/effect-execution.ts +70 -0
- package/src/internal/safe-equal.ts +27 -0
- package/src/ledger.ts +45 -11
- package/src/mcp.ts +65 -0
- package/src/node-direct.ts +37 -0
- package/src/reconciliation-worker.ts +372 -0
- package/src/reflection.ts +7 -0
- package/src/server/client-ip.ts +60 -0
- package/src/server/context.ts +50 -2
- package/src/server/contract.ts +26 -7
- package/src/server/http.ts +58 -0
- package/src/server/idempotency-lane.ts +321 -0
- package/src/server/install.ts +28 -0
- package/src/server/ledger-lane.ts +125 -0
- package/src/server/mcp-hook.ts +41 -0
- package/src/server/node-outcome-hook.ts +9 -0
- package/src/server/node-outcome.ts +112 -0
- package/src/server/plugin.ts +92 -0
- package/src/server/query.ts +119 -0
- package/src/server/registry.ts +36 -6
- package/src/server/request-context.ts +271 -0
- package/src/server/respond.ts +94 -0
- package/src/server/runtime-core.ts +74 -0
- package/src/server/server-types.ts +204 -0
- package/src/server/server.ts +448 -1314
- package/src/server/sse-hook.ts +14 -0
- package/src/server/sse.ts +26 -0
- package/src/server/transport-lane.ts +141 -0
- package/src/server/websocket.ts +35 -1
- package/src/server/ws-hook.ts +8 -19
- package/src/server.ts +92 -0
- package/src/transport-codec-rich.ts +20 -0
- package/src/transport-codec.ts +250 -0
- package/src/transport-plugin.ts +2 -0
- package/src/wire.ts +474 -0
- package/src/ws.ts +33 -10
- package/dist/invariants.d.ts +0 -70
- package/dist/invariants.d.ts.map +0 -1
- package/dist/invariants.js +0 -487
- package/dist/invariants.js.map +0 -1
- package/src/invariants.ts +0 -604
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public API-surface types for the server: construction options, the capacity-admission contract,
|
|
3
|
+
* route/tool/MCP descriptors, and the middleware bundle shape. Pure types (no runtime), split out of
|
|
4
|
+
* the server kernel so the descriptor/option vocabulary is one file, distinct from the engine.
|
|
5
|
+
*/
|
|
6
|
+
import type { CapabilityUseEvent } from "../internal/capability-runtime.js";
|
|
7
|
+
import type { AssuranceEvidence } from "../internal/route-assurance.js";
|
|
8
|
+
import type { Method } from "../router/router.js";
|
|
9
|
+
import type { ClientIpTrust } from "./client-ip.js";
|
|
10
|
+
import type { Context, Platform, RouteSchema } from "./context.js";
|
|
11
|
+
import type { Logger } from "./logger.js";
|
|
12
|
+
import type { MaybePromise, OnRequestResult } from "./server.js";
|
|
13
|
+
/**
|
|
14
|
+
* The outcome of a capacity-admission decision. `admitted` requests carry a `release` the server calls
|
|
15
|
+
* exactly once when the response is finalized; a shed request carries a ready `429` Response.
|
|
16
|
+
*/
|
|
17
|
+
export type AdmissionDecision = {
|
|
18
|
+
readonly admitted: true;
|
|
19
|
+
release(): void;
|
|
20
|
+
} | {
|
|
21
|
+
readonly admitted: false;
|
|
22
|
+
readonly response: Response;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* A capacity-admission gate. Decides, per request, whether the instance has capacity to run it now -
|
|
26
|
+
* bounding *concurrency*, which rate limits (frequency) and deadlines (duration) do not. Provide an
|
|
27
|
+
* implementation (see `@nifrajs/middleware`'s `createAdmissionController`) as {@link ServerOptions.admission}.
|
|
28
|
+
*
|
|
29
|
+
* Enabling it trades the fused native-route lane for native matching + this gate (the gate cannot be a
|
|
30
|
+
* per-request `onRequest` hook without disabling native routes entirely); when unset, the request path
|
|
31
|
+
* is untouched.
|
|
32
|
+
*/
|
|
33
|
+
export interface AdmissionController {
|
|
34
|
+
admit(req: Request): AdmissionDecision | Promise<AdmissionDecision>;
|
|
35
|
+
}
|
|
36
|
+
export interface ServerOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Max request body size (bytes), enforced **only when a route declares a body schema** - the cap
|
|
39
|
+
* lives in the schema-validated read path. Default 1_000_000.
|
|
40
|
+
*
|
|
41
|
+
* A route WITHOUT a body schema (raw body, file upload, BYO-validation) that reads `c.req` directly
|
|
42
|
+
* is not auto-bounded - use **`c.boundedBody(maxBytes?)`** / **`c.boundedJson(maxBytes?)`**, which
|
|
43
|
+
* apply this same cap (override per route by passing `maxBytes` - larger for an upload endpoint,
|
|
44
|
+
* smaller to tighten one).
|
|
45
|
+
*/
|
|
46
|
+
readonly maxBodyBytes?: number;
|
|
47
|
+
/** Max inbound WebSocket message size (bytes) when `listen()`ing on Bun - frames over this are rejected
|
|
48
|
+
* by the runtime before reaching your handler (so a huge frame can't be JSON-parsed into memory).
|
|
49
|
+
* Default: `maxBodyBytes` (1 MB). */
|
|
50
|
+
readonly wsMaxPayloadBytes?: number;
|
|
51
|
+
/** Per-request timeout (ms): a slower request gets a 503 and `ctx.signal` aborts. 0 disables (default). */
|
|
52
|
+
readonly requestTimeoutMs?: number;
|
|
53
|
+
/**
|
|
54
|
+
* How to derive `c.clientIp` behind a reverse proxy or CDN. Omit (default) to trust only the raw
|
|
55
|
+
* socket peer and never believe a forwarded header. Set `{ trustedHops: n }` when the app sits
|
|
56
|
+
* behind `n` proxies you operate (the caller is read from `X-Forwarded-For` past those hops), or
|
|
57
|
+
* `{ header: name }` to trust one edge-set header's first value. Declaring trust the app can't
|
|
58
|
+
* actually enforce lets clients forge their IP, so leave it unset unless a proxy really fronts you.
|
|
59
|
+
*/
|
|
60
|
+
readonly clientIp?: ClientIpTrust;
|
|
61
|
+
/**
|
|
62
|
+
* Admit the public `x-nifra-deadline` header and let it shorten local work. Disabled by default:
|
|
63
|
+
* services that participate in trusted cross-service deadline propagation opt in explicitly,
|
|
64
|
+
* while ordinary/public HTTP routes pay no header-admission tax and ignore hostile client values.
|
|
65
|
+
*/
|
|
66
|
+
readonly acceptInboundDeadlines?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Maximum time accepted from an inbound `x-nifra-deadline`, in milliseconds. An incoming absolute
|
|
69
|
+
* deadline may shorten this cap (and `requestTimeoutMs`, when configured), never extend it.
|
|
70
|
+
* Default 30_000; applies only when `acceptInboundDeadlines` is enabled and the header is present.
|
|
71
|
+
*/
|
|
72
|
+
readonly maxInboundDeadlineMs?: number;
|
|
73
|
+
/** When `listen()`ing, install SIGTERM/SIGINT handlers that gracefully `stop()`. Default false. */
|
|
74
|
+
readonly gracefulSignals?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Capacity-admission gate (see {@link AdmissionController}). Bounds concurrent in-flight work so a
|
|
77
|
+
* healthy instance sheds load (`429` + `Retry-After`) instead of accepting more than it can finish.
|
|
78
|
+
* Off by default. Enabling it disables the fused native-route fast path (requests route through the
|
|
79
|
+
* shared matched lane where the gate runs); when unset, the request path pays nothing.
|
|
80
|
+
*/
|
|
81
|
+
readonly admission?: AdmissionController;
|
|
82
|
+
/**
|
|
83
|
+
* Optional token-only observation hook called by `useCapability(c, id)`. It receives no request,
|
|
84
|
+
* parameters, body, tenant, or values. Routes without capability declarations keep the old hot path.
|
|
85
|
+
*/
|
|
86
|
+
readonly onCapabilityUse?: (event: CapabilityUseEvent) => void;
|
|
87
|
+
/** Structured logger for framework events (redacts secrets). Default: JSON to stderr. */
|
|
88
|
+
readonly logger?: Logger;
|
|
89
|
+
/**
|
|
90
|
+
* App-wide fallback fired when a route **without its own `onValidationError`** fails body/query
|
|
91
|
+
* validation. Same contract as the per-route hook (`(issues, ctx, kind) => Response | repaired-value |
|
|
92
|
+
* undefined`): a route's own hook takes precedence, and a route can fall through to the plain `422` by
|
|
93
|
+
* returning `undefined`. Use it for one app-wide error envelope (like tRPC's `errorFormatter` /
|
|
94
|
+
* Fastify's `setErrorHandler`) instead of repeating a formatter per route.
|
|
95
|
+
*/
|
|
96
|
+
readonly onValidationError?: RouteSchema["onValidationError"];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* MCP tool safety hints, surfaced in `tools/list`, that tell an agent how risky a `.tool()` call is - so it
|
|
100
|
+
* can decide whether to auto-invoke or confirm first. All optional; an omitted hint means "unknown". Mirrors
|
|
101
|
+
* the MCP spec's tool `annotations`.
|
|
102
|
+
*/
|
|
103
|
+
export interface ToolAnnotations {
|
|
104
|
+
/** Human-readable display title for the tool, distinct from the machine `name`. */
|
|
105
|
+
readonly title?: string;
|
|
106
|
+
/** The tool does not modify its environment (a pure read). */
|
|
107
|
+
readonly readOnlyHint?: boolean;
|
|
108
|
+
/** The tool may perform destructive updates - only meaningful when `readOnlyHint` is not `true`. */
|
|
109
|
+
readonly destructiveHint?: boolean;
|
|
110
|
+
/** Repeated calls with the same arguments have no additional effect beyond the first. */
|
|
111
|
+
readonly idempotentHint?: boolean;
|
|
112
|
+
/** The tool interacts with external entities (an "open world" beyond this server). */
|
|
113
|
+
readonly openWorldHint?: boolean;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* A registered route's public descriptor - method, path, and input schemas. The
|
|
117
|
+
* router trie discards the original patterns, so this flat list is what lets tools
|
|
118
|
+
* (e.g. `toOpenAPI`) enumerate routes after registration.
|
|
119
|
+
*/
|
|
120
|
+
export interface RouteDescriptor {
|
|
121
|
+
readonly method: Method;
|
|
122
|
+
readonly path: string;
|
|
123
|
+
readonly schema: RouteSchema | undefined;
|
|
124
|
+
/** Effective enforcement evidence, populated only during reflection/introspection. */
|
|
125
|
+
readonly assurance?: readonly AssuranceEvidence[];
|
|
126
|
+
/** Normalized declared effect tokens, populated only when the route declares any. */
|
|
127
|
+
readonly capabilities?: readonly string[];
|
|
128
|
+
/** Set when the route is a declared dynamic route family (`schema.family`). */
|
|
129
|
+
readonly family?: boolean;
|
|
130
|
+
readonly tool?: {
|
|
131
|
+
readonly name: string;
|
|
132
|
+
readonly description: string;
|
|
133
|
+
readonly annotations?: ToolAnnotations;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/** A message in an MCP prompt's rendered output (see {@link Server.prompt}). */
|
|
137
|
+
export interface PromptMessage {
|
|
138
|
+
readonly role: "user" | "assistant";
|
|
139
|
+
readonly content: {
|
|
140
|
+
readonly type: "text";
|
|
141
|
+
readonly text: string;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/** One declared argument of an MCP prompt, surfaced in `prompts/list`. */
|
|
145
|
+
export interface PromptArgument {
|
|
146
|
+
readonly name: string;
|
|
147
|
+
readonly description?: string;
|
|
148
|
+
readonly required?: boolean;
|
|
149
|
+
}
|
|
150
|
+
/** An app-declared MCP resource - read-only data an agent can fetch through `nifra mcp`. */
|
|
151
|
+
export interface McpResourceDescriptor {
|
|
152
|
+
readonly uri: string;
|
|
153
|
+
readonly name: string;
|
|
154
|
+
readonly description?: string;
|
|
155
|
+
readonly mimeType?: string;
|
|
156
|
+
readonly read: () => MaybePromise<string | {
|
|
157
|
+
readonly text: string;
|
|
158
|
+
readonly mimeType?: string;
|
|
159
|
+
}>;
|
|
160
|
+
}
|
|
161
|
+
/** An app-declared MCP prompt - a reusable prompt template an agent can fetch through `nifra mcp`. */
|
|
162
|
+
export interface McpPromptDescriptor {
|
|
163
|
+
readonly name: string;
|
|
164
|
+
readonly description: string;
|
|
165
|
+
readonly arguments?: readonly PromptArgument[];
|
|
166
|
+
readonly handler: (args: Record<string, string>) => MaybePromise<readonly PromptMessage[]>;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The handle `listen()` returns - the slice of Bun's server nifra holds and exposes.
|
|
170
|
+
* Declared explicitly (rather than `ReturnType<typeof Bun.serve>`) so the public type
|
|
171
|
+
* surface doesn't leak the ambient `Bun` global into consumers' `.d.ts` resolution.
|
|
172
|
+
*/
|
|
173
|
+
export interface RunningServer {
|
|
174
|
+
readonly port: number;
|
|
175
|
+
readonly hostname: string;
|
|
176
|
+
readonly pendingRequests: number;
|
|
177
|
+
stop(closeActiveConnections?: boolean): void;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* A bundle of lifecycle hooks applied together via {@link Server.use} - the unit
|
|
181
|
+
* `@nifrajs/middleware` ships (cors, security headers, rate-limit). Every hook is
|
|
182
|
+
* optional and wired to its lifecycle point. Middleware is context-agnostic (sees
|
|
183
|
+
* the base `Context`); `use` does no context-type merging - the full type-merging
|
|
184
|
+
* plugin system is deferred, and `.use` is reserved as its future entry point.
|
|
185
|
+
*/
|
|
186
|
+
export interface Middleware {
|
|
187
|
+
readonly name?: string;
|
|
188
|
+
readonly onRequest?: (req: Request, platform?: Platform) => MaybePromise<OnRequestResult>;
|
|
189
|
+
readonly around?: <T>(context: Context, next: () => MaybePromise<T>) => MaybePromise<T>;
|
|
190
|
+
readonly beforeHandle?: (context: Context) => MaybePromise<unknown>;
|
|
191
|
+
readonly afterHandle?: (result: unknown, context: Context) => MaybePromise<unknown>;
|
|
192
|
+
readonly onResponse?: (response: Response, req: Request) => MaybePromise<Response>;
|
|
193
|
+
readonly onResponseFinalized?: (outcome: ResponseFinalization, req: Request) => MaybePromise<void>;
|
|
194
|
+
readonly onError?: (error: unknown, context: Context) => MaybePromise<unknown>;
|
|
195
|
+
}
|
|
196
|
+
/** The terminal response-pipeline outcome observed after every transforming `onResponse` hook. */
|
|
197
|
+
export interface ResponseFinalization {
|
|
198
|
+
/** The final response, or the last response available when a transformation failed. */
|
|
199
|
+
readonly response: Response;
|
|
200
|
+
/** A response-hook failure. Terminal observers run fail-open before the error is rethrown. */
|
|
201
|
+
readonly error?: unknown;
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=server-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-types.d.ts","sourceRoot":"","sources":["../../src/server/server-types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAC3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB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