@solidjs/web 2.0.0-beta.32 → 2.0.0-beta.33
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/dist/dev.cjs +51 -15
- package/dist/dev.js +47 -16
- package/dist/server.cjs +710 -71
- package/dist/server.js +707 -74
- package/dist/web.cjs +51 -15
- package/dist/web.js +47 -16
- package/frames/dist/client.cjs +181 -64
- package/frames/dist/client.dev.cjs +185 -64
- package/frames/dist/client.dev.js +183 -62
- package/frames/dist/client.js +179 -62
- package/frames/dist/server.cjs +969 -133
- package/frames/dist/server.js +971 -135
- package/package.json +17 -6
- package/serialization/decode/package.json +20 -0
- package/serialization/dist/decode.cjs +110 -0
- package/serialization/dist/decode.js +104 -0
- package/serialization/dist/serialization.cjs +98 -43
- package/serialization/dist/serialization.js +99 -44
- package/serialization/types/index.d.ts +18 -160
- package/serialization/types/serializer-decode.d.ts +182 -0
- package/serialization/types-cjs/index.d.cts +18 -160
- package/serialization/types-cjs/serializer-decode.d.cts +182 -0
- package/server-functions/dist/client.cjs +101 -105
- package/server-functions/dist/client.js +101 -105
- package/server-functions/dist/server.cjs +131 -107
- package/server-functions/dist/server.dev.cjs +131 -107
- package/server-functions/dist/server.dev.js +132 -108
- package/server-functions/dist/server.js +132 -108
- package/types/client.d.ts +23 -1
- package/types/cookies.d.ts +93 -0
- package/types/core.d.ts +1 -1
- package/types/frames/frame-client.d.ts +26 -0
- package/types/frames/frame-transport.d.ts +1 -1
- package/types/frames/serializer.d.ts +18 -160
- package/types/serializer-decode.d.ts +182 -0
- package/types/serializer.d.ts +18 -160
- package/types/server-functions/client.d.ts +1 -1
- package/types/server-functions/server.d.ts +1 -1
- package/types/server-functions/shared.d.ts +57 -1
- package/types/server.d.ts +21 -1
- package/types-cjs/client.d.cts +23 -1
- package/types-cjs/cookies.d.cts +93 -0
- package/types-cjs/core.d.cts +1 -1
- package/types-cjs/frames/frame-client.d.cts +26 -0
- package/types-cjs/frames/frame-transport.d.cts +1 -1
- package/types-cjs/frames/serializer.d.cts +18 -160
- package/types-cjs/serializer-decode.d.cts +182 -0
- package/types-cjs/serializer.d.cts +18 -160
- package/types-cjs/server-functions/client.d.cts +1 -1
- package/types-cjs/server-functions/server.d.cts +1 -1
- package/types-cjs/server-functions/shared.d.cts +57 -1
- package/types-cjs/server.d.cts +21 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JSONCodecOptions } from "../serializer.js";
|
|
1
|
+
import { JSONCodecOptions } from "../serializer-decode.js";
|
|
2
2
|
|
|
3
3
|
export type { JSONCodecOptions };
|
|
4
4
|
|
|
@@ -283,6 +283,46 @@ export function withMeta<F extends (...args: any[]) => any>(fn: F, meta: ServerF
|
|
|
283
283
|
*/
|
|
284
284
|
export const SERVER_FUNCTION_METADATA: unique symbol;
|
|
285
285
|
|
|
286
|
+
/**
|
|
287
|
+
* The transport surface integrations consume through the late-bound RPC
|
|
288
|
+
* seam (server-functions/registry.js) — filled by the transport halves when
|
|
289
|
+
* the first server function reference is created (code that only exists in
|
|
290
|
+
* a bundle when a `"use server"` function was actually compiled in), read
|
|
291
|
+
* by routers so they never import the transport/codec statically.
|
|
292
|
+
*/
|
|
293
|
+
export interface ServerFunctionRPC {
|
|
294
|
+
/**
|
|
295
|
+
* The build's `GET` declaration wrapper (client fetch transport or
|
|
296
|
+
* server in-process dispatch — see the respective entries).
|
|
297
|
+
*/
|
|
298
|
+
GET<A extends readonly any[], R>(fn: (...args: A) => R): ServerFunction<A, Awaited<R>>;
|
|
299
|
+
/**
|
|
300
|
+
* `decodeResponse` bound to the configured codec: decodes a server
|
|
301
|
+
* function response body the transport handed over whole (redirects,
|
|
302
|
+
* revalidation). Resolves undefined for empty bodies and bodies without
|
|
303
|
+
* a recognized encoding (e.g. a raw user Response).
|
|
304
|
+
*/
|
|
305
|
+
decodeResponse<T = unknown>(response: Response): Promise<T | undefined>;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Fills the RPC seam. Called by the transport halves when the first server
|
|
310
|
+
* function reference is created; first write wins.
|
|
311
|
+
* @internal
|
|
312
|
+
*/
|
|
313
|
+
export function provideServerFunctionRPC(rpc: ServerFunctionRPC): void;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* The registered RPC surface, or undefined when no server function exists
|
|
317
|
+
* in this build's graph. Integration plumbing (routers): gate every use of
|
|
318
|
+
* the transport/codec behind this read instead of importing it — an app
|
|
319
|
+
* with no server functions then ships none of it, while a reference in the
|
|
320
|
+
* bundle guarantees the seam is filled before integration code can hold
|
|
321
|
+
* that reference (compiled output creates references at module scope).
|
|
322
|
+
* @internal
|
|
323
|
+
*/
|
|
324
|
+
export function getServerFunctionRPC(): ServerFunctionRPC | undefined;
|
|
325
|
+
|
|
286
326
|
/**
|
|
287
327
|
* Header carrying the body format tag (a `BodyFormat` value) —
|
|
288
328
|
* `"X-Server-Function-Format"`.
|
|
@@ -316,6 +356,11 @@ export const BodyFormat: {
|
|
|
316
356
|
readonly File: "5";
|
|
317
357
|
readonly ArrayBuffer: "6";
|
|
318
358
|
readonly Uint8Array: "7";
|
|
359
|
+
/**
|
|
360
|
+
* Plain `JSON.stringify` — the fast path for JSON-safe payloads on both
|
|
361
|
+
* legs: argument lists on the request, results on the response.
|
|
362
|
+
*/
|
|
363
|
+
readonly Json: "8";
|
|
319
364
|
};
|
|
320
365
|
|
|
321
366
|
/**
|
|
@@ -324,6 +369,17 @@ export const BodyFormat: {
|
|
|
324
369
|
*/
|
|
325
370
|
export type BodyFormatValue = (typeof BodyFormat)[keyof typeof BodyFormat];
|
|
326
371
|
|
|
372
|
+
/**
|
|
373
|
+
* Whether a value survives a `JSON.stringify` round trip faithfully: JSON
|
|
374
|
+
* primitives (finite numbers only), arrays, and plain objects. Anything
|
|
375
|
+
* else — Dates, Maps, typed arrays, undefined (bare or as a property),
|
|
376
|
+
* NaN, class instances, cyclic structures — needs the codec. Never throws:
|
|
377
|
+
* cycles and pathological depth answer `false`. Both peers negotiate the
|
|
378
|
+
* wire format with this guard: the client for argument lists, the server
|
|
379
|
+
* for results.
|
|
380
|
+
*/
|
|
381
|
+
export function isJSONSafe(value: unknown): boolean;
|
|
382
|
+
|
|
327
383
|
/**
|
|
328
384
|
* Picks a direct HTTP encoding (headers + BodyInit) for values that have
|
|
329
385
|
* one — strings, FormData, URLSearchParams, File, Blob, ArrayBuffer,
|
package/types/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSX } from "./jsx.js";
|
|
2
|
-
import { SerializerPlugin } from "./serializer.js";
|
|
2
|
+
import { SerializerPlugin } from "./serializer-decode.js";
|
|
3
3
|
export const DOMWithState: Record<string, Record<string, 1 | 2>>;
|
|
4
4
|
export const ChildProperties: Set<string>;
|
|
5
5
|
export const DelegatedEvents: Set<string>;
|
|
@@ -345,6 +345,26 @@ export function commitEventResponse(response: Response, event?: RequestEvent): R
|
|
|
345
345
|
export { parseCookieHeader, serializeCookie } from "./cookies.js";
|
|
346
346
|
export type { CookieOptions } from "./cookies.js";
|
|
347
347
|
|
|
348
|
+
/**
|
|
349
|
+
* The flash cookie's isomorphic half and the codec-free server-function
|
|
350
|
+
* layer (reference detection + the late-bound RPC seam) — mirrors of the
|
|
351
|
+
* client entry's exports, so integration code reading them stays
|
|
352
|
+
* universal. Declared through server-functions/shared.d.ts, the
|
|
353
|
+
* declaration home published-types layouts ship.
|
|
354
|
+
*/
|
|
355
|
+
export {
|
|
356
|
+
clearFlashCookie,
|
|
357
|
+
getServerFunctionMetadata,
|
|
358
|
+
getServerFunctionRPC,
|
|
359
|
+
hasFlashCookie,
|
|
360
|
+
isServerFunction
|
|
361
|
+
} from "./server-functions/shared.js";
|
|
362
|
+
export type {
|
|
363
|
+
ServerFunction,
|
|
364
|
+
ServerFunctionMetadata,
|
|
365
|
+
ServerFunctionRPC
|
|
366
|
+
} from "./server-functions/shared.js";
|
|
367
|
+
|
|
348
368
|
export interface SSRResponseOptions {
|
|
349
369
|
/** Base head; the stub's status/headers win over it. */
|
|
350
370
|
responseInit?: ResponseInit;
|
package/types-cjs/client.d.cts
CHANGED
|
@@ -289,7 +289,7 @@ export interface ResponseStub {
|
|
|
289
289
|
* share ONE interface identity and a single augmentation reaches every
|
|
290
290
|
* `locals`, whichever entry typed the event.
|
|
291
291
|
*/
|
|
292
|
-
export
|
|
292
|
+
export { RequestEventLocals } from "./server.cjs";
|
|
293
293
|
export interface RequestEvent {
|
|
294
294
|
request: Request;
|
|
295
295
|
locals: RequestEventLocals;
|
|
@@ -311,5 +311,27 @@ export function getRequestEvent(): RequestEvent | undefined;
|
|
|
311
311
|
*/
|
|
312
312
|
export { parseCookieHeader, serializeCookie } from "./cookies.cjs";
|
|
313
313
|
export type { CookieOptions } from "./cookies.cjs";
|
|
314
|
+
/**
|
|
315
|
+
* The flash cookie's isomorphic half (name/detection/clearing — cookie
|
|
316
|
+
* utilities living beside the cookie codec) and the codec-free
|
|
317
|
+
* server-function layer (reference detection + the late-bound RPC seam).
|
|
318
|
+
* On the core entries so integrations consuming them eagerly (routers)
|
|
319
|
+
* never import the server-functions entry — whose client half is the
|
|
320
|
+
* transport + codec — from their eager graph. Declared through
|
|
321
|
+
* server-functions/shared.d.ts, the declaration home published-types
|
|
322
|
+
* layouts ship.
|
|
323
|
+
*/
|
|
324
|
+
export {
|
|
325
|
+
clearFlashCookie,
|
|
326
|
+
getServerFunctionMetadata,
|
|
327
|
+
getServerFunctionRPC,
|
|
328
|
+
hasFlashCookie,
|
|
329
|
+
isServerFunction
|
|
330
|
+
} from "./server-functions/shared.cjs";
|
|
331
|
+
export type {
|
|
332
|
+
ServerFunction,
|
|
333
|
+
ServerFunctionMetadata,
|
|
334
|
+
ServerFunctionRPC
|
|
335
|
+
} from "./server-functions/shared.cjs";
|
|
314
336
|
/** Hydration-walk primitive; not for hand-written code. @internal */
|
|
315
337
|
export function runHydrationEvents(): void;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Cookie wire format: the platform-gap primitives, and ALL of core's
|
|
2
|
+
// cookie surface — core owns the exchange (the request's headers in, the
|
|
3
|
+
// response stub's headers out) and the codec, nothing ambient. Blessed
|
|
4
|
+
// patterns:
|
|
5
|
+
//
|
|
6
|
+
// parseCookieHeader(event.request.headers.get("cookie"))
|
|
7
|
+
// event.response.headers.append("set-cookie", serializeCookie(name, value, options))
|
|
8
|
+
//
|
|
9
|
+
// Dependency-free and isomorphic (exported from both entries — real
|
|
10
|
+
// implementation, never a stub); integrity/confidentiality layers
|
|
11
|
+
// (sessions) belong to the caller, on top of these primitives.
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Attributes for a `Set-Cookie` header, mirroring RFC 6265. `path`
|
|
15
|
+
* defaults to `/`; nothing else is defaulted.
|
|
16
|
+
*/
|
|
17
|
+
export interface CookieOptions {
|
|
18
|
+
/** Cookie `Path` attribute. Defaults to `/`. */
|
|
19
|
+
path?: string;
|
|
20
|
+
/** Cookie `Domain` attribute. Emitted only when provided. */
|
|
21
|
+
domain?: string;
|
|
22
|
+
/** Cookie `Max-Age` attribute, in seconds (truncated to an integer). */
|
|
23
|
+
maxAge?: number;
|
|
24
|
+
/** Cookie `Expires` attribute. */
|
|
25
|
+
expires?: Date;
|
|
26
|
+
/** Emit the `HttpOnly` attribute. */
|
|
27
|
+
httpOnly?: boolean;
|
|
28
|
+
/** Emit the `Secure` attribute. */
|
|
29
|
+
secure?: boolean;
|
|
30
|
+
/** Cookie `SameSite` attribute, any case. */
|
|
31
|
+
sameSite?: "lax" | "strict" | "none" | "Lax" | "Strict" | "None";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Parses a `Cookie` request header into a name → value map. Names and
|
|
36
|
+
* values are `decodeURIComponent`-decoded (falling back to the raw text
|
|
37
|
+
* when decoding throws); a quoted value keeps its content. `null`/empty
|
|
38
|
+
* input parses to an empty map.
|
|
39
|
+
*
|
|
40
|
+
* The read half of the platform gap — the blessed request-cookie read is
|
|
41
|
+
* `parseCookieHeader(event.request.headers.get("cookie"))`.
|
|
42
|
+
*/
|
|
43
|
+
export function parseCookieHeader(header: string | null | undefined): Record<string, string>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Serializes a cookie to a `Set-Cookie` header value. The name and value
|
|
47
|
+
* are `encodeURIComponent`-encoded (the parser decodes symmetrically);
|
|
48
|
+
* `path` defaults to `/` and every other attribute is emitted exactly
|
|
49
|
+
* when the caller asked for it.
|
|
50
|
+
*
|
|
51
|
+
* The write half of the platform gap — the blessed response-cookie write
|
|
52
|
+
* is `event.response.headers.append("set-cookie", serializeCookie(name,
|
|
53
|
+
* value, options))`, which every head materialization path carries to the
|
|
54
|
+
* wire entry-by-entry.
|
|
55
|
+
*/
|
|
56
|
+
export function serializeCookie(name: string, value: string, options?: CookieOptions): string;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Name of the cookie carrying the outcome of a server function call made
|
|
60
|
+
* without the client runtime (`"flash"`). A no-JS form post has no way to
|
|
61
|
+
* receive a value — the browser follows the redirect and renders the next
|
|
62
|
+
* page — so the handler stashes the outcome here for the render after it
|
|
63
|
+
* to pick up, which is how a form submitted without JavaScript still shows
|
|
64
|
+
* its result.
|
|
65
|
+
*
|
|
66
|
+
* The name, detection and clearing are cookie utilities and isomorphic
|
|
67
|
+
* (integrations read the cookie from code that also ships to the browser);
|
|
68
|
+
* the codec that fills and decodes it is server-only and lives behind the
|
|
69
|
+
* server-functions server entry.
|
|
70
|
+
*/
|
|
71
|
+
export const FLASH_COOKIE: string;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Whether a Cookie header carries a flash cookie, readable or not. Cheap
|
|
75
|
+
* enough to call on every render so the clear can be queued before the
|
|
76
|
+
* response headers flush.
|
|
77
|
+
*/
|
|
78
|
+
export function hasFlashCookie(cookieHeader: string | null): boolean;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The `Set-Cookie` value clearing the flash cookie. The outcome is
|
|
82
|
+
* one-shot: append this as soon as the cookie is detected, whether or not
|
|
83
|
+
* it decodes, so a stale outcome cannot resurface on a later request.
|
|
84
|
+
*/
|
|
85
|
+
export function clearFlashCookie(): string;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The raw encoded flash payload out of a Cookie header, if present — the
|
|
89
|
+
* codec's own accessor.
|
|
90
|
+
*
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
export function matchFlashCookie(cookieHeader: string | null): string | undefined;
|
package/types-cjs/core.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { getOwner, runWithOwner, createComponent, createRoot as root, sharedConfig, untrack, merge as mergeProps, flatten, ssrHandleError, ssrScope, NoHydration, Hydration, runInServerComponentScope } from "solid-js";
|
|
1
|
+
export { getOwner, runWithOwner, createComponent, createRoot as root, sharedConfig, untrack, merge as mergeProps, flatten, ssrHandleError, ssrScope, NoHydration, Hydration, runInServerComponentScope, creationStamp, inServerComponentScope } from "solid-js";
|
|
2
2
|
export declare const effect: (fn: any, effectFn: any, options?: any) => void;
|
|
3
3
|
export declare const memo: (fn: any) => import("solid-js").SourceAccessor<any>;
|
|
4
4
|
export declare const runWithHydrationScope: (id: any, fn: any) => unknown;
|
|
@@ -186,6 +186,10 @@ export interface FrameHost {
|
|
|
186
186
|
serialize(value: unknown): { $ref: string };
|
|
187
187
|
/** `frameId` is the resolving frame's id — route to its stream's table. */
|
|
188
188
|
resolve(ref: { $ref: string }, frameId?: string): unknown;
|
|
189
|
+
/** See FrameHostOptions.revive. */
|
|
190
|
+
revive?(value: unknown): unknown;
|
|
191
|
+
/** See FrameHostOptions.isContainer. */
|
|
192
|
+
isContainer?(value: unknown): boolean;
|
|
189
193
|
}
|
|
190
194
|
|
|
191
195
|
/**
|
|
@@ -219,6 +223,28 @@ export interface FrameHostOptions {
|
|
|
219
223
|
* `applyData: c => table.apply(c)` (see `createJSONDataTable`).
|
|
220
224
|
*/
|
|
221
225
|
applyData?(chunk: Extract<FrameChunk, { type: "data" }>): void;
|
|
226
|
+
/**
|
|
227
|
+
* A lazily-loaded deserializer's load, awaited by the transport before it
|
|
228
|
+
* delivers a `data` chunk — `applyData`/`resolve` can assume the codec is
|
|
229
|
+
* resident once data has arrived. Keeps codec weight out of the eager
|
|
230
|
+
* client graph for responses that never carry serialized data.
|
|
231
|
+
*/
|
|
232
|
+
prepareData?(): Promise<unknown>;
|
|
233
|
+
/**
|
|
234
|
+
* Revive protocol markers inside LITERAL slot args (values that are
|
|
235
|
+
* neither `{$ref}` nor `{$frame}`) at arg-resolution time. Document-face
|
|
236
|
+
* container traces ride this way — inline in the record, revived by the
|
|
237
|
+
* integration (`reviveContainerTraces`) into live local containers.
|
|
238
|
+
*/
|
|
239
|
+
revive?(value: unknown): unknown;
|
|
240
|
+
/**
|
|
241
|
+
* Whether a resolved arg value is a LIVE CONTAINER (a materialized trace —
|
|
242
|
+
* see `isMaterializedContainer`). The record-dedupe compare must know: a
|
|
243
|
+
* pending container's property reads throw not-ready, so async probes and
|
|
244
|
+
* serialization compares would detonate it. Containers compare by
|
|
245
|
+
* identity only.
|
|
246
|
+
*/
|
|
247
|
+
isContainer?(value: unknown): boolean;
|
|
222
248
|
}
|
|
223
249
|
|
|
224
250
|
/** @experimental */
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// shapes and the wire format may change between prereleases (RFC 11).
|
|
4
4
|
// Every export in this module is @experimental.
|
|
5
5
|
import { FrameChunk, FrameHost } from "./frame-client.cjs";
|
|
6
|
-
import { JSONCodecOptions } from "./serializer.cjs";
|
|
6
|
+
import { JSONCodecOptions } from "./serializer-decode.cjs";
|
|
7
7
|
|
|
8
8
|
// Structural mirror of server-functions/shared.js's FlightDataConsumer:
|
|
9
9
|
// this file may only reference siblings that ship with it when integrations
|
|
@@ -5,15 +5,20 @@
|
|
|
5
5
|
// 2.0 stability guarantee and may change between releases. Application and
|
|
6
6
|
// router code should configure `codec` on the server-function entries
|
|
7
7
|
// instead of importing from here.
|
|
8
|
-
import { Serializer
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
import type { Serializer } from "seroval";
|
|
9
|
+
import {
|
|
10
|
+
JSONCodecOptions,
|
|
11
|
+
PluginInfo,
|
|
12
|
+
SerializerPlugin,
|
|
13
|
+
SerovalNode
|
|
14
|
+
} from "./serializer-decode.cjs";
|
|
15
|
+
|
|
16
|
+
// The decode half — `SerovalNode`, the plugin TYPES, `DEFAULT_WEB_PLUGINS`,
|
|
17
|
+
// `resolveSerializerPlugins`, `JSONCodecOptions`, `createJSONDeserializer`,
|
|
18
|
+
// `createJSONDataTable` — is declared in serializer-decode.d.ts (published
|
|
19
|
+
// as `@solidjs/web/serialization/decode`, the module lazy client consumers
|
|
20
|
+
// load) and re-exported here so this remains the full surface.
|
|
21
|
+
export * from "./serializer-decode.cjs";
|
|
17
22
|
|
|
18
23
|
// ---- Plugin authoring ----
|
|
19
24
|
//
|
|
@@ -21,86 +26,8 @@ export type { SerovalNode };
|
|
|
21
26
|
// it is the supported way to feed the serializers' `plugins` options and
|
|
22
27
|
// the server-function entries' `codec.plugins`. The values re-export
|
|
23
28
|
// seroval's own (`createPlugin`, `OpaqueReference` — see serializer.js);
|
|
24
|
-
// the TYPES
|
|
25
|
-
//
|
|
26
|
-
// that `moduleResolution: "nodenext"` cannot follow — a bare type
|
|
27
|
-
// re-export would silently degrade the whole authoring surface to `any`
|
|
28
|
-
// under skipLibCheck. The declarations mirror seroval ~1.5 exactly; the
|
|
29
|
-
// `~` pin is what makes mirroring safe.
|
|
30
|
-
|
|
31
|
-
/** Per-plugin bookkeeping seroval hands each plugin callback. */
|
|
32
|
-
export interface PluginData {
|
|
33
|
-
id: number;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* The shape of a plugin's parsed payload: a map of `SerovalNode`s produced
|
|
38
|
-
* by the parse contexts, consumed by `serialize`/`deserialize`.
|
|
39
|
-
*/
|
|
40
|
-
export type PluginInfo = { [key: string]: SerovalNode };
|
|
41
|
-
|
|
42
|
-
/** Parse context for `parse.sync`: turns child values into nodes. */
|
|
43
|
-
export interface SyncParsePluginContext {
|
|
44
|
-
parse<T>(current: T): SerovalNode;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** Parse context for `parse.async`: like sync, but child parses await. */
|
|
48
|
-
export interface AsyncParsePluginContext {
|
|
49
|
-
parse<T>(current: T): Promise<SerovalNode>;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Parse context for `parse.stream`: sync parsing plus the streaming
|
|
54
|
-
* lifecycle (pending-state tracking, late node emission, cleanup).
|
|
55
|
-
*/
|
|
56
|
-
export interface StreamParsePluginContext {
|
|
57
|
-
parse<T>(current: T): SerovalNode;
|
|
58
|
-
parseWithError<T>(current: T): SerovalNode | undefined;
|
|
59
|
-
isAlive(): boolean;
|
|
60
|
-
pushPendingState(): void;
|
|
61
|
-
popPendingState(): void;
|
|
62
|
-
onParse(node: SerovalNode): void;
|
|
63
|
-
onError(error: unknown): void;
|
|
64
|
-
addCleanup(callback: () => void): void;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Serialize context: renders child nodes to JS source. */
|
|
68
|
-
export interface SerializePluginContext {
|
|
69
|
-
serialize(node: SerovalNode): string;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** Deserialize context: revives child nodes to runtime values. */
|
|
73
|
-
export interface DeserializePluginContext {
|
|
74
|
-
deserialize<T>(node: SerovalNode): T;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* A Seroval plugin usable with the web serializers — teaches the codec how
|
|
79
|
-
* to encode/decode a custom value type (`Value` is the value it matches,
|
|
80
|
-
* `Info` its parsed payload). Supply matching plugins on both peers of a
|
|
81
|
-
* transport. Bare `SerializerPlugin` (both parameters defaulted to `any`)
|
|
82
|
-
* is the list-element type every `plugins` option accepts.
|
|
83
|
-
*
|
|
84
|
-
* Integration-facing; may change (see the entry banner).
|
|
85
|
-
*/
|
|
86
|
-
export interface SerializerPlugin<Value = any, Info extends PluginInfo = any> {
|
|
87
|
-
/** A unique string identifying the plugin — namespace it (`"app/Thing"`). */
|
|
88
|
-
tag: string;
|
|
89
|
-
/** Dependency plugins, resolved ahead of this one. */
|
|
90
|
-
extends?: SerializerPlugin[];
|
|
91
|
-
/** Whether `value` is this plugin's to encode. */
|
|
92
|
-
test(value: unknown): boolean;
|
|
93
|
-
/** Parsing modes — provide the ones the transports you target use. */
|
|
94
|
-
parse: {
|
|
95
|
-
sync?: (value: Value, ctx: SyncParsePluginContext, data: PluginData) => Info;
|
|
96
|
-
async?: (value: Value, ctx: AsyncParsePluginContext, data: PluginData) => Promise<Info>;
|
|
97
|
-
stream?: (value: Value, ctx: StreamParsePluginContext, data: PluginData) => Info;
|
|
98
|
-
};
|
|
99
|
-
/** Renders the parsed payload as JS source (script-injection form). */
|
|
100
|
-
serialize(node: Info, ctx: SerializePluginContext, data: PluginData): string;
|
|
101
|
-
/** Revives the parsed payload back into the runtime value. */
|
|
102
|
-
deserialize(node: Info, ctx: DeserializePluginContext, data: PluginData): Value;
|
|
103
|
-
}
|
|
29
|
+
// the plugin TYPES live in serializer-decode.d.ts (hand-declared there —
|
|
30
|
+
// see its banner for why).
|
|
104
31
|
|
|
105
32
|
/**
|
|
106
33
|
* Builds a `SerializerPlugin` — seroval's `createPlugin`, re-exported so
|
|
@@ -130,26 +57,6 @@ export class OpaqueReference<V, R = undefined> {
|
|
|
130
57
|
constructor(value: V, replacement?: R);
|
|
131
58
|
}
|
|
132
59
|
|
|
133
|
-
/**
|
|
134
|
-
* Baseline plugin set for serializing web-platform values (AbortSignal,
|
|
135
|
-
* Event, FormData, Headers, ReadableStream, Request, Response, URL, ...).
|
|
136
|
-
* Applied by every serializer in this module; custom plugins compose ahead
|
|
137
|
-
* of it via `resolveSerializerPlugins`.
|
|
138
|
-
*
|
|
139
|
-
* Integration-facing; may change (see the entry banner).
|
|
140
|
-
*/
|
|
141
|
-
export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Composes custom plugins with `DEFAULT_WEB_PLUGINS`. Custom plugins come
|
|
145
|
-
* first so they can shadow a default for values both would match. Returns a
|
|
146
|
-
* fresh array; the defaults are never mutated. Useful when handing a full
|
|
147
|
-
* plugin list to another serialization layer.
|
|
148
|
-
*
|
|
149
|
-
* Integration-facing; may change (see the entry banner).
|
|
150
|
-
*/
|
|
151
|
-
export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
|
|
152
|
-
|
|
153
60
|
/**
|
|
154
61
|
* Options for `createSerializer`.
|
|
155
62
|
*
|
|
@@ -217,30 +124,8 @@ export function createHydrationSerializer(options: HydrationSerializerOptions):
|
|
|
217
124
|
export function getLocalHeaderScript(id?: string): string;
|
|
218
125
|
|
|
219
126
|
// ---- JSON codec (server function transports) ----
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
* Options shared by both halves of the JSON codec. All of them must match
|
|
223
|
-
* on the serializing and deserializing peer or payloads will not
|
|
224
|
-
* round-trip — for server functions, set them once through the
|
|
225
|
-
* client/server `codec` config option.
|
|
226
|
-
*
|
|
227
|
-
* Integration-facing; may change (see the entry banner).
|
|
228
|
-
*/
|
|
229
|
-
export interface JSONCodecOptions {
|
|
230
|
-
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
|
|
231
|
-
plugins?: SerializerPlugin[];
|
|
232
|
-
/**
|
|
233
|
-
* Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
|
|
234
|
-
* (payloads may come from an untrusted peer). Must match on both peers.
|
|
235
|
-
* Outside development, the encoding side additionally strips
|
|
236
|
-
* `Error.prototype.stack` on top of any override — serialized stacks leak
|
|
237
|
-
* server paths to the client. Decoding stays permissive, so payloads from
|
|
238
|
-
* a development peer still round-trip.
|
|
239
|
-
*/
|
|
240
|
-
disabledFeatures?: number;
|
|
241
|
-
/** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
|
|
242
|
-
depthLimit?: number;
|
|
243
|
-
}
|
|
127
|
+
// (`JSONCodecOptions` and the decode half are declared in
|
|
128
|
+
// serializer-decode.d.ts and re-exported above.)
|
|
244
129
|
|
|
245
130
|
/**
|
|
246
131
|
* Options for `serializeJSON`.
|
|
@@ -270,17 +155,6 @@ export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
|
270
155
|
*/
|
|
271
156
|
export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
272
157
|
|
|
273
|
-
/**
|
|
274
|
-
* Creates the decoding counterpart of `serializeJSON`. Cross-references
|
|
275
|
-
* between chunks resolve through state shared across calls, so all chunks
|
|
276
|
-
* from one stream must go through the same deserializer instance. The first
|
|
277
|
-
* chunk's return value is the decoded source value; feeding later chunks
|
|
278
|
-
* settles the async values referenced inside it.
|
|
279
|
-
*
|
|
280
|
-
* Integration-facing; may change (see the entry banner).
|
|
281
|
-
*/
|
|
282
|
-
export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
|
|
283
|
-
|
|
284
158
|
/** Options for `createJSONSerializer`. */
|
|
285
159
|
export interface JSONSerializerOptions extends JSONCodecOptions {
|
|
286
160
|
/**
|
|
@@ -306,19 +180,3 @@ export function createJSONSerializer(options: JSONSerializerOptions): {
|
|
|
306
180
|
flush(): void;
|
|
307
181
|
close(): void;
|
|
308
182
|
};
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* A resident, response-scoped decode table over the keyed JSON codec: apply
|
|
312
|
-
* each frame `data` chunk with `apply`, resolve `{ $ref }` slot args with
|
|
313
|
-
* `resolve`. The frames client host wires one per response
|
|
314
|
-
* (`applyData: c => table.apply(c)`).
|
|
315
|
-
*
|
|
316
|
-
* Integration-facing; may change (see the entry banner). This serialization
|
|
317
|
-
* entry is the single home of the data table — the frames client consumes
|
|
318
|
-
* it internally rather than re-exporting it.
|
|
319
|
-
*/
|
|
320
|
-
export interface JSONDataTable {
|
|
321
|
-
apply(chunk: { key?: string; node?: unknown; initial?: boolean }): void;
|
|
322
|
-
resolve<T = unknown>(ref: { $ref: string }): T;
|
|
323
|
-
}
|
|
324
|
-
export function createJSONDataTable(options?: JSONCodecOptions): JSONDataTable;
|