@spooky-sync/core 0.0.1-canary.98 → 1.0.0-beta.10
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/AGENTS.md +58 -21
- package/README.md +59 -16
- package/dist/index.d.ts +2235 -908
- package/dist/index.js +20424 -5052
- package/dist/live.d.ts +149 -0
- package/dist/live.js +739 -0
- package/dist/otel/index.d.ts +1 -1
- package/dist/pure.d.ts +401 -0
- package/dist/pure.js +24 -0
- package/dist/rows-worker.d.ts +1 -0
- package/dist/rows-worker.js +2639 -0
- package/dist/sqlite-open.js +392 -0
- package/dist/sqlite-worker.d.ts +1 -0
- package/dist/sqlite-worker.js +439 -0
- package/dist/sw.d.ts +207 -0
- package/dist/sw.js +393 -0
- package/dist/tabs-broker-worker.d.ts +8 -0
- package/dist/tabs-broker-worker.js +477 -0
- package/dist/types.d.ts +2084 -82
- package/dist/worker-edges.js +498 -0
- package/dist/worker-impersonation.js +60 -0
- package/dist/worker-ref-tables.d.ts +48 -0
- package/dist/worker-types.d.ts +112 -0
- package/dist/worker-types.js +73 -0
- package/package.json +39 -8
- package/scripts/check-broker-bundle.mjs +33 -0
- package/scripts/check-worker-entries.mjs +186 -0
- package/skills/sp00ky-core/SKILL.md +44 -8
- package/skills/sp00ky-core/references/config.md +8 -2
- package/src/boot/auth-flip.saga.test.ts +174 -0
- package/src/boot/auth-flip.saga.ts +77 -0
- package/src/boot/boot.saga.test.ts +203 -0
- package/src/boot/boot.saga.ts +146 -0
- package/src/boot/bucket-switch.saga.test.ts +191 -0
- package/src/boot/bucket-switch.saga.ts +151 -0
- package/src/boot/preload.saga.test.ts +96 -0
- package/src/boot/preload.saga.ts +45 -0
- package/src/bucket-blurhash.test.ts +148 -0
- package/src/client/bucket-handle.test.ts +195 -0
- package/src/client/bucket-handle.ts +372 -0
- package/src/client/eager-paint.test.ts +82 -0
- package/src/client/router.test.ts +59 -0
- package/src/client/router.ts +104 -0
- package/src/client/runtime.test.ts +319 -0
- package/src/client/runtime.ts +307 -0
- package/src/client/services.test.ts +74 -0
- package/src/client/services.ts +440 -0
- package/src/client/sp00ky-client.test.ts +570 -0
- package/src/client/sp00ky-client.ts +875 -0
- package/src/index.ts +87 -0
- package/src/kernel/constants.test.ts +19 -0
- package/src/kernel/constants.ts +94 -0
- package/src/kernel/effects.test.ts +40 -0
- package/src/kernel/effects.ts +181 -0
- package/src/kernel/events.ts +60 -0
- package/src/kernel/interpreter.test.ts +133 -0
- package/src/kernel/interpreter.ts +151 -0
- package/src/kernel/saga.test.ts +89 -0
- package/src/kernel/saga.ts +73 -0
- package/src/live/index.test.ts +512 -0
- package/src/live/index.ts +1059 -0
- package/src/modules/app-release/index.test.ts +125 -0
- package/src/modules/app-release/index.ts +209 -0
- package/src/modules/auth/auth.local-first.test.ts +228 -0
- package/src/modules/auth/auth.session-recheck.test.ts +140 -0
- package/src/modules/auth/events/index.ts +7 -1
- package/src/modules/auth/impersonation-banner.ts +443 -0
- package/src/modules/auth/impersonation.integration.test.ts +209 -0
- package/src/modules/auth/impersonation.test.ts +377 -0
- package/src/modules/auth/impersonation.ts +179 -0
- package/src/modules/auth/index.ts +516 -34
- package/src/modules/channel/channel.test.ts +752 -0
- package/src/modules/channel/hub.test.ts +223 -0
- package/src/modules/channel/hub.ts +355 -0
- package/src/modules/channel/index.ts +1497 -0
- package/src/modules/channel/room.test.ts +340 -0
- package/src/modules/channel/room.ts +367 -0
- package/src/modules/channel/rooms.fixture.ts +383 -0
- package/src/modules/channel/share.test.ts +535 -0
- package/src/modules/channel/webrtc.ts +472 -0
- package/src/modules/crdt/acceptance.ts +75 -0
- package/src/modules/crdt/bytes.ts +50 -0
- package/src/modules/crdt/crdt-field.ts +82 -238
- package/src/modules/crdt/crdt.test.ts +546 -0
- package/src/modules/crdt/hash.ts +103 -0
- package/src/modules/crdt/index.ts +740 -271
- package/src/modules/crdt/loro-loader.ts +25 -0
- package/src/modules/crdt/mirror.ts +37 -0
- package/src/modules/devtools/flags.ts +349 -0
- package/src/modules/devtools/index.ts +661 -99
- package/src/modules/devtools/mutations.test.ts +92 -0
- package/src/modules/devtools/mutations.ts +160 -0
- package/src/modules/devtools/notify-throttle.test.ts +166 -0
- package/src/modules/devtools/state-shape.test.ts +263 -0
- package/src/modules/devtools/storage-info.test.ts +79 -0
- package/src/modules/devtools/storage-info.ts +169 -0
- package/src/modules/devtools/versions.ts +29 -0
- package/src/modules/feature-flag/index.test.ts +179 -1
- package/src/modules/feature-flag/index.ts +117 -10
- package/src/modules/ref-tables.test.ts +28 -1
- package/src/modules/ref-tables.ts +23 -1
- package/src/modules/web-push/index.test.ts +824 -0
- package/src/modules/web-push/index.ts +1027 -0
- package/src/mutation/ingest-outage.integration.test.ts +400 -0
- package/src/mutation/jobs.test.ts +25 -0
- package/src/mutation/jobs.ts +41 -0
- package/src/mutation/mutation-id.test.ts +37 -0
- package/src/mutation/mutation-id.ts +35 -0
- package/src/mutation/pending-writes.integration.test.ts +175 -0
- package/src/mutation/push.saga.test.ts +361 -0
- package/src/mutation/push.saga.ts +245 -0
- package/src/mutation/rows.test.ts +278 -0
- package/src/mutation/rows.ts +515 -0
- package/src/mutation/tray.saga.test.ts +63 -0
- package/src/mutation/tray.saga.ts +48 -0
- package/src/mutation/write.saga.test.ts +436 -0
- package/src/mutation/write.saga.ts +384 -0
- package/src/pure.ts +66 -0
- package/src/push/types.ts +174 -0
- package/src/query/anon-query-isolation.integration.test.ts +531 -0
- package/src/query/env.test.ts +23 -0
- package/src/query/env.ts +65 -0
- package/src/query/fetch.saga.test.ts +199 -0
- package/src/query/fetch.saga.ts +120 -0
- package/src/query/hash.test.ts +14 -0
- package/src/query/hash.ts +18 -0
- package/src/query/id-set-plan.test.ts +132 -0
- package/src/query/lifecycle.saga.test.ts +274 -0
- package/src/query/lifecycle.saga.ts +186 -0
- package/src/query/list-ref-live.integration.test.ts +203 -0
- package/src/query/materialize.saga.test.ts +216 -0
- package/src/query/materialize.saga.ts +83 -0
- package/src/query/materialize.test.ts +58 -0
- package/src/query/materialize.ts +133 -0
- package/src/query/membership.saga.test.ts +514 -0
- package/src/query/membership.saga.ts +339 -0
- package/src/query/membership.test.ts +151 -0
- package/src/query/membership.ts +234 -0
- package/src/query/register.saga.test.ts +430 -0
- package/src/query/register.saga.ts +330 -0
- package/src/query/render-set.test.ts +47 -0
- package/src/query/render-set.ts +71 -0
- package/src/query/session-guard.integration.test.ts +304 -0
- package/src/query/sql.test.ts +118 -0
- package/src/query/sql.ts +174 -0
- package/src/{modules/data → query}/window-query.test.ts +22 -4
- package/src/{modules/data → query}/window-query.ts +86 -8
- package/src/services/blobs/blob-cache.test.ts +359 -0
- package/src/services/blobs/blob-cache.ts +603 -0
- package/src/services/blobs/blob-manifest.ts +227 -0
- package/src/services/blobs/blob-store.test.ts +77 -0
- package/src/services/blobs/blob-store.ts +359 -0
- package/src/services/blobs/blob.fixture.ts +90 -0
- package/src/services/blobs/index.ts +70 -0
- package/src/services/database/cache-engine.ts +223 -0
- package/src/services/database/connection-supervisor.test.ts +318 -0
- package/src/services/database/connection-supervisor.ts +422 -0
- package/src/services/database/database.query-timeout.test.ts +140 -0
- package/src/services/database/database.responses.test.ts +43 -0
- package/src/services/database/database.ts +151 -56
- package/src/services/database/engine-factory.ts +40 -0
- package/src/services/database/errors.ts +34 -0
- package/src/services/database/index.ts +8 -0
- package/src/services/database/landed-body-clear.integration.test.ts +236 -0
- package/src/services/database/local-migrator.integration.test.ts +110 -0
- package/src/services/database/local-migrator.ts +54 -9
- package/src/services/database/local.test.ts +117 -0
- package/src/services/database/local.ts +364 -74
- package/src/services/database/plan-render.test.ts +159 -0
- package/src/services/database/plan-render.ts +108 -0
- package/src/services/database/relation-resolver.test.ts +484 -0
- package/src/services/database/relation-resolver.ts +0 -0
- package/src/services/database/remote.ts +283 -4
- package/src/services/database/rows-cache-engine.test.ts +1014 -0
- package/src/services/database/rows-cache-engine.ts +921 -0
- package/src/services/database/rows-exec.integration.test.ts +589 -0
- package/src/services/database/rows-exec.ts +1027 -0
- package/src/services/database/rows-prewarm.ts +225 -0
- package/src/services/database/rows-store.test.ts +635 -0
- package/src/services/database/rows-store.ts +1208 -0
- package/src/services/database/rows-transport.fixture.ts +151 -0
- package/src/services/database/rows-worker.ts +588 -0
- package/src/services/database/sqlite-cache-engine.test.ts +649 -0
- package/src/services/database/sqlite-cache-engine.timeout.test.ts +61 -0
- package/src/services/database/sqlite-cache-engine.ts +1422 -0
- package/src/services/database/sqlite-column-reset.integration.test.ts +100 -0
- package/src/services/database/sqlite-column-reset.ts +91 -0
- package/src/services/database/sqlite-devtools-queries.integration.test.ts +143 -0
- package/src/services/database/sqlite-devtools-queries.test.ts +154 -0
- package/src/services/database/sqlite-lock-verify.test.ts +33 -0
- package/src/services/database/sqlite-lock-verify.ts +45 -0
- package/src/services/database/sqlite-open.test.ts +150 -0
- package/src/services/database/sqlite-open.ts +164 -0
- package/src/services/database/sqlite-plan-sql.test.ts +164 -0
- package/src/services/database/sqlite-plan-sql.ts +196 -0
- package/src/services/database/sqlite-projection.test.ts +121 -0
- package/src/services/database/sqlite-select.integration.test.ts +185 -0
- package/src/services/database/sqlite-select.test.ts +261 -0
- package/src/services/database/sqlite-select.ts +131 -0
- package/src/services/database/sqlite-transport.fixture.ts +30 -0
- package/src/services/database/sqlite-transport.ts +231 -0
- package/src/services/database/sqlite-worker.ts +437 -0
- package/src/services/database/surql-translate.ts +417 -0
- package/src/services/database/surreal-cache-engine.ts +163 -0
- package/src/services/logger/index.test.ts +132 -0
- package/src/services/logger/index.ts +187 -6
- package/src/services/persistence/surrealdb.ts +2 -2
- package/src/services/stream-processor/index.ts +621 -93
- package/src/services/stream-processor/stream-processor.batch.test.ts +57 -7
- package/src/services/stream-processor/stream-processor.prime.test.ts +234 -0
- package/src/services/stream-processor/stream-processor.reset.test.ts +226 -0
- package/src/services/stream-processor/wasm-types.ts +41 -1
- package/src/services/tabs/broker-client.ts +284 -0
- package/src/services/tabs/broker.test.ts +381 -0
- package/src/services/tabs/coordinator.test.ts +386 -0
- package/src/services/tabs/coordinator.ts +646 -0
- package/src/services/tabs/fake-ports.fixture.ts +112 -0
- package/src/services/tabs/leader-locks.ts +75 -0
- package/src/services/tabs/protocol.ts +262 -0
- package/src/services/tabs/support.ts +38 -0
- package/src/services/tabs/tabs-broker-worker.ts +652 -0
- package/src/sp00ky.ts +5 -648
- package/src/state/client-state.ts +231 -0
- package/src/state/lifecycle.test.ts +184 -0
- package/src/state/lifecycle.ts +127 -0
- package/src/state/reducers.test.ts +337 -0
- package/src/state/reducers.ts +571 -0
- package/src/state/selectors.test.ts +203 -0
- package/src/state/selectors.ts +264 -0
- package/src/sw/index.test.ts +582 -0
- package/src/sw/index.ts +607 -0
- package/src/sw/store.ts +96 -0
- package/src/sync/connection.saga.test.ts +97 -0
- package/src/sync/connection.saga.ts +89 -0
- package/src/sync/live.saga.test.ts +229 -0
- package/src/sync/live.saga.ts +116 -0
- package/src/sync/policy.health.test.ts +56 -0
- package/src/{modules/sync/utils.test.ts → sync/policy.test.ts} +96 -11
- package/src/{modules/sync/utils.ts → sync/policy.ts} +186 -7
- package/src/sync/poll.saga.test.ts +51 -0
- package/src/sync/poll.saga.ts +36 -0
- package/src/sync/tabs.saga.test.ts +78 -0
- package/src/sync/tabs.saga.ts +96 -0
- package/src/testing/adapters.ts +137 -0
- package/src/testing/build.ts +63 -0
- package/src/testing/fake-services.ts +63 -0
- package/src/testing/run-pure.test.ts +92 -0
- package/src/testing/run-pure.ts +128 -0
- package/src/testing/services.ts +17 -0
- package/src/types.ts +601 -25
- package/src/utils/blurhash.ts +90 -0
- package/src/utils/edges.ts +57 -0
- package/src/utils/error-classification.test.ts +116 -0
- package/src/utils/error-classification.ts +74 -0
- package/src/utils/index.ts +58 -3
- package/src/utils/parser.test.ts +67 -102
- package/src/utils/parser.ts +62 -1
- package/src/utils/semver.test.ts +32 -0
- package/src/utils/semver.ts +30 -0
- package/src/utils/sha256.ts +15 -0
- package/src/utils/surql.ts +17 -15
- package/src/utils/utils.test.ts +3 -2
- package/tsdown.config.ts +105 -4
- package/vitest.config.ts +52 -0
- package/src/modules/cache/index.ts +0 -253
- package/src/modules/cache/types.ts +0 -19
- package/src/modules/crdt/crdt-hydration.test.ts +0 -206
- package/src/modules/data/data.status.test.ts +0 -108
- package/src/modules/data/data.test.ts +0 -58
- package/src/modules/data/index.ts +0 -1491
- package/src/modules/sync/engine.ts +0 -227
- package/src/modules/sync/events/index.ts +0 -84
- package/src/modules/sync/index.ts +0 -3
- package/src/modules/sync/queue/index.ts +0 -2
- package/src/modules/sync/queue/queue-down.ts +0 -90
- package/src/modules/sync/queue/queue-up.ts +0 -224
- package/src/modules/sync/scheduler.ts +0 -121
- package/src/modules/sync/sync.ts +0 -1244
- package/src/sp00ky.auth-order.test.ts +0 -65
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
/// <reference lib="webworker" />
|
|
2
|
+
/**
|
|
3
|
+
* Dedicated Web Worker that owns a bucket's row store (`rows-store.ts`): the
|
|
4
|
+
* OPFS sync access handles it reads and writes through exist only in a
|
|
5
|
+
* dedicated worker, and are exclusive, so one worker per bucket holds them and
|
|
6
|
+
* every tab's reads and writes go through it.
|
|
7
|
+
*
|
|
8
|
+
* It speaks the request/response protocol of the SQLite worker (requests keyed
|
|
9
|
+
* by `id`, replies on the channel the request came in on), with the same
|
|
10
|
+
* lifecycle messages, so the engine's transport, its shared-tabs roles and the
|
|
11
|
+
* leader fencing work unchanged:
|
|
12
|
+
*
|
|
13
|
+
* { id, type: 'open', payload: { dbName, useOpfs, workerLockName?, openOptions?, share?, reader? } }
|
|
14
|
+
* -> { id, ok, persisted, opfsError? }
|
|
15
|
+
* { id, type: 'close' | 'shutdown' | 'relock' | 'add-client' | 'remove-client' | 'diag' }
|
|
16
|
+
* every other type is a data op, answered by `handleRowsOp` (rows-exec.ts)
|
|
17
|
+
*
|
|
18
|
+
* Rows travel as JSON text in a transferred buffer, in both directions.
|
|
19
|
+
*
|
|
20
|
+
* Housekeeping runs on the same chain as the ops, in the quiet after them:
|
|
21
|
+
* unflushed writes are flushed within {@link FLUSH_LAG_MS}, the index is
|
|
22
|
+
* persisted after {@link IDLE_MS} without traffic (and at once when the log
|
|
23
|
+
* written since the last checkpoint grows past its bound), and dead bytes are
|
|
24
|
+
* compacted away when they outweigh the live ones.
|
|
25
|
+
*/
|
|
26
|
+
import { verifyLockStillHeld as verifyLockStillHeldBounded } from './sqlite-lock-verify';
|
|
27
|
+
import { MemoryFile, RowStore, bucketDirName, type StoreIo, type SyncFile } from './rows-store';
|
|
28
|
+
import {
|
|
29
|
+
CHECKPOINT_TAIL_BYTES,
|
|
30
|
+
CHECKPOINT_TAIL_OPS,
|
|
31
|
+
ROWS_CLIENT_OPS,
|
|
32
|
+
ROWS_PROTOCOL,
|
|
33
|
+
RowsExec,
|
|
34
|
+
handleReaderOp,
|
|
35
|
+
handleRowsOp,
|
|
36
|
+
maintenance,
|
|
37
|
+
visibleTables,
|
|
38
|
+
} from './rows-exec';
|
|
39
|
+
import { ROWS_AHEAD_ID, ROWS_AHEAD_OPS } from './rows-prewarm';
|
|
40
|
+
|
|
41
|
+
type PostTarget = Pick<MessagePort, 'postMessage'>;
|
|
42
|
+
|
|
43
|
+
interface OpenOptions {
|
|
44
|
+
maxAttempts?: number;
|
|
45
|
+
backoffMs?: number[];
|
|
46
|
+
disallowMemoryFallback?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Retry schedule for an open that finds the files held. The usual holder is
|
|
51
|
+
* this tab's previous worker, whose handles the browser releases a moment
|
|
52
|
+
* after a reload, so the first retries come within milliseconds: a reload
|
|
53
|
+
* should not wait a quarter second for a file that is free after five. The
|
|
54
|
+
* whole ramp still gives another tab about as long as the SQLite worker does
|
|
55
|
+
* (750 ms) before falling back to memory.
|
|
56
|
+
*/
|
|
57
|
+
const DEFAULT_BACKOFF_MS = [4, 8, 16, 32, 64, 128, 250, 250];
|
|
58
|
+
const DEFAULT_MAX_ATTEMPTS = DEFAULT_BACKOFF_MS.length + 1;
|
|
59
|
+
|
|
60
|
+
/** How long a write may sit with the operating system before it is flushed. */
|
|
61
|
+
const FLUSH_LAG_MS = 100;
|
|
62
|
+
/** Quiet time after which the index is persisted and the store tidied. */
|
|
63
|
+
const IDLE_MS = 500;
|
|
64
|
+
|
|
65
|
+
class OpfsFile implements SyncFile {
|
|
66
|
+
constructor(private access: FileSystemSyncAccessHandle) {}
|
|
67
|
+
read(buffer: Uint8Array, at: number): number {
|
|
68
|
+
return this.access.read(buffer, { at });
|
|
69
|
+
}
|
|
70
|
+
write(buffer: Uint8Array, at: number): number {
|
|
71
|
+
const written = this.access.write(buffer, { at });
|
|
72
|
+
// A short write is a full disk: fail the batch rather than store part of it.
|
|
73
|
+
if (written !== buffer.length) throw new Error(`rows: wrote ${written} of ${buffer.length} bytes (storage full?)`);
|
|
74
|
+
return written;
|
|
75
|
+
}
|
|
76
|
+
size(): number {
|
|
77
|
+
return this.access.getSize();
|
|
78
|
+
}
|
|
79
|
+
truncate(size: number): void {
|
|
80
|
+
this.access.truncate(size);
|
|
81
|
+
}
|
|
82
|
+
flush(): void {
|
|
83
|
+
this.access.flush();
|
|
84
|
+
}
|
|
85
|
+
close(): void {
|
|
86
|
+
this.access.close();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let store: RowStore | null = null;
|
|
91
|
+
let exec: RowsExec | null = null;
|
|
92
|
+
/** The open store is a reader's: it answers reads beside another worker's writes and does no housekeeping. */
|
|
93
|
+
let reading = false;
|
|
94
|
+
/** What the open store was opened as, so a second `open` for the same thing is a no-op. */
|
|
95
|
+
let opened: { dbName: string; useOpfs: boolean; mode: FileMode; result: { persisted: boolean; opfsError?: string } } | null = null;
|
|
96
|
+
/** Handles held for the open store, closed with it. */
|
|
97
|
+
let openFiles: SyncFile[] = [];
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* How the store's files are opened.
|
|
101
|
+
* `own` the default: one worker holds them, any other fails to open.
|
|
102
|
+
* `share` a shared-tabs leader that lets followers read the file beside it.
|
|
103
|
+
* `reader` such a follower: it only reads (`RowStore` in reader mode).
|
|
104
|
+
* The last two use `readwrite-unsafe` handles (Chrome 121+), which several
|
|
105
|
+
* workers can hold on one file. Nothing but the leader's Web Lock then stands
|
|
106
|
+
* between two writers, which is why sharing is something an app asks for.
|
|
107
|
+
*/
|
|
108
|
+
type FileMode = 'own' | 'share' | 'reader';
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Whether this browser opens a second `readwrite-unsafe` handle on a file. One
|
|
112
|
+
* that does not know the option ignores it and hands out the exclusive handle,
|
|
113
|
+
* so the only way to know is to try, on a file of no importance.
|
|
114
|
+
*/
|
|
115
|
+
async function canShareFiles(dir: FileSystemDirectoryHandle): Promise<boolean> {
|
|
116
|
+
const handles: FileSystemSyncAccessHandle[] = [];
|
|
117
|
+
try {
|
|
118
|
+
const probe = await dir.getFileHandle('probe', { create: true });
|
|
119
|
+
// oxlint-disable-next-line typescript/no-explicit-any
|
|
120
|
+
const open = (): Promise<FileSystemSyncAccessHandle> => (probe as any).createSyncAccessHandle({ mode: 'readwrite-unsafe' });
|
|
121
|
+
handles.push(await open());
|
|
122
|
+
handles.push(await open());
|
|
123
|
+
return true;
|
|
124
|
+
} catch {
|
|
125
|
+
return false;
|
|
126
|
+
} finally {
|
|
127
|
+
for (const handle of handles) handle.close();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function opfsIo(bucketId: string, mode: FileMode = 'own'): Promise<StoreIo> {
|
|
132
|
+
const root = await navigator.storage.getDirectory();
|
|
133
|
+
const dir = await root.getDirectoryHandle(bucketDirName(bucketId), { create: true });
|
|
134
|
+
let shared = false;
|
|
135
|
+
if (mode !== 'own') {
|
|
136
|
+
shared = await canShareFiles(dir);
|
|
137
|
+
// A leader without the option leads as before; a reader has nothing to read with.
|
|
138
|
+
if (!shared && mode === 'reader') throw new Error('Missing required OPFS APIs: shared access handles');
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
open: async (name) => {
|
|
142
|
+
const handle = await dir.getFileHandle(name, { create: true });
|
|
143
|
+
// oxlint-disable-next-line typescript/no-explicit-any
|
|
144
|
+
const access = await (shared ? (handle as any).createSyncAccessHandle({ mode: 'readwrite-unsafe' }) : handle.createSyncAccessHandle());
|
|
145
|
+
const file = new OpfsFile(access as FileSystemSyncAccessHandle);
|
|
146
|
+
openFiles.push(file);
|
|
147
|
+
return file;
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function memoryIo(): StoreIo {
|
|
153
|
+
const files = { a: new MemoryFile(), b: new MemoryFile() };
|
|
154
|
+
return { open: (name) => files[name] };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function closeFiles(): void {
|
|
158
|
+
for (const file of openFiles) {
|
|
159
|
+
try {
|
|
160
|
+
file.close();
|
|
161
|
+
} catch {
|
|
162
|
+
/* already closed */
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
openFiles = [];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const errMessage = (e: unknown): string =>
|
|
169
|
+
e instanceof Error ? (e.name && e.name !== 'Error' ? `${e.name}: ${e.message}` : e.message) : String(e);
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Open `bucketId`'s store. Sync access handles are exclusive, so a second
|
|
173
|
+
* worker on the same bucket (another tab that is still closing) fails here:
|
|
174
|
+
* retry, then fall back to memory and say so loudly, as the SQLite worker
|
|
175
|
+
* does. A caller that must not run in memory (a shared-tabs leader) gets the
|
|
176
|
+
* error instead.
|
|
177
|
+
*/
|
|
178
|
+
async function openStore(
|
|
179
|
+
bucketId: string,
|
|
180
|
+
useOpfs: boolean,
|
|
181
|
+
opts: OpenOptions = {},
|
|
182
|
+
mode: FileMode = 'own'
|
|
183
|
+
): Promise<{ persisted: boolean; opfsError?: string }> {
|
|
184
|
+
reading = false;
|
|
185
|
+
if (!useOpfs) {
|
|
186
|
+
store = await RowStore.open(memoryIo());
|
|
187
|
+
exec = new RowsExec(store);
|
|
188
|
+
return { persisted: false };
|
|
189
|
+
}
|
|
190
|
+
const maxAttempts = Math.max(1, opts.maxAttempts ?? DEFAULT_MAX_ATTEMPTS);
|
|
191
|
+
const backoffMs = opts.backoffMs ?? DEFAULT_BACKOFF_MS;
|
|
192
|
+
let lastError = 'unknown error';
|
|
193
|
+
let attempts = 0;
|
|
194
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
195
|
+
attempts = attempt;
|
|
196
|
+
try {
|
|
197
|
+
if (!navigator.storage?.getDirectory) throw new Error('Missing required OPFS APIs');
|
|
198
|
+
store = await RowStore.open(await opfsIo(bucketId, mode), { reader: mode === 'reader' });
|
|
199
|
+
exec = new RowsExec(store, mode === 'reader');
|
|
200
|
+
reading = mode === 'reader';
|
|
201
|
+
return { persisted: true };
|
|
202
|
+
} catch (e) {
|
|
203
|
+
closeFiles();
|
|
204
|
+
lastError = errMessage(e);
|
|
205
|
+
if (attempt === maxAttempts || lastError.includes('Missing required OPFS APIs')) break;
|
|
206
|
+
await new Promise((resolve) => setTimeout(resolve, backoffMs[Math.min(attempt - 1, backoffMs.length - 1)] ?? 0));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// A reader in memory would read nothing of the leader's: it has no fallback.
|
|
210
|
+
if (opts.disallowMemoryFallback || mode === 'reader') throw new Error(`opfs-unavailable: ${lastError} (after ${attempts} attempts)`);
|
|
211
|
+
// Deliberately console, not a logger: host apps set their own log level, and
|
|
212
|
+
// losing durability must never be filtered into silence.
|
|
213
|
+
// oxlint-disable-next-line no-console
|
|
214
|
+
console.error(
|
|
215
|
+
`[sp00ky] OPFS persistence unavailable for "${bucketId}" after ${attempts} attempt${attempts === 1 ? '' : 's'}: ` +
|
|
216
|
+
`${lastError}. The local row store is running IN MEMORY, which keeps the whole dataset in RAM and loses ` +
|
|
217
|
+
'every local write on reload. The usual cause is another tab of this app holding the storage lock, so ' +
|
|
218
|
+
'closing the other tabs and reloading restores persistence.'
|
|
219
|
+
);
|
|
220
|
+
store = await RowStore.open(memoryIo());
|
|
221
|
+
exec = new RowsExec(store);
|
|
222
|
+
return { persisted: false, opfsError: lastError };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** Persist the index and let go of the files. */
|
|
226
|
+
function closeStore(): void {
|
|
227
|
+
clearTimers();
|
|
228
|
+
try {
|
|
229
|
+
store?.checkpoint();
|
|
230
|
+
} catch {
|
|
231
|
+
/* the log already holds every write; the next open replays it */
|
|
232
|
+
}
|
|
233
|
+
try {
|
|
234
|
+
store?.close();
|
|
235
|
+
} catch {
|
|
236
|
+
/* ignore */
|
|
237
|
+
}
|
|
238
|
+
store = null;
|
|
239
|
+
exec = null;
|
|
240
|
+
opened = null;
|
|
241
|
+
reading = false;
|
|
242
|
+
warmQueue = null;
|
|
243
|
+
closeFiles();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// ==================== housekeeping ====================
|
|
247
|
+
|
|
248
|
+
let flushTimer: ReturnType<typeof setTimeout> | null = null;
|
|
249
|
+
let idleTimer: ReturnType<typeof setTimeout> | null = null;
|
|
250
|
+
|
|
251
|
+
function clearTimers(): void {
|
|
252
|
+
if (flushTimer) clearTimeout(flushTimer);
|
|
253
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
254
|
+
flushTimer = null;
|
|
255
|
+
idleTimer = null;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function afterOp(wrote: boolean): void {
|
|
259
|
+
if (!store) return;
|
|
260
|
+
if (wrote) {
|
|
261
|
+
const stats = store.stats();
|
|
262
|
+
// Bound what the next open has to replay, even under constant writing.
|
|
263
|
+
if (stats.tailBytes > CHECKPOINT_TAIL_BYTES || stats.tailOps > CHECKPOINT_TAIL_OPS) store.checkpoint();
|
|
264
|
+
else if (!flushTimer) {
|
|
265
|
+
flushTimer = setTimeout(() => {
|
|
266
|
+
flushTimer = null;
|
|
267
|
+
enqueue(() => store?.flush());
|
|
268
|
+
}, FLUSH_LAG_MS);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
272
|
+
idleTimer = setTimeout(() => {
|
|
273
|
+
idleTimer = null;
|
|
274
|
+
enqueue(tidy);
|
|
275
|
+
}, IDLE_MS);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
async function tidy(): Promise<void> {
|
|
279
|
+
if (!store) return;
|
|
280
|
+
store.flush();
|
|
281
|
+
// A checkpoint, then at most a compaction and the checkpoint after it.
|
|
282
|
+
for (let round = 0; round < 3 && store; round++) {
|
|
283
|
+
const step = maintenance(store.stats());
|
|
284
|
+
if (!step) break;
|
|
285
|
+
if (step === 'checkpoint') store.checkpoint();
|
|
286
|
+
else await store.compact();
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// ==================== leader fencing (worker web lock) ====================
|
|
291
|
+
// Same scheme as the SQLite worker: a Web Lock named per leadership, held for
|
|
292
|
+
// the store's lifetime. Losing it without having released it means the broker
|
|
293
|
+
// gave the bucket to another tab, and this worker must never write again.
|
|
294
|
+
|
|
295
|
+
let fenced = false;
|
|
296
|
+
|
|
297
|
+
interface HeldLock {
|
|
298
|
+
name: string;
|
|
299
|
+
release: () => void;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
let currentLock: HeldLock | null = null;
|
|
303
|
+
|
|
304
|
+
function workerLocks(): LockManager | null {
|
|
305
|
+
const nav = (globalThis as { navigator?: { locks?: LockManager } }).navigator;
|
|
306
|
+
return nav?.locks && typeof nav.locks.request === 'function' ? nav.locks : null;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function acquireWorkerLock(name: string): Promise<HeldLock | null> {
|
|
310
|
+
const locks = workerLocks();
|
|
311
|
+
if (!locks) return Promise.resolve({ name, release() {} });
|
|
312
|
+
return new Promise<HeldLock | null>((resolve) => {
|
|
313
|
+
let granted = false;
|
|
314
|
+
let intentional = false;
|
|
315
|
+
let releaseGrant: (() => void) | null = null;
|
|
316
|
+
locks
|
|
317
|
+
.request(name, { mode: 'exclusive', ifAvailable: true }, (lock) => {
|
|
318
|
+
if (!lock) {
|
|
319
|
+
resolve(null);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
granted = true;
|
|
323
|
+
resolve({
|
|
324
|
+
name,
|
|
325
|
+
release() {
|
|
326
|
+
intentional = true;
|
|
327
|
+
releaseGrant?.();
|
|
328
|
+
},
|
|
329
|
+
});
|
|
330
|
+
return new Promise<void>((release) => {
|
|
331
|
+
releaseGrant = release;
|
|
332
|
+
});
|
|
333
|
+
})
|
|
334
|
+
.then(
|
|
335
|
+
() => {
|
|
336
|
+
if (granted && !intentional) fence('worker lock stolen');
|
|
337
|
+
},
|
|
338
|
+
() => {
|
|
339
|
+
if (granted && !intentional) fence('worker lock request failed');
|
|
340
|
+
}
|
|
341
|
+
);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function releaseHeldLock(): void {
|
|
346
|
+
currentLock?.release();
|
|
347
|
+
currentLock = null;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** Terminal: close the files without another write, tell the owner, stop. */
|
|
351
|
+
function fence(reason: string): void {
|
|
352
|
+
if (fenced) return;
|
|
353
|
+
fenced = true;
|
|
354
|
+
// oxlint-disable-next-line no-console
|
|
355
|
+
console.error(
|
|
356
|
+
`[sp00ky] row store worker fenced (${reason}): leadership was taken over, ` +
|
|
357
|
+
'closing the store and refusing further ops.'
|
|
358
|
+
);
|
|
359
|
+
clearTimers();
|
|
360
|
+
// No checkpoint: the new leader owns the file now.
|
|
361
|
+
store = null;
|
|
362
|
+
exec = null;
|
|
363
|
+
opened = null;
|
|
364
|
+
closeFiles();
|
|
365
|
+
try {
|
|
366
|
+
(self as unknown as Worker).postMessage({ type: 'lock-lost', reason });
|
|
367
|
+
} catch {
|
|
368
|
+
/* owner gone */
|
|
369
|
+
}
|
|
370
|
+
releaseHeldLock();
|
|
371
|
+
self.close();
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// A frozen tab's worker resumes with its queue intact, and a queued write could
|
|
375
|
+
// run before the lock-steal callback does. After a long gap, ops wait for a
|
|
376
|
+
// lock check first. See the SQLite worker for the reasoning behind the bound.
|
|
377
|
+
const FREEZE_SUSPECT_MS = 10_000;
|
|
378
|
+
let lastTickAt = performance.now();
|
|
379
|
+
let thawVerification: Promise<void> | null = null;
|
|
380
|
+
|
|
381
|
+
function noteTick(): void {
|
|
382
|
+
const now = performance.now();
|
|
383
|
+
const gap = now - lastTickAt;
|
|
384
|
+
lastTickAt = now;
|
|
385
|
+
if (gap > FREEZE_SUSPECT_MS && currentLock && !fenced && !thawVerification) {
|
|
386
|
+
thawVerification = verifyLockStillHeldBounded(
|
|
387
|
+
// oxlint-disable-next-line typescript/no-explicit-any
|
|
388
|
+
workerLocks() as any,
|
|
389
|
+
currentLock?.name,
|
|
390
|
+
(reason) => Promise.resolve(fence(reason)),
|
|
391
|
+
undefined,
|
|
392
|
+
// oxlint-disable-next-line no-console
|
|
393
|
+
(msg) => console.warn(`[rows-worker] ${msg}`)
|
|
394
|
+
).finally(() => {
|
|
395
|
+
thawVerification = null;
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
setInterval(noteTick, 1000);
|
|
400
|
+
|
|
401
|
+
// ==================== dispatch ====================
|
|
402
|
+
|
|
403
|
+
const clients = new Map<string, MessagePort>();
|
|
404
|
+
|
|
405
|
+
/** One chain for every op from every channel, housekeeping included. */
|
|
406
|
+
let opChain: Promise<unknown> = Promise.resolve();
|
|
407
|
+
|
|
408
|
+
/** Ops queued or running, and when the last one finished. */
|
|
409
|
+
let pendingOps = 0;
|
|
410
|
+
let lastOpAt = 0;
|
|
411
|
+
|
|
412
|
+
function enqueue<T>(fn: () => T | Promise<T>): Promise<T> {
|
|
413
|
+
pendingOps++;
|
|
414
|
+
const result = opChain.then(fn, fn);
|
|
415
|
+
const settle = (): void => {
|
|
416
|
+
pendingOps--;
|
|
417
|
+
lastOpAt = performance.now();
|
|
418
|
+
};
|
|
419
|
+
opChain = result.then(
|
|
420
|
+
() => settle(),
|
|
421
|
+
() => settle()
|
|
422
|
+
);
|
|
423
|
+
return result;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// ---- warming ----
|
|
427
|
+
// Reading every index at once took 15 to 20 ms on an 80,000 row store, and a
|
|
428
|
+
// request that arrived meanwhile waited for all of it: the page's first read
|
|
429
|
+
// came back slower than with no warming at all. So a table is read per turn,
|
|
430
|
+
// and only once the worker has been left alone for a moment. A request never
|
|
431
|
+
// waits for more than the one table being read.
|
|
432
|
+
|
|
433
|
+
const WARM_QUIET_MS = 15;
|
|
434
|
+
/** Tables whose index is still to be read; null when there is nothing to warm. */
|
|
435
|
+
let warmQueue: string[] | null = null;
|
|
436
|
+
let warmTimer: ReturnType<typeof setTimeout> | null = null;
|
|
437
|
+
|
|
438
|
+
function warmSoon(delay: number): void {
|
|
439
|
+
if (warmTimer === null) warmTimer = setTimeout(warmStep, delay);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function warmStep(): void {
|
|
443
|
+
warmTimer = null;
|
|
444
|
+
if (!warmQueue || !store || fenced) {
|
|
445
|
+
warmQueue = null;
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
if (pendingOps > 0 || performance.now() - lastOpAt < WARM_QUIET_MS) return warmSoon(WARM_QUIET_MS);
|
|
449
|
+
const table = warmQueue.shift();
|
|
450
|
+
if (table === undefined) {
|
|
451
|
+
warmQueue = null;
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
try {
|
|
455
|
+
// No op is running (the count is zero), so this reads beside none.
|
|
456
|
+
store.ordered(table);
|
|
457
|
+
} catch {
|
|
458
|
+
/* whatever is wrong with this index, the read that needs it reports */
|
|
459
|
+
}
|
|
460
|
+
warmSoon(0);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// oxlint-disable-next-line typescript/no-explicit-any
|
|
464
|
+
async function handle(type: string, payload: any, source: 'owner' | 'client'): Promise<{ result: object; transfer?: Transferable[] }> {
|
|
465
|
+
if (fenced) throw new Error('rows: fenced, leadership was taken over');
|
|
466
|
+
if (source === 'client' && !ROWS_CLIENT_OPS.has(type)) {
|
|
467
|
+
throw new Error(`rows worker: op ${type} is not allowed on a client port`);
|
|
468
|
+
}
|
|
469
|
+
switch (type) {
|
|
470
|
+
case 'open': {
|
|
471
|
+
if (payload.workerLockName) {
|
|
472
|
+
const lock = await acquireWorkerLock(payload.workerLockName);
|
|
473
|
+
if (!lock) throw new Error('worker-lock-unavailable');
|
|
474
|
+
releaseHeldLock();
|
|
475
|
+
currentLock = lock;
|
|
476
|
+
}
|
|
477
|
+
// The page may have started this worker and its store ahead of itself
|
|
478
|
+
// (`prewarmRows`): the store it asks for is then already open.
|
|
479
|
+
const mode: FileMode = payload.reader ? 'reader' : payload.share ? 'share' : 'own';
|
|
480
|
+
const same =
|
|
481
|
+
store !== null && opened !== null && opened.dbName === payload.dbName && opened.useOpfs === payload.useOpfs && opened.mode === mode;
|
|
482
|
+
if (!same) {
|
|
483
|
+
closeStore();
|
|
484
|
+
const result = await openStore(payload.dbName, payload.useOpfs, payload.openOptions, mode);
|
|
485
|
+
opened = { dbName: payload.dbName, useOpfs: payload.useOpfs, mode, result };
|
|
486
|
+
}
|
|
487
|
+
return { result: { ...opened!.result, proto: ROWS_PROTOCOL, workerUrl: self.location.href } };
|
|
488
|
+
}
|
|
489
|
+
case 'warm':
|
|
490
|
+
// Read the tables' indexes ahead of the page, so its first query finds
|
|
491
|
+
// them in memory. One table at a time and only while nothing is asked
|
|
492
|
+
// for: see `warmStep`.
|
|
493
|
+
warmQueue = exec ? exec.warmOrder() : null;
|
|
494
|
+
warmSoon(WARM_QUIET_MS);
|
|
495
|
+
return { result: {} };
|
|
496
|
+
case 'relock': {
|
|
497
|
+
const lock = await acquireWorkerLock(payload.workerLockName);
|
|
498
|
+
if (!lock) throw new Error('worker-lock-unavailable');
|
|
499
|
+
releaseHeldLock();
|
|
500
|
+
currentLock = lock;
|
|
501
|
+
return { result: {} };
|
|
502
|
+
}
|
|
503
|
+
case 'close':
|
|
504
|
+
closeStore();
|
|
505
|
+
releaseHeldLock();
|
|
506
|
+
return { result: {} };
|
|
507
|
+
case 'shutdown':
|
|
508
|
+
// Graceful pagehide: persist the index and release the handles now, so
|
|
509
|
+
// the next leader's open does not wait for this worker to be collected.
|
|
510
|
+
closeStore();
|
|
511
|
+
releaseHeldLock();
|
|
512
|
+
queueMicrotask(() => self.close());
|
|
513
|
+
return { result: {} };
|
|
514
|
+
case 'remove-client': {
|
|
515
|
+
clients.get(payload.clientId)?.close();
|
|
516
|
+
clients.delete(payload.clientId);
|
|
517
|
+
return { result: {} };
|
|
518
|
+
}
|
|
519
|
+
case 'diag': {
|
|
520
|
+
if (!store) throw new Error('rows: store not open');
|
|
521
|
+
store.refresh();
|
|
522
|
+
const stats = store.stats();
|
|
523
|
+
const tableCounts = payload?.tableCounts
|
|
524
|
+
? visibleTables(store).map((table) => ({ table, rows: store!.count(table) }))
|
|
525
|
+
: undefined;
|
|
526
|
+
return { result: { stats, tableCounts } };
|
|
527
|
+
}
|
|
528
|
+
default: {
|
|
529
|
+
if (!store || !exec) throw new Error('rows: store not open');
|
|
530
|
+
if (reading) {
|
|
531
|
+
const answer = await handleReaderOp(exec, store, type, payload);
|
|
532
|
+
if (!answer) throw new Error(`rows worker: unknown message ${type}`);
|
|
533
|
+
return answer;
|
|
534
|
+
}
|
|
535
|
+
const reply = await handleRowsOp(exec, store, type, payload);
|
|
536
|
+
if (!reply) throw new Error(`rows worker: unknown message ${type}`);
|
|
537
|
+
afterOp(type === 'write' || type === 'reset-versions' || type === 'blob-put' || type === 'blob-del');
|
|
538
|
+
return reply;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// oxlint-disable-next-line typescript/no-explicit-any
|
|
544
|
+
function dispatch(target: PostTarget, data: any, source: 'owner' | 'client'): void {
|
|
545
|
+
const { id, type, payload } = data ?? {};
|
|
546
|
+
noteTick();
|
|
547
|
+
// What a page head replays from localStorage (`prewarmRows`) is a read, whatever the storage says.
|
|
548
|
+
if (typeof id === 'number' && id <= ROWS_AHEAD_ID && !ROWS_AHEAD_OPS.has(type)) {
|
|
549
|
+
target.postMessage({ id, ok: false, error: 'rows worker: only reads may be asked ahead' });
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
void enqueue(async () => {
|
|
553
|
+
const t0 = performance.now();
|
|
554
|
+
try {
|
|
555
|
+
if (thawVerification) await thawVerification;
|
|
556
|
+
const { result, transfer } = await handle(type, payload, source);
|
|
557
|
+
// `wt` is the time spent in here, so the page can tell work from transit.
|
|
558
|
+
target.postMessage({ id, ok: true, wt: performance.now() - t0, ...result }, transfer ?? []);
|
|
559
|
+
} catch (err) {
|
|
560
|
+
target.postMessage({ id, ok: false, error: err instanceof Error ? err.message : String(err) });
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
self.onmessage = (ev: MessageEvent) => {
|
|
566
|
+
const data = ev.data ?? {};
|
|
567
|
+
// Handled off the chain: registering a port must not wait behind a long op,
|
|
568
|
+
// or the follower's first requests would deadlock its attach.
|
|
569
|
+
if (data.type === 'add-client') {
|
|
570
|
+
const port = ev.ports?.[0];
|
|
571
|
+
const clientId = data.payload?.clientId as string | undefined;
|
|
572
|
+
if (!port || !clientId) {
|
|
573
|
+
(self as unknown as Worker).postMessage({
|
|
574
|
+
id: data.id,
|
|
575
|
+
ok: false,
|
|
576
|
+
error: 'rows worker: add-client needs a clientId and a transferred port',
|
|
577
|
+
});
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
clients.get(clientId)?.close();
|
|
581
|
+
clients.set(clientId, port);
|
|
582
|
+
port.onmessage = (pe: MessageEvent) => dispatch(port, pe.data, 'client');
|
|
583
|
+
port.start?.();
|
|
584
|
+
(self as unknown as Worker).postMessage({ id: data.id, ok: true, wt: 0 });
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
dispatch(self as unknown as Worker, data, 'owner');
|
|
588
|
+
};
|