zen-fs-config 0.7.2 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1389,6 +1389,74 @@ declare function resolveLocalPrimary(appId: string, kind: 'config' | 'data', opt
1389
1389
  /** The backend type used for the implicit local primary in the current env (default). */
1390
1390
  declare function localPrimaryType(): string;
1391
1391
 
1392
+ /**
1393
+ * 本地主存储(IndexedDB)不可用 / 已损坏。
1394
+ *
1395
+ * 背景:浏览器 IndexedDB 记录丢失时,@zenfs/dom 抛出 `NotReadableError`,
1396
+ * @zenfs/core 再把它映射成 `EIO`。此前 `AppDataGroupImpl.init()` 把任何异常
1397
+ * 都包成一句 `Failed to create local primary ...`,原始错因(name/code/message)
1398
+ * 全部丢失,调用方无法区分「本地库坏了」和「组就是不存在」,于是被降级成
1399
+ * 「没有可用的数据同步组」。
1400
+ *
1401
+ * 这个错误类型把「本地存储不可用」变成可识别、可修复的状态:
1402
+ * - 保留原始 `cause`(含 code/name/message);
1403
+ * - 带上 appId / groupId / IndexedDB 库名,供 UI 精确展示与一键重建;
1404
+ * - `isLocalStorageUnavailableError()` 能穿透 cause 链识别底层原始异常。
1405
+ */
1406
+ declare const LOCAL_STORAGE_UNAVAILABLE = "LOCAL_STORAGE_UNAVAILABLE";
1407
+ interface LocalStorageUnavailableDetails {
1408
+ appId: string;
1409
+ groupId: string;
1410
+ /** 该数据组独占的 IndexedDB 库名(`zen-fs-config-data-{appId}[-{groupId}]`)。 */
1411
+ storeName: string;
1412
+ /** 原始异常(NotReadableError / EIO / DOMException …)。 */
1413
+ cause?: unknown;
1414
+ }
1415
+ /** 数据组本地主存储所在的 IndexedDB 库名(与 resolveLocalPrimary 保持一致)。 */
1416
+ declare function dataGroupLocalStoreName(appId: string, groupId: string): string;
1417
+ declare class LocalStorageUnavailableError extends Error {
1418
+ readonly code = "LOCAL_STORAGE_UNAVAILABLE";
1419
+ readonly appId: string;
1420
+ readonly groupId: string;
1421
+ readonly storeName: string;
1422
+ readonly cause?: unknown;
1423
+ constructor(details: LocalStorageUnavailableDetails);
1424
+ /** 原始异常的可序列化摘要(code / name / message),便于日志与诊断面板展示。 */
1425
+ toJSON(): Record<string, unknown>;
1426
+ }
1427
+ /**
1428
+ * 判断一个异常(含 cause 链)是否代表「本地存储不可用」。
1429
+ *
1430
+ * 识别依据:
1431
+ * - 本库包装的 {@link LocalStorageUnavailableError};
1432
+ * - `NotReadableError`(IndexedDB 记录丢失);
1433
+ * - `EIO`(@zenfs/core 对 NotReadableError 的映射);
1434
+ * - “Data lost due to missing file” 等原始 message。
1435
+ */
1436
+ declare function isLocalStorageUnavailableError(err: unknown): boolean;
1437
+ interface LocalStoreDeletionResult {
1438
+ storeName: string;
1439
+ /** 库已被删除(或本来就不存在)。 */
1440
+ deleted: boolean;
1441
+ /** 删除被其它连接(其它标签页)阻塞,尚未完成。 */
1442
+ blocked: boolean;
1443
+ /** 当前环境没有 IndexedDB(例如 Node),无法执行。 */
1444
+ unsupported?: boolean;
1445
+ error?: string;
1446
+ }
1447
+ /**
1448
+ * 删除**该数据组独占**的本地 IndexedDB 库(只删
1449
+ * `zen-fs-config-data-{appId}[-{groupId}]`,绝不触碰配置仓的
1450
+ * `zen-fs-config-config-{appId}`)。
1451
+ *
1452
+ * 注意:如果还有别的标签页/实例连着这个库,浏览器会触发 `blocked`,此时删除
1453
+ * 会一直挂起。函数在 `timeoutMs` 后返回 `blocked: true`,调用方应提示用户关闭
1454
+ * 其它页面(或刷新后在没有旧连接的情况下重试)。
1455
+ */
1456
+ declare function deleteDataGroupLocalStore(appId: string, groupId: string, options?: {
1457
+ timeoutMs?: number;
1458
+ }): Promise<LocalStoreDeletionResult>;
1459
+
1392
1460
  /**
1393
1461
  * zen-fs-config — Unified Connect Entry Point
1394
1462
  *
@@ -1607,4 +1675,4 @@ declare class ConflictStore {
1607
1675
  resolve(conflictId: string, mergedContent: string | Uint8Array): Promise<void>;
1608
1676
  }
1609
1677
 
1610
- export { type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type BackendDescriptor, type BackendFactory, type BackendInstance, type BackendMetadata, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, type ConnectOptions, type ConnectResult, DATA_GROUP_DEFAULT_FEATURES, FolderStore, GROUP_DESCRIPTOR_FILE, type GroupDescriptor, type IConfigRepo, type KeepPurgeResult, LEGACY_CONFLICTS_DIR, LEGACY_TOMBSTONES_DIR, LOCAL_IDB_BACKEND_ID, META_DIR, type MigrateLocalFS, type MigrateReplicaFS, type MtimePurgeResult, type PurgeKeepOptions, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, configKeyToFilePath, connect, createBackend, createConfigRepo, createSerializerChain, encodeMetaPath, getAccountFields, getBackendMetadata, getExtension, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isMtimeSidecar, legacyVersionPathFor, listBackendMetadata, listBackends, localPrimaryType, mergeAccountFields, migrateVersionSidecars, purgeKeepFiles, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, sha256, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };
1678
+ export { type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type BackendDescriptor, type BackendFactory, type BackendInstance, type BackendMetadata, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, type ConnectOptions, type ConnectResult, DATA_GROUP_DEFAULT_FEATURES, FolderStore, GROUP_DESCRIPTOR_FILE, type GroupDescriptor, type IConfigRepo, type KeepPurgeResult, LEGACY_CONFLICTS_DIR, LEGACY_TOMBSTONES_DIR, LOCAL_IDB_BACKEND_ID, LOCAL_STORAGE_UNAVAILABLE, type LocalStorageUnavailableDetails, LocalStorageUnavailableError, type LocalStoreDeletionResult, META_DIR, type MigrateLocalFS, type MigrateReplicaFS, type MtimePurgeResult, type PurgeKeepOptions, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, configKeyToFilePath, connect, createBackend, createConfigRepo, createSerializerChain, dataGroupLocalStoreName, deleteDataGroupLocalStore, encodeMetaPath, getAccountFields, getBackendMetadata, getExtension, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalStorageUnavailableError, isMtimeSidecar, legacyVersionPathFor, listBackendMetadata, listBackends, localPrimaryType, mergeAccountFields, migrateVersionSidecars, purgeKeepFiles, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, sha256, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };
package/dist/index.d.ts CHANGED
@@ -1389,6 +1389,74 @@ declare function resolveLocalPrimary(appId: string, kind: 'config' | 'data', opt
1389
1389
  /** The backend type used for the implicit local primary in the current env (default). */
1390
1390
  declare function localPrimaryType(): string;
1391
1391
 
1392
+ /**
1393
+ * 本地主存储(IndexedDB)不可用 / 已损坏。
1394
+ *
1395
+ * 背景:浏览器 IndexedDB 记录丢失时,@zenfs/dom 抛出 `NotReadableError`,
1396
+ * @zenfs/core 再把它映射成 `EIO`。此前 `AppDataGroupImpl.init()` 把任何异常
1397
+ * 都包成一句 `Failed to create local primary ...`,原始错因(name/code/message)
1398
+ * 全部丢失,调用方无法区分「本地库坏了」和「组就是不存在」,于是被降级成
1399
+ * 「没有可用的数据同步组」。
1400
+ *
1401
+ * 这个错误类型把「本地存储不可用」变成可识别、可修复的状态:
1402
+ * - 保留原始 `cause`(含 code/name/message);
1403
+ * - 带上 appId / groupId / IndexedDB 库名,供 UI 精确展示与一键重建;
1404
+ * - `isLocalStorageUnavailableError()` 能穿透 cause 链识别底层原始异常。
1405
+ */
1406
+ declare const LOCAL_STORAGE_UNAVAILABLE = "LOCAL_STORAGE_UNAVAILABLE";
1407
+ interface LocalStorageUnavailableDetails {
1408
+ appId: string;
1409
+ groupId: string;
1410
+ /** 该数据组独占的 IndexedDB 库名(`zen-fs-config-data-{appId}[-{groupId}]`)。 */
1411
+ storeName: string;
1412
+ /** 原始异常(NotReadableError / EIO / DOMException …)。 */
1413
+ cause?: unknown;
1414
+ }
1415
+ /** 数据组本地主存储所在的 IndexedDB 库名(与 resolveLocalPrimary 保持一致)。 */
1416
+ declare function dataGroupLocalStoreName(appId: string, groupId: string): string;
1417
+ declare class LocalStorageUnavailableError extends Error {
1418
+ readonly code = "LOCAL_STORAGE_UNAVAILABLE";
1419
+ readonly appId: string;
1420
+ readonly groupId: string;
1421
+ readonly storeName: string;
1422
+ readonly cause?: unknown;
1423
+ constructor(details: LocalStorageUnavailableDetails);
1424
+ /** 原始异常的可序列化摘要(code / name / message),便于日志与诊断面板展示。 */
1425
+ toJSON(): Record<string, unknown>;
1426
+ }
1427
+ /**
1428
+ * 判断一个异常(含 cause 链)是否代表「本地存储不可用」。
1429
+ *
1430
+ * 识别依据:
1431
+ * - 本库包装的 {@link LocalStorageUnavailableError};
1432
+ * - `NotReadableError`(IndexedDB 记录丢失);
1433
+ * - `EIO`(@zenfs/core 对 NotReadableError 的映射);
1434
+ * - “Data lost due to missing file” 等原始 message。
1435
+ */
1436
+ declare function isLocalStorageUnavailableError(err: unknown): boolean;
1437
+ interface LocalStoreDeletionResult {
1438
+ storeName: string;
1439
+ /** 库已被删除(或本来就不存在)。 */
1440
+ deleted: boolean;
1441
+ /** 删除被其它连接(其它标签页)阻塞,尚未完成。 */
1442
+ blocked: boolean;
1443
+ /** 当前环境没有 IndexedDB(例如 Node),无法执行。 */
1444
+ unsupported?: boolean;
1445
+ error?: string;
1446
+ }
1447
+ /**
1448
+ * 删除**该数据组独占**的本地 IndexedDB 库(只删
1449
+ * `zen-fs-config-data-{appId}[-{groupId}]`,绝不触碰配置仓的
1450
+ * `zen-fs-config-config-{appId}`)。
1451
+ *
1452
+ * 注意:如果还有别的标签页/实例连着这个库,浏览器会触发 `blocked`,此时删除
1453
+ * 会一直挂起。函数在 `timeoutMs` 后返回 `blocked: true`,调用方应提示用户关闭
1454
+ * 其它页面(或刷新后在没有旧连接的情况下重试)。
1455
+ */
1456
+ declare function deleteDataGroupLocalStore(appId: string, groupId: string, options?: {
1457
+ timeoutMs?: number;
1458
+ }): Promise<LocalStoreDeletionResult>;
1459
+
1392
1460
  /**
1393
1461
  * zen-fs-config — Unified Connect Entry Point
1394
1462
  *
@@ -1607,4 +1675,4 @@ declare class ConflictStore {
1607
1675
  resolve(conflictId: string, mergedContent: string | Uint8Array): Promise<void>;
1608
1676
  }
1609
1677
 
1610
- export { type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type BackendDescriptor, type BackendFactory, type BackendInstance, type BackendMetadata, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, type ConnectOptions, type ConnectResult, DATA_GROUP_DEFAULT_FEATURES, FolderStore, GROUP_DESCRIPTOR_FILE, type GroupDescriptor, type IConfigRepo, type KeepPurgeResult, LEGACY_CONFLICTS_DIR, LEGACY_TOMBSTONES_DIR, LOCAL_IDB_BACKEND_ID, META_DIR, type MigrateLocalFS, type MigrateReplicaFS, type MtimePurgeResult, type PurgeKeepOptions, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, configKeyToFilePath, connect, createBackend, createConfigRepo, createSerializerChain, encodeMetaPath, getAccountFields, getBackendMetadata, getExtension, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isMtimeSidecar, legacyVersionPathFor, listBackendMetadata, listBackends, localPrimaryType, mergeAccountFields, migrateVersionSidecars, purgeKeepFiles, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, sha256, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };
1678
+ export { type AppDataBackendDescriptor, type AppDataGroup, type AppDataGroupDescriptor, type BackendDescriptor, type BackendFactory, type BackendInstance, type BackendMetadata, type BackendParamDef, type BackendSyncState, type BackendsMeta, CONFIG_DIR, CONFLICTS_DIR, type CacheOptions, ConfigRepo, type ConfigRepoOptions, type ConfigSerializer, type ConfigSyncGroupDescriptor, type ConfigSyncGroupHandle, type ConflictArchive, type ConflictInfo, ConflictStore, type ConnectOptions, type ConnectResult, DATA_GROUP_DEFAULT_FEATURES, FolderStore, GROUP_DESCRIPTOR_FILE, type GroupDescriptor, type IConfigRepo, type KeepPurgeResult, LEGACY_CONFLICTS_DIR, LEGACY_TOMBSTONES_DIR, LOCAL_IDB_BACKEND_ID, LOCAL_STORAGE_UNAVAILABLE, type LocalStorageUnavailableDetails, LocalStorageUnavailableError, type LocalStoreDeletionResult, META_DIR, type MigrateLocalFS, type MigrateReplicaFS, type MtimePurgeResult, type PurgeKeepOptions, type PurgeMtimeOptions, type PurgeableFS$1 as PurgeableFS, type SyncGroupFeatures, type SyncGroupHandle, type SyncGroupKind, type SyncGroupType, TOMBSTONES_DIR, type TombstoneMeta, TombstoneStore, VERSIONS_DIR, type VersionMeta, type VersionMigrationOptions, type VersionMigrationResult, VersionStore, configKeyToFilePath, connect, createBackend, createConfigRepo, createSerializerChain, dataGroupLocalStoreName, deleteDataGroupLocalStore, encodeMetaPath, getAccountFields, getBackendMetadata, getExtension, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalStorageUnavailableError, isMtimeSidecar, legacyVersionPathFor, listBackendMetadata, listBackends, localPrimaryType, mergeAccountFields, migrateVersionSidecars, purgeKeepFiles, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, sha256, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };
package/dist/index.js CHANGED
@@ -523,6 +523,8 @@ __export(index_exports, {
523
523
  LEGACY_CONFLICTS_DIR: () => LEGACY_CONFLICTS_DIR,
524
524
  LEGACY_TOMBSTONES_DIR: () => LEGACY_TOMBSTONES_DIR,
525
525
  LOCAL_IDB_BACKEND_ID: () => LOCAL_IDB_BACKEND_ID,
526
+ LOCAL_STORAGE_UNAVAILABLE: () => LOCAL_STORAGE_UNAVAILABLE,
527
+ LocalStorageUnavailableError: () => LocalStorageUnavailableError,
526
528
  META_DIR: () => META_DIR,
527
529
  TOMBSTONES_DIR: () => TOMBSTONES_DIR,
528
530
  TombstoneStore: () => TombstoneStore,
@@ -533,6 +535,8 @@ __export(index_exports, {
533
535
  createBackend: () => createBackend,
534
536
  createConfigRepo: () => createConfigRepo,
535
537
  createSerializerChain: () => createSerializerChain,
538
+ dataGroupLocalStoreName: () => dataGroupLocalStoreName,
539
+ deleteDataGroupLocalStore: () => deleteDataGroupLocalStore,
536
540
  encodeMetaPath: () => encodeMetaPath,
537
541
  getAccountFields: () => getAccountFields,
538
542
  getBackendMetadata: () => getBackendMetadata,
@@ -541,6 +545,7 @@ __export(index_exports, {
541
545
  incrementVersion: () => incrementVersion,
542
546
  isBrowserEnv: () => isBrowserEnv,
543
547
  isKeepFile: () => isKeepFile,
548
+ isLocalStorageUnavailableError: () => isLocalStorageUnavailableError,
544
549
  isMtimeSidecar: () => isMtimeSidecar,
545
550
  legacyVersionPathFor: () => legacyVersionPathFor,
546
551
  listBackendMetadata: () => listBackendMetadata,
@@ -977,6 +982,125 @@ async function defaultNodeDir(appId, kind, groupId) {
977
982
  return kindDir;
978
983
  }
979
984
 
985
+ // src/errors.ts
986
+ var LOCAL_STORAGE_UNAVAILABLE = "LOCAL_STORAGE_UNAVAILABLE";
987
+ function dataGroupLocalStoreName(appId, groupId) {
988
+ return groupId === "default" ? `zen-fs-config-data-${appId}` : `zen-fs-config-data-${appId}-${groupId}`;
989
+ }
990
+ var LocalStorageUnavailableError = class extends Error {
991
+ code = LOCAL_STORAGE_UNAVAILABLE;
992
+ appId;
993
+ groupId;
994
+ storeName;
995
+ cause;
996
+ constructor(details) {
997
+ super(
998
+ `Local storage for data group "${details.groupId}" is unavailable (IndexedDB "${details.storeName}"): ${describeError(details.cause)}`
999
+ );
1000
+ this.name = "LocalStorageUnavailableError";
1001
+ this.appId = details.appId;
1002
+ this.groupId = details.groupId;
1003
+ this.storeName = details.storeName;
1004
+ this.cause = details.cause;
1005
+ }
1006
+ /** 原始异常的可序列化摘要(code / name / message),便于日志与诊断面板展示。 */
1007
+ toJSON() {
1008
+ return {
1009
+ name: this.name,
1010
+ code: this.code,
1011
+ appId: this.appId,
1012
+ groupId: this.groupId,
1013
+ storeName: this.storeName,
1014
+ message: this.message,
1015
+ cause: summarizeError(this.cause)
1016
+ };
1017
+ }
1018
+ };
1019
+ function summarizeError(err) {
1020
+ if (err instanceof Error || err && typeof err === "object") {
1021
+ const anyErr = err;
1022
+ return {
1023
+ name: anyErr.name,
1024
+ code: anyErr.code,
1025
+ message: anyErr.message ?? String(err),
1026
+ stack: anyErr.stack
1027
+ };
1028
+ }
1029
+ return { message: String(err) };
1030
+ }
1031
+ function describeError(err) {
1032
+ const s = summarizeError(err);
1033
+ return [s.name, s.code, s.message].filter(Boolean).join(": ");
1034
+ }
1035
+ var STORAGE_MESSAGE_HINTS = [
1036
+ /Data lost due to missing file/i,
1037
+ /should be considered irrecoverable/i,
1038
+ /IndexedDB.*(corrupt|unreadable)/i
1039
+ ];
1040
+ function isLocalStorageUnavailableError(err) {
1041
+ let cur = err;
1042
+ for (let depth = 0; cur && depth < 6; depth++) {
1043
+ if (cur instanceof LocalStorageUnavailableError) return true;
1044
+ const anyErr = cur;
1045
+ if (anyErr.name === "NotReadableError") return true;
1046
+ if (anyErr.code === "EIO") return true;
1047
+ const message = typeof anyErr.message === "string" ? anyErr.message : "";
1048
+ if (message && STORAGE_MESSAGE_HINTS.some((re) => re.test(message))) return true;
1049
+ cur = anyErr.cause;
1050
+ }
1051
+ return false;
1052
+ }
1053
+ function deleteDataGroupLocalStore(appId, groupId, options = {}) {
1054
+ const storeName = dataGroupLocalStoreName(appId, groupId);
1055
+ const idb = globalThis.indexedDB;
1056
+ if (!idb || typeof idb.deleteDatabase !== "function") {
1057
+ return Promise.resolve({
1058
+ storeName,
1059
+ deleted: false,
1060
+ blocked: false,
1061
+ unsupported: true,
1062
+ error: "\u5F53\u524D\u73AF\u5883\u6CA1\u6709 IndexedDB\uFF1A\u65E0\u6CD5\u5220\u9664\u672C\u5730\u6570\u636E\u7EC4\u5B58\u50A8"
1063
+ });
1064
+ }
1065
+ const timeoutMs = options.timeoutMs ?? 4e3;
1066
+ return new Promise((resolve) => {
1067
+ let settled = false;
1068
+ let blocked = false;
1069
+ let timer;
1070
+ const finish = (result) => {
1071
+ if (settled) return;
1072
+ settled = true;
1073
+ if (timer) clearTimeout(timer);
1074
+ resolve(result);
1075
+ };
1076
+ let request;
1077
+ try {
1078
+ request = idb.deleteDatabase(storeName);
1079
+ } catch (err) {
1080
+ finish({ storeName, deleted: false, blocked: false, error: summarizeError(err).message });
1081
+ return;
1082
+ }
1083
+ request.onsuccess = () => finish({ storeName, deleted: true, blocked: false });
1084
+ request.onerror = () => finish({
1085
+ storeName,
1086
+ deleted: false,
1087
+ blocked: false,
1088
+ error: summarizeError(request.error).message
1089
+ });
1090
+ request.onblocked = () => {
1091
+ blocked = true;
1092
+ };
1093
+ timer = setTimeout(() => {
1094
+ finish({
1095
+ storeName,
1096
+ deleted: false,
1097
+ blocked,
1098
+ error: blocked ? "\u5220\u9664\u88AB\u5176\u5B83\u9875\u9762/\u5B9E\u4F8B\u5360\u7528\uFF08blocked\uFF09\uFF1A\u8BF7\u5173\u95ED\u5176\u5B83\u6253\u5F00\u8BE5\u9875\u9762\u7684\u6807\u7B7E\u9875\u540E\u91CD\u8BD5" : "\u5220\u9664\u8D85\u65F6\uFF1AIndexedDB \u672A\u5728\u9884\u671F\u65F6\u95F4\u5185\u54CD\u5E94"
1099
+ });
1100
+ }, timeoutMs);
1101
+ });
1102
+ }
1103
+
980
1104
  // src/config-repo.ts
