@fireproof/core-base 0.22.0-keybag → 0.23.1-dev-issue-1057
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/LICENSE.md +197 -228
- package/README.md +269 -0
- package/apply-head-queue.js.map +1 -1
- package/bundle-not-impl.js.map +1 -1
- package/compact-strategies.js +3 -0
- package/compact-strategies.js.map +1 -1
- package/crdt-clock.d.ts +1 -1
- package/crdt-clock.js +2 -0
- package/crdt-clock.js.map +1 -1
- package/crdt-helpers.js.map +1 -1
- package/crdt.js.map +1 -1
- package/database.js.map +1 -1
- package/index.js.map +1 -1
- package/indexer-helpers.js.map +1 -1
- package/indexer.js +1 -0
- package/indexer.js.map +1 -1
- package/ledger.js.map +1 -1
- package/package.json +11 -11
- package/version.js.map +1 -1
- package/write-queue.js.map +1 -1
- package/apply-head-queue.ts +0 -72
- package/bundle-not-impl.ts +0 -4
- package/compact-strategies.ts +0 -95
- package/crdt-clock.ts +0 -192
- package/crdt-helpers.ts +0 -408
- package/crdt.ts +0 -275
- package/database.ts +0 -200
- package/index.ts +0 -15
- package/indexer-helpers.ts +0 -263
- package/indexer.ts +0 -360
- package/ledger.ts +0 -345
- package/tsconfig.json +0 -18
- package/version.ts +0 -3
- package/write-queue.ts +0 -93
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": [
|
|
3
|
-
"/home/runner/work/fireproof/fireproof/tsconfig.dist.json"
|
|
4
|
-
],
|
|
5
|
-
"compilerOptions": {
|
|
6
|
-
"noEmit": false,
|
|
7
|
-
"outDir": "./"
|
|
8
|
-
},
|
|
9
|
-
"include": [
|
|
10
|
-
"**/*"
|
|
11
|
-
],
|
|
12
|
-
"exclude": [
|
|
13
|
-
"node_modules",
|
|
14
|
-
"dist",
|
|
15
|
-
".git",
|
|
16
|
-
".vscode"
|
|
17
|
-
]
|
|
18
|
-
}
|
package/version.ts
DELETED
package/write-queue.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { ensureLogger } from "@fireproof/core-runtime";
|
|
2
|
-
import {
|
|
3
|
-
DocTypes,
|
|
4
|
-
MetaType,
|
|
5
|
-
DocUpdate,
|
|
6
|
-
SuperThis,
|
|
7
|
-
WriteQueue,
|
|
8
|
-
defaultWriteQueueOpts,
|
|
9
|
-
WriteQueueParams,
|
|
10
|
-
} from "@fireproof/core-types-base";
|
|
11
|
-
import { Future, Logger } from "@adviser/cement";
|
|
12
|
-
|
|
13
|
-
type WorkerFunction<T extends DocTypes> = (tasks: DocUpdate<T>[]) => Promise<MetaType>;
|
|
14
|
-
|
|
15
|
-
interface WriteQueueItem<T extends DocTypes> {
|
|
16
|
-
// readonly task?: DocUpdate<T>;
|
|
17
|
-
readonly tasks?: DocUpdate<T>[];
|
|
18
|
-
resolve(result: MetaType): void;
|
|
19
|
-
reject(error: Error): void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
class WriteQueueImpl<T extends DocUpdate<S>, S extends DocTypes = DocTypes> implements WriteQueue<T> {
|
|
23
|
-
private readonly opts: WriteQueueParams;
|
|
24
|
-
|
|
25
|
-
private readonly queue: WriteQueueItem<S>[] = [];
|
|
26
|
-
private readonly worker: WorkerFunction<S>;
|
|
27
|
-
private isProcessing = false;
|
|
28
|
-
private readonly logger: Logger;
|
|
29
|
-
|
|
30
|
-
constructor(sthis: SuperThis, worker: WorkerFunction<S>, opts: WriteQueueParams) {
|
|
31
|
-
this.logger = ensureLogger(sthis, "WriteQueueImpl");
|
|
32
|
-
this.worker = worker;
|
|
33
|
-
this.opts = defaultWriteQueueOpts(opts);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
private waitForEmptyQueue?: Future<void>;
|
|
37
|
-
private testEmptyQueue() {
|
|
38
|
-
if (this.waitForEmptyQueue && this.queue.length === 0) {
|
|
39
|
-
this.waitForEmptyQueue.resolve();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
private async process() {
|
|
44
|
-
if (this.isProcessing || this.queue.length === 0) {
|
|
45
|
-
this.testEmptyQueue();
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
this.isProcessing = true;
|
|
49
|
-
try {
|
|
50
|
-
this.logger.Debug().Any("opts", this.opts).Len(this.queue).Msg("Processing tasks");
|
|
51
|
-
const tasksToProcess = this.queue.splice(0, this.opts.chunkSize);
|
|
52
|
-
const updates = tasksToProcess.map((item) => item.tasks).filter((item) => item) as DocUpdate<S>[][];
|
|
53
|
-
const promises = updates.map(async (update, index) => {
|
|
54
|
-
try {
|
|
55
|
-
const result = await this.worker(update);
|
|
56
|
-
tasksToProcess[index].resolve(result);
|
|
57
|
-
} catch (error) {
|
|
58
|
-
tasksToProcess[index].reject(this.logger.Error().Err(error).Msg("Error processing task").AsError());
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
await Promise.allSettled(promises);
|
|
62
|
-
this.logger.Debug().Any("opts", this.opts).Len(this.queue).Msg("Processed tasks");
|
|
63
|
-
} catch (error) {
|
|
64
|
-
this.logger.Error().Err(error).Msg("Error processing tasks");
|
|
65
|
-
} finally {
|
|
66
|
-
this.isProcessing = false;
|
|
67
|
-
setTimeout(() => this.process(), 0);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
bulk(tasks: DocUpdate<S>[]): Promise<MetaType> {
|
|
72
|
-
return new Promise<MetaType>((resolve, reject) => {
|
|
73
|
-
this.queue.push({ tasks, resolve, reject });
|
|
74
|
-
this.process();
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
push(task: DocUpdate<S>): Promise<MetaType> {
|
|
78
|
-
return this.bulk([task]);
|
|
79
|
-
}
|
|
80
|
-
close(): Promise<void> {
|
|
81
|
-
this.waitForEmptyQueue = new Future();
|
|
82
|
-
this.testEmptyQueue();
|
|
83
|
-
return this.waitForEmptyQueue.asPromise();
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function writeQueue<T extends DocUpdate<S>, S extends DocTypes = DocTypes>(
|
|
88
|
-
sthis: SuperThis,
|
|
89
|
-
worker: WorkerFunction<S>,
|
|
90
|
-
opts: WriteQueueParams,
|
|
91
|
-
): WriteQueue<T, S> {
|
|
92
|
-
return new WriteQueueImpl<T, S>(sthis, worker, opts);
|
|
93
|
-
}
|