@nifrajs/core 2.14.1 → 3.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 +4 -0
- package/dist/assurance.d.ts +16 -8
- package/dist/assurance.d.ts.map +1 -1
- package/dist/assurance.js +33 -0
- package/dist/assurance.js.map +1 -1
- package/dist/edge-kit.d.ts +27 -0
- package/dist/edge-kit.d.ts.map +1 -0
- package/dist/edge-kit.js +24 -0
- package/dist/edge-kit.js.map +1 -0
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/route-execution.d.ts +11 -5
- package/dist/internal/route-execution.d.ts.map +1 -1
- package/dist/internal/route-execution.js +2 -1
- package/dist/internal/route-execution.js.map +1 -1
- package/dist/response-observer.d.ts +25 -0
- package/dist/response-observer.d.ts.map +1 -0
- package/dist/response-observer.js +40 -0
- package/dist/response-observer.js.map +1 -0
- package/dist/security/baseline.d.ts +68 -0
- package/dist/security/baseline.d.ts.map +1 -0
- package/dist/security/baseline.js +118 -0
- package/dist/security/baseline.js.map +1 -0
- package/dist/server/bare-error-lane.d.ts +26 -0
- package/dist/server/bare-error-lane.d.ts.map +1 -0
- package/dist/server/bare-error-lane.js +60 -0
- package/dist/server/bare-error-lane.js.map +1 -0
- package/dist/server/body.d.ts +7 -0
- package/dist/server/body.d.ts.map +1 -1
- package/dist/server/body.js +7 -0
- package/dist/server/body.js.map +1 -1
- package/dist/server/bridge-markers.d.ts +25 -0
- package/dist/server/bridge-markers.d.ts.map +1 -0
- package/dist/server/bridge-markers.js +25 -0
- package/dist/server/bridge-markers.js.map +1 -0
- package/dist/server/context.d.ts +6 -1
- package/dist/server/context.d.ts.map +1 -1
- package/dist/server/header-case.d.ts.map +1 -1
- package/dist/server/header-case.js +2 -1
- package/dist/server/header-case.js.map +1 -1
- package/dist/server/http.d.ts +36 -3
- package/dist/server/http.d.ts.map +1 -1
- package/dist/server/http.js +49 -3
- package/dist/server/http.js.map +1 -1
- package/dist/server/install.d.ts +6 -8
- package/dist/server/install.d.ts.map +1 -1
- package/dist/server/install.js +7 -0
- package/dist/server/install.js.map +1 -1
- package/dist/server/node-outcome-hook.d.ts +2 -1
- package/dist/server/node-outcome-hook.d.ts.map +1 -1
- package/dist/server/node-outcome-hook.js.map +1 -1
- package/dist/server/node-outcome.d.ts +17 -2
- package/dist/server/node-outcome.d.ts.map +1 -1
- package/dist/server/node-outcome.js +37 -3
- package/dist/server/node-outcome.js.map +1 -1
- package/dist/server/query.d.ts +7 -1
- package/dist/server/query.d.ts.map +1 -1
- package/dist/server/query.js +8 -3
- package/dist/server/query.js.map +1 -1
- package/dist/server/request-context.d.ts +17 -4
- package/dist/server/request-context.d.ts.map +1 -1
- package/dist/server/request-context.js +63 -29
- package/dist/server/request-context.js.map +1 -1
- package/dist/server/respond.d.ts.map +1 -1
- package/dist/server/respond.js +19 -2
- package/dist/server/respond.js.map +1 -1
- package/dist/server/response-contract-lane.d.ts.map +1 -1
- package/dist/server/response-contract-lane.js +5 -2
- package/dist/server/response-contract-lane.js.map +1 -1
- package/dist/server/response-observer-runtime.d.ts +20 -0
- package/dist/server/response-observer-runtime.d.ts.map +1 -0
- package/dist/server/response-observer-runtime.js +95 -0
- package/dist/server/response-observer-runtime.js.map +1 -0
- package/dist/server/runtime-core.d.ts +60 -0
- package/dist/server/runtime-core.d.ts.map +1 -1
- package/dist/server/runtime-core.js +65 -1
- package/dist/server/runtime-core.js.map +1 -1
- package/dist/server/server-types.d.ts +3 -1
- package/dist/server/server-types.d.ts.map +1 -1
- package/dist/server/server.d.ts +52 -39
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +267 -271
- package/dist/server/server.js.map +1 -1
- package/dist/server/websocket.d.ts +20 -4
- package/dist/server/websocket.d.ts.map +1 -1
- package/dist/server/websocket.js +81 -11
- package/dist/server/websocket.js.map +1 -1
- package/dist/server/ws-bun.d.ts +1 -1
- package/dist/server/ws-bun.d.ts.map +1 -1
- package/dist/server/ws-bun.js +12 -8
- package/dist/server/ws-bun.js.map +1 -1
- package/dist/server.d.ts +2 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +2 -1
- package/dist/server.js.map +1 -1
- package/dist/single-copy-register.d.ts +2 -0
- package/dist/single-copy-register.d.ts.map +1 -0
- package/dist/single-copy-register.js +24 -0
- package/dist/single-copy-register.js.map +1 -0
- package/dist/single-copy.d.ts +156 -0
- package/dist/single-copy.d.ts.map +1 -0
- package/dist/single-copy.js +470 -0
- package/dist/single-copy.js.map +1 -0
- package/package.json +24 -2
- package/src/assurance.ts +58 -1
- package/src/edge-kit.ts +27 -0
- package/src/errors.ts +1 -0
- package/src/index.ts +1 -1
- package/src/internal/route-execution.ts +23 -16
- package/src/response-observer.ts +64 -0
- package/src/security/baseline.ts +172 -0
- package/src/server/bare-error-lane.ts +76 -0
- package/src/server/body.ts +8 -0
- package/src/server/bridge-markers.ts +24 -0
- package/src/server/context.ts +6 -1
- package/src/server/header-case.ts +3 -1
- package/src/server/http.ts +53 -3
- package/src/server/install.ts +14 -0
- package/src/server/node-outcome-hook.ts +2 -1
- package/src/server/node-outcome.ts +44 -3
- package/src/server/query.ts +10 -4
- package/src/server/request-context.ts +85 -33
- package/src/server/respond.ts +26 -1
- package/src/server/response-contract-lane.ts +6 -2
- package/src/server/response-observer-runtime.ts +135 -0
- package/src/server/runtime-core.ts +98 -1
- package/src/server/server-types.ts +3 -1
- package/src/server/server.ts +436 -367
- package/src/server/websocket.ts +127 -17
- package/src/server/ws-bun.ts +26 -7
- package/src/server.ts +2 -1
- package/src/single-copy-register.ts +24 -0
- package/src/single-copy.ts +524 -0
|
@@ -98,10 +98,18 @@ export interface WebSocketHandler<Data = unknown, Env = unknown, Schema extends
|
|
|
98
98
|
/**
|
|
99
99
|
* The **outbound** frame contract (server → client), a Standard Schema. Purely type-level: it types
|
|
100
100
|
* the frames the typed client's `.ws()` handle receives, and documents what this route pushes. The
|
|
101
|
-
* server does NOT runtime-validate its own sends - the inbound `messageSchema` guards the
|
|
102
|
-
* boundary; outbound honesty is the handler author's code
|
|
101
|
+
* server does NOT runtime-validate its own sends by default - the inbound `messageSchema` guards the
|
|
102
|
+
* trust boundary; outbound honesty is the handler author's code. Set {@link validateSend} to opt into
|
|
103
|
+
* a synchronous runtime check of JSON text/UTF-8 binary frames.
|
|
103
104
|
*/
|
|
104
105
|
sendSchema?: Send;
|
|
106
|
+
/**
|
|
107
|
+
* Opt-in runtime enforcement for {@link sendSchema}. Invalid JSON, schema failures, and async
|
|
108
|
+
* validators are dropped before the native socket's `send()` runs and reported to `error()` when it
|
|
109
|
+
* exists. This is a development/contract check for the server's own output, not an inbound security
|
|
110
|
+
* boundary. It is off by default and requires `sendSchema` at registration.
|
|
111
|
+
*/
|
|
112
|
+
validateSend?: boolean;
|
|
105
113
|
/** Decode versioned transport frames before inbound schema validation. Omit for legacy JSON. */
|
|
106
114
|
transport?: {
|
|
107
115
|
readonly registry: TransportCodecRegistry;
|
|
@@ -165,11 +173,19 @@ export interface StandardWebSocket {
|
|
|
165
173
|
* `open` event (Deno). Lifecycle callbacks are error-isolated - a throw (or async rejection) routes to
|
|
166
174
|
* `error()` and never tears the process down; binary frames are normalized to `Uint8Array`.
|
|
167
175
|
*/
|
|
168
|
-
export declare function attachWebSocket(socket: StandardWebSocket, handler: WebSocketHandler, data: unknown, options: {
|
|
176
|
+
export declare function attachWebSocket<Data = unknown, Env = unknown, Schema extends StandardSchemaV1 | undefined = undefined, Send extends StandardSchemaV1 | undefined = undefined>(socket: StandardWebSocket, handler: WebSocketHandler<Data, Env, Schema, Send>, data: unknown, options: {
|
|
169
177
|
openNow: boolean;
|
|
170
178
|
pubsub: TopicRegistry;
|
|
171
179
|
maxPayloadBytes?: number;
|
|
172
|
-
}): NifraWebSocket
|
|
180
|
+
}): NifraWebSocket<Data>;
|
|
181
|
+
type WebSocketSendPayload = string | ArrayBufferView | ArrayBuffer;
|
|
182
|
+
/**
|
|
183
|
+
* Build the socket's send function once. The disabled path returns the native sender directly, so
|
|
184
|
+
* the default type-only contract adds no per-frame branch or schema work. Runtime validation is
|
|
185
|
+
* deliberately synchronous: a socket `send()` cannot await an async Standard Schema without changing
|
|
186
|
+
* the portable API, so an async result fails closed and is never sent.
|
|
187
|
+
*/
|
|
188
|
+
export declare function createWebSocketSender(send: (payload: WebSocketSendPayload) => void, schema: StandardSchemaV1 | undefined, enabled: boolean | undefined, transport: WebSocketHandler["transport"], onError: (error: unknown) => void): (payload: WebSocketSendPayload) => void;
|
|
173
189
|
/**
|
|
174
190
|
* If the handler declares a `messageSchema`, return a copy whose `message` validates each frame -
|
|
175
191
|
* parse as JSON, run the Standard Schema, then call the user's `message` with the typed value, or
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../src/server/websocket.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,gBAAgB,EAEjB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAwB,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAEzF,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AAErC,4FAA4F;AAC5F,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,UAAU,CAAA;AAE/C;+DAC+D;AAC/D,KAAK,cAAc,CAAC,MAAM,SAAS,gBAAgB,GAAG,SAAS,IAAI,MAAM,SAAS,gBAAgB,GAC9F,WAAW,CAAC,MAAM,CAAC,GACnB,aAAa,CAAA;AAEjB,kGAAkG;AAClG,MAAM,WAAW,cAAc,CAAC,IAAI,GAAG,OAAO;IAC5C,6FAA6F;IAC7F,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,eA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eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7E,cAAc,CAAC,IAAI,CAAC,CA+EtB;AAKD,KAAK,oBAAoB,GAAG,MAAM,GAAG,eAAe,GAAG,WAAW,CAAA;AAuBlE;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,EAC7C,MAAM,EAAE,gBAAgB,GAAG,SAAS,EACpC,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,EACxC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAChC,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CA8CzC;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAgC1F"}
|
package/dist/server/websocket.js
CHANGED
|
@@ -91,17 +91,7 @@ function toBinary(raw) {
|
|
|
91
91
|
*/
|
|
92
92
|
export function attachWebSocket(socket, handler, data, options) {
|
|
93
93
|
const { pubsub } = options;
|
|
94
|
-
|
|
95
|
-
send: (payload) => socket.send(payload),
|
|
96
|
-
close: (code, reason) => socket.close(code, reason),
|
|
97
|
-
get readyState() {
|
|
98
|
-
return socket.readyState;
|
|
99
|
-
},
|
|
100
|
-
subscribe: (topic) => pubsub.subscribe(topic, ws),
|
|
101
|
-
unsubscribe: (topic) => pubsub.unsubscribe(topic, ws),
|
|
102
|
-
data,
|
|
103
|
-
raw: socket,
|
|
104
|
-
};
|
|
94
|
+
let ws;
|
|
105
95
|
const reportError = (error) => {
|
|
106
96
|
if (handler.error === undefined)
|
|
107
97
|
return;
|
|
@@ -114,6 +104,18 @@ export function attachWebSocket(socket, handler, data, options) {
|
|
|
114
104
|
/* the error handler itself failed - last resort, swallow */
|
|
115
105
|
}
|
|
116
106
|
};
|
|
107
|
+
const send = createWebSocketSender((payload) => socket.send(payload), handler.sendSchema, handler.validateSend, handler.transport, reportError);
|
|
108
|
+
ws = {
|
|
109
|
+
send,
|
|
110
|
+
close: (code, reason) => socket.close(code, reason),
|
|
111
|
+
get readyState() {
|
|
112
|
+
return socket.readyState;
|
|
113
|
+
},
|
|
114
|
+
subscribe: (topic) => pubsub.subscribe(topic, ws),
|
|
115
|
+
unsubscribe: (topic) => pubsub.unsubscribe(topic, ws),
|
|
116
|
+
data: data,
|
|
117
|
+
raw: socket,
|
|
118
|
+
};
|
|
117
119
|
const safe = (call) => {
|
|
118
120
|
try {
|
|
119
121
|
const r = call();
|
|
@@ -160,6 +162,74 @@ export function attachWebSocket(socket, handler, data, options) {
|
|
|
160
162
|
}
|
|
161
163
|
const WS_MESSAGE_DECODER = new TextDecoder();
|
|
162
164
|
const WS_PAYLOAD_ENCODER = new TextEncoder();
|
|
165
|
+
const OUTBOUND_VALIDATION_ERROR = "outbound WebSocket frame failed sendSchema validation";
|
|
166
|
+
function outboundValueOf(payload, transport) {
|
|
167
|
+
const text = typeof payload === "string"
|
|
168
|
+
? payload
|
|
169
|
+
: WS_MESSAGE_DECODER.decode(payload instanceof ArrayBuffer
|
|
170
|
+
? new Uint8Array(payload)
|
|
171
|
+
: new Uint8Array(payload.buffer, payload.byteOffset, payload.byteLength));
|
|
172
|
+
return transport === undefined
|
|
173
|
+
? JSON.parse(text)
|
|
174
|
+
: decodeTransportFrame(text, transport.registry, {
|
|
175
|
+
...(transport.maxBytes === undefined ? {} : { maxBytes: transport.maxBytes }),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Build the socket's send function once. The disabled path returns the native sender directly, so
|
|
180
|
+
* the default type-only contract adds no per-frame branch or schema work. Runtime validation is
|
|
181
|
+
* deliberately synchronous: a socket `send()` cannot await an async Standard Schema without changing
|
|
182
|
+
* the portable API, so an async result fails closed and is never sent.
|
|
183
|
+
*/
|
|
184
|
+
export function createWebSocketSender(send, schema, enabled, transport, onError) {
|
|
185
|
+
if (enabled !== true || schema === undefined)
|
|
186
|
+
return send;
|
|
187
|
+
let reporting = false;
|
|
188
|
+
const reportFailure = (error) => {
|
|
189
|
+
// An error handler may try to send a diagnostic. Do not recurse forever when that diagnostic also
|
|
190
|
+
// violates the same outbound contract. EVERY failure path reports through here - a path that calls
|
|
191
|
+
// `onError` directly reopens that recursion for the one rejection shape it happens to cover.
|
|
192
|
+
if (reporting)
|
|
193
|
+
return;
|
|
194
|
+
reporting = true;
|
|
195
|
+
try {
|
|
196
|
+
onError(error);
|
|
197
|
+
}
|
|
198
|
+
finally {
|
|
199
|
+
reporting = false;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
return (payload) => {
|
|
203
|
+
let value;
|
|
204
|
+
try {
|
|
205
|
+
value = outboundValueOf(payload, transport);
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
reportFailure(new Error(OUTBOUND_VALIDATION_ERROR));
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
let outcome;
|
|
212
|
+
try {
|
|
213
|
+
outcome = validateStandard(schema, value);
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
reportFailure(new Error(OUTBOUND_VALIDATION_ERROR));
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (outcome instanceof Promise) {
|
|
220
|
+
// Do not await or send later: the portable `send()` contract is synchronous. Attach a rejection
|
|
221
|
+
// handler so a validator that rejects cannot become an unhandled process-level rejection.
|
|
222
|
+
outcome.catch(() => { });
|
|
223
|
+
reportFailure(new Error(`${OUTBOUND_VALIDATION_ERROR}; validator must be synchronous`));
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (!outcome.ok) {
|
|
227
|
+
reportFailure(new Error(OUTBOUND_VALIDATION_ERROR));
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
send(payload);
|
|
231
|
+
};
|
|
232
|
+
}
|
|
163
233
|
/**
|
|
164
234
|
* If the handler declares a `messageSchema`, return a copy whose `message` validates each frame -
|
|
165
235
|
* parse as JSON, run the Standard Schema, then call the user's `message` with the typed value, or
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../src/server/websocket.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAA+B,MAAM,uBAAuB,CAAA;AA+BzF;;;;;GAKG;AACH,MAAM,OAAO,aAAa;IACP,MAAM,GAAG,IAAI,GAAG,EAA+B,CAAA;IAC/C,WAAW,GAAG,IAAI,OAAO,EAA+B,CAAA;IAEzE,SAAS,CAAC,KAAa,EAAE,EAAkB;QACzC,IAAI,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACjC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,IAAI,GAAG,IAAI,GAAG,EAAE,CAAA;YAChB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QAC9B,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACZ,IAAI,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACnC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,IAAI,GAAG,IAAI,GAAG,EAAE,CAAA;YAChB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;QAChC,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACjB,CAAC;IAED,WAAW,CAAC,KAAa,EAAE,EAAkB;QAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACnC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,IAAI,CAAC,MA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WebSocket app never ships it; `server.ts` only imports the **types** from here
|
|
5
5
|
* (erased). No `Bun.*` calls here - the runtime seam stays in `server.ts` (see runtime-boundary.test).
|
|
6
6
|
*/
|
|
7
|
-
import type
|
|
7
|
+
import { type NifraWebSocket, type TopicRegistry, type WebSocketHandler } from "./websocket.js";
|
|
8
8
|
import type { BunWsHandlers } from "./ws-hook.js";
|
|
9
9
|
/** Per-connection state Bun's `websocket` callbacks read via `ws.data`: the matched handler, the
|
|
10
10
|
* `upgrade()`-seeded user data, and the memoized portable {@link NifraWebSocket} wrapper. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws-bun.d.ts","sourceRoot":"","sources":["../../src/server/ws-bun.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"ws-bun.d.ts","sourceRoot":"","sources":["../../src/server/ws-bun.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,aAAa,EAElB,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAEjD;6FAC6F;AAC7F,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAA;IAClC,IAAI,EAAE,OAAO,CAAA;IACb,KAAK,CAAC,EAAE,cAAc,CAAA;CACvB;AAED;6EAC6E;AAC7E,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,WAAW,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC9E,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAE3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CACzB;AAqED;gFACgF;AAChF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAqBxE"}
|
package/dist/server/ws-bun.js
CHANGED
|
@@ -4,17 +4,21 @@
|
|
|
4
4
|
* bundle of a no-WebSocket app never ships it; `server.ts` only imports the **types** from here
|
|
5
5
|
* (erased). No `Bun.*` calls here - the runtime seam stays in `server.ts` (see runtime-boundary.test).
|
|
6
6
|
*/
|
|
7
|
+
import { createWebSocketSender, } from "./websocket.js";
|
|
7
8
|
/** Normalize a received binary frame to `Uint8Array` (Bun hands a `Buffer`, already one; an
|
|
8
9
|
* `ArrayBuffer` is wrapped). Text frames stay `string`. */
|
|
9
10
|
function toBinaryData(message) {
|
|
10
11
|
return message instanceof Uint8Array ? message : new Uint8Array(message);
|
|
11
12
|
}
|
|
12
13
|
/** Wrap a Bun `ServerWebSocket` as the portable {@link NifraWebSocket} handed to WS callbacks. */
|
|
13
|
-
function wrapBunSocket(raw, topics) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
function wrapBunSocket(raw, topics, handler) {
|
|
15
|
+
let ws;
|
|
16
|
+
const reportError = (error) => reportWsError(error, ws, handler);
|
|
17
|
+
const send = createWebSocketSender((data) => {
|
|
18
|
+
raw.send(data);
|
|
19
|
+
}, handler.sendSchema, handler.validateSend, handler.transport, reportError);
|
|
20
|
+
ws = {
|
|
21
|
+
send,
|
|
18
22
|
close: (code, reason) => raw.close(code, reason),
|
|
19
23
|
get readyState() {
|
|
20
24
|
return raw.readyState;
|
|
@@ -61,19 +65,19 @@ export function createBunWsHandlers(topics) {
|
|
|
61
65
|
return {
|
|
62
66
|
open: (raw) => {
|
|
63
67
|
const ws = raw;
|
|
64
|
-
const nifra = wrapBunSocket(ws, topics);
|
|
68
|
+
const nifra = wrapBunSocket(ws, topics, ws.data.handler);
|
|
65
69
|
ws.data.nifra = nifra;
|
|
66
70
|
dispatchWsCallback(() => ws.data.handler.open?.(nifra), nifra, ws.data.handler);
|
|
67
71
|
},
|
|
68
72
|
message: (raw, message) => {
|
|
69
73
|
const ws = raw;
|
|
70
|
-
const nifra = ws.data.nifra ?? wrapBunSocket(ws, topics);
|
|
74
|
+
const nifra = ws.data.nifra ?? wrapBunSocket(ws, topics, ws.data.handler);
|
|
71
75
|
const data = typeof message === "string" ? message : toBinaryData(message);
|
|
72
76
|
dispatchWsCallback(() => ws.data.handler.message?.(nifra, data), nifra, ws.data.handler);
|
|
73
77
|
},
|
|
74
78
|
close: (raw, code, reason) => {
|
|
75
79
|
const ws = raw;
|
|
76
|
-
const nifra = ws.data.nifra ?? wrapBunSocket(ws, topics);
|
|
80
|
+
const nifra = ws.data.nifra ?? wrapBunSocket(ws, topics, ws.data.handler);
|
|
77
81
|
topics.unsubscribeAll(nifra); // drop topic subscriptions so the registry never holds a dead socket
|
|
78
82
|
dispatchWsCallback(() => ws.data.handler.close?.(nifra, code, reason), nifra, ws.data.handler);
|
|
79
83
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws-bun.js","sourceRoot":"","sources":["../../src/server/ws-bun.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"ws-bun.js","sourceRoot":"","sources":["../../src/server/ws-bun.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,qBAAqB,GAKtB,MAAM,gBAAgB,CAAA;AAqBvB;2DAC2D;AAC3D,SAAS,YAAY,CAAC,OAAiC;IACrD,OAAO,OAAO,YAAY,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,CAAA;AAC1E,CAAC;AAED,kGAAkG;AAClG,SAAS,aAAa,CACpB,GAAc,EACd,MAAqB,EACrB,OAAyB;IAEzB,IAAI,EAAmB,CAAA;IACvB,MAAM,WAAW,GAAG,CAAC,KAAc,EAAQ,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE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,CAAC,OAAO,CAAC,CAAA;YACzF,kBAAkB,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC1F,CAAC;QACD,KAAK,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;YAC3B,MAAM,EAAE,GAAG,GAAgB,CAAA;YAC3B,MAAM,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YACzE,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA,CAAC,qEAAqE;YAClG,kBAAkB,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAChG,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/dist/server.d.ts
CHANGED
|
@@ -15,10 +15,11 @@ export type { InferInput, InferOutput, StandardIssue, StandardResult, StandardSc
|
|
|
15
15
|
export type { Context, Params, Platform, Prettify, ResponseControls, RouteSchema, } from "./server/context.js";
|
|
16
16
|
export { type CookieOptions, type CookieSecret, cookieNamePrefix, parseCookies, serializeCookie, signValue, unsignValue, } from "./server/cookies.js";
|
|
17
17
|
export { type DurableObjectNamespaceLike, type ExecutionContext, type ScheduledController, type ScheduledHandler, toFetchHandler, } from "./server/edge.js";
|
|
18
|
-
export { pathnameOf, type UrlParts, urlPartsOf } from "./server/http.js";
|
|
18
|
+
export { isSameOriginPath, pathnameOf, type UrlParts, urlPartsOf } from "./server/http.js";
|
|
19
19
|
export { commonSecretPatterns, jsonLogger, type LogFields, type Logger, type RedactOptions, redactLogFields, silentLogger, } from "./server/logger.js";
|
|
20
20
|
export { type FetchApp, type LambdaEvent, type LambdaHandler, type LambdaResponse, type LambdaV1Event, type LambdaV2Event, type NetlifyEvent, type NetlifyHandler, type PlatformResponse, toLambdaHandler, toNetlifyHandler, toVercelHandler, type VercelHandler, } from "./server/platform-adapters.js";
|
|
21
21
|
export type { Registry, RouteInfo } from "./server/registry.js";
|
|
22
|
+
export { type PlainRender, type ResponseResult, status } from "./server/runtime-core.js";
|
|
22
23
|
export { type AdmissionController, type AdmissionDecision, type AnyServer, type ContextPlugin, type DefinePluginResult, defineContextPlugin, defineIdentityPlugin, definePlugin, defineRouterPlugin, type Handler, type IdentityPlugin, type McpPromptDescriptor, type McpResourceDescriptor, type Middleware, type NifraFeatureVersion, type NifraPlugin, type NodeRequestContext, type NodeRequestHook, type NodeResponseContext, type NodeResponseHook, type NodeServeOutcome, type OnRequestResult, type PluginTypeCollapsed, type PromptArgument, type PromptMessage, type ResponseBodyHook, type ResponseBodyReplacement, type ResponseFinalization, type ResponseHeadersHook, type ResponseHeadersView, type RouteDescriptor, type RunningServer, Server, type ServerOptions, server, type ToolAnnotations, } from "./server/server.js";
|
|
23
24
|
export type { SSEContext, SSEInit, SSEMessage, SSEStream, TypedSSEStream, } from "./server/sse.js";
|
|
24
25
|
export type { NifraWebSocket, StandardWebSocket, WebSocketContext, WebSocketData, WebSocketHandler, WebSocketUpgradeOutcome, } from "./server/websocket.js";
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAA;AACzF,OAAO,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACxE,OAAO,EAAE,mBAAmB,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EACxB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,MAAM,EACN,KAAK,aAAa,EAClB,MAAM,EACN,KAAK,eAAe,GACrB,MAAM,oBAAoB,CAAA;AAC3B,YAAY,EACV,UAAU,EACV,OAAO,EACP,UAAU,EACV,SAAS,EACT,cAAc,GACf,MAAM,iBAAiB,CAAA;AACxB,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,uBAAuB,CAAA"}
|
package/dist/server.js
CHANGED
|
@@ -13,8 +13,9 @@ export { isSameOriginRequest } from "./internal/same-origin.js";
|
|
|
13
13
|
export { METHODS, Router } from "./router/router.js";
|
|
14
14
|
export { cookieNamePrefix, parseCookies, serializeCookie, signValue, unsignValue, } from "./server/cookies.js";
|
|
15
15
|
export { toFetchHandler, } from "./server/edge.js";
|
|
16
|
-
export { pathnameOf, urlPartsOf } from "./server/http.js";
|
|
16
|
+
export { isSameOriginPath, pathnameOf, urlPartsOf } from "./server/http.js";
|
|
17
17
|
export { commonSecretPatterns, jsonLogger, redactLogFields, silentLogger, } from "./server/logger.js";
|
|
18
18
|
export { toLambdaHandler, toNetlifyHandler, toVercelHandler, } from "./server/platform-adapters.js";
|
|
19
|
+
export { status } from "./server/runtime-core.js";
|
|
19
20
|
export { defineContextPlugin, defineIdentityPlugin, definePlugin, defineRouterPlugin, Server, server, } from "./server/server.js";
|
|
20
21
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAA6B,MAAM,aAAa,CAAA;AACzF,OAAO,EAAE,cAAc,EAAsB,MAAM,qBAAqB,CAAA;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,EAAE,OAAO,EAAe,MAAM,EAAoB,MAAM,oBAAoB,CAAA;AAkBnF,OAAO,EAGL,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,SAAS,EACT,WAAW,GACZ,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAKL,cAAc,GACf,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,UAAU,EAAiB,UAAU,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAA6B,MAAM,aAAa,CAAA;AACzF,OAAO,EAAE,cAAc,EAAsB,MAAM,qBAAqB,CAAA;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,EAAE,OAAO,EAAe,MAAM,EAAoB,MAAM,oBAAoB,CAAA;AAkBnF,OAAO,EAGL,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,SAAS,EACT,WAAW,GACZ,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAKL,cAAc,GACf,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAiB,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC1F,OAAO,EACL,oBAAoB,EACpB,UAAU,EAIV,eAAe,EACf,YAAY,GACb,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAUL,eAAe,EACf,gBAAgB,EAChB,eAAe,GAEhB,MAAM,+BAA+B,CAAA;AAEtC,OAAO,EAAyC,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACxF,OAAO,EAML,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,EAwBlB,MAAM,EAEN,MAAM,GAEP,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single-copy-register.d.ts","sourceRoot":"","sources":["../src/single-copy-register.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Side-effect entry (`@nifrajs/core/single-copy/register`): install the single-copy resolver into the
|
|
3
|
+
* Bun runtime.
|
|
4
|
+
*
|
|
5
|
+
* Preload it - never import it from application code:
|
|
6
|
+
*
|
|
7
|
+
* ```toml
|
|
8
|
+
* # bunfig.toml
|
|
9
|
+
* preload = ["@nifrajs/core/single-copy/register"]
|
|
10
|
+
* [test]
|
|
11
|
+
* preload = ["@nifrajs/core/single-copy/register"]
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* A resolver only affects imports that have not resolved yet, and a module's own imports resolve
|
|
15
|
+
* before its body runs. Registering from inside application code would therefore miss exactly the
|
|
16
|
+
* imports it exists to redirect. `preload` runs before the entry point, which is the only moment that
|
|
17
|
+
* covers the whole graph.
|
|
18
|
+
*
|
|
19
|
+
* `nifra check` reads this specifier out of `bunfig.toml` as the proof that the runtime arm is armed,
|
|
20
|
+
* so the string above is a contract rather than a suggestion.
|
|
21
|
+
*/
|
|
22
|
+
import { registerSingleCopy } from "./single-copy";
|
|
23
|
+
registerSingleCopy();
|
|
24
|
+
//# sourceMappingURL=single-copy-register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single-copy-register.js","sourceRoot":"","sources":["../src/single-copy-register.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAElD,kBAAkB,EAAE,CAAA"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One physical copy of an identity-sensitive package, enforced at LOAD time.
|
|
3
|
+
*
|
|
4
|
+
* ## The gap this closes
|
|
5
|
+
*
|
|
6
|
+
* `@nifrajs/web`'s build already pins react/preact/svelte to the app's copy through `onResolve`
|
|
7
|
+
* (`reactDedupePlugin` and friends), and that covers every bundled phase. It cannot cover an
|
|
8
|
+
* UNBUNDLED one: Bun's runtime plugin API delivers only the entry point and RELATIVE specifiers to
|
|
9
|
+
* `onResolve`, so a bare `import "react"` inside a linked package never reaches a resolver hook. The
|
|
10
|
+
* surfaces that run app sources unbundled - `bun test`, a preloaded script, a route imported natively
|
|
11
|
+
* - therefore keep loading a second copy no matter what the build does. `onLoad` DOES fire on the
|
|
12
|
+
* resolved file, which is the one hook that can still intervene, and it is what this module uses.
|
|
13
|
+
*
|
|
14
|
+
* It also covers a package class the build plugins never did: `@nifrajs/*` itself. Two copies of
|
|
15
|
+
* `@nifrajs/core` are two `Server` classes, and `Server` carries private members, so `.merge()` stops
|
|
16
|
+
* accepting the other's app with a type error that names neither copy.
|
|
17
|
+
*
|
|
18
|
+
* ## Why a topology needs it at all
|
|
19
|
+
*
|
|
20
|
+
* A package consumed with `link:` (or `file:`, or an `npm link`) resolves ITS OWN imports from where
|
|
21
|
+
* it physically lives. A shared component library in a sibling repository therefore loads that
|
|
22
|
+
* repository's react, while the app loads its own - same version, two paths, two module registries.
|
|
23
|
+
* React reads hooks off a dispatcher the other copy never set, and SSR dies with `Invalid hook call
|
|
24
|
+
* … resolveDispatcher() is null`, naming neither react nor the package that shadowed it.
|
|
25
|
+
*
|
|
26
|
+
* The conventional fixes both cost something real: a cross-repo `workspaces` entry makes the
|
|
27
|
+
* consumer's install the owner of the other repository's tree and writes into it, and vendoring or
|
|
28
|
+
* packing copies files that exist precisely so they are not copied. This module is the third option -
|
|
29
|
+
* leave the topology alone and make the resolution answer correctly - and it is not a workaround:
|
|
30
|
+
* these packages declare react as a `peerDependency`, which means "the consumer supplies the copy".
|
|
31
|
+
* That sentence has simply never been enforceable at runtime. Now it is.
|
|
32
|
+
*
|
|
33
|
+
* ## What it will not do
|
|
34
|
+
*
|
|
35
|
+
* Redirect across a VERSION difference. Two versions is a different defect (someone's range is wrong)
|
|
36
|
+
* and silently serving 19.2.8 to a package that asked for 19.2.7 turns a loud install problem into a
|
|
37
|
+
* quiet behavioural one. A version skew is left untouched, so `nifra check` still fails it.
|
|
38
|
+
*
|
|
39
|
+
* @example Declare it in package.json, then preload the registrar in bunfig.toml.
|
|
40
|
+
* ```json
|
|
41
|
+
* { "nifra": { "singleCopy": ["react", "react-dom", "@nifrajs/*"] } }
|
|
42
|
+
* ```
|
|
43
|
+
* ```toml
|
|
44
|
+
* preload = ["@nifrajs/core/single-copy/register"]
|
|
45
|
+
* [test]
|
|
46
|
+
* preload = ["@nifrajs/core/single-copy/register"]
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
import type { BunPlugin } from "bun";
|
|
50
|
+
/**
|
|
51
|
+
* Packages whose duplication is a defect rather than a waste. Each keeps module-scoped state that
|
|
52
|
+
* every importer must share - a hook dispatcher, a renderer's options global, a class identity - so a
|
|
53
|
+
* second physical copy breaks behaviour instead of merely costing bytes. Anything scoped `@nifrajs/`
|
|
54
|
+
* qualifies for the same reason and is matched by pattern.
|
|
55
|
+
*/
|
|
56
|
+
export declare const IDENTITY_SENSITIVE_PACKAGES: readonly string[];
|
|
57
|
+
export type SingleCopySkipReason = "version-skew" | "no-counterpart";
|
|
58
|
+
/** One foreign copy that will be redirected into the app's copy. */
|
|
59
|
+
export interface SingleCopyRedirect {
|
|
60
|
+
readonly package: string;
|
|
61
|
+
/** Absolute realpath of the copy that loses - the one a linked package would otherwise load. */
|
|
62
|
+
readonly from: string;
|
|
63
|
+
/** Absolute realpath of the copy that wins - the one resolvable from the app root. */
|
|
64
|
+
readonly to: string;
|
|
65
|
+
readonly version: string;
|
|
66
|
+
}
|
|
67
|
+
/** A foreign copy deliberately left alone, and why - never silently dropped. */
|
|
68
|
+
export interface SingleCopySkip {
|
|
69
|
+
readonly package: string;
|
|
70
|
+
readonly from: string;
|
|
71
|
+
readonly reason: SingleCopySkipReason;
|
|
72
|
+
readonly detail: string;
|
|
73
|
+
}
|
|
74
|
+
export interface SingleCopyPlan {
|
|
75
|
+
/** The app root whose installed copy wins. */
|
|
76
|
+
readonly root: string;
|
|
77
|
+
/** Declared package names and patterns, as written. */
|
|
78
|
+
readonly declared: readonly string[];
|
|
79
|
+
readonly redirects: readonly SingleCopyRedirect[];
|
|
80
|
+
readonly skipped: readonly SingleCopySkip[];
|
|
81
|
+
}
|
|
82
|
+
export interface SingleCopyOptions {
|
|
83
|
+
/** The app root whose copy wins. Defaults to `process.cwd()`. */
|
|
84
|
+
readonly cwd?: string;
|
|
85
|
+
/** Package names or `@scope/*` patterns. Defaults to the `nifra.singleCopy` declaration. */
|
|
86
|
+
readonly packages?: readonly string[];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The declaration, read from `package.json` - deliberately NOT from `nifra.config.ts`.
|
|
90
|
+
*
|
|
91
|
+
* `nifra check` holds a pre-load invariant: it never imports the app's config, because importing is
|
|
92
|
+
* executing. A dedupe claim has to be verifiable by a checker that refuses to run the app, so it lives
|
|
93
|
+
* in the one file every tool already parses. `true` means the built-in identity-sensitive set.
|
|
94
|
+
*/
|
|
95
|
+
export declare function readSingleCopyDeclaration(cwd: string): readonly string[] | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Match a package name against a declaration entry: an exact name, or a `@scope/*` prefix.
|
|
98
|
+
*
|
|
99
|
+
* Exported because the enforcement and the CHECK must agree on it exactly. If `nifra check` decided
|
|
100
|
+
* coverage by its own rule, a package could be reported as deduplicated while the plugin walked past
|
|
101
|
+
* it - which is worse than no check at all, because it is a green light for a broken graph.
|
|
102
|
+
*/
|
|
103
|
+
export declare const matchesSingleCopyDeclaration: (declared: readonly string[], name: string) => boolean;
|
|
104
|
+
/** The public specifier a `bunfig.toml` preload must name to arm the runtime. */
|
|
105
|
+
export declare const SINGLE_COPY_REGISTER_SPECIFIER = "@nifrajs/core/single-copy/register";
|
|
106
|
+
/** Which unbundled phases have the resolver preloaded. Bundled phases never need it - nifra's build
|
|
107
|
+
* injects the plugin itself. */
|
|
108
|
+
export interface SingleCopyRegistration {
|
|
109
|
+
/** `preload` at the top level: covers `bun run` and anything that loads app sources directly. */
|
|
110
|
+
readonly run: boolean;
|
|
111
|
+
/** `[test] preload`: covers `bun test`, the surface that runs app sources unbundled. */
|
|
112
|
+
readonly test: boolean;
|
|
113
|
+
/** The `bunfig.toml` that was read, if one exists. */
|
|
114
|
+
readonly config?: string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Read the runtime proof out of `bunfig.toml`.
|
|
118
|
+
*
|
|
119
|
+
* Line-oriented on purpose: this runs inside `nifra check`, which must not execute or import anything
|
|
120
|
+
* from the project, and the shape being read is a literal array of strings under a known key. A full
|
|
121
|
+
* TOML parse would buy nothing here and would turn an unrelated syntax error elsewhere in the file
|
|
122
|
+
* into a failure to answer this question.
|
|
123
|
+
*/
|
|
124
|
+
export declare function readSingleCopyRegistration(cwd: string): SingleCopyRegistration;
|
|
125
|
+
/**
|
|
126
|
+
* Work out which foreign copies exist and which of them may be redirected.
|
|
127
|
+
*
|
|
128
|
+
* Pure discovery: it reads `package.json` files and symlink targets, never application source, and
|
|
129
|
+
* never mutates anything. Both the plugin and `nifra check`'s verification are built on it, so the
|
|
130
|
+
* enforcement and the report cannot drift apart.
|
|
131
|
+
*/
|
|
132
|
+
export declare function planSingleCopy(options?: SingleCopyOptions): SingleCopyPlan;
|
|
133
|
+
/** A Bun plugin - `Bun.plugin(...)` for the runtime, or a `plugins:` entry for `Bun.build`. */
|
|
134
|
+
export interface SingleCopyPlugin extends BunPlugin {
|
|
135
|
+
/** What it will do, computed once at construction. Exposed so a caller can report it. */
|
|
136
|
+
readonly plan: SingleCopyPlan;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Pin every declared package to the app's copy.
|
|
140
|
+
*
|
|
141
|
+
* Two hooks, because the two phases resolve differently. `onResolve` is the direct statement of the
|
|
142
|
+
* rule and it is what a BUNDLER honours - it sees every bare specifier. The runtime does not deliver
|
|
143
|
+
* bare specifiers to it at all, so the `onLoad` arm intercepts the foreign file itself and hands back
|
|
144
|
+
* a re-export of the counterpart in the winning copy. The importer gets the same function objects and
|
|
145
|
+
* therefore the same module state, which is the entire requirement.
|
|
146
|
+
*/
|
|
147
|
+
export declare function singleCopyPlugin(options?: SingleCopyOptions): SingleCopyPlugin;
|
|
148
|
+
/** Set once the runtime plugin is installed, so a checker can tell "one copy" from "deduplicated". */
|
|
149
|
+
export declare const SINGLE_COPY_ACTIVE: unique symbol;
|
|
150
|
+
/**
|
|
151
|
+
* Install the plugin into the Bun RUNTIME. Import `@nifrajs/core/single-copy/register` from a
|
|
152
|
+
* `bunfig.toml` preload rather than calling this from application code: a resolver installed from
|
|
153
|
+
* inside a module cannot affect the imports that module already resolved.
|
|
154
|
+
*/
|
|
155
|
+
export declare function registerSingleCopy(options?: SingleCopyOptions): SingleCopyPlan;
|
|
156
|
+
//# sourceMappingURL=single-copy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single-copy.d.ts","sourceRoot":"","sources":["../src/single-copy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAEpC;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,EAAE,SAAS,MAAM,EAQxD,CAAA;AASD,MAAM,MAAM,oBAAo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