sliftutils 1.1.42 → 1.1.43
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 +171 -0
- package/package.json +2 -2
- package/render-utils/mobxTyped.d.ts +1 -0
- package/render-utils/mobxTyped.ts +4 -0
- package/storage/BulkDatabase2/BulkDatabase2.d.ts +70 -0
- package/storage/BulkDatabase2/BulkDatabase2.ts +667 -0
- package/storage/BulkDatabase2/BulkDatabaseFormat.d.ts +24 -0
- package/storage/BulkDatabase2/BulkDatabaseFormat.ts +235 -0
- package/storage/BulkDatabase2/blockCache.d.ts +17 -0
- package/storage/BulkDatabase2/blockCache.ts +173 -0
- package/storage/BulkDatabase2/streamLog.d.ts +25 -0
- package/storage/BulkDatabase2/streamLog.ts +116 -0
- package/storage/BulkDatabase2/syncClient.d.ts +9 -0
- package/storage/BulkDatabase2/syncClient.ts +58 -0
- package/storage/BulkDatabase2/syncWorker.d.ts +1 -0
- package/storage/BulkDatabase2/syncWorker.ts +65 -0
- package/yarn.lock +4 -4
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { isNode } from "typesafecss";
|
|
2
|
+
|
|
3
|
+
// SharedWorker that synchronizes BulkDatabase2 writes between tabs of the same origin. It does NOT
|
|
4
|
+
// persist anything (each tab still writes to disk itself); it just relays writes to other tabs and
|
|
5
|
+
// buffers the recent ones so a freshly-opened tab can catch writes that haven't been flushed to disk
|
|
6
|
+
// yet. Per collection it keeps the latest write per key, pruned to a short recency window (older
|
|
7
|
+
// writes are already on disk, so a new tab gets them from there).
|
|
8
|
+
|
|
9
|
+
type RemoteWrite = { key: string; time: number; deleted?: boolean; value?: unknown };
|
|
10
|
+
type Collection = { ports: Set<MessagePort>; recent: Map<string, RemoteWrite> };
|
|
11
|
+
|
|
12
|
+
const RECENT_WINDOW_MS = 60_000;
|
|
13
|
+
const collections = new Map<string, Collection>();
|
|
14
|
+
|
|
15
|
+
function getCollection(name: string): Collection {
|
|
16
|
+
let c = collections.get(name);
|
|
17
|
+
if (!c) {
|
|
18
|
+
c = { ports: new Set(), recent: new Map() };
|
|
19
|
+
collections.set(name, c);
|
|
20
|
+
}
|
|
21
|
+
return c;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function prune(c: Collection) {
|
|
25
|
+
let cutoff = Date.now() - RECENT_WINDOW_MS;
|
|
26
|
+
for (let [key, write] of c.recent) {
|
|
27
|
+
if (write.time < cutoff) c.recent.delete(key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function post(port: MessagePort, message: unknown) {
|
|
32
|
+
try {
|
|
33
|
+
port.postMessage(message);
|
|
34
|
+
} catch {
|
|
35
|
+
// Port closed (tab gone); it'll be dropped on the next failed send.
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function main() {
|
|
40
|
+
if (isNode()) return;
|
|
41
|
+
(self as unknown as { onconnect: (e: MessageEvent) => void }).onconnect = (event: MessageEvent) => {
|
|
42
|
+
let port = (event as unknown as { ports: MessagePort[] }).ports[0];
|
|
43
|
+
port.onmessage = (ev: MessageEvent) => {
|
|
44
|
+
let msg = ev.data as { type: string; collection: string } & RemoteWrite;
|
|
45
|
+
let c = getCollection(msg.collection);
|
|
46
|
+
if (msg.type === "hello") {
|
|
47
|
+
c.ports.add(port);
|
|
48
|
+
prune(c);
|
|
49
|
+
port.postMessage({ type: "recent", collection: msg.collection, writes: [...c.recent.values()] });
|
|
50
|
+
} else if (msg.type === "write") {
|
|
51
|
+
prune(c);
|
|
52
|
+
let existing = c.recent.get(msg.key);
|
|
53
|
+
if (!existing || msg.time > existing.time) {
|
|
54
|
+
c.recent.set(msg.key, { key: msg.key, time: msg.time, deleted: msg.deleted, value: msg.value });
|
|
55
|
+
}
|
|
56
|
+
for (let other of c.ports) {
|
|
57
|
+
if (other !== port) post(other, msg);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
port.start();
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
main();
|
package/yarn.lock
CHANGED
|
@@ -1940,10 +1940,10 @@ slash@^3.0.0:
|
|
|
1940
1940
|
resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"
|
|
1941
1941
|
integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==
|
|
1942
1942
|
|
|
1943
|
-
socket-function@^1.1.
|
|
1944
|
-
version "1.1.
|
|
1945
|
-
resolved "https://registry.yarnpkg.com/socket-function/-/socket-function-1.1.
|
|
1946
|
-
integrity sha512-
|
|
1943
|
+
socket-function@^1.1.38:
|
|
1944
|
+
version "1.1.38"
|
|
1945
|
+
resolved "https://registry.yarnpkg.com/socket-function/-/socket-function-1.1.38.tgz#8923a1db19480d5828d9bde9975eabac505698ce"
|
|
1946
|
+
integrity sha512-LJFeVUaXT8D8egyKr7fZajq7ctmLUN58Uih6GHx3/pfXV3pDFfJS0+XJRqsk0udn0II1ZqozEz242khs4fLCKQ==
|
|
1947
1947
|
dependencies:
|
|
1948
1948
|
"@types/pako" "^2.0.3"
|
|
1949
1949
|
"@types/ws" "^8.5.3"
|