@brightsideoy/kama 0.1.0-alpha.127 → 0.1.0-alpha.129

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/index.js CHANGED
@@ -4401,10 +4401,13 @@ function kr() {
4401
4401
  return null;
4402
4402
  }
4403
4403
  }
4404
- function Ar(e) {
4405
- return jr(e);
4404
+ var Ar = null, jr = null;
4405
+ function Mr(e) {
4406
+ if (Ar && jr === e) return Ar;
4407
+ let t = Nr(e);
4408
+ return Ar = t, jr = e, t;
4406
4409
  }
4407
- function jr(e) {
4410
+ function Nr(e) {
4408
4411
  if (e) {
4409
4412
  let n = {
4410
4413
  nodes: {
@@ -4445,7 +4448,7 @@ function jr(e) {
4445
4448
  }
4446
4449
  return r;
4447
4450
  };
4448
- return Mr({
4451
+ return Pr({
4449
4452
  rawNodes: e(n.nodes),
4450
4453
  rawTrees: e(n.trees),
4451
4454
  rawChannels: e(n.channels),
@@ -4455,12 +4458,12 @@ function jr(e) {
4455
4458
  rawFieldSets: e(n.fieldSets)
4456
4459
  });
4457
4460
  }
4458
- return Mr(n);
4461
+ return Pr(n);
4459
4462
  }
4460
4463
  let n = kr();
4461
- return n && Object.keys(n.rawNodes || {}).length > 0 ? Mr(n) : Mr(null);
4464
+ return n && Object.keys(n.rawNodes || {}).length > 0 ? Pr(n) : Pr(null);
4462
4465
  }
4463
- function Mr(e) {
4466
+ function Pr(e) {
4464
4467
  if (!e) return {
4465
4468
  nodes: {},
4466
4469
  trees: {},
@@ -4747,7 +4750,7 @@ function Mr(e) {
4747
4750
  }
4748
4751
  //#endregion
4749
4752
  //#region node_modules/hono/dist/middleware/cors/index.js
4750
- var Nr = (e) => {
4753
+ var Fr = (e) => {
4751
4754
  let t = {
4752
4755
  origin: "*",
4753
4756
  allowMethods: [
@@ -4792,17 +4795,17 @@ var Nr = (e) => {
4792
4795
  }
4793
4796
  await o(), t.origin !== "*" && e.header("Vary", "Origin", { append: !0 });
4794
4797
  };
4795
- }, Pr = (/* @__PURE__ */ i(((e, t) => {
4798
+ }, Ir = (/* @__PURE__ */ i(((e, t) => {
4796
4799
  t.exports = {};
4797
- })))(), Fr = null;
4798
- function Ir() {
4799
- if (!Fr) {
4800
- let e = (0, Pr.createRequire)(import.meta.url), t = e("better-sqlite3"), n = e("node:path"), r = e("node:fs"), i = n.resolve(process.cwd(), "./data/cms.db");
4801
- r.mkdirSync(n.dirname(i), { recursive: !0 }), Fr = new t(i), Fr.pragma("journal_mode = WAL");
4800
+ })))(), Lr = null;
4801
+ function Rr() {
4802
+ if (!Lr) {
4803
+ let e = (0, Ir.createRequire)(import.meta.url), t = e("better-sqlite3"), n = e("node:path"), r = e("node:fs"), i = n.resolve(process.cwd(), "./data/cms.db");
4804
+ r.mkdirSync(n.dirname(i), { recursive: !0 }), Lr = new t(i), Lr.pragma("journal_mode = WAL");
4802
4805
  }
4803
- return Fr;
4806
+ return Lr;
4804
4807
  }
4805
- function Lr(e) {
4808
+ function zr(e) {
4806
4809
  let t = e?.env?.kama_db || e?.env?.DB;
4807
4810
  if (t) return {
4808
4811
  prepare(e) {
@@ -4835,7 +4838,7 @@ function Lr(e) {
4835
4838
  await t.batch(n);
4836
4839
  }
4837
4840
  };
4838
- let n = Ir();
4841
+ let n = Rr();
4839
4842
  return {
4840
4843
  prepare(e) {
4841
4844
  let t = n.prepare(e);
@@ -4871,7 +4874,7 @@ function Lr(e) {
4871
4874
  }
4872
4875
  //#endregion
4873
4876
  //#region server/db/dynamic-sync.ts
4874
- async function Rr(e, t) {
4877
+ async function Br(e, t) {
4875
4878
  try {
4876
4879
  let n = await e.prepare(`PRAGMA table_info("${t}")`).all(), r = Array.isArray(n) ? n : n?.results || [];
4877
4880
  return new Set(r.map((e) => e.name));
@@ -4879,7 +4882,7 @@ async function Rr(e, t) {
4879
4882
  return /* @__PURE__ */ new Set();
4880
4883
  }
4881
4884
  }
4882
- var zr = {
4885
+ var Vr = {
4883
4886
  content_schemas: "\n id TEXT PRIMARY KEY,\n name TEXT NOT NULL,\n type TEXT UNIQUE NOT NULL,\n schemaJson TEXT NOT NULL,\n isSystem INTEGER DEFAULT 1,\n createdAt TEXT DEFAULT CURRENT_TIMESTAMP,\n updatedAt TEXT DEFAULT CURRENT_TIMESTAMP\n ",
4884
4887
  users: "\n id TEXT PRIMARY KEY,\n email TEXT UNIQUE NOT NULL,\n name TEXT NOT NULL,\n globalRole TEXT DEFAULT 'editor',\n createdAt TEXT DEFAULT CURRENT_TIMESTAMP,\n updatedAt TEXT DEFAULT CURRENT_TIMESTAMP\n ",
4885
4888
  user_accounts: "\n id TEXT PRIMARY KEY,\n userId TEXT NOT NULL,\n provider TEXT NOT NULL,\n providerAccountId TEXT NOT NULL,\n passwordHash TEXT NOT NULL,\n createdAt TEXT DEFAULT CURRENT_TIMESTAMP,\n FOREIGN KEY (userId) REFERENCES users(id) ON DELETE CASCADE,\n UNIQUE(provider, providerAccountId)\n ",
@@ -4894,14 +4897,14 @@ var zr = {
4894
4897
  node_revisions: "\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n nodeId INTEGER NOT NULL,\n version INTEGER NOT NULL DEFAULT 1,\n snapshotJson TEXT NOT NULL,\n createdById TEXT,\n createdAt TEXT DEFAULT CURRENT_TIMESTAMP,\n FOREIGN KEY (nodeId) REFERENCES content_nodes(id) ON DELETE CASCADE,\n FOREIGN KEY (createdById) REFERENCES users(id) ON DELETE SET NULL\n ",
4895
4898
  assets: "\n id TEXT PRIMARY KEY,\n filename TEXT NOT NULL,\n mimeType TEXT NOT NULL,\n sizeBytes INTEGER NOT NULL,\n storageKeyPrivate TEXT,\n cdnUrl TEXT,\n parentAssetId TEXT,\n cropCoordinatesJson TEXT,\n isSystemVariant INTEGER DEFAULT 0,\n dataJson TEXT DEFAULT '{}',\n createdById TEXT,\n createdAt TEXT DEFAULT CURRENT_TIMESTAMP,\n updatedAt TEXT DEFAULT CURRENT_TIMESTAMP,\n deletedAt TEXT,\n FOREIGN KEY (parentAssetId) REFERENCES assets(id) ON DELETE SET NULL,\n FOREIGN KEY (createdById) REFERENCES users(id) ON DELETE SET NULL\n ",
4896
4899
  node_assets: "\n nodeId INTEGER NOT NULL,\n assetId TEXT NOT NULL,\n fieldKey TEXT NOT NULL,\n sortOrder INTEGER DEFAULT 0,\n PRIMARY KEY (nodeId, assetId, fieldKey),\n FOREIGN KEY (nodeId) REFERENCES content_nodes(id) ON DELETE CASCADE,\n FOREIGN KEY (assetId) REFERENCES assets(id) ON DELETE CASCADE\n "
4897
- }, Br = /* @__PURE__ */ "CREATE INDEX IF NOT EXISTS idx_tree_nodes_tree_parent ON tree_nodes(treeId, parentId);.CREATE INDEX IF NOT EXISTS idx_tree_nodes_contentId ON tree_nodes(contentId);.CREATE INDEX IF NOT EXISTS idx_content_nodes_slug_status ON content_nodes(slug, status);.CREATE INDEX IF NOT EXISTS idx_content_blocks_node ON content_blocks(contentId, isDraft);.CREATE INDEX IF NOT EXISTS idx_node_assets_nodeId ON node_assets(nodeId);.CREATE INDEX IF NOT EXISTS idx_node_assets_assetId ON node_assets(assetId);.CREATE INDEX IF NOT EXISTS idx_content_schemas_type ON content_schemas(type);.CREATE INDEX IF NOT EXISTS idx_sessions_user ON sessions(userId);.CREATE INDEX IF NOT EXISTS idx_sessions_expires ON sessions(expiresAt);.CREATE INDEX IF NOT EXISTS idx_channels_visibility ON channels(isHidden);.CREATE INDEX IF NOT EXISTS idx_trees_visibility ON trees(isHidden);.CREATE INDEX IF NOT EXISTS idx_content_nodes_visibility ON content_nodes(isHidden, status);.CREATE INDEX IF NOT EXISTS idx_content_nodes_slug ON content_nodes(slug);.CREATE INDEX IF NOT EXISTS idx_content_nodes_type ON content_nodes(contentType);.CREATE INDEX IF NOT EXISTS idx_content_nodes_deleted_updated ON content_nodes(deletedAt, updatedAt DESC);.CREATE INDEX IF NOT EXISTS idx_tree_nodes_hierarchy ON tree_nodes(treeId, parentId, sortOrder);.CREATE INDEX IF NOT EXISTS idx_tree_nodes_content ON tree_nodes(contentId, treeId);.CREATE INDEX IF NOT EXISTS idx_content_blocks_content ON content_blocks(contentId, isDraft, region, sortOrder);.CREATE INDEX IF NOT EXISTS idx_node_channels_channel ON node_channels(channelId, nodeId);.CREATE INDEX IF NOT EXISTS idx_node_channels_node ON node_channels(nodeId, channelId);.CREATE INDEX IF NOT EXISTS idx_node_assets_node_asset ON node_assets(nodeId, assetId);.CREATE INDEX IF NOT EXISTS idx_node_assets_asset_node ON node_assets(assetId, nodeId);.CREATE INDEX IF NOT EXISTS idx_node_revisions_node ON node_revisions(nodeId, version);.CREATE INDEX IF NOT EXISTS idx_assets_system_created ON assets(isSystemVariant, createdAt DESC);.CREATE INDEX IF NOT EXISTS idx_assets_system_mime ON assets(isSystemVariant, mimeType);.CREATE INDEX IF NOT EXISTS idx_assets_deleted ON assets(deletedAt);.CREATE INDEX IF NOT EXISTS idx_assets_parent ON assets(parentAssetId);".split(".");
4898
- async function Vr(e, t) {
4900
+ }, Hr = /* @__PURE__ */ "CREATE INDEX IF NOT EXISTS idx_tree_nodes_tree_parent ON tree_nodes(treeId, parentId);.CREATE INDEX IF NOT EXISTS idx_tree_nodes_contentId ON tree_nodes(contentId);.CREATE INDEX IF NOT EXISTS idx_content_nodes_slug_status ON content_nodes(slug, status);.CREATE INDEX IF NOT EXISTS idx_content_blocks_node ON content_blocks(contentId, isDraft);.CREATE INDEX IF NOT EXISTS idx_node_assets_nodeId ON node_assets(nodeId);.CREATE INDEX IF NOT EXISTS idx_node_assets_assetId ON node_assets(assetId);.CREATE INDEX IF NOT EXISTS idx_content_schemas_type ON content_schemas(type);.CREATE INDEX IF NOT EXISTS idx_sessions_user ON sessions(userId);.CREATE INDEX IF NOT EXISTS idx_sessions_expires ON sessions(expiresAt);.CREATE INDEX IF NOT EXISTS idx_channels_visibility ON channels(isHidden);.CREATE INDEX IF NOT EXISTS idx_trees_visibility ON trees(isHidden);.CREATE INDEX IF NOT EXISTS idx_content_nodes_visibility ON content_nodes(isHidden, status);.CREATE INDEX IF NOT EXISTS idx_content_nodes_slug ON content_nodes(slug);.CREATE INDEX IF NOT EXISTS idx_content_nodes_type ON content_nodes(contentType);.CREATE INDEX IF NOT EXISTS idx_content_nodes_deleted_updated ON content_nodes(deletedAt, updatedAt DESC);.CREATE INDEX IF NOT EXISTS idx_tree_nodes_hierarchy ON tree_nodes(treeId, parentId, sortOrder);.CREATE INDEX IF NOT EXISTS idx_tree_nodes_content ON tree_nodes(contentId, treeId);.CREATE INDEX IF NOT EXISTS idx_content_blocks_content ON content_blocks(contentId, isDraft, region, sortOrder);.CREATE INDEX IF NOT EXISTS idx_node_channels_channel ON node_channels(channelId, nodeId);.CREATE INDEX IF NOT EXISTS idx_node_channels_node ON node_channels(nodeId, channelId);.CREATE INDEX IF NOT EXISTS idx_node_assets_node_asset ON node_assets(nodeId, assetId);.CREATE INDEX IF NOT EXISTS idx_node_assets_asset_node ON node_assets(assetId, nodeId);.CREATE INDEX IF NOT EXISTS idx_node_revisions_node ON node_revisions(nodeId, version);.CREATE INDEX IF NOT EXISTS idx_assets_system_created ON assets(isSystemVariant, createdAt DESC);.CREATE INDEX IF NOT EXISTS idx_assets_system_mime ON assets(isSystemVariant, mimeType);.CREATE INDEX IF NOT EXISTS idx_assets_deleted ON assets(deletedAt);.CREATE INDEX IF NOT EXISTS idx_assets_parent ON assets(parentAssetId);".split(".");
4901
+ async function Ur(e, t) {
4899
4902
  try {
4900
4903
  await e.prepare("PRAGMA foreign_keys = ON;").run();
4901
4904
  } catch {}
4902
- for (let [t, n] of Object.entries(zr)) await e.prepare(`CREATE TABLE IF NOT EXISTS "${t}" (${n});`).run();
4903
- for (let [t] of Object.entries(zr)) {
4904
- let n = await Rr(e, t);
4905
+ for (let [t, n] of Object.entries(Vr)) await e.prepare(`CREATE TABLE IF NOT EXISTS "${t}" (${n});`).run();
4906
+ for (let [t] of Object.entries(Vr)) {
4907
+ let n = await Br(e, t);
4905
4908
  if (n.size > 0) {
4906
4909
  if (t === "content_nodes" && !n.has("disabledRegionsJson")) try {
4907
4910
  await e.prepare("ALTER TABLE \"content_nodes\" ADD COLUMN disabledRegionsJson TEXT DEFAULT '{}';").run();
@@ -4916,13 +4919,13 @@ async function Vr(e, t) {
4916
4919
  }
4917
4920
  }
4918
4921
  }
4919
- for (let t of Br) try {
4922
+ for (let t of Hr) try {
4920
4923
  await e.prepare(t).run();
4921
4924
  } catch {}
4922
- await Hr(e, t);
4925
+ await Wr(e, t);
4923
4926
  }
4924
- async function Hr(e, t) {
4925
- let n = Ar(t), r = n.rawNodes || n.nodes || {};
4927
+ async function Wr(e, t) {
4928
+ let n = Mr(t), r = n.rawNodes || n.nodes || {};
4926
4929
  for (let [t, n] of Object.entries(r)) {
4927
4930
  if (!n || typeof n != "object") continue;
4928
4931
  let r = n.type || n.id || t, i = n.name || n.label || r, a = `schema_${r}`, o = JSON.stringify(n);
@@ -4936,7 +4939,7 @@ async function Hr(e, t) {
4936
4939
  }
4937
4940
  //#endregion
4938
4941
  //#region server/middleware/media-static.ts
4939
- function Ur() {
4942
+ function Gr() {
4940
4943
  return async (e, t) => {
4941
4944
  if (e.env?.MEDIA_BUCKET) {
4942
4945
  let t = e.req.path.replace(/^\/media\//, ""), n = await e.env.MEDIA_BUCKET.get(t, { onlyIf: e.req.raw.headers });
@@ -4967,18 +4970,18 @@ function Ur() {
4967
4970
  }
4968
4971
  //#endregion
4969
4972
  //#region node_modules/lru-cache/dist/esm/browser/index.min.js
4970
- var Wr = { hasSubscribers: !1 }, J = Wr, Gr = Wr, Kr = typeof performance == "object" && performance && typeof performance.now == "function" ? performance : Date, qr = () => J.hasSubscribers || Gr.hasSubscribers, Jr = /* @__PURE__ */ new Set(), Yr = typeof process == "object" && process ? process : {}, Xr = (e, t, n, r) => {
4971
- typeof Yr.emitWarning == "function" ? Yr.emitWarning(e, t, n, r) : console.error(`[${n}] ${t}: ${e}`);
4972
- }, Zr = (e) => !Jr.has(e), Qr = (e) => !!e && e === Math.floor(e) && e > 0 && isFinite(e), $r = (e) => Qr(e) ? e <= 256 ? Uint8Array : e <= 2 ** 16 ? Uint16Array : e <= 2 ** 32 ? Uint32Array : e <= 2 ** 53 - 1 ? ei : null : null, ei = class extends Array {
4973
+ var Kr = { hasSubscribers: !1 }, J = Kr, qr = Kr, Jr = typeof performance == "object" && performance && typeof performance.now == "function" ? performance : Date, Yr = () => J.hasSubscribers || qr.hasSubscribers, Xr = /* @__PURE__ */ new Set(), Zr = typeof process == "object" && process ? process : {}, Qr = (e, t, n, r) => {
4974
+ typeof Zr.emitWarning == "function" ? Zr.emitWarning(e, t, n, r) : console.error(`[${n}] ${t}: ${e}`);
4975
+ }, $r = (e) => !Xr.has(e), ei = (e) => !!e && e === Math.floor(e) && e > 0 && isFinite(e), ti = (e) => ei(e) ? e <= 256 ? Uint8Array : e <= 2 ** 16 ? Uint16Array : e <= 2 ** 32 ? Uint32Array : e <= 2 ** 53 - 1 ? ni : null : null, ni = class extends Array {
4973
4976
  constructor(e) {
4974
4977
  super(e), this.fill(0);
4975
4978
  }
4976
- }, ti = class e {
4979
+ }, ri = class e {
4977
4980
  heap;
4978
4981
  length;
4979
4982
  static #e = !1;
4980
4983
  static create(t) {
4981
- let n = $r(t);
4984
+ let n = ti(t);
4982
4985
  if (!n) return [];
4983
4986
  e.#e = !0;
4984
4987
  let r = new e(t, n);
@@ -4994,7 +4997,7 @@ var Wr = { hasSubscribers: !1 }, J = Wr, Gr = Wr, Kr = typeof performance == "ob
4994
4997
  pop() {
4995
4998
  return this.heap[--this.length];
4996
4999
  }
4997
- }, ni = class e {
5000
+ }, ii = class e {
4998
5001
  #e;
4999
5002
  #t;
5000
5003
  #n;
@@ -5097,8 +5100,8 @@ var Wr = { hasSubscribers: !1 }, J = Wr, Gr = Wr, Kr = typeof performance == "ob
5097
5100
  constructor(t) {
5098
5101
  let { max: n = 0, ttl: r, ttlResolution: i = 1, ttlAutopurge: a, updateAgeOnGet: o, updateAgeOnHas: s, allowStale: c, dispose: l, onInsert: u, disposeAfter: d, noDisposeOnSet: f, noUpdateTTL: p, maxSize: m = 0, maxEntrySize: h = 0, sizeCalculation: g, fetchMethod: _, memoMethod: v, noDeleteOnFetchRejection: y, noDeleteOnStaleGet: b, allowStaleOnFetchRejection: x, allowStaleOnFetchAbort: S, ignoreFetchAbort: C, backgroundFetchSize: w = 1, perf: T } = t;
5099
5102
  if (this.backgroundFetchSize = w, T !== void 0 && typeof T?.now != "function") throw TypeError("perf option must have a now() method if specified");
5100
- if (this.#s = T ?? Kr, n !== 0 && !Qr(n)) throw TypeError("max option must be a nonnegative integer");
5101
- let E = n ? $r(n) : Array;
5103
+ if (this.#s = T ?? Jr, n !== 0 && !ei(n)) throw TypeError("max option must be a nonnegative integer");
5104
+ let E = n ? ti(n) : Array;
5102
5105
  if (!E) throw Error("invalid max value: " + n);
5103
5106
  if (this.#e = n, this.#t = m, this.maxEntrySize = h || this.#t, this.sizeCalculation = g, this.sizeCalculation) {
5104
5107
  if (!this.#t && !this.maxEntrySize) throw TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
@@ -5106,26 +5109,26 @@ var Wr = { hasSubscribers: !1 }, J = Wr, Gr = Wr, Kr = typeof performance == "ob
5106
5109
  }
5107
5110
  if (v !== void 0 && typeof v != "function") throw TypeError("memoMethod must be a function if defined");
5108
5111
  if (this.#o = v, _ !== void 0 && typeof _ != "function") throw TypeError("fetchMethod must be a function if specified");
5109
- if (this.#a = _, this.#w = !!_, this.#u = /* @__PURE__ */ new Map(), this.#d = Array.from({ length: n }).fill(void 0), this.#f = Array.from({ length: n }).fill(void 0), this.#p = new E(n), this.#m = new E(n), this.#h = 0, this.#g = 0, this.#_ = ti.create(n), this.#c = 0, this.#l = 0, typeof l == "function" && (this.#n = l), typeof u == "function" && (this.#r = u), typeof d == "function" ? (this.#i = d, this.#v = []) : (this.#i = void 0, this.#v = void 0), this.#C = !!this.#n, this.#E = !!this.#r, this.#T = !!this.#i, this.noDisposeOnSet = !!f, this.noUpdateTTL = !!p, this.noDeleteOnFetchRejection = !!y, this.allowStaleOnFetchRejection = !!x, this.allowStaleOnFetchAbort = !!S, this.ignoreFetchAbort = !!C, this.maxEntrySize !== 0) {
5110
- if (this.#t !== 0 && !Qr(this.#t)) throw TypeError("maxSize must be a positive integer if specified");
5111
- if (!Qr(this.maxEntrySize)) throw TypeError("maxEntrySize must be a positive integer if specified");
5112
+ if (this.#a = _, this.#w = !!_, this.#u = /* @__PURE__ */ new Map(), this.#d = Array.from({ length: n }).fill(void 0), this.#f = Array.from({ length: n }).fill(void 0), this.#p = new E(n), this.#m = new E(n), this.#h = 0, this.#g = 0, this.#_ = ri.create(n), this.#c = 0, this.#l = 0, typeof l == "function" && (this.#n = l), typeof u == "function" && (this.#r = u), typeof d == "function" ? (this.#i = d, this.#v = []) : (this.#i = void 0, this.#v = void 0), this.#C = !!this.#n, this.#E = !!this.#r, this.#T = !!this.#i, this.noDisposeOnSet = !!f, this.noUpdateTTL = !!p, this.noDeleteOnFetchRejection = !!y, this.allowStaleOnFetchRejection = !!x, this.allowStaleOnFetchAbort = !!S, this.ignoreFetchAbort = !!C, this.maxEntrySize !== 0) {
5113
+ if (this.#t !== 0 && !ei(this.#t)) throw TypeError("maxSize must be a positive integer if specified");
5114
+ if (!ei(this.maxEntrySize)) throw TypeError("maxEntrySize must be a positive integer if specified");
5112
5115
  this.#M();
5113
5116
  }
5114
- if (this.allowStale = !!c, this.noDeleteOnStaleGet = !!b, this.updateAgeOnGet = !!o, this.updateAgeOnHas = !!s, this.ttlResolution = Qr(i) || i === 0 ? i : 1, this.ttlAutopurge = !!a, this.ttl = r || 0, this.ttl) {
5115
- if (!Qr(this.ttl)) throw TypeError("ttl must be a positive integer if specified");
5117
+ if (this.allowStale = !!c, this.noDeleteOnStaleGet = !!b, this.updateAgeOnGet = !!o, this.updateAgeOnHas = !!s, this.ttlResolution = ei(i) || i === 0 ? i : 1, this.ttlAutopurge = !!a, this.ttl = r || 0, this.ttl) {
5118
+ if (!ei(this.ttl)) throw TypeError("ttl must be a positive integer if specified");
5116
5119
  this.#D();
5117
5120
  }
5118
5121
  if (this.#e === 0 && this.ttl === 0 && this.#t === 0) throw TypeError("At least one of max, maxSize, or ttl is required");
5119
5122
  if (!this.ttlAutopurge && !this.#e && !this.#t) {
5120
5123
  let t = "LRU_CACHE_UNBOUNDED";
5121
- Zr(t) && (Jr.add(t), Xr("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", t, e));
5124
+ $r(t) && (Xr.add(t), Qr("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", t, e));
5122
5125
  }
5123
5126
  }
5124
5127
  getRemainingTTL(e) {
5125
5128
  return this.#u.has(e) ? 1 / 0 : 0;
5126
5129
  }
5127
5130
  #D() {
5128
- let e = new ei(this.#e), t = new ei(this.#e);
5131
+ let e = new ni(this.#e), t = new ni(this.#e);
5129
5132
  this.#x = e, this.#b = t;
5130
5133
  let n = this.ttlAutopurge ? Array.from({ length: this.#e }) : void 0;
5131
5134
  this.#S = n, this.#A = (n, i, a = this.#s.now()) => {
@@ -5175,15 +5178,15 @@ var Wr = { hasSubscribers: !1 }, J = Wr, Gr = Wr, Kr = typeof performance == "ob
5175
5178
  #A = () => {};
5176
5179
  #j = () => !1;
5177
5180
  #M() {
5178
- let e = new ei(this.#e);
5181
+ let e = new ni(this.#e);
5179
5182
  this.#l = 0, this.#y = e, this.#N = (t) => {
5180
5183
  this.#l -= e[t], e[t] = 0;
5181
5184
  }, this.#F = (e, t, n, r) => {
5182
- if (!Qr(n)) {
5185
+ if (!ei(n)) {
5183
5186
  if (this.#W(t)) return this.backgroundFetchSize;
5184
5187
  if (r) {
5185
5188
  if (typeof r != "function") throw TypeError("sizeCalculation must be a function");
5186
- if (n = r(t, e), !Qr(n)) throw TypeError("sizeCalculation return invalid (expect positive integer)");
5189
+ if (n = r(t, e), !ei(n)) throw TypeError("sizeCalculation return invalid (expect positive integer)");
5187
5190
  } else throw TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
5188
5191
  }
5189
5192
  return n;
@@ -5386,7 +5389,7 @@ var Wr = { hasSubscribers: !1 }, J = Wr, Gr = Wr, Kr = typeof performance == "ob
5386
5389
  return !1;
5387
5390
  }
5388
5391
  peek(e, t = {}) {
5389
- let { status: n = qr() ? {} : void 0 } = t;
5392
+ let { status: n = Yr() ? {} : void 0 } = t;
5390
5393
  n && (n.op = "peek", n.key = e, n.cache = this), t.status = n;
5391
5394
  let r = this.#H(e, t);
5392
5395
  return J.hasSubscribers && J.publish(n), r;
@@ -5441,10 +5444,10 @@ var Wr = { hasSubscribers: !1 }, J = Wr, Gr = Wr, Kr = typeof performance == "ob
5441
5444
  return !!t && t instanceof Promise && t.hasOwnProperty("__staleWhileFetching") && t.__abortController instanceof AbortController;
5442
5445
  }
5443
5446
  fetch(e, t = {}) {
5444
- let n = Gr.hasSubscribers, { status: r = qr() ? {} : void 0 } = t;
5447
+ let n = qr.hasSubscribers, { status: r = Yr() ? {} : void 0 } = t;
5445
5448
  t.status = r, r && t.context && (r.context = t.context);
5446
5449
  let i = this.#G(e, t);
5447
- return r && n && (r.trace = !0, Gr.tracePromise(() => i, r).catch(() => {})), i;
5450
+ return r && n && (r.trace = !0, qr.tracePromise(() => i, r).catch(() => {})), i;
5448
5451
  }
5449
5452
  async #G(e, t = {}) {
5450
5453
  let { allowStale: n = this.allowStale, updateAgeOnGet: r = this.updateAgeOnGet, noDeleteOnStaleGet: i = this.noDeleteOnStaleGet, ttl: a = this.ttl, noDisposeOnSet: o = this.noDisposeOnSet, size: s = 0, sizeCalculation: c = this.sizeCalculation, noUpdateTTL: l = this.noUpdateTTL, noDeleteOnFetchRejection: u = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection: d = this.allowStaleOnFetchRejection, ignoreFetchAbort: f = this.ignoreFetchAbort, allowStaleOnFetchAbort: p = this.allowStaleOnFetchAbort, context: m, forceRefresh: h = !1, status: g, signal: _ } = t;
@@ -5488,10 +5491,10 @@ var Wr = { hasSubscribers: !1 }, J = Wr, Gr = Wr, Kr = typeof performance == "ob
5488
5491
  }
5489
5492
  }
5490
5493
  forceFetch(e, t = {}) {
5491
- let n = Gr.hasSubscribers, { status: r = qr() ? {} : void 0 } = t;
5494
+ let n = qr.hasSubscribers, { status: r = Yr() ? {} : void 0 } = t;
5492
5495
  t.status = r, r && t.context && (r.context = t.context);
5493
5496
  let i = this.#K(e, t);
5494
- return r && n && (r.trace = !0, Gr.tracePromise(() => i, r).catch(() => {})), i;
5497
+ return r && n && (r.trace = !0, qr.tracePromise(() => i, r).catch(() => {})), i;
5495
5498
  }
5496
5499
  async #K(e, t = {}) {
5497
5500
  let n = await this.#G(e, t);
@@ -5604,10 +5607,10 @@ var Wr = { hasSubscribers: !1 }, J = Wr, Gr = Wr, Kr = typeof performance == "ob
5604
5607
  for (; t = e?.shift();) this.#i?.(...t);
5605
5608
  }
5606
5609
  }
5607
- }, ri = class {
5610
+ }, ai = class {
5608
5611
  cache;
5609
5612
  constructor(e = 1e3, t = 3e5) {
5610
- this.cache = new ni({
5613
+ this.cache = new ii({
5611
5614
  max: e,
5612
5615
  ttl: t
5613
5616
  });
@@ -5626,7 +5629,7 @@ var Wr = { hasSubscribers: !1 }, J = Wr, Gr = Wr, Kr = typeof performance == "ob
5626
5629
  async clear() {
5627
5630
  this.cache.clear();
5628
5631
  }
5629
- }, ii = class {
5632
+ }, oi = class {
5630
5633
  kv;
5631
5634
  constructor(e) {
5632
5635
  this.kv = e;
@@ -5643,37 +5646,37 @@ var Wr = { hasSubscribers: !1 }, J = Wr, Gr = Wr, Kr = typeof performance == "ob
5643
5646
  this.kv && await this.kv.delete(e);
5644
5647
  }
5645
5648
  async clear() {}
5646
- }, ai = class {
5649
+ }, si = class {
5647
5650
  async get() {
5648
5651
  return null;
5649
5652
  }
5650
5653
  async set() {}
5651
5654
  async delete() {}
5652
5655
  async clear() {}
5653
- }, oi = null;
5656
+ }, ci = null;
5654
5657
  function Y(e) {
5655
5658
  let t = process.env.CACHE_DRIVER || "lru";
5656
- return t === "none" || t === "off" || t === "false" ? new ai() : e?.env?.CMS_CACHE_KV ? new ii(e.env.CMS_CACHE_KV) : t === "lru" ? (oi ||= new ri(), oi) : new ai();
5659
+ return t === "none" || t === "off" || t === "false" ? new si() : e?.env?.CMS_CACHE_KV ? new oi(e.env.CMS_CACHE_KV) : t === "lru" ? (ci ||= new ai(), ci) : new si();
5657
5660
  }
5658
5661
  //#endregion
5659
5662
  //#region server/utils/asset-hydrator.ts
5660
- function si(e) {
5663
+ function li(e) {
5661
5664
  if (!e) return null;
5662
5665
  if (typeof e == "string" && e.startsWith("ast_")) return e;
5663
5666
  if (typeof e == "object" && e) {
5664
5667
  if (typeof e.id == "string" && e.id.startsWith("ast_")) return e.id;
5665
- if (typeof e.id == "object") return si(e.id);
5668
+ if (typeof e.id == "object") return li(e.id);
5666
5669
  }
5667
5670
  return null;
5668
5671
  }
5669
- async function ci(e, t) {
5672
+ async function ui(e, t) {
5670
5673
  if (!t || typeof t != "object" || !JSON.stringify(t).includes("ast_")) return t;
5671
5674
  let n = /* @__PURE__ */ new Set(), r = (e) => {
5672
5675
  if (!e) return;
5673
- let t = si(e);
5676
+ let t = li(e);
5674
5677
  if (t) {
5675
5678
  if (n.add(t), typeof e == "object" && e.parentAssetId) {
5676
- let t = si(e.parentAssetId);
5679
+ let t = li(e.parentAssetId);
5677
5680
  t && n.add(t);
5678
5681
  }
5679
5682
  } else Array.isArray(e) ? e.forEach(r) : typeof e == "object" && Object.values(e).forEach(r);
@@ -5709,7 +5712,7 @@ async function ci(e, t) {
5709
5712
  }
5710
5713
  let s = /* @__PURE__ */ new Map();
5711
5714
  for (let e of o) {
5712
- let t = si(e.parentAssetId) || i.find((t) => e.filename.includes(t));
5715
+ let t = li(e.parentAssetId) || i.find((t) => e.filename.includes(t));
5713
5716
  if (!t) continue;
5714
5717
  let n = e.filename.match(/^crop_([a-z0-9]+)_/i), r = n ? n[1] : "standard", a = null;
5715
5718
  if (e.cropCoordinatesJson) try {
@@ -5744,7 +5747,7 @@ async function ci(e, t) {
5744
5747
  id: e.id,
5745
5748
  url: t,
5746
5749
  originalUrl: n,
5747
- parentAssetId: si(e.parentAssetId) || null,
5750
+ parentAssetId: li(e.parentAssetId) || null,
5748
5751
  cropCoordinates: r,
5749
5752
  variants: i && Object.keys(i).length > 0 ? i : void 0,
5750
5753
  filename: e.filename,
@@ -5756,7 +5759,7 @@ async function ci(e, t) {
5756
5759
  }
5757
5760
  let l = (e) => {
5758
5761
  if (!e) return e;
5759
- let t = si(e);
5762
+ let t = li(e);
5760
5763
  if (t) {
5761
5764
  let n = c.get(t) || {
5762
5765
  id: t,
@@ -5766,7 +5769,7 @@ async function ci(e, t) {
5766
5769
  return {
5767
5770
  ...n,
5768
5771
  id: t,
5769
- parentAssetId: n.parentAssetId ? si(n.parentAssetId) : null,
5772
+ parentAssetId: n.parentAssetId ? li(n.parentAssetId) : null,
5770
5773
  url: typeof e == "object" && e.url && !e.url.startsWith("blob:") ? e.url : n.url,
5771
5774
  originalUrl: typeof e == "object" && e.originalUrl && !e.originalUrl.startsWith("blob:") ? e.originalUrl : n.originalUrl,
5772
5775
  cropCoordinates: i || n.cropCoordinates || null,
@@ -5906,13 +5909,13 @@ var X = class {
5906
5909
  }
5907
5910
  }
5908
5911
  }, Z = new n();
5909
- function li(e, t) {
5912
+ function di(e, t) {
5910
5913
  let n = Promise.resolve(typeof t == "function" ? t() : t).catch((e) => console.error("[Background Task Error]:", e));
5911
5914
  try {
5912
5915
  e.executionCtx && typeof e.executionCtx.waitUntil == "function" && e.executionCtx.waitUntil(n);
5913
5916
  } catch {}
5914
5917
  }
5915
- async function ui(e, t, n = []) {
5918
+ async function fi(e, t, n = []) {
5916
5919
  let r = e.prepare(t);
5917
5920
  if (typeof r.bind == "function") {
5918
5921
  let e = await r.bind(...n).all();
@@ -5924,23 +5927,23 @@ async function ui(e, t, n = []) {
5924
5927
  }
5925
5928
  return [];
5926
5929
  }
5927
- async function di(e, t, n = []) {
5930
+ async function pi(e, t, n = []) {
5928
5931
  let r = e.prepare(t);
5929
5932
  if (typeof r.bind == "function") return r.bind(...n).run();
5930
5933
  if (typeof r.run == "function") return r.run(...n);
5931
5934
  }
5932
- function fi(e) {
5935
+ function mi(e) {
5933
5936
  return !e || !e.trim() ? null : e.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/[^a-z0-9\s-]/g, "").replace(/[\s-]+/g, "-").replace(/^-+|-+$/g, "") || null;
5934
5937
  }
5935
- function pi(e) {
5938
+ function hi(e) {
5936
5939
  return +(e === !0 || e === 1 || e === "1" || e === "true");
5937
5940
  }
5938
- function mi(e) {
5941
+ function gi(e) {
5939
5942
  if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
5940
5943
  let t = Number(e);
5941
5944
  return isNaN(t) ? null : t;
5942
5945
  }
5943
- function hi(e) {
5946
+ function _i(e) {
5944
5947
  if (!e || typeof e != "object") return {};
5945
5948
  let t = { ...e };
5946
5949
  for (let e of [
@@ -5971,7 +5974,7 @@ function hi(e) {
5971
5974
  ]) e === "id" && typeof t[e] == "string" && t[e].startsWith("ast_") || delete t[e];
5972
5975
  return t;
5973
5976
  }
5974
- async function gi(e, t, n) {
5977
+ async function vi(e, t, n) {
5975
5978
  let r = {}, i = null;
5976
5979
  if (t) {
5977
5980
  let n = await e.prepare("\n WITH RECURSIVE ancestor_path(id, parentId, draftDataJson, dataJson, level) AS (\n SELECT t.id, t.parentId, c.draftDataJson, c.dataJson, 0 FROM tree_nodes t\n INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.id = ?\n UNION ALL\n SELECT t.id, t.parentId, c.draftDataJson, c.dataJson, ap.level + 1 FROM tree_nodes t\n INNER JOIN content_nodes c ON t.contentId = c.id INNER JOIN ancestor_path ap ON t.id = ap.parentId\n ) SELECT draftDataJson, dataJson FROM ancestor_path ORDER BY level ASC\n ").all(t), a = Array.isArray(n) ? n : n?.results || [], o = /* @__PURE__ */ new Set([
@@ -6034,7 +6037,7 @@ Z.get("/", async (e) => {
6034
6037
  updatedAt: i.updatedAt
6035
6038
  }, s = i.draftDataJson || i.dataJson;
6036
6039
  if (s) try {
6037
- let n = typeof s == "string" ? JSON.parse(s) : s, a = await t.prepare("SELECT id as treeNodeId, treeId, parentId FROM tree_nodes WHERE contentId = ? LIMIT 1").get(r), c = Ar(e.env?.BUNDLED_DEFINITIONS).nodes?.[i.contentType] || {}, l = hi(n), u = l.layoutId || null, d = !1, f = null;
6040
+ let n = typeof s == "string" ? JSON.parse(s) : s, a = await t.prepare("SELECT id as treeNodeId, treeId, parentId FROM tree_nodes WHERE contentId = ? LIMIT 1").get(r), c = Mr(e.env?.BUNDLED_DEFINITIONS).nodes?.[i.contentType] || {}, l = _i(n), u = l.layoutId || null, d = !1, f = null;
6038
6041
  if (c) {
6039
6042
  let e = (e) => {
6040
6043
  e && (d = !0, e.options && Array.isArray(e.options) && (f = e.options.map((e) => typeof e == "object" ? e.value || e.id : e)));
@@ -6044,11 +6047,11 @@ Z.get("/", async (e) => {
6044
6047
  if (d && f && f.length === 1 && f[0] !== "inherit") u = f[0];
6045
6048
  else if (!d && c.defaultLayout) u = c.defaultLayout;
6046
6049
  else if (a) {
6047
- let { resolvedLayoutId: e, inheritedFields: n } = await gi(t, a.parentId, a.treeId);
6050
+ let { resolvedLayoutId: e, inheritedFields: n } = await vi(t, a.parentId, a.treeId);
6048
6051
  (u === "inherit" || !u) && (u = e && (!f || f.includes(e) || f.includes("inherit")) ? e : c.defaultLayout || null);
6049
6052
  for (let [e, t] of Object.entries(n)) (l[e] === void 0 || l[e] === null || l[e] === "" || l[e] === "inherit") && (l[e] = t);
6050
6053
  } else (u === "inherit" || !u) && (u = c.defaultLayout || null);
6051
- let p = await ci(t, l);
6054
+ let p = await ui(t, l);
6052
6055
  Object.assign(o, p), c.hasCanvas && (o.resolvedLayoutId = u);
6053
6056
  } catch {}
6054
6057
  let c = await t.prepare("SELECT channelId FROM node_channels WHERE nodeId = ?").all(r);
@@ -6058,7 +6061,7 @@ Z.get("/", async (e) => {
6058
6061
  let u = await t.prepare("SELECT * FROM content_blocks WHERE contentId = ? AND isDraft = 1 ORDER BY sortOrder ASC").all(r), d = Array.isArray(u) ? u : u?.results || [], f = await Promise.all(d.map(async (e) => {
6059
6062
  let n = {};
6060
6063
  try {
6061
- n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {}, n && typeof n == "object" && (n = await ci(t, n));
6064
+ n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {}, n && typeof n == "object" && (n = await ui(t, n));
6062
6065
  } catch {
6063
6066
  n = {};
6064
6067
  }
@@ -6141,12 +6144,12 @@ Z.get("/", async (e) => {
6141
6144
  limit: u
6142
6145
  });
6143
6146
  }), Z.post("/", async (e) => {
6144
- let t = e.get("db"), n = await e.req.json(), r = n.node || n.activeNode || n, i = r.id || n.id, a = i != null && i !== "" && !isNaN(Number(i)) ? Number(i) : null, { title: o, slug: s, language: c, nodeType: l, contentType: u, isHidden: d, hidden: f, is_hidden: p, blocks: m, channels: h, trees: g, attachedAssets: _, ...v } = r, y = hi(v), b = pi(d === void 0 ? f === void 0 ? p : f : d), x = c || "en", S = l || u || "page", C = e.get("user")?.id || null, w = a, T = [];
6147
+ let t = e.get("db"), n = await e.req.json(), r = n.node || n.activeNode || n, i = r.id || n.id, a = i != null && i !== "" && !isNaN(Number(i)) ? Number(i) : null, { title: o, slug: s, language: c, nodeType: l, contentType: u, isHidden: d, hidden: f, is_hidden: p, blocks: m, channels: h, trees: g, attachedAssets: _, ...v } = r, y = _i(v), b = hi(d === void 0 ? f === void 0 ? p : f : d), x = c || "en", S = l || u || "page", C = e.get("user")?.id || null, w = a, T = [];
6145
6148
  if (a) {
6146
6149
  let e = await t.prepare("SELECT assetId FROM node_assets WHERE nodeId = ?").all(a);
6147
6150
  T = (Array.isArray(e) ? e : e?.results || []).map((e) => e.assetId);
6148
6151
  }
6149
- let E = s === void 0 ? null : fi(s), D = [];
6152
+ let E = s === void 0 ? null : mi(s), D = [];
6150
6153
  if (a) D.push({
6151
6154
  sql: "UPDATE content_nodes \n SET title = COALESCE(?, title), \n slug = COALESCE(?, slug), \n language = COALESCE(?, language), \n contentType = COALESCE(?, contentType), \n isHidden = COALESCE(?, isHidden), \n status = 'draft', \n draftDataJson = json_patch(COALESCE(draftDataJson, '{}'), ?), \n updatedById = ?, \n updatedAt = CURRENT_TIMESTAMP \n WHERE id = ?",
6152
6155
  params: [
@@ -6184,7 +6187,7 @@ Z.get("/", async (e) => {
6184
6187
  }
6185
6188
  if (g !== void 0 && Array.isArray(g) && g.length > 0 && w) for (let e of g) {
6186
6189
  if (!e || !e.treeId) continue;
6187
- let n = Number(e.treeId) || e.treeId, r = mi(e.parentId ?? e._draftParentId ?? null), i = typeof e.sortOrder == "number" ? e.sortOrder : 0, a = await t.prepare("SELECT id FROM tree_nodes WHERE treeId = ? AND contentId = ?").get(n, w);
6190
+ let n = Number(e.treeId) || e.treeId, r = gi(e.parentId ?? e._draftParentId ?? null), i = typeof e.sortOrder == "number" ? e.sortOrder : 0, a = await t.prepare("SELECT id FROM tree_nodes WHERE treeId = ? AND contentId = ?").get(n, w);
6188
6191
  a ? D.push({
6189
6192
  sql: "UPDATE tree_nodes SET parentId = ?, sortOrder = ? WHERE id = ?",
6190
6193
  params: [
@@ -6238,10 +6241,10 @@ Z.get("/", async (e) => {
6238
6241
  });
6239
6242
  }
6240
6243
  }
6241
- return D.length > 0 && await t.batch(D), li(e, async () => {
6244
+ return D.length > 0 && await t.batch(D), di(e, async () => {
6242
6245
  if (w && Array.isArray(_)) {
6243
6246
  let e = new Set([...T].filter((e) => !O.has(e)));
6244
- for (let n of e) (await ui(t, "SELECT 1 FROM node_assets WHERE assetId = ? LIMIT 1", [n])).length > 0 || await di(t, "DELETE FROM assets WHERE id = ?", [n]);
6247
+ for (let n of e) (await fi(t, "SELECT 1 FROM node_assets WHERE assetId = ? LIMIT 1", [n])).length > 0 || await pi(t, "DELETE FROM assets WHERE id = ?", [n]);
6245
6248
  }
6246
6249
  await Y(e).clear();
6247
6250
  }), e.json({
@@ -6252,37 +6255,46 @@ Z.get("/", async (e) => {
6252
6255
  }), Z.post("/publish", async (e) => {
6253
6256
  let t = e.get("db"), n = await e.req.json(), r = n.id || n.nodeId;
6254
6257
  if (!r || isNaN(Number(r))) return e.json({ error: "Node ID required for publishing" }, 400);
6255
- let i = Number(r), a = e.get("user")?.id || null;
6256
- if (!await t.prepare("SELECT status, slug, title FROM content_nodes WHERE id = ?").get(i)) return e.json({ error: "Node not found" }, 404);
6257
- let o = [];
6258
- o.push({
6258
+ let i = Number(r), a = e.get("user")?.id || null, o = (await fi(t, "SELECT status, slug, title, draftDataJson FROM content_nodes WHERE id = ?", [i]))[0];
6259
+ if (!o) return e.json({ error: "Node not found" }, 404);
6260
+ let s = [];
6261
+ return s.push({
6259
6262
  sql: "UPDATE content_nodes \n SET publishedDataJson = draftDataJson, \n dataJson = draftDataJson, \n publishedAt = CURRENT_TIMESTAMP, \n status = 'published', \n updatedById = ?, \n updatedAt = CURRENT_TIMESTAMP \n WHERE id = ?",
6260
6263
  params: [a, i]
6261
- }), o.push({
6264
+ }), s.push({
6262
6265
  sql: "DELETE FROM content_blocks WHERE contentId = ? AND isDraft = 0",
6263
6266
  params: [i]
6264
- }), o.push({
6267
+ }), s.push({
6265
6268
  sql: "INSERT INTO content_blocks (contentId, sortOrder, elementType, dataJson, region, isDraft) \n SELECT contentId, sortOrder, elementType, dataJson, region, 0 \n FROM content_blocks \n WHERE contentId = ? AND isDraft = 1",
6266
6269
  params: [i]
6267
- });
6268
- let s = ((await t.prepare("SELECT COUNT(*) as count FROM node_revisions WHERE nodeId = ?").get(i))?.count || 0) + 1;
6269
- return o.push({
6270
- sql: "INSERT INTO node_revisions (nodeId, version, snapshotJson, createdById) \n SELECT ?, ?, \n json_object(\n 'version', ?, \n 'publishedAt', CURRENT_TIMESTAMP, \n 'node', json_patch(draftDataJson, json_object('contentType', contentType)), \n 'blocks', (SELECT json_group_array(json_object('elementType', elementType, 'dataJson', dataJson, 'region', region, 'sortOrder', sortOrder, 'instanceId', instanceId)) FROM content_blocks WHERE contentId = ? AND isDraft = 1)\n ), ?\n FROM content_nodes WHERE id = ?",
6271
- params: [
6272
- i,
6273
- s,
6274
- s,
6275
- i,
6276
- a,
6277
- i
6278
- ]
6279
- }), await t.batch(o), li(e, async () => {
6280
- new X(e.env).purgeNode(e, t, i, !1), await Y(e).clear();
6270
+ }), await t.batch(s), di(e, async () => {
6271
+ try {
6272
+ let n = ((await fi(t, "SELECT COUNT(*) as count FROM node_revisions WHERE nodeId = ?", [i]))[0]?.count || 0) + 1, r = (await fi(t, "SELECT elementType, dataJson, region, sortOrder FROM content_blocks WHERE contentId = ? AND isDraft = 1", [i])).map((e) => {
6273
+ let t = e.dataJson ? JSON.parse(e.dataJson) : {};
6274
+ return {
6275
+ ...e,
6276
+ instanceId: t.blockId || t.id || `block-${Date.now()}`,
6277
+ dataJson: t
6278
+ };
6279
+ }), s = JSON.stringify({
6280
+ version: n,
6281
+ publishedAt: (/* @__PURE__ */ new Date()).toISOString(),
6282
+ node: o.draftDataJson ? JSON.parse(o.draftDataJson) : {},
6283
+ blocks: r
6284
+ });
6285
+ await pi(t, "INSERT INTO node_revisions (nodeId, version, snapshotJson, createdById) VALUES (?, ?, ?, ?)", [
6286
+ i,
6287
+ n,
6288
+ s,
6289
+ a
6290
+ ]), new X(e.env).purgeNode(e, t, i, !1);
6291
+ } catch (e) {
6292
+ console.warn("Failed to compile revision snapshot in background", e);
6293
+ }
6281
6294
  }), e.json({
6282
6295
  success: !0,
6283
6296
  id: i,
6284
6297
  status: "published",
6285
- version: s,
6286
6298
  publishedAt: (/* @__PURE__ */ new Date()).toISOString()
6287
6299
  });
6288
6300
  }), Z.get("/revisions", async (e) => {
@@ -6305,7 +6317,7 @@ Z.get("/", async (e) => {
6305
6317
  return e.json({ error: "Failed to parse snapshot" }, 500);
6306
6318
  }
6307
6319
  let o = typeof a.node?.dataJson == "string" ? JSON.parse(a.node.dataJson) : a.node?.dataJson || {};
6308
- o = await ci(t, hi(o));
6320
+ o = await ui(t, _i(o));
6309
6321
  let s = {
6310
6322
  ...a.node,
6311
6323
  ...o,
@@ -6313,7 +6325,7 @@ Z.get("/", async (e) => {
6313
6325
  contentType: a.node?.contentType || a.node?.nodeType
6314
6326
  }, c = a.blocks || [], l = await Promise.all(c.map(async (e) => {
6315
6327
  let n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {};
6316
- n = await ci(t, n);
6328
+ n = await ui(t, n);
6317
6329
  let r = n.blockId || n._instanceId || (n.id && !String(n.id).startsWith("ast_") ? n.id : null) || e.instanceId || String(e.id), i = { ...n };
6318
6330
  return delete i._instanceId, {
6319
6331
  instanceId: String(r),
@@ -6332,7 +6344,7 @@ Z.get("/", async (e) => {
6332
6344
  let t = e.get("db"), n = e.req.query("id");
6333
6345
  if (!n) return e.json({ error: "Node ID required" }, 400);
6334
6346
  let r = Number(n);
6335
- return await t.prepare("UPDATE content_nodes SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?").run(r), li(e, async () => {
6347
+ return await t.prepare("UPDATE content_nodes SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?").run(r), di(e, async () => {
6336
6348
  new X(e.env).purgeNode(e, t, r, !0), await Y(e).clear();
6337
6349
  }), e.json({
6338
6350
  success: !0,
@@ -6340,7 +6352,7 @@ Z.get("/", async (e) => {
6340
6352
  });
6341
6353
  }), Z.post("/restore", async (e) => {
6342
6354
  let t = e.get("db"), n = await e.req.json(), r = Number(n.id);
6343
- return r ? await t.prepare("SELECT id FROM content_nodes WHERE id = ?").get(r) ? (await t.prepare("UPDATE content_nodes SET deletedAt = NULL WHERE id = ?").run(r), li(e, async () => {
6355
+ return r ? await t.prepare("SELECT id FROM content_nodes WHERE id = ?").get(r) ? (await t.prepare("UPDATE content_nodes SET deletedAt = NULL WHERE id = ?").run(r), di(e, async () => {
6344
6356
  new X(e.env).purgeNode(e, t, r, !0), await Y(e).clear();
6345
6357
  }), e.json({
6346
6358
  success: !0,
@@ -6375,7 +6387,7 @@ Z.get("/", async (e) => {
6375
6387
  params: [r]
6376
6388
  }
6377
6389
  ];
6378
- return await t.batch(i), li(e, async () => {
6390
+ return await t.batch(i), di(e, async () => {
6379
6391
  new X(e.env).purgeNode(e, t, r, !0), await Y(e).clear();
6380
6392
  }), e.json({
6381
6393
  success: !0,
@@ -6384,8 +6396,8 @@ Z.get("/", async (e) => {
6384
6396
  });
6385
6397
  //#endregion
6386
6398
  //#region server/routes/admin/trees.ts
6387
- var _i = new n();
6388
- function vi(e, t = null) {
6399
+ var yi = new n();
6400
+ function bi(e, t = null) {
6389
6401
  let n = [];
6390
6402
  for (let r = 0; r < e.length; r++) {
6391
6403
  let i = e[r];
@@ -6397,19 +6409,19 @@ function vi(e, t = null) {
6397
6409
  id: o,
6398
6410
  parentId: t,
6399
6411
  sortOrder: r
6400
- }), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...vi(i.children, o)));
6412
+ }), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...bi(i.children, o)));
6401
6413
  }
6402
6414
  return n;
6403
6415
  }
6404
- function yi(e) {
6416
+ function xi(e) {
6405
6417
  if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
6406
6418
  let t = Number(e);
6407
6419
  return isNaN(t) ? null : t;
6408
6420
  }
6409
- function bi(e) {
6421
+ function Si(e) {
6410
6422
  return +(e === !0 || e === 1 || e === "1" || e === "true");
6411
6423
  }
6412
- _i.get("/tree.json", async (e) => {
6424
+ yi.get("/tree.json", async (e) => {
6413
6425
  try {
6414
6426
  let t = e.get("db"), n = e.req.query("treeId") || "main-nav", r = e.req.query("preview") === "true", i = 1;
6415
6427
  if (isNaN(Number(n))) {
@@ -6459,7 +6471,7 @@ _i.get("/tree.json", async (e) => {
6459
6471
  } catch (t) {
6460
6472
  return console.error("[CMS Tree API] GET Error:", t), e.json({ error: t.message || "Failed to fetch tree" }, 500);
6461
6473
  }
6462
- }), _i.post("/tree.json", async (e) => {
6474
+ }), yi.post("/tree.json", async (e) => {
6463
6475
  try {
6464
6476
  let t = e.get("db"), n = await e.req.json(), r = n.treeId ? String(n.treeId).trim() : "main-nav", i = Y(e), a = new X(e.env), o = 1;
6465
6477
  if (isNaN(Number(r))) {
@@ -6471,7 +6483,7 @@ _i.get("/tree.json", async (e) => {
6471
6483
  }
6472
6484
  } else o = Number(r);
6473
6485
  if (n.tree && Array.isArray(n.tree)) {
6474
- let r = vi(n.tree, null);
6486
+ let r = bi(n.tree, null);
6475
6487
  if (r.length > 0) for (let e = 0; e < r.length; e += 15) {
6476
6488
  let n = r.slice(e, e + 15), i = n.map((e) => e.id), a = i.map(() => "?").join(","), s = "UPDATE tree_nodes SET \n";
6477
6489
  s += "parentId = CASE id \n", n.forEach(() => {
@@ -6491,9 +6503,9 @@ _i.get("/tree.json", async (e) => {
6491
6503
  reorderedCount: r.length
6492
6504
  });
6493
6505
  }
6494
- let { action: s, title: c, nodeType: l, parentId: u, contentId: d, nodeData: f = {}, pageData: p = {} } = n, m = Object.keys(f).length > 0 ? { ...f } : { ...p }, h = bi(n.isHidden === void 0 ? m.isHidden === void 0 ? m.hidden : m.isHidden : n.isHidden);
6506
+ let { action: s, title: c, nodeType: l, parentId: u, contentId: d, nodeData: f = {}, pageData: p = {} } = n, m = Object.keys(f).length > 0 ? { ...f } : { ...p }, h = Si(n.isHidden === void 0 ? m.isHidden === void 0 ? m.hidden : m.isHidden : n.isHidden);
6495
6507
  delete m._isTreeDraft, delete m._draftParentId, delete m.isNew, delete m.nodeType, delete m.contentType, delete m.title, delete m.slug, delete m.hidden, delete m.is_hidden, delete m.isHidden, delete m.status;
6496
- let g = yi(u), _ = e.get("user")?.id || null;
6508
+ let g = xi(u), _ = e.get("user")?.id || null;
6497
6509
  if (s === "create") {
6498
6510
  let r = m.slug || n.slug || c, s = r ? String(r).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "") : null;
6499
6511
  if (s) {
@@ -6582,7 +6594,7 @@ _i.get("/tree.json", async (e) => {
6582
6594
  details: t.message
6583
6595
  }, 500);
6584
6596
  }
6585
- }), _i.get("/trees.json", async (e) => {
6597
+ }), yi.get("/trees.json", async (e) => {
6586
6598
  try {
6587
6599
  let t = e.get("db"), n = await t.prepare("SELECT * FROM trees ORDER BY LOWER(label) ASC").all(), r = Array.isArray(n) ? n : n?.results || [], i = await t.prepare("SELECT channelId, treeId FROM channel_trees").all(), a = (Array.isArray(i) ? i : i?.results || []).reduce((e, t) => {
6588
6600
  let n = Number(t.treeId), r = Number(t.channelId);
@@ -6612,7 +6624,7 @@ _i.get("/tree.json", async (e) => {
6612
6624
  } catch {
6613
6625
  return e.json([]);
6614
6626
  }
6615
- }), _i.post("/trees.json", async (e) => {
6627
+ }), yi.post("/trees.json", async (e) => {
6616
6628
  try {
6617
6629
  let t = e.get("db"), n = await e.req.json(), r = n.id, i = r != null && r !== "" && !isNaN(Number(r)) ? Number(r) : null, a = `tree-${Date.now().toString(36)}`, o = (n.key || n.slug || a).toLowerCase().replace(/[^a-z0-9_-]/g, "-"), s = n.label?.trim() || o, c = n.treeType !== void 0 && n.treeType !== null ? n.treeType : n.type ?? "site", l = n.channelId !== void 0 && n.channelId !== null && Number(n.channelId) || null, u = +(n.isHidden === !0 || n.isHidden === 1 || n.isHidden === "true"), d = e.get("user")?.id || null, f = { ...n };
6618
6630
  if (delete f.id, delete f.key, delete f.label, delete f.treeType, delete f.type, delete f.channelId, delete f.channels, delete f.isHidden, delete f.createdById, delete f.updatedById, delete f.createdAt, delete f.updatedAt, await t.prepare("SELECT id FROM trees WHERE key = ? AND id != ? LIMIT 1").get(o, i ?? -1)) return e.json({
@@ -6651,7 +6663,7 @@ _i.get("/tree.json", async (e) => {
6651
6663
  } catch (t) {
6652
6664
  return console.error("[API Trees] Error saving tree:", t), e.json({ error: t.message || "Failed to save tree" }, 500);
6653
6665
  }
6654
- }), _i.delete("/trees.json", async (e) => {
6666
+ }), yi.delete("/trees.json", async (e) => {
6655
6667
  let t = e.get("db"), n = e.req.query("id");
6656
6668
  if (!n) return e.json({ error: "Tree ID required" }, 400);
6657
6669
  let r = Number(n);
@@ -6666,8 +6678,8 @@ _i.get("/tree.json", async (e) => {
6666
6678
  });
6667
6679
  //#endregion
6668
6680
  //#region server/routes/admin/channels.ts
6669
- var xi = new n();
6670
- xi.get("/", async (e) => {
6681
+ var Ci = new n();
6682
+ Ci.get("/", async (e) => {
6671
6683
  try {
6672
6684
  let t = e.get("db"), n = await t.prepare("SELECT * FROM channels ORDER BY id ASC").all(), r = Array.isArray(n) ? n : n?.results || [], i = await t.prepare("SELECT channelId, treeId, key, metaJson FROM channel_trees ORDER BY rowid ASC").all(), a = ((Array.isArray(i) ? i : i?.results || []) || []).reduce((e, t) => {
6673
6685
  e[t.channelId] || (e[t.channelId] = []);
@@ -6691,7 +6703,7 @@ xi.get("/", async (e) => {
6691
6703
  isHidden: !!e.isHidden,
6692
6704
  trees: a[e.id] || []
6693
6705
  };
6694
- }), s = e.get("schemas")?.rawChannels || {}, c = e.env?.BUNDLED_DEFINITIONS, l = Ar(c), u = l?.channelTemplate || Object.values(s)[0] || {
6706
+ }), s = e.get("schemas")?.rawChannels || {}, c = e.env?.BUNDLED_DEFINITIONS, l = Mr(c), u = l?.channelTemplate || Object.values(s)[0] || {
6695
6707
  label: "Channel Settings",
6696
6708
  fields: {
6697
6709
  key: {
@@ -6735,7 +6747,7 @@ xi.get("/", async (e) => {
6735
6747
  error: t.message
6736
6748
  }, 500);
6737
6749
  }
6738
- }), xi.post("/", async (e) => {
6750
+ }), Ci.post("/", async (e) => {
6739
6751
  try {
6740
6752
  let t = e.get("db"), n = await e.req.json(), r = n.id, i = r != null && r !== "" && !isNaN(Number(r)) ? Number(r) : null, { key: a, label: o, channelType: s, domain: c, baseUrl: l, defaultLanguage: u, isHidden: d = !1, trees: f = [], createdById: p = null, updatedById: m = null, id: h, createdAt: g, updatedAt: _, ...v } = n, y = a?.trim() || "main", b = o?.trim() || "Untitled Channel", x = s ?? "website", S = c ?? "localhost", C = l ?? "http://localhost:4321", w = u ?? "en", T = JSON.stringify(v || {}), E = e.get("user")?.id || m || p, D = E === void 0 ? null : E;
6741
6753
  if (await t.prepare("SELECT id FROM channels WHERE key = ? AND id != ? LIMIT 1").get(y, i ?? -1)) return e.json({
@@ -6775,7 +6787,7 @@ xi.get("/", async (e) => {
6775
6787
  details: t.message
6776
6788
  }, 500);
6777
6789
  }
6778
- }), xi.delete("/", async (e) => {
6790
+ }), Ci.delete("/", async (e) => {
6779
6791
  let t = e.get("db"), n = e.req.query("id");
6780
6792
  if (!n) return e.json({ error: "Channel ID required" }, 400);
6781
6793
  let r = Number(n);
@@ -6793,7 +6805,7 @@ xi.get("/", async (e) => {
6793
6805
  });
6794
6806
  //#endregion
6795
6807
  //#region server/db/bundled-definitions.ts
6796
- var Si = {
6808
+ var wi = {
6797
6809
  nodes: {
6798
6810
  address: {
6799
6811
  id: "address",
@@ -11500,11 +11512,11 @@ var Si = {
11500
11512
  treeTemplate: null,
11501
11513
  channelTemplate: null,
11502
11514
  userTemplate: null
11503
- }, Ci = new n(), wi = null, Ti = (e) => {
11515
+ }, Ti = new n(), Ei = null, Di = (e) => {
11504
11516
  try {
11505
11517
  let t = process.env.NODE_ENV !== "production";
11506
- if (!wi || t) {
11507
- let t = e.env?.BUNDLED_DEFINITIONS || Si || {}, n = Ar(t) || {}, r = e.get("schemas") || {}, i = r.rawChannels || {}, a = r.rawNodes || {}, o = r.rawTrees || {}, s = r.rawBlocks || {}, c = r.rawNodeLayouts || {}, l = r.rawBlockLayouts || {}, u = t.rawChannels || t.channels || n.channels || {}, d = t.rawNodes || t.nodes || n.nodes || {}, f = t.rawTrees || t.trees || n.trees || {}, p = t.rawBlocks || t.blocks || n.blocks || {}, m = t.rawNodeLayouts || t.nodeLayouts || n.nodeLayouts || {}, h = t.rawBlockLayouts || t.blockLayouts || n.blockLayouts || {}, g = Object.keys(i).length > 0 ? i : u, _ = Object.keys(a).length > 0 ? a : d, v = Object.keys(o).length > 0 ? o : f, y = Object.keys(s).length > 0 ? s : p, b = Object.keys(c).length > 0 ? c : m, x = Object.keys(l).length > 0 ? l : h, S = n.userTemplate || {
11518
+ if (!Ei || t) {
11519
+ let t = e.env?.BUNDLED_DEFINITIONS || wi || {}, n = Mr(t) || {}, r = e.get("schemas") || {}, i = r.rawChannels || {}, a = r.rawNodes || {}, o = r.rawTrees || {}, s = r.rawBlocks || {}, c = r.rawNodeLayouts || {}, l = r.rawBlockLayouts || {}, u = t.rawChannels || t.channels || n.channels || {}, d = t.rawNodes || t.nodes || n.nodes || {}, f = t.rawTrees || t.trees || n.trees || {}, p = t.rawBlocks || t.blocks || n.blocks || {}, m = t.rawNodeLayouts || t.nodeLayouts || n.nodeLayouts || {}, h = t.rawBlockLayouts || t.blockLayouts || n.blockLayouts || {}, g = Object.keys(i).length > 0 ? i : u, _ = Object.keys(a).length > 0 ? a : d, v = Object.keys(o).length > 0 ? o : f, y = Object.keys(s).length > 0 ? s : p, b = Object.keys(c).length > 0 ? c : m, x = Object.keys(l).length > 0 ? l : h, S = n.userTemplate || {
11508
11520
  id: "userTemplate",
11509
11521
  label: "User Account",
11510
11522
  fields: {
@@ -11540,7 +11552,7 @@ var Si = {
11540
11552
  }
11541
11553
  }
11542
11554
  }, C = Object.keys(g)[0];
11543
- wi = {
11555
+ Ei = {
11544
11556
  channelTemplate: n.channelTemplate || (C ? g[C] : null),
11545
11557
  treeTemplate: n.treeTemplate || null,
11546
11558
  userTemplate: S,
@@ -11555,7 +11567,7 @@ var Si = {
11555
11567
  blockLayouts: x
11556
11568
  };
11557
11569
  }
11558
- return e.json(wi, 200, { "Cache-Control": "no-cache, no-store, must-revalidate" });
11570
+ return e.json(Ei, 200, { "Cache-Control": "no-cache, no-store, must-revalidate" });
11559
11571
  } catch (t) {
11560
11572
  return console.error("[CMS API] Error loading schemas:", t), e.json({
11561
11573
  error: "Failed to load schemas",
@@ -11563,10 +11575,10 @@ var Si = {
11563
11575
  }, 500);
11564
11576
  }
11565
11577
  };
11566
- Ci.get("/", Ti), Ci.get("/schemas.json", Ti);
11578
+ Ti.get("/", Di), Ti.get("/schemas.json", Di);
11567
11579
  //#endregion
11568
11580
  //#region server/routes/admin/validation.ts
11569
- var Ei = new n(), Di = {
11581
+ var Oi = new n(), ki = {
11570
11582
  node: "content_nodes",
11571
11583
  nodes: "content_nodes",
11572
11584
  content_node: "content_nodes",
@@ -11578,7 +11590,7 @@ var Ei = new n(), Di = {
11578
11590
  user: "users",
11579
11591
  users: "users",
11580
11592
  user_account: "user_accounts"
11581
- }, Oi = {
11593
+ }, Ai = {
11582
11594
  content_nodes: [
11583
11595
  "id",
11584
11596
  "title",
@@ -11635,11 +11647,11 @@ var Ei = new n(), Di = {
11635
11647
  "createdAt"
11636
11648
  ]
11637
11649
  };
11638
- Ei.post("/validate-unique", async (e) => {
11650
+ Oi.post("/validate-unique", async (e) => {
11639
11651
  try {
11640
11652
  let t = e.get("db"), { entityType: n, field: r, value: i, excludeId: a } = await e.req.json();
11641
11653
  if (!r || i == null || String(i).trim() === "") return e.json({ isUnique: !0 });
11642
- let o = Di[n] || "content_nodes", s = r.replace(/[^a-zA-Z0-9_]/g, ""), c = (Oi[o] || Oi.content_nodes).includes(s), l = -1;
11654
+ let o = ki[n] || "content_nodes", s = r.replace(/[^a-zA-Z0-9_]/g, ""), c = (Ai[o] || Ai.content_nodes).includes(s), l = -1;
11643
11655
  if (a != null && String(a).trim() !== "") {
11644
11656
  let e = Number(a);
11645
11657
  l = isNaN(e) ? String(a) : e;
@@ -11651,7 +11663,7 @@ Ei.post("/validate-unique", async (e) => {
11651
11663
  } catch (t) {
11652
11664
  return console.error("[API Validation] Error validating global uniqueness:", t), e.json({ error: "Failed to validate uniqueness" }, 500);
11653
11665
  }
11654
- }), Ei.post("/validate-unique-sibling", async (e) => {
11666
+ }), Oi.post("/validate-unique-sibling", async (e) => {
11655
11667
  try {
11656
11668
  let t = e.get("db"), { slug: n, treeId: r, parentId: i, excludeTreeNodeId: a } = await e.req.json();
11657
11669
  if (!n || !String(n).trim() || !r) return e.json({ isUnique: !0 });
@@ -11679,8 +11691,8 @@ Ei.post("/validate-unique", async (e) => {
11679
11691
  });
11680
11692
  //#endregion
11681
11693
  //#region server/routes/admin/stats.ts
11682
- var ki = new n();
11683
- ki.get("/", async (e) => {
11694
+ var ji = new n();
11695
+ ji.get("/", async (e) => {
11684
11696
  try {
11685
11697
  let t = e.get("db"), n = await t.prepare("\n SELECT \n COUNT(*) as total,\n SUM(CASE WHEN isHidden = 0 THEN 1 ELSE 0 END) as published,\n SUM(CASE WHEN isHidden = 1 THEN 1 ELSE 0 END) as hidden\n FROM content_nodes\n ").get(), r = Number(n?.total) || 0, i = Number(n?.published) || 0, a = Number(n?.hidden) || 0, o = await t.prepare("\n SELECT \n (SELECT COUNT(*) FROM channels) as totalChannels,\n (SELECT COUNT(*) FROM trees) as totalTrees,\n (SELECT COUNT(*) FROM users) as totalUsers\n ").get(), s = await t.prepare("\n SELECT contentType as type, COUNT(*) as count \n FROM content_nodes \n GROUP BY contentType \n ORDER BY count DESC\n ").all(), c = Array.isArray(s) ? s : s?.results || [], l = await t.prepare("\n SELECT id, title, slug, contentType, isHidden, status, updatedAt \n FROM content_nodes \n ORDER BY updatedAt DESC \n LIMIT 5\n ").all(), u = (Array.isArray(l) ? l : l?.results || []).map((e) => ({
11686
11698
  ...e,
@@ -11695,7 +11707,7 @@ ki.get("/", async (e) => {
11695
11707
  isHidden: !!e.isHidden,
11696
11708
  channelNames: e.channelLabels ? e.channelLabels.split(",") : [],
11697
11709
  treeNames: e.treeLabels ? e.treeLabels.split(",") : []
11698
- })), p = e.env?.BUNDLED_DEFINITIONS, m = Ar(p), h = m.nodes || m.nodeSchemas || {}, g = c.map((e) => {
11710
+ })), p = e.env?.BUNDLED_DEFINITIONS, m = Mr(p), h = m.nodes || m.nodeSchemas || {}, g = c.map((e) => {
11699
11711
  let t = e.type || "node", n = h[t]?.label || t.charAt(0).toUpperCase() + t.slice(1);
11700
11712
  return {
11701
11713
  type: t,
@@ -11723,7 +11735,7 @@ ki.get("/", async (e) => {
11723
11735
  });
11724
11736
  //#endregion
11725
11737
  //#region server/storage/provider.ts
11726
- function Ai(e) {
11738
+ function Mi(e) {
11727
11739
  let t = e.split(".").pop()?.toLowerCase() || "bin";
11728
11740
  return t = t.replace(/[^a-z0-9]/g, ""), [
11729
11741
  "php",
@@ -11738,14 +11750,14 @@ function Ai(e) {
11738
11750
  "cjs"
11739
11751
  ].includes(t) ? "bin" : t;
11740
11752
  }
11741
- var ji = class {
11753
+ var Ni = class {
11742
11754
  bucket;
11743
11755
  publicDomain;
11744
11756
  constructor(e, t) {
11745
11757
  this.bucket = e, this.publicDomain = t;
11746
11758
  }
11747
11759
  async upload(e, t = "uploads") {
11748
- let n = Ai(e.name), r = `${t}/${crypto.randomUUID().replace(/-/g, "")}.${n}`;
11760
+ let n = Mi(e.name), r = `${t}/${crypto.randomUUID().replace(/-/g, "")}.${n}`;
11749
11761
  return await this.bucket.put(r, e.stream(), { httpMetadata: { contentType: e.type } }), {
11750
11762
  key: r,
11751
11763
  url: `/media/${r.replace(/^\//, "")}`
@@ -11754,7 +11766,7 @@ var ji = class {
11754
11766
  async delete(e) {
11755
11767
  await this.bucket.delete(e);
11756
11768
  }
11757
- }, Mi = class {
11769
+ }, Pi = class {
11758
11770
  customStoragePath;
11759
11771
  constructor(e) {
11760
11772
  this.customStoragePath = e;
@@ -11772,7 +11784,7 @@ var ji = class {
11772
11784
  ), { pipeline: a } = await import(
11773
11785
  /* @vite-ignore */
11774
11786
  "node:stream/promises"
11775
- ), o = Ai(e.name), s = `${t}/${crypto.randomUUID().replace(/-/g, "")}.${o}`, c = this.customStoragePath || "./public/media", l = n.resolve(process.cwd(), c), u = n.join(l, s);
11787
+ ), o = Mi(e.name), s = `${t}/${crypto.randomUUID().replace(/-/g, "")}.${o}`, c = this.customStoragePath || "./public/media", l = n.resolve(process.cwd(), c), u = n.join(l, s);
11776
11788
  await i.mkdir(n.dirname(u), { recursive: !0 });
11777
11789
  let d = r.createWriteStream(u);
11778
11790
  return await a(e.stream(), d), {
@@ -11795,16 +11807,16 @@ var ji = class {
11795
11807
  }
11796
11808
  }
11797
11809
  };
11798
- function Ni(e) {
11810
+ function Fi(e) {
11799
11811
  if (e.MEDIA_BUCKET) {
11800
11812
  let t = e.CDN_DOMAIN || "cdn.yourdomain.com";
11801
- return new ji(e.MEDIA_BUCKET, t);
11813
+ return new Ni(e.MEDIA_BUCKET, t);
11802
11814
  }
11803
- return new Mi(e.LOCAL_MEDIA_PATH);
11815
+ return new Pi(e.LOCAL_MEDIA_PATH);
11804
11816
  }
11805
11817
  //#endregion
11806
11818
  //#region server/routes/admin/assets.ts
11807
- var Pi = new n();
11819
+ var Ii = new n();
11808
11820
  async function Q(e, t, n = []) {
11809
11821
  let r = e.prepare(t);
11810
11822
  if (typeof r.bind == "function") {
@@ -11817,21 +11829,21 @@ async function Q(e, t, n = []) {
11817
11829
  }
11818
11830
  return [];
11819
11831
  }
11820
- async function Fi(e, t, n = []) {
11832
+ async function Li(e, t, n = []) {
11821
11833
  let r = e.prepare(t);
11822
11834
  if (typeof r.bind == "function") return await r.bind(...n).run();
11823
11835
  if (typeof r.run == "function") return await r.run(...n);
11824
11836
  }
11825
- function Ii(e, t) {
11837
+ function Ri(e, t) {
11826
11838
  let n = e || (t ? `/media/${t}` : "");
11827
11839
  try {
11828
11840
  n.startsWith("http") && (n = new URL(n).pathname);
11829
11841
  } catch {}
11830
11842
  return n.startsWith("/media/") || (n = `/media/${n.replace(/^\/+/, "")}`), n;
11831
11843
  }
11832
- Pi.get("/", async (e) => {
11844
+ Ii.get("/", async (e) => {
11833
11845
  try {
11834
- let t = Lr(e), { search: n = "", type: r = "all", page: i = "1", limit: a = "24", sort: o = "createdAt", order: s = "DESC", nodeId: c, channelId: l, trashed: u } = e.req.query(), d = Math.max(1, parseInt(i, 10) || 1), f = Math.max(1, Math.min(100, parseInt(a, 10) || 24)), p = (d - 1) * f, m = {
11846
+ let t = zr(e), { search: n = "", type: r = "all", page: i = "1", limit: a = "24", sort: o = "createdAt", order: s = "DESC", nodeId: c, channelId: l, trashed: u } = e.req.query(), d = Math.max(1, parseInt(i, 10) || 1), f = Math.max(1, Math.min(100, parseInt(a, 10) || 24)), p = (d - 1) * f, m = {
11835
11847
  createdAt: "a.createdAt",
11836
11848
  updatedAt: "a.updatedAt",
11837
11849
  filename: "a.filename",
@@ -11896,7 +11908,7 @@ Pi.get("/", async (e) => {
11896
11908
  ...JSON.parse(e.dataJson || "{}")
11897
11909
  };
11898
11910
  } catch {}
11899
- let n = Ii(e.cdnUrl, e.storageKeyPrivate);
11911
+ let n = Ri(e.cdnUrl, e.storageKeyPrivate);
11900
11912
  return {
11901
11913
  id: e.id,
11902
11914
  filename: e.filename || "Untitled Asset",
@@ -11920,9 +11932,9 @@ Pi.get("/", async (e) => {
11920
11932
  details: t.message || String(t)
11921
11933
  }, 500);
11922
11934
  }
11923
- }), Pi.post("/upload", async (e) => {
11935
+ }), Ii.post("/upload", async (e) => {
11924
11936
  try {
11925
- let t = Lr(e), n = Ni(e.env), r = await e.req.parseBody(), i = r.file, a = r.isVariant === "true" || r.isVariant === "1" || r.temporary === "true", o = r.parentAssetId || r.parentAsset, s = typeof o == "string" && o.trim().length > 0 ? o.trim() : null;
11937
+ let t = zr(e), n = Fi(e.env), r = await e.req.parseBody(), i = r.file, a = r.isVariant === "true" || r.isVariant === "1" || r.temporary === "true", o = r.parentAssetId || r.parentAsset, s = typeof o == "string" && o.trim().length > 0 ? o.trim() : null;
11926
11938
  s && (await Q(t, "SELECT id FROM assets WHERE id = ?", [s])).length === 0 && (s = null);
11927
11939
  let c = r.cropCoordinates, l = null, u = null;
11928
11940
  if (c) {
@@ -11939,7 +11951,7 @@ Pi.get("/", async (e) => {
11939
11951
  let v = `/media/${_.replace(/^\//, "")}`, y = i.type || "application/octet-stream", b = i.size || 0, x = e.get("userId"), S = typeof x == "string" && x.trim().length > 0 ? x : null;
11940
11952
  S && (await Q(t, "SELECT id FROM users WHERE id = ?", [S])).length === 0 && (S = null);
11941
11953
  let C = +!!m;
11942
- await Fi(t, "\n INSERT INTO assets (id, filename, mimeType, sizeBytes, storageKeyPrivate, cdnUrl, createdById, isSystemVariant, parentAssetId, cropCoordinatesJson)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n ", [
11954
+ await Li(t, "\n INSERT INTO assets (id, filename, mimeType, sizeBytes, storageKeyPrivate, cdnUrl, createdById, isSystemVariant, parentAssetId, cropCoordinatesJson)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n ", [
11943
11955
  f,
11944
11956
  i.name,
11945
11957
  y,
@@ -11954,7 +11966,7 @@ Pi.get("/", async (e) => {
11954
11966
  let w = v;
11955
11967
  if (s) {
11956
11968
  let n = await Q(t, "SELECT cdnUrl, storageKeyPrivate FROM assets WHERE id = ?", [s]);
11957
- n.length > 0 && (w = Ii(n[0].cdnUrl, n[0].storageKeyPrivate)), new X(e.env).purgeAsset(e, t, s);
11969
+ n.length > 0 && (w = Ri(n[0].cdnUrl, n[0].storageKeyPrivate)), new X(e.env).purgeAsset(e, t, s);
11958
11970
  }
11959
11971
  return e.json({
11960
11972
  id: f,
@@ -11973,9 +11985,9 @@ Pi.get("/", async (e) => {
11973
11985
  details: t.message || String(t)
11974
11986
  }, 500);
11975
11987
  }
11976
- }), Pi.get("/:id/details", async (e) => {
11988
+ }), Ii.get("/:id/details", async (e) => {
11977
11989
  try {
11978
- let t = Lr(e), n = e.req.param("id"), r = await Q(t, "SELECT * FROM assets WHERE id = ?", [n]);
11990
+ let t = zr(e), n = e.req.param("id"), r = await Q(t, "SELECT * FROM assets WHERE id = ?", [n]);
11979
11991
  if (!r || r.length === 0) return e.json({ error: "Asset not found" }, 404);
11980
11992
  let i = r[0], a = i.filename ? i.filename.replace(/\.[^/.]+$/, "") : "", o = await Q(t, "\n SELECT DISTINCT cn.id, cn.title, cn.contentType, cn.slug, na.fieldKey, na.assetId \n FROM node_assets na\n INNER JOIN content_nodes cn ON na.nodeId = cn.id\n LEFT JOIN assets crop ON na.assetId = crop.id\n WHERE na.assetId = ?\n OR (crop.isSystemVariant = 1 AND (crop.filename LIKE ? OR crop.filename LIKE ?))\n ", [
11981
11993
  n,
@@ -11996,7 +12008,7 @@ Pi.get("/", async (e) => {
11996
12008
  ...JSON.parse(i.dataJson || "{}")
11997
12009
  };
11998
12010
  } catch {}
11999
- let l = Ii(i.cdnUrl, i.storageKeyPrivate);
12011
+ let l = Ri(i.cdnUrl, i.storageKeyPrivate);
12000
12012
  return e.json({
12001
12013
  id: i.id,
12002
12014
  filename: i.filename,
@@ -12023,7 +12035,7 @@ Pi.get("/", async (e) => {
12023
12035
  createdAt: e.createdAt,
12024
12036
  parentAssetId: e.parentAssetId || i.id,
12025
12037
  cropCoordinates: t,
12026
- url: Ii(e.cdnUrl, e.storageKeyPrivate),
12038
+ url: Ri(e.cdnUrl, e.storageKeyPrivate),
12027
12039
  originalUrl: l
12028
12040
  };
12029
12041
  })
@@ -12031,15 +12043,15 @@ Pi.get("/", async (e) => {
12031
12043
  } catch (t) {
12032
12044
  return console.error("❌ [Asset Details Error]:", t), e.json({ error: "Failed to load details" }, 500);
12033
12045
  }
12034
- }), Pi.put("/:id", async (e) => {
12046
+ }), Ii.put("/:id", async (e) => {
12035
12047
  try {
12036
- let t = Lr(e), n = e.req.param("id"), r = await e.req.json(), i = await Q(t, "SELECT filename, dataJson FROM assets WHERE id = ?", [n]);
12048
+ let t = zr(e), n = e.req.param("id"), r = await e.req.json(), i = await Q(t, "SELECT filename, dataJson FROM assets WHERE id = ?", [n]);
12037
12049
  if (!i || i.length === 0) return e.json({ error: "Asset not found" }, 404);
12038
12050
  let a = i[0], o = {};
12039
12051
  try {
12040
12052
  o = JSON.parse(a.dataJson || "{}");
12041
12053
  } catch {}
12042
- return r.title !== void 0 && (o.title = r.title), r.alt !== void 0 && (o.alt = r.alt), r.description !== void 0 && (o.description = r.description), await Fi(t, "UPDATE assets SET filename = ?, dataJson = ?, updatedAt = CURRENT_TIMESTAMP WHERE id = ?", [
12054
+ return r.title !== void 0 && (o.title = r.title), r.alt !== void 0 && (o.alt = r.alt), r.description !== void 0 && (o.description = r.description), await Li(t, "UPDATE assets SET filename = ?, dataJson = ?, updatedAt = CURRENT_TIMESTAMP WHERE id = ?", [
12043
12055
  r.filename === void 0 ? a.filename : r.filename,
12044
12056
  JSON.stringify(o),
12045
12057
  n
@@ -12047,10 +12059,10 @@ Pi.get("/", async (e) => {
12047
12059
  } catch (t) {
12048
12060
  return console.error("❌ [Asset Update Error]:", t), e.json({ error: "Failed to update asset" }, 500);
12049
12061
  }
12050
- }), Pi.delete("/:id", async (e) => {
12062
+ }), Ii.delete("/:id", async (e) => {
12051
12063
  try {
12052
- let t = Lr(e), n = e.req.param("id"), r = (await Q(t, "SELECT id, filename, isSystemVariant FROM assets WHERE id = ?", [n]))[0];
12053
- return r ? (new X(e.env).purgeAsset(e, t, n), r.isSystemVariant ? await Fi(t, "UPDATE assets SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?", [n]) : await Fi(t, "UPDATE assets\n SET deletedAt = CURRENT_TIMESTAMP\n WHERE id = ? OR parentAssetId = ? OR (isSystemVariant = 1 AND (filename LIKE ? OR filename LIKE ?))", [
12064
+ let t = zr(e), n = e.req.param("id"), r = (await Q(t, "SELECT id, filename, isSystemVariant FROM assets WHERE id = ?", [n]))[0];
12065
+ return r ? (new X(e.env).purgeAsset(e, t, n), r.isSystemVariant ? await Li(t, "UPDATE assets SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?", [n]) : await Li(t, "UPDATE assets\n SET deletedAt = CURRENT_TIMESTAMP\n WHERE id = ? OR parentAssetId = ? OR (isSystemVariant = 1 AND (filename LIKE ? OR filename LIKE ?))", [
12054
12066
  n,
12055
12067
  n,
12056
12068
  `crop_%${r.filename ? r.filename.replace(/\.[^/.]+$/, "") : ""}%`,
@@ -12066,12 +12078,12 @@ Pi.get("/", async (e) => {
12066
12078
  details: t.message || String(t)
12067
12079
  }, 500);
12068
12080
  }
12069
- }), Pi.post("/restore", async (e) => {
12081
+ }), Ii.post("/restore", async (e) => {
12070
12082
  try {
12071
- let t = Lr(e), n = await e.req.json(), r = n.id || n.assetId;
12083
+ let t = zr(e), n = await e.req.json(), r = n.id || n.assetId;
12072
12084
  if (!r) return e.json({ error: "Asset ID required" }, 400);
12073
12085
  let i = (await Q(t, "SELECT id, filename FROM assets WHERE id = ?", [r]))[0];
12074
- return i ? (await Fi(t, "UPDATE assets \n SET deletedAt = NULL \n WHERE id = ? OR parentAssetId = ? OR (isSystemVariant = 1 AND (filename LIKE ? OR filename LIKE ?))", [
12086
+ return i ? (await Li(t, "UPDATE assets \n SET deletedAt = NULL \n WHERE id = ? OR parentAssetId = ? OR (isSystemVariant = 1 AND (filename LIKE ? OR filename LIKE ?))", [
12075
12087
  r,
12076
12088
  r,
12077
12089
  `crop_%${i.filename ? i.filename.replace(/\.[^/.]+$/, "") : ""}%`,
@@ -12087,9 +12099,9 @@ Pi.get("/", async (e) => {
12087
12099
  details: t.message
12088
12100
  }, 500);
12089
12101
  }
12090
- }), Pi.delete("/purge/:id", async (e) => {
12102
+ }), Ii.delete("/purge/:id", async (e) => {
12091
12103
  try {
12092
- let t = Lr(e), n = Ni(e.env), r = e.req.param("id"), i = (await Q(t, "SELECT id, filename, storageKeyPrivate, isSystemVariant FROM assets WHERE id = ?", [r]))[0];
12104
+ let t = zr(e), n = Fi(e.env), r = e.req.param("id"), i = (await Q(t, "SELECT id, filename, storageKeyPrivate, isSystemVariant FROM assets WHERE id = ?", [r]))[0];
12093
12105
  if (!i) return e.json({ error: "Asset not found" }, 404);
12094
12106
  new X(e.env).purgeAsset(e, t, r);
12095
12107
  let a = [i];
@@ -12107,7 +12119,7 @@ Pi.get("/", async (e) => {
12107
12119
  }
12108
12120
  }
12109
12121
  let s = o.map(() => "?").join(",");
12110
- return await Fi(t, `DELETE FROM node_assets WHERE assetId IN (${s})`, o), await Fi(t, `DELETE FROM assets WHERE id IN (${s})`, o), e.json({
12122
+ return await Li(t, `DELETE FROM node_assets WHERE assetId IN (${s})`, o), await Li(t, `DELETE FROM assets WHERE id IN (${s})`, o), e.json({
12111
12123
  success: !0,
12112
12124
  id: r,
12113
12125
  purged: !0,
@@ -12123,14 +12135,14 @@ Pi.get("/", async (e) => {
12123
12135
  });
12124
12136
  //#endregion
12125
12137
  //#region server/routes/public/node.ts
12126
- var Li = new n();
12127
- function Ri(e, t) {
12138
+ var zi = new n();
12139
+ function Bi(e, t) {
12128
12140
  let n = Promise.resolve(t).catch((e) => console.error("[Background Task Error]:", e));
12129
12141
  try {
12130
12142
  e.executionCtx && typeof e.executionCtx.waitUntil == "function" && e.executionCtx.waitUntil(n);
12131
12143
  } catch {}
12132
12144
  }
12133
- function zi() {
12145
+ function Vi() {
12134
12146
  return {
12135
12147
  fullPath: /* @__PURE__ */ new Map(),
12136
12148
  treeEdges: /* @__PURE__ */ new Map(),
@@ -12138,15 +12150,15 @@ function zi() {
12138
12150
  assetUrls: /* @__PURE__ */ new Map()
12139
12151
  };
12140
12152
  }
12141
- function Bi(...e) {
12153
+ function Hi(...e) {
12142
12154
  return e.map((e) => String(e ?? "")).join(":");
12143
12155
  }
12144
- function Vi(e) {
12156
+ function Ui(e) {
12145
12157
  if (!e || String(e).trim() === "") return null;
12146
12158
  let t = new Date(e.includes("T") ? e : e.replace(" ", "T") + "Z");
12147
12159
  return isNaN(t.getTime()) ? e : t.toISOString();
12148
12160
  }
12149
- function Hi(e, t) {
12161
+ function Wi(e, t) {
12150
12162
  let n = Date.now();
12151
12163
  if (e && String(e).trim() !== "") {
12152
12164
  let t = Date.parse(e);
@@ -12158,7 +12170,7 @@ function Hi(e, t) {
12158
12170
  }
12159
12171
  return !0;
12160
12172
  }
12161
- async function Ui(e, t, n) {
12173
+ async function Gi(e, t, n) {
12162
12174
  let r = t.filter((e) => e.componentId === "content-feed" || e.componentId === "article-list");
12163
12175
  await Promise.all(r.map(async (t) => {
12164
12176
  let r = t.data || {}, i = r.nodeType || "article", a = Number(r.limit) || 12, o = r.sortBy || "updatedAt", s = "FROM content_nodes WHERE contentType = ? AND isHidden = 0 AND (status = 'published' OR status IS NULL)", c = [i];
@@ -12172,13 +12184,13 @@ async function Ui(e, t, n) {
12172
12184
  if (e.dataJson) try {
12173
12185
  t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
12174
12186
  } catch {}
12175
- return Hi(t.startShowingAt, t.stopShowingAt) ? {
12187
+ return Wi(t.startShowingAt, t.stopShowingAt) ? {
12176
12188
  id: e.id,
12177
12189
  title: e.title,
12178
12190
  slug: e.slug,
12179
12191
  language: e.language || "en",
12180
- createdAt: Vi(e.createdAt),
12181
- updatedAt: Vi(e.updatedAt),
12192
+ createdAt: Ui(e.createdAt),
12193
+ updatedAt: Ui(e.updatedAt),
12182
12194
  excerpt: t.excerpt || "",
12183
12195
  image: t.image || t.coverImage || null,
12184
12196
  author: t.author || null
@@ -12189,7 +12201,7 @@ async function Ui(e, t, n) {
12189
12201
  }
12190
12202
  }));
12191
12203
  }
12192
- async function Wi(e, t, n, r, i = !1, a) {
12204
+ async function Ki(e, t, n, r, i = !1, a) {
12193
12205
  if (!t) return { blocks: [] };
12194
12206
  let o = await e.prepare("\n WITH RECURSIVE ancestor_path(id, contentId, title, slug, parentId, level) AS (\n SELECT t.id, t.contentId, c.title, c.slug, t.parentId, 0 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.id = ? OR c.id = ?\n UNION ALL\n SELECT t.id, t.contentId, c.title, c.slug, t.parentId, ap.level + 1 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id INNER JOIN ancestor_path ap ON t.id = ap.parentId\n ) SELECT * FROM ancestor_path ORDER BY level ASC\n ").all(t, t), s = Array.isArray(o) ? o : o?.results || [];
12195
12207
  if (!s || s.length === 0) return { blocks: [] };
@@ -12230,10 +12242,10 @@ async function Wi(e, t, n, r, i = !1, a) {
12230
12242
  try {
12231
12243
  a = (typeof t.dataJson == "string" ? JSON.parse(t.dataJson) : t.dataJson) || {};
12232
12244
  } catch {}
12233
- let o = a.hidden === !0 || a.hidden === 1 || a.hidden === "1" || a.hidden === "true", s = Hi(a.startShowingAt, a.stopShowingAt);
12245
+ let o = a.hidden === !0 || a.hidden === 1 || a.hidden === "1" || a.hidden === "true", s = Wi(a.startShowingAt, a.stopShowingAt);
12234
12246
  if (!i && (o || !s)) return null;
12235
- let c = t.elementType || t.componentId || "text-block", l = r.blocks?.[c]?.fields || r.elements?.[c]?.fields || r.components?.[c]?.fields || {}, u = String(a.blockId || a._instanceId || (a.id && !String(a.id).startsWith("ast_") ? a.id : null) || t.blockId || t.id), d = Gi(a, l);
12236
- return d = await ci(e, d), d = Ki(d), d.blockId = u, {
12247
+ let c = t.elementType || t.componentId || "text-block", l = r.blocks?.[c]?.fields || r.elements?.[c]?.fields || r.components?.[c]?.fields || {}, u = String(a.blockId || a._instanceId || (a.id && !String(a.id).startsWith("ast_") ? a.id : null) || t.blockId || t.id), d = qi(a, l);
12248
+ return d = await ui(e, d), d = Ji(d), d.blockId = u, {
12237
12249
  region: t.region || n,
12238
12250
  block: {
12239
12251
  instanceId: t.id,
@@ -12253,7 +12265,7 @@ async function Wi(e, t, n, r, i = !1, a) {
12253
12265
  }
12254
12266
  return { blocks: [] };
12255
12267
  }
12256
- function Gi(e, t = {}) {
12268
+ function qi(e, t = {}) {
12257
12269
  let n = {};
12258
12270
  for (let [r, i] of Object.entries(e)) {
12259
12271
  if (r === "id" && typeof i == "string" && i.startsWith("ast_")) {
@@ -12264,14 +12276,14 @@ function Gi(e, t = {}) {
12264
12276
  }
12265
12277
  return n;
12266
12278
  }
12267
- function Ki(e) {
12268
- if (Array.isArray(e)) return e.map(Ki);
12279
+ function Ji(e) {
12280
+ if (Array.isArray(e)) return e.map(Ji);
12269
12281
  if (!e || typeof e != "object") return e;
12270
12282
  if (typeof e.id == "string" && e.id.startsWith("ast_") && typeof e.url == "string") {
12271
12283
  let t = e.metadataOverrides || {}, n = e.variants && typeof e.variants == "object" ? e.variants : {}, r = Object.entries(n).find(([, t]) => t?.id === e.id)?.[0], i = r ? {
12272
12284
  ...t,
12273
12285
  ...t.crops?.[r] || {}
12274
- } : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t, Ki({
12286
+ } : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t, Ji({
12275
12287
  ...n,
12276
12288
  title: n?.title ?? e.title ?? "",
12277
12289
  alt: n?.alt ?? e.alt ?? "",
@@ -12285,9 +12297,9 @@ function Ki(e) {
12285
12297
  ...Object.keys(a).length > 0 ? { variants: a } : {}
12286
12298
  };
12287
12299
  }
12288
- return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, Ki(t)]));
12300
+ return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, Ji(t)]));
12289
12301
  }
12290
- async function qi(e, t, n) {
12302
+ async function Yi(e, t, n) {
12291
12303
  if (!t) return t;
12292
12304
  if (typeof t == "string") {
12293
12305
  if (!t.includes("#node:") && !t.includes("data-node-id") && !t.includes("#asset:") && !t.includes("data-asset-id")) return t;
@@ -12306,9 +12318,9 @@ async function qi(e, t, n) {
12306
12318
  return await Promise.all(Array.from(t.matchAll(d)).map(async (t) => {
12307
12319
  let i = t[1], a = r(i, "data-node-id"), o = r(i, "data-tree-id");
12308
12320
  if (!a || !o) return;
12309
- let s = await Yi(e, a, o, n);
12321
+ let s = await Zi(e, a, o, n);
12310
12322
  if (s?.treeNodeId) {
12311
- let t = await $i(e, String(s.treeNodeId), o, n);
12323
+ let t = await ta(e, String(s.treeNodeId), o, n);
12312
12324
  u.set(`${a}:${o}`, t);
12313
12325
  }
12314
12326
  })), t.replace(d, (e, t) => {
@@ -12328,41 +12340,41 @@ async function qi(e, t, n) {
12328
12340
  return /href\s*=/.test(h) || (h += ` href="${m || "/"}"`), `<a ${h}>`;
12329
12341
  });
12330
12342
  }
12331
- if (Array.isArray(t)) return Promise.all(t.map((t) => qi(e, t, n)));
12343
+ if (Array.isArray(t)) return Promise.all(t.map((t) => Yi(e, t, n)));
12332
12344
  if (typeof t == "object") {
12333
12345
  let r = JSON.stringify(t);
12334
12346
  if (!r.includes("#node:") && !r.includes("data-node-id") && !r.includes("#asset:") && !r.includes("data-asset-id")) return t;
12335
12347
  if (typeof t.href == "string" && (t.href.startsWith("#node:") || t.href.startsWith("#asset:"))) return {
12336
12348
  ...t,
12337
- href: await Ji(e, t, n)
12349
+ href: await Xi(e, t, n)
12338
12350
  };
12339
- let i = await Promise.all(Object.entries(t).map(async ([t, r]) => [t, await qi(e, r, n)]));
12351
+ let i = await Promise.all(Object.entries(t).map(async ([t, r]) => [t, await Yi(e, r, n)]));
12340
12352
  return Object.fromEntries(i);
12341
12353
  }
12342
12354
  return t;
12343
12355
  }
12344
- async function Ji(e, t, n) {
12356
+ async function Xi(e, t, n) {
12345
12357
  let r = t.href.match(/^#node:(.+)$/), i = t.href.match(/^#asset:(.+)$/);
12346
- if (i) return Zi(e, i[1], n);
12358
+ if (i) return $i(e, i[1], n);
12347
12359
  if (!r) return t.href;
12348
12360
  let a = r[1];
12349
12361
  if (t.treeId) {
12350
- let r = await Yi(e, a, String(t.treeId), n);
12362
+ let r = await Zi(e, a, String(t.treeId), n);
12351
12363
  if (r?.treeNodeId) {
12352
- let i = await $i(e, String(r.treeNodeId), String(t.treeId), n);
12364
+ let i = await ta(e, String(r.treeNodeId), String(t.treeId), n);
12353
12365
  if (i) return i;
12354
12366
  }
12355
12367
  }
12356
- let o = await Xi(e, a, n);
12368
+ let o = await Qi(e, a, n);
12357
12369
  return o === void 0 ? "#" : `/${o}`;
12358
12370
  }
12359
- async function Yi(e, t, n, r) {
12360
- let i = Bi(t, n);
12371
+ async function Zi(e, t, n, r) {
12372
+ let i = Hi(t, n);
12361
12373
  if (r.treeEdges.has(i)) return r.treeEdges.get(i);
12362
12374
  let a = e.prepare("SELECT id as treeNodeId FROM tree_nodes WHERE contentId = ? AND treeId = ? LIMIT 1").get(t, n);
12363
12375
  return r.treeEdges.set(i, Promise.resolve(a)), a;
12364
12376
  }
12365
- async function Xi(e, t, n) {
12377
+ async function Qi(e, t, n) {
12366
12378
  let r = String(t);
12367
12379
  if (n.nodeSlugs.has(r)) return n.nodeSlugs.get(r);
12368
12380
  let i = (async () => {
@@ -12371,7 +12383,7 @@ async function Xi(e, t, n) {
12371
12383
  })();
12372
12384
  return n.nodeSlugs.set(r, i), i;
12373
12385
  }
12374
- async function Zi(e, t, n) {
12386
+ async function $i(e, t, n) {
12375
12387
  let r = String(t);
12376
12388
  if (n.assetUrls.has(r)) return n.assetUrls.get(r);
12377
12389
  let i = (async () => {
@@ -12380,7 +12392,7 @@ async function Zi(e, t, n) {
12380
12392
  })();
12381
12393
  return n.assetUrls.set(r, i), i;
12382
12394
  }
12383
- function Qi(e) {
12395
+ function ea(e) {
12384
12396
  let t = e.socialImage;
12385
12397
  if (!t || typeof t != "object") return null;
12386
12398
  let n = (e, t) => {
@@ -12411,9 +12423,9 @@ function Qi(e) {
12411
12423
  ])
12412
12424
  };
12413
12425
  }
12414
- async function $i(e, t, n, r) {
12426
+ async function ta(e, t, n, r) {
12415
12427
  if (!t) return "";
12416
- let i = Bi(t, n);
12428
+ let i = Hi(t, n);
12417
12429
  if (r && r.fullPath.has(i)) return r.fullPath.get(i);
12418
12430
  let a = (async () => {
12419
12431
  let r = await e.prepare("\n WITH RECURSIVE ancestor_path(id, parentId, slug, level) AS (\n SELECT t.id, t.parentId, c.slug, 0 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.id = ? AND t.treeId = ?\n UNION ALL\n SELECT t.id, t.parentId, c.slug, ap.level + 1 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id INNER JOIN ancestor_path ap ON t.id = ap.parentId WHERE t.treeId = ?\n ) SELECT slug FROM ancestor_path ORDER BY level DESC\n ").all(t, n, n), i = Array.isArray(r) ? r : r?.results || [], a = [];
@@ -12425,7 +12437,7 @@ async function $i(e, t, n, r) {
12425
12437
  })();
12426
12438
  return r && r.fullPath.set(i, a), a;
12427
12439
  }
12428
- async function ea(e, t, n, r, i) {
12440
+ async function na(e, t, n, r, i) {
12429
12441
  let a = {}, o = null;
12430
12442
  if (t) {
12431
12443
  let n = await e.prepare("\n WITH RECURSIVE ancestor_path(id, contentId, title, slug, parentId, level) AS (\n SELECT t.id, t.contentId, c.title, c.slug, t.parentId, 0 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.id = ? OR c.id = ?\n UNION ALL\n SELECT t.id, t.contentId, c.title, c.slug, t.parentId, ap.level + 1 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id INNER JOIN ancestor_path ap ON t.id = ap.parentId\n ) SELECT c.dataJson, c.draftDataJson FROM ancestor_path ap INNER JOIN content_nodes c ON ap.contentId = c.id ORDER BY ap.level ASC\n ").all(t, t), i = Array.isArray(n) ? n : n?.results || [], s = /* @__PURE__ */ new Set([
@@ -12463,13 +12475,13 @@ async function ea(e, t, n, r, i) {
12463
12475
  inheritedFields: a
12464
12476
  };
12465
12477
  }
12466
- function ta(e) {
12478
+ function ra(e) {
12467
12479
  let t = Number(e?.env?.CMS_NODE_CACHE_TTL);
12468
12480
  return Number.isFinite(t) && t >= 60 ? Math.floor(t) : 300;
12469
12481
  }
12470
- Li.get("/*", async (e) => {
12482
+ zi.get("/*", async (e) => {
12471
12483
  try {
12472
- let t = e.get("db"), n = zi(), r = new URL(e.req.url).pathname.match(/\/node\/(.+)$/), i = (r ? r[1] : "home").replace(/^\/+|\/+$/g, ""), a = e.req.query("channelId") || e.req.query("channel") || "1", o = e.req.query("lang") || "en", s = e.req.query("preview") === "true", c = isNaN(Number(a)) ? await t.prepare("SELECT * FROM channels WHERE key = ?").get(a) : await t.prepare("SELECT * FROM channels WHERE id = ?").get(Number(a));
12484
+ let t = e.get("db"), n = Vi(), r = new URL(e.req.url).pathname.match(/\/node\/(.+)$/), i = (r ? r[1] : "home").replace(/^\/+|\/+$/g, ""), a = e.req.query("channelId") || e.req.query("channel") || "1", o = e.req.query("lang") || "en", s = e.req.query("preview") === "true", c = isNaN(Number(a)) ? await t.prepare("SELECT * FROM channels WHERE key = ?").get(a) : await t.prepare("SELECT * FROM channels WHERE id = ?").get(Number(a));
12473
12485
  if (!c) return e.json({ error: `Channel '${a}' not found` }, 404);
12474
12486
  let l = c.status === "disabled" || c.status === "inactive" || c.isEnabled === 0 || c.isEnabled === !1;
12475
12487
  if (!s && l) return e.json({ error: `Channel '${c.key || a}' is currently inactive` }, 404);
@@ -12478,7 +12490,7 @@ Li.get("/*", async (e) => {
12478
12490
  let t = await f.get(p);
12479
12491
  if (t) return e.header("X-Cache", "HIT"), e.json(t);
12480
12492
  }
12481
- let h = Ar(e.env?.BUNDLED_DEFINITIONS), g = /^\d+$/.test(i), _ = null, v = null, y = e.req.query("treeId"), b = i.split("/"), x = b[b.length - 1], S = "/" + i.replace(/^\/+|\/+$/g, ""), C = `
12493
+ let h = Mr(e.env?.BUNDLED_DEFINITIONS), g = /^\d+$/.test(i), _ = null, v = null, y = e.req.query("treeId"), b = i.split("/"), x = b[b.length - 1], S = "/" + i.replace(/^\/+|\/+$/g, ""), C = `
12482
12494
  SELECT cn.*, tn.id as treeNodeId, tn.parentId, tn.treeId
12483
12495
  FROM content_nodes cn
12484
12496
  INNER JOIN tree_nodes tn ON cn.id = tn.contentId
@@ -12488,7 +12500,7 @@ Li.get("/*", async (e) => {
12488
12500
  if (E.length > 0) {
12489
12501
  let e = await Promise.all(E.map(async (e) => ({
12490
12502
  candidate: e,
12491
- calculatedPath: await $i(t, String(e.treeNodeId), String(e.treeId), n)
12503
+ calculatedPath: await ta(t, String(e.treeNodeId), String(e.treeId), n)
12492
12504
  }))), r = S.replace(/^\/+|\/+$/g, "");
12493
12505
  for (let { candidate: t, calculatedPath: n } of e) {
12494
12506
  let e = n.replace(/^\/+|\/+$/g, "");
@@ -12503,7 +12515,7 @@ Li.get("/*", async (e) => {
12503
12515
  let e = y ? [_.id, y] : [_.id];
12504
12516
  v = await t.prepare(`SELECT id as treeNodeId, treeId, parentId FROM tree_nodes WHERE contentId = ? ${y ? "AND treeId = ?" : ""} LIMIT 1`).get(...e);
12505
12517
  }
12506
- let D = v?.treeId || y || "main-nav", O = v?.parentId || null, ee = v?.treeNodeId ? await $i(t, String(v.treeNodeId), String(D), n) : `/${(_.slug || "").replace(/^\/+|\/+$/g, "")}`, k = {}, te = s && _.draftDataJson ? _.draftDataJson : _.dataJson || _.draftDataJson;
12518
+ let D = v?.treeId || y || "main-nav", O = v?.parentId || null, ee = v?.treeNodeId ? await ta(t, String(v.treeNodeId), String(D), n) : `/${(_.slug || "").replace(/^\/+|\/+$/g, "")}`, k = {}, te = s && _.draftDataJson ? _.draftDataJson : _.dataJson || _.draftDataJson;
12507
12519
  if (te) try {
12508
12520
  k = typeof te == "string" ? JSON.parse(te) : te;
12509
12521
  } catch {}
@@ -12512,7 +12524,7 @@ Li.get("/*", async (e) => {
12512
12524
  Object.assign(j, e.fields || {});
12513
12525
  });
12514
12526
  let ie = +!!s, [ae, oe, M] = await Promise.all([
12515
- ea(t, O, D, s, j),
12527
+ na(t, O, D, s, j),
12516
12528
  v?.treeNodeId ? t.prepare("SELECT t.id as treeNodeId, t.contentId as id, c.title, c.slug, c.language, c.contentType as nodeType, c.isHidden, c.dataJson, c.draftDataJson FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.parentId = ? AND t.treeId = ? ORDER BY t.sortOrder ASC").all(v.treeNodeId, D) : Promise.resolve([]),
12517
12529
  t.prepare("SELECT * FROM content_blocks WHERE contentId = ? AND isDraft = ? ORDER BY sortOrder ASC").all(_.id, ie)
12518
12530
  ]), { resolvedLayoutId: N, inheritedFields: se } = ae, P = {
@@ -12521,10 +12533,10 @@ Li.get("/*", async (e) => {
12521
12533
  slug: _.slug,
12522
12534
  path: ee === "" ? "/" : ee,
12523
12535
  nodeType: ne,
12524
- createdAt: Vi(_.createdAt),
12525
- updatedAt: Vi(_.updatedAt),
12526
- publishedAt: Vi(k.publishedAt || _.createdAt)
12527
- }, ce = k.disabledRegions || {}, le = k.hidden === !0 || k.hidden === 1 || k.hidden === "1" || k.hidden === "true", F = k.startShowingAt || null, ue = k.stopShowingAt || null, de = Gi(k, j), fe = de.layoutId || null, pe = fe && fe !== "inherit", me = !1, I = null;
12536
+ createdAt: Ui(_.createdAt),
12537
+ updatedAt: Ui(_.updatedAt),
12538
+ publishedAt: Ui(k.publishedAt || _.createdAt)
12539
+ }, ce = k.disabledRegions || {}, le = k.hidden === !0 || k.hidden === 1 || k.hidden === "1" || k.hidden === "true", F = k.startShowingAt || null, ue = k.stopShowingAt || null, de = qi(k, j), fe = de.layoutId || null, pe = fe && fe !== "inherit", me = !1, I = null;
12528
12540
  j.layoutId && (me = !0, j.layoutId.options && Array.isArray(j.layoutId.options) && (I = j.layoutId.options.map((e) => typeof e == "object" ? e.value || e.id : e)));
12529
12541
  let he = null;
12530
12542
  if (me && I && I.length === 1 && I[0] !== "inherit") he = I[0];
@@ -12534,11 +12546,11 @@ Li.get("/*", async (e) => {
12534
12546
  he = e && e !== "inherit" && (!I || I.includes(e) || I.includes("inherit")) ? e : A.defaultLayout || null;
12535
12547
  }
12536
12548
  for (let [e, t] of Object.entries(se)) j[e] && (de[e] === void 0 || de[e] === null || de[e] === "" || de[e] === "inherit") && t !== void 0 && (de[e] = t);
12537
- let L = await ci(t, de);
12538
- L = Ki(L), L = await qi(t, L, n);
12539
- let R = Qi(L);
12549
+ let L = await ui(t, de);
12550
+ L = Ji(L), L = await Yi(t, L, n);
12551
+ let R = ea(L);
12540
12552
  delete L.socialImage, delete L.fbImage, delete L.xImage, delete L.whatsappImage, R && (L.socialImages = R), delete L.id, delete L.title, delete L.slug, delete L.language, delete L.contentType, delete L.nodeType, delete L.createdAt, delete L.updatedAt, delete L.publishedAt, delete L.channelId, delete L.treeId, delete L.path, L.iconName === "" && (L.iconName = null), Object.assign(P, L), A.hasCanvas && (P.layoutId = he);
12541
- let ge = Number(_.isHidden) === 1 || le, _e = !Hi(F, ue);
12553
+ let ge = Number(_.isHidden) === 1 || le, _e = !Wi(F, ue);
12542
12554
  if (!s && (ge || _e)) return e.json({ error: "Node is hidden or outside its scheduled publishing window" }, 404);
12543
12555
  let ve = [];
12544
12556
  if (v?.treeNodeId) {
@@ -12548,7 +12560,7 @@ Li.get("/*", async (e) => {
12548
12560
  try {
12549
12561
  n = (typeof r == "string" ? JSON.parse(r) : r) || {};
12550
12562
  } catch {}
12551
- let i = Number(e.isHidden) === 1 || n.hidden === !0 || n.hidden === 1 || n.hidden === "1", a = Hi(n.startShowingAt, n.stopShowingAt), o = (e.slug || "").replace(/^\/+|\/+$/g, "");
12563
+ let i = Number(e.isHidden) === 1 || n.hidden === !0 || n.hidden === 1 || n.hidden === "1", a = Wi(n.startShowingAt, n.stopShowingAt), o = (e.slug || "").replace(/^\/+|\/+$/g, "");
12552
12564
  return !s && (i || !a) ? null : {
12553
12565
  treeNodeId: e.treeNodeId,
12554
12566
  id: e.id,
@@ -12571,10 +12583,10 @@ Li.get("/*", async (e) => {
12571
12583
  try {
12572
12584
  i = (typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson) || {};
12573
12585
  } catch {}
12574
- let a = i.hidden === !0 || i.hidden === 1 || i.hidden === "1" || i.hidden === "true", o = Hi(i.startShowingAt, i.stopShowingAt);
12586
+ let a = i.hidden === !0 || i.hidden === 1 || i.hidden === "1" || i.hidden === "true", o = Wi(i.startShowingAt, i.stopShowingAt);
12575
12587
  if (!s && (a || !o)) return null;
12576
- let c = e.elementType || e.componentId || "text-block", l = h.blocks?.[c]?.fields || h.elements?.[c]?.fields || h.components?.[c]?.fields || {}, u = String(i.blockId || i._instanceId || (i.id && !String(i.id).startsWith("ast_") ? i.id : null) || e.blockId || e.id), d = Gi(i, l);
12577
- return d = await ci(t, d), d = Ki(d), d = await qi(t, d, n), d.blockId = u, {
12588
+ let c = e.elementType || e.componentId || "text-block", l = h.blocks?.[c]?.fields || h.elements?.[c]?.fields || h.components?.[c]?.fields || {}, u = String(i.blockId || i._instanceId || (i.id && !String(i.id).startsWith("ast_") ? i.id : null) || e.blockId || e.id), d = qi(i, l);
12589
+ return d = await ui(t, d), d = Ji(d), d = await Yi(t, d, n), d.blockId = u, {
12578
12590
  region: r,
12579
12591
  block: {
12580
12592
  instanceId: e.id,
@@ -12599,7 +12611,7 @@ Li.get("/*", async (e) => {
12599
12611
  for (let [e, r] of Object.entries(xe)) {
12600
12612
  let i = z[e] && z[e].length > 0, a = !!ce[e];
12601
12613
  if (z[e] || (z[e] = [], B[e] = { isInherited: !1 }), (r?.inherit === "parent" || r?.inherit === !0 || r?.inherit === "true" || e === "header" || e === "footer") && !i && !a && O) {
12602
- let r = await Wi(t, O, e, h, s, n);
12614
+ let r = await Ki(t, O, e, h, s, n);
12603
12615
  if (r.blocks.length > 0 && (z[e] = r.blocks, B[e] = {
12604
12616
  isInherited: !0,
12605
12617
  inheritedFromId: r.inheritedFromId,
@@ -12611,7 +12623,7 @@ Li.get("/*", async (e) => {
12611
12623
  });
12612
12624
  }
12613
12625
  }
12614
- await Promise.all(Object.keys(z).map((e) => Ui(t, z[e], u)));
12626
+ await Promise.all(Object.keys(z).map((e) => Gi(t, z[e], u)));
12615
12627
  let Se = {
12616
12628
  channelId: u || d,
12617
12629
  treeId: D,
@@ -12620,7 +12632,7 @@ Li.get("/*", async (e) => {
12620
12632
  content: z,
12621
12633
  regionMeta: B
12622
12634
  };
12623
- return !s && !m ? (e.header("X-Cache", "MISS"), Ri(e, f.set(p, Se, ta(e)))) : e.header("Cache-Control", "no-store, no-cache, must-revalidate"), e.json(Se);
12635
+ return !s && !m ? (e.header("X-Cache", "MISS"), Bi(e, f.set(p, Se, ra(e)))) : e.header("Cache-Control", "no-store, no-cache, must-revalidate"), e.json(Se);
12624
12636
  } catch (t) {
12625
12637
  console.error("[CMS Public API] Error fetching node by path:", t);
12626
12638
  let n = e.env?.ENVIRONMENT === "development";
@@ -12632,14 +12644,14 @@ Li.get("/*", async (e) => {
12632
12644
  });
12633
12645
  //#endregion
12634
12646
  //#region server/routes/public/tree.ts
12635
- var na = new n();
12636
- function ra(e, t) {
12647
+ var ia = new n();
12648
+ function aa(e, t) {
12637
12649
  let n = Promise.resolve(t).catch((e) => console.error("[Background Task Error]:", e));
12638
12650
  try {
12639
12651
  e.executionCtx && typeof e.executionCtx.waitUntil == "function" && e.executionCtx.waitUntil(n);
12640
12652
  } catch {}
12641
12653
  }
12642
- function ia(e, t) {
12654
+ function oa(e, t) {
12643
12655
  let n = /* @__PURE__ */ new Date();
12644
12656
  if (e && String(e).trim() !== "") {
12645
12657
  let t = new Date(e);
@@ -12651,7 +12663,7 @@ function ia(e, t) {
12651
12663
  }
12652
12664
  return !0;
12653
12665
  }
12654
- na.get("/:treeParam", async (e) => {
12666
+ ia.get("/:treeParam", async (e) => {
12655
12667
  try {
12656
12668
  let t = e.get("db"), n = e.req.param("treeParam"), r = e.req.query("channelId") || e.req.query("channel") || "default", i = e.req.query("preview") === "true";
12657
12669
  if (r && r !== "default" && r !== "all") {
@@ -12692,7 +12704,7 @@ na.get("/:treeParam", async (e) => {
12692
12704
  if ((!p || p.length === 0) && !u) return e.json({ error: `Tree '${n}' not found` }, 404);
12693
12705
  let m = {};
12694
12706
  if (u && u.dataJson) try {
12695
- let t = typeof u.dataJson == "string" ? JSON.parse(u.dataJson) : u.dataJson, r = e.env?.BUNDLED_DEFINITIONS, i = Ar(r), a = (i.trees?.[u.treeType || n] || i.trees?.site || {}).fields || {};
12707
+ let t = typeof u.dataJson == "string" ? JSON.parse(u.dataJson) : u.dataJson, r = e.env?.BUNDLED_DEFINITIONS, i = Mr(r), a = (i.trees?.[u.treeType || n] || i.trees?.site || {}).fields || {};
12696
12708
  for (let [e, n] of Object.entries(t)) a[e]?.public === !0 && (m[e] = n);
12697
12709
  } catch (e) {
12698
12710
  console.warn("[CMS Public Tree API] Failed to parse tree dataJson", e);
@@ -12729,7 +12741,7 @@ na.get("/:treeParam", async (e) => {
12729
12741
  "isHidden",
12730
12742
  "status"
12731
12743
  ].includes(e) || (r[e] = t);
12732
- let a = !i && (e.status === "draft" || e.status === "new"), o = Number(e.isHidden) === 1 || a || n.hidden === !0 || n.hidden === 1 || n.hidden === "1" || n.hidden === "true", s = ia(n.startShowingAt, n.stopShowingAt), c = (e.slug || "").replace(/^\/+|\/+$/g, ""), l = (!e.parentId || e.parentId === "null" || e.parentId === "") && (c === "home" || c === "homee") ? "/" : `${t}/${c}`.replace(/\/+/g, "/"), u = {
12744
+ let a = !i && (e.status === "draft" || e.status === "new"), o = Number(e.isHidden) === 1 || a || n.hidden === !0 || n.hidden === 1 || n.hidden === "1" || n.hidden === "true", s = oa(n.startShowingAt, n.stopShowingAt), c = (e.slug || "").replace(/^\/+|\/+$/g, ""), l = (!e.parentId || e.parentId === "null" || e.parentId === "") && (c === "home" || c === "homee") ? "/" : `${t}/${c}`.replace(/\/+/g, "/"), u = {
12733
12745
  id: e.id,
12734
12746
  treeNodeId: e.treeNodeId,
12735
12747
  parentId: e.parentId || null,
@@ -12754,7 +12766,7 @@ na.get("/:treeParam", async (e) => {
12754
12766
  ...m,
12755
12767
  items: _(null)
12756
12768
  };
12757
- return !i && !s ? (e.header("X-Cache", "MISS"), ra(e, a.set(o, v, 300))) : e.header("Cache-Control", "no-store, no-cache, must-revalidate"), e.json(v);
12769
+ return !i && !s ? (e.header("X-Cache", "MISS"), aa(e, a.set(o, v, 300))) : e.header("Cache-Control", "no-store, no-cache, must-revalidate"), e.json(v);
12758
12770
  } catch (t) {
12759
12771
  return console.error("[CMS Public Tree API] Error:", t), e.json({
12760
12772
  error: "Failed to fetch public tree",
@@ -12764,8 +12776,8 @@ na.get("/:treeParam", async (e) => {
12764
12776
  });
12765
12777
  //#endregion
12766
12778
  //#region server/routes/public/assets.ts
12767
- var aa = new n();
12768
- function oa(e, t) {
12779
+ var sa = new n();
12780
+ function ca(e, t) {
12769
12781
  if (t === "webp") return "image/webp";
12770
12782
  if (t === "avif") return "image/avif";
12771
12783
  if (t === "jpeg" || t === "jpg") return "image/jpeg";
@@ -12773,7 +12785,7 @@ function oa(e, t) {
12773
12785
  let n = e.toLowerCase();
12774
12786
  return n.endsWith(".jpg") || n.endsWith(".jpeg") ? "image/jpeg" : n.endsWith(".png") ? "image/png" : n.endsWith(".webp") ? "image/webp" : n.endsWith(".gif") ? "image/gif" : n.endsWith(".svg") ? "image/svg+xml" : n.endsWith(".pdf") ? "application/pdf" : n.endsWith(".mp4") ? "video/mp4" : n.endsWith(".webm") ? "video/webm" : "application/octet-stream";
12775
12787
  }
12776
- aa.get("/*", async (e) => {
12788
+ sa.get("/*", async (e) => {
12777
12789
  let t = e.req.path.replace(/^\/media\//, "").replace(/^\//, "");
12778
12790
  if (!t) return e.text("Asset key missing", 400);
12779
12791
  let n = e.env?.MEDIA_BUCKET, { w: r, h: i, q: a, f: o } = e.req.query(), s = !!(r || i || a || o), c = e.req.header("Accept") || "", l = "";
@@ -12790,7 +12802,7 @@ aa.get("/*", async (e) => {
12790
12802
  }
12791
12803
  let p = e.req.header("Via")?.includes("image-resizing") || e.req.header("User-Agent")?.includes("Cloudflare-ImgRen"), m = new URL(e.req.url), h = e.env?.CDN_DOMAIN || m.hostname;
12792
12804
  if (n) {
12793
- let l = oa(t), u = l.startsWith("image/") && !l.includes("svg");
12805
+ let l = ca(t), u = l.startsWith("image/") && !l.includes("svg");
12794
12806
  if (s && u && h && !p) {
12795
12807
  let e = r ? parseInt(r, 10) : void 0, n = i ? parseInt(i, 10) : void 0, s = a ? parseInt(a, 10) : 85, l = o || "auto", u = `https://${h}/media/${t}`;
12796
12808
  try {
@@ -12833,7 +12845,7 @@ aa.get("/*", async (e) => {
12833
12845
  if (!s) {
12834
12846
  let n = _(C);
12835
12847
  return e.body(n, 200, {
12836
- "Content-Type": oa(t),
12848
+ "Content-Type": ca(t),
12837
12849
  "Cache-Control": "public, max-age=86400"
12838
12850
  });
12839
12851
  }
@@ -12841,7 +12853,7 @@ aa.get("/*", async (e) => {
12841
12853
  if (g(f)) {
12842
12854
  let n = _(f);
12843
12855
  return e.body(n, 200, {
12844
- "Content-Type": oa(t, u),
12856
+ "Content-Type": ca(t, u),
12845
12857
  "Cache-Control": "public, max-age=31536000, immutable",
12846
12858
  "X-Local-Cache": "HIT"
12847
12859
  });
@@ -12854,14 +12866,14 @@ aa.get("/*", async (e) => {
12854
12866
  typeof n == "number" && (a.width = n), typeof o == "number" && (a.height = o), (a.width || a.height) && (a.fit = "cover", i = i.resize(a)), u === "webp" ? i = i.webp({ quality: typeof c == "number" ? c : 80 }) : u === "avif" ? i = i.avif({ quality: typeof c == "number" ? c : 70 }) : u === "jpeg" || u === "jpg" ? i = i.jpeg({ quality: typeof c == "number" ? c : 80 }) : u === "png" && (i = i.png({ quality: typeof c == "number" ? c : 80 }));
12855
12867
  let s = await i.toBuffer();
12856
12868
  return v(x(f), { recursive: !0 }), y(f, s), e.body(s, 200, {
12857
- "Content-Type": oa(t, u),
12869
+ "Content-Type": ca(t, u),
12858
12870
  "Cache-Control": "public, max-age=31536000, immutable",
12859
12871
  "X-Local-Cache": "MISS"
12860
12872
  });
12861
12873
  } catch {
12862
12874
  let n = _(C);
12863
12875
  return e.body(n, 200, {
12864
- "Content-Type": oa(t),
12876
+ "Content-Type": ca(t),
12865
12877
  "Cache-Control": "public, max-age=86400"
12866
12878
  });
12867
12879
  }
@@ -12872,8 +12884,8 @@ aa.get("/*", async (e) => {
12872
12884
  });
12873
12885
  //#endregion
12874
12886
  //#region server/routes/public/paths.ts
12875
- var sa = new n();
12876
- function ca(e, t) {
12887
+ var la = new n();
12888
+ function ua(e, t) {
12877
12889
  let n = /* @__PURE__ */ new Date();
12878
12890
  if (e && String(e).trim() !== "") {
12879
12891
  let t = new Date(e);
@@ -12885,7 +12897,7 @@ function ca(e, t) {
12885
12897
  }
12886
12898
  return !0;
12887
12899
  }
12888
- sa.get("/", async (e) => {
12900
+ la.get("/", async (e) => {
12889
12901
  try {
12890
12902
  let t = await e.get("db").prepare("\n SELECT\n t.id as treeNodeId,\n t.parentId,\n c.slug,\n c.contentType as nodeType,\n c.status,\n c.dataJson\n FROM tree_nodes t\n INNER JOIN content_nodes c ON t.contentId = c.id\n WHERE (c.deletedAt IS NULL OR c.deletedAt = '')\n ORDER BY t.sortOrder ASC\n ").all(), n = Array.isArray(t) ? t : t?.results || [], r = [], i = /* @__PURE__ */ new Map();
12891
12903
  for (let e of n) {
@@ -12909,7 +12921,7 @@ sa.get("/", async (e) => {
12909
12921
  function o(e = null, t = "") {
12910
12922
  let n = e == null || e === "" || e === "null" ? "__ROOT__" : String(e), s = i.get(n) || [];
12911
12923
  for (let e of s) {
12912
- let n = a.get(String(e.treeNodeId)) || {}, i = e.status === "published" || e.status === "active", s = ca(n.startShowingAt, n.stopShowingAt);
12924
+ let n = a.get(String(e.treeNodeId)) || {}, i = e.status === "published" || e.status === "active", s = ua(n.startShowingAt, n.stopShowingAt);
12913
12925
  if (!i || !s) continue;
12914
12926
  let c = (e.slug || "").replace(/^\/+|\/+$/g, ""), l = c === "home" || c === "homee" ? "/" : `${t}/${c}`.replace(/\/+/g, "/");
12915
12927
  e.nodeType !== "external-link" && r.push(l);
@@ -12926,8 +12938,8 @@ sa.get("/", async (e) => {
12926
12938
  });
12927
12939
  //#endregion
12928
12940
  //#region server/index.ts
12929
- var la = jr(), $ = new n(), ua = !1;
12930
- $.use("*", Nr()), $.use("/media/*", Nr({
12941
+ var da = Nr(), $ = new n(), fa = !1;
12942
+ $.use("*", Fr()), $.use("/media/*", Fr({
12931
12943
  origin: "*",
12932
12944
  allowMethods: [
12933
12945
  "GET",
@@ -12944,18 +12956,18 @@ $.use("*", Nr()), $.use("/media/*", Nr({
12944
12956
  await t(), e.header("Cache-Control", "public, max-age=31536000, immutable"), e.header("Access-Control-Allow-Origin", "*");
12945
12957
  }), $.use("*", async (e, t) => {
12946
12958
  if (e.req.path.startsWith("/media/")) return t();
12947
- let n = la;
12948
- e.env?.BUNDLED_DEFINITIONS && (e.env.BUNDLED_DEFINITIONS._isCompiled || (e.env.BUNDLED_DEFINITIONS = jr(e.env.BUNDLED_DEFINITIONS), e.env.BUNDLED_DEFINITIONS._isCompiled = !0), n = e.env.BUNDLED_DEFINITIONS), e.set("schemas", n);
12959
+ let n = da;
12960
+ e.env?.BUNDLED_DEFINITIONS && (e.env.BUNDLED_DEFINITIONS._isCompiled || (e.env.BUNDLED_DEFINITIONS = Nr(e.env.BUNDLED_DEFINITIONS), e.env.BUNDLED_DEFINITIONS._isCompiled = !0), n = e.env.BUNDLED_DEFINITIONS), e.set("schemas", n);
12949
12961
  let r = new URL(e.req.url), i = (e.req.header("host") || r.hostname).split(":")[0];
12950
12962
  e.set("currentDomain", i);
12951
- let a = Lr(e);
12952
- if (e.set("db", a), !ua) try {
12953
- await Vr(a, n), ua = !0;
12963
+ let a = zr(e);
12964
+ if (e.set("db", a), !fa) try {
12965
+ await Ur(a, n), fa = !0;
12954
12966
  } catch (e) {
12955
12967
  console.error("❌ [CMS Server] Failed to initialize system tables on cold start:", e);
12956
12968
  }
12957
12969
  await t();
12958
- }), $.route("/media", aa), $.use("/media/*", Ur()), $.route("/api/cms/nodes", Z), $.route("/api/cms/nodes.json", Z), $.route("/api/cms/formcsv", Z), $.route("/api/cms/formcsv.json", Z), $.route("/api/cms/stats", ki), $.route("/api/cms/stats.json", ki), $.route("/api/cms", _i), $.route("/api/cms/channels", xi), $.route("/api/cms/channels.json", xi), $.route("/api/cms/schemas", Ci), $.route("/api/cms/schemas.json", Ci), $.route("/api/admin/schemas", Ci), $.route("/api/cms", Ei), $.route("/api/admin/assets", Pi), $.route("/api/v1/node", Li), $.route("/api/v1/page", Li), $.route("/api/v1/tree", na), $.route("/api/v1/all-paths", sa), $.get("*", async (e) => {
12970
+ }), $.route("/media", sa), $.use("/media/*", Gr()), $.route("/api/cms/nodes", Z), $.route("/api/cms/nodes.json", Z), $.route("/api/cms/formcsv", Z), $.route("/api/cms/formcsv.json", Z), $.route("/api/cms/stats", ji), $.route("/api/cms/stats.json", ji), $.route("/api/cms", yi), $.route("/api/cms/channels", Ci), $.route("/api/cms/channels.json", Ci), $.route("/api/cms/schemas", Ti), $.route("/api/cms/schemas.json", Ti), $.route("/api/admin/schemas", Ti), $.route("/api/cms", Oi), $.route("/api/admin/assets", Ii), $.route("/api/v1/node", zi), $.route("/api/v1/page", zi), $.route("/api/v1/tree", ia), $.route("/api/v1/all-paths", la), $.get("*", async (e) => {
12959
12971
  if (e.env?.ASSETS) {
12960
12972
  let t = await e.env.ASSETS.fetch(e.req.raw);
12961
12973
  if (t.status === 404) {