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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { o as a } from "./plugin-DkXOrSVC.js";
1
+ import { o as a } from "./plugin-DmiwHDt_.js";
2
2
  export {
3
3
  a as okno
4
4
  };
@@ -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":"AAuBA,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;AAqBD;8EAC8E;AAC9E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,GAAE,CAAW,EAAE,OAAO,GAAE,eAAoB,GAAG,CAAC,CA6BrF"}
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"}
@@ -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
- /** The App-Router context object (Next 15 makes `params` a Promise; 14 doesn't). */
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?: Promise<Record<string, string | string[]>> | Record<string, string | string[]>;
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?: RouteContext) => Promise<Response>;
18
- POST: (req: Request, ctx?: RouteContext) => Promise<Response>;
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,oFAAoF;AACpF,KAAK,YAAY,GAAG;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAA;CAAE,CAAA;AA6B/G;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,CAAC,EAAE,gBAAgB,GAAG;IAChE,GAAG,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC5D,IAAI,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC7D,CAyCA"}
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"}
@@ -1,79 +1,120 @@
1
- import { resolve as l } from "node:path";
2
- import { existsSync as m, watch as w } from "node:fs";
3
- import { g as k, d as v } from "../dispatch-bnmIdH8E.js";
4
- function g(r, o) {
5
- const n = { source: "/__okno/api/:path*", destination: `/${o}/:path*` };
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 r == "function" ? await r() : void 0;
8
- return e ? Array.isArray(e) ? [n, ...e] : { ...e, beforeFiles: [n, ...e.beforeFiles ?? []] } : [n];
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 f = !1;
12
- function S(r = {}, o = {}) {
13
- const n = o.apiMount ?? "oknoapi", e = {
14
- ...r,
15
- rewrites: g(r.rewrites, n)
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 (!f) {
18
- f = !0;
19
- const s = process.cwd(), t = l(s, o.dir ?? "okno");
20
- if (m(t)) {
21
- const a = () => {
22
- k(t, s).catch((i) => console.warn("[okno] codegen failed:", i));
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 (a(), process.env.NODE_ENV !== "production")
65
+ if (c(), process.env.NODE_ENV !== "production")
25
66
  try {
26
- w(t, { recursive: !0 }, () => a());
67
+ A(r, { recursive: !0 }, () => c());
27
68
  } catch {
28
69
  }
29
70
  }
30
71
  }
31
- return e;
72
+ return a;
32
73
  }
33
- const p = { "Content-Type": "application/json", "Cache-Control": "no-store" };
34
- function O(r) {
35
- return l(r?.root ?? process.cwd(), r?.dir ?? "okno");
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 d() {
38
- return new Response(JSON.stringify({ error: "Not found" }), { status: 404, headers: p });
78
+ function h() {
79
+ return new Response(JSON.stringify({ error: "Not found" }), { status: 404, headers: y });
39
80
  }
40
- async function R(r, o) {
41
- const n = o?.params ? await o.params : void 0;
42
- if (n) {
43
- const t = n.okno ?? Object.values(n)[0];
44
- if (Array.isArray(t)) return t.join("/");
45
- if (typeof t == "string") return t;
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/", s = new URL(r.url).pathname.indexOf(e);
48
- return s === -1 ? null : new URL(r.url).pathname.slice(s + e.length);
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 _(r) {
51
- const o = O(r), n = async (e, s) => {
52
- const t = await R(e, s);
53
- if (t == null) return d();
54
- let a, i = !1, c;
55
- const h = {
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: t,
98
+ route: s,
58
99
  json: async () => {
59
- if (!i) {
60
- i = !0;
100
+ if (!c) {
101
+ c = !0;
61
102
  try {
62
- a = await e.json();
103
+ r = await e.json();
63
104
  } catch {
64
- a = {};
105
+ r = {};
65
106
  }
66
107
  }
67
- return a ?? {};
108
+ return r ?? {};
68
109
  },
69
- binary: async () => (c === void 0 && (c = Buffer.from(await e.arrayBuffer())), c),
70
- header: (y) => e.headers.get(y) ?? void 0
71
- }, u = await v(o, h);
72
- return u ? new Response(JSON.stringify(u.body), { status: u.status, headers: p }) : d();
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: n, POST: n };
115
+ return { GET: t, POST: t };
75
116
  }
76
117
  export {
77
- _ as createOknoRouteHandler,
78
- S as withOkno
118
+ Z as createOknoRouteHandler,
119
+ Y as withOkno
79
120
  };