okno 1.0.0-beta.37 → 1.0.0-beta.39

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,934 +0,0 @@
1
- import { join as g, relative as z, sep as W, dirname as E, resolve as ce } from "node:path";
2
- import { readdir as P, readFile as ke, writeFile as we } from "node:fs/promises";
3
- import { existsSync as _, readFileSync as O, readdirSync as D, statSync as be, realpathSync as Se, writeFileSync as x, mkdirSync as M, unlinkSync as L, renameSync as Oe } from "node:fs";
4
- import { execSync as ee } from "node:child_process";
5
- import { fileURLToPath as ve } from "node:url";
6
- import { p as J } from "./parse-tlTHgSSs.js";
7
- import { o as je } from "./order-bAkdncZC.js";
8
- import { simpleGit as ue } from "simple-git";
9
- import { b as q, a as Ae, e as Te } from "./encode-BfJY0Xy5.js";
10
- import { applyKeyChanges as fe, setStringsSchema as xe, saveFields as Pe, setLocales as Re, setName as Ee, setUrl as Me, renameSlug as Ne, reorderKind as Ie, setLayout as We, setCollectionOrder as Fe, setDrafts as Le, deleteSchemaEntry as Ue, scaffoldEntry as Ce, fieldsToContent as ze, EngineError as Je } from "./engine/index.js";
11
- const Ve = /* @__PURE__ */ new Set([".astro", ".svelte", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".vue"]), Be = /* @__PURE__ */ new Set([
12
- "node_modules",
13
- ".astro",
14
- ".svelte-kit",
15
- ".next",
16
- ".nuxt",
17
- ".vite",
18
- "dist",
19
- "build",
20
- ".git",
21
- ".turbo"
22
- ]);
23
- async function Z(e, n) {
24
- const o = new RegExp(`import\\s*\\{([^}]+)\\}\\s*from\\s*["']okno[:/]${n}["']`, "g"), a = /* @__PURE__ */ new Set();
25
- async function u(l) {
26
- let f;
27
- try {
28
- f = await P(l, { withFileTypes: !0 });
29
- } catch {
30
- return;
31
- }
32
- for (const c of f) {
33
- if (c.name.startsWith(".") && c.name !== "." || Be.has(c.name)) continue;
34
- const i = g(l, c.name);
35
- if (c.isDirectory()) {
36
- await u(i);
37
- continue;
38
- }
39
- const t = c.name.lastIndexOf(".");
40
- if (t === -1) continue;
41
- const s = c.name.slice(t);
42
- if (!Ve.has(s)) continue;
43
- let r;
44
- try {
45
- r = await ke(i, "utf-8");
46
- } catch {
47
- continue;
48
- }
49
- if (!(!r.includes(`okno:${n}`) && !r.includes(`okno/${n}`)))
50
- for (const d of r.matchAll(o)) {
51
- const m = d[1] ?? "";
52
- for (const h of m.split(",")) {
53
- const y = h.trim().split(/\s+as\s+/)[0]?.trim();
54
- y && /^[A-Za-z_$][\w$]*$/.test(y) && a.add(y);
55
- }
56
- }
57
- }
58
- }
59
- return await u(e), a;
60
- }
61
- async function wt(e, n) {
62
- const o = await De(e), a = new Map(o.map((s) => [s.name, s.first])), u = Qe(e), l = [
63
- "// Auto-generated by okno. Do not edit.",
64
- "",
65
- "/** A wrapped content value that can be spread onto elements and rendered as text. */",
66
- "type OknoValue<T = unknown> = {",
67
- ' readonly "data-okno": string',
68
- " toString(): string",
69
- // NB: NO `[Symbol.toPrimitive]` in the TYPE. Svelte 5's element-attribute type
70
- // carries a symbol index signature for attachments (`[key: symbol]: Attachment`),
71
- // and a `(hint: string) => string` toPrimitive isn't assignable to it — so a
72
- // `{...field}` spread would fail type-check on every element. The runtime keeps
73
- // Symbol.toPrimitive (see runtime/wrap.ts) so `{field}` / String(field) still
74
- // coerce; `toString()` covers the static string-coercion the type needs.
75
- " onedit(callback: (value: T) => void): () => void",
76
- " /** Re-root reads at a locale; no-op when unset or on the default locale. Returns the SAME wrapped shape (not `this`, which would drop array element types). */",
77
- " locale(code?: string | null): OknoWrapped<T>",
78
- " /** `true` when this field/reference actually holds a value — every read is a truthy wrapper, so `entry.ref ? …` can't tell set from unset. */",
79
- " readonly exists: boolean",
80
- "}",
81
- "",
82
- "/** The explicit reorder handle — spread `.drag` on a semantic wrapper (`<li {...item.drag}>`, `<tr {...item.drag}>`) when the item's own element can't be the direct child of the reorder container. Emits the same `data-okno-item` boundary as the bare `{...item}` spread; the editor resolves the OUTERMOST element carrying it as the drag unit, so both a wrapper's `.drag` and an inner `{...item}` can coexist. Present on every array item (leaf AND block). */",
83
- 'type OknoDrag = { readonly drag: { readonly "data-okno-item": string } }',
84
- "/** The reorder hook carried directly on a LEAF array item's bare spread (`{...item}`), so a leaf multiple needs no separate `{...item.drag}` in the common case. */",
85
- 'type OknoDragItem = { readonly "data-okno-item": string }',
86
- "/** One array member. A LEAF (media/link/text) is spread bare — `{...item}` — so it carries `data-okno-item` for reorder AND still exposes `.drag` as an escape hatch (for a semantic wrapper). A BLOCK/reference member has inner fields, so its bare `{...item}` would dump field keys; it spreads content fields on its wrapper plus `.drag` for reorder. */",
87
- "type OknoArrayItem<U> =",
88
- " U extends string | number | boolean",
89
- " ? OknoWrapped<U> & OknoDragItem & OknoDrag",
90
- " : U extends { src: string }",
91
- " ? OknoWrapped<U> & OknoDragItem & OknoDrag",
92
- " : U extends { url: string; text: string }",
93
- " ? OknoWrapped<U> & OknoDragItem & OknoDrag",
94
- " : OknoWrapped<U> & OknoDrag",
95
- "",
96
- "/** A media value's `.image` handle — a spreadable bundle for a framework image component (Astro `<Image {...cover.image}>`): build-optimized `src` (from `okno/files`), plus alt/dimensions and the edit hook. Use `<img {...cover}>` for the raw/universal path. `src` is loose (framework's shape, e.g. Astro `ImageMetadata`) so okno stays framework-agnostic. */",
97
- 'type OknoImage = { src: any; alt: string; width?: number; height?: number; readonly "data-okno": string }',
98
- "",
99
- "/** Recursively wraps content types so values are spreadable/renderable. Media (`{src}`) and link (`{url,text}`) objects keep RAW attribute values so `<img {...media}>` / `<a {...link}>` type-check; media also exposes `.image`; other objects expose wrapped fields + the data-okno hook. Array items carry `data-okno-item` on the bare spread (leaf multiples) AND expose `.drag` (the explicit reorder handle, for block wrappers or a leaf's semantic wrapper). */",
100
- "type OknoWrapped<T> =",
101
- " T extends string | number | boolean",
102
- " ? OknoValue<T>",
103
- " : T extends ReadonlyArray<infer U>",
104
- " ? OknoArrayItem<U>[]",
105
- " : T extends { src: string }",
106
- ' ? Omit<T, "focal"> & OknoValue<T> & { readonly image: OknoImage } & (T extends { focal: infer F } ? { readonly focal: OknoWrapped<F> } : {})',
107
- " : T extends { url: string; text: string }",
108
- " ? { href: string; target?: string; rel?: string } & OknoValue<T>",
109
- " : T extends Record<string, unknown>",
110
- " ? { [K in keyof T]: OknoWrapped<T[K]> } & OknoValue<T>",
111
- " : OknoValue<T>",
112
- "",
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. */",
114
- "type OknoUnscaffolded = OknoWrapped<Record<string, unknown>>",
115
- "",
116
- "/** Authorship + timestamp metadata Okno writes on every entry (page, collection item, global). Read-only — never edit or spread; it's the data your own `.sort()` uses. Each is wrapped, so render `{a.updated.date}` and compare `String(a.updated.date)`. */",
117
- "type OknoStamp = { readonly date: string; readonly author: string }",
118
- "type OknoMeta = {",
119
- " readonly created: OknoWrapped<OknoStamp>",
120
- " readonly updated: OknoWrapped<OknoStamp>",
121
- "}",
122
- ""
123
- ], f = (s, r, d) => {
124
- const m = `typeof import("${d}").default`, h = u?.[s]?.[r]?.fields, y = h ? Object.entries(h) : [], p = y.filter(
125
- ([, w]) => w?.type === "reference" && typeof w.collection == "string" && a.has(w.collection)
126
- ), $ = y.filter(([, w]) => w?.type === "enum"), k = '"created" | "updated"';
127
- if (p.length === 0 && $.length === 0) return `OknoWrapped<Omit<${m}, ${k}>> & OknoMeta`;
128
- const S = `${[...p, ...$].map(([w]) => `"${w}"`).join(" | ")} | ${k}`, v = [
129
- ...p.map(([w, b]) => {
130
- const j = `typeof import("./collections/${b.collection}/${a.get(b.collection)}").default`;
131
- return `${w}: ${b.multiple ? `${j}[]` : j}`;
132
- }),
133
- ...$.map(([w, b]) => {
134
- const j = (Array.isArray(b.options) ? b.options : []).map((T) => typeof T == "string" ? T : T?.value).filter((T) => typeof T == "string"), V = `{ name: string; value: ${j.length ? j.map((T) => JSON.stringify(T)).join(" | ") : "string"} }`;
135
- return `${w}: ${b.multiple ? `${V}[]` : V}`;
136
- })
137
- ].join("; ");
138
- return `OknoWrapped<Omit<${m}, ${S}> & { ${v} }> & OknoMeta`;
139
- }, [c, i, t] = await Promise.all([
140
- Z(n, "pages"),
141
- Z(n, "globals"),
142
- Z(n, "collections")
143
- ]);
144
- l.push(
145
- ...me("okno:pages", "pages", await Q(g(e, "pages")), c, f)
146
- ), l.push(...qe(o, t, f)), l.push(
147
- ...me("okno:globals", "globals", await Q(g(e, "globals")), i, f)
148
- ), l.push(...He(Ye(e), Xe(u))), l.push(...Ge()), l.push(...Ke());
149
- for (const s of ["pages", "collections", "globals", "locales", "strings", "content"])
150
- l.push(`declare module "okno/${s}" {`, ` export * from "okno:${s}";`, "}", "");
151
- await we(g(e, "modules.d.ts"), l.join(`
152
- `));
153
- }
154
- function me(e, n, o, a, u) {
155
- const l = /* @__PURE__ */ new Set(), f = [];
156
- for (const c of o)
157
- f.push(` export const ${c}: ${u(n, c, `./${n}/${c}`)}`), l.add(c);
158
- for (const c of a)
159
- l.has(c) || f.push(` export const ${c}: OknoUnscaffolded`);
160
- return [`declare module "${e}" {`, ...f, "}", ""];
161
- }
162
- function Ge() {
163
- return [
164
- 'declare module "okno:locales" {',
165
- ' /** 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. */',
166
- " export interface OknoLocale {",
167
- " id: string",
168
- " name: string",
169
- " slug: string",
170
- ' link(url: URL | string): { rel: "alternate"; hreflang: string; href: string }',
171
- " }",
172
- " /** The configured languages; `locales.default` is the base-locale entry. Empty (`.default` undefined) when no languages are configured. */",
173
- " export const locales: OknoLocale[] & { default: OknoLocale }",
174
- "}",
175
- ""
176
- ];
177
- }
178
- function Ke() {
179
- return [
180
- 'declare module "okno:content" {',
181
- ' /** Unified content namespace — `import * as okno from "okno:content"` then `okno.pages.home`, `okno.globals.nav`, `okno.collections.articles`, `okno.strings.nav.home`. */',
182
- ' export * as pages from "okno:pages"',
183
- ' export * as globals from "okno:globals"',
184
- ' export * as collections from "okno:collections"',
185
- ' export { strings } from "okno:strings"',
186
- "}",
187
- ""
188
- ];
189
- }
190
- function He(e, n) {
191
- const o = e.length ? `${Ze(e, n)}` : "any", a = e.length ? `
192
- locale(code?: string | null): ${o}` : "";
193
- return [
194
- 'declare module "okno:strings" {',
195
- " /** The UI-strings store. A plain leaf is string-like (spread `{...s.nav.home}` for the edit hook, render `{s.nav.home}` for the text); a SLOTTED leaf is a `(params) => …` function — call it, then spread/render the result (`{...s.cart.items({count})}`). `.locale(code)` re-roots the whole tree at a language. */",
196
- ` export const strings: ${e.length ? `${o} & {${a}
197
- }` : "any"}`,
198
- "}",
199
- ""
200
- ];
201
- }
202
- function Ze(e, n) {
203
- const o = { children: /* @__PURE__ */ new Map() };
204
- for (const f of e) {
205
- let c = o;
206
- for (const i of f.split(".")) {
207
- let t = c.children.get(i);
208
- t || (t = { children: /* @__PURE__ */ new Map() }, c.children.set(i, t)), c = t;
209
- }
210
- }
211
- const a = (f) => f === "text" ? "string" : "number", u = (f) => {
212
- const c = n[f];
213
- return !c || Object.keys(c).length === 0 ? "OknoValue<string>" : `(p: { ${Object.entries(c).map(([t, s]) => `${JSON.stringify(t)}: ${a(s)}`).join("; ")} }) => OknoValue<string>`;
214
- }, l = (f, c) => f.children.size === 0 ? u(c) : `{ ${[...f.children.entries()].map(
215
- ([t, s]) => `${JSON.stringify(t)}: ${l(s, c ? `${c}.${t}` : t)}`
216
- ).join("; ")} }`;
217
- return l(o, "");
218
- }
219
- function Xe(e) {
220
- const n = {}, o = e?.strings;
221
- if (!o || typeof o != "object" || Array.isArray(o)) return n;
222
- for (const [a, u] of Object.entries(o)) {
223
- const l = u?.slots;
224
- if (!l || typeof l != "object" || Array.isArray(l)) continue;
225
- const f = {};
226
- for (const [c, i] of Object.entries(l))
227
- (i === "text" || i === "number" || i === "count") && (f[c] = i);
228
- Object.keys(f).length && (n[a] = f);
229
- }
230
- return n;
231
- }
232
- function qe(e, n, o) {
233
- const a = /* @__PURE__ */ new Set(), u = [];
234
- for (const l of e) {
235
- const f = o("collections", l.name, `./collections/${l.name}/${l.first}`);
236
- u.push(` export const ${l.name}: (${f} & OknoDrag)[]`), a.add(l.name);
237
- }
238
- for (const l of n)
239
- a.has(l) || u.push(` export const ${l}: OknoUnscaffolded[]`);
240
- return ['declare module "okno:collections" {', ...u, "}", ""];
241
- }
242
- function Qe(e) {
243
- const n = g(e, "schema.ts");
244
- if (!_(n)) return null;
245
- try {
246
- let o = O(n, "utf8");
247
- const a = o.indexOf("export default");
248
- return a === -1 ? null : (o = o.slice(a + 14).replace(/\bas const\b/g, "").replace(/\bsatisfies\s+[A-Za-z0-9_.]+/g, "").trim(), o.endsWith(";") && (o = o.slice(0, -1).trim()), JSON.parse(o));
249
- } catch {
250
- return null;
251
- }
252
- }
253
- function Ye(e) {
254
- const n = g(e, "strings.ts");
255
- if (!_(n)) return [];
256
- try {
257
- let o = O(n, "utf8");
258
- const a = o.indexOf("export default");
259
- if (a === -1) return [];
260
- o = o.slice(a + 14).replace(/\bas const\b/g, "").replace(/\bsatisfies\s+[A-Za-z0-9_.]+/g, "").trim(), o.endsWith(";") && (o = o.slice(0, -1).trim());
261
- const u = JSON.parse(o);
262
- return u && typeof u == "object" && !Array.isArray(u) ? Object.keys(u) : [];
263
- } catch {
264
- return [];
265
- }
266
- }
267
- async function De(e) {
268
- const n = g(e, "collections");
269
- if (!_(n)) return [];
270
- const o = (await P(n, { withFileTypes: !0 })).filter((u) => u.isDirectory()), a = [];
271
- for (const u of o) {
272
- const l = await Q(g(n, u.name));
273
- l.length > 0 && a.push({ name: u.name, first: l[0] });
274
- }
275
- return a;
276
- }
277
- async function Q(e) {
278
- return _(e) ? (await P(e)).filter((o) => o.endsWith(".ts") && o !== "index.ts" && o !== "modules.d.ts").map((o) => o.replace(".ts", "")) : [];
279
- }
280
- function te(e) {
281
- try {
282
- return ee(e, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
283
- } catch {
284
- return null;
285
- }
286
- }
287
- function et() {
288
- const e = te("git rev-parse --abbrev-ref HEAD");
289
- if (e && e !== "HEAD") return e;
290
- const n = process.env;
291
- return n.CF_PAGES_BRANCH || // Cloudflare Pages
292
- n.VERCEL_GIT_COMMIT_REF || // Vercel
293
- n.BRANCH || // Netlify
294
- n.GITHUB_REF_NAME || // GitHub Actions
295
- "main";
296
- }
297
- function bt() {
298
- const e = te("git remote get-url origin");
299
- if (!e) return null;
300
- const n = e.match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/);
301
- return n ? `${n[1]}/${n[2]}@${et()}` : null;
302
- }
303
- function St() {
304
- const e = te("git rev-parse --show-toplevel");
305
- return e ? z(e, process.cwd()).split(W).join("/") : "";
306
- }
307
- const ne = '__oknoSetImages(import.meta.glob("/okno/files/**/*.{png,jpg,jpeg,webp,avif,gif,svg,tiff}", { eager: false }))', de = E(ve(import.meta.url)), tt = [
308
- ce(de, "./runtime/wrap.js"),
309
- // bundled at dist/ (Vite plugin chunk)
310
- ce(de, "../runtime/wrap.js")
311
- // bundled at dist/next/ (Next entry)
312
- ];
313
- function Ot() {
314
- for (const e of tt)
315
- if (_(e)) return O(e, "utf-8");
316
- return null;
317
- }
318
- function vt() {
319
- return [
320
- 'export * as pages from "okno:pages"',
321
- 'export * as globals from "okno:globals"',
322
- 'export * as collections from "okno:collections"',
323
- 'export { strings } from "okno:strings"'
324
- ].join(`
325
- `);
326
- }
327
- function G(e) {
328
- const n = g(e, "schema.ts");
329
- if (!_(n)) return null;
330
- try {
331
- const a = J(O(n, "utf-8"))?.locales?.supported;
332
- if (!Array.isArray(a) || a.length === 0) return null;
333
- const u = a.map((l) => typeof l == "string" ? l : l?.id).filter((l) => typeof l == "string");
334
- return u.length ? new Set(u) : null;
335
- } catch {
336
- return null;
337
- }
338
- }
339
- function C(e, n) {
340
- return n ? n.has(e) : st.test(e);
341
- }
342
- function nt(e) {
343
- for (const n of [e, "en"])
344
- try {
345
- const o = new Intl.DisplayNames([n], { type: "language" }).of(e);
346
- if (o && o !== e) return o;
347
- } catch {
348
- }
349
- return e;
350
- }
351
- async function oe(e) {
352
- return _(e) ? (await P(e)).filter((o) => o.endsWith(".ts") && o !== "index.ts") : [];
353
- }
354
- function ot(e) {
355
- const n = g(e, "schema.ts"), o = {}, a = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set();
356
- if (!_(n)) return { orders: o, drafts: a, scheduling: u };
357
- try {
358
- const f = J(O(n, "utf-8"))?.collections ?? {};
359
- for (const [c, i] of Object.entries(f))
360
- Array.isArray(i?.order) && (o[c] = i.order.filter((t) => typeof t == "string")), i?.drafts === !0 && a.add(c), i?.scheduling === !0 && u.add(c);
361
- } catch {
362
- }
363
- return { orders: o, drafts: a, scheduling: u };
364
- }
365
- const st = /^[a-z]{2,3}(-[a-z]{4})?(-([a-z]{2}|[0-9]{3}))?$/i, K = (e) => e.replace(/[^a-zA-Z0-9]/g, "_");
366
- function se(e) {
367
- return e.replace(".ts", "").replace(/-/g, "_");
368
- }
369
- function ye(e) {
370
- return e.replace(".ts", "").replace(/-/g, "_");
371
- }
372
- function B(e) {
373
- return e.replace(".ts", "");
374
- }
375
- function jt(e) {
376
- const n = g(e, "schema.ts");
377
- let o = [], a = "";
378
- if (_(n))
379
- try {
380
- const u = J(O(n, "utf-8")), l = u?.locales?.supported;
381
- Array.isArray(l) && (o = l.map((f) => typeof f == "string" ? { id: f } : f).filter((f) => !!f && typeof f.id == "string").map((f) => ({
382
- id: f.id,
383
- name: f.name || nt(f.id),
384
- // Preserve an intentionally empty slug (= no URL prefix for the default).
385
- slug: typeof f.slug == "string" ? f.slug : f.id.toLowerCase()
386
- })), a = typeof u.locales.default == "string" ? u.locales.default : o[0]?.id ?? "");
387
- } catch {
388
- }
389
- return [
390
- `const __raw = ${JSON.stringify(o)}`,
391
- `const __def = ${JSON.stringify(a)}`,
392
- // Swap the locale prefix on a path (empty slug = no prefix). Best-effort,
393
- // matches the editor's own resolver; fully translated paths = dev's own tags.
394
- "function __swap(pathname, slug) {",
395
- ' const norm = (pathname || "/").replace(/\\/+$/, "") || "/"',
396
- ' const segs = norm.split("/").filter(Boolean)',
397
- " const known = __raw.find((l) => l.slug && l.slug === segs[0])",
398
- ' const rest = known ? "/" + segs.slice(1).join("/") : norm',
399
- ' const r = rest === "" ? "/" : rest',
400
- " if (!slug) return r",
401
- ' return r === "/" ? "/" + slug : "/" + slug + r',
402
- "}",
403
- 'const __origin = (url) => (typeof url === "object" && url !== null ? url.origin : "")',
404
- 'const __path = (url) => (typeof url === "object" && url !== null ? url.pathname : String(url || "/"))',
405
- "/** The configured languages — an array of { id, name, slug, link(url) }.",
406
- " * link(url) → this entry's hreflang <link> descriptor (spread onto a <link>;",
407
- " * pass Astro.url for an absolute href). `locales.default` is the base entry. */",
408
- "export const locales = __raw.map((l) => ({",
409
- " ...l,",
410
- ' link: (url) => ({ rel: "alternate", hreflang: l.id, href: __origin(url) + __swap(__path(url), l.slug) }),',
411
- "}))",
412
- // `.default` = the base-locale entry (same object reference as in the array).
413
- "locales.default = locales.find((l) => l.id === __def) || locales[0]"
414
- ].join(`
415
- `);
416
- }
417
- async function At(e) {
418
- const n = g(e, "strings.ts");
419
- if (!_(n))
420
- return [
421
- 'import { __oknoMakeStrings } from "okno:runtime"',
422
- 'export const strings = __oknoMakeStrings({}, {}, "")'
423
- ].join(`
424
- `);
425
- const o = g(e, "schema.ts"), a = _(o), u = G(e), l = g(e, "strings"), f = [];
426
- if (_(l)) {
427
- const r = await P(l, { withFileTypes: !0 });
428
- for (const d of r) {
429
- if (!d.isFile() || !d.name.endsWith(".ts") || d.name === "index.ts") continue;
430
- const m = d.name.replace(/\.ts$/, "");
431
- C(m, u) && f.push(m);
432
- }
433
- }
434
- const c = [
435
- 'import { __oknoMakeStrings, __oknoLocalize, __oknoExpandStrings } from "okno:runtime"',
436
- `import _strings_default from "${n}"`
437
- ];
438
- a && c.push(`import __schema from "${o}"`);
439
- const i = a ? "__schema?.strings" : "{}", t = a ? "__schema?.locales?.default" : '""';
440
- if (f.length === 0)
441
- return c.push(`export const strings = __oknoMakeStrings(__oknoExpandStrings(_strings_default), ${i}, ${t})`), c.join(`
442
- `);
443
- const s = [];
444
- for (const r of f) {
445
- const d = K(r);
446
- c.push(`import _strings_${d} from "${g(l, r + ".ts")}"`), s.push(`"${r}": __oknoExpandStrings(_strings_${d})`);
447
- }
448
- return c.push("const _strings_base = __oknoExpandStrings(_strings_default)"), c.push(`const _strings_localized = __oknoLocalize(_strings_base, { ${s.join(", ")} })`), c.push(`export const strings = __oknoMakeStrings(_strings_localized, ${i}, ${t})`), c.join(`
449
- `);
450
- }
451
- async function Tt(e, n = /* @__PURE__ */ new Set()) {
452
- const o = g(e, "pages"), a = g(e, "schema.ts"), u = _(a), l = [
453
- 'import { __oknoWrap, __oknoLocalize, __oknoResolveRefs, __oknoResolveEnums, __oknoSetImages } from "okno:runtime"',
454
- ne
455
- ];
456
- u && (l.push('import * as __collections from "okno:collections"'), l.push(`import __schema from "${a}"`));
457
- let f = "[]";
458
- const c = (t, s) => {
459
- if (!u) return `_${t}`;
460
- const r = `__schema?.pages?.["${s}"]?.fields`;
461
- return `__oknoResolveEnums(__oknoResolveRefs(_${t}, ${r}, __collections, ${f}), ${r}, ${f})`;
462
- }, i = /* @__PURE__ */ new Set();
463
- if (_(o)) {
464
- const t = G(e), r = (await P(o, { withFileTypes: !0 })).filter((m) => m.isDirectory() && C(m.name, t)).map((m) => m.name);
465
- f = JSON.stringify(r);
466
- const d = await oe(o);
467
- for (const m of d) {
468
- const h = se(m), y = ye(m), p = B(m), $ = g(o, m);
469
- if (r.length === 0) {
470
- l.push(`import _${h} from "${$}"`), l.push(`export const ${y} = __oknoWrap(${c(h, p)}, "${p}")`), i.add(y);
471
- continue;
472
- }
473
- const k = [`import _${h}_default from "${$}"`], S = [];
474
- for (const v of r) {
475
- const w = g(o, v, m);
476
- if (_(w)) {
477
- const b = K(v);
478
- k.push(`import _${h}_${b} from "${w}"`), S.push(`"${v}": _${h}_${b}`);
479
- }
480
- }
481
- l.push(...k), l.push(`const _${h} = __oknoLocalize(_${h}_default, { ${S.join(", ")} })`), l.push(`export const ${y} = __oknoWrap(${c(h, p)}, "${p}")`), i.add(y);
482
- }
483
- }
484
- for (const t of n)
485
- i.has(t) || l.push(`export const ${t} = __oknoWrap(null, "${t}")`);
486
- return l.join(`
487
- `);
488
- }
489
- async function xt(e, n = /* @__PURE__ */ new Set(), o = !1) {
490
- const a = g(e, "collections");
491
- if (!_(a)) {
492
- const p = [];
493
- for (const $ of n) {
494
- const k = $.replace(/-/g, "_");
495
- p.push(`export const ${k} = []`);
496
- }
497
- return p.join(`
498
- `) || "export {}";
499
- }
500
- const u = G(e), l = await P(a, { withFileTypes: !0 }), f = l.filter((p) => p.isDirectory() && C(p.name, u)).map((p) => p.name), c = l.filter((p) => p.isDirectory() && !f.includes(p.name)).map((p) => p.name), i = JSON.stringify(f);
501
- for (const p of c) {
502
- const $ = await P(g(a, p), { withFileTypes: !0 }).catch(() => []);
503
- for (const k of $)
504
- k.isDirectory() && C(k.name, u) && console.warn(
505
- `[okno] "collections/${p}/${k.name}/" looks like a misplaced locale folder. Collection locale overrides go at "collections/${k.name}/${p}/<slug>.ts" (locale right after "collections/"). This folder will NOT be localized.`
506
- );
507
- }
508
- const { orders: t, drafts: s, scheduling: r } = ot(e), d = g(e, "schema.ts"), m = _(d), h = [
509
- 'import { __oknoWrap, __oknoLocalize, __oknoResolveRefs, __oknoResolveEnums, __oknoSetImages, __oknoVisible } from "okno:runtime"',
510
- ne
511
- ];
512
- m && h.push(`import __schema from "${d}"`);
513
- const y = [];
514
- for (const p of c) {
515
- const $ = g(a, p), k = je(await oe($), B, t[p]), S = p.replace(/-/g, "_"), v = o && s.has(p), w = o && r.has(p), b = [];
516
- for (const j of k) {
517
- const R = `_${S}_${se(j)}`, V = B(j), T = g($, j);
518
- if (f.length === 0)
519
- h.push(`import ${R} from "${T}"`);
520
- else {
521
- const re = [`import ${R}_default from "${T}"`], ae = [];
522
- for (const H of f) {
523
- const ie = g(a, H, p, j);
524
- if (_(ie)) {
525
- const le = K(H);
526
- re.push(`import ${R}_${le} from "${ie}"`), ae.push(`"${H}": ${R}_${le}`);
527
- }
528
- }
529
- h.push(...re), h.push(`const ${R} = __oknoLocalize(${R}_default, { ${ae.join(", ")} })`);
530
- }
531
- b.push({ varName: R, itemName: V });
532
- }
533
- h.push(`const __oknoRaw_${S} = [${b.map((j) => j.varName).join(", ")}]`), y.push({ name: p, safe: S, draftsOn: v, schedulingOn: w, items: b });
534
- }
535
- m && h.push(`const __oknoNs = { ${y.map((p) => `${p.safe}: __oknoRaw_${p.safe}`).join(", ")} }`);
536
- for (const p of y) {
537
- const $ = `__schema?.collections?.["${p.name}"]?.fields`, k = (w) => m ? `__oknoResolveEnums(__oknoResolveRefs(${w.varName}, ${$}, __oknoNs, ${i}), ${$}, ${i})` : w.varName, S = [];
538
- p.draftsOn && S.push('e[0]?.status !== "draft"'), p.schedulingOn && S.push("__oknoVisible(e[0])");
539
- const v = S.length ? `[${p.items.map((w) => `[${w.varName}, ${k(w)}, ${JSON.stringify(w.itemName)}]`).join(", ")}].filter((e) => ${S.join(" && ")}).map((e, __i) => __oknoWrap(e[1], "${p.name}." + e[2], "${p.name}." + __i))` : `[${p.items.map((w, b) => `__oknoWrap(${k(w)}, "${p.name}.${w.itemName}", "${p.name}.${b}")`).join(", ")}]`;
540
- h.push(`export const ${p.safe} = ${v}`);
541
- }
542
- return h.join(`
543
- `);
544
- }
545
- async function Pt(e, n = /* @__PURE__ */ new Set()) {
546
- const o = g(e, "globals"), a = g(e, "schema.ts"), u = _(a), l = [
547
- 'import { __oknoWrap, __oknoLocalize, __oknoResolveRefs, __oknoResolveEnums, __oknoSetImages } from "okno:runtime"',
548
- ne
549
- ];
550
- u && (l.push('import * as __collections from "okno:collections"'), l.push(`import __schema from "${a}"`));
551
- let f = "[]";
552
- const c = (t, s) => {
553
- if (!u) return `_${t}`;
554
- const r = `__schema?.globals?.["${s}"]?.fields`;
555
- return `__oknoResolveEnums(__oknoResolveRefs(_${t}, ${r}, __collections, ${f}), ${r}, ${f})`;
556
- }, i = /* @__PURE__ */ new Set();
557
- if (_(o)) {
558
- const t = G(e), r = (await P(o, { withFileTypes: !0 })).filter((m) => m.isDirectory() && C(m.name, t)).map((m) => m.name);
559
- f = JSON.stringify(r);
560
- const d = await oe(o);
561
- for (const m of d) {
562
- const h = se(m), y = ye(m), p = B(m), $ = g(o, m);
563
- if (r.length === 0) {
564
- l.push(`import _${h} from "${$}"`), l.push(`export const ${y} = __oknoWrap(${c(h, p)}, "${p}")`), i.add(y);
565
- continue;
566
- }
567
- const k = [`import _${h}_default from "${$}"`], S = [];
568
- for (const v of r) {
569
- const w = g(o, v, m);
570
- if (_(w)) {
571
- const b = K(v);
572
- k.push(`import _${h}_${b} from "${w}"`), S.push(`"${v}": _${h}_${b}`);
573
- }
574
- }
575
- l.push(...k), l.push(`const _${h} = __oknoLocalize(_${h}_default, { ${S.join(", ")} })`), l.push(`export const ${y} = __oknoWrap(${c(h, p)}, "${p}")`), i.add(y);
576
- }
577
- }
578
- for (const t of n)
579
- i.has(t) || l.push(`export const ${t} = __oknoWrap(null, "${t}")`);
580
- return l.join(`
581
- `);
582
- }
583
- const _e = /* @__PURE__ */ new Map();
584
- function I(e) {
585
- _e.set(e, Date.now());
586
- }
587
- function Rt(e) {
588
- const n = _e.get(e);
589
- return n !== void 0 && Date.now() - n < 3e3;
590
- }
591
- const rt = ["pages", "collections", "globals"];
592
- function N(e, n) {
593
- if (!n || n.includes("..") || n.includes("\0") || n.startsWith("/") || !n.endsWith(".ts")) return null;
594
- const o = g(e, n);
595
- return o !== e && !o.startsWith(e + W) ? null : o;
596
- }
597
- function F(e, n) {
598
- if (!n || n.includes("..") || n.includes("\0") || n.startsWith("/")) return null;
599
- const o = g(e, n);
600
- return o !== e && !o.startsWith(e + W) ? null : o;
601
- }
602
- function at(e) {
603
- const n = {}, o = (u) => {
604
- if (_(u))
605
- for (const l of D(u, { withFileTypes: !0 })) {
606
- const f = g(u, l.name);
607
- if (l.isDirectory()) o(f);
608
- else if (l.name.endsWith(".ts") && l.name !== "index.ts") {
609
- const c = z(e, f).split(W).join("/");
610
- n[c] = O(f, "utf-8");
611
- }
612
- }
613
- };
614
- for (const u of rt) o(g(e, u));
615
- const a = g(e, "strings.ts");
616
- return _(a) && (n["strings.ts"] = O(a, "utf-8")), o(g(e, "strings")), n;
617
- }
618
- function $e(e) {
619
- const n = g(e, "files"), o = [], a = (u) => {
620
- if (_(u))
621
- for (const l of D(u, { withFileTypes: !0 })) {
622
- const f = g(u, l.name);
623
- if (l.isDirectory()) a(f);
624
- else if (l.name !== ".okno-tree.json") {
625
- const c = z(n, f).split(W).join("/");
626
- o.push({ path: `files/${c}`, filename: l.name, size: be(f).size });
627
- }
628
- }
629
- };
630
- return a(n), o;
631
- }
632
- function it(e) {
633
- const n = g(e, "schema.ts"), o = g(e, "users.json"), a = g(e, "origins.json");
634
- return {
635
- schema: _(n) ? O(n, "utf-8") : null,
636
- users: _(o) ? O(o, "utf-8") : null,
637
- origins: _(a) ? O(a, "utf-8") : null,
638
- content: at(e),
639
- files: $e(e)
640
- };
641
- }
642
- const pe = (e) => e.replace(/[^a-zA-Z0-9._-]/g, "-"), he = (e) => e.split("/").map((n) => n.replace(/[^a-zA-Z0-9._-]/g, "-")).filter((n) => n && n !== "-" && n !== "..").join("/");
643
- function A(e) {
644
- const n = g(e, "schema.ts");
645
- let o = `import type { Schema } from "okno"
646
-
647
- `, a = {};
648
- if (_(n)) {
649
- const u = O(n, "utf-8"), l = u.indexOf("export default");
650
- l > 0 && (o = u.slice(0, l));
651
- try {
652
- a = J(u) ?? {};
653
- } catch {
654
- a = {};
655
- }
656
- }
657
- return { schema: a, header: o };
658
- }
659
- function lt(e, n, o) {
660
- x(g(e, "schema.ts"), Ae(n, o));
661
- }
662
- function ct(e, n, o, a, u) {
663
- const l = g(e, n), f = new Set(u), c = [];
664
- if (!_(l) || Object.keys(a).length === 0 && f.size === 0) return c;
665
- const i = [], t = (s) => {
666
- for (const r of D(s, { withFileTypes: !0 })) {
667
- const d = g(s, r.name);
668
- r.isDirectory() ? t(d) : r.name === `${o}.ts` && i.push(d);
669
- }
670
- };
671
- t(l);
672
- for (const s of i) {
673
- let r;
674
- try {
675
- r = J(O(s, "utf-8"));
676
- } catch {
677
- continue;
678
- }
679
- let d, m = !1;
680
- if (Array.isArray(r))
681
- d = r.map((y) => {
682
- if (y && typeof y == "object" && !Array.isArray(y)) {
683
- const p = fe(y, a, f);
684
- return p.changed && (m = !0), p.out;
685
- }
686
- return y;
687
- });
688
- else if (r && typeof r == "object") {
689
- const y = fe(r, a, f);
690
- d = y.out, m = y.changed;
691
- } else
692
- continue;
693
- if (!m) continue;
694
- I(s), x(s, q(d));
695
- const h = z(e, s).split(W).join("/");
696
- c.push({ rel: h, abs: s }), console.log(`[okno] field-change migrated content: ${h}`, { renames: a, deletes: u });
697
- }
698
- return c;
699
- }
700
- let X;
701
- function Y(e) {
702
- return X || (X = ee("git rev-parse --show-toplevel", { cwd: e, encoding: "utf-8" }).trim()), X;
703
- }
704
- function ge(e) {
705
- return z(Y(e), Se(e)).split(W).join("/");
706
- }
707
- let U;
708
- function ut(e) {
709
- if (U !== void 0) return U;
710
- try {
711
- U = ee("git config user.name", { cwd: e, encoding: "utf-8" }).trim() || "local";
712
- } catch {
713
- U = "local";
714
- }
715
- return U;
716
- }
717
- async function Et(e, n) {
718
- const { method: o, route: a } = n, u = { files: [], modules: [] }, l = (t, s) => {
719
- const r = t.split("/")[0];
720
- r !== "pages" && r !== "collections" && r !== "globals" || (u.modules.push(r), u.files.push(s));
721
- }, f = () => u.modules.push("pages", "collections", "globals"), c = (t, s) => {
722
- lt(e, t, s), f();
723
- }, i = (t, s) => ({ status: t, body: s, invalidation: u });
724
- try {
725
- if (o === "GET" && a === "content") return i(200, it(e));
726
- if (o === "POST" && a === "content/save") {
727
- const { path: t, content: s, created: r, author: d } = await n.json();
728
- if (!t || !s) return i(400, { error: "Missing path or content" });
729
- const m = N(e, t);
730
- if (!m) return i(400, { error: "Invalid path" });
731
- const h = Te(s, { now: (/* @__PURE__ */ new Date()).toISOString(), author: d || ut(e), created: r });
732
- return M(E(m), { recursive: !0 }), I(m), x(m, h), l(t, m), i(200, { ok: !0, commit: { fileSha: "" } });
733
- }
734
- if (o === "POST" && a === "content/delete") {
735
- const t = (await n.json())?.path;
736
- if (!t) return i(400, { error: "Missing path" });
737
- const s = N(e, t);
738
- return s ? (_(s) && (L(s), l(t, s)), i(200, { ok: !0 })) : i(400, { error: "Invalid path" });
739
- }
740
- if (o === "POST" && a === "strings/save") {
741
- const { path: t, content: s } = await n.json();
742
- if (!t || !s || typeof s != "object") return i(400, { error: "Missing path or content" });
743
- if (t !== "strings.ts" && !/^strings\/[^/]+\.ts$/.test(t)) return i(400, { error: "Invalid strings path" });
744
- const r = N(e, t);
745
- return r ? (M(E(r), { recursive: !0 }), I(r), x(r, q(s)), u.modules.push("strings", "content"), u.files.push(r), i(200, { ok: !0, commit: { fileSha: "" } })) : i(400, { error: "Invalid path" });
746
- }
747
- if (o === "POST" && a === "strings/set-schema") {
748
- const { strings: t } = await n.json();
749
- if (t != null && (typeof t != "object" || Array.isArray(t))) return i(400, { error: "Invalid strings" });
750
- const { schema: s, header: r } = A(e);
751
- return xe(s, t), c(s, r), u.modules.push("strings", "content"), i(200, { ok: !0, commit: { fileSha: "" }, schema: s });
752
- }
753
- if (o === "GET" && a === "publish-state")
754
- try {
755
- const s = await ue(Y(e)).status(), r = ge(e), d = s.files.some((m) => m.path.startsWith(r + "/"));
756
- return i(200, { pendingPublish: d || s.ahead > 0 });
757
- } catch {
758
- return i(200, { pendingPublish: !1 });
759
- }
760
- if (o === "POST" && a === "publish") {
761
- const t = ue(Y(e)), s = ge(e);
762
- await t.raw(["add", "-A", "--", s]);
763
- const r = await t.status(), d = r.staged.length > 0;
764
- let m = !1;
765
- d && (await t.commit("okno: publish content"), m = !0);
766
- let h = !1, y = null;
767
- try {
768
- (m || r.ahead > 0) && (await t.push(), h = !0);
769
- } catch (p) {
770
- y = p instanceof Error ? p.message.split(`
771
- `)[0] : String(p);
772
- }
773
- return i(200, { ok: !0, alreadyUpToDate: !m && r.ahead === 0, committed: m, pushed: h, pushError: y });
774
- }
775
- if (o === "POST" && a === "schema/save-fields") {
776
- const { kind: t, name: s, fields: r, renames: d, deletes: m } = await n.json();
777
- if (!t || !s || !r) return i(400, { error: "Missing kind, name or fields" });
778
- const { schema: h, header: y } = A(e);
779
- Pe(h, t, s, r), c(h, y);
780
- const p = d && typeof d == "object" ? d : {}, $ = Array.isArray(m) ? m : [];
781
- if (Object.keys(p).length > 0 || $.length > 0)
782
- for (const { rel: k, abs: S } of ct(e, t, s, p, $)) l(k, S);
783
- return i(200, { ok: !0, commit: { fileSha: "" }, schema: h });
784
- }
785
- if (o === "POST" && a === "schema/set-locales") {
786
- const t = (await n.json())?.locales, { schema: s, header: r } = A(e);
787
- return Re(s, t), c(s, r), i(200, { ok: !0, commit: { fileSha: "" } });
788
- }
789
- if (o === "POST" && a === "schema/set-name") {
790
- const { kind: t, slug: s, name: r } = await n.json();
791
- if (!t || !s || !r) return i(400, { error: "Missing kind, slug or name" });
792
- const { schema: d, header: m } = A(e);
793
- return Ee(d, t, s, r), c(d, m), i(200, { ok: !0, commit: { fileSha: "" } });
794
- }
795
- if (o === "POST" && a === "schema/set-url") {
796
- const { kind: t, slug: s, url: r } = await n.json();
797
- if (!t || !s) return i(400, { error: "Missing kind or slug" });
798
- const { schema: d, header: m } = A(e);
799
- return Me(d, t, s, r), c(d, m), i(200, { ok: !0, commit: { fileSha: "" } });
800
- }
801
- if (o === "POST" && a === "schema/rename-slug") {
802
- const { kind: t, from: s, to: r } = await n.json();
803
- if (!t || !s || !r) return i(400, { error: "Missing kind, from or to" });
804
- const { schema: d, header: m } = A(e), { unchanged: h } = Ne(d, t, s, r);
805
- if (h) return i(200, { ok: !0, unchanged: !0 });
806
- c(d, m);
807
- const y = `${t}/${s}.ts`, p = `${t}/${r}.ts`, $ = N(e, y), k = N(e, p);
808
- return $ && k && _($) && (M(E(k), { recursive: !0 }), I($), I(k), x(k, O($)), L($), l(y, $), l(p, k)), i(200, { ok: !0, commit: { fileSha: "" }, schema: d, from: s, to: r, kind: t });
809
- }
810
- if (o === "POST" && a === "schema/reorder") {
811
- const { kind: t, order: s } = await n.json();
812
- if (!t || !Array.isArray(s)) return i(400, { error: "Missing kind or order" });
813
- const { schema: r, header: d } = A(e);
814
- return Ie(r, t, s), c(r, d), i(200, { ok: !0, commit: { fileSha: "" }, schema: r });
815
- }
816
- if (o === "POST" && a === "schema/set-layout") {
817
- const { kind: t, layout: s } = await n.json();
818
- if (!t || !Array.isArray(s)) return i(400, { error: "Missing kind or layout" });
819
- const { schema: r, header: d } = A(e);
820
- return We(r, t, s), c(r, d), i(200, { ok: !0, commit: { fileSha: "" }, schema: r });
821
- }
822
- if (o === "POST" && a === "collections/set-order") {
823
- const { name: t, order: s } = await n.json();
824
- if (!t || !Array.isArray(s)) return i(400, { error: "Missing name or order" });
825
- const { schema: r, header: d } = A(e);
826
- return Fe(r, t, s), c(r, d), i(200, { ok: !0, commit: { fileSha: "" }, schema: r });
827
- }
828
- if (o === "POST" && a === "collections/set-drafts") {
829
- const { name: t, drafts: s } = await n.json();
830
- if (!t || typeof s != "boolean") return i(400, { error: "Missing name or drafts" });
831
- const { schema: r, header: d } = A(e);
832
- return Le(r, t, s), c(r, d), i(200, { ok: !0, commit: { fileSha: "" }, schema: r });
833
- }
834
- if (o === "POST" && a === "schema/delete-entry") {
835
- const { kind: t, name: s } = await n.json();
836
- if (!t || !s) return i(400, { error: "Missing kind or name" });
837
- const { schema: r, header: d } = A(e);
838
- Ue(r, t, s), c(r, d);
839
- const m = `${t}/${s}.ts`, h = N(e, m);
840
- return h && _(h) && (I(h), L(h), l(m, h)), i(200, { ok: !0, commit: { fileSha: "" }, schema: r });
841
- }
842
- if (o === "POST" && a === "setup/scaffold-page") {
843
- const { name: t, kind: s, fields: r, label: d } = await n.json();
844
- if (!t || !s) return i(400, { error: "Missing name or kind" });
845
- const m = r ?? [], { schema: h, header: y } = A(e);
846
- if (Ce(h, t, s, m, d), c(h, y), s !== "blocks") {
847
- const p = `${s}/${t}.ts`, $ = N(e, p);
848
- if ($) {
849
- const k = s === "collections" ? `export default []
850
- ` : q(ze(m));
851
- M(E($), { recursive: !0 }), I($), x($, k), l(p, $);
852
- }
853
- }
854
- return i(200, { ok: !0 });
855
- }
856
- if (o === "GET" && a === "files") {
857
- const t = g(e, "files", ".okno-tree.json");
858
- return i(200, {
859
- files: $e(e),
860
- manifest: _(t) ? O(t, "utf-8") : null
861
- });
862
- }
863
- if (o === "POST" && a === "files/blob") {
864
- const t = pe(decodeURIComponent(n.header("x-okno-filename") || "")), s = n.header("x-okno-dir") ? decodeURIComponent(n.header("x-okno-dir")) : "";
865
- if (!t || t === "-") return i(400, { error: "Invalid filename" });
866
- const r = he(s), d = r ? `${r}/${t}` : t, m = F(e, `files/${d}`);
867
- if (!m) return i(400, { error: "Invalid path" });
868
- const h = await n.binary();
869
- return h.length === 0 ? i(400, { error: "Empty body" }) : (M(E(m), { recursive: !0 }), x(m, h), i(200, { ok: !0, blobSha: "", path: `files/${d}`, filename: t }));
870
- }
871
- if (o === "POST" && a === "files/commit") return i(200, { ok: !0 });
872
- if (o === "POST" && a === "files/upload") {
873
- const { filename: t, content: s, dir: r } = await n.json();
874
- if (!t || s == null) return i(400, { error: "Missing filename or content" });
875
- const d = pe(t);
876
- if (!d || d === "-") return i(400, { error: "Invalid filename" });
877
- const m = he(r ?? ""), h = m ? `${m}/${d}` : d, y = F(e, `files/${h}`);
878
- return y ? (M(E(y), { recursive: !0 }), x(y, Buffer.from(s, "base64")), i(200, { ok: !0, path: `files/${h}`, filename: d, commit: { fileSha: "" } })) : i(400, { error: "Invalid path" });
879
- }
880
- if (o === "POST" && a === "files/delete") {
881
- const t = (await n.json())?.path;
882
- if (!t) return i(400, { error: "Missing path" });
883
- const s = F(e, t);
884
- return s ? (_(s) && L(s), i(200, { ok: !0 })) : i(400, { error: "Invalid path" });
885
- }
886
- if (o === "POST" && a === "files/delete-many") {
887
- const t = (await n.json())?.paths;
888
- if (!Array.isArray(t)) return i(400, { error: "Missing paths" });
889
- for (const s of t) {
890
- const r = F(e, String(s));
891
- r && _(r) && L(r);
892
- }
893
- return i(200, { ok: !0 });
894
- }
895
- if (o === "POST" && a === "files/rename") {
896
- const { from: t, to: s } = await n.json();
897
- if (!t || !s) return i(400, { error: "Missing from or to" });
898
- const r = F(e, t), d = F(e, s);
899
- return !r || !d ? i(400, { error: "Invalid path" }) : _(r) ? (M(E(d), { recursive: !0 }), Oe(r, d), i(200, { ok: !0, commit: { fileSha: "" } })) : i(404, { error: "Source not found" });
900
- }
901
- if (o === "POST" && a === "users/save") {
902
- const t = (await n.json())?.users;
903
- return Array.isArray(t) ? (x(g(e, "users.json"), JSON.stringify(t, null, " ") + `
904
- `), i(200, { ok: !0, commit: { fileSha: "" } })) : i(400, { error: "Missing users" });
905
- }
906
- if (o === "POST" && a === "origins/save") {
907
- const t = (await n.json())?.origins;
908
- if (!Array.isArray(t) || t.some((r) => typeof r != "string")) return i(400, { error: "Missing origins" });
909
- const s = [...new Set(t.map((r) => r.trim()).filter(Boolean))];
910
- return x(g(e, "origins.json"), JSON.stringify(s, null, " ") + `
911
- `), i(200, { ok: !0, origins: s, commit: { fileSha: "" } });
912
- }
913
- return null;
914
- } catch (t) {
915
- return t instanceof Je ? { status: t.status, body: { error: t.message } } : { status: 500, body: { error: t instanceof Error ? t.message : String(t) } };
916
- }
917
- }
918
- export {
919
- ne as I,
920
- xt as a,
921
- Tt as b,
922
- Pt as c,
923
- At as d,
924
- jt as e,
925
- vt as f,
926
- Ot as g,
927
- St as h,
928
- bt as i,
929
- wt as j,
930
- Et as k,
931
- Rt as l,
932
- it as m,
933
- Z as s
934
- };