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

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,7 +6004,7 @@ 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 = [
6007
+ }, Mr = [
6008
6008
  "CREATE INDEX IF NOT EXISTS idx_content_schemas_type ON content_schemas(type);",
6009
6009
  "CREATE INDEX IF NOT EXISTS idx_sessions_user ON sessions(userId);",
6010
6010
  "CREATE INDEX IF NOT EXISTS idx_sessions_expires ON sessions(expiresAt);",
@@ -6027,13 +6027,13 @@ var Ar = {
6027
6027
  "CREATE INDEX IF NOT EXISTS idx_assets_deleted ON assets(deletedAt);",
6028
6028
  "CREATE INDEX IF NOT EXISTS idx_assets_parent ON assets(parentAssetId);"
6029
6029
  ];
6030
- async function Mr(e, t) {
6030
+ async function Nr(e, t) {
6031
6031
  try {
6032
6032
  await e.prepare("PRAGMA foreign_keys = ON;").run();
6033
6033
  } 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);
6034
+ for (let [t, n] of Object.entries(jr)) await e.prepare(`CREATE TABLE IF NOT EXISTS "${t}" (${n});`).run();
6035
+ for (let [t] of Object.entries(jr)) {
6036
+ let n = await Ar(e, t);
6037
6037
  if (n.size > 0) {
6038
6038
  if (t === "content_nodes" && !n.has("disabledRegionsJson")) try {
6039
6039
  await e.prepare("ALTER TABLE \"content_nodes\" ADD COLUMN disabledRegionsJson TEXT DEFAULT '{}';").run();
@@ -6048,12 +6048,12 @@ async function Mr(e, t) {
6048
6048
  }
6049
6049
  }
6050
6050
  }
6051
- for (let t of jr) try {
6051
+ for (let t of Mr) try {
6052
6052
  await e.prepare(t).run();
6053
6053
  } catch {}
6054
- await Nr(e, t || Or), await Pr(e);
6054
+ await Pr(e, t || kr), await Fr(e);
6055
6055
  }
6056
- async function Nr(e, t) {
6056
+ async function Pr(e, t) {
6057
6057
  if (!t) return;
6058
6058
  let n = t.rawNodes || {}, r = Object.entries(n);
6059
6059
  for (let [t, n] of r) {
@@ -6070,7 +6070,7 @@ async function Nr(e, t) {
6070
6070
  }
6071
6071
  }
6072
6072
  }
6073
- async function Pr(e) {
6073
+ async function Fr(e) {
6074
6074
  try {
6075
6075
  let t = await e.prepare("SELECT COUNT(*) as count FROM channels").get(), n = 1;
6076
6076
  if (!t || t.count === 0) {
@@ -6091,7 +6091,7 @@ async function Pr(e) {
6091
6091
  }
6092
6092
  //#endregion
6093
6093
  //#region server/middleware/media-static.ts
6094
- function Fr() {
6094
+ function Ir() {
6095
6095
  return async (e, t) => {
6096
6096
  if (e.env?.MEDIA_BUCKET) {
6097
6097
  let t = e.req.path.replace(/^\/media\//, ""), n = await e.env.MEDIA_BUCKET.get(t, { onlyIf: e.req.raw.headers });
@@ -6122,18 +6122,18 @@ function Fr() {
6122
6122
  }
6123
6123
  //#endregion
6124
6124
  //#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 {
6125
+ 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) => {
6126
+ typeof Hr.emitWarning == "function" ? Hr.emitWarning(e, t, n, r) : console.error(`[${n}] ${t}: ${e}`);
6127
+ }, 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
6128
  constructor(e) {
6129
6129
  super(e), this.fill(0);
6130
6130
  }
6131
- }, qr = class e {
6131
+ }, Jr = class e {
6132
6132
  heap;
6133
6133
  length;
6134
6134
  static #e = !1;
6135
6135
  static create(t) {
6136
- let n = Gr(t);
6136
+ let n = Kr(t);
6137
6137
  if (!n) return [];
6138
6138
  e.#e = !0;
6139
6139
  let r = new e(t, n);
@@ -6149,7 +6149,7 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6149
6149
  pop() {
6150
6150
  return this.heap[--this.length];
6151
6151
  }
6152
- }, Jr = class e {
6152
+ }, Yr = class e {
6153
6153
  #e;
6154
6154
  #t;
6155
6155
  #n;
@@ -6252,8 +6252,8 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6252
6252
  constructor(t) {
6253
6253
  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
6254
  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;
6255
+ if (this.#s = T ?? zr, n !== 0 && !Gr(n)) throw TypeError("max option must be a nonnegative integer");
6256
+ let E = n ? Kr(n) : Array;
6257
6257
  if (!E) throw Error("invalid max value: " + n);
6258
6258
  if (this.#e = n, this.#t = m, this.maxEntrySize = h || this.#t, this.sizeCalculation = g, this.sizeCalculation) {
6259
6259
  if (!this.#t && !this.maxEntrySize) throw TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
@@ -6261,26 +6261,26 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6261
6261
  }
6262
6262
  if (v !== void 0 && typeof v != "function") throw TypeError("memoMethod must be a function if defined");
6263
6263
  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");
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.#_ = 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) {
6265
+ if (this.#t !== 0 && !Gr(this.#t)) throw TypeError("maxSize must be a positive integer if specified");
6266
+ if (!Gr(this.maxEntrySize)) throw TypeError("maxEntrySize must be a positive integer if specified");
6267
6267
  this.#M();
6268
6268
  }
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");
6269
+ 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) {
6270
+ if (!Gr(this.ttl)) throw TypeError("ttl must be a positive integer if specified");
6271
6271
  this.#D();
6272
6272
  }
6273
6273
  if (this.#e === 0 && this.ttl === 0 && this.#t === 0) throw TypeError("At least one of max, maxSize, or ttl is required");
6274
6274
  if (!this.ttlAutopurge && !this.#e && !this.#t) {
6275
6275
  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));
6276
+ Wr(t) && (Vr.add(t), Ur("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", t, e));
6277
6277
  }
6278
6278
  }
6279
6279
  getRemainingTTL(e) {
6280
6280
  return this.#u.has(e) ? 1 / 0 : 0;
6281
6281
  }
6282
6282
  #D() {
6283
- let e = new Kr(this.#e), t = new Kr(this.#e);
6283
+ let e = new qr(this.#e), t = new qr(this.#e);
6284
6284
  this.#x = e, this.#b = t;
6285
6285
  let n = this.ttlAutopurge ? Array.from({ length: this.#e }) : void 0;
6286
6286
  this.#S = n, this.#A = (n, i, a = this.#s.now()) => {
@@ -6330,15 +6330,15 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6330
6330
  #A = () => {};
6331
6331
  #j = () => !1;
6332
6332
  #M() {
6333
- let e = new Kr(this.#e);
6333
+ let e = new qr(this.#e);
6334
6334
  this.#l = 0, this.#y = e, this.#N = (t) => {
6335
6335
  this.#l -= e[t], e[t] = 0;
6336
6336
  }, this.#F = (e, t, n, r) => {
6337
- if (!Wr(n)) {
6337
+ if (!Gr(n)) {
6338
6338
  if (this.#W(t)) return this.backgroundFetchSize;
6339
6339
  if (r) {
6340
6340
  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)");
6341
+ if (n = r(t, e), !Gr(n)) throw TypeError("sizeCalculation return invalid (expect positive integer)");
6342
6342
  } else throw TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
6343
6343
  }
6344
6344
  return n;
@@ -6454,10 +6454,10 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6454
6454
  }
6455
6455
  }
6456
6456
  set(e, t, n = {}) {
6457
- let { status: r = q.hasSubscribers ? {} : void 0 } = n;
6457
+ let { status: r = K.hasSubscribers ? {} : void 0 } = n;
6458
6458
  n.status = r, r && (r.op = "set", r.key = e, t !== void 0 && (r.value = t), r.cache = this);
6459
6459
  let i = this.#z(e, t, n);
6460
- return r && q.hasSubscribers && q.publish(r), i;
6460
+ return r && K.hasSubscribers && K.publish(r), i;
6461
6461
  }
6462
6462
  #z(e, t, n, r) {
6463
6463
  let { ttl: i = this.ttl, start: a, noDisposeOnSet: o = this.noDisposeOnSet, sizeCalculation: s = this.sizeCalculation, status: c } = n, l = this.#W(t);
@@ -6525,10 +6525,10 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6525
6525
  ])), 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
6526
  }
6527
6527
  has(e, t = {}) {
6528
- let { status: n = q.hasSubscribers ? {} : void 0 } = t;
6528
+ let { status: n = K.hasSubscribers ? {} : void 0 } = t;
6529
6529
  t.status = n, n && (n.op = "has", n.key = e, n.cache = this);
6530
6530
  let r = this.#V(e, t);
6531
- return q.hasSubscribers && q.publish(n), r;
6531
+ return K.hasSubscribers && K.publish(n), r;
6532
6532
  }
6533
6533
  #V(e, t = {}) {
6534
6534
  let { updateAgeOnHas: n = this.updateAgeOnHas, status: r } = t, i = this.#u.get(e);
@@ -6541,10 +6541,10 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6541
6541
  return !1;
6542
6542
  }
6543
6543
  peek(e, t = {}) {
6544
- let { status: n = zr() ? {} : void 0 } = t;
6544
+ let { status: n = Br() ? {} : void 0 } = t;
6545
6545
  n && (n.op = "peek", n.key = e, n.cache = this), t.status = n;
6546
6546
  let r = this.#H(e, t);
6547
- return q.hasSubscribers && q.publish(n), r;
6547
+ return K.hasSubscribers && K.publish(n), r;
6548
6548
  }
6549
6549
  #H(e, t) {
6550
6550
  let { status: n, allowStale: r = this.allowStale } = t, i = this.#u.get(e);
@@ -6596,10 +6596,10 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6596
6596
  return !!t && t instanceof Promise && t.hasOwnProperty("__staleWhileFetching") && t.__abortController instanceof AbortController;
6597
6597
  }
6598
6598
  fetch(e, t = {}) {
6599
- let n = Lr.hasSubscribers, { status: r = zr() ? {} : void 0 } = t;
6599
+ let n = Rr.hasSubscribers, { status: r = Br() ? {} : void 0 } = t;
6600
6600
  t.status = r, r && t.context && (r.context = t.context);
6601
6601
  let i = this.#G(e, t);
6602
- return r && n && (r.trace = !0, Lr.tracePromise(() => i, r).catch(() => {})), i;
6602
+ return r && n && (r.trace = !0, Rr.tracePromise(() => i, r).catch(() => {})), i;
6603
6603
  }
6604
6604
  async #G(e, t = {}) {
6605
6605
  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 +6643,10 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6643
6643
  }
6644
6644
  }
6645
6645
  forceFetch(e, t = {}) {
6646
- let n = Lr.hasSubscribers, { status: r = zr() ? {} : void 0 } = t;
6646
+ let n = Rr.hasSubscribers, { status: r = Br() ? {} : void 0 } = t;
6647
6647
  t.status = r, r && t.context && (r.context = t.context);
6648
6648
  let i = this.#K(e, t);
6649
- return r && n && (r.trace = !0, Lr.tracePromise(() => i, r).catch(() => {})), i;
6649
+ return r && n && (r.trace = !0, Rr.tracePromise(() => i, r).catch(() => {})), i;
6650
6650
  }
6651
6651
  async #K(e, t = {}) {
6652
6652
  let n = await this.#G(e, t);
@@ -6654,10 +6654,10 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6654
6654
  return n;
6655
6655
  }
6656
6656
  memo(e, t = {}) {
6657
- let { status: n = q.hasSubscribers ? {} : void 0 } = t;
6657
+ let { status: n = K.hasSubscribers ? {} : void 0 } = t;
6658
6658
  t.status = n, n && (n.op = "memo", n.key = e, t.context && (n.context = t.context), n.cache = this);
6659
6659
  let r = this.#q(e, t);
6660
- return n && (n.value = r), q.hasSubscribers && q.publish(n), r;
6660
+ return n && (n.value = r), K.hasSubscribers && K.publish(n), r;
6661
6661
  }
6662
6662
  #q(e, t = {}) {
6663
6663
  let n = this.#o;
@@ -6673,10 +6673,10 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6673
6673
  return i && (i.value = l), this.#z(e, l, o), l;
6674
6674
  }
6675
6675
  get(e, t = {}) {
6676
- let { status: n = q.hasSubscribers ? {} : void 0 } = t;
6676
+ let { status: n = K.hasSubscribers ? {} : void 0 } = t;
6677
6677
  t.status = n, n && (n.op = "get", n.key = e, n.cache = this);
6678
6678
  let r = this.#J(e, t);
6679
- return n && (r !== void 0 && (n.value = r), q.hasSubscribers && q.publish(n)), r;
6679
+ return n && (r !== void 0 && (n.value = r), K.hasSubscribers && K.publish(n)), r;
6680
6680
  }
6681
6681
  #J(e, t = {}) {
6682
6682
  let { allowStale: n = this.allowStale, updateAgeOnGet: r = this.updateAgeOnGet, noDeleteOnStaleGet: i = this.noDeleteOnStaleGet, status: a } = t, o = this.#u.get(e);
@@ -6697,7 +6697,7 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6697
6697
  return this.#Z(e, "delete");
6698
6698
  }
6699
6699
  #Z(e, t) {
6700
- q.hasSubscribers && q.publish({
6700
+ K.hasSubscribers && K.publish({
6701
6701
  op: "delete",
6702
6702
  delete: t,
6703
6703
  key: e,
@@ -6759,10 +6759,10 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6759
6759
  for (; t = e?.shift();) this.#i?.(...t);
6760
6760
  }
6761
6761
  }
6762
- }, Yr = class {
6762
+ }, Xr = class {
6763
6763
  cache;
6764
6764
  constructor(e = 1e3, t = 3e5) {
6765
- this.cache = new Jr({
6765
+ this.cache = new Yr({
6766
6766
  max: e,
6767
6767
  ttl: t
6768
6768
  });
@@ -6781,7 +6781,7 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6781
6781
  async clear() {
6782
6782
  this.cache.clear();
6783
6783
  }
6784
- }, Xr = class {
6784
+ }, Zr = class {
6785
6785
  kv;
6786
6786
  constructor(e) {
6787
6787
  this.kv = e;
@@ -6798,21 +6798,21 @@ var Ir = { hasSubscribers: !1 }, q = Ir, Lr = Ir, Rr = typeof performance == "ob
6798
6798
  this.kv && await this.kv.delete(e);
6799
6799
  }
6800
6800
  async clear() {}
6801
- }, Zr = class {
6801
+ }, Qr = class {
6802
6802
  async get() {
6803
6803
  return null;
6804
6804
  }
6805
6805
  async set() {}
6806
6806
  async delete() {}
6807
6807
  async clear() {}
6808
- }, Qr = null;
6809
- function J(e) {
6808
+ }, $r = null;
6809
+ function q(e) {
6810
6810
  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();
6811
+ 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
6812
  }
6813
6813
  //#endregion
6814
6814
  //#region server/storage/provider.ts
6815
- function $r(e) {
6815
+ function ei(e) {
6816
6816
  let t = e.split(".").pop()?.toLowerCase() || "bin";
6817
6817
  return t = t.replace(/[^a-z0-9]/g, ""), [
6818
6818
  "php",
@@ -6827,14 +6827,14 @@ function $r(e) {
6827
6827
  "cjs"
6828
6828
  ].includes(t) ? "bin" : t;
6829
6829
  }
6830
- var ei = class {
6830
+ var ti = class {
6831
6831
  bucket;
6832
6832
  publicDomain;
6833
6833
  constructor(e, t) {
6834
6834
  this.bucket = e, this.publicDomain = t;
6835
6835
  }
6836
6836
  async upload(e, t = "uploads") {
6837
- let n = $r(e.name), r = `${t}/${crypto.randomUUID().replace(/-/g, "")}.${n}`;
6837
+ let n = ei(e.name), r = `${t}/${crypto.randomUUID().replace(/-/g, "")}.${n}`;
6838
6838
  await this.bucket.put(r, e.stream(), { httpMetadata: { contentType: e.type } });
6839
6839
  let i = r.replace(/^\//, ""), a = `/media/${i}`;
6840
6840
  if (this.publicDomain && this.publicDomain.trim().length > 0) {
@@ -6849,7 +6849,7 @@ var ei = class {
6849
6849
  async delete(e) {
6850
6850
  await this.bucket.delete(e);
6851
6851
  }
6852
- }, ti = class {
6852
+ }, ni = class {
6853
6853
  customStoragePath;
6854
6854
  constructor(e) {
6855
6855
  this.customStoragePath = e;
@@ -6867,7 +6867,7 @@ var ei = class {
6867
6867
  ), { pipeline: a } = await import(
6868
6868
  /* @vite-ignore */
6869
6869
  "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);
6870
+ ), 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
6871
  await i.mkdir(n.dirname(u), { recursive: !0 });
6872
6872
  let d = r.createWriteStream(u);
6873
6873
  return await a(e.stream(), d), {
@@ -6890,16 +6890,16 @@ var ei = class {
6890
6890
  }
6891
6891
  }
6892
6892
  };
6893
- function ni(e) {
6893
+ function ri(e) {
6894
6894
  if (e.MEDIA_BUCKET) {
6895
6895
  let t = e.CDN_DOMAIN || "cdn.yourdomain.com";
6896
- return new ei(e.MEDIA_BUCKET, t);
6896
+ return new ti(e.MEDIA_BUCKET, t);
6897
6897
  }
6898
- return new ti(e.LOCAL_MEDIA_PATH);
6898
+ return new ni(e.LOCAL_MEDIA_PATH);
6899
6899
  }
6900
6900
  //#endregion
6901
6901
  //#region server/utils/node-assets-interceptor.ts
6902
- function ri(e) {
6902
+ function ii(e) {
6903
6903
  if (!e || typeof e != "object") return {
6904
6904
  cleanedData: e,
6905
6905
  assetRefs: []
@@ -6958,7 +6958,7 @@ function ri(e) {
6958
6958
  assetRefs: t
6959
6959
  };
6960
6960
  }
6961
- async function ii(e, t, n) {
6961
+ async function ai(e, t, n) {
6962
6962
  if (await e.prepare("DELETE FROM node_assets WHERE nodeId = ?").run(t), n.length === 0) return;
6963
6963
  let r = /* @__PURE__ */ new Set();
6964
6964
  for (let i of n) {
@@ -6968,23 +6968,23 @@ async function ii(e, t, n) {
6968
6968
  }
6969
6969
  //#endregion
6970
6970
  //#region server/utils/asset-hydrator.ts
6971
- function ai(e) {
6971
+ function oi(e) {
6972
6972
  if (!e) return null;
6973
6973
  if (typeof e == "string" && e.startsWith("ast_")) return e;
6974
6974
  if (typeof e == "object" && e) {
6975
6975
  if (typeof e.id == "string" && e.id.startsWith("ast_")) return e.id;
6976
- if (typeof e.id == "object") return ai(e.id);
6976
+ if (typeof e.id == "object") return oi(e.id);
6977
6977
  }
6978
6978
  return null;
6979
6979
  }
6980
- async function oi(e, t) {
6980
+ async function si(e, t) {
6981
6981
  if (!t || typeof t != "object") return t;
6982
6982
  let n = /* @__PURE__ */ new Set(), r = (e) => {
6983
6983
  if (!e) return;
6984
- let t = ai(e);
6984
+ let t = oi(e);
6985
6985
  if (t) {
6986
6986
  if (n.add(t), typeof e == "object" && e.parentAssetId) {
6987
- let t = ai(e.parentAssetId);
6987
+ let t = oi(e.parentAssetId);
6988
6988
  t && n.add(t);
6989
6989
  }
6990
6990
  } else Array.isArray(e) ? e.forEach(r) : typeof e == "object" && Object.values(e).forEach(r);
@@ -7013,7 +7013,7 @@ async function oi(e, t) {
7013
7013
  AND (parentAssetId IN (${i}) OR ${Array.from(n).map(() => "filename LIKE ?").join(" OR ")})
7014
7014
  `).all(...Array.from(n), ...Array.from(n).map((e) => `%${e}%`)), c = Array.isArray(s) ? s : s?.results || [], l = /* @__PURE__ */ new Map();
7015
7015
  for (let e of c) {
7016
- let t = ai(e.parentAssetId) || Array.from(n).find((t) => e.filename.includes(t));
7016
+ let t = oi(e.parentAssetId) || Array.from(n).find((t) => e.filename.includes(t));
7017
7017
  if (!t) continue;
7018
7018
  let r = e.filename.match(/^crop_([a-z0-9]+)_/i), i = r ? r[1] : "standard", a = null;
7019
7019
  if (e.cropCoordinatesJson) try {
@@ -7048,7 +7048,7 @@ async function oi(e, t) {
7048
7048
  id: e.id,
7049
7049
  url: t,
7050
7050
  originalUrl: n,
7051
- parentAssetId: ai(e.parentAssetId) || null,
7051
+ parentAssetId: oi(e.parentAssetId) || null,
7052
7052
  cropCoordinates: r,
7053
7053
  variants: i && Object.keys(i).length > 0 ? i : void 0,
7054
7054
  filename: e.filename,
@@ -7060,7 +7060,7 @@ async function oi(e, t) {
7060
7060
  }
7061
7061
  let d = (e) => {
7062
7062
  if (!e) return e;
7063
- let t = ai(e);
7063
+ let t = oi(e);
7064
7064
  if (t) {
7065
7065
  let n = u.get(t) || {
7066
7066
  id: t,
@@ -7070,7 +7070,7 @@ async function oi(e, t) {
7070
7070
  return {
7071
7071
  ...n,
7072
7072
  id: t,
7073
- parentAssetId: n.parentAssetId ? ai(n.parentAssetId) : null,
7073
+ parentAssetId: n.parentAssetId ? oi(n.parentAssetId) : null,
7074
7074
  url: typeof e == "object" && e.url && !e.url.startsWith("blob:") ? e.url : n.url,
7075
7075
  originalUrl: typeof e == "object" && e.originalUrl && !e.originalUrl.startsWith("blob:") ? e.originalUrl : n.originalUrl,
7076
7076
  cropCoordinates: i || n.cropCoordinates || null,
@@ -7090,7 +7090,7 @@ async function oi(e, t) {
7090
7090
  }
7091
7091
  //#endregion
7092
7092
  //#region src/schemas/definitions.ts
7093
- function Y(e = {}, t = {}) {
7093
+ function J(e = {}, t = {}) {
7094
7094
  let n = {
7095
7095
  ...e,
7096
7096
  ...t
@@ -7108,7 +7108,7 @@ function Y(e = {}, t = {}) {
7108
7108
  ...t.rules || {}
7109
7109
  }, n;
7110
7110
  }
7111
- function si() {
7111
+ function ci() {
7112
7112
  if (typeof process > "u" || !process?.versions?.node) return null;
7113
7113
  try {
7114
7114
  let e = (e) => {
@@ -7137,7 +7137,7 @@ function si() {
7137
7137
  for (let a of e(r)) {
7138
7138
  let e = n.basename(a, n.extname(a));
7139
7139
  try {
7140
- i[e] = Dr.parse(t.readFileSync(a, "utf-8"));
7140
+ i[e] = Or.parse(t.readFileSync(a, "utf-8"));
7141
7141
  } catch (e) {
7142
7142
  console.warn(`[CMS Schema] Failed to parse ${a}:`, e);
7143
7143
  }
@@ -7147,7 +7147,7 @@ function si() {
7147
7147
  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
7148
  if (!o) return null;
7149
7149
  try {
7150
- return Dr.parse(t.readFileSync(o, "utf-8"));
7150
+ return Or.parse(t.readFileSync(o, "utf-8"));
7151
7151
  } catch {
7152
7152
  return null;
7153
7153
  }
@@ -7175,12 +7175,12 @@ function si() {
7175
7175
  return null;
7176
7176
  }
7177
7177
  }
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
7178
  function li(e) {
7179
+ if (e && (Object.keys(e.rawNodes || {}).length > 0 || Object.keys(e.nodes || {}).length > 0)) return ui(e);
7180
+ let t = ci();
7181
+ return t && Object.keys(t.rawNodes).length > 0 ? ui(t) : ui(null);
7182
+ }
7183
+ function ui(e) {
7184
7184
  if (!e) return {
7185
7185
  nodes: {},
7186
7186
  trees: {},
@@ -7200,7 +7200,7 @@ function li(e) {
7200
7200
  let i = {};
7201
7201
  if (!Array.isArray(e)) return typeof e == "object" && e ? (Object.entries(e).forEach(([e, t]) => {
7202
7202
  let n = i[e] || m[e] || {};
7203
- i[e] = Y(n, t);
7203
+ i[e] = J(n, t);
7204
7204
  }), i) : {};
7205
7205
  let a = (e) => {
7206
7206
  let a = h[e] || h[`${e}-base`] || {};
@@ -7213,11 +7213,11 @@ function li(e) {
7213
7213
  fields: {}
7214
7214
  }), Object.entries(s).forEach(([e, r]) => {
7215
7215
  let i = n[t].fields[e] || {};
7216
- n[t].fields[e] = Y(i, r);
7216
+ n[t].fields[e] = J(i, r);
7217
7217
  });
7218
7218
  } else Object.entries(s).forEach(([e, t]) => {
7219
7219
  let n = i[e] || {};
7220
- i[e] = Y(n, t);
7220
+ i[e] = J(n, t);
7221
7221
  });
7222
7222
  };
7223
7223
  return e.forEach((e) => {
@@ -7225,7 +7225,7 @@ function li(e) {
7225
7225
  if (e.startsWith("fieldSet:")) a(e.replace("fieldSet:", "").trim());
7226
7226
  else {
7227
7227
  let t = i[e] || m[e] || {};
7228
- i[e] = Y(t, {
7228
+ i[e] = J(t, {
7229
7229
  type: "text",
7230
7230
  label: e
7231
7231
  });
@@ -7235,7 +7235,7 @@ function li(e) {
7235
7235
  if (t === "fieldSet") a(String(n));
7236
7236
  else {
7237
7237
  let e = i[t] || m[t] || {};
7238
- i[t] = Y(e, typeof n == "object" && n ? n : {});
7238
+ i[t] = J(e, typeof n == "object" && n ? n : {});
7239
7239
  }
7240
7240
  }
7241
7241
  }), i;
@@ -7253,7 +7253,7 @@ function li(e) {
7253
7253
  let s = g(i.fields || i, a, n, t);
7254
7254
  Object.entries(s).forEach(([e, t]) => {
7255
7255
  let r = n[a].fields[e] || {};
7256
- n[a].fields[e] = Y(r, t);
7256
+ n[a].fields[e] = J(r, t);
7257
7257
  });
7258
7258
  }
7259
7259
  }), n) : (Object.entries(e).forEach(([e, r]) => {
@@ -7265,7 +7265,7 @@ function li(e) {
7265
7265
  let o = g(a, e, n, t);
7266
7266
  Object.entries(o).forEach(([t, r]) => {
7267
7267
  let i = n[e].fields[t] || {};
7268
- n[e].fields[t] = Y(i, r);
7268
+ n[e].fields[t] = J(i, r);
7269
7269
  });
7270
7270
  }), n);
7271
7271
  }, v = {};
@@ -7283,16 +7283,16 @@ function li(e) {
7283
7283
  fields: {}
7284
7284
  }), Object.entries(o).forEach(([e, r]) => {
7285
7285
  let i = n[t].fields[e] || {};
7286
- n[t].fields[e] = Y(i, r);
7286
+ n[t].fields[e] = J(i, r);
7287
7287
  });
7288
7288
  } else Object.entries(o).forEach(([e, t]) => {
7289
7289
  let n = r[e] || m[e] || {};
7290
- r[e] = Y(n, t);
7290
+ r[e] = J(n, t);
7291
7291
  });
7292
7292
  }), Object.values(n).forEach((e) => {
7293
7293
  Object.entries(e.fields).forEach(([e, t]) => {
7294
7294
  let n = r[e] || {};
7295
- r[e] = Y(n, t);
7295
+ r[e] = J(n, t);
7296
7296
  });
7297
7297
  }), Object.keys(n).length === 0 && Object.keys(r).length > 0 && (n.settings = {
7298
7298
  label: t.label || "Settings",
@@ -7315,11 +7315,11 @@ function li(e) {
7315
7315
  Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
7316
7316
  let t = h[e] || {}, i = t.fields || t, a = g(i, "settings", n);
7317
7317
  Object.entries(a).forEach(([e, t]) => {
7318
- r[e] = Y(r[e] || {}, t);
7318
+ r[e] = J(r[e] || {}, t);
7319
7319
  });
7320
7320
  }), Object.values(n).forEach((e) => {
7321
7321
  Object.entries(e.fields).forEach(([e, t]) => {
7322
- r[e] = Y(r[e] || {}, t);
7322
+ r[e] = J(r[e] || {}, t);
7323
7323
  });
7324
7324
  }), y[e] = {
7325
7325
  ...t,
@@ -7338,7 +7338,7 @@ function li(e) {
7338
7338
  Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
7339
7339
  let t = h[e] || {}, r = t.fields || t, i = g(r);
7340
7340
  Object.entries(i).forEach(([e, t]) => {
7341
- n[e] = Y(n[e] || {}, t);
7341
+ n[e] = J(n[e] || {}, t);
7342
7342
  });
7343
7343
  }), b[e] = {
7344
7344
  ...t,
@@ -7387,7 +7387,7 @@ function li(e) {
7387
7387
  Array.isArray(f?.fieldSets) && f?.fieldSets.forEach((e) => {
7388
7388
  let t = h[e] || {}, n = t.fields || t, r = g(n);
7389
7389
  Object.entries(r).forEach(([e, t]) => {
7390
- T[e] = Y(T[e] || {}, t);
7390
+ T[e] = J(T[e] || {}, t);
7391
7391
  });
7392
7392
  });
7393
7393
  let E = f ? {
@@ -7397,7 +7397,7 @@ function li(e) {
7397
7397
  Array.isArray(p?.fieldSets) && p?.fieldSets.forEach((e) => {
7398
7398
  let t = h[e] || {}, n = t.fields || t, r = g(n);
7399
7399
  Object.entries(r).forEach(([e, t]) => {
7400
- D[e] = Y(D[e] || {}, t);
7400
+ D[e] = J(D[e] || {}, t);
7401
7401
  });
7402
7402
  });
7403
7403
  let ee = p ? {
@@ -7419,7 +7419,7 @@ function li(e) {
7419
7419
  }
7420
7420
  //#endregion
7421
7421
  //#region server/services/cache-manager.ts
7422
- var X = class {
7422
+ var Y = class {
7423
7423
  zoneId;
7424
7424
  apiToken;
7425
7425
  frontendUrl;
@@ -7451,7 +7451,7 @@ var X = class {
7451
7451
  }
7452
7452
  async purgeInternalWorkerCache(e, t, n, r, i = "en") {
7453
7453
  try {
7454
- let a = J(e);
7454
+ let a = q(e);
7455
7455
  if (n) {
7456
7456
  let e = await t.prepare("SELECT treeId FROM tree_nodes WHERE contentId = ?").all(n), r = Array.isArray(e) ? e : e?.results || [];
7457
7457
  for (let e of r) await a.delete(`tree:default:${e.treeId}`), await a.delete(`tree:all:${e.treeId}`);
@@ -7567,8 +7567,8 @@ var X = class {
7567
7567
  console.error("❌ [CacheManager] Dual Slug Purge CRASH:", e);
7568
7568
  }
7569
7569
  }
7570
- }, Z = new e();
7571
- async function ui(e, t, n = []) {
7570
+ }, X = new e();
7571
+ async function di(e, t, n = []) {
7572
7572
  let r = e.prepare(t);
7573
7573
  if (typeof r.bind == "function") {
7574
7574
  let e = await r.bind(...n).all();
@@ -7580,37 +7580,37 @@ async function ui(e, t, n = []) {
7580
7580
  }
7581
7581
  return [];
7582
7582
  }
7583
- async function di(e, t, n = []) {
7583
+ async function fi(e, t, n = []) {
7584
7584
  let r = e.prepare(t);
7585
7585
  if (typeof r.bind == "function") return r.bind(...n).run();
7586
7586
  if (typeof r.run == "function") return r.run(...n);
7587
7587
  }
7588
- async function fi(e, t) {
7588
+ async function pi(e, t) {
7589
7589
  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);
7590
+ 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
7591
  } catch {
7592
7592
  return [];
7593
7593
  }
7594
7594
  }
7595
- async function pi(e, t) {
7595
+ async function mi(e, t) {
7596
7596
  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);
7597
+ 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
7598
  } catch (e) {
7599
7599
  return console.warn("[Cache] Failed to fetch descendant slugs:", e), [];
7600
7600
  }
7601
7601
  }
7602
- function mi(e) {
7602
+ function hi(e) {
7603
7603
  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
7604
  }
7605
- function hi(e) {
7605
+ function gi(e) {
7606
7606
  return +(e === !0 || e === 1 || e === "1" || e === "true");
7607
7607
  }
7608
- function gi(e) {
7608
+ function _i(e) {
7609
7609
  if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
7610
7610
  let t = Number(e);
7611
7611
  return isNaN(t) ? null : t;
7612
7612
  }
7613
- function _i(e) {
7613
+ function vi(e) {
7614
7614
  let t = { ...e };
7615
7615
  for (let e of [
7616
7616
  "id",
@@ -7639,17 +7639,17 @@ function _i(e) {
7639
7639
  ]) delete t[e];
7640
7640
  return t;
7641
7641
  }
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;
7642
+ function yi(e, t = /* @__PURE__ */ new Set()) {
7643
+ 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
7644
  }
7645
- async function yi(e, t, n) {
7645
+ async function bi(e, t, n) {
7646
7646
  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;
7647
+ let n = (await di(e, "\n SELECT id, storageKeyPrivate, isSystemVariant, parentAssetId, filename\n FROM assets WHERE id = ?\n ", [r]))[0];
7648
+ if (!n || (await di(e, "SELECT 1 FROM node_assets WHERE assetId = ? LIMIT 1", [n.id])).length > 0) continue;
7649
7649
  let i = [n];
7650
7650
  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;
7651
+ 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);
7652
+ if (r.length > 0 && (await di(e, `SELECT DISTINCT assetId FROM node_assets WHERE assetId IN (${r.map(() => "?").join(",")})`, r)).length > 0) continue;
7653
7653
  i = [n, ...t];
7654
7654
  }
7655
7655
  for (let e of i) if (e.storageKeyPrivate) try {
@@ -7658,10 +7658,10 @@ async function yi(e, t, n) {
7658
7658
  console.warn(`[Asset Cleanup] Failed to delete ${e.storageKeyPrivate}:`, t);
7659
7659
  }
7660
7660
  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);
7661
+ await fi(e, `DELETE FROM node_assets WHERE assetId IN (${o})`, a), await fi(e, `DELETE FROM assets WHERE id IN (${o})`, a);
7662
7662
  }
7663
7663
  }
7664
- async function bi(e, t, n) {
7664
+ async function xi(e, t, n) {
7665
7665
  let r = {}, i = null;
7666
7666
  if (t) {
7667
7667
  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 +7686,7 @@ async function bi(e, t, n) {
7686
7686
  inheritedFields: r
7687
7687
  };
7688
7688
  }
7689
- Z.get("/", async (e) => {
7689
+ X.get("/", async (e) => {
7690
7690
  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
7691
  if (n) {
7692
7692
  let r = Number(n);
@@ -7711,13 +7711,13 @@ Z.get("/", async (e) => {
7711
7711
  updatedAt: i.updatedAt
7712
7712
  }, s = i.draftDataJson || i.dataJson;
7713
7713
  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;
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 = ui(e.env?.BUNDLED_DEFINITIONS).nodes?.[i.contentType] || {}, l = n.layoutId || null;
7715
7715
  if (a) {
7716
- let { resolvedLayoutId: e, inheritedFields: r } = await bi(t, a.parentId, a.treeId);
7716
+ let { resolvedLayoutId: e, inheritedFields: r } = await xi(t, a.parentId, a.treeId);
7717
7717
  (l === "inherit" || !l) && (l = e || c.defaultLayout || null);
7718
7718
  for (let [e, t] of Object.entries(r)) (n[e] === void 0 || n[e] === null || n[e] === "") && t !== void 0 && (n[e] = t);
7719
7719
  } else (l === "inherit" || !l) && (l = c.defaultLayout || null);
7720
- let u = await oi(t, _i(n));
7720
+ let u = await si(t, vi(n));
7721
7721
  Object.assign(o, u), o.resolvedLayoutId = l;
7722
7722
  } catch {}
7723
7723
  let c = await t.prepare("SELECT channelId FROM node_channels WHERE nodeId = ?").all(r);
@@ -7727,7 +7727,7 @@ Z.get("/", async (e) => {
7727
7727
  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
7728
  let n = {};
7729
7729
  try {
7730
- n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {}, n && typeof n == "object" && (n = await oi(t, n));
7730
+ n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {}, n && typeof n == "object" && (n = await si(t, n));
7731
7731
  } catch {
7732
7732
  n = {};
7733
7733
  }
@@ -7827,7 +7827,7 @@ Z.get("/", async (e) => {
7827
7827
  assetCount: e.assetCount || 0
7828
7828
  }, i = e.draftDataJson || e.dataJson;
7829
7829
  if (i) try {
7830
- let e = typeof i == "string" ? JSON.parse(i) : i, n = await oi(t, _i(e));
7830
+ let e = typeof i == "string" ? JSON.parse(i) : i, n = await si(t, vi(e));
7831
7831
  Object.assign(r, n);
7832
7832
  } catch {}
7833
7833
  return r;
@@ -7839,107 +7839,88 @@ Z.get("/", async (e) => {
7839
7839
  offset: p,
7840
7840
  limit: f
7841
7841
  });
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();
7842
+ }), X.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, { 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
7844
  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 || "{}";
7845
+ 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
7846
  try {
7847
- vi(typeof r == "string" ? JSON.parse(r) : r, E);
7847
+ yi(typeof n == "string" ? JSON.parse(n) : n, T);
7848
7848
  } catch {}
7849
7849
  if (m !== void 0) {
7850
7850
  let e = await t.prepare("SELECT dataJson FROM content_blocks WHERE contentId = ? AND isDraft = 1").all(a);
7851
7851
  (Array.isArray(e) ? e : e?.results || []).forEach((e) => {
7852
7852
  try {
7853
- vi(typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson, E);
7853
+ yi(typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson, T);
7854
7854
  } catch {}
7855
7855
  });
7856
7856
  }
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
- }
7857
+ 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 = {};
7858
+ try {
7859
+ d = JSON.parse(u);
7860
+ } catch {}
7861
+ let f = JSON.stringify({
7862
+ ...d,
7863
+ ...v
7864
+ });
7865
+ 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
7866
  } 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);
7867
+ 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);
7868
+ w = Number(i.lastInsertRowid);
7884
7869
  }
7885
- if (h !== void 0 && Array.isArray(h) && T) {
7886
- await t.prepare("DELETE FROM node_channels WHERE nodeId = ?").run(T);
7870
+ if (h !== void 0 && Array.isArray(h) && w) {
7871
+ await t.prepare("DELETE FROM node_channels WHERE nodeId = ?").run(w);
7887
7872
  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
7873
  if (n.length > 0) {
7889
- let e = n.map(() => "(?, ?)").join(", "), r = n.flatMap((e) => [T, e]);
7874
+ let e = n.map(() => "(?, ?)").join(", "), r = n.flatMap((e) => [w, e]);
7890
7875
  await t.prepare(`INSERT OR IGNORE INTO node_channels (nodeId, channelId) VALUES ${e}`).run(...r);
7891
7876
  }
7892
7877
  }
7893
- if (g !== void 0 && Array.isArray(g) && T) {
7894
- await t.prepare("DELETE FROM tree_nodes WHERE contentId = ?").run(T);
7878
+ if (g !== void 0 && Array.isArray(g) && w) {
7879
+ await t.prepare("DELETE FROM tree_nodes WHERE contentId = ?").run(w);
7895
7880
  let e = /* @__PURE__ */ new Set(), n = [], r = [];
7896
7881
  for (let t of g) if (t && t.treeId) {
7897
7882
  let i = Number(t.treeId) || t.treeId;
7898
7883
  if (!e.has(i)) {
7899
7884
  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);
7885
+ let a = _i(t.parentId ?? t._draftParentId ?? null), o = typeof t.sortOrder == "number" ? t.sortOrder : 0;
7886
+ n.push("(?, ?, ?, ?)"), r.push(i, w, a, o);
7902
7887
  }
7903
7888
  }
7904
7889
  n.length > 0 && await t.prepare(`INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder) VALUES ${n.join(", ")}`).run(...r);
7905
7890
  }
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);
7891
+ let E = [];
7892
+ if (m !== void 0 && Array.isArray(m) && w) {
7893
+ await t.prepare("DELETE FROM content_blocks WHERE contentId = ? AND isDraft = 1").run(w);
7909
7894
  let e = [], n = [];
7910
7895
  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({
7896
+ 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
7897
  ...a,
7913
7898
  blockId: o,
7914
7899
  _instanceId: o
7915
7900
  });
7916
7901
  c.forEach((e) => {
7917
- D.push({
7902
+ E.push({
7918
7903
  ...e,
7919
7904
  fieldKey: `blocks[${t}].${e.fieldKey}`
7920
7905
  });
7921
7906
  });
7922
7907
  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);
7908
+ e.push("(?, ?, ?, ?, ?, 1)"), n.push(w, t, i, JSON.stringify(s), l);
7924
7909
  }
7925
7910
  e.length > 0 && await t.prepare(`INSERT INTO content_blocks (contentId, sortOrder, elementType, dataJson, region, isDraft) VALUES ${e.join(", ")}`).run(...n);
7926
7911
  }
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);
7912
+ if (w) {
7913
+ let n = [...y, ...E];
7914
+ await ai(t, w, n);
7915
+ let r = new Set(n.map((e) => e.assetId)), i = new Set([...T].filter((e) => !r.has(e)));
7916
+ i.size > 0 && await bi(t, ri(e.env), i);
7936
7917
  }
7937
- return e.json({
7918
+ return await q(e).clear(), e.json({
7938
7919
  success: !0,
7939
- id: T,
7920
+ id: w,
7940
7921
  status: "draft"
7941
7922
  });
7942
- }), Z.post("/publish", async (e) => {
7923
+ }), X.post("/publish", async (e) => {
7943
7924
  let t = e.get("db"), n = await e.req.json(), r = n.id || n.nodeId;
7944
7925
  if (!r || isNaN(Number(r))) return e.json({ error: "Node ID required for publishing" }, 400);
7945
7926
  let i = Number(r), a = e.get("user")?.id || null, o = await t.prepare("SELECT * FROM content_nodes WHERE id = ?").get(i);
@@ -7952,7 +7933,7 @@ Z.get("/", async (e) => {
7952
7933
  try {
7953
7934
  c = typeof o.draftDataJson == "string" ? JSON.parse(o.draftDataJson) : o.draftDataJson || {};
7954
7935
  } 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 || "{}";
7936
+ 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
7937
  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
7938
  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
7939
  if (g.length > 0) {
@@ -7972,12 +7953,11 @@ Z.get("/", async (e) => {
7972
7953
  },
7973
7954
  blocks: g
7974
7955
  };
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);
7956
+ await t.prepare("\n INSERT INTO node_revisions (nodeId, version, snapshotJson, createdById)\n VALUES (?, ?, ?, ?)\n ").run(i, _, v.publishedAt, a), await q(e).clear();
7957
+ let y = new Y(e.env);
7977
7958
  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);
7959
+ let b = await pi(t, i), x = await mi(t, i);
7960
+ if (y.purgeSmart(e, t, i, o.slug, b, p), !p && x.length > 0) for (let t of x) y.purgeAndWarmSlug(e, t);
7981
7961
  return e.json({
7982
7962
  success: !0,
7983
7963
  id: i,
@@ -7985,47 +7965,47 @@ Z.get("/", async (e) => {
7985
7965
  version: _,
7986
7966
  publishedAt: v.publishedAt
7987
7967
  });
7988
- }), Z.delete("/", async (e) => {
7968
+ }), X.delete("/", async (e) => {
7989
7969
  let t = e.get("db"), n = e.req.query("id");
7990
7970
  if (!n) return e.json({ error: "Node ID required" }, 400);
7991
7971
  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);
7972
+ await t.prepare("UPDATE content_nodes SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?").run(r), await q(e).clear();
7973
+ let a = new Y(e.env);
7994
7974
  if (i && await a.purgeInternalWorkerCache(e, t, r, i.slug, i.language || "en"), i && i.status === "published") {
7995
- let n = await fi(t, r);
7975
+ let n = await pi(t, r);
7996
7976
  a.purgeSmart(e, t, r, i.slug, n, !0);
7997
7977
  }
7998
7978
  return e.json({
7999
7979
  success: !0,
8000
7980
  deletedNodeId: r
8001
7981
  });
8002
- }), Z.post("/restore", async (e) => {
7982
+ }), X.post("/restore", async (e) => {
8003
7983
  let t = e.get("db"), n = await e.req.json(), r = Number(n.id);
8004
7984
  if (!r) return e.json({ error: "Node ID required" }, 400);
8005
7985
  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);
7986
+ await t.prepare("UPDATE content_nodes SET deletedAt = NULL WHERE id = ?").run(r), await q(e).clear();
7987
+ let a = new Y(e.env);
8008
7988
  if (i && await a.purgeInternalWorkerCache(e, t, r, i.slug, i.language || "en"), i && i.status === "published") {
8009
- let n = await fi(t, r);
7989
+ let n = await pi(t, r);
8010
7990
  a.purgeSmart(e, t, r, i.slug, n, !0);
8011
7991
  }
8012
7992
  return e.json({
8013
7993
  success: !0,
8014
7994
  restoredNodeId: r
8015
7995
  });
8016
- }), Z.delete("/purge", async (e) => {
7996
+ }), X.delete("/purge", async (e) => {
8017
7997
  let t = e.get("db"), n = e.req.query("id");
8018
7998
  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({
7999
+ 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);
8000
+ 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
8001
  success: !0,
8022
8002
  purgedNodeId: r
8023
8003
  });
8024
8004
  });
8025
8005
  //#endregion
8026
8006
  //#region server/routes/admin/trees.ts
8027
- var xi = new e();
8028
- function Si(e, t = null) {
8007
+ var Si = new e();
8008
+ function Ci(e, t = null) {
8029
8009
  let n = [];
8030
8010
  for (let r = 0; r < e.length; r++) {
8031
8011
  let i = e[r];
@@ -8037,19 +8017,19 @@ function Si(e, t = null) {
8037
8017
  id: o,
8038
8018
  parentId: t,
8039
8019
  sortOrder: r
8040
- }), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...Si(i.children, o)));
8020
+ }), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...Ci(i.children, o)));
8041
8021
  }
8042
8022
  return n;
8043
8023
  }
8044
- function Ci(e) {
8024
+ function wi(e) {
8045
8025
  if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
8046
8026
  let t = Number(e);
8047
8027
  return isNaN(t) ? null : t;
8048
8028
  }
8049
- function wi(e) {
8029
+ function Ti(e) {
8050
8030
  return +(e === !0 || e === 1 || e === "1" || e === "true");
8051
8031
  }
8052
- xi.get("/tree.json", async (e) => {
8032
+ Si.get("/tree.json", async (e) => {
8053
8033
  try {
8054
8034
  let t = e.get("db"), n = e.req.query("treeId") || "main-nav", r = e.req.query("preview") === "true", i = 1;
8055
8035
  if (isNaN(Number(n))) {
@@ -8099,9 +8079,9 @@ xi.get("/tree.json", async (e) => {
8099
8079
  } catch (t) {
8100
8080
  return console.error("[CMS Tree API] GET Error:", t), e.json({ error: t.message || "Failed to fetch tree" }, 500);
8101
8081
  }
8102
- }), xi.post("/tree.json", async (e) => {
8082
+ }), Si.post("/tree.json", async (e) => {
8103
8083
  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;
8084
+ 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
8085
  if (isNaN(Number(r))) {
8106
8086
  let e = await t.prepare("SELECT id FROM trees WHERE key = ?").get(r);
8107
8087
  if (e && e.id) o = Number(e.id);
@@ -8111,7 +8091,7 @@ xi.get("/tree.json", async (e) => {
8111
8091
  }
8112
8092
  } else o = Number(r);
8113
8093
  if (n.tree && Array.isArray(n.tree)) {
8114
- let r = Si(n.tree, null);
8094
+ let r = Ci(n.tree, null);
8115
8095
  if (r.length > 0) for (let e = 0; e < r.length; e += 50) {
8116
8096
  let n = r.slice(e, e + 50), i = n.map((e) => e.id), a = i.map(() => "?").join(","), s = "UPDATE tree_nodes SET \n";
8117
8097
  s += "parentId = CASE id \n", n.forEach(() => {
@@ -8126,14 +8106,14 @@ xi.get("/tree.json", async (e) => {
8126
8106
  c.push(e.id, e.sortOrder);
8127
8107
  }), c.push(...i), c.push(o), await t.prepare(s).run(...c);
8128
8108
  }
8129
- return await i.clear(), e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(a.purgeGlobalCache(e)) : await a.purgeGlobalCache(e), e.json({
8109
+ 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
8110
  success: !0,
8131
8111
  reorderedCount: r.length
8132
8112
  });
8133
8113
  }
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);
8114
+ 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
8115
  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;
8116
+ let g = wi(u), _ = e.get("user")?.id || null;
8137
8117
  if (s === "create") {
8138
8118
  let r = m.slug || n.slug || c, s = r ? String(r).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "") : null;
8139
8119
  if (s) {
@@ -8165,7 +8145,7 @@ xi.get("/tree.json", async (e) => {
8165
8145
  let e = b.map(() => "(?, ?)").join(", "), n = b.flatMap((e) => [f, e]);
8166
8146
  await t.prepare(`INSERT OR IGNORE INTO node_channels (nodeId, channelId) VALUES ${e}`).run(...n);
8167
8147
  }
8168
- return await i.clear(), e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(a.purgeGlobalCache(e)) : await a.purgeGlobalCache(e), e.json({
8148
+ 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
8149
  success: !0,
8170
8150
  id: f,
8171
8151
  treeNodeId: v,
@@ -8203,14 +8183,14 @@ xi.get("/tree.json", async (e) => {
8203
8183
  }
8204
8184
  await t.prepare("DELETE FROM tree_nodes WHERE treeId = ? AND contentId = ?").run(o, d);
8205
8185
  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({
8186
+ 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
8187
  success: !0,
8208
8188
  treeNodeId: s
8209
8189
  });
8210
8190
  }
8211
8191
  if (s === "detach") {
8212
8192
  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);
8193
+ 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
8194
  }
8215
8195
  return e.json({ error: "Invalid payload or action" }, 400);
8216
8196
  } catch (t) {
@@ -8219,7 +8199,7 @@ xi.get("/tree.json", async (e) => {
8219
8199
  details: t.message
8220
8200
  }, 500);
8221
8201
  }
8222
- }), xi.get("/trees.json", async (e) => {
8202
+ }), Si.get("/trees.json", async (e) => {
8223
8203
  try {
8224
8204
  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
8205
  let n = Number(t.treeId), r = Number(t.channelId);
@@ -8249,7 +8229,7 @@ xi.get("/tree.json", async (e) => {
8249
8229
  } catch {
8250
8230
  return e.json([]);
8251
8231
  }
8252
- }), xi.post("/trees.json", async (e) => {
8232
+ }), Si.post("/trees.json", async (e) => {
8253
8233
  try {
8254
8234
  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
8235
  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 +8254,9 @@ xi.get("/tree.json", async (e) => {
8274
8254
  await t.prepare(`INSERT OR IGNORE INTO channel_trees (channelId, treeId, key) VALUES ${n}`).run(...r);
8275
8255
  }
8276
8256
  }
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({
8257
+ await q(e).clear();
8258
+ let m = new Y(e.env);
8259
+ return e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(m.purgeGlobalCacheDirect(e, t)) : await m.purgeGlobalCacheDirect(e, t), e.json({
8280
8260
  success: !0,
8281
8261
  id: p,
8282
8262
  key: o,
@@ -8290,14 +8270,14 @@ xi.get("/tree.json", async (e) => {
8290
8270
  } catch (t) {
8291
8271
  return console.error("[API Trees] Error saving tree:", t), e.json({ error: t.message || "Failed to save tree" }, 500);
8292
8272
  }
8293
- }), xi.delete("/trees.json", async (e) => {
8273
+ }), Si.delete("/trees.json", async (e) => {
8294
8274
  let t = e.get("db"), n = e.req.query("id");
8295
8275
  if (!n) return e.json({ error: "Tree ID required" }, 400);
8296
8276
  let r = Number(n);
8297
8277
  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({
8278
+ 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();
8279
+ let n = new Y(e.env);
8280
+ return e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(n.purgeGlobalCacheDirect(e, t)) : await n.purgeGlobalCacheDirect(e, t), e.json({
8301
8281
  success: !0,
8302
8282
  deletedTreeId: r
8303
8283
  });
@@ -8307,8 +8287,8 @@ xi.get("/tree.json", async (e) => {
8307
8287
  });
8308
8288
  //#endregion
8309
8289
  //#region server/routes/admin/channels.ts
8310
- var Ti = new e();
8311
- Ti.get("/", async (e) => {
8290
+ var Ei = new e();
8291
+ Ei.get("/", async (e) => {
8312
8292
  try {
8313
8293
  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
8294
  e[t.channelId] || (e[t.channelId] = []);
@@ -8332,7 +8312,7 @@ Ti.get("/", async (e) => {
8332
8312
  isHidden: !!e.isHidden,
8333
8313
  trees: a[e.id] || []
8334
8314
  };
8335
- }), s = e.env?.BUNDLED_DEFINITIONS, c = li(s)?.channelTemplate || {
8315
+ }), s = e.env?.BUNDLED_DEFINITIONS, c = ui(s)?.channelTemplate || {
8336
8316
  label: "Channel Settings",
8337
8317
  fields: {
8338
8318
  key: {
@@ -8374,7 +8354,7 @@ Ti.get("/", async (e) => {
8374
8354
  error: t.message
8375
8355
  }, 500);
8376
8356
  }
8377
- }), Ti.post("/", async (e) => {
8357
+ }), Ei.post("/", async (e) => {
8378
8358
  try {
8379
8359
  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
8360
  if (await t.prepare("SELECT id FROM channels WHERE key = ? AND id != ? LIMIT 1").get(y, i ?? -1)) return e.json({
@@ -8401,7 +8381,9 @@ Ti.get("/", async (e) => {
8401
8381
  VALUES ${e}
8402
8382
  `).run(...n);
8403
8383
  }
8404
- return await J(e).clear(), new X(e.env).purgeGlobalCache(e), e.json({
8384
+ await q(e).clear();
8385
+ let E = new Y(e.env);
8386
+ return e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(E.purgeGlobalCacheDirect(e, t)) : await E.purgeGlobalCacheDirect(e, t), e.json({
8405
8387
  success: !0,
8406
8388
  id: w
8407
8389
  });
@@ -8411,12 +8393,14 @@ Ti.get("/", async (e) => {
8411
8393
  details: t.message
8412
8394
  }, 500);
8413
8395
  }
8414
- }), Ti.delete("/", async (e) => {
8396
+ }), Ei.delete("/", async (e) => {
8415
8397
  let t = e.get("db"), n = e.req.query("id");
8416
8398
  if (!n) return e.json({ error: "Channel ID required" }, 400);
8417
8399
  let r = Number(n);
8418
8400
  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({
8401
+ 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();
8402
+ let n = new Y(e.env);
8403
+ return e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(n.purgeGlobalCacheDirect(e, t)) : await n.purgeGlobalCacheDirect(e, t), e.json({
8420
8404
  success: !0,
8421
8405
  deletedSiteId: r
8422
8406
  });
@@ -8429,10 +8413,10 @@ Ti.get("/", async (e) => {
8429
8413
  });
8430
8414
  //#endregion
8431
8415
  //#region server/routes/admin/schemas.ts
8432
- var Ei = new e(), Di = null, Oi = (e) => {
8416
+ var Di = new e(), Oi = null, ki = (e) => {
8433
8417
  try {
8434
- if (!Di) {
8435
- let t = ci(e.env?.BUNDLED_DEFINITIONS || Or), n = t.userTemplate || {
8418
+ if (!Oi) {
8419
+ let t = li(e.env?.BUNDLED_DEFINITIONS || kr), n = t.userTemplate || {
8436
8420
  id: "userTemplate",
8437
8421
  label: "User Account",
8438
8422
  fields: {
@@ -8468,7 +8452,7 @@ var Ei = new e(), Di = null, Oi = (e) => {
8468
8452
  }
8469
8453
  }
8470
8454
  };
8471
- Di = {
8455
+ Oi = {
8472
8456
  channelTemplate: t.channelTemplate || null,
8473
8457
  treeTemplate: t.treeTemplate || null,
8474
8458
  userTemplate: n,
@@ -8480,7 +8464,7 @@ var Ei = new e(), Di = null, Oi = (e) => {
8480
8464
  blockLayouts: t.blockLayouts || {}
8481
8465
  };
8482
8466
  }
8483
- return e.json(Di, 200, { "Cache-Control": "public, max-age=300, stale-while-revalidate=86400" });
8467
+ return e.json(Oi, 200, { "Cache-Control": "public, max-age=300, stale-while-revalidate=86400" });
8484
8468
  } catch (t) {
8485
8469
  return console.error("[CMS API] Error loading schemas:", t), e.json({
8486
8470
  error: "Failed to load schemas",
@@ -8488,10 +8472,10 @@ var Ei = new e(), Di = null, Oi = (e) => {
8488
8472
  }, 500);
8489
8473
  }
8490
8474
  };
8491
- Ei.get("/", Oi), Ei.get("/schemas.json", Oi);
8475
+ Di.get("/", ki), Di.get("/schemas.json", ki);
8492
8476
  //#endregion
8493
8477
  //#region server/routes/admin/validation.ts
8494
- var ki = new e(), Ai = {
8478
+ var Ai = new e(), ji = {
8495
8479
  node: "content_nodes",
8496
8480
  nodes: "content_nodes",
8497
8481
  content_node: "content_nodes",
@@ -8503,7 +8487,7 @@ var ki = new e(), Ai = {
8503
8487
  user: "users",
8504
8488
  users: "users",
8505
8489
  user_account: "user_accounts"
8506
- }, ji = {
8490
+ }, Mi = {
8507
8491
  content_nodes: [
8508
8492
  "id",
8509
8493
  "title",
@@ -8560,11 +8544,11 @@ var ki = new e(), Ai = {
8560
8544
  "createdAt"
8561
8545
  ]
8562
8546
  };
8563
- ki.post("/validate-unique", async (e) => {
8547
+ Ai.post("/validate-unique", async (e) => {
8564
8548
  try {
8565
8549
  let t = e.get("db"), { entityType: n, field: r, value: i, excludeId: a } = await e.req.json();
8566
8550
  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;
8551
+ 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
8552
  if (a != null && String(a).trim() !== "") {
8569
8553
  let e = Number(a);
8570
8554
  l = isNaN(e) ? String(a) : e;
@@ -8576,7 +8560,7 @@ ki.post("/validate-unique", async (e) => {
8576
8560
  } catch (t) {
8577
8561
  return console.error("[API Validation] Error validating global uniqueness:", t), e.json({ error: "Failed to validate uniqueness" }, 500);
8578
8562
  }
8579
- }), ki.post("/validate-unique-sibling", async (e) => {
8563
+ }), Ai.post("/validate-unique-sibling", async (e) => {
8580
8564
  try {
8581
8565
  let t = e.get("db"), { slug: n, treeId: r, parentId: i, excludeTreeNodeId: a } = await e.req.json();
8582
8566
  if (!n || !String(n).trim() || !r) return e.json({ isUnique: !0 });
@@ -8603,8 +8587,8 @@ ki.post("/validate-unique", async (e) => {
8603
8587
  });
8604
8588
  //#endregion
8605
8589
  //#region server/routes/admin/stats.ts
8606
- var Mi = new e();
8607
- Mi.get("/", async (e) => {
8590
+ var Ni = new e();
8591
+ Ni.get("/", async (e) => {
8608
8592
  try {
8609
8593
  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
8594
  ...e,
@@ -8619,7 +8603,7 @@ Mi.get("/", async (e) => {
8619
8603
  isHidden: !!e.isHidden,
8620
8604
  channelNames: e.channelLabels ? e.channelLabels.split(",") : [],
8621
8605
  treeNames: e.treeLabels ? e.treeLabels.split(",") : []
8622
- })), p = e.env?.BUNDLED_DEFINITIONS, m = ci(p), h = m.nodes || m.nodeSchemas || {}, g = c.map((e) => {
8606
+ })), p = e.env?.BUNDLED_DEFINITIONS, m = li(p), h = m.nodes || m.nodeSchemas || {}, g = c.map((e) => {
8623
8607
  let t = e.type || "node", n = h[t]?.label || t.charAt(0).toUpperCase() + t.slice(1);
8624
8608
  return {
8625
8609
  type: t,
@@ -8647,7 +8631,7 @@ Mi.get("/", async (e) => {
8647
8631
  });
8648
8632
  //#endregion
8649
8633
  //#region server/routes/admin/assets.ts
8650
- var Ni = new e();
8634
+ var Z = new e();
8651
8635
  async function Q(e, t, n = []) {
8652
8636
  let r = e.prepare(t);
8653
8637
  if (typeof r.bind == "function") {
@@ -8671,7 +8655,7 @@ function Fi(e, t, n) {
8671
8655
  }
8672
8656
  async function Ii(e, t, n) {
8673
8657
  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 = [];
8658
+ 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
8659
  for (let t of i) {
8676
8660
  let n = Fi(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN);
8677
8661
  n && a.push(n);
@@ -8682,12 +8666,12 @@ async function Ii(e, t, n) {
8682
8666
  n
8683
8667
  ]);
8684
8668
  if (o.length === 0) return;
8685
- for (let n of o) n.id && r.purgeSmart(e, t, n.id, n.slug, a);
8669
+ for (let n of o) n.id && n.slug && r.purgeSmart(e, t, n.id, n.slug, a, !1);
8686
8670
  } catch (e) {
8687
8671
  console.warn("[Assets Router] Failed to purge edge cache for asset nodes:", e);
8688
8672
  }
8689
8673
  }
8690
- Ni.get("/", async (e) => {
8674
+ Z.get("/", async (e) => {
8691
8675
  try {
8692
8676
  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
8677
  createdAt: "a.createdAt",
@@ -8778,9 +8762,9 @@ Ni.get("/", async (e) => {
8778
8762
  details: t.message || String(t)
8779
8763
  }, 500);
8780
8764
  }
8781
- }), Ni.post("/upload", async (e) => {
8765
+ }), Z.post("/upload", async (e) => {
8782
8766
  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;
8767
+ 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
8768
  s && (await Q(t, "SELECT id FROM assets WHERE id = ?", [s])).length === 0 && (s = null);
8785
8769
  let c = r.cropCoordinates, l = null, d = null;
8786
8770
  if (c) {
@@ -8831,7 +8815,7 @@ Ni.get("/", async (e) => {
8831
8815
  details: t.message || String(t)
8832
8816
  }, 500);
8833
8817
  }
8834
- }), Ni.get("/:id/details", async (e) => {
8818
+ }), Z.get("/:id/details", async (e) => {
8835
8819
  try {
8836
8820
  let t = u(e), n = e.req.param("id"), r = await Q(t, "SELECT * FROM assets WHERE id = ?", [n]);
8837
8821
  if (!r || r.length === 0) return e.json({ error: "Asset not found" }, 404);
@@ -8889,7 +8873,7 @@ Ni.get("/", async (e) => {
8889
8873
  } catch (t) {
8890
8874
  return console.error("❌ [Asset Details Error]:", t), e.json({ error: "Failed to load details" }, 500);
8891
8875
  }
8892
- }), Ni.put("/:id", async (e) => {
8876
+ }), Z.put("/:id", async (e) => {
8893
8877
  try {
8894
8878
  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
8879
  if (!i || i.length === 0) return e.json({ error: "Asset not found" }, 404);
@@ -8905,7 +8889,7 @@ Ni.get("/", async (e) => {
8905
8889
  } catch (t) {
8906
8890
  return console.error("❌ [Asset Update Error]:", t), e.json({ error: "Failed to update asset" }, 500);
8907
8891
  }
8908
- }), Ni.delete("/:id", async (e) => {
8892
+ }), Z.delete("/:id", async (e) => {
8909
8893
  try {
8910
8894
  let t = u(e), n = e.req.param("id"), r = (await Q(t, "SELECT id, filename, isSystemVariant FROM assets WHERE id = ?", [n]))[0];
8911
8895
  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 +8908,7 @@ Ni.get("/", async (e) => {
8924
8908
  details: t.message || String(t)
8925
8909
  }, 500);
8926
8910
  }
8927
- }), Ni.post("/restore", async (e) => {
8911
+ }), Z.post("/restore", async (e) => {
8928
8912
  try {
8929
8913
  let t = u(e), n = await e.req.json(), r = n.id || n.assetId;
8930
8914
  if (!r) return e.json({ error: "Asset ID required" }, 400);
@@ -8945,9 +8929,9 @@ Ni.get("/", async (e) => {
8945
8929
  details: t.message
8946
8930
  }, 500);
8947
8931
  }
8948
- }), Ni.delete("/purge/:id", async (e) => {
8932
+ }), Z.delete("/purge/:id", async (e) => {
8949
8933
  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];
8934
+ 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
8935
  if (!i) return e.json({ error: "Asset not found" }, 404);
8952
8936
  await Ii(e, t, r);
8953
8937
  let a = [i];
@@ -9102,7 +9086,7 @@ async function Hi(e, t, n, r, i = !1, a) {
9102
9086
  let o = a.hidden === !0 || a.hidden === 1 || a.hidden === "1" || a.hidden === "true", s = Bi(a.startShowingAt, a.stopShowingAt);
9103
9087
  if (!i && (o || !s)) return null;
9104
9088
  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, {
9089
+ return d = await si(e, d), d = Wi(d), d.blockId = u, {
9106
9090
  region: t.region || n,
9107
9091
  block: {
9108
9092
  instanceId: t.id,
@@ -9355,12 +9339,12 @@ Li.get("/*", async (e) => {
9355
9339
  if (!c) return e.json({ error: `Channel '${a}' not found` }, 404);
9356
9340
  let l = c.status === "disabled" || c.status === "inactive" || c.isEnabled === 0 || c.isEnabled === !1;
9357
9341
  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";
9342
+ 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
9343
  if (!s && !m) {
9360
9344
  let t = await f.get(p);
9361
9345
  if (t) return e.header("X-Cache", "HIT"), e.json(t);
9362
9346
  }
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 = `
9347
+ 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
9348
  SELECT
9365
9349
  cn.*,
9366
9350
  tn.id as treeNodeId,
@@ -9420,7 +9404,7 @@ Li.get("/*", async (e) => {
9420
9404
  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
9405
  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
9406
  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));
9407
+ let F = await si(t, Ui(M, j));
9424
9408
  F = Wi(F), F = await Gi(t, F, n);
9425
9409
  let ue = Xi(F);
9426
9410
  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 +9441,7 @@ Li.get("/*", async (e) => {
9457
9441
  let a = i.hidden === !0 || i.hidden === 1 || i.hidden === "1" || i.hidden === "true", o = Bi(i.startShowingAt, i.stopShowingAt);
9458
9442
  if (!s && (a || !o)) return null;
9459
9443
  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, {
9444
+ return d = await si(t, d), d = Wi(d), d = await Gi(t, d, n), d.blockId = u, {
9461
9445
  region: r,
9462
9446
  block: {
9463
9447
  instanceId: e.id,
@@ -9545,7 +9529,7 @@ ta.get("/:treeParam", async (e) => {
9545
9529
  if (!i && t) return e.json({ error: `Channel '${n.key || r}' is currently inactive` }, 404);
9546
9530
  }
9547
9531
  }
9548
- let a = J(e), o = `tree:${r}:${n}`, s = e.req.header("x-bypass-cache") === "true";
9532
+ let a = q(e), o = `tree:${r}:${n}`, s = e.req.header("x-bypass-cache") === "true";
9549
9533
  if (!i && !s) {
9550
9534
  let t = await a.get(o);
9551
9535
  if (t) return e.header("X-Cache", "HIT"), e.json(t);
@@ -9554,7 +9538,7 @@ ta.get("/:treeParam", async (e) => {
9554
9538
  if (l && Number(l.isHidden) === 1 && !i) return e.json({ error: `Tree '${n}' is hidden` }, 404);
9555
9539
  let u = l?.id || (c ? Number(n) : null), d = {};
9556
9540
  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 || {};
9541
+ 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
9542
  for (let [e, n] of Object.entries(t)) a[e]?.public === !0 && (d[e] = n);
9559
9543
  } catch (e) {
9560
9544
  console.warn("[CMS Public Tree API] Failed to parse tree dataJson", e);
@@ -9834,12 +9818,12 @@ $.use("*", o()), $.use("/media/*", o({
9834
9818
  e.set("currentDomain", r);
9835
9819
  let i = u(e);
9836
9820
  if (e.set("db", i), !ca) try {
9837
- await Mr(i), ca = !0;
9821
+ await Nr(i), ca = !0;
9838
9822
  } catch (e) {
9839
9823
  console.error("❌ [CMS Server] Failed to initialize system tables on cold start:", e);
9840
9824
  }
9841
9825
  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) => {
9826
+ }), $.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
9827
  if (e.env?.ASSETS) {
9844
9828
  let t = await e.env.ASSETS.fetch(e.req.raw);
9845
9829
  if (t.status === 404) {