@solidjs/web 2.0.0-beta.31 → 2.0.0-beta.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +1 -6
  2. package/dist/dev.cjs +285 -60
  3. package/dist/dev.js +267 -57
  4. package/dist/server.cjs +1148 -176
  5. package/dist/server.js +1133 -175
  6. package/dist/web.cjs +285 -60
  7. package/dist/web.js +267 -57
  8. package/frames/dist/client.cjs +397 -175
  9. package/frames/dist/client.dev.cjs +401 -175
  10. package/frames/dist/client.dev.js +399 -173
  11. package/frames/dist/client.js +395 -173
  12. package/frames/dist/server.cjs +1424 -277
  13. package/frames/dist/server.js +1426 -280
  14. package/package.json +69 -7
  15. package/serialization/decode/package.json +20 -0
  16. package/serialization/dist/decode.cjs +110 -0
  17. package/serialization/dist/decode.js +104 -0
  18. package/serialization/dist/serialization.cjs +106 -43
  19. package/serialization/dist/serialization.js +100 -44
  20. package/serialization/types/index.d.ts +85 -60
  21. package/serialization/types/serializer-decode.d.ts +182 -0
  22. package/serialization/types-cjs/index.d.cts +85 -60
  23. package/serialization/types-cjs/serializer-decode.d.cts +182 -0
  24. package/server-functions/dist/client.cjs +131 -98
  25. package/server-functions/dist/client.js +131 -99
  26. package/server-functions/dist/rich-args.cjs +11 -0
  27. package/server-functions/dist/rich-args.js +9 -0
  28. package/server-functions/dist/server.cjs +367 -194
  29. package/server-functions/dist/server.dev.cjs +1077 -0
  30. package/server-functions/dist/server.dev.js +1045 -0
  31. package/server-functions/dist/server.js +365 -195
  32. package/server-functions/package.json +10 -0
  33. package/server-functions/rich-args/package.json +20 -0
  34. package/storage/types/index.d.ts +1 -1
  35. package/storage/types-cjs/index.d.cts +1 -1
  36. package/types/client.d.ts +149 -6
  37. package/types/cookies.d.ts +93 -0
  38. package/types/core.d.ts +4 -2
  39. package/types/frames/client.d.ts +15 -1
  40. package/types/frames/frame-client.d.ts +63 -7
  41. package/types/frames/frame-sink.d.ts +26 -3
  42. package/types/frames/frame-transport.d.ts +40 -8
  43. package/types/frames/serializer.d.ts +85 -60
  44. package/types/frames/server.d.ts +22 -0
  45. package/types/index.d.ts +2 -3
  46. package/types/response.d.ts +45 -0
  47. package/types/serializer-decode.d.ts +182 -0
  48. package/types/serializer.d.ts +85 -60
  49. package/types/server-functions/client.d.ts +2 -1
  50. package/types/server-functions/rich-args.d.ts +10 -0
  51. package/types/server-functions/server.d.ts +99 -1
  52. package/types/server-functions/shared.d.ts +79 -1
  53. package/types/server-mock.d.ts +171 -59
  54. package/types/server.d.ts +209 -37
  55. package/types-cjs/client.d.cts +149 -6
  56. package/types-cjs/cookies.d.cts +93 -0
  57. package/types-cjs/core.d.cts +4 -2
  58. package/types-cjs/frames/client.d.cts +15 -1
  59. package/types-cjs/frames/frame-client.d.cts +63 -7
  60. package/types-cjs/frames/frame-sink.d.cts +26 -3
  61. package/types-cjs/frames/frame-transport.d.cts +40 -8
  62. package/types-cjs/frames/serializer.d.cts +85 -60
  63. package/types-cjs/frames/server.d.cts +22 -0
  64. package/types-cjs/index.d.cts +2 -3
  65. package/types-cjs/response.d.cts +45 -0
  66. package/types-cjs/serializer-decode.d.cts +182 -0
  67. package/types-cjs/serializer.d.cts +85 -60
  68. package/types-cjs/server-functions/client.d.cts +2 -1
  69. package/types-cjs/server-functions/rich-args.d.cts +10 -0
  70. package/types-cjs/server-functions/server.d.cts +99 -1
  71. package/types-cjs/server-functions/shared.d.cts +79 -1
  72. package/types-cjs/server-mock.d.cts +171 -59
  73. package/types-cjs/server.d.cts +209 -37
@@ -1,5 +1,5 @@
1
1
  import { JSX } from "./jsx.cjs";
2
- import { SerializerPlugin } from "./serializer.cjs";
2
+ import { SerializerPlugin } from "./serializer-decode.cjs";
3
3
  export const DOMWithState: Record<string, Record<string, 1 | 2>>;
4
4
  export const ChildProperties: Set<string>;
5
5
  export const DelegatedEvents: Set<string>;
