@solidjs/web 2.0.0-rc.0 → 2.0.0-rc.2

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.
Files changed (40) hide show
  1. package/README.md +1 -1
  2. package/dist/dev.cjs +40 -11
  3. package/dist/dev.js +39 -12
  4. package/dist/server.cjs +419 -69
  5. package/dist/server.js +411 -73
  6. package/dist/web.cjs +37 -11
  7. package/dist/web.js +36 -12
  8. package/frames/dist/client.cjs +94 -8
  9. package/frames/dist/client.dev.cjs +97 -8
  10. package/frames/dist/client.dev.js +98 -9
  11. package/frames/dist/client.js +95 -9
  12. package/frames/dist/server.cjs +266 -56
  13. package/frames/dist/server.js +267 -57
  14. package/package.json +4 -3
  15. package/serialization/dist/decode.cjs +32 -3
  16. package/serialization/dist/decode.js +33 -4
  17. package/serialization/dist/serialization.cjs +32 -3
  18. package/serialization/dist/serialization.js +33 -4
  19. package/server-functions/dist/client.cjs +196 -8
  20. package/server-functions/dist/client.js +195 -9
  21. package/server-functions/dist/server.cjs +201 -36
  22. package/server-functions/dist/server.dev.cjs +201 -36
  23. package/server-functions/dist/server.dev.js +199 -37
  24. package/server-functions/dist/server.js +199 -37
  25. package/types/core.d.ts +3 -0
  26. package/types/frames/frame-client.d.ts +18 -0
  27. package/types/index.d.ts +16 -2
  28. package/types/jsx.d.ts +9 -0
  29. package/types/server-functions/client.d.ts +61 -0
  30. package/types/server-functions/server.d.ts +94 -1
  31. package/types/server-mock.d.ts +11 -2
  32. package/types/server.d.ts +23 -2
  33. package/types-cjs/core.d.cts +3 -0
  34. package/types-cjs/frames/frame-client.d.cts +18 -0
  35. package/types-cjs/index.d.cts +16 -2
  36. package/types-cjs/jsx.d.cts +9 -0
  37. package/types-cjs/server-functions/client.d.cts +61 -0
  38. package/types-cjs/server-functions/server.d.cts +94 -1
  39. package/types-cjs/server-mock.d.cts +11 -2
  40. package/types-cjs/server.d.cts +23 -2
@@ -28,7 +28,7 @@ export type {
28
28
  } from "./shared.js";
29
29
  export { decodeFlashCookie, encodeFlashCookie } from "./flash.js";
30
30
  export type { FlashSubmission } from "./flash.js";
31
- import { ServerFunction } from "./shared.js";
31
+ import { ServerFunction, ServerFunctionMetadata } from "./shared.js";
32
32
 
33
33
  /**
34
34
  * The request event a server function call runs under: the base
@@ -197,6 +197,26 @@ export function createNoJSHandler(
197
197
  options?: NoJSHandlerOptions
198
198
  ): (result: unknown, request: Request, args: unknown[], thrown?: boolean) => Response;
199
199
 
200
+ export type ServerFunctionOriginMatcher =
201
+ | string
202
+ | readonly string[]
203
+ | ((origin: string, request: Request) => boolean | Promise<boolean>);
204
+
205
+ /** Same-origin validation options for server function requests. */
206
+ export interface ServerFunctionCSRFOptions {
207
+ /**
208
+ * Expected public origin. Defaults to the incoming request URL's origin.
209
+ * A function can validate origins dynamically for multi-tenant hosts.
210
+ */
211
+ origin?: ServerFunctionOriginMatcher;
212
+ /**
213
+ * Allows requests without `Sec-Fetch-Site`, `Origin`, or `Referer`.
214
+ * Cross-origin metadata is still rejected.
215
+ * @default false
216
+ */
217
+ allowRequestsWithoutOriginCheck?: boolean;
218
+ }
219
+
200
220
  /** Options for `configureServerFunctionsServer`. */
