@nifrajs/core 2.0.0 → 2.2.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 +27 -0
- 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-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 +5 -0
- package/dist/idempotency-plugin.d.ts.map +1 -1
- package/dist/idempotency-plugin.js +8 -0
- package/dist/idempotency-plugin.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +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/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/router/pattern.d.ts +26 -1
- package/dist/router/pattern.d.ts.map +1 -1
- package/dist/router/pattern.js +164 -8
- package/dist/router/pattern.js.map +1 -1
- package/dist/router/router.d.ts.map +1 -1
- package/dist/router/router.js +49 -1
- package/dist/router/router.js.map +1 -1
- package/dist/server/idempotency-lane.d.ts +1 -0
- package/dist/server/idempotency-lane.d.ts.map +1 -1
- package/dist/server/idempotency-lane.js +61 -37
- package/dist/server/idempotency-lane.js.map +1 -1
- package/dist/server/respond.d.ts.map +1 -1
- package/dist/server/respond.js.map +1 -1
- package/dist/server/server.d.ts +12 -0
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +33 -2
- package/dist/server/server.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 +6 -0
- 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/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 +214 -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/package.json +46 -1
- package/src/capabilities.ts +306 -5
- package/src/durable-adapters.ts +1039 -0
- package/src/durable-execution.ts +1676 -0
- package/src/effect-lifecycle.ts +120 -0
- package/src/effect-scope.ts +267 -0
- package/src/idempotency-plugin.ts +10 -0
- package/src/index.ts +1 -1
- 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/reconciliation-worker.ts +372 -0
- package/src/router/pattern.ts +179 -8
- package/src/router/router.ts +75 -1
- package/src/server/idempotency-lane.ts +68 -34
- package/src/server/respond.ts +1 -0
- package/src/server/server.ts +46 -0
- package/src/server/transport-lane.ts +141 -0
- package/src/server/websocket.ts +15 -1
- package/src/transport-codec-rich.ts +20 -0
- package/src/transport-codec.ts +284 -0
- package/src/transport-plugin.ts +2 -0
- package/src/wire.ts +474 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { parse as parseWire, stringify as stringifyWire } from "./wire.js";
|
|
2
|
+
export function richWireCodec(options = {}) {
|
|
3
|
+
const limits = Object.freeze({ ...(options.limits ?? {}) });
|
|
4
|
+
return Object.freeze({
|
|
5
|
+
id: "wire",
|
|
6
|
+
version: 1,
|
|
7
|
+
mediaType: "application/vnd.nifra.wire+json;v=1",
|
|
8
|
+
encode: stringifyWire,
|
|
9
|
+
decode(text) {
|
|
10
|
+
return parseWire(text, limits);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=transport-codec-rich.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport-codec-rich.js","sourceRoot":"","sources":["../src/transport-codec-rich.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,SAAS,IAAI,aAAa,EAAyB,MAAM,WAAW,CAAA;AAMjG,MAAM,UAAU,aAAa,CAAC,UAAgC,EAAE;IAC9D,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,CAAC,CAAA;IAC3D,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,EAAE,EAAE,MAAM;QACV,OAAO,EAAE,CAAC;QACV,SAAS,EAAE,qCAAqC;QAChD,MAAM,EAAE,aAAa;QACrB,MAAM,CAAC,IAAY;YACjB,OAAO,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAChC,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Versioned, bounded codecs shared by HTTP bodies, loader streams, and WebSocket frames. Plain JSON
|
|
3
|
+
* remains the zero-configuration fast path; rich wire is explicit and preserves non-JSON values.
|
|
4
|
+
*/
|
|
5
|
+
export interface TransportDecodeOptions {
|
|
6
|
+
readonly maxBytes?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface TransportCodec {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly version: number;
|
|
11
|
+
readonly mediaType: string;
|
|
12
|
+
encode(value: unknown): string;
|
|
13
|
+
decode(text: string): unknown;
|
|
14
|
+
}
|
|
15
|
+
export declare class TransportCodecError extends TypeError {
|
|
16
|
+
constructor(message: string, options?: ErrorOptions);
|
|
17
|
+
}
|
|
18
|
+
export declare const plainJsonCodec: TransportCodec;
|
|
19
|
+
export interface TransportCodecRegistry {
|
|
20
|
+
readonly fallback: TransportCodec;
|
|
21
|
+
forContentType(contentType: string | null): TransportCodec;
|
|
22
|
+
negotiate(accept: string | null): TransportCodec;
|
|
23
|
+
byIdentity(id: string, version: number): TransportCodec;
|
|
24
|
+
}
|
|
25
|
+
export declare function createTransportCodecRegistry(codecs: readonly TransportCodec[], fallback?: TransportCodec): TransportCodecRegistry;
|
|
26
|
+
export declare const defaultTransportCodecs: TransportCodecRegistry;
|
|
27
|
+
export declare function encodeTransportResponse(value: unknown, codec?: TransportCodec, init?: ResponseInit): Response;
|
|
28
|
+
export declare function decodeTransportResponse(response: Response, registry?: TransportCodecRegistry, options?: TransportDecodeOptions): Promise<unknown>;
|
|
29
|
+
export declare function encodeTransportFrame(value: unknown, codec?: TransportCodec): string;
|
|
30
|
+
export declare function decodeTransportFrame(frame: string, registry?: TransportCodecRegistry, options?: TransportDecodeOptions): unknown;
|
|
31
|
+
//# sourceMappingURL=transport-codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport-codec.d.ts","sourceRoot":"","sources":["../src/transport-codec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAA;IAC9B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;CAC9B;AAED,qBAAa,mBAAoB,SAAQ,SAAS;gBACpC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIpD;AAsCD,eAAO,MAAM,cAAc,EAAE,cAY3B,CAAA;AAEF,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAA;IACjC,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,cAAc,CAAA;IAC1D,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,cAAc,CAAA;IAChD,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc,CAAA;CACxD;AAUD,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,QAAQ,GAAE,cAA+B,GACxC,sBAAsB,CA0ExB;AAED,eAAO,MAAM,sBAAsB,EAAE,sBAEnC,CAAA;AAEF,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,cAA+B,EACtC,IAAI,GAAE,YAAiB,GACtB,QAAQ,CAKV;AA8CD,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,QAAQ,EAClB,QAAQ,GAAE,sBAA+C,EACzD,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,OAAO,CAAC,CAQlB;AAQD,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,cAA+B,GACrC,MAAM,CAER;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,sBAA+C,EACzD,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAsBT"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Versioned, bounded codecs shared by HTTP bodies, loader streams, and WebSocket frames. Plain JSON
|
|
3
|
+
* remains the zero-configuration fast path; rich wire is explicit and preserves non-JSON values.
|
|
4
|
+
*/
|
|
5
|
+
const DEFAULT_MAX_BYTES = 16 * 1024 * 1024;
|
|
6
|
+
const TOKEN = /^[a-z][a-z0-9_.-]{0,63}$/;
|
|
7
|
+
export class TransportCodecError extends TypeError {
|
|
8
|
+
constructor(message, options) {
|
|
9
|
+
super(message, options);
|
|
10
|
+
this.name = "TransportCodecError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Run a decode step and normalize whatever it throws into {@link TransportCodecError}.
|
|
15
|
+
*
|
|
16
|
+
* Decoding is the one place this module touches attacker-controlled bytes, and the primitives it
|
|
17
|
+
* delegates to raise their own native types — `JSON.parse` throws `SyntaxError`, a BYO codec throws
|
|
18
|
+
* whatever it likes. Every other failure here is a `TransportCodecError`, so letting those escape
|
|
19
|
+
* would mean a malformed payload — the single most likely hostile input — is the one case that slips
|
|
20
|
+
* past a caller catching the documented error type. The original is kept as `cause`, so the parse
|
|
21
|
+
* failure stays diagnosable; a codec already speaking the contract is re-thrown untouched.
|
|
22
|
+
*/
|
|
23
|
+
function decodeOrThrow(decode, message) {
|
|
24
|
+
try {
|
|
25
|
+
return decode();
|
|
26
|
+
}
|
|
27
|
+
catch (cause) {
|
|
28
|
+
if (cause instanceof TransportCodecError)
|
|
29
|
+
throw cause;
|
|
30
|
+
throw new TransportCodecError(message, { cause });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function maxBytesOf(options) {
|
|
34
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
35
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 0)
|
|
36
|
+
throw new RangeError("transport maxBytes must be a non-negative safe integer");
|
|
37
|
+
return maxBytes;
|
|
38
|
+
}
|
|
39
|
+
function byteLength(text) {
|
|
40
|
+
return new TextEncoder().encode(text).byteLength;
|
|
41
|
+
}
|
|
42
|
+
function assertBounded(text, options) {
|
|
43
|
+
if (byteLength(text) > maxBytesOf(options)) {
|
|
44
|
+
throw new TransportCodecError("transport payload exceeds maxBytes");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export const plainJsonCodec = Object.freeze({
|
|
48
|
+
id: "json",
|
|
49
|
+
version: 1,
|
|
50
|
+
mediaType: "application/json",
|
|
51
|
+
encode(value) {
|
|
52
|
+
const encoded = JSON.stringify(value);
|
|
53
|
+
if (encoded === undefined)
|
|
54
|
+
throw new TransportCodecError("value is not JSON serializable");
|
|
55
|
+
return encoded;
|
|
56
|
+
},
|
|
57
|
+
decode(text) {
|
|
58
|
+
return JSON.parse(text);
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
function canonicalMediaType(value) {
|
|
62
|
+
return value
|
|
63
|
+
.split(";")
|
|
64
|
+
.map((part) => part.trim().toLowerCase())
|
|
65
|
+
.filter(Boolean)
|
|
66
|
+
.join(";");
|
|
67
|
+
}
|
|
68
|
+
export function createTransportCodecRegistry(codecs, fallback = plainJsonCodec) {
|
|
69
|
+
if (codecs.length === 0)
|
|
70
|
+
throw new TypeError("transport codec registry cannot be empty");
|
|
71
|
+
const byMedia = new Map();
|
|
72
|
+
const byId = new Map();
|
|
73
|
+
for (const codec of codecs) {
|
|
74
|
+
if (!TOKEN.test(codec.id))
|
|
75
|
+
throw new TypeError("transport codec id is invalid");
|
|
76
|
+
if (!Number.isSafeInteger(codec.version) || codec.version < 1)
|
|
77
|
+
throw new TypeError("transport codec version must be a positive safe integer");
|
|
78
|
+
if (typeof codec.encode !== "function" || typeof codec.decode !== "function")
|
|
79
|
+
throw new TypeError("transport codec must provide encode and decode");
|
|
80
|
+
const media = canonicalMediaType(codec.mediaType);
|
|
81
|
+
const identity = `${codec.id}@${codec.version}`;
|
|
82
|
+
if (byMedia.has(media) || byId.has(identity))
|
|
83
|
+
throw new TypeError("duplicate transport codec registration");
|
|
84
|
+
byMedia.set(media, codec);
|
|
85
|
+
byId.set(identity, codec);
|
|
86
|
+
}
|
|
87
|
+
if (!byId.has(`${fallback.id}@${fallback.version}`))
|
|
88
|
+
throw new TypeError("transport fallback must be registered");
|
|
89
|
+
const forContentType = (contentType) => {
|
|
90
|
+
if (contentType === null || contentType.trim() === "")
|
|
91
|
+
return fallback;
|
|
92
|
+
const canonical = canonicalMediaType(contentType);
|
|
93
|
+
const direct = byMedia.get(canonical);
|
|
94
|
+
if (direct !== undefined)
|
|
95
|
+
return direct;
|
|
96
|
+
const base = canonical.split(";")[0];
|
|
97
|
+
if (base === "application/json") {
|
|
98
|
+
const json = byId.get("json@1");
|
|
99
|
+
if (json !== undefined)
|
|
100
|
+
return json;
|
|
101
|
+
}
|
|
102
|
+
throw new TransportCodecError(`unsupported transport content type: ${contentType}`);
|
|
103
|
+
};
|
|
104
|
+
return Object.freeze({
|
|
105
|
+
fallback,
|
|
106
|
+
forContentType,
|
|
107
|
+
negotiate(accept) {
|
|
108
|
+
if (accept === null || accept.trim() === "" || accept.trim() === "*/*")
|
|
109
|
+
return fallback;
|
|
110
|
+
const candidates = accept
|
|
111
|
+
.split(",")
|
|
112
|
+
.map((candidate) => {
|
|
113
|
+
const quality = /;\s*q=([01](?:\.\d+)?)\s*$/iu.exec(candidate);
|
|
114
|
+
const q = quality === null ? 1 : Number(quality[1]);
|
|
115
|
+
return {
|
|
116
|
+
media: quality === null ? candidate.trim() : candidate.slice(0, quality.index).trim(),
|
|
117
|
+
q,
|
|
118
|
+
};
|
|
119
|
+
})
|
|
120
|
+
.filter((candidate) => Number.isFinite(candidate.q) && candidate.q > 0 && candidate.q <= 1)
|
|
121
|
+
.sort((a, b) => b.q - a.q);
|
|
122
|
+
for (const candidate of candidates) {
|
|
123
|
+
try {
|
|
124
|
+
return forContentType(candidate.media);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// Try the next advertised representation.
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
throw new TransportCodecError("no acceptable transport codec");
|
|
131
|
+
},
|
|
132
|
+
byIdentity(id, version) {
|
|
133
|
+
const codec = byId.get(`${id}@${version}`);
|
|
134
|
+
if (codec === undefined)
|
|
135
|
+
throw new TransportCodecError(`unsupported transport codec: ${id}@${version}`);
|
|
136
|
+
return codec;
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
export const defaultTransportCodecs = createTransportCodecRegistry([
|
|
141
|
+
plainJsonCodec,
|
|
142
|
+
]);
|
|
143
|
+
export function encodeTransportResponse(value, codec = plainJsonCodec, init = {}) {
|
|
144
|
+
const headers = new Headers(init.headers);
|
|
145
|
+
headers.set("content-type", codec.mediaType);
|
|
146
|
+
headers.set("vary", appendVary(headers.get("vary"), "accept"));
|
|
147
|
+
return new Response(codec.encode(value), { ...init, headers });
|
|
148
|
+
}
|
|
149
|
+
function appendVary(current, name) {
|
|
150
|
+
if (current === null || current.trim() === "")
|
|
151
|
+
return name;
|
|
152
|
+
const values = current.split(",").map((value) => value.trim().toLowerCase());
|
|
153
|
+
return values.includes(name.toLowerCase()) ? current : `${current}, ${name}`;
|
|
154
|
+
}
|
|
155
|
+
async function readBoundedText(response, options) {
|
|
156
|
+
const maxBytes = maxBytesOf(options);
|
|
157
|
+
const declared = response.headers.get("content-length");
|
|
158
|
+
if (declared !== null && /^\d+$/u.test(declared) && Number(declared) > maxBytes)
|
|
159
|
+
throw new TransportCodecError("transport payload exceeds maxBytes");
|
|
160
|
+
if (response.body === null)
|
|
161
|
+
return "";
|
|
162
|
+
const reader = response.body.getReader();
|
|
163
|
+
const chunks = [];
|
|
164
|
+
let total = 0;
|
|
165
|
+
try {
|
|
166
|
+
for (;;) {
|
|
167
|
+
const { done, value } = await reader.read();
|
|
168
|
+
if (done)
|
|
169
|
+
break;
|
|
170
|
+
total += value.byteLength;
|
|
171
|
+
if (!Number.isSafeInteger(total) || total > maxBytes) {
|
|
172
|
+
await reader.cancel();
|
|
173
|
+
throw new TransportCodecError("transport payload exceeds maxBytes");
|
|
174
|
+
}
|
|
175
|
+
chunks.push(value);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
reader.releaseLock();
|
|
180
|
+
}
|
|
181
|
+
const bytes = new Uint8Array(total);
|
|
182
|
+
let offset = 0;
|
|
183
|
+
for (const chunk of chunks) {
|
|
184
|
+
bytes.set(chunk, offset);
|
|
185
|
+
offset += chunk.byteLength;
|
|
186
|
+
}
|
|
187
|
+
return decodeOrThrow(() => new TextDecoder("utf-8", { fatal: true }).decode(bytes), "transport payload is not valid UTF-8");
|
|
188
|
+
}
|
|
189
|
+
export async function decodeTransportResponse(response, registry = defaultTransportCodecs, options = {}) {
|
|
190
|
+
const codec = registry.forContentType(response.headers.get("content-type"));
|
|
191
|
+
const text = await readBoundedText(response, options);
|
|
192
|
+
if (text === "")
|
|
193
|
+
return undefined;
|
|
194
|
+
return decodeOrThrow(() => codec.decode(text), `malformed transport body for codec ${codec.id}@${codec.version}`);
|
|
195
|
+
}
|
|
196
|
+
export function encodeTransportFrame(value, codec = plainJsonCodec) {
|
|
197
|
+
return JSON.stringify({ codec: codec.id, version: codec.version, payload: codec.encode(value) });
|
|
198
|
+
}
|
|
199
|
+
export function decodeTransportFrame(frame, registry = defaultTransportCodecs, options = {}) {
|
|
200
|
+
assertBounded(frame, options);
|
|
201
|
+
const envelope = decodeOrThrow(() => JSON.parse(frame), "malformed transport frame");
|
|
202
|
+
if (envelope === null ||
|
|
203
|
+
typeof envelope !== "object" ||
|
|
204
|
+
typeof envelope.codec !== "string" ||
|
|
205
|
+
!Number.isSafeInteger(envelope.version) ||
|
|
206
|
+
typeof envelope.payload !== "string") {
|
|
207
|
+
throw new TransportCodecError("malformed transport frame");
|
|
208
|
+
}
|
|
209
|
+
const payload = envelope.payload;
|
|
210
|
+
assertBounded(payload, options);
|
|
211
|
+
const codec = registry.byIdentity(envelope.codec, envelope.version);
|
|
212
|
+
return decodeOrThrow(() => codec.decode(payload), `malformed transport frame payload for codec ${codec.id}@${codec.version}`);
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=transport-codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport-codec.js","sourceRoot":"","sources":["../src/transport-codec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAA;AAC1C,MAAM,KAAK,GAAG,0BAA0B,CAAA;AAcxC,MAAM,OAAO,mBAAoB,SAAQ,SAAS;IAChD,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,SAAS,aAAa,CAAI,MAAe,EAAE,OAAe;IACxD,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,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QAAQ,KAAK,IAAI;QACjB,OAAO,QAAQ,KAAK,QAAQ;QAC5B,OAAO,QAAQ,CAAC,KAAK,KAAK,QAAQ;QAClC,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC;QACvC,OAAO,QAAQ,CAAC,OAAO,KAAK,QAAQ,EACpC,CAAC;QACD,MAAM,IAAI,mBAAmB,CAAC,2BAA2B,CAAC,CAAA;IAC5D,CAAC;IACD,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAA;IAChC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC/B,MAAM,KAAK,GAAG,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,OAAiB,CAAC,CAAA;IAC7E,OAAO,aAAa,CAClB,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAC3B,+CAA+C,KAAK,CAAC,EAAE,IAAI,KAAK,CAAC,OAAO,EAAE,CAC3E,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport-plugin.d.ts","sourceRoot":"","sources":["../src/transport-plugin.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport-plugin.js","sourceRoot":"","sources":["../src/transport-plugin.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA"}
|
package/dist/wire.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rich-type wire codec: round-trips values that plain JSON silently drops or corrupts, across any
|
|
3
|
+
* JSON transport (RPC bodies, loader payloads, WebSocket frames).
|
|
4
|
+
*
|
|
5
|
+
* `JSON.stringify` turns `undefined` into a missing key, `Date` into a lossy string, `NaN`/`Infinity`
|
|
6
|
+
* into `null`, loses `-0`, and throws on `BigInt` - and it has no notion of `Map`, `Set`, `RegExp`,
|
|
7
|
+
* `URL`, `ArrayBuffer`, or typed arrays. It also flattens a shared reference into two copies and throws
|
|
8
|
+
* on a cycle. A typed client that infers `Date` from the server type then receives a `string` at runtime
|
|
9
|
+
* is exactly the drift this framework exists to remove. `encode` maps a value to a JSON-safe structure
|
|
10
|
+
* that `decode` reconstructs exactly - including cycles and preserved reference identity; `stringify` /
|
|
11
|
+
* `parse` are the drop-in `JSON.*` equivalents.
|
|
12
|
+
*
|
|
13
|
+
* The wire form is `{ r, n }`: `r` is the root (an inline value or a `ref`), `n` is a flat table of
|
|
14
|
+
* container/rich nodes addressed by index. Because every object is interned in `n` and referenced by
|
|
15
|
+
* index, a shared object is encoded once (and decodes to a single shared instance), and a cycle is a
|
|
16
|
+
* back-reference rather than infinite recursion. Functions and symbols are rejected, never silently
|
|
17
|
+
* dropped. Decoding validates every tag and index, so a malformed payload throws {@link WireDecodeError}
|
|
18
|
+
* rather than producing a corrupt value.
|
|
19
|
+
*
|
|
20
|
+
* Not covered by design (matches `JSON`): class identity (a class instance decodes to a plain object
|
|
21
|
+
* carrying its own enumerable properties), non-enumerable and symbol keys, and getters (read once).
|
|
22
|
+
*/
|
|
23
|
+
/** The JSON-safe encoded form produced by {@link encode} and consumed by {@link decode}. */
|
|
24
|
+
export interface Wire {
|
|
25
|
+
/** The root value: an inline primitive/scalar, or a `{ [TAG]: "ref", i }` into {@link Wire.n}. */
|
|
26
|
+
readonly r: unknown;
|
|
27
|
+
/** Interned container and rich-type nodes, addressed by index from `ref`s. */
|
|
28
|
+
readonly n: readonly unknown[];
|
|
29
|
+
}
|
|
30
|
+
/** Resource limits applied while reconstructing transport-controlled wire data. */
|
|
31
|
+
export interface WireDecodeLimits {
|
|
32
|
+
/** Maximum number of interned nodes. Default 10,000. */
|
|
33
|
+
readonly maxNodes?: number;
|
|
34
|
+
/** Maximum nesting depth across containers and references. Default 256. */
|
|
35
|
+
readonly maxDepth?: number;
|
|
36
|
+
/** Maximum total object/array/map/set entries visited. Default 100,000. */
|
|
37
|
+
readonly maxCollectionEntries?: number;
|
|
38
|
+
/** Maximum UTF-8 string plus decoded binary bytes materialized. Default 16 MiB. */
|
|
39
|
+
readonly maxDecodedBytes?: number;
|
|
40
|
+
}
|
|
41
|
+
export declare const DEFAULT_WIRE_DECODE_LIMITS: Readonly<Required<WireDecodeLimits>>;
|
|
42
|
+
/** Thrown by {@link encode} for a value it will not encode (a function or a symbol). */
|
|
43
|
+
export declare class WireEncodeError extends TypeError {
|
|
44
|
+
constructor(message: string);
|
|
45
|
+
}
|
|
46
|
+
/** Thrown by {@link decode} for a wire value carrying an unknown tag, a bad index, or malformed shape. */
|
|
47
|
+
export declare class WireDecodeError extends TypeError {
|
|
48
|
+
constructor(message: string);
|
|
49
|
+
}
|
|
50
|
+
/** Encode any supported value into a JSON-safe {@link Wire} form. */
|
|
51
|
+
export declare function encode(value: unknown): Wire;
|
|
52
|
+
/** Reconstruct the original value from a {@link Wire} form produced by {@link encode}. */
|
|
53
|
+
export declare function decode(wire: Wire, limits?: WireDecodeLimits): unknown;
|
|
54
|
+
/** `encode` + `JSON.stringify` in one call - the rich-type equivalent of `JSON.stringify`. */
|
|
55
|
+
export declare function stringify(value: unknown): string;
|
|
56
|
+
/** `JSON.parse` + `decode` in one call - the rich-type equivalent of `JSON.parse`. */
|
|
57
|
+
export declare function parse(text: string, limits?: WireDecodeLimits): unknown;
|
|
58
|
+
//# sourceMappingURL=wire.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAMH,4FAA4F;AAC5F,MAAM,WAAW,IAAI;IACnB,kGAAkG;IAClG,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAA;IACnB,8EAA8E;IAC9E,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