@blocklet/pages-kit-inner-components 0.6.97 → 0.6.99

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.
@@ -1,43 +1,43 @@
1
- import { d as Ne, l as f, I as et, c as tt, m as st, b as ot } from "./components-DLwSTd_N.js";
2
- import { getYjsValue as V, syncedStore as at } from "@syncedstore/core";
3
- import * as _ from "yjs";
4
- import { setPageDataSource as nt } from "@blocklet/pages-kit/utils/data-source";
5
- import { getRouteMetaDataByOptionIds as rt, generateParamCombinations as Ie } from "@blocklet/pages-kit/utils/route";
1
+ import { d as Fe, l as f, I as tt, c as st, m as ot, b as at } from "./components-DLwSTd_N.js";
2
+ import { getYjsValue as V, syncedStore as nt } from "@syncedstore/core";
3
+ import * as N from "yjs";
4
+ import { setPageDataSource as rt } from "@blocklet/pages-kit/utils/data-source";
5
+ import { getRouteMetaDataByOptionIds as it, generateParamCombinations as Ie } from "@blocklet/pages-kit/utils/route";
6
6
  import Ee from "lodash/cloneDeep";
7
7
  import E from "@blocklet/sdk/lib/config";
8
- import { mkdtempSync as it, existsSync as M, readFileSync as J, renameSync as Re, mkdirSync as N, rmSync as Fe, writeFileSync as te, copyFileSync as ct, lstatSync as x, readdirSync as lt, createWriteStream as pt } from "fs";
8
+ import { mkdtempSync as ct, existsSync as $, readFileSync as J, renameSync as je, mkdirSync as _, rmSync as Ge, writeFileSync as te, copyFileSync as lt, lstatSync as x, readdirSync as pt, createWriteStream as ut } from "fs";
9
9
  import { join as b, basename as k, dirname as L } from "path";
10
- import { nextId as je } from "@blocklet/pages-kit/utils/common";
11
- import { unzipSection as ut } from "@blocklet/pages-kit/utils/page-model";
12
- import { getComponentDependencies as dt } from "@blocklet/pages-kit/utils/property";
13
- import { getComponentWebEndpoint as ft, getResources as mt, call as gt } from "@blocklet/sdk/lib/component";
14
- import { reactive as ht } from "@reactivedata/reactive";
10
+ import { nextId as De } from "@blocklet/pages-kit/utils/common";
11
+ import { unzipSection as dt } from "@blocklet/pages-kit/utils/page-model";
12
+ import { getComponentDependencies as ft } from "@blocklet/pages-kit/utils/property";
13
+ import { getComponentWebEndpoint as mt, getResources as gt, call as ht } from "@blocklet/sdk/lib/component";
14
+ import { reactive as yt } from "@reactivedata/reactive";
15
15
  import { globSync as se } from "glob";
16
16
  import * as de from "lib0/decoding";
17
17
  import * as D from "lib0/encoding";
18
- import Ge from "lodash/debounce";
18
+ import xe from "lodash/debounce";
19
19
  import be from "lodash/get";
20
20
  import Ae from "lodash/isEmpty";
21
- import De from "lodash/set";
22
- import yt from "lodash/union";
21
+ import Te from "lodash/set";
22
+ import St from "lodash/union";
23
23
  import { LRUCache as we } from "lru-cache";
24
- import St from "p-limit";
25
- import { DataTypes as R, Sequelize as It, Model as xe, Op as Pe } from "sequelize";
26
- import { pipeline as Et } from "stream/promises";
27
- import { x as bt } from "tar";
28
- import { withoutTrailingSlash as Be, withLeadingSlash as At, joinURL as Y } from "ufo";
24
+ import It from "p-limit";
25
+ import { DataTypes as R, Sequelize as Et, Model as Be, Op as Pe } from "sequelize";
26
+ import { pipeline as bt } from "stream/promises";
27
+ import { x as At } from "tar";
28
+ import { withoutTrailingSlash as Oe, withLeadingSlash as Ve, joinURL as Y } from "ufo";
29
29
  import wt from "wait-on";
30
- import { Awareness as Pt, encodeAwarenessUpdate as Te, removeAwarenessStates as Ot, applyAwarenessUpdate as Ct } from "y-protocols/awareness";
30
+ import { Awareness as Pt, encodeAwarenessUpdate as ke, removeAwarenessStates as Ot, applyAwarenessUpdate as Ct } from "y-protocols/awareness";
31
31
  import { writeUpdate as vt, writeSyncStep1 as Rt, readSyncMessage as jt } from "y-protocols/sync";
32
32
  import * as B from "yaml";
33
- import { m as ke } from "./html-DOgzvdOd.js";
33
+ import { m as Le } from "./html-DOgzvdOd.js";
34
34
  import "sqlite3";
35
35
  import "@blocklet/pages-kit/types/state";
36
36
  const Dt = R.sqlite.DATE.parse;
37
37
  R.sqlite.DATE.parse = (t, e) => typeof t == "number" ? new Date(t) : Dt(t, e);
