@solidjs/web 2.0.0-rc.2 → 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 +86 -61
- package/dist/dev.js +81 -60
- package/dist/server.cjs +34 -17
- package/dist/server.js +35 -19
- package/dist/web.cjs +83 -59
- package/dist/web.js +78 -58
- package/frames/dist/client.cjs +8 -8
- package/frames/dist/client.dev.cjs +8 -8
- package/frames/dist/client.dev.js +8 -8
- package/frames/dist/client.js +8 -8
- package/frames/dist/server.cjs +28 -18
- package/frames/dist/server.js +29 -19
- package/package.json +20 -22
- package/serialization/dist/decode.cjs +3 -3
- package/serialization/dist/decode.js +3 -3
- package/serialization/dist/serialization.cjs +7 -11
- package/serialization/dist/serialization.js +7 -6
- 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/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 -277
- 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 +93 -222
- 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 +292 -574
- package/types/server-functions/shared.d.ts +112 -458
- package/types/server-mock.d.ts +2 -2
- package/types/server.d.ts +242 -434
- 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 -277
- 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 +93 -222
- 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 +292 -574
- package/types-cjs/server-functions/shared.d.cts +112 -458
- package/types-cjs/server-mock.d.cts +2 -2
- package/types-cjs/server.d.cts +242 -434
- package/LICENSE +0 -21
- package/types/core.d.ts +0 -9
- package/types-cjs/core.d.cts +0 -9
|
@@ -1,182 +1,94 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// 2.0 stability guarantee and may change between releases. Application and
|
|
6
|
-
// router code should configure `codec` on the server-function entries
|
|
7
|
-
// instead of importing from here.
|
|
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";
|
|
22
|
-
|
|
23
|
-
// ---- Plugin authoring ----
|
|
24
|
-
//
|
|
25
|
-
// Unlike the rest of this entry, plugin authoring is APPLICATION-FACING —
|
|
26
|
-
// it is the supported way to feed the serializers' `plugins` options and
|
|
27
|
-
// the server-function entries' `codec.plugins`. The values re-export
|
|
28
|
-
// seroval's own (`createPlugin`, `OpaqueReference` — see serializer.js);
|
|
29
|
-
// the plugin TYPES live in serializer-decode.d.ts (hand-declared there —
|
|
30
|
-
// see its banner for why).
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Builds a `SerializerPlugin` — seroval's `createPlugin`, re-exported so
|
|
34
|
-
* plugin authors stay on the exact seroval instance/version the runtime
|
|
35
|
-
* serializes with. Import it from HERE, not from your own `seroval`
|
|
36
|
-
* dependency: a plugin built against a different copy/version would not
|
|
37
|
-
* fail the build — it would emit nodes the other peer can't interpret.
|
|
38
|
-
*
|
|
39
|
-
* Application-facing (see the plugin-authoring banner above).
|
|
40
|
-
*/
|
|
41
|
-
export function createPlugin<Value, Info extends PluginInfo>(
|
|
42
|
-
plugin: SerializerPlugin<Value, Info>
|
|
43
|
-
): SerializerPlugin<Value, Info>;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Seroval's `OpaqueReference`, re-exported from the runtime's own instance
|
|
47
|
-
* (an `OpaqueReference` from another seroval copy fails the serializer's
|
|
48
|
-
* instanceof check and serializes as a plain value): wraps a value so it
|
|
49
|
-
* crosses the wire as its `replacement` (default `undefined`) while
|
|
50
|
-
* staying readable in-process through `.value`.
|
|
51
|
-
*
|
|
52
|
-
* Application-facing (see the plugin-authoring banner above).
|
|
53
|
-
*/
|
|
54
|
-
export class OpaqueReference<V, R = undefined> {
|
|
55
|
-
readonly value: V;
|
|
56
|
-
readonly replacement?: R;
|
|
57
|
-
constructor(value: V, replacement?: R);
|
|
58
|
-
}
|
|
59
|
-
|
|
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";
|
|
60
5
|
/**
|
|
61
6
|
* Options for `createSerializer`.
|
|
62
7
|
*
|
|
63
8
|
* Integration-facing; may change (see the entry banner).
|
|
64
9
|
*/
|
|
65
10
|
export interface WebSerializerOptions {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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;
|
|
84
29
|
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Creates a streaming Seroval serializer preconfigured with the web plugin
|
|
88
|
-
* set and the default feature policy. Emits JavaScript chunks (through
|
|
89
|
-
* `onData`) that reconstruct the values under `globalIdentifier` when
|
|
90
|
-
* evaluated — the script-injection form of serialization renderers build
|
|
91
|
-
* on. For a JSON-based wire codec (no eval on the receiving side), use
|
|
92
|
-
* `serializeJSON` / `createJSONDeserializer` instead.
|
|
93
|
-
*
|
|
94
|
-
* Integration-facing; may change (see the entry banner).
|
|
95
|
-
*/
|
|
96
|
-
export function createSerializer(options: WebSerializerOptions): Serializer;
|
|
97
|
-
|
|
98
30
|
/**
|
|
99
31
|
* Options for `createHydrationSerializer` — `WebSerializerOptions` minus
|
|
100
32
|
* the knobs hydration pins (`globalIdentifier`, `disabledFeatures`).
|
|
101
33
|
* @internal
|
|
102
34
|
*/
|
|
103
|
-
export type HydrationSerializerOptions = Omit<
|
|
104
|
-
WebSerializerOptions,
|
|
105
|
-
"globalIdentifier" | "disabledFeatures"
|
|
106
|
-
>;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Renderer primitive — the serializer SSR uses for hydration output. Pins
|
|
110
|
-
* the hydration global (`_$HY.r`) and feature policy; only the wiring
|
|
111
|
-
* options (callbacks, scope, extra plugins) are configurable. Not meant
|
|
112
|
-
* for hand-written code — custom serialization should use
|
|
113
|
-
* `createSerializer` or the JSON codec.
|
|
114
|
-
* @internal
|
|
115
|
-
*/
|
|
116
|
-
export function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Renderer primitive — returns the cross-reference bootstrap script SSR
|
|
120
|
-
* emits ahead of hydration data for a render scope. Not meant for
|
|
121
|
-
* hand-written code.
|
|
122
|
-
* @internal
|
|
123
|
-
*/
|
|
124
|
-
export function getLocalHeaderScript(id?: string): string;
|
|
125
|
-
|
|
126
|
-
// ---- JSON codec (server function transports) ----
|
|
127
|
-
// (`JSONCodecOptions` and the decode half are declared in
|
|
128
|
-
// serializer-decode.d.ts and re-exported above.)
|
|
129
|
-
|
|
35
|
+
export type HydrationSerializerOptions = Omit<WebSerializerOptions, "globalIdentifier" | "disabledFeatures">;
|
|
130
36
|
/**
|
|
131
37
|
* Options for `serializeJSON`.
|
|
132
38
|
*
|
|
133
39
|
* Integration-facing; may change (see the entry banner).
|
|
134
40
|
*/
|
|
135
41
|
export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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;
|
|
145
51
|
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Serializes `value` as SerovalNode chunks delivered through `onParse` —
|
|
149
|
-
* the encoding half of the eval-free JSON codec (RPC-style transports;
|
|
150
|
-
* the deserializing peer needs no script evaluation, so CSP-safe). Wire
|
|
151
|
-
* framing of the nodes is the transport's concern. Returns a cancel
|
|
152
|
-
* function that aborts pending async serialization.
|
|
153
|
-
*
|
|
154
|
-
* Integration-facing; may change (see the entry banner).
|
|
155
|
-
*/
|
|
156
|
-
export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
157
|
-
|
|
158
52
|
/** Options for `createJSONSerializer`. */
|
|
159
53
|
export interface JSONSerializerOptions extends JSONCodecOptions {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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;
|
|
169
72
|
}
|
|
170
|
-
|
|
73
|
+
export declare const OpaqueReference: {
|
|
74
|
+
new <V, R = undefined>(value: V, replacement?: R): OpaqueReference<V, R>;
|
|
75
|
+
};
|
|
171
76
|
/**
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
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).
|
|
177
85
|
*/
|
|
178
|
-
export function
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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;
|
|
182
94
|
};
|
|
@@ -1,50 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import { ServerFunction, ServerFunctionMetadata } from "./shared.cjs";
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
ChunkReader,
|
|
6
|
-
ERROR_HEADER,
|
|
7
|
-
FLASH_COOKIE,
|
|
8
|
-
FUNCTION_HEADER,
|
|
9
|
-
INSTANCE_HEADER,
|
|
10
|
-
SINGLE_FLIGHT_HEADER,
|
|
11
|
-
clearFlashCookie,
|
|
12
|
-
createChunk,
|
|
13
|
-
decodeErrorHeaderValue,
|
|
14
|
-
decodeResponse,
|
|
15
|
-
decodeResponsePayload,
|
|
16
|
-
deserializeStream,
|
|
17
|
-
encodeErrorHeaderValue,
|
|
18
|
-
frameAddress,
|
|
19
|
-
getFlightDataConsumer,
|
|
20
|
-
getServerFunctionMetadata,
|
|
21
|
-
getServerFunctionsCodec,
|
|
22
|
-
hasFlashCookie,
|
|
23
|
-
isServerFunction,
|
|
24
|
-
serializeString,
|
|
25
|
-
subscribeFlightData,
|
|
26
|
-
withMeta
|
|
27
|
-
} from "./shared.cjs";
|
|
1
|
+
export { ChunkReader, ERROR_HEADER, FLASH_COOKIE, FUNCTION_HEADER, INSTANCE_HEADER, SINGLE_FLIGHT_HEADER, clearFlashCookie, createChunk, decodeErrorHeaderValue, decodeResponse, decodeResponsePayload, deserializeStream, encodeErrorHeaderValue, frameAddress, getFlightDataConsumer, getServerFunctionMetadata, getServerFunctionsCodec, hasFlashCookie, isServerFunction, serializeString, subscribeFlightData, withMeta } from "./shared.cjs";
|
|
28
2
|
export { REVALIDATE_HEADER } from "../response.cjs";
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
FlightDataContext,
|
|
32
|
-
ServerFunction,
|
|
33
|
-
ServerFunctionMetadata,
|
|
34
|
-
SingleFlightPayload
|
|
35
|
-
} from "./shared.cjs";
|
|
36
|
-
|
|
3
|
+
import { JSONCodecOptions } from "../serializer-decode.cjs";
|
|
4
|
+
export type { FlightDataConsumer, FlightDataContext, ServerFunction, ServerFunctionMetadata, SingleFlightPayload } from "./shared.cjs";
|
|
37
5
|
/** The context `prepareRequest` receives alongside the outgoing RequestInit. */
|
|
38
6
|
export interface PrepareRequestContext {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
7
|
+
/** The build-stable id of the function being called. */
|
|
8
|
+
id: string;
|
|
9
|
+
/**
|
|
10
|
+
* The reference's declaration metadata (e.g. `method: "GET"` for
|
|
11
|
+
* `GET(fn)` references). Plain references carry an empty object.
|
|
12
|
+
*/
|
|
13
|
+
meta: ServerFunctionMetadata | undefined;
|
|
46
14
|
}
|
|
47
|
-
|
|
48
15
|
/**
|
|
49
16
|
* Client-side session-dynamic transport hook: runs before every
|
|
50
17
|
* server-function fetch. Return (or mutate and return) the RequestInit the
|
|
@@ -54,141 +21,90 @@ export interface PrepareRequestContext {
|
|
|
54
21
|
* the client-side symmetric of the server handler hooks. Single hook, not
|
|
55
22
|
* a chain — compose by wrapping functions in userland.
|
|
56
23
|
*/
|
|
57
|
-
export type PrepareRequestHook = (
|
|
58
|
-
init: RequestInit,
|
|
59
|
-
context: PrepareRequestContext
|
|
60
|
-
) => RequestInit | Promise<RequestInit>;
|
|
61
|
-
|
|
24
|
+
export type PrepareRequestHook = (init: RequestInit, context: PrepareRequestContext) => RequestInit | Promise<RequestInit>;
|
|
62
25
|
/** Options for `configureServerFunctionsClient`. */
|
|
63
26
|
export interface ServerFunctionsClientConfig {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Endpoint the server's HTTP handler is mounted on. Must match the
|
|
29
|
+
* server configuration — SSR'd reference `url`s (e.g. form actions) and
|
|
30
|
+
* client fetches both derive from it. Prefix it when the app serves from
|
|
31
|
+
* a base path (e.g. `` `${BASE_URL}_server` ``).
|
|
32
|
+
* @default "/_server"
|
|
33
|
+
*/
|
|
34
|
+
endpoint?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Codec options (extra plugins etc.) for encoding arguments and decoding
|
|
37
|
+
* results — must match the server's. Stored in the shared layer, so
|
|
38
|
+
* `decodeResponse` sees them too.
|
|
39
|
+
*/
|
|
40
|
+
codec?: JSONCodecOptions;
|
|
41
|
+
/**
|
|
42
|
+
* Runs before every server-function fetch. Return (or mutate and return)
|
|
43
|
+
* the RequestInit the transport will use; `context.meta` is the
|
|
44
|
+
* reference's declaration metadata (e.g. method). For session-dynamic
|
|
45
|
+
* cross-cutting concerns — bearer tokens, tracing headers:
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* configureServerFunctionsClient({
|
|
49
|
+
* prepareRequest(init) {
|
|
50
|
+
* return {
|
|
51
|
+
* ...init,
|
|
52
|
+
* headers: { ...init.headers, Authorization: `Bearer ${session.token()}` }
|
|
53
|
+
* };
|
|
54
|
+
* }
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
prepareRequest?: PrepareRequestHook;
|
|
59
|
+
/**
|
|
60
|
+
* Response-side integration seam — the client mirror of the handler's
|
|
61
|
+
* `transformResult`. `handle(response, ctx)` sees every response before
|
|
62
|
+
* the transport decodes it; returning anything but undefined resolves the
|
|
63
|
+
* call with that value. `capture(info)` runs synchronously at the call
|
|
64
|
+
* site (before any await) and its return arrives as `ctx.context`, so
|
|
65
|
+
* ambient per-call state (e.g. a reactive owner) survives to response
|
|
66
|
+
* time. See `createServerComponentHandler` in frame-transport for the
|
|
67
|
+
* canonical implementation.
|
|
68
|
+
*/
|
|
69
|
+
responseHandler?: {
|
|
70
|
+
capture?(info: {
|
|
71
|
+
id: string;
|
|
72
|
+
meta: unknown;
|
|
73
|
+
}): unknown;
|
|
74
|
+
handle(response: Response, ctx: {
|
|
75
|
+
id: string;
|
|
76
|
+
meta: unknown;
|
|
77
|
+
args: unknown[];
|
|
78
|
+
context: unknown;
|
|
79
|
+
}): unknown;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Encoder for argument lists JSON can't carry faithfully. JSON-safe args
|
|
83
|
+
* always go as plain JSON (no codec in the bundle); anything else throws
|
|
84
|
+
* unless this is set. Installed by `enableRichArguments()` from the
|
|
85
|
+
* rich-args entry — set directly only for custom wire encodings.
|
|
86
|
+
*/
|
|
87
|
+
serializeArgs?(args: unknown[]): string | Promise<string>;
|
|
120
88
|
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Configures the client transport. Call once, before any server function is
|
|
124
|
-
* invoked — typically in the client entry, next to `hydrate()`. Only needed
|
|
125
|
-
* when deviating from the defaults (custom endpoint, codec plugins, or a
|
|
126
|
-
* `prepareRequest` hook).
|
|
127
|
-
*/
|
|
128
|
-
export function configureServerFunctionsClient(config?: ServerFunctionsClientConfig): void;
|
|
129
|
-
|
|
130
89
|
export interface ServerFunctionRequestCall {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
90
|
+
type: "request";
|
|
91
|
+
id: string;
|
|
92
|
+
instance: string;
|
|
93
|
+
request: Request;
|
|
94
|
+
meta: ServerFunctionMetadata | undefined;
|
|
95
|
+
time: number;
|
|
137
96
|
}
|
|
138
|
-
|
|
139
97
|
export interface ServerFunctionResponseCall {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
98
|
+
type: "response";
|
|
99
|
+
id: string;
|
|
100
|
+
instance: string;
|
|
101
|
+
response: Response;
|
|
102
|
+
meta: ServerFunctionMetadata | undefined;
|
|
103
|
+
time: number;
|
|
146
104
|
}
|
|
147
|
-
|
|
148
105
|
export type ServerFunctionCall = ServerFunctionRequestCall | ServerFunctionResponseCall;
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Observes cloned requests and responses without handling them. Subscribe
|
|
152
|
-
* from devtools; do not use this to replace `prepareRequest` /
|
|
153
|
-
* `responseHandler`. The server entry exports a no-op of the same name so
|
|
154
|
-
* isomorphic `@solidjs/web/server-functions` imports resolve.
|
|
155
|
-
*/
|
|
156
|
-
export function observeServerFunctionCalls(
|
|
157
|
-
observer: (call: ServerFunctionCall) => void
|
|
158
|
-
): () => void;
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Declares a server function callable over HTTP GET: calls to the returned
|
|
162
|
-
* reference go out as GET requests with the arguments codec-encoded in the
|
|
163
|
-
* query string — cacheable by HTTP infrastructure. Cache headers flow
|
|
164
|
-
* through the handler's header forwarding
|
|
165
|
-
* (`respond(data, { headers: { "cache-control": "max-age=60" } })`).
|
|
166
|
-
*
|
|
167
|
-
* The declaration rides the metadata channel
|
|
168
|
-
* (`getServerFunctionMetadata(fn)?.method === "GET"`) for routers and
|
|
169
|
-
* integrations to detect, and the server honors it: GET-declared functions
|
|
170
|
-
* accept GET requests in addition to the default POST transport (declaring
|
|
171
|
-
* GET grants, it does not revoke); functions that never declared GET answer
|
|
172
|
-
* GET requests with 405. Server-side the wrapper is identity-flavored — SSR
|
|
173
|
-
* calls stay in-process.
|
|
174
|
-
*
|
|
175
|
-
* Wrap the reference at its declaration; the compiler round-trips the call
|
|
176
|
-
* in both builds:
|
|
177
|
-
*
|
|
178
|
-
* ```ts
|
|
179
|
-
* export const getUser = GET(async (id: string) => {
|
|
180
|
-
* "use server";
|
|
181
|
-
* return db.users.find(id);
|
|
182
|
-
* });
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
export function GET<A extends readonly any[], R>(
|
|
186
|
-
fn: (...args: A) => R
|
|
187
|
-
): ServerFunction<A, Awaited<R>>;
|
|
188
|
-
|
|
189
106
|
/** Wire-state transitions a live call's iterable can report. */
|
|
190
107
|
export type LiveSourceStatus = "connected" | "reconnecting" | "closed";
|
|
191
|
-
|
|
192
108
|
/**
|
|
193
109
|
* A live call's answer: the source's iterable, plus an optional `onstatus`
|
|
194
110
|
* side channel for the wire facts the reconnect loop erases from the value
|
|
@@ -198,65 +114,20 @@ export type LiveSourceStatus = "connected" | "reconnecting" | "closed";
|
|
|
198
114
|
* end was a definite rejection (4xx) failing fast instead of retrying.
|
|
199
115
|
*/
|
|
200
116
|
export type LiveSource<R> = R & {
|
|
201
|
-
|
|
117
|
+
onstatus?: (state: LiveSourceStatus, error?: unknown) => void;
|
|
202
118
|
};
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Declares a value-shaped live source: a server function returning an async
|
|
206
|
-
* iterable whose yields are successive VALUES of one logical query, with the
|
|
207
|
-
* contract that the source re-yields current state on every invocation.
|
|
208
|
-
* Calls to the returned reference produce an iterable that survives the
|
|
209
|
-
* connection — post-connect deaths re-invoke with exponential backoff
|
|
210
|
-
* (reset per healthy value, woken early by connectivity returning),
|
|
211
|
-
* first-connect failures reject like a normal call, and `break` aborts the
|
|
212
|
-
* in-flight request. Live calls are reads and never opt into single-flight
|
|
213
|
-
* enveloping. Wire state, if wanted, rides the returned iterable's
|
|
214
|
-
* `onstatus` hook. Compose with `GET` inside-out: `live(GET(fn))`.
|
|
215
|
-
*/
|
|
216
|
-
export function live<A extends readonly any[], R>(
|
|
217
|
-
fn: (...args: A) => R
|
|
218
|
-
): ServerFunction<A, LiveSource<Awaited<R>>>;
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Compiler ABI — emitted by compiled `"use server"` client output where a
|
|
222
|
-
* server function was referenced; produces the fetch-backed callable for
|
|
223
|
-
* the function's build-stable id. Development builds pass the function's
|
|
224
|
-
* source name as the trailing argument (dev-only metadata seeded on the
|
|
225
|
-
* metadata channel; never emitted in production). Not meant for
|
|
226
|
-
* hand-written code.
|
|
227
|
-
*
|
|
228
|
-
* The optional `base` targets calls at that url verbatim instead of the
|
|
229
|
-
* configured endpoint — for integrations reconstructing a callable from a
|
|
230
|
-
* server-rendered action url (e.g. a router intercepting a form submit whose
|
|
231
|
-
* `action="/_server?id=...&args=..."` came off the wire): bound arguments
|
|
232
|
-
* stay in the query string, where the server reads them for natural-encoding
|
|
233
|
-
* bodies (FormData, urlencoded).
|
|
234
|
-
* @internal
|
|
235
|
-
*/
|
|
236
|
-
export function createServerReference(id: string, name?: string, base?: string): ServerFunction;
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Compiler ABI — only ever referenced by server-mode compiler output;
|
|
240
|
-
* throws so a misconfigured build (server transform feeding a client
|
|
241
|
-
* bundle) fails loudly instead of with a missing-export error. Not meant
|
|
242
|
-
* for hand-written code.
|
|
243
|
-
* @internal
|
|
244
|
-
*/
|
|
245
|
-
export function registerServerReference(): never;
|
|
246
|
-
|
|
247
119
|
/**
|
|
248
120
|
* Identity of the currently executing server function call — see the
|
|
249
121
|
* server entry. Named here so isomorphic code can import the type from
|
|
250
122
|
* either entry.
|
|
251
123
|
*/
|
|
252
124
|
export interface ServerFunctionInvocation {
|
|
253
|
-
|
|
125
|
+
id: string;
|
|
254
126
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
export function getServerFunctionInvocation(): ServerFunctionInvocation | undefined;
|
|
127
|
+
export declare function observeServerFunctionCalls(observer: (call: ServerFunctionCall) => void): () => void;
|
|
128
|
+
export declare function configureServerFunctionsClient(config?: ServerFunctionsClientConfig): void;
|
|
129
|
+
export declare function createServerReference(id: string, name?: string, base?: string): ServerFunction;
|
|
130
|
+
export declare function GET<A extends readonly any[], R>(fn: (...args: A) => R): ServerFunction<A, Awaited<R>>;
|
|
131
|
+
export declare function live<A extends readonly any[], R>(fn: (...args: A) => R): ServerFunction<A, LiveSource<Awaited<R>>>;
|
|
132
|
+
export declare function registerServerReference(): never;
|
|
133
|
+
export declare function getServerFunctionInvocation(): ServerFunctionInvocation | undefined;
|
|
@@ -5,34 +5,14 @@
|
|
|
5
5
|
* returned one fills `result` — mirroring the split a scripted call sees.
|
|
6
6
|
*/
|
|
7
7
|
export interface FlashSubmission {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
/** The arguments the call was made with (files are dropped). */
|
|
9
|
+
input: any[];
|
|
10
|
+
/** The call's url: pathname + search of the server function request. */
|
|
11
|
+
url: string;
|
|
12
|
+
/** The returned value, when the call returned. */
|
|
13
|
+
result?: any;
|
|
14
|
+
/** The thrown value, when the call threw. */
|
|
15
|
+
error?: any;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* Encodes the outcome of a no-JS call as a `Set-Cookie` value, for the
|
|
20
|
-
* handler to send with its redirect. `url` identifies which submission the
|
|
21
|
-
* outcome belongs to; pass `thrown` when the call threw rather than
|
|
22
|
-
* returned.
|
|
23
|
-
*
|
|
24
|
-
* The payload is JSON inside the cookie: `FormData` and `URLSearchParams`
|
|
25
|
-
* arguments are captured as entry pairs and revived on decode, and `File`
|
|
26
|
-
* entries are dropped (they cannot ride a cookie). Keep in mind the 4 KB
|
|
27
|
-
* cookie budget — outcomes larger than that will not survive the round
|
|
28
|
-
* trip.
|
|
29
|
-
*/
|
|
30
|
-
export function encodeFlashCookie(url: string, result: any, input: any[], thrown?: boolean): string;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Decodes the flash cookie out of a request's `Cookie` header, for the
|
|
34
|
-
* render that follows the redirect. Returns undefined when the cookie is
|
|
35
|
-
* absent or unreadable — a malformed cookie never takes down the render,
|
|
36
|
-
* and `clearFlashCookie` should be appended regardless.
|
|
37
|
-
*/
|
|
38
|
-
export function decodeFlashCookie(cookieHeader: string | null): FlashSubmission | undefined;
|
|
17
|
+
export declare function encodeFlashCookie(url: string, result: any, input: any[], thrown?: boolean): string;
|
|
18
|
+
export declare function decodeFlashCookie(cookieHeader: string | null): FlashSubmission | undefined;
|