@korajs/store 1.0.0-beta.13 → 1.0.0-beta.14
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/dist/adapters/better-sqlite3.cjs.map +1 -1
- package/dist/adapters/better-sqlite3.js +1 -1
- package/dist/adapters/indexeddb.cjs.map +1 -1
- package/dist/adapters/indexeddb.js +4 -4
- package/dist/adapters/sqlite-wasm-worker.cjs +67 -15
- package/dist/adapters/sqlite-wasm-worker.cjs.map +1 -1
- package/dist/adapters/sqlite-wasm-worker.js +65 -17
- package/dist/adapters/sqlite-wasm-worker.js.map +1 -1
- package/dist/adapters/sqlite-wasm.cjs.map +1 -1
- package/dist/adapters/sqlite-wasm.js +5 -5
- package/dist/{backup-4NUPDEMB.js → backup-IHKVMUAM.js} +5 -5
- package/dist/{chunk-Y5LRH7KI.js → chunk-5AQSGMJV.js} +151 -21
- package/dist/chunk-5AQSGMJV.js.map +1 -0
- package/dist/{chunk-W5F2LWG6.js → chunk-5JMGMPUE.js} +2 -2
- package/dist/{chunk-HZTDBLDB.js → chunk-BILSA6XZ.js} +4 -3
- package/dist/{chunk-HZTDBLDB.js.map → chunk-BILSA6XZ.js.map} +1 -1
- package/dist/{chunk-QDUSJMFV.js → chunk-BQSIL6TT.js} +5 -5
- package/dist/{chunk-MCQKEHOD.js → chunk-KK3GBONL.js} +2 -2
- package/dist/{chunk-32EDKWMI.js → chunk-KTVNANUH.js} +2 -2
- package/dist/{chunk-SJP2HTYZ.js → chunk-QW4UU7NG.js} +2 -2
- package/dist/{chunk-DUKTWVZW.js → chunk-SRHDJF5B.js} +13 -2
- package/dist/{chunk-DUKTWVZW.js.map → chunk-SRHDJF5B.js.map} +1 -1
- package/dist/{chunk-P4V375FY.js → chunk-UC2LGFPV.js} +4 -4
- package/dist/index.cjs +203 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +96 -6
- package/dist/index.d.ts +96 -6
- package/dist/index.js +55 -39
- package/dist/index.js.map +1 -1
- package/dist/internal.cjs +1 -0
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +2 -2
- package/dist/internal.d.ts +2 -2
- package/dist/internal.js +3 -3
- package/dist/{restore-FR7XIKT2.js → restore-MNDPR557.js} +4 -4
- package/dist/{sql-builder-C4u55jKW.d.cts → sql-builder-D0tC3sv9.d.cts} +8 -1
- package/dist/{sql-builder-CGckdBDL.d.ts → sql-builder-D5UMzHEo.d.ts} +8 -1
- package/dist/sqlite-wasm-channel-QCCNBYCU.js +12 -0
- package/dist/store-HNGX4KTT.js +16 -0
- package/package.json +2 -2
- package/dist/chunk-Y5LRH7KI.js.map +0 -1
- package/dist/sqlite-wasm-channel-MLHLKEED.js +0 -12
- package/dist/store-IMWKZLWB.js +0 -16
- /package/dist/{backup-4NUPDEMB.js.map → backup-IHKVMUAM.js.map} +0 -0
- /package/dist/{chunk-W5F2LWG6.js.map → chunk-5JMGMPUE.js.map} +0 -0
- /package/dist/{chunk-QDUSJMFV.js.map → chunk-BQSIL6TT.js.map} +0 -0
- /package/dist/{chunk-MCQKEHOD.js.map → chunk-KK3GBONL.js.map} +0 -0
- /package/dist/{chunk-32EDKWMI.js.map → chunk-KTVNANUH.js.map} +0 -0
- /package/dist/{chunk-SJP2HTYZ.js.map → chunk-QW4UU7NG.js.map} +0 -0
- /package/dist/{chunk-P4V375FY.js.map → chunk-UC2LGFPV.js.map} +0 -0
- /package/dist/{restore-FR7XIKT2.js.map → restore-MNDPR557.js.map} +0 -0
- /package/dist/{sqlite-wasm-channel-MLHLKEED.js.map → sqlite-wasm-channel-QCCNBYCU.js.map} +0 -0
- /package/dist/{store-IMWKZLWB.js.map → store-HNGX4KTT.js.map} +0 -0
|
@@ -15,16 +15,16 @@ import {
|
|
|
15
15
|
restoreDumpStatements,
|
|
16
16
|
saveDumpToIndexedDB,
|
|
17
17
|
saveToIndexedDB
|
|
18
|
-
} from "../chunk-
|
|
19
|
-
import "../chunk-
|
|
18
|
+
} from "../chunk-BQSIL6TT.js";
|
|
19
|
+
import "../chunk-KK3GBONL.js";
|
|
20
20
|
import "../chunk-TVJEC5S2.js";
|
|
21
|
-
import "../chunk-
|
|
21
|
+
import "../chunk-5JMGMPUE.js";
|
|
22
22
|
import {
|
|
23
23
|
AdapterError,
|
|
24
24
|
PersistenceError,
|
|
25
25
|
SchemaVersionAheadError,
|
|
26
26
|
StorageBackendMismatchError
|
|
27
|
-
} from "../chunk-
|
|
27
|
+
} from "../chunk-SRHDJF5B.js";
|
|
28
28
|
|
|
29
29
|
// src/adapters/indexeddb-persistence-scheduler.ts
|
|
30
30
|
var DEFAULT_DEBOUNCE_MS = 500;
|
|
@@ -58,6 +58,12 @@ function opfsPoolPath(dbName) {
|
|
|
58
58
|
|
|
59
59
|
// src/errors.ts
|
|
60
60
|
var import_core = require("@korajs/core");
|
|
61
|
+
var WorkerInitError = class extends import_core.KoraError {
|
|
62
|
+
constructor(message, context) {
|
|
63
|
+
super(`Worker initialization failed: ${message}`, "WORKER_INIT_ERROR", context);
|
|
64
|
+
this.name = "WorkerInitError";
|
|
65
|
+
}
|
|
66
|
+
};
|
|
61
67
|
var BridgeTerminatedError = class extends import_core.KoraError {
|
|
62
68
|
constructor(operation, reason) {
|
|
63
69
|
super(
|
|
@@ -588,35 +594,81 @@ async function migrateFromLegacyPool(sqlite3, target, poolPath, reporter) {
|
|
|
588
594
|
}
|
|
589
595
|
}
|
|
590
596
|
|
|
591
|
-
// src/adapters/sqlite-wasm-
|
|
592
|
-
var
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
const sqlite3InitModule = (await import("@sqlite.org/sqlite-wasm")).default;
|
|
597
|
-
const wasmUrl = globalThis.__KORA_SQLITE_WASM_URL;
|
|
598
|
-
const initOptions = wasmUrl ? {
|
|
599
|
-
locateFile: (file) => file.endsWith(".wasm") ? wasmUrl : file
|
|
600
|
-
} : void 0;
|
|
601
|
-
const initFn = sqlite3InitModule;
|
|
597
|
+
// src/adapters/sqlite-wasm-loader.ts
|
|
598
|
+
var SQLITE_INIT_TIMEOUT_MS = 6e4;
|
|
599
|
+
async function loadSqliteModule(init, options = {}) {
|
|
600
|
+
const timeoutMs = options.timeoutMs ?? SQLITE_INIT_TIMEOUT_MS;
|
|
601
|
+
const source = options.unhandledRejections ?? globalUnhandledRejections;
|
|
602
602
|
let timer;
|
|
603
|
+
let unsubscribe;
|
|
603
604
|
try {
|
|
604
605
|
return await Promise.race([
|
|
605
|
-
|
|
606
|
+
init(options.initOptions),
|
|
606
607
|
new Promise((_, reject) => {
|
|
608
|
+
unsubscribe = source((reason) => {
|
|
609
|
+
if (!isWasmLoadFailure(reason)) return;
|
|
610
|
+
reject(
|
|
611
|
+
new WorkerInitError(
|
|
612
|
+
`could not load the SQLite WebAssembly binary (sqlite3.wasm): ${describe(reason)}. The device may be offline before the app was cached, or the file is not served (check the URL and the application/wasm MIME type).`,
|
|
613
|
+
{ cause: describe(reason) }
|
|
614
|
+
)
|
|
615
|
+
);
|
|
616
|
+
});
|
|
607
617
|
timer = setTimeout(
|
|
608
|
-
() => reject(
|
|
609
|
-
|
|
618
|
+
() => reject(
|
|
619
|
+
new WorkerInitError(`SQLite3 module init timed out after ${String(timeoutMs)}ms`)
|
|
620
|
+
),
|
|
621
|
+
timeoutMs
|
|
610
622
|
);
|
|
611
623
|
})
|
|
612
624
|
]);
|
|
613
625
|
} finally {
|
|
614
626
|
if (timer !== void 0) clearTimeout(timer);
|
|
627
|
+
unsubscribe?.();
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
function isWasmLoadFailure(reason) {
|
|
631
|
+
if (reason instanceof TypeError) return true;
|
|
632
|
+
const wasm = globalThis.WebAssembly;
|
|
633
|
+
if (!wasm) return false;
|
|
634
|
+
for (const name of ["CompileError", "LinkError", "RuntimeError"]) {
|
|
635
|
+
const ctor = wasm[name];
|
|
636
|
+
if (typeof ctor === "function" && reason instanceof ctor) return true;
|
|
615
637
|
}
|
|
638
|
+
return false;
|
|
639
|
+
}
|
|
640
|
+
function describe(reason) {
|
|
641
|
+
return reason instanceof Error ? reason.message : String(reason);
|
|
642
|
+
}
|
|
643
|
+
var globalUnhandledRejections = (listener) => {
|
|
644
|
+
const scope = globalThis;
|
|
645
|
+
if (typeof scope.addEventListener !== "function") return () => {
|
|
646
|
+
};
|
|
647
|
+
const handler = (event) => listener(event.reason);
|
|
648
|
+
scope.addEventListener("unhandledrejection", handler);
|
|
649
|
+
return () => scope.removeEventListener?.("unhandledrejection", handler);
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
// src/adapters/sqlite-wasm-worker-core.ts
|
|
653
|
+
var PROGRESS_HEARTBEAT_MS = 500;
|
|
654
|
+
var PROGRESS_HANDLER_OPS = 2e4;
|
|
655
|
+
var sqlite3Promise = null;
|
|
656
|
+
async function loadSqlite3() {
|
|
657
|
+
const sqlite3InitModule = (await import("@sqlite.org/sqlite-wasm")).default;
|
|
658
|
+
const wasmUrl = globalThis.__KORA_SQLITE_WASM_URL;
|
|
659
|
+
const initOptions = wasmUrl ? {
|
|
660
|
+
locateFile: (file) => file.endsWith(".wasm") ? wasmUrl : file
|
|
661
|
+
} : void 0;
|
|
662
|
+
const initFn = sqlite3InitModule;
|
|
663
|
+
return loadSqliteModule(initFn, initOptions ? { initOptions } : {});
|
|
616
664
|
}
|
|
617
665
|
function getSqlite3() {
|
|
618
666
|
if (!sqlite3Promise) {
|
|
619
|
-
|
|
667
|
+
const loading = loadSqlite3();
|
|
668
|
+
sqlite3Promise = loading;
|
|
669
|
+
loading.catch(() => {
|
|
670
|
+
if (sqlite3Promise === loading) sqlite3Promise = null;
|
|
671
|
+
});
|
|
620
672
|
}
|
|
621
673
|
return sqlite3Promise;
|
|
622
674
|
}
|