okno 1.0.0-beta.13 → 1.0.0-beta.14
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/dist/codegen/generate.d.ts.map +1 -1
- package/dist/codegen/modules.d.ts +32 -0
- package/dist/codegen/modules.d.ts.map +1 -0
- package/dist/dispatch-C34WXMSB.js +1049 -0
- package/dist/index.js +1 -1
- package/dist/next/codegen.d.ts +26 -0
- package/dist/next/codegen.d.ts.map +1 -0
- package/dist/next/config.d.ts.map +1 -1
- package/dist/next/handler.d.ts +11 -4
- package/dist/next/handler.d.ts.map +1 -1
- package/dist/next/index.js +94 -53
- package/dist/plugin-DmiwHDt_.js +459 -0
- package/dist/vite/index.js +1 -1
- package/dist/vite/plugin.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/dispatch-bnmIdH8E.js +0 -759
- package/dist/plugin-DkXOrSVC.js +0 -721
package/dist/index.js
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface WriteOknoModulesOptions {
|
|
2
|
+
/** Output dir under `root` for the generated `okno:*` files (default ".okno"). */
|
|
3
|
+
outDir?: string;
|
|
4
|
+
/** Production build → drop drafted collection items (dev keeps them visible).
|
|
5
|
+
* Defaults to `NODE_ENV === "production"`, matching the Vite plugin. */
|
|
6
|
+
isBuild?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** The `okno:*` → generated-filename map. The extension is `.js` because the
|
|
9
|
+
* files hold plain ES-module source (the generators emit JS, importing content
|
|
10
|
+
* `.ts` files by absolute path — the consumer's bundler transpiles those). */
|
|
11
|
+
export declare const OKNO_MODULE_FILES: {
|
|
12
|
+
readonly "okno:pages": "pages.js";
|
|
13
|
+
readonly "okno:collections": "collections.js";
|
|
14
|
+
readonly "okno:globals": "globals.js";
|
|
15
|
+
readonly "okno:locales": "locales.js";
|
|
16
|
+
readonly "okno:strings": "strings.js";
|
|
17
|
+
readonly "okno:content": "content.js";
|
|
18
|
+
readonly "okno:runtime": "runtime.js";
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Generate every `okno:*` value module to disk under `<root>/<outDir>/`.
|
|
22
|
+
* Overwrites each file. Mirrors exactly what the Vite plugin's `load()` returns
|
|
23
|
+
* per specifier, using the same generators + `scanImports` for placeholder sets.
|
|
24
|
+
*/
|
|
25
|
+
export declare function writeOknoModules(oknoDir: string, root: string, opts?: WriteOknoModulesOptions): Promise<void>;
|
|
26
|
+
//# sourceMappingURL=codegen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/next/codegen.ts"],"names":[],"mappings":"AAwEA,MAAM,WAAW,uBAAuB;IACvC,kFAAkF;IAClF,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;6EACyE;IACzE,OAAO,CAAC,EAAE,OAAO,CAAA;CACjB;AAED;;+EAE+E;AAC/E,eAAO,MAAM,iBAAiB;;;;;;;;CAQpB,CAAA;AAEV;;;;GAIG;AACH,wBAAsB,gBAAgB,CACrC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,uBAA4B,GAChC,OAAO,CAAC,IAAI,CAAC,CA2Cf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/next/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/next/config.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAEpD,MAAM,WAAW,eAAe;IAC/B,4EAA4E;IAC5E,GAAG,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;IACvB;;+CAE2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB;AAsBD;8EAC8E;AAC9E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,GAAE,CAAW,EAAE,OAAO,GAAE,eAAoB,GAAG,CAAC,CAkCrF"}
|
package/dist/next/handler.d.ts
CHANGED
|
@@ -4,9 +4,16 @@ export interface OknoRouteOptions {
|
|
|
4
4
|
/** Project root the dir resolves against (default `process.cwd()`). */
|
|
5
5
|
root?: string;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* The App-Router handler context. Next 15's route validator requires the
|
|
9
|
+
* EXPORTED handler's 2nd param to be exactly this shape — `params` present and a
|
|
10
|
+
* Promise, non-optional — or `next build` fails type validation. (Next 14 passes
|
|
11
|
+
* a plain `params` object; it still `await`s fine at runtime.) So the returned
|
|
12
|
+
* GET/POST type this as a required param even though the impl is defensive about
|
|
13
|
+
* a missing ctx.
|
|
14
|
+
*/
|
|
8
15
|
type RouteContext = {
|
|
9
|
-
params
|
|
16
|
+
params: Promise<Record<string, string | string[]>>;
|
|
10
17
|
};
|
|
11
18
|
/**
|
|
12
19
|
* Build the `{ GET, POST }` handlers for the okno dev API. Mount at a Next
|
|
@@ -14,8 +21,8 @@ type RouteContext = {
|
|
|
14
21
|
* `withOkno` rewrite from `/__okno/api/*`).
|
|
15
22
|
*/
|
|
16
23
|
export declare function createOknoRouteHandler(opts?: OknoRouteOptions): {
|
|
17
|
-
GET: (req: Request, ctx
|
|
18
|
-
POST: (req: Request, ctx
|
|
24
|
+
GET: (req: Request, ctx: RouteContext) => Promise<Response>;
|
|
25
|
+
POST: (req: Request, ctx: RouteContext) => Promise<Response>;
|
|
19
26
|
};
|
|
20
27
|
export {};
|
|
21
28
|
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/next/handler.ts"],"names":[],"mappings":"AA6BA,MAAM,WAAW,gBAAgB;IAChC,kEAAkE;IAClE,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAA;CACb;AAED
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/next/handler.ts"],"names":[],"mappings":"AA6BA,MAAM,WAAW,gBAAgB;IAChC,kEAAkE;IAClE,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAA;CACb;AAED;;;;;;;GAOG;AACH,KAAK,YAAY,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,CAAA;CAAE,CAAA;AA6B1E;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,CAAC,EAAE,gBAAgB,GAAG;IAChE,GAAG,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC3D,IAAI,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC5D,CAyCA"}
|
package/dist/next/index.js
CHANGED
|
@@ -1,79 +1,120 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { existsSync as
|
|
3
|
-
import { g as
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { join as l, relative as E, sep as w, resolve as b } from "node:path";
|
|
2
|
+
import { existsSync as S, watch as A } from "node:fs";
|
|
3
|
+
import { s as g, b as M, a as C, c as R, d as N, e as P, g as F, I, f as L, h as T, i as $ } from "../dispatch-C34WXMSB.js";
|
|
4
|
+
import { mkdir as B, writeFile as u } from "node:fs/promises";
|
|
5
|
+
const G = (o) => o.replaceAll(I, "__oknoSetImages(undefined)"), U = (o) => {
|
|
6
|
+
let n = o;
|
|
7
|
+
for (const [t, e] of Object.entries(z))
|
|
8
|
+
n = n.replaceAll(`"${t}"`, `"./${e}"`).replaceAll(`'${t}'`, `'./${e}'`);
|
|
9
|
+
return n;
|
|
10
|
+
}, x = (o, n, t) => {
|
|
11
|
+
const e = E(t, n).split(w).join("/");
|
|
12
|
+
return o.replaceAll(n.split(w).join("/"), e);
|
|
13
|
+
}, z = {
|
|
14
|
+
"okno:pages": "pages.js",
|
|
15
|
+
"okno:collections": "collections.js",
|
|
16
|
+
"okno:globals": "globals.js",
|
|
17
|
+
"okno:locales": "locales.js",
|
|
18
|
+
"okno:strings": "strings.js",
|
|
19
|
+
"okno:content": "content.js",
|
|
20
|
+
"okno:runtime": "runtime.js"
|
|
21
|
+
};
|
|
22
|
+
async function D(o, n, t = {}) {
|
|
23
|
+
const e = l(n, t.outDir ?? ".okno"), a = t.isBuild ?? process.env.NODE_ENV === "production";
|
|
24
|
+
await B(e, { recursive: !0 });
|
|
25
|
+
const [s, r, c] = await Promise.all([
|
|
26
|
+
g(n, "pages"),
|
|
27
|
+
g(n, "collections"),
|
|
28
|
+
g(n, "globals")
|
|
29
|
+
]), [i, p, f, m] = await Promise.all([
|
|
30
|
+
M(o, s),
|
|
31
|
+
C(o, r, a),
|
|
32
|
+
R(o, c),
|
|
33
|
+
N(o)
|
|
34
|
+
]), k = P(o), v = L(), O = F() ?? 'throw new Error("okno: runtime/wrap.js missing — run \\`bun run build:pkg\\`")', d = (_) => x(U(G(_)), o, e);
|
|
35
|
+
await Promise.all([
|
|
36
|
+
u(l(e, "pages.js"), d(i)),
|
|
37
|
+
u(l(e, "collections.js"), d(p)),
|
|
38
|
+
u(l(e, "globals.js"), d(f)),
|
|
39
|
+
u(l(e, "locales.js"), d(k)),
|
|
40
|
+
u(l(e, "strings.js"), d(m)),
|
|
41
|
+
u(l(e, "content.js"), d(v)),
|
|
42
|
+
u(l(e, "runtime.js"), O)
|
|
43
|
+
]);
|
|
44
|
+
}
|
|
45
|
+
function J(o, n) {
|
|
46
|
+
const t = { source: "/__okno/api/:path*", destination: `/${n}/:path*` };
|
|
6
47
|
return async () => {
|
|
7
|
-
const e = typeof
|
|
8
|
-
return e ? Array.isArray(e) ? [
|
|
48
|
+
const e = typeof o == "function" ? await o() : void 0;
|
|
49
|
+
return e ? Array.isArray(e) ? [t, ...e] : { ...e, beforeFiles: [t, ...e.beforeFiles ?? []] } : [t];
|
|
9
50
|
};
|
|
10
51
|
}
|
|
11
|
-
let
|
|
12
|
-
function
|
|
13
|
-
const
|
|
14
|
-
...
|
|
15
|
-
rewrites:
|
|
52
|
+
let j = !1;
|
|
53
|
+
function Y(o = {}, n = {}) {
|
|
54
|
+
const t = n.apiMount ?? "oknoapi", e = o, a = {
|
|
55
|
+
...e,
|
|
56
|
+
rewrites: J(e.rewrites, t)
|
|
16
57
|
};
|
|
17
|
-
if (!
|
|
18
|
-
|
|
19
|
-
const s = process.cwd(),
|
|
20
|
-
if (
|
|
21
|
-
const
|
|
22
|
-
|
|
58
|
+
if (!j) {
|
|
59
|
+
j = !0;
|
|
60
|
+
const s = process.cwd(), r = b(s, n.dir ?? "okno");
|
|
61
|
+
if (S(r)) {
|
|
62
|
+
const c = () => {
|
|
63
|
+
T(r, s).catch((i) => console.warn("[okno] type codegen failed:", i)), D(r, s).catch((i) => console.warn("[okno] module codegen failed:", i));
|
|
23
64
|
};
|
|
24
|
-
if (
|
|
65
|
+
if (c(), process.env.NODE_ENV !== "production")
|
|
25
66
|
try {
|
|
26
|
-
|
|
67
|
+
A(r, { recursive: !0 }, () => c());
|
|
27
68
|
} catch {
|
|
28
69
|
}
|
|
29
70
|
}
|
|
30
71
|
}
|
|
31
|
-
return
|
|
72
|
+
return a;
|
|
32
73
|
}
|
|
33
|
-
const
|
|
34
|
-
function
|
|
35
|
-
return
|
|
74
|
+
const y = { "Content-Type": "application/json", "Cache-Control": "no-store" };
|
|
75
|
+
function H(o) {
|
|
76
|
+
return b(o?.root ?? process.cwd(), o?.dir ?? "okno");
|
|
36
77
|
}
|
|
37
|
-
function
|
|
38
|
-
return new Response(JSON.stringify({ error: "Not found" }), { status: 404, headers:
|
|
78
|
+
function h() {
|
|
79
|
+
return new Response(JSON.stringify({ error: "Not found" }), { status: 404, headers: y });
|
|
39
80
|
}
|
|
40
|
-
async function
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
const
|
|
44
|
-
if (Array.isArray(
|
|
45
|
-
if (typeof
|
|
81
|
+
async function V(o, n) {
|
|
82
|
+
const t = n?.params ? await n.params : void 0;
|
|
83
|
+
if (t) {
|
|
84
|
+
const s = t.okno ?? Object.values(t)[0];
|
|
85
|
+
if (Array.isArray(s)) return s.join("/");
|
|
86
|
+
if (typeof s == "string") return s;
|
|
46
87
|
}
|
|
47
|
-
const e = "/__okno/api/",
|
|
48
|
-
return
|
|
88
|
+
const e = "/__okno/api/", a = new URL(o.url).pathname.indexOf(e);
|
|
89
|
+
return a === -1 ? null : new URL(o.url).pathname.slice(a + e.length);
|
|
49
90
|
}
|
|
50
|
-
function
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
let
|
|
55
|
-
const
|
|
91
|
+
function Z(o) {
|
|
92
|
+
const n = H(o), t = async (e, a) => {
|
|
93
|
+
const s = await V(e, a);
|
|
94
|
+
if (s == null) return h();
|
|
95
|
+
let r, c = !1, i;
|
|
96
|
+
const p = {
|
|
56
97
|
method: e.method,
|
|
57
|
-
route:
|
|
98
|
+
route: s,
|
|
58
99
|
json: async () => {
|
|
59
|
-
if (!
|
|
60
|
-
|
|
100
|
+
if (!c) {
|
|
101
|
+
c = !0;
|
|
61
102
|
try {
|
|
62
|
-
|
|
103
|
+
r = await e.json();
|
|
63
104
|
} catch {
|
|
64
|
-
|
|
105
|
+
r = {};
|
|
65
106
|
}
|
|
66
107
|
}
|
|
67
|
-
return
|
|
108
|
+
return r ?? {};
|
|
68
109
|
},
|
|
69
|
-
binary: async () => (
|
|
70
|
-
header: (
|
|
71
|
-
},
|
|
72
|
-
return
|
|
110
|
+
binary: async () => (i === void 0 && (i = Buffer.from(await e.arrayBuffer())), i),
|
|
111
|
+
header: (m) => e.headers.get(m) ?? void 0
|
|
112
|
+
}, f = await $(n, p);
|
|
113
|
+
return f ? new Response(JSON.stringify(f.body), { status: f.status, headers: y }) : h();
|
|
73
114
|
};
|
|
74
|
-
return { GET:
|
|
115
|
+
return { GET: t, POST: t };
|
|
75
116
|
}
|
|
76
117
|
export {
|
|
77
|
-
|
|
78
|
-
|
|
118
|
+
Z as createOknoRouteHandler,
|
|
119
|
+
Y as withOkno
|
|
79
120
|
};
|