38
- const F = new It({
38
+ const F = new Et({
39
39
  dialect: "sqlite",
40
- storage: Ne,
40
+ storage: Fe,
41
41
  benchmark: process.env.ENABLE_SEQUELIZE_BENCHMARK === "true",
42
42
  retry: {
43
43
  match: [/SQLITE_BUSY/],
@@ -76,16 +76,16 @@ let ge = null;
76
76
  ge && clearInterval(ge);
77
77
  ge = setInterval(
78
78
  async () => {
79
- f.info("Start cleanupSqliteMemory"), await Tt(F, Ne), f.info("End cleanupSqliteMemory");
79
+ f.info("Start cleanupSqliteMemory"), await Tt(F, Fe), f.info("End cleanupSqliteMemory");
80
80
  },
81
81
  60 * 1e3 * 10
82
82
  // 10 minutes
83
83
  );
84
- const kt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", Le = "page", he = "trigger-reload-project-resource", Ve = kt, Lt = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM", Ut = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o";
85
- class Oe extends xe {
84
+ const kt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", Ue = "page", he = "trigger-reload-project-resource", ze = kt, Lt = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM", Ut = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o";
85
+ class Ce extends Be {
86
86
  // Foreign key to Component
87
87
  }
88
- Oe.init(
88
+ Ce.init(
89
89
  {
90
90
  id: {
91
91
  type: R.UUID,
@@ -104,22 +104,22 @@ Oe.init(
104
104
  },
105
105
  { sequelize: F, tableName: "ProjectComponents", timestamps: !1 }
106
106
  );
107
- const $t = "SLUG_INVALID", K = (t) => ({
107
+ const Mt = "SLUG_INVALID", K = (t) => ({
108
108
  error: "slugInvalid",
109
- code: $t,
109
+ code: Mt,
110
110
  field: "slug",
111
111
  message: t
112
- }), Mt = {
112
+ }), $t = {
113
113
  error: "slugRequired",
114
114
  code: "SLUG_REQUIRED",
115
115
  field: "slug",
116
116
  message: () => "Project slug is required"
117
- }, _t = {
117
+ }, Nt = {
118
118
  error: "slugAlreadyExists",
119
119
  code: "SLUG_EXISTS",
120
120
  field: "slug",
121
121
  message: (t) => `Project slug "${t}" already exists`
122
- }, Nt = [
122
+ }, _t = [
123
123
  /\.\./,
124
124
  // Directory traversal
125
125
  /<[^>]*>/,
@@ -135,21 +135,19 @@ const $t = "SLUG_INVALID", K = (t) => ({
135
135
  // Control characters
136
136
  /[^a-zA-Z0-9-_@/\\:]/
137
137
  // Only allow specific characters
138
- ], Ue = (t) => {
138
+ ], Me = (t) => {
139
139
  if (!t) return "";
140
140
  if (t === "/") return "/";
141
- const e = Be(t);
142
- return At(e) || "/";
141
+ const e = Oe(t);
142
+ return Ve(e) || "/";
143
143
  }, Ft = (t) => t.did === Ut;
144
- class U extends xe {
144
+ class U extends Be {
145
145
  static async getProjectByIdOrSlug(e, s) {
146
146
  return e ? U.findOne({
147
147
  where: {
148
148
  [Pe.or]: [{ id: e }, { slug: e }],
149
149
  ...s?.createdBy ? { createdBy: s.createdBy } : {}
150
- },
151
- // 软删除
152
- paranoid: !1
150
+ }
153
151
  }) : null;
154
152
  }
155
153
  static async validateProjectSlug({
@@ -159,20 +157,22 @@ class U extends xe {
159
157
  if (e == null)
160
158
  return null;
161
159
  if (e === "")
162
- return Mt;
163
- const o = Ue(e);
164
- if (e !== "/" && e.endsWith("/"))
160
+ return $t;
161
+ const o = e === "/" ? "/" : Oe(Ve(e)), a = Me(o);
162
+ if (o !== "/" && o.endsWith("/"))
165
163
  return K((r) => `Project slug "${r}" cannot end with /`);
166
- if (/\/{2,}/.test(e))
164
+ if (/\/{2,}/.test(o))
167
165
  return K((r) => `Project slug "${r}" cannot contain consecutive /`);
168
- if (/\s/.test(e))
166
+ if (/\s/.test(o))
169
167
  return K((r) => `Project slug "${r}" cannot contain whitespace`);
170
- if (Nt.some((r) => r.test(e)))
168
+ if (_t.some((r) => r.test(o)))
171
169
  return K((r) => `Project slug "${r}" contains invalid characters`);
172
- if (E.components?.filter((r) => r.mountPoint && !Ft(r)).some((r) => Ue(r.mountPoint) === o))
170
+ if (E.components?.filter((r) => r.mountPoint && !Ft(r)).some((r) => Me(r.mountPoint) === a))
173
171
  return K((r) => `Project slug "${r}" conflicts with existing blocklet`);
174
- const n = await U.findOne({ where: { slug: `${e}` } });
175
- return n && n?.id !== s ? _t : null;
172
+ const c = await U.findOne({
173
+ where: { slug: o }
174
+ });
175
+ return c && c?.id !== s ? Nt : null;
176
176
  }
177
177
  }
178
178
  U.init(
@@ -279,7 +279,7 @@ U.init(
279
279
  ]
280
280
  }
281
281
  );
282
- U.hasMany(Oe, {
282
+ U.hasMany(Ce, {
283
283
  foreignKey: "projectId",
284
284
  as: "components"
285
285
  });
@@ -288,8 +288,8 @@ function oe(t) {
288
288
  e.some((s) => s.changes.keys.has("updatedAt") || s.changes.keys.has("publishedAt")) || t.set("updatedAt", (/* @__PURE__ */ new Date()).toISOString());
289
289
  });
290
290
  }
291
- function ze() {
292
- return it(b(E.env.dataDir, "tmp-"));
291
+ function qe() {
292
+ return ct(b(E.env.dataDir, "tmp-"));
293
293
  }
294
294
  function ae(t, e, s = []) {
295
295
  return Array.isArray(t) ? t.flatMap((o, a) => ae(o, e, [...s, a])) : typeof t == "object" ? t === null ? [] : Object.entries(t).flatMap(([o, a]) => ae(a, e, [...s, o])) : e(t) ? [s] : [];
@@ -300,14 +300,14 @@ function T(t) {
300
300
  function Gt(t) {
301
301
  t.pages && Object.keys(t.pages).forEach((s) => {
302
302
  const o = V(t.pages[s]);
303
- o && o instanceof _.Map && oe(o);
303
+ o && o instanceof N.Map && oe(o);
304
304
  });
305
305
  const e = V(t.pages);
306
- e && e instanceof _.Map && e.observe((s) => {
306
+ e && e instanceof N.Map && e.observe((s) => {
307
307
  s.changes.keys.forEach((o, a) => {
308
308
  if (o.action === "add") {
309
309
  const n = V(t.pages[a]);
310
- n && n instanceof _.Map && oe(n);
310
+ n && n instanceof N.Map && oe(n);
311
311
  }
312
312
  });
313
313
  });
@@ -315,14 +315,14 @@ function Gt(t) {
315
315
  function xt(t) {
316
316
  t.routes && Object.keys(t.routes).forEach((s) => {
317
317
  const o = V(t.routes?.[s]);
318
- o && o instanceof _.Map && oe(o);
318
+ o && o instanceof N.Map && oe(o);
319
319
  });
320
320
  const e = V(t.routes);
321
- e && e instanceof _.Map && e.observe((s) => {
321
+ e && e instanceof N.Map && e.observe((s) => {
322
322
  s.changes.keys.forEach((o, a) => {
323
323
  if (o.action === "add") {
324
324
  const n = V(t.routes?.[a]);
325
- n && n instanceof _.Map && oe(n);
325
+ n && n instanceof N.Map && oe(n);
326
326
  }
327
327
  });
328
328
  });
@@ -331,8 +331,8 @@ function Bt(t, e) {
331
331
  for (const s of e || Object.keys(t.routes || {})) {
332
332
  let o = s, a = [];
333
333
  if (s.includes("-")) {
334
- const [n, ...r] = s.split("-");
335
- o = n, a = r || [];
334
+ const [n, ...c] = s.split("-");
335
+ o = n, a = c || [];
336
336
  }
337
337
  if (t.routes?.[o] !== void 0) {
338
338
  t.routes[o].publishedAt = (/* @__PURE__ */ new Date()).toISOString();
@@ -340,11 +340,11 @@ function Bt(t, e) {
340
340
  if (!n || !n.params || n.params.length === 0)
341
341
  continue;
342
342
  if (s.includes("-") && a.length > 0) {
343
- const r = rt(a, n);
344
- r && (r.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
343
+ const c = it(a, n);
344
+ c && (c.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
345
345
  }
346
346
  if (!e) {
347
- const r = Ie({
347
+ const c = Ie({
348
348
  basePath: n.path,
349
349
  params: n.params,
350
350
  routeId: n.id,
@@ -354,8 +354,8 @@ function Bt(t, e) {
354
354
  currentOptionIds: [],
355
355
  result: []
356
356
  });
357
- for (const l of r)
358
- l.routeMetaData ??= {}, l.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString();
357
+ for (const r of c)
358
+ r.routeMetaData ??= {}, r.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString();
359
359
  }
360
360
  }
361
361
  }
@@ -379,14 +379,14 @@ function fe({
379
379
  publishedAt: a?.routeMetaData?.publishedAt ?? e.publishedAt,
380
380
  isPublic: (a?.routeMetaData?.isPublic ?? e.isPublic) && e.isPublic
381
381
  };
382
- for (const r of s.supportedLocales) {
382
+ for (const c of s.supportedLocales) {
383
383
  if (e.dataSource) {
384
- let l = e.id;
385
- a && (l = a.paramOptionIds.join("-"));
386
- const p = e.dataSource.pathDataMappings?.[l]?.dataCache?.[r.locale] ?? e.dataSource.pathDataMappings?.[l]?.dataCache?.[s.config.defaultLocale || "en"];
384
+ let r = e.id;
385
+ a && (r = a.paramOptionIds.join("-"));
386
+ const p = e.dataSource.pathDataMappings?.[r]?.dataCache?.[c.locale] ?? e.dataSource.pathDataMappings?.[r]?.dataCache?.[s.config.defaultLocale || "en"];
387
387
  if (!p)
388
388
  continue;
389
- nt(n, s, r.locale, p);
389
+ rt(n, s, c.locale, p);
390
390
  }
391
391
  a && a.routeMetaData && (a.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
392
392
  }
@@ -402,15 +402,15 @@ const Vt = 60 * 60 * 1e3, W = new we({
402
402
  });
403
403
  function zt(t, e = []) {
404
404
  let s = 0;
405
- const o = Array.from(W.keys()), a = t.map((n) => Be(n));
405
+ const o = Array.from(W.keys()), a = t.map((n) => Oe(n));
406
406
  for (const n of o)
407
- for (const r of a) {
408
- if (ke(n, { currentPath: r })) {
407
+ for (const c of a) {
408
+ if (Le(n, { currentPath: c })) {
409
409
  W.delete(n), s++, f.info(`[Cache CLEAR] key: ${n}`);
410
410
  break;
411
411
  }
412
- for (const l of e)
413
- if (ke(n, { currentPath: `/${l}${r}` })) {
412
+ for (const r of e)
413
+ if (Le(n, { currentPath: `/${r}${c}` })) {
414
414
  W.delete(n), s++, f.info(`[Cache CLEAR] key: ${n}`);
415
415
  break;
416
416
  }
@@ -422,7 +422,7 @@ function qt() {
422
422
  return W.clear(), f.info(`[Cache CLEAR ALL] cleared ${t} entries`), t;
423
423
  }
424
424
  E.events.on(E.Events.envUpdate, qt);
425
- const { uploadToMediaKit: Kt } = require("@blocklet/uploader-server"), Ce = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, X = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, $e = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, Ht = 1e4, Jt = 3e4, Z = 0, me = 1, Yt = 0, Wt = 1, ye = E, H = b(process.env.BLOCKLET_DATA_DIR, "site-state"), Ms = ["production", "draft"], _s = ["production"];
425
+ const { uploadToMediaKit: Kt } = require("@blocklet/uploader-server"), ve = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, X = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, $e = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, Ht = 1e4, Jt = 3e4, Z = 0, me = 1, Yt = 0, Wt = 1, ye = E, H = b(process.env.BLOCKLET_DATA_DIR, "site-state"), $s = ["production", "draft"], Ns = ["production"];
426
426
  function ne(t) {
427
427
  return t?.replace(/\//g, "|") || "";
428
428
  }
@@ -441,10 +441,10 @@ function Xt() {
441
441
  resources: {}
442
442
  };
443
443
  }
444
- class O extends _.Doc {
444
+ class O extends N.Doc {
445
445
  constructor(e) {
446
- super(), this.options = e, M(this.draftYjsFilePath) && _.applyUpdate(this, J(this.draftYjsFilePath)), this.syncedStore = ht(
447
- at(
446
+ super(), this.options = e, $(this.draftYjsFilePath) && N.applyUpdate(this, J(this.draftYjsFilePath)), this.syncedStore = yt(
447
+ nt(
448
448
  {
449
449
  pages: {},
450
450
  pageIds: [],
@@ -480,7 +480,7 @@ class O extends _.Doc {
480
480
  throw new Error("Should provide project context");
481
481
  try {
482
482
  const s = b(H, e), o = b(H, `@del-${e}`);
483
- Re(s, o);
483
+ je(s, o);
484
484
  } catch (s) {
485
485
  f.error("Failed to safe delete project state dir:", s);
486
486
  }
@@ -514,10 +514,10 @@ class O extends _.Doc {
514
514
  attributes: ["productionState"]
515
515
  });
516
516
  if (Ae(s?.productionState)) {
517
- const o = b(H, e, "production"), a = await Ke(o, { includeResources: !0 }) ?? Xt();
517
+ const o = b(H, e, "production"), a = await He(o, { includeResources: !0 }) ?? Xt();
518
518
  if (!a?.config?.defaultLocale) {
519
519
  a.config ??= {};
520
- const n = ye.env.languages?.map((r) => ({ locale: r.code, name: r.name })) || [];
520
+ const n = ye.env.languages?.map((c) => ({ locale: c.code, name: c.name })) || [];
521
521
  a.config.defaultLocale = n[0]?.locale;
522
522
  }
523
523
  return a;
@@ -550,11 +550,11 @@ class O extends _.Doc {
550
550
  }
551
551
  async setState(e, s) {
552
552
  const o = await ts(s, { exportAssets: !1, includeResources: !0 }), a = this.getPublishDir(e);
553
- if (N(L(a), { recursive: !0 }), Fe(a, { force: !0, recursive: !0 }), Re(o, a), e === "production") {
553
+ if (_(L(a), { recursive: !0 }), Ge(a, { force: !0, recursive: !0 }), je(o, a), e === "production") {
554
554
  const n = k(this.options.path);
555
555
  O.pageUrlMapCache.delete(n);
556
- const r = Ee(s);
557
- await U.update({ productionState: r }, { where: { id: n } });
556
+ const c = Ee(s);
557
+ await U.update({ productionState: c }, { where: { id: n } });
558
558
  }
559
559
  }
560
560
  getPublishDir(e) {
@@ -575,10 +575,10 @@ class O extends _.Doc {
575
575
  p.delete(y);
576
576
  }));
577
577
  }
578
- const r = D.createEncoder();
579
- D.writeVarUint(r, me), D.writeVarUint8Array(r, Te(this.awareness, n));
580
- const l = D.toUint8Array(r);
581
- this.conns.forEach((p, y) => this.send(y, l));
578
+ const c = D.createEncoder();
579
+ D.writeVarUint(c, me), D.writeVarUint8Array(c, ke(this.awareness, n));
580
+ const r = D.toUint8Array(c);
581
+ this.conns.forEach((p, y) => this.send(y, r));
582
582
  };
583
583
  updateHandler = (e) => {
584
584
  const s = D.createEncoder();
@@ -587,30 +587,30 @@ class O extends _.Doc {
587
587
  this.conns.forEach((a, n) => this.send(n, o));
588
588
  };
589
589
  ensureDataStructure = () => {
590
- const { supportedLocales: e, pages: s, pageIds: o, config: a, routes: n, routeIds: r } = this.syncedStore;
590
+ const { supportedLocales: e, pages: s, pageIds: o, config: a, routes: n, routeIds: c } = this.syncedStore;
591
591
  {
592
- const l = new Set(Object.keys(s));
592
+ const r = new Set(Object.keys(s));
593
593
  let p = 0;
594
594
  for (; p < o.length; ) {
595
595
  const y = o[p];
596
- l.has(y) ? (l.delete(y), p++) : o.splice(p, 1);
596
+ r.has(y) ? (r.delete(y), p++) : o.splice(p, 1);
597
597
  }
598
598
  }
599
599
  {
600
- const l = new Set(Object.keys(n));
600
+ const r = new Set(Object.keys(n));
601
601
  let p = 0;
602
- for (; p < r.length; ) {
603
- const y = r[p];
604
- l.has(y) ? (l.delete(y), p++) : r.splice(p, 1);
602
+ for (; p < c.length; ) {
603
+ const y = c[p];
604
+ r.has(y) ? (r.delete(y), p++) : c.splice(p, 1);
605
605
  }
606
606
  }
607
- e.splice(0, e.length), e.push(...ye.env.languages.map((l) => ({ locale: l.code, name: l.name }))), a.defaultLocale = e[0]?.locale;
607
+ e.splice(0, e.length), e.push(...ye.env.languages.map((r) => ({ locale: r.code, name: r.name }))), a.defaultLocale = e[0]?.locale;
608
608
  {
609
- let l = 0;
609
+ let r = 0;
610
610
  const p = /* @__PURE__ */ new Set();
611
- for (; l < e.length; ) {
612
- const { locale: y } = e[l];
613
- p.has(y) ? e.splice(l, 1) : (l++, p.add(y));
611
+ for (; r < e.length; ) {
612
+ const { locale: y } = e[r];
613
+ p.has(y) ? e.splice(r, 1) : (r++, p.add(y));
614
614
  }
615
615
  }
616
616
  };
@@ -651,8 +651,8 @@ class O extends _.Doc {
651
651
  f.info(`[SiteState] cancelled scheduled release for project ${e}`);
652
652
  }
653
653
  }
654
- autoSave = Ge(() => {
655
- N(L(this.draftYjsFilePath), { recursive: !0 }), te(this.draftYjsFilePath, _.encodeStateAsUpdate(this));
654
+ autoSave = xe(() => {
655
+ _(L(this.draftYjsFilePath), { recursive: !0 }), te(this.draftYjsFilePath, N.encodeStateAsUpdate(this));
656
656
  }, Ht);
657
657
  save = ({ flush: e = !1 } = {}) => {
658
658
  this.autoSave(), e && this.autoSave.flush();
@@ -667,30 +667,30 @@ class O extends _.Doc {
667
667
  const o = JSON.parse(JSON.stringify(s));
668
668
  e.config.fontFamily ??= {};
669
669
  const a = o.config?.fontFamily, n = e.config?.fontFamily;
670
- e.config.fontFamily.title = a?.title || n?.title, e.config.fontFamily.description = a?.description || n?.description, await new Promise((r, l) => {
670
+ e.config.fontFamily.title = a?.title || n?.title, e.config.fontFamily.description = a?.description || n?.description, await new Promise((c, r) => {
671
671
  this.transact(async () => {
672
672
  try {
673
673
  const p = await _e(e, s);
674
- r(p);
674
+ c(p);
675
675
  } catch (p) {
676
- l(p);
676
+ r(p);
677
677
  }
678
678
  });
679
679
  });
680
680
  };
681
681
  clearPageCacheForRoutes = async (e, s) => {
682
682
  const o = k(this.options.path), n = (await U.findByPk(o))?.slug || o;
683
- let r = e;
684
- (!r || r.length === 0) && (r = s.pageIds ?? []), f.info(`[SiteState] clearing page cache for project ${o}, routes:`, r || []);
685
- const l = s.supportedLocales.map((A) => A.locale), p = [], y = r.filter((A) => s.pageIds?.includes(A));
683
+ let c = e;
684
+ (!c || c.length === 0) && (c = s.pageIds ?? []), f.info(`[SiteState] clearing page cache for project ${o}, routes:`, c || []);
685
+ const r = s.supportedLocales.map((A) => A.locale), p = [], y = c.filter((A) => s.pageIds?.includes(A));
686
686
  for (const A of y) {
687
687
  const I = s.pages[A].slug;
688
688
  n && n !== o && (n === "/" ? p.push(I) : p.push(`/${n}${I}`)), p.push(`/${o}${I}`);
689
689
  }
690
690
  if (p.length > 0)
691
691
  try {
692
- const A = zt(p, l);
693
- f.info(`[SiteState] cleared ${A} page cache entries for project ${o}, routes:`, r);
692
+ const A = zt(p, r);
693
+ f.info(`[SiteState] cleared ${A} page cache entries for project ${o}, routes:`, c);
694
694
  } catch {
695
695
  }
696
696
  O.pageUrlMapCache.delete(o);
@@ -722,8 +722,8 @@ class O extends _.Doc {
722
722
  D.writeVarUint(a, Z), Rt(a, this), this.send(e, D.toUint8Array(a));
723
723
  const n = this.awareness.getStates();
724
724
  if (n.size > 0) {
725
- const r = D.createEncoder();
726
- D.writeVarUint(r, me), D.writeVarUint8Array(r, Te(this.awareness, Array.from(n.keys()))), this.send(e, D.toUint8Array(r));
725
+ const c = D.createEncoder();
726
+ D.writeVarUint(c, me), D.writeVarUint8Array(c, ke(this.awareness, Array.from(n.keys()))), this.send(e, D.toUint8Array(c));
727
727
  }
728
728
  }
729
729
  };
@@ -752,10 +752,10 @@ class O extends _.Doc {
752
752
  s ? o = [s] : o = await this.getProjectIds();
753
753
  let a = {};
754
754
  if (e === "production" && o?.length) {
755
- const n = new Map(o?.map((r) => [r, !0]) || []);
756
- for (const r of o) {
757
- const l = O.pageUrlMapCache.get(r);
758
- l && (a = { ...a, ...l }, n.delete(r));
755
+ const n = new Map(o?.map((c) => [c, !0]) || []);
756
+ for (const c of o) {
757
+ const r = O.pageUrlMapCache.get(c);
758
+ r && (a = { ...a, ...r }, n.delete(c));
759
759
  }
760
760
  o = Array.from(n.keys());
761
761
  }
@@ -768,35 +768,35 @@ class O extends _.Doc {
768
768
  }
769
769
  });
770
770
  await Promise.all(
771
- n?.map(async (r) => {
772
- const l = r.id, p = r.slug || l, y = {}, A = e === "production" && r?.productionState ? r.productionState : await O.getStateByProjectId(r.id, e), j = yt(
771
+ n?.map(async (c) => {
772
+ const r = c.id, p = c.slug || r, y = {}, A = e === "production" && c?.productionState ? c.productionState : await O.getStateByProjectId(c.id, e), j = St(
773
773
  E.env.languages?.map((u) => u.code) || [],
774
774
  A.supportedLocales?.map((u) => u.locale) || []
775
- ), I = (u, c) => {
775
+ ), I = (u, l) => {
776
776
  p && (y[Y("/", p, u)] = {
777
- ...c,
777
+ ...l,
778
778
  shouldRedirect: !0,
779
779
  mainPage: !0
780
- }), y[Y("/", l, u)] = {
781
- ...c,
780
+ }), y[Y("/", r, u)] = {
781
+ ...l,
782
782
  shouldRedirect: !0,
783
783
  mainPage: !0
784
784
  };
785
785
  for (const g of j) {
786
- const C = { ...c, locale: g };
787
- y[Y("/", g, l, u)] = C, p && (y[Y("/", g, p, u)] = C);
786
+ const C = { ...l, locale: g };
787
+ y[Y("/", g, r, u)] = C, p && (y[Y("/", g, p, u)] = C);
788
788
  }
789
789
  };
790
790
  if (e === "draft")
791
791
  for (const u of A.routeIds || []) {
792
- const c = A?.routes?.[u];
793
- if (!c) continue;
794
- if (c.params && c.params.length > 0) {
792
+ const l = A?.routes?.[u];
793
+ if (!l) continue;
794
+ if (l.params && l.params.length > 0) {
795
795
  const m = Ie({
796
- basePath: c.path,
797
- params: c.params,
798
- routeId: c.id,
799
- paramsOptions: c.paramsOptions,
796
+ basePath: l.path,
797
+ params: l.params,
798
+ routeId: l.id,
799
+ paramsOptions: l.paramsOptions,
800
800
  currentIndex: 0,
801
801
  currentParams: [],
802
802
  currentOptionIds: [],
@@ -804,40 +804,40 @@ class O extends _.Doc {
804
804
  });
805
805
  for (const d of m) {
806
806
  const h = d.path, w = {
807
- projectId: l,
807
+ projectId: r,
808
808
  projectSlug: p,
809
809
  pageSlug: h,
810
- pageId: c.displayTemplateId || "",
810
+ pageId: l.displayTemplateId || "",
811
811
  routeId: u,
812
812
  // default locale
813
813
  defaultLocale: j?.[0],
814
814
  locales: j,
815
815
  publishedAt: A.config.publishedAt,
816
- isPublic: c.isPublic && d?.routeMetaData?.isPublic
816
+ isPublic: l.isPublic && d?.routeMetaData?.isPublic
817
817
  };
818
818
  I(h, w);
819
819
  }
820
820
  }
821
- const g = c.path, C = {
822
- projectId: l,
821
+ const g = l.path, C = {
822
+ projectId: r,
823
823
  projectSlug: p,
824
824
  pageSlug: g,
825
- pageId: c.displayTemplateId || "",
825
+ pageId: l.displayTemplateId || "",
826
826
  routeId: u,
827
827
  // default locale
828
828
  defaultLocale: j?.[0],
829
829
  locales: j,
830
830
  publishedAt: A.config.publishedAt,
831
- isPublic: c.isPublic
831
+ isPublic: l.isPublic
832
832
  };
833
833
  I(g, C);
834
834
  }
835
835
  for (const u of A.pageIds || []) {
836
- const c = A.pages[u];
837
- if (!c || e === "production" && !c.isPublic)
836
+ const l = A.pages[u];
837
+ if (!l || e === "production" && !l.isPublic)
838
838
  continue;
839
- const g = c.slug, C = r.slug || l, m = {
840
- projectId: l,
839
+ const g = l.slug, C = c.slug || r, m = {
840
+ projectId: r,
841
841
  projectSlug: C,
842
842
  pageSlug: g,
843
843
  pageId: u,
@@ -845,19 +845,19 @@ class O extends _.Doc {
845
845
  defaultLocale: j?.[0],
846
846
  locales: j,
847
847
  publishedAt: A.config.publishedAt,
848
- isPublic: c.isPublic,
849
- templateConfig: c.templateConfig
848
+ isPublic: l.isPublic,
849
+ templateConfig: l.templateConfig
850
850
  };
851
851
  I(g, m);
852
852
  }
853
- e === "production" && O.pageUrlMapCache.set(l, y), a = { ...a, ...y };
853
+ e === "production" && O.pageUrlMapCache.set(r, y), a = { ...a, ...y };
854
854
  })
855
855
  );
856
856
  }
857
857
  return a;
858
858
  }
859
859
  getDocumentSize() {
860
- return _.encodeStateAsUpdate(this).byteLength;
860
+ return N.encodeStateAsUpdate(this).byteLength;
861
861
  }
862
862
  static getInstancesSizeInfo() {
863
863
  const e = [];
@@ -897,11 +897,11 @@ class O extends _.Doc {
897
897
  s.map((n) => n.projectId)
898
898
  );
899
899
  let a = 0;
900
- for (const { projectId: n, instance: r } of s)
900
+ for (const { projectId: n, instance: c } of s)
901
901
  try {
902
- f.info(`[SiteState] releasing instance due to periodic check: ${n}`), r.destroy(), a++;
903
- } catch (l) {
904
- f.error(`[SiteState] failed to release instance ${n} during periodic check:`, l);
902
+ f.info(`[SiteState] releasing instance due to periodic check: ${n}`), c.destroy(), a++;
903
+ } catch (r) {
904
+ f.error(`[SiteState] failed to release instance ${n} during periodic check:`, r);
905
905
  }
906
906
  f.info(
907
907
  `[SiteState] periodic check completed: ${a}/${s.length} instances released successfully`
@@ -910,7 +910,7 @@ class O extends _.Doc {
910
910
  }
911
911
  }
912
912
  async function Qt(t, e, s) {
913
- if (!t || !M(t) || !x(t).isFile())
913
+ if (!t || !$(t) || !x(t).isFile())
914
914
  return null;
915
915
  let o = s[t];
916
916
  return o || (o = (async () => {
@@ -925,15 +925,15 @@ async function Qt(t, e, s) {
925
925
  })(), s[t] = o), o;
926
926
  }
927
927
  const Zt = async (t, e) => {
928
- const s = k(t), o = await gt({
929
- name: Ve,
928
+ const s = k(t), o = await ht({
929
+ name: ze,
930
930
  path: Y("/uploads", s),
931
931
  responseType: "stream",
932
932
  method: "GET"
933
933
  });
934
934
  if (o.status >= 200 && o.status < 400) {
935
- const a = pt(e);
936
- await Et(o.data, a);
935
+ const a = ut(e);
936
+ await bt(o.data, a);
937
937
  } else
938
938
  throw new Error(`download asset failed ${o.status}`);
939
939
  }, es = async (t, e) => {
@@ -947,20 +947,20 @@ const Zt = async (t, e) => {
947
947
  })
948
948
  );
949
949
  };
950
- function qe(t) {
951
- return Ce.test(t) ? [t] : X.test(t) ? ($e.lastIndex = 0, Array.from(t.matchAll($e)).map((s) => s[1]).filter((s) => !!s)) : [];
950
+ function Ke(t) {
951
+ return ve.test(t) ? [t] : X.test(t) ? ($e.lastIndex = 0, Array.from(t.matchAll($e)).map((s) => s[1]).filter((s) => !!s)) : [];
952
952
  }
953
953
  async function ee(t, e, s) {
954
954
  const { getFilename: o, exportAssets: a } = s, n = b(e, o(t));
955
- if (N(L(n), { recursive: !0 }), te(n, B.stringify(t)), a) {
956
- const l = ae(
955
+ if (_(L(n), { recursive: !0 }), te(n, B.stringify(t)), a) {
956
+ const r = ae(
957
957
  t,
958
- (p) => typeof p == "string" && (Ce.test(p) || X.test(p))
958
+ (p) => typeof p == "string" && (ve.test(p) || X.test(p))
959
959
  ).map((p) => {
960
960
  const y = be(t, p);
961
- return qe(y);
961
+ return Ke(y);
962
962
  }).flat().filter(Boolean);
963
- await es(l, L(n));
963
+ await es(r, L(n));
964
964
  }
965
965
  }
966
966
  const Se = new we({
@@ -968,29 +968,29 @@ const Se = new we({
968
968
  ttl: 1 * 60 * 1e3
969
969
  // 1 minute
970
970
  });
971
- async function Me(t, e, s) {
971
+ async function Ne(t, e, s) {
972
972
  const o = ae(
973
973
  t,
974
- (l) => typeof l == "string" && (Ce.test(l) || X.test(l))
975
- ), a = St(2), n = o.map(
976
- (l) => a(async () => {
974
+ (r) => typeof r == "string" && (ve.test(r) || X.test(r))
975
+ ), a = It(2), n = o.map(
976
+ (r) => a(async () => {
977
977
  try {
978
- const p = be(t, l), y = qe(p);
978
+ const p = be(t, r), y = Ke(p);
979
979
  for (const A of y) {
980
- const j = k(A), I = s.getFilePath(A, l), u = I ? `${I}:${j}` : j, c = Se.get(u);
981
- if (c) {
982
- X.test(p) || De(t, l, c);
980
+ const j = k(A), I = s.getFilePath(A, r), u = I ? `${I}:${j}` : j, l = Se.get(u);
981
+ if (l) {
982
+ X.test(p) || Te(t, r, l);
983
983
  return;
984
984
  }
985
985
  const g = await Qt(I, j, e);
986
- g && (X.test(p) || De(t, l, g), Se.set(u, g));
986
+ g && (X.test(p) || Te(t, r, g), Se.set(u, g));
987
987
  }
988
988
  } catch (p) {
989
- f.error(`Failed to process upload for path ${l.join(".")}:`, p.message || p.reason);
989
+ f.error(`Failed to process upload for path ${r.join(".")}:`, p.message || p.reason);
990
990
  }
991
991
  })
992
- ), r = await Promise.allSettled(n);
993
- s.onFinish?.(r);
992
+ ), c = await Promise.allSettled(n);
993
+ s.onFinish?.(c);
994
994
  }
995
995
  async function ts(t, {
996
996
  exportAssets: e,
@@ -998,17 +998,17 @@ async function ts(t, {
998
998
  componentIds: o = "all",
999
999
  rawConfig: a,
1000
1000
  includeResources: n = !1,
1001
- routeIds: r = "all"
1001
+ routeIds: c = "all"
1002
1002
  } = {}) {
1003
- const l = s === "all" ? t.pageIds : s, p = dt({
1003
+ const r = s === "all" ? t.pageIds : s, p = ft({
1004
1004
  state: t,
1005
- pageIds: l,
1005
+ pageIds: r,
1006
1006
  componentIds: o === "all" ? Object.keys(t.components) : o
1007
1007
  });
1008
1008
  Object.entries(t.components).forEach(([i, S]) => {
1009
1009
  S.data?.renderer?.type === "component-template" && p.push(i);
1010
1010
  });
1011
- const y = r === "all" ? t.routeIds : r, A = (i) => ({
1011
+ const y = c === "all" ? t.routeIds : c, A = (i) => ({
1012
1012
  id: i.id,
1013
1013
  name: i.name,
1014
1014
  isTemplateSection: i.isTemplateSection ?? !1,
@@ -1061,9 +1061,9 @@ async function ts(t, {
1061
1061
  const S = t.routes[i];
1062
1062
  return S && I(S);
1063
1063
  })
1064
- ), c = T(
1064
+ ), l = T(
1065
1065
  t.supportedLocales.map((i) => i.locale).flatMap(
1066
- (i) => l.map((S) => {
1066
+ (i) => r.map((S) => {
1067
1067
  const v = t.pages[S];
1068
1068
  return v && {
1069
1069
  locale: i,
@@ -1072,13 +1072,13 @@ async function ts(t, {
1072
1072
  };
1073
1073
  })
1074
1074
  )
1075
- ), g = ze(), C = b(g, "pages");
1076
- N(C, { recursive: !0 });
1075
+ ), g = qe(), C = b(g, "pages");
1076
+ _(C, { recursive: !0 });
1077
1077
  const m = b(g, "components");
1078
- N(m, { recursive: !0 });
1078
+ _(m, { recursive: !0 });
1079
1079
  const d = b(g, "routes");
1080
- N(d, { recursive: !0 });
1081
- for (const { locale: i, slug: S, page: v } of c)
1080
+ _(d, { recursive: !0 });
1081
+ for (const { locale: i, slug: S, page: v } of l)
1082
1082
  await ee(v, C, {
1083
1083
  getFilename: () => `${ne(S) || "index"}.${i}.yml`,
1084
1084
  exportAssets: e
@@ -1097,10 +1097,10 @@ async function ts(t, {
1097
1097
  });
1098
1098
  }
1099
1099
  const h = b(g, ".blocklet/pages/pages.config.yml");
1100
- N(L(h), { recursive: !0 });
1100
+ _(L(h), { recursive: !0 });
1101
1101
  const w = {
1102
1102
  pages: T(
1103
- l.map((i) => {
1103
+ r.map((i) => {
1104
1104
  const S = t.pages[i];
1105
1105
  return S && { id: i, slug: S.slug };
1106
1106
  })
@@ -1137,32 +1137,32 @@ async function ts(t, {
1137
1137
  const P = b(g, "config.source.json");
1138
1138
  if (a && te(P, JSON.stringify(a)), n) {
1139
1139
  const i = b(g, "resources"), S = b(i, "components");
1140
- N(S, { recursive: !0 });
1140
+ _(S, { recursive: !0 });
1141
1141
  for (const z of Object.keys(t?.resources?.components ?? {}).filter(
1142
- ($) => p.includes($)
1142
+ (M) => p.includes(M)
1143
1143
  )) {
1144
- const $ = t.resources?.components?.[z]?.component;
1145
- $ && await ee($, S, {
1144
+ const M = t.resources?.components?.[z]?.component;
1145
+ M && await ee(M, S, {
1146
1146
  getFilename: (q) => `${q.name || "unnamed"}.${q.id}.yml`,
1147
1147
  exportAssets: e
1148
1148
  });
1149
1149
  }
1150
1150
  const v = b(g, "chunks");
1151
- N(v, { recursive: !0 });
1151
+ _(v, { recursive: !0 });
1152
1152
  const G = ss();
1153
1153
  for (const z of Object.keys(t?.resources?.components ?? {}).filter(
1154
- ($) => p.includes($)
1154
+ (M) => p.includes(M)
1155
1155
  )) {
1156
- const $ = t.resources?.components?.[z]?.component;
1157
- if ($ && $.renderer?.type === "react-component") {
1158
- const q = $.renderer?.chunks ?? [];
1156
+ const M = t.resources?.components?.[z]?.component;
1157
+ if (M && M.renderer?.type === "react-component") {
1158
+ const q = M.renderer?.chunks ?? [];
1159
1159
  if (q?.length > 0)
1160
1160
  for (const pe of q) {
1161
- const ve = b(v, pe), ue = G?.[pe];
1161
+ const Re = b(v, pe), ue = G?.[pe];
1162
1162
  try {
1163
- ue && M(ue) && !M(ve) && ct(ue, ve);
1164
- } catch (Ze) {
1165
- f.error(`copy chunk ${pe} error`, Ze.message);
1163
+ ue && $(ue) && !$(Re) && lt(ue, Re);
1164
+ } catch (et) {
1165
+ f.error(`copy chunk ${pe} error`, et.message);
1166
1166
  }
1167
1167
  }
1168
1168
  }
@@ -1170,18 +1170,18 @@ async function ts(t, {
1170
1170
  }
1171
1171
  return g;
1172
1172
  }
1173
- async function Ke(t, { importAssets: e, includeResources: s } = {}) {
1174
- if (!M(t))
1173
+ async function He(t, { importAssets: e, includeResources: s } = {}) {
1174
+ if (!$(t))
1175
1175
  return null;
1176
1176
  let o, a = !1;
1177
1177
  try {
1178
- x(t).isDirectory() ? o = t : /\.(tgz|gz|tar)$/.test(t) && (a = !0, o = ze(), await bt({ file: t, C: o }));
1179
- const n = se("**/.blocklet/pages/pages.config.yml", { cwd: o, absolute: !0 }).at(0), r = n && b(L(n), "../../pages"), l = n && b(L(n), "../../components"), p = n && b(L(n), "../../routes");
1178
+ x(t).isDirectory() ? o = t : /\.(tgz|gz|tar)$/.test(t) && (a = !0, o = qe(), await At({ file: t, C: o }));
1179
+ const n = se("**/.blocklet/pages/pages.config.yml", { cwd: o, absolute: !0 }).at(0), c = n && b(L(n), "../../pages"), r = n && b(L(n), "../../components"), p = n && b(L(n), "../../routes");
1180
1180
  if (!n)
1181
1181
  return null;
1182
1182
  const y = B.parse(J(n).toString()), A = (m, d, h) => {
1183
1183
  let w = b(m, `${d}${h ? `.${h}` : ""}.yml`);
1184
- return (!M(w) || !x(w).isFile()) && (w = b(m, d, `index${h ? `.${h}` : ""}.yml`), !M(w) || !x(w)) ? null : B.parse(J(w).toString());
1184
+ return (!$(w) || !x(w).isFile()) && (w = b(m, d, `index${h ? `.${h}` : ""}.yml`), !$(w) || !x(w)) ? null : B.parse(J(w).toString());
1185
1185
  }, j = (m, d) => {
1186
1186
  try {
1187
1187
  const h = se(`*.${d}.yml`, { cwd: m, absolute: !0 })[0];
@@ -1192,23 +1192,23 @@ async function Ke(t, { importAssets: e, includeResources: s } = {}) {
1192
1192
  return null;
1193
1193
  }, I = (m, d) => {
1194
1194
  let h = b(m, `${d}.yml`);
1195
- return (!M(h) || !x(h).isFile()) && (h = b(m, d, "index.yml"), !M(h) || !x(h)) ? null : B.parse(J(h).toString());
1195
+ return (!$(h) || !x(h).isFile()) && (h = b(m, d, "index.yml"), !$(h) || !x(h)) ? null : B.parse(J(h).toString());
1196
1196
  }, u = T(
1197
1197
  y.pages.map(({ slug: m }) => {
1198
1198
  const d = T(
1199
1199
  y.supportedLocales.map(({ locale: P }) => {
1200
- const i = r ? A(r, ne(m), P) : void 0;
1200
+ const i = c ? A(c, ne(m), P) : void 0;
1201
1201
  if (i)
1202
1202
  return { locale: P, page: i };
1203
- const S = r ? A(r, m, P) : void 0;
1203
+ const S = c ? A(c, m, P) : void 0;
1204
1204
  return S && { locale: P, page: S };
1205
1205
  })
1206
1206
  ), h = d[0]?.page;
1207
1207
  if (!h)
1208
1208
  return null;
1209
- const w = h.sections.map(ut);
1209
+ const w = h.sections.map(dt);
1210
1210
  return {
1211
- id: h.id || je(),
1211
+ id: h.id || De(),
1212
1212
  createdAt: h.createdAt,
1213
1213
  updatedAt: h.updatedAt,
1214
1214
  publishedAt: h.publishedAt,
@@ -1246,12 +1246,12 @@ async function Ke(t, { importAssets: e, includeResources: s } = {}) {
1246
1246
  )
1247
1247
  };
1248
1248
  })
1249
- ), c = T(
1249
+ ), l = T(
1250
1250
  y?.routes?.map(({ path: m }) => {
1251
1251
  const d = p ? I(p, ne(m)) : void 0;
1252
1252
  return {
1253
1253
  ...d,
1254
- id: d?.id || je(),
1254
+ id: d?.id || De(),
1255
1255
  createdAt: d?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1256
1256
  updatedAt: d?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1257
1257
  publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
@@ -1264,28 +1264,28 @@ async function Ke(t, { importAssets: e, includeResources: s } = {}) {
1264
1264
  dataSource: d?.dataSource ?? {}
1265
1265
  };
1266
1266
  }) ?? []
1267
- ), g = l ? T(y.components?.map(({ id: m }) => j(l, m)) ?? []) : [];
1267
+ ), g = r ? T(y.components?.map(({ id: m }) => j(r, m)) ?? []) : [];
1268
1268
  if (e) {
1269
1269
  const m = (...d) => {
1270
1270
  f.info(`[${a ? k(t) : k(b(t, "../../../../"))}] importAssets:`, ...d);
1271
1271
  };
1272
1272
  try {
1273
1273
  m("wait image-bin api ready"), await wt({
1274
- resources: [`${ft(et)}/api/sdk/uploads`],
1274
+ resources: [`${mt(tt)}/api/sdk/uploads`],
1275
1275
  validateStatus: (w) => w >= 200 && w <= 500
1276
1276
  }), m("image-bin api is ready");
1277
1277
  const d = {}, h = {};
1278
1278
  m("start to upload assets"), await Promise.allSettled([
1279
- Me(g, d, {
1280
- getFilePath: (w) => l && b(l, w),
1279
+ Ne(g, d, {
1280
+ getFilePath: (w) => r && b(r, w),
1281
1281
  onFinish: (w) => {
1282
1282
  m(`upload ${w.length} component assets`);
1283
1283
  }
1284
1284
  }),
1285
- Me(u, h, {
1285
+ Ne(u, h, {
1286
1286
  getFilePath: (w, P) => {
1287
1287
  const i = be(u, P.slice(0, 1));
1288
- return r && b(r, L(i.slug), w);
1288
+ return c && b(c, L(i.slug), w);
1289
1289
  },
1290
1290
  onFinish: (w) => {
1291
1291
  m(`upload ${w.length} page assets`);
@@ -1312,13 +1312,13 @@ async function Ke(t, { importAssets: e, includeResources: s } = {}) {
1312
1312
  pages: Object.fromEntries(u.map((m) => [m.id, m])),
1313
1313
  config: y.config || {},
1314
1314
  resources: C,
1315
- routeIds: c.map((m) => m.id),
1316
- routes: Object.fromEntries(c.map((m) => [m.id, m])),
1315
+ routeIds: l.map((m) => m.id),
1316
+ routes: Object.fromEntries(l.map((m) => [m.id, m])),
1317
1317
  dataSourceIds: [],
1318
1318
  dataSources: {}
1319
1319
  };
1320
1320
  } finally {
1321
- a && o && Fe(o, { force: !0, recursive: !0 });
1321
+ a && o && Ge(o, { force: !0, recursive: !0 });
1322
1322
  }
1323
1323
  }
1324
1324
  async function _e(t, e, {
@@ -1328,15 +1328,15 @@ async function _e(t, e, {
1328
1328
  publishMode: n = void 0
1329
1329
  } = {}) {
1330
1330
  try {
1331
- n && tt(n);
1331
+ n && st(n);
1332
1332
  } catch (I) {
1333
1333
  f.error("clear preload page cache error", { error: I });
1334
1334
  }
1335
- const { pages: r, pageIds: l, routeIds: p, routes: y, supportedLocales: A } = t;
1335
+ const { pages: c, pageIds: r, routeIds: p, routes: y, supportedLocales: A } = t;
1336
1336
  if (n === "production") {
1337
1337
  let I = s ?? [], u = null;
1338
- for (const c of p ?? []) {
1339
- const g = y?.[c];
1338
+ for (const l of p ?? []) {
1339
+ const g = y?.[l];
1340
1340
  if (g?.params && g?.params.length > 0 && g?.paramsOptions && g?.paramsOptions.length > 0) {
1341
1341
  const C = Ie({
1342
1342
  basePath: g.path,
@@ -1347,13 +1347,13 @@ async function _e(t, e, {
1347
1347
  currentParams: [],
1348
1348
  currentOptionIds: [],
1349
1349
  result: []
1350
- }), m = Object.fromEntries(C.map((d) => [`${c}-${d.paramOptionIds.join("-")}`, d]));
1351
- u = { ...u || {}, ...m }, s || (I = [...I, ...C.map((d) => `${c}-${d.paramOptionIds.join("-")}`)]);
1352
- } else s || I.push(c);
1350
+ }), m = Object.fromEntries(C.map((d) => [`${l}-${d.paramOptionIds.join("-")}`, d]));
1351
+ u = { ...u || {}, ...m }, s || (I = [...I, ...C.map((d) => `${l}-${d.paramOptionIds.join("-")}`)]);
1352
+ } else s || I.push(l);
1353
1353
  }
1354
1354
  f.info("routeIds to be published: ", I);
1355
- for (const c of I) {
1356
- let g = c;
1355
+ for (const l of I) {
1356
+ let g = l;
1357
1357
  if (g.includes("-")) {
1358
1358
  const [d] = g.split("-");
1359
1359
  g = d;
@@ -1367,61 +1367,61 @@ async function _e(t, e, {
1367
1367
  f.info("delete main route page", g);
1368
1368
  continue;
1369
1369
  }
1370
- if (c.includes("-") && !u?.[c]) {
1371
- const d = e.pageIds.indexOf(c);
1372
- d !== -1 && a && (e.pageIds.splice(d, 1), delete e.pages[c]), f.info("delete page", c);
1370
+ if (l.includes("-") && !u?.[l]) {
1371
+ const d = e.pageIds.indexOf(l);
1372
+ d !== -1 && a && (e.pageIds.splice(d, 1), delete e.pages[l]), f.info("delete page", l);
1373
1373
  continue;
1374
1374
  }
1375
1375
  if (!C.displayTemplateId) {
1376
- f.info("no display template", c);
1376
+ f.info("no display template", l);
1377
1377
  continue;
1378
1378
  }
1379
- const m = r[C.displayTemplateId];
1379
+ const m = c[C.displayTemplateId];
1380
1380
  if (!m) {
1381
- f.info("no template page", c);
1381
+ f.info("no template page", l);
1382
1382
  continue;
1383
1383
  }
1384
- if (e.pageIds.includes(c)) {
1385
- if (f.info("has need update page", c), o === "replace")
1386
- e.pages[c] = fe({
1384
+ if (e.pageIds.includes(l)) {
1385
+ if (f.info("has need update page", l), o === "replace")
1386
+ e.pages[l] = fe({
1387
1387
  page: m,
1388
1388
  route: C,
1389
1389
  state: t,
1390
- routeId: c,
1391
- routePathInfo: u?.[c]
1392
- }), f.info("replace page", c);
1390
+ routeId: l,
1391
+ routePathInfo: u?.[l]
1392
+ }), f.info("replace page", l);
1393
1393
  else if (o === "byUpdateTime") {
1394
1394
  const d = e.pages[C.id];
1395
- (!d || C.updatedAt && C.updatedAt > d.updatedAt) && (e.pages[c] = fe({
1395
+ (!d || C.updatedAt && C.updatedAt > d.updatedAt) && (e.pages[l] = fe({
1396
1396
  page: m,
1397
1397
  route: C,
1398
1398
  state: t,
1399
- routeId: c,
1400
- routePathInfo: u?.[c]
1401
- }), f.info("replace page by update time", c));
1399
+ routeId: l,
1400
+ routePathInfo: u?.[l]
1401
+ }), f.info("replace page by update time", l));
1402
1402
  }
1403
1403
  } else
1404
- e.pageIds.push(c), e.pages[c] = fe({
1404
+ e.pageIds.push(l), e.pages[l] = fe({
1405
1405
  page: m,
1406
1406
  route: C,
1407
1407
  state: t,
1408
- routeId: c,
1409
- routePathInfo: u?.[c]
1410
- }), f.info("add page", c);
1408
+ routeId: l,
1409
+ routePathInfo: u?.[l]
1410
+ }), f.info("add page", l);
1411
1411
  }
1412
1412
  if (a && !s)
1413
- for (const c of e.pageIds)
1414
- I?.includes(c) || (delete e.pages[c], f.info("delete page", c)), e.pageIds = [...e.pageIds].filter((g) => I?.includes(g));
1413
+ for (const l of e.pageIds)
1414
+ I?.includes(l) || (delete e.pages[l], f.info("delete page", l)), e.pageIds = [...e.pageIds].filter((g) => I?.includes(g));
1415
1415
  } else {
1416
- for (const I of l) {
1417
- const u = r[I];
1416
+ for (const I of r) {
1417
+ const u = c[I];
1418
1418
  if (u)
1419
1419
  if (e.pageIds.includes(u.id)) {
1420
1420
  if (o === "replace")
1421
1421
  e.pages[u.id] = u;
1422
1422
  else if (o === "byUpdateTime") {
1423
- const c = e.pages[u.id];
1424
- (!c || u.updatedAt && u.updatedAt > c.updatedAt) && (e.pages[u.id] = u);
1423
+ const l = e.pages[u.id];
1424
+ (!l || u.updatedAt && u.updatedAt > l.updatedAt) && (e.pages[u.id] = u);
1425
1425
  }
1426
1426
  } else
1427
1427
  e.pageIds.push(u.id), e.pages[u.id] = u;
@@ -1433,8 +1433,8 @@ async function _e(t, e, {
1433
1433
  if (o === "replace")
1434
1434
  e.routes[u.id] = u;
1435
1435
  else if (o === "byUpdateTime") {
1436
- const c = e.routes[u.id];
1437
- (!c || u.updatedAt && u.updatedAt > c.updatedAt) && (e.routes[u.id] = u);
1436
+ const l = e.routes[u.id];
1437
+ (!l || u.updatedAt && u.updatedAt > l.updatedAt) && (e.routes[u.id] = u);
1438
1438
  }
1439
1439
  } else
1440
1440
  e.routeIds.push(u.id), e.routes[u.id] = u;
@@ -1447,19 +1447,19 @@ async function _e(t, e, {
1447
1447
  j = Object.fromEntries(
1448
1448
  await Promise.all(
1449
1449
  Object.entries(j).map(async ([I, u]) => {
1450
- const c = await He(u?.data);
1450
+ const l = await Je(u?.data);
1451
1451
  return [
1452
1452
  I,
1453
1453
  {
1454
1454
  ...u,
1455
- data: c
1455
+ data: l
1456
1456
  }
1457
1457
  ];
1458
1458
  })
1459
1459
  )
1460
1460
  ), Object.assign(e.components, j), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))), Ae(t.resources.components) || (e.resources.components = JSON.parse(JSON.stringify(t.resources.components || {})));
1461
1461
  }
1462
- const He = st(
1462
+ const Je = ot(
1463
1463
  async (t) => {
1464
1464
  if (!Ae(t?.properties))
1465
1465
  return t;
@@ -1467,7 +1467,7 @@ const He = st(
1467
1467
  const { script: e, PROPERTIES_SCHEMA: s } = t?.renderer || {};
1468
1468
  if (s || e && e.includes("PROPERTIES_SCHEMA"))
1469
1469
  try {
1470
- const o = await ot(
1470
+ const o = await at(
1471
1471
  e ?? "",
1472
1472
  "PROPERTIES_SCHEMA",
1473
1473
  t.id,
@@ -1490,28 +1490,28 @@ const He = st(
1490
1490
  }
1491
1491
  );
1492
1492
  let re, Q, ie, ce;
1493
- const Je = () => mt({
1493
+ const Ye = () => gt({
1494
1494
  types: [
1495
- { did: Ve, type: Le },
1496
- { did: Lt, type: Le }
1495
+ { did: ze, type: Ue },
1496
+ { did: Lt, type: Ue }
1497
1497
  ]
1498
1498
  }), ss = () => {
1499
- const t = Je(), e = {};
1499
+ const t = Ye(), e = {};
1500
1500
  return t.forEach((s) => {
1501
1501
  const o = se("**/.blocklet/pages/pages.config.yml", { cwd: s.path, absolute: !0 }).at(0), a = o && b(L(o), "../../chunks");
1502
- if (a && M(a)) {
1503
- const n = lt(a);
1504
- for (const r of n)
1505
- e[r] = b(a, r);
1502
+ if (a && $(a)) {
1503
+ const n = pt(a);
1504
+ for (const c of n)
1505
+ e[c] = b(a, c);
1506
1506
  }
1507
1507
  }), e;
1508
1508
  };
1509
- function Ye() {
1509
+ function We() {
1510
1510
  return re = (async () => {
1511
- const t = Je();
1511
+ const t = Ye();
1512
1512
  Q = (await Promise.all(
1513
1513
  t.map(async (s) => {
1514
- const o = s.path ? await Ke(s.path, { importAssets: !1 }) : void 0;
1514
+ const o = s.path ? await He(s.path, { importAssets: !1 }) : void 0;
1515
1515
  return o ? { blockletId: s.did, state: o, blockletTitle: s.title } : void 0;
1516
1516
  })
1517
1517
  )).filter((s) => !!s), ie = Q.reduce(
@@ -1535,7 +1535,7 @@ function Ye() {
1535
1535
  ce = Object.fromEntries(
1536
1536
  await Promise.all(
1537
1537
  Object.entries(e).map(async ([s, o]) => {
1538
- const a = await He(o.component);
1538
+ const a = await Je(o.component);
1539
1539
  return [
1540
1540
  s,
1541
1541
  {
@@ -1549,9 +1549,9 @@ function Ye() {
1549
1549
  })(), re;
1550
1550
  }
1551
1551
  function os(t) {
1552
- const e = Ge(
1552
+ const e = xe(
1553
1553
  async () => {
1554
- await Ye().catch((s) => {
1554
+ await We().catch((s) => {
1555
1555
  f.error("load resource states error", { error: s });
1556
1556
  }), await t?.({
1557
1557
  states: Q,
@@ -1567,9 +1567,9 @@ function os(t) {
1567
1567
  E.events.off(E.Events.componentAdded, e), E.events.off(E.Events.componentRemoved, e), E.events.off(E.Events.componentStarted, e), E.events.off(E.Events.componentStopped, e), E.events.off(E.Events.componentUpdated, e), E.events.off(he, e);
1568
1568
  };
1569
1569
  }
1570
- const We = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), Xe = Symbol.for("GLOBAL_ENV_UPDATE_LISTENER_KEY"), le = globalThis;
1571
- le[We]?.();
1572
- le[We] = os(async ({ pages: t, components: e }) => {
1570
+ const Xe = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), Qe = Symbol.for("GLOBAL_ENV_UPDATE_LISTENER_KEY"), le = globalThis;
1571
+ le[Xe]?.();
1572
+ le[Xe] = os(async ({ pages: t, components: e }) => {
1573
1573
  const s = await O.getProjectIds();
1574
1574
  f.info(`start update resource states projects(${s.length})`, s), await Promise.race([
1575
1575
  new Promise((o) => {
@@ -1579,7 +1579,7 @@ le[We] = os(async ({ pages: t, components: e }) => {
1579
1579
  }),
1580
1580
  Promise.all(
1581
1581
  s.map(async (o) => {
1582
- Qe({
1582
+ Ze({
1583
1583
  projectId: o,
1584
1584
  pages: t,
1585
1585
  components: e
@@ -1590,8 +1590,8 @@ le[We] = os(async ({ pages: t, components: e }) => {
1590
1590
  f.error("update resource states failed:", o);
1591
1591
  });
1592
1592
  });
1593
- le[Xe]?.();
1594
- le[Xe] = () => {
1593
+ le[Qe]?.();
1594
+ le[Qe] = () => {
1595
1595
  const t = () => {
1596
1596
  O.pageUrlMapCache.clear(), f.info("[Cache CLEAR ALL] clear all page url map cache by env update");
1597
1597
  };
@@ -1609,7 +1609,7 @@ process.on("SIGINT", () => {
1609
1609
  process.on("SIGTERM", () => {
1610
1610
  O.stopPeriodicCheck(), process.exit(0);
1611
1611
  });
1612
- async function Qe({
1612
+ async function Ze({
1613
1613
  projectId: t,
1614
1614
  pages: e,
1615
1615
  components: s
@@ -1622,10 +1622,10 @@ async function Qe({
1622
1622
  if (o.syncedStore.resources.pages = e, (await U.findByPk(t))?.useAllResources)
1623
1623
  o.syncedStore.resources.components = s;
1624
1624
  else {
1625
- const r = (await Oe.findAll({ where: { projectId: t } })).map((p) => p.componentId), l = Object.fromEntries(
1626
- Object.entries(s || {}).filter(([p]) => r.includes(p))
1625
+ const c = (await Ce.findAll({ where: { projectId: t } })).map((p) => p.componentId), r = Object.fromEntries(
1626
+ Object.entries(s || {}).filter(([p]) => c.includes(p))
1627
1627
  );
1628
- o.syncedStore.resources.components = l;
1628
+ o.syncedStore.resources.components = r;
1629
1629
  }
1630
1630
  f.info(`update [${t}] resource states:`, {
1631
1631
  pages: Object.keys(o.syncedStore.resources.pages || {}).length,
@@ -1633,35 +1633,35 @@ async function Qe({
1633
1633
  });
1634
1634
  }
1635
1635
  async function as(t) {
1636
- return Qe({
1636
+ return Ze({
1637
1637
  projectId: t,
1638
1638
  pages: ie,
1639
1639
  components: ce
1640
1640
  });
1641
1641
  }
1642
- async function Ns() {
1642
+ async function _s() {
1643
1643
  f.info("trigger reload all project resource"), E.events.emit(he);
1644
1644
  }
1645
1645
  async function Fs({
1646
1646
  ensureLoaded: t = !0
1647
1647
  } = {}) {
1648
- return t && (re ??= Ye(), await re), { states: Q, pages: ie, components: ce };
1648
+ return t && (re ??= We(), await re), { states: Q, pages: ie, components: ce };
1649
1649
  }
1650
1650
  export {
1651
- Ve as C,
1651
+ ze as C,
1652
1652
  U as P,
1653
- Le as R,
1653
+ Ue as R,
1654
1654
  O as S,
1655
1655
  H as a,
1656
- Ms as b,
1657
- _s as c,
1656
+ $s as b,
1657
+ Ns as c,
1658
1658
  Xt as d,
1659
1659
  Zt as e,
1660
1660
  es as f,
1661
1661
  Fs as g,
1662
- Ke as h,
1662
+ He as h,
1663
1663
  os as i,
1664
- Ns as j,
1664
+ _s as j,
1665
1665
  _e as m,
1666
1666
  ts as t,
1667
1667
  as as u