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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sliftutils",
3
- "version": "0.64.0",
3
+ "version": "0.66.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -12,5 +12,6 @@ export declare class CBORStorage<T> implements IStorage<T> {
12
12
  size: number;
13
13
  lastModified: number;
14
14
  } | undefined>;
15
+ watchResync(callback: () => void): void;
15
16
  reset(): Promise<void>;
16
17
  }
@@ -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
  }
@@ -12,5 +12,6 @@ export declare class JSONStorage<T> implements IStorage<T> {
12
12
  size: number;
13
13
  lastModified: number;
14
14
  } | undefined>;
15
+ watchResync(callback: () => void): void;
15
16
  reset(): Promise<void>;
16
17
  }
@@ -27,7 +27,9 @@ export class JSONStorage<T> implements IStorage<T> {
27
27
  }
28
28
 
29
29
 
30
-
30
+ public watchResync(callback: () => void): void {
31
+ this.storage.watchResync?.(callback);
32
+ }
31
33
 
32
34
  public async reset() {
33
35
  await this.storage.reset();
@@ -10,9 +10,6 @@ export declare class StorageSync<T> implements IStorageSync<T> {
10
10
  synced: {
11
11
  keySeqNum: number;
12
12
  };
13
- resynced: {
14
- seqNum: number;
15
- };
16
13
  constructor(storage: IStorage<T>);
17
14
  get(key: string): T | undefined;
18
15
  set(key: string, value: T): void;
@@ -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.resynced.seqNum++;
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 => {