zen-fs-config 0.7.13 → 0.7.14
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 +44 -1
- package/dist/index.d.ts +44 -1
- package/dist/index.js +117 -0
- package/dist/index.mjs +114 -0
- package/dist/zen-fs-config.js +114 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1567,6 +1567,49 @@ declare function deleteDataGroupLocalStore(appId: string, groupId: string, optio
|
|
|
1567
1567
|
timeoutMs?: number;
|
|
1568
1568
|
}): Promise<LocalStoreDeletionResult>;
|
|
1569
1569
|
|
|
1570
|
+
/**
|
|
1571
|
+
* zen-fs-config — 本地同步配置清理(“清除本页同步组配置”)。
|
|
1572
|
+
*
|
|
1573
|
+
* 只动**本页**应用的本地状态:
|
|
1574
|
+
* · 配置组的 IndexedDB:`zen-fs-config-config-{appId}`
|
|
1575
|
+
* · 各数据组的 IndexedDB:`zen-fs-config-data-{appId}`(default)与
|
|
1576
|
+
* `zen-fs-config-data-{appId}-{groupId}`
|
|
1577
|
+
* · 调用方显式列出的 localStorage 键(后端信息、重建标记等)
|
|
1578
|
+
*
|
|
1579
|
+
* 远端副本、其它设备与其它标签页的配置都不受影响;删除后本页会以「未连接」
|
|
1580
|
+
* 状态重来一次(重新选后端 / 重新认领远端根)。
|
|
1581
|
+
*/
|
|
1582
|
+
|
|
1583
|
+
interface PurgeLocalSyncConfigOptions {
|
|
1584
|
+
/** 已知的数据组 id;与 `indexedDB.databases()` 的枚举结果合并。 */
|
|
1585
|
+
groupIds?: string[];
|
|
1586
|
+
/** 需要一并删除的 localStorage 键(后端信息、重建标记等)。 */
|
|
1587
|
+
extraStorageKeys?: string[];
|
|
1588
|
+
/** 单个库删除的超时;默认 4000ms。 */
|
|
1589
|
+
timeoutMs?: number;
|
|
1590
|
+
}
|
|
1591
|
+
interface PurgeLocalSyncConfigResult {
|
|
1592
|
+
appId: string;
|
|
1593
|
+
databases: LocalStoreDeletionResult[];
|
|
1594
|
+
removedStorageKeys: string[];
|
|
1595
|
+
/** 当前环境没有 IndexedDB(例如 Node):只清了 storage key。 */
|
|
1596
|
+
unsupported?: boolean;
|
|
1597
|
+
}
|
|
1598
|
+
/**
|
|
1599
|
+
* 删除一个 IndexedDB 库并等到成功 / 失败 / 超时。
|
|
1600
|
+
* 仍被其它连接占用时返回 `blocked: true`(而不是无限挂起)。
|
|
1601
|
+
*/
|
|
1602
|
+
declare function deleteIndexedDbStore(name: string, timeoutMs?: number): Promise<LocalStoreDeletionResult>;
|
|
1603
|
+
/** 本页该应用会创建的全部本地配置库名(用于精确删除,不误伤别的 appId)。 */
|
|
1604
|
+
declare function localSyncStoreNames(appId: string, groupIds?: string[]): string[];
|
|
1605
|
+
/**
|
|
1606
|
+
* 清除本页该应用的同步组配置(IndexedDB 本地副本 + 指定的 storage 键)。
|
|
1607
|
+
*
|
|
1608
|
+
* 典型用法:同步时发现远端根属于类型不匹配 / instanceId 不一致的另一个组,
|
|
1609
|
+
* 用户确认后清掉本页配置,再重新连接一遍。
|
|
1610
|
+
*/
|
|
1611
|
+
declare function purgeLocalSyncConfig(appId: string, options?: PurgeLocalSyncConfigOptions): Promise<PurgeLocalSyncConfigResult>;
|
|
1612
|
+
|
|
1570
1613
|
/**
|
|
1571
1614
|
* zen-fs-config — Unified Connect Entry Point
|
|
1572
1615
|
*
|
|
@@ -1823,4 +1866,4 @@ declare class ConflictStore {
|
|
|
1823
1866
|
resolve(conflictId: string, mergedContent: string | Uint8Array): Promise<void>;
|
|
1824
1867
|
}
|
|
1825
1868
|
|
|
1826
|
-
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 };
|
|
1869
|
+
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 PurgeLocalSyncConfigOptions, type PurgeLocalSyncConfigResult, 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, deleteIndexedDbStore, encodeMetaPath, getAccountFields, getBackendMetadata, getExtension, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalStorageUnavailableError, isMtimeSidecar, legacyVersionPathFor, listBackendMetadata, listBackends, localPrimaryType, localSyncStoreNames, mergeAccountFields, migrateVersionSidecars, purgeKeepFiles, purgeLocalSyncConfig, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, sha256, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };
|
package/dist/index.d.ts
CHANGED
|
@@ -1567,6 +1567,49 @@ declare function deleteDataGroupLocalStore(appId: string, groupId: string, optio
|
|
|
1567
1567
|
timeoutMs?: number;
|
|
1568
1568
|
}): Promise<LocalStoreDeletionResult>;
|
|
1569
1569
|
|
|
1570
|
+
/**
|
|
1571
|
+
* zen-fs-config — 本地同步配置清理(“清除本页同步组配置”)。
|
|
1572
|
+
*
|
|
1573
|
+
* 只动**本页**应用的本地状态:
|
|
1574
|
+
* · 配置组的 IndexedDB:`zen-fs-config-config-{appId}`
|
|
1575
|
+
* · 各数据组的 IndexedDB:`zen-fs-config-data-{appId}`(default)与
|
|
1576
|
+
* `zen-fs-config-data-{appId}-{groupId}`
|
|
1577
|
+
* · 调用方显式列出的 localStorage 键(后端信息、重建标记等)
|
|
1578
|
+
*
|
|
1579
|
+
* 远端副本、其它设备与其它标签页的配置都不受影响;删除后本页会以「未连接」
|
|
1580
|
+
* 状态重来一次(重新选后端 / 重新认领远端根)。
|
|
1581
|
+
*/
|
|
1582
|
+
|
|
1583
|
+
interface PurgeLocalSyncConfigOptions {
|
|
1584
|
+
/** 已知的数据组 id;与 `indexedDB.databases()` 的枚举结果合并。 */
|
|
1585
|
+
groupIds?: string[];
|
|
1586
|
+
/** 需要一并删除的 localStorage 键(后端信息、重建标记等)。 */
|
|
1587
|
+
extraStorageKeys?: string[];
|
|
1588
|
+
/** 单个库删除的超时;默认 4000ms。 */
|
|
1589
|
+
timeoutMs?: number;
|
|
1590
|
+
}
|
|
1591
|
+
interface PurgeLocalSyncConfigResult {
|
|
1592
|
+
appId: string;
|
|
1593
|
+
databases: LocalStoreDeletionResult[];
|
|
1594
|
+
removedStorageKeys: string[];
|
|
1595
|
+
/** 当前环境没有 IndexedDB(例如 Node):只清了 storage key。 */
|
|
1596
|
+
unsupported?: boolean;
|
|
1597
|
+
}
|
|
1598
|
+
/**
|
|
1599
|
+
* 删除一个 IndexedDB 库并等到成功 / 失败 / 超时。
|
|
1600
|
+
* 仍被其它连接占用时返回 `blocked: true`(而不是无限挂起)。
|
|
1601
|
+
*/
|
|
1602
|
+
declare function deleteIndexedDbStore(name: string, timeoutMs?: number): Promise<LocalStoreDeletionResult>;
|
|
1603
|
+
/** 本页该应用会创建的全部本地配置库名(用于精确删除,不误伤别的 appId)。 */
|
|
1604
|
+
declare function localSyncStoreNames(appId: string, groupIds?: string[]): string[];
|
|
1605
|
+
/**
|
|
1606
|
+
* 清除本页该应用的同步组配置(IndexedDB 本地副本 + 指定的 storage 键)。
|
|
1607
|
+
*
|
|
1608
|
+
* 典型用法:同步时发现远端根属于类型不匹配 / instanceId 不一致的另一个组,
|
|
1609
|
+
* 用户确认后清掉本页配置,再重新连接一遍。
|
|
1610
|
+
*/
|
|
1611
|
+
declare function purgeLocalSyncConfig(appId: string, options?: PurgeLocalSyncConfigOptions): Promise<PurgeLocalSyncConfigResult>;
|
|
1612
|
+
|
|
1570
1613
|
/**
|
|
1571
1614
|
* zen-fs-config — Unified Connect Entry Point
|
|
1572
1615
|
*
|
|
@@ -1823,4 +1866,4 @@ declare class ConflictStore {
|
|
|
1823
1866
|
resolve(conflictId: string, mergedContent: string | Uint8Array): Promise<void>;
|
|
1824
1867
|
}
|
|
1825
1868
|
|
|
1826
|
-
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 };
|
|
1869
|
+
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 PurgeLocalSyncConfigOptions, type PurgeLocalSyncConfigResult, 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, deleteIndexedDbStore, encodeMetaPath, getAccountFields, getBackendMetadata, getExtension, hasBackend, incrementVersion, isBrowserEnv, isKeepFile, isLocalStorageUnavailableError, isMtimeSidecar, legacyVersionPathFor, listBackendMetadata, listBackends, localPrimaryType, localSyncStoreNames, mergeAccountFields, migrateVersionSidecars, purgeKeepFiles, purgeLocalSyncConfig, purgeMtimeSidecars, readGroupDescriptor, readVersion, registerBackend, registerFolderBackend, resolveLocalPrimary, sha256, unregisterBackend, verifyOrRepairVersion, versionPathFor, wrapZenFSFileSystem, writeGroupDescriptor, writeVersion };
|
package/dist/index.js
CHANGED
|
@@ -726,6 +726,7 @@ __export(index_exports, {
|
|
|
726
726
|
createSerializerChain: () => createSerializerChain,
|
|
727
727
|
dataGroupLocalStoreName: () => dataGroupLocalStoreName,
|
|
728
728
|
deleteDataGroupLocalStore: () => deleteDataGroupLocalStore,
|
|
729
|
+
deleteIndexedDbStore: () => deleteIndexedDbStore,
|
|
729
730
|
encodeMetaPath: () => encodeMetaPath,
|
|
730
731
|
getAccountFields: () => getAccountFields,
|
|
731
732
|
getBackendMetadata: () => getBackendMetadata,
|
|
@@ -740,9 +741,11 @@ __export(index_exports, {
|
|
|
740
741
|
listBackendMetadata: () => listBackendMetadata,
|
|
741
742
|
listBackends: () => listBackends,
|
|
742
743
|
localPrimaryType: () => localPrimaryType,
|
|
744
|
+
localSyncStoreNames: () => localSyncStoreNames,
|
|
743
745
|
mergeAccountFields: () => mergeAccountFields,
|
|
744
746
|
migrateVersionSidecars: () => migrateVersionSidecars,
|
|
745
747
|
purgeKeepFiles: () => purgeKeepFiles,
|
|
748
|
+
purgeLocalSyncConfig: () => purgeLocalSyncConfig,
|
|
746
749
|
purgeMtimeSidecars: () => purgeMtimeSidecars,
|
|
747
750
|
readGroupDescriptor: () => readGroupDescriptor,
|
|
748
751
|
readVersion: () => readVersion,
|
|
@@ -6004,6 +6007,117 @@ function sidecarOwnerPath(path) {
|
|
|
6004
6007
|
return owner === "" ? null : owner;
|
|
6005
6008
|
}
|
|
6006
6009
|
|
|
6010
|
+
// src/local-purge.ts
|
|
6011
|
+
var CONFIG_STORE_PREFIX = "zen-fs-config-config-";
|
|
6012
|
+
var DATA_STORE_PREFIX = "zen-fs-config-data-";
|
|
6013
|
+
function getIdb() {
|
|
6014
|
+
const idb2 = globalThis.indexedDB;
|
|
6015
|
+
if (!idb2 || typeof idb2.deleteDatabase !== "function") return null;
|
|
6016
|
+
return idb2;
|
|
6017
|
+
}
|
|
6018
|
+
function deleteIndexedDbStore(name, timeoutMs = 4e3) {
|
|
6019
|
+
const idb2 = getIdb();
|
|
6020
|
+
if (!idb2) {
|
|
6021
|
+
return Promise.resolve({
|
|
6022
|
+
storeName: name,
|
|
6023
|
+
deleted: false,
|
|
6024
|
+
blocked: false,
|
|
6025
|
+
unsupported: true,
|
|
6026
|
+
error: "\u5F53\u524D\u73AF\u5883\u6CA1\u6709 IndexedDB\uFF1A\u65E0\u6CD5\u5220\u9664\u672C\u5730\u5E93"
|
|
6027
|
+
});
|
|
6028
|
+
}
|
|
6029
|
+
return new Promise((resolve) => {
|
|
6030
|
+
let settled = false;
|
|
6031
|
+
let blocked = false;
|
|
6032
|
+
let timer;
|
|
6033
|
+
const finish = (result) => {
|
|
6034
|
+
if (settled) return;
|
|
6035
|
+
settled = true;
|
|
6036
|
+
if (timer) clearTimeout(timer);
|
|
6037
|
+
resolve(result);
|
|
6038
|
+
};
|
|
6039
|
+
let request2;
|
|
6040
|
+
try {
|
|
6041
|
+
request2 = idb2.deleteDatabase(name);
|
|
6042
|
+
} catch (err) {
|
|
6043
|
+
finish({ storeName: name, deleted: false, blocked: false, error: summarizeError(err).message });
|
|
6044
|
+
return;
|
|
6045
|
+
}
|
|
6046
|
+
request2.onsuccess = () => finish({ storeName: name, deleted: true, blocked: false });
|
|
6047
|
+
request2.onerror = () => finish({
|
|
6048
|
+
storeName: name,
|
|
6049
|
+
deleted: false,
|
|
6050
|
+
blocked: false,
|
|
6051
|
+
error: summarizeError(request2.error).message
|
|
6052
|
+
});
|
|
6053
|
+
request2.onblocked = () => {
|
|
6054
|
+
blocked = true;
|
|
6055
|
+
};
|
|
6056
|
+
timer = setTimeout(() => {
|
|
6057
|
+
finish({
|
|
6058
|
+
storeName: name,
|
|
6059
|
+
deleted: false,
|
|
6060
|
+
blocked,
|
|
6061
|
+
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"
|
|
6062
|
+
});
|
|
6063
|
+
}, timeoutMs);
|
|
6064
|
+
});
|
|
6065
|
+
}
|
|
6066
|
+
function localSyncStoreNames(appId, groupIds = []) {
|
|
6067
|
+
const names = /* @__PURE__ */ new Set([
|
|
6068
|
+
`${CONFIG_STORE_PREFIX}${appId}`,
|
|
6069
|
+
`${DATA_STORE_PREFIX}${appId}`
|
|
6070
|
+
]);
|
|
6071
|
+
for (const groupId of groupIds) {
|
|
6072
|
+
if (!groupId) continue;
|
|
6073
|
+
names.add(`${DATA_STORE_PREFIX}${appId}-${groupId}`);
|
|
6074
|
+
}
|
|
6075
|
+
return Array.from(names);
|
|
6076
|
+
}
|
|
6077
|
+
async function purgeLocalSyncConfig(appId, options = {}) {
|
|
6078
|
+
const idb2 = getIdb();
|
|
6079
|
+
const names = new Set(localSyncStoreNames(appId, options.groupIds));
|
|
6080
|
+
const removedStorageKeys = [];
|
|
6081
|
+
const removeStorageKeys = () => {
|
|
6082
|
+
try {
|
|
6083
|
+
const ls = globalThis.localStorage;
|
|
6084
|
+
if (!ls) return;
|
|
6085
|
+
for (const key of options.extraStorageKeys ?? []) {
|
|
6086
|
+
try {
|
|
6087
|
+
if (ls.getItem(key) !== null) {
|
|
6088
|
+
ls.removeItem(key);
|
|
6089
|
+
removedStorageKeys.push(key);
|
|
6090
|
+
}
|
|
6091
|
+
} catch {
|
|
6092
|
+
}
|
|
6093
|
+
}
|
|
6094
|
+
} catch {
|
|
6095
|
+
}
|
|
6096
|
+
};
|
|
6097
|
+
if (!idb2) {
|
|
6098
|
+
removeStorageKeys();
|
|
6099
|
+
return { appId, databases: [], removedStorageKeys, unsupported: true };
|
|
6100
|
+
}
|
|
6101
|
+
try {
|
|
6102
|
+
const list = await idb2.databases?.();
|
|
6103
|
+
for (const entry of list ?? []) {
|
|
6104
|
+
const name = entry?.name;
|
|
6105
|
+
if (!name) continue;
|
|
6106
|
+
if (name === `${CONFIG_STORE_PREFIX}${appId}`) names.add(name);
|
|
6107
|
+
if (name === `${DATA_STORE_PREFIX}${appId}` || name.startsWith(`${DATA_STORE_PREFIX}${appId}-`)) {
|
|
6108
|
+
names.add(name);
|
|
6109
|
+
}
|
|
6110
|
+
}
|
|
6111
|
+
} catch {
|
|
6112
|
+
}
|
|
6113
|
+
const databases = [];
|
|
6114
|
+
for (const name of names) {
|
|
6115
|
+
databases.push(await deleteIndexedDbStore(name, options.timeoutMs));
|
|
6116
|
+
}
|
|
6117
|
+
removeStorageKeys();
|
|
6118
|
+
return { appId, databases, removedStorageKeys };
|
|
6119
|
+
}
|
|
6120
|
+
|
|
6007
6121
|
// src/connect.ts
|
|
6008
6122
|
init_backend_registry();
|
|
6009
6123
|
var log6 = createLogger2("connect");
|
|
@@ -6170,6 +6284,7 @@ init_backend_registry();
|
|
|
6170
6284
|
createSerializerChain,
|
|
6171
6285
|
dataGroupLocalStoreName,
|
|
6172
6286
|
deleteDataGroupLocalStore,
|
|
6287
|
+
deleteIndexedDbStore,
|
|
6173
6288
|
encodeMetaPath,
|
|
6174
6289
|
getAccountFields,
|
|
6175
6290
|
getBackendMetadata,
|
|
@@ -6184,9 +6299,11 @@ init_backend_registry();
|
|
|
6184
6299
|
listBackendMetadata,
|
|
6185
6300
|
listBackends,
|
|
6186
6301
|
localPrimaryType,
|
|
6302
|
+
localSyncStoreNames,
|
|
6187
6303
|
mergeAccountFields,
|
|
6188
6304
|
migrateVersionSidecars,
|
|
6189
6305
|
purgeKeepFiles,
|
|
6306
|
+
purgeLocalSyncConfig,
|
|
6190
6307
|
purgeMtimeSidecars,
|
|
6191
6308
|
readGroupDescriptor,
|
|
6192
6309
|
readVersion,
|
package/dist/index.mjs
CHANGED
|
@@ -5255,6 +5255,117 @@ function sidecarOwnerPath(path) {
|
|
|
5255
5255
|
return owner === "" ? null : owner;
|
|
5256
5256
|
}
|
|
5257
5257
|
|
|
5258
|
+
// src/local-purge.ts
|
|
5259
|
+
var CONFIG_STORE_PREFIX = "zen-fs-config-config-";
|
|
5260
|
+
var DATA_STORE_PREFIX = "zen-fs-config-data-";
|
|
5261
|
+
function getIdb() {
|
|
5262
|
+
const idb = globalThis.indexedDB;
|
|
5263
|
+
if (!idb || typeof idb.deleteDatabase !== "function") return null;
|
|
5264
|
+
return idb;
|
|
5265
|
+
}
|
|
5266
|
+
function deleteIndexedDbStore(name, timeoutMs = 4e3) {
|
|
5267
|
+
const idb = getIdb();
|
|
5268
|
+
if (!idb) {
|
|
5269
|
+
return Promise.resolve({
|
|
5270
|
+
storeName: name,
|
|
5271
|
+
deleted: false,
|
|
5272
|
+
blocked: false,
|
|
5273
|
+
unsupported: true,
|
|
5274
|
+
error: "\u5F53\u524D\u73AF\u5883\u6CA1\u6709 IndexedDB\uFF1A\u65E0\u6CD5\u5220\u9664\u672C\u5730\u5E93"
|
|
5275
|
+
});
|
|
5276
|
+
}
|
|
5277
|
+
return new Promise((resolve) => {
|
|
5278
|
+
let settled = false;
|
|
5279
|
+
let blocked = false;
|
|
5280
|
+
let timer;
|
|
5281
|
+
const finish = (result) => {
|
|
5282
|
+
if (settled) return;
|
|
5283
|
+
settled = true;
|
|
5284
|
+
if (timer) clearTimeout(timer);
|
|
5285
|
+
resolve(result);
|
|
5286
|
+
};
|
|
5287
|
+
let request;
|
|
5288
|
+
try {
|
|
5289
|
+
request = idb.deleteDatabase(name);
|
|
5290
|
+
} catch (err) {
|
|
5291
|
+
finish({ storeName: name, deleted: false, blocked: false, error: summarizeError(err).message });
|
|
5292
|
+
return;
|
|
5293
|
+
}
|
|
5294
|
+
request.onsuccess = () => finish({ storeName: name, deleted: true, blocked: false });
|
|
5295
|
+
request.onerror = () => finish({
|
|
5296
|
+
storeName: name,
|
|
5297
|
+
deleted: false,
|
|
5298
|
+
blocked: false,
|
|
5299
|
+
error: summarizeError(request.error).message
|
|
5300
|
+
});
|
|
5301
|
+
request.onblocked = () => {
|
|
5302
|
+
blocked = true;
|
|
5303
|
+
};
|
|
5304
|
+
timer = setTimeout(() => {
|
|
5305
|
+
finish({
|
|
5306
|
+
storeName: name,
|
|
5307
|
+
deleted: false,
|
|
5308
|
+
blocked,
|
|
5309
|
+
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"
|
|
5310
|
+
});
|
|
5311
|
+
}, timeoutMs);
|
|
5312
|
+
});
|
|
5313
|
+
}
|
|
5314
|
+
function localSyncStoreNames(appId, groupIds = []) {
|
|
5315
|
+
const names = /* @__PURE__ */ new Set([
|
|
5316
|
+
`${CONFIG_STORE_PREFIX}${appId}`,
|
|
5317
|
+
`${DATA_STORE_PREFIX}${appId}`
|
|
5318
|
+
]);
|
|
5319
|
+
for (const groupId of groupIds) {
|
|
5320
|
+
if (!groupId) continue;
|
|
5321
|
+
names.add(`${DATA_STORE_PREFIX}${appId}-${groupId}`);
|
|
5322
|
+
}
|
|
5323
|
+
return Array.from(names);
|
|
5324
|
+
}
|
|
5325
|
+
async function purgeLocalSyncConfig(appId, options = {}) {
|
|
5326
|
+
const idb = getIdb();
|
|
5327
|
+
const names = new Set(localSyncStoreNames(appId, options.groupIds));
|
|
5328
|
+
const removedStorageKeys = [];
|
|
5329
|
+
const removeStorageKeys = () => {
|
|
5330
|
+
try {
|
|
5331
|
+
const ls = globalThis.localStorage;
|
|
5332
|
+
if (!ls) return;
|
|
5333
|
+
for (const key of options.extraStorageKeys ?? []) {
|
|
5334
|
+
try {
|
|
5335
|
+
if (ls.getItem(key) !== null) {
|
|
5336
|
+
ls.removeItem(key);
|
|
5337
|
+
removedStorageKeys.push(key);
|
|
5338
|
+
}
|
|
5339
|
+
} catch {
|
|
5340
|
+
}
|
|
5341
|
+
}
|
|
5342
|
+
} catch {
|
|
5343
|
+
}
|
|
5344
|
+
};
|
|
5345
|
+
if (!idb) {
|
|
5346
|
+
removeStorageKeys();
|
|
5347
|
+
return { appId, databases: [], removedStorageKeys, unsupported: true };
|
|
5348
|
+
}
|
|
5349
|
+
try {
|
|
5350
|
+
const list = await idb.databases?.();
|
|
5351
|
+
for (const entry of list ?? []) {
|
|
5352
|
+
const name = entry?.name;
|
|
5353
|
+
if (!name) continue;
|
|
5354
|
+
if (name === `${CONFIG_STORE_PREFIX}${appId}`) names.add(name);
|
|
5355
|
+
if (name === `${DATA_STORE_PREFIX}${appId}` || name.startsWith(`${DATA_STORE_PREFIX}${appId}-`)) {
|
|
5356
|
+
names.add(name);
|
|
5357
|
+
}
|
|
5358
|
+
}
|
|
5359
|
+
} catch {
|
|
5360
|
+
}
|
|
5361
|
+
const databases = [];
|
|
5362
|
+
for (const name of names) {
|
|
5363
|
+
databases.push(await deleteIndexedDbStore(name, options.timeoutMs));
|
|
5364
|
+
}
|
|
5365
|
+
removeStorageKeys();
|
|
5366
|
+
return { appId, databases, removedStorageKeys };
|
|
5367
|
+
}
|
|
5368
|
+
|
|
5258
5369
|
// src/connect.ts
|
|
5259
5370
|
var log6 = createLogger2("connect");
|
|
5260
5371
|
var GROUP_TYPE_FILE2 = "/.config/group-type";
|
|
@@ -5416,6 +5527,7 @@ export {
|
|
|
5416
5527
|
createSerializerChain,
|
|
5417
5528
|
dataGroupLocalStoreName,
|
|
5418
5529
|
deleteDataGroupLocalStore,
|
|
5530
|
+
deleteIndexedDbStore,
|
|
5419
5531
|
encodeMetaPath,
|
|
5420
5532
|
getAccountFields,
|
|
5421
5533
|
getBackendMetadata,
|
|
@@ -5430,9 +5542,11 @@ export {
|
|
|
5430
5542
|
listBackendMetadata,
|
|
5431
5543
|
listBackends,
|
|
5432
5544
|
localPrimaryType,
|
|
5545
|
+
localSyncStoreNames,
|
|
5433
5546
|
mergeAccountFields,
|
|
5434
5547
|
migrateVersionSidecars,
|
|
5435
5548
|
purgeKeepFiles,
|
|
5549
|
+
purgeLocalSyncConfig,
|
|
5436
5550
|
purgeMtimeSidecars,
|
|
5437
5551
|
readGroupDescriptor,
|
|
5438
5552
|
readVersion,
|
package/dist/zen-fs-config.js
CHANGED
|
@@ -25475,6 +25475,7 @@ var ZenFSConfig = (() => {
|
|
|
25475
25475
|
createSerializerChain: () => createSerializerChain,
|
|
25476
25476
|
dataGroupLocalStoreName: () => dataGroupLocalStoreName,
|
|
25477
25477
|
deleteDataGroupLocalStore: () => deleteDataGroupLocalStore,
|
|
25478
|
+
deleteIndexedDbStore: () => deleteIndexedDbStore,
|
|
25478
25479
|
encodeMetaPath: () => encodeMetaPath,
|
|
25479
25480
|
getAccountFields: () => getAccountFields,
|
|
25480
25481
|
getBackendMetadata: () => getBackendMetadata,
|
|
@@ -25489,9 +25490,11 @@ var ZenFSConfig = (() => {
|
|
|
25489
25490
|
listBackendMetadata: () => listBackendMetadata,
|
|
25490
25491
|
listBackends: () => listBackends,
|
|
25491
25492
|
localPrimaryType: () => localPrimaryType,
|
|
25493
|
+
localSyncStoreNames: () => localSyncStoreNames,
|
|
25492
25494
|
mergeAccountFields: () => mergeAccountFields,
|
|
25493
25495
|
migrateVersionSidecars: () => migrateVersionSidecars,
|
|
25494
25496
|
purgeKeepFiles: () => purgeKeepFiles,
|
|
25497
|
+
purgeLocalSyncConfig: () => purgeLocalSyncConfig,
|
|
25495
25498
|
purgeMtimeSidecars: () => purgeMtimeSidecars,
|
|
25496
25499
|
readGroupDescriptor: () => readGroupDescriptor,
|
|
25497
25500
|
readVersion: () => readVersion,
|
|
@@ -31961,6 +31964,117 @@ var ZenFSConfig = (() => {
|
|
|
31961
31964
|
return owner === "" ? null : owner;
|
|
31962
31965
|
}
|
|
31963
31966
|
|
|
31967
|
+
// src/local-purge.ts
|
|
31968
|
+
var CONFIG_STORE_PREFIX = "zen-fs-config-config-";
|
|
31969
|
+
var DATA_STORE_PREFIX = "zen-fs-config-data-";
|
|
31970
|
+
function getIdb() {
|
|
31971
|
+
const idb2 = globalThis.indexedDB;
|
|
31972
|
+
if (!idb2 || typeof idb2.deleteDatabase !== "function") return null;
|
|
31973
|
+
return idb2;
|
|
31974
|
+
}
|
|
31975
|
+
function deleteIndexedDbStore(name, timeoutMs = 4e3) {
|
|
31976
|
+
const idb2 = getIdb();
|
|
31977
|
+
if (!idb2) {
|
|
31978
|
+
return Promise.resolve({
|
|
31979
|
+
storeName: name,
|
|
31980
|
+
deleted: false,
|
|
31981
|
+
blocked: false,
|
|
31982
|
+
unsupported: true,
|
|
31983
|
+
error: "\u5F53\u524D\u73AF\u5883\u6CA1\u6709 IndexedDB\uFF1A\u65E0\u6CD5\u5220\u9664\u672C\u5730\u5E93"
|
|
31984
|
+
});
|
|
31985
|
+
}
|
|
31986
|
+
return new Promise((resolve4) => {
|
|
31987
|
+
let settled = false;
|
|
31988
|
+
let blocked = false;
|
|
31989
|
+
let timer;
|
|
31990
|
+
const finish = (result) => {
|
|
31991
|
+
if (settled) return;
|
|
31992
|
+
settled = true;
|
|
31993
|
+
if (timer) clearTimeout(timer);
|
|
31994
|
+
resolve4(result);
|
|
31995
|
+
};
|
|
31996
|
+
let request3;
|
|
31997
|
+
try {
|
|
31998
|
+
request3 = idb2.deleteDatabase(name);
|
|
31999
|
+
} catch (err2) {
|
|
32000
|
+
finish({ storeName: name, deleted: false, blocked: false, error: summarizeError(err2).message });
|
|
32001
|
+
return;
|
|
32002
|
+
}
|
|
32003
|
+
request3.onsuccess = () => finish({ storeName: name, deleted: true, blocked: false });
|
|
32004
|
+
request3.onerror = () => finish({
|
|
32005
|
+
storeName: name,
|
|
32006
|
+
deleted: false,
|
|
32007
|
+
blocked: false,
|
|
32008
|
+
error: summarizeError(request3.error).message
|
|
32009
|
+
});
|
|
32010
|
+
request3.onblocked = () => {
|
|
32011
|
+
blocked = true;
|
|
32012
|
+
};
|
|
32013
|
+
timer = setTimeout(() => {
|
|
32014
|
+
finish({
|
|
32015
|
+
storeName: name,
|
|
32016
|
+
deleted: false,
|
|
32017
|
+
blocked,
|
|
32018
|
+
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"
|
|
32019
|
+
});
|
|
32020
|
+
}, timeoutMs);
|
|
32021
|
+
});
|
|
32022
|
+
}
|
|
32023
|
+
function localSyncStoreNames(appId, groupIds = []) {
|
|
32024
|
+
const names = /* @__PURE__ */ new Set([
|
|
32025
|
+
`${CONFIG_STORE_PREFIX}${appId}`,
|
|
32026
|
+
`${DATA_STORE_PREFIX}${appId}`
|
|
32027
|
+
]);
|
|
32028
|
+
for (const groupId of groupIds) {
|
|
32029
|
+
if (!groupId) continue;
|
|
32030
|
+
names.add(`${DATA_STORE_PREFIX}${appId}-${groupId}`);
|
|
32031
|
+
}
|
|
32032
|
+
return Array.from(names);
|
|
32033
|
+
}
|
|
32034
|
+
async function purgeLocalSyncConfig(appId, options = {}) {
|
|
32035
|
+
const idb2 = getIdb();
|
|
32036
|
+
const names = new Set(localSyncStoreNames(appId, options.groupIds));
|
|
32037
|
+
const removedStorageKeys = [];
|
|
32038
|
+
const removeStorageKeys = () => {
|
|
32039
|
+
try {
|
|
32040
|
+
const ls = globalThis.localStorage;
|
|
32041
|
+
if (!ls) return;
|
|
32042
|
+
for (const key of options.extraStorageKeys ?? []) {
|
|
32043
|
+
try {
|
|
32044
|
+
if (ls.getItem(key) !== null) {
|
|
32045
|
+
ls.removeItem(key);
|
|
32046
|
+
removedStorageKeys.push(key);
|
|
32047
|
+
}
|
|
32048
|
+
} catch {
|
|
32049
|
+
}
|
|
32050
|
+
}
|
|
32051
|
+
} catch {
|
|
32052
|
+
}
|
|
32053
|
+
};
|
|
32054
|
+
if (!idb2) {
|
|
32055
|
+
removeStorageKeys();
|
|
32056
|
+
return { appId, databases: [], removedStorageKeys, unsupported: true };
|
|
32057
|
+
}
|
|
32058
|
+
try {
|
|
32059
|
+
const list2 = await idb2.databases?.();
|
|
32060
|
+
for (const entry of list2 ?? []) {
|
|
32061
|
+
const name = entry?.name;
|
|
32062
|
+
if (!name) continue;
|
|
32063
|
+
if (name === `${CONFIG_STORE_PREFIX}${appId}`) names.add(name);
|
|
32064
|
+
if (name === `${DATA_STORE_PREFIX}${appId}` || name.startsWith(`${DATA_STORE_PREFIX}${appId}-`)) {
|
|
32065
|
+
names.add(name);
|
|
32066
|
+
}
|
|
32067
|
+
}
|
|
32068
|
+
} catch {
|
|
32069
|
+
}
|
|
32070
|
+
const databases = [];
|
|
32071
|
+
for (const name of names) {
|
|
32072
|
+
databases.push(await deleteIndexedDbStore(name, options.timeoutMs));
|
|
32073
|
+
}
|
|
32074
|
+
removeStorageKeys();
|
|
32075
|
+
return { appId, databases, removedStorageKeys };
|
|
32076
|
+
}
|
|
32077
|
+
|
|
31964
32078
|
// src/connect.ts
|
|
31965
32079
|
init_backend_registry();
|
|
31966
32080
|
var log10 = createLogger3("connect");
|