@blocklet/pages-kit-inner-components 0.7.5 → 0.7.7

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