@brightsideoy/kama 0.1.0-alpha.83 → 0.1.0-alpha.85

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
@@ -3645,11 +3645,11 @@ var cr = /* @__PURE__ */ new Set("0123456789ABCDEFabcdef"), lr = /* @__PURE__ */
3645
3645
  };
3646
3646
  //#endregion
3647
3647
  //#region node_modules/yaml/browser/dist/parse/parser.js
3648
- function K(e, t) {
3648
+ function hr(e, t) {
3649
3649
  for (let n = 0; n < e.length; ++n) if (e[n].type === t) return !0;
3650
3650
  return !1;
3651
3651
  }
3652
- function hr(e) {
3652
+ function gr(e) {
3653
3653
  for (let t = 0; t < e.length; ++t) switch (e[t].type) {
3654
3654
  case "space":
3655
3655
  case "comment":
@@ -3658,7 +3658,7 @@ function hr(e) {
3658
3658
  }
3659
3659
  return -1;
3660
3660
  }
3661
- function gr(e) {
3661
+ function _r(e) {
3662
3662
  switch (e?.type) {
3663
3663
  case "alias":
3664
3664
  case "scalar":
@@ -3668,7 +3668,7 @@ function gr(e) {
3668
3668
  default: return !1;
3669
3669
  }
3670
3670
  }
3671
- function _r(e) {
3671
+ function vr(e) {
3672
3672
  switch (e.type) {
3673
3673
  case "document": return e.start;
3674
3674
  case "block-map": {
@@ -3680,7 +3680,7 @@ function _r(e) {
3680
3680
  default: return [];
3681
3681
  }
3682
3682
  }
3683
- function vr(e) {
3683
+ function yr(e) {
3684
3684
  if (e.length === 0) return [];
3685
3685
  let t = e.length;
3686
3686
  loop: for (; --t >= 0;) switch (e[t].type) {
@@ -3693,14 +3693,14 @@ function vr(e) {
3693
3693
  for (; e[++t]?.type === "space";);
3694
3694
  return e.splice(t, e.length);
3695
3695
  }
3696
- function yr(e, t) {
3696
+ function br(e, t) {
3697
3697
  if (t.length < 1e5) Array.prototype.push.apply(e, t);
3698
3698
  else for (let n = 0; n < t.length; ++n) e.push(t[n]);
3699
3699
  }
3700
- function br(e) {
3701
- if (e.start.type === "flow-seq-start") for (let t of e.items) t.sep && !t.value && !K(t.start, "explicit-key-ind") && !K(t.sep, "map-value-ind") && (t.key && (t.value = t.key), delete t.key, gr(t.value) ? t.value.end ? yr(t.value.end, t.sep) : t.value.end = t.sep : yr(t.start, t.sep), delete t.sep);
3700
+ function xr(e) {
3701
+ if (e.start.type === "flow-seq-start") for (let t of e.items) t.sep && !t.value && !hr(t.start, "explicit-key-ind") && !hr(t.sep, "map-value-ind") && (t.key && (t.value = t.key), delete t.key, _r(t.value) ? t.value.end ? br(t.value.end, t.sep) : t.value.end = t.sep : br(t.start, t.sep), delete t.sep);
3702
3702
  }
3703
- var xr = class {
3703
+ var Sr = class {
3704
3704
  constructor(e) {
3705
3705
  this.atNewLine = !0, this.atScalar = !1, this.indent = 0, this.offset = 0, this.onKeyLine = !1, this.stack = [], this.source = "", this.type = "", this.lexer = new pr(), this.onNewLine = e;
3706
3706
  }
@@ -3797,7 +3797,7 @@ var xr = class {
3797
3797
  else if (this.stack.length === 0) yield t;
3798
3798
  else {
3799
3799
  let e = this.peek(1);
3800
- switch (t.type === "block-scalar" ? t.indent = "indent" in e ? e.indent : 0 : t.type === "flow-collection" && e.type === "document" && (t.indent = 0), t.type === "flow-collection" && br(t), e.type) {
3800
+ switch (t.type === "block-scalar" ? t.indent = "indent" in e ? e.indent : 0 : t.type === "flow-collection" && e.type === "document" && (t.indent = 0), t.type === "flow-collection" && xr(t), e.type) {
3801
3801
  case "document":
3802
3802
  e.value = t;
3803
3803
  break;
@@ -3849,7 +3849,7 @@ var xr = class {
3849
3849
  }
3850
3850
  if ((e.type === "document" || e.type === "block-map" || e.type === "block-seq") && (t.type === "block-map" || t.type === "block-seq")) {
3851
3851
  let n = t.items[t.items.length - 1];
3852
- n && !n.sep && !n.value && n.start.length > 0 && hr(n.start) === -1 && (t.indent === 0 || n.start.every((e) => e.type !== "comment" || e.indent < t.indent)) && (e.type === "document" ? e.end = n.start : e.items.push({ start: n.start }), t.items.splice(-1, 1));
3852
+ n && !n.sep && !n.value && n.start.length > 0 && gr(n.start) === -1 && (t.indent === 0 || n.start.every((e) => e.type !== "comment" || e.indent < t.indent)) && (e.type === "document" ? e.end = n.start : e.items.push({ start: n.start }), t.items.splice(-1, 1));
3853
3853
  }
3854
3854
  }
3855
3855
  }
@@ -3890,7 +3890,7 @@ var xr = class {
3890
3890
  if (e.value) return yield* this.lineEnd(e);
3891
3891
  switch (this.type) {
3892
3892
  case "doc-start":
3893
- hr(e.start) === -1 ? e.start.push(this.sourceToken) : (yield* this.pop(), yield* this.step());
3893
+ gr(e.start) === -1 ? e.start.push(this.sourceToken) : (yield* this.pop(), yield* this.step());
3894
3894
  return;
3895
3895
  case "anchor":
3896
3896
  case "tag":
@@ -3910,7 +3910,7 @@ var xr = class {
3910
3910
  }
3911
3911
  *scalar(e) {
3912
3912
  if (this.type === "map-value-ind") {
3913
- let t = vr(_r(this.peek(2))), n;
3913
+ let t = yr(vr(this.peek(2))), n;
3914
3914
  e.end ? (n = e.end, n.push(this.sourceToken), delete e.end) : n = [this.sourceToken];
3915
3915
  let r = {
3916
3916
  type: "block-map",
@@ -3960,7 +3960,7 @@ var xr = class {
3960
3960
  if (this.atIndentedComment(t.start, e.indent)) {
3961
3961
  let n = e.items[e.items.length - 2]?.value?.end;
3962
3962
  if (Array.isArray(n)) {
3963
- yr(n, t.start), n.push(this.sourceToken), e.items.pop();
3963
+ br(n, t.start), n.push(this.sourceToken), e.items.pop();
3964
3964
  return;
3965
3965
  }
3966
3966
  }
@@ -4009,12 +4009,12 @@ var xr = class {
4009
4009
  case "map-value-ind":
4010
4010
  if (t.explicitKey) {
4011
4011
  if (!t.sep) {
4012
- if (K(t.start, "newline")) Object.assign(t, {
4012
+ if (hr(t.start, "newline")) Object.assign(t, {
4013
4013
  key: null,
4014
4014
  sep: [this.sourceToken]
4015
4015
  });
4016
4016
  else {
4017
- let e = vr(t.start);
4017
+ let e = yr(t.start);
4018
4018
  this.stack.push({
4019
4019
  type: "block-map",
4020
4020
  offset: this.offset,
@@ -4031,7 +4031,7 @@ var xr = class {
4031
4031
  key: null,
4032
4032
  sep: [this.sourceToken]
4033
4033
  });
4034
- else if (K(t.sep, "map-value-ind")) this.stack.push({
4034
+ else if (hr(t.sep, "map-value-ind")) this.stack.push({
4035
4035
  type: "block-map",
4036
4036
  offset: this.offset,
4037
4037
  indent: this.indent,
@@ -4041,8 +4041,8 @@ var xr = class {
4041
4041
  sep: [this.sourceToken]
4042
4042
  }]
4043
4043
  });
4044
- else if (gr(t.key) && !K(t.sep, "newline")) {
4045
- let e = vr(t.start), n = t.key, r = t.sep;
4044
+ else if (_r(t.key) && !hr(t.sep, "newline")) {
4045
+ let e = yr(t.start), n = t.key, r = t.sep;
4046
4046
  r.push(this.sourceToken), delete t.key, delete t.sep, this.stack.push({
4047
4047
  type: "block-map",
4048
4048
  offset: this.offset,
@@ -4058,7 +4058,7 @@ var xr = class {
4058
4058
  start: i,
4059
4059
  key: null,
4060
4060
  sep: [this.sourceToken]
4061
- }) : K(t.sep, "map-value-ind") ? this.stack.push({
4061
+ }) : hr(t.sep, "map-value-ind") ? this.stack.push({
4062
4062
  type: "block-map",
4063
4063
  offset: this.offset,
4064
4064
  indent: this.indent,
@@ -4092,7 +4092,7 @@ var xr = class {
4092
4092
  let r = this.startBlockValue(e);
4093
4093
  if (r) {
4094
4094
  if (r.type === "block-seq") {
4095
- if (!t.explicitKey && t.sep && !K(t.sep, "newline")) {
4095
+ if (!t.explicitKey && t.sep && !hr(t.sep, "newline")) {
4096
4096
  yield* this.pop({
4097
4097
  type: "error",
4098
4098
  offset: this.offset,
@@ -4126,7 +4126,7 @@ var xr = class {
4126
4126
  if (this.atIndentedComment(t.start, e.indent)) {
4127
4127
  let n = e.items[e.items.length - 2]?.value?.end;
4128
4128
  if (Array.isArray(n)) {
4129
- yr(n, t.start), n.push(this.sourceToken), e.items.pop();
4129
+ br(n, t.start), n.push(this.sourceToken), e.items.pop();
4130
4130
  return;
4131
4131
  }
4132
4132
  }
@@ -4140,7 +4140,7 @@ var xr = class {
4140
4140
  return;
4141
4141
  case "seq-item-ind":
4142
4142
  if (this.indent !== e.indent) break;
4143
- t.value || K(t.start, "seq-item-ind") ? e.items.push({ start: [this.sourceToken] }) : t.start.push(this.sourceToken);
4143
+ t.value || hr(t.start, "seq-item-ind") ? e.items.push({ start: [this.sourceToken] }) : t.start.push(this.sourceToken);
4144
4144
  return;
4145
4145
  }
4146
4146
  if (this.indent > e.indent) {
@@ -4209,8 +4209,8 @@ var xr = class {
4209
4209
  let t = this.peek(2);
4210
4210
  if (t.type === "block-map" && (this.type === "map-value-ind" && t.indent === e.indent || this.type === "newline" && !t.items[t.items.length - 1].sep)) yield* this.pop(), yield* this.step();
4211
4211
  else if (this.type === "map-value-ind" && t.type !== "flow-collection") {
4212
- let n = vr(_r(t));
4213
- br(e);
4212
+ let n = yr(vr(t));
4213
+ xr(e);
4214
4214
  let r = e.end.splice(1, e.end.length);
4215
4215
  r.push(this.sourceToken);
4216
4216
  let i = {
@@ -4269,7 +4269,7 @@ var xr = class {
4269
4269
  };
4270
4270
  case "explicit-key-ind": {
4271
4271
  this.onKeyLine = !0;
4272
- let t = vr(_r(e));
4272
+ let t = yr(vr(e));
4273
4273
  return t.push(this.sourceToken), {
4274
4274
  type: "block-map",
4275
4275
  offset: this.offset,
@@ -4282,7 +4282,7 @@ var xr = class {
4282
4282
  }
4283
4283
  case "map-value-ind": {
4284
4284
  this.onKeyLine = !0;
4285
- let t = vr(_r(e));
4285
+ let t = yr(vr(e));
4286
4286
  return {
4287
4287
  type: "block-map",
4288
4288
  offset: this.offset,
@@ -4320,20 +4320,20 @@ var xr = class {
4320
4320
  };
4321
4321
  //#endregion
4322
4322
  //#region node_modules/yaml/browser/dist/public-api.js
4323
- function Sr(e) {
4323
+ function Cr(e) {
4324
4324
  let t = e.prettyErrors !== !1;
4325
4325
  return {
4326
4326
  lineCounter: e.lineCounter || t && new mr() || null,
4327
4327
  prettyErrors: t
4328
4328
  };
4329
4329
  }
4330
- function Cr(e, t = {}) {
4331
- let { lineCounter: n, prettyErrors: r } = Sr(t), i = new xr(n?.addNewLine), a = new Hn(t), o = Array.from(a.compose(i.parse(e)));
4330
+ function wr(e, t = {}) {
4331
+ let { lineCounter: n, prettyErrors: r } = Cr(t), i = new Sr(n?.addNewLine), a = new Hn(t), o = Array.from(a.compose(i.parse(e)));
4332
4332
  if (r && n) for (let t of o) t.errors.forEach(on(e, n)), t.warnings.forEach(on(e, n));
4333
4333
  return o.length > 0 ? o : Object.assign([], { empty: !0 }, a.streamInfo());
4334
4334
  }
4335
- function wr(e, t = {}) {
4336
- let { lineCounter: n, prettyErrors: r } = Sr(t), i = new xr(n?.addNewLine), a = new Hn(t), o = null;
4335
+ function Tr(e, t = {}) {
4336
+ let { lineCounter: n, prettyErrors: r } = Cr(t), i = new Sr(n?.addNewLine), a = new Hn(t), o = null;
4337
4337
  for (let t of a.compose(i.parse(e), !0, e.length)) if (!o) o = t;
4338
4338
  else if (o.options.logLevel !== "silent") {
4339
4339
  o.errors.push(new rn(t.range.slice(0, 2), "MULTIPLE_DOCS", "Source contains multiple documents; please use YAML.parseAllDocuments()"));
@@ -4341,10 +4341,10 @@ function wr(e, t = {}) {
4341
4341
  }
4342
4342
  return r && n && (o.errors.forEach(on(e, n)), o.warnings.forEach(on(e, n))), o;
4343
4343
  }
4344
- function Tr(e, t, n) {
4344
+ function Er(e, t, n) {
4345
4345
  let r;
4346
4346
  typeof t == "function" ? r = t : n === void 0 && t && typeof t == "object" && (n = t);
4347
- let i = wr(e, n);
4347
+ let i = Tr(e, n);
4348
4348
  if (!i) return null;
4349
4349
  if (i.warnings.forEach((e) => Be(i.options.logLevel, e)), i.errors.length > 0) {
4350
4350
  if (i.options.logLevel !== "silent") throw i.errors[0];
@@ -4352,7 +4352,7 @@ function Tr(e, t, n) {
4352
4352
  }
4353
4353
  return i.toJS(Object.assign({ reviver: r }, n));
4354
4354
  }
4355
- function Er(e, t, n) {
4355
+ function Dr(e, t, n) {
4356
4356
  let r = null;
4357
4357
  if (typeof t == "function" || Array.isArray(t) ? r = t : n === void 0 && t && (n = t), typeof n == "string" && (n = n.length), typeof n == "number") {
4358
4358
  let e = Math.round(n);
@@ -4366,7 +4366,7 @@ function Er(e, t, n) {
4366
4366
  }
4367
4367
  //#endregion
4368
4368
  //#region node_modules/yaml/browser/index.js
4369
- var Dr = /* @__PURE__ */ a({
4369
+ var Or = /* @__PURE__ */ a({
4370
4370
  Alias: () => de,
4371
4371
  CST: () => rr,
4372
4372
  Composer: () => Hn,
@@ -4374,7 +4374,7 @@ var Dr = /* @__PURE__ */ a({
4374
4374
  Lexer: () => pr,
4375
4375
  LineCounter: () => mr,
4376
4376
  Pair: () => V,
4377
- Parser: () => xr,
4377
+ Parser: () => Sr,
4378
4378
  Scalar: () => I,
4379
4379
  Schema: () => Qt,
4380
4380
  YAMLError: () => nn,
@@ -4390,13 +4390,13 @@ var Dr = /* @__PURE__ */ a({
4390
4390
  isPair: () => x,
4391
4391
  isScalar: () => S,
4392
4392
  isSeq: () => C,
4393
- parse: () => Tr,
4394
- parseAllDocuments: () => Cr,
4395
- parseDocument: () => wr,
4396
- stringify: () => Er,
4393
+ parse: () => Er,
4394
+ parseAllDocuments: () => wr,
4395
+ parseDocument: () => Tr,
4396
+ stringify: () => Dr,
4397
4397
  visit: () => k,
4398
4398
  visitAsync: () => A
4399
- }), Or = {
4399
+ }), kr = {
4400
4400
  rawNodes: {
4401
4401
  address: {
4402
4402
  id: "address",
@@ -5981,7 +5981,7 @@ var Dr = /* @__PURE__ */ a({
5981
5981
  };
5982
5982
  //#endregion
5983
5983
  //#region server/db/dynamic-sync.ts
5984
- async function kr(e, t) {
5984
+ async function Ar(e, t) {
5985
5985
  try {
5986
5986
  let n = await e.prepare(`PRAGMA table_info("${t}")`).all(), r = Array.isArray(n) ? n : n?.results || [];
5987
5987
  return new Set(r.map((e) => e.name));
@@ -5989,7 +5989,7 @@ async function kr(e, t) {
5989
5989
  return /* @__PURE__ */ new Set();
5990
5990
  }
5991
5991
  }
5992
- var Ar = {
5992
+ var jr = {
5993
5993
  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 ",
5994
5994
  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 ",
5995
5995
  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 ",
@@ -6004,36 +6004,14 @@ var Ar = {
6004
6004
  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 ",
6005
6005
  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 ",
6006
6006
  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 "
6007
- }, jr = [
6008
- "CREATE INDEX IF NOT EXISTS idx_content_schemas_type ON content_schemas(type);",
6009
- "CREATE INDEX IF NOT EXISTS idx_sessions_user ON sessions(userId);",
6010
- "CREATE INDEX IF NOT EXISTS idx_sessions_expires ON sessions(expiresAt);",
6011
- "CREATE INDEX IF NOT EXISTS idx_channels_visibility ON channels(isHidden);",
6012
- "CREATE INDEX IF NOT EXISTS idx_trees_visibility ON trees(isHidden);",
6013
- "CREATE INDEX IF NOT EXISTS idx_content_nodes_visibility ON content_nodes(isHidden, status);",
6014
- "CREATE INDEX IF NOT EXISTS idx_content_nodes_slug ON content_nodes(slug);",
6015
- "CREATE INDEX IF NOT EXISTS idx_content_nodes_type ON content_nodes(contentType);",
6016
- "CREATE INDEX IF NOT EXISTS idx_content_nodes_deleted_updated ON content_nodes(deletedAt, updatedAt DESC);",
6017
- "CREATE INDEX IF NOT EXISTS idx_tree_nodes_hierarchy ON tree_nodes(treeId, parentId, sortOrder);",
6018
- "CREATE INDEX IF NOT EXISTS idx_tree_nodes_content ON tree_nodes(contentId, treeId);",
6019
- "CREATE INDEX IF NOT EXISTS idx_content_blocks_content ON content_blocks(contentId, isDraft, region, sortOrder);",
6020
- "CREATE INDEX IF NOT EXISTS idx_node_channels_channel ON node_channels(channelId, nodeId);",
6021
- "CREATE INDEX IF NOT EXISTS idx_node_channels_node ON node_channels(nodeId, channelId);",
6022
- "CREATE INDEX IF NOT EXISTS idx_node_assets_node_asset ON node_assets(nodeId, assetId);",
6023
- "CREATE INDEX IF NOT EXISTS idx_node_assets_asset_node ON node_assets(assetId, nodeId);",
6024
- "CREATE INDEX IF NOT EXISTS idx_node_revisions_node ON node_revisions(nodeId, version);",
6025
- "CREATE INDEX IF NOT EXISTS idx_assets_system_created ON assets(isSystemVariant, createdAt DESC);",
6026
- "CREATE INDEX IF NOT EXISTS idx_assets_system_mime ON assets(isSystemVariant, mimeType);",
6027
- "CREATE INDEX IF NOT EXISTS idx_assets_deleted ON assets(deletedAt);",
6028
- "CREATE INDEX IF NOT EXISTS idx_assets_parent ON assets(parentAssetId);"
6029
- ];
6030
- async function Mr(e, t) {
6007
+ }, Mr = /* @__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(".");
6008
+ async function Nr(e, t) {
6031
6009
  try {
6032
6010
  await e.prepare("PRAGMA foreign_keys = ON;").run();
6033
6011
  } catch {}
6034
- for (let [t, n] of Object.entries(Ar)) await e.prepare(`CREATE TABLE IF NOT EXISTS "${t}" (${n});`).run();
6035
- for (let [t] of Object.entries(Ar)) {
6036
- let n = await kr(e, t);
6012
+ for (let [t, n] of Object.entries(jr)) await e.prepare(`CREATE TABLE IF NOT EXISTS "${t}" (${n});`).run();
6013
+ for (let [t] of Object.entries(jr)) {
6014
+ let n = await Ar(e, t);
6037
6015
  if (n.size > 0) {
6038
6016
  if (t === "content_nodes" && !n.has("disabledRegionsJson")) try {
6039
6017
  await e.prepare("ALTER TABLE \"content_nodes\" ADD COLUMN disabledRegionsJson TEXT DEFAULT '{}';").run();
@@ -6048,12 +6026,12 @@ async function Mr(e, t) {
6048
6026
  }
6049
6027
  }
6050
6028
  }
6051
- for (let t of jr) try {
6029
+ for (let t of Mr) try {
6052
6030
  await e.prepare(t).run();
6053
6031
  } catch {}
6054
- await Nr(e, t || Or), await Pr(e);
6032
+ await Pr(e, t || kr), await Fr(e);
6055
6033
  }
6056
- async function Nr(e, t) {
6034
+ async function Pr(e, t) {
6057
6035
  if (!t) return;
6058
6036
  let n = t.rawNodes || {}, r = Object.entries(n);
6059
6037
  for (let [t, n] of r) {
@@ -6070,7 +6048,7 @@ async function Nr(e, t) {
6070
6048
  }
6071
6049
  }
6072
6050
  }
6073
- async function Pr(e) {
6051
+ async function Fr(e) {
6074
6052
  try {
6075
6053
  let t = await e.prepare("SELECT COUNT(*) as count FROM channels").get(), n = 1;
6076
6054
  if (!t || t.count === 0) {
@@ -6091,7 +6069,7 @@ async function Pr(e) {
6091
6069
  }
6092
6070
  //#endregion
6093
6071
  //#region server/middleware/media-static.ts
6094
- function Fr() {
6072
+ function Ir() {
6095
6073
  return async (e, t) => {
6096
6074
  if (e.env?.MEDIA_BUCKET) {
6097
6075
  let t = e.req.path.replace(/^\/media\//, ""), n = await e.env.MEDIA_BUCKET.get(t, { onlyIf: e.req.raw.headers });
@@ -6122,18 +6100,18 @@ function Fr() {
6122
6100
  }
6123
6101
  //#endregion
6124
6102
  //#region node_modules/lru-cache/dist/esm/browser/index.min.js
6125
- var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "object" && performance && typeof performance.now == "function" ? performance : Date, zr = () => q.hasSubscribers || Lr.hasSubscribers, Br = /* @__PURE__ */ new Set(), Vr = typeof process == "object" && process ? process : {}, Hr = (e, t, n, r) => {
6126
- typeof Vr.emitWarning == "function" ? Vr.emitWarning(e, t, n, r) : console.error(`[${n}] ${t}: ${e}`);
6127
- }, Ur = (e) => !Br.has(e), Wr = (e) => !!e && e === Math.floor(e) && e > 0 && isFinite(e), Gr = (e) => Wr(e) ? e <= 256 ? Uint8Array : e <= 2 ** 16 ? Uint16Array : e <= 2 ** 32 ? Uint32Array : e <= 2 ** 53 - 1 ? Kr : null : null, Kr = class extends Array {
6103
+ var Lr = { hasSubscribers: !1 }, K = Lr, Rr = Lr, zr = typeof performance == "object" && performance && typeof performance.now == "function" ? performance : Date, Br = () => K.hasSubscribers || Rr.hasSubscribers, Vr = /* @__PURE__ */ new Set(), Hr = typeof process == "object" && process ? process : {}, Ur = (e, t, n, r) => {
6104
+ typeof Hr.emitWarning == "function" ? Hr.emitWarning(e, t, n, r) : console.error(`[${n}] ${t}: ${e}`);
6105
+ }, Wr = (e) => !Vr.has(e), Gr = (e) => !!e && e === Math.floor(e) && e > 0 && isFinite(e), Kr = (e) => Gr(e) ? e <= 256 ? Uint8Array : e <= 2 ** 16 ? Uint16Array : e <= 2 ** 32 ? Uint32Array : e <= 2 ** 53 - 1 ? qr : null : null, qr = class extends Array {
6128
6106
  constructor(e) {
6129
6107
  super(e), this.fill(0);
6130
6108
  }
6131
- }, qr = class e {
6109
+ }, Jr = class e {
6132
6110
  heap;
6133
6111
  length;
6134
6112
  static #e = !1;
6135
6113
  static create(t) {
6136
- let n = Gr(t);
6114
+ let n = Kr(t);
6137
6115
  if (!n) return [];
6138
6116
  e.#e = !0;
6139
6117
  let r = new e(t, n);
@@ -6149,7 +6127,7 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6149
6127
  pop() {
6150
6128
  return this.heap[--this.length];
6151
6129
  }
6152
- }, Jr = class e {
6130
+ }, Yr = class e {
6153
6131
  #e;
6154
6132
  #t;
6155
6133
  #n;
@@ -6252,8 +6230,8 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6252
6230
  constructor(t) {
6253
6231
  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;
6254
6232
  if (this.backgroundFetchSize = w, T !== void 0 && typeof T?.now != "function") throw TypeError("perf option must have a now() method if specified");
6255
- if (this.#s = T ?? Rr, n !== 0 && !Wr(n)) throw TypeError("max option must be a nonnegative integer");
6256
- let E = n ? Gr(n) : Array;
6233
+ if (this.#s = T ?? zr, n !== 0 && !Gr(n)) throw TypeError("max option must be a nonnegative integer");
6234
+ let E = n ? Kr(n) : Array;
6257
6235
  if (!E) throw Error("invalid max value: " + n);
6258
6236
  if (this.#e = n, this.#t = m, this.maxEntrySize = h || this.#t, this.sizeCalculation = g, this.sizeCalculation) {
6259
6237
  if (!this.#t && !this.maxEntrySize) throw TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
@@ -6261,26 +6239,26 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6261
6239
  }
6262
6240
  if (v !== void 0 && typeof v != "function") throw TypeError("memoMethod must be a function if defined");
6263
6241
  if (this.#o = v, _ !== void 0 && typeof _ != "function") throw TypeError("fetchMethod must be a function if specified");
6264
- 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.#_ = qr.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) {
6265
- if (this.#t !== 0 && !Wr(this.#t)) throw TypeError("maxSize must be a positive integer if specified");
6266
- if (!Wr(this.maxEntrySize)) throw TypeError("maxEntrySize must be a positive integer if specified");
6242
+ 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.#_ = Jr.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) {
6243
+ if (this.#t !== 0 && !Gr(this.#t)) throw TypeError("maxSize must be a positive integer if specified");
6244
+ if (!Gr(this.maxEntrySize)) throw TypeError("maxEntrySize must be a positive integer if specified");
6267
6245
  this.#M();
6268
6246
  }
6269
- if (this.allowStale = !!c, this.noDeleteOnStaleGet = !!b, this.updateAgeOnGet = !!o, this.updateAgeOnHas = !!s, this.ttlResolution = Wr(i) || i === 0 ? i : 1, this.ttlAutopurge = !!a, this.ttl = r || 0, this.ttl) {
6270
- if (!Wr(this.ttl)) throw TypeError("ttl must be a positive integer if specified");
6247
+ if (this.allowStale = !!c, this.noDeleteOnStaleGet = !!b, this.updateAgeOnGet = !!o, this.updateAgeOnHas = !!s, this.ttlResolution = Gr(i) || i === 0 ? i : 1, this.ttlAutopurge = !!a, this.ttl = r || 0, this.ttl) {
6248
+ if (!Gr(this.ttl)) throw TypeError("ttl must be a positive integer if specified");
6271
6249
  this.#D();
6272
6250
  }
6273
6251
  if (this.#e === 0 && this.ttl === 0 && this.#t === 0) throw TypeError("At least one of max, maxSize, or ttl is required");
6274
6252
  if (!this.ttlAutopurge && !this.#e && !this.#t) {
6275
6253
  let t = "LRU_CACHE_UNBOUNDED";
6276
- Ur(t) && (Br.add(t), Hr("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", t, e));
6254
+ Wr(t) && (Vr.add(t), Ur("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", t, e));
6277
6255
  }
6278
6256
  }
6279
6257
  getRemainingTTL(e) {
6280
6258
  return this.#u.has(e) ? 1 / 0 : 0;
6281
6259
  }
6282
6260
  #D() {
6283
- let e = new Kr(this.#e), t = new Kr(this.#e);
6261
+ let e = new qr(this.#e), t = new qr(this.#e);
6284
6262
  this.#x = e, this.#b = t;
6285
6263
  let n = this.ttlAutopurge ? Array.from({ length: this.#e }) : void 0;
6286
6264
  this.#S = n, this.#A = (n, i, a = this.#s.now()) => {
@@ -6330,15 +6308,15 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6330
6308
  #A = () => {};
6331
6309
  #j = () => !1;
6332
6310
  #M() {
6333
- let e = new Kr(this.#e);
6311
+ let e = new qr(this.#e);
6334
6312
  this.#l = 0, this.#y = e, this.#N = (t) => {
6335
6313
  this.#l -= e[t], e[t] = 0;
6336
6314
  }, this.#F = (e, t, n, r) => {
6337
- if (!Wr(n)) {
6315
+ if (!Gr(n)) {
6338
6316
  if (this.#W(t)) return this.backgroundFetchSize;
6339
6317
  if (r) {
6340
6318
  if (typeof r != "function") throw TypeError("sizeCalculation must be a function");
6341
- if (n = r(t, e), !Wr(n)) throw TypeError("sizeCalculation return invalid (expect positive integer)");
6319
+ if (n = r(t, e), !Gr(n)) throw TypeError("sizeCalculation return invalid (expect positive integer)");
6342
6320
  } else throw TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
6343
6321
  }
6344
6322
  return n;
@@ -6454,10 +6432,10 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6454
6432
  }
6455
6433
  }
6456
6434
  set(e, t, n = {}) {
6457
- let { status: r = q.hasSubscribers ? {} : void 0 } = n;
6435
+ let { status: r = K.hasSubscribers ? {} : void 0 } = n;
6458
6436
  n.status = r, r && (r.op = "set", r.key = e, t !== void 0 && (r.value = t), r.cache = this);
6459
6437
  let i = this.#z(e, t, n);
6460
- return r && q.hasSubscribers && q.publish(r), i;
6438
+ return r && K.hasSubscribers && K.publish(r), i;
6461
6439
  }
6462
6440
  #z(e, t, n, r) {
6463
6441
  let { ttl: i = this.ttl, start: a, noDisposeOnSet: o = this.noDisposeOnSet, sizeCalculation: s = this.sizeCalculation, status: c } = n, l = this.#W(t);
@@ -6525,10 +6503,10 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6525
6503
  ])), this.#N(t), this.#S?.[t] && (clearTimeout(this.#S[t]), this.#S[t] = void 0), e && (this.#d[t] = void 0, this.#f[t] = void 0, this.#_.push(t)), this.#c === 1 ? (this.#h = this.#g = 0, this.#_.length = 0) : this.#h = this.#p[t], this.#u.delete(n), this.#c--, t;
6526
6504
  }
6527
6505
  has(e, t = {}) {
6528
- let { status: n = q.hasSubscribers ? {} : void 0 } = t;
6506
+ let { status: n = K.hasSubscribers ? {} : void 0 } = t;
6529
6507
  t.status = n, n && (n.op = "has", n.key = e, n.cache = this);
6530
6508
  let r = this.#V(e, t);
6531
- return q.hasSubscribers && q.publish(n), r;
6509
+ return K.hasSubscribers && K.publish(n), r;
6532
6510
  }
6533
6511
  #V(e, t = {}) {
6534
6512
  let { updateAgeOnHas: n = this.updateAgeOnHas, status: r } = t, i = this.#u.get(e);
@@ -6541,10 +6519,10 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6541
6519
  return !1;
6542
6520
  }
6543
6521
  peek(e, t = {}) {
6544
- let { status: n = zr() ? {} : void 0 } = t;
6522
+ let { status: n = Br() ? {} : void 0 } = t;
6545
6523
  n && (n.op = "peek", n.key = e, n.cache = this), t.status = n;
6546
6524
  let r = this.#H(e, t);
6547
- return q.hasSubscribers && q.publish(n), r;
6525
+ return K.hasSubscribers && K.publish(n), r;
6548
6526
  }
6549
6527
  #H(e, t) {
6550
6528
  let { status: n, allowStale: r = this.allowStale } = t, i = this.#u.get(e);
@@ -6596,10 +6574,10 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6596
6574
  return !!t && t instanceof Promise && t.hasOwnProperty("__staleWhileFetching") && t.__abortController instanceof AbortController;
6597
6575
  }
6598
6576
  fetch(e, t = {}) {
6599
- let n = Lr.hasSubscribers, { status: r = zr() ? {} : void 0 } = t;
6577
+ let n = Rr.hasSubscribers, { status: r = Br() ? {} : void 0 } = t;
6600
6578
  t.status = r, r && t.context && (r.context = t.context);
6601
6579
  let i = this.#G(e, t);
6602
- return r && n && (r.trace = !0, Lr.tracePromise(() => i, r).catch(() => {})), i;
6580
+ return r && n && (r.trace = !0, Rr.tracePromise(() => i, r).catch(() => {})), i;
6603
6581
  }
6604
6582
  async #G(e, t = {}) {
6605
6583
  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;
@@ -6643,10 +6621,10 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6643
6621
  }
6644
6622
  }
6645
6623
  forceFetch(e, t = {}) {
6646
- let n = Lr.hasSubscribers, { status: r = zr() ? {} : void 0 } = t;
6624
+ let n = Rr.hasSubscribers, { status: r = Br() ? {} : void 0 } = t;
6647
6625
  t.status = r, r && t.context && (r.context = t.context);
6648
6626
  let i = this.#K(e, t);
6649
- return r && n && (r.trace = !0, Lr.tracePromise(() => i, r).catch(() => {})), i;
6627
+ return r && n && (r.trace = !0, Rr.tracePromise(() => i, r).catch(() => {})), i;
6650
6628
  }
6651
6629
  async #K(e, t = {}) {
6652
6630
  let n = await this.#G(e, t);
@@ -6654,10 +6632,10 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6654
6632
  return n;
6655
6633
  }
6656
6634
  memo(e, t = {}) {
6657
- let { status: n = q.hasSubscribers ? {} : void 0 } = t;
6635
+ let { status: n = K.hasSubscribers ? {} : void 0 } = t;
6658
6636
  t.status = n, n && (n.op = "memo", n.key = e, t.context && (n.context = t.context), n.cache = this);
6659
6637
  let r = this.#q(e, t);
6660
- return n && (n.value = r), q.hasSubscribers && q.publish(n), r;
6638
+ return n && (n.value = r), K.hasSubscribers && K.publish(n), r;
6661
6639
  }
6662
6640
  #q(e, t = {}) {
6663
6641
  let n = this.#o;
@@ -6673,10 +6651,10 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6673
6651
  return i && (i.value = l), this.#z(e, l, o), l;
6674
6652
  }
6675
6653
  get(e, t = {}) {
6676
- let { status: n = q.hasSubscribers ? {} : void 0 } = t;
6654
+ let { status: n = K.hasSubscribers ? {} : void 0 } = t;
6677
6655
  t.status = n, n && (n.op = "get", n.key = e, n.cache = this);
6678
6656
  let r = this.#J(e, t);
6679
- return n && (r !== void 0 && (n.value = r), q.hasSubscribers && q.publish(n)), r;
6657
+ return n && (r !== void 0 && (n.value = r), K.hasSubscribers && K.publish(n)), r;
6680
6658
  }
6681
6659
  #J(e, t = {}) {
6682
6660
  let { allowStale: n = this.allowStale, updateAgeOnGet: r = this.updateAgeOnGet, noDeleteOnStaleGet: i = this.noDeleteOnStaleGet, status: a } = t, o = this.#u.get(e);
@@ -6697,7 +6675,7 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6697
6675
  return this.#Z(e, "delete");
6698
6676
  }
6699
6677
  #Z(e, t) {
6700
- q.hasSubscribers && q.publish({
6678
+ K.hasSubscribers && K.publish({
6701
6679
  op: "delete",
6702
6680
  delete: t,
6703
6681
  key: e,
@@ -6759,10 +6737,10 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6759
6737
  for (; t = e?.shift();) this.#i?.(...t);
6760
6738
  }
6761
6739
  }
6762
- }, Yr = class {
6740
+ }, Xr = class {
6763
6741
  cache;
6764
6742
  constructor(e = 1e3, t = 3e5) {
6765
- this.cache = new Jr({
6743
+ this.cache = new Yr({
6766
6744
  max: e,
6767
6745
  ttl: t
6768
6746
  });
@@ -6781,7 +6759,7 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6781
6759
  async clear() {
6782
6760
  this.cache.clear();
6783
6761
  }
6784
- }, Xr = class {
6762
+ }, Zr = class {
6785
6763
  kv;
6786
6764
  constructor(e) {
6787
6765
  this.kv = e;
@@ -6798,21 +6776,21 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6798
6776
  this.kv && await this.kv.delete(e);
6799
6777
  }
6800
6778
  async clear() {}
6801
- }, Zr = class {
6779
+ }, Qr = class {
6802
6780
  async get() {
6803
6781
  return null;
6804
6782
  }
6805
6783
  async set() {}
6806
6784
  async delete() {}
6807
6785
  async clear() {}
6808
- }, Qr = null;
6809
- function J(e) {
6786
+ }, $r = null;
6787
+ function q(e) {
6810
6788
  let t = process.env.CACHE_DRIVER || "lru";
6811
- return t === "none" || t === "off" || t === "false" ? new Zr() : e?.env?.CMS_CACHE_KV ? new Xr(e.env.CMS_CACHE_KV) : t === "lru" ? (Qr ||= new Yr(), Qr) : new Zr();
6789
+ return t === "none" || t === "off" || t === "false" ? new Qr() : e?.env?.CMS_CACHE_KV ? new Zr(e.env.CMS_CACHE_KV) : t === "lru" ? ($r ||= new Xr(), $r) : new Qr();
6812
6790
  }
6813
6791
  //#endregion
6814
6792
  //#region server/storage/provider.ts
6815
- function $r(e) {
6793
+ function ei(e) {
6816
6794
  let t = e.split(".").pop()?.toLowerCase() || "bin";
6817
6795
  return t = t.replace(/[^a-z0-9]/g, ""), [
6818
6796
  "php",
@@ -6827,14 +6805,14 @@ function $r(e) {
6827
6805
  "cjs"
6828
6806
  ].includes(t) ? "bin" : t;
6829
6807
  }
6830
- var ei = class {
6808
+ var ti = class {
6831
6809
  bucket;
6832
6810
  publicDomain;
6833
6811
  constructor(e, t) {
6834
6812
  this.bucket = e, this.publicDomain = t;
6835
6813
  }
6836
6814
  async upload(e, t = "uploads") {
6837
- let n = $r(e.name), r = `${t}/${crypto.randomUUID().replace(/-/g, "")}.${n}`;
6815
+ let n = ei(e.name), r = `${t}/${crypto.randomUUID().replace(/-/g, "")}.${n}`;
6838
6816
  await this.bucket.put(r, e.stream(), { httpMetadata: { contentType: e.type } });
6839
6817
  let i = r.replace(/^\//, ""), a = `/media/${i}`;
6840
6818
  if (this.publicDomain && this.publicDomain.trim().length > 0) {
@@ -6849,7 +6827,7 @@ var ei = class {
6849
6827
  async delete(e) {
6850
6828
  await this.bucket.delete(e);
6851
6829
  }
6852
- }, ti = class {
6830
+ }, ni = class {
6853
6831
  customStoragePath;
6854
6832
  constructor(e) {
6855
6833
  this.customStoragePath = e;
@@ -6867,7 +6845,7 @@ var ei = class {
6867
6845
  ), { pipeline: a } = await import(
6868
6846
  /* @vite-ignore */
6869
6847
  "node:stream/promises"
6870
- ), o = $r(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);
6848
+ ), o = ei(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);
6871
6849
  await i.mkdir(n.dirname(u), { recursive: !0 });
6872
6850
  let d = r.createWriteStream(u);
6873
6851
  return await a(e.stream(), d), {
@@ -6890,16 +6868,16 @@ var ei = class {
6890
6868
  }
6891
6869
  }
6892
6870
  };
6893
- function ni(e) {
6871
+ function ri(e) {
6894
6872
  if (e.MEDIA_BUCKET) {
6895
6873
  let t = e.CDN_DOMAIN || "cdn.yourdomain.com";
6896
- return new ei(e.MEDIA_BUCKET, t);
6874
+ return new ti(e.MEDIA_BUCKET, t);
6897
6875
  }
6898
- return new ti(e.LOCAL_MEDIA_PATH);
6876
+ return new ni(e.LOCAL_MEDIA_PATH);
6899
6877
  }
6900
6878
  //#endregion
6901
6879
  //#region server/utils/node-assets-interceptor.ts
6902
- function ri(e) {
6880
+ function ii(e) {
6903
6881
  if (!e || typeof e != "object") return {
6904
6882
  cleanedData: e,
6905
6883
  assetRefs: []
@@ -6958,7 +6936,7 @@ function ri(e) {
6958
6936
  assetRefs: t
6959
6937
  };
6960
6938
  }
6961
- async function ii(e, t, n) {
6939
+ async function ai(e, t, n) {
6962
6940
  if (await e.prepare("DELETE FROM node_assets WHERE nodeId = ?").run(t), n.length === 0) return;
6963
6941
  let r = /* @__PURE__ */ new Set();
6964
6942
  for (let i of n) {
@@ -6968,23 +6946,23 @@ async function ii(e, t, n) {
6968
6946
  }
6969
6947
  //#endregion
6970
6948
  //#region server/utils/asset-hydrator.ts
6971
- function ai(e) {
6949
+ function oi(e) {
6972
6950
  if (!e) return null;
6973
6951
  if (typeof e == "string" && e.startsWith("ast_")) return e;
6974
6952
  if (typeof e == "object" && e) {
6975
6953
  if (typeof e.id == "string" && e.id.startsWith("ast_")) return e.id;
6976
- if (typeof e.id == "object") return ai(e.id);
6954
+ if (typeof e.id == "object") return oi(e.id);
6977
6955
  }
6978
6956
  return null;
6979
6957
  }
6980
- async function oi(e, t) {
6958
+ async function si(e, t) {
6981
6959
  if (!t || typeof t != "object") return t;
6982
6960
  let n = /* @__PURE__ */ new Set(), r = (e) => {
6983
6961
  if (!e) return;
6984
- let t = ai(e);
6962
+ let t = oi(e);
6985
6963
  if (t) {
6986
6964
  if (n.add(t), typeof e == "object" && e.parentAssetId) {
6987
- let t = ai(e.parentAssetId);
6965
+ let t = oi(e.parentAssetId);
6988
6966
  t && n.add(t);
6989
6967
  }
6990
6968
  } else Array.isArray(e) ? e.forEach(r) : typeof e == "object" && Object.values(e).forEach(r);
@@ -7013,7 +6991,7 @@ async function oi(e, t) {
7013
6991
  AND (parentAssetId IN (${i}) OR ${Array.from(n).map(() => "filename LIKE ?").join(" OR ")})
7014
6992
  `).all(...Array.from(n), ...Array.from(n).map((e) => `%${e}%`)), c = Array.isArray(s) ? s : s?.results || [], l = /* @__PURE__ */ new Map();
7015
6993
  for (let e of c) {
7016
- let t = ai(e.parentAssetId) || Array.from(n).find((t) => e.filename.includes(t));
6994
+ let t = oi(e.parentAssetId) || Array.from(n).find((t) => e.filename.includes(t));
7017
6995
  if (!t) continue;
7018
6996
  let r = e.filename.match(/^crop_([a-z0-9]+)_/i), i = r ? r[1] : "standard", a = null;
7019
6997
  if (e.cropCoordinatesJson) try {
@@ -7048,7 +7026,7 @@ async function oi(e, t) {
7048
7026
  id: e.id,
7049
7027
  url: t,
7050
7028
  originalUrl: n,
7051
- parentAssetId: ai(e.parentAssetId) || null,
7029
+ parentAssetId: oi(e.parentAssetId) || null,
7052
7030
  cropCoordinates: r,
7053
7031
  variants: i && Object.keys(i).length > 0 ? i : void 0,
7054
7032
  filename: e.filename,
@@ -7060,7 +7038,7 @@ async function oi(e, t) {
7060
7038
  }
7061
7039
  let d = (e) => {
7062
7040
  if (!e) return e;
7063
- let t = ai(e);
7041
+ let t = oi(e);
7064
7042
  if (t) {
7065
7043
  let n = u.get(t) || {
7066
7044
  id: t,
@@ -7070,7 +7048,7 @@ async function oi(e, t) {
7070
7048
  return {
7071
7049
  ...n,
7072
7050
  id: t,
7073
- parentAssetId: n.parentAssetId ? ai(n.parentAssetId) : null,
7051
+ parentAssetId: n.parentAssetId ? oi(n.parentAssetId) : null,
7074
7052
  url: typeof e == "object" && e.url && !e.url.startsWith("blob:") ? e.url : n.url,
7075
7053
  originalUrl: typeof e == "object" && e.originalUrl && !e.originalUrl.startsWith("blob:") ? e.originalUrl : n.originalUrl,
7076
7054
  cropCoordinates: i || n.cropCoordinates || null,
@@ -7090,7 +7068,7 @@ async function oi(e, t) {
7090
7068
  }
7091
7069
  //#endregion
7092
7070
  //#region src/schemas/definitions.ts
7093
- function Y(e = {}, t = {}) {
7071
+ function J(e = {}, t = {}) {
7094
7072
  let n = {
7095
7073
  ...e,
7096
7074
  ...t
@@ -7108,7 +7086,7 @@ function Y(e = {}, t = {}) {
7108
7086
  ...t.rules || {}
7109
7087
  }, n;
7110
7088
  }
7111
- function si() {
7089
+ function ci() {
7112
7090
  if (typeof process > "u" || !process?.versions?.node) return null;
7113
7091
  try {
7114
7092
  let e = (e) => {
@@ -7137,7 +7115,7 @@ function si() {
7137
7115
  for (let a of e(r)) {
7138
7116
  let e = n.basename(a, n.extname(a));
7139
7117
  try {
7140
- i[e] = Dr.parse(t.readFileSync(a, "utf-8"));
7118
+ i[e] = Or.parse(t.readFileSync(a, "utf-8"));
7141
7119
  } catch (e) {
7142
7120
  console.warn(`[CMS Schema] Failed to parse ${a}:`, e);
7143
7121
  }
@@ -7147,7 +7125,7 @@ function si() {
7147
7125
  let i = e(n.dirname(r)), a = n.basename(r), o = i.find((e) => n.basename(e) === a || n.basename(e) === a.replace(/\.yaml$/, ".yml"));
7148
7126
  if (!o) return null;
7149
7127
  try {
7150
- return Dr.parse(t.readFileSync(o, "utf-8"));
7128
+ return Or.parse(t.readFileSync(o, "utf-8"));
7151
7129
  } catch {
7152
7130
  return null;
7153
7131
  }
@@ -7175,12 +7153,12 @@ function si() {
7175
7153
  return null;
7176
7154
  }
7177
7155
  }
7178
- function ci(e) {
7179
- if (e && (Object.keys(e.rawNodes || {}).length > 0 || Object.keys(e.nodes || {}).length > 0)) return li(e);
7180
- let t = si();
7181
- return t && Object.keys(t.rawNodes).length > 0 ? li(t) : li(null);
7182
- }
7183
7156
  function li(e) {
7157
+ if (e && (Object.keys(e.rawNodes || {}).length > 0 || Object.keys(e.nodes || {}).length > 0)) return ui(e);
7158
+ let t = ci();
7159
+ return t && Object.keys(t.rawNodes).length > 0 ? ui(t) : ui(null);
7160
+ }
7161
+ function ui(e) {
7184
7162
  if (!e) return {
7185
7163
  nodes: {},
7186
7164
  trees: {},
@@ -7200,7 +7178,7 @@ function li(e) {
7200
7178
  let i = {};
7201
7179
  if (!Array.isArray(e)) return typeof e == "object" && e ? (Object.entries(e).forEach(([e, t]) => {
7202
7180
  let n = i[e] || m[e] || {};
7203
- i[e] = Y(n, t);
7181
+ i[e] = J(n, t);
7204
7182
  }), i) : {};
7205
7183
  let a = (e) => {
7206
7184
  let a = h[e] || h[`${e}-base`] || {};
@@ -7213,11 +7191,11 @@ function li(e) {
7213
7191
  fields: {}
7214
7192
  }), Object.entries(s).forEach(([e, r]) => {
7215
7193
  let i = n[t].fields[e] || {};
7216
- n[t].fields[e] = Y(i, r);
7194
+ n[t].fields[e] = J(i, r);
7217
7195
  });
7218
7196
  } else Object.entries(s).forEach(([e, t]) => {
7219
7197
  let n = i[e] || {};
7220
- i[e] = Y(n, t);
7198
+ i[e] = J(n, t);
7221
7199
  });
7222
7200
  };
7223
7201
  return e.forEach((e) => {
@@ -7225,7 +7203,7 @@ function li(e) {
7225
7203
  if (e.startsWith("fieldSet:")) a(e.replace("fieldSet:", "").trim());
7226
7204
  else {
7227
7205
  let t = i[e] || m[e] || {};
7228
- i[e] = Y(t, {
7206
+ i[e] = J(t, {
7229
7207
  type: "text",
7230
7208
  label: e
7231
7209
  });
@@ -7235,7 +7213,7 @@ function li(e) {
7235
7213
  if (t === "fieldSet") a(String(n));
7236
7214
  else {
7237
7215
  let e = i[t] || m[t] || {};
7238
- i[t] = Y(e, typeof n == "object" && n ? n : {});
7216
+ i[t] = J(e, typeof n == "object" && n ? n : {});
7239
7217
  }
7240
7218
  }
7241
7219
  }), i;
@@ -7253,7 +7231,7 @@ function li(e) {
7253
7231
  let s = g(i.fields || i, a, n, t);
7254
7232
  Object.entries(s).forEach(([e, t]) => {
7255
7233
  let r = n[a].fields[e] || {};
7256
- n[a].fields[e] = Y(r, t);
7234
+ n[a].fields[e] = J(r, t);
7257
7235
  });
7258
7236
  }
7259
7237
  }), n) : (Object.entries(e).forEach(([e, r]) => {
@@ -7265,7 +7243,7 @@ function li(e) {
7265
7243
  let o = g(a, e, n, t);
7266
7244
  Object.entries(o).forEach(([t, r]) => {
7267
7245
  let i = n[e].fields[t] || {};
7268
- n[e].fields[t] = Y(i, r);
7246
+ n[e].fields[t] = J(i, r);
7269
7247
  });
7270
7248
  }), n);
7271
7249
  }, v = {};
@@ -7283,16 +7261,16 @@ function li(e) {
7283
7261
  fields: {}
7284
7262
  }), Object.entries(o).forEach(([e, r]) => {
7285
7263
  let i = n[t].fields[e] || {};
7286
- n[t].fields[e] = Y(i, r);
7264
+ n[t].fields[e] = J(i, r);
7287
7265
  });
7288
7266
  } else Object.entries(o).forEach(([e, t]) => {
7289
7267
  let n = r[e] || m[e] || {};
7290
- r[e] = Y(n, t);
7268
+ r[e] = J(n, t);
7291
7269
  });
7292
7270
  }), Object.values(n).forEach((e) => {
7293
7271
  Object.entries(e.fields).forEach(([e, t]) => {
7294
7272
  let n = r[e] || {};
7295
- r[e] = Y(n, t);
7273
+ r[e] = J(n, t);
7296
7274
  });
7297
7275
  }), Object.keys(n).length === 0 && Object.keys(r).length > 0 && (n.settings = {
7298
7276
  label: t.label || "Settings",
@@ -7315,11 +7293,11 @@ function li(e) {
7315
7293
  Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
7316
7294
  let t = h[e] || {}, i = t.fields || t, a = g(i, "settings", n);
7317
7295
  Object.entries(a).forEach(([e, t]) => {
7318
- r[e] = Y(r[e] || {}, t);
7296
+ r[e] = J(r[e] || {}, t);
7319
7297
  });
7320
7298
  }), Object.values(n).forEach((e) => {
7321
7299
  Object.entries(e.fields).forEach(([e, t]) => {
7322
- r[e] = Y(r[e] || {}, t);
7300
+ r[e] = J(r[e] || {}, t);
7323
7301
  });
7324
7302
  }), y[e] = {
7325
7303
  ...t,
@@ -7338,7 +7316,7 @@ function li(e) {
7338
7316
  Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
7339
7317
  let t = h[e] || {}, r = t.fields || t, i = g(r);
7340
7318
  Object.entries(i).forEach(([e, t]) => {
7341
- n[e] = Y(n[e] || {}, t);
7319
+ n[e] = J(n[e] || {}, t);
7342
7320
  });
7343
7321
  }), b[e] = {
7344
7322
  ...t,
@@ -7387,7 +7365,7 @@ function li(e) {
7387
7365
  Array.isArray(f?.fieldSets) && f?.fieldSets.forEach((e) => {
7388
7366
  let t = h[e] || {}, n = t.fields || t, r = g(n);
7389
7367
  Object.entries(r).forEach(([e, t]) => {
7390
- T[e] = Y(T[e] || {}, t);
7368
+ T[e] = J(T[e] || {}, t);
7391
7369
  });
7392
7370
  });
7393
7371
  let E = f ? {
@@ -7397,7 +7375,7 @@ function li(e) {
7397
7375
  Array.isArray(p?.fieldSets) && p?.fieldSets.forEach((e) => {
7398
7376
  let t = h[e] || {}, n = t.fields || t, r = g(n);
7399
7377
  Object.entries(r).forEach(([e, t]) => {
7400
- D[e] = Y(D[e] || {}, t);
7378
+ D[e] = J(D[e] || {}, t);
7401
7379
  });
7402
7380
  });
7403
7381
  let ee = p ? {
@@ -7419,7 +7397,7 @@ function li(e) {
7419
7397
  }
7420
7398
  //#endregion
7421
7399
  //#region server/services/cache-manager.ts
7422
- var X = class {
7400
+ var Y = class {
7423
7401
  zoneId;
7424
7402
  apiToken;
7425
7403
  frontendUrl;
@@ -7428,10 +7406,6 @@ var X = class {
7428
7406
  this.env = e, this.zoneId = e.CLOUDFLARE_ZONE_ID, this.apiToken = e.CLOUDFLARE_API_TOKEN, this.frontendUrl = (e.PUBLIC_FRONTEND_URL || "https://kama.t3cloud.eu").replace(/\/+$/, "");
7429
7407
  }
7430
7408
  dispatch(e, t) {
7431
- if (!this.zoneId || !this.apiToken) {
7432
- console.warn("[CacheManager] Missing ZONE_ID or API_TOKEN. Purge aborted.");
7433
- return;
7434
- }
7435
7409
  e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(t) : t.catch((e) => console.warn("[CacheManager Warn]:", e));
7436
7410
  }
7437
7411
  async callAstroPurge(e, t) {
@@ -7451,7 +7425,7 @@ var X = class {
7451
7425
  }
7452
7426
  async purgeInternalWorkerCache(e, t, n, r, i = "en") {
7453
7427
  try {
7454
- let a = J(e);
7428
+ let a = q(e);
7455
7429
  if (n) {
7456
7430
  let e = await t.prepare("SELECT treeId FROM tree_nodes WHERE contentId = ?").all(n), r = Array.isArray(e) ? e : e?.results || [];
7457
7431
  for (let e of r) await a.delete(`tree:default:${e.treeId}`), await a.delete(`tree:all:${e.treeId}`);
@@ -7505,25 +7479,29 @@ var X = class {
7505
7479
  }
7506
7480
  async purgeGlobalCacheDirect(e, t) {
7507
7481
  try {
7508
- console.log("[CacheManager] Executing Direct Global Version Purge..."), await fetch(`https://api.cloudflare.com/client/v4/zones/${this.zoneId}/purge_cache`, {
7509
- method: "POST",
7510
- headers: {
7511
- Authorization: `Bearer ${this.apiToken}`,
7512
- "Content-Type": "application/json"
7513
- },
7514
- body: JSON.stringify({ purge_everything: !0 })
7515
- });
7482
+ console.log("[CacheManager] Executing Direct Global Version Purge...");
7516
7483
  let n = await this.callAstroPurge(e, { purge_everything: !0 });
7517
7484
  if (!n.ok) {
7518
7485
  let e = await n.text();
7519
7486
  console.error(`❌ [CacheManager] Astro Global Purge FAILED (${n.status}): ${e}`);
7520
- } else if (console.log("✅ [CacheManager] Dual Global Version Purge SUCCESS"), t) {
7521
- let n = this.warmAllPublishedPages(t);
7522
- e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(n) : await n;
7523
- } else {
7524
- let e = this.frontendUrl.replace(/\/+$/, "");
7525
- fetch(`${e}/?_warmer=${Date.now()}`, { headers: { "X-Cache-Warmer": "true" } }).catch(() => {});
7487
+ return;
7526
7488
  }
7489
+ console.log("✅ [CacheManager] Astro Global Version Tag Updated");
7490
+ let r = (async () => {
7491
+ if (this.zoneId && this.apiToken && fetch(`https://api.cloudflare.com/client/v4/zones/${this.zoneId}/purge_cache`, {
7492
+ method: "POST",
7493
+ headers: {
7494
+ Authorization: `Bearer ${this.apiToken}`,
7495
+ "Content-Type": "application/json"
7496
+ },
7497
+ body: JSON.stringify({ purge_everything: !0 })
7498
+ }).catch((e) => console.warn("⚠️ Zone purge warning:", e)), await new Promise((e) => setTimeout(e, 100)), t) await this.warmAllPublishedPages(t);
7499
+ else {
7500
+ let e = this.frontendUrl.replace(/\/+$/, "");
7501
+ fetch(`${e}/?_warmer=${Date.now()}`, { headers: { "X-Cache-Warmer": "true" } }).catch(() => {});
7502
+ }
7503
+ })();
7504
+ this.dispatch(e, r);
7527
7505
  } catch (e) {
7528
7506
  console.error("❌ [CacheManager] Direct Global Purge CRASH:", e);
7529
7507
  }
@@ -7542,33 +7520,35 @@ var X = class {
7542
7520
  let t = e.startsWith("/") ? e : `/${e}`;
7543
7521
  a.push(`${this.frontendUrl}${t}`);
7544
7522
  }
7545
- console.log(`[CacheManager] Executing Version Invalidation for ${a.length} URLs...`), await fetch(`https://api.cloudflare.com/client/v4/zones/${this.zoneId}/purge_cache`, {
7546
- method: "POST",
7547
- headers: {
7548
- Authorization: `Bearer ${this.apiToken}`,
7549
- "Content-Type": "application/json"
7550
- },
7551
- body: JSON.stringify({ files: a })
7552
- });
7523
+ console.log(`[CacheManager] Executing Version Invalidation for ${a.length} URLs...`);
7553
7524
  let o = await this.callAstroPurge(e, { urls: a });
7554
- if (o.ok) {
7555
- console.log("✅ [CacheManager] Dual Slug Invalidation SUCCESS");
7556
- let t = fetch(`${i}?_warmer=${Date.now()}`, { headers: { "X-Cache-Warmer": "true" } }).then((e) => {
7525
+ if (!o.ok) {
7526
+ let e = await o.text();
7527
+ console.error(`❌ [CacheManager] Astro Slug Invalidation FAILED (${o.status}): ${e}`);
7528
+ return;
7529
+ }
7530
+ console.log("✅ [CacheManager] Dual Slug Invalidation SUCCESS");
7531
+ let s = (async () => {
7532
+ this.zoneId && this.apiToken && fetch(`https://api.cloudflare.com/client/v4/zones/${this.zoneId}/purge_cache`, {
7533
+ method: "POST",
7534
+ headers: {
7535
+ Authorization: `Bearer ${this.apiToken}`,
7536
+ "Content-Type": "application/json"
7537
+ },
7538
+ body: JSON.stringify({ files: a })
7539
+ }).catch((e) => console.warn("⚠️ Zone files purge warning:", e)), await new Promise((e) => setTimeout(e, 100)), await fetch(`${i}?_warmer=${Date.now()}`, { headers: { "X-Cache-Warmer": "true" } }).then((e) => {
7557
7540
  console.log(`🔥 [CacheWarmer] Warm state for ${i}: ${e.status}`);
7558
7541
  }).catch((e) => {
7559
7542
  console.warn(`⚠️ [CacheWarmer] Failed to warm ${i}:`, e);
7560
7543
  });
7561
- e.executionCtx && typeof e.executionCtx.waitUntil == "function" && e.executionCtx.waitUntil(t);
7562
- } else {
7563
- let e = await o.text();
7564
- console.error(`❌ [CacheManager] Astro Slug Invalidation FAILED (${o.status}): ${e}`);
7565
- }
7544
+ })();
7545
+ this.dispatch(e, s);
7566
7546
  } catch (e) {
7567
7547
  console.error("❌ [CacheManager] Dual Slug Purge CRASH:", e);
7568
7548
  }
7569
7549
  }
7570
- }, Z = new e();
7571
- async function ui(e, t, n = []) {
7550
+ }, X = new e();
7551
+ async function di(e, t, n = []) {
7572
7552
  let r = e.prepare(t);
7573
7553
  if (typeof r.bind == "function") {
7574
7554
  let e = await r.bind(...n).all();
@@ -7580,37 +7560,37 @@ async function ui(e, t, n = []) {
7580
7560
  }
7581
7561
  return [];
7582
7562
  }
7583
- async function di(e, t, n = []) {
7563
+ async function fi(e, t, n = []) {
7584
7564
  let r = e.prepare(t);
7585
7565
  if (typeof r.bind == "function") return r.bind(...n).run();
7586
7566
  if (typeof r.run == "function") return r.run(...n);
7587
7567
  }
7588
- async function fi(e, t) {
7568
+ async function pi(e, t) {
7589
7569
  try {
7590
- return (await ui(e, "\n SELECT DISTINCT a.url\n FROM node_assets na\n JOIN assets a ON na.assetId = a.id\n WHERE na.nodeId = ? AND a.url IS NOT NULL AND a.url != ''\n ", [t])).map((e) => e.url).filter(Boolean);
7570
+ return (await di(e, "\n SELECT DISTINCT a.url\n FROM node_assets na\n JOIN assets a ON na.assetId = a.id\n WHERE na.nodeId = ? AND a.url IS NOT NULL AND a.url != ''\n ", [t])).map((e) => e.url).filter(Boolean);
7591
7571
  } catch {
7592
7572
  return [];
7593
7573
  }
7594
7574
  }
7595
- async function pi(e, t) {
7575
+ async function mi(e, t) {
7596
7576
  try {
7597
- return (await ui(e, "\n WITH RECURSIVE tree_path(treeNodeId, contentId, parentId) AS (\n SELECT id, contentId, parentId \n FROM tree_nodes \n WHERE contentId = ?\n UNION ALL\n SELECT tn.id, tn.contentId, tn.parentId\n FROM tree_nodes tn\n INNER JOIN tree_path tp ON tn.parentId = tp.treeNodeId\n )\n SELECT DISTINCT cn.slug\n FROM tree_path tp\n INNER JOIN content_nodes cn ON tp.contentId = cn.id\n WHERE cn.status = 'published' AND cn.slug IS NOT NULL AND cn.id != ?\n ", [t, t])).map((e) => e.slug).filter(Boolean);
7577
+ return (await di(e, "\n WITH RECURSIVE tree_path(treeNodeId, contentId, parentId) AS (\n SELECT id, contentId, parentId \n FROM tree_nodes \n WHERE contentId = ?\n UNION ALL\n SELECT tn.id, tn.contentId, tn.parentId\n FROM tree_nodes tn\n INNER JOIN tree_path tp ON tn.parentId = tp.treeNodeId\n )\n SELECT DISTINCT cn.slug\n FROM tree_path tp\n INNER JOIN content_nodes cn ON tp.contentId = cn.id\n WHERE cn.status = 'published' AND cn.slug IS NOT NULL AND cn.id != ?\n ", [t, t])).map((e) => e.slug).filter(Boolean);
7598
7578
  } catch (e) {
7599
7579
  return console.warn("[Cache] Failed to fetch descendant slugs:", e), [];
7600
7580
  }
7601
7581
  }
7602
- function mi(e) {
7582
+ function hi(e) {
7603
7583
  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;
7604
7584
  }
7605
- function hi(e) {
7585
+ function gi(e) {
7606
7586
  return +(e === !0 || e === 1 || e === "1" || e === "true");
7607
7587
  }
7608
- function gi(e) {
7588
+ function _i(e) {
7609
7589
  if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
7610
7590
  let t = Number(e);
7611
7591
  return isNaN(t) ? null : t;
7612
7592
  }
7613
- function _i(e) {
7593
+ function vi(e) {
7614
7594
  let t = { ...e };
7615
7595
  for (let e of [
7616
7596
  "id",
@@ -7639,17 +7619,17 @@ function _i(e) {
7639
7619
  ]) delete t[e];
7640
7620
  return t;
7641
7621
  }
7642
- function vi(e, t = /* @__PURE__ */ new Set()) {
7643
- return e ? typeof e == "string" ? (e.startsWith("ast_") && t.add(e), t) : Array.isArray(e) ? (e.forEach((e) => vi(e, t)), t) : (typeof e == "object" && Object.values(e).forEach((e) => vi(e, t)), t) : t;
7622
+ function yi(e, t = /* @__PURE__ */ new Set()) {
7623
+ return e ? typeof e == "string" ? (e.startsWith("ast_") && t.add(e), t) : Array.isArray(e) ? (e.forEach((e) => yi(e, t)), t) : (typeof e == "object" && Object.values(e).forEach((e) => yi(e, t)), t) : t;
7644
7624
  }
7645
- async function yi(e, t, n) {
7625
+ async function bi(e, t, n) {
7646
7626
  for (let r of n) {
7647
- let n = (await ui(e, "\n SELECT id, storageKeyPrivate, isSystemVariant, parentAssetId, filename\n FROM assets WHERE id = ?\n ", [r]))[0];
7648
- if (!n || (await ui(e, "SELECT 1 FROM node_assets WHERE assetId = ? LIMIT 1", [n.id])).length > 0) continue;
7627
+ let n = (await di(e, "\n SELECT id, storageKeyPrivate, isSystemVariant, parentAssetId, filename\n FROM assets WHERE id = ?\n ", [r]))[0];
7628
+ if (!n || (await di(e, "SELECT 1 FROM node_assets WHERE assetId = ? LIMIT 1", [n.id])).length > 0) continue;
7649
7629
  let i = [n];
7650
7630
  if (!n.isSystemVariant) {
7651
- let t = await ui(e, "\n SELECT id, storageKeyPrivate, isSystemVariant, parentAssetId, filename\n FROM assets\n WHERE parentAssetId = ? OR (isSystemVariant = 1 AND filename LIKE ?)\n ", [n.id, `crop_%${String(n.filename || "").replace(/\.[^/.]+$/, "")}%`]), r = t.map((e) => e.id);
7652
- if (r.length > 0 && (await ui(e, `SELECT DISTINCT assetId FROM node_assets WHERE assetId IN (${r.map(() => "?").join(",")})`, r)).length > 0) continue;
7631
+ let t = await di(e, "\n SELECT id, storageKeyPrivate, isSystemVariant, parentAssetId, filename\n FROM assets\n WHERE parentAssetId = ? OR (isSystemVariant = 1 AND filename LIKE ?)\n ", [n.id, `crop_%${String(n.filename || "").replace(/\.[^/.]+$/, "")}%`]), r = t.map((e) => e.id);
7632
+ if (r.length > 0 && (await di(e, `SELECT DISTINCT assetId FROM node_assets WHERE assetId IN (${r.map(() => "?").join(",")})`, r)).length > 0) continue;
7653
7633
  i = [n, ...t];
7654
7634
  }
7655
7635
  for (let e of i) if (e.storageKeyPrivate) try {
@@ -7658,10 +7638,10 @@ async function yi(e, t, n) {
7658
7638
  console.warn(`[Asset Cleanup] Failed to delete ${e.storageKeyPrivate}:`, t);
7659
7639
  }
7660
7640
  let a = i.map((e) => e.id), o = a.map(() => "?").join(",");
7661
- await di(e, `DELETE FROM node_assets WHERE assetId IN (${o})`, a), await di(e, `DELETE FROM assets WHERE id IN (${o})`, a);
7641
+ await fi(e, `DELETE FROM node_assets WHERE assetId IN (${o})`, a), await fi(e, `DELETE FROM assets WHERE id IN (${o})`, a);
7662
7642
  }
7663
7643
  }
7664
- async function bi(e, t, n) {
7644
+ async function xi(e, t, n) {
7665
7645
  let r = {}, i = null;
7666
7646
  if (t) {
7667
7647
  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\n FROM tree_nodes t\n INNER JOIN content_nodes c ON t.contentId = c.id\n WHERE t.id = ?\n UNION ALL\n SELECT t.id, t.parentId, c.draftDataJson, c.dataJson, ap.level + 1\n FROM tree_nodes t\n INNER JOIN content_nodes c ON t.contentId = c.id\n INNER JOIN ancestor_path ap ON t.id = ap.parentId\n )\n SELECT draftDataJson, dataJson FROM ancestor_path ORDER BY level ASC\n ").all(t), a = Array.isArray(n) ? n : n?.results || [];
@@ -7686,7 +7666,7 @@ async function bi(e, t, n) {
7686
7666
  inheritedFields: r
7687
7667
  };
7688
7668
  }
7689
- Z.get("/", async (e) => {
7669
+ X.get("/", async (e) => {
7690
7670
  let t = e.get("db"), n = e.req.query("id"), r = e.req.query("type"), i = e.req.query("q") || e.req.query("search"), a = e.req.query("channelId"), o = e.req.query("trashed") === "true", s = e.req.query("assetId"), c = e.req.query("sort") || "updatedAt", l = (e.req.query("order") || "DESC").toUpperCase() === "ASC" ? "ASC" : "DESC", u = e.req.query("limit"), d = e.req.query("offset"), f = Math.max(1, Math.min(100, parseInt(u || "50", 10))), p = Math.max(0, parseInt(d || "0", 10));
7691
7671
  if (n) {
7692
7672
  let r = Number(n);
@@ -7711,13 +7691,13 @@ Z.get("/", async (e) => {
7711
7691
  updatedAt: i.updatedAt
7712
7692
  }, s = i.draftDataJson || i.dataJson;
7713
7693
  if (s) try {
7714
- 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 = li(e.env?.BUNDLED_DEFINITIONS).nodes?.[i.contentType] || {}, l = n.layoutId || null;
7694
+ 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 = ui(e.env?.BUNDLED_DEFINITIONS).nodes?.[i.contentType] || {}, l = n.layoutId || null;
7715
7695
  if (a) {
7716
- let { resolvedLayoutId: e, inheritedFields: r } = await bi(t, a.parentId, a.treeId);
7696
+ let { resolvedLayoutId: e, inheritedFields: r } = await xi(t, a.parentId, a.treeId);
7717
7697
  (l === "inherit" || !l) && (l = e || c.defaultLayout || null);
7718
7698
  for (let [e, t] of Object.entries(r)) (n[e] === void 0 || n[e] === null || n[e] === "") && t !== void 0 && (n[e] = t);
7719
7699
  } else (l === "inherit" || !l) && (l = c.defaultLayout || null);
7720
- let u = await oi(t, _i(n));
7700
+ let u = await si(t, vi(n));
7721
7701
  Object.assign(o, u), o.resolvedLayoutId = l;
7722
7702
  } catch {}
7723
7703
  let c = await t.prepare("SELECT channelId FROM node_channels WHERE nodeId = ?").all(r);
@@ -7727,7 +7707,7 @@ Z.get("/", async (e) => {
7727
7707
  let u = await t.prepare("\n SELECT * FROM content_blocks \n WHERE contentId = ? AND isDraft = 1 \n ORDER BY sortOrder ASC\n ").all(r), d = Array.isArray(u) ? u : u?.results || [], f = await Promise.all(d.map(async (e) => {
7728
7708
  let n = {};
7729
7709
  try {
7730
- n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {}, n && typeof n == "object" && (n = await oi(t, n));
7710
+ n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {}, n && typeof n == "object" && (n = await si(t, n));
7731
7711
  } catch {
7732
7712
  n = {};
7733
7713
  }
@@ -7827,7 +7807,7 @@ Z.get("/", async (e) => {
7827
7807
  assetCount: e.assetCount || 0
7828
7808
  }, i = e.draftDataJson || e.dataJson;
7829
7809
  if (i) try {
7830
- let e = typeof i == "string" ? JSON.parse(i) : i, n = await oi(t, _i(e));
7810
+ let e = typeof i == "string" ? JSON.parse(i) : i, n = await si(t, vi(e));
7831
7811
  Object.assign(r, n);
7832
7812
  } catch {}
7833
7813
  return r;
@@ -7839,107 +7819,88 @@ Z.get("/", async (e) => {
7839
7819
  offset: p,
7840
7820
  limit: f
7841
7821
  });
7842
- }), Z.post("/", async (e) => {
7843
- 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, ..._ } = r, v = _i(_), { cleanedData: y, assetRefs: b } = ri(v), x = hi(d === void 0 ? f === void 0 ? p : f : d), S = c || "en", C = l || u || "page", w = e.get("user")?.id || null, T = a, E = /* @__PURE__ */ new Set();
7822
+ }), X.post("/", async (e) => {
7823
+ 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, ..._ } = r, { cleanedData: v, assetRefs: y } = ii(vi(_)), b = gi(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 = /* @__PURE__ */ new Set();
7844
7824
  if (a) {
7845
- let n = await t.prepare("SELECT title, slug, language, contentType, draftDataJson, dataJson, publishedAt, status FROM content_nodes WHERE id = ?").get(a), r = n?.draftDataJson || n?.dataJson || "{}";
7825
+ let e = await t.prepare("SELECT title, slug, language, contentType, draftDataJson, dataJson, publishedAt, status FROM content_nodes WHERE id = ?").get(a), n = e?.draftDataJson || e?.dataJson || "{}";
7846
7826
  try {
7847
- vi(typeof r == "string" ? JSON.parse(r) : r, E);
7827
+ yi(typeof n == "string" ? JSON.parse(n) : n, T);
7848
7828
  } catch {}
7849
7829
  if (m !== void 0) {
7850
7830
  let e = await t.prepare("SELECT dataJson FROM content_blocks WHERE contentId = ? AND isDraft = 1").all(a);
7851
7831
  (Array.isArray(e) ? e : e?.results || []).forEach((e) => {
7852
7832
  try {
7853
- vi(typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson, E);
7833
+ yi(typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson, T);
7854
7834
  } catch {}
7855
7835
  });
7856
7836
  }
7857
- if (m === void 0 && o === void 0 && s === void 0 && h === void 0 && g === void 0 && Object.keys(v).length === 0) {
7858
- await t.prepare("\n UPDATE content_nodes \n SET isHidden = ?, \n updatedById = ?, \n updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ").run(x, w, a), await J(e).clear();
7859
- let r = new X(e.env);
7860
- if (await r.purgeInternalWorkerCache(e, t, a, n?.slug || "", n?.language || "en"), n?.status === "published") {
7861
- let i = await fi(t, a);
7862
- r.purgeSmart(e, t, a, n.slug, i, !0);
7863
- }
7864
- return e.json({
7865
- success: !0,
7866
- id: a,
7867
- status: n?.status || "published"
7868
- });
7869
- }
7870
- {
7871
- let e = o === void 0 ? n?.title || "Untitled" : o, r = s === void 0 ? n?.slug ?? null : mi(s), i = C || n?.contentType || "page", c = S || n?.language || "en", l = n?.draftDataJson || n?.dataJson || "{}", u = {};
7872
- try {
7873
- u = JSON.parse(l);
7874
- } catch {}
7875
- let d = JSON.stringify({
7876
- ...u,
7877
- ...y
7878
- });
7879
- await t.prepare("\n UPDATE content_nodes \n SET title = ?, \n slug = ?, \n language = ?,\n contentType = ?, \n isHidden = ?, \n status = 'draft', \n draftDataJson = ?, \n updatedById = ?, \n updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ").run(e, r, c, i, x, d, w, a);
7880
- }
7837
+ let r = o === void 0 ? e?.title || "Untitled" : o, i = s === void 0 ? e?.slug ?? null : hi(s), c = S || e?.contentType || "page", l = x || e?.language || "en", u = e?.draftDataJson || e?.dataJson || "{}", d = {};
7838
+ try {
7839
+ d = JSON.parse(u);
7840
+ } catch {}
7841
+ let f = JSON.stringify({
7842
+ ...d,
7843
+ ...v
7844
+ });
7845
+ await t.prepare("\n UPDATE content_nodes \n SET title = ?, \n slug = ?, \n language = ?,\n contentType = ?, \n isHidden = ?, \n status = 'draft', \n draftDataJson = ?, \n updatedById = ?, \n updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ").run(r, i, l, c, b, f, C, a);
7881
7846
  } else {
7882
- let e = o || "Untitled", n = mi(s), r = JSON.stringify(y), i = await t.prepare("\n INSERT INTO content_nodes (contentType, title, slug, language, isHidden, status, draftDataJson, dataJson, createdById, updatedById)\n VALUES (?, ?, ?, ?, ?, 'draft', ?, NULL, ?, ?)\n ").run(C, e, n, S, x, r, w, w);
7883
- T = Number(i.lastInsertRowid);
7847
+ let e = o || "Untitled", n = hi(s), r = JSON.stringify(v), i = await t.prepare("\n INSERT INTO content_nodes (contentType, title, slug, language, isHidden, status, draftDataJson, dataJson, createdById, updatedById)\n VALUES (?, ?, ?, ?, ?, 'draft', ?, NULL, ?, ?)\n ").run(S, e, n, x, b, r, C, C);
7848
+ w = Number(i.lastInsertRowid);
7884
7849
  }
7885
- if (h !== void 0 && Array.isArray(h) && T) {
7886
- await t.prepare("DELETE FROM node_channels WHERE nodeId = ?").run(T);
7850
+ if (h !== void 0 && Array.isArray(h) && w) {
7851
+ await t.prepare("DELETE FROM node_channels WHERE nodeId = ?").run(w);
7887
7852
  let e = h.map((e) => typeof e == "object" && e ? e.id || e.channelId : e), n = [...new Set(e)].filter((e) => e && e !== "all").map((e) => Number(e) || e);
7888
7853
  if (n.length > 0) {
7889
- let e = n.map(() => "(?, ?)").join(", "), r = n.flatMap((e) => [T, e]);
7854
+ let e = n.map(() => "(?, ?)").join(", "), r = n.flatMap((e) => [w, e]);
7890
7855
  await t.prepare(`INSERT OR IGNORE INTO node_channels (nodeId, channelId) VALUES ${e}`).run(...r);
7891
7856
  }
7892
7857
  }
7893
- if (g !== void 0 && Array.isArray(g) && T) {
7894
- await t.prepare("DELETE FROM tree_nodes WHERE contentId = ?").run(T);
7858
+ if (g !== void 0 && Array.isArray(g) && w) {
7859
+ await t.prepare("DELETE FROM tree_nodes WHERE contentId = ?").run(w);
7895
7860
  let e = /* @__PURE__ */ new Set(), n = [], r = [];
7896
7861
  for (let t of g) if (t && t.treeId) {
7897
7862
  let i = Number(t.treeId) || t.treeId;
7898
7863
  if (!e.has(i)) {
7899
7864
  e.add(i);
7900
- let a = gi(t.parentId ?? t._draftParentId ?? null), o = typeof t.sortOrder == "number" ? t.sortOrder : 0;
7901
- n.push("(?, ?, ?, ?)"), r.push(i, T, a, o);
7865
+ let a = _i(t.parentId ?? t._draftParentId ?? null), o = typeof t.sortOrder == "number" ? t.sortOrder : 0;
7866
+ n.push("(?, ?, ?, ?)"), r.push(i, w, a, o);
7902
7867
  }
7903
7868
  }
7904
7869
  n.length > 0 && await t.prepare(`INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder) VALUES ${n.join(", ")}`).run(...r);
7905
7870
  }
7906
- let D = [];
7907
- if (m !== void 0 && Array.isArray(m) && T) {
7908
- await t.prepare("DELETE FROM content_blocks WHERE contentId = ? AND isDraft = 1").run(T);
7871
+ let E = [];
7872
+ if (m !== void 0 && Array.isArray(m) && w) {
7873
+ await t.prepare("DELETE FROM content_blocks WHERE contentId = ? AND isDraft = 1").run(w);
7909
7874
  let e = [], n = [];
7910
7875
  for (let t = 0; t < m.length; t++) {
7911
- let r = m[t], i = r.componentId || r.elementType || "text-block", a = r.data || {}, o = String(r.blockId || a.blockId || r.instanceId || r.id || `block-${Date.now()}`), { cleanedData: s, assetRefs: c } = ri({
7876
+ let r = m[t], i = r.componentId || r.elementType || "text-block", a = r.data || {}, o = String(r.blockId || a.blockId || r.instanceId || r.id || `block-${Date.now()}`), { cleanedData: s, assetRefs: c } = ii({
7912
7877
  ...a,
7913
7878
  blockId: o,
7914
7879
  _instanceId: o
7915
7880
  });
7916
7881
  c.forEach((e) => {
7917
- D.push({
7882
+ E.push({
7918
7883
  ...e,
7919
7884
  fieldKey: `blocks[${t}].${e.fieldKey}`
7920
7885
  });
7921
7886
  });
7922
7887
  let l = r.region !== void 0 && r.region !== null && String(r.region).trim() !== "" ? String(r.region) : "content";
7923
- e.push("(?, ?, ?, ?, ?, 1)"), n.push(T, t, i, JSON.stringify(s), l);
7888
+ e.push("(?, ?, ?, ?, ?, 1)"), n.push(w, t, i, JSON.stringify(s), l);
7924
7889
  }
7925
7890
  e.length > 0 && await t.prepare(`INSERT INTO content_blocks (contentId, sortOrder, elementType, dataJson, region, isDraft) VALUES ${e.join(", ")}`).run(...n);
7926
7891
  }
7927
- if (T) {
7928
- let n = [...b, ...D];
7929
- await ii(t, T, n);
7930
- let r = new Set(n.map((e) => e.assetId)), i = new Set([...E].filter((e) => !r.has(e)));
7931
- i.size > 0 && await yi(t, ni(e.env), i);
7932
- }
7933
- if (await J(e).clear(), T) {
7934
- let n = new X(e.env), r = o === void 0 ? s : mi(s);
7935
- await n.purgeInternalWorkerCache(e, t, T, r || "", S);
7892
+ if (w) {
7893
+ let n = [...y, ...E];
7894
+ await ai(t, w, n);
7895
+ let r = new Set(n.map((e) => e.assetId)), i = new Set([...T].filter((e) => !r.has(e)));
7896
+ i.size > 0 && await bi(t, ri(e.env), i);
7936
7897
  }
7937
- return e.json({
7898
+ return await q(e).clear(), e.json({
7938
7899
  success: !0,
7939
- id: T,
7900
+ id: w,
7940
7901
  status: "draft"
7941
7902
  });
7942
- }), Z.post("/publish", async (e) => {
7903
+ }), X.post("/publish", async (e) => {
7943
7904
  let t = e.get("db"), n = await e.req.json(), r = n.id || n.nodeId;
7944
7905
  if (!r || isNaN(Number(r))) return e.json({ error: "Node ID required for publishing" }, 400);
7945
7906
  let i = Number(r), a = e.get("user")?.id || null, o = await t.prepare("SELECT * FROM content_nodes WHERE id = ?").get(i);
@@ -7952,7 +7913,7 @@ Z.get("/", async (e) => {
7952
7913
  try {
7953
7914
  c = typeof o.draftDataJson == "string" ? JSON.parse(o.draftDataJson) : o.draftDataJson || {};
7954
7915
  } catch {}
7955
- let l = s.title || o.title, u = c.title || n.title || o.title, d = s.slug || o.slug, f = c.slug || n.slug || o.slug, p = !!(l && u && l !== u) || !!(d && f && d !== f), m = o.draftDataJson || o.dataJson || "{}";
7916
+ let l = (s.title ?? o.title ?? "").trim(), u = (c.title ?? n.title ?? o.title ?? "").trim(), d = (s.slug ?? o.slug ?? "").trim(), f = (c.slug ?? n.slug ?? o.slug ?? "").trim(), p = l !== "" && u !== "" && l !== u || d !== "" && f !== "" && d !== f, m = o.draftDataJson || o.dataJson || "{}";
7956
7917
  await t.prepare("\n UPDATE content_nodes\n SET publishedDataJson = ?,\n dataJson = ?,\n publishedAt = CURRENT_TIMESTAMP,\n status = 'published',\n updatedById = ?,\n updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ").run(m, m, a, i), await t.prepare("DELETE FROM content_blocks WHERE contentId = ? AND isDraft = 0").run(i);
7957
7918
  let h = await t.prepare("SELECT * FROM content_blocks WHERE contentId = ? AND isDraft = 1 ORDER BY sortOrder ASC").all(i), g = Array.isArray(h) ? h : h?.results || [];
7958
7919
  if (g.length > 0) {
@@ -7972,12 +7933,11 @@ Z.get("/", async (e) => {
7972
7933
  },
7973
7934
  blocks: g
7974
7935
  };
7975
- await t.prepare("\n INSERT INTO node_revisions (nodeId, version, snapshotJson, createdById)\n VALUES (?, ?, ?, ?)\n ").run(i, _, v.publishedAt, a), await J(e).clear();
7976
- let y = new X(e.env);
7936
+ await t.prepare("\n INSERT INTO node_revisions (nodeId, version, snapshotJson, createdById)\n VALUES (?, ?, ?, ?)\n ").run(i, _, v.publishedAt, a), await q(e).clear();
7937
+ let y = new Y(e.env);
7977
7938
  await y.purgeInternalWorkerCache(e, t, i, o.slug, o.language || "en");
7978
- let b = await fi(t, i), x = await pi(t, i);
7979
- y.purgeSmart(e, t, i, o.slug, b, p);
7980
- for (let t of x) y.purgeAndWarmSlug(e, t);
7939
+ let b = await pi(t, i), x = await mi(t, i);
7940
+ if (y.purgeSmart(e, t, i, o.slug, b, p), !p && x.length > 0) for (let t of x) y.purgeAndWarmSlug(e, t);
7981
7941
  return e.json({
7982
7942
  success: !0,
7983
7943
  id: i,
@@ -7985,47 +7945,47 @@ Z.get("/", async (e) => {
7985
7945
  version: _,
7986
7946
  publishedAt: v.publishedAt
7987
7947
  });
7988
- }), Z.delete("/", async (e) => {
7948
+ }), X.delete("/", async (e) => {
7989
7949
  let t = e.get("db"), n = e.req.query("id");
7990
7950
  if (!n) return e.json({ error: "Node ID required" }, 400);
7991
7951
  let r = Number(n), i = await t.prepare("SELECT slug, language, status FROM content_nodes WHERE id = ?").get(r);
7992
- await t.prepare("UPDATE content_nodes SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?").run(r), await J(e).clear();
7993
- let a = new X(e.env);
7952
+ await t.prepare("UPDATE content_nodes SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?").run(r), await q(e).clear();
7953
+ let a = new Y(e.env);
7994
7954
  if (i && await a.purgeInternalWorkerCache(e, t, r, i.slug, i.language || "en"), i && i.status === "published") {
7995
- let n = await fi(t, r);
7955
+ let n = await pi(t, r);
7996
7956
  a.purgeSmart(e, t, r, i.slug, n, !0);
7997
7957
  }
7998
7958
  return e.json({
7999
7959
  success: !0,
8000
7960
  deletedNodeId: r
8001
7961
  });
8002
- }), Z.post("/restore", async (e) => {
7962
+ }), X.post("/restore", async (e) => {
8003
7963
  let t = e.get("db"), n = await e.req.json(), r = Number(n.id);
8004
7964
  if (!r) return e.json({ error: "Node ID required" }, 400);
8005
7965
  let i = await t.prepare("SELECT slug, language, status FROM content_nodes WHERE id = ?").get(r);
8006
- await t.prepare("UPDATE content_nodes SET deletedAt = NULL WHERE id = ?").run(r), await J(e).clear();
8007
- let a = new X(e.env);
7966
+ await t.prepare("UPDATE content_nodes SET deletedAt = NULL WHERE id = ?").run(r), await q(e).clear();
7967
+ let a = new Y(e.env);
8008
7968
  if (i && await a.purgeInternalWorkerCache(e, t, r, i.slug, i.language || "en"), i && i.status === "published") {
8009
- let n = await fi(t, r);
7969
+ let n = await pi(t, r);
8010
7970
  a.purgeSmart(e, t, r, i.slug, n, !0);
8011
7971
  }
8012
7972
  return e.json({
8013
7973
  success: !0,
8014
7974
  restoredNodeId: r
8015
7975
  });
8016
- }), Z.delete("/purge", async (e) => {
7976
+ }), X.delete("/purge", async (e) => {
8017
7977
  let t = e.get("db"), n = e.req.query("id");
8018
7978
  if (!n) return e.json({ error: "Node ID required" }, 400);
8019
- let r = Number(n), i = await t.prepare("SELECT slug, language, status FROM content_nodes WHERE id = ?").get(r), a = await fi(t, r), o = new X(e.env);
8020
- return i && await o.purgeInternalWorkerCache(e, t, r, i.slug, i.language || "en"), await t.prepare("DELETE FROM node_channels WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM tree_nodes WHERE contentId = ?").run(r), await t.prepare("DELETE FROM content_blocks WHERE contentId = ?").run(r), await t.prepare("DELETE FROM node_revisions WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM node_assets WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM content_nodes WHERE id = ?").run(r), await J(e).clear(), i && i.status === "published" && o.purgeSmart(e, t, r, i.slug, a, !0), e.json({
7979
+ let r = Number(n), i = await t.prepare("SELECT slug, language, status FROM content_nodes WHERE id = ?").get(r), a = await pi(t, r), o = new Y(e.env);
7980
+ return i && await o.purgeInternalWorkerCache(e, t, r, i.slug, i.language || "en"), await t.prepare("DELETE FROM node_channels WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM tree_nodes WHERE contentId = ?").run(r), await t.prepare("DELETE FROM content_blocks WHERE contentId = ?").run(r), await t.prepare("DELETE FROM node_revisions WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM node_assets WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM content_nodes WHERE id = ?").run(r), await q(e).clear(), i && i.status === "published" && o.purgeSmart(e, t, r, i.slug, a, !0), e.json({
8021
7981
  success: !0,
8022
7982
  purgedNodeId: r
8023
7983
  });
8024
7984
  });
8025
7985
  //#endregion
8026
7986
  //#region server/routes/admin/trees.ts
8027
- var xi = new e();
8028
- function Si(e, t = null) {
7987
+ var Si = new e();
7988
+ function Ci(e, t = null) {
8029
7989
  let n = [];
8030
7990
  for (let r = 0; r < e.length; r++) {
8031
7991
  let i = e[r];
@@ -8037,19 +7997,19 @@ function Si(e, t = null) {
8037
7997
  id: o,
8038
7998
  parentId: t,
8039
7999
  sortOrder: r
8040
- }), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...Si(i.children, o)));
8000
+ }), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...Ci(i.children, o)));
8041
8001
  }
8042
8002
  return n;
8043
8003
  }
8044
- function Ci(e) {
8004
+ function wi(e) {
8045
8005
  if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
8046
8006
  let t = Number(e);
8047
8007
  return isNaN(t) ? null : t;
8048
8008
  }
8049
- function wi(e) {
8009
+ function Ti(e) {
8050
8010
  return +(e === !0 || e === 1 || e === "1" || e === "true");
8051
8011
  }
8052
- xi.get("/tree.json", async (e) => {
8012
+ Si.get("/tree.json", async (e) => {
8053
8013
  try {
8054
8014
  let t = e.get("db"), n = e.req.query("treeId") || "main-nav", r = e.req.query("preview") === "true", i = 1;
8055
8015
  if (isNaN(Number(n))) {
@@ -8099,9 +8059,9 @@ xi.get("/tree.json", async (e) => {
8099
8059
  } catch (t) {
8100
8060
  return console.error("[CMS Tree API] GET Error:", t), e.json({ error: t.message || "Failed to fetch tree" }, 500);
8101
8061
  }
8102
- }), xi.post("/tree.json", async (e) => {
8062
+ }), Si.post("/tree.json", async (e) => {
8103
8063
  try {
8104
- let t = e.get("db"), n = await e.req.json(), r = n.treeId ? String(n.treeId).trim() : "main-nav", i = J(e), a = new X(e.env), o = 1;
8064
+ let t = e.get("db"), n = await e.req.json(), r = n.treeId ? String(n.treeId).trim() : "main-nav", i = q(e), a = new Y(e.env), o = 1;
8105
8065
  if (isNaN(Number(r))) {
8106
8066
  let e = await t.prepare("SELECT id FROM trees WHERE key = ?").get(r);
8107
8067
  if (e && e.id) o = Number(e.id);
@@ -8111,7 +8071,7 @@ xi.get("/tree.json", async (e) => {
8111
8071
  }
8112
8072
  } else o = Number(r);
8113
8073
  if (n.tree && Array.isArray(n.tree)) {
8114
- let r = Si(n.tree, null);
8074
+ let r = Ci(n.tree, null);
8115
8075
  if (r.length > 0) for (let e = 0; e < r.length; e += 50) {
8116
8076
  let n = r.slice(e, e + 50), i = n.map((e) => e.id), a = i.map(() => "?").join(","), s = "UPDATE tree_nodes SET \n";
8117
8077
  s += "parentId = CASE id \n", n.forEach(() => {
@@ -8126,14 +8086,14 @@ xi.get("/tree.json", async (e) => {
8126
8086
  c.push(e.id, e.sortOrder);
8127
8087
  }), c.push(...i), c.push(o), await t.prepare(s).run(...c);
8128
8088
  }
8129
- return await i.clear(), e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(a.purgeGlobalCache(e)) : await a.purgeGlobalCache(e), e.json({
8089
+ return await i.clear(), e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(a.purgeGlobalCacheDirect(e, t)) : await a.purgeGlobalCacheDirect(e, t), e.json({
8130
8090
  success: !0,
8131
8091
  reorderedCount: r.length
8132
8092
  });
8133
8093
  }
8134
- 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 = wi(n.isHidden === void 0 ? m.isHidden === void 0 ? m.hidden : m.isHidden : n.isHidden);
8094
+ 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 = Ti(n.isHidden === void 0 ? m.isHidden === void 0 ? m.hidden : m.isHidden : n.isHidden);
8135
8095
  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;
8136
- let g = Ci(u), _ = e.get("user")?.id || null;
8096
+ let g = wi(u), _ = e.get("user")?.id || null;
8137
8097
  if (s === "create") {
8138
8098
  let r = m.slug || n.slug || c, s = r ? String(r).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "") : null;
8139
8099
  if (s) {
@@ -8165,7 +8125,7 @@ xi.get("/tree.json", async (e) => {
8165
8125
  let e = b.map(() => "(?, ?)").join(", "), n = b.flatMap((e) => [f, e]);
8166
8126
  await t.prepare(`INSERT OR IGNORE INTO node_channels (nodeId, channelId) VALUES ${e}`).run(...n);
8167
8127
  }
8168
- return await i.clear(), e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(a.purgeGlobalCache(e)) : await a.purgeGlobalCache(e), e.json({
8128
+ return await i.clear(), e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(a.purgeGlobalCacheDirect(e, t)) : await a.purgeGlobalCacheDirect(e, t), e.json({
8169
8129
  success: !0,
8170
8130
  id: f,
8171
8131
  treeNodeId: v,
@@ -8203,14 +8163,14 @@ xi.get("/tree.json", async (e) => {
8203
8163
  }
8204
8164
  await t.prepare("DELETE FROM tree_nodes WHERE treeId = ? AND contentId = ?").run(o, d);
8205
8165
  let r = await t.prepare("\n INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder)\n VALUES (?, ?, ?, 0)\n ").run(o, d, g), s = Number(r.lastInsertRowid);
8206
- return await i.clear(), e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(a.purgeGlobalCache(e)) : await a.purgeGlobalCache(e), e.json({
8166
+ return await i.clear(), e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(a.purgeGlobalCacheDirect(e, t)) : await a.purgeGlobalCacheDirect(e, t), e.json({
8207
8167
  success: !0,
8208
8168
  treeNodeId: s
8209
8169
  });
8210
8170
  }
8211
8171
  if (s === "detach") {
8212
8172
  let r = n.treeNodeId || n.contentId;
8213
- return r ? (await t.prepare("\n UPDATE tree_nodes \n SET parentId = (SELECT parentId FROM tree_nodes WHERE (id = ? OR contentId = ?) AND treeId = ?) \n WHERE parentId = ? AND treeId = ?\n ").run(r, r, o, r, o), await t.prepare("DELETE FROM tree_nodes WHERE (id = ? OR contentId = ?) AND treeId = ?").run(r, r, o), await i.clear(), e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(a.purgeGlobalCache(e)) : await a.purgeGlobalCache(e), e.json({ success: !0 })) : e.json({ error: "treeNodeId or contentId required for detach" }, 400);
8173
+ return r ? (await t.prepare("\n UPDATE tree_nodes \n SET parentId = (SELECT parentId FROM tree_nodes WHERE (id = ? OR contentId = ?) AND treeId = ?) \n WHERE parentId = ? AND treeId = ?\n ").run(r, r, o, r, o), await t.prepare("DELETE FROM tree_nodes WHERE (id = ? OR contentId = ?) AND treeId = ?").run(r, r, o), await i.clear(), e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(a.purgeGlobalCacheDirect(e, t)) : await a.purgeGlobalCacheDirect(e, t), e.json({ success: !0 })) : e.json({ error: "treeNodeId or contentId required for detach" }, 400);
8214
8174
  }
8215
8175
  return e.json({ error: "Invalid payload or action" }, 400);
8216
8176
  } catch (t) {
@@ -8219,7 +8179,7 @@ xi.get("/tree.json", async (e) => {
8219
8179
  details: t.message
8220
8180
  }, 500);
8221
8181
  }
8222
- }), xi.get("/trees.json", async (e) => {
8182
+ }), Si.get("/trees.json", async (e) => {
8223
8183
  try {
8224
8184
  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) => {
8225
8185
  let n = Number(t.treeId), r = Number(t.channelId);
@@ -8249,7 +8209,7 @@ xi.get("/tree.json", async (e) => {
8249
8209
  } catch {
8250
8210
  return e.json([]);
8251
8211
  }
8252
- }), xi.post("/trees.json", async (e) => {
8212
+ }), Si.post("/trees.json", async (e) => {
8253
8213
  try {
8254
8214
  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 };
8255
8215
  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({
@@ -8274,9 +8234,9 @@ xi.get("/tree.json", async (e) => {
8274
8234
  await t.prepare(`INSERT OR IGNORE INTO channel_trees (channelId, treeId, key) VALUES ${n}`).run(...r);
8275
8235
  }
8276
8236
  }
8277
- await J(e).clear();
8278
- let m = new X(e.env);
8279
- return e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(m.purgeGlobalCache(e)) : await m.purgeGlobalCache(e), e.json({
8237
+ await q(e).clear();
8238
+ let m = new Y(e.env);
8239
+ return e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(m.purgeGlobalCacheDirect(e, t)) : await m.purgeGlobalCacheDirect(e, t), e.json({
8280
8240
  success: !0,
8281
8241
  id: p,
8282
8242
  key: o,
@@ -8290,14 +8250,14 @@ xi.get("/tree.json", async (e) => {
8290
8250
  } catch (t) {
8291
8251
  return console.error("[API Trees] Error saving tree:", t), e.json({ error: t.message || "Failed to save tree" }, 500);
8292
8252
  }
8293
- }), xi.delete("/trees.json", async (e) => {
8253
+ }), Si.delete("/trees.json", async (e) => {
8294
8254
  let t = e.get("db"), n = e.req.query("id");
8295
8255
  if (!n) return e.json({ error: "Tree ID required" }, 400);
8296
8256
  let r = Number(n);
8297
8257
  try {
8298
- await t.prepare("DELETE FROM trees WHERE id = ?").run(r), await t.prepare("DELETE FROM channel_trees WHERE treeId = ?").run(r), await t.prepare("DELETE FROM tree_nodes WHERE treeId = ?").run(r), await J(e).clear();
8299
- let n = new X(e.env);
8300
- return e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(n.purgeGlobalCache(e)) : await n.purgeGlobalCache(e), e.json({
8258
+ await t.prepare("DELETE FROM trees WHERE id = ?").run(r), await t.prepare("DELETE FROM channel_trees WHERE treeId = ?").run(r), await t.prepare("DELETE FROM tree_nodes WHERE treeId = ?").run(r), await q(e).clear();
8259
+ let n = new Y(e.env);
8260
+ return e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(n.purgeGlobalCacheDirect(e, t)) : await n.purgeGlobalCacheDirect(e, t), e.json({
8301
8261
  success: !0,
8302
8262
  deletedTreeId: r
8303
8263
  });
@@ -8307,8 +8267,8 @@ xi.get("/tree.json", async (e) => {
8307
8267
  });
8308
8268
  //#endregion
8309
8269
  //#region server/routes/admin/channels.ts
8310
- var Ti = new e();
8311
- Ti.get("/", async (e) => {
8270
+ var Ei = new e();
8271
+ Ei.get("/", async (e) => {
8312
8272
  try {
8313
8273
  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").all(), a = ((Array.isArray(i) ? i : i?.results || []) || []).reduce((e, t) => {
8314
8274
  e[t.channelId] || (e[t.channelId] = []);
@@ -8332,7 +8292,7 @@ Ti.get("/", async (e) => {
8332
8292
  isHidden: !!e.isHidden,
8333
8293
  trees: a[e.id] || []
8334
8294
  };
8335
- }), s = e.env?.BUNDLED_DEFINITIONS, c = li(s)?.channelTemplate || {
8295
+ }), s = e.env?.BUNDLED_DEFINITIONS, c = ui(s)?.channelTemplate || {
8336
8296
  label: "Channel Settings",
8337
8297
  fields: {
8338
8298
  key: {
@@ -8374,7 +8334,7 @@ Ti.get("/", async (e) => {
8374
8334
  error: t.message
8375
8335
  }, 500);
8376
8336
  }
8377
- }), Ti.post("/", async (e) => {
8337
+ }), Ei.post("/", async (e) => {
8378
8338
  try {
8379
8339
  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 = "website", domain: c = "localhost", baseUrl: l = "http://localhost:4321", defaultLanguage: u = "en", 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 = Array.isArray(f) ? f : [], S = JSON.stringify(v || {}), C = e.get("user")?.id || m || p || null;
8380
8340
  if (await t.prepare("SELECT id FROM channels WHERE key = ? AND id != ? LIMIT 1").get(y, i ?? -1)) return e.json({
@@ -8401,7 +8361,9 @@ Ti.get("/", async (e) => {
8401
8361
  VALUES ${e}
8402
8362
  `).run(...n);
8403
8363
  }
8404
- return await J(e).clear(), new X(e.env).purgeGlobalCache(e), e.json({
8364
+ await q(e).clear();
8365
+ let E = new Y(e.env);
8366
+ return e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(E.purgeGlobalCacheDirect(e, t)) : await E.purgeGlobalCacheDirect(e, t), e.json({
8405
8367
  success: !0,
8406
8368
  id: w
8407
8369
  });
@@ -8411,12 +8373,14 @@ Ti.get("/", async (e) => {
8411
8373
  details: t.message
8412
8374
  }, 500);
8413
8375
  }
8414
- }), Ti.delete("/", async (e) => {
8376
+ }), Ei.delete("/", async (e) => {
8415
8377
  let t = e.get("db"), n = e.req.query("id");
8416
8378
  if (!n) return e.json({ error: "Channel ID required" }, 400);
8417
8379
  let r = Number(n);
8418
8380
  try {
8419
- return await t.prepare("DELETE FROM channel_trees WHERE channelId = ?").run(r), await t.prepare("DELETE FROM node_channels WHERE channelId = ?").run(r), await t.prepare("DELETE FROM channels WHERE id = ?").run(r), await J(e).clear(), new X(e.env).purgeGlobalCache(e), e.json({
8381
+ await t.prepare("DELETE FROM channel_trees WHERE channelId = ?").run(r), await t.prepare("DELETE FROM node_channels WHERE channelId = ?").run(r), await t.prepare("DELETE FROM channels WHERE id = ?").run(r), await q(e).clear();
8382
+ let n = new Y(e.env);
8383
+ return e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(n.purgeGlobalCacheDirect(e, t)) : await n.purgeGlobalCacheDirect(e, t), e.json({
8420
8384
  success: !0,
8421
8385
  deletedSiteId: r
8422
8386
  });
@@ -8429,10 +8393,10 @@ Ti.get("/", async (e) => {
8429
8393
  });
8430
8394
  //#endregion
8431
8395
  //#region server/routes/admin/schemas.ts
8432
- var Ei = new e(), Di = null, Oi = (e) => {
8396
+ var Di = new e(), Oi = null, ki = (e) => {
8433
8397
  try {
8434
- if (!Di) {
8435
- let t = ci(e.env?.BUNDLED_DEFINITIONS || Or), n = t.userTemplate || {
8398
+ if (!Oi) {
8399
+ let t = li(e.env?.BUNDLED_DEFINITIONS || kr), n = t.userTemplate || {
8436
8400
  id: "userTemplate",
8437
8401
  label: "User Account",
8438
8402
  fields: {
@@ -8468,7 +8432,7 @@ var Ei = new e(), Di = null, Oi = (e) => {
8468
8432
  }
8469
8433
  }
8470
8434
  };
8471
- Di = {
8435
+ Oi = {
8472
8436
  channelTemplate: t.channelTemplate || null,
8473
8437
  treeTemplate: t.treeTemplate || null,
8474
8438
  userTemplate: n,
@@ -8480,7 +8444,7 @@ var Ei = new e(), Di = null, Oi = (e) => {
8480
8444
  blockLayouts: t.blockLayouts || {}
8481
8445
  };
8482
8446
  }
8483
- return e.json(Di, 200, { "Cache-Control": "public, max-age=300, stale-while-revalidate=86400" });
8447
+ return e.json(Oi, 200, { "Cache-Control": "public, max-age=300, stale-while-revalidate=86400" });
8484
8448
  } catch (t) {
8485
8449
  return console.error("[CMS API] Error loading schemas:", t), e.json({
8486
8450
  error: "Failed to load schemas",
@@ -8488,10 +8452,10 @@ var Ei = new e(), Di = null, Oi = (e) => {
8488
8452
  }, 500);
8489
8453
  }
8490
8454
  };
8491
- Ei.get("/", Oi), Ei.get("/schemas.json", Oi);
8455
+ Di.get("/", ki), Di.get("/schemas.json", ki);
8492
8456
  //#endregion
8493
8457
  //#region server/routes/admin/validation.ts
8494
- var ki = new e(), Ai = {
8458
+ var Ai = new e(), ji = {
8495
8459
  node: "content_nodes",
8496
8460
  nodes: "content_nodes",
8497
8461
  content_node: "content_nodes",
@@ -8503,7 +8467,7 @@ var ki = new e(), Ai = {
8503
8467
  user: "users",
8504
8468
  users: "users",
8505
8469
  user_account: "user_accounts"
8506
- }, ji = {
8470
+ }, Mi = {
8507
8471
  content_nodes: [
8508
8472
  "id",
8509
8473
  "title",
@@ -8560,11 +8524,11 @@ var ki = new e(), Ai = {
8560
8524
  "createdAt"
8561
8525
  ]
8562
8526
  };
8563
- ki.post("/validate-unique", async (e) => {
8527
+ Ai.post("/validate-unique", async (e) => {
8564
8528
  try {
8565
8529
  let t = e.get("db"), { entityType: n, field: r, value: i, excludeId: a } = await e.req.json();
8566
8530
  if (!r || i == null || String(i).trim() === "") return e.json({ isUnique: !0 });
8567
- let o = Ai[n] || "content_nodes", s = r.replace(/[^a-zA-Z0-9_]/g, ""), c = (ji[o] || ji.content_nodes).includes(s), l = -1;
8531
+ let o = ji[n] || "content_nodes", s = r.replace(/[^a-zA-Z0-9_]/g, ""), c = (Mi[o] || Mi.content_nodes).includes(s), l = -1;
8568
8532
  if (a != null && String(a).trim() !== "") {
8569
8533
  let e = Number(a);
8570
8534
  l = isNaN(e) ? String(a) : e;
@@ -8576,7 +8540,7 @@ ki.post("/validate-unique", async (e) => {
8576
8540
  } catch (t) {
8577
8541
  return console.error("[API Validation] Error validating global uniqueness:", t), e.json({ error: "Failed to validate uniqueness" }, 500);
8578
8542
  }
8579
- }), ki.post("/validate-unique-sibling", async (e) => {
8543
+ }), Ai.post("/validate-unique-sibling", async (e) => {
8580
8544
  try {
8581
8545
  let t = e.get("db"), { slug: n, treeId: r, parentId: i, excludeTreeNodeId: a } = await e.req.json();
8582
8546
  if (!n || !String(n).trim() || !r) return e.json({ isUnique: !0 });
@@ -8603,8 +8567,8 @@ ki.post("/validate-unique", async (e) => {
8603
8567
  });
8604
8568
  //#endregion
8605
8569
  //#region server/routes/admin/stats.ts
8606
- var Mi = new e();
8607
- Mi.get("/", async (e) => {
8570
+ var Ni = new e();
8571
+ Ni.get("/", async (e) => {
8608
8572
  try {
8609
8573
  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) => ({
8610
8574
  ...e,
@@ -8619,7 +8583,7 @@ Mi.get("/", async (e) => {
8619
8583
  isHidden: !!e.isHidden,
8620
8584
  channelNames: e.channelLabels ? e.channelLabels.split(",") : [],
8621
8585
  treeNames: e.treeLabels ? e.treeLabels.split(",") : []
8622
- })), p = e.env?.BUNDLED_DEFINITIONS, m = ci(p), h = m.nodes || m.nodeSchemas || {}, g = c.map((e) => {
8586
+ })), p = e.env?.BUNDLED_DEFINITIONS, m = li(p), h = m.nodes || m.nodeSchemas || {}, g = c.map((e) => {
8623
8587
  let t = e.type || "node", n = h[t]?.label || t.charAt(0).toUpperCase() + t.slice(1);
8624
8588
  return {
8625
8589
  type: t,
@@ -8647,7 +8611,7 @@ Mi.get("/", async (e) => {
8647
8611
  });
8648
8612
  //#endregion
8649
8613
  //#region server/routes/admin/assets.ts
8650
- var Ni = new e();
8614
+ var Z = new e();
8651
8615
  async function Q(e, t, n = []) {
8652
8616
  let r = e.prepare(t);
8653
8617
  if (typeof r.bind == "function") {
@@ -8671,7 +8635,7 @@ function Fi(e, t, n) {
8671
8635
  }
8672
8636
  async function Ii(e, t, n) {
8673
8637
  try {
8674
- let r = new X(e.env), i = await Q(t, "\n SELECT cdnUrl, storageKeyPrivate\n FROM assets\n WHERE id = ? OR parentAssetId = ?\n ", [n, n]), a = [];
8638
+ let r = new Y(e.env), i = await Q(t, "\n SELECT cdnUrl, storageKeyPrivate\n FROM assets\n WHERE id = ? OR parentAssetId = ?\n ", [n, n]), a = [];
8675
8639
  for (let t of i) {
8676
8640
  let n = Fi(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN);
8677
8641
  n && a.push(n);
@@ -8682,12 +8646,12 @@ async function Ii(e, t, n) {
8682
8646
  n
8683
8647
  ]);
8684
8648
  if (o.length === 0) return;
8685
- for (let n of o) n.id && r.purgeSmart(e, t, n.id, n.slug, a);
8649
+ for (let n of o) n.id && n.slug && r.purgeSmart(e, t, n.id, n.slug, a, !1);
8686
8650
  } catch (e) {
8687
8651
  console.warn("[Assets Router] Failed to purge edge cache for asset nodes:", e);
8688
8652
  }
8689
8653
  }
8690
- Ni.get("/", async (e) => {
8654
+ Z.get("/", async (e) => {
8691
8655
  try {
8692
8656
  let t = u(e), { search: n = "", type: r = "all", page: i = "1", limit: a = "24", sort: o = "createdAt", order: s = "DESC", nodeId: c, channelId: l, trashed: d } = e.req.query(), f = Math.max(1, parseInt(i, 10) || 1), p = Math.max(1, Math.min(100, parseInt(a, 10) || 24)), m = (f - 1) * p, h = {
8693
8657
  createdAt: "a.createdAt",
@@ -8778,9 +8742,9 @@ Ni.get("/", async (e) => {
8778
8742
  details: t.message || String(t)
8779
8743
  }, 500);
8780
8744
  }
8781
- }), Ni.post("/upload", async (e) => {
8745
+ }), Z.post("/upload", async (e) => {
8782
8746
  try {
8783
- let t = u(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;
8747
+ let t = u(e), n = ri(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;
8784
8748
  s && (await Q(t, "SELECT id FROM assets WHERE id = ?", [s])).length === 0 && (s = null);
8785
8749
  let c = r.cropCoordinates, l = null, d = null;
8786
8750
  if (c) {
@@ -8831,7 +8795,7 @@ Ni.get("/", async (e) => {
8831
8795
  details: t.message || String(t)
8832
8796
  }, 500);
8833
8797
  }
8834
- }), Ni.get("/:id/details", async (e) => {
8798
+ }), Z.get("/:id/details", async (e) => {
8835
8799
  try {
8836
8800
  let t = u(e), n = e.req.param("id"), r = await Q(t, "SELECT * FROM assets WHERE id = ?", [n]);
8837
8801
  if (!r || r.length === 0) return e.json({ error: "Asset not found" }, 404);
@@ -8889,7 +8853,7 @@ Ni.get("/", async (e) => {
8889
8853
  } catch (t) {
8890
8854
  return console.error("❌ [Asset Details Error]:", t), e.json({ error: "Failed to load details" }, 500);
8891
8855
  }
8892
- }), Ni.put("/:id", async (e) => {
8856
+ }), Z.put("/:id", async (e) => {
8893
8857
  try {
8894
8858
  let t = u(e), n = e.req.param("id"), r = await e.req.json(), i = await Q(t, "SELECT filename, dataJson FROM assets WHERE id = ?", [n]);
8895
8859
  if (!i || i.length === 0) return e.json({ error: "Asset not found" }, 404);
@@ -8905,7 +8869,7 @@ Ni.get("/", async (e) => {
8905
8869
  } catch (t) {
8906
8870
  return console.error("❌ [Asset Update Error]:", t), e.json({ error: "Failed to update asset" }, 500);
8907
8871
  }
8908
- }), Ni.delete("/:id", async (e) => {
8872
+ }), Z.delete("/:id", async (e) => {
8909
8873
  try {
8910
8874
  let t = u(e), n = e.req.param("id"), r = (await Q(t, "SELECT id, filename, isSystemVariant FROM assets WHERE id = ?", [n]))[0];
8911
8875
  return r ? (await Ii(e, t, n), r.isSystemVariant ? await Pi(t, "UPDATE assets SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?", [n]) : await Pi(t, "UPDATE assets\n SET deletedAt = CURRENT_TIMESTAMP\n WHERE id = ? OR parentAssetId = ? OR (isSystemVariant = 1 AND (filename LIKE ? OR filename LIKE ?))", [
@@ -8924,7 +8888,7 @@ Ni.get("/", async (e) => {
8924
8888
  details: t.message || String(t)
8925
8889
  }, 500);
8926
8890
  }
8927
- }), Ni.post("/restore", async (e) => {
8891
+ }), Z.post("/restore", async (e) => {
8928
8892
  try {
8929
8893
  let t = u(e), n = await e.req.json(), r = n.id || n.assetId;
8930
8894
  if (!r) return e.json({ error: "Asset ID required" }, 400);
@@ -8945,9 +8909,9 @@ Ni.get("/", async (e) => {
8945
8909
  details: t.message
8946
8910
  }, 500);
8947
8911
  }
8948
- }), Ni.delete("/purge/:id", async (e) => {
8912
+ }), Z.delete("/purge/:id", async (e) => {
8949
8913
  try {
8950
- let t = u(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];
8914
+ let t = u(e), n = ri(e.env), r = e.req.param("id"), i = (await Q(t, "SELECT id, filename, storageKeyPrivate, isSystemVariant FROM assets WHERE id = ?", [r]))[0];
8951
8915
  if (!i) return e.json({ error: "Asset not found" }, 404);
8952
8916
  await Ii(e, t, r);
8953
8917
  let a = [i];
@@ -9102,7 +9066,7 @@ async function Hi(e, t, n, r, i = !1, a) {
9102
9066
  let o = a.hidden === !0 || a.hidden === 1 || a.hidden === "1" || a.hidden === "true", s = Bi(a.startShowingAt, a.stopShowingAt);
9103
9067
  if (!i && (o || !s)) return null;
9104
9068
  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 || t.blockId || t.id), d = Ui(a, l);
9105
- return d = await oi(e, d), d = Wi(d), d.blockId = u, {
9069
+ return d = await si(e, d), d = Wi(d), d.blockId = u, {
9106
9070
  region: t.region || n,
9107
9071
  block: {
9108
9072
  instanceId: t.id,
@@ -9355,12 +9319,12 @@ Li.get("/*", async (e) => {
9355
9319
  if (!c) return e.json({ error: `Channel '${a}' not found` }, 404);
9356
9320
  let l = c.status === "disabled" || c.status === "inactive" || c.isEnabled === 0 || c.isEnabled === !1;
9357
9321
  if (!s && l) return e.json({ error: `Channel '${c.key || a}' is currently inactive` }, 404);
9358
- let u = c.id, d = c.key || a, f = J(e), p = `node:${u || d}:${o}:${i}`, m = e.req.header("x-bypass-cache") === "true";
9322
+ let u = c.id, d = c.key || a, f = q(e), p = `node:${u || d}:${o}:${i}`, m = e.req.header("x-bypass-cache") === "true";
9359
9323
  if (!s && !m) {
9360
9324
  let t = await f.get(p);
9361
9325
  if (t) return e.header("X-Cache", "HIT"), e.json(t);
9362
9326
  }
9363
- let h = li(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 = `
9327
+ let h = ui(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 = `
9364
9328
  SELECT
9365
9329
  cn.*,
9366
9330
  tn.id as treeNodeId,
@@ -9420,7 +9384,7 @@ Li.get("/*", async (e) => {
9420
9384
  M.disabledRegions && (ne = M.disabledRegions), ae = M.hidden === !0 || M.hidden === 1 || M.hidden === "1" || M.hidden === "true", re = M.startShowingAt || null, ie = M.stopShowingAt || null;
9421
9385
  let oe = M.layoutId, se = oe && oe !== "inherit", { resolvedLayoutId: ce, inheritedFields: le } = await Qi(t, ee, D, s, j), P = se ? oe : ce || A.defaultLayout || null;
9422
9386
  for (let [e, t] of Object.entries(le)) (M[e] === void 0 || M[e] === null || M[e] === "" || M[e] === "inherit") && t !== void 0 && (M[e] = t);
9423
- let F = await oi(t, Ui(M, j));
9387
+ let F = await si(t, Ui(M, j));
9424
9388
  F = Wi(F), F = await Gi(t, F, n);
9425
9389
  let ue = Xi(F);
9426
9390
  delete F.socialImage, delete F.fbImage, delete F.xImage, delete F.whatsappImage, ue && (F.socialImages = ue), k.slug = _.slug, k.title = _.title, Object.assign(k, F), k.layoutId = P;
@@ -9457,7 +9421,7 @@ Li.get("/*", async (e) => {
9457
9421
  let a = i.hidden === !0 || i.hidden === 1 || i.hidden === "1" || i.hidden === "true", o = Bi(i.startShowingAt, i.stopShowingAt);
9458
9422
  if (!s && (a || !o)) return null;
9459
9423
  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 || e.blockId || e.id), d = Ui(i, l);
9460
- return d = await oi(t, d), d = Wi(d), d = await Gi(t, d, n), d.blockId = u, {
9424
+ return d = await si(t, d), d = Wi(d), d = await Gi(t, d, n), d.blockId = u, {
9461
9425
  region: r,
9462
9426
  block: {
9463
9427
  instanceId: e.id,
@@ -9545,7 +9509,7 @@ ta.get("/:treeParam", async (e) => {
9545
9509
  if (!i && t) return e.json({ error: `Channel '${n.key || r}' is currently inactive` }, 404);
9546
9510
  }
9547
9511
  }
9548
- let a = J(e), o = `tree:${r}:${n}`, s = e.req.header("x-bypass-cache") === "true";
9512
+ let a = q(e), o = `tree:${r}:${n}`, s = e.req.header("x-bypass-cache") === "true";
9549
9513
  if (!i && !s) {
9550
9514
  let t = await a.get(o);
9551
9515
  if (t) return e.header("X-Cache", "HIT"), e.json(t);
@@ -9554,7 +9518,7 @@ ta.get("/:treeParam", async (e) => {
9554
9518
  if (l && Number(l.isHidden) === 1 && !i) return e.json({ error: `Tree '${n}' is hidden` }, 404);
9555
9519
  let u = l?.id || (c ? Number(n) : null), d = {};
9556
9520
  if (l && l.dataJson) try {
9557
- let t = typeof l.dataJson == "string" ? JSON.parse(l.dataJson) : l.dataJson, r = e.env?.BUNDLED_DEFINITIONS, i = li(r), a = (i.trees?.[l.treeType || n] || i.trees?.site || {}).fields || {};
9521
+ let t = typeof l.dataJson == "string" ? JSON.parse(l.dataJson) : l.dataJson, r = e.env?.BUNDLED_DEFINITIONS, i = ui(r), a = (i.trees?.[l.treeType || n] || i.trees?.site || {}).fields || {};
9558
9522
  for (let [e, n] of Object.entries(t)) a[e]?.public === !0 && (d[e] = n);
9559
9523
  } catch (e) {
9560
9524
  console.warn("[CMS Public Tree API] Failed to parse tree dataJson", e);
@@ -9834,12 +9798,12 @@ $.use("*", o()), $.use("/media/*", o({
9834
9798
  e.set("currentDomain", r);
9835
9799
  let i = u(e);
9836
9800
  if (e.set("db", i), !ca) try {
9837
- await Mr(i), ca = !0;
9801
+ await Nr(i), ca = !0;
9838
9802
  } catch (e) {
9839
9803
  console.error("❌ [CMS Server] Failed to initialize system tables on cold start:", e);
9840
9804
  }
9841
9805
  await t();
9842
- }), $.route("/media", ia), $.use("/media/*", Fr()), $.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", Mi), $.route("/api/cms/stats.json", Mi), $.route("/api/cms", xi), $.route("/api/cms/channels", Ti), $.route("/api/cms/channels.json", Ti), $.route("/api/cms/schemas", Ei), $.route("/api/cms/schemas.json", Ei), $.route("/api/cms", ki), $.route("/api/admin/assets", Ni), $.route("/api/v1/node", Li), $.route("/api/v1/page", Li), $.route("/api/v1/tree", ta), $.route("/api/v1/all-paths", oa), $.get("*", async (e) => {
9806
+ }), $.route("/media", ia), $.use("/media/*", Ir()), $.route("/api/cms/nodes", X), $.route("/api/cms/nodes.json", X), $.route("/api/cms/formcsv", X), $.route("/api/cms/formcsv.json", X), $.route("/api/cms/stats", Ni), $.route("/api/cms/stats.json", Ni), $.route("/api/cms", Si), $.route("/api/cms/channels", Ei), $.route("/api/cms/channels.json", Ei), $.route("/api/cms/schemas", Di), $.route("/api/cms/schemas.json", Di), $.route("/api/cms", Ai), $.route("/api/admin/assets", Z), $.route("/api/v1/node", Li), $.route("/api/v1/page", Li), $.route("/api/v1/tree", ta), $.route("/api/v1/all-paths", oa), $.get("*", async (e) => {
9843
9807
  if (e.env?.ASSETS) {
9844
9808
  let t = await e.env.ASSETS.fetch(e.req.raw);
9845
9809
  if (t.status === 404) {