@syncular/client 0.22.0 → 0.24.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/dist/bun-database.d.ts +4 -1
- package/dist/bun-database.js +24 -1
- package/dist/client.d.ts +47 -0
- package/dist/client.js +326 -4
- package/dist/database.d.ts +27 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/invalidation.d.ts +9 -0
- package/dist/node-database.d.ts +4 -1
- package/dist/node-database.js +24 -1
- package/dist/previous-version.d.ts +207 -0
- package/dist/previous-version.js +732 -0
- package/dist/query-guard.d.ts +5 -0
- package/dist/query-guard.js +5 -0
- package/dist/schema.d.ts +4 -2
- package/dist/schema.js +4 -2
- package/dist/wasm-database.js +87 -35
- package/dist/worker-entry.js +15 -4
- package/dist/worker-host.d.ts +13 -1
- package/dist/worker-host.js +13 -0
- package/dist/worker-protocol.d.ts +16 -1
- package/package.json +3 -3
- package/src/bun-database.ts +26 -1
- package/src/client.ts +481 -4
- package/src/database.ts +28 -0
- package/src/index.ts +13 -0
- package/src/invalidation.ts +9 -0
- package/src/node-database.ts +26 -1
- package/src/previous-version.ts +1070 -0
- package/src/query-guard.ts +5 -0
- package/src/schema.ts +4 -2
- package/src/wasm-database.ts +114 -47
- package/src/worker-entry.ts +16 -4
- package/src/worker-host.ts +40 -0
- package/src/worker-protocol.ts +19 -0
package/src/node-database.ts
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
* adapter: synchronous queries, nested transactions, and SQLite image attach.
|
|
4
4
|
*/
|
|
5
5
|
import { DatabaseSync, type SQLInputValue } from 'node:sqlite';
|
|
6
|
-
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
7
7
|
import { tmpdir } from 'node:os';
|
|
8
8
|
import { join } from 'node:path';
|
|
9
9
|
import {
|
|
10
10
|
assertImageAlias,
|
|
11
11
|
type ClientDatabase,
|
|
12
12
|
runTransaction,
|
|
13
|
+
type SiblingDatabase,
|
|
13
14
|
type SqlRow,
|
|
14
15
|
type SqlValue,
|
|
15
16
|
} from './database';
|
|
@@ -36,9 +37,11 @@ function normalizeRow(row: Record<string, unknown>): SqlRow {
|
|
|
36
37
|
|
|
37
38
|
export class NodeClientDatabase implements ClientDatabase {
|
|
38
39
|
readonly db: DatabaseSync;
|
|
40
|
+
readonly #path: string;
|
|
39
41
|
#tx = { depth: 0 };
|
|
40
42
|
|
|
41
43
|
constructor(path = ':memory:') {
|
|
44
|
+
this.#path = path;
|
|
42
45
|
this.db = new DatabaseSync(path);
|
|
43
46
|
try {
|
|
44
47
|
this.db.exec('PRAGMA journal_mode = WAL');
|
|
@@ -58,6 +61,28 @@ export class NodeClientDatabase implements ClientDatabase {
|
|
|
58
61
|
return rows.map(normalizeRow);
|
|
59
62
|
}
|
|
60
63
|
|
|
64
|
+
/** RFC 0005: a sibling file beside the replica, e.g. `<path>.prev-context`. */
|
|
65
|
+
openSibling(name: string): SiblingDatabase {
|
|
66
|
+
const siblingPath =
|
|
67
|
+
this.#path === ':memory:' ? ':memory:' : `${this.#path}.${name}`;
|
|
68
|
+
const database = new NodeClientDatabase(siblingPath);
|
|
69
|
+
return {
|
|
70
|
+
database,
|
|
71
|
+
close: () => database.close(),
|
|
72
|
+
removeFile: () => {
|
|
73
|
+
if (siblingPath === ':memory:') return;
|
|
74
|
+
rmSync(siblingPath, { force: true });
|
|
75
|
+
rmSync(`${siblingPath}-wal`, { force: true });
|
|
76
|
+
rmSync(`${siblingPath}-shm`, { force: true });
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
siblingExists(name: string): boolean {
|
|
82
|
+
if (this.#path === ':memory:') return false;
|
|
83
|
+
return existsSync(`${this.#path}.${name}`);
|
|
84
|
+
}
|
|
85
|
+
|
|
61
86
|
transaction<T>(fn: () => T): T {
|
|
62
87
|
return runTransaction(this.#tx, (sql) => this.db.exec(sql), fn);
|
|
63
88
|
}
|