@blocklet/pages-kit-inner-components 0.6.45 → 0.6.47

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,11 +1,11 @@
1
- import { d as $e, l as f, I as We, c as Qe, m as Xe, b as Ze } from "./components-6zI6vrkL.js";
2
- import { getYjsValue as V, syncedStore as et } from "@syncedstore/core";
1
+ import { d as $e, l as f, I as Qe, c as Xe, m as Ze, b as et } from "./components-6zI6vrkL.js";
2
+ import { getYjsValue as V, syncedStore as tt } from "@syncedstore/core";
3
3
  import * as N from "yjs";
4
- import { setPageDataSource as tt } from "@blocklet/pages-kit/utils/data-source";
5
- import { getRouteMetaDataByOptionIds as st, generateParamCombinations as Se } from "@blocklet/pages-kit/utils/route";
6
- import { cloneDeep as ot } from "lodash";
4
+ import { setPageDataSource as st } from "@blocklet/pages-kit/utils/data-source";
5
+ import { getRouteMetaDataByOptionIds as at, generateParamCombinations as Se } from "@blocklet/pages-kit/utils/route";
6
+ import Ue from "lodash/cloneDeep";
7
7
  import E from "@blocklet/sdk/lib/config";
8
- import { mkdtempSync as at, existsSync as U, readFileSync as q, renameSync as Ce, mkdirSync as _, rmSync as Ue, writeFileSync as ee, copyFileSync as rt, lstatSync as B, readdirSync as nt, createWriteStream as it } from "fs";
8
+ import { mkdtempSync as ot, existsSync as U, readFileSync as q, renameSync as Ce, mkdirSync as _, rmSync as Me, writeFileSync as ee, copyFileSync as rt, lstatSync as B, readdirSync as nt, createWriteStream as it } from "fs";
9
9
  import { join as b, basename as R, dirname as L } from "path";
10
10
  import { nextId as Oe } from "@blocklet/pages-kit/utils/common";
11
11
  import { unzipSection as ct } from "@blocklet/pages-kit/utils/page-model";
@@ -14,29 +14,28 @@ import { getComponentWebEndpoint as lt, getResources as ut, call as dt } from "@
14
14
  import { reactive as ft } from "@reactivedata/reactive";
15
15
  import { globSync as te } from "glob";
16
16
  import * as ue from "lib0/decoding";
17
- import * as D from "lib0/encoding";
18
- import mt from "lodash/cloneDeep";
19
- import Me from "lodash/debounce";
17
+ import * as T from "lib0/encoding";
18
+ import Ne from "lodash/debounce";
20
19
  import Ie from "lodash/get";
21
20
  import Ee from "lodash/isEmpty";
22
21
  import ve from "lodash/set";
23
- import gt from "lodash/union";
22
+ import mt from "lodash/union";
24
23
  import { LRUCache as be } from "lru-cache";
25
- import ht from "p-limit";
26
- import { DataTypes as k, Sequelize as yt, Model as Ne, Op as Fe } from "sequelize";
27
- import { pipeline as St } from "stream/promises";
28
- import { x as It } from "tar";
24
+ import gt from "p-limit";
25
+ import { DataTypes as k, Sequelize as ht, Model as Fe, Op as _e } from "sequelize";
26
+ import { pipeline as yt } from "stream/promises";
27
+ import { x as St } from "tar";
29
28
  import { joinURL as H } from "ufo";
30
- import Et from "wait-on";
31
- import { Awareness as bt, encodeAwarenessUpdate as je, removeAwarenessStates as wt, applyAwarenessUpdate as At } from "y-protocols/awareness";
32
- import { writeUpdate as Pt, writeSyncStep1 as Ct, readSyncMessage as Ot } from "y-protocols/sync";
29
+ import It from "wait-on";
30
+ import { Awareness as Et, encodeAwarenessUpdate as je, removeAwarenessStates as bt, applyAwarenessUpdate as wt } from "y-protocols/awareness";
31
+ import { writeUpdate as At, writeSyncStep1 as Pt, readSyncMessage as Ct } from "y-protocols/sync";
33
32
  import * as G from "yaml";
34
33
  import { m as ke } from "./html-DfzaaIYa.js";
35
34
  import "sqlite3";
36
35
  import "@blocklet/pages-kit/types/state";
