@blocklet/pages-kit-inner-components 0.7.11 → 0.7.12

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,47 +1,47 @@
1
- import { d as Je, l as p, m as lt, b as pt, I as ut, c as dt } from "./components-D4ywfyMi.js";
2
- import { getYjsValue as J, syncedStore as ft } from "@syncedstore/core";
1
+ import { d as ze, l as p, m as it, b as ct, I as lt, c as pt } from "./components-D4ywfyMi.js";
2
+ import { getYjsValue as W, syncedStore as ut } from "@syncedstore/core";
3
3
  import * as F from "yjs";
4
- import { setPageDataSource as mt } from "@blocklet/pages-kit/utils/data-source";
5
- import { getRouteMetaDataByOptionIds as gt, generateParamCombinations as be } from "@blocklet/pages-kit/utils/route";
4
+ import { setPageDataSource as dt } from "@blocklet/pages-kit/utils/data-source";
5
+ import { getRouteMetaDataByOptionIds as ft, generateParamCombinations as be } from "@blocklet/pages-kit/utils/route";
6
6
  import Ae from "lodash/cloneDeep";
7
- import { DataTypes as P, Sequelize as ht, Model as Ee, Op as Z } from "sequelize";
7
+ import { DataTypes as P, Sequelize as mt, Model as Ee, Op as Z } from "sequelize";
8
8
  import "sqlite3";
9
9
  import E from "@blocklet/sdk/lib/config";
10
- import { withoutTrailingSlash as Oe, withLeadingSlash as He, joinURL as x } from "ufo";
11
- import { union as yt, debounce as St } from "lodash";
12
- import Le from "crypto";
13
- import z, { mkdtempSync as wt, existsSync as It, readFileSync as Pt, createWriteStream as bt } from "fs";
14
- import Re from "p-limit";
15
- import $e, { join as A, basename as $, dirname as M } from "path";
16
- import { Worker as At } from "worker_threads";
17
- import { nextId as Ue } from "@blocklet/pages-kit/utils/common";
18
- import { unzipSection as Et } from "@blocklet/pages-kit/utils/page-model";
19
- import { getComponentDependencies as Ot } from "@blocklet/pages-kit/utils/property";
20
- import { getComponentWebEndpoint as Rt, getResources as Ct, call as jt } from "@blocklet/sdk/lib/component";
21
- import { reactive as kt } from "@reactivedata/reactive";
22
- import { rename as Ne, mkdir as B, rm as We, writeFile as re, lstat as oe, readFile as te, copyFile as Dt, readdir as vt } from "fs/promises";
23
- import { globSync as Tt, glob as ye } from "glob";
10
+ import { withoutTrailingSlash as je, withLeadingSlash as qe, joinURL as x } from "ufo";
11
+ import { union as gt, debounce as ht } from "lodash";
12
+ import "crypto";
13
+ import z, { mkdtempSync as yt, existsSync as St, readFileSync as wt, createWriteStream as It } from "fs";
14
+ import Oe from "p-limit";
15
+ import Le, { join as A, basename as $, dirname as M } from "path";
16
+ import { Worker as Pt } from "worker_threads";
17
+ import { nextId as $e } from "@blocklet/pages-kit/utils/common";
18
+ import { unzipSection as bt } from "@blocklet/pages-kit/utils/page-model";
19
+ import { getComponentDependencies as At } from "@blocklet/pages-kit/utils/property";
20
+ import { getComponentWebEndpoint as Et, getResources as jt, call as Ot } from "@blocklet/sdk/lib/component";
21
+ import { reactive as Rt } from "@reactivedata/reactive";
22
+ import { rename as Ue, mkdir as B, rm as We, writeFile as re, lstat as oe, readFile as te, copyFile as Ct, readdir as Dt } from "fs/promises";
23
+ import { globSync as vt, glob as ye } from "glob";
24
24
  import * as fe from "lib0/decoding";
25
- import * as v from "lib0/encoding";
26
- import Ce from "lodash/debounce";
27
- import je from "lodash/get";
28
- import ke from "lodash/isEmpty";
29
- import Me from "lodash/set";
30
- import Lt from "lodash/union";
31
- import { LRUCache as Ke } from "lru-cache";
32
- import { pipeline as $t } from "stream/promises";
33
- import { x as Ut } from "tar";
34
- import Nt from "wait-on";
35
- import { Awareness as Mt, encodeAwarenessUpdate as _e, removeAwarenessStates as _t, applyAwarenessUpdate as Ft } from "y-protocols/awareness";
36
- import { writeUpdate as xt, writeSyncStep1 as Bt, readSyncMessage as Gt } from "y-protocols/sync";
25
+ import * as k from "lib0/encoding";
26
+ import Re from "lodash/debounce";
27
+ import Ce from "lodash/get";
28
+ import De from "lodash/isEmpty";
29
+ import Ne from "lodash/set";
30
+ import kt from "lodash/union";
31
+ import { LRUCache as Je } from "lru-cache";
32
+ import { pipeline as Tt } from "stream/promises";
33
+ import { x as Lt } from "tar";
34
+ import $t from "wait-on";
35
+ import { Awareness as Ut, encodeAwarenessUpdate as Me, removeAwarenessStates as Nt, applyAwarenessUpdate as Mt } from "y-protocols/awareness";
36
+ import { writeUpdate as _t, writeSyncStep1 as Ft, readSyncMessage as xt } from "y-protocols/sync";
37
37
  import * as q from "yaml";
38
- import { m as Fe } from "./html-CNFwwbdj.js";
38
+ import { m as _e } from "./html-CNFwwbdj.js";
39
39
  import "@blocklet/pages-kit/types/state";
