@delali/sirannon-db 0.3.4-next.62 → 0.3.4
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 +79 -56
- package/dist/backup/index.d.ts +44 -45
- package/dist/backup/index.mjs +7 -7
- package/dist/backup-scheduler/index.d.ts +42 -41
- package/dist/backup-scheduler/index.mjs +4 -4
- package/dist/baseline-Co3iIsN_.d.ts +19 -0
- package/dist/change-tracker-DqCdeEyx.d.ts +128 -0
- package/dist/{chunk-VOSJBZ6Q.mjs → chunk-2ES3DT4A.mjs} +71 -33
- package/dist/{chunk-6CMCO7S4.mjs → chunk-2O3PP4CF.mjs} +1 -1
- package/dist/{chunk-E7Q7HE46.mjs → chunk-3BZLZ47R.mjs} +26 -26
- package/dist/chunk-4KASJKKK.mjs +2501 -0
- package/dist/{chunk-MYNI2WFS.mjs → chunk-52XW3Z76.mjs} +40 -8
- package/dist/chunk-55YRLSM2.mjs +57 -0
- package/dist/{chunk-KDAHYFW7.mjs → chunk-6AOJCNRU.mjs} +5 -5
- package/dist/{chunk-KXTYR2OQ.mjs → chunk-A3PHCO6W.mjs} +39 -111
- package/dist/chunk-ADNWEHGZ.mjs +299 -0
- package/dist/{chunk-2QLXDHAP.mjs → chunk-BLMRNSUG.mjs} +11 -2
- package/dist/chunk-BVMZJOVM.mjs +5 -0
- package/dist/{chunk-IWGIYDMZ.mjs → chunk-BZWDPF4G.mjs} +1 -1
- package/dist/{chunk-YVF2ZJTE.mjs → chunk-CZL4D3BM.mjs} +1 -1
- package/dist/{chunk-7SC2TZAS.mjs → chunk-DX4WGJL7.mjs} +2 -2
- package/dist/{chunk-45MKELYA.mjs → chunk-ESTZZPT5.mjs} +132 -13
- package/dist/{chunk-QP5L5DFJ.mjs → chunk-FJPR2CJX.mjs} +3 -3
- package/dist/chunk-HR7K3GZW.mjs +36 -0
- package/dist/{chunk-LXCGPZPA.mjs → chunk-IEKIYO4V.mjs} +1 -1
- package/dist/{chunk-TUD5CJ76.mjs → chunk-KB4OLJAD.mjs} +26 -19
- package/dist/{chunk-PBRXXISQ.mjs → chunk-KINDFBQP.mjs} +3 -2
- package/dist/{chunk-E6IMX7RS.mjs → chunk-KJLNYOOL.mjs} +2 -2
- package/dist/{chunk-BTTFW4Z4.mjs → chunk-KU32OT4H.mjs} +2 -10
- package/dist/{chunk-JQWGHSEH.mjs → chunk-NVSQ2T5Q.mjs} +71 -70
- package/dist/{chunk-W4EUTJNT.mjs → chunk-NZGSDALX.mjs} +94 -96
- package/dist/{chunk-U445A3C4.mjs → chunk-QGVRRKB2.mjs} +1 -1
- package/dist/{chunk-GYCEJNU4.mjs → chunk-R7GBXNTO.mjs} +1 -1
- package/dist/{chunk-7C36BCSN.mjs → chunk-VDN6FHU4.mjs} +1 -1
- package/dist/{chunk-6IYS4WLH.mjs → chunk-VO3ZWA2G.mjs} +142 -115
- package/dist/chunk-WOMADPM4.mjs +12 -0
- package/dist/{chunk-OUSWVNWT.mjs → chunk-YCMB6GR4.mjs} +1 -1
- package/dist/{chunk-YNTDOFTN.mjs → chunk-YW7IKQ7T.mjs} +1 -1
- package/dist/{chunk-M2BEAH5I.mjs → chunk-ZN4HI5FK.mjs} +126 -72
- package/dist/{chunk-SBL6GN43.mjs → chunk-ZYWI45EN.mjs} +1 -1
- package/dist/client/index.d.ts +135 -137
- package/dist/client/index.mjs +177 -82
- package/dist/client/topology.d.ts +31 -31
- package/dist/client/topology.mjs +42 -23
- package/dist/client-base-BxTocU1x.d.ts +398 -0
- package/dist/client-streams-YKANXMWO.mjs +112 -0
- package/dist/codegen/cli.mjs +4 -4
- package/dist/codegen/index.d.ts +36 -29
- package/dist/codegen/index.mjs +4 -4
- package/dist/core/index.d.ts +130 -115
- package/dist/core/index.mjs +387 -297
- package/dist/core/writer-worker.mjs +3 -3
- package/dist/database-CGDsXW1K.d.ts +959 -0
- package/dist/database-backup-DcLhxoa1.d.ts +143 -0
- package/dist/driver/better-sqlite3.d.ts +11 -10
- package/dist/driver/better-sqlite3.mjs +11 -11
- package/dist/driver/bun.d.ts +9 -8
- package/dist/driver/expo.d.ts +6 -7
- package/dist/driver/node.d.ts +11 -10
- package/dist/driver/node.mjs +13 -11
- package/dist/driver/wa-sqlite.d.ts +6 -6
- package/dist/errors-CJUkQ-KL.d.ts +199 -0
- package/dist/file-migrations/index.d.ts +20 -18
- package/dist/file-migrations/index.mjs +3 -3
- package/dist/forward-rpc-VRWFZXHN.mjs +44 -0
- package/dist/operation-registry-CGhNT-Sn.d.ts +96 -0
- package/dist/primary-wins-CHNOYuN7.d.ts +81 -0
- package/dist/protocol-DFpNNsIT.d.ts +153 -0
- package/dist/query-types-5B02ixH0.d.ts +129 -0
- package/dist/react/index.d.ts +22 -22
- package/dist/replication/coordinator/etcd.d.ts +37 -31
- package/dist/replication/coordinator/etcd.mjs +296 -131
- package/dist/replication/index.d.ts +201 -161
- package/dist/replication/index.mjs +630 -529
- package/dist/restore-options-CH8mE-Tb.d.ts +84 -0
- package/dist/server/index.d.ts +201 -191
- package/dist/server/index.mjs +736 -619
- package/dist/server-options-aYtCkefX.d.ts +317 -0
- package/dist/server-streams-24XL4T43.mjs +254 -0
- package/dist/sirannon-J3EgPVD7.d.ts +179 -0
- package/dist/transport/grpc.d.ts +37 -24
- package/dist/transport/grpc.mjs +83 -3199
- package/dist/transport/memory.d.ts +25 -26
- package/dist/transport/memory.mjs +18 -9
- package/dist/types-BrAiDGOb.d.ts +505 -0
- package/dist/types-CEJG0eFS.d.ts +88 -0
- package/dist/types-Dc8oWlxj.d.ts +1580 -0
- package/dist/types-DqODKeOq.d.ts +123 -0
- package/dist/types-guEKSzMr.d.ts +367 -0
- package/package.json +7 -7
- package/dist/baseline-D93hcIEE.d.ts +0 -17
- package/dist/change-tracker-CjRFuZdB.d.ts +0 -144
- package/dist/client-base-Cmd9EVme.d.ts +0 -397
- package/dist/database-BLQvqjsw.d.ts +0 -917
- package/dist/database-backup-B7oszQ2n.d.ts +0 -141
- package/dist/errors-Dei4GdBb.d.ts +0 -196
- package/dist/operation-registry-oiPuSYI6.d.ts +0 -94
- package/dist/primary-wins-B0np8JS3.d.ts +0 -85
- package/dist/protocol-HI-nY8DD.d.ts +0 -152
- package/dist/query-types-p1liOP-b.d.ts +0 -127
- package/dist/restore-options-CksYsH1l.d.ts +0 -83
- package/dist/server-options-Bj5iJnjx.d.ts +0 -292
- package/dist/sirannon-BPxC5tC2.d.ts +0 -178
- package/dist/types-B0EhgDbr.d.ts +0 -340
- package/dist/types-CbjfRwrK.d.ts +0 -499
- package/dist/types-CjhxcjhA.d.ts +0 -123
- package/dist/types-DPSmjU54.d.ts +0 -1518
- package/dist/types-DTO4CYhW.d.ts +0 -88
|
@@ -1,917 +0,0 @@
|
|
|
1
|
-
import { D as DatabaseBackupController, B as BackupCapabilities, a as BackupChainLocation, b as BackupRestorePlan, c as BackupSafeToDeleteOptions } from './database-backup-B7oszQ2n.js';
|
|
2
|
-
import { S as SQLiteDriver, U as SynchronousLevel, an as WorkerHostOptions, I as SQLiteConnection, T as Transaction, ao as WriterContext, M as Migration, W as MigrationResult, X as RollbackResult, ai as QueryHookContext, a3 as ConnectionHookContext, a0 as BeforeSubscribeHook, $ as BeforeSnapshotHook, a8 as HookConfig, aa as MetricsConfig, aj as QueryMetrics, a4 as ConnectionMetrics, a1 as CDCMetrics, D as DatabaseOptions, p as BackupFileReport, y as BackupToDestinationOptions, f as BackupRunReport, O as BackupScheduleOptions, g as BackupChain, o as BackupCycleStatus, z as BackupVerifyResult, k as BackupChainRecord, b as BeforeQueryHook, A as AfterQueryHook } from './types-DPSmjU54.js';
|
|
3
|
-
import { C as ChangeTracker } from './change-tracker-CjRFuZdB.js';
|
|
4
|
-
import { C as ChangeEvent, d as SubscriptionOptions, S as Subscription, c as SubscriptionBuilder, P as Params, Q as QueryOptions, E as ExecuteResult } from './query-types-p1liOP-b.js';
|
|
5
|
-
import { H as HLCTimestamp, c as ReplicationChange, C as ConflictResolver, A as ApplyResult, R as ReplicationBatch } from './types-CjhxcjhA.js';
|
|
6
|
-
import { A as AppliedMigrationRow, c as BulkLoadOptions, a as BulkLoadResult } from './server-options-Bj5iJnjx.js';
|
|
7
|
-
import { L as LiveQueryOptions, a as LiveQuery } from './types-DTO4CYhW.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Settings a connection pool opens its writer and readers with.
|
|
11
|
-
*
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
interface ConnectionPoolOptions {
|
|
15
|
-
driver: SQLiteDriver;
|
|
16
|
-
path: string;
|
|
17
|
-
readOnly?: boolean;
|
|
18
|
-
readPoolSize?: number;
|
|
19
|
-
walMode?: boolean;
|
|
20
|
-
synchronous?: SynchronousLevel;
|
|
21
|
-
walAutoCheckpoint?: number;
|
|
22
|
-
useWriterWorker?: boolean;
|
|
23
|
-
workerHostOptions?: WorkerHostOptions;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Holds one writer connection and a rotating set of reader connections for a single database file.
|
|
27
|
-
*
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
declare class ConnectionPool {
|
|
31
|
-
private readonly writer;
|
|
32
|
-
private readonly readers;
|
|
33
|
-
private readerIndex;
|
|
34
|
-
private closed;
|
|
35
|
-
private constructor();
|
|
36
|
-
static create(options: ConnectionPoolOptions): Promise<ConnectionPool>;
|
|
37
|
-
acquireReader(): SQLiteConnection;
|
|
38
|
-
acquireWriter(): SQLiteConnection;
|
|
39
|
-
/** Returns the writer and every reader, for an operation that must apply to the whole pool. */
|
|
40
|
-
connections(): readonly SQLiteConnection[];
|
|
41
|
-
get readerCount(): number;
|
|
42
|
-
get isReadOnly(): boolean;
|
|
43
|
-
close(): Promise<void>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
declare class SubscriptionManager {
|
|
47
|
-
private nextId;
|
|
48
|
-
private readonly subscriptions;
|
|
49
|
-
private readonly byTable;
|
|
50
|
-
private readonly batchEndListeners;
|
|
51
|
-
subscribe(table: string, filter: Record<string, unknown> | undefined, callback: (event: ChangeEvent) => void, options?: SubscriptionOptions): Subscription;
|
|
52
|
-
dispatch(events: ChangeEvent[]): void;
|
|
53
|
-
reportError(error: Error): void;
|
|
54
|
-
addBatchEndListener(listener: (atTxBoundary: boolean) => void): () => void;
|
|
55
|
-
endBatch(atTxBoundary: boolean): void;
|
|
56
|
-
get size(): number;
|
|
57
|
-
subscriberCount(table: string): number;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Hybrid Logical Clock (HLC) for causal ordering of events across nodes.
|
|
62
|
-
*
|
|
63
|
-
* Each timestamp is encoded as `{wallMs hex}-{logical hex}-{nodeId}`, which
|
|
64
|
-
* is directly comparable with string comparison while preserving both
|
|
65
|
-
* wall-clock proximity and causal ordering guarantees. The wall-clock
|
|
66
|
-
* component tracks real time (milliseconds since epoch), the logical counter
|
|
67
|
-
* disambiguates events that occur within the same millisecond, and the nodeId
|
|
68
|
-
* ties the timestamp to its origin.
|
|
69
|
-
*
|
|
70
|
-
* Call `now()` before persisting a local write to generate a monotonically
|
|
71
|
-
* increasing timestamp. Call `receive(remote)` when processing a remote
|
|
72
|
-
* change to merge the remote clock into the local state, ensuring the local
|
|
73
|
-
* clock is never behind any observed timestamp.
|
|
74
|
-
*
|
|
75
|
-
* @public
|
|
76
|
-
*/
|
|
77
|
-
declare class HLC {
|
|
78
|
-
private wallMs;
|
|
79
|
-
private logical;
|
|
80
|
-
private readonly nodeId;
|
|
81
|
-
constructor(nodeId: string);
|
|
82
|
-
/**
|
|
83
|
-
* Generate a new HLC timestamp, advancing the clock.
|
|
84
|
-
*
|
|
85
|
-
* @internal
|
|
86
|
-
*/
|
|
87
|
-
now(): string;
|
|
88
|
-
/**
|
|
89
|
-
* Merge a remote HLC timestamp into the local clock and return the updated value.
|
|
90
|
-
*
|
|
91
|
-
* @internal
|
|
92
|
-
*/
|
|
93
|
-
receive(remote: string): string;
|
|
94
|
-
/** Lexicographic comparison of two encoded HLC strings. Returns -1, 0, or 1. */
|
|
95
|
-
static compare(a: string, b: string): number;
|
|
96
|
-
/** Parse an encoded HLC string into its wall-clock, logical, and nodeId components. */
|
|
97
|
-
static decode(hlc: string): HLCTimestamp;
|
|
98
|
-
/**
|
|
99
|
-
* Builds the string form of a clock reading, which sorts in the same order as the reading itself.
|
|
100
|
-
*
|
|
101
|
-
* @param wallMs - Wall-clock milliseconds since the Unix epoch.
|
|
102
|
-
* @param logical - Counter that orders events sharing one millisecond.
|
|
103
|
-
* @param nodeId - Identifier of the node taking the reading.
|
|
104
|
-
* @returns The encoded stamp.
|
|
105
|
-
*/
|
|
106
|
-
static encode(wallMs: number, logical: number, nodeId: string): string;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
interface StampStatement {
|
|
110
|
-
sql: string;
|
|
111
|
-
params: unknown[];
|
|
112
|
-
trusted: true;
|
|
113
|
-
}
|
|
114
|
-
declare class SyncStamper {
|
|
115
|
-
readonly nodeId: string;
|
|
116
|
-
readonly hlc: HLC;
|
|
117
|
-
private readonly changesTable;
|
|
118
|
-
private constructor();
|
|
119
|
-
static init(conn: SQLiteConnection, changesTable?: string): Promise<SyncStamper>;
|
|
120
|
-
stampStatements(options?: {
|
|
121
|
-
persistClock?: boolean;
|
|
122
|
-
}): StampStatement[];
|
|
123
|
-
applyStamps(txConn: SQLiteConnection): Promise<void>;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
type RunExclusive$1 = <T>(op: () => Promise<T>) => Promise<T>;
|
|
127
|
-
declare class DatabaseCdcController {
|
|
128
|
-
private readonly runExclusive;
|
|
129
|
-
private readonly acquireWriter;
|
|
130
|
-
private readonly pollInterval;
|
|
131
|
-
private readonly retention;
|
|
132
|
-
private readonly openSnapshotConnection;
|
|
133
|
-
private tracker;
|
|
134
|
-
private subscriptionManager;
|
|
135
|
-
private liveConnRequest;
|
|
136
|
-
private stopPolling;
|
|
137
|
-
private stamper;
|
|
138
|
-
private epochRequest;
|
|
139
|
-
constructor(runExclusive: RunExclusive$1, acquireWriter: () => SQLiteConnection, pollInterval: number, retention: number, openSnapshotConnection: (() => Promise<SQLiteConnection>) | null);
|
|
140
|
-
ensureEpoch(): Promise<string>;
|
|
141
|
-
readAtPositionWith<T>(read: (conn: SQLiteConnection) => Promise<T>): Promise<{
|
|
142
|
-
value: T;
|
|
143
|
-
position: string;
|
|
144
|
-
seq: bigint;
|
|
145
|
-
}>;
|
|
146
|
-
liveConnection(): Promise<{
|
|
147
|
-
conn: SQLiteConnection;
|
|
148
|
-
run: RunExclusive$1;
|
|
149
|
-
}>;
|
|
150
|
-
closeLiveConnection(): Promise<void>;
|
|
151
|
-
get subscriptions(): SubscriptionManager | null;
|
|
152
|
-
get changeTracker(): ChangeTracker | null;
|
|
153
|
-
watch(table: string): Promise<void>;
|
|
154
|
-
ensureStamper(): Promise<SyncStamper>;
|
|
155
|
-
ensureStamping(): Promise<void>;
|
|
156
|
-
stampStatements(options?: {
|
|
157
|
-
persistClock?: boolean;
|
|
158
|
-
}): readonly StampStatement[] | null;
|
|
159
|
-
applyStamps(txConn: SQLiteConnection): Promise<void>;
|
|
160
|
-
unwatch(table: string): Promise<void>;
|
|
161
|
-
on(table: string): SubscriptionBuilder;
|
|
162
|
-
runTransaction<T>(writer: SQLiteConnection, fn: (tx: Transaction) => Promise<T>): Promise<T>;
|
|
163
|
-
stop(): void;
|
|
164
|
-
private ensure;
|
|
165
|
-
private ensurePolling;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
declare class WriterLock {
|
|
169
|
-
private tail;
|
|
170
|
-
private readonly context;
|
|
171
|
-
constructor(context?: WriterContext);
|
|
172
|
-
run<T>(operation: () => Promise<T>): Promise<T>;
|
|
173
|
-
isHeld(): boolean;
|
|
174
|
-
settle(): Promise<void>;
|
|
175
|
-
detached<T>(operation: () => T): T;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
interface DatabaseMigrationDeps {
|
|
179
|
-
pool: ConnectionPool;
|
|
180
|
-
writerLock: WriterLock;
|
|
181
|
-
changeTracker: () => ChangeTracker | null;
|
|
182
|
-
}
|
|
183
|
-
declare class DatabaseMigrationController {
|
|
184
|
-
private readonly deps;
|
|
185
|
-
constructor(deps: DatabaseMigrationDeps);
|
|
186
|
-
migrate(migrations: Migration[]): Promise<MigrationResult>;
|
|
187
|
-
rollback(migrations: Migration[], version?: number): Promise<RollbackResult>;
|
|
188
|
-
applied(): Promise<AppliedMigrationRow[]>;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Names of the lifecycle points a hook can attach to.
|
|
193
|
-
*
|
|
194
|
-
* @internal
|
|
195
|
-
*/
|
|
196
|
-
type HookEvent = 'beforeQuery' | 'afterQuery' | 'beforeConnect' | 'databaseOpen' | 'databaseClose' | 'beforeSubscribe' | 'beforeSnapshot';
|
|
197
|
-
/**
|
|
198
|
-
* Context a subscribe hook receives.
|
|
199
|
-
*
|
|
200
|
-
* @internal
|
|
201
|
-
*/
|
|
202
|
-
type SubscribeHookContext = Parameters<BeforeSubscribeHook>[0];
|
|
203
|
-
/**
|
|
204
|
-
* Context a snapshot hook receives.
|
|
205
|
-
*
|
|
206
|
-
* @internal
|
|
207
|
-
*/
|
|
208
|
-
type SnapshotHookContext = Parameters<BeforeSnapshotHook>[0];
|
|
209
|
-
/**
|
|
210
|
-
* Maps each lifecycle point to the context its hooks receive.
|
|
211
|
-
*
|
|
212
|
-
* @internal
|
|
213
|
-
*/
|
|
214
|
-
interface HookEventContextMap {
|
|
215
|
-
beforeQuery: QueryHookContext;
|
|
216
|
-
afterQuery: QueryHookContext & {
|
|
217
|
-
durationMs: number;
|
|
218
|
-
};
|
|
219
|
-
beforeConnect: ConnectionHookContext;
|
|
220
|
-
databaseOpen: ConnectionHookContext;
|
|
221
|
-
databaseClose: ConnectionHookContext;
|
|
222
|
-
beforeSubscribe: SubscribeHookContext;
|
|
223
|
-
beforeSnapshot: SnapshotHookContext;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Function a hook registration stores for one lifecycle point.
|
|
227
|
-
*
|
|
228
|
-
* @internal
|
|
229
|
-
*/
|
|
230
|
-
type HookHandler<E extends HookEvent> = (ctx: HookEventContextMap[E]) => void | Promise<void>;
|
|
231
|
-
/**
|
|
232
|
-
* Removes the hook it was returned for, and changes nothing when called again.
|
|
233
|
-
*
|
|
234
|
-
* @public
|
|
235
|
-
*/
|
|
236
|
-
type HookDispose = () => void;
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Holds the lifecycle hooks a database or registry has registered and invokes them in order.
|
|
240
|
-
*
|
|
241
|
-
* @internal
|
|
242
|
-
*/
|
|
243
|
-
declare class HookRegistry {
|
|
244
|
-
private hooks;
|
|
245
|
-
constructor(config?: HookConfig);
|
|
246
|
-
register<E extends HookEvent>(event: E, hook: HookHandler<E>): HookDispose;
|
|
247
|
-
invoke<E extends HookEvent>(event: E, ctx: HookEventContextMap[E]): Promise<void>;
|
|
248
|
-
invokeSync<E extends HookEvent>(event: E, ctx: HookEventContextMap[E]): void;
|
|
249
|
-
has(event: HookEvent): boolean;
|
|
250
|
-
count(event: HookEvent): number;
|
|
251
|
-
clear(event?: HookEvent): void;
|
|
252
|
-
private addHook;
|
|
253
|
-
private loadConfig;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Times queries and reports connection and change-capture activity to the configured metrics callbacks.
|
|
258
|
-
*
|
|
259
|
-
* @internal
|
|
260
|
-
*/
|
|
261
|
-
declare class MetricsCollector {
|
|
262
|
-
private config;
|
|
263
|
-
constructor(config?: MetricsConfig);
|
|
264
|
-
trackQuery<T>(fn: () => Promise<T>, context: Omit<QueryMetrics, 'durationMs' | 'error'>): Promise<T>;
|
|
265
|
-
trackConnection(metrics: ConnectionMetrics): void;
|
|
266
|
-
trackCDCEvent(metrics: CDCMetrics): void;
|
|
267
|
-
get active(): boolean;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
interface ObservedStatement {
|
|
271
|
-
sql: string;
|
|
272
|
-
params?: Params;
|
|
273
|
-
}
|
|
274
|
-
declare class DatabaseObserver {
|
|
275
|
-
private readonly databaseId;
|
|
276
|
-
private readonly localHooks;
|
|
277
|
-
private readonly parentHooks;
|
|
278
|
-
private readonly metrics;
|
|
279
|
-
constructor(databaseId: string, localHooks: HookRegistry, parentHooks: HookRegistry | null, metrics: MetricsCollector | null);
|
|
280
|
-
get observesQueries(): boolean;
|
|
281
|
-
withQueryHooks<T>(sql: string, params: Params | undefined, options: QueryOptions | undefined, op: () => Promise<T>): Promise<T>;
|
|
282
|
-
track<T>(sql: string, op: () => Promise<T>): Promise<T>;
|
|
283
|
-
withTransactionHooks(statements: readonly ObservedStatement[], op: () => Promise<ExecuteResult[]>): Promise<ExecuteResult[]>;
|
|
284
|
-
private trackEach;
|
|
285
|
-
private fireBefore;
|
|
286
|
-
private fireAfter;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
interface DatabaseReadDeps {
|
|
290
|
-
pool: ConnectionPool;
|
|
291
|
-
writerLock: WriterLock;
|
|
292
|
-
observer: DatabaseObserver;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
interface StagedRecovery {
|
|
296
|
-
resumeSeq: bigint | null;
|
|
297
|
-
appliedSeq: bigint | null;
|
|
298
|
-
/**
|
|
299
|
-
* The failure that stopped the recovery apply, or null. The staged rows
|
|
300
|
-
* are untouched by the failure and the resume watermark still covers
|
|
301
|
-
* them, so the caller opens the subscription anyway: a schema-gate refusal
|
|
302
|
-
* there is what tells a device it must migrate before this apply can
|
|
303
|
-
* succeed. The caller must then retry the recovery, because the resume
|
|
304
|
-
* watermark is past the transaction this apply left unapplied, so the
|
|
305
|
-
* server sends nothing that would prompt another try.
|
|
306
|
-
*/
|
|
307
|
-
applyError: unknown | null;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* How far a device has pulled from its server, and which sequence space that
|
|
312
|
-
* position belongs to.
|
|
313
|
-
*
|
|
314
|
-
* @public
|
|
315
|
-
*/
|
|
316
|
-
interface DeviceSyncPullState {
|
|
317
|
-
/** Highest server change-log position this device has applied. */
|
|
318
|
-
seq: bigint;
|
|
319
|
-
/** Sequence space that position came from. */
|
|
320
|
-
epoch: string | undefined;
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* What a device's local database offers the sync loop: it stages and applies
|
|
324
|
-
* what the server sends, reads what the device still owes the server, and
|
|
325
|
-
* keeps both cursors. Take one from {@link Database.deviceSync}.
|
|
326
|
-
*
|
|
327
|
-
* @public
|
|
328
|
-
*/
|
|
329
|
-
interface DeviceSyncPort {
|
|
330
|
-
/** Returns the identifier this device stamps its own changes with. */
|
|
331
|
-
identity(): Promise<{
|
|
332
|
-
nodeId: string;
|
|
333
|
-
}>;
|
|
334
|
-
/** Applies one pulled transaction and advances the pull cursor in the same write. */
|
|
335
|
-
applyPulledTransaction(changes: readonly ReplicationChange[], pullSeq: bigint, resolver?: ConflictResolver | ((table: string) => ConflictResolver)): Promise<ApplyResult>;
|
|
336
|
-
/** Stores pulled changes durably without applying them, so an interrupted device resumes from disk. */
|
|
337
|
-
stagePulledChanges(events: readonly ChangeEvent[]): Promise<bigint | null>;
|
|
338
|
-
/** Applies whatever is staged and returns the position reached. */
|
|
339
|
-
applyStagedPull(resolver?: ConflictResolver | ((table: string) => ConflictResolver), onChange?: (event: ChangeEvent) => void): Promise<bigint | null>;
|
|
340
|
-
/** Applies what a previous run left staged, and reports the failure that stopped it. */
|
|
341
|
-
recoverStagedPull(resolver?: ConflictResolver | ((table: string) => ConflictResolver), onChange?: (event: ChangeEvent) => void): Promise<StagedRecovery>;
|
|
342
|
-
/** Reads the next run of local changes the device still owes the server. */
|
|
343
|
-
readOutboxBatch(afterSeq: bigint, limit: number): Promise<ReplicationBatch | null>;
|
|
344
|
-
/** Counts the local changes the device still owes the server. */
|
|
345
|
-
countOutboxPending(afterSeq: bigint): Promise<number>;
|
|
346
|
-
/** Reads how far the device has pushed. */
|
|
347
|
-
getPushCursor(): Promise<bigint>;
|
|
348
|
-
/** Records how far the device has pushed. */
|
|
349
|
-
setPushCursor(seq: bigint): Promise<void>;
|
|
350
|
-
/** Reads how far the device has pulled, or null before it has pulled anything. */
|
|
351
|
-
getPullState(): Promise<DeviceSyncPullState | null>;
|
|
352
|
-
/** Reports whether the server has told this device to download a fresh snapshot. */
|
|
353
|
-
getResyncRequired(): Promise<boolean>;
|
|
354
|
-
/** Records whether the device must download a fresh snapshot. */
|
|
355
|
-
setResyncRequired(required: boolean): Promise<void>;
|
|
356
|
-
/** Records how far the device has pulled, and the sequence space it came from. */
|
|
357
|
-
setPullState(seq: bigint, epoch?: string): Promise<void>;
|
|
358
|
-
/** Keeps changes above a position out of pruning until the server has accepted them. */
|
|
359
|
-
protectUnpushedChanges(pushedSeq: bigint): void;
|
|
360
|
-
/** Reports whether a snapshot download was interrupted and still has to finish. */
|
|
361
|
-
snapshotLoadPending(): Promise<boolean>;
|
|
362
|
-
/** Clears the named tables and opens the database for a snapshot download. */
|
|
363
|
-
beginSnapshotLoad(tables: readonly string[]): Promise<void>;
|
|
364
|
-
/** Applies the schema statements a snapshot carries. */
|
|
365
|
-
applySnapshotSchema(schema: readonly string[]): Promise<void>;
|
|
366
|
-
/** Writes one page of snapshot rows into a table. */
|
|
367
|
-
loadSnapshotPage(table: string, rows: readonly Record<string, unknown>[]): Promise<void>;
|
|
368
|
-
/** Replaces the local migration history with the server's. */
|
|
369
|
-
replaceMigrationHistory(rows: readonly AppliedMigrationRow[]): Promise<void>;
|
|
370
|
-
/** Closes a completed snapshot download and reopens the database for normal use. */
|
|
371
|
-
endSnapshotLoad(tables: readonly string[]): Promise<void>;
|
|
372
|
-
/** Abandons a snapshot download, leaving the database marked as needing another. */
|
|
373
|
-
abortSnapshotLoad(): Promise<void>;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
type RunExclusive = <T>(op: () => Promise<T>) => Promise<T>;
|
|
377
|
-
|
|
378
|
-
declare class DatabaseSyncController {
|
|
379
|
-
private readonly runExclusive;
|
|
380
|
-
private readonly acquireWriter;
|
|
381
|
-
private readonly cdc;
|
|
382
|
-
private pkResolver;
|
|
383
|
-
private tablesReady;
|
|
384
|
-
private metaReady;
|
|
385
|
-
private outboxReader;
|
|
386
|
-
private localPruneBoundary;
|
|
387
|
-
private snapshotGate;
|
|
388
|
-
private readonly defaultResolver;
|
|
389
|
-
constructor(runExclusive: RunExclusive, acquireWriter: () => SQLiteConnection, cdc: DatabaseCdcController);
|
|
390
|
-
applyChanges(batch: ReplicationBatch, resolver?: ConflictResolver | ((table: string) => ConflictResolver)): Promise<ApplyResult>;
|
|
391
|
-
devicePort(): DeviceSyncPort;
|
|
392
|
-
get snapshotLoadBlocked(): boolean;
|
|
393
|
-
seedSnapshotGate(): void;
|
|
394
|
-
private applyPulledTransaction;
|
|
395
|
-
private stagePulled;
|
|
396
|
-
private applyStagedPull;
|
|
397
|
-
private recoverStagedPullState;
|
|
398
|
-
private stagedApplyOptions;
|
|
399
|
-
private replaceMigrationHistory;
|
|
400
|
-
private beginSnapshotLoad;
|
|
401
|
-
private endSnapshotLoad;
|
|
402
|
-
private applyLocalPruneBoundary;
|
|
403
|
-
private readOutboxBatch;
|
|
404
|
-
private countOutboxPending;
|
|
405
|
-
private getResyncRequired;
|
|
406
|
-
private setResyncRequired;
|
|
407
|
-
private getPullState;
|
|
408
|
-
private setPullState;
|
|
409
|
-
private getMetaSeq;
|
|
410
|
-
private setMetaSeq;
|
|
411
|
-
private ensureMeta;
|
|
412
|
-
private ensureSyncTables;
|
|
413
|
-
private ensureOutboxReader;
|
|
414
|
-
private ensureApplier;
|
|
415
|
-
private catchUpLocalColumnVersions;
|
|
416
|
-
private lastAppliedSeq;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* Runs a read on one connection and returns the rows with their values decoded.
|
|
421
|
-
*
|
|
422
|
-
* @internal
|
|
423
|
-
*/
|
|
424
|
-
declare function query<T = Record<string, unknown>>(conn: SQLiteConnection, sql: string, params?: Params): Promise<T[]>;
|
|
425
|
-
/**
|
|
426
|
-
* Runs a read on one connection and returns the first row, or undefined when there is none.
|
|
427
|
-
*
|
|
428
|
-
* @internal
|
|
429
|
-
*/
|
|
430
|
-
declare function queryOne<T = Record<string, unknown>>(conn: SQLiteConnection, sql: string, params?: Params): Promise<T | undefined>;
|
|
431
|
-
/**
|
|
432
|
-
* Runs one write on a connection and returns the change count and last inserted row id.
|
|
433
|
-
*
|
|
434
|
-
* @internal
|
|
435
|
-
*/
|
|
436
|
-
declare function execute(conn: SQLiteConnection, sql: string, params?: Params, trusted?: boolean): Promise<ExecuteResult>;
|
|
437
|
-
interface GroupStatement {
|
|
438
|
-
sql: string;
|
|
439
|
-
params?: Params;
|
|
440
|
-
trusted?: boolean;
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Runs one statement over many parameter sets on a connection and returns a result per set.
|
|
444
|
-
*
|
|
445
|
-
* @internal
|
|
446
|
-
*/
|
|
447
|
-
declare function executeBatch(conn: SQLiteConnection, sql: string, paramsBatch: Params[]): Promise<ExecuteResult[]>;
|
|
448
|
-
|
|
449
|
-
interface GroupCommitterHooks {
|
|
450
|
-
acquireWriter: () => SQLiteConnection;
|
|
451
|
-
afterCommit: (writer: SQLiteConnection, sql: string) => Promise<void>;
|
|
452
|
-
stampStatements: (options?: {
|
|
453
|
-
persistClock?: boolean;
|
|
454
|
-
}) => readonly GroupStatement[] | null;
|
|
455
|
-
}
|
|
456
|
-
declare class GroupCommitter {
|
|
457
|
-
private readonly writerLock;
|
|
458
|
-
private readonly hooks;
|
|
459
|
-
private readonly maxGroup;
|
|
460
|
-
private readonly pending;
|
|
461
|
-
private running;
|
|
462
|
-
private scheduled;
|
|
463
|
-
private loopPromise;
|
|
464
|
-
constructor(writerLock: WriterLock, hooks: GroupCommitterHooks, maxGroup?: number);
|
|
465
|
-
submit(sql: string, params?: Params): Promise<ExecuteResult>;
|
|
466
|
-
submitTransaction(statements: readonly GroupStatement[]): Promise<ExecuteResult[]>;
|
|
467
|
-
drain(): Promise<void>;
|
|
468
|
-
runUngrouped(sql: string, params?: Params): Promise<ExecuteResult>;
|
|
469
|
-
private schedule;
|
|
470
|
-
private runLoop;
|
|
471
|
-
private takeBatch;
|
|
472
|
-
private flush;
|
|
473
|
-
private needsStamp;
|
|
474
|
-
private runSingle;
|
|
475
|
-
private runStampedAlone;
|
|
476
|
-
private runGroup;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
declare class WriteGate {
|
|
480
|
-
private readonly limit;
|
|
481
|
-
private readonly retryAfterMs;
|
|
482
|
-
private inFlight;
|
|
483
|
-
constructor(limit: number, retryAfterMs: number);
|
|
484
|
-
run<T>(op: () => Promise<T>): Promise<T>;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
interface DatabaseWriteDeps {
|
|
488
|
-
pool: ConnectionPool;
|
|
489
|
-
writeGate: WriteGate;
|
|
490
|
-
writerLock: WriterLock;
|
|
491
|
-
groupCommitter: GroupCommitter;
|
|
492
|
-
cdc: DatabaseCdcController;
|
|
493
|
-
observer: DatabaseObserver;
|
|
494
|
-
synchronous: SynchronousLevel;
|
|
495
|
-
walMode: boolean;
|
|
496
|
-
capturesChangeLog: boolean;
|
|
497
|
-
}
|
|
498
|
-
declare class DatabaseWriteController {
|
|
499
|
-
private readonly deps;
|
|
500
|
-
constructor(deps: DatabaseWriteDeps);
|
|
501
|
-
execute(sql: string, params?: Params, options?: QueryOptions): Promise<ExecuteResult>;
|
|
502
|
-
executeBatch(sql: string, paramsBatch: Params[], options?: QueryOptions): Promise<ExecuteResult[]>;
|
|
503
|
-
bulkLoad(sql: string, paramsBatch: Params[], options?: BulkLoadOptions): Promise<BulkLoadResult>;
|
|
504
|
-
executeTransaction(statements: readonly {
|
|
505
|
-
sql: string;
|
|
506
|
-
params?: Params;
|
|
507
|
-
}[]): Promise<ExecuteResult[]>;
|
|
508
|
-
transaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T>;
|
|
509
|
-
drain(): Promise<void>;
|
|
510
|
-
private runStatementsAlone;
|
|
511
|
-
private runInTransaction;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
interface DatabaseInternals {
|
|
515
|
-
parentHooks?: HookRegistry;
|
|
516
|
-
metrics?: MetricsCollector;
|
|
517
|
-
}
|
|
518
|
-
interface DatabaseRuntime {
|
|
519
|
-
pool: ConnectionPool;
|
|
520
|
-
writeGate: WriteGate;
|
|
521
|
-
writerLock: WriterLock;
|
|
522
|
-
hookRegistry: HookRegistry;
|
|
523
|
-
observer: DatabaseObserver;
|
|
524
|
-
backups: DatabaseBackupController;
|
|
525
|
-
cdc: DatabaseCdcController;
|
|
526
|
-
sync: DatabaseSyncController;
|
|
527
|
-
groupCommitter: GroupCommitter;
|
|
528
|
-
writes: DatabaseWriteController;
|
|
529
|
-
reads: DatabaseReadDeps;
|
|
530
|
-
migrations: DatabaseMigrationController;
|
|
531
|
-
loadExtension: (extensionPath: string) => Promise<void>;
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
/**
|
|
535
|
-
* What every open database carries whatever statements run on it: which file
|
|
536
|
-
* it is, the runtime behind it, the guards each member runs before it touches
|
|
537
|
-
* that runtime, and the members that close it.
|
|
538
|
-
*
|
|
539
|
-
* Open a database through {@link Sirannon.open}, which hands back a
|
|
540
|
-
* {@link Database} built on this.
|
|
541
|
-
*
|
|
542
|
-
* @public
|
|
543
|
-
*/
|
|
544
|
-
declare class DatabaseLifecycle {
|
|
545
|
-
/** Identifier this database was opened under. */
|
|
546
|
-
readonly id: string;
|
|
547
|
-
/** File path of the SQLite database. */
|
|
548
|
-
readonly path: string;
|
|
549
|
-
/** Whether this database refuses writes. */
|
|
550
|
-
readonly readOnly: boolean;
|
|
551
|
-
/**
|
|
552
|
-
* Pool, locks, and controllers this database runs its work through.
|
|
553
|
-
*
|
|
554
|
-
* @internal
|
|
555
|
-
*/
|
|
556
|
-
protected readonly runtime: DatabaseRuntime;
|
|
557
|
-
/**
|
|
558
|
-
* Functions that run while this database closes.
|
|
559
|
-
*
|
|
560
|
-
* @internal
|
|
561
|
-
*/
|
|
562
|
-
protected readonly closeListeners: (() => void | Promise<void>)[];
|
|
563
|
-
private closing;
|
|
564
|
-
protected constructor(id: string, path: string, runtime: DatabaseRuntime, options?: DatabaseOptions);
|
|
565
|
-
/**
|
|
566
|
-
* Registers a function that runs while this database closes.
|
|
567
|
-
*
|
|
568
|
-
* @param fn - Called during {@link DatabaseLifecycle.close}.
|
|
569
|
-
*
|
|
570
|
-
* @internal
|
|
571
|
-
*/
|
|
572
|
-
addCloseListener(fn: () => void | Promise<void>): void;
|
|
573
|
-
/**
|
|
574
|
-
* Closes every connection this database holds and ends its subscriptions.
|
|
575
|
-
*/
|
|
576
|
-
close(): Promise<void>;
|
|
577
|
-
/**
|
|
578
|
-
* Whether this database has been closed.
|
|
579
|
-
*/
|
|
580
|
-
get closed(): boolean;
|
|
581
|
-
/**
|
|
582
|
-
* Number of read connections the pool holds.
|
|
583
|
-
*/
|
|
584
|
-
get readerCount(): number;
|
|
585
|
-
/**
|
|
586
|
-
* Refuses the call when this database is closed, is loading a snapshot, or refuses writes.
|
|
587
|
-
*
|
|
588
|
-
* @internal
|
|
589
|
-
*/
|
|
590
|
-
protected ensureWritable(): void;
|
|
591
|
-
/**
|
|
592
|
-
* Refuses the call when this database is closed or is loading a snapshot.
|
|
593
|
-
*
|
|
594
|
-
* @internal
|
|
595
|
-
*/
|
|
596
|
-
protected ensureOpen(): void;
|
|
597
|
-
/**
|
|
598
|
-
* Refuses the call when this database is closed.
|
|
599
|
-
*
|
|
600
|
-
* @internal
|
|
601
|
-
*/
|
|
602
|
-
protected ensureNotClosed(): void;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* Everything an open database does about its backups: one-off copies, the cron
|
|
607
|
-
* schedule, the cycle that captures its change log, and the questions its chain
|
|
608
|
-
* of backups can answer.
|
|
609
|
-
*
|
|
610
|
-
* Open a database through {@link Sirannon.open}. What you get back is a
|
|
611
|
-
* {@link Database}, which is built on this.
|
|
612
|
-
*
|
|
613
|
-
* @public
|
|
614
|
-
*/
|
|
615
|
-
declare class DatabaseBackups extends DatabaseLifecycle {
|
|
616
|
-
/**
|
|
617
|
-
* Copies this database to a file while it stays open for reads and writes.
|
|
618
|
-
*
|
|
619
|
-
* SQLite moves the pages in steps on the connection that writes, so a write
|
|
620
|
-
* runs in the gap between two steps rather than waiting for the whole copy.
|
|
621
|
-
*
|
|
622
|
-
* @param destPath - Path the copy is written to.
|
|
623
|
-
* @returns The run identifier, the timings, the pages it moved, and the bytes the file holds.
|
|
624
|
-
*/
|
|
625
|
-
backup(destPath: string): Promise<BackupFileReport>;
|
|
626
|
-
/**
|
|
627
|
-
* Copies this database to a destination you supply, in fixed-size pieces,
|
|
628
|
-
* while it stays open for reads and writes.
|
|
629
|
-
*
|
|
630
|
-
* Sirannon carries no storage client, so the destination is where you
|
|
631
|
-
* connect object storage or anything else that moves bytes.
|
|
632
|
-
*
|
|
633
|
-
* The pieces reach the destination as SQLite writes them where this runtime
|
|
634
|
-
* carries the compiled streaming extension, so the run needs no local disk.
|
|
635
|
-
* Every other runtime writes one local file first and needs local disk equal
|
|
636
|
-
* to the backup. {@link DatabaseBackups.backupCapabilities} states which of
|
|
637
|
-
* the two this one does.
|
|
638
|
-
*
|
|
639
|
-
* @param options - Destination, naming, piece size, and progress reporting.
|
|
640
|
-
* @returns The run identifier, the timings, what the run wrote, and how often the copy restarted.
|
|
641
|
-
*/
|
|
642
|
-
backupTo(options: BackupToDestinationOptions): Promise<BackupRunReport>;
|
|
643
|
-
/**
|
|
644
|
-
* Reports which backup operations this database's runtime supports, so you
|
|
645
|
-
* learn before a run rather than when one fails.
|
|
646
|
-
*
|
|
647
|
-
* @returns What this runtime copies, whether it needs local disk, and whether it schedules.
|
|
648
|
-
*/
|
|
649
|
-
backupCapabilities(): BackupCapabilities;
|
|
650
|
-
/**
|
|
651
|
-
* Starts repeating backups on a cron schedule, keeping a bounded number of files.
|
|
652
|
-
*
|
|
653
|
-
* @param options - Cron expression, destination directory, retention, and time zone, along with the callbacks Sirannon calls after each finished copy and after each failure.
|
|
654
|
-
*/
|
|
655
|
-
scheduleBackup(options: BackupScheduleOptions): void;
|
|
656
|
-
/**
|
|
657
|
-
* Runs one turn of the checkpoint cycle now instead of waiting for its
|
|
658
|
-
* interval. A turn sends any capture still waiting, reads the log frames
|
|
659
|
-
* written since the previous turn, and then checkpoints the log.
|
|
660
|
-
*
|
|
661
|
-
* A database needs the `backups` option to have a cycle at all. On a node its
|
|
662
|
-
* replication group backs up from somewhere else, the turn writes nothing and
|
|
663
|
-
* reports a skip through `onSkip`.
|
|
664
|
-
*
|
|
665
|
-
* @returns What the turn wrote, or undefined where it wrote nothing.
|
|
666
|
-
*/
|
|
667
|
-
captureBackupChanges(): Promise<BackupRunReport | undefined>;
|
|
668
|
-
/**
|
|
669
|
-
* Lists what the backup destination holds.
|
|
670
|
-
*
|
|
671
|
-
* @returns One entry per chain, newest first, each with its full copy and its change pieces in order.
|
|
672
|
-
*/
|
|
673
|
-
backupChain(): Promise<BackupChain[]>;
|
|
674
|
-
/**
|
|
675
|
-
* Reads what this database's backup cycle is doing at this moment, and what
|
|
676
|
-
* its recent turns produced.
|
|
677
|
-
*
|
|
678
|
-
* A caller that triggers a turn with {@link DatabaseBackups.captureBackupChanges}
|
|
679
|
-
* without waiting on it would read this until that turn finishes. A full copy
|
|
680
|
-
* of a large database reports its pages as SQLite moves them.
|
|
681
|
-
*
|
|
682
|
-
* @returns Whether a turn is under way, how far it has got, and the last run, skip, and failure.
|
|
683
|
-
*/
|
|
684
|
-
backupStatus(): BackupCycleStatus;
|
|
685
|
-
/**
|
|
686
|
-
* Reads one of this database's backups back out of the destination and
|
|
687
|
-
* compares it against the record the backup that wrote it left behind.
|
|
688
|
-
*
|
|
689
|
-
* A restore would fail on a damaged piece only once that restore had already
|
|
690
|
-
* begun, so name the backup here beforehand. Sirannon then fetches every
|
|
691
|
-
* piece in order and folds a SHA-256 over the bytes as they arrive, and it
|
|
692
|
-
* compares that digest and the byte count against the record. Only one piece
|
|
693
|
-
* is in memory at any moment, so a check over a large full copy needs no
|
|
694
|
-
* local storage of its own.
|
|
695
|
-
*
|
|
696
|
-
* A missing piece, a byte count that differs from the recorded one, and a
|
|
697
|
-
* digest that differs from the recorded one will each fail with
|
|
698
|
-
* `BACKUP_DESTINATION_ERROR`.
|
|
699
|
-
*
|
|
700
|
-
* @param name - Name the backup is stored under, which every entry {@link DatabaseBackups.backupChain} returns states.
|
|
701
|
-
* @returns The pieces read, the bytes they add up to, and the digest where the backup recorded one.
|
|
702
|
-
*/
|
|
703
|
-
verifyBackup(name: string): Promise<BackupVerifyResult>;
|
|
704
|
-
/**
|
|
705
|
-
* Reads where this database's backups are stored.
|
|
706
|
-
*
|
|
707
|
-
* `restoreBackup` accepts what you get back, and it then rebuilds this
|
|
708
|
-
* database from its own backups at whatever path you name.
|
|
709
|
-
*
|
|
710
|
-
* @returns The destination, the name its chains are listed under, and the directory Sirannon stages captures in.
|
|
711
|
-
*/
|
|
712
|
-
backupLocation(): BackupChainLocation;
|
|
713
|
-
/**
|
|
714
|
-
* Works out what a restore to a given moment has to read.
|
|
715
|
-
*
|
|
716
|
-
* The result also tells you the moment it would actually reach, which is when
|
|
717
|
-
* the last piece was captured. One piece covers every write in the interval
|
|
718
|
-
* it was taken over, so a restore arrives at a piece boundary, not at the
|
|
719
|
-
* exact millisecond you named.
|
|
720
|
-
*
|
|
721
|
-
* @param moment - Epoch milliseconds you want back.
|
|
722
|
-
* @returns The full copy, the change pieces to apply in order, and the moment the result reflects.
|
|
723
|
-
*/
|
|
724
|
-
backupRestorePlan(moment: number): Promise<BackupRestorePlan>;
|
|
725
|
-
/**
|
|
726
|
-
* Tells you which backups no restore still needs, so you can delete them
|
|
727
|
-
* knowing exactly what you give up. Name the earliest moment you still want
|
|
728
|
-
* to reach and the answer also covers the older chains a newer full copy
|
|
729
|
-
* already spans.
|
|
730
|
-
*
|
|
731
|
-
* Sirannon lists them and deletes nothing. The destination is yours.
|
|
732
|
-
*
|
|
733
|
-
* @param options - How far back you still want to be able to restore.
|
|
734
|
-
* @returns The records you may delete, oldest first.
|
|
735
|
-
*/
|
|
736
|
-
backupPiecesSafeToDelete(options?: BackupSafeToDeleteOptions): Promise<BackupChainRecord[]>;
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
/**
|
|
740
|
-
* One open SQLite database, with its reads, writes, transactions, migrations, change subscriptions, and live queries.
|
|
741
|
-
*
|
|
742
|
-
* Open one through {@link Sirannon.open} rather than constructing it.
|
|
743
|
-
*
|
|
744
|
-
* @public
|
|
745
|
-
*/
|
|
746
|
-
declare class Database extends DatabaseBackups {
|
|
747
|
-
/** @internal */
|
|
748
|
-
static create(id: string, path: string, driver: SQLiteDriver, options?: DatabaseOptions, internals?: DatabaseInternals): Promise<Database>;
|
|
749
|
-
/** @internal */
|
|
750
|
-
applyChanges(batch: ReplicationBatch, resolver?: ConflictResolver | ((table: string) => ConflictResolver)): Promise<ApplyResult>;
|
|
751
|
-
/**
|
|
752
|
-
* Returns the device-sync port for this database, which reads and advances
|
|
753
|
-
* the cursors a `SyncController` keeps against a server.
|
|
754
|
-
*
|
|
755
|
-
* @returns The port, which `downloadDatabaseSnapshot` also accepts.
|
|
756
|
-
*/
|
|
757
|
-
deviceSync(): DeviceSyncPort;
|
|
758
|
-
/**
|
|
759
|
-
* Runs a read and returns every row.
|
|
760
|
-
*
|
|
761
|
-
* @param sql - The statement to run.
|
|
762
|
-
* @param params - Values bound to the statement, named or positional.
|
|
763
|
-
* @param options - Read concern for this statement.
|
|
764
|
-
* @returns The rows the statement produced.
|
|
765
|
-
*/
|
|
766
|
-
query<T = Record<string, unknown>>(sql: string, params?: Params, options?: QueryOptions): Promise<T[]>;
|
|
767
|
-
/** @internal */
|
|
768
|
-
queryForWire(sql: string, params?: Params, options?: QueryOptions): Promise<unknown[]>;
|
|
769
|
-
/**
|
|
770
|
-
* Runs a read and returns its first row.
|
|
771
|
-
*
|
|
772
|
-
* @param sql - The statement to run.
|
|
773
|
-
* @param params - Values bound to the statement, named or positional.
|
|
774
|
-
* @param options - Read concern for this statement.
|
|
775
|
-
* @returns The first row, or undefined when the statement produced none.
|
|
776
|
-
*/
|
|
777
|
-
queryOne<T = Record<string, unknown>>(sql: string, params?: Params, options?: QueryOptions): Promise<T | undefined>;
|
|
778
|
-
/**
|
|
779
|
-
* Runs one write.
|
|
780
|
-
*
|
|
781
|
-
* @param sql - The statement to run.
|
|
782
|
-
* @param params - Values bound to the statement, named or positional.
|
|
783
|
-
* @param options - Write concern for this statement.
|
|
784
|
-
* @returns How many rows changed, and the last inserted row id.
|
|
785
|
-
*/
|
|
786
|
-
execute(sql: string, params?: Params, options?: QueryOptions): Promise<ExecuteResult>;
|
|
787
|
-
/**
|
|
788
|
-
* Runs one statement over many parameter sets inside a single transaction.
|
|
789
|
-
*
|
|
790
|
-
* @param sql - The statement to run for each parameter set.
|
|
791
|
-
* @param paramsBatch - One parameter set per run.
|
|
792
|
-
* @param options - Write concern for the transaction.
|
|
793
|
-
* @returns One result per parameter set, in order.
|
|
794
|
-
*/
|
|
795
|
-
executeBatch(sql: string, paramsBatch: Params[], options?: QueryOptions): Promise<ExecuteResult[]>;
|
|
796
|
-
/**
|
|
797
|
-
* Imports many rows with relaxed writer durability, then restores the configured level.
|
|
798
|
-
*
|
|
799
|
-
* Use this for a load you can re-run from scratch, because
|
|
800
|
-
* {@link Database.executeBatch} keeps full durability. The load holds the
|
|
801
|
-
* writer lock throughout and restores the configured level before this
|
|
802
|
-
* resolves, whether it succeeds or fails. One transaction covers the whole
|
|
803
|
-
* batch, and the rows are summed rather than returned one by one to bound
|
|
804
|
-
* memory on a large load. Like {@link Database.execute}, this writes only to
|
|
805
|
-
* the local database; under replication the server routes loads through the
|
|
806
|
-
* engine instead.
|
|
807
|
-
*
|
|
808
|
-
* @param sql - The statement to run for each parameter set.
|
|
809
|
-
* @param paramsBatch - One parameter set per row.
|
|
810
|
-
* @param options - Durability during the load, and whether it ends with a checkpoint.
|
|
811
|
-
* @returns How many rows the load applied and how many rows changed.
|
|
812
|
-
*/
|
|
813
|
-
bulkLoad(sql: string, paramsBatch: Params[], options?: BulkLoadOptions): Promise<BulkLoadResult>;
|
|
814
|
-
/**
|
|
815
|
-
* Runs a fixed list of statements in one transaction so that several callers can share one commit.
|
|
816
|
-
*
|
|
817
|
-
* This takes the statements up front rather than a callback, because a group
|
|
818
|
-
* cannot wait on an arbitrary caller-supplied callback without delaying every
|
|
819
|
-
* transaction beside it.
|
|
820
|
-
*
|
|
821
|
-
* @param statements - The statements to run, in order, each with its own parameters.
|
|
822
|
-
* @returns One result per statement, in order.
|
|
823
|
-
*/
|
|
824
|
-
executeTransaction(statements: readonly {
|
|
825
|
-
sql: string;
|
|
826
|
-
params?: Params;
|
|
827
|
-
}[]): Promise<ExecuteResult[]>;
|
|
828
|
-
/**
|
|
829
|
-
* Runs a function inside one transaction, committing when it returns and rolling back when it throws.
|
|
830
|
-
*
|
|
831
|
-
* @param fn - Receives the transaction and runs statements on it.
|
|
832
|
-
* @returns Whatever the function returned.
|
|
833
|
-
*/
|
|
834
|
-
transaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T>;
|
|
835
|
-
/**
|
|
836
|
-
* Starts recording changes to a table so that subscribers and replication see them.
|
|
837
|
-
*
|
|
838
|
-
* @param table - Name of the table to watch.
|
|
839
|
-
*/
|
|
840
|
-
watch(table: string): Promise<void>;
|
|
841
|
-
/**
|
|
842
|
-
* Stops recording changes to a table.
|
|
843
|
-
*
|
|
844
|
-
* @param table - Name of the table to stop watching.
|
|
845
|
-
*/
|
|
846
|
-
unwatch(table: string): Promise<void>;
|
|
847
|
-
/**
|
|
848
|
-
* Runs a CDC maintenance write (change-log pruning) on the shared writer
|
|
849
|
-
* under the writer lock. Serialising it with application writes keeps it
|
|
850
|
-
* from becoming a second writer that contends for SQLite's single write
|
|
851
|
-
* lock and stalls the event loop on `busy_timeout`.
|
|
852
|
-
*
|
|
853
|
-
* @internal
|
|
854
|
-
*/
|
|
855
|
-
runCdcMaintenance(op: (writer: SQLiteConnection) => Promise<unknown>): Promise<void>;
|
|
856
|
-
/** @internal */
|
|
857
|
-
ensureChangeStamping(): Promise<void>;
|
|
858
|
-
/**
|
|
859
|
-
* Begins a change subscription on a watched table.
|
|
860
|
-
*
|
|
861
|
-
* @param table - Name of the watched table.
|
|
862
|
-
* @returns A builder you narrow with a filter and then subscribe to.
|
|
863
|
-
*/
|
|
864
|
-
on(table: string): SubscriptionBuilder;
|
|
865
|
-
/**
|
|
866
|
-
* Opens a live query that keeps a registered read's rows current as the tables behind it change.
|
|
867
|
-
*
|
|
868
|
-
* @param operation - Name of the registered read, or a reference built by {@link operationRef}.
|
|
869
|
-
* @param args - Arguments the operation takes.
|
|
870
|
-
* @param options - Re-read jitter and the transaction size above which the query re-reads.
|
|
871
|
-
* @returns The live query, already subscribed.
|
|
872
|
-
*/
|
|
873
|
-
live<T = Record<string, unknown>>(sql: string, params?: Params, options?: LiveQueryOptions): Promise<LiveQuery<T>>;
|
|
874
|
-
/**
|
|
875
|
-
* Applies every migration this database has not yet applied, in ascending version order.
|
|
876
|
-
*
|
|
877
|
-
* @param migrations - The full set of migrations for this database.
|
|
878
|
-
* @returns Which migrations this call applied, and how many it skipped.
|
|
879
|
-
*/
|
|
880
|
-
migrate(migrations: Migration[]): Promise<MigrationResult>;
|
|
881
|
-
/**
|
|
882
|
-
* Lists the migrations this database has applied.
|
|
883
|
-
*
|
|
884
|
-
* @returns One entry per applied migration, with its version, name, and checksum.
|
|
885
|
-
*/
|
|
886
|
-
appliedMigrations(): Promise<AppliedMigrationRow[]>;
|
|
887
|
-
/**
|
|
888
|
-
* Undoes applied migrations, newest first.
|
|
889
|
-
*
|
|
890
|
-
* @param migrations - The full set of migrations so that the runner finds each down statement.
|
|
891
|
-
* @param version - Lowest version to keep. Without it, only the newest migration is undone.
|
|
892
|
-
* @returns Which migrations this call undid.
|
|
893
|
-
*/
|
|
894
|
-
rollback(migrations: Migration[], version?: number): Promise<RollbackResult>;
|
|
895
|
-
/**
|
|
896
|
-
* Loads a SQLite extension into this database.
|
|
897
|
-
*
|
|
898
|
-
* @param extensionPath - Path to the extension, which the driver resolves to an absolute path.
|
|
899
|
-
*/
|
|
900
|
-
loadExtension(extensionPath: string): Promise<void>;
|
|
901
|
-
/**
|
|
902
|
-
* Registers a hook that runs before each statement on this database. Throw from it to refuse the statement.
|
|
903
|
-
*
|
|
904
|
-
* @param hook - Receives the statement, its parameters, and the concerns it carries.
|
|
905
|
-
* @returns A function that removes the hook.
|
|
906
|
-
*/
|
|
907
|
-
onBeforeQuery(hook: BeforeQueryHook): HookDispose;
|
|
908
|
-
/**
|
|
909
|
-
* Registers a hook that runs after each statement on this database.
|
|
910
|
-
*
|
|
911
|
-
* @param hook - Receives the statement and how long it took.
|
|
912
|
-
* @returns A function that removes the hook.
|
|
913
|
-
*/
|
|
914
|
-
onAfterQuery(hook: AfterQueryHook): HookDispose;
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
export { ConnectionPool as C, Database as D, HookRegistry as H, MetricsCollector as M, type SnapshotHookContext as S, type HookDispose as a, type ConnectionPoolOptions as b, DatabaseBackups as c, DatabaseLifecycle as d, type HookEvent as e, type HookEventContextMap as f, type HookHandler as g, type SubscribeHookContext as h, execute as i, executeBatch as j, queryOne as k, type DeviceSyncPort as l, HLC as m, query as q };
|