okno 1.0.0-beta.20 → 1.0.0-beta.21

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.
@@ -0,0 +1,183 @@
1
+ import { e as D, b as I, a as R, p as U } from "../encode-DoojdsVU.js";
2
+ import { o as K, a as N, b as T } from "../order-bAkdncZC.js";
3
+ function a(s) {
4
+ switch (s) {
5
+ case "number":
6
+ return 0;
7
+ case "boolean":
8
+ return !1;
9
+ case "media":
10
+ return null;
11
+ default:
12
+ return "";
13
+ }
14
+ }
15
+ function u(s) {
16
+ const t = {};
17
+ for (const e of s) {
18
+ const o = e.path.split(".");
19
+ let n = t;
20
+ for (let r = 0; r < o.length - 1; r++) {
21
+ const c = o[r];
22
+ (!n[c] || n[c].type !== "group") && (n[c] = { type: "group", fields: {} }), n = n[c].fields;
23
+ }
24
+ const i = o[o.length - 1];
25
+ if (!n[i]) {
26
+ const r = {};
27
+ for (const [c, f] of Object.entries(e)) c !== "path" && c !== "value" && (r[c] = f);
28
+ n[i] = { ...r, type: e.type };
29
+ }
30
+ }
31
+ return t;
32
+ }
33
+ function y(s) {
34
+ const t = {};
35
+ for (const e of s) {
36
+ const o = e.path.split(".");
37
+ let n = t;
38
+ for (let r = 0; r < o.length - 1; r++) {
39
+ const c = o[r];
40
+ (!n[c] || typeof n[c] != "object") && (n[c] = {}), n = n[c];
41
+ }
42
+ const i = o[o.length - 1];
43
+ n[i] = e.value !== void 0 && e.value !== null ? e.value : a(e.type);
44
+ }
45
+ return t;
46
+ }
47
+ function g(s, t, e) {
48
+ const o = {};
49
+ let n = !1;
50
+ for (const [i, r] of Object.entries(s)) {
51
+ if (e.has(i)) {
52
+ n = !0;
53
+ continue;
54
+ }
55
+ const c = i in t && !(t[i] in s) ? t[i] : i;
56
+ c !== i && (n = !0), o[c] = r;
57
+ }
58
+ return { out: o, changed: n };
59
+ }
60
+ class l extends Error {
61
+ status;
62
+ constructor(t, e) {
63
+ super(e), this.name = "EngineError", this.status = t;
64
+ }
65
+ }
66
+ const d = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/, p = /^[a-z]{2,3}(-[A-Za-z]{4})?(-([A-Za-z]{2}|[0-9]{3}))?$/, h = (s) => s.charAt(0).toUpperCase() + s.slice(1);
67
+ function w(s, t, e, o) {
68
+ const n = s[t] ??= {};
69
+ if (!n[e]) throw new l(404, `${t}/${e} does not exist in schema`);
70
+ n[e].fields = o;
71
+ }
72
+ function b(s, t, e, o) {
73
+ const n = s[t] ??= {}, i = n[e];
74
+ if (!i) throw new l(404, `${t}/${e} does not exist in schema`);
75
+ const r = { ...i, name: o };
76
+ delete r.label, n[e] = r;
77
+ }
78
+ function $(s, t, e, o) {
79
+ const n = s[t] ??= {}, i = n[e];
80
+ if (!i) throw new l(404, `${t}/${e} does not exist in schema`);
81
+ const r = { ...i };
82
+ typeof o == "string" && o.trim() ? r.url = o.trim() : delete r.url, n[e] = r;
83
+ }
84
+ function m(s, t, e, o) {
85
+ if (!d.test(o)) throw new l(400, "Invalid target slug");
86
+ if (e === o) return { unchanged: !0 };
87
+ const n = s[t] ??= {};
88
+ if (!n[e]) throw new l(404, `${t}/${e} does not exist in schema`);
89
+ if (n[o]) throw new l(409, `${t}/${o} already exists`);
90
+ const i = {};
91
+ for (const c of Object.keys(n)) i[c === e ? o : c] = n[c];
92
+ s[t] = i;
93
+ const r = s.layout?.[t];
94
+ return Array.isArray(r) && (s.layout[t] = r.map(
95
+ (c) => typeof c == "string" ? c === e ? o : c : {
96
+ ...c,
97
+ items: (c.items ?? []).map((f) => f === e ? o : f)
98
+ }
99
+ )), { unchanged: !1 };
100
+ }
101
+ function x(s, t, e) {
102
+ const o = s[t];
103
+ if (!o) throw new l(404, `${t} not in schema`);
104
+ const n = {};
105
+ for (const i of e) o[i] && (n[i] = o[i]);
106
+ for (const i of Object.keys(o)) i in n || (n[i] = o[i]);
107
+ s[t] = n;
108
+ }
109
+ function E(s, t, e) {
110
+ const o = s.layout ??= {};
111
+ e.length ? o[t] = e : delete o[t], Object.keys(o).length === 0 && delete s.layout;
112
+ }
113
+ function v(s, t, e) {
114
+ const n = (s.collections ??= {})[t];
115
+ if (!n) throw new l(404, `collections/${t} not in schema`);
116
+ n.order = e.filter((i) => typeof i == "string");
117
+ }
118
+ function z(s, t, e) {
119
+ const n = (s.collections ??= {})[t];
120
+ if (!n) throw new l(404, `collections/${t} not in schema`);
121
+ e ? n.drafts = !0 : delete n.drafts;
122
+ }
123
+ function S(s, t, e) {
124
+ const o = s[t];
125
+ if (!o || !o[e]) throw new l(404, `${t}/${e} does not exist in schema`);
126
+ delete o[e];
127
+ }
128
+ function A(s, t, e, o, n) {
129
+ s[e] || (s[e] = {}), s[e][t] = { name: n?.trim() || h(t), fields: u(o) };
130
+ }
131
+ function O(s, t) {
132
+ t && Object.keys(t).length ? s.strings = t : delete s.strings;
133
+ }
134
+ function j(s, t) {
135
+ let e = null;
136
+ if (t && Array.isArray(t.supported) && t.supported.length > 0) {
137
+ const o = t.supported.map((r) => typeof r == "string" ? { id: r } : r);
138
+ if (!o.every((r) => r && typeof r.id == "string" && p.test(r.id)))
139
+ throw new l(400, "Invalid locale code");
140
+ const n = o.map((r) => r.id);
141
+ if (new Set(n).size !== n.length) throw new l(400, "Duplicate locale code");
142
+ const i = t.default;
143
+ if (typeof i != "string" || !n.includes(i))
144
+ throw new l(400, "Default must be one of the supported locales");
145
+ e = {
146
+ default: i,
147
+ supported: o.map((r) => ({
148
+ id: r.id,
149
+ name: typeof r.name == "string" && r.name ? r.name : r.id,
150
+ // Preserve an intentionally empty slug (= no URL prefix for the default).
151
+ slug: typeof r.slug == "string" ? r.slug : r.id.toLowerCase()
152
+ }))
153
+ };
154
+ }
155
+ e ? s.locales = e : delete s.locales;
156
+ }
157
+ export {
158
+ l as EngineError,
159
+ d as SLUG_RE,
160
+ g as applyKeyChanges,
161
+ S as deleteSchemaEntry,
162
+ a as emptyValueFor,
163
+ D as encodeEntry,
164
+ I as encodeRaw,
165
+ R as encodeSchema,
166
+ y as fieldsToContent,
167
+ u as fieldsToSchema,
168
+ K as orderBySlugs,
169
+ N as orderWithInsert,
170
+ T as orderWithout,
171
+ U as parseExportDefault,
172
+ m as renameSlug,
173
+ x as reorderKind,
174
+ w as saveFields,
175
+ A as scaffoldEntry,
176
+ v as setCollectionOrder,
177
+ z as setDrafts,
178
+ E as setLayout,
179
+ j as setLocales,
180
+ b as setName,
181
+ O as setStringsSchema,
182
+ $ as setUrl
183
+ };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { o as a } from "./plugin-jvqdZWC0.js";
1
+ import { o as a } from "./plugin-DcdYJY8n.js";
2
2
  export {
3
3
  a as okno
4
4
  };
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/next/config.ts"],"names":[],"mappings":"AAoCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AA4BpD,MAAM,WAAW,eAAe;IAC/B,4EAA4E;IAC5E,GAAG,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;IACvB;;+CAE2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;wEACoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAA;CACf;AAoDD;8EAC8E;AAC9E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,GAAE,CAAW,EAAE,OAAO,GAAE,eAAoB,GAAG,CAAC,CA4CrF"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/next/config.ts"],"names":[],"mappings":"AAqCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AA4BpD,MAAM,WAAW,eAAe;IAC/B,4EAA4E;IAC5E,GAAG,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;IACvB;;+CAE2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;wEACoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAA;CACf;AAqDD;8EAC8E;AAC9E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,GAAE,CAAW,EAAE,OAAO,GAAE,eAAoB,GAAG,CAAC,CA4CrF"}
@@ -1,17 +1,17 @@
1
- import { join as c, relative as v, sep as O, resolve as g, dirname as E } from "node:path";
2
- import { existsSync as w, watch as R, readFileSync as M, mkdirSync as A, cpSync as P } from "node:fs";
1
+ import { join as c, relative as v, sep as O, resolve as g, dirname as R } from "node:path";
2
+ import { existsSync as w, watch as E, readFileSync as M, mkdirSync as P, cpSync as A } from "node:fs";
3
3
  import { fileURLToPath as C } from "node:url";