981
1105
  var import_localstorage_logger3 = require("@richard432/localstorage-logger");
982
1106
 
@@ -4416,14 +4540,28 @@ var AppDataGroupImpl = class {
4416
4540
  });
4417
4541
  }
4418
4542
  async init() {
4543
+ const storeName = dataGroupLocalStoreName(this.appId, this.groupId);
4419
4544
  try {
4420
4545
  const localPrimary = await resolveLocalPrimary(this.appId, "data", {
4421
4546
  groupId: this.groupId,
4422
- ...this.groupId === "default" ? {} : { idbStoreName: `zen-fs-config-data-${this.appId}-${this.groupId}` }
4547
+ ...this.groupId === "default" ? {} : { idbStoreName: storeName }
4423
4548
  });
4424
4549
  this.localFS = await createBackend(localPrimary);
4425
- } catch {
4426
- throw new Error(`Failed to create local primary for data group "${this.groupId}"`);
4550
+ } catch (err) {
4551
+ if (isLocalStorageUnavailableError(err)) {
4552
+ throw new LocalStorageUnavailableError({
4553
+ appId: this.appId,
4554
+ groupId: this.groupId,
4555
+ storeName,
4556
+ cause: err
4557
+ });
4558
+ }
4559
+ const detail = summarizeError(err);
4560
+ const wrapped = new Error(
4561
+ `Failed to create local primary for data group "${this.groupId}" (${[detail.name, detail.code, detail.message].filter(Boolean).join(": ")})`,
4562
+ { cause: err }
4563
+ );
4564
+ throw wrapped;
4427
4565
  }
4428
4566
  try {
4429
4567
  const purged = await purgeMtimeSidecars(this.localFS);
@@ -5053,10 +5191,11 @@ async function connect(appId, options = {}) {
5053
5191
  log4(`connect: failed to load app data group "${d.id}":`, err);
5054
5192
  }
5055
5193
  }
5056
- let dataGroup2 = appDataGroups2[0];
5057
- if (!dataGroup2) {
5058
- dataGroup2 = await repo2.createAppDataGroup("default", []);
5059
- appDataGroups2.push(dataGroup2);
5194
+ const dataGroup2 = appDataGroups2[0];
5195
+ if (!dataGroup2 && descriptors2.length > 0) {
5196
+ log4(
5197
+ `connect: ${descriptors2.length} data group descriptor(s) found but none could be loaded; leaving them untouched (no empty group is created)`
5198
+ );
5060
5199
  }
5061
5200
  return {
5062
5201
  groupType: options.groupType ?? "config-sync",
@@ -5114,11 +5253,17 @@ async function connect(appId, options = {}) {
5114
5253
  let dataGroup = appDataGroups[0];
5115
5254
  if (groupType === "data-sync") {
5116
5255
  if (!dataGroup) {
5117
- dataGroup = await repo.createAppDataGroup("default", []);
5118
- appDataGroups.push(dataGroup);
5256
+ if (descriptors.length > 0) {
5257
+ log4(
5258
+ `connect: ${descriptors.length} data group descriptor(s) exist but could not be loaded; refusing to create/overwrite "default"`
5259
+ );
5260
+ } else {
5261
+ dataGroup = await repo.createAppDataGroup("default", []);
5262
+ appDataGroups.push(dataGroup);
5263
+ }
5119
5264
  }
5120
5265
  const backendId = `${type}-primary`;
5121
- if (!dataGroup.listBackends().some((b) => b.id === backendId)) {
5266
+ if (dataGroup && !dataGroup.listBackends().some((b) => b.id === backendId)) {
5122
5267
  await dataGroup.addBackend(backendId, type, backendOptions);
5123
5268
  }
5124
5269
  }
@@ -5146,6 +5291,8 @@ init_backend_registry();
5146
5291
  LEGACY_CONFLICTS_DIR,
5147
5292
  LEGACY_TOMBSTONES_DIR,
5148
5293
  LOCAL_IDB_BACKEND_ID,
5294
+ LOCAL_STORAGE_UNAVAILABLE,
5295
+ LocalStorageUnavailableError,
5149
5296
  META_DIR,
5150
5297
  TOMBSTONES_DIR,
5151
5298
  TombstoneStore,
@@ -5156,6 +5303,8 @@ init_backend_registry();
5156
5303
  createBackend,
5157
5304
  createConfigRepo,
5158
5305
  createSerializerChain,
5306
+ dataGroupLocalStoreName,
5307
+ deleteDataGroupLocalStore,
5159
5308
  encodeMetaPath,
5160
5309
  getAccountFields,
5161
5310
  getBackendMetadata,
@@ -5164,6 +5313,7 @@ init_backend_registry();
5164
5313
  incrementVersion,
5165
5314
  isBrowserEnv,
5166
5315
  isKeepFile,
5316
+ isLocalStorageUnavailableError,
5167
5317
  isMtimeSidecar,
5168
5318
  legacyVersionPathFor,
5169
5319
  listBackendMetadata,
package/dist/index.mjs CHANGED
@@ -422,6 +422,125 @@ async function defaultNodeDir(appId, kind, groupId) {
422
422
  return kindDir;
423
423
  }
424
424
 
425
+ // src/errors.ts
426
+ var LOCAL_STORAGE_UNAVAILABLE = "LOCAL_STORAGE_UNAVAILABLE";
427
+ function dataGroupLocalStoreName(appId, groupId) {
428
+ return groupId === "default" ? `zen-fs-config-data-${appId}` : `zen-fs-config-data-${appId}-${groupId}`;
429
+ }
430
+ var LocalStorageUnavailableError = class extends Error {
431
+ code = LOCAL_STORAGE_UNAVAILABLE;
432
+ appId;
433
+ groupId;
434
+ storeName;
435
+ cause;
436
+ constructor(details) {
437
+ super(
438
+ `Local storage for data group "${details.groupId}" is unavailable (IndexedDB "${details.storeName}"): ${describeError(details.cause)}`
439
+ );
440
+ this.name = "LocalStorageUnavailableError";
441
+ this.appId = details.appId;
442
+ this.groupId = details.groupId;
443
+ this.storeName = details.storeName;
444
+ this.cause = details.cause;
445
+ }
446
+ /** 原始异常的可序列化摘要(code / name / message),便于日志与诊断面板展示。 */
447
+ toJSON() {
448
+ return {
449
+ name: this.name,
450
+ code: this.code,
451
+ appId: this.appId,
452
+ groupId: this.groupId,
453
+ storeName: this.storeName,
454
+ message: this.message,
455
+ cause: summarizeError(this.cause)
456
+ };
457
+ }
458
+ };
459
+ function summarizeError(err) {
460
+ if (err instanceof Error || err && typeof err === "object") {
461
+ const anyErr = err;
462
+ return {
463
+ name: anyErr.name,
464
+ code: anyErr.code,
465
+ message: anyErr.message ?? String(err),
466
+ stack: anyErr.stack
467
+ };
468
+ }
469
+ return { message: String(err) };
470
+ }
471
+ function describeError(err) {
472
+ const s = summarizeError(err);
473
+ return [s.name, s.code, s.message].filter(Boolean).join(": ");
474
+ }
475
+ var STORAGE_MESSAGE_HINTS = [
476
+ /Data lost due to missing file/i,
477
+ /should be considered irrecoverable/i,
478
+ /IndexedDB.*(corrupt|unreadable)/i
479
+ ];
480
+ function isLocalStorageUnavailableError(err) {
481
+ let cur = err;
482
+ for (let depth = 0; cur && depth < 6; depth++) {
483
+ if (cur instanceof LocalStorageUnavailableError) return true;
484
+ const anyErr = cur;
485
+ if (anyErr.name === "NotReadableError") return true;
486
+ if (anyErr.code === "EIO") return true;
487
+ const message = typeof anyErr.message === "string" ? anyErr.message : "";
488
+ if (message && STORAGE_MESSAGE_HINTS.some((re) => re.test(message))) return true;
489
+ cur = anyErr.cause;
490
+ }
491
+ return false;
492
+ }
493
+ function deleteDataGroupLocalStore(appId, groupId, options = {}) {
494
+ const storeName = dataGroupLocalStoreName(appId, groupId);
495
+ const idb = globalThis.indexedDB;
496
+ if (!idb || typeof idb.deleteDatabase !== "function") {
497
+ return Promise.resolve({
498
+ storeName,
499
+ deleted: false,
500
+ blocked: false,
501
+ unsupported: true,
502
+ error: "\u5F53\u524D\u73AF\u5883\u6CA1\u6709 IndexedDB\uFF1A\u65E0\u6CD5\u5220\u9664\u672C\u5730\u6570\u636E\u7EC4\u5B58\u50A8"
503
+ });
504
+ }
505
+ const timeoutMs = options.timeoutMs ?? 4e3;
506
+ return new Promise((resolve) => {
507
+ let settled = false;
508
+ let blocked = false;
509
+ let timer;
510
+ const finish = (result) => {
511
+ if (settled) return;
512
+ settled = true;
513
+ if (timer) clearTimeout(timer);
514
+ resolve(result);
515
+ };
516
+ let request;
517
+ try {
518
+ request = idb.deleteDatabase(storeName);
519
+ } catch (err) {
520
+ finish({ storeName, deleted: false, blocked: false, error: summarizeError(err).message });
521
+ return;
522
+ }
523
+ request.onsuccess = () => finish({ storeName, deleted: true, blocked: false });
524
+ request.onerror = () => finish({
525
+ storeName,
526
+ deleted: false,
527
+ blocked: false,
528
+ error: summarizeError(request.error).message
529
+ });
530
+ request.onblocked = () => {
531
+ blocked = true;
532
+ };
533
+ timer = setTimeout(() => {
534
+ finish({
535
+ storeName,
536
+ deleted: false,
537
+ blocked,
538
+ error: blocked ? "\u5220\u9664\u88AB\u5176\u5B83\u9875\u9762/\u5B9E\u4F8B\u5360\u7528\uFF08blocked\uFF09\uFF1A\u8BF7\u5173\u95ED\u5176\u5B83\u6253\u5F00\u8BE5\u9875\u9762\u7684\u6807\u7B7E\u9875\u540E\u91CD\u8BD5" : "\u5220\u9664\u8D85\u65F6\uFF1AIndexedDB \u672A\u5728\u9884\u671F\u65F6\u95F4\u5185\u54CD\u5E94"
539
+ });
540
+ }, timeoutMs);
541
+ });
542
+ }
543
+
425
544
  // src/config-repo.ts
426
545
  import { createLogger as createLogger3 } from "@richard432/localstorage-logger";
427
546
 
@@ -3861,14 +3980,28 @@ var AppDataGroupImpl = class {
3861
3980
  });
3862
3981
  }
3863
3982
  async init() {
3983
+ const storeName = dataGroupLocalStoreName(this.appId, this.groupId);
3864
3984
  try {
3865
3985
  const localPrimary = await resolveLocalPrimary(this.appId, "data", {
3866
3986
  groupId: this.groupId,
3867
- ...this.groupId === "default" ? {} : { idbStoreName: `zen-fs-config-data-${this.appId}-${this.groupId}` }
3987
+ ...this.groupId === "default" ? {} : { idbStoreName: storeName }
3868
3988
  });
3869
3989
  this.localFS = await createBackend(localPrimary);
3870
- } catch {
3871
- throw new Error(`Failed to create local primary for data group "${this.groupId}"`);
3990
+ } catch (err) {
3991
+ if (isLocalStorageUnavailableError(err)) {
3992
+ throw new LocalStorageUnavailableError({
3993
+ appId: this.appId,
3994
+ groupId: this.groupId,
3995
+ storeName,
3996
+ cause: err
3997
+ });
3998
+ }
3999
+ const detail = summarizeError(err);
4000
+ const wrapped = new Error(
4001
+ `Failed to create local primary for data group "${this.groupId}" (${[detail.name, detail.code, detail.message].filter(Boolean).join(": ")})`,
4002
+ { cause: err }
4003
+ );
4004
+ throw wrapped;
3872
4005
  }
3873
4006
  try {
3874
4007
  const purged = await purgeMtimeSidecars(this.localFS);
@@ -4497,10 +4630,11 @@ async function connect(appId, options = {}) {
4497
4630
  log4(`connect: failed to load app data group "${d.id}":`, err);
4498
4631
  }
4499
4632
  }
4500
- let dataGroup2 = appDataGroups2[0];
4501
- if (!dataGroup2) {
4502
- dataGroup2 = await repo2.createAppDataGroup("default", []);
4503
- appDataGroups2.push(dataGroup2);
4633
+ const dataGroup2 = appDataGroups2[0];
4634
+ if (!dataGroup2 && descriptors2.length > 0) {
4635
+ log4(
4636
+ `connect: ${descriptors2.length} data group descriptor(s) found but none could be loaded; leaving them untouched (no empty group is created)`
4637
+ );
4504
4638
  }
4505
4639
  return {
4506
4640
  groupType: options.groupType ?? "config-sync",
@@ -4558,11 +4692,17 @@ async function connect(appId, options = {}) {
4558
4692
  let dataGroup = appDataGroups[0];
4559
4693
  if (groupType === "data-sync") {
4560
4694
  if (!dataGroup) {
4561
- dataGroup = await repo.createAppDataGroup("default", []);
4562
- appDataGroups.push(dataGroup);
4695
+ if (descriptors.length > 0) {
4696
+ log4(
4697
+ `connect: ${descriptors.length} data group descriptor(s) exist but could not be loaded; refusing to create/overwrite "default"`
4698
+ );
4699
+ } else {
4700
+ dataGroup = await repo.createAppDataGroup("default", []);
4701
+ appDataGroups.push(dataGroup);
4702
+ }
4563
4703
  }
4564
4704
  const backendId = `${type}-primary`;
4565
- if (!dataGroup.listBackends().some((b) => b.id === backendId)) {
4705
+ if (dataGroup && !dataGroup.listBackends().some((b) => b.id === backendId)) {
4566
4706
  await dataGroup.addBackend(backendId, type, backendOptions);
4567
4707
  }
4568
4708
  }
@@ -4586,6 +4726,8 @@ export {
4586
4726
  LEGACY_CONFLICTS_DIR,
4587
4727
  LEGACY_TOMBSTONES_DIR,
4588
4728
  LOCAL_IDB_BACKEND_ID,
4729
+ LOCAL_STORAGE_UNAVAILABLE,
4730
+ LocalStorageUnavailableError,
4589
4731
  META_DIR,
4590
4732
  TOMBSTONES_DIR,
4591
4733
  TombstoneStore,
@@ -4596,6 +4738,8 @@ export {
4596
4738
  createBackend,
4597
4739
  createConfigRepo,
4598
4740
  createSerializerChain,
4741
+ dataGroupLocalStoreName,
4742
+ deleteDataGroupLocalStore,
4599
4743
  encodeMetaPath,
4600
4744
  getAccountFields,
4601
4745
  getBackendMetadata,
@@ -4604,6 +4748,7 @@ export {
4604
4748
  incrementVersion,
4605
4749
  isBrowserEnv,
4606
4750
  isKeepFile,
4751
+ isLocalStorageUnavailableError,
4607
4752
  isMtimeSidecar,
4608
4753
  legacyVersionPathFor,
4609
4754
  listBackendMetadata,
@@ -25272,6 +25272,8 @@ var ZenFSConfig = (() => {
25272
25272
  LEGACY_CONFLICTS_DIR: () => LEGACY_CONFLICTS_DIR,
25273
25273
  LEGACY_TOMBSTONES_DIR: () => LEGACY_TOMBSTONES_DIR,
25274
25274
  LOCAL_IDB_BACKEND_ID: () => LOCAL_IDB_BACKEND_ID,
25275
+ LOCAL_STORAGE_UNAVAILABLE: () => LOCAL_STORAGE_UNAVAILABLE,
25276
+ LocalStorageUnavailableError: () => LocalStorageUnavailableError,
25275
25277
  META_DIR: () => META_DIR,
25276
25278
  TOMBSTONES_DIR: () => TOMBSTONES_DIR,
25277
25279
  TombstoneStore: () => TombstoneStore,
@@ -25282,6 +25284,8 @@ var ZenFSConfig = (() => {
25282
25284
  createBackend: () => createBackend,
25283
25285
  createConfigRepo: () => createConfigRepo,
25284
25286
  createSerializerChain: () => createSerializerChain,
25287
+ dataGroupLocalStoreName: () => dataGroupLocalStoreName,
25288
+ deleteDataGroupLocalStore: () => deleteDataGroupLocalStore,
25285
25289
  encodeMetaPath: () => encodeMetaPath,
25286
25290
  getAccountFields: () => getAccountFields,
25287
25291
  getBackendMetadata: () => getBackendMetadata,
@@ -25290,6 +25294,7 @@ var ZenFSConfig = (() => {
25290
25294
  incrementVersion: () => incrementVersion,
25291
25295
  isBrowserEnv: () => isBrowserEnv,
25292
25296
  isKeepFile: () => isKeepFile,
25297
+ isLocalStorageUnavailableError: () => isLocalStorageUnavailableError,
25293
25298
  isMtimeSidecar: () => isMtimeSidecar,
25294
25299
  legacyVersionPathFor: () => legacyVersionPathFor,
25295
25300
  listBackendMetadata: () => listBackendMetadata,
@@ -26950,6 +26955,125 @@ var ZenFSConfig = (() => {
26950
26955
  return kindDir;
26951
26956
  }
26952
26957
 
26958
+ // src/errors.ts
26959
+ var LOCAL_STORAGE_UNAVAILABLE = "LOCAL_STORAGE_UNAVAILABLE";
26960
+ function dataGroupLocalStoreName(appId, groupId) {
26961
+ return groupId === "default" ? `zen-fs-config-data-${appId}` : `zen-fs-config-data-${appId}-${groupId}`;
26962
+ }
26963
+ var LocalStorageUnavailableError = class extends Error {
26964
+ constructor(details) {
26965
+ super(
26966
+ `Local storage for data group "${details.groupId}" is unavailable (IndexedDB "${details.storeName}"): ${describeError(details.cause)}`
26967
+ );
26968
+ __publicField(this, "code", LOCAL_STORAGE_UNAVAILABLE);
26969
+ __publicField(this, "appId");
26970
+ __publicField(this, "groupId");
26971
+ __publicField(this, "storeName");
26972
+ __publicField(this, "cause");
26973
+ this.name = "LocalStorageUnavailableError";
26974
+ this.appId = details.appId;
26975
+ this.groupId = details.groupId;
26976
+ this.storeName = details.storeName;
26977
+ this.cause = details.cause;
26978
+ }
26979
+ /** 原始异常的可序列化摘要(code / name / message),便于日志与诊断面板展示。 */
26980
+ toJSON() {
26981
+ return {
26982
+ name: this.name,
26983
+ code: this.code,
26984
+ appId: this.appId,
26985
+ groupId: this.groupId,
26986
+ storeName: this.storeName,
26987
+ message: this.message,
26988
+ cause: summarizeError(this.cause)
26989
+ };
26990
+ }
26991
+ };
26992
+ function summarizeError(err2) {
26993
+ if (err2 instanceof Error || err2 && typeof err2 === "object") {
26994
+ const anyErr = err2;
26995
+ return {
26996
+ name: anyErr.name,
26997
+ code: anyErr.code,
26998
+ message: anyErr.message ?? String(err2),
26999
+ stack: anyErr.stack
27000
+ };
27001
+ }
27002
+ return { message: String(err2) };
27003
+ }
27004
+ function describeError(err2) {
27005
+ const s = summarizeError(err2);
27006
+ return [s.name, s.code, s.message].filter(Boolean).join(": ");
27007
+ }
27008
+ var STORAGE_MESSAGE_HINTS = [
27009
+ /Data lost due to missing file/i,
27010
+ /should be considered irrecoverable/i,
27011
+ /IndexedDB.*(corrupt|unreadable)/i
27012
+ ];
27013
+ function isLocalStorageUnavailableError(err2) {
27014
+ let cur = err2;
27015
+ for (let depth = 0; cur && depth < 6; depth++) {
27016
+ if (cur instanceof LocalStorageUnavailableError) return true;
27017
+ const anyErr = cur;
27018
+ if (anyErr.name === "NotReadableError") return true;
27019
+ if (anyErr.code === "EIO") return true;
27020
+ const message = typeof anyErr.message === "string" ? anyErr.message : "";
27021
+ if (message && STORAGE_MESSAGE_HINTS.some((re) => re.test(message))) return true;
27022
+ cur = anyErr.cause;
27023
+ }
27024
+ return false;
27025
+ }
27026
+ function deleteDataGroupLocalStore(appId, groupId, options = {}) {
27027
+ const storeName = dataGroupLocalStoreName(appId, groupId);
27028
+ const idb = globalThis.indexedDB;
27029
+ if (!idb || typeof idb.deleteDatabase !== "function") {
27030
+ return Promise.resolve({
27031
+ storeName,
27032
+ deleted: false,
27033
+ blocked: false,
27034
+ unsupported: true,
27035
+ error: "\u5F53\u524D\u73AF\u5883\u6CA1\u6709 IndexedDB\uFF1A\u65E0\u6CD5\u5220\u9664\u672C\u5730\u6570\u636E\u7EC4\u5B58\u50A8"
27036
+ });
27037
+ }
27038
+ const timeoutMs = options.timeoutMs ?? 4e3;
27039
+ return new Promise((resolve4) => {
27040
+ let settled = false;
27041
+ let blocked = false;
27042
+ let timer;
27043
+ const finish = (result) => {
27044
+ if (settled) return;
27045
+ settled = true;
27046
+ if (timer) clearTimeout(timer);
27047
+ resolve4(result);
27048
+ };
27049
+ let request2;
27050
+ try {
27051
+ request2 = idb.deleteDatabase(storeName);
27052
+ } catch (err2) {
27053
+ finish({ storeName, deleted: false, blocked: false, error: summarizeError(err2).message });
27054
+ return;
27055
+ }
27056
+ request2.onsuccess = () => finish({ storeName, deleted: true, blocked: false });
27057
+ request2.onerror = () => finish({
27058
+ storeName,
27059
+ deleted: false,
27060
+ blocked: false,
27061
+ error: summarizeError(request2.error).message
27062
+ });
27063
+ request2.onblocked = () => {
27064
+ blocked = true;
27065
+ };
27066
+ timer = setTimeout(() => {
27067
+ finish({
27068
+ storeName,
27069
+ deleted: false,
27070
+ blocked,
27071
+ error: blocked ? "\u5220\u9664\u88AB\u5176\u5B83\u9875\u9762/\u5B9E\u4F8B\u5360\u7528\uFF08blocked\uFF09\uFF1A\u8BF7\u5173\u95ED\u5176\u5B83\u6253\u5F00\u8BE5\u9875\u9762\u7684\u6807\u7B7E\u9875\u540E\u91CD\u8BD5" : "\u5220\u9664\u8D85\u65F6\uFF1AIndexedDB \u672A\u5728\u9884\u671F\u65F6\u95F4\u5185\u54CD\u5E94"
27072
+ });
27073
+ }, timeoutMs);
27074
+ });
27075
+ }
27076
+
26953
27077
  // src/version.ts
26954
27078
  function versionPathFor(configFilePath) {
26955
27079
  const lastSlash = configFilePath.lastIndexOf("/");
@@ -30375,14 +30499,28 @@ var ZenFSConfig = (() => {
30375
30499
  });
30376
30500
  }
30377
30501
  async init() {
30502
+ const storeName = dataGroupLocalStoreName(this.appId, this.groupId);
30378
30503
  try {
30379
30504
  const localPrimary = await resolveLocalPrimary(this.appId, "data", {
30380
30505
  groupId: this.groupId,
30381
- ...this.groupId === "default" ? {} : { idbStoreName: `zen-fs-config-data-${this.appId}-${this.groupId}` }
30506
+ ...this.groupId === "default" ? {} : { idbStoreName: storeName }
30382
30507
  });
30383
30508
  this.localFS = await createBackend(localPrimary);
30384
- } catch {
30385
- throw new Error(`Failed to create local primary for data group "${this.groupId}"`);
30509
+ } catch (err2) {
30510
+ if (isLocalStorageUnavailableError(err2)) {
30511
+ throw new LocalStorageUnavailableError({
30512
+ appId: this.appId,
30513
+ groupId: this.groupId,
30514
+ storeName,
30515
+ cause: err2
30516
+ });
30517
+ }
30518
+ const detail = summarizeError(err2);
30519
+ const wrapped = new Error(
30520
+ `Failed to create local primary for data group "${this.groupId}" (${[detail.name, detail.code, detail.message].filter(Boolean).join(": ")})`,
30521
+ { cause: err2 }
30522
+ );
30523
+ throw wrapped;
30386
30524
  }
30387
30525
  try {
30388
30526
  const purged = await purgeMtimeSidecars(this.localFS);
@@ -31012,10 +31150,11 @@ var ZenFSConfig = (() => {
31012
31150
  log8(`connect: failed to load app data group "${d.id}":`, err2);
31013
31151
  }
31014
31152
  }
31015
- let dataGroup2 = appDataGroups2[0];
31016
- if (!dataGroup2) {
31017
- dataGroup2 = await repo2.createAppDataGroup("default", []);
31018
- appDataGroups2.push(dataGroup2);
31153
+ const dataGroup2 = appDataGroups2[0];
31154
+ if (!dataGroup2 && descriptors2.length > 0) {
31155
+ log8(
31156
+ `connect: ${descriptors2.length} data group descriptor(s) found but none could be loaded; leaving them untouched (no empty group is created)`
31157
+ );
31019
31158
  }
31020
31159
  return {
31021
31160
  groupType: options.groupType ?? "config-sync",
@@ -31073,11 +31212,17 @@ var ZenFSConfig = (() => {
31073
31212
  let dataGroup = appDataGroups[0];
31074
31213
  if (groupType === "data-sync") {
31075
31214
  if (!dataGroup) {
31076
- dataGroup = await repo.createAppDataGroup("default", []);
31077
- appDataGroups.push(dataGroup);
31215
+ if (descriptors.length > 0) {
31216
+ log8(
31217
+ `connect: ${descriptors.length} data group descriptor(s) exist but could not be loaded; refusing to create/overwrite "default"`
31218
+ );
31219
+ } else {
31220
+ dataGroup = await repo.createAppDataGroup("default", []);
31221
+ appDataGroups.push(dataGroup);
31222
+ }
31078
31223
  }
31079
31224
  const backendId = `${type}-primary`;
31080
- if (!dataGroup.listBackends().some((b) => b.id === backendId)) {
31225
+ if (dataGroup && !dataGroup.listBackends().some((b) => b.id === backendId)) {
31081
31226
  await dataGroup.addBackend(backendId, type, backendOptions);
31082
31227
  }
31083
31228
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-fs-config",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "Distributed config management library built on ZenFS, zen-fs-cache, and zen-fs-sync",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",