zen-fs-config 0.7.12 → 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 +144 -11
- package/dist/index.mjs +141 -11
- package/dist/zen-fs-config.js +141 -11
- 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,
|
|
@@ -855,6 +858,13 @@ function makeEperm(userPath) {
|
|
|
855
858
|
err.code = "EPERM";
|
|
856
859
|
return err;
|
|
857
860
|
}
|
|
861
|
+
function makeEconfirm(userPath) {
|
|
862
|
+
const err = new Error(
|
|
863
|
+
`ECONFIRM: '${userPath}' changes sync metadata \u2014 retry with { confirm: true } after warning the user`
|
|
864
|
+
);
|
|
865
|
+
err.code = "ECONFIRM";
|
|
866
|
+
return err;
|
|
867
|
+
}
|
|
858
868
|
function createChrootFS(inner, root, options = {}) {
|
|
859
869
|
const normalizedRoot = root.replace(/\\/g, "/").replace(/\/+$/, "") || "/";
|
|
860
870
|
const hiddenPrefixes = (options.hiddenPrefixes ?? []).map(
|
|
@@ -863,6 +873,9 @@ function createChrootFS(inner, root, options = {}) {
|
|
|
863
873
|
const readOnlyPrefixes = (options.readOnlyPrefixes ?? []).map(
|
|
864
874
|
(p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
|
|
865
875
|
);
|
|
876
|
+
const confirmPrefixes = (options.confirmPrefixes ?? []).map(
|
|
877
|
+
(p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
|
|
878
|
+
);
|
|
866
879
|
function rp(path) {
|
|
867
880
|
return resolveChroot(normalizedRoot, path);
|
|
868
881
|
}
|
|
@@ -881,9 +894,15 @@ function createChrootFS(inner, root, options = {}) {
|
|
|
881
894
|
(prefix) => absolutePath === prefix || absolutePath.startsWith(`${prefix}/`)
|
|
882
895
|
);
|
|
883
896
|
}
|
|
884
|
-
function
|
|
897
|
+
function needsConfirm(absolutePath) {
|
|
898
|
+
return confirmPrefixes.some(
|
|
899
|
+
(prefix) => absolutePath === prefix || absolutePath.startsWith(`${prefix}/`)
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
function writable(path, writeOptions) {
|
|
885
903
|
const absolute = visible(path);
|
|
886
904
|
if (isReadOnly(absolute)) throw makeEperm(path);
|
|
905
|
+
if (needsConfirm(absolute) && writeOptions?.confirm !== true) throw makeEconfirm(path);
|
|
887
906
|
return absolute;
|
|
888
907
|
}
|
|
889
908
|
const promises = {
|
|
@@ -891,7 +910,7 @@ function createChrootFS(inner, root, options = {}) {
|
|
|
891
910
|
return inner.readFile(visible(path), encoding);
|
|
892
911
|
},
|
|
893
912
|
async writeFile(path, data, writeOptions) {
|
|
894
|
-
const target = writable(path);
|
|
913
|
+
const target = writable(path, writeOptions);
|
|
895
914
|
await ensureParentDir(target);
|
|
896
915
|
await inner.writeFile(target, data, writeOptions);
|
|
897
916
|
if (options.onWrite) await options.onWrite(path, data);
|
|
@@ -918,21 +937,21 @@ function createChrootFS(inner, root, options = {}) {
|
|
|
918
937
|
if (!exists) throw makeEnoent(path);
|
|
919
938
|
},
|
|
920
939
|
async mkdir(path, mkdirOptions) {
|
|
921
|
-
return inner.mkdir(writable(path), mkdirOptions);
|
|
940
|
+
return inner.mkdir(writable(path, mkdirOptions), mkdirOptions);
|
|
922
941
|
},
|
|
923
|
-
async unlink(path) {
|
|
924
|
-
const target = writable(path);
|
|
942
|
+
async unlink(path, unlinkOptions) {
|
|
943
|
+
const target = writable(path, unlinkOptions);
|
|
925
944
|
if (options.onUnlink) return options.onUnlink(target);
|
|
926
945
|
return inner.unlink(target);
|
|
927
946
|
},
|
|
928
|
-
async rmdir(path) {
|
|
929
|
-
const target = writable(path);
|
|
947
|
+
async rmdir(path, rmdirOptions) {
|
|
948
|
+
const target = writable(path, rmdirOptions);
|
|
930
949
|
const hook = options.onRmdir ?? options.onUnlink;
|
|
931
950
|
if (hook) return hook(target);
|
|
932
951
|
return inner.rmdir?.(target);
|
|
933
952
|
},
|
|
934
|
-
async rename(oldPath, newPath) {
|
|
935
|
-
return inner.rename?.(writable(oldPath), writable(newPath));
|
|
953
|
+
async rename(oldPath, newPath, renameOptions) {
|
|
954
|
+
return inner.rename?.(writable(oldPath, renameOptions), writable(newPath, renameOptions));
|
|
936
955
|
},
|
|
937
956
|
async exists(path) {
|
|
938
957
|
if (isHidden(rp(path))) return false;
|
|
@@ -5397,9 +5416,9 @@ var AppDataGroupImpl = class {
|
|
|
5397
5416
|
LEGACY_TOMBSTONES_DIR,
|
|
5398
5417
|
VERSIONS_DIR,
|
|
5399
5418
|
CONFLICTS_DIR,
|
|
5400
|
-
LEGACY_CONFLICTS_DIR
|
|
5401
|
-
GROUP_DESCRIPTOR_FILE3
|
|
5419
|
+
LEGACY_CONFLICTS_DIR
|
|
5402
5420
|
],
|
|
5421
|
+
confirmPrefixes: [GROUP_DESCRIPTOR_FILE3],
|
|
5403
5422
|
onWrite: async (path, data) => {
|
|
5404
5423
|
if (path.startsWith(`${META_DIR}/`) || path === META_DIR) return;
|
|
5405
5424
|
await this.clearTombstonesForWrite(path);
|
|
@@ -5988,6 +6007,117 @@ function sidecarOwnerPath(path) {
|
|
|
5988
6007
|
return owner === "" ? null : owner;
|
|
5989
6008
|
}
|
|
5990
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
|
+
|
|
5991
6121
|
// src/connect.ts
|
|
5992
6122
|
init_backend_registry();
|
|
5993
6123
|
var log6 = createLogger2("connect");
|
|
@@ -6154,6 +6284,7 @@ init_backend_registry();
|
|
|
6154
6284
|
createSerializerChain,
|
|
6155
6285
|
dataGroupLocalStoreName,
|
|
6156
6286
|
deleteDataGroupLocalStore,
|
|
6287
|
+
deleteIndexedDbStore,
|
|
6157
6288
|
encodeMetaPath,
|
|
6158
6289
|
getAccountFields,
|
|
6159
6290
|
getBackendMetadata,
|
|
@@ -6168,9 +6299,11 @@ init_backend_registry();
|
|
|
6168
6299
|
listBackendMetadata,
|
|
6169
6300
|
listBackends,
|
|
6170
6301
|
localPrimaryType,
|
|
6302
|
+
localSyncStoreNames,
|
|
6171
6303
|
mergeAccountFields,
|
|
6172
6304
|
migrateVersionSidecars,
|
|
6173
6305
|
purgeKeepFiles,
|
|
6306
|
+
purgeLocalSyncConfig,
|
|
6174
6307
|
purgeMtimeSidecars,
|
|
6175
6308
|
readGroupDescriptor,
|
|
6176
6309
|
readVersion,
|
package/dist/index.mjs
CHANGED
|
@@ -110,6 +110,13 @@ function makeEperm(userPath) {
|
|
|
110
110
|
err.code = "EPERM";
|
|
111
111
|
return err;
|
|
112
112
|
}
|
|
113
|
+
function makeEconfirm(userPath) {
|
|
114
|
+
const err = new Error(
|
|
115
|
+
`ECONFIRM: '${userPath}' changes sync metadata \u2014 retry with { confirm: true } after warning the user`
|
|
116
|
+
);
|
|
117
|
+
err.code = "ECONFIRM";
|
|
118
|
+
return err;
|
|
119
|
+
}
|
|
113
120
|
function createChrootFS(inner, root, options = {}) {
|
|
114
121
|
const normalizedRoot = root.replace(/\\/g, "/").replace(/\/+$/, "") || "/";
|
|
115
122
|
const hiddenPrefixes = (options.hiddenPrefixes ?? []).map(
|
|
@@ -118,6 +125,9 @@ function createChrootFS(inner, root, options = {}) {
|
|
|
118
125
|
const readOnlyPrefixes = (options.readOnlyPrefixes ?? []).map(
|
|
119
126
|
(p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
|
|
120
127
|
);
|
|
128
|
+
const confirmPrefixes = (options.confirmPrefixes ?? []).map(
|
|
129
|
+
(p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
|
|
130
|
+
);
|
|
121
131
|
function rp(path) {
|
|
122
132
|
return resolveChroot(normalizedRoot, path);
|
|
123
133
|
}
|
|
@@ -136,9 +146,15 @@ function createChrootFS(inner, root, options = {}) {
|
|
|
136
146
|
(prefix) => absolutePath === prefix || absolutePath.startsWith(`${prefix}/`)
|
|
137
147
|
);
|
|
138
148
|
}
|
|
139
|
-
function
|
|
149
|
+
function needsConfirm(absolutePath) {
|
|
150
|
+
return confirmPrefixes.some(
|
|
151
|
+
(prefix) => absolutePath === prefix || absolutePath.startsWith(`${prefix}/`)
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
function writable(path, writeOptions) {
|
|
140
155
|
const absolute = visible(path);
|
|
141
156
|
if (isReadOnly(absolute)) throw makeEperm(path);
|
|
157
|
+
if (needsConfirm(absolute) && writeOptions?.confirm !== true) throw makeEconfirm(path);
|
|
142
158
|
return absolute;
|
|
143
159
|
}
|
|
144
160
|
const promises = {
|
|
@@ -146,7 +162,7 @@ function createChrootFS(inner, root, options = {}) {
|
|
|
146
162
|
return inner.readFile(visible(path), encoding);
|
|
147
163
|
},
|
|
148
164
|
async writeFile(path, data, writeOptions) {
|
|
149
|
-
const target = writable(path);
|
|
165
|
+
const target = writable(path, writeOptions);
|
|
150
166
|
await ensureParentDir(target);
|
|
151
167
|
await inner.writeFile(target, data, writeOptions);
|
|
152
168
|
if (options.onWrite) await options.onWrite(path, data);
|
|
@@ -173,21 +189,21 @@ function createChrootFS(inner, root, options = {}) {
|
|
|
173
189
|
if (!exists) throw makeEnoent(path);
|
|
174
190
|
},
|
|
175
191
|
async mkdir(path, mkdirOptions) {
|
|
176
|
-
return inner.mkdir(writable(path), mkdirOptions);
|
|
192
|
+
return inner.mkdir(writable(path, mkdirOptions), mkdirOptions);
|
|
177
193
|
},
|
|
178
|
-
async unlink(path) {
|
|
179
|
-
const target = writable(path);
|
|
194
|
+
async unlink(path, unlinkOptions) {
|
|
195
|
+
const target = writable(path, unlinkOptions);
|
|
180
196
|
if (options.onUnlink) return options.onUnlink(target);
|
|
181
197
|
return inner.unlink(target);
|
|
182
198
|
},
|
|
183
|
-
async rmdir(path) {
|
|
184
|
-
const target = writable(path);
|
|
199
|
+
async rmdir(path, rmdirOptions) {
|
|
200
|
+
const target = writable(path, rmdirOptions);
|
|
185
201
|
const hook = options.onRmdir ?? options.onUnlink;
|
|
186
202
|
if (hook) return hook(target);
|
|
187
203
|
return inner.rmdir?.(target);
|
|
188
204
|
},
|
|
189
|
-
async rename(oldPath, newPath) {
|
|
190
|
-
return inner.rename?.(writable(oldPath), writable(newPath));
|
|
205
|
+
async rename(oldPath, newPath, renameOptions) {
|
|
206
|
+
return inner.rename?.(writable(oldPath, renameOptions), writable(newPath, renameOptions));
|
|
191
207
|
},
|
|
192
208
|
async exists(path) {
|
|
193
209
|
if (isHidden(rp(path))) return false;
|
|
@@ -4648,9 +4664,9 @@ var AppDataGroupImpl = class {
|
|
|
4648
4664
|
LEGACY_TOMBSTONES_DIR,
|
|
4649
4665
|
VERSIONS_DIR,
|
|
4650
4666
|
CONFLICTS_DIR,
|
|
4651
|
-
LEGACY_CONFLICTS_DIR
|
|
4652
|
-
GROUP_DESCRIPTOR_FILE3
|
|
4667
|
+
LEGACY_CONFLICTS_DIR
|
|
4653
4668
|
],
|
|
4669
|
+
confirmPrefixes: [GROUP_DESCRIPTOR_FILE3],
|
|
4654
4670
|
onWrite: async (path, data) => {
|
|
4655
4671
|
if (path.startsWith(`${META_DIR}/`) || path === META_DIR) return;
|
|
4656
4672
|
await this.clearTombstonesForWrite(path);
|
|
@@ -5239,6 +5255,117 @@ function sidecarOwnerPath(path) {
|
|
|
5239
5255
|
return owner === "" ? null : owner;
|
|
5240
5256
|
}
|
|
5241
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
|
+
|
|
5242
5369
|
// src/connect.ts
|
|
5243
5370
|
var log6 = createLogger2("connect");
|
|
5244
5371
|
var GROUP_TYPE_FILE2 = "/.config/group-type";
|
|
@@ -5400,6 +5527,7 @@ export {
|
|
|
5400
5527
|
createSerializerChain,
|
|
5401
5528
|
dataGroupLocalStoreName,
|
|
5402
5529
|
deleteDataGroupLocalStore,
|
|
5530
|
+
deleteIndexedDbStore,
|
|
5403
5531
|
encodeMetaPath,
|
|
5404
5532
|
getAccountFields,
|
|
5405
5533
|
getBackendMetadata,
|
|
@@ -5414,9 +5542,11 @@ export {
|
|
|
5414
5542
|
listBackendMetadata,
|
|
5415
5543
|
listBackends,
|
|
5416
5544
|
localPrimaryType,
|
|
5545
|
+
localSyncStoreNames,
|
|
5417
5546
|
mergeAccountFields,
|
|
5418
5547
|
migrateVersionSidecars,
|
|
5419
5548
|
purgeKeepFiles,
|
|
5549
|
+
purgeLocalSyncConfig,
|
|
5420
5550
|
purgeMtimeSidecars,
|
|
5421
5551
|
readGroupDescriptor,
|
|
5422
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,
|
|
@@ -26829,6 +26832,13 @@ var ZenFSConfig = (() => {
|
|
|
26829
26832
|
err2.code = "EPERM";
|
|
26830
26833
|
return err2;
|
|
26831
26834
|
}
|
|
26835
|
+
function makeEconfirm(userPath) {
|
|
26836
|
+
const err2 = new Error(
|
|
26837
|
+
`ECONFIRM: '${userPath}' changes sync metadata \u2014 retry with { confirm: true } after warning the user`
|
|
26838
|
+
);
|
|
26839
|
+
err2.code = "ECONFIRM";
|
|
26840
|
+
return err2;
|
|
26841
|
+
}
|
|
26832
26842
|
function createChrootFS(inner, root, options = {}) {
|
|
26833
26843
|
const normalizedRoot = root.replace(/\\/g, "/").replace(/\/+$/, "") || "/";
|
|
26834
26844
|
const hiddenPrefixes = (options.hiddenPrefixes ?? []).map(
|
|
@@ -26837,6 +26847,9 @@ var ZenFSConfig = (() => {
|
|
|
26837
26847
|
const readOnlyPrefixes = (options.readOnlyPrefixes ?? []).map(
|
|
26838
26848
|
(p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
|
|
26839
26849
|
);
|
|
26850
|
+
const confirmPrefixes = (options.confirmPrefixes ?? []).map(
|
|
26851
|
+
(p) => p.startsWith("/") ? p.replace(/\/+$/, "") : `/${p}`.replace(/\/+$/, "")
|
|
26852
|
+
);
|
|
26840
26853
|
function rp(path) {
|
|
26841
26854
|
return resolveChroot(normalizedRoot, path);
|
|
26842
26855
|
}
|
|
@@ -26855,9 +26868,15 @@ var ZenFSConfig = (() => {
|
|
|
26855
26868
|
(prefix) => absolutePath === prefix || absolutePath.startsWith(`${prefix}/`)
|
|
26856
26869
|
);
|
|
26857
26870
|
}
|
|
26858
|
-
function
|
|
26871
|
+
function needsConfirm(absolutePath) {
|
|
26872
|
+
return confirmPrefixes.some(
|
|
26873
|
+
(prefix) => absolutePath === prefix || absolutePath.startsWith(`${prefix}/`)
|
|
26874
|
+
);
|
|
26875
|
+
}
|
|
26876
|
+
function writable(path, writeOptions) {
|
|
26859
26877
|
const absolute = visible(path);
|
|
26860
26878
|
if (isReadOnly(absolute)) throw makeEperm(path);
|
|
26879
|
+
if (needsConfirm(absolute) && writeOptions?.confirm !== true) throw makeEconfirm(path);
|
|
26861
26880
|
return absolute;
|
|
26862
26881
|
}
|
|
26863
26882
|
const promises = {
|
|
@@ -26865,7 +26884,7 @@ var ZenFSConfig = (() => {
|
|
|
26865
26884
|
return inner.readFile(visible(path), encoding);
|
|
26866
26885
|
},
|
|
26867
26886
|
async writeFile(path, data, writeOptions) {
|
|
26868
|
-
const target = writable(path);
|
|
26887
|
+
const target = writable(path, writeOptions);
|
|
26869
26888
|
await ensureParentDir(target);
|
|
26870
26889
|
await inner.writeFile(target, data, writeOptions);
|
|
26871
26890
|
if (options.onWrite) await options.onWrite(path, data);
|
|
@@ -26892,21 +26911,21 @@ var ZenFSConfig = (() => {
|
|
|
26892
26911
|
if (!exists3) throw makeEnoent(path);
|
|
26893
26912
|
},
|
|
26894
26913
|
async mkdir(path, mkdirOptions) {
|
|
26895
|
-
return inner.mkdir(writable(path), mkdirOptions);
|
|
26914
|
+
return inner.mkdir(writable(path, mkdirOptions), mkdirOptions);
|
|
26896
26915
|
},
|
|
26897
|
-
async unlink(path) {
|
|
26898
|
-
const target = writable(path);
|
|
26916
|
+
async unlink(path, unlinkOptions) {
|
|
26917
|
+
const target = writable(path, unlinkOptions);
|
|
26899
26918
|
if (options.onUnlink) return options.onUnlink(target);
|
|
26900
26919
|
return inner.unlink(target);
|
|
26901
26920
|
},
|
|
26902
|
-
async rmdir(path) {
|
|
26903
|
-
const target = writable(path);
|
|
26921
|
+
async rmdir(path, rmdirOptions) {
|
|
26922
|
+
const target = writable(path, rmdirOptions);
|
|
26904
26923
|
const hook = options.onRmdir ?? options.onUnlink;
|
|
26905
26924
|
if (hook) return hook(target);
|
|
26906
26925
|
return inner.rmdir?.(target);
|
|
26907
26926
|
},
|
|
26908
|
-
async rename(oldPath, newPath) {
|
|
26909
|
-
return inner.rename?.(writable(oldPath), writable(newPath));
|
|
26927
|
+
async rename(oldPath, newPath, renameOptions) {
|
|
26928
|
+
return inner.rename?.(writable(oldPath, renameOptions), writable(newPath, renameOptions));
|
|
26910
26929
|
},
|
|
26911
26930
|
async exists(path) {
|
|
26912
26931
|
if (isHidden(rp(path))) return false;
|
|
@@ -31354,9 +31373,9 @@ var ZenFSConfig = (() => {
|
|
|
31354
31373
|
LEGACY_TOMBSTONES_DIR,
|
|
31355
31374
|
VERSIONS_DIR,
|
|
31356
31375
|
CONFLICTS_DIR,
|
|
31357
|
-
LEGACY_CONFLICTS_DIR
|
|
31358
|
-
GROUP_DESCRIPTOR_FILE3
|
|
31376
|
+
LEGACY_CONFLICTS_DIR
|
|
31359
31377
|
],
|
|
31378
|
+
confirmPrefixes: [GROUP_DESCRIPTOR_FILE3],
|
|
31360
31379
|
onWrite: async (path, data) => {
|
|
31361
31380
|
if (path.startsWith(`${META_DIR}/`) || path === META_DIR) return;
|
|
31362
31381
|
await this.clearTombstonesForWrite(path);
|
|
@@ -31945,6 +31964,117 @@ var ZenFSConfig = (() => {
|
|
|
31945
31964
|
return owner === "" ? null : owner;
|
|
31946
31965
|
}
|
|
31947
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
|
+
|
|
31948
32078
|
// src/connect.ts
|
|
31949
32079
|
init_backend_registry();
|
|
31950
32080
|
var log10 = createLogger3("connect");
|