40
- const Vt = P.sqlite.DATE.parse;
41
- P.sqlite.DATE.parse = (t, e) => typeof t == "number" ? new Date(t) : Vt(t, e);
42
- const _ = new ht({
40
+ const Bt = P.sqlite.DATE.parse;
41
+ P.sqlite.DATE.parse = (t, e) => typeof t == "number" ? new Date(t) : Bt(t, e);
42
+ const _ = new mt({
43
43
  dialect: "sqlite",
44
- storage: Je,
44
+ storage: ze,
45
45
  benchmark: process.env.ENABLE_SEQUELIZE_BENCHMARK === "true",
46
46
  retry: {
47
47
  match: [/SQLITE_BUSY/],
@@ -62,7 +62,7 @@ process.on("SIGINT", async () => {
62
62
  process.on("SIGTERM", async () => {
63
63
  await _.close(), process.exit(0);
64
64
  });
65
- async function zt(t, e) {
65
+ async function Gt(t, e) {
66
66
  try {
67
67
  if (t.getDialect() !== "sqlite")
68
68
  return;
@@ -80,16 +80,16 @@ let Se = null;
80
80
  Se && clearInterval(Se);
81
81
  Se = setInterval(
82
82
  async () => {
83
- p.info("Start cleanupSqliteMemory"), await zt(_, Je), p.info("End cleanupSqliteMemory");
83
+ p.info("Start cleanupSqliteMemory"), await Gt(_, ze), p.info("End cleanupSqliteMemory");
84
84
  },
85
85
  60 * 1e3 * 10
86
86
  // 10 minutes
87
87
  );
88
- const qt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", xe = "page", we = "trigger-reload-project-resource", Ye = qt, Jt = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM", Ht = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o";
89
- class De extends Ee {
88
+ const Vt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", Fe = "page", we = "trigger-reload-project-resource", Ke = Vt, zt = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM", qt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o";
89
+ class ve extends Ee {
90
90
  // Foreign key to Component
91
91
  }
92
- De.init(
92
+ ve.init(
93
93
  {
94
94
  id: {
95
95
  type: P.UUID,
@@ -108,22 +108,22 @@ De.init(
108
108
  },
109
109
  { sequelize: _, tableName: "ProjectComponents", timestamps: !1 }
110
110
  );
111
- const Wt = "SLUG_INVALID", W = (t) => ({
111
+ const Wt = "SLUG_INVALID", K = (t) => ({
112
112
  error: "slugInvalid",
113
113
  code: Wt,
114
114
  field: "slug",
115
115
  message: t
116
- }), Kt = {
116
+ }), Jt = {
117
117
  error: "slugRequired",
118
118
  code: "SLUG_REQUIRED",
119
119
  field: "slug",
120
120
  message: () => "Project slug is required"
121
- }, Yt = {
121
+ }, Kt = {
122
122
  error: "slugAlreadyExists",
123
123
  code: "SLUG_EXISTS",
124
124
  field: "slug",
125
125
  message: (t) => `Project slug "${t}" already exists`
126
- }, Xt = [
126
+ }, Ht = [
127
127
  /\.\./,
128
128
  // Directory traversal
129
129
  /<[^>]*>/,
@@ -139,12 +139,12 @@ const Wt = "SLUG_INVALID", W = (t) => ({
139
139
  // Control characters
140
140
  /[^a-zA-Z0-9-_@/\\:]/
141
141
  // Only allow specific characters
142
- ], Be = (t) => {
142
+ ], xe = (t) => {
143
143
  if (!t) return "";
144
144
  if (t === "/") return "/";
145
- const e = Oe(t);
146
- return He(e) || "/";
147
- }, Qt = (t) => t.did === Ht;
145
+ const e = je(t);
146
+ return qe(e) || "/";
147
+ }, Yt = (t) => t.did === qt;
148
148
  class U extends Ee {
149
149
  static async getProjectByIdOrSlug(e, s) {
150
150
  return e ? U.findOne({
@@ -161,22 +161,22 @@ class U extends Ee {
161
161
  if (e == null)
162
162
  return null;
163
163
  if (e === "")
164
- return Kt;
165
- const a = e === "/" ? "/" : Oe(He(e)), o = Be(a);
164
+ return Jt;
165
+ const a = e === "/" ? "/" : je(qe(e)), o = xe(a);
166
166
  if (a !== "/" && a.endsWith("/"))
167
- return W((n) => `Project slug "${n}" cannot end with /`);
167
+ return K((n) => `Project slug "${n}" cannot end with /`);
168
168
  if (/\/{2,}/.test(a))
169
- return W((n) => `Project slug "${n}" cannot contain consecutive /`);
169
+ return K((n) => `Project slug "${n}" cannot contain consecutive /`);
170
170
  if (/\s/.test(a))
171
- return W((n) => `Project slug "${n}" cannot contain whitespace`);
172
- if (Xt.some((n) => n.test(a)))
173
- return W((n) => `Project slug "${n}" contains invalid characters`);
174
- if (E.components?.filter((n) => n.mountPoint && !Qt(n)).some((n) => Be(n.mountPoint) === o))
175
- return W((n) => `Project slug "${n}" conflicts with existing blocklet`);
171
+ return K((n) => `Project slug "${n}" cannot contain whitespace`);
172
+ if (Ht.some((n) => n.test(a)))
173
+ return K((n) => `Project slug "${n}" contains invalid characters`);
174
+ if (E.components?.filter((n) => n.mountPoint && !Yt(n)).some((n) => xe(n.mountPoint) === o))
175
+ return K((n) => `Project slug "${n}" conflicts with existing blocklet`);
176
176
  const l = await U.findOne({
177
177
  where: { slug: a }
178
178
  });
179
- return l && l?.id !== s ? Yt : null;
179
+ return l && l?.id !== s ? Kt : null;
180
180
  }
181
181
  }
182
182
  U.init(
@@ -283,7 +283,7 @@ U.init(
283
283
  ]
284
284
  }
285
285
  );
286
- U.hasMany(De, {
286
+ U.hasMany(ve, {
287
287
  foreignKey: "projectId",
288
288
  as: "components"
289
289
  });
@@ -294,22 +294,22 @@ async function G(t) {
294
294
  return !1;
295
295
  }
296
296
  }
297
- function Xe(t, e) {
297
+ function He(t, e) {
298
298
  return new Promise((s, a) => {
299
299
  const o = z.createReadStream(t), r = z.createWriteStream(e);
300
300
  o.on("error", a), r.on("error", a), r.on("finish", s), o.pipe(r);
301
301
  });
302
302
  }
303
- async function Qe(t, e) {
303
+ async function Ye(t, e) {
304
304
  await z.promises.mkdir(e, { recursive: !0 });
305
305
  const s = await z.promises.readdir(t, { withFileTypes: !0 });
306
306
  for (const a of s) {
307
- const o = $e.join(t, a.name), r = $e.join(e, a.name);
308
- a.isDirectory() ? await Qe(o, r) : await Xe(o, r);
307
+ const o = Le.join(t, a.name), r = Le.join(e, a.name);
308
+ a.isDirectory() ? await Ye(o, r) : await He(o, r);
309
309
  }
310
310
  }
311
- async function oa(t, e) {
312
- (await z.promises.stat(t)).isDirectory() ? await Qe(t, e) : await Xe(t, e);
311
+ async function sa(t, e) {
312
+ (await z.promises.stat(t)).isDirectory() ? await Ye(t, e) : await He(t, e);
313
313
  }
314
314
  class ee extends Ee {
315
315
  }
@@ -411,44 +411,44 @@ ee.init(
411
411
  ]
412
412
  }
413
413
  );
414
- function Zt(t) {
415
- const { projectId: e, projectSlug: s, state: a } = t, o = s || e, r = yt(
414
+ function Xt(t) {
415
+ const { projectId: e, projectSlug: s, state: a } = t, o = s || e, r = gt(
416
416
  E.env.languages?.map((c) => c.code) || [],
417
417
  a.supportedLocales?.map((c) => c.locale) || []
418
- ), l = {}, n = (c, f) => {
418
+ ), l = {}, n = (c, h) => {
419
419
  o && (l[x("/", o, c)] = {
420
- ...f,
420
+ ...h,
421
421
  shouldRedirect: !0,
422
422
  mainPage: !0
423
423
  }), l[x("/", e, c)] = {
424
- ...f,
424
+ ...h,
425
425
  shouldRedirect: !0,
426
426
  mainPage: !0
427
427
  };
428
428
  for (const b of r) {
429
- const R = { ...f, locale: b };
430
- l[x("/", b, e, c)] = R, o && (l[x("/", b, o, c)] = R);
429
+ const O = { ...h, locale: b };
430
+ l[x("/", b, e, c)] = O, o && (l[x("/", b, o, c)] = O);
431
431
  }
432
432
  };
433
433
  for (const c of a.pageIds || []) {
434
- const f = a.pages?.[c];
435
- if (!f || !f.isPublic)
434
+ const h = a.pages?.[c];
435
+ if (!h || !h.isPublic)
436
436
  continue;
437
437
  const b = {
438
438
  projectId: e,
439
439
  projectSlug: o,
440
- pageSlug: f.slug,
440
+ pageSlug: h.slug,
441
441
  pageId: c,
442
442
  defaultLocale: r?.[0],
443
443
  locales: r,
444
444
  publishedAt: a.config?.publishedAt,
445
- isPublic: f.isPublic
445
+ isPublic: h.isPublic
446
446
  };
447
- n(f.slug, b);
447
+ n(h.slug, b);
448
448
  }
449
449
  return l;
450
450
  }
451
- async function es(t, e, s) {
451
+ async function Qt(t, e, s) {
452
452
  const a = t.map((r) => r.urlPath), o = await ee.findAll({
453
453
  where: {
454
454
  urlPath: {
@@ -480,14 +480,14 @@ async function es(t, e, s) {
480
480
  );
481
481
  }
482
482
  }
483
- async function ts(t) {
483
+ async function Zt(t) {
484
484
  const { projectId: e, transaction: s } = t;
485
485
  try {
486
486
  await ee.destroy({
487
487
  where: { projectId: e },
488
488
  transaction: s
489
489
  });
490
- const a = Zt(t), o = Object.entries(a).map(([r, l]) => ({
490
+ const a = Xt(t), o = Object.entries(a).map(([r, l]) => ({
491
491
  projectId: e,
492
492
  urlPath: r,
493
493
  projectSlug: l.projectSlug,
@@ -503,7 +503,7 @@ async function ts(t) {
503
503
  locales: l.locales
504
504
  }));
505
505
  if (o.length > 0) {
506
- await es(o, e, s);
506
+ await Qt(o, e, s);
507
507
  const r = 100, l = [];
508
508
  for (let n = 0; n < o.length; n += r) {
509
509
  const c = o.slice(n, n + r);
@@ -527,8 +527,8 @@ function ne(t) {
527
527
  e.some((s) => s.changes.keys.has("updatedAt") || s.changes.keys.has("publishedAt")) || t.set("updatedAt", (/* @__PURE__ */ new Date()).toISOString());
528
528
  });
529
529
  }
530
- function Ze() {
531
- return wt(A(E.env.dataDir, "tmp-"));
530
+ function Xe() {
531
+ return yt(A(E.env.dataDir, "tmp-"));
532
532
  }
533
533
  function ie(t, e, s = []) {
534
534
  return Array.isArray(t) ? t.flatMap((a, o) => ie(a, e, [...s, o])) : typeof t == "object" ? t === null ? [] : Object.entries(t).flatMap(([a, o]) => ie(o, e, [...s, a])) : e(t) ? [s] : [];
@@ -536,11 +536,11 @@ function ie(t, e, s = []) {
536
536
  function L(t) {
537
537
  return t.filter((e) => e != null);
538
538
  }
539
- function ss(t) {
539
+ function es(t) {
540
540
  return new Promise((e, s) => {
541
541
  let a;
542
542
  process.env.NODE_ENV === "development" ? a = A(__dirname, "yaml-worker.js") : a = A(__dirname, "api/dist/utils/yaml-worker.js");
543
- const o = new At(a);
543
+ const o = new Pt(a);
544
544
  o.postMessage({ payload: t }), o.on("message", (r) => {
545
545
  r.status === "success" ? e(r.result) : s(new Error(`YAML stringify failed in worker: ${r.message}`)), o.terminate();
546
546
  }), o.on("error", (r) => {
@@ -550,54 +550,37 @@ function ss(t) {
550
550
  });
551
551
  });
552
552
  }
553
- function Ge(t, e) {
554
- if (t === e) return !0;
555
- if (!t || !e) return t === e;
556
- const s = Object.keys(t), a = Object.keys(e);
557
- if (s.length !== a.length) return !1;
558
- if (s.length < 10) {
559
- for (const l of s) {
560
- if (!(l in e)) return !1;
561
- const n = t[l], c = e[l];
562
- if (n?.blockletId !== c?.blockletId || n?.page?.id !== c?.page?.id || n?.page?.updatedAt !== c?.page?.updatedAt || n?.component?.id !== c?.component?.id || n?.component?.updatedAt !== c?.component?.updatedAt)
563
- return !1;
564
- }
565
- return !0;
566
- }
567
- const o = Le.createHash("md5").update(JSON.stringify(t, Object.keys(t).sort())).digest("hex"), r = Le.createHash("md5").update(JSON.stringify(e, Object.keys(e).sort())).digest("hex");
568
- return o === r;
569
- }
570
- function as(t) {
553
+ function ts(t) {
571
554
  t.pages && Object.keys(t.pages).forEach((s) => {
572
- const a = J(t.pages[s]);
555
+ const a = W(t.pages[s]);
573
556
  a && a instanceof F.Map && ne(a);
574
557
  });
575
- const e = J(t.pages);
558
+ const e = W(t.pages);
576
559
  e && e instanceof F.Map && e.observe((s) => {
577
560
  s.changes.keys.forEach((a, o) => {
578
561
  if (a.action === "add") {
579
- const r = J(t.pages[o]);
562
+ const r = W(t.pages[o]);
580
563
  r && r instanceof F.Map && ne(r);
581
564
  }
582
565
  });
583
566
  });
584
567
  }
585
- function os(t) {
568
+ function ss(t) {
586
569
  t.routes && Object.keys(t.routes).forEach((s) => {
587
- const a = J(t.routes?.[s]);
570
+ const a = W(t.routes?.[s]);
588
571
  a && a instanceof F.Map && ne(a);
589
572
  });
590
- const e = J(t.routes);
573
+ const e = W(t.routes);
591
574
  e && e instanceof F.Map && e.observe((s) => {
592
575
  s.changes.keys.forEach((a, o) => {
593
576
  if (a.action === "add") {
594
- const r = J(t.routes?.[o]);
577
+ const r = W(t.routes?.[o]);
595
578
  r && r instanceof F.Map && ne(r);
596
579
  }
597
580
  });
598
581
  });
599
582
  }
600
- function rs(t, e) {
583
+ function as(t, e) {
601
584
  for (const s of e || Object.keys(t.routes || {})) {
602
585
  let a = s, o = [];
603
586
  if (s.includes("-")) {
@@ -610,7 +593,7 @@ function rs(t, e) {
610
593
  if (!r || !r.params || r.params.length === 0)
611
594
  continue;
612
595
  if (s.includes("-") && o.length > 0) {
613
- const l = gt(o, r);
596
+ const l = ft(o, r);
614
597
  l && (l.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
615
598
  }
616
599
  if (!e) {
@@ -656,48 +639,48 @@ function me({
656
639
  const c = e.dataSource.pathDataMappings?.[n]?.dataCache?.[l.locale] ?? e.dataSource.pathDataMappings?.[n]?.dataCache?.[s.config.defaultLocale || "en"];
657
640
  if (!c)
658
641
  continue;
659
- mt(r, s, l.locale, c);
642
+ dt(r, s, l.locale, c);
660
643
  }
661
644
  o && o.routeMetaData && (o.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
662
645
  }
663
646
  return r;
664
647
  }
665
648
  ["true", "1", "yes", "y"].includes(process.env.USE_FS_CACHE_HTML ?? "");
666
- const ns = 60 * 60 * 1e3, Y = new Ke({
649
+ const os = 60 * 60 * 1e3, Y = new Je({
667
650
  max: 300,
668
- ttl: ns,
651
+ ttl: os,
669
652
  ttlResolution: 10 * 1e3,
670
653
  // 10 seconds
671
654
  allowStale: !0
672
655
  });
673
- function is(t, e = []) {
656
+ function rs(t, e = []) {
674
657
  let s = 0;
675
- const a = Array.from(Y.keys()), o = t.map((r) => Oe(r));
658
+ const a = Array.from(Y.keys()), o = t.map((r) => je(r));
676
659
  for (const r of a)
677
660
  for (const l of o) {
678
- if (Fe(r, { currentPath: l })) {
661
+ if (_e(r, { currentPath: l })) {
679
662
  Y.delete(r), s++, p.info(`[Cache CLEAR] key: ${r}`);
680
663
  break;
681
664
  }
682
665
  for (const n of e)
683
- if (Fe(r, { currentPath: `/${n}${l}` })) {
666
+ if (_e(r, { currentPath: `/${n}${l}` })) {
684
667
  Y.delete(r), s++, p.info(`[Cache CLEAR] key: ${r}`);
685
668
  break;
686
669
  }
687
670
  }
688
671
  return p.info(`[Cache CLEAR] cleared ${s} entries for paths:`, o), s;
689
672
  }
690
- function cs() {
673
+ function ns() {
691
674
  const t = Y.size;
692
675
  return Y.clear(), p.info(`[Cache CLEAR ALL] cleared ${t} entries`), t;
693
676
  }
694
- const ls = St(cs, 300);
695
- E.events.on(E.Events.envUpdate, ls);
696
- const { uploadToMediaKit: ps } = 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, Ve = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, us = 1e4, ds = 3e4, se = 0, ge = 1, fs = 0, ms = 1, Ie = E, K = A(process.env.BLOCKLET_DATA_DIR, "site-state"), ra = ["production", "draft"], na = ["production"];
677
+ const is = ht(ns, 300);
678
+ E.events.on(E.Events.envUpdate, is);
679
+ const { uploadToMediaKit: cs } = require("@blocklet/uploader-server"), ke = /^\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, Be = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, ls = 1e4, ps = 3e4, se = 0, ge = 1, us = 0, ds = 1, Ie = E, H = A(process.env.BLOCKLET_DATA_DIR, "site-state"), aa = ["production", "draft"], oa = ["production"];
697
680
  function ce(t) {
698
681
  return t?.replace(/\//g, "|") || "";
699
682
  }
700
- function gs() {
683
+ function fs() {
701
684
  const t = Ie.env.languages?.map((s) => ({ locale: s.code, name: s.name })) || [], e = t[0]?.locale || "en";
702
685
  return {
703
686
  pageIds: [],
@@ -712,10 +695,10 @@ function gs() {
712
695
  resources: {}
713
696
  };
714
697
  }
715
- class k extends F.Doc {
698
+ class D extends F.Doc {
716
699
  constructor(e) {
717
- super(), this.options = e, It(this.draftYjsFilePath) && F.applyUpdate(this, Pt(this.draftYjsFilePath)), this.syncedStore = kt(
718
- ft(
700
+ super(), this.options = e, St(this.draftYjsFilePath) && F.applyUpdate(this, wt(this.draftYjsFilePath)), this.syncedStore = Rt(
701
+ ut(
719
702
  {
720
703
  pages: {},
721
704
  pageIds: [],
@@ -730,7 +713,7 @@ class k extends F.Doc {
730
713
  },
731
714
  this
732
715
  )
733
- ), this.initObserver(), this.on("update", this.updateHandler), this.awareness = new Mt(this), this.awareness.on("update", this.awarenessChangeHandler), this.ensureDataStructure();
716
+ ), this.initObserver(), this.on("update", this.updateHandler), this.awareness = new Ut(this), this.awareness.on("update", this.awarenessChangeHandler), this.ensureDataStructure();
734
717
  }
735
718
  // 延迟释放时间:5 分钟
736
719
  static RELEASE_DELAY = 5 * 60 * 1e3;
@@ -745,8 +728,8 @@ class k extends F.Doc {
745
728
  if (!e)
746
729
  throw new Error("Should provide project context");
747
730
  try {
748
- const s = A(K, e), a = A(K, `@del-${e}`);
749
- await Ne(s, a);
731
+ const s = A(H, e), a = A(H, `@del-${e}`);
732
+ await Ue(s, a);
750
733
  } catch (s) {
751
734
  p.error("Failed to safe delete project state dir:", s);
752
735
  }
@@ -756,31 +739,31 @@ class k extends F.Doc {
756
739
  }
757
740
  /** @deprecated 不再使用这个 getter 了,仅作为兼容性处理,请使用 getProjectIds 代替 */
758
741
  static get projectIds() {
759
- return Tt("*/", {
760
- cwd: K,
742
+ return vt("*/", {
743
+ cwd: H,
761
744
  ignore: ["@del-*", "@tmp-*", ".*", "staging", "production", "@backup-*", "undefined"]
762
745
  // Ignore temp directories and hidden files
763
746
  });
764
747
  }
765
748
  /** @deprecated 不再使用这个 getter 了,仅作为兼容性处理 */
766
749
  static get allShared() {
767
- return this.projectIds.map((e) => k.shared(e));
750
+ return this.projectIds.map((e) => D.shared(e));
768
751
  }
769
752
  static shared(e) {
770
753
  if (!e)
771
754
  throw new Error("Should provide project context");
772
- let s = k.sharedInstances[e];
773
- return s || (s = new k({
774
- path: A(K, e)
775
- }), k.sharedInstances[e] = s, s);
755
+ let s = D.sharedInstances[e];
756
+ return s || (s = new D({
757
+ path: A(H, e)
758
+ }), D.sharedInstances[e] = s, s);
776
759
  }
777
760
  // 轻量级 production 状态获取,不加载 draft 数据
778
761
  static async getProductionState(e) {
779
762
  const s = await U.findByPk(e, {
780
763
  attributes: ["productionState"]
781
764
  });
782
- if (ke(s?.productionState)) {
783
- const a = A(K, e, "production"), o = await tt(a, { includeResources: !0 }) ?? gs();
765
+ if (De(s?.productionState)) {
766
+ const a = A(H, e, "production"), o = await Ze(a, { includeResources: !0 }) ?? fs();
784
767
  if (!o?.config?.defaultLocale) {
785
768
  o.config ??= {};
786
769
  const r = Ie.env.languages?.map((l) => ({ locale: l.code, name: l.name })) || [];
@@ -793,10 +776,10 @@ class k extends F.Doc {
793
776
  destroy() {
794
777
  this.cancelRelease(), this.save({ flush: !0 }), this.conns.forEach((s, a) => this.closeConn(a)), this.awareness.destroy();
795
778
  const e = $(this.options.path);
796
- delete k.sharedInstances[e], super.destroy();
779
+ delete D.sharedInstances[e], super.destroy();
797
780
  }
798
781
  initObserver() {
799
- as(this.syncedStore), os(this.syncedStore);
782
+ ts(this.syncedStore), ss(this.syncedStore);
800
783
  }
801
784
  get draftYjsFilePath() {
802
785
  return A(this.options.path, "draft.yjs");
@@ -807,16 +790,16 @@ class k extends F.Doc {
807
790
  clone: a = !0
808
791
  }) {
809
792
  if (s === "draft") {
810
- const o = k.shared(e);
793
+ const o = D.shared(e);
811
794
  return a ? JSON.parse(JSON.stringify(o.syncedStore)) : o.syncedStore;
812
795
  }
813
- return k.getProductionState(e);
796
+ return D.getProductionState(e);
814
797
  }
815
798
  async getState(e) {
816
799
  if (e === "draft")
817
800
  return JSON.parse(JSON.stringify(this.syncedStore));
818
801
  const s = $(this.options.path);
819
- return k.getProductionState(s);
802
+ return D.getProductionState(s);
820
803
  }
821
804
  async setState(e, s) {
822
805
  if (e === "production") {
@@ -826,17 +809,17 @@ class k extends F.Doc {
826
809
  const c = await U.findByPk(r, {
827
810
  attributes: ["slug"],
828
811
  transaction: n
829
- }), f = await ts({
812
+ }), h = await Zt({
830
813
  projectId: r,
831
814
  projectSlug: c?.slug,
832
815
  state: s,
833
816
  transaction: n
834
817
  });
835
- p.info(`[SiteState] saved ${f} URL mappings for project ${r}`);
818
+ p.info(`[SiteState] saved ${h} URL mappings for project ${r}`);
836
819
  }), await this.clearPageCacheForRoutes(void 0, s);
837
820
  }
838
- const a = await ws(s, { exportAssets: !1, includeResources: !0 }), o = this.getPublishDir(e);
839
- await B(M(o), { recursive: !0 }), await We(o, { force: !0, recursive: !0 }), await Ne(a, o);
821
+ const a = await ys(s, { exportAssets: !1, includeResources: !0 }), o = this.getPublishDir(e);
822
+ await B(M(o), { recursive: !0 }), await We(o, { force: !0, recursive: !0 }), await Ue(a, o);
840
823
  }
841
824
  getPublishDir(e) {
842
825
  return A(this.options.path, e);
@@ -850,21 +833,21 @@ class k extends F.Doc {
850
833
  const r = e.concat(s, a);
851
834
  if (o !== null) {
852
835
  const c = this.conns.get(o);
853
- c && (e.forEach((f) => {
854
- c.add(f);
855
- }), a.forEach((f) => {
856
- c.delete(f);
836
+ c && (e.forEach((h) => {
837
+ c.add(h);
838
+ }), a.forEach((h) => {
839
+ c.delete(h);
857
840
  }));
858
841
  }
859
- const l = v.createEncoder();
860
- v.writeVarUint(l, ge), v.writeVarUint8Array(l, _e(this.awareness, r));
861
- const n = v.toUint8Array(l);
862
- this.conns.forEach((c, f) => this.send(f, n));
842
+ const l = k.createEncoder();
843
+ k.writeVarUint(l, ge), k.writeVarUint8Array(l, Me(this.awareness, r));
844
+ const n = k.toUint8Array(l);
845
+ this.conns.forEach((c, h) => this.send(h, n));
863
846
  };
864
847
  updateHandler = (e) => {
865
- const s = v.createEncoder();
866
- v.writeVarUint(s, se), xt(s, e);
867
- const a = v.toUint8Array(s);
848
+ const s = k.createEncoder();
849
+ k.writeVarUint(s, se), _t(s, e);
850
+ const a = k.toUint8Array(s);
868
851
  this.conns.forEach((o, r) => this.send(r, a));
869
852
  };
870
853
  ensureDataStructure = () => {
@@ -874,16 +857,16 @@ class k extends F.Doc {
874
857
  const n = new Set(Object.keys(s));
875
858
  let c = 0;
876
859
  for (; c < a.length; ) {
877
- const f = a[c];
878
- n.has(f) ? (n.delete(f), c++) : a.splice(c, 1);
860
+ const h = a[c];
861
+ n.has(h) ? (n.delete(h), c++) : a.splice(c, 1);
879
862
  }
880
863
  }
881
864
  {
882
865
  const n = new Set(Object.keys(r));
883
866
  let c = 0;
884
867
  for (; c < l.length; ) {
885
- const f = l[c];
886
- n.has(f) ? (n.delete(f), c++) : l.splice(c, 1);
868
+ const h = l[c];
869
+ n.has(h) ? (n.delete(h), c++) : l.splice(c, 1);
887
870
  }
888
871
  }
889
872
  e.splice(0, e.length), e.push(...Ie.env.languages.map((n) => ({ locale: n.code, name: n.name }))), o.defaultLocale = e[0]?.locale;
@@ -891,14 +874,14 @@ class k extends F.Doc {
891
874
  let n = 0;
892
875
  const c = /* @__PURE__ */ new Set();
893
876
  for (; n < e.length; ) {
894
- const { locale: f } = e[n];
895
- c.has(f) ? e.splice(n, 1) : (n++, c.add(f));
877
+ const { locale: h } = e[n];
878
+ c.has(h) ? e.splice(n, 1) : (n++, c.add(h));
896
879
  }
897
880
  }
898
881
  });
899
882
  };
900
883
  send = (e, s) => {
901
- e.readyState !== fs && e.readyState !== ms && this.closeConn(e);
884
+ e.readyState !== us && e.readyState !== ds && this.closeConn(e);
902
885
  try {
903
886
  e.send(s, (a) => {
904
887
  a && this.closeConn(e);
@@ -910,7 +893,7 @@ class k extends F.Doc {
910
893
  closeConn = (e) => {
911
894
  if (e.removeAllListeners(), this.conns.has(e)) {
912
895
  const s = this.conns.get(e);
913
- this.conns.delete(e), s && _t(this.awareness, Array.from(s), null);
896
+ this.conns.delete(e), s && Nt(this.awareness, Array.from(s), null);
914
897
  }
915
898
  e.close(), this.checkAndScheduleRelease();
916
899
  };
@@ -924,7 +907,7 @@ class k extends F.Doc {
924
907
  const e = $(this.options.path);
925
908
  this.releaseTimer = setTimeout(() => {
926
909
  p.info(`[SiteState] releasing instance due to no active connections: ${e}`), this.conns.size === 0 && (this.releaseTimer = void 0, this.destroy());
927
- }, k.RELEASE_DELAY), p.info(`[SiteState] scheduled release for project ${e} in ${k.RELEASE_DELAY / 1e3}s`);
910
+ }, D.RELEASE_DELAY), p.info(`[SiteState] scheduled release for project ${e} in ${D.RELEASE_DELAY / 1e3}s`);
928
911
  }
929
912
  // 取消延迟释放
930
913
  cancelRelease() {
@@ -934,19 +917,19 @@ class k extends F.Doc {
934
917
  p.info(`[SiteState] cancelled scheduled release for project ${e}`);
935
918
  }
936
919
  }
937
- autoSave = Ce(async () => {
920
+ autoSave = Re(async () => {
938
921
  await B(M(this.draftYjsFilePath), { recursive: !0 }), await re(this.draftYjsFilePath, F.encodeStateAsUpdate(this));
939
- }, us);
922
+ }, ls);
940
923
  save = ({ flush: e = !1 } = {}) => {
941
924
  this.autoSave(), e && this.autoSave.flush();
942
925
  };
943
926
  publish = async ({ mode: e, routes: s }) => {
944
927
  const a = $(this.options.path);
945
- await bs(a);
928
+ await Is(a);
946
929
  const o = await this.getState("draft"), r = await this.getState("production");
947
- await qe(o, r, { routes: s, mergeMode: "replace", deleteRoutes: !0, publishMode: e }), r.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(), setImmediate(() => {
930
+ await Ve(o, r, { routes: s, mergeMode: "replace", deleteRoutes: !0, publishMode: e }), r.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(), setImmediate(() => {
948
931
  this.transact(() => {
949
- rs(this.syncedStore, s);
932
+ as(this.syncedStore, s);
950
933
  });
951
934
  }), await this.setState(e, r);
952
935
  };
@@ -957,7 +940,7 @@ class k extends F.Doc {
957
940
  e.config.fontFamily.title = o?.title || r?.title, e.config.fontFamily.description = o?.description || r?.description, await new Promise((l, n) => {
958
941
  this.transact(async () => {
959
942
  try {
960
- const c = await qe(e, s);
943
+ const c = await Ve(e, s);
961
944
  l(c);
962
945
  } catch (c) {
963
946
  n(c);
@@ -969,14 +952,14 @@ class k extends F.Doc {
969
952
  const a = $(this.options.path), r = (await U.findByPk(a))?.slug || a;
970
953
  let l = e;
971
954
  (!l || l.length === 0) && (l = s.pageIds ?? []), p.info(`[SiteState] clearing page cache for project ${a}, routes:`, l || []);
972
- const n = s.supportedLocales.map((b) => b.locale), c = [], f = l.filter((b) => s.pageIds?.includes(b));
973
- for (const b of f) {
974
- const y = s.pages[b].slug;
975
- r && r !== a && (r === "/" ? c.push(y) : c.push(`${r.startsWith("/") ? "" : "/"}${r}${y}`)), c.push(`/${a}${y}`);
955
+ const n = s.supportedLocales.map((b) => b.locale), c = [], h = l.filter((b) => s.pageIds?.includes(b));
956
+ for (const b of h) {
957
+ const w = s.pages[b].slug;
958
+ r && r !== a && (r === "/" ? c.push(w) : c.push(`${r.startsWith("/") ? "" : "/"}${r}${w}`)), c.push(`/${a}${w}`);
976
959
  }
977
960
  if (c.length > 0)
978
961
  try {
979
- const b = is(c, n);
962
+ const b = rs(c, n);
980
963
  p.info(`[SiteState] cleared ${b} page cache entries for project ${a}, routes:`, l);
981
964
  } catch {
982
965
  }
@@ -997,31 +980,31 @@ class k extends F.Doc {
997
980
  this.closeConn(e), clearInterval(a);
998
981
  }
999
982
  }
1000
- }, ds);
983
+ }, ps);
1001
984
  e.on("close", () => {
1002
985
  this.closeConn(e), clearInterval(a);
1003
986
  }), e.on("pong", () => {
1004
987
  s = !0;
1005
988
  });
1006
989
  {
1007
- const o = v.createEncoder();
1008
- v.writeVarUint(o, se), Bt(o, this), this.send(e, v.toUint8Array(o));
990
+ const o = k.createEncoder();
991
+ k.writeVarUint(o, se), Ft(o, this), this.send(e, k.toUint8Array(o));
1009
992
  const r = this.awareness.getStates();
1010
993
  if (r.size > 0) {
1011
- const l = v.createEncoder();
1012
- v.writeVarUint(l, ge), v.writeVarUint8Array(l, _e(this.awareness, Array.from(r.keys()))), this.send(e, v.toUint8Array(l));
994
+ const l = k.createEncoder();
995
+ k.writeVarUint(l, ge), k.writeVarUint8Array(l, Me(this.awareness, Array.from(r.keys()))), this.send(e, k.toUint8Array(l));
1013
996
  }
1014
997
  }
1015
998
  };
1016
999
  messageListener = (e, s) => {
1017
1000
  try {
1018
- const a = v.createEncoder(), o = fe.createDecoder(s), r = fe.readVarUint(o);
1001
+ const a = k.createEncoder(), o = fe.createDecoder(s), r = fe.readVarUint(o);
1019
1002
  switch (p.info(`[SiteState] messageListener, messageType: ${r}`), r) {
1020
1003
  case se:
1021
- v.writeVarUint(a, se), Gt(o, a, this, null), p.info(`[SiteState] messageListener, encoder length: ${v.length(a)}`), v.length(a) > 1 && (this.ensureDataStructure(), this.send(e, v.toUint8Array(a)));
1004
+ k.writeVarUint(a, se), xt(o, a, this, null), p.info(`[SiteState] messageListener, encoder length: ${k.length(a)}`), k.length(a) > 1 && (this.ensureDataStructure(), this.send(e, k.toUint8Array(a)));
1022
1005
  break;
1023
1006
  case ge: {
1024
- Ft(this.awareness, fe.readVarUint8Array(o), e);
1007
+ Mt(this.awareness, fe.readVarUint8Array(o), e);
1025
1008
  break;
1026
1009
  }
1027
1010
  default:
@@ -1061,11 +1044,11 @@ class k extends F.Doc {
1061
1044
  let o = {};
1062
1045
  if (a?.length) {
1063
1046
  p.info("[SiteState] find project infos from database, projectIds: ", a);
1064
- const r = 30, l = Re(5);
1047
+ const r = 30, l = Oe(5);
1065
1048
  for (let n = 0; n < a.length; n += r) {
1066
1049
  const c = a.slice(n, n + r);
1067
1050
  p.info(`[SiteState] processing project batch ${n / r + 1}, ids: `, c);
1068
- const f = await U.findAll({
1051
+ const h = await U.findAll({
1069
1052
  where: {
1070
1053
  id: {
1071
1054
  [Z.in]: c
@@ -1076,89 +1059,89 @@ class k extends F.Doc {
1076
1059
  }
1077
1060
  });
1078
1061
  await Promise.all(
1079
- f?.map(
1062
+ h?.map(
1080
1063
  (b) => l(async () => {
1081
- const R = b.id, y = b.slug || R, g = {}, u = await k.getStateByProjectId({ projectId: b.id, mode: e, clone: !1 }), I = Lt(
1082
- E.env.languages?.map((O) => O.code) || [],
1083
- u.supportedLocales?.map((O) => O.locale) || []
1084
- ), C = (O, w) => {
1085
- y && (g[x("/", y, O)] = {
1086
- ...w,
1064
+ const O = b.id, w = b.slug || O, m = {}, u = await D.getStateByProjectId({ projectId: b.id, mode: e, clone: !1 }), I = kt(
1065
+ E.env.languages?.map((j) => j.code) || [],
1066
+ u.supportedLocales?.map((j) => j.locale) || []
1067
+ ), R = (j, S) => {
1068
+ w && (m[x("/", w, j)] = {
1069
+ ...S,
1087
1070
  shouldRedirect: !0,
1088
1071
  mainPage: !0
1089
- }), g[x("/", R, O)] = {
1090
- ...w,
1072
+ }), m[x("/", O, j)] = {
1073
+ ...S,
1091
1074
  shouldRedirect: !0,
1092
1075
  mainPage: !0
1093
1076
  };
1094
- for (const D of I) {
1095
- const h = { ...w, locale: D };
1096
- g[x("/", D, R, O)] = h, y && (g[x("/", D, y, O)] = h);
1077
+ for (const v of I) {
1078
+ const g = { ...S, locale: v };
1079
+ m[x("/", v, O, j)] = g, w && (m[x("/", v, w, j)] = g);
1097
1080
  }
1098
1081
  };
1099
1082
  if (e === "draft")
1100
- for (const O of u.routeIds || []) {
1101
- const w = u?.routes?.[O];
1102
- if (!w) continue;
1103
- if (w.params && w.params.length > 0) {
1104
- const S = be({
1105
- basePath: w.path,
1106
- params: w.params,
1107
- routeId: w.id,
1108
- paramsOptions: w.paramsOptions,
1083
+ for (const j of u.routeIds || []) {
1084
+ const S = u?.routes?.[j];
1085
+ if (!S) continue;
1086
+ if (S.params && S.params.length > 0) {
1087
+ const y = be({
1088
+ basePath: S.path,
1089
+ params: S.params,
1090
+ routeId: S.id,
1091
+ paramsOptions: S.paramsOptions,
1109
1092
  currentIndex: 0,
1110
1093
  currentParams: [],
1111
1094
  currentOptionIds: [],
1112
1095
  result: []
1113
1096
  });
1114
- for (const i of S) {
1115
- const d = i.path, m = {
1116
- projectId: R,
1117
- projectSlug: y,
1097
+ for (const i of y) {
1098
+ const d = i.path, f = {
1099
+ projectId: O,
1100
+ projectSlug: w,
1118
1101
  pageSlug: d,
1119
- pageId: w.displayTemplateId || "",
1120
- routeId: O,
1102
+ pageId: S.displayTemplateId || "",
1103
+ routeId: j,
1121
1104
  // default locale
1122
1105
  defaultLocale: I?.[0],
1123
1106
  locales: I,
1124
1107
  publishedAt: u.config.publishedAt,
1125
- isPublic: w.isPublic && i?.routeMetaData?.isPublic
1108
+ isPublic: S.isPublic && i?.routeMetaData?.isPublic
1126
1109
  };
1127
- C(d, m);
1110
+ R(d, f);
1128
1111
  }
1129
1112
  }
1130
- const D = w.path, h = {
1131
- projectId: R,
1132
- projectSlug: y,
1133
- pageSlug: D,
1134
- pageId: w.displayTemplateId || "",
1135
- routeId: O,
1113
+ const v = S.path, g = {
1114
+ projectId: O,
1115
+ projectSlug: w,
1116
+ pageSlug: v,
1117
+ pageId: S.displayTemplateId || "",
1118
+ routeId: j,
1136
1119
  // default locale
1137
1120
  defaultLocale: I?.[0],
1138
1121
  locales: I,
1139
1122
  publishedAt: u.config.publishedAt,
1140
- isPublic: w.isPublic
1123
+ isPublic: S.isPublic
1141
1124
  };
1142
- C(D, h);
1125
+ R(v, g);
1143
1126
  }
1144
- for (const O of u.pageIds || []) {
1145
- const w = u.pages[O];
1146
- if (!w) continue;
1147
- const D = w.slug, h = b.slug || R, S = {
1148
- projectId: R,
1149
- projectSlug: h,
1150
- pageSlug: D,
1151
- pageId: O,
1127
+ for (const j of u.pageIds || []) {
1128
+ const S = u.pages[j];
1129
+ if (!S) continue;
1130
+ const v = S.slug, g = b.slug || O, y = {
1131
+ projectId: O,
1132
+ projectSlug: g,
1133
+ pageSlug: v,
1134
+ pageId: j,
1152
1135
  // default locale
1153
1136
  defaultLocale: I?.[0],
1154
1137
  locales: I,
1155
1138
  publishedAt: u.config.publishedAt,
1156
- isPublic: w.isPublic,
1157
- templateConfig: w.templateConfig
1139
+ isPublic: S.isPublic,
1140
+ templateConfig: S.templateConfig
1158
1141
  };
1159
- C(D, S);
1142
+ R(v, y);
1160
1143
  }
1161
- o = { ...o, ...g };
1144
+ o = { ...o, ...m };
1162
1145
  })
1163
1146
  )
1164
1147
  );
@@ -1171,7 +1154,7 @@ class k extends F.Doc {
1171
1154
  }
1172
1155
  static getInstancesSizeInfo() {
1173
1156
  const e = [];
1174
- for (const [s, a] of Object.entries(k.sharedInstances)) {
1157
+ for (const [s, a] of Object.entries(D.sharedInstances)) {
1175
1158
  const o = a.getDocumentSize();
1176
1159
  e.push({
1177
1160
  projectId: s,
@@ -1196,8 +1179,8 @@ class k extends F.Doc {
1196
1179
  }
1197
1180
  // 执行定期检查
1198
1181
  static performPeriodicCheck() {
1199
- const e = Object.keys(k.sharedInstances).length, s = [], a = [];
1200
- for (const [o, r] of Object.entries(k.sharedInstances))
1182
+ const e = Object.keys(D.sharedInstances).length, s = [], a = [];
1183
+ for (const [o, r] of Object.entries(D.sharedInstances))
1201
1184
  r.conns.size === 0 ? s.push({ projectId: o, instance: r }) : a.push({ projectId: o, connections: r.conns.size });
1202
1185
  if (p.info(
1203
1186
  `[SiteState] periodic check summary: total instances: ${e}, with connections: ${a.length}, without connections: ${s.length}`
@@ -1219,13 +1202,13 @@ class k extends F.Doc {
1219
1202
  } else e > 0 ? p.debug("[SiteState] periodic check: all instances have active connections") : p.debug("[SiteState] periodic check: no instances exist");
1220
1203
  }
1221
1204
  }
1222
- async function hs(t, e, s) {
1205
+ async function ms(t, e, s) {
1223
1206
  if (!t || !await G(t) || !(await oe(t)).isFile())
1224
1207
  return null;
1225
1208
  let o = s[t];
1226
1209
  return o || (o = (async () => {
1227
1210
  try {
1228
- return (await ps({
1211
+ return (await cs({
1229
1212
  filePath: t,
1230
1213
  fileName: e
1231
1214
  }))?.data?.filename;
@@ -1234,68 +1217,68 @@ async function hs(t, e, s) {
1234
1217
  }
1235
1218
  })(), s[t] = o), o;
1236
1219
  }
1237
- const ys = async (t, e) => {
1238
- const s = $(t), a = await jt({
1239
- name: Ye,
1220
+ const gs = async (t, e) => {
1221
+ const s = $(t), a = await Ot({
1222
+ name: Ke,
1240
1223
  path: x("/uploads", s),
1241
1224
  responseType: "stream",
1242
1225
  method: "GET"
1243
1226
  });
1244
1227
  if (a.status >= 200 && a.status < 400) {
1245
- const o = bt(e);
1246
- await $t(a.data, o);
1228
+ const o = It(e);
1229
+ await Tt(a.data, o);
1247
1230
  } else
1248
1231
  throw new Error(`download asset failed ${a.status}`);
1249
- }, Ss = async (t, e) => {
1232
+ }, hs = async (t, e) => {
1250
1233
  await Promise.all(
1251
1234
  t.map(async (s) => {
1252
1235
  try {
1253
- await ys(s, A(e, $(s)));
1236
+ await gs(s, A(e, $(s)));
1254
1237
  } catch (a) {
1255
1238
  p.error(`Failed to export assets: ${s}, ${a}`);
1256
1239
  }
1257
1240
  })
1258
1241
  );
1259
1242
  };
1260
- function et(t) {
1261
- return ve.test(t) ? [t] : X.test(t) ? (Ve.lastIndex = 0, Array.from(t.matchAll(Ve)).map((s) => s[1]).filter((s) => !!s)) : [];
1243
+ function Qe(t) {
1244
+ return ke.test(t) ? [t] : X.test(t) ? (Be.lastIndex = 0, Array.from(t.matchAll(Be)).map((s) => s[1]).filter((s) => !!s)) : [];
1262
1245
  }
1263
1246
  async function ae(t, e, s) {
1264
1247
  const { getFilename: a, exportAssets: o, useWorker: r } = s, l = A(e, a(t));
1265
1248
  await B(M(l), { recursive: !0 });
1266
- const n = r ? await ss(t) : q.stringify(t);
1249
+ const n = r ? await es(t) : q.stringify(t);
1267
1250
  if (await re(l, n), o) {
1268
- const f = ie(
1251
+ const h = ie(
1269
1252
  t,
1270
- (b) => typeof b == "string" && (ve.test(b) || X.test(b))
1253
+ (b) => typeof b == "string" && (ke.test(b) || X.test(b))
1271
1254
  ).map((b) => {
1272
- const R = je(t, b);
1273
- return et(R);
1255
+ const O = Ce(t, b);
1256
+ return Qe(O);
1274
1257
  }).flat().filter(Boolean);
1275
- await Ss(f, M(l));
1258
+ await hs(h, M(l));
1276
1259
  }
1277
1260
  }
1278
- const Pe = new Ke({
1261
+ const Pe = new Je({
1279
1262
  max: 100,
1280
1263
  ttl: 1 * 60 * 1e3
1281
1264
  // 1 minute
1282
1265
  });
1283
- async function ze(t, e, s) {
1266
+ async function Ge(t, e, s) {
1284
1267
  const a = ie(
1285
1268
  t,
1286
- (n) => typeof n == "string" && (ve.test(n) || X.test(n))
1287
- ), o = Re(2), r = a.map(
1269
+ (n) => typeof n == "string" && (ke.test(n) || X.test(n))
1270
+ ), o = Oe(2), r = a.map(
1288
1271
  (n) => o(async () => {
1289
1272
  try {
1290
- const c = je(t, n), f = et(c);
1291
- for (const b of f) {
1292
- const R = $(b), y = s.getFilePath(b, n), g = y ? `${y}:${R}` : R, u = Pe.get(g);
1273
+ const c = Ce(t, n), h = Qe(c);
1274
+ for (const b of h) {
1275
+ const O = $(b), w = s.getFilePath(b, n), m = w ? `${w}:${O}` : O, u = Pe.get(m);
1293
1276
  if (u) {
1294
- X.test(c) || Me(t, n, u);
1277
+ X.test(c) || Ne(t, n, u);
1295
1278
  return;
1296
1279
  }
1297
- const I = await hs(y, R, e);
1298
- I && (X.test(c) || Me(t, n, I), Pe.set(g, I));
1280
+ const I = await ms(w, O, e);
1281
+ I && (X.test(c) || Ne(t, n, I), Pe.set(m, I));
1299
1282
  }
1300
1283
  } catch (c) {
1301
1284
  p.error(`Failed to process upload for path ${n.join(".")}:`, c.message || c.reason);
@@ -1304,7 +1287,7 @@ async function ze(t, e, s) {
1304
1287
  ), l = await Promise.allSettled(r);
1305
1288
  s.onFinish?.(l);
1306
1289
  }
1307
- async function ws(t, {
1290
+ async function ys(t, {
1308
1291
  exportAssets: e,
1309
1292
  pageIds: s = "all",
1310
1293
  componentIds: a = "all",
@@ -1312,7 +1295,7 @@ async function ws(t, {
1312
1295
  includeResources: r = !1,
1313
1296
  routeIds: l = "all"
1314
1297
  } = {}) {
1315
- const n = s === "all" ? t.pageIds : s, c = Ot({
1298
+ const n = s === "all" ? t.pageIds : s, c = At({
1316
1299
  state: t,
1317
1300
  pageIds: n,
1318
1301
  componentIds: a === "all" ? Object.keys(t.components) : a
@@ -1320,7 +1303,7 @@ async function ws(t, {
1320
1303
  Object.entries(t.components).forEach(([i, d]) => {
1321
1304
  d.data?.renderer?.type === "component-template" && c.push(i);
1322
1305
  });
1323
- const f = l === "all" ? t.routeIds : l, b = (i) => ({
1306
+ const h = l === "all" ? t.routeIds : l, b = (i) => ({
1324
1307
  id: i.id,
1325
1308
  name: i.name,
1326
1309
  isTemplateSection: i.isTemplateSection ?? !1,
@@ -1332,13 +1315,13 @@ async function ws(t, {
1332
1315
  visibility: i.visibility,
1333
1316
  sections: i?.sectionIds ? L(
1334
1317
  i?.sectionIds?.map((d) => {
1335
- const m = i.sections?.[d];
1336
- return m && b(m);
1318
+ const f = i.sections?.[d];
1319
+ return f && b(f);
1337
1320
  })
1338
1321
  ) : void 0
1339
1322
  /** @deprecated 已经废弃,数据在 page.dataSource 中管理 */
1340
1323
  // properties: section.locales?.[locale] ?? {},
1341
- }), R = (i, d) => ({
1324
+ }), O = (i, d) => ({
1342
1325
  id: i.id,
1343
1326
  createdAt: i.createdAt,
1344
1327
  updatedAt: i.updatedAt,
@@ -1347,16 +1330,16 @@ async function ws(t, {
1347
1330
  templateConfig: i.templateConfig,
1348
1331
  meta: i.locales?.[d] ?? {},
1349
1332
  sections: L(
1350
- i.sectionIds.map((m) => {
1351
- const j = i.sections[m];
1352
- return j && b(j);
1333
+ i.sectionIds.map((f) => {
1334
+ const C = i.sections[f];
1335
+ return C && b(C);
1353
1336
  })
1354
1337
  ),
1355
1338
  // 将 dataSource.sectionId.locale 转换为 dataSource.sectionId
1356
1339
  dataSource: Object.fromEntries(
1357
- Object.entries(i.dataSource || {}).map(([m, j]) => [m, j?.[d] ?? {}])
1340
+ Object.entries(i.dataSource || {}).map(([f, C]) => [f, C?.[d] ?? {}])
1358
1341
  )
1359
- }), y = (i) => ({
1342
+ }), w = (i) => ({
1360
1343
  id: i.id,
1361
1344
  createdAt: i.createdAt,
1362
1345
  updatedAt: i.updatedAt,
@@ -1368,50 +1351,50 @@ async function ws(t, {
1368
1351
  enabledGenerate: i.enabledGenerate ?? !1,
1369
1352
  displayTemplateId: i.displayTemplateId,
1370
1353
  dataSource: i.dataSource
1371
- }), g = L(
1372
- f.map((i) => {
1354
+ }), m = L(
1355
+ h.map((i) => {
1373
1356
  const d = t.routes[i];
1374
- return d && y(d);
1357
+ return d && w(d);
1375
1358
  })
1376
1359
  ), u = L(
1377
1360
  t.supportedLocales.map((i) => i.locale).flatMap(
1378
1361
  (i) => n.map((d) => {
1379
- const m = t.pages[d];
1380
- return m && {
1362
+ const f = t.pages[d];
1363
+ return f && {
1381
1364
  locale: i,
1382
- slug: m.slug,
1383
- page: R(m, i)
1365
+ slug: f.slug,
1366
+ page: O(f, i)
1384
1367
  };
1385
1368
  })
1386
1369
  )
1387
- ), I = Ze(), C = A(I, "pages");
1388
- await B(C, { recursive: !0 });
1389
- const O = A(I, "components");
1390
- await B(O, { recursive: !0 });
1391
- const w = A(I, "routes");
1392
- await B(w, { recursive: !0 });
1393
- for (const { locale: i, slug: d, page: m } of u)
1394
- await ae(m, C, {
1370
+ ), I = Xe(), R = A(I, "pages");
1371
+ await B(R, { recursive: !0 });
1372
+ const j = A(I, "components");
1373
+ await B(j, { recursive: !0 });
1374
+ const S = A(I, "routes");
1375
+ await B(S, { recursive: !0 });
1376
+ for (const { locale: i, slug: d, page: f } of u)
1377
+ await ae(f, R, {
1395
1378
  getFilename: () => `${ce(d) || "index"}.${i}.yml`,
1396
1379
  exportAssets: e,
1397
1380
  useWorker: !0
1398
1381
  });
1399
- for (const i of g)
1400
- await ae(i, w, {
1382
+ for (const i of m)
1383
+ await ae(i, S, {
1401
1384
  // getFilename: () => `${sanitizeSlug(route.path)}.yml`,
1402
1385
  getFilename: () => `${ce(i.path) || "index"}.yml`,
1403
1386
  exportAssets: e
1404
1387
  });
1405
1388
  for (const i of c) {
1406
1389
  const d = t.components[i]?.data;
1407
- d && await ae(d, O, {
1408
- getFilename: (m) => `${m.name || "unnamed"}.${m.id}.yml`,
1390
+ d && await ae(d, j, {
1391
+ getFilename: (f) => `${f.name || "unnamed"}.${f.id}.yml`,
1409
1392
  exportAssets: e
1410
1393
  });
1411
1394
  }
1412
- const D = A(I, ".blocklet/pages/pages.config.yml");
1413
- await B(M(D), { recursive: !0 });
1414
- const h = {
1395
+ const v = A(I, ".blocklet/pages/pages.config.yml");
1396
+ await B(M(v), { recursive: !0 });
1397
+ const g = {
1415
1398
  pages: L(
1416
1399
  n.map((i) => {
1417
1400
  const d = t.pages[i];
@@ -1419,7 +1402,7 @@ async function ws(t, {
1419
1402
  })
1420
1403
  ),
1421
1404
  routes: L(
1422
- f.map((i) => {
1405
+ h.map((i) => {
1423
1406
  const d = t.routes[i];
1424
1407
  return d && { id: i, path: d.path };
1425
1408
  })
@@ -1446,9 +1429,9 @@ async function ws(t, {
1446
1429
  supportedLocales: t.supportedLocales,
1447
1430
  config: t.config
1448
1431
  };
1449
- await re(D, q.stringify(h));
1450
- const S = A(I, "config.source.json");
1451
- if (o && await re(S, JSON.stringify(o)), r) {
1432
+ await re(v, q.stringify(g));
1433
+ const y = A(I, "config.source.json");
1434
+ if (o && await re(y, JSON.stringify(o)), r) {
1452
1435
  const i = A(I, "resources"), d = A(i, "components");
1453
1436
  await B(d, { recursive: !0 });
1454
1437
  for (const N of Object.keys(t?.resources?.components ?? {}).filter(
@@ -1460,9 +1443,9 @@ async function ws(t, {
1460
1443
  exportAssets: e
1461
1444
  });
1462
1445
  }
1463
- const m = A(I, "chunks");
1464
- await B(m, { recursive: !0 });
1465
- const j = await Is();
1446
+ const f = A(I, "chunks");
1447
+ await B(f, { recursive: !0 });
1448
+ const C = await Ss();
1466
1449
  for (const N of Object.keys(t?.resources?.components ?? {}).filter(
1467
1450
  (T) => c.includes(T)
1468
1451
  )) {
@@ -1470,12 +1453,12 @@ async function ws(t, {
1470
1453
  if (T && T.renderer?.type === "react-component") {
1471
1454
  const V = T.renderer?.chunks ?? [];
1472
1455
  if (V?.length > 0)
1473
- for (const H of V) {
1474
- const Te = A(m, H), de = j?.[H];
1456
+ for (const J of V) {
1457
+ const Te = A(f, J), de = C?.[J];
1475
1458
  try {
1476
- de && await G(de) && !await G(Te) && await Dt(de, Te);
1477
- } catch (ct) {
1478
- p.error(`copy chunk ${H} error`, ct.message);
1459
+ de && await G(de) && !await G(Te) && await Ct(de, Te);
1460
+ } catch (nt) {
1461
+ p.error(`copy chunk ${J} error`, nt.message);
1479
1462
  }
1480
1463
  }
1481
1464
  }
@@ -1483,87 +1466,87 @@ async function ws(t, {
1483
1466
  }
1484
1467
  return I;
1485
1468
  }
1486
- async function tt(t, { importAssets: e, includeResources: s } = {}) {
1469
+ async function Ze(t, { importAssets: e, includeResources: s } = {}) {
1487
1470
  if (!await G(t))
1488
1471
  return null;
1489
1472
  let a, o = !1;
1490
1473
  try {
1491
- (await oe(t)).isDirectory() ? a = t : /\.(tgz|gz|tar)$/.test(t) && (o = !0, a = Ze(), await Ut({ file: t, C: a }));
1492
- const n = (await ye("**/.blocklet/pages/pages.config.yml", { cwd: a, absolute: !0 }))[0], c = n && A(M(n), "../../pages"), f = n && A(M(n), "../../components"), b = n && A(M(n), "../../routes");
1474
+ (await oe(t)).isDirectory() ? a = t : /\.(tgz|gz|tar)$/.test(t) && (o = !0, a = Xe(), await Lt({ file: t, C: a }));
1475
+ const n = (await ye("**/.blocklet/pages/pages.config.yml", { cwd: a, absolute: !0 }))[0], c = n && A(M(n), "../../pages"), h = n && A(M(n), "../../components"), b = n && A(M(n), "../../routes");
1493
1476
  if (!n)
1494
1477
  return null;
1495
- const R = await te(n, "utf-8"), y = q.parse(R), g = async (h, S, i) => {
1496
- let d = A(h, `${S}${i ? `.${i}` : ""}.yml`);
1497
- if (!await G(d) && (d = A(h, S, `index${i ? `.${i}` : ""}.yml`), !await G(d)) || !(await oe(d)).isFile())
1478
+ const O = await te(n, "utf-8"), w = q.parse(O), m = async (g, y, i) => {
1479
+ let d = A(g, `${y}${i ? `.${i}` : ""}.yml`);
1480
+ if (!await G(d) && (d = A(g, y, `index${i ? `.${i}` : ""}.yml`), !await G(d)) || !(await oe(d)).isFile())
1498
1481
  return null;
1499
- const j = await te(d, "utf-8");
1500
- return q.parse(j);
1501
- }, u = async (h, S) => {
1482
+ const C = await te(d, "utf-8");
1483
+ return q.parse(C);
1484
+ }, u = async (g, y) => {
1502
1485
  try {
1503
- const d = (await ye(`*.${S}.yml`, { cwd: h, absolute: !0 }))[0];
1486
+ const d = (await ye(`*.${y}.yml`, { cwd: g, absolute: !0 }))[0];
1504
1487
  if (!d) return null;
1505
- const m = await te(d, "utf-8");
1506
- return q.parse(m);
1488
+ const f = await te(d, "utf-8");
1489
+ return q.parse(f);
1507
1490
  } catch (i) {
1508
1491
  p.error("parse component error", i);
1509
1492
  }
1510
1493
  return null;
1511
- }, I = async (h, S) => {
1512
- let i = A(h, `${S}.yml`);
1513
- if (!await G(i) && (i = A(h, S, "index.yml"), !await G(i)) || !(await oe(i)).isFile())
1494
+ }, I = async (g, y) => {
1495
+ let i = A(g, `${y}.yml`);
1496
+ if (!await G(i) && (i = A(g, y, "index.yml"), !await G(i)) || !(await oe(i)).isFile())
1514
1497
  return null;
1515
- const m = await te(i, "utf-8");
1516
- return q.parse(m);
1517
- }, C = L(
1498
+ const f = await te(i, "utf-8");
1499
+ return q.parse(f);
1500
+ }, R = L(
1518
1501
  await Promise.all(
1519
- y.pages.map(async ({ slug: h }) => {
1520
- const S = L(
1502
+ w.pages.map(async ({ slug: g }) => {
1503
+ const y = L(
1521
1504
  await Promise.all(
1522
- y.supportedLocales.map(async ({ locale: m }) => {
1523
- const j = c ? await g(c, ce(h), m) : void 0;
1524
- if (j)
1525
- return { locale: m, page: j };
1526
- const N = c ? await g(c, h, m) : void 0;
1527
- return N && { locale: m, page: N };
1505
+ w.supportedLocales.map(async ({ locale: f }) => {
1506
+ const C = c ? await m(c, ce(g), f) : void 0;
1507
+ if (C)
1508
+ return { locale: f, page: C };
1509
+ const N = c ? await m(c, g, f) : void 0;
1510
+ return N && { locale: f, page: N };
1528
1511
  })
1529
1512
  )
1530
- ), i = S[0]?.page;
1513
+ ), i = y[0]?.page;
1531
1514
  if (!i)
1532
1515
  return null;
1533
- const d = i.sections.map(Et);
1516
+ const d = i.sections.map(bt);
1534
1517
  return {
1535
- id: i.id || Ue(),
1518
+ id: i.id || $e(),
1536
1519
  createdAt: i.createdAt,
1537
1520
  updatedAt: i.updatedAt,
1538
1521
  publishedAt: i.publishedAt,
1539
1522
  isPublic: i.isPublic ?? !0,
1540
1523
  templateConfig: i.templateConfig,
1541
- slug: h,
1542
- sections: Object.fromEntries(d.map((m) => [m.id, m])),
1543
- sectionIds: d.map((m) => m.id),
1544
- locales: Object.fromEntries(S.map(({ locale: m, page: j }) => [m, j.meta])),
1524
+ slug: g,
1525
+ sections: Object.fromEntries(d.map((f) => [f.id, f])),
1526
+ sectionIds: d.map((f) => f.id),
1527
+ locales: Object.fromEntries(y.map(({ locale: f, page: C }) => [f, C.meta])),
1545
1528
  dataSource: i.dataSource ? Object.fromEntries(
1546
1529
  // 获取 dataSource 中所有 section ID
1547
- [...new Set(S.flatMap(({ page: m }) => Object.keys(m.dataSource ?? {})))].map((m) => [
1548
- m,
1530
+ [...new Set(y.flatMap(({ page: f }) => Object.keys(f.dataSource ?? {})))].map((f) => [
1531
+ f,
1549
1532
  Object.fromEntries(
1550
- S.map(({ locale: j, page: N }) => {
1551
- const T = N.dataSource?.[m];
1552
- return [j, T || {}];
1533
+ y.map(({ locale: C, page: N }) => {
1534
+ const T = N.dataSource?.[f];
1535
+ return [C, T || {}];
1553
1536
  })
1554
1537
  )
1555
1538
  ])
1556
1539
  ) : Object.fromEntries(
1557
1540
  // 获取所有 section ID
1558
- [...new Set(S.flatMap(({ page: m }) => m.sections.map((j) => j.id)))].map((m) => [
1559
- m,
1541
+ [...new Set(y.flatMap(({ page: f }) => f.sections.map((C) => C.id)))].map((f) => [
1542
+ f,
1560
1543
  Object.fromEntries(
1561
- S.map(({ locale: j, page: N }) => {
1562
- const T = N.dataSource?.[m];
1544
+ y.map(({ locale: C, page: N }) => {
1545
+ const T = N.dataSource?.[f];
1563
1546
  if (T)
1564
- return [j, T];
1565
- const V = N.sections.find((H) => H.id === m);
1566
- return [j, V?.properties || {}];
1547
+ return [C, T];
1548
+ const V = N.sections.find((J) => J.id === f);
1549
+ return [C, V?.properties || {}];
1567
1550
  })
1568
1551
  )
1569
1552
  ])
@@ -1571,80 +1554,80 @@ async function tt(t, { importAssets: e, includeResources: s } = {}) {
1571
1554
  };
1572
1555
  })
1573
1556
  )
1574
- ), O = L(
1557
+ ), j = L(
1575
1558
  await Promise.all(
1576
- (y?.routes || []).map(async ({ path: h }) => {
1577
- const S = b ? await I(b, ce(h)) : void 0;
1559
+ (w?.routes || []).map(async ({ path: g }) => {
1560
+ const y = b ? await I(b, ce(g)) : void 0;
1578
1561
  return {
1579
- ...S,
1580
- id: S?.id || Ue(),
1581
- createdAt: S?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1582
- updatedAt: S?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1562
+ ...y,
1563
+ id: y?.id || $e(),
1564
+ createdAt: y?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1565
+ updatedAt: y?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1583
1566
  publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
1584
- path: S?.path ?? `/${S?.id}`,
1585
- params: S?.params,
1586
- handler: S?.handler ?? "Pages Kit",
1587
- isPublic: S?.isPublic ?? !0,
1588
- enabledGenerate: S?.enabledGenerate ?? !1,
1589
- displayTemplateId: S?.displayTemplateId ?? void 0,
1590
- dataSource: S?.dataSource ?? {}
1567
+ path: y?.path ?? `/${y?.id}`,
1568
+ params: y?.params,
1569
+ handler: y?.handler ?? "Pages Kit",
1570
+ isPublic: y?.isPublic ?? !0,
1571
+ enabledGenerate: y?.enabledGenerate ?? !1,
1572
+ displayTemplateId: y?.displayTemplateId ?? void 0,
1573
+ dataSource: y?.dataSource ?? {}
1591
1574
  };
1592
1575
  })
1593
1576
  )
1594
- ), w = f ? L(
1595
- await Promise.all((y.components || []).map(async ({ id: h }) => u(f, h)))
1577
+ ), S = h ? L(
1578
+ await Promise.all((w.components || []).map(async ({ id: g }) => u(h, g)))
1596
1579
  ) : [];
1597
1580
  if (e) {
1598
- const h = (...S) => {
1599
- p.info(`[${o ? $(t) : $(A(t, "../../../../"))}] importAssets:`, ...S);
1581
+ const g = (...y) => {
1582
+ p.info(`[${o ? $(t) : $(A(t, "../../../../"))}] importAssets:`, ...y);
1600
1583
  };
1601
1584
  try {
1602
- h("wait image-bin api ready"), await Nt({
1603
- resources: [`${Rt(ut)}/api/sdk/uploads`],
1585
+ g("wait image-bin api ready"), await $t({
1586
+ resources: [`${Et(lt)}/api/sdk/uploads`],
1604
1587
  validateStatus: (d) => d >= 200 && d <= 500
1605
- }), h("image-bin api is ready");
1606
- const S = {}, i = {};
1607
- h("start to upload assets"), await Promise.allSettled([
1608
- ze(w, S, {
1609
- getFilePath: (d) => f && A(f, d),
1588
+ }), g("image-bin api is ready");
1589
+ const y = {}, i = {};
1590
+ g("start to upload assets"), await Promise.allSettled([
1591
+ Ge(S, y, {
1592
+ getFilePath: (d) => h && A(h, d),
1610
1593
  onFinish: (d) => {
1611
- h(`upload ${d.length} component assets`);
1594
+ g(`upload ${d.length} component assets`);
1612
1595
  }
1613
1596
  }),
1614
- ze(C, i, {
1615
- getFilePath: (d, m) => {
1616
- const j = je(C, m.slice(0, 1));
1617
- return c && A(c, M(j.slug), d);
1597
+ Ge(R, i, {
1598
+ getFilePath: (d, f) => {
1599
+ const C = Ce(R, f.slice(0, 1));
1600
+ return c && A(c, M(C.slug), d);
1618
1601
  },
1619
1602
  onFinish: (d) => {
1620
- h(`upload ${d.length} page assets`);
1603
+ g(`upload ${d.length} page assets`);
1621
1604
  }
1622
1605
  })
1623
- ]), h("upload assets done"), Pe.clear(), global.gc && global.gc();
1624
- } catch (S) {
1625
- h("Error during asset import:", S);
1606
+ ]), g("upload assets done"), Pe.clear(), global.gc && global.gc();
1607
+ } catch (y) {
1608
+ g("Error during asset import:", y);
1626
1609
  }
1627
1610
  }
1628
- const D = {};
1611
+ const v = {};
1629
1612
  if (s) {
1630
- const h = n && A(M(n), "../../resources/components"), S = L(
1613
+ const g = n && A(M(n), "../../resources/components"), y = L(
1631
1614
  await Promise.all(
1632
- (y.resources?.components || []).map(async ({ id: i }) => u(h, i))
1615
+ (w.resources?.components || []).map(async ({ id: i }) => u(g, i))
1633
1616
  )
1634
1617
  );
1635
- S.length > 0 && (D.components = Object.fromEntries(
1636
- S.map((i, d) => [i.id, { index: d, component: i }])
1618
+ y.length > 0 && (v.components = Object.fromEntries(
1619
+ y.map((i, d) => [i.id, { index: d, component: i }])
1637
1620
  ));
1638
1621
  }
1639
1622
  return {
1640
- supportedLocales: y.supportedLocales,
1641
- pageIds: C.map((h) => h.id),
1642
- components: Object.fromEntries(w.map((h, S) => [h.id, { index: S, data: h }])),
1643
- pages: Object.fromEntries(C.map((h) => [h.id, h])),
1644
- config: y.config || {},
1645
- resources: D,
1646
- routeIds: O.map((h) => h.id),
1647
- routes: Object.fromEntries(O.map((h) => [h.id, h])),
1623
+ supportedLocales: w.supportedLocales,
1624
+ pageIds: R.map((g) => g.id),
1625
+ components: Object.fromEntries(S.map((g, y) => [g.id, { index: y, data: g }])),
1626
+ pages: Object.fromEntries(R.map((g) => [g.id, g])),
1627
+ config: w.config || {},
1628
+ resources: v,
1629
+ routeIds: j.map((g) => g.id),
1630
+ routes: Object.fromEntries(j.map((g) => [g.id, g])),
1648
1631
  dataSourceIds: [],
1649
1632
  dataSources: {}
1650
1633
  };
@@ -1652,24 +1635,24 @@ async function tt(t, { importAssets: e, includeResources: s } = {}) {
1652
1635
  o && a && await We(a, { force: !0, recursive: !0 });
1653
1636
  }
1654
1637
  }
1655
- async function qe(t, e, {
1638
+ async function Ve(t, e, {
1656
1639
  routes: s,
1657
1640
  mergeMode: a = "byUpdateTime",
1658
1641
  deleteRoutes: o = !1,
1659
1642
  publishMode: r = void 0
1660
1643
  } = {}) {
1661
1644
  try {
1662
- r && dt(r);
1663
- } catch (y) {
1664
- p.error("clear preload page cache error", { error: y });
1645
+ r && pt(r);
1646
+ } catch (w) {
1647
+ p.error("clear preload page cache error", { error: w });
1665
1648
  }
1666
- const { pages: l, pageIds: n, routeIds: c, routes: f, supportedLocales: b } = t;
1649
+ const { pages: l, pageIds: n, routeIds: c, routes: h, supportedLocales: b } = t;
1667
1650
  if (r === "production") {
1668
- let y = s ?? [], g = null;
1651
+ let w = s ?? [], m = null;
1669
1652
  for (const u of c ?? []) {
1670
- const I = f?.[u];
1653
+ const I = h?.[u];
1671
1654
  if (I?.params && I?.params.length > 0 && I?.paramsOptions && I?.paramsOptions.length > 0) {
1672
- const C = be({
1655
+ const R = be({
1673
1656
  basePath: I.path,
1674
1657
  params: I.params,
1675
1658
  routeId: I.id,
@@ -1678,127 +1661,127 @@ async function qe(t, e, {
1678
1661
  currentParams: [],
1679
1662
  currentOptionIds: [],
1680
1663
  result: []
1681
- }), O = Object.fromEntries(C.map((w) => [`${u}-${w.paramOptionIds.join("-")}`, w]));
1682
- g = { ...g || {}, ...O }, s || (y = [...y, ...C.map((w) => `${u}-${w.paramOptionIds.join("-")}`)]);
1683
- } else s || y.push(u);
1664
+ }), j = Object.fromEntries(R.map((S) => [`${u}-${S.paramOptionIds.join("-")}`, S]));
1665
+ m = { ...m || {}, ...j }, s || (w = [...w, ...R.map((S) => `${u}-${S.paramOptionIds.join("-")}`)]);
1666
+ } else s || w.push(u);
1684
1667
  }
1685
- p.info("routeIds to be published: ", y);
1686
- for (const u of y) {
1668
+ p.info("routeIds to be published: ", w);
1669
+ for (const u of w) {
1687
1670
  let I = u;
1688
1671
  if (I.includes("-")) {
1689
- const [w] = I.split("-");
1690
- I = w;
1672
+ const [S] = I.split("-");
1673
+ I = S;
1691
1674
  }
1692
- const C = f?.[I];
1693
- if (!C) {
1694
- const w = e.pageIds.indexOf(I);
1695
- w !== -1 && o && (e.pageIds.splice(w, 1), delete e.pages[I]);
1696
- for (const D of e.pageIds)
1697
- D.includes(`${I}-`) && (e.pageIds.splice(e.pageIds.indexOf(D), 1), delete e.pages[D]);
1675
+ const R = h?.[I];
1676
+ if (!R) {
1677
+ const S = e.pageIds.indexOf(I);
1678
+ S !== -1 && o && (e.pageIds.splice(S, 1), delete e.pages[I]);
1679
+ for (const v of e.pageIds)
1680
+ v.includes(`${I}-`) && (e.pageIds.splice(e.pageIds.indexOf(v), 1), delete e.pages[v]);
1698
1681
  p.info("delete main route page", I);
1699
1682
  continue;
1700
1683
  }
1701
- if (u.includes("-") && !g?.[u]) {
1702
- const w = e.pageIds.indexOf(u);
1703
- w !== -1 && o && (e.pageIds.splice(w, 1), delete e.pages[u]), p.info("delete page", u);
1684
+ if (u.includes("-") && !m?.[u]) {
1685
+ const S = e.pageIds.indexOf(u);
1686
+ S !== -1 && o && (e.pageIds.splice(S, 1), delete e.pages[u]), p.info("delete page", u);
1704
1687
  continue;
1705
1688
  }
1706
- if (!C.displayTemplateId) {
1689
+ if (!R.displayTemplateId) {
1707
1690
  p.info("no display template", u);
1708
1691
  continue;
1709
1692
  }
1710
- const O = l[C.displayTemplateId];
1711
- if (!O) {
1693
+ const j = l[R.displayTemplateId];
1694
+ if (!j) {
1712
1695
  p.info("no template page", u);
1713
1696
  continue;
1714
1697
  }
1715
1698
  if (e.pageIds.includes(u)) {
1716
1699
  if (p.info("has need update page", u), a === "replace")
1717
1700
  e.pages[u] = me({
1718
- page: O,
1719
- route: C,
1701
+ page: j,
1702
+ route: R,
1720
1703
  state: t,
1721
1704
  routeId: u,
1722
- routePathInfo: g?.[u]
1705
+ routePathInfo: m?.[u]
1723
1706
  }), p.info("replace page", u);
1724
1707
  else if (a === "byUpdateTime") {
1725
- const w = e.pages[C.id];
1726
- (!w || C.updatedAt && C.updatedAt > w.updatedAt) && (e.pages[u] = me({
1727
- page: O,
1728
- route: C,
1708
+ const S = e.pages[R.id];
1709
+ (!S || R.updatedAt && R.updatedAt > S.updatedAt) && (e.pages[u] = me({
1710
+ page: j,
1711
+ route: R,
1729
1712
  state: t,
1730
1713
  routeId: u,
1731
- routePathInfo: g?.[u]
1714
+ routePathInfo: m?.[u]
1732
1715
  }), p.info("replace page by update time", u));
1733
1716
  }
1734
1717
  } else
1735
1718
  e.pageIds.push(u), e.pages[u] = me({
1736
- page: O,
1737
- route: C,
1719
+ page: j,
1720
+ route: R,
1738
1721
  state: t,
1739
1722
  routeId: u,
1740
- routePathInfo: g?.[u]
1723
+ routePathInfo: m?.[u]
1741
1724
  }), p.info("add page", u);
1742
1725
  }
1743
1726
  if (o && !s)
1744
1727
  for (const u of e.pageIds)
1745
- y?.includes(u) || (delete e.pages[u], p.info("delete page", u)), e.pageIds = [...e.pageIds].filter((I) => y?.includes(I));
1728
+ w?.includes(u) || (delete e.pages[u], p.info("delete page", u)), e.pageIds = [...e.pageIds].filter((I) => w?.includes(I));
1746
1729
  } else {
1747
- for (const y of n) {
1748
- const g = l[y];
1749
- if (g)
1750
- if (e.pageIds.includes(g.id)) {
1730
+ for (const w of n) {
1731
+ const m = l[w];
1732
+ if (m)
1733
+ if (e.pageIds.includes(m.id)) {
1751
1734
  if (a === "replace")
1752
- e.pages[g.id] = g;
1735
+ e.pages[m.id] = m;
1753
1736
  else if (a === "byUpdateTime") {
1754
- const u = e.pages[g.id];
1755
- (!u || g.updatedAt && g.updatedAt > u.updatedAt) && (e.pages[g.id] = g);
1737
+ const u = e.pages[m.id];
1738
+ (!u || m.updatedAt && m.updatedAt > u.updatedAt) && (e.pages[m.id] = m);
1756
1739
  }
1757
1740
  } else
1758
- e.pageIds.push(g.id), e.pages[g.id] = g;
1741
+ e.pageIds.push(m.id), e.pages[m.id] = m;
1759
1742
  }
1760
- for (const y of c) {
1761
- const g = f[y];
1762
- if (g)
1763
- if (e.routeIds.includes(g.id)) {
1743
+ for (const w of c) {
1744
+ const m = h[w];
1745
+ if (m)
1746
+ if (e.routeIds.includes(m.id)) {
1764
1747
  if (a === "replace")
1765
- e.routes[g.id] = g;
1748
+ e.routes[m.id] = m;
1766
1749
  else if (a === "byUpdateTime") {
1767
- const u = e.routes[g.id];
1768
- (!u || g.updatedAt && g.updatedAt > u.updatedAt) && (e.routes[g.id] = g);
1750
+ const u = e.routes[m.id];
1751
+ (!u || m.updatedAt && m.updatedAt > u.updatedAt) && (e.routes[m.id] = m);
1769
1752
  }
1770
1753
  } else
1771
- e.routeIds.push(g.id), e.routes[g.id] = g;
1754
+ e.routeIds.push(m.id), e.routes[m.id] = m;
1772
1755
  }
1773
1756
  }
1774
1757
  if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...Ae(b)), o)
1775
- for (const y of Object.keys(e.components))
1776
- delete e.components[y];
1777
- let R = JSON.parse(JSON.stringify(t.components));
1778
- R = Object.fromEntries(
1758
+ for (const w of Object.keys(e.components))
1759
+ delete e.components[w];
1760
+ let O = JSON.parse(JSON.stringify(t.components));
1761
+ O = Object.fromEntries(
1779
1762
  await Promise.all(
1780
- Object.entries(R).map(async ([y, g]) => {
1781
- const u = await st(g?.data);
1763
+ Object.entries(O).map(async ([w, m]) => {
1764
+ const u = await et(m?.data);
1782
1765
  return [
1783
- y,
1766
+ w,
1784
1767
  {
1785
- ...g,
1768
+ ...m,
1786
1769
  data: u
1787
1770
  }
1788
1771
  ];
1789
1772
  })
1790
1773
  )
1791
- ), Object.assign(e.components, R), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))), ke(t.resources.components) || (e.resources.components = JSON.parse(JSON.stringify(t.resources.components || {})));
1774
+ ), Object.assign(e.components, O), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))), De(t.resources.components) || (e.resources.components = JSON.parse(JSON.stringify(t.resources.components || {})));
1792
1775
  }
1793
- const st = lt(
1776
+ const et = it(
1794
1777
  async (t) => {
1795
- if (!ke(t?.properties))
1778
+ if (!De(t?.properties))
1796
1779
  return t;
1797
1780
  if (t?.renderer?.type === "react-component") {
1798
1781
  const { script: e, PROPERTIES_SCHEMA: s } = t?.renderer || {};
1799
1782
  if (s || e && e.includes("PROPERTIES_SCHEMA"))
1800
1783
  try {
1801
- const a = await pt(
1784
+ const a = await ct(
1802
1785
  e ?? "",
1803
1786
  "PROPERTIES_SCHEMA",
1804
1787
  t.id,
@@ -1821,32 +1804,32 @@ const st = lt(
1821
1804
  }
1822
1805
  );
1823
1806
  let le, Q, pe, ue;
1824
- const at = () => Ct({
1807
+ const tt = () => jt({
1825
1808
  types: [
1826
- { did: Ye, type: xe },
1827
- { did: Jt, type: xe }
1809
+ { did: Ke, type: Fe },
1810
+ { did: zt, type: Fe }
1828
1811
  ]
1829
- }), Is = async () => {
1830
- const t = at(), e = {};
1812
+ }), Ss = async () => {
1813
+ const t = tt(), e = {};
1831
1814
  for (const s of t) {
1832
1815
  const o = (await ye("**/.blocklet/pages/pages.config.yml", {
1833
1816
  cwd: s.path,
1834
1817
  absolute: !0
1835
1818
  }))[0], r = o && A(M(o), "../../chunks");
1836
1819
  if (r && await G(r)) {
1837
- const l = await vt(r);
1820
+ const l = await Dt(r);
1838
1821
  for (const n of l)
1839
1822
  e[n] = A(r, n);
1840
1823
  }
1841
1824
  }
1842
1825
  return e;
1843
1826
  };
1844
- function ot() {
1827
+ function st() {
1845
1828
  return le = (async () => {
1846
- const t = at();
1829
+ const t = tt();
1847
1830
  Q = (await Promise.all(
1848
1831
  t.map(async (s) => {
1849
- const a = s.path ? await tt(s.path, { importAssets: !1 }) : void 0;
1832
+ const a = s.path ? await Ze(s.path, { importAssets: !1 }) : void 0;
1850
1833
  return a ? { blockletId: s.did, state: a, blockletTitle: s.title } : void 0;
1851
1834
  })
1852
1835
  )).filter((s) => !!s), pe = Q.reduce(
@@ -1870,7 +1853,7 @@ function ot() {
1870
1853
  ue = Object.fromEntries(
1871
1854
  await Promise.all(
1872
1855
  Object.entries(e).map(async ([s, a]) => {
1873
- const o = await st(a.component);
1856
+ const o = await et(a.component);
1874
1857
  return [
1875
1858
  s,
1876
1859
  {
@@ -1883,10 +1866,10 @@ function ot() {
1883
1866
  );
1884
1867
  })(), le;
1885
1868
  }
1886
- function Ps(t) {
1887
- const e = Ce(
1869
+ function ws(t) {
1870
+ const e = Re(
1888
1871
  async () => {
1889
- await ot().catch((s) => {
1872
+ await st().catch((s) => {
1890
1873
  p.error("load resource states error", { error: s });
1891
1874
  }), await t?.({
1892
1875
  states: Q,
@@ -1902,12 +1885,12 @@ function Ps(t) {
1902
1885
  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(we, e);
1903
1886
  };
1904
1887
  }
1905
- const rt = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), nt = globalThis;
1906
- nt[rt]?.();
1907
- nt[rt] = Ps(async ({ pages: t, components: e }) => {
1908
- const s = await k.getProjectIds();
1888
+ const at = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), ot = globalThis;
1889
+ ot[at]?.();
1890
+ ot[at] = ws(async ({ pages: t, components: e }) => {
1891
+ const s = await D.getProjectIds();
1909
1892
  p.info(`start update resource states projects(${s.length})`, s);
1910
- const a = Re(10);
1893
+ const a = Oe(10);
1911
1894
  await Promise.race([
1912
1895
  new Promise((o) => {
1913
1896
  setTimeout(() => {
@@ -1917,7 +1900,7 @@ nt[rt] = Ps(async ({ pages: t, components: e }) => {
1917
1900
  Promise.all(
1918
1901
  s.map(
1919
1902
  (o) => a(async () => {
1920
- it({
1903
+ rt({
1921
1904
  projectId: o,
1922
1905
  pages: t,
1923
1906
  components: e
@@ -1929,52 +1912,47 @@ nt[rt] = Ps(async ({ pages: t, components: e }) => {
1929
1912
  p.error("update resource states failed:", o);
1930
1913
  });
1931
1914
  });
1932
- k.startPeriodicCheck();
1915
+ D.startPeriodicCheck();
1933
1916
  process.on("beforeExit", () => {
1934
- k.stopPeriodicCheck();
1917
+ D.stopPeriodicCheck();
1935
1918
  });
1936
1919
  process.on("SIGINT", () => {
1937
- k.stopPeriodicCheck(), process.exit(0);
1920
+ D.stopPeriodicCheck(), process.exit(0);
1938
1921
  });
1939
1922
  process.on("SIGTERM", () => {
1940
- k.stopPeriodicCheck(), process.exit(0);
1923
+ D.stopPeriodicCheck(), process.exit(0);
1941
1924
  });
1942
- async function it({
1925
+ async function rt({
1943
1926
  projectId: t,
1944
1927
  pages: e,
1945
1928
  components: s
1946
1929
  }) {
1947
- const a = k.sharedInstances[t];
1930
+ const a = D.sharedInstances[t];
1948
1931
  if (!a) {
1949
1932
  p.info(`projectId: ${t} not found in sharedInstances`);
1950
1933
  return;
1951
1934
  }
1952
- const o = a.syncedStore.resources.pages, r = a.syncedStore.resources.components, l = await U.findByPk(t, {
1935
+ const o = await U.findByPk(t, {
1953
1936
  attributes: { exclude: ["productionState", "relatedBlocklets"] }
1954
1937
  });
1955
- let n;
1956
- if (l?.useAllResources)
1957
- n = s;
1938
+ let r;
1939
+ if (o?.useAllResources)
1940
+ r = s;
1958
1941
  else {
1959
- const R = (await De.findAll({ where: { projectId: t } })).map((y) => y.componentId);
1960
- n = Object.fromEntries(Object.entries(s || {}).filter(([y]) => R.includes(y)));
1942
+ const n = (await ve.findAll({ where: { projectId: t } })).map((c) => c.componentId);
1943
+ r = Object.fromEntries(Object.entries(s || {}).filter(([c]) => n.includes(c)));
1961
1944
  }
1962
- const c = !Ge(o, e), f = !Ge(r, n);
1963
- c || f ? a.transact(() => {
1964
- c && (a.syncedStore.resources.pages = e, p.info(`[${t}] pages resources updated: ${Object.keys(e || {}).length} pages`)), f && (a.syncedStore.resources.components = n, p.info(
1965
- `[${t}] components resources updated: ${Object.keys(n || {}).length} components`
1966
- ));
1967
- }) : p.info(`[${t}] resource states unchanged, skipping update`), p.info(`update [${t}] resource states summary:`, {
1945
+ a.transact(() => {
1946
+ a.syncedStore.resources.pages = e, p.info(`[${t}] pages resources updated: ${Object.keys(e || {}).length} pages`), a.syncedStore.resources.components = r, p.info(`[${t}] components resources updated: ${Object.keys(r || {}).length} components`);
1947
+ }), p.info(`update [${t}] resource states summary:`, {
1968
1948
  pages: Object.keys(a.syncedStore.resources.pages || {}).length,
1969
- components: Object.keys(a.syncedStore.resources.components || {}).length,
1970
- pagesChanged: c,
1971
- componentsChanged: f
1949
+ components: Object.keys(a.syncedStore.resources.components || {}).length
1972
1950
  });
1973
1951
  }
1974
1952
  const he = /* @__PURE__ */ new Map();
1975
- async function bs(t) {
1953
+ async function Is(t) {
1976
1954
  if (!he.has(t)) {
1977
- const e = Ce(async (s) => it({
1955
+ const e = Re(async (s) => rt({
1978
1956
  projectId: s,
1979
1957
  pages: pe,
1980
1958
  components: ue
@@ -1983,31 +1961,31 @@ async function bs(t) {
1983
1961
  }
1984
1962
  return he.get(t)(t);
1985
1963
  }
1986
- async function ia() {
1964
+ async function ra() {
1987
1965
  p.info("trigger reload all project resource"), E.events.emit(we);
1988
1966
  }
1989
- async function ca({
1967
+ async function na({
1990
1968
  ensureLoaded: t = !0
1991
1969
  } = {}) {
1992
- return t && (le ??= ot(), await le), { states: Q, pages: pe, components: ue };
1970
+ return t && (le ??= st(), await le), { states: Q, pages: pe, components: ue };
1993
1971
  }
1994
1972
  export {
1995
- Ye as C,
1973
+ Ke as C,
1996
1974
  U as P,
1997
- xe as R,
1998
- k as S,
1999
- K as a,
2000
- ra as b,
2001
- oa as c,
2002
- na as d,
2003
- gs as e,
2004
- ys as f,
2005
- ca as g,
2006
- Ss as h,
2007
- tt as i,
2008
- Ps as j,
2009
- ia as k,
2010
- qe as m,
2011
- ws as t,
2012
- bs as u
1975
+ Fe as R,
1976
+ D as S,
1977
+ H as a,
1978
+ aa as b,
1979
+ sa as c,
1980
+ oa as d,
1981
+ fs as e,
1982
+ gs as f,
1983
+ na as g,
1984
+ hs as h,
1985
+ Ze as i,
1986
+ ws as j,
1987
+ ra as k,
1988
+ Ve as m,
1989
+ ys as t,
1990
+ Is as u
2013
1991
  };