@k8ordo/framework 1.4.3 → 2.0.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 +1 -1
- package/dist/generated.d.mts +23 -2
- package/dist/runtime/app-router.d.mts +10 -10
- package/dist/runtime/app-router.mjs +119 -83
- package/dist/runtime/browser-payloads.mjs +2 -1
- package/dist/runtime/client-files.d.mts +11 -0
- package/dist/runtime/client-files.mjs +42 -0
- package/dist/runtime/client-ready.d.mts +3 -2
- package/dist/runtime/document-root.mjs +1 -1
- package/dist/runtime/entry.browser.d.mts +1 -1
- package/dist/runtime/entry.browser.mjs +8 -12
- package/dist/runtime/entry.rsc.mjs +148 -102
- package/dist/runtime/entry.ssr.d.mts +21 -1
- package/dist/runtime/entry.ssr.mjs +10 -13
- package/dist/runtime/head-scripts.d.mts +18 -0
- package/dist/runtime/head-scripts.mjs +159 -0
- package/dist/runtime/hydrating-pathname.d.mts +16 -0
- package/dist/runtime/hydrating-pathname.mjs +26 -0
- package/dist/runtime/mount.d.mts +16 -11
- package/dist/runtime/mount.mjs +29 -18
- package/dist/runtime/payload.d.mts +22 -23
- package/dist/runtime/payload.mjs +11 -16
- package/dist/runtime/prefetch.d.mts +60 -25
- package/dist/runtime/prefetch.mjs +166 -38
- package/dist/runtime/recover.d.mts +2 -0
- package/dist/runtime/recover.mjs +11 -7
- package/dist/runtime/redirect.d.mts +20 -14
- package/dist/runtime/redirect.mjs +42 -15
- package/dist/runtime/request-scope.d.mts +1 -1
- package/dist/runtime/request-scope.mjs +11 -23
- package/dist/runtime/server.d.mts +6 -0
- package/dist/runtime/server.mjs +3 -0
- package/dist/runtime/stylesheets.d.mts +13 -0
- package/dist/runtime/stylesheets.mjs +15 -0
- package/dist/serve.d.mts +1 -0
- package/dist/serve.mjs +5 -11
- package/dist/{static-6z8_6B1U.d.mts → static-DnbgGIoy.d.mts} +2 -1
- package/dist/static-file-BAjwBMMl.mjs +1274 -0
- package/dist/{static-host-C6D_11Gp.mjs → static-host-B-1fAfAw.mjs} +49 -74
- package/dist/vercel.d.mts +1 -2
- package/dist/vercel.mjs +20 -20
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +232 -1469
- package/docs/GUIDE.md +6 -3
- package/docs/llms.txt +8 -4
- package/docs/references/csp.md +11 -9
- package/docs/references/deploy.md +17 -20
- package/docs/references/errors.md +0 -34
- package/docs/references/params.md +5 -5
- package/docs/references/routing.md +104 -20
- package/package.json +6 -6
- package/dist/runtime/redirect-file.d.mts +0 -20
- package/dist/runtime/redirect-file.mjs +0 -42
- package/dist/runtime/tree-pathname.d.mts +0 -2
- package/dist/runtime/tree-pathname.mjs +0 -11
- package/dist/server.d.mts +0 -110
- package/dist/server.mjs +0 -97
package/dist/server.mjs
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
// ../framework-engine/dist/runtime/request-scope.mjs
|
|
3
|
-
/**
|
|
4
|
-
* The framework bundles this module twice — into the runtime the handler
|
|
5
|
-
* is built from, and into the entry an application imports the response API
|
|
6
|
-
* from — and both copies have to find the one request in progress. So the
|
|
7
|
-
* storage lives on `globalThis` under a registry symbol, as `@k8ordo/i18n`'s
|
|
8
|
-
* locale storage does, rather than in either copy.
|
|
9
|
-
*/
|
|
10
|
-
const KEY = Symbol.for("k8ordo.request");
|
|
11
|
-
const storage = () => {
|
|
12
|
-
const global = globalThis;
|
|
13
|
-
global[KEY] ??= new AsyncLocalStorage();
|
|
14
|
-
return global[KEY];
|
|
15
|
-
};
|
|
16
|
-
const fileRefusal = (caller) => /* @__PURE__ */ new Error(`${caller} answers a request, and under mode: 'static' a file is written once for every visitor — it was called through an import of @k8ordo/framework/server the build cannot name, such as a dependency's\nthis application wants mode: 'server'`);
|
|
17
|
-
/**
|
|
18
|
-
* Where the response API is allowed: the request in progress, while
|
|
19
|
-
* something that answers it runs.
|
|
20
|
-
*/
|
|
21
|
-
const answering = (caller) => {
|
|
22
|
-
const scope = storage().getStore();
|
|
23
|
-
if (scope === void 0) throw new Error(`${caller} needs a request — call it from a guard.ts, a route.ts or a Server Action, while the request is being answered`);
|
|
24
|
-
if (scope.file === true) throw fileRefusal(caller);
|
|
25
|
-
if (scope.phase === "render") throw new Error(`${caller} belongs to what answers the request, and a page is a render — call it from a guard.ts, a route.ts or a Server Action; a page reads the request from its props`);
|
|
26
|
-
return scope;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* The headers the final response will carry, whatever answers the request.
|
|
30
|
-
* Set from a `guard.ts` that lets the request through — a
|
|
31
|
-
* `Content-Security-Policy`, say — or from one that ends it, or from a
|
|
32
|
-
* Server Action: they are added to the answer. A header the answer already
|
|
33
|
-
* carries is replaced.
|
|
34
|
-
*/
|
|
35
|
-
const responseHeaders = () => answering("responseHeaders()").outgoing.headers;
|
|
36
|
-
/**
|
|
37
|
-
* The request's cookies, to read and to write: what the request carried,
|
|
38
|
-
* with what this answer set or deleted since, and every write said as a
|
|
39
|
-
* `Set-Cookie` on the answer. From a `guard.ts`, a `route.ts` or a Server
|
|
40
|
-
* Action; a page
|
|
41
|
-
* reads `request.cookies` from its props.
|
|
42
|
-
*/
|
|
43
|
-
const cookies = () => answering("cookies()").cookies;
|
|
44
|
-
/**
|
|
45
|
-
* The headers the request arrived with — for a Server Action, which is
|
|
46
|
-
* handed its arguments rather than the request. Read them; they are the
|
|
47
|
-
* request's own.
|
|
48
|
-
*/
|
|
49
|
-
const requestHeaders = () => answering("requestHeaders()").request.headers;
|
|
50
|
-
/**
|
|
51
|
-
* The nonce this answer's inline scripts carry: the framework's own — the
|
|
52
|
-
* payload written into the HTML, React's — and any the application signs
|
|
53
|
-
* with it, as `<ColorSchemeProvider nonce={nonce()}>`. A new one per
|
|
54
|
-
* request. Readable wherever the request is in progress, the render
|
|
55
|
-
* included: signing a script is not writing the response. A guard names it
|
|
56
|
-
* in the `Content-Security-Policy` it writes; a build into files turns what
|
|
57
|
-
* carries it into hashes.
|
|
58
|
-
*/
|
|
59
|
-
const nonce = () => {
|
|
60
|
-
const scope = storage().getStore();
|
|
61
|
-
if (scope === void 0) throw new Error("nonce() needs a request — call it while one is answered: from a guard.ts, a layout or page, or a Server Action");
|
|
62
|
-
if (scope.file === true) throw fileRefusal("nonce()");
|
|
63
|
-
return scope.nonce;
|
|
64
|
-
};
|
|
65
|
-
// ../framework-engine/dist/runtime/redirect.mjs
|
|
66
|
-
/**
|
|
67
|
-
* A redirect thrown from a Server Action. Branded with a registry symbol
|
|
68
|
-
* rather than a class: the framework bundles this module once into the
|
|
69
|
-
* entry an application imports `redirect()` from and once into the runtime
|
|
70
|
-
* it copies beside it (where the handler catches it), and two copies of a
|
|
71
|
-
* class are two classes. `Symbol.for` is the one identity both share.
|
|
72
|
-
*/
|
|
73
|
-
const BRAND = Symbol.for("k8ordo.redirect");
|
|
74
|
-
/**
|
|
75
|
-
* An `Error` for the linter's and the stack's sake, recognised by the brand
|
|
76
|
-
* and never by `instanceof`.
|
|
77
|
-
*/
|
|
78
|
-
var Redirect = class extends Error {
|
|
79
|
-
to;
|
|
80
|
-
[BRAND] = true;
|
|
81
|
-
constructor(to) {
|
|
82
|
-
super(`redirect to ${to}`);
|
|
83
|
-
this.to = to;
|
|
84
|
-
this.name = "Redirect";
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Ends a Server Action by sending the visitor somewhere else. Thrown, so an
|
|
89
|
-
* action reads the way it did before the redirect was added — the lines
|
|
90
|
-
* after it never run. A form posted without JavaScript is answered with a
|
|
91
|
-
* `303` to `to`; one posted by the client runtime is answered with a
|
|
92
|
-
* payload that tells the browser to navigate there.
|
|
93
|
-
*/
|
|
94
|
-
const redirect = (to) => {
|
|
95
|
-
throw new Redirect(to);
|
|
96
|
-
};
|
|
97
|
-
export { cookies, nonce, redirect, requestHeaders, responseHeaders };
|