@delali/sirannon-db 0.1.8 → 0.2.1-next.18
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/README.md +117 -989
- package/dist/backup-scheduler/index.d.ts +15 -1
- package/dist/backup-scheduler/index.mjs +2 -2
- package/dist/baseline-D93hcIEE.d.ts +17 -0
- package/dist/{change-tracker-CbmaMO-N.d.ts → change-tracker-DDmXB754.d.ts} +59 -14
- package/dist/chunk-2QLXDHAP.mjs +18 -0
- package/dist/chunk-7C36BCSN.mjs +18 -0
- package/dist/chunk-7FQRQH5Z.mjs +654 -0
- package/dist/{chunk-GEZUUIKV.mjs → chunk-7R4ER4FB.mjs} +5 -2
- package/dist/{chunk-BNUTBHHH.mjs → chunk-BQFQ65OL.mjs} +1 -1
- package/dist/{chunk-H5AB6NIR.mjs → chunk-BTTFW4Z4.mjs} +2 -15
- package/dist/{chunk-HHRMRFFR.mjs → chunk-CCZK6LCB.mjs} +374 -150
- package/dist/chunk-GVCNMPOS.mjs +130 -0
- package/dist/{chunk-CW6S3WL5.mjs → chunk-HCCGEIZ2.mjs} +7 -5
- package/dist/chunk-IWGIYDMZ.mjs +90 -0
- package/dist/{chunk-CJLYFDP5.mjs → chunk-OUSWVNWT.mjs} +1 -1
- package/dist/chunk-P2VJYRVY.mjs +714 -0
- package/dist/{chunk-YPYVQJ4C.mjs → chunk-PBRXXISQ.mjs} +12 -1
- package/dist/chunk-SBL6GN43.mjs +299 -0
- package/dist/chunk-TUD5CJ76.mjs +126 -0
- package/dist/{chunk-UXLAO6ZH.mjs → chunk-UPKKSUPA.mjs} +8 -3
- package/dist/chunk-VOSJBZ6Q.mjs +187 -0
- package/dist/{chunk-VLTICJOD.mjs → chunk-VOYGMAU7.mjs} +9 -1
- package/dist/chunk-WJ67DTD6.mjs +1449 -0
- package/dist/chunk-XF2HH5E6.mjs +226 -0
- package/dist/client/index.d.ts +393 -299
- package/dist/client/index.mjs +1265 -1327
- package/dist/client/topology.d.ts +109 -0
- package/dist/client/topology.mjs +701 -0
- package/dist/client-base-CmZO0v3m.d.ts +343 -0
- package/dist/codegen/cli.d.ts +2 -0
- package/dist/codegen/cli.mjs +11 -0
- package/dist/codegen/index.d.ts +120 -0
- package/dist/codegen/index.mjs +5 -0
- package/dist/core/index.d.ts +201 -18
- package/dist/core/index.mjs +2783 -504
- package/dist/core/writer-worker.mjs +3 -3
- package/dist/database-B5Qv1-cU.d.ts +380 -0
- package/dist/driver/better-sqlite3.d.ts +18 -1
- package/dist/driver/better-sqlite3.mjs +5 -5
- package/dist/driver/bun.d.ts +28 -0
- package/dist/driver/expo.d.ts +17 -0
- package/dist/driver/node.d.ts +18 -1
- package/dist/driver/node.mjs +5 -5
- package/dist/driver/wa-sqlite.d.ts +14 -132
- package/dist/{errors-5Nf5ZAEC.d.ts → errors-Dei4GdBb.d.ts} +85 -8
- package/dist/file-migrations/index.d.ts +59 -5
- package/dist/file-migrations/index.mjs +42 -37
- package/dist/operation-registry-hlbhqu7q.d.ts +94 -0
- package/dist/primary-wins-B0np8JS3.d.ts +85 -0
- package/dist/protocol-rqANt-9Q.d.ts +152 -0
- package/dist/query-types-DL3LtPvY.d.ts +95 -0
- package/dist/react/index.d.ts +75 -0
- package/dist/react/index.mjs +137 -0
- package/dist/replication/coordinator/etcd.d.ts +66 -4
- package/dist/replication/coordinator/etcd.mjs +593 -465
- package/dist/replication/index.d.ts +355 -175
- package/dist/replication/index.mjs +1515 -2046
- package/dist/server/index.d.ts +330 -88
- package/dist/server/index.mjs +1895 -454
- package/dist/server-options-Dab_Jvd_.d.ts +275 -0
- package/dist/sirannon-CMhiJa5Y.d.ts +111 -0
- package/dist/transport/grpc.d.ts +95 -8
- package/dist/transport/grpc.mjs +251 -114
- package/dist/transport/memory.d.ts +50 -149
- package/dist/transport/memory.mjs +28 -1
- package/dist/types-BCejqzNA.d.ts +63 -0
- package/dist/types-CMBcFPhb.d.ts +336 -0
- package/dist/types-CjhxcjhA.d.ts +123 -0
- package/dist/types-DyrCiWuc.d.ts +499 -0
- package/dist/types-rVZKnKN-.d.ts +591 -0
- package/package.json +65 -21
- package/dist/chunk-TKGHYWQ6.mjs +0 -35
- package/dist/database-DuGp0Rtr.d.ts +0 -127
- package/dist/sirannon-4SspRvP5.d.ts +0 -31
- package/dist/types-BEu1I_9_.d.ts +0 -139
- package/dist/types-BsjobKbl.d.ts +0 -274
- package/dist/types-D4p4UyDK.d.ts +0 -26
- package/dist/types-D_hQW1hr.d.ts +0 -494
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { e as SQLiteConnection, f as BackupScheduleOptions } from '../types-
|
|
1
|
+
import { e as SQLiteConnection, f as BackupScheduleOptions } from '../types-rVZKnKN-.js';
|
|
2
|
+
import '../query-types-DL3LtPvY.js';
|
|
2
3
|
|
|
3
4
|
declare class BackupManager {
|
|
4
5
|
backup(conn: SQLiteConnection, destPath: string): Promise<void>;
|
|
@@ -8,9 +9,22 @@ declare class BackupManager {
|
|
|
8
9
|
|
|
9
10
|
/** Runs a backup while the caller's writer lock is held, so it never shares the writer connection with another write. */
|
|
10
11
|
type RunExclusive = (op: () => Promise<void>) => Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*
|
|
15
|
+
* Repeats a database backup on a cron schedule and keeps a bounded number of files.
|
|
16
|
+
*/
|
|
11
17
|
declare class BackupScheduler {
|
|
12
18
|
private readonly manager;
|
|
13
19
|
constructor(manager?: BackupManager);
|
|
20
|
+
/**
|
|
21
|
+
* Starts repeating backups and returns a function that stops them.
|
|
22
|
+
*
|
|
23
|
+
* @param conn - Connection to the database being copied.
|
|
24
|
+
* @param options - Cron expression, destination directory, retention, time zone, and failure callback.
|
|
25
|
+
* @param runExclusive - Runs each copy with the database's writer held so that no write commits mid-copy.
|
|
26
|
+
* @returns A function that stops the schedule.
|
|
27
|
+
*/
|
|
14
28
|
schedule(conn: SQLiteConnection, options: BackupScheduleOptions, runExclusive?: RunExclusive): () => void;
|
|
15
29
|
private run;
|
|
16
30
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { BackupScheduler } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
export { BackupScheduler } from '../chunk-VOYGMAU7.mjs';
|
|
2
|
+
import '../chunk-PBRXXISQ.mjs';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marks the migration an existing database starts from, so earlier versions are recorded without running.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
interface BaselineFileOption {
|
|
7
|
+
/**
|
|
8
|
+
* Version of the migration carrying the baseline.
|
|
9
|
+
*/
|
|
10
|
+
version: number;
|
|
11
|
+
/**
|
|
12
|
+
* Highest version this baseline covers.
|
|
13
|
+
*/
|
|
14
|
+
through: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type { BaselineFileOption as B };
|
|
@@ -1,25 +1,59 @@
|
|
|
1
|
-
import { e as SQLiteConnection
|
|
1
|
+
import { e as SQLiteConnection } from './types-rVZKnKN-.js';
|
|
2
|
+
import { C as ChangeEvent } from './query-types-DL3LtPvY.js';
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* How long a change tracker keeps changes, and how much it reads at a time.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
3
9
|
interface ChangeTrackerOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Milliseconds a change stays readable before it is pruned. Default: 3_600_000 (one hour).
|
|
12
|
+
*/
|
|
4
13
|
retention?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Name of the table changes are recorded in.
|
|
16
|
+
*/
|
|
5
17
|
changesTable?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Changes read in one poll. Default: 1000.
|
|
20
|
+
*/
|
|
6
21
|
pollBatchSize?: number;
|
|
7
|
-
replication?: boolean;
|
|
8
22
|
}
|
|
9
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Records every change to the tables you watch so that subscribers and replication can read them in order.
|
|
26
|
+
*
|
|
27
|
+
* Construct one, watch the tables you want captured, and pass it to a replication engine or leave it to the database that owns it.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
10
31
|
declare class ChangeTracker {
|
|
11
32
|
private readonly watched;
|
|
12
33
|
private lastSeq;
|
|
13
34
|
private readonly retentionMs;
|
|
14
35
|
private readonly changesTable;
|
|
15
36
|
private readonly pollBatchSize;
|
|
16
|
-
private readonly replication;
|
|
17
37
|
private changesTableReady;
|
|
38
|
+
private changesTableEnsured;
|
|
18
39
|
private watchedTablesCache;
|
|
19
40
|
private readonly stmtCache;
|
|
20
41
|
private pruneBoundary;
|
|
42
|
+
private lastPollAtTxBoundary;
|
|
21
43
|
constructor(options?: ChangeTrackerOptions);
|
|
44
|
+
/**
|
|
45
|
+
* Starts recording changes to a table by installing its change-capture triggers.
|
|
46
|
+
*
|
|
47
|
+
* @param conn - Writer connection the triggers are created on.
|
|
48
|
+
* @param table - Name of the table to watch.
|
|
49
|
+
*/
|
|
22
50
|
watch(conn: SQLiteConnection, table: string): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Stops recording changes to a table and drops its triggers.
|
|
53
|
+
*
|
|
54
|
+
* @param conn - Writer connection the triggers are dropped from.
|
|
55
|
+
* @param table - Name of the table to stop watching.
|
|
56
|
+
*/
|
|
23
57
|
unwatch(conn: SQLiteConnection, table: string): Promise<void>;
|
|
24
58
|
/**
|
|
25
59
|
* Rebuilds CDC triggers for every watched table directly on the supplied
|
|
@@ -45,6 +79,8 @@ declare class ChangeTracker {
|
|
|
45
79
|
* `conn`. The cached column list is updated on success.
|
|
46
80
|
* - Any other error (driver failure, identifier validation failure) is
|
|
47
81
|
* rethrown so the caller's transaction can roll back deterministically.
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
48
84
|
*/
|
|
49
85
|
refreshAllTriggersUsingConnection(conn: SQLiteConnection): Promise<void>;
|
|
50
86
|
/**
|
|
@@ -66,33 +102,42 @@ declare class ChangeTracker {
|
|
|
66
102
|
* re-installed triggers compiled against the new schema. Those triggers
|
|
67
103
|
* are dropped here so the recreated table starts with a clean slate and
|
|
68
104
|
* the caller must explicitly `watch` it again.
|
|
105
|
+
*
|
|
106
|
+
* @internal
|
|
69
107
|
*/
|
|
70
108
|
pruneDroppedTables(conn: SQLiteConnection, tables: readonly string[]): Promise<void>;
|
|
109
|
+
/** @internal */
|
|
71
110
|
poll(conn: SQLiteConnection): Promise<ChangeEvent[]>;
|
|
72
|
-
/**
|
|
111
|
+
/** @internal */
|
|
112
|
+
get pollEndedAtTxBoundary(): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* The highest seq already polled; live subscribers receive events beyond it.
|
|
115
|
+
*
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
73
118
|
get cursor(): bigint;
|
|
119
|
+
/** @internal */
|
|
120
|
+
readSinceTables(conn: SQLiteConnection, tables: readonly string[], afterSeq: bigint, upToSeq: bigint, limit: number): Promise<ChangeEvent[]>;
|
|
74
121
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
122
|
+
* The lowest retained seq, or `null` when the change log is empty.
|
|
123
|
+
*
|
|
124
|
+
* @internal
|
|
78
125
|
*/
|
|
79
|
-
readSince(conn: SQLiteConnection, table: string, afterSeq: bigint, upToSeq: bigint, limit: number): Promise<ChangeEvent[]>;
|
|
80
|
-
/** The lowest retained seq, or `null` when the change log is empty. */
|
|
81
126
|
getMinSeq(conn: SQLiteConnection): Promise<bigint | null>;
|
|
82
|
-
|
|
127
|
+
/** @internal */
|
|
83
128
|
advanceToLatest(conn: SQLiteConnection): Promise<void>;
|
|
129
|
+
/** @internal */
|
|
84
130
|
cleanup(conn: SQLiteConnection): Promise<number>;
|
|
131
|
+
/** @internal */
|
|
85
132
|
setPruneBoundary(seq: bigint): void;
|
|
133
|
+
/** @internal */
|
|
86
134
|
clearPruneBoundary(): void;
|
|
135
|
+
/** @internal */
|
|
87
136
|
get watchedTables(): ReadonlySet<string>;
|
|
88
137
|
private computeSeqBound;
|
|
89
138
|
private assertIdentifier;
|
|
90
139
|
private detectChangesTable;
|
|
91
140
|
private ensureChangesTable;
|
|
92
|
-
private getColumns;
|
|
93
|
-
private getPkColumns;
|
|
94
|
-
private dropTriggers;
|
|
95
|
-
private getStmt;
|
|
96
141
|
private installTriggers;
|
|
97
142
|
}
|
|
98
143
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SirannonError } from './chunk-PBRXXISQ.mjs';
|
|
2
|
+
|
|
3
|
+
// src/core/sync/errors.ts
|
|
4
|
+
var ReplicationError = class extends SirannonError {
|
|
5
|
+
constructor(message, code = "REPLICATION_ERROR", details) {
|
|
6
|
+
super(message, code);
|
|
7
|
+
this.details = details;
|
|
8
|
+
this.name = "ReplicationError";
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var BatchValidationError = class extends ReplicationError {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message, "BATCH_VALIDATION_ERROR");
|
|
14
|
+
this.name = "BatchValidationError";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { BatchValidationError, ReplicationError };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MigrationError } from './chunk-PBRXXISQ.mjs';
|
|
2
|
+
|
|
3
|
+
// src/core/migrations/lazy-down.ts
|
|
4
|
+
var LAZY_DOWN_SQL = /* @__PURE__ */ Symbol("sirannon.file-migration.lazy-down");
|
|
5
|
+
|
|
6
|
+
// src/core/migrations/filename.ts
|
|
7
|
+
var MIGRATION_FILENAME_PATTERN = /^(\d+)_(\w+)\.(up|down)\.sql$/;
|
|
8
|
+
function parseMigrationFilename(filename) {
|
|
9
|
+
const match = MIGRATION_FILENAME_PATTERN.exec(filename);
|
|
10
|
+
if (!match) return null;
|
|
11
|
+
const version = parseInt(match[1], 10);
|
|
12
|
+
if (!Number.isFinite(version) || version <= 0 || !Number.isSafeInteger(version)) {
|
|
13
|
+
throw new MigrationError(`Invalid migration version: ${match[1]}`, version, "MIGRATION_VALIDATION_ERROR");
|
|
14
|
+
}
|
|
15
|
+
return { version, name: match[2], direction: match[3] };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { LAZY_DOWN_SQL, MIGRATION_FILENAME_PATTERN, parseMigrationFilename };
|