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