@@ -79,19 +79,6 @@ export function renderToString<T>(
79
79
  onHead?: (head: string) => void;
80
80
  }
81
81
  ): string;
82
- /** @deprecated use renderToStream which also returns a promise */
83
- export function renderToStringAsync<T>(
84
- fn: () => T,
85
- options?: {
86
- timeoutMs?: number;
87
- nonce?: string;
88
- renderId?: string;
89
- noScripts?: boolean;
90
- plugins?: SerializerPlugin[];
91
- manifest?: AssetManifest | AssetResolver | AssetResolverFn;
92
- onError?: (err: any) => void;
93
- }
94
- ): Promise<string>;
95
82
  export function renderToStream<T>(
96
83
  fn: () => T,
97
84
  options?: {
@@ -116,7 +103,17 @@ export function renderToStream<T>(
116
103
  onHead?: (head: string) => void;
117
104
  }
118
105
  ): {
119
- then: (fn: (html: string) => void) => void;
106
+ /**
107
+ * Awaiting the stream resolves with the complete HTML once every boundary
108
+ * settles — the fully-settled-string form of the render (`const html =
109
+ * await renderToStream(...)`). Render errors route through `onError` and
110
+ * the promise resolves with whatever HTML the render produced; it never
111
+ * rejects.
112
+ */
113
+ then<TResult1 = string, TResult2 = never>(
114
+ onfulfilled?: ((html: string) => TResult1 | PromiseLike<TResult1>) | null,
115
+ onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
116
+ ): Promise<TResult1 | TResult2>;
120
117
  pipe: (writable: { write: (v: string) => void; end: () => void }) => void;
121
118
  pipeTo: (writable: WritableStream) => Promise<void>;
122
119
  /**
@@ -153,21 +150,20 @@ export function applyRef(
153
150
  r: ((element: any) => void) | ((element: any) => void)[],
154
151
  element: any
155
152
  ): void;
156
- /** @deprecated Use `useHead` — removed before `0.50.0` stable. */
157
- export function useAssets(fn: () => JSX.Element): void;
158
- /**
159
- * @deprecated Use the `onHead` render option — removed before `0.50.0`
160
- * stable. Reads ambient render state, so it is unsafe across concurrent
161
- * renders; `onHead` is closure-bound to its render and also carries
162
- * `useHead` output, which this does not.
163
- */
164
- export function getAssets(): string;
165
153
  /**
166
154
  * A head tag descriptor. Props values may be getters (evaluated lazily on
167
155
  * the server — at the owning flush boundary — and reactively on the client);
168
156
  * `children` is the text body (title text, inline style/script content).
169
157
  * `key` overrides the built-in dedupe identity (`title` is a hard singleton
170
158
  * that `key` cannot fork).
159
+ *
160
+ * Getters must be plain reads: they evaluate at flush time here (under no
161
+ * component owner) and inside registry-owned computations on the client, so
162
+ * a getter that allocates a reactive owner (`createMemo`, a `children()`
163
+ * helper) consumes a hydration id slot on one side only and desyncs every
164
+ * id allocated after the `useHead` call. Create such helpers eagerly at
165
+ * component position and read them from the getter. See
166
+ * docs/head-management-rfc.md.
171
167
  */
172
168
  export type HeadTag = {
173
169
  tag: "title" | "meta" | "link" | "style" | "script" | "base";
@@ -212,32 +208,62 @@ export declare const RequestContext: unique symbol;
212
208
  * `response` property on `RequestEvent` itself: integrations that provide
213
209
  * one declare it through module augmentation (as `@solidjs/router` does),
214
210
  * and this type names the shape they agree on. Core's server-function
215
- * handler reads its `Set-Cookie` headers when folding single-flight
216
- * cookies but never requires it.
211
+ * handler folds it onto the outgoing response when present — its
212
+ * `Set-Cookie` values (cookies appended during the call via
213
+ * `serializeCookie`) append cookie-by-cookie, other headers fill gaps —
214
+ * and reads it when folding single-flight cookies, but never requires it.
217
215
  */
218
216
  export interface ResponseStub {
219
217
  status?: number;
220
218
  statusText?: string;
221
219
  headers: Headers;
222
220
  /**
223
- * Set by the integration once the response head has been derived/sent
224
- * from this stub — status and headers can no longer change. Consumers
225
- * that write response metadata during render (e.g. JSX response
226
- * components) must treat later status/header writes and cleanup-time
227
- * retractions as no-ops.
221
+ * Set once the response head has been derived/sent from this stub —
222
+ * status and headers can no longer change. Flip it through
223
+ * `commitResponseStub`, which also instruments the stub's `headers` so
224
+ * a post-commit write fails loudly (dev build throws, production
225
+ * reports + no-ops) instead of silently missing the wire. `status`/
226
+ * `statusText` stay plain fields: consumers that write response
227
+ * metadata during render (e.g. JSX response components) must still
228
+ * treat later status writes and cleanup-time retractions as no-ops.
228
229
  */
229
230
  committed?: boolean;
230
231
  }
231
232
 
233
+ /**
234
+ * The type of `RequestEvent.locals` — a module-augmentable interface so
235
+ * applications can type the state their middleware hangs on the event.
236
+ * Augment it through the package that re-exports the event (interface
237
+ * identity flows through the re-export chain):
238
+ *
239
+ * ```ts
240
+ * declare module "@solidjs/web" {
241
+ * interface RequestEventLocals {
242
+ * user: User;
243
+ * }
244
+ * }
245
+ * ```
246
+ *
247
+ * The index signature keeps un-augmented usage permissive — `locals` is a
248
+ * free-form bag by default — so augmentation adds precision for the keys
249
+ * it names without gating existing code. The flip side: unaugmented keys
250
+ * read as `any` rather than erroring, a deliberate trade (a strict-only
251
+ * `locals` would break every untyped write that works today).
252
+ */
253
+ export interface RequestEventLocals {
254
+ [key: string | number | symbol]: any;
255
+ }
256
+
232
257
  /**
233
258
  * The per-request context available on the server: the incoming `Request`
234
- * and a `locals` bag integrations and middleware can hang state on.
235
- * Frameworks typically extend this shape with richer fields (e.g. a
236
- * `response` head — see `ResponseStub`).
259
+ * and a `locals` bag integrations and middleware can hang state on (typed
260
+ * through the augmentable `RequestEventLocals`). Frameworks typically
261
+ * extend this shape with richer fields (e.g. a `response` head — see
262
+ * `ResponseStub`).
237
263
  */
238
264
  export interface RequestEvent {
239
265
  request: Request;
240
- locals: Record<string | number | symbol, any>;
266
+ locals: RequestEventLocals;
241
267
  }
242
268
  /**
243
269
  * The current request event, when called on the server inside a request
@@ -247,7 +273,149 @@ export interface RequestEvent {
247
273
  */
248
274
  export function getRequestEvent(): RequestEvent | undefined;
249
275
 
250
- export function Assets(props: { children?: JSX.Element }): JSX.Element;
276
+ /** A fresh, uncommitted response head. */
277
+ export function createResponseStub(): ResponseStub;
278
+
279
+ /**
280
+ * The canonical request event for HTTP handlers: the incoming `Request`, a
281
+ * `locals` bag, and a `response` head stub the render writes to. `init`
282
+ * spreads over the defaults so frameworks can extend the shape.
283
+ */
284
+ export function createRequestEvent<T extends object = {}>(
285
+ request: Request,
286
+ init?: T
287
+ ): RequestEvent & { response: ResponseStub } & T;
288
+
289
+ /**
290
+ * The status an outgoing redirect should use for a response head carrying
291
+ * a `Location`: the stub's own status when it is a redirect status, 302
292
+ * otherwise.
293
+ */
294
+ export function getExpectedRedirectStatus(response: ResponseStub): number;
295
+
296
+ /**
297
+ * Flips a response stub to `committed` — the moment its head freezes on
298
+ * the wire — and instruments the stub's `headers` mutating methods
299
+ * (`set`/`append`/`delete`, patched in place; the `Headers` identity and
300
+ * reads are untouched) so a post-commit write fails loudly instead of
301
+ * silently missing the wire: it throws in the dev build and reports +
302
+ * no-ops otherwise. Every head materialization path commits through here
303
+ * (`createSSRResponse`, the server-function handler's commit seam);
304
+ * integrations deriving their own heads should too.
305
+ *
306
+ * `allowLateLocation` is the stream path's documented exception: a
307
+ * `Location` set after the shell flushed is still honored client-side
308
+ * (stream completion appends a `window.location` script), so that one
309
+ * write stays permitted there.
310
+ */
311
+ export function commitResponseStub(
312
+ stub: ResponseStub,
313
+ options?: { allowLateLocation?: boolean }
314
+ ): ResponseStub;
315
+
316
+ /**
317
+ * Handler-lifecycle plumbing — a response's exit through the request
318
+ * event's response-stub lifecycle: page results leave through
319
+ * `createSSRResponse`, any other `Response` (a middleware early return, an
320
+ * API result) leaves through `commitEventResponse`; application middleware
321
+ * never calls this. Folds the event's stub onto the outgoing response —
322
+ * `Set-Cookie` appends entry-by-entry alongside the response's own, other
323
+ * stub headers fill gaps only (never the wire-protocol family the handlers
324
+ * own, never `Content-Type`/`Content-Length` on a bodiless response), the
325
+ * status is never taken from the stub — then commits the stub
326
+ * (`commitResponseStub`: post-commit writes fail loudly). Responses with
327
+ * immutable headers are rebuilt around merged copies.
328
+ *
329
+ * Idempotent at handler edges: an already-committed stub passes the
330
+ * response through untouched, so a handler may apply this unconditionally
331
+ * after its middleware chain unwinds — page responses from
332
+ * `createSSRResponse` come back committed and do not double-fold.
333
+ *
334
+ * `event` defaults to the ambient `getRequestEvent()`.
335
+ */
336
+ export function commitEventResponse(response: Response, event?: RequestEvent): Response;
337
+
338
+ /**
339
+ * The cookie codec (the platform-gap primitives — see cookies.d.ts): ALL
340
+ * of core's cookie surface. The blessed patterns are
341
+ * `parseCookieHeader(event.request.headers.get("cookie"))` for reads and
342
+ * `event.response.headers.append("set-cookie", serializeCookie(name,
343
+ * value, options))` for writes.
344
+ */
345
+ export { parseCookieHeader, serializeCookie } from "./cookies.cjs";
346
+ export type { CookieOptions } from "./cookies.cjs";
347
+
348
+ /**
349
+ * The flash cookie's isomorphic half and the codec-free server-function
350
+ * layer (reference detection + the late-bound RPC seam) — mirrors of the
351
+ * client entry's exports, so integration code reading them stays
352
+ * universal. Declared through server-functions/shared.d.ts, the
353
+ * declaration home published-types layouts ship.
354
+ */
355
+ export {
356
+ clearFlashCookie,
357
+ getServerFunctionMetadata,
358
+ getServerFunctionRPC,
359
+ hasFlashCookie,
360
+ isServerFunction
361
+ } from "./server-functions/shared.cjs";
362
+ export type {
363
+ ServerFunction,
364
+ ServerFunctionMetadata,
365
+ ServerFunctionRPC
366
+ } from "./server-functions/shared.cjs";
367
+
368
+ export interface SSRResponseOptions {
369
+ /** Base head; the stub's status/headers win over it. */
370
+ responseInit?: ResponseInit;
371
+ /** Nonce carried by the post-flush `<script>` redirect fallback. */
372
+ nonce?: string;
373
+ /** Rewrites each outgoing HTML chunk (entry script injection, ...). */
374
+ transformChunk?: (chunk: string) => string;
375
+ }
376
+
377
+ /**
378
+ * Derives the outgoing `Response` for an SSR render result, running the
379
+ * response-head lifecycle against `event.response`: commit at shell flush,
380
+ * pre-flush `Location` becomes a real redirect, post-flush `Location`
381
+ * appends a client-side script redirect before the stream closes.
382
+ * Synchronous for string results; resolves at shell flush for stream
383
+ * results.
384
+ */
385
+ export function createSSRResponse(
386
+ result: string,
387
+ event: RequestEvent | undefined,
388
+ options?: SSRResponseOptions
389
+ ): Response;
390
+ export function createSSRResponse(
391
+ result: { pipe(writable: { write: (v: string) => void; end: () => void }): void },
392
+ event: RequestEvent | undefined,
393
+ options?: SSRResponseOptions
394
+ ): Promise<Response>;
395
+
396
+ /**
397
+ * Fetch-style middleware: return a `Response` to answer the request, or
398
+ * call `next()` (optionally with a substitute `Request`) to advance the
399
+ * chain and observe/replace the eventual response.
400
+ */
401
+ export type FetchMiddleware = (
402
+ request: Request,
403
+ next: (request?: Request) => Promise<Response>
404
+ ) => Response | Promise<Response>;
405
+
406
+ /**
407
+ * Composes fetch-style middleware into one function of the same shape;
408
+ * the terminal `next` dispatches to the actual handler. Runs in whatever
409
+ * scope the caller established (`provideRequestEvent`), so
410
+ * `getRequestEvent()` works exactly as in application code.
411
+ */
412
+ export function composeMiddleware(
413
+ middlewares: FetchMiddleware[]
414
+ ): (
415
+ request: Request,
416
+ next: (request?: Request) => Response | Promise<Response>
417
+ ) => Promise<Response>;
418
+
251
419
  export function untrack<T>(fn: () => T): T;
252
420
 
253
421
  // client-only APIs
@@ -347,5 +515,9 @@ export function ref(
347
515
  ): void;
348
516
  /** @deprecated not supported on the server side */
349
517
  export function setStyleProperty(node: Element, name: string, value: any): void;
350
- /** @deprecated not supported on the server side — register assets through the render context instead */
518
+ /**
519
+ * @internal See client.d.ts — head-management RFC policy: ambient CSS is
520
+ * unmanaged; the head registry owns directly-mounted stylesheet lifecycle.
521
+ * @deprecated not supported on the server side — register assets through the render context instead
522
+ */
351
523
  export function acquireAsset(descriptor: unknown): () => void;