okno 1.0.0-beta.39 → 1.0.0-beta.40

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.
@@ -1,14 +1,14 @@
1
- import { join as _, relative as H, sep as U, dirname as N, resolve as ue } from "node:path";
2
- import { readdir as E, readFile as we, writeFile as be } from "node:fs/promises";
3
- import { existsSync as $, readFileSync as v, readdirSync as se, statSync as Se, realpathSync as Oe, writeFileSync as R, mkdirSync as W, unlinkSync as B, renameSync as ve } from "node:fs";
4
- import { execSync as oe } from "node:child_process";
5
- import { fileURLToPath as je } from "node:url";
1
+ import { join as _, relative as H, sep as U, dirname as N, resolve as fe } from "node:path";
2
+ import { readdir as E, readFile as Se, writeFile as Oe } from "node:fs/promises";
3
+ import { existsSync as $, readFileSync as v, readdirSync as oe, statSync as ve, realpathSync as je, writeFileSync as R, mkdirSync as W, unlinkSync as B, renameSync as Ae } from "node:fs";
4
+ import { execSync as re } from "node:child_process";
5
+ import { fileURLToPath as Te } from "node:url";
6
6
  import { p as Z } from "./parse-tlTHgSSs.js";
7
- import { o as Ae } from "./order-bAkdncZC.js";
8
- import { simpleGit as fe } from "simple-git";
9
- import { b as ee, a as Te, e as xe } from "./encode-BfJY0Xy5.js";
10
- import { applyKeyChanges as me, setStringsSchema as Re, saveFields as Pe, setLocales as Ee, setName as Me, setUrl as Ne, renameSlug as Ie, reorderKind as We, setLayout as Fe, setCollectionOrder as Le, setDrafts as Ue, deleteSchemaEntry as Ce, scaffoldEntry as ze, fieldsToContent as Je, EngineError as Ve } from "./engine/index.js";
11
- const Be = /* @__PURE__ */ new Set([".astro", ".svelte", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".vue"]), Ge = /* @__PURE__ */ new Set([
7
+ import { o as xe } from "./order-bAkdncZC.js";
8
+ import { simpleGit as de } from "simple-git";
9
+ import { b as te, a as Re, e as Pe } from "./encode-BfJY0Xy5.js";
10
+ import { applyKeyChanges as me, setStringsSchema as Ee, saveFields as Me, setLocales as Ne, setName as Ie, setUrl as We, renameSlug as Fe, reorderKind as Le, setLayout as Ue, setCollectionOrder as Ce, setDrafts as ze, deleteSchemaEntry as Je, scaffoldEntry as Ve, fieldsToContent as Be, EngineError as Ge } from "./engine/index.js";
11
+ const Ke = /* @__PURE__ */ new Set([".astro", ".svelte", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".vue"]), He = /* @__PURE__ */ new Set([
12
12
  "node_modules",
13
13
  ".astro",
14
14
  ".svelte-kit",
@@ -20,7 +20,7 @@ const Be = /* @__PURE__ */ new Set([".astro", ".svelte", ".ts", ".tsx", ".js", "
20
20
  ".git",
21
21
  ".turbo"
22
22
  ]);
23
- async function Y(e, n) {
23
+ async function D(e, n) {
24
24
  const s = new RegExp(`import\\s*\\{([^}]+)\\}\\s*from\\s*["']okno[:/]${n}["']`, "g"), i = /* @__PURE__ */ new Set();
25
25
  async function u(c) {
26
26
  let p;
@@ -30,7 +30,7 @@ async function Y(e, n) {
30
30
  return;
31
31
  }
32
32
  for (const f of p) {
33
- if (f.name.startsWith(".") && f.name !== "." || Ge.has(f.name)) continue;
33
+ if (f.name.startsWith(".") && f.name !== "." || He.has(f.name)) continue;
34
34
  const a = _(c, f.name);
35
35
  if (f.isDirectory()) {
36
36
  await u(a);
@@ -38,18 +38,18 @@ async function Y(e, n) {
38
38
  }
39
39
  const t = f.name.lastIndexOf(".");
40
40
  if (t === -1) continue;
41
- const r = f.name.slice(t);
42
- if (!Be.has(r)) continue;
43
- let o;
41
+ const o = f.name.slice(t);
42
+ if (!Ke.has(o)) continue;
43
+ let r;
44
44
  try {
45
- o = await we(a, "utf-8");
45
+ r = await Se(a, "utf-8");
46
46
  } catch {
47
47
  continue;
48
48
  }
49
- if (!(!o.includes(`okno:${n}`) && !o.includes(`okno/${n}`)))
50
- for (const m of o.matchAll(s)) {
51
- const d = m[1] ?? "";
52
- for (const h of d.split(",")) {
49
+ if (!(!r.includes(`okno:${n}`) && !r.includes(`okno/${n}`)))
50
+ for (const d of r.matchAll(s)) {
51
+ const m = d[1] ?? "";
52
+ for (const h of m.split(",")) {
53
53
  const y = h.trim().split(/\s+as\s+/)[0]?.trim();
54
54
  y && /^[A-Za-z_$][\w$]*$/.test(y) && i.add(y);
55
55
  }
@@ -58,8 +58,8 @@ async function Y(e, n) {
58
58
  }
59
59
  return await u(e), i;
60
60
  }
61
- async function bt(e, n) {
62
- const s = await et(e), i = new Map(s.map((l) => [l.name, l.first])), u = Ye(e), c = [
61
+ async function St(e, n) {
62
+ const s = await nt(e), i = new Map(s.map((l) => [l.name, l.first])), u = et(e), c = [
63
63
  "// Auto-generated by okno. Do not edit.",
64
64
  "",
65
65
  "/** A wrapped content value that can be spread onto elements and rendered as text. */",
@@ -107,7 +107,7 @@ async function bt(e, n) {
107
107
  " : T extends { url: string; text: string }",
108
108
  " ? { href: string; target?: string; rel?: string } & OknoValue<T>",
109
109
  " : T extends Record<string, unknown>",
110
- ' ? { [K in keyof T]: K extends "href" ? string : OknoWrapped<T[K]> } & OknoValue<T>',
110
+ ' ? { [K in keyof T]: K extends "href" | "slug" ? string : OknoWrapped<T[K]> } & OknoValue<T>',
111
111
  " : OknoValue<T>",
112
112
  "",
113
113
  "/** Content referenced in code but not yet scaffolded — shape unknown, so every field is a flat leaf. Nested access (`home.hero.title`) is a type error on purpose: okno fields are flat (dividers organize the editor, they don't nest data). Use a Block for nested shapes. */",
@@ -123,48 +123,48 @@ async function bt(e, n) {
123
123
  ], p = ([, l]) => l?.type === "reference" && typeof l.collection == "string" && i.has(l.collection), f = ([, l]) => l?.type === "enum", a = ([l, g]) => {
124
124
  const k = (Array.isArray(g?.options) ? g.options : []).map((w) => typeof w == "string" ? w : w?.value).filter((w) => typeof w == "string"), S = `{ name: string; value: ${k.length ? k.map((w) => JSON.stringify(w)).join(" | ") : "string"} }`;
125
125
  return `${l}: ${g.multiple ? `${S}[]` : S}`;
126
- }, t = (l) => `typeof import("./collections/${l}/${i.get(l)}").default`, r = (l) => {
126
+ }, t = (l) => `typeof import("./collections/${l}/${i.get(l)}").default`, o = (l) => {
127
127
  const g = u?.collections?.[l]?.url;
128
128
  return typeof g == "string" && g.trim() ? " & { href: string }" : "";
129
- }, o = (l, g) => {
129
+ }, r = (l, g) => {
130
130
  const k = t(l), b = u?.collections?.[l]?.fields, S = b ? Object.entries(b) : [], w = S.filter(p), O = S.filter(f);
131
- if (w.length === 0 && O.length === 0) return `${k}${r(l)}`;
131
+ if (w.length === 0 && O.length === 0) return `${k}${o(l)}`;
132
132
  const j = [...w, ...O].map(([P]) => `"${P}"`).join(" | "), A = new Set(g).add(l), C = [
133
133
  ...w.map(([P, I]) => {
134
- const M = I.collection, x = g.has(M) ? t(M) : o(M, A);
134
+ const M = I.collection, x = g.has(M) ? t(M) : r(M, A);
135
135
  return `${P}: ${I.multiple ? `(${x})[]` : x}`;
136
136
  }),
137
137
  ...O.map(a)
138
138
  ].join("; ");
139
- return `Omit<${k}, ${j}> & { ${C} }${r(l)}`;
140
- }, m = (l, g, k) => {
141
- const b = `typeof import("${k}").default`, S = u?.[l]?.[g]?.fields, w = S ? Object.entries(S) : [], O = w.filter(p), j = w.filter(f), A = '"created" | "updated"', C = l === "collections" ? r(g) : "";
139
+ return `Omit<${k}, ${j}> & { ${C} }${o(l)}`;
140
+ }, d = (l, g, k) => {
141
+ const b = `typeof import("${k}").default`, S = u?.[l]?.[g]?.fields, w = S ? Object.entries(S) : [], O = w.filter(p), j = w.filter(f), A = '"created" | "updated"', C = l === "collections" ? o(g) : "";
142
142
  if (O.length === 0 && j.length === 0)
143
143
  return `OknoWrapped<Omit<${b}, ${A}>${C}> & OknoMeta`;
144
144
  const P = l === "collections" ? /* @__PURE__ */ new Set([g]) : /* @__PURE__ */ new Set(), I = `${[...O, ...j].map(([x]) => `"${x}"`).join(" | ")} | ${A}`, M = [
145
145
  ...O.map(([x, V]) => {
146
- const z = V.collection, ce = P.has(z) ? t(z) : o(z, P);
147
- return `${x}: ${V.multiple ? `(${ce})[]` : ce}`;
146
+ const z = V.collection, ue = P.has(z) ? t(z) : r(z, P);
147
+ return `${x}: ${V.multiple ? `(${ue})[]` : ue}`;
148
148
  }),
149
149
  ...j.map(a)
150
150
  ].join("; ");
151
151
  return `OknoWrapped<Omit<${b}, ${I}> & { ${M} }${C}> & OknoMeta`;
152
- }, [d, h, y] = await Promise.all([
153
- Y(n, "pages"),
154
- Y(n, "globals"),
155
- Y(n, "collections")
152
+ }, [m, h, y] = await Promise.all([
153
+ D(n, "pages"),
154
+ D(n, "globals"),
155
+ D(n, "collections")
156
156
  ]);
157
157
  c.push(
158
- ...de("okno:pages", "pages", await te(_(e, "pages")), d, m)
159
- ), c.push(...Qe(s, y, m)), c.push(
160
- ...de("okno:globals", "globals", await te(_(e, "globals")), h, m)
161
- ), c.push(...Ze(De(e), qe(u))), c.push(...Ke()), c.push(...He());
158
+ ...pe("okno:pages", "pages", await ne(_(e, "pages")), m, d)
159
+ ), c.push(...De(s, y, d)), c.push(
160
+ ...pe("okno:globals", "globals", await ne(_(e, "globals")), h, d)
161
+ ), c.push(...qe(tt(e), Ye(u))), c.push(...Ze()), c.push(...Xe());
162
162
  for (const l of ["pages", "collections", "globals", "locales", "strings", "content"])
163
163
  c.push(`declare module "okno/${l}" {`, ` export * from "okno:${l}";`, "}", "");
164
- await be(_(e, "modules.d.ts"), c.join(`
164
+ await Oe(_(e, "modules.d.ts"), c.join(`
165
165
  `));
166
166
  }
167
- function de(e, n, s, i, u) {
167
+ function pe(e, n, s, i, u) {
168
168
  const c = /* @__PURE__ */ new Set(), p = [];
169
169
  for (const f of s)
170
170
  p.push(` export const ${f}: ${u(n, f, `./${n}/${f}`)}`), c.add(f);
@@ -172,7 +172,7 @@ function de(e, n, s, i, u) {
172
172
  c.has(f) || p.push(` export const ${f}: OknoUnscaffolded`);
173
173
  return [`declare module "${e}" {`, ...p, "}", ""];
174
174
  }
175
- function Ke() {
175
+ function Ze() {
176
176
  return [
177
177
  'declare module "okno:locales" {',
178
178
  ' /** A configured language. `id` is the BCP-47 tag (e.g. "zh-Hant"), `name` the display label, `slug` the URL segment you map into routing. `link(url)` returns this page\'s hreflang <link> descriptor — spread onto a <link> (pass Astro.url for an absolute href). Okno owns no routing; you map these. */',
@@ -188,7 +188,7 @@ function Ke() {
188
188
  ""
189
189
  ];
190
190
  }
191
- function He() {
191
+ function Xe() {
192
192
  return [
193
193
  'declare module "okno:content" {',
194
194
  ' /** Unified content namespace — `import * as okno from "okno:content"` then `okno.pages.home`, `okno.globals.nav`, `okno.collections.articles`, `okno.strings.nav.home`. */',
@@ -200,8 +200,8 @@ function He() {
200
200
  ""
201
201
  ];
202
202
  }
203
- function Ze(e, n) {
204
- const s = e.length ? `${Xe(e, n)}` : "any", i = e.length ? `
203
+ function qe(e, n) {
204
+ const s = e.length ? `${Qe(e, n)}` : "any", i = e.length ? `
205
205
  locale(code?: string | null): ${s}` : "";
206
206
  return [
207
207
  'declare module "okno:strings" {',
@@ -212,7 +212,7 @@ function Ze(e, n) {
212
212
  ""
213
213
  ];
214
214
  }
215
- function Xe(e, n) {
215
+ function Qe(e, n) {
216
216
  const s = { children: /* @__PURE__ */ new Map() };
217
217
  for (const p of e) {
218
218
  let f = s;
@@ -223,13 +223,13 @@ function Xe(e, n) {
223
223
  }
224
224
  const i = (p) => p === "text" ? "string" : "number", u = (p) => {
225
225
  const f = n[p];
226
- return !f || Object.keys(f).length === 0 ? "OknoValue<string>" : `(p: { ${Object.entries(f).map(([t, r]) => `${JSON.stringify(t)}: ${i(r)}`).join("; ")} }) => OknoValue<string>`;
226
+ return !f || Object.keys(f).length === 0 ? "OknoValue<string>" : `(p: { ${Object.entries(f).map(([t, o]) => `${JSON.stringify(t)}: ${i(o)}`).join("; ")} }) => OknoValue<string>`;
227
227
  }, c = (p, f) => p.children.size === 0 ? u(f) : `{ ${[...p.children.entries()].map(
228
- ([t, r]) => `${JSON.stringify(t)}: ${c(r, f ? `${f}.${t}` : t)}`
228
+ ([t, o]) => `${JSON.stringify(t)}: ${c(o, f ? `${f}.${t}` : t)}`
229
229
  ).join("; ")} }`;
230
230
  return c(s, "");
231
231
  }
232
- function qe(e) {
232
+ function Ye(e) {
233
233
  const n = {}, s = e?.strings;
234
234
  if (!s || typeof s != "object" || Array.isArray(s)) return n;
235
235
  for (const [i, u] of Object.entries(s)) {
@@ -242,7 +242,7 @@ function qe(e) {
242
242
  }
243
243
  return n;
244
244
  }
245
- function Qe(e, n, s) {
245
+ function De(e, n, s) {
246
246
  const i = /* @__PURE__ */ new Set(), u = [];
247
247
  for (const c of e) {
248
248
  const p = s("collections", c.name, `./collections/${c.name}/${c.first}`);
@@ -252,7 +252,7 @@ function Qe(e, n, s) {
252
252
  i.has(c) || u.push(` export const ${c}: OknoUnscaffolded[]`);
253
253
  return ['declare module "okno:collections" {', ...u, "}", ""];
254
254
  }
255
- function Ye(e) {
255
+ function et(e) {
256
256
  const n = _(e, "schema.ts");
257
257
  if (!$(n)) return null;
258
258
  try {
@@ -263,7 +263,7 @@ function Ye(e) {
263
263
  return null;
264
264
  }
265
265
  }
266
- function De(e) {
266
+ function tt(e) {
267
267
  const n = _(e, "strings.ts");
268
268
  if (!$(n)) return [];
269
269
  try {
@@ -277,28 +277,28 @@ function De(e) {
277
277
  return [];
278
278
  }
279
279
  }
280
- async function et(e) {
280
+ async function nt(e) {
281
281
  const n = _(e, "collections");
282
282
  if (!$(n)) return [];
283
283
  const s = (await E(n, { withFileTypes: !0 })).filter((u) => u.isDirectory()), i = [];
284
284
  for (const u of s) {
285
- const c = await te(_(n, u.name));
285
+ const c = await ne(_(n, u.name));
286
286
  c.length > 0 && i.push({ name: u.name, first: c[0] });
287
287
  }
288
288
  return i;
289
289
  }
290
- async function te(e) {
290
+ async function ne(e) {
291
291
  return $(e) ? (await E(e)).filter((s) => s.endsWith(".ts") && s !== "index.ts" && s !== "modules.d.ts").map((s) => s.replace(".ts", "")) : [];
292
292
  }
293
- function re(e) {
293
+ function ae(e) {
294
294
  try {
295
- return oe(e, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
295
+ return re(e, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
296
296
  } catch {
297
297
  return null;
298
298
  }
299
299
  }
300
- function tt() {
301
- const e = re("git rev-parse --abbrev-ref HEAD");
300
+ function st() {
301
+ const e = ae("git rev-parse --abbrev-ref HEAD");
302
302
  if (e && e !== "HEAD") return e;
303
303
  const n = process.env;
304
304
  return n.CF_PAGES_BRANCH || // Cloudflare Pages
@@ -307,28 +307,35 @@ function tt() {
307
307
  n.GITHUB_REF_NAME || // GitHub Actions
308
308
  "main";
309
309
  }
310
- function St() {
311
- const e = re("git remote get-url origin");
310
+ function Ot() {
311
+ const e = ae("git remote get-url origin");
312
312
  if (!e) return null;
313
313
  const n = e.match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/);
314
- return n ? `${n[1]}/${n[2]}@${tt()}` : null;
314
+ return n ? `${n[1]}/${n[2]}@${st()}` : null;
315
315
  }
316
- function Ot() {
317
- const e = re("git rev-parse --show-toplevel");
316
+ function vt() {
317
+ const e = ae("git rev-parse --show-toplevel");
318
318
  return e ? H(e, process.cwd()).split(U).join("/") : "";
319
319
  }
320
- const ae = '__oknoSetImages(import.meta.glob("/okno/files/**/*.{png,jpg,jpeg,webp,avif,gif,svg,tiff}", { eager: false }))', pe = N(je(import.meta.url)), nt = [
321
- ue(pe, "./runtime/wrap.js"),
320
+ const ie = '__oknoSetImages(import.meta.glob("/okno/files/**/*.{png,jpg,jpeg,webp,avif,gif,svg,tiff}", { eager: false }))', he = N(Te(import.meta.url)), $e = [
321
+ fe(he, "./runtime/wrap.js"),
322
322
  // bundled at dist/ (Vite plugin chunk)
323
- ue(pe, "../runtime/wrap.js")
323
+ fe(he, "../runtime/wrap.js")
324
324
  // bundled at dist/next/ (Next entry)
325
325
  ];
326
- function vt() {
327
- for (const e of nt)
326
+ function jt() {
327
+ for (const e of $e)
328
328
  if ($(e)) return v(e, "utf-8");
329
329
  return null;
330
330
  }
331
- function jt() {
331
+ function At() {
332
+ for (const e of $e) {
333
+ const n = e.replace(/wrap\.js$/, "instant.js");
334
+ if ($(n)) return v(n, "utf-8");
335
+ }
336
+ return null;
337
+ }
338
+ function Tt() {
332
339
  return [
333
340
  'export * as pages from "okno:pages"',
334
341
  'export * as globals from "okno:globals"',
@@ -337,7 +344,7 @@ function jt() {
337
344
  ].join(`
338
345
  `);
339
346
  }
340
- function q(e) {
347
+ function Q(e) {
341
348
  const n = _(e, "schema.ts");
342
349
  if (!$(n)) return null;
343
350
  try {
@@ -350,9 +357,9 @@ function q(e) {
350
357
  }
351
358
  }
352
359
  function K(e, n) {
353
- return n ? n.has(e) : rt.test(e);
360
+ return n ? n.has(e) : at.test(e);
354
361
  }
355
- function st(e) {
362
+ function ot(e) {
356
363
  for (const n of [e, "en"])
357
364
  try {
358
365
  const s = new Intl.DisplayNames([n], { type: "language" }).of(e);
@@ -361,10 +368,10 @@ function st(e) {
361
368
  }
362
369
  return e;
363
370
  }
364
- async function ie(e) {
371
+ async function le(e) {
365
372
  return $(e) ? (await E(e)).filter((s) => s.endsWith(".ts") && s !== "index.ts") : [];
366
373
  }
367
- function ot(e) {
374
+ function rt(e) {
368
375
  const n = _(e, "schema.ts"), s = {}, i = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set();
369
376
  if (!$(n)) return { orders: s, draftsOff: i, schedulingOff: u };
370
377
  try {
@@ -375,17 +382,17 @@ function ot(e) {
375
382
  }
376
383
  return { orders: s, draftsOff: i, schedulingOff: u };
377
384
  }
378
- const rt = /^[a-z]{2,3}(-[a-z]{4})?(-([a-z]{2}|[0-9]{3}))?$/i, Q = (e) => e.replace(/[^a-zA-Z0-9]/g, "_");
379
- function le(e) {
385
+ const at = /^[a-z]{2,3}(-[a-z]{4})?(-([a-z]{2}|[0-9]{3}))?$/i, Y = (e) => e.replace(/[^a-zA-Z0-9]/g, "_");
386
+ function ce(e) {
380
387
  return e.replace(".ts", "").replace(/-/g, "_");
381
388
  }
382
- function ye(e) {
389
+ function ke(e) {
383
390
  return e.replace(".ts", "").replace(/-/g, "_");
384
391
  }
385
- function X(e) {
392
+ function q(e) {
386
393
  return e.replace(".ts", "");
387
394
  }
388
- function At(e) {
395
+ function xt(e) {
389
396
  const n = _(e, "schema.ts");
390
397
  let s = [], i = "";
391
398
  if ($(n))
@@ -393,7 +400,7 @@ function At(e) {
393
400
  const u = Z(v(n, "utf-8")), c = u?.locales?.supported;
394
401
  Array.isArray(c) && (s = c.map((p) => typeof p == "string" ? { id: p } : p).filter((p) => !!p && typeof p.id == "string").map((p) => ({
395
402
  id: p.id,
396
- name: p.name || st(p.id),
403
+ name: p.name || ot(p.id),
397
404
  // Preserve an intentionally empty slug (= no URL prefix for the default).
398
405
  slug: typeof p.slug == "string" ? p.slug : p.id.toLowerCase()
399
406
  })), i = typeof u.locales.default == "string" ? u.locales.default : s[0]?.id ?? "");
@@ -427,7 +434,7 @@ function At(e) {
427
434
  ].join(`
428
435
  `);
429
436
  }
430
- async function Tt(e) {
437
+ async function Rt(e) {
431
438
  const n = _(e, "strings.ts");
432
439
  if (!$(n))
433
440
  return [
@@ -435,13 +442,13 @@ async function Tt(e) {
435
442
  'export const strings = __oknoMakeStrings({}, {}, "")'
436
443
  ].join(`
437
444
  `);
438
- const s = _(e, "schema.ts"), i = $(s), u = q(e), c = _(e, "strings"), p = [];
445
+ const s = _(e, "schema.ts"), i = $(s), u = Q(e), c = _(e, "strings"), p = [];
439
446
  if ($(c)) {
440
- const o = await E(c, { withFileTypes: !0 });
441
- for (const m of o) {
442
- if (!m.isFile() || !m.name.endsWith(".ts") || m.name === "index.ts") continue;
443
- const d = m.name.replace(/\.ts$/, "");
444
- K(d, u) && p.push(d);
447
+ const r = await E(c, { withFileTypes: !0 });
448
+ for (const d of r) {
449
+ if (!d.isFile() || !d.name.endsWith(".ts") || d.name === "index.ts") continue;
450
+ const m = d.name.replace(/\.ts$/, "");
451
+ K(m, u) && p.push(m);
445
452
  }
446
453
  }
447
454
  const f = [
@@ -453,41 +460,41 @@ async function Tt(e) {
453
460
  if (p.length === 0)
454
461
  return f.push(`export const strings = __oknoMakeStrings(__oknoExpandStrings(_strings_default), ${a}, ${t})`), f.join(`
455
462
  `);
456
- const r = [];
457
- for (const o of p) {
458
- const m = Q(o);
459
- f.push(`import _strings_${m} from "${_(c, o + ".ts")}"`), r.push(`"${o}": __oknoExpandStrings(_strings_${m})`);
463
+ const o = [];
464
+ for (const r of p) {
465
+ const d = Y(r);
466
+ f.push(`import _strings_${d} from "${_(c, r + ".ts")}"`), o.push(`"${r}": __oknoExpandStrings(_strings_${d})`);
460
467
  }
461
- return f.push("const _strings_base = __oknoExpandStrings(_strings_default)"), f.push(`const _strings_localized = __oknoLocalize(_strings_base, { ${r.join(", ")} })`), f.push(`export const strings = __oknoMakeStrings(_strings_localized, ${a}, ${t})`), f.join(`
468
+ return f.push("const _strings_base = __oknoExpandStrings(_strings_default)"), f.push(`const _strings_localized = __oknoLocalize(_strings_base, { ${o.join(", ")} })`), f.push(`export const strings = __oknoMakeStrings(_strings_localized, ${a}, ${t})`), f.join(`
462
469
  `);
463
470
  }
464
- async function xt(e, n = /* @__PURE__ */ new Set()) {
471
+ async function Pt(e, n = /* @__PURE__ */ new Set()) {
465
472
  const s = _(e, "pages"), i = _(e, "schema.ts"), u = $(i), c = [
466
473
  'import { __oknoWrap, __oknoLocalize, __oknoResolveRefs, __oknoResolveEnums, __oknoSetImages, __oknoSetRoutes } from "okno:runtime"',
467
- ae
474
+ ie
468
475
  ];
469
476
  u && (c.push('import * as __collections from "okno:collections"'), c.push(`import __schema from "${i}"`), c.push("__oknoSetRoutes(__schema)"));
470
477
  let p = "[]";
471
- const f = (t, r) => {
478
+ const f = (t, o) => {
472
479
  if (!u) return `_${t}`;
473
- const o = `__schema?.pages?.["${r}"]?.fields`;
474
- return `__oknoResolveEnums(__oknoResolveRefs(_${t}, ${o}, __collections, ${p}), ${o}, ${p})`;
480
+ const r = `__schema?.pages?.["${o}"]?.fields`;
481
+ return `__oknoResolveEnums(__oknoResolveRefs(_${t}, ${r}, __collections, ${p}), ${r}, ${p})`;
475
482
  }, a = /* @__PURE__ */ new Set();
476
483
  if ($(s)) {
477
- const t = q(e), o = (await E(s, { withFileTypes: !0 })).filter((d) => d.isDirectory() && K(d.name, t)).map((d) => d.name);
478
- p = JSON.stringify(o);
479
- const m = await ie(s);
480
- for (const d of m) {
481
- const h = le(d), y = ye(d), l = X(d), g = _(s, d);
482
- if (o.length === 0) {
484
+ const t = Q(e), r = (await E(s, { withFileTypes: !0 })).filter((m) => m.isDirectory() && K(m.name, t)).map((m) => m.name);
485
+ p = JSON.stringify(r);
486
+ const d = await le(s);
487
+ for (const m of d) {
488
+ const h = ce(m), y = ke(m), l = q(m), g = _(s, m);
489
+ if (r.length === 0) {
483
490
  c.push(`import _${h} from "${g}"`), c.push(`export const ${y} = __oknoWrap(${f(h, l)}, "${l}")`), a.add(y);
484
491
  continue;
485
492
  }
486
493
  const k = [`import _${h}_default from "${g}"`], b = [];
487
- for (const S of o) {
488
- const w = _(s, S, d);
494
+ for (const S of r) {
495
+ const w = _(s, S, m);
489
496
  if ($(w)) {
490
- const O = Q(S);
497
+ const O = Y(S);
491
498
  k.push(`import _${h}_${O} from "${w}"`), b.push(`"${S}": _${h}_${O}`);
492
499
  }
493
500
  }
@@ -499,7 +506,7 @@ async function xt(e, n = /* @__PURE__ */ new Set()) {
499
506
  return c.join(`
500
507
  `);
501
508
  }
502
- async function Rt(e, n = /* @__PURE__ */ new Set(), s = !1) {
509
+ async function Et(e, n = /* @__PURE__ */ new Set(), s = !1) {
503
510
  const i = _(e, "collections");
504
511
  if (!$(i)) {
505
512
  const l = [];
@@ -510,7 +517,7 @@ async function Rt(e, n = /* @__PURE__ */ new Set(), s = !1) {
510
517
  return l.join(`
511
518
  `) || "export {}";
512
519
  }
513
- const u = q(e), c = await E(i, { withFileTypes: !0 }), p = c.filter((l) => l.isDirectory() && K(l.name, u)).map((l) => l.name), f = c.filter((l) => l.isDirectory() && !p.includes(l.name)).map((l) => l.name), a = JSON.stringify(p);
520
+ const u = Q(e), c = await E(i, { withFileTypes: !0 }), p = c.filter((l) => l.isDirectory() && K(l.name, u)).map((l) => l.name), f = c.filter((l) => l.isDirectory() && !p.includes(l.name)).map((l) => l.name), a = JSON.stringify(p);
514
521
  for (const l of f) {
515
522
  const g = await E(_(i, l), { withFileTypes: !0 }).catch(() => []);
516
523
  for (const k of g)
@@ -518,16 +525,16 @@ async function Rt(e, n = /* @__PURE__ */ new Set(), s = !1) {
518
525
  `[okno] "collections/${l}/${k.name}/" looks like a misplaced locale folder. Collection locale overrides go at "collections/${k.name}/${l}/<slug>.ts" (locale right after "collections/"). This folder will NOT be localized.`
519
526
  );
520
527
  }
521
- const { orders: t, draftsOff: r, schedulingOff: o } = ot(e), m = _(e, "schema.ts"), d = $(m), h = [
528
+ const { orders: t, draftsOff: o, schedulingOff: r } = rt(e), d = _(e, "schema.ts"), m = $(d), h = [
522
529
  'import { __oknoWrap, __oknoLocalize, __oknoResolveRefs, __oknoResolveEnums, __oknoSetImages, __oknoSetRoutes, __oknoVisible } from "okno:runtime"',
523
- ae
530
+ ie
524
531
  ];
525
- d && (h.push(`import __schema from "${m}"`), h.push("__oknoSetRoutes(__schema)"));
532
+ m && (h.push(`import __schema from "${d}"`), h.push("__oknoSetRoutes(__schema)"));
526
533
  const y = [];
527
534
  for (const l of f) {
528
- const g = _(i, l), k = Ae(await ie(g), X, t[l]), b = l.replace(/-/g, "_"), S = s && !r.has(l), w = s && !o.has(l), O = [];
535
+ const g = _(i, l), k = xe(await le(g), q, t[l]), b = l.replace(/-/g, "_"), S = s && !o.has(l), w = s && !r.has(l), O = [];
529
536
  for (const j of k) {
530
- const A = `_${b}_${le(j)}`, C = X(j), P = _(g, j);
537
+ const A = `_${b}_${ce(j)}`, C = q(j), P = _(g, j);
531
538
  if (p.length === 0)
532
539
  h.push(`import ${A} from "${P}"`);
533
540
  else {
@@ -535,7 +542,7 @@ async function Rt(e, n = /* @__PURE__ */ new Set(), s = !1) {
535
542
  for (const x of p) {
536
543
  const V = _(i, x, l, j);
537
544
  if ($(V)) {
538
- const z = Q(x);
545
+ const z = Y(x);
539
546
  I.push(`import ${A}_${z} from "${V}"`), M.push(`"${x}": ${A}_${z}`);
540
547
  }
541
548
  }
@@ -545,9 +552,9 @@ async function Rt(e, n = /* @__PURE__ */ new Set(), s = !1) {
545
552
  }
546
553
  h.push(`const __oknoRaw_${b} = [${O.map((j) => j.varName).join(", ")}]`), y.push({ name: l, safe: b, draftsOn: S, schedulingOn: w, items: O });
547
554
  }
548
- d && h.push(`const __oknoNs = { ${y.map((l) => `${l.safe}: __oknoRaw_${l.safe}`).join(", ")} }`);
555
+ m && h.push(`const __oknoNs = { ${y.map((l) => `${l.safe}: __oknoRaw_${l.safe}`).join(", ")} }`);
549
556
  for (const l of y) {
550
- const g = `__schema?.collections?.["${l.name}"]?.fields`, k = (w) => d ? `__oknoResolveEnums(__oknoResolveRefs(${w.varName}, ${g}, __oknoNs, ${a}), ${g}, ${a})` : w.varName, b = [];
557
+ const g = `__schema?.collections?.["${l.name}"]?.fields`, k = (w) => m ? `__oknoResolveEnums(__oknoResolveRefs(${w.varName}, ${g}, __oknoNs, ${a}), ${g}, ${a})` : w.varName, b = [];
551
558
  l.draftsOn && b.push('e[0]?.status !== "draft"'), l.schedulingOn && b.push("__oknoVisible(e[0])");
552
559
  const S = b.length ? `[${l.items.map((w) => `[${w.varName}, ${k(w)}, ${JSON.stringify(w.itemName)}]`).join(", ")}].filter((e) => ${b.join(" && ")}).map((e, __i) => __oknoWrap(e[1], "${l.name}." + e[2], "${l.name}." + __i))` : `[${l.items.map((w, O) => `__oknoWrap(${k(w)}, "${l.name}.${w.itemName}", "${l.name}.${O}")`).join(", ")}]`;
553
560
  h.push(`export const ${l.safe} = ${S}`);
@@ -555,33 +562,33 @@ async function Rt(e, n = /* @__PURE__ */ new Set(), s = !1) {
555
562
  return h.join(`
556
563
  `);
557
564
  }
558
- async function Pt(e, n = /* @__PURE__ */ new Set()) {
565
+ async function Mt(e, n = /* @__PURE__ */ new Set()) {
559
566
  const s = _(e, "globals"), i = _(e, "schema.ts"), u = $(i), c = [
560
567
  'import { __oknoWrap, __oknoLocalize, __oknoResolveRefs, __oknoResolveEnums, __oknoSetImages, __oknoSetRoutes } from "okno:runtime"',
561
- ae
568
+ ie
562
569
  ];
563
570
  u && (c.push('import * as __collections from "okno:collections"'), c.push(`import __schema from "${i}"`), c.push("__oknoSetRoutes(__schema)"));
564
571
  let p = "[]";
565
- const f = (t, r) => {
572
+ const f = (t, o) => {
566
573
  if (!u) return `_${t}`;
567
- const o = `__schema?.globals?.["${r}"]?.fields`;
568
- return `__oknoResolveEnums(__oknoResolveRefs(_${t}, ${o}, __collections, ${p}), ${o}, ${p})`;
574
+ const r = `__schema?.globals?.["${o}"]?.fields`;
575
+ return `__oknoResolveEnums(__oknoResolveRefs(_${t}, ${r}, __collections, ${p}), ${r}, ${p})`;
569
576
  }, a = /* @__PURE__ */ new Set();
570
577
  if ($(s)) {
571
- const t = q(e), o = (await E(s, { withFileTypes: !0 })).filter((d) => d.isDirectory() && K(d.name, t)).map((d) => d.name);
572
- p = JSON.stringify(o);
573
- const m = await ie(s);
574
- for (const d of m) {
575
- const h = le(d), y = ye(d), l = X(d), g = _(s, d);
576
- if (o.length === 0) {
578
+ const t = Q(e), r = (await E(s, { withFileTypes: !0 })).filter((m) => m.isDirectory() && K(m.name, t)).map((m) => m.name);
579
+ p = JSON.stringify(r);
580
+ const d = await le(s);
581
+ for (const m of d) {
582
+ const h = ce(m), y = ke(m), l = q(m), g = _(s, m);
583
+ if (r.length === 0) {
577
584
  c.push(`import _${h} from "${g}"`), c.push(`export const ${y} = __oknoWrap(${f(h, l)}, "${l}")`), a.add(y);
578
585
  continue;
579
586
  }
580
587
  const k = [`import _${h}_default from "${g}"`], b = [];
581
- for (const S of o) {
582
- const w = _(s, S, d);
588
+ for (const S of r) {
589
+ const w = _(s, S, m);
583
590
  if ($(w)) {
584
- const O = Q(S);
591
+ const O = Y(S);
585
592
  k.push(`import _${h}_${O} from "${w}"`), b.push(`"${S}": _${h}_${O}`);
586
593
  }
587
594
  }
@@ -593,15 +600,15 @@ async function Pt(e, n = /* @__PURE__ */ new Set()) {
593
600
  return c.join(`
594
601
  `);
595
602
  }
596
- const $e = /* @__PURE__ */ new Map();
603
+ const we = /* @__PURE__ */ new Map();
597
604
  function L(e) {
598
- $e.set(e, Date.now());
605
+ we.set(e, Date.now());
599
606
  }
600
- function Et(e) {
601
- const n = $e.get(e);
607
+ function Nt(e) {
608
+ const n = we.get(e);
602
609
  return n !== void 0 && Date.now() - n < 3e3;
603
610
  }
604
- const at = ["pages", "collections", "globals"];
611
+ const it = ["pages", "collections", "globals"];
605
612
  function F(e, n) {
606
613
  if (!n || n.includes("..") || n.includes("\0") || n.startsWith("/") || !n.endsWith(".ts")) return null;
607
614
  const s = _(e, n);
@@ -612,10 +619,10 @@ function J(e, n) {
612
619
  const s = _(e, n);
613
620
  return s !== e && !s.startsWith(e + U) ? null : s;
614
621
  }
615
- function it(e) {
622
+ function lt(e) {
616
623
  const n = {}, s = (u) => {
617
624
  if ($(u))
618
- for (const c of se(u, { withFileTypes: !0 })) {
625
+ for (const c of oe(u, { withFileTypes: !0 })) {
619
626
  const p = _(u, c.name);
620
627
  if (c.isDirectory()) s(p);
621
628
  else if (c.name.endsWith(".ts") && c.name !== "index.ts") {
@@ -624,35 +631,35 @@ function it(e) {
624
631
  }
625
632
  }
626
633
  };
627
- for (const u of at) s(_(e, u));
634
+ for (const u of it) s(_(e, u));
628
635
  const i = _(e, "strings.ts");
629
636
  return $(i) && (n["strings.ts"] = v(i, "utf-8")), s(_(e, "strings")), n;
630
637
  }
631
- function ke(e) {
638
+ function be(e) {
632
639
  const n = _(e, "files"), s = [], i = (u) => {
633
640
  if ($(u))
634
- for (const c of se(u, { withFileTypes: !0 })) {
641
+ for (const c of oe(u, { withFileTypes: !0 })) {
635
642
  const p = _(u, c.name);
636
643
  if (c.isDirectory()) i(p);
637
644
  else if (c.name !== ".okno-tree.json") {
638
645
  const f = H(n, p).split(U).join("/");
639
- s.push({ path: `files/${f}`, filename: c.name, size: Se(p).size });
646
+ s.push({ path: `files/${f}`, filename: c.name, size: ve(p).size });
640
647
  }
641
648
  }
642
649
  };
643
650
  return i(n), s;
644
651
  }
645
- function lt(e) {
652
+ function ct(e) {
646
653
  const n = _(e, "schema.ts"), s = _(e, "users.json"), i = _(e, "origins.json");
647
654
  return {
648
655
  schema: $(n) ? v(n, "utf-8") : null,
649
656
  users: $(s) ? v(s, "utf-8") : null,
650
657
  origins: $(i) ? v(i, "utf-8") : null,
651
- content: it(e),
652
- files: ke(e)
658
+ content: lt(e),
659
+ files: be(e)
653
660
  };
654
661
  }
655
- const he = (e) => e.replace(/[^a-zA-Z0-9._-]/g, "-"), ge = (e) => e.split("/").map((n) => n.replace(/[^a-zA-Z0-9._-]/g, "-")).filter((n) => n && n !== "-" && n !== "..").join("/");
662
+ const ge = (e) => e.replace(/[^a-zA-Z0-9._-]/g, "-"), _e = (e) => e.split("/").map((n) => n.replace(/[^a-zA-Z0-9._-]/g, "-")).filter((n) => n && n !== "-" && n !== "..").join("/");
656
663
  function T(e) {
657
664
  const n = _(e, "schema.ts");
658
665
  let s = `import type { Schema } from "okno"
@@ -669,206 +676,209 @@ function T(e) {
669
676
  }
670
677
  return { schema: i, header: s };
671
678
  }
672
- function ct(e, n, s) {
673
- R(_(e, "schema.ts"), Te(n, s));
679
+ function ut(e, n, s) {
680
+ R(_(e, "schema.ts"), Re(n, s));
674
681
  }
675
- function ut(e, n, s, i, u) {
682
+ function ft(e, n, s, i, u) {
676
683
  const c = _(e, n), p = new Set(u), f = [];
677
684
  if (!$(c) || Object.keys(i).length === 0 && p.size === 0) return f;
678
- const a = [], t = (r) => {
679
- for (const o of se(r, { withFileTypes: !0 })) {
680
- const m = _(r, o.name);
681
- o.isDirectory() ? t(m) : o.name === `${s}.ts` && a.push(m);
685
+ const a = [], t = (o) => {
686
+ for (const r of oe(o, { withFileTypes: !0 })) {
687
+ const d = _(o, r.name);
688
+ r.isDirectory() ? t(d) : r.name === `${s}.ts` && a.push(d);
682
689
  }
683
690
  };
684
691
  t(c);
685
- for (const r of a) {
686
- let o;
692
+ for (const o of a) {
693
+ let r;
687
694
  try {
688
- o = Z(v(r, "utf-8"));
695
+ r = Z(v(o, "utf-8"));
689
696
  } catch {
690
697
  continue;
691
698
  }
692
- let m, d = !1;
693
- if (Array.isArray(o))
694
- m = o.map((y) => {
699
+ let d, m = !1;
700
+ if (Array.isArray(r))
701
+ d = r.map((y) => {
695
702
  if (y && typeof y == "object" && !Array.isArray(y)) {
696
703
  const l = me(y, i, p);
697
- return l.changed && (d = !0), l.out;
704
+ return l.changed && (m = !0), l.out;
698
705
  }
699
706
  return y;
700
707
  });
701
- else if (o && typeof o == "object") {
702
- const y = me(o, i, p);
703
- m = y.out, d = y.changed;
708
+ else if (r && typeof r == "object") {
709
+ const y = me(r, i, p);
710
+ d = y.out, m = y.changed;
704
711
  } else
705
712
  continue;
706
- if (!d) continue;
707
- L(r), R(r, ee(m));
708
- const h = H(e, r).split(U).join("/");
709
- f.push({ rel: h, abs: r }), console.log(`[okno] field-change migrated content: ${h}`, { renames: i, deletes: u });
713
+ if (!m) continue;
714
+ L(o), R(o, te(d));
715
+ const h = H(e, o).split(U).join("/");
716
+ f.push({ rel: h, abs: o }), console.log(`[okno] field-change migrated content: ${h}`, { renames: i, deletes: u });
710
717
  }
711
718
  return f;
712
719
  }
713
- let D;
714
- function ne(e) {
715
- return D || (D = oe("git rev-parse --show-toplevel", { cwd: e, encoding: "utf-8" }).trim()), D;
720
+ let ee;
721
+ function se(e) {
722
+ return ee || (ee = re("git rev-parse --show-toplevel", { cwd: e, encoding: "utf-8" }).trim()), ee;
716
723
  }
717
- function _e(e) {
718
- return H(ne(e), Oe(e)).split(U).join("/");
724
+ function ye(e) {
725
+ return H(se(e), je(e)).split(U).join("/");
719
726
  }
720
727
  let G;
721
- function ft(e) {
728
+ function dt(e) {
722
729
  if (G !== void 0) return G;
723
730
  try {
724
- G = oe("git config user.name", { cwd: e, encoding: "utf-8" }).trim() || "local";
731
+ G = re("git config user.name", { cwd: e, encoding: "utf-8" }).trim() || "local";
725
732
  } catch {
726
733
  G = "local";
727
734
  }
728
735
  return G;
729
736
  }
730
- async function Mt(e, n) {
731
- const { method: s, route: i } = n, u = { files: [], modules: [] }, c = (t, r) => {
732
- const o = t.split("/")[0];
733
- o !== "pages" && o !== "collections" && o !== "globals" || (u.modules.push(o), u.files.push(r));
734
- }, p = () => u.modules.push("pages", "collections", "globals"), f = (t, r) => {
735
- ct(e, t, r), p();
736
- }, a = (t, r) => ({ status: t, body: r, invalidation: u });
737
+ function X(e) {
738
+ return e.startsWith("files/") && e.length > 6;
739
+ }
740
+ async function It(e, n) {
741
+ const { method: s, route: i } = n, u = { files: [], modules: [] }, c = (t, o) => {
742
+ const r = t.split("/")[0];
743
+ r !== "pages" && r !== "collections" && r !== "globals" || (u.modules.push(r), u.files.push(o));
744
+ }, p = () => u.modules.push("pages", "collections", "globals"), f = (t, o) => {
745
+ ut(e, t, o), p();
746
+ }, a = (t, o) => ({ status: t, body: o, invalidation: u });
737
747
  try {
738
- if (s === "GET" && i === "content") return a(200, lt(e));
748
+ if (s === "GET" && i === "content") return a(200, ct(e));
739
749
  if (s === "POST" && i === "content/save") {
740
- const { path: t, content: r, created: o, author: m } = await n.json();
741
- if (!t || !r) return a(400, { error: "Missing path or content" });
742
- const d = F(e, t);
743
- if (!d) return a(400, { error: "Invalid path" });
744
- const h = xe(r, { now: (/* @__PURE__ */ new Date()).toISOString(), author: m || ft(e), created: o });
745
- return W(N(d), { recursive: !0 }), L(d), R(d, h), c(t, d), a(200, { ok: !0, commit: { fileSha: "" } });
750
+ const { path: t, content: o, created: r, author: d } = await n.json();
751
+ if (!t || !o) return a(400, { error: "Missing path or content" });
752
+ const m = F(e, t);
753
+ if (!m) return a(400, { error: "Invalid path" });
754
+ const h = Pe(o, { now: (/* @__PURE__ */ new Date()).toISOString(), author: d || dt(e), created: r });
755
+ return W(N(m), { recursive: !0 }), L(m), R(m, h), c(t, m), a(200, { ok: !0, commit: { fileSha: "" } });
746
756
  }
747
757
  if (s === "POST" && i === "content/delete") {
748
758
  const t = (await n.json())?.path;
749
759
  if (!t) return a(400, { error: "Missing path" });
750
- const r = F(e, t);
751
- return r ? ($(r) && (B(r), c(t, r)), a(200, { ok: !0 })) : a(400, { error: "Invalid path" });
760
+ const o = F(e, t);
761
+ return o ? ($(o) && (B(o), c(t, o)), a(200, { ok: !0 })) : a(400, { error: "Invalid path" });
752
762
  }
753
763
  if (s === "POST" && i === "strings/save") {
754
- const { path: t, content: r } = await n.json();
755
- if (!t || !r || typeof r != "object") return a(400, { error: "Missing path or content" });
764
+ const { path: t, content: o } = await n.json();
765
+ if (!t || !o || typeof o != "object") return a(400, { error: "Missing path or content" });
756
766
  if (t !== "strings.ts" && !/^strings\/[^/]+\.ts$/.test(t)) return a(400, { error: "Invalid strings path" });
757
- const o = F(e, t);
758
- return o ? (W(N(o), { recursive: !0 }), L(o), R(o, ee(r)), u.modules.push("strings", "content"), u.files.push(o), a(200, { ok: !0, commit: { fileSha: "" } })) : a(400, { error: "Invalid path" });
767
+ const r = F(e, t);
768
+ return r ? (W(N(r), { recursive: !0 }), L(r), R(r, te(o)), u.modules.push("strings", "content"), u.files.push(r), a(200, { ok: !0, commit: { fileSha: "" } })) : a(400, { error: "Invalid path" });
759
769
  }
760
770
  if (s === "POST" && i === "strings/set-schema") {
761
771
  const { strings: t } = await n.json();
762
772
  if (t != null && (typeof t != "object" || Array.isArray(t))) return a(400, { error: "Invalid strings" });
763
- const { schema: r, header: o } = T(e);
764
- return Re(r, t), f(r, o), u.modules.push("strings", "content"), a(200, { ok: !0, commit: { fileSha: "" }, schema: r });
773
+ const { schema: o, header: r } = T(e);
774
+ return Ee(o, t), f(o, r), u.modules.push("strings", "content"), a(200, { ok: !0, commit: { fileSha: "" }, schema: o });
765
775
  }
766
776
  if (s === "GET" && i === "publish-state")
767
777
  try {
768
- const t = fe(ne(e)), r = await t.status(), o = _e(e), m = (l) => l.startsWith(o + "/"), d = r.files.map((l) => l.path).filter(m);
778
+ const t = de(se(e)), o = await t.status(), r = ye(e), d = (l) => l.startsWith(r + "/"), m = o.files.map((l) => l.path).filter(d);
769
779
  let h = [];
770
- if (r.ahead > 0)
780
+ if (o.ahead > 0)
771
781
  try {
772
- h = (await t.raw(["diff", "--name-only", "@{u}...HEAD", "--", o])).split(`
782
+ h = (await t.raw(["diff", "--name-only", "@{u}...HEAD", "--", r])).split(`
773
783
  `).map((g) => g.trim()).filter(Boolean);
774
784
  } catch {
775
785
  }
776
- const y = Array.from(/* @__PURE__ */ new Set([...d, ...h]));
777
- return a(200, { pendingPublish: d.length > 0 || r.ahead > 0, changed: y });
786
+ const y = Array.from(/* @__PURE__ */ new Set([...m, ...h]));
787
+ return a(200, { pendingPublish: m.length > 0 || o.ahead > 0, changed: y });
778
788
  } catch {
779
789
  return a(200, { pendingPublish: !1 });
780
790
  }
781
791
  if (s === "POST" && i === "publish") {
782
- const t = fe(ne(e)), r = _e(e);
783
- await t.raw(["add", "-A", "--", r]);
784
- const o = await t.status(), m = o.staged.length > 0;
785
- let d = !1;
786
- m && (await t.commit("okno: publish content"), d = !0);
792
+ const t = de(se(e)), o = ye(e);
793
+ await t.raw(["add", "-A", "--", o]);
794
+ const r = await t.status(), d = r.staged.length > 0;
795
+ let m = !1;
796
+ d && (await t.commit("okno: publish content"), m = !0);
787
797
  let h = !1, y = null;
788
798
  try {
789
- (d || o.ahead > 0) && (await t.push(), h = !0);
799
+ (m || r.ahead > 0) && (await t.push(), h = !0);
790
800
  } catch (l) {
791
801
  y = l instanceof Error ? l.message.split(`
792
802
  `)[0] : String(l);
793
803
  }
794
- return a(200, { ok: !0, alreadyUpToDate: !d && o.ahead === 0, committed: d, pushed: h, pushError: y });
804
+ return a(200, { ok: !0, alreadyUpToDate: !m && r.ahead === 0, committed: m, pushed: h, pushError: y });
795
805
  }
796
806
  if (s === "POST" && i === "schema/save-fields") {
797
- const { kind: t, name: r, fields: o, renames: m, deletes: d } = await n.json();
798
- if (!t || !r || !o) return a(400, { error: "Missing kind, name or fields" });
807
+ const { kind: t, name: o, fields: r, renames: d, deletes: m } = await n.json();
808
+ if (!t || !o || !r) return a(400, { error: "Missing kind, name or fields" });
799
809
  const { schema: h, header: y } = T(e);
800
- Pe(h, t, r, o), f(h, y);
801
- const l = m && typeof m == "object" ? m : {}, g = Array.isArray(d) ? d : [];
810
+ Me(h, t, o, r), f(h, y);
811
+ const l = d && typeof d == "object" ? d : {}, g = Array.isArray(m) ? m : [];
802
812
  if (Object.keys(l).length > 0 || g.length > 0)
803
- for (const { rel: k, abs: b } of ut(e, t, r, l, g)) c(k, b);
813
+ for (const { rel: k, abs: b } of ft(e, t, o, l, g)) c(k, b);
804
814
  return a(200, { ok: !0, commit: { fileSha: "" }, schema: h });
805
815
  }
806
816
  if (s === "POST" && i === "schema/set-locales") {
807
- const t = (await n.json())?.locales, { schema: r, header: o } = T(e);
808
- return Ee(r, t), f(r, o), a(200, { ok: !0, commit: { fileSha: "" } });
817
+ const t = (await n.json())?.locales, { schema: o, header: r } = T(e);
818
+ return Ne(o, t), f(o, r), a(200, { ok: !0, commit: { fileSha: "" } });
809
819
  }
810
820
  if (s === "POST" && i === "schema/set-name") {
811
- const { kind: t, slug: r, name: o } = await n.json();
812
- if (!t || !r || !o) return a(400, { error: "Missing kind, slug or name" });
813
- const { schema: m, header: d } = T(e);
814
- return Me(m, t, r, o), f(m, d), a(200, { ok: !0, commit: { fileSha: "" } });
821
+ const { kind: t, slug: o, name: r } = await n.json();
822
+ if (!t || !o || !r) return a(400, { error: "Missing kind, slug or name" });
823
+ const { schema: d, header: m } = T(e);
824
+ return Ie(d, t, o, r), f(d, m), a(200, { ok: !0, commit: { fileSha: "" } });
815
825
  }
816
826
  if (s === "POST" && i === "schema/set-url") {
817
- const { kind: t, slug: r, url: o } = await n.json();
818
- if (!t || !r) return a(400, { error: "Missing kind or slug" });
819
- const { schema: m, header: d } = T(e);
820
- return Ne(m, t, r, o), f(m, d), a(200, { ok: !0, commit: { fileSha: "" } });
827
+ const { kind: t, slug: o, url: r } = await n.json();
828
+ if (!t || !o) return a(400, { error: "Missing kind or slug" });
829
+ const { schema: d, header: m } = T(e);
830
+ return We(d, t, o, r), f(d, m), a(200, { ok: !0, commit: { fileSha: "" } });
821
831
  }
822
832
  if (s === "POST" && i === "schema/rename-slug") {
823
- const { kind: t, from: r, to: o } = await n.json();
824
- if (!t || !r || !o) return a(400, { error: "Missing kind, from or to" });
825
- const { schema: m, header: d } = T(e), { unchanged: h } = Ie(m, t, r, o);
833
+ const { kind: t, from: o, to: r } = await n.json();
834
+ if (!t || !o || !r) return a(400, { error: "Missing kind, from or to" });
835
+ const { schema: d, header: m } = T(e), { unchanged: h } = Fe(d, t, o, r);
826
836
  if (h) return a(200, { ok: !0, unchanged: !0 });
827
- f(m, d);
828
- const y = `${t}/${r}.ts`, l = `${t}/${o}.ts`, g = F(e, y), k = F(e, l);
829
- return g && k && $(g) && (W(N(k), { recursive: !0 }), L(g), L(k), R(k, v(g)), B(g), c(y, g), c(l, k)), a(200, { ok: !0, commit: { fileSha: "" }, schema: m, from: r, to: o, kind: t });
837
+ f(d, m);
838
+ const y = `${t}/${o}.ts`, l = `${t}/${r}.ts`, g = F(e, y), k = F(e, l);
839
+ return g && k && $(g) && (W(N(k), { recursive: !0 }), L(g), L(k), R(k, v(g)), B(g), c(y, g), c(l, k)), a(200, { ok: !0, commit: { fileSha: "" }, schema: d, from: o, to: r, kind: t });
830
840
  }
831
841
  if (s === "POST" && i === "schema/reorder") {
832
- const { kind: t, order: r } = await n.json();
833
- if (!t || !Array.isArray(r)) return a(400, { error: "Missing kind or order" });
834
- const { schema: o, header: m } = T(e);
835
- return We(o, t, r), f(o, m), a(200, { ok: !0, commit: { fileSha: "" }, schema: o });
842
+ const { kind: t, order: o } = await n.json();
843
+ if (!t || !Array.isArray(o)) return a(400, { error: "Missing kind or order" });
844
+ const { schema: r, header: d } = T(e);
845
+ return Le(r, t, o), f(r, d), a(200, { ok: !0, commit: { fileSha: "" }, schema: r });
836
846
  }
837
847
  if (s === "POST" && i === "schema/set-layout") {
838
- const { kind: t, layout: r } = await n.json();
839
- if (!t || !Array.isArray(r)) return a(400, { error: "Missing kind or layout" });
840
- const { schema: o, header: m } = T(e);
841
- return Fe(o, t, r), f(o, m), a(200, { ok: !0, commit: { fileSha: "" }, schema: o });
848
+ const { kind: t, layout: o } = await n.json();
849
+ if (!t || !Array.isArray(o)) return a(400, { error: "Missing kind or layout" });
850
+ const { schema: r, header: d } = T(e);
851
+ return Ue(r, t, o), f(r, d), a(200, { ok: !0, commit: { fileSha: "" }, schema: r });
842
852
  }
843
853
  if (s === "POST" && i === "collections/set-order") {
844
- const { name: t, order: r } = await n.json();
845
- if (!t || !Array.isArray(r)) return a(400, { error: "Missing name or order" });
846
- const { schema: o, header: m } = T(e);
847
- return Le(o, t, r), f(o, m), a(200, { ok: !0, commit: { fileSha: "" }, schema: o });
854
+ const { name: t, order: o } = await n.json();
855
+ if (!t || !Array.isArray(o)) return a(400, { error: "Missing name or order" });
856
+ const { schema: r, header: d } = T(e);
857
+ return Ce(r, t, o), f(r, d), a(200, { ok: !0, commit: { fileSha: "" }, schema: r });
848
858
  }
849
859
  if (s === "POST" && i === "collections/set-drafts") {
850
- const { name: t, drafts: r } = await n.json();
851
- if (!t || typeof r != "boolean") return a(400, { error: "Missing name or drafts" });
852
- const { schema: o, header: m } = T(e);
853
- return Ue(o, t, r), f(o, m), a(200, { ok: !0, commit: { fileSha: "" }, schema: o });
860
+ const { name: t, drafts: o } = await n.json();
861
+ if (!t || typeof o != "boolean") return a(400, { error: "Missing name or drafts" });
862
+ const { schema: r, header: d } = T(e);
863
+ return ze(r, t, o), f(r, d), a(200, { ok: !0, commit: { fileSha: "" }, schema: r });
854
864
  }
855
865
  if (s === "POST" && i === "schema/delete-entry") {
856
- const { kind: t, name: r } = await n.json();
857
- if (!t || !r) return a(400, { error: "Missing kind or name" });
858
- const { schema: o, header: m } = T(e);
859
- Ce(o, t, r), f(o, m);
860
- const d = `${t}/${r}.ts`, h = F(e, d);
861
- return h && $(h) && (L(h), B(h), c(d, h)), a(200, { ok: !0, commit: { fileSha: "" }, schema: o });
866
+ const { kind: t, name: o } = await n.json();
867
+ if (!t || !o) return a(400, { error: "Missing kind or name" });
868
+ const { schema: r, header: d } = T(e);
869
+ Je(r, t, o), f(r, d);
870
+ const m = `${t}/${o}.ts`, h = F(e, m);
871
+ return h && $(h) && (L(h), B(h), c(m, h)), a(200, { ok: !0, commit: { fileSha: "" }, schema: r });
862
872
  }
863
873
  if (s === "POST" && i === "setup/scaffold-page") {
864
- const { name: t, kind: r, fields: o, label: m } = await n.json();
865
- if (!t || !r) return a(400, { error: "Missing name or kind" });
866
- const d = o ?? [], { schema: h, header: y } = T(e);
867
- if (ze(h, t, r, d, m), f(h, y), r !== "blocks") {
868
- const l = `${r}/${t}.ts`, g = F(e, l);
874
+ const { name: t, kind: o, fields: r, label: d } = await n.json();
875
+ if (!t || !o) return a(400, { error: "Missing name or kind" });
876
+ const m = r ?? [], { schema: h, header: y } = T(e);
877
+ if (Ve(h, t, o, m, d), f(h, y), o !== "blocks") {
878
+ const l = `${o}/${t}.ts`, g = F(e, l);
869
879
  if (g) {
870
- const k = r === "collections" ? `export default []
871
- ` : ee(Je(d));
880
+ const k = o === "collections" ? `export default []
881
+ ` : te(Be(m));
872
882
  W(N(g), { recursive: !0 }), L(g), R(g, k), c(l, g);
873
883
  }
874
884
  }
@@ -877,47 +887,50 @@ async function Mt(e, n) {
877
887
  if (s === "GET" && i === "files") {
878
888
  const t = _(e, "files", ".okno-tree.json");
879
889
  return a(200, {
880
- files: ke(e),
890
+ files: be(e),
881
891
  manifest: $(t) ? v(t, "utf-8") : null
882
892
  });
883
893
  }
884
894
  if (s === "POST" && i === "files/blob") {
885
- const t = he(decodeURIComponent(n.header("x-okno-filename") || "")), r = n.header("x-okno-dir") ? decodeURIComponent(n.header("x-okno-dir")) : "";
895
+ const t = ge(decodeURIComponent(n.header("x-okno-filename") || "")), o = n.header("x-okno-dir") ? decodeURIComponent(n.header("x-okno-dir")) : "";
886
896
  if (!t || t === "-") return a(400, { error: "Invalid filename" });
887
- const o = ge(r), m = o ? `${o}/${t}` : t, d = J(e, `files/${m}`);
888
- if (!d) return a(400, { error: "Invalid path" });
897
+ const r = _e(o), d = r ? `${r}/${t}` : t, m = J(e, `files/${d}`);
898
+ if (!m) return a(400, { error: "Invalid path" });
889
899
  const h = await n.binary();
890
- return h.length === 0 ? a(400, { error: "Empty body" }) : (W(N(d), { recursive: !0 }), R(d, h), a(200, { ok: !0, blobSha: "", path: `files/${m}`, filename: t }));
900
+ return h.length === 0 ? a(400, { error: "Empty body" }) : (W(N(m), { recursive: !0 }), R(m, h), a(200, { ok: !0, blobSha: "", path: `files/${d}`, filename: t }));
891
901
  }
892
902
  if (s === "POST" && i === "files/commit") return a(200, { ok: !0 });
893
903
  if (s === "POST" && i === "files/upload") {
894
- const { filename: t, content: r, dir: o } = await n.json();
895
- if (!t || r == null) return a(400, { error: "Missing filename or content" });
896
- const m = he(t);
897
- if (!m || m === "-") return a(400, { error: "Invalid filename" });
898
- const d = ge(o ?? ""), h = d ? `${d}/${m}` : m, y = J(e, `files/${h}`);
899
- return y ? (W(N(y), { recursive: !0 }), R(y, Buffer.from(r, "base64")), a(200, { ok: !0, path: `files/${h}`, filename: m, commit: { fileSha: "" } })) : a(400, { error: "Invalid path" });
904
+ const { filename: t, content: o, dir: r } = await n.json();
905
+ if (!t || o == null) return a(400, { error: "Missing filename or content" });
906
+ const d = ge(t);
907
+ if (!d || d === "-") return a(400, { error: "Invalid filename" });
908
+ const m = _e(r ?? ""), h = m ? `${m}/${d}` : d, y = J(e, `files/${h}`);
909
+ return y ? (W(N(y), { recursive: !0 }), R(y, Buffer.from(o, "base64")), a(200, { ok: !0, path: `files/${h}`, filename: d, commit: { fileSha: "" } })) : a(400, { error: "Invalid path" });
900
910
  }
901
911
  if (s === "POST" && i === "files/delete") {
902
912
  const t = (await n.json())?.path;
903
913
  if (!t) return a(400, { error: "Missing path" });
904
- const r = J(e, t);
905
- return r ? ($(r) && B(r), a(200, { ok: !0 })) : a(400, { error: "Invalid path" });
914
+ if (!X(t)) return a(400, { error: "Invalid path" });
915
+ const o = J(e, t);
916
+ return o ? ($(o) && B(o), a(200, { ok: !0 })) : a(400, { error: "Invalid path" });
906
917
  }
907
918
  if (s === "POST" && i === "files/delete-many") {
908
919
  const t = (await n.json())?.paths;
909
920
  if (!Array.isArray(t)) return a(400, { error: "Missing paths" });
910
- for (const r of t) {
911
- const o = J(e, String(r));
912
- o && $(o) && B(o);
921
+ if (t.some((o) => !X(String(o)))) return a(400, { error: "Invalid path" });
922
+ for (const o of t) {
923
+ const r = J(e, String(o));
924
+ r && $(r) && B(r);
913
925
  }
914
926
  return a(200, { ok: !0 });
915
927
  }
916
928
  if (s === "POST" && i === "files/rename") {
917
- const { from: t, to: r } = await n.json();
918
- if (!t || !r) return a(400, { error: "Missing from or to" });
919
- const o = J(e, t), m = J(e, r);
920
- return !o || !m ? a(400, { error: "Invalid path" }) : $(o) ? (W(N(m), { recursive: !0 }), ve(o, m), a(200, { ok: !0, commit: { fileSha: "" } })) : a(404, { error: "Source not found" });
929
+ const { from: t, to: o } = await n.json();
930
+ if (!t || !o) return a(400, { error: "Missing from or to" });
931
+ if (!X(t) || !X(o)) return a(400, { error: "Invalid path" });
932
+ const r = J(e, t), d = J(e, o);
933
+ return !r || !d ? a(400, { error: "Invalid path" }) : $(r) ? (W(N(d), { recursive: !0 }), Ae(r, d), a(200, { ok: !0, commit: { fileSha: "" } })) : a(404, { error: "Source not found" });
921
934
  }
922
935
  if (s === "POST" && i === "users/save") {
923
936
  const t = (await n.json())?.users;
@@ -926,30 +939,35 @@ async function Mt(e, n) {
926
939
  }
927
940
  if (s === "POST" && i === "origins/save") {
928
941
  const t = (await n.json())?.origins;
929
- if (!Array.isArray(t) || t.some((o) => typeof o != "string")) return a(400, { error: "Missing origins" });
930
- const r = [...new Set(t.map((o) => o.trim()).filter(Boolean))];
931
- return R(_(e, "origins.json"), JSON.stringify(r, null, " ") + `
932
- `), a(200, { ok: !0, origins: r, commit: { fileSha: "" } });
942
+ if (!Array.isArray(t) || t.some((r) => typeof r != "string")) return a(400, { error: "Missing origins" });
943
+ const o = [...new Set(t.map((r) => r.trim()).filter(Boolean))];
944
+ return R(_(e, "origins.json"), JSON.stringify(o, null, " ") + `
945
+ `), a(200, { ok: !0, origins: o, commit: { fileSha: "" } });
933
946
  }
934
947
  return null;
935
948
  } catch (t) {
936
- return t instanceof Ve ? { status: t.status, body: { error: t.message } } : { status: 500, body: { error: t instanceof Error ? t.message : String(t) } };
949
+ return t instanceof Ge ? { status: t.status, body: { error: t.message } } : { status: 500, body: { error: t instanceof Error ? t.message : String(t) } };
937
950
  }
938
951
  }
939
952
  export {
940
- ae as I,
941
- Rt as a,
942
- xt as b,
943
- Pt as c,
944
- Tt as d,
945
- At as e,
946
- jt as f,
947
- vt as g,
948
- Ot as h,
949
- St as i,
950
- bt as j,
951
- Mt as k,
952
- Et as l,
953
- lt as m,
954
- Y as s
953
+ ie as I,
954
+ Et as a,
955
+ Pt as b,
956
+ Mt as c,
957
+ Rt as d,
958
+ xt as e,
959
+ Tt as f,
960
+ jt as g,
961
+ vt as h,
962
+ Ot as i,
963
+ St as j,
964
+ It as k,
965
+ le as l,
966
+ ke as m,
967
+ At as n,
968
+ Nt as o,
969
+ ct as p,
970
+ rt as r,
971
+ D as s,
972
+ q as t
955
973
  };