zen-fs-config 0.5.34 → 0.5.36
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.
|
@@ -9,12 +9,23 @@ function wrapWithCache(backend, backendId, options) {
|
|
|
9
9
|
} else {
|
|
10
10
|
store = new MemoryCacheStore();
|
|
11
11
|
}
|
|
12
|
+
try {
|
|
13
|
+
const purge = store.purgeKeepFiles?.();
|
|
14
|
+
if (purge && typeof purge.catch === "function") {
|
|
15
|
+
purge.catch(() => {
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
12
20
|
const wrapped = new CachedFileSystem(backend, store, {
|
|
13
21
|
ttlMs: options.ttlMs ?? 0
|
|
14
22
|
});
|
|
15
23
|
if (typeof backend.shouldSync === "function") {
|
|
16
24
|
wrapped.shouldSync = (...args) => backend.shouldSync(...args);
|
|
17
25
|
}
|
|
26
|
+
if (typeof backend.writeFileWithMtime === "function") {
|
|
27
|
+
wrapped.writeFileWithMtime = (path, data, mtimeMs) => backend.writeFileWithMtime(path, data, mtimeMs);
|
|
28
|
+
}
|
|
18
29
|
return wrapped;
|
|
19
30
|
}
|
|
20
31
|
export {
|
package/dist/index.js
CHANGED
|
@@ -385,12 +385,23 @@ function wrapWithCache(backend, backendId, options) {
|
|
|
385
385
|
} else {
|
|
386
386
|
store = new import_zen_fs_cache.MemoryCacheStore();
|
|
387
387
|
}
|
|
388
|
+
try {
|
|
389
|
+
const purge = store.purgeKeepFiles?.();
|
|
390
|
+
if (purge && typeof purge.catch === "function") {
|
|
391
|
+
purge.catch(() => {
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
} catch {
|
|
395
|
+
}
|
|
388
396
|
const wrapped = new import_zen_fs_cache.CachedFileSystem(backend, store, {
|
|
389
397
|
ttlMs: options.ttlMs ?? 0
|
|
390
398
|
});
|
|
391
399
|
if (typeof backend.shouldSync === "function") {
|
|
392
400
|
wrapped.shouldSync = (...args) => backend.shouldSync(...args);
|
|
393
401
|
}
|
|
402
|
+
if (typeof backend.writeFileWithMtime === "function") {
|
|
403
|
+
wrapped.writeFileWithMtime = (path, data, mtimeMs) => backend.writeFileWithMtime(path, data, mtimeMs);
|
|
404
|
+
}
|
|
394
405
|
return wrapped;
|
|
395
406
|
}
|
|
396
407
|
var import_zen_fs_cache;
|
package/dist/index.mjs
CHANGED
|
@@ -1635,7 +1635,7 @@ var ConfigRepo = class {
|
|
|
1635
1635
|
const instance = await createBackend(desc);
|
|
1636
1636
|
let fsInstance = instance;
|
|
1637
1637
|
if (this.cacheOptions) {
|
|
1638
|
-
const { wrapWithCache } = await import("./cache-wrapper-
|
|
1638
|
+
const { wrapWithCache } = await import("./cache-wrapper-S5HRLRQX.mjs");
|
|
1639
1639
|
fsInstance = wrapWithCache(instance, desc.id, this.cacheOptions);
|
|
1640
1640
|
log2.log(`[ConfigRepo] Replica ${desc.id} wrapped with CachedFileSystem (store=${this.cacheOptions.storeType ?? "IdbCacheStore"})`);
|
|
1641
1641
|
}
|
package/dist/zen-fs-config.js
CHANGED
|
@@ -24886,10 +24886,35 @@ var ZenFSConfig = (() => {
|
|
|
24886
24886
|
}
|
|
24887
24887
|
async exists(path) {
|
|
24888
24888
|
try {
|
|
24889
|
+
const innerType = this.inner?.constructor?.name ?? typeof this.inner;
|
|
24890
|
+
const hasStat = typeof this.inner?.stat === "function";
|
|
24891
|
+
const hasExists = typeof this.inner?.exists === "function";
|
|
24892
|
+
const backendName = this.inner?.backendName ?? this.inner?.constructor?.name ?? "unknown";
|
|
24893
|
+
console.log(`[CACHE-EXISTS] exists(${path}): inner=${innerType} backend=${backendName} hasStat=${hasStat} hasExists=${hasExists}`);
|
|
24894
|
+
const statKey = `stat:${path}`;
|
|
24895
|
+
const cachedStat = await this.store.get(statKey);
|
|
24896
|
+
if (cachedStat) {
|
|
24897
|
+
const age = Date.now() - cachedStat.cachedAt;
|
|
24898
|
+
console.log(`[CACHE-EXISTS] exists(${path}): cached stat entry found, age=${age}ms, ttlMs=${this.ttlMs}`);
|
|
24899
|
+
} else {
|
|
24900
|
+
console.log(`[CACHE-EXISTS] exists(${path}): no cached stat entry`);
|
|
24901
|
+
}
|
|
24902
|
+
if (hasExists) {
|
|
24903
|
+
console.log(`[CACHE-EXISTS] exists(${path}): \u2192 calling inner.exists() [backend=${backendName}]`);
|
|
24904
|
+
const result = await this.inner.exists(path);
|
|
24905
|
+
console.log(`[CACHE-EXISTS] exists(${path}): \u2190 inner.exists() [backend=${backendName}] \u2192 ${result}`);
|
|
24906
|
+
return result;
|
|
24907
|
+
}
|
|
24908
|
+
console.log(`[CACHE-EXISTS] exists(${path}): no inner.exists(), falling back to inner.stat() [backend=${backendName}]`);
|
|
24889
24909
|
await this.inner.stat(path);
|
|
24910
|
+
console.log(`[CACHE-EXISTS] exists(${path}): \u2190 inner.stat() [backend=${backendName}] \u2192 OK (exists)`);
|
|
24890
24911
|
return true;
|
|
24891
24912
|
} catch (err2) {
|
|
24892
|
-
if (this.isNotFound(err2))
|
|
24913
|
+
if (this.isNotFound(err2)) {
|
|
24914
|
+
console.log(`[CACHE-EXISTS] exists(${path}): \u2190 inner.stat() \u2192 NotFound`);
|
|
24915
|
+
return false;
|
|
24916
|
+
}
|
|
24917
|
+
console.log(`[CACHE-EXISTS] exists(${path}): \u2190 inner.stat() \u2192 ERROR: ${err2}`);
|
|
24893
24918
|
throw err2;
|
|
24894
24919
|
}
|
|
24895
24920
|
}
|
|
@@ -24922,7 +24947,10 @@ var ZenFSConfig = (() => {
|
|
|
24922
24947
|
await this.invalidateMeta(path);
|
|
24923
24948
|
}
|
|
24924
24949
|
async unlink(path) {
|
|
24950
|
+
const backendName = this.inner?.backendName ?? this.inner?.constructor?.name ?? "unknown";
|
|
24951
|
+
console.log(`[CACHE-UNLINK] unlink(${path}): calling inner.unlink() [backend=${backendName}]`);
|
|
24925
24952
|
await this.inner.unlink(path);
|
|
24953
|
+
console.log(`[CACHE-UNLINK] unlink(${path}): inner.unlink() OK [backend=${backendName}], invalidating cache`);
|
|
24926
24954
|
await this.invalidate(path);
|
|
24927
24955
|
}
|
|
24928
24956
|
async mkdir(path, options) {
|
|
@@ -24981,6 +25009,12 @@ var ZenFSConfig = (() => {
|
|
|
24981
25009
|
async clear() {
|
|
24982
25010
|
this.store.clear();
|
|
24983
25011
|
}
|
|
25012
|
+
async purgeKeepFiles() {
|
|
25013
|
+
for (const key of Array.from(this.store.keys())) {
|
|
25014
|
+
const base = key === "/" ? "" : key.split("/").pop() ?? "";
|
|
25015
|
+
if (base === ".keep") this.store.delete(key);
|
|
25016
|
+
}
|
|
25017
|
+
}
|
|
24984
25018
|
};
|
|
24985
25019
|
IdbCacheStore = class {
|
|
24986
25020
|
constructor(prefix = "zen-fs-cache:", dbName = "zen-fs-cache", storeName = "cache") {
|
|
@@ -25061,6 +25095,28 @@ var ZenFSConfig = (() => {
|
|
|
25061
25095
|
} catch {
|
|
25062
25096
|
}
|
|
25063
25097
|
}
|
|
25098
|
+
async purgeKeepFiles() {
|
|
25099
|
+
try {
|
|
25100
|
+
const db = await this.open();
|
|
25101
|
+
await new Promise((resolve4, reject) => {
|
|
25102
|
+
const tx = db.transaction(this.storeName, "readwrite");
|
|
25103
|
+
const store = tx.objectStore(this.storeName);
|
|
25104
|
+
const req = store.getAllKeys();
|
|
25105
|
+
req.onsuccess = () => {
|
|
25106
|
+
const keys = req.result ?? [];
|
|
25107
|
+
for (const raw of keys) {
|
|
25108
|
+
const path = raw.startsWith(this.prefix) ? raw.slice(this.prefix.length) : raw;
|
|
25109
|
+
const base = path === "/" ? "" : path.split("/").pop() ?? "";
|
|
25110
|
+
if (base === ".keep") store.delete(raw);
|
|
25111
|
+
}
|
|
25112
|
+
};
|
|
25113
|
+
req.onerror = () => reject(req.error);
|
|
25114
|
+
tx.oncomplete = () => resolve4();
|
|
25115
|
+
tx.onerror = () => reject(tx.error);
|
|
25116
|
+
});
|
|
25117
|
+
} catch {
|
|
25118
|
+
}
|
|
25119
|
+
}
|
|
25064
25120
|
};
|
|
25065
25121
|
}
|
|
25066
25122
|
});
|
|
@@ -25079,12 +25135,23 @@ var ZenFSConfig = (() => {
|
|
|
25079
25135
|
} else {
|
|
25080
25136
|
store = new MemoryCacheStore();
|
|
25081
25137
|
}
|
|
25138
|
+
try {
|
|
25139
|
+
const purge = store.purgeKeepFiles?.();
|
|
25140
|
+
if (purge && typeof purge.catch === "function") {
|
|
25141
|
+
purge.catch(() => {
|
|
25142
|
+
});
|
|
25143
|
+
}
|
|
25144
|
+
} catch {
|
|
25145
|
+
}
|
|
25082
25146
|
const wrapped = new CachedFileSystem(backend, store, {
|
|
25083
25147
|
ttlMs: options.ttlMs ?? 0
|
|
25084
25148
|
});
|
|
25085
25149
|
if (typeof backend.shouldSync === "function") {
|
|
25086
25150
|
wrapped.shouldSync = (...args) => backend.shouldSync(...args);
|
|
25087
25151
|
}
|
|
25152
|
+
if (typeof backend.writeFileWithMtime === "function") {
|
|
25153
|
+
wrapped.writeFileWithMtime = (path, data, mtimeMs) => backend.writeFileWithMtime(path, data, mtimeMs);
|
|
25154
|
+
}
|
|
25088
25155
|
return wrapped;
|
|
25089
25156
|
}
|
|
25090
25157
|
var init_cache_wrapper = __esm({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zen-fs-config",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.36",
|
|
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",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"tsup": "^8.5.1",
|
|
81
81
|
"typescript": "^5.9.3",
|
|
82
82
|
"vitest": "^1.6.1",
|
|
83
|
-
"zen-fs-cache": "^1.0.
|
|
83
|
+
"zen-fs-cache": "^1.0.6",
|
|
84
84
|
"zen-fs-sync": "^0.4.9"
|
|
85
85
|
}
|
|
86
86
|
}
|