sliftutils 0.64.0 → 0.66.0
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/index.d.ts
CHANGED
|
@@ -574,6 +574,7 @@ declare module "sliftutils/storage/CBORStorage" {
|
|
|
574
574
|
size: number;
|
|
575
575
|
lastModified: number;
|
|
576
576
|
} | undefined>;
|
|
577
|
+
watchResync(callback: () => void): void;
|
|
577
578
|
reset(): Promise<void>;
|
|
578
579
|
}
|
|
579
580
|
|
|
@@ -858,6 +859,7 @@ declare module "sliftutils/storage/JSONStorage" {
|
|
|
858
859
|
size: number;
|
|
859
860
|
lastModified: number;
|
|
860
861
|
} | undefined>;
|
|
862
|
+
watchResync(callback: () => void): void;
|
|
861
863
|
reset(): Promise<void>;
|
|
862
864
|
}
|
|
863
865
|
|
|
@@ -936,9 +938,6 @@ declare module "sliftutils/storage/StorageObservable" {
|
|
|
936
938
|
synced: {
|
|
937
939
|
keySeqNum: number;
|
|
938
940
|
};
|
|
939
|
-
resynced: {
|
|
940
|
-
seqNum: number;
|
|
941
|
-
};
|
|
942
941
|
constructor(storage: IStorage<T>);
|
|
943
942
|
get(key: string): T | undefined;
|
|
944
943
|
set(key: string, value: T): void;
|
package/package.json
CHANGED
package/storage/CBORStorage.d.ts
CHANGED
package/storage/CBORStorage.ts
CHANGED
|
@@ -30,6 +30,11 @@ export class CBORStorage<T> implements IStorage<T> {
|
|
|
30
30
|
return await this.storage.getInfo(key);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
|
|
34
|
+
public watchResync(callback: () => void): void {
|
|
35
|
+
this.storage.watchResync?.(callback);
|
|
36
|
+
}
|
|
37
|
+
|
|
33
38
|
public async reset() {
|
|
34
39
|
await this.storage.reset();
|
|
35
40
|
}
|
package/storage/JSONStorage.d.ts
CHANGED
package/storage/JSONStorage.ts
CHANGED
|
@@ -11,16 +11,17 @@ export class StorageSync<T> implements IStorageSync<T> {
|
|
|
11
11
|
keySeqNum: 0,
|
|
12
12
|
}, undefined, { deep: false });
|
|
13
13
|
|
|
14
|
-
resynced = observable({ seqNum: 0 });
|
|
15
|
-
|
|
16
14
|
constructor(public storage: IStorage<T>) {
|
|
17
15
|
storage.watchResync?.(() => {
|
|
18
|
-
this.
|
|
16
|
+
this.cached.clear();
|
|
17
|
+
this.infoCached.clear();
|
|
18
|
+
this.keys.clear();
|
|
19
|
+
this.loadedKeys = false;
|
|
20
|
+
this.synced.keySeqNum++;
|
|
19
21
|
});
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
public get(key: string): T | undefined {
|
|
23
|
-
this.resynced.seqNum;
|
|
24
25
|
if (!this.cached.has(key)) {
|
|
25
26
|
this.cached.set(key, undefined);
|
|
26
27
|
void this.getPromise(key);
|
|
@@ -48,14 +49,12 @@ export class StorageSync<T> implements IStorageSync<T> {
|
|
|
48
49
|
}
|
|
49
50
|
private loadedKeys = false;
|
|
50
51
|
public getKeys(): string[] {
|
|
51
|
-
this.resynced.seqNum;
|
|
52
52
|
void this.getKeysPromise();
|
|
53
53
|
this.synced.keySeqNum;
|
|
54
54
|
return Array.from(this.keys);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
public getInfo(key: string): { size: number; lastModified: number } | undefined {
|
|
58
|
-
this.resynced.seqNum;
|
|
59
58
|
if (!this.infoCached.has(key)) {
|
|
60
59
|
this.infoCached.set(key, { size: 0, lastModified: 0 });
|
|
61
60
|
void this.storage.getInfo(key).then(info => {
|