@bquery/bquery 1.10.0 → 1.11.0
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/README.md +44 -19
- package/dist/{a11y-DG2i4iZN.js → a11y-DgUQ8-fI.js} +1 -1
- package/dist/{a11y-DG2i4iZN.js.map → a11y-DgUQ8-fI.js.map} +1 -1
- package/dist/a11y.es.mjs +1 -1
- package/dist/{component-DRotf1hl.js → component-D8ydhe58.js} +2 -2
- package/dist/{component-DRotf1hl.js.map → component-D8ydhe58.js.map} +1 -1
- package/dist/component.es.mjs +1 -1
- package/dist/concurrency-BU1wPEsZ.js.map +1 -1
- package/dist/{constraints-CqjhmpZC.js → constraints-Dlbx_m1b.js} +1 -1
- package/dist/{constraints-CqjhmpZC.js.map → constraints-Dlbx_m1b.js.map} +1 -1
- package/dist/{core-EMYSLzaT.js → core-tOP6QOrY.js} +2 -2
- package/dist/{core-EMYSLzaT.js.map → core-tOP6QOrY.js.map} +1 -1
- package/dist/core.es.mjs +1 -1
- package/dist/{custom-directives-BjFzFhuf.js → custom-directives-5DlKqvd2.js} +1 -1
- package/dist/{custom-directives-BjFzFhuf.js.map → custom-directives-5DlKqvd2.js.map} +1 -1
- package/dist/{devtools-C5FExMwv.js → devtools-QosAqo0T.js} +2 -2
- package/dist/{devtools-C5FExMwv.js.map → devtools-QosAqo0T.js.map} +1 -1
- package/dist/devtools.es.mjs +1 -1
- package/dist/{dnd-BAqzPlSo.js → dnd-d2OU4len.js} +1 -1
- package/dist/{dnd-BAqzPlSo.js.map → dnd-d2OU4len.js.map} +1 -1
- package/dist/dnd.es.mjs +1 -1
- package/dist/{forms-Dx1Scvh0.js → forms-BLx4ZzT7.js} +1 -1
- package/dist/{forms-Dx1Scvh0.js.map → forms-BLx4ZzT7.js.map} +1 -1
- package/dist/forms.es.mjs +1 -1
- package/dist/full.d.ts +4 -2
- package/dist/full.d.ts.map +1 -1
- package/dist/full.es.mjs +258 -219
- package/dist/full.iife.js +41 -37
- package/dist/full.iife.js.map +1 -1
- package/dist/full.umd.js +41 -37
- package/dist/full.umd.js.map +1 -1
- package/dist/{i18n-Cazyk9RD.js → i18n--p7PM-9r.js} +1 -1
- package/dist/{i18n-Cazyk9RD.js.map → i18n--p7PM-9r.js.map} +1 -1
- package/dist/i18n.es.mjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.mjs +291 -252
- package/dist/match-CrZRVC4z.js +174 -0
- package/dist/match-CrZRVC4z.js.map +1 -0
- package/dist/{media-dAKIGPk3.js → media-gjbWNq50.js} +1 -1
- package/dist/{media-dAKIGPk3.js.map → media-gjbWNq50.js.map} +1 -1
- package/dist/media.es.mjs +1 -1
- package/dist/motion-BBMso9Ir.js.map +1 -1
- package/dist/{mount-C8O2vXkQ.js → mount-0A9qtcRJ.js} +3 -3
- package/dist/{mount-C8O2vXkQ.js.map → mount-0A9qtcRJ.js.map} +1 -1
- package/dist/platform-BPHIXbw8.js.map +1 -1
- package/dist/{plugin-DjTqWg-P.js → plugin-SZEirbwq.js} +2 -2
- package/dist/{plugin-DjTqWg-P.js.map → plugin-SZEirbwq.js.map} +1 -1
- package/dist/plugin.es.mjs +1 -1
- package/dist/reactive-BAd2hfl8.js.map +1 -1
- package/dist/{registry-Cr6VH8CR.js → registry-jpUQHf4E.js} +1 -1
- package/dist/{registry-Cr6VH8CR.js.map → registry-jpUQHf4E.js.map} +1 -1
- package/dist/router-C4weu0QL.js +333 -0
- package/dist/router-C4weu0QL.js.map +1 -0
- package/dist/router.es.mjs +1 -1
- package/dist/{sanitize-B1V4JswB.js → sanitize-DOMkRO9G.js} +12 -7
- package/dist/{sanitize-B1V4JswB.js.map → sanitize-DOMkRO9G.js.map} +1 -1
- package/dist/security.es.mjs +1 -1
- package/dist/server/create-server.d.ts +25 -0
- package/dist/server/create-server.d.ts.map +1 -0
- package/dist/server/index.d.ts +11 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/types.d.ts +396 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server-QdyKtCS1.js +349 -0
- package/dist/server-QdyKtCS1.js.map +1 -0
- package/dist/server.es.mjs +6 -0
- package/dist/ssr/adapters.d.ts +74 -0
- package/dist/ssr/adapters.d.ts.map +1 -0
- package/dist/ssr/async.d.ts +40 -0
- package/dist/ssr/async.d.ts.map +1 -0
- package/dist/ssr/config.d.ts +60 -0
- package/dist/ssr/config.d.ts.map +1 -0
- package/dist/ssr/context.d.ts +73 -0
- package/dist/ssr/context.d.ts.map +1 -0
- package/dist/ssr/defer-brand.d.ts +5 -0
- package/dist/ssr/defer-brand.d.ts.map +1 -0
- package/dist/ssr/escape.d.ts +17 -0
- package/dist/ssr/escape.d.ts.map +1 -0
- package/dist/ssr/expression.d.ts +44 -0
- package/dist/ssr/expression.d.ts.map +1 -0
- package/dist/ssr/hash.d.ts +39 -0
- package/dist/ssr/hash.d.ts.map +1 -0
- package/dist/ssr/head.d.ts +102 -0
- package/dist/ssr/head.d.ts.map +1 -0
- package/dist/ssr/html-parser.d.ts +58 -0
- package/dist/ssr/html-parser.d.ts.map +1 -0
- package/dist/ssr/index.d.ts +49 -43
- package/dist/ssr/index.d.ts.map +1 -1
- package/dist/ssr/mismatch.d.ts +60 -0
- package/dist/ssr/mismatch.d.ts.map +1 -0
- package/dist/ssr/render-async.d.ts +84 -0
- package/dist/ssr/render-async.d.ts.map +1 -0
- package/dist/ssr/render.d.ts.map +1 -1
- package/dist/ssr/renderer.d.ts +25 -0
- package/dist/ssr/renderer.d.ts.map +1 -0
- package/dist/ssr/resumability.d.ts +65 -0
- package/dist/ssr/resumability.d.ts.map +1 -0
- package/dist/ssr/router-bridge.d.ts +101 -0
- package/dist/ssr/router-bridge.d.ts.map +1 -0
- package/dist/ssr/runtime.d.ts +63 -0
- package/dist/ssr/runtime.d.ts.map +1 -0
- package/dist/ssr/serialize.d.ts.map +1 -1
- package/dist/ssr/store-snapshot.d.ts +87 -0
- package/dist/ssr/store-snapshot.d.ts.map +1 -0
- package/dist/ssr/strategies.d.ts +43 -0
- package/dist/ssr/strategies.d.ts.map +1 -0
- package/dist/ssr/suspense.d.ts +47 -0
- package/dist/ssr/suspense.d.ts.map +1 -0
- package/dist/ssr/types.d.ts +17 -0
- package/dist/ssr/types.d.ts.map +1 -1
- package/dist/ssr-Bt6BQA3J.js +2127 -0
- package/dist/ssr-Bt6BQA3J.js.map +1 -0
- package/dist/ssr.es.mjs +42 -7
- package/dist/{store-CjmEeX9-.js → store-DnXuu6Li.js} +2 -2
- package/dist/{store-CjmEeX9-.js.map → store-DnXuu6Li.js.map} +1 -1
- package/dist/store.es.mjs +2 -2
- package/dist/storybook.es.mjs +1 -1
- package/dist/{testing-TdfaL7VE.js → testing-CeMUwrRD.js} +2 -2
- package/dist/{testing-TdfaL7VE.js.map → testing-CeMUwrRD.js.map} +1 -1
- package/dist/testing.es.mjs +1 -1
- package/dist/view.es.mjs +1 -1
- package/package.json +17 -12
- package/src/full.ts +99 -0
- package/src/index.ts +3 -0
- package/src/server/create-server.ts +754 -0
- package/src/server/index.ts +33 -0
- package/src/server/types.ts +490 -0
- package/src/ssr/adapters.ts +330 -0
- package/src/ssr/async.ts +125 -0
- package/src/ssr/config.ts +86 -0
- package/src/ssr/context.ts +245 -0
- package/src/ssr/defer-brand.ts +3 -0
- package/src/ssr/escape.ts +25 -0
- package/src/ssr/expression.ts +669 -0
- package/src/ssr/hash.ts +71 -0
- package/src/ssr/head.ts +240 -0
- package/src/ssr/html-parser.ts +387 -0
- package/src/ssr/index.ts +136 -43
- package/src/ssr/mismatch.ts +110 -0
- package/src/ssr/render-async.ts +286 -0
- package/src/ssr/render.ts +130 -59
- package/src/ssr/renderer.ts +453 -0
- package/src/ssr/resumability.ts +142 -0
- package/src/ssr/router-bridge.ts +177 -0
- package/src/ssr/runtime.ts +131 -0
- package/src/ssr/serialize.ts +1 -27
- package/src/ssr/store-snapshot.ts +209 -0
- package/src/ssr/strategies.ts +245 -0
- package/src/ssr/suspense.ts +504 -0
- package/src/ssr/types.ts +18 -0
- package/dist/router-CCepRMpC.js +0 -493
- package/dist/router-CCepRMpC.js.map +0 -1
- package/dist/ssr-D-1IPcfw.js +0 -248
- package/dist/ssr-D-1IPcfw.js.map +0 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side rendering context.
|
|
3
|
+
*
|
|
4
|
+
* Encapsulates everything a render path may need to know about the incoming
|
|
5
|
+
* request and to produce response-side metadata (head tags, asset hints,
|
|
6
|
+
* nonces, etc.). The context is propagated explicitly through the public
|
|
7
|
+
* async APIs (`renderToStringAsync`, `renderToStream`, `renderToResponse`)
|
|
8
|
+
* and is available to template loaders.
|
|
9
|
+
*
|
|
10
|
+
* @module bquery/ssr
|
|
11
|
+
*/
|
|
12
|
+
import { type AssetManager, type HeadManager } from './head';
|
|
13
|
+
/** Options for `createSSRContext()`. */
|
|
14
|
+
export interface CreateSSRContextOptions {
|
|
15
|
+
/** Pre-built request to use as the source of URL/headers/cookies/etc. */
|
|
16
|
+
request?: Request;
|
|
17
|
+
/** Override the URL (defaults to `request.url` or `'http://localhost/'`). */
|
|
18
|
+
url?: string | URL;
|
|
19
|
+
/** Override the user agent string. */
|
|
20
|
+
userAgent?: string;
|
|
21
|
+
/** Override the request locale; defaults to `Accept-Language` parsing. */
|
|
22
|
+
locale?: string;
|
|
23
|
+
/** Provide an `AbortSignal` for cancellation. Default: `request.signal`. */
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
/** Pre-computed CSP nonce. If omitted and `crypto.getRandomValues` exists, a fresh nonce is generated. */
|
|
26
|
+
nonce?: string;
|
|
27
|
+
/** Render mode hint — used by streaming/string renderers for diagnostics. */
|
|
28
|
+
mode?: 'string' | 'stream';
|
|
29
|
+
/** Optional error sink invoked for non-fatal render errors. */
|
|
30
|
+
onError?: (error: unknown) => void;
|
|
31
|
+
}
|
|
32
|
+
/** Public SSR context shape. */
|
|
33
|
+
export interface SSRContext {
|
|
34
|
+
/** The originating `Request` (may be a synthetic one if none was provided). */
|
|
35
|
+
request: Request;
|
|
36
|
+
/** Parsed URL of the request. */
|
|
37
|
+
url: URL;
|
|
38
|
+
/** Request headers (via `Request.headers`). */
|
|
39
|
+
headers: Headers;
|
|
40
|
+
/** Resolved cookie map from `Cookie` header. */
|
|
41
|
+
cookies: Record<string, string>;
|
|
42
|
+
/** Best-effort user agent string. */
|
|
43
|
+
userAgent: string;
|
|
44
|
+
/** Best-effort locale parsed from `Accept-Language`. */
|
|
45
|
+
locale: string;
|
|
46
|
+
/** Cancellation signal — render paths must respect it. */
|
|
47
|
+
signal: AbortSignal;
|
|
48
|
+
/** CSP nonce applied to all generated `<script>` tags. */
|
|
49
|
+
nonce: string;
|
|
50
|
+
/** Render mode hint. */
|
|
51
|
+
mode: 'string' | 'stream';
|
|
52
|
+
/** Head manager — call `head.add(...)`, `head.render()`, or read `head.state()`. */
|
|
53
|
+
head: HeadManager;
|
|
54
|
+
/** Asset manifest — call `assets.preload()`/`module()`/`style()`. */
|
|
55
|
+
assets: AssetManager;
|
|
56
|
+
/** Status code suggested by render paths (loaders, error boundaries). */
|
|
57
|
+
status: number;
|
|
58
|
+
/** Outgoing response headers (used by `renderToResponse()`). */
|
|
59
|
+
responseHeaders: Headers;
|
|
60
|
+
/** Reports a non-fatal error. */
|
|
61
|
+
reportError(error: unknown): void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Creates a fully populated SSR context.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const ctx = createSSRContext({ request });
|
|
69
|
+
* const { html } = await renderToStringAsync(template, data, { context: ctx });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare const createSSRContext: (options?: CreateSSRContextOptions) => SSRContext;
|
|
73
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sour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ACrB,yEAAyE;IACzE,MAAM,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,eAAe,EAAE,OAAO,CAAC;IACzB,iCAAiC;IACjC,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CACnC;AAoHD;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAAI,UAAS,uBAA4B,KAAG,UAqDxE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defer-brand.d.ts","sourceRoot":"","sources":["../../src/ssr/defer-brand.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,CAAC,MAAM,iBAAiB,EAAE,OAAO,MAAM,CAAC;AAC/C,eAAO,MAAM,WAAW,EAAqC,OAAO,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared escaping helpers for SSR inline script payloads and HTML attributes.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/ssr
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Escapes a string for safe embedding in an inline `<script>` body.
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare const escapeForScript: (str: string) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Escapes a string for safe embedding in an HTML attribute value.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare const escapeForHtmlAttribute: (str: string) => string;
|
|
17
|
+
//# sourceMappingURL=escape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.d.ts","sourceRoot":"","sources":["../../src/ssr/escape.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,KAAG,MAMZ,CAAC;AAEnC;;;GAGG;AACH,eAAO,MAAM,sBAAsB,GAAI,KAAK,MAAM,KAAG,MAC2C,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSP-safe expression evaluator for SSR templates.
|
|
3
|
+
*
|
|
4
|
+
* Evaluates a tightly scoped subset of JavaScript expressions against a
|
|
5
|
+
* binding context without using `eval` or `new Function()`. Runs in any
|
|
6
|
+
* runtime (Bun, Deno, Node, browsers) and is safe under strict CSP without
|
|
7
|
+
* `'unsafe-eval'`.
|
|
8
|
+
*
|
|
9
|
+
* Supported grammar (operator-precedence Pratt parser):
|
|
10
|
+
*
|
|
11
|
+
* - Literals: numbers, single/double-quoted strings, `true`, `false`, `null`,
|
|
12
|
+
* `undefined`.
|
|
13
|
+
* - Identifiers and member access (`a.b`, `a['b']`, `a[0]`).
|
|
14
|
+
* - Optional chaining (`a?.b`, `a?.[b]`).
|
|
15
|
+
* - Unary `!`, `+`, `-`, `typeof`.
|
|
16
|
+
* - Binary `+`, `-`, `*`, `/`, `%`, `==`, `===`, `!=`, `!==`, `<`, `<=`,
|
|
17
|
+
* `>`, `>=`, `&&`, `||`, `??`.
|
|
18
|
+
* - Ternary `cond ? a : b`.
|
|
19
|
+
* - Parentheses for grouping.
|
|
20
|
+
* - Function calls `fn(arg1, arg2, ...)` (only on identifiers / member chains
|
|
21
|
+
* resolved against the context — no arbitrary expression invocation).
|
|
22
|
+
*
|
|
23
|
+
* Anything outside this grammar throws a parse error which the caller
|
|
24
|
+
* converts into the standard SSR fallback (`undefined`).
|
|
25
|
+
*
|
|
26
|
+
* @module bquery/ssr
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
import type { BindingContext } from '../view/types';
|
|
30
|
+
/**
|
|
31
|
+
* Evaluates a tightly scoped expression against a binding context.
|
|
32
|
+
*
|
|
33
|
+
* Returns `undefined` when the expression cannot be parsed or evaluated.
|
|
34
|
+
* This matches the behaviour of the previous `new Function()`-based fallback
|
|
35
|
+
* but never invokes dynamic code generation.
|
|
36
|
+
*
|
|
37
|
+
* @param expression - Expression source.
|
|
38
|
+
* @param context - Binding context whose top-level signal/computed values are
|
|
39
|
+
* automatically unwrapped.
|
|
40
|
+
*
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
export declare const evaluateExpression: <T = unknown>(expression: string, context: BindingContext) => T;
|
|
44
|
+
//# sourceMappingURL=expression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression.d.ts","sourceRoot":"","sources":["../../src/ssr/expression.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAgmBpD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,GAAG,OAAO,EAAE,YAAY,MAAM,EAAE,SAAS,cAAc,KAAG,CAgB7F,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared hashing helpers used by the SSR renderer and the client-side
|
|
3
|
+
* hydration mismatch verifier.
|
|
4
|
+
*
|
|
5
|
+
* The hash is intentionally cheap (DJB2 → base36) — its goal is to spot
|
|
6
|
+
* Server↔Client divergence in dev, not to provide cryptographic guarantees.
|
|
7
|
+
*
|
|
8
|
+
* @module bquery/ssr
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Computes a stable, very small hash for a string. Used to attach a hydration
|
|
12
|
+
* annotation that the client can compare against during dev-time hydration.
|
|
13
|
+
*
|
|
14
|
+
* Collisions are acceptable here: the goal is a mismatch *warning*, not
|
|
15
|
+
* security.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare const cheapHash: (input: string) => string;
|
|
20
|
+
/**
|
|
21
|
+
* The attribute that holds the directive-signature hash on a server-rendered
|
|
22
|
+
* element. Public name so userland can read/write it deterministically.
|
|
23
|
+
*/
|
|
24
|
+
export declare const HYDRATION_HASH_ATTR = "data-bq-h";
|
|
25
|
+
/**
|
|
26
|
+
* Collects the directive signature for a virtual element (used by the pure
|
|
27
|
+
* renderer).
|
|
28
|
+
*
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export declare const collectDirectiveSignatureFromAttrs: (attributeOrder: readonly string[], attributes: Readonly<Record<string, string | undefined>>, prefix: string) => string;
|
|
32
|
+
/**
|
|
33
|
+
* Collects the directive signature for a real DOM `Element`. Used by the
|
|
34
|
+
* client-side mismatch verifier and the DOM-backed renderer.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export declare const collectDirectiveSignatureFromElement: (el: Element, prefix: string) => string;
|
|
39
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/ssr/hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,KAAG,MAMzC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,cAAc,CAAC;AAE/C;;;;;GAKG;AACH,eAAO,MAAM,kCAAkC,GAC7C,gBAAgB,SAAS,MAAM,EAAE,EACjC,YAAY,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,EACxD,QAAQ,MAAM,KACb,MASF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oCAAoC,GAAI,IAAI,OAAO,EAAE,QAAQ,MAAM,KAAG,MAUlF,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Head manager for SSR.
|
|
3
|
+
*
|
|
4
|
+
* Collects `<title>`, `<meta>`, `<link>` and inline `<script>` directives that
|
|
5
|
+
* a render path wants to inject into the document head, then serialises them
|
|
6
|
+
* as a single HTML string. The same descriptor shape is reused by the
|
|
7
|
+
* server-side head manager methods across SSR entry points.
|
|
8
|
+
*
|
|
9
|
+
* @module bquery/ssr
|
|
10
|
+
*/
|
|
11
|
+
/** A `<meta>` tag descriptor. */
|
|
12
|
+
export interface SSRMeta {
|
|
13
|
+
name?: string;
|
|
14
|
+
property?: string;
|
|
15
|
+
httpEquiv?: string;
|
|
16
|
+
charset?: string;
|
|
17
|
+
content?: string;
|
|
18
|
+
}
|
|
19
|
+
/** A `<link>` tag descriptor. */
|
|
20
|
+
export interface SSRLink {
|
|
21
|
+
rel: string;
|
|
22
|
+
href: string;
|
|
23
|
+
as?: string;
|
|
24
|
+
type?: string;
|
|
25
|
+
crossorigin?: string;
|
|
26
|
+
media?: string;
|
|
27
|
+
integrity?: string;
|
|
28
|
+
nonce?: string;
|
|
29
|
+
}
|
|
30
|
+
/** An inline or external `<script>` tag descriptor. */
|
|
31
|
+
export interface SSRScript {
|
|
32
|
+
src?: string;
|
|
33
|
+
type?: string;
|
|
34
|
+
body?: string;
|
|
35
|
+
defer?: boolean;
|
|
36
|
+
async?: boolean;
|
|
37
|
+
nonce?: string;
|
|
38
|
+
crossorigin?: string;
|
|
39
|
+
integrity?: string;
|
|
40
|
+
module?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Options accepted by `HeadManager.add()`. */
|
|
43
|
+
export interface UseHeadOptions {
|
|
44
|
+
title?: string;
|
|
45
|
+
titleTemplate?: string;
|
|
46
|
+
meta?: SSRMeta[];
|
|
47
|
+
link?: SSRLink[];
|
|
48
|
+
script?: SSRScript[];
|
|
49
|
+
}
|
|
50
|
+
/** Aggregated head state collected during a render. */
|
|
51
|
+
export interface SSRHeadState {
|
|
52
|
+
title: string | null;
|
|
53
|
+
titleTemplate: string | null;
|
|
54
|
+
meta: SSRMeta[];
|
|
55
|
+
link: SSRLink[];
|
|
56
|
+
script: SSRScript[];
|
|
57
|
+
}
|
|
58
|
+
/** Public head manager handle. */
|
|
59
|
+
export interface HeadManager {
|
|
60
|
+
/** Add or replace head entries. */
|
|
61
|
+
add(options: UseHeadOptions): void;
|
|
62
|
+
/** Returns the current state snapshot. */
|
|
63
|
+
state(): SSRHeadState;
|
|
64
|
+
/** Renders the collected head into HTML. */
|
|
65
|
+
render(options?: {
|
|
66
|
+
nonce?: string;
|
|
67
|
+
}): string;
|
|
68
|
+
/** Resets the manager to an empty state. */
|
|
69
|
+
reset(): void;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Creates an isolated head manager. Each SSR context owns one instance.
|
|
73
|
+
*/
|
|
74
|
+
export declare const createHeadManager: () => HeadManager;
|
|
75
|
+
/** Asset preload entry. */
|
|
76
|
+
export interface SSRAsset {
|
|
77
|
+
href: string;
|
|
78
|
+
rel: 'preload' | 'modulepreload' | 'stylesheet';
|
|
79
|
+
as?: string;
|
|
80
|
+
type?: string;
|
|
81
|
+
crossorigin?: string;
|
|
82
|
+
integrity?: string;
|
|
83
|
+
}
|
|
84
|
+
/** Public asset manager handle. */
|
|
85
|
+
export interface AssetManager {
|
|
86
|
+
/** Add a generic preload (`<link rel="preload">`). */
|
|
87
|
+
preload(href: string, opts?: Omit<SSRAsset, 'href' | 'rel'>): void;
|
|
88
|
+
/** Add a JS module preload (`<link rel="modulepreload">`). */
|
|
89
|
+
module(href: string, opts?: Omit<SSRAsset, 'href' | 'rel' | 'as'>): void;
|
|
90
|
+
/** Add a stylesheet link (`<link rel="stylesheet">`). */
|
|
91
|
+
style(href: string, opts?: Omit<SSRAsset, 'href' | 'rel' | 'as'>): void;
|
|
92
|
+
/** Returns the current asset list snapshot. */
|
|
93
|
+
list(): SSRAsset[];
|
|
94
|
+
/** Renders all assets to a series of `<link>` tags. */
|
|
95
|
+
render(options?: {
|
|
96
|
+
nonce?: string;
|
|
97
|
+
}): string;
|
|
98
|
+
/** Resets the manifest. */
|
|
99
|
+
reset(): void;
|
|
100
|
+
}
|
|
101
|
+
export declare const createAssetManager: () => AssetManager;
|
|
102
|
+
//# sourceMappingURL=head.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1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ACzE,yDAAyD;IACzD,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IACxE,+CAA+C;IAC/C,IAAI,IAAI,QAAQ,EAAE,CAAC;IACnB,uDAAuD;IACvD,MAAM,CAAC,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC;IAC7C,2BAA2B;IAC3B,KAAK,IAAI,IAAI,CAAC;CACf;AAED,eAAO,MAAM,kBAAkB,QAAO,YA+BrC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal, runtime-agnostic HTML parser for the SSR renderer.
|
|
3
|
+
*
|
|
4
|
+
* This is intentionally a small, linear scanner rather than a full HTML5
|
|
5
|
+
* tokenizer. It is sufficient for templates authored against the `bQuery`
|
|
6
|
+
* directive vocabulary (HTML fragments, common void/raw elements, attributes)
|
|
7
|
+
* and lets the SSR pipeline run on Bun, Deno and Node without depending on a
|
|
8
|
+
* `DOMParser` polyfill.
|
|
9
|
+
*
|
|
10
|
+
* Output: a tiny virtual node tree (`SSRNode`) compatible with the pluggable
|
|
11
|
+
* DOM adapter API used by `renderer.ts`.
|
|
12
|
+
*
|
|
13
|
+
* @module bquery/ssr
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
/** A DOM-free node structure produced by `parseTemplate()`. */
|
|
17
|
+
export type SSRNode = SSRElement | SSRText | SSRComment | SSRDocumentFragment;
|
|
18
|
+
export interface SSRElement {
|
|
19
|
+
type: 'element';
|
|
20
|
+
tag: string;
|
|
21
|
+
attributes: Record<string, string>;
|
|
22
|
+
/** Order-preserving attribute list (so output is deterministic). */
|
|
23
|
+
attributeOrder: string[];
|
|
24
|
+
children: SSRNode[];
|
|
25
|
+
/** Whether this element should be serialised as a void element. */
|
|
26
|
+
void: boolean;
|
|
27
|
+
/** Whether the children are raw (e.g. `<script>` content). */
|
|
28
|
+
raw: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface SSRText {
|
|
31
|
+
type: 'text';
|
|
32
|
+
value: string;
|
|
33
|
+
}
|
|
34
|
+
export interface SSRComment {
|
|
35
|
+
type: 'comment';
|
|
36
|
+
value: string;
|
|
37
|
+
}
|
|
38
|
+
export interface SSRDocumentFragment {
|
|
39
|
+
type: 'fragment';
|
|
40
|
+
children: SSRNode[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Decodes the named/numeric HTML entities the SSR parser actually needs.
|
|
44
|
+
* Anything else is preserved verbatim.
|
|
45
|
+
*/
|
|
46
|
+
export declare const decodeEntities: (input: string) => string;
|
|
47
|
+
/**
|
|
48
|
+
* Parses an HTML template string into a virtual node tree without depending
|
|
49
|
+
* on a DOM implementation. The parser is intentionally permissive: it does
|
|
50
|
+
* not validate nesting, but it preserves attribute order and never throws on
|
|
51
|
+
* malformed input.
|
|
52
|
+
*/
|
|
53
|
+
export declare const parseTemplate: (template: string) => SSRDocumentFragment;
|
|
54
|
+
/** Serialises a virtual node tree to an HTML string. */
|
|
55
|
+
export declare const serializeTree: (node: SSRNode) => string;
|
|
56
|
+
/** Recursively clones a virtual node (used by `bq-for`). */
|
|
57
|
+
export declare const cloneNode: (node: SSRNode) => SSRNode;
|
|
58
|
+
//# sourceMappingURL=html-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-parser.d.ts","sourceRoot":"","sources":["../../src/ssr/html-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAqBH,+DAA+D;AAC/D,MAAM,MAAM,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,GAAG,mBAAmB,CAAC;AAE9E,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,oEAAoE;IACpE,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,mEAAmE;IACnE,IAAI,EAAE,OAAO,CAAC;IACd,8DAA8D;IAC9D,GAAG,EAAE,OAAO,CAAC;CACd;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAWD;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,MAkB9C,CAAC;AAwHF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,UAAU,MAAM,KAAG,mBAuGhD,CAAC;AAQF,wDAAwD;AACxD,eAAO,MAAM,aAAa,GAAI,MAAM,OAAO,KAAG,MA+B7C,CAAC;AAEF,4DAA4D;AAC5D,eAAO,MAAM,SAAS,GAAI,MAAM,OAAO,KAAG,OAiBzC,CAAC"}
|
package/dist/ssr/index.d.ts
CHANGED
|
@@ -1,52 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SSR / Pre-rendering module for bQuery.js.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* and hydrating the pre-rendered DOM on the client.
|
|
4
|
+
* Server-side rendering, hydration, store-state serialization and runtime
|
|
5
|
+
* adapters for bQuery applications. The module is **runtime-agnostic** and
|
|
6
|
+
* runs on Bun, Deno and Node.js ≥ 24 without any external dependency.
|
|
8
7
|
*
|
|
9
|
-
*
|
|
8
|
+
* The synchronous `renderToString()` keeps its previous behaviour for
|
|
9
|
+
* backward compatibility but now automatically falls back to a fully
|
|
10
|
+
* DOM-free renderer when no `DOMParser` is available — that is what makes
|
|
11
|
+
* the same code path work on every server runtime.
|
|
10
12
|
*
|
|
11
|
-
*
|
|
12
|
-
* template to an `SSRResult` containing an `html` string with directive evaluation.
|
|
13
|
-
* - **`hydrateMount(selector, context, { hydrate: true })`** — Reuse
|
|
14
|
-
* existing server-rendered DOM and attach reactive bindings.
|
|
15
|
-
* - **`serializeStoreState(options?)`** — Serialize store state into a
|
|
16
|
-
* `<script>` tag for client-side pickup.
|
|
17
|
-
* - **`deserializeStoreState()`** — Read serialized state on the client.
|
|
18
|
-
* - **`hydrateStore(id, state)` / `hydrateStores(stateMap)`** — Apply
|
|
19
|
-
* server state to client stores.
|
|
13
|
+
* ## Highlights
|
|
20
14
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* ### Client
|
|
38
|
-
* ```ts
|
|
39
|
-
* import { hydrateMount, deserializeStoreState, hydrateStores } from '@bquery/bquery/ssr';
|
|
40
|
-
* import { signal } from '@bquery/bquery/reactive';
|
|
41
|
-
*
|
|
42
|
-
* // Restore store state from SSR
|
|
43
|
-
* const ssrState = deserializeStoreState();
|
|
44
|
-
* hydrateStores(ssrState);
|
|
45
|
-
*
|
|
46
|
-
* // Hydrate the DOM with reactive bindings
|
|
47
|
-
* const title = signal('Welcome');
|
|
48
|
-
* hydrateMount('#app', { title }, { hydrate: true });
|
|
49
|
-
* ```
|
|
15
|
+
* - **`renderToString(template, data)`** — synchronous render to HTML.
|
|
16
|
+
* - **`renderToStringAsync(template, data, ctx?)`** — awaits Promises and
|
|
17
|
+
* `defer()` values in the binding context.
|
|
18
|
+
* - **`renderToStream(template, data, ctx?)`** — Web `ReadableStream<Uint8Array>`.
|
|
19
|
+
* - **`renderToResponse(template, data, ctx?)`** — high-level `Response`
|
|
20
|
+
* wrapper with ETag, Cache-Control, head & store-state injection.
|
|
21
|
+
* - **`createSSRContext(...)`** — request/response context bag.
|
|
22
|
+
* - **`createHeadManager()`** — `<title>`, `<meta>`, `<link>` and
|
|
23
|
+
* `<script>` collection.
|
|
24
|
+
* - **`hydrateMount` / `hydrateOnVisible` / `hydrateOnIdle` /
|
|
25
|
+
* `hydrateOnInteraction` / `hydrateOnMedia` / `hydrateIsland`** — full
|
|
26
|
+
* progressive-hydration toolkit.
|
|
27
|
+
* - **Runtime adapters** — `createWebHandler`, `createBunHandler`,
|
|
28
|
+
* `createDenoHandler`, `createNodeHandler`, `createSSRHandler`.
|
|
50
29
|
*
|
|
51
30
|
* @module bquery/ssr
|
|
52
31
|
*/
|
|
@@ -56,4 +35,31 @@ export { renderToString } from './render';
|
|
|
56
35
|
export { deserializeStoreState, hydrateStore, hydrateStores, serializeStoreState, } from './serialize';
|
|
57
36
|
export type { SerializeResult } from './serialize';
|
|
58
37
|
export type { DeserializedStoreState, HydrationOptions, RenderOptions, SSRResult, SerializeOptions, } from './types';
|
|
38
|
+
export { detectRuntime, getSSRRuntimeFeatures, isBrowserRuntime, isServerRuntime } from './runtime';
|
|
39
|
+
export type { SSRRuntime, SSRRuntimeFeatures } from './runtime';
|
|
40
|
+
export { configureSSR, getSSRConfig } from './config';
|
|
41
|
+
export type { SSRDocumentImpl, SSRRendererBackend } from './config';
|
|
42
|
+
export { renderToResponse, renderToStream, renderToStringAsync } from './render-async';
|
|
43
|
+
export type { AsyncRenderOptions, AsyncSSRResult, RenderToResponseOptions } from './render-async';
|
|
44
|
+
export { createSSRContext } from './context';
|
|
45
|
+
export type { CreateSSRContextOptions, SSRContext } from './context';
|
|
46
|
+
export { createAssetManager, createHeadManager } from './head';
|
|
47
|
+
export type { AssetManager, HeadManager, SSRAsset, SSRHeadState, SSRLink, SSRMeta, SSRScript, UseHeadOptions, } from './head';
|
|
48
|
+
export { defer, defineLoader } from './async';
|
|
49
|
+
export type { SSRLoader } from './async';
|
|
50
|
+
export { hydrateIsland, hydrateOnIdle, hydrateOnInteraction, hydrateOnMedia, hydrateOnVisible, } from './strategies';
|
|
51
|
+
export type { HydrationHandle } from './strategies';
|
|
52
|
+
export { verifyHydration } from './mismatch';
|
|
53
|
+
export type { HydrationMismatch, VerifyHydrationOptions } from './mismatch';
|
|
54
|
+
export { HYDRATION_HASH_ATTR } from './hash';
|
|
55
|
+
export { renderToStreamSuspense } from './suspense';
|
|
56
|
+
export type { SuspenseStreamOptions } from './suspense';
|
|
57
|
+
export { createSSRRouterContext, resolveSSRRoute, runRouteLoaders } from './router-bridge';
|
|
58
|
+
export type { ResolvedSSRRoute, SSRRouteLoader } from './router-bridge';
|
|
59
|
+
export { hydrateStoreSnapshot, readStoreSnapshot, serializeStoreSnapshot } from './store-snapshot';
|
|
60
|
+
export type { HydrateSnapshotOptions, HydrateSnapshotResult, SerializeSnapshotOptions, SerializeSnapshotResult, SSRStoreSnapshot, } from './store-snapshot';
|
|
61
|
+
export { createResumableState, resumeState } from './resumability';
|
|
62
|
+
export type { CreateResumableStateOptions, ResumableState, ResumeReader } from './resumability';
|
|
63
|
+
export { createBunHandler, createDenoHandler, createNodeHandler, createSSRHandler, createWebHandler, } from './adapters';
|
|
64
|
+
export type { NodeHandlerOptions, NodeIncomingMessage, NodeServerResponse, SSRRequestHandler, } from './adapters';
|
|
59
65
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/ssr/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ssr/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ssr/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;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OM-free SSR renderer can annotate every element that carries a `bq-*`
|
|
5
|
+
* directive with a small `data-bq-h` hash (see `RenderOptions.annotateHydration`).
|
|
6
|
+
* On the client, `verifyHydration()` walks the live DOM, recomputes the same
|
|
7
|
+
* hash for each annotated element and reports any divergence.
|
|
8
|
+
*
|
|
9
|
+
* The check is intentionally cheap and safe: collisions only result in false
|
|
10
|
+
* negatives (a mismatch slips through), never in false positives (a stable
|
|
11
|
+
* tree never reports a mismatch).
|
|
12
|
+
*
|
|
13
|
+
* @module bquery/ssr
|
|
14
|
+
*/
|
|
15
|
+
/** A single hydration mismatch entry returned by `verifyHydration()`. */
|
|
16
|
+
export interface HydrationMismatch {
|
|
17
|
+
/** The DOM element whose annotation diverged. */
|
|
18
|
+
element: Element;
|
|
19
|
+
/** The hash that the server emitted (`data-bq-h` value). */
|
|
20
|
+
expected: string;
|
|
21
|
+
/** The hash recomputed from the live element. */
|
|
22
|
+
actual: string;
|
|
23
|
+
/** The directive signature that was hashed (useful for diagnostics). */
|
|
24
|
+
signature: string;
|
|
25
|
+
}
|
|
26
|
+
/** Options for `verifyHydration`. */
|
|
27
|
+
export interface VerifyHydrationOptions {
|
|
28
|
+
/** Directive prefix to match. Default: `'bq'`. */
|
|
29
|
+
prefix?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Whether to log a `console.warn` for each mismatch. Defaults to `true` in
|
|
32
|
+
* non-production environments and `false` otherwise. Pass an explicit
|
|
33
|
+
* boolean to override.
|
|
34
|
+
*/
|
|
35
|
+
warn?: boolean;
|
|
36
|
+
/** Optional callback invoked once per mismatch. */
|
|
37
|
+
onMismatch?: (mismatch: HydrationMismatch) => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Walks `[data-bq-h]` elements within `root`, recomputes the directive hash
|
|
41
|
+
* and reports mismatches. Returns the list of mismatches; callers can react
|
|
42
|
+
* however they want (throw in tests, log in dev, ignore in production).
|
|
43
|
+
*
|
|
44
|
+
* Safe to call in any environment. When the runtime has no DOM (server-side)
|
|
45
|
+
* or `root` has no `querySelectorAll`, the function returns an empty array
|
|
46
|
+
* without throwing.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { detectDevEnvironment } from '@bquery/bquery';
|
|
51
|
+
* import { hydrateMount, verifyHydration } from '@bquery/bquery/ssr';
|
|
52
|
+
*
|
|
53
|
+
* const view = hydrateMount('#app', context);
|
|
54
|
+
* if (detectDevEnvironment()) {
|
|
55
|
+
* verifyHydration(document.getElementById('app')!);
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare const verifyHydration: (root: Element | Document, options?: VerifyHydrationOptions) => HydrationMismatch[];
|
|
60
|
+
//# sourceMappingURL=mismatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mismatch.d.ts","sourceRoot":"","sources":["../../src/ssr/mismatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,yEAAyE;AACzE,MAAM,WAAW,iBAAiB;IAChC,iDAAiD;IACjD,OAAO,EAAE,OAAO,CAAC;IACjB,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qCAAqC;AACrC,MAAM,WAAW,sBAAsB;IACrC,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,mDAAmD;IACnD,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,iBAAiB,KAAK,IAAI,CAAC;CACpD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,eAAe,GAC1B,MAAM,OAAO,GAAG,QAAQ,EACxB,UAAS,sBAA2B,KACnC,iBAAiB,EA0CnB,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Async / streaming render entry points.
|
|
3
|
+
*
|
|
4
|
+
* Builds on top of the synchronous `renderToString()` and adds:
|
|
5
|
+
* - `renderToStringAsync()` — awaits Promise/`defer()` values in the context.
|
|
6
|
+
* - `renderToStream()` — emits the HTML as a Web `ReadableStream<Uint8Array>`.
|
|
7
|
+
* - `renderToResponse()` — wraps the stream in a `Response` with sensible
|
|
8
|
+
* defaults (`Content-Type`, `Cache-Control`, ETag, head injection, store
|
|
9
|
+
* state injection).
|
|
10
|
+
*
|
|
11
|
+
* All three run on Bun, Deno and Node ≥ 24 without external dependencies.
|
|
12
|
+
*
|
|
13
|
+
* @module bquery/ssr
|
|
14
|
+
*/
|
|
15
|
+
import type { BindingContext } from '../view/types';
|
|
16
|
+
import { type SSRContext } from './context';
|
|
17
|
+
import type { RenderOptions, SSRResult } from './types';
|
|
18
|
+
/**
|
|
19
|
+
* Options accepted by the async render APIs. Extends the base `RenderOptions`
|
|
20
|
+
* with response-shaping switches.
|
|
21
|
+
*/
|
|
22
|
+
export interface AsyncRenderOptions extends RenderOptions {
|
|
23
|
+
/** Pre-built SSR context. Created automatically if omitted. */
|
|
24
|
+
context?: SSRContext;
|
|
25
|
+
/**
|
|
26
|
+
* Whether to inject the head manager output, asset manifest and store-state
|
|
27
|
+
* `<script>` tag into the output HTML when the template contains
|
|
28
|
+
* `</head>`/`</body>` markers. Default: `true`.
|
|
29
|
+
*/
|
|
30
|
+
injectHead?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Custom store-state script ID/global key forwarded to `serializeStoreState()`.
|
|
33
|
+
*/
|
|
34
|
+
storeScriptId?: string;
|
|
35
|
+
storeGlobalKey?: string;
|
|
36
|
+
}
|
|
37
|
+
/** Result of an async render call. */
|
|
38
|
+
export interface AsyncSSRResult extends SSRResult {
|
|
39
|
+
/** SSR context that produced this result. */
|
|
40
|
+
context: SSRContext;
|
|
41
|
+
/** Aggregated head HTML (already injected when `injectHead` is true). */
|
|
42
|
+
headHtml: string;
|
|
43
|
+
/** Aggregated asset preload HTML (already injected when `injectHead` is true). */
|
|
44
|
+
assetsHtml: string;
|
|
45
|
+
/** `<script>` tag with serialized store state, if any. */
|
|
46
|
+
storeScriptTag: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Async-aware render. Resolves all `Promise`/`defer()` values in the context,
|
|
50
|
+
* then delegates to `renderToString()` and applies head/asset/store-state
|
|
51
|
+
* injection based on the SSR context.
|
|
52
|
+
*/
|
|
53
|
+
export declare const renderToStringAsync: (template: string, data: BindingContext, options?: AsyncRenderOptions) => Promise<AsyncSSRResult>;
|
|
54
|
+
/**
|
|
55
|
+
* Renders a template into a Web `ReadableStream<Uint8Array>`. The stream is
|
|
56
|
+
* single-chunk for now (the HTML is fully resolved before flushing) but is
|
|
57
|
+
* exposed as a stream so adapters can pipe it directly into Bun/Deno/Node
|
|
58
|
+
* responses without buffering into memory twice.
|
|
59
|
+
*
|
|
60
|
+
* Future Suspense-style streaming patches will reuse the same return type.
|
|
61
|
+
*/
|
|
62
|
+
export declare const renderToStream: (template: string, data: BindingContext, options?: AsyncRenderOptions) => ReadableStream<Uint8Array>;
|
|
63
|
+
/** Options for `renderToResponse()`. */
|
|
64
|
+
export interface RenderToResponseOptions extends AsyncRenderOptions {
|
|
65
|
+
/** Override the response status code. */
|
|
66
|
+
status?: number;
|
|
67
|
+
/** Override the `Content-Type` header. Default: `text/html; charset=utf-8`. */
|
|
68
|
+
contentType?: string;
|
|
69
|
+
/** Set a `Cache-Control` header value. */
|
|
70
|
+
cacheControl?: string;
|
|
71
|
+
/** Whether to compute a weak ETag from the rendered HTML. Default: `false`. */
|
|
72
|
+
etag?: boolean;
|
|
73
|
+
/** Extra headers merged into the response. */
|
|
74
|
+
headers?: HeadersInit;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Renders a template and returns a `Response` ready to be returned from a
|
|
78
|
+
* `fetch`-style handler (`Bun.serve`, `Deno.serve`, Hono, Elysia, etc.).
|
|
79
|
+
*
|
|
80
|
+
* Honours `SSRContext.signal` for cancellation and `SSRContext.responseHeaders`
|
|
81
|
+
* for headers added during the render path.
|
|
82
|
+
*/
|
|
83
|
+
export declare const renderToResponse: (template: string, data: BindingContext, options?: RenderToResponseOptions) => Promise<Response>;
|
|
84
|
+
//# sourceMappingURL=render-async.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-async.d.ts","sourceRoot":"","sources":["../../src/ssr/render-async.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAG9D,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AA2BxD;;;GAGG;AACH,MAAM,WAAW,kBAAmB,SAAQ,aAAa;IACvD,+DAA+D;IAC/D,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,sCAAsC;AACtC,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C,6CAA6C;IAC7C,OAAO,EAAE,UAAU,CAAC;IACpB,yEAAyE;IACzE,QAAQ,EAAE,MAAM,CAAC;IACjB,kFAAkF;IAClF,UAAU,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,cAAc,EAAE,MAAM,CAAC;CACxB;AAgBD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAC9B,UAAU,MAAM,EAChB,MAAM,cAAc,EACpB,UAAS,kBAAuB,KAC/B,OAAO,CAAC,cAAc,CAwDxB,CAAC;AASF;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GACzB,UAAU,MAAM,EAChB,MAAM,cAAc,EACpB,UAAS,kBAAuB,KAC/B,cAAc,CAAC,UAAU,CAwC3B,CAAC;AAgBF,wCAAwC;AACxC,MAAM,WAAW,uBAAwB,SAAQ,kBAAkB;IACjE,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0CAA0C;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+EAA+E;IAC/E,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,8CAA8C;IAC9C,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAC3B,UAAU,MAAM,EAChB,MAAM,cAAc,EACpB,UAAS,uBAA4B,KACpC,OAAO,CAAC,QAAQ,CAyBlB,CAAC"}
|
package/dist/ssr/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/ssr/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/ssr/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAIpD,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAobxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,eAAO,MAAM,cAAc,GACzB,UAAU,MAAM,EAChB,MAAM,cAAc,EACpB,UAAS,aAAkB,KAC1B,SAyEF,CAAC"}
|