37
- const vt = k.sqlite.DATE.parse;
38
- k.sqlite.DATE.parse = (t, e) => typeof t == "number" ? new Date(t) : vt(t, e);
39
- const F = new yt({
36
+ const Ot = k.sqlite.DATE.parse;
37
+ k.sqlite.DATE.parse = (t, e) => typeof t == "number" ? new Date(t) : Ot(t, e);
38
+ const F = new ht({
40
39
  dialect: "sqlite",
41
40
  storage: $e,
42
41
  benchmark: process.env.ENABLE_SEQUELIZE_BENCHMARK === "true",
@@ -60,7 +59,7 @@ process.on("SIGINT", async () => {
60
59
  process.on("SIGTERM", async () => {
61
60
  await F.close(), process.exit(0);
62
61
  });
63
- async function jt(t, e) {
62
+ async function vt(t, e) {
64
63
  try {
65
64
  if (t.getDialect() !== "sqlite")
66
65
  return;
@@ -78,12 +77,12 @@ let me = null;
78
77
  me && clearInterval(me);
79
78
  me = setInterval(
80
79
  async () => {
81
- f.info("Start cleanupSqliteMemory"), await jt(F, $e), f.info("End cleanupSqliteMemory");
80
+ f.info("Start cleanupSqliteMemory"), await vt(F, $e), f.info("End cleanupSqliteMemory");
82
81
  },
83
82
  60 * 1e3 * 10
84
83
  // 10 minutes
85
84
  );
86
- class we extends Ne {
85
+ class we extends Fe {
87
86
  // Foreign key to Component
88
87
  }
89
88
  we.init(
@@ -105,11 +104,11 @@ we.init(
105
104
  },
106
105
  { sequelize: F, tableName: "ProjectComponents", timestamps: !1 }
107
106
  );
108
- class M extends Ne {
107
+ class M extends Fe {
109
108
  static async getProjectByIdOrSlug(e) {
110
109
  return M.findOne({
111
110
  where: {
112
- [Fe.or]: [{ id: e }, { slug: e }]
111
+ [_e.or]: [{ id: e }, { slug: e }]
113
112
  }
114
113
  });
115
114
  }
@@ -192,65 +191,65 @@ M.hasMany(we, {
192
191
  foreignKey: "projectId",
193
192
  as: "components"
194
193
  });
195
- const kt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", De = "page", ge = "trigger-reload-project-resource", _e = kt, Dt = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM";
194
+ const jt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", Te = "page", ge = "trigger-reload-project-resource", xe = jt, kt = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM";
196
195
  function se(t) {
197
196
  t.observeDeep((e) => {
198
197
  e.some((s) => s.changes.keys.has("updatedAt") || s.changes.keys.has("publishedAt")) || t.set("updatedAt", (/* @__PURE__ */ new Date()).toISOString());
199
198
  });
200
199
  }
201
- function xe() {
202
- return at(b(E.env.dataDir, "tmp-"));
200
+ function Be() {
201
+ return ot(b(E.env.dataDir, "tmp-"));
203
202
  }
204
- function oe(t, e, s = []) {
205
- return Array.isArray(t) ? t.flatMap((o, a) => oe(o, e, [...s, a])) : typeof t == "object" ? t === null ? [] : Object.entries(t).flatMap(([o, a]) => oe(a, e, [...s, o])) : e(t) ? [s] : [];
203
+ function ae(t, e, s = []) {
204
+ return Array.isArray(t) ? t.flatMap((a, o) => ae(a, e, [...s, o])) : typeof t == "object" ? t === null ? [] : Object.entries(t).flatMap(([a, o]) => ae(o, e, [...s, a])) : e(t) ? [s] : [];
206
205
  }
207
- function T(t) {
206
+ function D(t) {
208
207
  return t.filter((e) => e != null);
209
208
  }
210
209
  function Tt(t) {
211
210
  t.pages && Object.keys(t.pages).forEach((s) => {
212
- const o = V(t.pages[s]);
213
- o && o instanceof N.Map && se(o);
211
+ const a = V(t.pages[s]);
212
+ a && a instanceof N.Map && se(a);
214
213
  });
215
214
  const e = V(t.pages);
216
215
  e && e instanceof N.Map && e.observe((s) => {
217
- s.changes.keys.forEach((o, a) => {
218
- if (o.action === "add") {
219
- const r = V(t.pages[a]);
216
+ s.changes.keys.forEach((a, o) => {
217
+ if (a.action === "add") {
218
+ const r = V(t.pages[o]);
220
219
  r && r instanceof N.Map && se(r);
221
220
  }
222
221
  });
223
222
  });
224
223
  }
225
- function Rt(t) {
224
+ function Dt(t) {
226
225
  t.routes && Object.keys(t.routes).forEach((s) => {
227
- const o = V(t.routes?.[s]);
228
- o && o instanceof N.Map && se(o);
226
+ const a = V(t.routes?.[s]);
227
+ a && a instanceof N.Map && se(a);
229
228
  });
230
229
  const e = V(t.routes);
231
230
  e && e instanceof N.Map && e.observe((s) => {
232
- s.changes.keys.forEach((o, a) => {
233
- if (o.action === "add") {
234
- const r = V(t.routes?.[a]);
231
+ s.changes.keys.forEach((a, o) => {
232
+ if (a.action === "add") {
233
+ const r = V(t.routes?.[o]);
235
234
  r && r instanceof N.Map && se(r);
236
235
  }
237
236
  });
238
237
  });
239
238
  }
240
- function Lt(t, e) {
239
+ function Rt(t, e) {
241
240
  for (const s of e || Object.keys(t.routes || {})) {
242
- let o = s, a = [];
241
+ let a = s, o = [];
243
242
  if (s.includes("-")) {
244
243
  const [r, ...c] = s.split("-");
245
- o = r, a = c || [];
244
+ a = r, o = c || [];
246
245
  }
247
- if (t.routes?.[o] !== void 0) {
248
- t.routes[o].publishedAt = (/* @__PURE__ */ new Date()).toISOString();
249
- const r = t.routes[o];
246
+ if (t.routes?.[a] !== void 0) {
247
+ t.routes[a].publishedAt = (/* @__PURE__ */ new Date()).toISOString();
248
+ const r = t.routes[a];
250
249
  if (!r || !r.params || r.params.length === 0)
251
250
  continue;
252
- if (s.includes("-") && a.length > 0) {
253
- const c = st(a, r);
251
+ if (s.includes("-") && o.length > 0) {
252
+ const c = at(o, r);
254
253
  c && (c.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
255
254
  }
256
255
  if (!e) {
@@ -274,69 +273,69 @@ function de({
274
273
  page: t,
275
274
  route: e,
276
275
  state: s,
277
- routeId: o,
278
- routePathInfo: a
276
+ routeId: a,
277
+ routePathInfo: o
279
278
  }) {
280
279
  f.info(
281
- `Executing datasource data assembly, routeId: ${o}, routePathInfo: ${JSON.stringify(a)}`
280
+ `Executing datasource data assembly, routeId: ${a}, routePathInfo: ${JSON.stringify(o)}`
282
281
  );
283
282
  const r = {
284
- ...ot(t),
285
- id: o,
286
- slug: a?.path ?? e.path,
283
+ ...Ue(t),
284
+ id: a,
285
+ slug: o?.path ?? e.path,
287
286
  createdAt: e.createdAt,
288
- updatedAt: a?.routeMetaData?.updatedAt ?? e.updatedAt,
289
- publishedAt: a?.routeMetaData?.publishedAt ?? e.publishedAt,
290
- isPublic: (a?.routeMetaData?.isPublic ?? e.isPublic) && e.isPublic
287
+ updatedAt: o?.routeMetaData?.updatedAt ?? e.updatedAt,
288
+ publishedAt: o?.routeMetaData?.publishedAt ?? e.publishedAt,
289
+ isPublic: (o?.routeMetaData?.isPublic ?? e.isPublic) && e.isPublic
291
290
  };
292
291
  for (const c of s.supportedLocales) {
293
292
  if (e.dataSource) {
294
293
  let l = e.id;
295
- a && (l = a.paramOptionIds.join("-"));
294
+ o && (l = o.paramOptionIds.join("-"));
296
295
  const p = e.dataSource.pathDataMappings?.[l]?.dataCache?.[c.locale] ?? e.dataSource.pathDataMappings?.[l]?.dataCache?.[s.config.defaultLocale || "en"];
297
296
  if (!p)
298
297
  continue;
299
- tt(r, s, c.locale, p);
298
+ st(r, s, c.locale, p);
300
299
  }
301
- a && a.routeMetaData && (a.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
300
+ o && o.routeMetaData && (o.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
302
301
  }
303
302
  return r;
304
303
  }
305
304
  ["true", "1", "yes", "y"].includes(process.env.USE_FS_CACHE_HTML ?? "");
306
- const $t = 60 * 60 * 1e3, Y = new be({
305
+ const Lt = 60 * 60 * 1e3, Y = new be({
307
306
  max: 100,
308
- ttl: $t,
307
+ ttl: Lt,
309
308
  ttlResolution: 10 * 1e3,
310
309
  // 10 seconds
311
310
  allowStale: !0
312
311
  });
313
- function Ut(t, e = []) {
312
+ function $t(t, e = []) {
314
313
  let s = 0;
315
- const o = Array.from(Y.keys());
316
- for (const a of o)
314
+ const a = Array.from(Y.keys());
315
+ for (const o of a)
317
316
  for (const r of t) {
318
- if (ke(a, { currentPath: r })) {
319
- Y.delete(a), s++, f.info(`[Cache CLEAR] key: ${a}`);
317
+ if (ke(o, { currentPath: r })) {
318
+ Y.delete(o), s++, f.info(`[Cache CLEAR] key: ${o}`);
320
319
  break;
321
320
  }
322
321
  for (const c of e)
323
- if (ke(a, { currentPath: `/${c}${r}` })) {
324
- Y.delete(a), s++, f.info(`[Cache CLEAR] key: ${a}`);
322
+ if (ke(o, { currentPath: `/${c}${r}` })) {
323
+ Y.delete(o), s++, f.info(`[Cache CLEAR] key: ${o}`);
325
324
  break;
326
325
  }
327
326
  }
328
327
  return f.info(`[Cache CLEAR] cleared ${s} entries for paths:`, t), s;
329
328
  }
330
- function Mt() {
329
+ function Ut() {
331
330
  const t = Y.size;
332
331
  return Y.clear(), f.info(`[Cache CLEAR ALL] cleared ${t} entries`), t;
333
332
  }
334
- E.events.on(E.Events.envUpdate, Mt);
335
- const { uploadToMediaKit: Nt } = require("@blocklet/uploader-server"), Ae = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, W = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, Te = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, Ft = 1e4, _t = 3e4, X = 0, fe = 1, xt = 0, Bt = 1, he = E, K = b(process.env.BLOCKLET_DATA_DIR, "site-state"), vs = ["production", "draft"], js = ["production"];
336
- function ae(t) {
333
+ E.events.on(E.Events.envUpdate, Ut);
334
+ const { uploadToMediaKit: Mt } = require("@blocklet/uploader-server"), Ae = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, W = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, De = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, Nt = 1e4, Ft = 3e4, X = 0, fe = 1, _t = 0, xt = 1, he = E, K = b(process.env.BLOCKLET_DATA_DIR, "site-state"), Cs = ["production", "draft"], Os = ["production"];
335
+ function oe(t) {
337
336
  return t?.replace(/\//g, "|") || "";
338
337
  }
339
- function Gt() {
338
+ function Bt() {
340
339
  const t = he.env.languages?.map((s) => ({ locale: s.code, name: s.name })) || [], e = t[0]?.locale || "en";
341
340
  return {
342
341
  pageIds: [],
@@ -354,7 +353,7 @@ function Gt() {
354
353
  class O extends N.Doc {
355
354
  constructor(e) {
356
355
  super(), this.options = e, U(this.draftYjsFilePath) && N.applyUpdate(this, q(this.draftYjsFilePath)), this.syncedStore = ft(
357
- et(
356
+ tt(
358
357
  {
359
358
  pages: {},
360
359
  pageIds: [],
@@ -369,7 +368,7 @@ class O extends N.Doc {
369
368
  },
370
369
  this
371
370
  )
372
- ), this.initObserver(), this.on("update", this.updateHandler), this.awareness = new bt(this), this.awareness.on("update", this.awarenessChangeHandler), this.ensureDataStructure();
371
+ ), this.initObserver(), this.on("update", this.updateHandler), this.awareness = new Et(this), this.awareness.on("update", this.awarenessChangeHandler), this.ensureDataStructure();
373
372
  }
374
373
  // 延迟释放时间:5 分钟
375
374
  static RELEASE_DELAY = 5 * 60 * 1e3;
@@ -389,8 +388,8 @@ class O extends N.Doc {
389
388
  if (!e)
390
389
  throw new Error("Should provide project context");
391
390
  try {
392
- const s = b(K, e), o = b(K, `@del-${e}`);
393
- Ce(s, o);
391
+ const s = b(K, e), a = b(K, `@del-${e}`);
392
+ Ce(s, a);
394
393
  } catch (s) {
395
394
  f.error("Failed to safe delete project state dir:", s);
396
395
  }
@@ -424,31 +423,31 @@ class O extends N.Doc {
424
423
  attributes: ["productionState"]
425
424
  });
426
425
  if (Ee(s?.productionState)) {
427
- const o = b(K, e, "production"), a = await Ge(o, { includeResources: !0 }) ?? Gt();
428
- if (!a?.config?.defaultLocale) {
429
- a.config ??= {};
426
+ const a = b(K, e, "production"), o = await Ve(a, { includeResources: !0 }) ?? Bt();
427
+ if (!o?.config?.defaultLocale) {
428
+ o.config ??= {};
430
429
  const r = he.env.languages?.map((c) => ({ locale: c.code, name: c.name })) || [];
431
- a.config.defaultLocale = r[0]?.locale;
430
+ o.config.defaultLocale = r[0]?.locale;
432
431
  }
433
- return a;
432
+ return o;
434
433
  }
435
434
  return s?.productionState;
436
435
  }
437
436
  destroy() {
438
- this.cancelRelease(), this.save({ flush: !0 }), this.conns.forEach((s, o) => this.closeConn(o)), this.awareness.destroy();
437
+ this.cancelRelease(), this.save({ flush: !0 }), this.conns.forEach((s, a) => this.closeConn(a)), this.awareness.destroy();
439
438
  const e = R(this.options.path);
440
439
  delete O.sharedInstances[e], super.destroy();
441
440
  }
442
441
  initObserver() {
443
- Tt(this.syncedStore), Rt(this.syncedStore);
442
+ Tt(this.syncedStore), Dt(this.syncedStore);
444
443
  }
445
444
  get draftYjsFilePath() {
446
445
  return b(this.options.path, "draft.yjs");
447
446
  }
448
447
  static async getStateByProjectId(e, s) {
449
448
  if (s === "draft") {
450
- const o = O.shared(e);
451
- return JSON.parse(JSON.stringify(o.syncedStore));
449
+ const a = O.shared(e);
450
+ return JSON.parse(JSON.stringify(a.syncedStore));
452
451
  }
453
452
  return O.getProductionState(e);
454
453
  }
@@ -459,8 +458,8 @@ class O extends N.Doc {
459
458
  return O.getProductionState(s);
460
459
  }
461
460
  async setState(e, s) {
462
- const o = await Kt(s, { exportAssets: !1, includeResources: !0 }), a = this.getPublishDir(e);
463
- if (_(L(a), { recursive: !0 }), Ue(a, { force: !0, recursive: !0 }), Ce(o, a), e === "production") {
461
+ const a = await Jt(s, { exportAssets: !1, includeResources: !0 }), o = this.getPublishDir(e);
462
+ if (_(L(o), { recursive: !0 }), Me(o, { force: !0, recursive: !0 }), Ce(a, o), e === "production") {
464
463
  const r = R(this.options.path);
465
464
  O.pageUrlMapCache.delete(r), await M.update({ productionState: { ...s } }, { where: { id: r } });
466
465
  }
@@ -473,35 +472,35 @@ class O extends N.Doc {
473
472
  awareness;
474
473
  // 延迟释放定时器
475
474
  releaseTimer;
476
- awarenessChangeHandler = ({ added: e, updated: s, removed: o }, a) => {
477
- const r = e.concat(s, o);
478
- if (a !== null) {
479
- const p = this.conns.get(a);
475
+ awarenessChangeHandler = ({ added: e, updated: s, removed: a }, o) => {
476
+ const r = e.concat(s, a);
477
+ if (o !== null) {
478
+ const p = this.conns.get(o);
480
479
  p && (e.forEach((y) => {
481
480
  p.add(y);
482
- }), o.forEach((y) => {
481
+ }), a.forEach((y) => {
483
482
  p.delete(y);
484
483
  }));
485
484
  }
486
- const c = D.createEncoder();
487
- D.writeVarUint(c, fe), D.writeVarUint8Array(c, je(this.awareness, r));
488
- const l = D.toUint8Array(c);
485
+ const c = T.createEncoder();
486
+ T.writeVarUint(c, fe), T.writeVarUint8Array(c, je(this.awareness, r));
487
+ const l = T.toUint8Array(c);
489
488
  this.conns.forEach((p, y) => this.send(y, l));
490
489
  };
491
490
  updateHandler = (e) => {
492
- const s = D.createEncoder();
493
- D.writeVarUint(s, X), Pt(s, e);
494
- const o = D.toUint8Array(s);
495
- this.conns.forEach((a, r) => this.send(r, o));
491
+ const s = T.createEncoder();
492
+ T.writeVarUint(s, X), At(s, e);
493
+ const a = T.toUint8Array(s);
494
+ this.conns.forEach((o, r) => this.send(r, a));
496
495
  };
497
496
  ensureDataStructure = () => {
498
- const { supportedLocales: e, pages: s, pageIds: o, config: a, routes: r, routeIds: c } = this.syncedStore;
497
+ const { supportedLocales: e, pages: s, pageIds: a, config: o, routes: r, routeIds: c } = this.syncedStore;
499
498
  {
500
499
  const l = new Set(Object.keys(s));
501
500
  let p = 0;
502
- for (; p < o.length; ) {
503
- const y = o[p];
504
- l.has(y) ? (l.delete(y), p++) : o.splice(p, 1);
501
+ for (; p < a.length; ) {
502
+ const y = a[p];
503
+ l.has(y) ? (l.delete(y), p++) : a.splice(p, 1);
505
504
  }
506
505
  }
507
506
  {
@@ -512,7 +511,7 @@ class O extends N.Doc {
512
511
  l.has(y) ? (l.delete(y), p++) : c.splice(p, 1);
513
512
  }
514
513
  }
515
- e.splice(0, e.length), e.push(...he.env.languages.map((l) => ({ locale: l.code, name: l.name }))), a.defaultLocale = e[0]?.locale;
514
+ e.splice(0, e.length), e.push(...he.env.languages.map((l) => ({ locale: l.code, name: l.name }))), o.defaultLocale = e[0]?.locale;
516
515
  {
517
516
  let l = 0;
518
517
  const p = /* @__PURE__ */ new Set();
@@ -523,10 +522,10 @@ class O extends N.Doc {
523
522
  }
524
523
  };
525
524
  send = (e, s) => {
526
- e.readyState !== xt && e.readyState !== Bt && this.closeConn(e);
525
+ e.readyState !== _t && e.readyState !== xt && this.closeConn(e);
527
526
  try {
528
- e.send(s, (o) => {
529
- o && this.closeConn(e);
527
+ e.send(s, (a) => {
528
+ a && this.closeConn(e);
530
529
  });
531
530
  } catch {
532
531
  this.closeConn(e);
@@ -535,7 +534,7 @@ class O extends N.Doc {
535
534
  closeConn = (e) => {
536
535
  if (e.removeAllListeners(), this.conns.has(e)) {
537
536
  const s = this.conns.get(e);
538
- this.conns.delete(e), s && wt(this.awareness, Array.from(s), null);
537
+ this.conns.delete(e), s && bt(this.awareness, Array.from(s), null);
539
538
  }
540
539
  e.close(), this.checkAndScheduleRelease();
541
540
  };
@@ -559,21 +558,21 @@ class O extends N.Doc {
559
558
  f.info(`[SiteState] cancelled scheduled release for project ${e}`);
560
559
  }
561
560
  }
562
- autoSave = Me(() => {
561
+ autoSave = Ne(() => {
563
562
  _(L(this.draftYjsFilePath), { recursive: !0 }), ee(this.draftYjsFilePath, N.encodeStateAsUpdate(this));
564
- }, Ft);
563
+ }, Nt);
565
564
  save = ({ flush: e = !1 } = {}) => {
566
565
  this.autoSave(), e && this.autoSave.flush();
567
566
  };
568
567
  publish = async ({ mode: e, routes: s }) => {
569
- const o = await this.getState("draft"), a = await this.getState("production");
570
- await Le(o, a, { routes: s, mergeMode: "replace", deleteRoutes: !0, publishMode: e }), a.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(), Lt(this.syncedStore, s), await this.setState(e, a), await this.clearPageCacheForRoutes(s, a);
568
+ const a = await this.getState("draft"), o = await this.getState("production");
569
+ await Le(a, o, { routes: s, mergeMode: "replace", deleteRoutes: !0, publishMode: e }), o.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(), Rt(this.syncedStore, s), await this.setState(e, o), await this.clearPageCacheForRoutes(s, o);
571
570
  };
572
571
  mergeState = async (e, s) => {
573
- const o = JSON.parse(JSON.stringify(s));
572
+ const a = JSON.parse(JSON.stringify(s));
574
573
  e.config.fontFamily ??= {};
575
- const a = o.config?.fontFamily, r = e.config?.fontFamily;
576
- e.config.fontFamily.title = a?.title || r?.title, e.config.fontFamily.description = a?.description || r?.description, await new Promise((c, l) => {
574
+ const o = a.config?.fontFamily, r = e.config?.fontFamily;
575
+ e.config.fontFamily.title = o?.title || r?.title, e.config.fontFamily.description = o?.description || r?.description, await new Promise((c, l) => {
577
576
  this.transact(async () => {
578
577
  try {
579
578
  const p = await Le(e, s);
@@ -585,96 +584,96 @@ class O extends N.Doc {
585
584
  });
586
585
  };
587
586
  clearPageCacheForRoutes = async (e, s) => {
588
- const o = R(this.options.path), r = (await M.findByPk(o))?.slug || o;
587
+ const a = R(this.options.path), r = (await M.findByPk(a))?.slug || a;
589
588
  let c = e;
590
- (!c || c.length === 0) && (c = s.pageIds ?? []), f.info(`[SiteState] clearing page cache for project ${o}, routes:`, c || []);
589
+ (!c || c.length === 0) && (c = s.pageIds ?? []), f.info(`[SiteState] clearing page cache for project ${a}, routes:`, c || []);
591
590
  const l = s.supportedLocales.map((w) => w.locale), p = [], y = c.filter((w) => s.pageIds?.includes(w));
592
591
  for (const w of y) {
593
592
  const I = s.pages[w].slug;
594
- r && r !== o && (r === "/" ? p.push(I) : p.push(`/${r}${I}`)), p.push(`/${o}${I}`);
593
+ r && r !== a && (r === "/" ? p.push(I) : p.push(`/${r}${I}`)), p.push(`/${a}${I}`);
595
594
  }
596
- if (f.info(`[SiteState] clearing page cache for project ${o}, pathPatterns:`, p), p.length > 0)
595
+ if (f.info(`[SiteState] clearing page cache for project ${a}, pathPatterns:`, p), p.length > 0)
597
596
  try {
598
- const w = Ut(p, l);
599
- f.info(`[SiteState] cleared ${w} page cache entries for project ${o}, routes:`, c);
597
+ const w = $t(p, l);
598
+ f.info(`[SiteState] cleared ${w} page cache entries for project ${a}, routes:`, c);
600
599
  } catch {
601
600
  }
602
601
  };
603
602
  addConnection = (e) => {
604
603
  if (this.conns.has(e))
605
604
  return;
606
- this.cancelRelease(), e.binaryType = "arraybuffer", this.conns.set(e, /* @__PURE__ */ new Set()), e.on("message", (a) => this.messageListener(e, new Uint8Array(a)));
605
+ this.cancelRelease(), e.binaryType = "arraybuffer", this.conns.set(e, /* @__PURE__ */ new Set()), e.on("message", (o) => this.messageListener(e, new Uint8Array(o)));
607
606
  let s = !0;
608
- const o = setInterval(() => {
607
+ const a = setInterval(() => {
609
608
  if (!s)
610
- this.conns.has(e) && this.closeConn(e), clearInterval(o);
609
+ this.conns.has(e) && this.closeConn(e), clearInterval(a);
611
610
  else if (this.conns.has(e)) {
612
611
  s = !1;
613
612
  try {
614
613
  e.ping();
615
614
  } catch {
616
- this.closeConn(e), clearInterval(o);
615
+ this.closeConn(e), clearInterval(a);
617
616
  }
618
617
  }
619
- }, _t);
618
+ }, Ft);
620
619
  e.on("close", () => {
621
- this.closeConn(e), clearInterval(o);
620
+ this.closeConn(e), clearInterval(a);
622
621
  }), e.on("pong", () => {
623
622
  s = !0;
624
623
  });
625
624
  {
626
- const a = D.createEncoder();
627
- D.writeVarUint(a, X), Ct(a, this), this.send(e, D.toUint8Array(a));
625
+ const o = T.createEncoder();
626
+ T.writeVarUint(o, X), Pt(o, this), this.send(e, T.toUint8Array(o));
628
627
  const r = this.awareness.getStates();
629
628
  if (r.size > 0) {
630
- const c = D.createEncoder();
631
- D.writeVarUint(c, fe), D.writeVarUint8Array(c, je(this.awareness, Array.from(r.keys()))), this.send(e, D.toUint8Array(c));
629
+ const c = T.createEncoder();
630
+ T.writeVarUint(c, fe), T.writeVarUint8Array(c, je(this.awareness, Array.from(r.keys()))), this.send(e, T.toUint8Array(c));
632
631
  }
633
632
  }
634
633
  };
635
634
  messageListener = (e, s) => {
636
635
  try {
637
- const o = D.createEncoder(), a = ue.createDecoder(s), r = ue.readVarUint(a);
636
+ const a = T.createEncoder(), o = ue.createDecoder(s), r = ue.readVarUint(o);
638
637
  switch (r) {
639
638
  case X:
640
- D.writeVarUint(o, X), Ot(a, o, this, null), D.length(o) > 1 && (this.ensureDataStructure(), this.send(e, D.toUint8Array(o)));
639
+ T.writeVarUint(a, X), Ct(o, a, this, null), T.length(a) > 1 && (this.ensureDataStructure(), this.send(e, T.toUint8Array(a)));
641
640
  break;
642
641
  case fe: {
643
- At(this.awareness, ue.readVarUint8Array(a), e);
642
+ wt(this.awareness, ue.readVarUint8Array(o), e);
644
643
  break;
645
644
  }
646
645
  default:
647
646
  f.warn(`Unsupported messageType ${r}`);
648
647
  }
649
- } catch (o) {
650
- f.error(o);
648
+ } catch (a) {
649
+ f.error(a);
651
650
  }
652
651
  this.save();
653
652
  };
654
653
  // 这个方法还是需要动态的,因为可能会动态修改 projectSlug、语言之类的
655
654
  static async pageUrlMap(e, s) {
656
- let o = [];
657
- s ? o = [s] : o = await this.getProjectIds();
658
- let a = {};
659
- if (e === "production" && o?.length) {
660
- const r = new Map(o?.map((c) => [c, !0]) || []);
661
- for (const c of o) {
655
+ let a = [];
656
+ s ? a = [s] : a = await this.getProjectIds();
657
+ let o = {};
658
+ if (e === "production" && a?.length) {
659
+ const r = new Map(a?.map((c) => [c, !0]) || []);
660
+ for (const c of a) {
662
661
  const l = O.pageUrlMapCache.get(c);
663
- l && (a = { ...a, ...l }, r.delete(c));
662
+ l && (o = { ...o, ...l }, r.delete(c));
664
663
  }
665
- o = Array.from(r.keys());
664
+ a = Array.from(r.keys());
666
665
  }
667
- if (o?.length) {
666
+ if (a?.length) {
668
667
  const r = await M.findAll({
669
668
  where: {
670
669
  id: {
671
- [Fe.in]: o
670
+ [_e.in]: a
672
671
  }
673
672
  }
674
673
  });
675
674
  await Promise.all(
676
675
  r?.map(async (c) => {
677
- const l = c.id, p = c.slug || l, y = {}, w = e === "production" && c?.productionState ? c.productionState : await O.getStateByProjectId(c.id, e), j = gt(
676
+ const l = c.id, p = c.slug || l, y = {}, w = e === "production" && c?.productionState ? c.productionState : await O.getStateByProjectId(c.id, e), j = mt(
678
677
  E.env.languages?.map((u) => u.code) || [],
679
678
  w.supportedLocales?.map((u) => u.locale) || []
680
679
  ), I = (u, i) => {
@@ -755,24 +754,24 @@ class O extends N.Doc {
755
754
  };
756
755
  I(g, m);
757
756
  }
758
- e === "production" && O.pageUrlMapCache.set(l, y), a = { ...a, ...y };
757
+ e === "production" && O.pageUrlMapCache.set(l, y), o = { ...o, ...y };
759
758
  })
760
759
  );
761
760
  }
762
- return a;
761
+ return o;
763
762
  }
764
763
  getDocumentSize() {
765
764
  return N.encodeStateAsUpdate(this).byteLength;
766
765
  }
767
766
  static getInstancesSizeInfo() {
768
767
  const e = [];
769
- for (const [s, o] of Object.entries(O.sharedInstances)) {
770
- const a = o.getDocumentSize();
768
+ for (const [s, a] of Object.entries(O.sharedInstances)) {
769
+ const o = a.getDocumentSize();
771
770
  e.push({
772
771
  projectId: s,
773
- sizeInBytes: a,
774
- sizeInMB: `${(a / (1024 * 1024)).toFixed(2)} MB`,
775
- activeConnections: o.conns.size
772
+ sizeInBytes: o,
773
+ sizeInMB: `${(o / (1024 * 1024)).toFixed(2)} MB`,
774
+ activeConnections: a.conns.size
776
775
  });
777
776
  }
778
777
  return e;
@@ -791,81 +790,81 @@ class O extends N.Doc {
791
790
  }
792
791
  // 执行定期检查
793
792
  static performPeriodicCheck() {
794
- const e = Object.keys(O.sharedInstances).length, s = [], o = [];
795
- for (const [a, r] of Object.entries(O.sharedInstances))
796
- r.conns.size === 0 ? s.push({ projectId: a, instance: r }) : o.push({ projectId: a, connections: r.conns.size });
793
+ const e = Object.keys(O.sharedInstances).length, s = [], a = [];
794
+ for (const [o, r] of Object.entries(O.sharedInstances))
795
+ r.conns.size === 0 ? s.push({ projectId: o, instance: r }) : a.push({ projectId: o, connections: r.conns.size });
797
796
  if (f.info(
798
- `[SiteState] periodic check summary: total instances: ${e}, with connections: ${o.length}, without connections: ${s.length}`
797
+ `[SiteState] periodic check summary: total instances: ${e}, with connections: ${a.length}, without connections: ${s.length}`
799
798
  ), s.length > 0) {
800
799
  f.info(
801
800
  `[SiteState] releasing ${s.length} instances without connections:`,
802
801
  s.map((r) => r.projectId)
803
802
  );
804
- let a = 0;
803
+ let o = 0;
805
804
  for (const { projectId: r, instance: c } of s)
806
805
  try {
807
- f.info(`[SiteState] releasing instance due to periodic check: ${r}`), c.destroy(), a++;
806
+ f.info(`[SiteState] releasing instance due to periodic check: ${r}`), c.destroy(), o++;
808
807
  } catch (l) {
809
808
  f.error(`[SiteState] failed to release instance ${r} during periodic check:`, l);
810
809
  }
811
810
  f.info(
812
- `[SiteState] periodic check completed: ${a}/${s.length} instances released successfully`
811
+ `[SiteState] periodic check completed: ${o}/${s.length} instances released successfully`
813
812
  );
814
813
  } else e > 0 ? f.debug("[SiteState] periodic check: all instances have active connections") : f.debug("[SiteState] periodic check: no instances exist");
815
814
  }
816
815
  }
817
- async function Vt(t, e, s) {
816
+ async function Gt(t, e, s) {
818
817
  if (!t || !U(t) || !B(t).isFile())
819
818
  return null;
820
- let o = s[t];
821
- return o || (o = (async () => {
819
+ let a = s[t];
820
+ return a || (a = (async () => {
822
821
  try {
823
- return (await Nt({
822
+ return (await Mt({
824
823
  filePath: t,
825
824
  fileName: e
826
825
  }))?.data?.filename;
827
- } catch (a) {
828
- return f.error(`Failed to upload asset ${t}:`, a), null;
826
+ } catch (o) {
827
+ return f.error(`Failed to upload asset ${t}:`, o), null;
829
828
  }
830
- })(), s[t] = o), o;
829
+ })(), s[t] = a), a;
831
830
  }
832
- const zt = async (t, e) => {
833
- const s = R(t), o = await dt({
834
- name: _e,
831
+ const Vt = async (t, e) => {
832
+ const s = R(t), a = await dt({
833
+ name: xe,
835
834
  path: H("/uploads", s),
836
835
  responseType: "stream",
837
836
  method: "GET"
838
837
  });
839
- if (o.status >= 200 && o.status < 400) {
840
- const a = it(e);
841
- await St(o.data, a);
838
+ if (a.status >= 200 && a.status < 400) {
839
+ const o = it(e);
840
+ await yt(a.data, o);
842
841
  } else
843
- throw new Error(`download asset failed ${o.status}`);
844
- }, Jt = async (t, e) => {
842
+ throw new Error(`download asset failed ${a.status}`);
843
+ }, zt = async (t, e) => {
845
844
  await Promise.all(
846
845
  t.map(async (s) => {
847
846
  try {
848
- await zt(s, b(e, R(s)));
849
- } catch (o) {
850
- f.error(`Failed to export assets: ${s}, ${o}`);
847
+ await Vt(s, b(e, R(s)));
848
+ } catch (a) {
849
+ f.error(`Failed to export assets: ${s}, ${a}`);
851
850
  }
852
851
  })
853
852
  );
854
853
  };
855
- function Be(t) {
856
- return Ae.test(t) ? [t] : W.test(t) ? (Te.lastIndex = 0, Array.from(t.matchAll(Te)).map((s) => s[1]).filter((s) => !!s)) : [];
854
+ function Ge(t) {
855
+ return Ae.test(t) ? [t] : W.test(t) ? (De.lastIndex = 0, Array.from(t.matchAll(De)).map((s) => s[1]).filter((s) => !!s)) : [];
857
856
  }
858
857
  async function Z(t, e, s) {
859
- const { getFilename: o, exportAssets: a } = s, r = b(e, o(t));
860
- if (_(L(r), { recursive: !0 }), ee(r, G.stringify(t)), a) {
861
- const l = oe(
858
+ const { getFilename: a, exportAssets: o } = s, r = b(e, a(t));
859
+ if (_(L(r), { recursive: !0 }), ee(r, G.stringify(t)), o) {
860
+ const l = ae(
862
861
  t,
863
862
  (p) => typeof p == "string" && (Ae.test(p) || W.test(p))
864
863
  ).map((p) => {
865
864
  const y = Ie(t, p);
866
- return Be(y);
865
+ return Ge(y);
867
866
  }).flat().filter(Boolean);
868
- await Jt(l, L(r));
867
+ await zt(l, L(r));
869
868
  }
870
869
  }
871
870
  const ye = new be({
@@ -874,20 +873,20 @@ const ye = new be({
874
873
  // 1 minute
875
874
  });
876
875
  async function Re(t, e, s) {
877
- const o = oe(
876
+ const a = ae(
878
877
  t,
879
878
  (l) => typeof l == "string" && (Ae.test(l) || W.test(l))
880
- ), a = ht(2), r = o.map(
881
- (l) => a(async () => {
879
+ ), o = gt(2), r = a.map(
880
+ (l) => o(async () => {
882
881
  try {
883
- const p = Ie(t, l), y = Be(p);
882
+ const p = Ie(t, l), y = Ge(p);
884
883
  for (const w of y) {
885
884
  const j = R(w), I = s.getFilePath(w, l), u = I ? `${I}:${j}` : j, i = ye.get(u);
886
885
  if (i) {
887
886
  W.test(p) || ve(t, l, i);
888
887
  return;
889
888
  }
890
- const g = await Vt(I, j, e);
889
+ const g = await Gt(I, j, e);
891
890
  g && (W.test(p) || ve(t, l, g), ye.set(u, g));
892
891
  }
893
892
  } catch (p) {
@@ -897,18 +896,18 @@ async function Re(t, e, s) {
897
896
  ), c = await Promise.allSettled(r);
898
897
  s.onFinish?.(c);
899
898
  }
900
- async function Kt(t, {
899
+ async function Jt(t, {
901
900
  exportAssets: e,
902
901
  pageIds: s = "all",
903
- componentIds: o = "all",
904
- rawConfig: a,
902
+ componentIds: a = "all",
903
+ rawConfig: o,
905
904
  includeResources: r = !1,
906
905
  routeIds: c = "all"
907
906
  } = {}) {
908
907
  const l = s === "all" ? t.pageIds : s, p = pt({
909
908
  state: t,
910
909
  pageIds: l,
911
- componentIds: o === "all" ? Object.keys(t.components) : o
910
+ componentIds: a === "all" ? Object.keys(t.components) : a
912
911
  }), y = c === "all" ? t.routeIds : c, w = (n) => ({
913
912
  id: n.id,
914
913
  name: n.name,
@@ -918,7 +917,7 @@ async function Kt(t, {
918
917
  component: n.component,
919
918
  config: n.config,
920
919
  visibility: n.visibility,
921
- sections: n?.sectionIds ? T(
920
+ sections: n?.sectionIds ? D(
922
921
  n?.sectionIds?.map((S) => {
923
922
  const v = n.sections?.[S];
924
923
  return v && w(v);
@@ -934,7 +933,7 @@ async function Kt(t, {
934
933
  isPublic: n.isPublic ?? !0,
935
934
  templateConfig: n.templateConfig,
936
935
  meta: n.locales?.[S] ?? {},
937
- sections: T(
936
+ sections: D(
938
937
  n.sectionIds.map((v) => {
939
938
  const x = n.sections[v];
940
939
  return x && w(x);
@@ -956,12 +955,12 @@ async function Kt(t, {
956
955
  enabledGenerate: n.enabledGenerate ?? !1,
957
956
  displayTemplateId: n.displayTemplateId,
958
957
  dataSource: n.dataSource
959
- }), u = T(
958
+ }), u = D(
960
959
  y.map((n) => {
961
960
  const S = t.routes[n];
962
961
  return S && I(S);
963
962
  })
964
- ), i = T(
963
+ ), i = D(
965
964
  t.supportedLocales.map((n) => n.locale).flatMap(
966
965
  (n) => l.map((S) => {
967
966
  const v = t.pages[S];
@@ -972,7 +971,7 @@ async function Kt(t, {
972
971
  };
973
972
  })
974
973
  )
975
- ), g = xe(), C = b(g, "pages");
974
+ ), g = Be(), C = b(g, "pages");
976
975
  _(C, { recursive: !0 });
977
976
  const m = b(g, "components");
978
977
  _(m, { recursive: !0 });
@@ -980,13 +979,13 @@ async function Kt(t, {
980
979
  _(d, { recursive: !0 });
981
980
  for (const { locale: n, slug: S, page: v } of i)
982
981
  await Z(v, C, {
983
- getFilename: () => `${ae(S) || "index"}.${n}.yml`,
982
+ getFilename: () => `${oe(S) || "index"}.${n}.yml`,
984
983
  exportAssets: e
985
984
  });
986
985
  for (const n of u)
987
986
  await Z(n, d, {
988
987
  // getFilename: () => `${sanitizeSlug(route.path)}.yml`,
989
- getFilename: () => `${ae(n.path) || "index"}.yml`,
988
+ getFilename: () => `${oe(n.path) || "index"}.yml`,
990
989
  exportAssets: e
991
990
  });
992
991
  for (const n of p) {
@@ -999,19 +998,19 @@ async function Kt(t, {
999
998
  const h = b(g, ".blocklet/pages/pages.config.yml");
1000
999
  _(L(h), { recursive: !0 });
1001
1000
  const A = {
1002
- pages: T(
1001
+ pages: D(
1003
1002
  l.map((n) => {
1004
1003
  const S = t.pages[n];
1005
1004
  return S && { id: n, slug: S.slug };
1006
1005
  })
1007
1006
  ),
1008
- routes: T(
1007
+ routes: D(
1009
1008
  y.map((n) => {
1010
1009
  const S = t.routes[n];
1011
1010
  return S && { id: n, path: S.path };
1012
1011
  })
1013
1012
  ),
1014
- components: T(
1013
+ components: D(
1015
1014
  p.map((n) => {
1016
1015
  const S = t.components[n]?.data;
1017
1016
  return S && {
@@ -1022,7 +1021,7 @@ async function Kt(t, {
1022
1021
  ),
1023
1022
  ...r ? {
1024
1023
  resources: {
1025
- components: T(
1024
+ components: D(
1026
1025
  Object.keys(t.resources?.components || {}).filter((n) => p.includes(n)).map((n) => ({
1027
1026
  id: n,
1028
1027
  name: t.resources?.components?.[n]?.component?.name
@@ -1035,7 +1034,7 @@ async function Kt(t, {
1035
1034
  };
1036
1035
  ee(h, G.stringify(A));
1037
1036
  const P = b(g, "config.source.json");
1038
- if (a && ee(P, JSON.stringify(a)), r) {
1037
+ if (o && ee(P, JSON.stringify(o)), r) {
1039
1038
  const n = b(g, "resources"), S = b(n, "components");
1040
1039
  _(S, { recursive: !0 });
1041
1040
  for (const z of Object.keys(t?.resources?.components ?? {}).filter(
@@ -1049,7 +1048,7 @@ async function Kt(t, {
1049
1048
  }
1050
1049
  const v = b(g, "chunks");
1051
1050
  _(v, { recursive: !0 });
1052
- const x = qt();
1051
+ const x = Kt();
1053
1052
  for (const z of Object.keys(t?.resources?.components ?? {}).filter(
1054
1053
  ($) => p.includes($)
1055
1054
  )) {
@@ -1061,8 +1060,8 @@ async function Kt(t, {
1061
1060
  const Pe = b(v, pe), le = x?.[pe];
1062
1061
  try {
1063
1062
  le && U(le) && !U(Pe) && rt(le, Pe);
1064
- } catch (Ye) {
1065
- f.error(`copy chunk ${pe} error`, Ye.message);
1063
+ } catch (We) {
1064
+ f.error(`copy chunk ${pe} error`, We.message);
1066
1065
  }
1067
1066
  }
1068
1067
  }
@@ -1070,13 +1069,13 @@ async function Kt(t, {
1070
1069
  }
1071
1070
  return g;
1072
1071
  }
1073
- async function Ge(t, { importAssets: e, includeResources: s } = {}) {
1072
+ async function Ve(t, { importAssets: e, includeResources: s } = {}) {
1074
1073
  if (!U(t))
1075
1074
  return null;
1076
- let o, a = !1;
1075
+ let a, o = !1;
1077
1076
  try {
1078
- B(t).isDirectory() ? o = t : /\.(tgz|gz|tar)$/.test(t) && (a = !0, o = xe(), await It({ file: t, C: o }));
1079
- const r = te("**/.blocklet/pages/pages.config.yml", { cwd: o, absolute: !0 }).at(0), c = r && b(L(r), "../../pages"), l = r && b(L(r), "../../components"), p = r && b(L(r), "../../routes");
1077
+ B(t).isDirectory() ? a = t : /\.(tgz|gz|tar)$/.test(t) && (o = !0, a = Be(), await St({ file: t, C: a }));
1078
+ const r = te("**/.blocklet/pages/pages.config.yml", { cwd: a, absolute: !0 }).at(0), c = r && b(L(r), "../../pages"), l = r && b(L(r), "../../components"), p = r && b(L(r), "../../routes");
1080
1079
  if (!r)
1081
1080
  return null;
1082
1081
  const y = G.parse(q(r).toString()), w = (m, d, h) => {
@@ -1093,11 +1092,11 @@ async function Ge(t, { importAssets: e, includeResources: s } = {}) {
1093
1092
  }, I = (m, d) => {
1094
1093
  let h = b(m, `${d}.yml`);
1095
1094
  return (!U(h) || !B(h).isFile()) && (h = b(m, d, "index.yml"), !U(h) || !B(h)) ? null : G.parse(q(h).toString());
1096
- }, u = T(
1095
+ }, u = D(
1097
1096
  y.pages.map(({ slug: m }) => {
1098
- const d = T(
1097
+ const d = D(
1099
1098
  y.supportedLocales.map(({ locale: P }) => {
1100
- const n = c ? w(c, ae(m), P) : void 0;
1099
+ const n = c ? w(c, oe(m), P) : void 0;
1101
1100
  if (n)
1102
1101
  return { locale: P, page: n };
1103
1102
  const S = c ? w(c, m, P) : void 0;
@@ -1146,9 +1145,9 @@ async function Ge(t, { importAssets: e, includeResources: s } = {}) {
1146
1145
  )
1147
1146
  };
1148
1147
  })
1149
- ), i = T(
1148
+ ), i = D(
1150
1149
  y?.routes?.map(({ path: m }) => {
1151
- const d = p ? I(p, ae(m)) : void 0;
1150
+ const d = p ? I(p, oe(m)) : void 0;
1152
1151
  return {
1153
1152
  ...d,
1154
1153
  id: d?.id || Oe(),
@@ -1164,14 +1163,14 @@ async function Ge(t, { importAssets: e, includeResources: s } = {}) {
1164
1163
  dataSource: d?.dataSource ?? {}
1165
1164
  };
1166
1165
  }) ?? []
1167
- ), g = l ? T(y.components?.map(({ id: m }) => j(l, m)) ?? []) : [];
1166
+ ), g = l ? D(y.components?.map(({ id: m }) => j(l, m)) ?? []) : [];
1168
1167
  if (e) {
1169
1168
  const m = (...d) => {
1170
- f.info(`[${a ? R(t) : R(b(t, "../../../../"))}] importAssets:`, ...d);
1169
+ f.info(`[${o ? R(t) : R(b(t, "../../../../"))}] importAssets:`, ...d);
1171
1170
  };
1172
1171
  try {
1173
- m("wait image-bin api ready"), await Et({
1174
- resources: [`${lt(We)}/api/sdk/uploads`],
1172
+ m("wait image-bin api ready"), await It({
1173
+ resources: [`${lt(Qe)}/api/sdk/uploads`],
1175
1174
  validateStatus: (A) => A >= 200 && A <= 500
1176
1175
  }), m("image-bin api is ready");
1177
1176
  const d = {}, h = {};
@@ -1198,7 +1197,7 @@ async function Ge(t, { importAssets: e, includeResources: s } = {}) {
1198
1197
  }
1199
1198
  const C = {};
1200
1199
  if (s) {
1201
- const m = r && b(L(r), "../../resources/components"), d = T(
1200
+ const m = r && b(L(r), "../../resources/components"), d = D(
1202
1201
  y.resources?.components?.map(({ id: h }) => j(m, h)) ?? []
1203
1202
  );
1204
1203
  d.length > 0 && (C.components = Object.fromEntries(
@@ -1218,17 +1217,17 @@ async function Ge(t, { importAssets: e, includeResources: s } = {}) {
1218
1217
  dataSources: {}
1219
1218
  };
1220
1219
  } finally {
1221
- a && o && Ue(o, { force: !0, recursive: !0 });
1220
+ o && a && Me(a, { force: !0, recursive: !0 });
1222
1221
  }
1223
1222
  }
1224
1223
  async function Le(t, e, {
1225
1224
  routes: s,
1226
- mergeMode: o = "byUpdateTime",
1227
- deleteRoutes: a = !1,
1225
+ mergeMode: a = "byUpdateTime",
1226
+ deleteRoutes: o = !1,
1228
1227
  publishMode: r = void 0
1229
1228
  } = {}) {
1230
1229
  try {
1231
- r && Qe(r);
1230
+ r && Xe(r);
1232
1231
  } catch (I) {
1233
1232
  f.error("clear preload page cache error", { error: I });
1234
1233
  }
@@ -1261,7 +1260,7 @@ async function Le(t, e, {
1261
1260
  const C = y?.[g];
1262
1261
  if (!C) {
1263
1262
  const d = e.pageIds.indexOf(g);
1264
- d !== -1 && a && (e.pageIds.splice(d, 1), delete e.pages[g]);
1263
+ d !== -1 && o && (e.pageIds.splice(d, 1), delete e.pages[g]);
1265
1264
  for (const h of e.pageIds)
1266
1265
  h.includes(`${g}-`) && (e.pageIds.splice(e.pageIds.indexOf(h), 1), delete e.pages[h]);
1267
1266
  f.info("delete main route page", g);
@@ -1269,7 +1268,7 @@ async function Le(t, e, {
1269
1268
  }
1270
1269
  if (i.includes("-") && !u?.[i]) {
1271
1270
  const d = e.pageIds.indexOf(i);
1272
- d !== -1 && a && (e.pageIds.splice(d, 1), delete e.pages[i]), f.info("delete page", i);
1271
+ d !== -1 && o && (e.pageIds.splice(d, 1), delete e.pages[i]), f.info("delete page", i);
1273
1272
  continue;
1274
1273
  }
1275
1274
  if (!C.displayTemplateId) {
@@ -1282,7 +1281,7 @@ async function Le(t, e, {
1282
1281
  continue;
1283
1282
  }
1284
1283
  if (e.pageIds.includes(i)) {
1285
- if (f.info("has need update page", i), o === "replace")
1284
+ if (f.info("has need update page", i), a === "replace")
1286
1285
  e.pages[i] = de({
1287
1286
  page: m,
1288
1287
  route: C,
@@ -1290,7 +1289,7 @@ async function Le(t, e, {
1290
1289
  routeId: i,
1291
1290
  routePathInfo: u?.[i]
1292
1291
  }), f.info("replace page", i);
1293
- else if (o === "byUpdateTime") {
1292
+ else if (a === "byUpdateTime") {
1294
1293
  const d = e.pages[C.id];
1295
1294
  (!d || C.updatedAt && C.updatedAt > d.updatedAt) && (e.pages[i] = de({
1296
1295
  page: m,
@@ -1309,7 +1308,7 @@ async function Le(t, e, {
1309
1308
  routePathInfo: u?.[i]
1310
1309
  }), f.info("add page", i);
1311
1310
  }
1312
- if (a && !s)
1311
+ if (o && !s)
1313
1312
  for (const i of e.pageIds)
1314
1313
  I?.includes(i) || (delete e.pages[i], f.info("delete page", i)), e.pageIds = [...e.pageIds].filter((g) => I?.includes(g));
1315
1314
  } else {
@@ -1317,9 +1316,9 @@ async function Le(t, e, {
1317
1316
  const u = c[I];
1318
1317
  if (u)
1319
1318
  if (e.pageIds.includes(u.id)) {
1320
- if (o === "replace")
1319
+ if (a === "replace")
1321
1320
  e.pages[u.id] = u;
1322
- else if (o === "byUpdateTime") {
1321
+ else if (a === "byUpdateTime") {
1323
1322
  const i = e.pages[u.id];
1324
1323
  (!i || u.updatedAt && u.updatedAt > i.updatedAt) && (e.pages[u.id] = u);
1325
1324
  }
@@ -1330,9 +1329,9 @@ async function Le(t, e, {
1330
1329
  const u = y[I];
1331
1330
  if (u)
1332
1331
  if (e.routeIds.includes(u.id)) {
1333
- if (o === "replace")
1332
+ if (a === "replace")
1334
1333
  e.routes[u.id] = u;
1335
- else if (o === "byUpdateTime") {
1334
+ else if (a === "byUpdateTime") {
1336
1335
  const i = e.routes[u.id];
1337
1336
  (!i || u.updatedAt && u.updatedAt > i.updatedAt) && (e.routes[u.id] = u);
1338
1337
  }
@@ -1340,14 +1339,14 @@ async function Le(t, e, {
1340
1339
  e.routeIds.push(u.id), e.routes[u.id] = u;
1341
1340
  }
1342
1341
  }
1343
- if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...mt(w)), a)
1342
+ if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...Ue(w)), o)
1344
1343
  for (const I of Object.keys(e.components))
1345
1344
  delete e.components[I];
1346
1345
  let j = JSON.parse(JSON.stringify(t.components));
1347
1346
  j = Object.fromEntries(
1348
1347
  await Promise.all(
1349
1348
  Object.entries(j).map(async ([I, u]) => {
1350
- const i = await Ve(u?.data);
1349
+ const i = await ze(u?.data);
1351
1350
  return [
1352
1351
  I,
1353
1352
  {
@@ -1359,7 +1358,7 @@ async function Le(t, e, {
1359
1358
  )
1360
1359
  ), Object.assign(e.components, j), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))), Ee(t.resources.components) || (e.resources.components = JSON.parse(JSON.stringify(t.resources.components || {})));
1361
1360
  }
1362
- const Ve = Xe(
1361
+ const ze = Ze(
1363
1362
  async (t) => {
1364
1363
  if (!Ee(t?.properties))
1365
1364
  return t;
@@ -1367,20 +1366,20 @@ const Ve = Xe(
1367
1366
  const { script: e, PROPERTIES_SCHEMA: s } = t?.renderer || {};
1368
1367
  if (s || e && e.includes("PROPERTIES_SCHEMA"))
1369
1368
  try {
1370
- const o = await Ze(
1369
+ const a = await et(
1371
1370
  e ?? "",
1372
1371
  "PROPERTIES_SCHEMA",
1373
1372
  t.id,
1374
1373
  s
1375
1374
  );
1376
- o && o.length > 0 && t && (t.properties = {}, o.forEach((a, r) => {
1377
- t?.properties && (t.properties[a.id] = {
1375
+ a && a.length > 0 && t && (t.properties = {}, a.forEach((o, r) => {
1376
+ t?.properties && (t.properties[o.id] = {
1378
1377
  index: r,
1379
- data: a
1378
+ data: o
1380
1379
  });
1381
1380
  }));
1382
- } catch (o) {
1383
- f.error("getPropertiesFromCode error", { componentId: t.id, name: t.name }, { error: o });
1381
+ } catch (a) {
1382
+ f.error("getPropertiesFromCode error", { componentId: t.id, name: t.name }, { error: a });
1384
1383
  }
1385
1384
  }
1386
1385
  return t;
@@ -1390,57 +1389,57 @@ const Ve = Xe(
1390
1389
  }
1391
1390
  );
1392
1391
  let re, Q, ne, ie;
1393
- const ze = () => ut({
1392
+ const Je = () => ut({
1394
1393
  types: [
1395
- { did: _e, type: De },
1396
- { did: Dt, type: De }
1394
+ { did: xe, type: Te },
1395
+ { did: kt, type: Te }
1397
1396
  ]
1398
- }), qt = () => {
1399
- const t = ze(), e = {};
1397
+ }), Kt = () => {
1398
+ const t = Je(), e = {};
1400
1399
  return t.forEach((s) => {
1401
- const o = te("**/.blocklet/pages/pages.config.yml", { cwd: s.path, absolute: !0 }).at(0), a = o && b(L(o), "../../chunks");
1402
- if (a && U(a)) {
1403
- const r = nt(a);
1400
+ const a = te("**/.blocklet/pages/pages.config.yml", { cwd: s.path, absolute: !0 }).at(0), o = a && b(L(a), "../../chunks");
1401
+ if (o && U(o)) {
1402
+ const r = nt(o);
1404
1403
  for (const c of r)
1405
- e[c] = b(a, c);
1404
+ e[c] = b(o, c);
1406
1405
  }
1407
1406
  }), e;
1408
1407
  };
1409
- function Je() {
1408
+ function Ke() {
1410
1409
  return re = (async () => {
1411
- const t = ze();
1410
+ const t = Je();
1412
1411
  Q = (await Promise.all(
1413
1412
  t.map(async (s) => {
1414
- const o = s.path ? await Ge(s.path, { importAssets: !1 }) : void 0;
1415
- return o ? { blockletId: s.did, state: o, blockletTitle: s.title } : void 0;
1413
+ const a = s.path ? await Ve(s.path, { importAssets: !1 }) : void 0;
1414
+ return a ? { blockletId: s.did, state: a, blockletTitle: s.title } : void 0;
1416
1415
  })
1417
1416
  )).filter((s) => !!s), ne = Q.reduce(
1418
- (s, o) => Object.assign(
1417
+ (s, a) => Object.assign(
1419
1418
  s,
1420
1419
  Object.fromEntries(
1421
- Object.values(o.state.pages).map((a) => a ? [a?.id, { page: a, blockletId: o.blockletId }] : [])
1420
+ Object.values(a.state.pages).map((o) => o ? [o?.id, { page: o, blockletId: a.blockletId }] : [])
1422
1421
  )
1423
1422
  ),
1424
1423
  {}
1425
1424
  );
1426
1425
  const e = Q.reduce(
1427
- (s, o) => Object.assign(
1426
+ (s, a) => Object.assign(
1428
1427
  s,
1429
1428
  Object.fromEntries(
1430
- Object.values(o.state.components).map((a) => [a.data.id, { blockletId: o.blockletId, component: a.data }])
1429
+ Object.values(a.state.components).map((o) => [o.data.id, { blockletId: a.blockletId, component: o.data }])
1431
1430
  )
1432
1431
  ),
1433
1432
  {}
1434
1433
  );
1435
1434
  ie = Object.fromEntries(
1436
1435
  await Promise.all(
1437
- Object.entries(e).map(async ([s, o]) => {
1438
- const a = await Ve(o.component);
1436
+ Object.entries(e).map(async ([s, a]) => {
1437
+ const o = await ze(a.component);
1439
1438
  return [
1440
1439
  s,
1441
1440
  {
1442
- ...o,
1443
- component: a
1441
+ ...a,
1442
+ component: o
1444
1443
  }
1445
1444
  ];
1446
1445
  })
@@ -1448,10 +1447,10 @@ function Je() {
1448
1447
  );
1449
1448
  })(), re;
1450
1449
  }
1451
- function Ht(t) {
1452
- const e = Me(
1450
+ function qt(t) {
1451
+ const e = Ne(
1453
1452
  async () => {
1454
- await Je().catch((s) => {
1453
+ await Ke().catch((s) => {
1455
1454
  f.error("load resource states error", { error: s });
1456
1455
  }), await t?.({
1457
1456
  states: Q,
@@ -1467,31 +1466,31 @@ function Ht(t) {
1467
1466
  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(ge, e);
1468
1467
  };
1469
1468
  }
1470
- const Ke = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), qe = Symbol.for("GLOBAL_ENV_UPDATE_LISTENER_KEY"), ce = globalThis;
1471
- ce[Ke]?.();
1472
- ce[Ke] = Ht(async ({ pages: t, components: e }) => {
1469
+ const qe = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), He = Symbol.for("GLOBAL_ENV_UPDATE_LISTENER_KEY"), ce = globalThis;
1470
+ ce[qe]?.();
1471
+ ce[qe] = qt(async ({ pages: t, components: e }) => {
1473
1472
  const s = await O.getProjectIds();
1474
1473
  f.info(`start update resource states projects(${s.length})`, s), await Promise.race([
1475
- new Promise((o) => {
1474
+ new Promise((a) => {
1476
1475
  setTimeout(() => {
1477
- o({});
1476
+ a({});
1478
1477
  }, 30 * 1e3);
1479
1478
  }),
1480
1479
  Promise.all(
1481
- s.map(async (o) => {
1482
- He({
1483
- projectId: o,
1480
+ s.map(async (a) => {
1481
+ Ye({
1482
+ projectId: a,
1484
1483
  pages: t,
1485
1484
  components: e
1486
1485
  });
1487
1486
  })
1488
1487
  )
1489
- ]).catch((o) => {
1490
- f.error("update resource states failed:", o);
1488
+ ]).catch((a) => {
1489
+ f.error("update resource states failed:", a);
1491
1490
  });
1492
1491
  });
1493
- ce[qe]?.();
1494
- ce[qe] = () => {
1492
+ ce[He]?.();
1493
+ ce[He] = () => {
1495
1494
  const t = () => {
1496
1495
  O.pageUrlMapCache.clear(), f.info("[Cache CLEAR ALL] clear all page url map cache by env update");
1497
1496
  };
@@ -1509,60 +1508,60 @@ process.on("SIGINT", () => {
1509
1508
  process.on("SIGTERM", () => {
1510
1509
  O.stopPeriodicCheck(), process.exit(0);
1511
1510
  });
1512
- async function He({
1511
+ async function Ye({
1513
1512
  projectId: t,
1514
1513
  pages: e,
1515
1514
  components: s
1516
1515
  }) {
1517
- const o = O.sharedInstances[t];
1518
- if (!o) {
1516
+ const a = O.sharedInstances[t];
1517
+ if (!a) {
1519
1518
  f.info(`projectId: ${t} not found in sharedInstances`);
1520
1519
  return;
1521
1520
  }
1522
- if (o.syncedStore.resources.pages = e, (await M.findByPk(t))?.useAllResources)
1523
- o.syncedStore.resources.components = s;
1521
+ if (a.syncedStore.resources.pages = e, (await M.findByPk(t))?.useAllResources)
1522
+ a.syncedStore.resources.components = s;
1524
1523
  else {
1525
1524
  const c = (await we.findAll({ where: { projectId: t } })).map((p) => p.componentId), l = Object.fromEntries(
1526
1525
  Object.entries(s || {}).filter(([p]) => c.includes(p))
1527
1526
  );
1528
- o.syncedStore.resources.components = l;
1527
+ a.syncedStore.resources.components = l;
1529
1528
  }
1530
1529
  f.info(`update [${t}] resource states:`, {
1531
- pages: Object.keys(o.syncedStore.resources.pages || {}).length,
1532
- components: Object.keys(o.syncedStore.resources.components || {}).length
1530
+ pages: Object.keys(a.syncedStore.resources.pages || {}).length,
1531
+ components: Object.keys(a.syncedStore.resources.components || {}).length
1533
1532
  });
1534
1533
  }
1535
- async function ks(t) {
1536
- return He({
1534
+ async function vs(t) {
1535
+ return Ye({
1537
1536
  projectId: t,
1538
1537
  pages: ne,
1539
1538
  components: ie
1540
1539
  });
1541
1540
  }
1542
- async function Ds() {
1541
+ async function js() {
1543
1542
  f.info("trigger reload all project resource"), E.events.emit(ge);
1544
1543
  }
1545
- async function Ts({
1544
+ async function ks({
1546
1545
  ensureLoaded: t = !0
1547
1546
  } = {}) {
1548
- return t && (re ??= Je(), await re), { states: Q, pages: ne, components: ie };
1547
+ return t && (re ??= Ke(), await re), { states: Q, pages: ne, components: ie };
1549
1548
  }
1550
1549
  export {
1551
- _e as C,
1550
+ xe as C,
1552
1551
  M as P,
1553
- De as R,
1552
+ Te as R,
1554
1553
  O as S,
1555
1554
  K as a,
1556
- vs as b,
1557
- js as c,
1558
- Gt as d,
1559
- zt as e,
1560
- Jt as f,
1561
- Ts as g,
1562
- Ge as h,
1563
- Ht as i,
1564
- Ds as j,
1555
+ Cs as b,
1556
+ Os as c,
1557
+ Bt as d,
1558
+ Vt as e,
1559
+ zt as f,
1560
+ ks as g,
1561
+ Ve as h,
1562
+ qt as i,
1563
+ js as j,
1565
1564
  Le as m,
1566
- Kt as t,
1567
- ks as u
1565
+ Jt as t,
1566
+ vs as u
1568
1567
  };