@k8ordo/framework 2.3.1 → 4.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 +28 -13
- package/dist/cli.mjs +3 -3
- package/dist/generated.d.mts +13 -13
- package/dist/headers-BxB_jJVk.mjs +73 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +1 -1
- package/dist/paths-type-DXpmjaOr.d.mts +43 -0
- package/dist/runtime/app-router.mjs +21 -8
- package/dist/runtime/browser-payloads.mjs +1 -1
- package/dist/runtime/client-files.d.mts +6 -5
- package/dist/runtime/client-files.mjs +17 -9
- package/dist/runtime/client-ready.d.mts +7 -1
- package/dist/runtime/client-ready.mjs +2 -1
- package/dist/runtime/cookies.d.mts +2 -0
- package/dist/runtime/cookies.mjs +2 -1
- package/dist/runtime/ended.d.mts +7 -0
- package/dist/runtime/ended.mjs +14 -0
- package/dist/runtime/entry.browser.mjs +1 -1
- package/dist/runtime/entry.rsc.d.mts +38 -2
- package/dist/runtime/entry.rsc.mjs +97 -31
- package/dist/runtime/entry.ssr.d.mts +7 -1
- package/dist/runtime/entry.ssr.mjs +12 -6
- package/dist/runtime/guard.d.mts +15 -10
- package/dist/runtime/guard.mjs +8 -2
- package/dist/runtime/mount.mjs +1 -1
- package/dist/runtime/page-boundary.mjs +2 -2
- package/dist/runtime/params.d.mts +5 -4
- package/dist/runtime/params.mjs +2 -2
- package/dist/runtime/payload.d.mts +19 -4
- package/dist/runtime/payload.mjs +20 -5
- package/dist/runtime/prefetch.d.mts +29 -8
- package/dist/runtime/prefetch.mjs +95 -24
- package/dist/runtime/redirect.d.mts +13 -7
- package/dist/runtime/redirect.mjs +25 -9
- package/dist/runtime/request-scope.d.mts +37 -2
- package/dist/runtime/request-scope.mjs +60 -3
- package/dist/runtime/request.d.mts +6 -1
- package/dist/runtime/request.mjs +7 -2
- package/dist/runtime/route.d.mts +4 -2
- package/dist/runtime/route.mjs +13 -5
- package/dist/runtime/server.d.mts +5 -5
- package/dist/runtime/server.mjs +2 -2
- package/dist/runtime/shell.d.mts +2 -1
- package/dist/serve.d.mts +4 -0
- package/dist/serve.mjs +29 -14
- package/dist/static-Be3xIqd8.d.mts +62 -0
- package/dist/{static-file-BAjwBMMl.mjs → static-file-BS-WEiwu.mjs} +311 -134
- package/dist/{static-host-B-1fAfAw.mjs → static-host-tIDLqV8c.mjs} +1 -1
- package/dist/vercel.d.mts +18 -1
- package/dist/vercel.mjs +131 -19
- package/dist/vite.d.mts +6 -3
- package/dist/vite.mjs +366 -156
- package/docs/GUIDE.md +173 -46
- package/docs/llms.txt +129 -65
- package/docs/references/actions.md +14 -5
- package/docs/references/boundaries.md +23 -2
- package/docs/references/csp.md +91 -2
- package/docs/references/deploy.md +154 -25
- package/docs/references/errors.md +57 -12
- package/docs/references/guards.md +100 -29
- package/docs/references/params.md +234 -126
- package/docs/references/routing.md +358 -75
- package/package.json +18 -13
- package/dist/shared-dir-CNXFRZgP.mjs +0 -9
- package/dist/static-DnbgGIoy.d.mts +0 -61
package/dist/serve.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import {
|
|
1
|
+
import { f as ENCODINGS, g as streamingCompressor, h as negotiateEncoding, m as isCompressible, n as resolveStatic, p as SUFFIX, t as readRules } from "./static-host-tIDLqV8c.mjs";
|
|
2
|
+
import { n as safeJoin, t as isFile } from "./static-file-BS-WEiwu.mjs";
|
|
3
3
|
import { withoutBase } from "@k8ordo/router";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { stat } from "node:fs/promises";
|
|
@@ -11,7 +11,7 @@ import { createServer } from "node:http";
|
|
|
11
11
|
import { Readable } from "node:stream";
|
|
12
12
|
import { pipeline } from "node:stream/promises";
|
|
13
13
|
import fresh from "fresh";
|
|
14
|
-
import
|
|
14
|
+
import { combineRanges, parse } from "range-parser";
|
|
15
15
|
// src/serve.ts
|
|
16
16
|
/**
|
|
17
17
|
* Vite writes the hash of the contents into the name of everything under
|
|
@@ -81,6 +81,8 @@ const digest = async (file) => {
|
|
|
81
81
|
for await (const chunk of createReadStream(file)) hash.update(chunk);
|
|
82
82
|
return hash.digest("base64url");
|
|
83
83
|
};
|
|
84
|
+
const UNREADABLE = 1;
|
|
85
|
+
const PAST_THE_END = 2;
|
|
84
86
|
/**
|
|
85
87
|
* The part of a file a GET asked for: the whole, one byte range, or a range
|
|
86
88
|
* that starts past the end. Only the single range a media element asks for
|
|
@@ -92,10 +94,11 @@ const rangeOf = (headers, size, etag) => {
|
|
|
92
94
|
const { range, "if-range": ifRange } = headers;
|
|
93
95
|
if (range === void 0) return "whole";
|
|
94
96
|
if (ifRange !== void 0 && ifRange !== etag) return "whole";
|
|
95
|
-
const ranges =
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
const { code, type, ranges } = parse(size, range);
|
|
98
|
+
if (type !== "bytes" || (code & UNREADABLE) !== 0) return "whole";
|
|
99
|
+
const [only, ...more] = combineRanges(ranges);
|
|
100
|
+
if (only === void 0) return code === PAST_THE_END ? "unsatisfiable" : "whole";
|
|
101
|
+
return more.length === 0 ? only : "whole";
|
|
99
102
|
};
|
|
100
103
|
/**
|
|
101
104
|
* The handler's answer, written out — compressed on the way when its type is
|
|
@@ -138,7 +141,8 @@ const sendAnswer = async (incoming, response, result) => {
|
|
|
138
141
|
const serve = async (options = {}) => {
|
|
139
142
|
const dist = path.resolve(process.cwd(), options.dist ?? "dist");
|
|
140
143
|
const clientDir = path.join(dist, "client");
|
|
141
|
-
const { default: handler, base, mode } = await import(pathToFileURL(path.join(dist, "rsc", "index.js")).href);
|
|
144
|
+
const { default: handler, base, mode, headers: declared } = await import(pathToFileURL(path.join(dist, "rsc", "index.js")).href);
|
|
145
|
+
const everywhere = Object.entries(declared);
|
|
142
146
|
const rules = mode === "static" ? await readRules(clientDir) : null;
|
|
143
147
|
const etags = /* @__PURE__ */ new Map();
|
|
144
148
|
const etagOf = (file, { size, mtimeMs }) => {
|
|
@@ -224,7 +228,15 @@ const serve = async (options = {}) => {
|
|
|
224
228
|
}
|
|
225
229
|
await sendFile(incoming, response, answer.file, answer.status);
|
|
226
230
|
};
|
|
231
|
+
const pending = /* @__PURE__ */ new Set();
|
|
232
|
+
const keeping = { waitUntil: (promise) => {
|
|
233
|
+
const settled = promise.finally(() => {
|
|
234
|
+
pending.delete(settled);
|
|
235
|
+
});
|
|
236
|
+
pending.add(settled);
|
|
237
|
+
} };
|
|
227
238
|
const server = createServer((incoming, response) => {
|
|
239
|
+
for (const [name, value] of everywhere) response.setHeader(name, value);
|
|
228
240
|
(async () => {
|
|
229
241
|
const url = urlOf(incoming);
|
|
230
242
|
if (url === null) {
|
|
@@ -243,7 +255,7 @@ const serve = async (options = {}) => {
|
|
|
243
255
|
await sendFile(incoming, response, file);
|
|
244
256
|
return;
|
|
245
257
|
}
|
|
246
|
-
await sendAnswer(incoming, response, await handler(asRequest(incoming, url)));
|
|
258
|
+
await sendAnswer(incoming, response, await handler(asRequest(incoming, url), keeping));
|
|
247
259
|
})().catch((error) => {
|
|
248
260
|
console.error("k8ordo: %s %s failed", incoming.method ?? "GET", incoming.url ?? "/", error);
|
|
249
261
|
response.writeHead(500, { "content-type": "text/plain;charset=utf-8" });
|
|
@@ -260,12 +272,15 @@ const serve = async (options = {}) => {
|
|
|
260
272
|
return {
|
|
261
273
|
port,
|
|
262
274
|
url,
|
|
263
|
-
close:
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
275
|
+
close: async () => {
|
|
276
|
+
await new Promise((resolve, reject) => {
|
|
277
|
+
server.close((error) => {
|
|
278
|
+
if (error === void 0) resolve();
|
|
279
|
+
else reject(error);
|
|
280
|
+
});
|
|
267
281
|
});
|
|
268
|
-
|
|
282
|
+
while (pending.size > 0) await Promise.all(pending);
|
|
283
|
+
}
|
|
269
284
|
};
|
|
270
285
|
};
|
|
271
286
|
export { serve };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Plugin, PluginOption } from "vite";
|
|
2
|
+
import "react";
|
|
3
|
+
/** What `framework()` takes whatever the mode. */
|
|
4
|
+
type EngineOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Compiles the client components with React Compiler — the Rust one,
|
|
7
|
+
* through `@vitejs/plugin-react`'s `compiler`, which needs
|
|
8
|
+
* `oxc-transform-react` installed. Server components are left as they are.
|
|
9
|
+
*/
|
|
10
|
+
readonly reactCompiler?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Headers every response carries, whatever answered — a page, a file of
|
|
13
|
+
* the build, a `404`, a redirect. Sent by `vite dev`, `vite preview` and
|
|
14
|
+
* `serve`, added by the request handler to its own answers under
|
|
15
|
+
* `mode: 'server'`, and written for the hosts that read them from the
|
|
16
|
+
* build. A header the answer already has under the same name — one a
|
|
17
|
+
* `guard.ts` or a `route.ts` set — is left as it is.
|
|
18
|
+
*/
|
|
19
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The `Content-Security-Policy` an application wants on every page, as
|
|
23
|
+
* directives and their sources. The build writes it into each page's
|
|
24
|
+
* `<meta>`, with the hashes of that page's signed inline scripts added.
|
|
25
|
+
*/
|
|
26
|
+
type ContentSecurityPolicy = Readonly<Record<string, readonly string[]>>;
|
|
27
|
+
/**
|
|
28
|
+
* An inline script of the application's as a CSP source, `'sha256-…'`: the
|
|
29
|
+
* hash of `text`, the string its `<script>` is given, for static mode's
|
|
30
|
+
* `csp` option, which adds the hashes of the framework's own scripts alone.
|
|
31
|
+
* A line break counts as the browser parses the page, a CR LF as one LF.
|
|
32
|
+
*/
|
|
33
|
+
declare const scriptHash: (text: string) => Promise<string>;
|
|
34
|
+
type StaticOptions = EngineOptions & {
|
|
35
|
+
/**
|
|
36
|
+
* Every route rendered at build time and written to files; no server at
|
|
37
|
+
* run time, so nothing that answers a request (Server Actions, guards, the
|
|
38
|
+
* request API) builds.
|
|
39
|
+
*/
|
|
40
|
+
readonly mode: 'static';
|
|
41
|
+
/**
|
|
42
|
+
* The origin the site is served from — `https://example.com`, with no
|
|
43
|
+
* path. The build asks for every page and `route.ts` under it, so it is
|
|
44
|
+
* the origin of the `request.url` a `route.ts` reads, and it writes
|
|
45
|
+
* `sitemap.xml`, listing every page it rendered at its URL, Vite's `base`
|
|
46
|
+
* included. A `route.ts` that writes `sitemap.xml` is the application's
|
|
47
|
+
* own list, and the build leaves the file to it.
|
|
48
|
+
*/
|
|
49
|
+
readonly site: string;
|
|
50
|
+
/**
|
|
51
|
+
* The `Content-Security-Policy` every page carries, as directives and
|
|
52
|
+
* their sources. The framework decides no policy: it writes this one into
|
|
53
|
+
* each page's `<meta>`, adding to `script-src` the hashes of its own inline
|
|
54
|
+
* scripts on that page — the payload and React's. An inline script of the
|
|
55
|
+
* application's is allowed by its hash here: `scriptHash()` from
|
|
56
|
+
* `@k8ordo/framework/vite` gives the hash of one the application writes,
|
|
57
|
+
* as `colorSchemeScriptHash()` gives `@k8ordo/color-scheme`'s. Without it,
|
|
58
|
+
* no policy is written.
|
|
59
|
+
*/
|
|
60
|
+
readonly csp?: ContentSecurityPolicy;
|
|
61
|
+
};
|
|
62
|
+
export { EngineOptions as i, ContentSecurityPolicy as n, scriptHash as r, StaticOptions as t };
|