@solidjs/web 2.0.0-rc.1 → 2.0.0-rc.3
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 +116 -66
- package/dist/dev.js +109 -65
- package/dist/server.cjs +386 -109
- package/dist/server.js +378 -113
- package/dist/web.cjs +113 -64
- package/dist/web.js +106 -63
- package/frames/dist/client.cjs +100 -14
- package/frames/dist/client.dev.cjs +103 -14
- package/frames/dist/client.dev.js +104 -15
- package/frames/dist/client.js +101 -15
- package/frames/dist/server.cjs +285 -154
- package/frames/dist/server.js +287 -156
- package/package.json +20 -22
- package/serialization/dist/decode.cjs +22 -5
- package/serialization/dist/decode.js +23 -6
- package/serialization/dist/serialization.cjs +26 -13
- package/serialization/dist/serialization.js +26 -8
- package/serialization/types/index.d.ts +69 -157
- package/serialization/types/serializer-decode.d.ts +89 -112
- package/serialization/types/serializer.d.ts +94 -0
- package/serialization/types-cjs/index.d.cts +69 -157
- package/serialization/types-cjs/serializer-decode.d.cts +89 -112
- package/serialization/types-cjs/serializer.d.cts +94 -0
- package/server-functions/dist/client.cjs +48 -7
- package/server-functions/dist/client.js +48 -8
- package/server-functions/dist/server.cjs +76 -5
- package/server-functions/dist/server.dev.cjs +76 -5
- package/server-functions/dist/server.dev.js +76 -6
- package/server-functions/dist/server.js +76 -6
- package/types/client.d.ts +150 -290
- package/types/constants.d.ts +18 -0
- package/types/cookies.d.ts +31 -75
- package/types/frames/frame-client.d.ts +287 -259
- package/types/frames/frame-container-plugin.d.ts +71 -0
- package/types/frames/frame-sink.d.ts +58 -160
- package/types/frames/frame-transport.d.ts +161 -194
- package/types/frames/serializer-decode.d.ts +159 -0
- package/types/frames/serializer.d.ts +69 -157
- package/types/head.d.ts +16 -0
- package/types/index.d.ts +0 -65
- package/types/index.server.d.ts +125 -0
- package/types/jsx.d.ts +5 -13
- package/types/reconcile.d.ts +1 -0
- package/types/render.d.ts +4 -0
- package/types/response.d.ts +41 -153
- package/types/serializer-decode.d.ts +89 -112
- package/types/serializer.d.ts +69 -157
- package/types/server-functions/client.d.ts +101 -199
- package/types/server-functions/flash.d.ts +10 -30
- package/types/server-functions/registry.d.ts +63 -0
- package/types/server-functions/rich-args.d.ts +1 -10
- package/types/server-functions/server.d.ts +301 -518
- package/types/server-functions/shared.d.ts +112 -458
- package/types/server-mock.d.ts +13 -4
- package/types/server.d.ts +256 -427
- package/types-cjs/client.d.cts +150 -290
- package/types-cjs/constants.d.cts +18 -0
- package/types-cjs/cookies.d.cts +31 -75
- package/types-cjs/frames/frame-client.d.cts +287 -259
- package/types-cjs/frames/frame-container-plugin.d.cts +71 -0
- package/types-cjs/frames/frame-sink.d.cts +58 -160
- package/types-cjs/frames/frame-transport.d.cts +161 -194
- package/types-cjs/frames/serializer-decode.d.cts +159 -0
- package/types-cjs/frames/serializer.d.cts +69 -157
- package/types-cjs/head.d.cts +16 -0
- package/types-cjs/index.d.cts +0 -65
- package/types-cjs/index.server.d.cts +125 -0
- package/types-cjs/jsx.d.cts +5 -13
- package/types-cjs/reconcile.d.cts +1 -0
- package/types-cjs/render.d.cts +4 -0
- package/types-cjs/response.d.cts +41 -153
- package/types-cjs/serializer-decode.d.cts +89 -112
- package/types-cjs/serializer.d.cts +69 -157
- package/types-cjs/server-functions/client.d.cts +101 -199
- package/types-cjs/server-functions/flash.d.cts +10 -30
- package/types-cjs/server-functions/registry.d.cts +63 -0
- package/types-cjs/server-functions/rich-args.d.cts +1 -10
- package/types-cjs/server-functions/server.d.cts +301 -518
- package/types-cjs/server-functions/shared.d.cts +112 -458
- package/types-cjs/server-mock.d.cts +13 -4
- package/types-cjs/server.d.cts +256 -427
- package/LICENSE +0 -21
- package/types/core.d.ts +0 -6
- package/types-cjs/core.d.cts +0 -6
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
// The DECODE half of the serialization surface (published as
|
|
2
|
-
// `@solidjs/web/serialization/decode`): what reading a serialized payload
|
|
3
|
-
// needs — `fromCrossJSON`-backed deserializers and the shared plugin set —
|
|
4
|
-
// with none of the encode machinery. Lazy client consumers (the frames
|
|
5
|
-
// data tables, `deserializeStream`) load this module so the encode half
|
|
6
|
-
// never ships to a browser that only reads. The full serializer.d.ts
|
|
7
|
-
// re-exports everything here; see its banner for the stability contract
|
|
8
|
-
// (integration-facing, exempt from the 2.0 stability guarantee).
|
|
9
|
-
// ---- Plugin types ----
|
|
10
|
-
//
|
|
11
|
-
// Declared here by hand (seroval's published d.ts use extensionless
|
|
12
|
-
// ESM-relative imports that `moduleResolution: "nodenext"` cannot follow —
|
|
13
|
-
// a bare type re-export would silently degrade the surface to `any` under
|
|
14
|
-
// skipLibCheck, and an import would make every entry whose types reach
|
|
15
|
-
// this module — the MAIN client entry included, via the server-function
|
|
16
|
-
// seam's `JSONCodecOptions` — unimportable from a strict Node16 CJS
|
|
17
|
-
// consumer). The declarations mirror seroval ~1.5 exactly; the `~` pin is
|
|
18
|
-
// what makes mirroring safe. Plugin AUTHORING (`createPlugin`,
|
|
19
|
-
// `OpaqueReference`) lives on the full serialization entry.
|
|
20
|
-
|
|
21
1
|
/**
|
|
22
2
|
* Seroval's node shape — the intermediate representation `serializeJSON`
|
|
23
3
|
* emits and `createJSONDeserializer` consumes. Safe to `JSON.stringify`.
|
|
@@ -29,59 +9,53 @@
|
|
|
29
9
|
* Integration-facing; may change (see the entry banner).
|
|
30
10
|
*/
|
|
31
11
|
export interface SerovalNode {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
12
|
+
/** Node type tag (seroval-internal enum). */
|
|
13
|
+
t: number;
|
|
14
|
+
/** Reference id, when the node participates in cross-referencing. */
|
|
15
|
+
i?: number | undefined;
|
|
16
|
+
[key: string]: unknown;
|
|
37
17
|
}
|
|
38
|
-
|
|
39
18
|
/** Per-plugin bookkeeping seroval hands each plugin callback. */
|
|
40
19
|
export interface PluginData {
|
|
41
|
-
|
|
20
|
+
id: number;
|
|
42
21
|
}
|
|
43
|
-
|
|
44
22
|
/**
|
|
45
23
|
* The shape of a plugin's parsed payload: a map of `SerovalNode`s produced
|
|
46
24
|
* by the parse contexts, consumed by `serialize`/`deserialize`.
|
|
47
25
|
*/
|
|
48
|
-
export type PluginInfo = {
|
|
49
|
-
|
|
26
|
+
export type PluginInfo = {
|
|
27
|
+
[key: string]: SerovalNode;
|
|
28
|
+
};
|
|
50
29
|
/** Parse context for `parse.sync`: turns child values into nodes. */
|
|
51
30
|
export interface SyncParsePluginContext {
|
|
52
|
-
|
|
31
|
+
parse<T>(current: T): SerovalNode;
|
|
53
32
|
}
|
|
54
|
-
|
|
55
33
|
/** Parse context for `parse.async`: like sync, but child parses await. */
|
|
56
34
|
export interface AsyncParsePluginContext {
|
|
57
|
-
|
|
35
|
+
parse<T>(current: T): Promise<SerovalNode>;
|
|
58
36
|
}
|
|
59
|
-
|
|
60
37
|
/**
|
|
61
38
|
* Parse context for `parse.stream`: sync parsing plus the streaming
|
|
62
39
|
* lifecycle (pending-state tracking, late node emission, cleanup).
|
|
63
40
|
*/
|
|
64
41
|
export interface StreamParsePluginContext {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
42
|
+
parse<T>(current: T): SerovalNode;
|
|
43
|
+
parseWithError<T>(current: T): SerovalNode | undefined;
|
|
44
|
+
isAlive(): boolean;
|
|
45
|
+
pushPendingState(): void;
|
|
46
|
+
popPendingState(): void;
|
|
47
|
+
onParse(node: SerovalNode): void;
|
|
48
|
+
onError(error: unknown): void;
|
|
49
|
+
addCleanup(callback: () => void): void;
|
|
73
50
|
}
|
|
74
|
-
|
|
75
51
|
/** Serialize context: renders child nodes to JS source. */
|
|
76
52
|
export interface SerializePluginContext {
|
|
77
|
-
|
|
53
|
+
serialize(node: SerovalNode): string;
|
|
78
54
|
}
|
|
79
|
-
|
|
80
55
|
/** Deserialize context: revives child nodes to runtime values. */
|
|
81
56
|
export interface DeserializePluginContext {
|
|
82
|
-
|
|
57
|
+
deserialize<T>(node: SerovalNode): T;
|
|
83
58
|
}
|
|
84
|
-
|
|
85
59
|
/**
|
|
86
60
|
* A Seroval plugin usable with the web serializers — teaches the codec how
|
|
87
61
|
* to encode/decode a custom value type (`Value` is the value it matches,
|
|
@@ -92,44 +66,23 @@ export interface DeserializePluginContext {
|
|
|
92
66
|
* Integration-facing; may change (see the entry banner).
|
|
93
67
|
*/
|
|
94
68
|
export interface SerializerPlugin<Value = any, Info extends PluginInfo = any> {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
69
|
+
/** A unique string identifying the plugin — namespace it (`"app/Thing"`). */
|
|
70
|
+
tag: string;
|
|
71
|
+
/** Dependency plugins, resolved ahead of this one. */
|
|
72
|
+
extends?: SerializerPlugin[];
|
|
73
|
+
/** Whether `value` is this plugin's to encode. */
|
|
74
|
+
test(value: unknown): boolean;
|
|
75
|
+
/** Parsing modes — provide the ones the transports you target use. */
|
|
76
|
+
parse: {
|
|
77
|
+
sync?: (value: Value, ctx: SyncParsePluginContext, data: PluginData) => Info;
|
|
78
|
+
async?: (value: Value, ctx: AsyncParsePluginContext, data: PluginData) => Promise<Info>;
|
|
79
|
+
stream?: (value: Value, ctx: StreamParsePluginContext, data: PluginData) => Info;
|
|
80
|
+
};
|
|
81
|
+
/** Renders the parsed payload as JS source (script-injection form). */
|
|
82
|
+
serialize(node: Info, ctx: SerializePluginContext, data: PluginData): string;
|
|
83
|
+
/** Revives the parsed payload back into the runtime value. */
|
|
84
|
+
deserialize(node: Info, ctx: DeserializePluginContext, data: PluginData): Value;
|
|
111
85
|
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Baseline plugin set for serializing web-platform values (AbortSignal,
|
|
115
|
-
* Event, FormData, Headers, ReadableStream, Request, Response, URL, ...).
|
|
116
|
-
* Applied by every serializer in this module; custom plugins compose ahead
|
|
117
|
-
* of it via `resolveSerializerPlugins`.
|
|
118
|
-
*
|
|
119
|
-
* Integration-facing; may change (see the entry banner).
|
|
120
|
-
*/
|
|
121
|
-
export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Composes custom plugins with `DEFAULT_WEB_PLUGINS`. Custom plugins come
|
|
125
|
-
* first so they can shadow a default for values both would match. Returns a
|
|
126
|
-
* fresh array; the defaults are never mutated. Useful when handing a full
|
|
127
|
-
* plugin list to another serialization layer.
|
|
128
|
-
*
|
|
129
|
-
* Integration-facing; may change (see the entry banner).
|
|
130
|
-
*/
|
|
131
|
-
export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
|
|
132
|
-
|
|
133
86
|
/**
|
|
134
87
|
* Options shared by both halves of the JSON codec. All of them must match
|
|
135
88
|
* on the serializing and deserializing peer or payloads will not
|
|
@@ -139,32 +92,20 @@ export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): Se
|
|
|
139
92
|
* Integration-facing; may change (see the entry banner).
|
|
140
93
|
*/
|
|
141
94
|
export interface JSONCodecOptions {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
95
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
|
|
96
|
+
plugins?: SerializerPlugin[];
|
|
97
|
+
/**
|
|
98
|
+
* Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
|
|
99
|
+
* (payloads may come from an untrusted peer). Must match on both peers.
|
|
100
|
+
* Outside development, the encoding side additionally strips
|
|
101
|
+
* `Error.prototype.stack` on top of any override — serialized stacks leak
|
|
102
|
+
* server paths to the client. Decoding stays permissive, so payloads from
|
|
103
|
+
* a development peer still round-trip.
|
|
104
|
+
*/
|
|
105
|
+
disabledFeatures?: number;
|
|
106
|
+
/** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
|
|
107
|
+
depthLimit?: number;
|
|
155
108
|
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Creates the decoding counterpart of `serializeJSON`. Cross-references
|
|
159
|
-
* between chunks resolve through state shared across calls, so all chunks
|
|
160
|
-
* from one stream must go through the same deserializer instance. The first
|
|
161
|
-
* chunk's return value is the decoded source value; feeding later chunks
|
|
162
|
-
* settles the async values referenced inside it.
|
|
163
|
-
*
|
|
164
|
-
* Integration-facing; may change (see the entry banner).
|
|
165
|
-
*/
|
|
166
|
-
export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
|
|
167
|
-
|
|
168
109
|
/**
|
|
169
110
|
* A resident, response-scoped decode table over the keyed JSON codec: apply
|
|
170
111
|
* each frame `data` chunk with `apply`, resolve `{ $ref }` slot args with
|
|
@@ -176,7 +117,43 @@ export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: Se
|
|
|
176
117
|
* it internally rather than re-exporting it.
|
|
177
118
|
*/
|
|
178
119
|
export interface JSONDataTable {
|
|
179
|
-
|
|
180
|
-
|
|
120
|
+
apply(chunk: {
|
|
121
|
+
key?: string;
|
|
122
|
+
node?: unknown;
|
|
123
|
+
initial?: boolean;
|
|
124
|
+
}): void;
|
|
125
|
+
resolve<T = unknown>(ref: {
|
|
126
|
+
$ref: string;
|
|
127
|
+
}): T;
|
|
181
128
|
}
|
|
182
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Baseline plugin set for serializing web-platform values. Shared by the
|
|
131
|
+
* hydration serializer and any consumer building its own serializer (e.g.
|
|
132
|
+
* server function transports). Plugin objects carry both their serialize
|
|
133
|
+
* and deserialize halves, so the set lives on the decode side and the
|
|
134
|
+
* encode module composes over it.
|
|
135
|
+
*/
|
|
136
|
+
export declare const DEFAULT_WEB_PLUGINS: any; /**
|
|
137
|
+
* Composes custom plugins with `DEFAULT_WEB_PLUGINS`. Custom plugins come
|
|
138
|
+
* first so they can shadow a default for values both would match. Returns a
|
|
139
|
+
* fresh array; the defaults are never mutated. Useful when handing a full
|
|
140
|
+
* plugin list to another serialization layer.
|
|
141
|
+
*
|
|
142
|
+
* Integration-facing; may change (see the entry banner).
|
|
143
|
+
*/
|
|
144
|
+
export declare function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
|
|
145
|
+
export declare function resolveCodecOptions({ plugins, disabledFeatures, depthLimit }?: JSONCodecOptions): {
|
|
146
|
+
plugins: SerializerPlugin<any, any>[];
|
|
147
|
+
disabledFeatures: any;
|
|
148
|
+
depthLimit: number;
|
|
149
|
+
}; /**
|
|
150
|
+
* Creates the decoding counterpart of `serializeJSON`. Cross-references
|
|
151
|
+
* between chunks resolve through state shared across calls, so all chunks
|
|
152
|
+
* from one stream must go through the same deserializer instance. The first
|
|
153
|
+
* chunk's return value is the decoded source value; feeding later chunks
|
|
154
|
+
* settles the async values referenced inside it.
|
|
155
|
+
*
|
|
156
|
+
* Integration-facing; may change (see the entry banner).
|
|
157
|
+
*/
|
|
158
|
+
export declare function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
|
|
159
|
+
export declare function createJSONDataTable(options?: JSONCodecOptions): JSONDataTable;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Serializer } from "seroval";
|
|
2
|
+
import type { JSONCodecOptions, PluginInfo, SerializerPlugin, SerovalNode } from "./serializer-decode.cjs";
|
|
3
|
+
export { DEFAULT_WEB_PLUGINS, createJSONDataTable, createJSONDeserializer, resolveSerializerPlugins } from "./serializer-decode.cjs";
|
|
4
|
+
export type * from "./serializer-decode.cjs";
|
|
5
|
+
/**
|
|
6
|
+
* Options for `createSerializer`.
|
|
7
|
+
*
|
|
8
|
+
* Integration-facing; may change (see the entry banner).
|
|
9
|
+
*/
|
|
10
|
+
export interface WebSerializerOptions {
|
|
11
|
+
/** Name of the global object the emitted scripts write resolved values into. */
|
|
12
|
+
globalIdentifier: string;
|
|
13
|
+
/** Cross-reference scope id, for isolating multiple streams on one page. */
|
|
14
|
+
scopeId?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Seroval feature bitflags to exclude from output. Defaults to disabling
|
|
17
|
+
* post-ES2017 features (AggregateError, BigInt typed arrays). Outside
|
|
18
|
+
* development, `Error.prototype.stack` is additionally stripped on top of
|
|
19
|
+
* any override — serialized stacks leak server paths to the client.
|
|
20
|
+
*/
|
|
21
|
+
disabledFeatures?: number;
|
|
22
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
|
|
23
|
+
plugins?: SerializerPlugin[];
|
|
24
|
+
/** Receives each emitted script chunk. */
|
|
25
|
+
onData: (result: string) => void;
|
|
26
|
+
onError?: (error: unknown) => void;
|
|
27
|
+
/** Fires once all async values have settled. */
|
|
28
|
+
onDone?: () => void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Options for `createHydrationSerializer` — `WebSerializerOptions` minus
|
|
32
|
+
* the knobs hydration pins (`globalIdentifier`, `disabledFeatures`).
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export type HydrationSerializerOptions = Omit<WebSerializerOptions, "globalIdentifier" | "disabledFeatures">;
|
|
36
|
+
/**
|
|
37
|
+
* Options for `serializeJSON`.
|
|
38
|
+
*
|
|
39
|
+
* Integration-facing; may change (see the entry banner).
|
|
40
|
+
*/
|
|
41
|
+
export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
42
|
+
/**
|
|
43
|
+
* Receives each serialized node; `initial` is true for the first chunk
|
|
44
|
+
* (the source value itself). Async values produce additional chunks as
|
|
45
|
+
* they resolve.
|
|
46
|
+
*/
|
|
47
|
+
onParse: (node: SerovalNode, initial: boolean) => void;
|
|
48
|
+
onError?: (error: unknown) => void;
|
|
49
|
+
/** Fires once all async values have settled. */
|
|
50
|
+
onDone?: () => void;
|
|
51
|
+
}
|
|
52
|
+
/** Options for `createJSONSerializer`. */
|
|
53
|
+
export interface JSONSerializerOptions extends JSONCodecOptions {
|
|
54
|
+
/**
|
|
55
|
+
* Receives each keyed record — `initial` is true for a key's first node
|
|
56
|
+
* (the written value itself); async values patch through later records
|
|
57
|
+
* under the same key. The decoding peer is `createJSONDataTable`.
|
|
58
|
+
*/
|
|
59
|
+
onData: (record: {
|
|
60
|
+
key: string;
|
|
61
|
+
node: SerovalNode;
|
|
62
|
+
initial: boolean;
|
|
63
|
+
}) => void;
|
|
64
|
+
onError?: (error: unknown) => void;
|
|
65
|
+
/** Fires once `flush()` has been called and every pending value settled. */
|
|
66
|
+
onDone?: () => void;
|
|
67
|
+
}
|
|
68
|
+
export declare const createPlugin: <Value, Info extends PluginInfo>(plugin: SerializerPlugin<Value, Info>) => SerializerPlugin<Value, Info>;
|
|
69
|
+
export interface OpaqueReference<V = unknown, R = undefined> {
|
|
70
|
+
readonly value: V;
|
|
71
|
+
readonly replacement?: R;
|
|
72
|
+
}
|
|
73
|
+
export declare const OpaqueReference: {
|
|
74
|
+
new <V, R = undefined>(value: V, replacement?: R): OpaqueReference<V, R>;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Creates a streaming Seroval serializer preconfigured with the web plugin
|
|
78
|
+
* set and the default feature policy. Emits JavaScript chunks (through
|
|
79
|
+
* `onData`) that reconstruct the values under `globalIdentifier` when
|
|
80
|
+
* evaluated — the script-injection form of serialization renderers build
|
|
81
|
+
* on. For a JSON-based wire codec (no eval on the receiving side), use
|
|
82
|
+
* `serializeJSON` / `createJSONDeserializer` instead.
|
|
83
|
+
*
|
|
84
|
+
* Integration-facing; may change (see the entry banner).
|
|
85
|
+
*/
|
|
86
|
+
export declare function createSerializer(options: WebSerializerOptions): Serializer;
|
|
87
|
+
export declare function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
|
|
88
|
+
export declare function getLocalHeaderScript(id?: string): string;
|
|
89
|
+
export declare function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
90
|
+
export declare function createJSONSerializer(options: JSONSerializerOptions): {
|
|
91
|
+
write(key: string, value: unknown): void;
|
|
92
|
+
flush(): void;
|
|
93
|
+
close(): void;
|
|
94
|
+
};
|
|
@@ -396,6 +396,30 @@ const config = {
|
|
|
396
396
|
responseHandler: undefined,
|
|
397
397
|
serializeArgs: undefined
|
|
398
398
|
};
|
|
399
|
+
const CALL_OBSERVERS = new Set();
|
|
400
|
+
function notifyCallObservers(type, id, instance, value, meta) {
|
|
401
|
+
if (CALL_OBSERVERS.size === 0) return;
|
|
402
|
+
const field = type === "request" ? "request" : "response";
|
|
403
|
+
const time = performance.now();
|
|
404
|
+
for (const observer of new Set(CALL_OBSERVERS)) {
|
|
405
|
+
try {
|
|
406
|
+
observer({
|
|
407
|
+
type,
|
|
408
|
+
id,
|
|
409
|
+
instance,
|
|
410
|
+
[field]: value.clone(),
|
|
411
|
+
meta,
|
|
412
|
+
time
|
|
413
|
+
});
|
|
414
|
+
} catch (error) {
|
|
415
|
+
console.error(error);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
function observeServerFunctionCalls(observer) {
|
|
420
|
+
CALL_OBSERVERS.add(observer);
|
|
421
|
+
return () => CALL_OBSERVERS.delete(observer);
|
|
422
|
+
}
|
|
399
423
|
function serializeArguments(args) {
|
|
400
424
|
if (!config.serializeArgs) {
|
|
401
425
|
throw new Error("Server function arguments are sent as JSON by default and these " + "arguments are not JSON-serializable. Call enableRichArguments() " + '(from "@solidjs/web/server-functions/rich-args") once at startup ' + "to send Dates, Maps, Sets, typed arrays, etc. through the codec — " + "or pass a single Blob/FormData/File argument, which has a native " + "HTTP encoding.");
|
|
@@ -425,6 +449,11 @@ function provideRPC() {
|
|
|
425
449
|
decodeResponse
|
|
426
450
|
});
|
|
427
451
|
}
|
|
452
|
+
function serverFunctionFailure(response, value) {
|
|
453
|
+
const error = value ?? new Error(`Server function call failed with status ${response.status}`);
|
|
454
|
+
if (error instanceof Error && !("status" in error)) error.status = response.status;
|
|
455
|
+
return error;
|
|
456
|
+
}
|
|
428
457
|
async function createRequest(base, id, instance, options, meta) {
|
|
429
458
|
const headers = {
|
|
430
459
|
...options.headers,
|
|
@@ -445,7 +474,12 @@ async function createRequest(base, id, instance, options, meta) {
|
|
|
445
474
|
meta
|
|
446
475
|
})) || init;
|
|
447
476
|
}
|
|
448
|
-
return fetch(base, init);
|
|
477
|
+
if (CALL_OBSERVERS.size === 0) return fetch(base, init);
|
|
478
|
+
const request = new Request(new URL(base, globalThis.location?.href || "http://localhost"), init);
|
|
479
|
+
notifyCallObservers("request", id, instance, request, meta);
|
|
480
|
+
const response = await fetch(request);
|
|
481
|
+
notifyCallObservers("response", id, instance, response, meta);
|
|
482
|
+
return response;
|
|
449
483
|
}
|
|
450
484
|
async function initializeResponse(base, id, instance, options, args, meta) {
|
|
451
485
|
if (args.length === 0) {
|
|
@@ -528,6 +562,7 @@ async function fetchServerFunction(base, id, options, args, meta, callArgs = arg
|
|
|
528
562
|
});
|
|
529
563
|
if (handled !== undefined) return handled;
|
|
530
564
|
}
|
|
565
|
+
const failed = response.headers.has(ERROR_HEADER) || response.status >= 500;
|
|
531
566
|
if (response.headers.has(SINGLE_FLIGHT_HEADER)) {
|
|
532
567
|
const consumer = getFlightDataConsumer();
|
|
533
568
|
if (consumer) {
|
|
@@ -535,8 +570,8 @@ async function fetchServerFunction(base, id, options, args, meta, callArgs = arg
|
|
|
535
570
|
await consumer(payload.data, {
|
|
536
571
|
response
|
|
537
572
|
});
|
|
538
|
-
if (
|
|
539
|
-
throw payload.value;
|
|
573
|
+
if (failed && !response.headers.has("Location") && !response.headers.has(REVALIDATE_HEADER)) {
|
|
574
|
+
throw serverFunctionFailure(response, payload.value);
|
|
540
575
|
}
|
|
541
576
|
return payload.value;
|
|
542
577
|
}
|
|
@@ -545,8 +580,8 @@ async function fetchServerFunction(base, id, options, args, meta, callArgs = arg
|
|
|
545
580
|
return response;
|
|
546
581
|
}
|
|
547
582
|
const result = await decodeResponse(response.clone());
|
|
548
|
-
if (
|
|
549
|
-
throw result;
|
|
583
|
+
if (failed) {
|
|
584
|
+
throw serverFunctionFailure(response, result);
|
|
550
585
|
}
|
|
551
586
|
if (controller && result?.[Symbol.asyncIterator]) {
|
|
552
587
|
return {
|
|
@@ -658,10 +693,10 @@ function live(fn) {
|
|
|
658
693
|
iterable.onstatus && iterable.onstatus(state, error);
|
|
659
694
|
} catch {}
|
|
660
695
|
};
|
|
661
|
-
const emitClosed =
|
|
696
|
+
const emitClosed = error => {
|
|
662
697
|
if (ended) return;
|
|
663
698
|
ended = true;
|
|
664
|
-
emit("closed");
|
|
699
|
+
emit("closed", error);
|
|
665
700
|
};
|
|
666
701
|
const closeIt = value => {
|
|
667
702
|
const current = it;
|
|
@@ -713,6 +748,11 @@ function live(fn) {
|
|
|
713
748
|
return r;
|
|
714
749
|
} catch (error) {
|
|
715
750
|
if (!connected) throw error;
|
|
751
|
+
if (error !== null && typeof error === "object" && typeof error.status === "number" && error.status >= 400 && error.status < 500) {
|
|
752
|
+
stopped = true;
|
|
753
|
+
emitClosed(error);
|
|
754
|
+
throw error;
|
|
755
|
+
}
|
|
716
756
|
it = undefined;
|
|
717
757
|
emit("reconnecting", error);
|
|
718
758
|
await new Promise(resolve => {
|
|
@@ -787,6 +827,7 @@ exports.getServerFunctionsCodec = getServerFunctionsCodec;
|
|
|
787
827
|
exports.hasFlashCookie = hasFlashCookie;
|
|
788
828
|
exports.isServerFunction = isServerFunction;
|
|
789
829
|
exports.live = live;
|
|
830
|
+
exports.observeServerFunctionCalls = observeServerFunctionCalls;
|
|
790
831
|
exports.registerServerReference = registerServerReference;
|
|
791
832
|
exports.serializeString = serializeString;
|
|
792
833
|
exports.subscribeFlightData = subscribeFlightData;
|
|
@@ -394,6 +394,30 @@ const config = {
|
|
|
394
394
|
responseHandler: undefined,
|
|
395
395
|
serializeArgs: undefined
|
|
396
396
|
};
|
|
397
|
+
const CALL_OBSERVERS = new Set();
|
|
398
|
+
function notifyCallObservers(type, id, instance, value, meta) {
|
|
399
|
+
if (CALL_OBSERVERS.size === 0) return;
|
|
400
|
+
const field = type === "request" ? "request" : "response";
|
|
401
|
+
const time = performance.now();
|
|
402
|
+
for (const observer of new Set(CALL_OBSERVERS)) {
|
|
403
|
+
try {
|
|
404
|
+
observer({
|
|
405
|
+
type,
|
|
406
|
+
id,
|
|
407
|
+
instance,
|
|
408
|
+
[field]: value.clone(),
|
|
409
|
+
meta,
|
|
410
|
+
time
|
|
411
|
+
});
|
|
412
|
+
} catch (error) {
|
|
413
|
+
console.error(error);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function observeServerFunctionCalls(observer) {
|
|
418
|
+
CALL_OBSERVERS.add(observer);
|
|
419
|
+
return () => CALL_OBSERVERS.delete(observer);
|
|
420
|
+
}
|
|
397
421
|
function serializeArguments(args) {
|
|
398
422
|
if (!config.serializeArgs) {
|
|
399
423
|
throw new Error("Server function arguments are sent as JSON by default and these " + "arguments are not JSON-serializable. Call enableRichArguments() " + '(from "@solidjs/web/server-functions/rich-args") once at startup ' + "to send Dates, Maps, Sets, typed arrays, etc. through the codec — " + "or pass a single Blob/FormData/File argument, which has a native " + "HTTP encoding.");
|
|
@@ -423,6 +447,11 @@ function provideRPC() {
|
|
|
423
447
|
decodeResponse
|
|
424
448
|
});
|
|
425
449
|
}
|
|
450
|
+
function serverFunctionFailure(response, value) {
|
|
451
|
+
const error = value ?? new Error(`Server function call failed with status ${response.status}`);
|
|
452
|
+
if (error instanceof Error && !("status" in error)) error.status = response.status;
|
|
453
|
+
return error;
|
|
454
|
+
}
|
|
426
455
|
async function createRequest(base, id, instance, options, meta) {
|
|
427
456
|
const headers = {
|
|
428
457
|
...options.headers,
|
|
@@ -443,7 +472,12 @@ async function createRequest(base, id, instance, options, meta) {
|
|
|
443
472
|
meta
|
|
444
473
|
})) || init;
|
|
445
474
|
}
|
|
446
|
-
return fetch(base, init);
|
|
475
|
+
if (CALL_OBSERVERS.size === 0) return fetch(base, init);
|
|
476
|
+
const request = new Request(new URL(base, globalThis.location?.href || "http://localhost"), init);
|
|
477
|
+
notifyCallObservers("request", id, instance, request, meta);
|
|
478
|
+
const response = await fetch(request);
|
|
479
|
+
notifyCallObservers("response", id, instance, response, meta);
|
|
480
|
+
return response;
|
|
447
481
|
}
|
|
448
482
|
async function initializeResponse(base, id, instance, options, args, meta) {
|
|
449
483
|
if (args.length === 0) {
|
|
@@ -526,6 +560,7 @@ async function fetchServerFunction(base, id, options, args, meta, callArgs = arg
|
|
|
526
560
|
});
|
|
527
561
|
if (handled !== undefined) return handled;
|
|
528
562
|
}
|
|
563
|
+
const failed = response.headers.has(ERROR_HEADER) || response.status >= 500;
|
|
529
564
|
if (response.headers.has(SINGLE_FLIGHT_HEADER)) {
|
|
530
565
|
const consumer = getFlightDataConsumer();
|
|
531
566
|
if (consumer) {
|
|
@@ -533,8 +568,8 @@ async function fetchServerFunction(base, id, options, args, meta, callArgs = arg
|
|
|
533
568
|
await consumer(payload.data, {
|
|
534
569
|
response
|
|
535
570
|
});
|
|
536
|
-
if (
|
|
537
|
-
throw payload.value;
|
|
571
|
+
if (failed && !response.headers.has("Location") && !response.headers.has(REVALIDATE_HEADER)) {
|
|
572
|
+
throw serverFunctionFailure(response, payload.value);
|
|
538
573
|
}
|
|
539
574
|
return payload.value;
|
|
540
575
|
}
|
|
@@ -543,8 +578,8 @@ async function fetchServerFunction(base, id, options, args, meta, callArgs = arg
|
|
|
543
578
|
return response;
|
|
544
579
|
}
|
|
545
580
|
const result = await decodeResponse(response.clone());
|
|
546
|
-
if (
|
|
547
|
-
throw result;
|
|
581
|
+
if (failed) {
|
|
582
|
+
throw serverFunctionFailure(response, result);
|
|
548
583
|
}
|
|
549
584
|
if (controller && result?.[Symbol.asyncIterator]) {
|
|
550
585
|
return {
|
|
@@ -656,10 +691,10 @@ function live(fn) {
|
|
|
656
691
|
iterable.onstatus && iterable.onstatus(state, error);
|
|
657
692
|
} catch {}
|
|
658
693
|
};
|
|
659
|
-
const emitClosed =
|
|
694
|
+
const emitClosed = error => {
|
|
660
695
|
if (ended) return;
|
|
661
696
|
ended = true;
|
|
662
|
-
emit("closed");
|
|
697
|
+
emit("closed", error);
|
|
663
698
|
};
|
|
664
699
|
const closeIt = value => {
|
|
665
700
|
const current = it;
|
|
@@ -711,6 +746,11 @@ function live(fn) {
|
|
|
711
746
|
return r;
|
|
712
747
|
} catch (error) {
|
|
713
748
|
if (!connected) throw error;
|
|
749
|
+
if (error !== null && typeof error === "object" && typeof error.status === "number" && error.status >= 400 && error.status < 500) {
|
|
750
|
+
stopped = true;
|
|
751
|
+
emitClosed(error);
|
|
752
|
+
throw error;
|
|
753
|
+
}
|
|
714
754
|
it = undefined;
|
|
715
755
|
emit("reconnecting", error);
|
|
716
756
|
await new Promise(resolve => {
|
|
@@ -760,4 +800,4 @@ function getServerFunctionInvocation() {
|
|
|
760
800
|
return undefined;
|
|
761
801
|
}
|
|
762
802
|
|
|
763
|
-
export { ChunkReader, ERROR_HEADER, FLASH_COOKIE, FUNCTION_HEADER, GET, INSTANCE_HEADER, REVALIDATE_HEADER, SINGLE_FLIGHT_HEADER, clearFlashCookie, configureServerFunctionsClient, createChunk, createServerReference, decodeErrorHeaderValue, decodeResponse, decodeResponsePayload, deserializeStream, encodeErrorHeaderValue, frameAddress, getFlightDataConsumer, getServerFunctionInvocation, getServerFunctionMetadata, getServerFunctionsCodec, hasFlashCookie, isServerFunction, live, registerServerReference, serializeString, subscribeFlightData, withMeta };
|
|
803
|
+
export { ChunkReader, ERROR_HEADER, FLASH_COOKIE, FUNCTION_HEADER, GET, INSTANCE_HEADER, REVALIDATE_HEADER, SINGLE_FLIGHT_HEADER, clearFlashCookie, configureServerFunctionsClient, createChunk, createServerReference, decodeErrorHeaderValue, decodeResponse, decodeResponsePayload, deserializeStream, encodeErrorHeaderValue, frameAddress, getFlightDataConsumer, getServerFunctionInvocation, getServerFunctionMetadata, getServerFunctionsCodec, hasFlashCookie, isServerFunction, live, observeServerFunctionCalls, registerServerReference, serializeString, subscribeFlightData, withMeta };
|