@solidjs/web 2.0.0-beta.17 → 2.0.0-beta.19
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 +138 -48
- package/dist/dev.js +134 -50
- package/dist/server.cjs +108 -23
- package/dist/server.js +105 -25
- package/dist/web.cjs +138 -48
- package/dist/web.js +134 -50
- package/package.json +100 -11
- package/serialization/dist/serialization.cjs +83 -0
- package/serialization/dist/serialization.js +75 -0
- package/serialization/package.json +20 -0
- package/serialization/types/index.d.ts +139 -0
- package/serialization/types-cjs/index.d.cts +139 -0
- package/serialization/types-cjs/package.json +3 -0
- package/server-functions/dist/client.cjs +370 -0
- package/server-functions/dist/client.js +363 -0
- package/server-functions/dist/server.cjs +542 -0
- package/server-functions/dist/server.js +531 -0
- package/server-functions/package.json +30 -0
- package/storage/types/index.d.ts +28 -0
- package/storage/types-cjs/index.d.cts +28 -0
- package/types/index.d.ts +8 -1
- package/types/response.d.ts +93 -0
- package/types/serializer.d.ts +139 -0
- package/types/server-functions/client.d.ts +63 -0
- package/types/server-functions/server.d.ts +188 -0
- package/types/server-functions/shared.d.ts +171 -0
- package/types/server.d.ts +70 -15
- package/types-cjs/index.d.cts +8 -1
- package/types-cjs/response.d.cts +93 -0
- package/types-cjs/serializer.d.cts +139 -0
- package/types-cjs/server-functions/client.d.cts +63 -0
- package/types-cjs/server-functions/server.d.cts +188 -0
- package/types-cjs/server-functions/shared.d.cts +171 -0
- package/types-cjs/server.d.cts +70 -15
- package/storage/types/src/client.d.ts +0 -1
- package/storage/types/src/index.d.ts +0 -171
- package/storage/types/src/server-mock.d.ts +0 -161
- package/storage/types/storage/src/index.d.ts +0 -2
- package/storage/types-cjs/src/client.d.cts +0 -1
- package/storage/types-cjs/src/index.d.cts +0 -171
- package/storage/types-cjs/src/server-mock.d.cts +0 -161
- package/storage/types-cjs/storage/src/index.d.cts +0 -2
package/types/server.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { JSX } from "./jsx.js";
|
|
2
|
+
import { SerializerPlugin } from "./serializer.js";
|
|
2
3
|
export const DOMWithState: Record<string, Record<string, 1 | 2>>;
|
|
3
4
|
export const ChildProperties: Set<string>;
|
|
4
5
|
export const DelegatedEvents: Set<string>;
|
|
@@ -11,17 +12,59 @@ export const Namespaces: Record<string, string>;
|
|
|
11
12
|
|
|
12
13
|
type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node;
|
|
13
14
|
|
|
15
|
+
/** Static asset manifest produced by a build (e.g. parsed Vite manifest.json). */
|
|
16
|
+
export type AssetManifest = Record<
|
|
17
|
+
string,
|
|
18
|
+
{ file: string; css?: string[]; isEntry?: boolean; imports?: string[] }
|
|
19
|
+
> & { _base?: string };
|
|
20
|
+
|
|
21
|
+
/** Inline style content, e.g. dev CSS collected from a bundler's module graph. */
|
|
22
|
+
export type InlineStyleAsset = {
|
|
23
|
+
id: string;
|
|
24
|
+
content: string;
|
|
25
|
+
attrs?: Record<string, string>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type ResolvedAssets = {
|
|
29
|
+
js: string[];
|
|
30
|
+
css: (string | InlineStyleAsset)[];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Resolver form of the manifest option — the primitive a dev server
|
|
35
|
+
* implements against its live module graph (a static manifest object is
|
|
36
|
+
* normalized into a sync resolver internally). `resolve` may return a
|
|
37
|
+
* promise (async resolvers require streaming rendering); CSS entries may be
|
|
38
|
+
* URL strings (emitted as load-gated `<link>` tags) or inline-style
|
|
39
|
+
* descriptors (emitted as `<style>` tags). A bare `resolve`-shaped function
|
|
40
|
+
* is accepted as shorthand for `{ resolve }`.
|
|
41
|
+
*/
|
|
42
|
+
export type AssetResolver = {
|
|
43
|
+
resolve(
|
|
44
|
+
key: string
|
|
45
|
+
): ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
|
|
46
|
+
/**
|
|
47
|
+
* Synchronous fast path answering with whatever is knowable without async
|
|
48
|
+
* work (typically js URLs, omitting css). Sync consumers — e.g. a lazy
|
|
49
|
+
* component's `moduleUrl` getter used by islands — use this when `resolve`
|
|
50
|
+
* would return a promise, so adapters should provide it whenever possible.
|
|
51
|
+
*/
|
|
52
|
+
resolveSync?(key: string): ResolvedAssets | null | undefined;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** Bare-function shorthand for `AssetResolver` (no sync fast path). */
|
|
56
|
+
export type AssetResolverFn = (
|
|
57
|
+
key: string
|
|
58
|
+
) => ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
|
|
59
|
+
|
|
14
60
|
export function renderToString<T>(
|
|
15
61
|
fn: () => T,
|
|
16
62
|
options?: {
|
|
17
63
|
nonce?: string;
|
|
18
64
|
renderId?: string;
|
|
19
65
|
noScripts?: boolean;
|
|
20
|
-
plugins?:
|
|
21
|
-
manifest?:
|
|
22
|
-
string,
|
|
23
|
-
{ file: string; css?: string[]; isEntry?: boolean; imports?: string[] }
|
|
24
|
-
> & { _base?: string };
|
|
66
|
+
plugins?: SerializerPlugin[];
|
|
67
|
+
manifest?: AssetManifest | AssetResolver | AssetResolverFn;
|
|
25
68
|
onError?: (err: any) => void;
|
|
26
69
|
}
|
|
27
70
|
): string;
|
|
@@ -33,11 +76,8 @@ export function renderToStringAsync<T>(
|
|
|
33
76
|
nonce?: string;
|
|
34
77
|
renderId?: string;
|
|
35
78
|
noScripts?: boolean;
|
|
36
|
-
plugins?:
|
|
37
|
-
manifest?:
|
|
38
|
-
string,
|
|
39
|
-
{ file: string; css?: string[]; isEntry?: boolean; imports?: string[] }
|
|
40
|
-
> & { _base?: string };
|
|
79
|
+
plugins?: SerializerPlugin[];
|
|
80
|
+
manifest?: AssetManifest | AssetResolver | AssetResolverFn;
|
|
41
81
|
onError?: (err: any) => void;
|
|
42
82
|
}
|
|
43
83
|
): Promise<string>;
|
|
@@ -47,11 +87,8 @@ export function renderToStream<T>(
|
|
|
47
87
|
nonce?: string;
|
|
48
88
|
renderId?: string;
|
|
49
89
|
noScripts?: boolean;
|
|
50
|
-
plugins?:
|
|
51
|
-
manifest?:
|
|
52
|
-
string,
|
|
53
|
-
{ file: string; css?: string[]; isEntry?: boolean; imports?: string[] }
|
|
54
|
-
> & { _base?: string };
|
|
90
|
+
plugins?: SerializerPlugin[];
|
|
91
|
+
manifest?: AssetManifest | AssetResolver | AssetResolverFn;
|
|
55
92
|
onCompleteShell?: (info: { write: (v: string) => void }) => void;
|
|
56
93
|
onCompleteAll?: (info: { write: (v: string) => void }) => void;
|
|
57
94
|
onError?: (err: any) => void;
|
|
@@ -95,11 +132,29 @@ export function generateHydrationScript(options?: {
|
|
|
95
132
|
nonce?: string;
|
|
96
133
|
eventNames?: string[];
|
|
97
134
|
}): string;
|
|
135
|
+
/**
|
|
136
|
+
* Registered symbol (`Symbol.for("solid.RequestContext")`) naming the
|
|
137
|
+
* global slot where `provideRequestEvent` parks the AsyncLocalStorage that
|
|
138
|
+
* scopes request events. Integration plumbing — application code reads the
|
|
139
|
+
* event through `getRequestEvent()` instead.
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
98
142
|
export declare const RequestContext: unique symbol;
|
|
143
|
+
/**
|
|
144
|
+
* The per-request context available on the server: the incoming `Request`
|
|
145
|
+
* and a `locals` bag integrations and middleware can hang state on.
|
|
146
|
+
* Frameworks typically extend this shape with richer fields.
|
|
147
|
+
*/
|
|
99
148
|
export interface RequestEvent {
|
|
100
149
|
request: Request;
|
|
101
150
|
locals: Record<string | number | symbol, any>;
|
|
102
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* The current request event, when called on the server inside a request
|
|
154
|
+
* scope (established by `provideRequestEvent` from `@solidjs/web/storage`
|
|
155
|
+
* or by the framework). Undefined on the client and outside a request.
|
|
156
|
+
* Read it above `await` boundaries in partially-polyfilled environments.
|
|
157
|
+
*/
|
|
103
158
|
export function getRequestEvent(): RequestEvent | undefined;
|
|
104
159
|
|
|
105
160
|
export function Assets(props: { children?: JSX.Element }): JSX.Element;
|
package/types-cjs/index.d.cts
CHANGED
|
@@ -3,6 +3,7 @@ import { Component } from "solid-js";
|
|
|
3
3
|
import type { JSX } from "./jsx.cjs";
|
|
4
4
|
export * from "./client.cjs";
|
|
5
5
|
export * from "./server-mock.cjs";
|
|
6
|
+
export * from "./response.cjs";
|
|
6
7
|
export type { JSX } from "./jsx.cjs";
|
|
7
8
|
export { For, Show, Switch, Match, Errored, Loading, Repeat, Reveal, NoHydration, Hydration } from "solid-js";
|
|
8
9
|
import { merge } from "solid-js";
|
|
@@ -118,6 +119,12 @@ export declare const hydrate: typeof hydrateCore;
|
|
|
118
119
|
* still participates in the parent's reactive scope and disposes when the
|
|
119
120
|
* parent does.
|
|
120
121
|
*
|
|
122
|
+
* Portals are client-only islands: the server renders nothing for them, and
|
|
123
|
+
* under hydration the children render fresh once hydration settles. Async
|
|
124
|
+
* read inside a portal therefore starts on the client — data that should be
|
|
125
|
+
* fetched on the server belongs above the portal (hoist the read, not the
|
|
126
|
+
* render), and async UI inside one wants its own `<Loading>` boundary.
|
|
127
|
+
*
|
|
121
128
|
* @example
|
|
122
129
|
* ```tsx
|
|
123
130
|
* <Portal mount={document.getElementById("modal-root")!}>
|
|
@@ -127,7 +134,7 @@ export declare const hydrate: typeof hydrateCore;
|
|
|
127
134
|
*
|
|
128
135
|
* @description https://docs.solidjs.com/reference/components/portal
|
|
129
136
|
*/
|
|
130
|
-
export declare function Portal
|
|
137
|
+
export declare function Portal(props: {
|
|
131
138
|
mount?: Element;
|
|
132
139
|
children: JSX.Element;
|
|
133
140
|
}): JSX.Element;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Envelope pairing HTTP metadata (a `Response`) with an in-memory value.
|
|
3
|
+
* Produced by `respond()` and by server-function `transformResult`
|
|
4
|
+
* implementations (e.g. single-flight payloads). The HTTP handler forwards
|
|
5
|
+
* `response`'s headers and (non-redirect) status and encodes `value` as the
|
|
6
|
+
* body through the codec, while client-only integrations read `value`
|
|
7
|
+
* directly — no reparse. Mostly consumed by integrations (routers);
|
|
8
|
+
* application code usually just returns what `respond()` gives it.
|
|
9
|
+
*/
|
|
10
|
+
export class ResponseEnvelope<T = unknown> {
|
|
11
|
+
constructor(response: Response | undefined, value: T);
|
|
12
|
+
/** The HTTP metadata: status and headers to forward (body ignored by integrations). */
|
|
13
|
+
response: Response | undefined;
|
|
14
|
+
/** The structured value the caller receives. */
|
|
15
|
+
value: T;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Whether `value` is a `ResponseEnvelope`. Uses a registered-symbol brand
|
|
20
|
+
* rather than `instanceof`, so it stays correct when separately bundled
|
|
21
|
+
* entries each carry a copy of the class. Integrations should always use
|
|
22
|
+
* this over `instanceof`.
|
|
23
|
+
*/
|
|
24
|
+
export function isResponseEnvelope(value: unknown): value is ResponseEnvelope;
|
|
25
|
+
|
|
26
|
+
/** `ResponseInit` accepted by the response helpers, plus `revalidate`. */
|
|
27
|
+
export interface ResponseHelperInit extends ResponseInit {
|
|
28
|
+
/**
|
|
29
|
+
* Cache keys the mutation invalidated, carried in the `X-Revalidate`
|
|
30
|
+
* header. Opaque to the protocol — the integration's keyed cache (e.g.
|
|
31
|
+
* the router's `query` cache) assigns them meaning.
|
|
32
|
+
*/
|
|
33
|
+
revalidate?: string | string[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Response redirecting to `url` (default status 302). Return (or throw) it
|
|
38
|
+
* from a server function — the HTTP handler forwards the redirect for the
|
|
39
|
+
* client integration to follow — or return it from a client-side action,
|
|
40
|
+
* where the integration interprets it in memory. Same object, same
|
|
41
|
+
* meaning, both sides.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { redirect } from "@solidjs/web";
|
|
46
|
+
*
|
|
47
|
+
* async function login(form: FormData) {
|
|
48
|
+
* "use server";
|
|
49
|
+
* // ...
|
|
50
|
+
* return redirect("/dashboard", { revalidate: "session" });
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export function redirect(url: string, init?: number | ResponseHelperInit): Response;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Empty response requesting revalidation of the named cache keys — all of
|
|
58
|
+
* them when omitted. For mutations whose only effect the caller needs is
|
|
59
|
+
* "refetch your data".
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { reload } from "@solidjs/web";
|
|
64
|
+
*
|
|
65
|
+
* async function addTodo(title: string) {
|
|
66
|
+
* "use server";
|
|
67
|
+
* await db.insert(title);
|
|
68
|
+
* return reload({ revalidate: "todos" });
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export function reload(init?: ResponseHelperInit): Response;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A value paired with response metadata (status, headers, `revalidate`) —
|
|
76
|
+
* for the things a naked return can't express. Scripted callers receive
|
|
77
|
+
* `value` transparently (the transport unwraps the envelope), and
|
|
78
|
+
* progressive enhancement stays invisible: the carried response holds a
|
|
79
|
+
* plain JSON body so consumers without the client runtime (no-JS form
|
|
80
|
+
* posts, direct HTTP) get real JSON.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* import { respond } from "@solidjs/web";
|
|
85
|
+
*
|
|
86
|
+
* async function createItem(input: Item) {
|
|
87
|
+
* "use server";
|
|
88
|
+
* const item = await db.create(input);
|
|
89
|
+
* return respond(item, { status: 201, revalidate: "items" });
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export function respond<T>(value: T, init?: ResponseHelperInit): ResponseEnvelope<T>;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Plugin, Serializer, SerovalNode } from "seroval";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Seroval's node shape — the intermediate representation `serializeJSON`
|
|
5
|
+
* emits and `createJSONDeserializer` consumes. Safe to `JSON.stringify`.
|
|
6
|
+
*/
|
|
7
|
+
export type { SerovalNode };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A Seroval plugin usable with the web serializers — teaches the codec how
|
|
11
|
+
* to encode/decode a custom value type. Supply matching plugins on both
|
|
12
|
+
* peers of a transport.
|
|
13
|
+
*/
|
|
14
|
+
export type SerializerPlugin = Plugin<any, any>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Baseline plugin set for serializing web-platform values (AbortSignal,
|
|
18
|
+
* Event, FormData, Headers, ReadableStream, Request, Response, URL, ...).
|
|
19
|
+
* Applied by every serializer in this module; custom plugins compose ahead
|
|
20
|
+
* of it via `resolveSerializerPlugins`.
|
|
21
|
+
*/
|
|
22
|
+
export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Composes custom plugins with `DEFAULT_WEB_PLUGINS`. Custom plugins come
|
|
26
|
+
* first so they can shadow a default for values both would match. Returns a
|
|
27
|
+
* fresh array; the defaults are never mutated. Useful when handing a full
|
|
28
|
+
* plugin list to another serialization layer.
|
|
29
|
+
*/
|
|
30
|
+
export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
|
|
31
|
+
|
|
32
|
+
/** Options for `createSerializer`. */
|
|
33
|
+
export interface WebSerializerOptions {
|
|
34
|
+
/** Name of the global object the emitted scripts write resolved values into. */
|
|
35
|
+
globalIdentifier: string;
|
|
36
|
+
/** Cross-reference scope id, for isolating multiple streams on one page. */
|
|
37
|
+
scopeId?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Seroval feature bitflags to exclude from output. Defaults to disabling
|
|
40
|
+
* post-ES2017 features (AggregateError, BigInt typed arrays).
|
|
41
|
+
*/
|
|
42
|
+
disabledFeatures?: number;
|
|
43
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
|
|
44
|
+
plugins?: SerializerPlugin[];
|
|
45
|
+
/** Receives each emitted script chunk. */
|
|
46
|
+
onData: (result: string) => void;
|
|
47
|
+
onError?: (error: unknown) => void;
|
|
48
|
+
/** Fires once all async values have settled. */
|
|
49
|
+
onDone?: () => void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Creates a streaming Seroval serializer preconfigured with the web plugin
|
|
54
|
+
* set and the default feature policy. Emits JavaScript chunks (through
|
|
55
|
+
* `onData`) that reconstruct the values under `globalIdentifier` when
|
|
56
|
+
* evaluated — the script-injection form of serialization renderers build
|
|
57
|
+
* on. For a JSON-based wire codec (no eval on the receiving side), use
|
|
58
|
+
* `serializeJSON` / `createJSONDeserializer` instead.
|
|
59
|
+
*/
|
|
60
|
+
export function createSerializer(options: WebSerializerOptions): Serializer;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Options for `createHydrationSerializer` — `WebSerializerOptions` minus
|
|
64
|
+
* the knobs hydration pins (`globalIdentifier`, `disabledFeatures`).
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export type HydrationSerializerOptions = Omit<
|
|
68
|
+
WebSerializerOptions,
|
|
69
|
+
"globalIdentifier" | "disabledFeatures"
|
|
70
|
+
>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Renderer primitive — the serializer SSR uses for hydration output. Pins
|
|
74
|
+
* the hydration global (`_$HY.r`) and feature policy; only the wiring
|
|
75
|
+
* options (callbacks, scope, extra plugins) are configurable. Not meant
|
|
76
|
+
* for hand-written code — custom serialization should use
|
|
77
|
+
* `createSerializer` or the JSON codec.
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
export function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Renderer primitive — returns the cross-reference bootstrap script SSR
|
|
84
|
+
* emits ahead of hydration data for a render scope. Not meant for
|
|
85
|
+
* hand-written code.
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
export function getLocalHeaderScript(id?: string): string;
|
|
89
|
+
|
|
90
|
+
// ---- JSON codec (server function transports) ----
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Options shared by both halves of the JSON codec. All of them must match
|
|
94
|
+
* on the serializing and deserializing peer or payloads will not
|
|
95
|
+
* round-trip — for server functions, set them once through the
|
|
96
|
+
* client/server `codec` config option.
|
|
97
|
+
*/
|
|
98
|
+
export interface JSONCodecOptions {
|
|
99
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
|
|
100
|
+
plugins?: SerializerPlugin[];
|
|
101
|
+
/**
|
|
102
|
+
* Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
|
|
103
|
+
* (payloads may come from an untrusted peer). Must match on both peers.
|
|
104
|
+
*/
|
|
105
|
+
disabledFeatures?: number;
|
|
106
|
+
/** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
|
|
107
|
+
depthLimit?: number;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Options for `serializeJSON`. */
|
|
111
|
+
export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
112
|
+
/**
|
|
113
|
+
* Receives each serialized node; `initial` is true for the first chunk
|
|
114
|
+
* (the source value itself). Async values produce additional chunks as
|
|
115
|
+
* they resolve.
|
|
116
|
+
*/
|
|
117
|
+
onParse: (node: SerovalNode, initial: boolean) => void;
|
|
118
|
+
onError?: (error: unknown) => void;
|
|
119
|
+
/** Fires once all async values have settled. */
|
|
120
|
+
onDone?: () => void;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Serializes `value` as SerovalNode chunks delivered through `onParse` —
|
|
125
|
+
* the encoding half of the eval-free JSON codec (RPC-style transports;
|
|
126
|
+
* the deserializing peer needs no script evaluation, so CSP-safe). Wire
|
|
127
|
+
* framing of the nodes is the transport's concern. Returns a cancel
|
|
128
|
+
* function that aborts pending async serialization.
|
|
129
|
+
*/
|
|
130
|
+
export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Creates the decoding counterpart of `serializeJSON`. Cross-references
|
|
134
|
+
* between chunks resolve through state shared across calls, so all chunks
|
|
135
|
+
* from one stream must go through the same deserializer instance. The first
|
|
136
|
+
* chunk's return value is the decoded source value; feeding later chunks
|
|
137
|
+
* settles the async values referenced inside it.
|
|
138
|
+
*/
|
|
139
|
+
export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { JSONCodecOptions } from "../serializer.cjs";
|
|
2
|
+
|
|
3
|
+
export { FUNCTION_HEADER, INSTANCE_HEADER, decodeResponse } from "./shared.cjs";
|
|
4
|
+
|
|
5
|
+
/** Options for `configureServerFunctionsClient`. */
|
|
6
|
+
export interface ServerFunctionsClientConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Endpoint the server's HTTP handler is mounted on. Must match the
|
|
9
|
+
* server configuration — SSR'd reference `url`s (e.g. form actions) and
|
|
10
|
+
* client fetches both derive from it. Prefix it when the app serves from
|
|
11
|
+
* a base path (e.g. `` `${BASE_URL}_server` ``).
|
|
12
|
+
* @default "/_server"
|
|
13
|
+
*/
|
|
14
|
+
endpoint?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Codec options (extra plugins etc.) for encoding arguments and decoding
|
|
17
|
+
* results — must match the server's. Stored in the shared layer, so
|
|
18
|
+
* `decodeResponse` sees them too.
|
|
19
|
+
*/
|
|
20
|
+
codec?: JSONCodecOptions;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Configures the client transport. Call once, before any server function is
|
|
25
|
+
* invoked — typically in the client entry, next to `hydrate()`. Only needed
|
|
26
|
+
* when deviating from the defaults (custom endpoint or codec plugins).
|
|
27
|
+
*/
|
|
28
|
+
export function configureServerFunctionsClient(config?: ServerFunctionsClientConfig): void;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* What a server function import is at runtime on the client: an async
|
|
32
|
+
* callable that fetches the server, plus escape hatches for forms and
|
|
33
|
+
* custom requests.
|
|
34
|
+
*/
|
|
35
|
+
export interface ServerFunctionCallable {
|
|
36
|
+
(...args: any[]): Promise<any>;
|
|
37
|
+
/** URL invoking this function directly over HTTP (e.g. form `action`s). */
|
|
38
|
+
url: string;
|
|
39
|
+
/**
|
|
40
|
+
* Variant issuing GET requests with the arguments encoded in the query
|
|
41
|
+
* string — cacheable by HTTP infrastructure.
|
|
42
|
+
*/
|
|
43
|
+
GET: ServerFunctionCallable;
|
|
44
|
+
/** Variant applying a custom RequestInit to every call (headers etc.). */
|
|
45
|
+
withOptions(options: RequestInit): ServerFunctionCallable;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Compiler ABI — emitted by compiled `"use server"` client output where a
|
|
50
|
+
* server function was referenced; produces the fetch-backed callable for
|
|
51
|
+
* the function's build-stable id. Not meant for hand-written code.
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
export function createServerReference(id: string): ServerFunctionCallable;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Compiler ABI — only ever referenced by server-mode compiler output;
|
|
58
|
+
* throws so a misconfigured build (server transform feeding a client
|
|
59
|
+
* bundle) fails loudly instead of with a missing-export error. Not meant
|
|
60
|
+
* for hand-written code.
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
export function registerServerReference(): never;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { ResponseEnvelope } from "../response.cjs";
|
|
2
|
+
import { JSONCodecOptions } from "../serializer.cjs";
|
|
3
|
+
import { RequestEvent } from "../server.cjs";
|
|
4
|
+
|
|
5
|
+
export { FUNCTION_HEADER, INSTANCE_HEADER, decodeResponse } from "./shared.cjs";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The request event a server function call runs under: the base
|
|
9
|
+
* `RequestEvent` (request + locals) plus `serverOnly`, set when the call is
|
|
10
|
+
* an in-process SSR invocation whose result never serializes to a client.
|
|
11
|
+
*/
|
|
12
|
+
export interface ServerFunctionEvent extends RequestEvent {
|
|
13
|
+
serverOnly?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Options for `configureServerFunctionsServer`. */
|
|
17
|
+
export interface ServerFunctionsServerConfig {
|
|
18
|
+
/**
|
|
19
|
+
* Establishes the request-event scope for a call — the function passed
|
|
20
|
+
* runs with `event` visible to `getRequestEvent()`. Wire it to
|
|
21
|
+
* `provideRequestEvent` from `@solidjs/web/storage` (or the framework's
|
|
22
|
+
* equivalent). When omitted, falls back to the AsyncLocalStorage instance
|
|
23
|
+
* an established request scope parks on the global.
|
|
24
|
+
*/
|
|
25
|
+
provideEvent?: <T>(event: ServerFunctionEvent, fn: () => T) => T;
|
|
26
|
+
/**
|
|
27
|
+
* Endpoint the HTTP handler is mounted on, used for the `url` of SSR'd
|
|
28
|
+
* references (e.g. form actions) — must match the client configuration.
|
|
29
|
+
* Prefix it when the app serves from a base path (e.g.
|
|
30
|
+
* `` `${BASE_URL}_server` ``).
|
|
31
|
+
* @default "/_server"
|
|
32
|
+
*/
|
|
33
|
+
endpoint?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Codec options (extra plugins etc.) for decoding arguments and encoding
|
|
36
|
+
* results — must match the client's. Stored in the shared layer, so
|
|
37
|
+
* `decodeResponse` sees them too.
|
|
38
|
+
*/
|
|
39
|
+
codec?: JSONCodecOptions;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Configures the server runtime. Call once at server startup, before
|
|
44
|
+
* handling requests. Only needed when deviating from the defaults (custom
|
|
45
|
+
* endpoint, codec plugins, or an explicit event provider).
|
|
46
|
+
*/
|
|
47
|
+
export function configureServerFunctionsServer(config?: ServerFunctionsServerConfig): void;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A registered server function: its build-stable id paired with the
|
|
51
|
+
* original implementation. Returned by `registerServerReference` and
|
|
52
|
+
* consumed by the server-side `createServerReference`.
|
|
53
|
+
*
|
|
54
|
+
* Compiler ABI shape; hand-written code rarely constructs these.
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export interface ServerFunctionReference<T extends any[] = any[], R = any> {
|
|
58
|
+
id: string;
|
|
59
|
+
fn: (...args: T) => R;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Adds a function to the dispatch registry under an id and returns it
|
|
64
|
+
* unchanged. The low-level registry write for integrations registering
|
|
65
|
+
* functions outside the compiler (e.g. a router registering its own
|
|
66
|
+
* endpoints); compiled output goes through `registerServerReference`
|
|
67
|
+
* instead. Ids must be stable across the client and server builds.
|
|
68
|
+
*/
|
|
69
|
+
export function registerServerFunction<T extends any[], R>(
|
|
70
|
+
id: string,
|
|
71
|
+
callback: (...args: T) => R
|
|
72
|
+
): (...args: T) => R;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Looks up a registered server function by id; throws for unknown ids.
|
|
76
|
+
* The HTTP handler uses this for dispatch — integrations building custom
|
|
77
|
+
* dispatch (or introspection) can too.
|
|
78
|
+
*/
|
|
79
|
+
export function getServerFunction<T extends any[], R>(id: string): (...args: T) => R;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Compiler ABI — emitted by compiled `"use server"` server output for
|
|
83
|
+
* every server function: registers `fn` for HTTP dispatch under its
|
|
84
|
+
* build-stable id and returns the reference the server-side
|
|
85
|
+
* `createServerReference` consumes. Not meant for hand-written code.
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
export function registerServerReference<T extends any[], R>(
|
|
89
|
+
id: string,
|
|
90
|
+
fn: (...args: T) => R
|
|
91
|
+
): ServerFunctionReference<T, R>;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Compiler ABI — emitted by compiled `"use server"` server output where
|
|
95
|
+
* the function was referenced; produces the server-side callable. Calling
|
|
96
|
+
* it during SSR runs the original function in-process (no HTTP), under a
|
|
97
|
+
* request event derived from the current one — marked `serverOnly` and
|
|
98
|
+
* carrying the function's meta. Not meant for hand-written code.
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
export function createServerReference<T extends any[], R>(
|
|
102
|
+
reference: ServerFunctionReference<T, R>
|
|
103
|
+
): (...args: T) => R;
|
|
104
|
+
|
|
105
|
+
/** Identity of the currently executing server function. */
|
|
106
|
+
export interface ServerFunctionMeta {
|
|
107
|
+
id: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Reads the calling server function's meta (its id) off the current request
|
|
112
|
+
* event — usable inside a server function body, e.g. to key caches or logs
|
|
113
|
+
* by function. Returns undefined outside a server function call.
|
|
114
|
+
*/
|
|
115
|
+
export function getServerFunctionMeta(): ServerFunctionMeta | undefined;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Hooks layering framework policy onto `handleServerFunctionRequest`.
|
|
119
|
+
* All are optional — the bare handler dispatches, scopes events, and
|
|
120
|
+
* encodes results on its own.
|
|
121
|
+
*/
|
|
122
|
+
export interface HandleServerFunctionOptions {
|
|
123
|
+
/**
|
|
124
|
+
* Builds the request event a call runs under (default: bare
|
|
125
|
+
* `{ request, locals: {} }`). Integrations supply their richer event
|
|
126
|
+
* (cookies, response helpers, platform handles).
|
|
127
|
+
*/
|
|
128
|
+
createEvent?(request: Request): ServerFunctionEvent;
|
|
129
|
+
/**
|
|
130
|
+
* Overrides the configured event provider for this handler — same
|
|
131
|
+
* contract as the `provideEvent` config option.
|
|
132
|
+
*/
|
|
133
|
+
provideEvent?<T>(event: ServerFunctionEvent, fn: () => T): T;
|
|
134
|
+
/**
|
|
135
|
+
* Observes or replaces the function's result before encoding — the
|
|
136
|
+
* extension point for policies like single-flight payloads. Runs for
|
|
137
|
+
* returned and thrown results alike (`context.thrown` distinguishes);
|
|
138
|
+
* `context.instance` is null for no-JS calls. Return the result
|
|
139
|
+
* unchanged to pass through, or a `ResponseEnvelope` (exposed through
|
|
140
|
+
* the core entry) to send HTTP metadata plus a structured payload.
|
|
141
|
+
*/
|
|
142
|
+
transformResult?(
|
|
143
|
+
event: ServerFunctionEvent,
|
|
144
|
+
result: unknown,
|
|
145
|
+
context: { instance: string | null; request: Request; thrown?: boolean }
|
|
146
|
+
): unknown | ResponseEnvelope | Promise<unknown | ResponseEnvelope>;
|
|
147
|
+
/**
|
|
148
|
+
* Builds the response for calls made without the client runtime (no
|
|
149
|
+
* instance header — no-JS form posts, direct HTTP) — the extension
|
|
150
|
+
* point for conventions like redirect-with-flash-cookie. Receives the
|
|
151
|
+
* (transformed) result, the request, and the decoded arguments; `thrown`
|
|
152
|
+
* is set when the result was thrown rather than returned. Defaults to
|
|
153
|
+
* the normal serialized response.
|
|
154
|
+
*/
|
|
155
|
+
handleNoJS?(
|
|
156
|
+
result: unknown,
|
|
157
|
+
request: Request,
|
|
158
|
+
args: unknown[],
|
|
159
|
+
thrown?: boolean
|
|
160
|
+
): Response | Promise<Response>;
|
|
161
|
+
/** Overrides the configured codec options for this handler. */
|
|
162
|
+
codec?: JSONCodecOptions;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Web-standard HTTP handler for server function calls: resolves the
|
|
167
|
+
* function id from the request, decodes arguments, runs the function under
|
|
168
|
+
* a request-event scope, and encodes the result (forwarding
|
|
169
|
+
* redirect/revalidation metadata through headers). Mount it on the endpoint
|
|
170
|
+
* the client transport targets (default `/_server`); platform adapters
|
|
171
|
+
* (h3, express, ...) convert their request shape to a web `Request` around
|
|
172
|
+
* it.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* import { handleServerFunctionRequest } from "@solidjs/web/server-functions";
|
|
177
|
+
* import "virtual:solid-server-function-manifest";
|
|
178
|
+
*
|
|
179
|
+
* // in the server's request handling:
|
|
180
|
+
* if (url.pathname.startsWith("/_server")) {
|
|
181
|
+
* return handleServerFunctionRequest(request);
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
export function handleServerFunctionRequest(
|
|
186
|
+
request: Request,
|
|
187
|
+
options?: HandleServerFunctionOptions
|
|
188
|
+
): Promise<Response>;
|