mates-fullstack 1.0.0-beta.1
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 +311 -0
- package/dist/arctic-auth.d.ts +101 -0
- package/dist/arctic-auth.d.ts.map +1 -0
- package/dist/arctic-auth.js +538 -0
- package/dist/arctic-auth.js.map +1 -0
- package/dist/asset-manifest.d.ts +14 -0
- package/dist/asset-manifest.d.ts.map +1 -0
- package/dist/asset-manifest.js +102 -0
- package/dist/asset-manifest.js.map +1 -0
- package/dist/browser.d.ts +18 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +25 -0
- package/dist/browser.js.map +1 -0
- package/dist/build-esbuild.d.ts +29 -0
- package/dist/build-esbuild.d.ts.map +1 -0
- package/dist/build-esbuild.js +699 -0
- package/dist/build-esbuild.js.map +1 -0
- package/dist/build-prod.d.ts +126 -0
- package/dist/build-prod.d.ts.map +1 -0
- package/dist/build-prod.js +1014 -0
- package/dist/build-prod.js.map +1 -0
- package/dist/cli-new.d.ts +14 -0
- package/dist/cli-new.d.ts.map +1 -0
- package/dist/cli-new.js +637 -0
- package/dist/cli-new.js.map +1 -0
- package/dist/client.d.ts +43 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +130 -0
- package/dist/client.js.map +1 -0
- package/dist/cors.d.ts +16 -0
- package/dist/cors.d.ts.map +1 -0
- package/dist/cors.js +60 -0
- package/dist/cors.js.map +1 -0
- package/dist/ctx.d.ts +78 -0
- package/dist/ctx.d.ts.map +1 -0
- package/dist/ctx.js +280 -0
- package/dist/ctx.js.map +1 -0
- package/dist/dev-watcher.d.ts +23 -0
- package/dist/dev-watcher.d.ts.map +1 -0
- package/dist/dev-watcher.js +136 -0
- package/dist/dev-watcher.js.map +1 -0
- package/dist/docs-generator.d.ts +69 -0
- package/dist/docs-generator.d.ts.map +1 -0
- package/dist/docs-generator.js +557 -0
- package/dist/docs-generator.js.map +1 -0
- package/dist/docs-page.d.ts +20 -0
- package/dist/docs-page.d.ts.map +1 -0
- package/dist/docs-page.js +1152 -0
- package/dist/docs-page.js.map +1 -0
- package/dist/download.d.ts +78 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +202 -0
- package/dist/download.js.map +1 -0
- package/dist/env-loader.d.ts +76 -0
- package/dist/env-loader.d.ts.map +1 -0
- package/dist/env-loader.js +213 -0
- package/dist/env-loader.js.map +1 -0
- package/dist/errors.d.ts +146 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +386 -0
- package/dist/errors.js.map +1 -0
- package/dist/head.d.ts +31 -0
- package/dist/head.d.ts.map +1 -0
- package/dist/head.js +245 -0
- package/dist/head.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/internal-prefixes.d.ts +16 -0
- package/dist/internal-prefixes.d.ts.map +1 -0
- package/dist/internal-prefixes.js +16 -0
- package/dist/internal-prefixes.js.map +1 -0
- package/dist/internal.d.ts +25 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +25 -0
- package/dist/internal.js.map +1 -0
- package/dist/jwt.d.ts +166 -0
- package/dist/jwt.d.ts.map +1 -0
- package/dist/jwt.js +261 -0
- package/dist/jwt.js.map +1 -0
- package/dist/log.d.ts +44 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +66 -0
- package/dist/log.js.map +1 -0
- package/dist/logger.d.ts +76 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +138 -0
- package/dist/logger.js.map +1 -0
- package/dist/main-runner.d.ts +59 -0
- package/dist/main-runner.d.ts.map +1 -0
- package/dist/main-runner.js +157 -0
- package/dist/main-runner.js.map +1 -0
- package/dist/mates-auth.d.ts +82 -0
- package/dist/mates-auth.d.ts.map +1 -0
- package/dist/mates-auth.js +323 -0
- package/dist/mates-auth.js.map +1 -0
- package/dist/middleware.d.ts +30 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +67 -0
- package/dist/middleware.js.map +1 -0
- package/dist/project-resolver.d.ts +102 -0
- package/dist/project-resolver.d.ts.map +1 -0
- package/dist/project-resolver.js +271 -0
- package/dist/project-resolver.js.map +1 -0
- package/dist/rate-limit.d.ts +37 -0
- package/dist/rate-limit.d.ts.map +1 -0
- package/dist/rate-limit.js +109 -0
- package/dist/rate-limit.js.map +1 -0
- package/dist/redirect.d.ts +84 -0
- package/dist/redirect.d.ts.map +1 -0
- package/dist/redirect.js +105 -0
- package/dist/redirect.js.map +1 -0
- package/dist/renderer.d.ts +91 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +630 -0
- package/dist/renderer.js.map +1 -0
- package/dist/request-logger.d.ts +12 -0
- package/dist/request-logger.d.ts.map +1 -0
- package/dist/request-logger.js +55 -0
- package/dist/request-logger.js.map +1 -0
- package/dist/rest.d.ts +25 -0
- package/dist/rest.d.ts.map +1 -0
- package/dist/rest.js +93 -0
- package/dist/rest.js.map +1 -0
- package/dist/router.d.ts +71 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +222 -0
- package/dist/router.js.map +1 -0
- package/dist/rpc-registry.d.ts +84 -0
- package/dist/rpc-registry.d.ts.map +1 -0
- package/dist/rpc-registry.js +271 -0
- package/dist/rpc-registry.js.map +1 -0
- package/dist/rpc-runner.d.ts +82 -0
- package/dist/rpc-runner.d.ts.map +1 -0
- package/dist/rpc-runner.js +564 -0
- package/dist/rpc-runner.js.map +1 -0
- package/dist/sanitize.d.ts +61 -0
- package/dist/sanitize.d.ts.map +1 -0
- package/dist/sanitize.js +193 -0
- package/dist/sanitize.js.map +1 -0
- package/dist/security-headers.d.ts +114 -0
- package/dist/security-headers.d.ts.map +1 -0
- package/dist/security-headers.js +121 -0
- package/dist/security-headers.js.map +1 -0
- package/dist/server-fn.d.ts +323 -0
- package/dist/server-fn.d.ts.map +1 -0
- package/dist/server-fn.js +373 -0
- package/dist/server-fn.js.map +1 -0
- package/dist/server-public.d.ts +13 -0
- package/dist/server-public.d.ts.map +1 -0
- package/dist/server-public.js +12 -0
- package/dist/server-public.js.map +1 -0
- package/dist/server-timeout.d.ts +38 -0
- package/dist/server-timeout.d.ts.map +1 -0
- package/dist/server-timeout.js +46 -0
- package/dist/server-timeout.js.map +1 -0
- package/dist/server.d.ts +100 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +1218 -0
- package/dist/server.js.map +1 -0
- package/dist/socket-router.d.ts +153 -0
- package/dist/socket-router.d.ts.map +1 -0
- package/dist/socket-router.js +612 -0
- package/dist/socket-router.js.map +1 -0
- package/dist/sso.d.ts +90 -0
- package/dist/sso.d.ts.map +1 -0
- package/dist/sso.js +261 -0
- package/dist/sso.js.map +1 -0
- package/dist/ssr-context.d.ts +49 -0
- package/dist/ssr-context.d.ts.map +1 -0
- package/dist/ssr-context.js +85 -0
- package/dist/ssr-context.js.map +1 -0
- package/dist/ssr-globals.d.ts +32 -0
- package/dist/ssr-globals.d.ts.map +1 -0
- package/dist/ssr-globals.js +1010 -0
- package/dist/ssr-globals.js.map +1 -0
- package/dist/ssr-template.d.ts +73 -0
- package/dist/ssr-template.d.ts.map +1 -0
- package/dist/ssr-template.js +507 -0
- package/dist/ssr-template.js.map +1 -0
- package/dist/stack-mapper.d.ts +25 -0
- package/dist/stack-mapper.d.ts.map +1 -0
- package/dist/stack-mapper.js +139 -0
- package/dist/stack-mapper.js.map +1 -0
- package/dist/stream.d.ts +89 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +299 -0
- package/dist/stream.js.map +1 -0
- package/dist/upload.d.ts +69 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +110 -0
- package/dist/upload.js.map +1 -0
- package/dist/validate.d.ts +58 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +89 -0
- package/dist/validate.js.map +1 -0
- package/dist/verify-package.d.ts +3 -0
- package/dist/verify-package.d.ts.map +1 -0
- package/dist/verify-package.js +128 -0
- package/dist/verify-package.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mates-fullstack — redirect.ts
|
|
3
|
+
*
|
|
4
|
+
* The redirect() helper for server functions and loaders.
|
|
5
|
+
*
|
|
6
|
+
* Throwing redirect() from a server function:
|
|
7
|
+
* - During RPC call → client calls navigateTo(url) or window.location.href
|
|
8
|
+
* - During SSR loader → server sends HTTP 302 before page renders
|
|
9
|
+
*
|
|
10
|
+
* Internal vs external detection happens on the client:
|
|
11
|
+
* - Starts with http:// or https:// or // → window.location.href (full nav)
|
|
12
|
+
* - Otherwise → navigateTo(url) (SPA navigation, no page reload)
|
|
13
|
+
*
|
|
14
|
+
* Wire format:
|
|
15
|
+
* { __type: "Redirect", url: "/dashboard", status: 302 }
|
|
16
|
+
* HTTP response status: 302 (or whatever status was passed)
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Thrown by redirect() to signal a navigation.
|
|
20
|
+
* Not a real Error — don't extend Error to keep the class hierarchy clean.
|
|
21
|
+
*/
|
|
22
|
+
export declare class Redirect {
|
|
23
|
+
readonly __type: "Redirect";
|
|
24
|
+
readonly url: string;
|
|
25
|
+
readonly status: 301 | 302 | 307 | 308;
|
|
26
|
+
constructor(url: string, status?: 301 | 302 | 307 | 308);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Throw this from any server function or loader to redirect the user.
|
|
30
|
+
*
|
|
31
|
+
* During a RPC call from the client:
|
|
32
|
+
* - Internal URL (/dashboard) → navigateTo("/dashboard") — SPA navigation
|
|
33
|
+
* - External URL (https://...) → window.location.href — full browser navigation
|
|
34
|
+
*
|
|
35
|
+
* During SSR (loader):
|
|
36
|
+
* - Sends HTTP 302 (or specified status) before the page renders
|
|
37
|
+
* - Browser follows the Location header
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* // Redirect after login
|
|
41
|
+
* export async function login(payload, ctx) {
|
|
42
|
+
* const user = await verify(payload);
|
|
43
|
+
* ctx.cookie.set("session", createToken(user), { httpOnly: true });
|
|
44
|
+
* throw redirect("/dashboard");
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* // Guard in SSR loader
|
|
48
|
+
* export async function loader(payload, ctx) {
|
|
49
|
+
* if (!ctx.auth) throw redirect("/login");
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* // Redirect to external URL (OAuth, Stripe, etc.)
|
|
53
|
+
* throw redirect("https://accounts.google.com/oauth/...");
|
|
54
|
+
*
|
|
55
|
+
* // Permanent redirect
|
|
56
|
+
* throw redirect("/new-path", 301);
|
|
57
|
+
*/
|
|
58
|
+
export declare function redirect(url: string, status?: 301 | 302 | 307 | 308): never;
|
|
59
|
+
/**
|
|
60
|
+
* Returns true if the value is a Redirect instance.
|
|
61
|
+
* Used by rpc-runner and renderer to catch redirect throws.
|
|
62
|
+
*/
|
|
63
|
+
export declare function isRedirect(value: unknown): value is Redirect;
|
|
64
|
+
export interface SerializedRedirect {
|
|
65
|
+
__type: "Redirect";
|
|
66
|
+
url: string;
|
|
67
|
+
status: 301 | 302 | 307 | 308;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Serialize a Redirect for the wire.
|
|
71
|
+
*/
|
|
72
|
+
export declare function serializeRedirect(r: Redirect): SerializedRedirect;
|
|
73
|
+
/**
|
|
74
|
+
* Returns true if the serialized object is a redirect response.
|
|
75
|
+
* Used by the Fetch client to detect redirect responses.
|
|
76
|
+
*/
|
|
77
|
+
export declare function isMatesRedirect(data: unknown): data is SerializedRedirect;
|
|
78
|
+
/**
|
|
79
|
+
* Returns true if the URL is external (starts with http://, https://, or //).
|
|
80
|
+
* External redirects use window.location.href on the client.
|
|
81
|
+
* Internal redirects use navigateTo() for SPA navigation.
|
|
82
|
+
*/
|
|
83
|
+
export declare function isExternalUrl(url: string): boolean;
|
|
84
|
+
//# sourceMappingURL=redirect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../src/redirect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH;;;GAGG;AACH,qBAAa,QAAQ;IACnB,QAAQ,CAAC,MAAM,aAAuB;IACtC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;gBAE3B,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAS;CAI7D;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,QAAQ,CACtB,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAS,GAClC,KAAK,CAEP;AAID;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAE5D;AAID,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,UAAU,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;CAC/B;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,QAAQ,GAAG,kBAAkB,CAMjE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,kBAAkB,CAOzE;AAID;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAMlD"}
|
package/dist/redirect.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mates-fullstack — redirect.ts
|
|
3
|
+
*
|
|
4
|
+
* The redirect() helper for server functions and loaders.
|
|
5
|
+
*
|
|
6
|
+
* Throwing redirect() from a server function:
|
|
7
|
+
* - During RPC call → client calls navigateTo(url) or window.location.href
|
|
8
|
+
* - During SSR loader → server sends HTTP 302 before page renders
|
|
9
|
+
*
|
|
10
|
+
* Internal vs external detection happens on the client:
|
|
11
|
+
* - Starts with http:// or https:// or // → window.location.href (full nav)
|
|
12
|
+
* - Otherwise → navigateTo(url) (SPA navigation, no page reload)
|
|
13
|
+
*
|
|
14
|
+
* Wire format:
|
|
15
|
+
* { __type: "Redirect", url: "/dashboard", status: 302 }
|
|
16
|
+
* HTTP response status: 302 (or whatever status was passed)
|
|
17
|
+
*/
|
|
18
|
+
// ─── Redirect class ───────────────────────────────────────────────────────────
|
|
19
|
+
/**
|
|
20
|
+
* Thrown by redirect() to signal a navigation.
|
|
21
|
+
* Not a real Error — don't extend Error to keep the class hierarchy clean.
|
|
22
|
+
*/
|
|
23
|
+
export class Redirect {
|
|
24
|
+
__type = "Redirect";
|
|
25
|
+
url;
|
|
26
|
+
status;
|
|
27
|
+
constructor(url, status = 302) {
|
|
28
|
+
this.url = url;
|
|
29
|
+
this.status = status;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// ─── redirect() helper ────────────────────────────────────────────────────────
|
|
33
|
+
/**
|
|
34
|
+
* Throw this from any server function or loader to redirect the user.
|
|
35
|
+
*
|
|
36
|
+
* During a RPC call from the client:
|
|
37
|
+
* - Internal URL (/dashboard) → navigateTo("/dashboard") — SPA navigation
|
|
38
|
+
* - External URL (https://...) → window.location.href — full browser navigation
|
|
39
|
+
*
|
|
40
|
+
* During SSR (loader):
|
|
41
|
+
* - Sends HTTP 302 (or specified status) before the page renders
|
|
42
|
+
* - Browser follows the Location header
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* // Redirect after login
|
|
46
|
+
* export async function login(payload, ctx) {
|
|
47
|
+
* const user = await verify(payload);
|
|
48
|
+
* ctx.cookie.set("session", createToken(user), { httpOnly: true });
|
|
49
|
+
* throw redirect("/dashboard");
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* // Guard in SSR loader
|
|
53
|
+
* export async function loader(payload, ctx) {
|
|
54
|
+
* if (!ctx.auth) throw redirect("/login");
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* // Redirect to external URL (OAuth, Stripe, etc.)
|
|
58
|
+
* throw redirect("https://accounts.google.com/oauth/...");
|
|
59
|
+
*
|
|
60
|
+
* // Permanent redirect
|
|
61
|
+
* throw redirect("/new-path", 301);
|
|
62
|
+
*/
|
|
63
|
+
export function redirect(url, status = 302) {
|
|
64
|
+
throw new Redirect(url, status);
|
|
65
|
+
}
|
|
66
|
+
// ─── Type guard ───────────────────────────────────────────────────────────────
|
|
67
|
+
/**
|
|
68
|
+
* Returns true if the value is a Redirect instance.
|
|
69
|
+
* Used by rpc-runner and renderer to catch redirect throws.
|
|
70
|
+
*/
|
|
71
|
+
export function isRedirect(value) {
|
|
72
|
+
return value instanceof Redirect;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Serialize a Redirect for the wire.
|
|
76
|
+
*/
|
|
77
|
+
export function serializeRedirect(r) {
|
|
78
|
+
return {
|
|
79
|
+
__type: "Redirect",
|
|
80
|
+
url: r.url,
|
|
81
|
+
status: r.status,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Returns true if the serialized object is a redirect response.
|
|
86
|
+
* Used by the Fetch client to detect redirect responses.
|
|
87
|
+
*/
|
|
88
|
+
export function isMatesRedirect(data) {
|
|
89
|
+
return (typeof data === "object" &&
|
|
90
|
+
data !== null &&
|
|
91
|
+
data.__type === "Redirect" &&
|
|
92
|
+
typeof data.url === "string");
|
|
93
|
+
}
|
|
94
|
+
// ─── URL helpers ──────────────────────────────────────────────────────────────
|
|
95
|
+
/**
|
|
96
|
+
* Returns true if the URL is external (starts with http://, https://, or //).
|
|
97
|
+
* External redirects use window.location.href on the client.
|
|
98
|
+
* Internal redirects use navigateTo() for SPA navigation.
|
|
99
|
+
*/
|
|
100
|
+
export function isExternalUrl(url) {
|
|
101
|
+
return (url.startsWith("http://") ||
|
|
102
|
+
url.startsWith("https://") ||
|
|
103
|
+
url.startsWith("//"));
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=redirect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirect.js","sourceRoot":"","sources":["../src/redirect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,iFAAiF;AAEjF;;;GAGG;AACH,MAAM,OAAO,QAAQ;IACV,MAAM,GAAG,UAAmB,CAAC;IAC7B,GAAG,CAAS;IACZ,MAAM,CAAwB;IAEvC,YAAY,GAAW,EAAE,SAAgC,GAAG;QAC1D,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,iFAAiF;AAEjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,QAAQ,CACtB,GAAW,EACX,SAAgC,GAAG;IAEnC,MAAM,IAAI,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAClC,CAAC;AAED,iFAAiF;AAEjF;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,KAAK,YAAY,QAAQ,CAAC;AACnC,CAAC;AAUD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,CAAW;IAC3C,OAAO;QACL,MAAM,EAAE,UAAU;QAClB,GAAG,EAAE,CAAC,CAAC,GAAG;QACV,MAAM,EAAE,CAAC,CAAC,MAAM;KACjB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAa;IAC3C,OAAO,CACL,OAAO,IAAI,KAAK,QAAQ;QACxB,IAAI,KAAK,IAAI;QACZ,IAAY,CAAC,MAAM,KAAK,UAAU;QACnC,OAAQ,IAAY,CAAC,GAAG,KAAK,QAAQ,CACtC,CAAC;AACJ,CAAC;AAED,iFAAiF;AAEjF;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,OAAO,CACL,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC;QACzB,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC;QAC1B,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CACrB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mates-ssr — renderer.ts
|
|
3
|
+
*
|
|
4
|
+
* The SSR render pipeline. Takes a Mates Component function, runs it through
|
|
5
|
+
* the custom TemplateResult serializer (ssrTemplate), and returns clean HTML.
|
|
6
|
+
*
|
|
7
|
+
* No happy-dom. No DOM. No per-request global patching. Fully concurrent.
|
|
8
|
+
*
|
|
9
|
+
* Design decisions:
|
|
10
|
+
* - SSR globals (installSsrGlobals) are installed ONCE at boot — no per-request
|
|
11
|
+
* Window creation, no global swapping.
|
|
12
|
+
* - Requests are fully concurrent — no render queue. ssrTemplate is a pure
|
|
13
|
+
* function that walks TemplateResult data structures directly.
|
|
14
|
+
* - Async work (onMount, asyncAction) is tracked via the global SSR async
|
|
15
|
+
* counter and per-host queues. The render loop drains and re-serializes.
|
|
16
|
+
* - CSS-in-JS styles are collected after render via collectSSRStyles().
|
|
17
|
+
* - pathAtom is set before each render via explicit .set() call.
|
|
18
|
+
* - Components run inside withHost(fakeHost, ...) on the server. No custom
|
|
19
|
+
* element is created — hooks get a fake host object that satisfies their
|
|
20
|
+
* getCurrentHost() calls.
|
|
21
|
+
*/
|
|
22
|
+
/** A standard Mates Component function: (propsFn) => () => TemplateResult */
|
|
23
|
+
export type ComponentFn = (propsFn: () => Record<string, any>) => () => any;
|
|
24
|
+
export declare const DEFAULT_SSR_TIMEOUT_MS = 10000;
|
|
25
|
+
export interface RenderOptions {
|
|
26
|
+
/** URL pathname for this request, e.g. "/users". */
|
|
27
|
+
pathname: string;
|
|
28
|
+
/** Props to pass to the root component. */
|
|
29
|
+
props?: Record<string, any>;
|
|
30
|
+
/** Optional layout component to wrap the app. */
|
|
31
|
+
layout?: ComponentFn | null;
|
|
32
|
+
/** Maximum time to wait for SSR async work before failing. */
|
|
33
|
+
ssrTimeoutMs?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface RenderResult {
|
|
36
|
+
/** Clean HTML string — ready to inject into the page shell. */
|
|
37
|
+
html: string;
|
|
38
|
+
/** SSR styles collected from stylesheet() / globalCSS() calls. */
|
|
39
|
+
styles: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Render the app from a file path.
|
|
43
|
+
* Imports client/App.ts (or .js), renders it with pathAtom set to pathname.
|
|
44
|
+
* This is the main SSR entry point — called once per incoming GET request.
|
|
45
|
+
*
|
|
46
|
+
* The app's Router() reads pathAtom and renders the correct page.
|
|
47
|
+
* No file-based routing on the server — the SPA router IS the server router.
|
|
48
|
+
*/
|
|
49
|
+
export declare function renderApp(appFile: string, pathname: string, dev: boolean, ssrTimeoutMs?: number): Promise<RenderResult & {
|
|
50
|
+
notFound?: boolean;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Must be called once at server startup, before any route handler runs.
|
|
54
|
+
* Initialises the boot window and imports lit-html + mates into module cache.
|
|
55
|
+
*
|
|
56
|
+
* @param matesPath Absolute path to the mates ESM dist file, e.g.
|
|
57
|
+
* "/project/node_modules/mates/dist/index.esm.js"
|
|
58
|
+
* When provided, mates is imported from this exact path so that the module
|
|
59
|
+
* instance (and its internal host stack) is shared with the page files.
|
|
60
|
+
* When omitted, we attempt a bare `import("mates")` which may resolve to a
|
|
61
|
+
* different instance — withHost/getCurrentHost will not share state with
|
|
62
|
+
* page files in that case and hooks will not work on the server.
|
|
63
|
+
*/
|
|
64
|
+
export declare function bootRenderer(matesPath?: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the CSS string collected from all stylesheet() and globalCSS()
|
|
67
|
+
* Tear down the boot window. Call this when the server is shutting down.
|
|
68
|
+
*/
|
|
69
|
+
export declare function shutdownRenderer(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Returns the CSS string collected from all stylesheet() and globalCSS()
|
|
72
|
+
* instances after bootRenderer() completed. Inject this into the HTML <head>
|
|
73
|
+
* as `<style id="mates-ssr-styles">` to prevent FOUC on first paint.
|
|
74
|
+
*/
|
|
75
|
+
export declare function getSSRStyles(): string;
|
|
76
|
+
/**
|
|
77
|
+
* Render a Mates Component to an HTML string.
|
|
78
|
+
*
|
|
79
|
+
* Enqueues the render so that globals are never mutated concurrently.
|
|
80
|
+
* Resolves with a clean HTML string (lit-html comment markers stripped).
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* const { html } = await renderToString(MyPage, { pathname: '/about', props: {} });
|
|
84
|
+
*/
|
|
85
|
+
export declare function renderToString(component: ComponentFn, options: RenderOptions): Promise<RenderResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Register a callback to be called on every render completion.
|
|
88
|
+
* Used by devtools / HMR.
|
|
89
|
+
*/
|
|
90
|
+
export declare function onRenderComplete(cb: () => void): void;
|
|
91
|
+
//# sourceMappingURL=renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAYH,6EAA6E;AAC7E,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,GAAG,CAAC;AAE5E,eAAO,MAAM,sBAAsB,QAAS,CAAC;AAE7C,MAAM,WAAW,aAAa;IAC5B,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,iDAAiD;IACjD,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAC7B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,OAAO,EACZ,YAAY,SAAyB,GACpC,OAAO,CAAC,YAAY,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CAQhD;AAcD;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA+DpE;AAgCD;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAKvC;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAID;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAClC,SAAS,EAAE,WAAW,EACtB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CASvB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAErD"}
|