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