@jini-ai/db 0.6.15 → 0.6.16
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/** Kysely's SQLite binding and kernel storage operations. */
|
|
2
2
|
export { sqliteKernel, openSqliteFileKernel, openMemorySqliteKernel, closeSqliteConnection, sqliteClientOf, sqliteConnectionOf, type SqliteConnectionSource, type SqliteKernel } from "./driver.js";
|
|
3
|
-
export { sqliteOps } from "./ops.js";
|
|
3
|
+
export { sqliteOps, copySqliteInto } from "./ops.js";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/** Kysely's SQLite binding and kernel storage operations. */
|
|
2
2
|
export { sqliteKernel, openSqliteFileKernel, openMemorySqliteKernel, closeSqliteConnection, sqliteClientOf, sqliteConnectionOf } from "./driver.js";
|
|
3
|
-
export { sqliteOps } from "./ops.js";
|
|
3
|
+
export { sqliteOps, copySqliteInto } from "./ops.js";
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import { type StorageKernel, type StorageOps } from "../index.js";
|
|
2
|
+
/** Synchronous WAL-safe snapshot for admission code that must commit under a synchronous lock.
|
|
3
|
+
* Accepts either the host's SQLite client or Node's built-in DatabaseSync; the caller owns it.
|
|
4
|
+
* @throws SQLite errors, including an existing destination or an active transaction.
|
|
5
|
+
* @complexity O(database bytes), performed by SQLite without buffering the database in JS.
|
|
6
|
+
*/
|
|
7
|
+
export declare function copySqliteInto({ source, targetPath }: {
|
|
8
|
+
source: {
|
|
9
|
+
prepare(sql: string): {
|
|
10
|
+
run(targetPath: string): unknown;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
targetPath: string;
|
|
14
|
+
}, _options?: {}): void;
|
|
2
15
|
/**
|
|
3
16
|
* The storage ops (`@jini-ai/db/kernel`'s `StorageOps`) for a kernel the sqlite driver built:
|
|
4
17
|
* `VACUUM INTO` for the copy; `VACUUM` + WAL checkpoint + `integrity_check` for compacting. Must be
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { outsideTransactionOf, StorageOpError } from "../index.js";
|
|
2
2
|
import { sqliteConnectionOf } from "./driver.js";
|
|
3
|
+
/** Synchronous WAL-safe snapshot for admission code that must commit under a synchronous lock.
|
|
4
|
+
* Accepts either the host's SQLite client or Node's built-in DatabaseSync; the caller owns it.
|
|
5
|
+
* @throws SQLite errors, including an existing destination or an active transaction.
|
|
6
|
+
* @complexity O(database bytes), performed by SQLite without buffering the database in JS.
|
|
7
|
+
*/
|
|
8
|
+
export function copySqliteInto({ source, targetPath }, _options = {}) {
|
|
9
|
+
// Bind the destination: quotes in a folder name must never become SQL syntax.
|
|
10
|
+
source.prepare("VACUUM INTO ?").run(targetPath);
|
|
11
|
+
}
|
|
3
12
|
/**
|
|
4
13
|
* The storage ops (`@jini-ai/db/kernel`'s `StorageOps`) for a kernel the sqlite driver built:
|
|
5
14
|
* `VACUUM INTO` for the copy; `VACUUM` + WAL checkpoint + `integrity_check` for compacting. Must be
|
|
@@ -17,8 +26,7 @@ export function sqliteOps(kernel) {
|
|
|
17
26
|
return {
|
|
18
27
|
async copyTo(targetPath) {
|
|
19
28
|
outsideTransaction("copyTo");
|
|
20
|
-
|
|
21
|
-
client.prepare("VACUUM INTO ?").run(targetPath);
|
|
29
|
+
copySqliteInto({ source: client, targetPath });
|
|
22
30
|
},
|
|
23
31
|
async compactAndVerify() {
|
|
24
32
|
outsideTransaction("compactAndVerify");
|
|
@@ -69,6 +69,17 @@ export interface TransferSource {
|
|
|
69
69
|
rows(table: string, columns: readonly string[], keep?: string): Iterable<unknown[]>;
|
|
70
70
|
close(): void;
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* A site database runs in WAL mode, and its snapshot's header says so (bytes 18-19 = 2). SQLite
|
|
74
|
+
* cannot open WAL-mode bytes in memory ("unable to open database file"), so a copy of the bytes is
|
|
75
|
+
* marked rollback-journal (1) first. The pages themselves are complete: a backup never needs the WAL.
|
|
76
|
+
* For complete backup/serialized images only, never a live main file with unapplied WAL pages.
|
|
77
|
+
* @returns Readable bytes; WAL headers are changed only on a copy, leaving the input untouched.
|
|
78
|
+
* @complexity O(snapshot bytes) time/space for WAL images, otherwise O(1).
|
|
79
|
+
*/
|
|
80
|
+
export declare function inMemoryReadableBytes({ bytes }: {
|
|
81
|
+
bytes: Buffer;
|
|
82
|
+
}, _options?: Record<string, never>): Buffer;
|
|
72
83
|
/** @complexity O(database size) to deserialize the snapshot. */
|
|
73
84
|
export declare function openSqliteSnapshotSource({ bytes }: {
|
|
74
85
|
bytes: Buffer;
|
|
@@ -9,8 +9,11 @@ function where(keep) {
|
|
|
9
9
|
* A site database runs in WAL mode, and its snapshot's header says so (bytes 18-19 = 2). SQLite
|
|
10
10
|
* cannot open WAL-mode bytes in memory ("unable to open database file"), so a copy of the bytes is
|
|
11
11
|
* marked rollback-journal (1) first. The pages themselves are complete: a backup never needs the WAL.
|
|
12
|
+
* For complete backup/serialized images only, never a live main file with unapplied WAL pages.
|
|
13
|
+
* @returns Readable bytes; WAL headers are changed only on a copy, leaving the input untouched.
|
|
14
|
+
* @complexity O(snapshot bytes) time/space for WAL images, otherwise O(1).
|
|
12
15
|
*/
|
|
13
|
-
function inMemoryReadableBytes(bytes) {
|
|
16
|
+
export function inMemoryReadableBytes({ bytes }, _options = {}) {
|
|
14
17
|
if (bytes[18] !== 2 && bytes[19] !== 2)
|
|
15
18
|
return bytes;
|
|
16
19
|
const copy = Buffer.from(bytes);
|
|
@@ -57,7 +60,7 @@ function layoutOf(db, table) {
|
|
|
57
60
|
}
|
|
58
61
|
/** @complexity O(database size) to deserialize the snapshot. */
|
|
59
62
|
export function openSqliteSnapshotSource({ bytes }, { open }) {
|
|
60
|
-
const db = open(inMemoryReadableBytes(bytes), { readonly: true });
|
|
63
|
+
const db = open(inMemoryReadableBytes({ bytes }), { readonly: true });
|
|
61
64
|
return {
|
|
62
65
|
tableNames() {
|
|
63
66
|
return db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name").all().map((row) => row.name);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/db",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.16",
|
|
4
4
|
"description": "Database ports, connection helpers, ownership, isolated Kysely kernels and migrations. All peers are optional; drivers are injected.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -35,6 +35,12 @@
|
|
|
35
35
|
"src/kernel/typegen.ts",
|
|
36
36
|
"src/sqlite/checked-state.ts"
|
|
37
37
|
]
|
|
38
|
+
},
|
|
39
|
+
"optionalPeers": {
|
|
40
|
+
"better-sqlite3": "opt-in: sqlite storage — SQLite storage could not load better-sqlite3. Install better-sqlite3 to enable this feature, or check its installed version and native binaries.",
|
|
41
|
+
"@electric-sql/pglite": "opt-in: embedded postgresql storage — Embedded PostgreSQL storage could not load @electric-sql/pglite. Install @electric-sql/pglite to enable this feature, or check its installed version and native binaries.",
|
|
42
|
+
"pg": "opt-in: postgresql storage — PostgreSQL storage could not load pg. Install pg to enable this feature, or check its installed version and native binaries.",
|
|
43
|
+
"@jini-ai/platform": "opt-in: platform-backed adapters; import @jini-ai/db/secrets-vault — Platform-backed adapters could not load @jini-ai/platform. Install @jini-ai/platform to enable this feature, or check its installed version and native binaries."
|
|
38
44
|
}
|
|
39
45
|
},
|
|
40
46
|
"type": "module",
|
|
@@ -203,15 +209,26 @@
|
|
|
203
209
|
"registry": "https://registry.npmjs.org"
|
|
204
210
|
},
|
|
205
211
|
"dependencies": {
|
|
206
|
-
"
|
|
212
|
+
"kysely": "^0.29.6",
|
|
213
|
+
"@jini-ai/core": "^0.6.16"
|
|
207
214
|
},
|
|
208
215
|
"peerDependencies": {
|
|
209
|
-
"kysely": "^0.29.6",
|
|
210
216
|
"better-sqlite3": "^13.0.0",
|
|
211
217
|
"@electric-sql/pglite": "0.5.8",
|
|
212
218
|
"pg": "^8.23.0",
|
|
213
219
|
"@jini-ai/platform": "^0.6.10"
|
|
214
220
|
},
|
|
221
|
+
"devDependencies": {
|
|
222
|
+
"@electric-sql/pglite": "0.5.8",
|
|
223
|
+
"@types/better-sqlite3": "7.6.13",
|
|
224
|
+
"@types/pg": "8.23.1",
|
|
225
|
+
"@vitest/coverage-v8": "^2.1.9",
|
|
226
|
+
"better-sqlite3": "13.0.3",
|
|
227
|
+
"kysely": "0.29.6",
|
|
228
|
+
"pg": "8.23.0",
|
|
229
|
+
"@jini-ai/core": "0.6.16",
|
|
230
|
+
"@jini-ai/platform": "0.6.16"
|
|
231
|
+
},
|
|
215
232
|
"peerDependenciesMeta": {
|
|
216
233
|
"better-sqlite3": {
|
|
217
234
|
"optional": true
|
|
@@ -222,24 +239,10 @@
|
|
|
222
239
|
"pg": {
|
|
223
240
|
"optional": true
|
|
224
241
|
},
|
|
225
|
-
"kysely": {
|
|
226
|
-
"optional": true
|
|
227
|
-
},
|
|
228
242
|
"@jini-ai/platform": {
|
|
229
243
|
"optional": true
|
|
230
244
|
}
|
|
231
245
|
},
|
|
232
|
-
"devDependencies": {
|
|
233
|
-
"@electric-sql/pglite": "0.5.8",
|
|
234
|
-
"@types/better-sqlite3": "7.6.13",
|
|
235
|
-
"@types/pg": "8.23.1",
|
|
236
|
-
"@vitest/coverage-v8": "^2.1.9",
|
|
237
|
-
"better-sqlite3": "13.0.3",
|
|
238
|
-
"kysely": "0.29.6",
|
|
239
|
-
"pg": "8.23.0",
|
|
240
|
-
"@jini-ai/core": "0.6.15",
|
|
241
|
-
"@jini-ai/platform": "0.6.15"
|
|
242
|
-
},
|
|
243
246
|
"scripts": {
|
|
244
247
|
"build": "tsc -p tsconfig.build.json",
|
|
245
248
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|