@delali/sirannon-db 0.2.0 → 0.2.1

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.
Files changed (75) hide show
  1. package/dist/backup-scheduler/index.d.ts +15 -1
  2. package/dist/backup-scheduler/index.mjs +2 -2
  3. package/dist/baseline-D93hcIEE.d.ts +17 -0
  4. package/dist/{change-tracker-DKRVUC3l.d.ts → change-tracker-DDmXB754.d.ts} +56 -8
  5. package/dist/{chunk-5NOIGN5Y.mjs → chunk-2QLXDHAP.mjs} +1 -1
  6. package/dist/{chunk-LNY2VVHE.mjs → chunk-7C36BCSN.mjs} +1 -1
  7. package/dist/{chunk-NVQS53NT.mjs → chunk-7FQRQH5Z.mjs} +53 -64
  8. package/dist/{chunk-D7LAYTKN.mjs → chunk-7R4ER4FB.mjs} +1 -1
  9. package/dist/{chunk-FHWTZFI4.mjs → chunk-BQFQ65OL.mjs} +1 -1
  10. package/dist/{chunk-O7SLN3GI.mjs → chunk-BTTFW4Z4.mjs} +1 -1
  11. package/dist/{chunk-H6PIVVDN.mjs → chunk-CCZK6LCB.mjs} +38 -25
  12. package/dist/{chunk-JZGINXTN.mjs → chunk-HCCGEIZ2.mjs} +2 -2
  13. package/dist/{chunk-67M7KAH6.mjs → chunk-IWGIYDMZ.mjs} +1 -1
  14. package/dist/{chunk-LFZ37BSX.mjs → chunk-OUSWVNWT.mjs} +1 -1
  15. package/dist/{chunk-HR5CWTLC.mjs → chunk-P2VJYRVY.mjs} +60 -7
  16. package/dist/{chunk-UC3SCMIN.mjs → chunk-PBRXXISQ.mjs} +3 -0
  17. package/dist/{chunk-JU64Y7HM.mjs → chunk-SBL6GN43.mjs} +1 -1
  18. package/dist/{chunk-EBJXPQQO.mjs → chunk-UPKKSUPA.mjs} +2 -2
  19. package/dist/{chunk-TJF5GZSV.mjs → chunk-VOSJBZ6Q.mjs} +1 -1
  20. package/dist/{chunk-PIKHN33N.mjs → chunk-VOYGMAU7.mjs} +9 -1
  21. package/dist/{chunk-H237TXZW.mjs → chunk-WJ67DTD6.mjs} +48 -6
  22. package/dist/{chunk-OQVZBEBY.mjs → chunk-XF2HH5E6.mjs} +4 -61
  23. package/dist/client/index.d.ts +211 -12
  24. package/dist/client/index.mjs +155 -67
  25. package/dist/client/topology.d.ts +55 -7
  26. package/dist/client/topology.mjs +20 -1
  27. package/dist/{client-base-CLWmH5Ln.d.ts → client-base-CmZO0v3m.d.ts} +133 -24
  28. package/dist/codegen/cli.mjs +3 -3
  29. package/dist/codegen/index.d.ts +92 -2
  30. package/dist/codegen/index.mjs +3 -3
  31. package/dist/core/index.d.ts +177 -15
  32. package/dist/core/index.mjs +2481 -2226
  33. package/dist/core/writer-worker.mjs +3 -3
  34. package/dist/database-B5Qv1-cU.d.ts +380 -0
  35. package/dist/driver/better-sqlite3.d.ts +18 -1
  36. package/dist/driver/better-sqlite3.mjs +5 -5
  37. package/dist/driver/bun.d.ts +28 -0
  38. package/dist/driver/expo.d.ts +17 -0
  39. package/dist/driver/node.d.ts +18 -1
  40. package/dist/driver/node.mjs +5 -5
  41. package/dist/driver/wa-sqlite.d.ts +18 -1
  42. package/dist/{errors-Bw5MdNCu.d.ts → errors-Dei4GdBb.d.ts} +80 -7
  43. package/dist/file-migrations/index.d.ts +54 -2
  44. package/dist/file-migrations/index.mjs +3 -3
  45. package/dist/{operation-registry-9DcvxcE5.d.ts → operation-registry-hlbhqu7q.d.ts} +50 -1
  46. package/dist/{primary-wins-DPAm2AKG.d.ts → primary-wins-B0np8JS3.d.ts} +25 -1
  47. package/dist/protocol-rqANt-9Q.d.ts +152 -0
  48. package/dist/query-types-DL3LtPvY.d.ts +95 -0
  49. package/dist/react/index.d.ts +58 -3
  50. package/dist/replication/coordinator/etcd.d.ts +63 -3
  51. package/dist/replication/coordinator/etcd.mjs +82 -46
  52. package/dist/replication/index.d.ts +329 -95
  53. package/dist/replication/index.mjs +256 -141
  54. package/dist/server/index.d.ts +230 -12
  55. package/dist/server/index.mjs +63 -50
  56. package/dist/{server-options-1JHu8pid.d.ts → server-options-Dab_Jvd_.d.ts} +96 -12
  57. package/dist/sirannon-CMhiJa5Y.d.ts +111 -0
  58. package/dist/transport/grpc.d.ts +93 -9
  59. package/dist/transport/grpc.mjs +63 -20
  60. package/dist/transport/memory.d.ts +50 -20
  61. package/dist/transport/memory.mjs +25 -0
  62. package/dist/{types-CL6piSnD.d.ts → types-BCejqzNA.d.ts} +20 -0
  63. package/dist/types-CMBcFPhb.d.ts +336 -0
  64. package/dist/types-CjhxcjhA.d.ts +123 -0
  65. package/dist/types-DyrCiWuc.d.ts +499 -0
  66. package/dist/types-rVZKnKN-.d.ts +591 -0
  67. package/package.json +7 -1
  68. package/dist/baseline-Br77Fnhb.d.ts +0 -6
  69. package/dist/database-BY0L5Q2n.d.ts +0 -172
  70. package/dist/protocol-6KrSq2Hy.d.ts +0 -66
  71. package/dist/sirannon-DaQSyhbJ.d.ts +0 -36
  72. package/dist/types-B7gmEsZW.d.ts +0 -221
  73. package/dist/types-BsVabqSI.d.ts +0 -139
  74. package/dist/types-C_D8IhpO.d.ts +0 -60
  75. package/dist/types-zhnRXrsb.d.ts +0 -384
