@taladb/web 0.7.10 → 0.8.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/package.json +1 -1
- package/pkg/package.json +1 -1
- package/pkg/taladb_web.d.ts +2 -2
- package/pkg/taladb_web.js +4 -4
- package/pkg/taladb_web_bg.wasm +0 -0
- package/pkg/taladb_web_bg.wasm.d.ts +2 -2
- package/worker/taladb.worker.js +27 -2
package/package.json
CHANGED
package/pkg/package.json
CHANGED
package/pkg/taladb_web.d.ts
CHANGED
|
@@ -416,12 +416,12 @@ export interface InitOutput {
|
|
|
416
416
|
readonly idb_load_snapshot: (a: number, b: number) => any;
|
|
417
417
|
readonly idb_save_snapshot: (a: number, b: number, c: number, d: number) => any;
|
|
418
418
|
readonly opfs_open_backend: (a: number, b: number) => any;
|
|
419
|
-
readonly
|
|
419
|
+
readonly wasm_bindgen__closure__destroy__h960c953e41cc5153: (a: number, b: number) => void;
|
|
420
420
|
readonly wasm_bindgen__closure__destroy__h48e8a8f67ee293c6: (a: number, b: number) => void;
|
|
421
421
|
readonly wasm_bindgen__closure__destroy__h8b8dc50e88fa67bc: (a: number, b: number) => void;
|
|
422
422
|
readonly wasm_bindgen__convert__closures_____invoke__hfb64ebab929241fc: (a: number, b: number, c: any) => [number, number];
|
|
423
423
|
readonly wasm_bindgen__convert__closures_____invoke__h31b79bb0cf86afae: (a: number, b: number, c: any, d: any) => void;
|
|
424
|
-
readonly
|
|
424
|
+
readonly wasm_bindgen__convert__closures_____invoke__hc4897ede22d87615: (a: number, b: number, c: any) => void;
|
|
425
425
|
readonly wasm_bindgen__convert__closures_____invoke__had96e062ebd712a6: (a: number, b: number) => void;
|
|
426
426
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
427
427
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
package/pkg/taladb_web.js
CHANGED
|
@@ -1636,8 +1636,8 @@ function __wbg_get_imports() {
|
|
|
1636
1636
|
return ret;
|
|
1637
1637
|
},
|
|
1638
1638
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
1639
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx:
|
|
1640
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
1639
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 138, function: Function { arguments: [Externref], shim_idx: 139, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1640
|
+
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h960c953e41cc5153, wasm_bindgen__convert__closures_____invoke__hc4897ede22d87615);
|
|
1641
1641
|
return ret;
|
|
1642
1642
|
},
|
|
1643
1643
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
@@ -1697,8 +1697,8 @@ function wasm_bindgen__convert__closures_____invoke__had96e062ebd712a6(arg0, arg
|
|
|
1697
1697
|
wasm.wasm_bindgen__convert__closures_____invoke__had96e062ebd712a6(arg0, arg1);
|
|
1698
1698
|
}
|
|
1699
1699
|
|
|
1700
|
-
function
|
|
1701
|
-
wasm.
|
|
1700
|
+
function wasm_bindgen__convert__closures_____invoke__hc4897ede22d87615(arg0, arg1, arg2) {
|
|
1701
|
+
wasm.wasm_bindgen__convert__closures_____invoke__hc4897ede22d87615(arg0, arg1, arg2);
|
|
1702
1702
|
}
|
|
1703
1703
|
|
|
1704
1704
|
function wasm_bindgen__convert__closures_____invoke__hfb64ebab929241fc(arg0, arg1, arg2) {
|
package/pkg/taladb_web_bg.wasm
CHANGED
|
Binary file
|
|
@@ -60,12 +60,12 @@ export const opfs_load_snapshot: (a: number, b: number) => any;
|
|
|
60
60
|
export const idb_load_snapshot: (a: number, b: number) => any;
|
|
61
61
|
export const idb_save_snapshot: (a: number, b: number, c: number, d: number) => any;
|
|
62
62
|
export const opfs_open_backend: (a: number, b: number) => any;
|
|
63
|
-
export const
|
|
63
|
+
export const wasm_bindgen__closure__destroy__h960c953e41cc5153: (a: number, b: number) => void;
|
|
64
64
|
export const wasm_bindgen__closure__destroy__h48e8a8f67ee293c6: (a: number, b: number) => void;
|
|
65
65
|
export const wasm_bindgen__closure__destroy__h8b8dc50e88fa67bc: (a: number, b: number) => void;
|
|
66
66
|
export const wasm_bindgen__convert__closures_____invoke__hfb64ebab929241fc: (a: number, b: number, c: any) => [number, number];
|
|
67
67
|
export const wasm_bindgen__convert__closures_____invoke__h31b79bb0cf86afae: (a: number, b: number, c: any, d: any) => void;
|
|
68
|
-
export const
|
|
68
|
+
export const wasm_bindgen__convert__closures_____invoke__hc4897ede22d87615: (a: number, b: number, c: any) => void;
|
|
69
69
|
export const wasm_bindgen__convert__closures_____invoke__had96e062ebd712a6: (a: number, b: number) => void;
|
|
70
70
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
71
71
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
package/worker/taladb.worker.js
CHANGED
|
@@ -124,6 +124,22 @@ const isDev = typeof location !== 'undefined' && (location.hostname === 'localho
|
|
|
124
124
|
const log = isDev ? console.log.bind(console, '[TalaDB Worker]') : () => {};
|
|
125
125
|
const warn = isDev ? console.warn.bind(console, '[TalaDB Worker]') : () => {};
|
|
126
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Origin of the page that spawned this DedicatedWorker. Messages from any
|
|
129
|
+
* other origin are silently dropped. Null only in edge environments where
|
|
130
|
+
* `location` is unavailable, in which case the check is skipped.
|
|
131
|
+
*/
|
|
132
|
+
const WORKER_ORIGIN = typeof location !== 'undefined' ? location.origin : null;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Per-worker-instance random token. Included in every `taladb:secondary-write`
|
|
136
|
+
* BroadcastChannel message so the primary tab can reject unauthenticated
|
|
137
|
+
* injections that omit a token.
|
|
138
|
+
*/
|
|
139
|
+
const SESSION_TOKEN = (typeof self.crypto !== 'undefined' && typeof self.crypto.randomUUID === 'function')
|
|
140
|
+
? self.crypto.randomUUID()
|
|
141
|
+
: Array.from(self.crypto.getRandomValues(new Uint8Array(16)), b => b.toString(16).padStart(2, '0')).join('');
|
|
142
|
+
|
|
127
143
|
/**
|
|
128
144
|
* Resolving this releases the Web Lock and closes the sync handle.
|
|
129
145
|
* Set inside doInit; called by the 'close' op or when the worker terminates.
|
|
@@ -288,7 +304,7 @@ function pushChangesetToPrimary() {
|
|
|
288
304
|
const parsed = JSON.parse(changeset);
|
|
289
305
|
if (parsed.length === 0) return;
|
|
290
306
|
lastSecondaryPushMs = Date.now();
|
|
291
|
-
broadcastChannel.postMessage({ type: 'taladb:secondary-write', changeset });
|
|
307
|
+
broadcastChannel.postMessage({ type: 'taladb:secondary-write', token: SESSION_TOKEN, changeset });
|
|
292
308
|
log(`Broadcast ${parsed.length} change(s) to primary tab`);
|
|
293
309
|
} catch (err) {
|
|
294
310
|
warn('Failed to export changeset for primary tab:', err);
|
|
@@ -314,6 +330,12 @@ function onWriteCommitted() {
|
|
|
314
330
|
// ---------------------------------------------------------------------------
|
|
315
331
|
|
|
316
332
|
self.onmessage = async (e) => {
|
|
333
|
+
// Reject messages from unexpected origins. In a DedicatedWorker only the
|
|
334
|
+
// creating page can post messages (browser-enforced), but this guard is a
|
|
335
|
+
// defence-in-depth measure in case the worker is ever repurposed.
|
|
336
|
+
if (WORKER_ORIGIN && e.origin && e.origin !== WORKER_ORIGIN) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
317
339
|
const { id, op, ...args } = e.data;
|
|
318
340
|
try {
|
|
319
341
|
const result = await dispatch(op, args);
|
|
@@ -531,8 +553,11 @@ async function doInit(dbName, configJson) {
|
|
|
531
553
|
const resolve = pendingSnapshotResolve;
|
|
532
554
|
pendingSnapshotResolve = null;
|
|
533
555
|
resolve();
|
|
534
|
-
} else if (e.data?.type === 'taladb:secondary-write' && !idbFallback && db) {
|
|
556
|
+
} else if (e.data?.type === 'taladb:secondary-write' && typeof e.data.token === 'string' && e.data.token.length > 0 && !idbFallback && db) {
|
|
535
557
|
// Primary (OPFS) tab: a secondary tab made a write — merge it in via LWW.
|
|
558
|
+
// The token requirement rejects unauthenticated injection attempts that
|
|
559
|
+
// omit the SESSION_TOKEN field (not a guarantee against same-origin attackers
|
|
560
|
+
// who observe the token, but defence-in-depth against naive injection).
|
|
536
561
|
try {
|
|
537
562
|
const applied = db.importChangeset(e.data.changeset);
|
|
538
563
|
if (applied > 0) {
|