sliftutils 1.7.4 → 1.7.5
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
|
@@ -1717,6 +1717,7 @@ declare module "sliftutils/storage/DiskCollection" {
|
|
|
1717
1717
|
writeDelay?: number | undefined;
|
|
1718
1718
|
cbor?: boolean | undefined;
|
|
1719
1719
|
noPrompt?: boolean | undefined;
|
|
1720
|
+
resyncFromDisk?: boolean | undefined;
|
|
1720
1721
|
freeze?: "deep" | "shallow" | undefined;
|
|
1721
1722
|
beforeWrite?: ((update: {
|
|
1722
1723
|
newValue: T;
|
|
@@ -2177,12 +2178,13 @@ declare module "sliftutils/storage/TransactionStorage" {
|
|
|
2177
2178
|
private rawStorage;
|
|
2178
2179
|
private debugName;
|
|
2179
2180
|
private writeDelay;
|
|
2181
|
+
private resyncFromDisk;
|
|
2180
2182
|
cache: Map<string, TransactionEntry>;
|
|
2181
2183
|
private diskFiles;
|
|
2182
2184
|
private currentChunk;
|
|
2183
2185
|
private entryCount;
|
|
2184
2186
|
private static allStorage;
|
|
2185
|
-
constructor(rawStorage: IStorageRaw, debugName: string, writeDelay?: number);
|
|
2187
|
+
constructor(rawStorage: IStorageRaw, debugName: string, writeDelay?: number, resyncFromDisk?: boolean);
|
|
2186
2188
|
static compressAll(): Promise<void>;
|
|
2187
2189
|
private resyncCallbacks;
|
|
2188
2190
|
watchResync(callback: () => void): void;
|
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ export declare class DiskCollection<T> implements IStorageSync<T> {
|
|
|
12
12
|
writeDelay?: number | undefined;
|
|
13
13
|
cbor?: boolean | undefined;
|
|
14
14
|
noPrompt?: boolean | undefined;
|
|
15
|
+
resyncFromDisk?: boolean | undefined;
|
|
15
16
|
freeze?: "deep" | "shallow" | undefined;
|
|
16
17
|
beforeWrite?: ((update: {
|
|
17
18
|
newValue: T;
|
|
@@ -34,6 +34,8 @@ export class DiskCollection<T> implements IStorageSync<T> {
|
|
|
34
34
|
writeDelay?: number;
|
|
35
35
|
cbor?: boolean;
|
|
36
36
|
noPrompt?: boolean;
|
|
37
|
+
// Poll disk and reload when another process/tab writes to this collection. Off by default.
|
|
38
|
+
resyncFromDisk?: boolean;
|
|
37
39
|
freeze?: "shallow" | "deep";
|
|
38
40
|
// May mutate newValue in order to change what will be written
|
|
39
41
|
beforeWrite?: (update: { newValue: T; key: string; collection: DiskCollection<T> }) => void;
|
|
@@ -52,7 +54,7 @@ export class DiskCollection<T> implements IStorageSync<T> {
|
|
|
52
54
|
let collections = await fileStorage.folder.getStorage("collections");
|
|
53
55
|
curCollection = await collections.folder.getStorage(this.collectionName);
|
|
54
56
|
}
|
|
55
|
-
let baseStorage = new TransactionStorage(curCollection, this.collectionName, this.config?.writeDelay);
|
|
57
|
+
let baseStorage = new TransactionStorage(curCollection, this.collectionName, this.config?.writeDelay, this.config?.resyncFromDisk);
|
|
56
58
|
this.transactionStorage = baseStorage;
|
|
57
59
|
return this.config?.cbor ? new CBORStorage<T>(baseStorage) : new JSONStorage<T>(baseStorage);
|
|
58
60
|
}
|
|
@@ -11,12 +11,13 @@ export declare class TransactionStorage implements IStorage<Buffer> {
|
|
|
11
11
|
private rawStorage;
|
|
12
12
|
private debugName;
|
|
13
13
|
private writeDelay;
|
|
14
|
+
private resyncFromDisk;
|
|
14
15
|
cache: Map<string, TransactionEntry>;
|
|
15
16
|
private diskFiles;
|
|
16
17
|
private currentChunk;
|
|
17
18
|
private entryCount;
|
|
18
19
|
private static allStorage;
|
|
19
|
-
constructor(rawStorage: IStorageRaw, debugName: string, writeDelay?: number);
|
|
20
|
+
constructor(rawStorage: IStorageRaw, debugName: string, writeDelay?: number, resyncFromDisk?: boolean);
|
|
20
21
|
static compressAll(): Promise<void>;
|
|
21
22
|
private resyncCallbacks;
|
|
22
23
|
watchResync(callback: () => void): void;
|
|
@@ -92,7 +92,11 @@ export class TransactionStorage implements IStorage<Buffer> {
|
|
|
92
92
|
constructor(
|
|
93
93
|
private rawStorage: IStorageRaw,
|
|
94
94
|
private debugName: string,
|
|
95
|
-
private writeDelay = WRITE_DELAY
|
|
95
|
+
private writeDelay = WRITE_DELAY,
|
|
96
|
+
// When set, we poll the underlying storage and reload if another process/tab writes new
|
|
97
|
+
// chunk files. Off by default, as it costs a periodic disk scan and most collections are
|
|
98
|
+
// only written by a single process.
|
|
99
|
+
private resyncFromDisk = false
|
|
96
100
|
) {
|
|
97
101
|
TransactionStorage.allStorage.push(this);
|
|
98
102
|
// VERY useful for debugging.
|
|
@@ -282,7 +286,7 @@ export class TransactionStorage implements IStorage<Buffer> {
|
|
|
282
286
|
private async loadAllTransactions(initialLoad?: boolean): Promise<string[]> {
|
|
283
287
|
if (isInBuild()) return [];
|
|
284
288
|
|
|
285
|
-
if (initialLoad) {
|
|
289
|
+
if (initialLoad && this.resyncFromDisk) {
|
|
286
290
|
runInfinitePoll(DISK_CHECK_INTERVAL, () => this.checkDisk());
|
|
287
291
|
}
|
|
288
292
|
|