@@ -1,384 +0,0 @@
1
- declare class Transaction {
2
- private readonly conn;
3
- private _lastInsertRowId;
4
- constructor(conn: SQLiteConnection);
5
- query<T = Record<string, unknown>>(sql: string, params?: Params): Promise<T[]>;
6
- execute(sql: string, params?: Params): Promise<ExecuteResult>;
7
- executeBatch(sql: string, paramsBatch: Params[]): Promise<ExecuteResult[]>;
8
- get lastInsertRowId(): number | bigint;
9
- static run<T>(conn: SQLiteConnection, fn: (tx: Transaction) => Promise<T>): Promise<T>;
10
- }
11
-
12
- declare const MIGRATION_NAME_RE: RegExp;
13
- interface AppliedMigration {
14
- version: number;
15
- name: string;
16
- applied_at: number;
17
- }
18
- interface MigrationBaseline {
19
- through: number;
20
- }
21
- interface Migration {
22
- version: number;
23
- name: string;
24
- up: string | ((tx: Transaction) => void | Promise<void>);
25
- down?: string | ((tx: Transaction) => void | Promise<void>);
26
- baseline?: MigrationBaseline;
27
- }
28
- type MigrationSource = Migration[] | (() => Migration[] | Promise<Migration[]>);
29
- interface AppliedMigrationEntry {
30
- version: number;
31
- name: string;
32
- }
33
- interface MigrationResult {
34
- applied: AppliedMigrationEntry[];
35
- skipped: number;
36
- }
37
- interface RollbackResult {
38
- rolledBack: AppliedMigrationEntry[];
39
- }
40
-
41
- /** Query parameter types: named (object) or positional (array). */
42
- type Params = Record<string, unknown> | unknown[];
43
- type WriteConcernLevel = 'local' | 'majority' | 'all';
44
- interface WriteConcern {
45
- level: WriteConcernLevel;
46
- timeoutMs?: number;
47
- }
48
- type ReadConcernLevel = 'local' | 'majority' | 'linearizable';
49
- interface ReadConcern {
50
- level: ReadConcernLevel;
51
- }
52
- interface QueryOptions {
53
- writeConcern?: WriteConcern;
54
- readConcern?: ReadConcern;
55
- }
56
- interface ClusterReadEndpointInfo {
57
- nodeId: string;
58
- endpoint: string;
59
- readConcerns: ReadConcernLevel[];
60
- }
61
- /** The single word describing what a node can do right now. */
62
- type NodeHealthState = 'healthy' | 'degraded' | 'failing_over' | 'repairing' | 'syncing' | 'unavailable';
63
- /** The condition that produced a {@link NodeHealthState}. */
64
- type NodeHealthReason = 'in-sync' | 'lagging' | 'coordinator-unreachable' | 'draining' | 'repairing' | 'faulted' | 'sync-pending' | 'no-group-state';
65
- /**
66
- * The health of one node, covering only the node that reports it.
67
- *
68
- * `canRead` and `canWrite` are what that node will accept at this moment;
69
- * `state` and `reason` name the condition behind them.
70
- */
71
- interface NodeHealth {
72
- state: NodeHealthState;
73
- reason: NodeHealthReason;
74
- canRead: boolean;
75
- canWrite: boolean;
76
- }
77
- interface ClusterStatusInfo {
78
- databaseId: string;
79
- replicationGroupId?: string;
80
- role?: 'primary' | 'replica';
81
- currentPrimary?: {
82
- nodeId: string;
83
- endpoint?: string;
84
- } | null;
85
- primaryTerm?: bigint;
86
- readEndpoints?: ClusterReadEndpointInfo[];
87
- health: NodeHealthState;
88
- healthReason: NodeHealthReason;
89
- }
90
- /** Result returned by mutation statements (INSERT, UPDATE, DELETE). */
91
- interface ExecuteResult {
92
- changes: number;
93
- lastInsertRowId: number | bigint;
94
- }
95
- /** CDC operation type. */
96
- type ChangeOperation = 'insert' | 'update' | 'delete';
97
- /** Event emitted when a watched table row changes. */
98
- interface ChangeEvent<T = Record<string, unknown>> {
99
- type: ChangeOperation;
100
- table: string;
101
- row: T;
102
- oldRow?: T;
103
- seq: bigint;
104
- timestamp: number;
105
- hlc?: string;
106
- origin?: string;
107
- rowId?: string;
108
- txId?: string;
109
- txEnd?: boolean;
110
- }
111
- /** Context passed to query hooks. */
112
- interface QueryHookContext {
113
- databaseId: string;
114
- sql: string;
115
- params?: Params;
116
- metadata?: Record<string, unknown>;
117
- writeConcern?: WriteConcern;
118
- readConcern?: ReadConcern;
119
- }
120
- /** Hook invoked before a query is executed. Throw to deny. */
121
- type BeforeQueryHook = (ctx: QueryHookContext) => void | Promise<void>;
122
- /** Hook invoked after a query is executed. */
123
- type AfterQueryHook = (ctx: QueryHookContext & {
124
- durationMs: number;
125
- }) => void | Promise<void>;
126
- /** Context passed to connection hooks. */
127
- interface ConnectionHookContext {
128
- databaseId: string;
129
- path: string;
130
- }
131
- /** Hook invoked before a database connection is established. */
132
- type BeforeConnectHook = (ctx: ConnectionHookContext) => void | Promise<void>;
133
- /** Hook invoked when a database is opened. */
134
- type DatabaseOpenHook = (ctx: ConnectionHookContext) => void | Promise<void>;
135
- /** Hook invoked when a database is closed. */
136
- type DatabaseCloseHook = (ctx: ConnectionHookContext) => void | Promise<void>;
137
- /** Hook invoked before a subscription is created. Throw to deny. */
138
- type BeforeSubscribeHook = (ctx: {
139
- databaseId: string;
140
- table: string;
141
- filter?: Record<string, unknown>;
142
- }) => void | Promise<void>;
143
- /** Aggregated hook configuration. */
144
- interface HookConfig {
145
- onBeforeQuery?: BeforeQueryHook | BeforeQueryHook[];
146
- onAfterQuery?: AfterQueryHook | AfterQueryHook[];
147
- onBeforeConnect?: BeforeConnectHook | BeforeConnectHook[];
148
- onDatabaseOpen?: DatabaseOpenHook | DatabaseOpenHook[];
149
- onDatabaseClose?: DatabaseCloseHook | DatabaseCloseHook[];
150
- onBeforeSubscribe?: BeforeSubscribeHook | BeforeSubscribeHook[];
151
- }
152
- /** Metrics emitted after a query completes. */
153
- interface QueryMetrics {
154
- databaseId: string;
155
- sql: string;
156
- durationMs: number;
157
- rowsReturned?: number;
158
- changes?: number;
159
- error?: boolean;
160
- }
161
- /** Metrics emitted when a connection opens or closes. */
162
- interface ConnectionMetrics {
163
- databaseId: string;
164
- path: string;
165
- readerCount: number;
166
- event: 'open' | 'close';
167
- }
168
- /** Metrics emitted when a CDC event is dispatched. */
169
- interface CDCMetrics {
170
- databaseId: string;
171
- table: string;
172
- operation: ChangeOperation;
173
- subscriberCount: number;
174
- }
175
- /** Callbacks for metrics collection. */
176
- interface MetricsConfig {
177
- onQueryComplete?: (metrics: QueryMetrics) => void;
178
- onConnectionOpen?: (metrics: ConnectionMetrics) => void;
179
- onConnectionClose?: (metrics: ConnectionMetrics) => void;
180
- onCDCEvent?: (metrics: CDCMetrics) => void;
181
- }
182
- /** Configuration for automatic database lifecycle management. */
183
- interface LifecycleConfig {
184
- autoOpen?: {
185
- resolver: (id: string) => {
186
- path: string;
187
- options?: DatabaseOptions;
188
- } | undefined;
189
- };
190
- /** Milliseconds before an idle database is closed. 0 = disabled. */
191
- idleTimeout?: number;
192
- /** Maximum number of concurrently open databases. 0 = unlimited. */
193
- maxOpen?: number;
194
- }
195
- /** Options for opening a single database. */
196
- interface DatabaseOptions {
197
- /** Open the database in read-only mode. */
198
- readOnly?: boolean;
199
- /** Number of read connections in the pool. Default: 4. */
200
- readPoolSize?: number;
201
- /** Enable WAL mode. Default: true. */
202
- walMode?: boolean;
203
- /**
204
- * Writer durability (`PRAGMA synchronous`). Default: 'normal'. This is the
205
- * level restored after every bulk load, whatever the load relaxed it to.
206
- */
207
- synchronous?: SynchronousLevel;
208
- /** CDC polling interval in milliseconds. Default: 50. */
209
- cdcPollInterval?: number;
210
- /** CDC retention period in milliseconds. Default: 3_600_000 (1 hour). */
211
- cdcRetention?: number;
212
- /**
213
- * Run writes on a dedicated worker thread so disk flushes never block the
214
- * thread serving connections; reads stay on the calling thread. Requires a
215
- * driver with a worker entry (the `better-sqlite3` and `node` drivers have
216
- * one), otherwise opening throws. Default: off.
217
- */
218
- writerWorker?: boolean | WriterWorkerOptions;
219
- }
220
- interface WriterWorkerOptions {
221
- /** Writes allowed in flight before new writes are rejected with a busy signal. Default: 1024. */
222
- maxPendingWrites?: number;
223
- /** Per-operation deadline in ms; when an operation stalls past it, its caller is rejected loudly while the worker keeps running, so a stalled write's outcome is indeterminate. 0 disables it. Default: 30000. */
224
- writeTimeoutMs?: number;
225
- /** Restarts the worker this many times after it crashes on its own before writes fail permanently. Default: 5. */
226
- maxRestarts?: number;
227
- }
228
- /** Top-level options for the Sirannon database registry. */
229
- interface SirannonOptions {
230
- driver: SQLiteDriver;
231
- hooks?: HookConfig;
232
- metrics?: MetricsConfig;
233
- lifecycle?: LifecycleConfig;
234
- migrations?: MigrationSource;
235
- writerWorker?: boolean | WriterWorkerOptions;
236
- }
237
- /** Options for scheduled backups. */
238
- interface BackupScheduleOptions {
239
- /** Cron expression (e.g., '0 * * * *' for hourly). */
240
- cron: string;
241
- /** Directory to store backup files. */
242
- destDir: string;
243
- /** Maximum number of backup files to keep. Default: 5. */
244
- maxFiles?: number;
245
- /**
246
- * Sirannon evaluates the cron expression in this IANA time zone (e.g. 'America/New_York').
247
- * When omitted, it uses the host's local time zone, which also sets the daylight saving rules that apply.
248
- */
249
- timezone?: string;
250
- /** Called when a scheduled backup fails. Without this, errors are silently discarded. */
251
- onError?: (error: Error) => void;
252
- }
253
- /** Builder for creating CDC subscriptions with optional filters. */
254
- interface SubscriptionBuilder {
255
- filter(conditions: Record<string, unknown>): SubscriptionBuilder;
256
- subscribe(callback: (event: ChangeEvent) => void): Subscription;
257
- }
258
- /** Handle for an active subscription. */
259
- interface Subscription {
260
- unsubscribe(): void;
261
- }
262
-
263
- interface WorkerHostOptions {
264
- writeTimeoutMs?: number;
265
- maxRestarts?: number;
266
- }
267
-
268
- interface RunResult {
269
- changes: number;
270
- lastInsertRowId: number | bigint;
271
- }
272
- /**
273
- * Tells a caller running inside the operation that holds the writer from one
274
- * merely waiting on it. A runtime without async context tracking cannot answer
275
- * this, and answering it wrongly runs one caller's writes inside another
276
- * caller's transaction.
277
- */
278
- interface WriterContext {
279
- run<T>(operation: () => T): T;
280
- isActive(): boolean;
281
- exit<T>(operation: () => T): T;
282
- }
283
- interface BackupEngine {
284
- backup(conn: SQLiteConnection, destPath: string): Promise<void>;
285
- schedule(conn: SQLiteConnection, options: BackupScheduleOptions, runExclusive: (op: () => Promise<void>) => Promise<void>): () => void;
286
- }
287
- interface BatchSummary {
288
- rowsLoaded: number;
289
- changes: number;
290
- }
291
- interface SQLiteStatement {
292
- all<T = unknown>(...params: unknown[]): Promise<T[]>;
293
- get<T = unknown>(...params: unknown[]): Promise<T | undefined>;
294
- run(...params: unknown[]): Promise<RunResult>;
295
- /**
296
- * Like {@link all} but skips the safe-range BigInt narrowing, leaving every
297
- * integer as a BigInt. The server wire path narrows and tags in one pass, so
298
- * feeding it raw rows avoids a second walk. Optional: a driver that omits it
299
- * falls back to {@link all}, still correct but with the extra narrowing walk.
300
- */
301
- allRaw?<T = unknown>(...params: unknown[]): Promise<T[]>;
302
- }
303
- interface GroupRunError {
304
- message: string;
305
- name?: string;
306
- code?: string;
307
- }
308
- type GroupRunOutcome = {
309
- ok: true;
310
- results: RunResult[];
311
- } | {
312
- ok: false;
313
- error: GroupRunError;
314
- };
315
- interface SQLiteConnection {
316
- exec(sql: string): Promise<void>;
317
- prepare(sql: string): Promise<SQLiteStatement>;
318
- transaction<T>(fn: (conn: SQLiteConnection) => Promise<T>): Promise<T>;
319
- close(): Promise<void>;
320
- runBatch?(sql: string, paramsBatch: readonly unknown[][]): Promise<RunResult[]>;
321
- runBatchSummary?(sql: string, paramsBatch: readonly unknown[][]): Promise<BatchSummary>;
322
- /**
323
- * Runs several independent units in one transaction, one outcome per unit in
324
- * order. A unit is one write or one whole transaction, and a unit that fails
325
- * must not disturb the others.
326
- */
327
- runGroup?(units: readonly {
328
- statements: readonly {
329
- sql: string;
330
- params?: readonly unknown[];
331
- trusted?: boolean;
332
- }[];
333
- }[]): Promise<GroupRunOutcome[]>;
334
- }
335
- /**
336
- * SQLite `PRAGMA synchronous` level applied to a connection. `normal` is safe
337
- * from corruption in WAL mode but can lose the most recent commits on power
338
- * loss; `full` fsyncs every commit; `extra` adds a directory sync after the
339
- * rollback journal is unlinked in DELETE journal mode and equals `full` in
340
- * WAL mode; `off` hands writes to the OS without syncing and is sanctioned
341
- * only for re-runnable bulk loads.
342
- */
343
- type SynchronousLevel = 'off' | 'normal' | 'full' | 'extra';
344
- interface OpenOptions {
345
- readonly?: boolean;
346
- walMode?: boolean;
347
- synchronous?: SynchronousLevel;
348
- }
349
- interface DriverCapabilities {
350
- multipleConnections: boolean;
351
- extensions: boolean;
352
- }
353
- /**
354
- * Lets a worker thread rebuild the driver, since the driver's `open` function
355
- * cannot cross the thread boundary. `specifier` must be importable from the
356
- * worker and `config` must survive a structured clone; the worker imports the
357
- * module and calls its `exportName` factory (default export otherwise) with it.
358
- */
359
- interface DriverWorkerEntry {
360
- specifier: string;
361
- exportName?: string;
362
- config?: unknown;
363
- }
364
- interface SQLiteDriver {
365
- readonly capabilities: DriverCapabilities;
366
- open(path: string, options?: OpenOptions): Promise<SQLiteConnection>;
367
- readonly worker?: DriverWorkerEntry;
368
- /**
369
- * Offloads writes to a worker thread. Only a driver whose runtime has
370
- * threads implements this, which is what keeps the thread machinery out of
371
- * bundles built for runtimes that do not.
372
- */
373
- startWriterHost?(path: string, options: OpenOptions, hostOptions?: WorkerHostOptions): Promise<SQLiteConnection>;
374
- createWriterContext?(): WriterContext;
375
- createBackupEngine?(): BackupEngine;
376
- /**
377
- * Makes an extension path absolute. Passing a bare name to `load_extension`
378
- * would let the dynamic linker search its own paths and open a different
379
- * library than the operator named.
380
- */
381
- resolveExtensionPath?(extensionPath: string): string;
382
- }
383
-
384
- export { type AfterQueryHook as A, type BeforeQueryHook as B, type ClusterStatusInfo as C, type DatabaseOptions as D, type ExecuteResult as E, type DriverWorkerEntry as F, MIGRATION_NAME_RE as G, type HookConfig as H, type MigrationBaseline as I, type MigrationSource as J, type NodeHealthReason as K, type LifecycleConfig as L, type Migration as M, type NodeHealth as N, type NodeHealthState as O, type Params as P, type QueryOptions as Q, type ReadConcern as R, type SirannonOptions as S, Transaction as T, type OpenOptions as U, type RunResult as V, type WriteConcern as W, type SQLiteStatement as X, type Subscription as Y, type WriteConcernLevel as Z, type WriterWorkerOptions as _, type SQLiteDriver as a, type BeforeConnectHook as b, type DatabaseOpenHook as c, type DatabaseCloseHook as d, type SQLiteConnection as e, type BackupScheduleOptions as f, type ReadConcernLevel as g, type ChangeEvent as h, type QueryHookContext as i, type ConnectionHookContext as j, type BeforeSubscribeHook as k, type MetricsConfig as l, type QueryMetrics as m, type ConnectionMetrics as n, type CDCMetrics as o, type SubscriptionBuilder as p, type MigrationResult as q, type RollbackResult as r, type SynchronousLevel as s, type WorkerHostOptions as t, type AppliedMigration as u, type AppliedMigrationEntry as v, type BatchSummary as w, type ChangeOperation as x, type ClusterReadEndpointInfo as y, type DriverCapabilities as z };