4
- import { s as m, b as J, a as D, c as I, d as U, e as K, g as L, I as T, f as F, h as V, i as $ } from "../dispatch-DKZB5I61.js";
5
- import { mkdir as B, writeFile as f } from "node:fs/promises";
6
- const G = (n) => n.replaceAll(T, "__oknoSetImages(undefined)"), z = (n) => {
4
+ import { s as m, b as J, a as I, c as D, d as U, e as K, g as L, I as T, f as F, h as V, i as $, j as B, k as G } from "../dispatch-CmTJLIKc.js";
5
+ import { mkdir as z, writeFile as f } from "node:fs/promises";
6
+ const H = (n) => n.replaceAll(T, "__oknoSetImages(undefined)"), W = (n) => {
7
7
  let t = n;
8
- for (const [o, e] of Object.entries(W))
8
+ for (const [o, e] of Object.entries(Q))
9
9
  t = t.replaceAll(`"${o}"`, `"./${e}"`).replaceAll(`'${o}'`, `'./${e}'`);
10
10
  return t;
11
- }, H = (n, t, o) => {
11
+ }, x = (n, t, o) => {
12
12
  const e = v(o, t).split(O).join("/");
13
13
  return n.replaceAll(t.split(O).join("/"), e);
14
- }, W = {
14
+ }, Q = {
15
15
  "okno:pages": "pages.js",
16
16
  "okno:collections": "collections.js",
17
17
  "okno:globals": "globals.js",
@@ -20,19 +20,19 @@ const G = (n) => n.replaceAll(T, "__oknoSetImages(undefined)"), z = (n) => {
20
20
  "okno:content": "content.js",
21
21
  "okno:runtime": "runtime.js"
22
22
  };
23
- async function x(n, t, o = {}) {
23
+ async function X(n, t, o = {}) {
24
24
  const e = c(t, o.outDir ?? ".okno"), s = o.isBuild ?? process.env.NODE_ENV === "production";
25
- await B(e, { recursive: !0 });
25
+ await z(e, { recursive: !0 });
26
26
  const [r, i, a] = await Promise.all([
27
27
  m(t, "pages"),
28
28
  m(t, "collections"),
29
29
  m(t, "globals")
30
30
  ]), [u, l, d, _] = await Promise.all([
31
31
  J(n, r),
32
- D(n, i, s),
33
- I(n, a),
32
+ I(n, i, s),
33
+ D(n, a),
34
34
  U(n)
35
- ]), b = K(n), j = F(), S = L() ?? 'throw new Error("okno: runtime/wrap.js missing — run \\`bun run build:pkg\\`")', p = (N) => H(z(G(N)), n, e);
35
+ ]), b = K(n), j = F(), S = L() ?? 'throw new Error("okno: runtime/wrap.js missing — run \\`bun run build:pkg\\`")', p = (N) => x(W(H(N)), n, e);
36
36
  await Promise.all([
37
37
  f(c(e, "pages.js"), p(u)),
38
38
  f(c(e, "collections.js"), p(l)),
@@ -43,8 +43,8 @@ async function x(n, t, o = {}) {
43
43
  f(c(e, "runtime.js"), S)
44
44
  ]);
45
45
  }
46
- function Q() {
47
- const n = E(C(import.meta.url));
46
+ function Y() {
47
+ const n = R(C(import.meta.url));
48
48
  for (const t of ["../package.json", "../../package.json"])
49
49
  try {
50
50
  return JSON.parse(M(g(n, t), "utf-8")).version ?? "0.0.0";
@@ -52,28 +52,26 @@ function Q() {
52
52
  }
53
53
  return "0.0.0";
54
54
  }
55
- function X(n, t) {
55
+ function Z(n, t) {
56
56
  const o = c(n, "files");
57
57
  if (!w(o)) return;
58
58
  const e = c(t, "public", "okno", "files");
59
- A(e, { recursive: !0 }), P(o, e, { recursive: !0, filter: (s) => !s.endsWith(".okno-tree.json") });
59
+ P(e, { recursive: !0 }), A(o, e, { recursive: !0, filter: (s) => !s.endsWith(".okno-tree.json") });
60
60
  }
61
- function Y(n) {
61
+ function q(n) {
62
62
  return {
63
63
  __OKNO_API_URL__: JSON.stringify(n),
64
- __OKNO_VERSION__: JSON.stringify(Q()),
64
+ __OKNO_VERSION__: JSON.stringify(Y()),
65
65
  __OKNO_IS_DEV__: JSON.stringify(!1),
66
66
  __OKNO_DEMO__: JSON.stringify(!1),
67
- __OKNO_REPO__: JSON.stringify(null),
68
- // Next has no Vite git-bake; repo is null (picker fallback) so the monorepo
69
- // subdir is the repo root. Baked to satisfy the editor's `__OKNO_ROOT__` ref.
70
- __OKNO_ROOT__: JSON.stringify("")
67
+ __OKNO_REPO__: JSON.stringify($()),
68
+ __OKNO_ROOT__: JSON.stringify(V())
71
69
  };
72
70
  }
73
- function Z(n, t) {
71
+ function ee(n, t) {
74
72
  return (o, e) => (o.plugins = o.plugins ?? [], o.plugins.push(new e.webpack.DefinePlugin(t)), typeof n == "function" ? n(o, e) : o);
75
73
  }
76
- function q(n, t) {
74
+ function ne(n, t) {
77
75
  const o = { source: "/__okno/api/:path*", destination: `/${t}/:path*` };
78
76
  return async () => {
79
77
  const e = typeof n == "function" ? await n() : void 0;
@@ -81,30 +79,30 @@ function q(n, t) {
81
79
  };
82
80
  }
83
81
  let y = !1;
84
- function ae(n = {}, t = {}) {
82
+ function le(n = {}, t = {}) {
85
83
  const o = t.apiMount ?? "oknoapi", e = t.apiUrl ?? "https://api.okno.build", s = n, r = {
86
84
  ...s,
87
- rewrites: q(s.rewrites, o),
85
+ rewrites: ne(s.rewrites, o),
88
86
  // Bake the editor's compile-time globals (webpack `next build`) so it doesn't
89
87
  // throw `__OKNO_API_URL__ is not defined` on boot. (Turbopack dev has no
90
88
  // DefinePlugin equivalent yet — the deployed demo is a webpack build.)
91
- webpack: Z(s.webpack, Y(e))
89
+ webpack: ee(s.webpack, q(e))
92
90
  };
93
91
  if (!y) {
94
92
  y = !0;
95
93
  const i = process.cwd(), a = g(i, t.dir ?? "okno");
96
94
  if (w(a)) {
97
95
  const u = () => {
98
- V(a, i).catch((l) => console.warn("[okno] type codegen failed:", l)), x(a, i).catch((l) => console.warn("[okno] module codegen failed:", l));
96
+ B(a, i).catch((l) => console.warn("[okno] type codegen failed:", l)), X(a, i).catch((l) => console.warn("[okno] module codegen failed:", l));
99
97
  try {
100
- X(a, i);
98
+ Z(a, i);
101
99
  } catch (l) {
102
100
  console.warn("[okno] media copy failed:", l);
103
101
  }
104
102
  };
105
103
  if (u(), process.env.NODE_ENV !== "production")
106
104
  try {
107
- R(a, { recursive: !0 }, () => u());
105
+ E(a, { recursive: !0 }, () => u());
108
106
  } catch {
109
107
  }
110
108
  }
@@ -112,13 +110,13 @@ function ae(n = {}, t = {}) {
112
110
  return r;
113
111
  }
114
112
  const h = { "Content-Type": "application/json", "Cache-Control": "no-store" };
115
- function ee(n) {
113
+ function oe(n) {
116
114
  return g(n?.root ?? process.cwd(), n?.dir ?? "okno");
117
115
  }
118
116
  function k() {
119
117
  return new Response(JSON.stringify({ error: "Not found" }), { status: 404, headers: h });
120
118
  }
121
- async function ne(n, t) {
119
+ async function te(n, t) {
122
120
  const o = t?.params ? await t.params : void 0;
123
121
  if (o) {
124
122
  const r = o.okno ?? Object.values(o)[0];
@@ -128,9 +126,9 @@ async function ne(n, t) {
128
126
  const e = "/__okno/api/", s = new URL(n.url).pathname.indexOf(e);
129
127
  return s === -1 ? null : new URL(n.url).pathname.slice(s + e.length);
130
128
  }
131
- function ce(n) {
132
- const t = ee(n), o = async (e, s) => {
133
- const r = await ne(e, s);
129
+ function ue(n) {
130
+ const t = oe(n), o = async (e, s) => {
131
+ const r = await te(e, s);
134
132
  if (r == null) return k();
135
133
  let i, a = !1, u;
136
134
  const l = {
@@ -149,12 +147,12 @@ function ce(n) {
149
147
  },
150
148
  binary: async () => (u === void 0 && (u = Buffer.from(await e.arrayBuffer())), u),
151
149
  header: (_) => e.headers.get(_) ?? void 0
152
- }, d = await $(t, l);
150
+ }, d = await G(t, l);
153
151
  return d ? new Response(JSON.stringify(d.body), { status: d.status, headers: h }) : k();
154
152
  };
155
153
  return { GET: o, POST: o };
156
154
  }
157
155
  export {
158
- ce as createOknoRouteHandler,
159
- ae as withOkno
156
+ ue as createOknoRouteHandler,
157
+ le as withOkno
160
158
  };