201
221
  export interface ServerFunctionsServerConfig {
202
222
  /**
@@ -287,6 +307,12 @@ export interface ServerFunctionsServerConfig {
287
307
  * @default "/_server"
288
308
  */
289
309
  endpoint?: string;
310
+ /**
311
+ * Same-origin protection for HTTP server function calls. Enabled by
312
+ * default. Set to `false` only when another trusted layer protects the
313
+ * endpoint.
314
+ */
315
+ csrf?: boolean | ServerFunctionCSRFOptions;
290
316
  /**
291
317
  * Codec options (extra plugins etc.) for decoding arguments and encoding
292
318
  * results — must match the client's. Stored in the shared layer, so
@@ -392,6 +418,36 @@ export function GET<A extends readonly any[], R>(
392
418
  fn: (...args: A) => R
393
419
  ): ServerFunction<A, Awaited<R>>;
394
420
 
421
+ /** Wire-state transitions a live call's iterable can report (client side).
422
+ * `"closed"` carries the error when a definite rejection (4xx) ended the
423
+ * call instead of the retry loop. */
424
+ export type LiveSourceStatus = "connected" | "reconnecting" | "closed";
425
+
426
+ /**
427
+ * Type-level mirror of the client's live answer shape so isomorphic code
428
+ * assigning `onstatus` typechecks against either build's declarations. On
429
+ * the server the hook is inert: in-process calls hand back the source's
430
+ * own iterable — there is no connection to report on.
431
+ */
432
+ export type LiveSource<R> = R & {
433
+ onstatus?: (state: LiveSourceStatus, error?: unknown) => void;
434
+ };
435
+
436
+ /**
437
+ * Declares a value-shaped live source: a server function returning an async
438
+ * iterable whose yields are successive VALUES of one logical query, with
439
+ * the contract that the source re-yields current state on every invocation.
440
+ * Writes `live: true` on the metadata channel and brands the resolved
441
+ * iterable (registered symbol `solid.LiveSource`) so SSR faces meeting the
442
+ * value in-process can apply live policy (document face: first value, then
443
+ * client takeover). Dispatch is untouched — over-the-wire calls stream the
444
+ * raw registered function's result. Declare live outermost:
445
+ * `live(GET(fn))`.
446
+ */
447
+ export function live<A extends readonly any[], R>(
448
+ fn: (...args: A) => R
449
+ ): ServerFunction<A, LiveSource<Awaited<R>>>;
450
+
395
451
  /** Identity of the currently executing server function call. */
396
452
  export interface ServerFunctionInvocation {
397
453
  id: string;
@@ -501,6 +557,11 @@ export interface HandleServerFunctionOptions {
501
557
  args: unknown[],
502
558
  thrown?: boolean
503
559
  ): Response | Promise<Response>;
560
+ /**
561
+ * Overrides same-origin protection for this handler. Set to `false` only
562
+ * when another trusted layer protects the endpoint.
563
+ */
564
+ csrf?: boolean | ServerFunctionCSRFOptions;
504
565
  /** Overrides the configured codec options for this handler. */
505
566
  codec?: JSONCodecOptions;
506
567
  }
@@ -515,6 +576,10 @@ export interface HandleServerFunctionOptions {
515
576
  * (default `/_server`); platform adapters (h3, express, ...) convert their
516
577
  * request shape to a web `Request` around it.
517
578
  *
579
+ * Requests are same-origin by default. The handler accepts browser requests
580
+ * proven by `Sec-Fetch-Site`, `Origin`, or `Referer`, and rejects requests
581
+ * without usable metadata unless explicitly configured otherwise.
582
+ *
518
583
  * When the event carries a `response` head stub (`event.response`, see the
519
584
  * server entry's `ResponseStub`), the handler folds it onto every outgoing
520
585
  * response as the head freezes — its `Set-Cookie` values (cookies appended
@@ -578,6 +643,34 @@ export const GENERIC_SERVER_ERROR_MESSAGE: string;
578
643
  */
579
644
  export function sanitizeServerError(value: unknown): unknown;
580
645
 
646
+ export interface ServerFunctionRequestCall {
647
+ type: "request";
648
+ id: string;
649
+ instance: string;
650
+ request: Request;
651
+ meta: ServerFunctionMetadata | undefined;
652
+ time: number;
653
+ }
654
+
655
+ export interface ServerFunctionResponseCall {
656
+ type: "response";
657
+ id: string;
658
+ instance: string;
659
+ response: Response;
660
+ meta: ServerFunctionMetadata | undefined;
661
+ time: number;
662
+ }
663
+
664
+ export type ServerFunctionCall = ServerFunctionRequestCall | ServerFunctionResponseCall;
665
+
666
+ /**
667
+ * Client-only inspection seam. A no-op on this entry so isomorphic
668
+ * `@solidjs/web/server-functions` imports resolve.
669
+ */
670
+ export function observeServerFunctionCalls(
671
+ observer: (call: ServerFunctionCall) => void
672
+ ): () => void;
673
+
581
674
  /**
582
675
  * Overrides the build-variant dev flag for this module instance — the seam
583
676
  * for test harnesses and hand-rolled bundles whose packaging cannot replace
@@ -39,6 +39,15 @@ export type AssetResolver = {
39
39
  };
40
40
  /** Bare-function shorthand for `AssetResolver` (no sync fast path). */
41
41
  export type AssetResolverFn = (key: string) => ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
42
+ /**
43
+ * CSP nonce for the tags a server render emits. A string applies to both
44
+ * nonce-aware destinations; a `{ script, style }` pair routes each tag to
45
+ * its destination's nonce, with `false` leaving that destination un-nonced.
46
+ */
47
+ export type CSPNonce = string | {
48
+ script: string | false;
49
+ style: string | false;
50
+ };
42
51
  /**
43
52
  * Renders a component tree synchronously to an HTML string. Async reads inside
44
53
  * `<Loading>` boundaries emit their `fallback` content; for full-graph
@@ -55,7 +64,7 @@ export type AssetResolverFn = (key: string) => ResolvedAssets | null | undefined
55
64
  * ```
56
65
  */
57
66
  export declare function renderToString<T>(fn: () => T, options?: {
58
- nonce?: string;
67
+ nonce?: CSPNonce;
59
68
  renderId?: string;
60
69
  noScripts?: boolean;
61
70
  plugins?: any[];
@@ -100,7 +109,7 @@ export declare function renderToString<T>(fn: () => T, options?: {
100
109
  * ```
101
110
  */
102
111
  export declare function renderToStream<T>(fn: () => T, options?: {
103
- nonce?: string;
112
+ nonce?: CSPNonce;
104
113
  renderId?: string;
105
114
  noScripts?: boolean;
106
115
  plugins?: any[];
package/types/server.d.ts CHANGED
@@ -57,10 +57,31 @@ export type AssetResolverFn = (
57
57
  key: string
58
58
  ) => ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
59
59
 
60
+ /**
61
+ * CSP nonce for the tags a server render emits. A string applies to both
62
+ * nonce-aware destinations. A `{ script, style }` pair routes each tag to
63
+ * the directive governing its fetch (`script-src-elem` / `style-src-elem`,
64
+ * falling back to `script-src` / `style-src` then `default-src`). Both
65
+ * keys are required; `false` leaves that destination un-nonced. Worker
66
+ * destinations take the script nonce, which only applies when their own
67
+ * fallback reaches `script-src`. A nonce on a `useHead` tag's own props
68
+ * always wins.
69
+ *
70
+ * Only `renderToString` / `renderToStream` take this shape. Surfaces that
71
+ * emit one script (`HydrationScript`, `generateHydrationScript`,
72
+ * `createSSRResponse`) take a string — project with `scriptNonce`.
73
+ */
74
+ export type CSPNonce = string | { script: string | false; style: string | false };
75
+
76
+ /** The script-destination half of a render `nonce`. */
77
+ export function scriptNonce(nonce?: CSPNonce): string | undefined;
78
+ /** The style-destination half of a render `nonce`. */
79
+ export function styleNonce(nonce?: CSPNonce): string | undefined;
80
+
60
81
  export function renderToString<T>(
61
82
  fn: () => T,
62
83
  options?: {
63
- nonce?: string;
84
+ nonce?: CSPNonce;
64
85
  renderId?: string;
65
86
  noScripts?: boolean;
66
87
  plugins?: SerializerPlugin[];
@@ -82,7 +103,7 @@ export function renderToString<T>(
82
103
  export function renderToStream<T>(
83
104
  fn: () => T,
84
105
  options?: {
85
- nonce?: string;
106
+ nonce?: CSPNonce;
86
107
  renderId?: string;
87
108
  noScripts?: boolean;
88
109
  plugins?: SerializerPlugin[];
@@ -4,3 +4,6 @@ export declare const memo: (fn: any) => import("solid-js").SourceAccessor<any>;
4
4
  export declare const runWithHydrationScope: (id: any, fn: any) => unknown;
5
5
  export declare const ssrAsyncValue: (value: any) => import("solid-js").SourceAccessor<any>;
6
6
  export declare const waitAsset: (promise: any) => void;
7
+ export declare const driveList: undefined;
8
+ export declare const patchableRaw: undefined;
9
+ export declare const registerPatch: undefined;
@@ -245,6 +245,15 @@ export interface FrameHostOptions {
245
245
  * identity only.
246
246
  */
247
247
  isContainer?(value: unknown): boolean;
248
+ /**
249
+ * Arms event types for behavior claims: the `_bnd` sweep collects the
250
+ * event names it finds and hands them here so delegated dispatch can
251
+ * reach them. Platform glue passes its `delegateEvents` — the option
252
+ * exists (rather than client.js importing the event system) so
253
+ * tree-shaken subsets without events pay nothing. Frames registered
254
+ * with this host inherit it unless they pass their own `delegate`.
255
+ */
256
+ delegate?(eventNames: Iterable<string>): void;
248
257
  }
249
258
 
250
259
  /** @experimental */
@@ -260,6 +269,13 @@ export interface FrameOptions {
260
269
  id?: string;
261
270
  /** Client content keyed by prop name (occurrences resolve by prop). */
262
271
  slots?: Record<string, Slot>;
272
+ /**
273
+ * Raw client props for behavior-claim resolution: server elements carrying
274
+ * `_bnd="pos=prop"` markers (compiled under the `serverComponents` option)
275
+ * resolve ref/event positions by name through this object — read live at
276
+ * dispatch/materialize time, so compiled prop getters stay latest-value.
277
+ */
278
+ props?: Record<string, unknown>;
263
279
  /**
264
280
  * Adopt existing server-rendered DOM: the first apply morphs against it,
265
281
  * and slots sync immediately (hydration attach) — a document-SSR boot
@@ -277,6 +293,8 @@ export interface FrameOptions {
277
293
  * streamed chunks).
278
294
  */
279
295
  ownerScope?<T>(fn: () => T): T;
296
+ /** Per-frame override of the host's `delegate` (see FrameHostOptions). */
297
+ delegate?(eventNames: Iterable<string>): void;
280
298
  /**
281
299
  * Boundary-driven segment reveal. When present, `#revealSegment` hands the
282
300
  * placeholder seam to this hook instead of swapping imperatively: the binding
@@ -102,6 +102,12 @@ export declare function render(code: () => JSX.Element, element: MountableElemen
102
102
  * Pass `options.renderId` to hydrate one of multiple roots emitted by a
103
103
  * server render that used the same id.
104
104
  *
105
+ * When the server renders a full document but the client hydrates only the
106
+ * app subtree, the server must give that subtree its own id namespace: wrap
107
+ * the document shell in `<NoHydration>` and re-enter with `<Hydration>`
108
+ * around the app. Otherwise the app's hydration ids are allocated under the
109
+ * document component's owner tree and this walk can never claim them.
110
+ *
105
111
  * @example
106
112
  * ```tsx
107
113
  * import { hydrate } from "@solidjs/web";
@@ -170,7 +176,8 @@ export declare function Dynamic<T extends ValidComponent>(props: DynamicProps<T>
170
176
  *
171
177
  * By default the import starts as soon as `clientOnly` is called (module
172
178
  * load); pass `{ lazy: true }` to defer the import to the component's first
173
- * render.
179
+ * render. Pass `{ export: "Name" }` to use a named export of the resolved
180
+ * module instead of its default (mirrors `lazy()`'s option).
174
181
  *
175
182
  * @example
176
183
  * ```tsx
@@ -178,11 +185,18 @@ export declare function Dynamic<T extends ValidComponent>(props: DynamicProps<T>
178
185
  * // <Chart fallback={<div>Loading chart…</div>} data={data()} />
179
186
  * ```
180
187
  */
188
+ export declare function clientOnly<M extends Record<string, any>, K extends keyof M & string>(fn: () => Promise<M>, options: {
189
+ lazy?: boolean;
190
+ export: K;
191
+ }, moduleUrl?: string): Component<ComponentProps<M[K]> & {
192
+ fallback?: JSX.Element;
193
+ }>;
181
194
  export declare function clientOnly<T extends Component<any>>(fn: () => Promise<{
182
195
  default: T;
183
196
  }>, options?: {
184
197
  lazy?: boolean;
185
- }, _moduleUrl?: string): Component<ComponentProps<T> & {
198
+ export?: string;
199
+ }, moduleUrl?: string): Component<ComponentProps<T> & {
186
200
  fallback?: JSX.Element;
187
201
  }>;
188
202
  /**
@@ -249,6 +249,15 @@ export namespace JSX {
249
249
  ref?: Ref<T>;
250
250
  children?: Element | undefined;
251
251
  $ServerOnly?: boolean | undefined;
252
+ /**
253
+ * Entity identity for server markup (SSR-only): compiles to the `_key`
254
+ * attribute the frame morph matches keyed elements by, so live element
255
+ * state (form values, `open`, focus) follows the entity across
256
+ * reordering morphs. Sibling-scoped, like client keyed rendering.
257
+ * Stripped from DOM compiles; on components, `$key` is slot occurrence
258
+ * identity instead.
259
+ */
260
+ $key?: string | number | undefined;
252
261
  }
253
262
  interface ExplicitProperties {}
254
263
  type PropAttributes = {
@@ -127,6 +127,36 @@ export interface ServerFunctionsClientConfig {
127
127
  */
128
128
  export function configureServerFunctionsClient(config?: ServerFunctionsClientConfig): void;
129
129
 
130
+ export interface ServerFunctionRequestCall {
131
+ type: "request";
132
+ id: string;
133
+ instance: string;
134
+ request: Request;
135
+ meta: ServerFunctionMetadata | undefined;
136
+ time: number;
137
+ }
138
+
139
+ export interface ServerFunctionResponseCall {
140
+ type: "response";
141
+ id: string;
142
+ instance: string;
143
+ response: Response;
144
+ meta: ServerFunctionMetadata | undefined;
145
+ time: number;
146
+ }
147
+
148
+ 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
+
130
160
  /**
131
161
  * Declares a server function callable over HTTP GET: calls to the returned
132
162
  * reference go out as GET requests with the arguments codec-encoded in the
@@ -156,6 +186,37 @@ export function GET<A extends readonly any[], R>(
156
186
  fn: (...args: A) => R
157
187
  ): ServerFunction<A, Awaited<R>>;
158
188
 
189
+ /** Wire-state transitions a live call's iterable can report. */
190
+ export type LiveSourceStatus = "connected" | "reconnecting" | "closed";
191
+
192
+ /**
193
+ * A live call's answer: the source's iterable, plus an optional `onstatus`
194
+ * side channel for the wire facts the reconnect loop erases from the value
195
+ * stream — `"connected"` on each successful (re)connect, `"reconnecting"`
196
+ * (with the error) on each transient post-connect death, `"closed"` when
197
+ * the source completes or the consumer ends it — with the error when the
198
+ * end was a definite rejection (4xx) failing fast instead of retrying.
199
+ */
200
+ export type LiveSource<R> = R & {
201
+ onstatus?: (state: LiveSourceStatus, error?: unknown) => void;
202
+ };
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
+
159
220
  /**
160
221
  * Compiler ABI — emitted by compiled `"use server"` client output where a
161
222
  * server function was referenced; produces the fetch-backed callable for
@@ -28,7 +28,7 @@ export type {
28
28
  } from "./shared.cjs";
29
29
  export { decodeFlashCookie, encodeFlashCookie } from "./flash.cjs";
30
30
  export type { FlashSubmission } from "./flash.cjs";
31
- import { ServerFunction } from "./shared.cjs";
31
+ import { ServerFunction, ServerFunctionMetadata } from "./shared.cjs";
32
32
 
33
33
  /**
34
34
  * The request event a server function call runs under: the base
@@ -197,6 +197,26 @@ export function createNoJSHandler(
197
197
  options?: NoJSHandlerOptions
198
198
  ): (result: unknown, request: Request, args: unknown[], thrown?: boolean) => Response;
199
199
 
200
+ export type ServerFunctionOriginMatcher =
201
+ | string
202
+ | readonly string[]
203
+ | ((origin: string, request: Request) => boolean | Promise<boolean>);
204
+
205
+ /** Same-origin validation options for server function requests. */
206
+ export interface ServerFunctionCSRFOptions {
207
+ /**
208
+ * Expected public origin. Defaults to the incoming request URL's origin.
209
+ * A function can validate origins dynamically for multi-tenant hosts.
210
+ */
211
+ origin?: ServerFunctionOriginMatcher;
212
+ /**
213
+ * Allows requests without `Sec-Fetch-Site`, `Origin`, or `Referer`.
214
+ * Cross-origin metadata is still rejected.
215
+ * @default false
216
+ */
217
+ allowRequestsWithoutOriginCheck?: boolean;
218
+ }
219
+
200
220
  /** Options for `configureServerFunctionsServer`. */
201
221
  export interface ServerFunctionsServerConfig {
202
222
  /**
@@ -287,6 +307,12 @@ export interface ServerFunctionsServerConfig {
287
307
  * @default "/_server"
288
308
  */
289
309
  endpoint?: string;
310
+ /**
311
+ * Same-origin protection for HTTP server function calls. Enabled by
312
+ * default. Set to `false` only when another trusted layer protects the
313
+ * endpoint.
314
+ */
315
+ csrf?: boolean | ServerFunctionCSRFOptions;
290
316
  /**
291
317
  * Codec options (extra plugins etc.) for decoding arguments and encoding
292
318
  * results — must match the client's. Stored in the shared layer, so
@@ -392,6 +418,36 @@ export function GET<A extends readonly any[], R>(
392
418
  fn: (...args: A) => R
393
419
  ): ServerFunction<A, Awaited<R>>;
394
420
 
421
+ /** Wire-state transitions a live call's iterable can report (client side).
422
+ * `"closed"` carries the error when a definite rejection (4xx) ended the
423
+ * call instead of the retry loop. */
424
+ export type LiveSourceStatus = "connected" | "reconnecting" | "closed";
425
+
426
+ /**
427
+ * Type-level mirror of the client's live answer shape so isomorphic code
428
+ * assigning `onstatus` typechecks against either build's declarations. On
429
+ * the server the hook is inert: in-process calls hand back the source's
430
+ * own iterable — there is no connection to report on.
431
+ */
432
+ export type LiveSource<R> = R & {
433
+ onstatus?: (state: LiveSourceStatus, error?: unknown) => void;
434
+ };
435
+
436
+ /**
437
+ * Declares a value-shaped live source: a server function returning an async
438
+ * iterable whose yields are successive VALUES of one logical query, with
439
+ * the contract that the source re-yields current state on every invocation.
440
+ * Writes `live: true` on the metadata channel and brands the resolved
441
+ * iterable (registered symbol `solid.LiveSource`) so SSR faces meeting the
442
+ * value in-process can apply live policy (document face: first value, then
443
+ * client takeover). Dispatch is untouched — over-the-wire calls stream the
444
+ * raw registered function's result. Declare live outermost:
445
+ * `live(GET(fn))`.
446
+ */
447
+ export function live<A extends readonly any[], R>(
448
+ fn: (...args: A) => R
449
+ ): ServerFunction<A, LiveSource<Awaited<R>>>;
450
+
395
451
  /** Identity of the currently executing server function call. */
396
452
  export interface ServerFunctionInvocation {
397
453
  id: string;
@@ -501,6 +557,11 @@ export interface HandleServerFunctionOptions {
501
557
  args: unknown[],
502
558
  thrown?: boolean
503
559
  ): Response | Promise<Response>;
560
+ /**
561
+ * Overrides same-origin protection for this handler. Set to `false` only
562
+ * when another trusted layer protects the endpoint.
563
+ */
564
+ csrf?: boolean | ServerFunctionCSRFOptions;
504
565
  /** Overrides the configured codec options for this handler. */
505
566
  codec?: JSONCodecOptions;
506
567
  }
@@ -515,6 +576,10 @@ export interface HandleServerFunctionOptions {
515
576
  * (default `/_server`); platform adapters (h3, express, ...) convert their
516
577
  * request shape to a web `Request` around it.
517
578
  *
579
+ * Requests are same-origin by default. The handler accepts browser requests
580
+ * proven by `Sec-Fetch-Site`, `Origin`, or `Referer`, and rejects requests
581
+ * without usable metadata unless explicitly configured otherwise.
582
+ *
518
583
  * When the event carries a `response` head stub (`event.response`, see the
519
584
  * server entry's `ResponseStub`), the handler folds it onto every outgoing
520
585
  * response as the head freezes — its `Set-Cookie` values (cookies appended
@@ -578,6 +643,34 @@ export const GENERIC_SERVER_ERROR_MESSAGE: string;
578
643
  */
579
644
  export function sanitizeServerError(value: unknown): unknown;
580
645
 
646
+ export interface ServerFunctionRequestCall {
647
+ type: "request";
648
+ id: string;
649
+ instance: string;
650
+ request: Request;
651
+ meta: ServerFunctionMetadata | undefined;
652
+ time: number;
653
+ }
654
+
655
+ export interface ServerFunctionResponseCall {
656
+ type: "response";
657
+ id: string;
658
+ instance: string;
659
+ response: Response;
660
+ meta: ServerFunctionMetadata | undefined;
661
+ time: number;
662
+ }
663
+
664
+ export type ServerFunctionCall = ServerFunctionRequestCall | ServerFunctionResponseCall;
665
+
666
+ /**
667
+ * Client-only inspection seam. A no-op on this entry so isomorphic
668
+ * `@solidjs/web/server-functions` imports resolve.
669
+ */
670
+ export function observeServerFunctionCalls(
671
+ observer: (call: ServerFunctionCall) => void
672
+ ): () => void;
673
+
581
674
  /**
582
675
  * Overrides the build-variant dev flag for this module instance — the seam
583
676
  * for test harnesses and hand-rolled bundles whose packaging cannot replace
@@ -39,6 +39,15 @@ export type AssetResolver = {
39
39
  };
40
40
  /** Bare-function shorthand for `AssetResolver` (no sync fast path). */
41
41
  export type AssetResolverFn = (key: string) => ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
42
+ /**
43
+ * CSP nonce for the tags a server render emits. A string applies to both
44
+ * nonce-aware destinations; a `{ script, style }` pair routes each tag to
45
+ * its destination's nonce, with `false` leaving that destination un-nonced.
46
+ */
47
+ export type CSPNonce = string | {
48
+ script: string | false;
49
+ style: string | false;
50
+ };
42
51
  /**
43
52
  * Renders a component tree synchronously to an HTML string. Async reads inside
44
53
  * `<Loading>` boundaries emit their `fallback` content; for full-graph
@@ -55,7 +64,7 @@ export type AssetResolverFn = (key: string) => ResolvedAssets | null | undefined
55
64
  * ```
56
65
  */
57
66
  export declare function renderToString<T>(fn: () => T, options?: {
58
- nonce?: string;
67
+ nonce?: CSPNonce;
59
68
  renderId?: string;
60
69
  noScripts?: boolean;
61
70
  plugins?: any[];
@@ -100,7 +109,7 @@ export declare function renderToString<T>(fn: () => T, options?: {
100
109
  * ```
101
110
  */
102
111
  export declare function renderToStream<T>(fn: () => T, options?: {
103
- nonce?: string;
112
+ nonce?: CSPNonce;
104
113
  renderId?: string;
105
114
  noScripts?: boolean;
106
115
  plugins?: any[];
@@ -57,10 +57,31 @@ export type AssetResolverFn = (
57
57
  key: string
58
58
  ) => ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
59
59
 
60
+ /**
61
+ * CSP nonce for the tags a server render emits. A string applies to both
62
+ * nonce-aware destinations. A `{ script, style }` pair routes each tag to
63
+ * the directive governing its fetch (`script-src-elem` / `style-src-elem`,
64
+ * falling back to `script-src` / `style-src` then `default-src`). Both
65
+ * keys are required; `false` leaves that destination un-nonced. Worker
66
+ * destinations take the script nonce, which only applies when their own
67
+ * fallback reaches `script-src`. A nonce on a `useHead` tag's own props
68
+ * always wins.
69
+ *
70
+ * Only `renderToString` / `renderToStream` take this shape. Surfaces that
71
+ * emit one script (`HydrationScript`, `generateHydrationScript`,
72
+ * `createSSRResponse`) take a string — project with `scriptNonce`.
73
+ */
74
+ export type CSPNonce = string | { script: string | false; style: string | false };
75
+
76
+ /** The script-destination half of a render `nonce`. */
77
+ export function scriptNonce(nonce?: CSPNonce): string | undefined;
78
+ /** The style-destination half of a render `nonce`. */
79
+ export function styleNonce(nonce?: CSPNonce): string | undefined;
80
+
60
81
  export function renderToString<T>(
61
82
  fn: () => T,
62
83
  options?: {
63
- nonce?: string;
84
+ nonce?: CSPNonce;
64
85
  renderId?: string;
65
86
  noScripts?: boolean;
66
87
  plugins?: SerializerPlugin[];
@@ -82,7 +103,7 @@ export function renderToString<T>(
82
103
  export function renderToStream<T>(
83
104
  fn: () => T,
84
105
  options?: {
85
- nonce?: string;
106
+ nonce?: CSPNonce;
86
107
  renderId?: string;
87
108
  noScripts?: boolean;
88
109
  plugins?: SerializerPlugin[];