@delali/sirannon-db 0.1.7 → 0.2.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.
Files changed (72) hide show
  1. package/README.md +117 -969
  2. package/dist/backup-scheduler/index.d.ts +1 -1
  3. package/dist/backup-scheduler/index.mjs +2 -2
  4. package/dist/baseline-Br77Fnhb.d.ts +6 -0
  5. package/dist/{change-tracker-CbmaMO-N.d.ts → change-tracker-DKRVUC3l.d.ts} +5 -8
  6. package/dist/{chunk-DJLX6CAE.mjs → chunk-4ISB7XMA.mjs} +2 -1
  7. package/dist/chunk-5NOIGN5Y.mjs +18 -0
  8. package/dist/chunk-67M7KAH6.mjs +90 -0
  9. package/dist/{chunk-GEZUUIKV.mjs → chunk-D7LAYTKN.mjs} +5 -2
  10. package/dist/{chunk-4IGMIJQK.mjs → chunk-EBJXPQQO.mjs} +59 -20
  11. package/dist/{chunk-BNUTBHHH.mjs → chunk-FHWTZFI4.mjs} +1 -1
  12. package/dist/chunk-GVCNMPOS.mjs +130 -0
  13. package/dist/chunk-H237TXZW.mjs +1407 -0
  14. package/dist/{chunk-HHRMRFFR.mjs → chunk-H6PIVVDN.mjs} +353 -142
  15. package/dist/chunk-HR5CWTLC.mjs +661 -0
  16. package/dist/chunk-JU64Y7HM.mjs +299 -0
  17. package/dist/{chunk-CW6S3WL5.mjs → chunk-JZGINXTN.mjs} +7 -5
  18. package/dist/{chunk-CJLYFDP5.mjs → chunk-LFZ37BSX.mjs} +1 -1
  19. package/dist/chunk-LNY2VVHE.mjs +18 -0
  20. package/dist/chunk-NVQS53NT.mjs +665 -0
  21. package/dist/{chunk-H5AB6NIR.mjs → chunk-O7SLN3GI.mjs} +2 -15
  22. package/dist/chunk-OQVZBEBY.mjs +283 -0
  23. package/dist/{chunk-VLTICJOD.mjs → chunk-PIKHN33N.mjs} +1 -1
  24. package/dist/chunk-TJF5GZSV.mjs +187 -0
  25. package/dist/chunk-TUD5CJ76.mjs +126 -0
  26. package/dist/{chunk-YPYVQJ4C.mjs → chunk-UC3SCMIN.mjs} +9 -1
  27. package/dist/client/index.d.ts +216 -321
  28. package/dist/client/index.mjs +1192 -1342
  29. package/dist/client/topology.d.ts +61 -0
  30. package/dist/client/topology.mjs +682 -0
  31. package/dist/client-base-CLWmH5Ln.d.ts +234 -0
  32. package/dist/codegen/cli.d.ts +2 -0
  33. package/dist/codegen/cli.mjs +11 -0
  34. package/dist/codegen/index.d.ts +30 -0
  35. package/dist/codegen/index.mjs +5 -0
  36. package/dist/core/index.d.ts +37 -16
  37. package/dist/core/index.mjs +2322 -298
  38. package/dist/core/writer-worker.mjs +28 -6
  39. package/dist/{database-DuGp0Rtr.d.ts → database-BY0L5Q2n.d.ts} +59 -14
  40. package/dist/driver/better-sqlite3.d.ts +1 -1
  41. package/dist/driver/better-sqlite3.mjs +6 -6
  42. package/dist/driver/node.d.ts +1 -1
  43. package/dist/driver/node.mjs +6 -6
  44. package/dist/driver/wa-sqlite.d.ts +1 -136
  45. package/dist/{errors-5Nf5ZAEC.d.ts → errors-Bw5MdNCu.d.ts} +5 -1
  46. package/dist/file-migrations/index.d.ts +7 -5
  47. package/dist/file-migrations/index.mjs +42 -37
  48. package/dist/operation-registry-9DcvxcE5.d.ts +45 -0
  49. package/dist/primary-wins-DPAm2AKG.d.ts +61 -0
  50. package/dist/protocol-6KrSq2Hy.d.ts +66 -0
  51. package/dist/react/index.d.ts +20 -0
  52. package/dist/react/index.mjs +137 -0
  53. package/dist/replication/coordinator/etcd.d.ts +5 -3
  54. package/dist/replication/coordinator/etcd.mjs +554 -462
  55. package/dist/replication/index.d.ts +51 -105
  56. package/dist/replication/index.mjs +1415 -2061
  57. package/dist/server/index.d.ts +111 -87
  58. package/dist/server/index.mjs +1917 -489
  59. package/dist/server-options-1JHu8pid.d.ts +191 -0
  60. package/dist/{sirannon-4SspRvP5.d.ts → sirannon-DaQSyhbJ.d.ts} +7 -2
  61. package/dist/transport/grpc.d.ts +7 -4
  62. package/dist/transport/grpc.mjs +191 -97
  63. package/dist/transport/memory.d.ts +5 -134
  64. package/dist/transport/memory.mjs +3 -1
  65. package/dist/{types-BsjobKbl.d.ts → types-B7gmEsZW.d.ts} +8 -61
  66. package/dist/{types-BEu1I_9_.d.ts → types-BsVabqSI.d.ts} +1 -1
  67. package/dist/types-CL6piSnD.d.ts +43 -0
  68. package/dist/types-C_D8IhpO.d.ts +60 -0
  69. package/dist/{types-D_hQW1hr.d.ts → types-zhnRXrsb.d.ts} +55 -165
  70. package/package.json +44 -6
  71. package/dist/chunk-TKGHYWQ6.mjs +0 -35
  72. package/dist/types-D4p4UyDK.d.ts +0 -26
@@ -1,6 +1,7 @@
1
- import { C as ChangeTracker } from './change-tracker-CbmaMO-N.js';
2
- import { e as SQLiteConnection } from './types-D_hQW1hr.js';
3
- import { C as ClusterCoordinator, j as CoordinatorCompatibilityMetadata, c as ReplicationGroupState } from './types-BEu1I_9_.js';
1
+ import { C as ChangeTracker } from './change-tracker-DKRVUC3l.js';
2
+ import { e as SQLiteConnection, N as NodeHealth } from './types-zhnRXrsb.js';
3
+ import { R as ReplicationBatch, S as SyncTableManifest, C as ConflictResolver } from './types-C_D8IhpO.js';
4
+ import { C as ClusterCoordinator, a as CoordinatorCompatibilityMetadata, R as ReplicationGroupState } from './types-BsVabqSI.js';
4
5
 
5
6
  interface NodeInfo {
6
7
  id: string;
@@ -13,37 +14,6 @@ interface NodeInfo {
13
14
  lastAckedSeq: bigint;
14
15
  metadata?: Record<string, unknown>;
15
16
  }
16
- interface HLCTimestamp {
17
- wallMs: number;
18
- logical: number;
19
- nodeId: string;
20
- }
21
- interface ReplicationChange {
22
- table: string;
23
- operation: 'insert' | 'update' | 'delete' | 'ddl';
24
- rowId: string;
25
- primaryKey: Record<string, unknown>;
26
- hlc: string;
27
- txId: string;
28
- nodeId: string;
29
- newData: Record<string, unknown> | null;
30
- oldData: Record<string, unknown> | null;
31
- ddlStatement?: string;
32
- }
33
- interface ReplicationBatch {
34
- sourceNodeId: string;
35
- batchId: string;
36
- fromSeq: bigint;
37
- toSeq: bigint;
38
- hlcRange: {
39
- min: string;
40
- max: string;
41
- };
42
- changes: ReplicationChange[];
43
- checksum: string;
44
- groupId?: string;
45
- primaryTerm?: bigint;
46
- }
47
17
  interface ReplicationAck {
48
18
  batchId: string;
49
19
  ackedSeq: bigint;
@@ -69,21 +39,6 @@ interface ForwardedTransactionResult {
69
39
  groupId?: string;
70
40
  primaryTerm?: bigint;
71
41
  }
72
- interface ConflictContext {
73
- table: string;
74
- rowId: string;
75
- localChange: ReplicationChange | null;
76
- remoteChange: ReplicationChange;
77
- localHlc: string | null;
78
- remoteHlc: string;
79
- }
80
- interface ConflictResolution {
81
- action: 'accept_remote' | 'keep_local' | 'merge';
82
- mergedData?: Record<string, unknown>;
83
- }
84
- interface ConflictResolver {
85
- resolve(ctx: ConflictContext): ConflictResolution | Promise<ConflictResolution>;
86
- }
87
42
  type TopologyRole = 'primary' | 'replica';
88
43
  interface Topology {
89
44
  role: TopologyRole;
@@ -191,6 +146,7 @@ interface ReplicationStatus {
191
146
  peers: PeerState[];
192
147
  localSeq: bigint;
193
148
  replicating: boolean;
149
+ health: NodeHealth;
194
150
  syncState?: SyncState;
195
151
  coordinator?: CoordinatorRuntimeStatus;
196
152
  }
@@ -205,14 +161,9 @@ interface CoordinatorRuntimeStatus {
205
161
  faultedNodeIds: string[];
206
162
  votingDataBearingNodeIds: string[];
207
163
  authority: boolean;
164
+ connected: boolean;
208
165
  controllerState: 'disabled' | 'standby' | 'active' | 'lost';
209
166
  }
210
- interface ApplyResult {
211
- applied: number;
212
- skipped: number;
213
- conflicts: number;
214
- droppedTables: string[];
215
- }
216
167
  type SyncPhase = 'pending' | 'syncing' | 'catching-up' | 'ready';
217
168
  interface SyncState {
218
169
  phase: SyncPhase;
@@ -227,6 +178,7 @@ interface SyncRequest {
227
178
  requestId: string;
228
179
  joinerNodeId: string;
229
180
  completedTables: string[];
181
+ supportsStreamVerification?: boolean;
230
182
  groupId?: string;
231
183
  primaryTerm?: bigint;
232
184
  }
@@ -242,11 +194,6 @@ interface SyncBatch {
242
194
  groupId?: string;
243
195
  primaryTerm?: bigint;
244
196
  }
245
- interface SyncTableManifest {
246
- table: string;
247
- rowCount: number;
248
- pkHash: string;
249
- }
250
197
  interface SyncComplete {
251
198
  requestId: string;
252
199
  snapshotSeq: bigint;
@@ -271,4 +218,4 @@ interface ReplicationErrorEvent {
271
218
  recoverable: boolean;
272
219
  }
273
220
 
274
- export type { ApplyResult as A, ConflictResolver as C, ForwardedTransaction as F, HLCTimestamp as H, InFlightBatch as I, NodeInfo as N, PeerState as P, ReplicationBatch as R, SyncRequest as S, TopologyRole as T, ReplicationAck as a, ForwardedTransactionResult as b, SyncBatch as c, SyncComplete as d, SyncAck as e, ReplicationTransport as f, TransportConfig as g, ConflictContext as h, ConflictResolution as i, SyncPhase as j, SyncTableManifest as k, ReplicationConfig as l, SyncState as m, ReplicationStatus as n, ReplicationErrorEvent as o, Topology as p, ReplicationChange as q };
221
+ export type { ForwardedTransaction as F, InFlightBatch as I, NodeInfo as N, PeerState as P, ReplicationAck as R, SyncRequest as S, TransportConfig as T, ForwardedTransactionResult as a, SyncBatch as b, SyncComplete as c, SyncAck as d, ReplicationTransport as e, TopologyRole as f, SyncPhase as g, ReplicationConfig as h, SyncState as i, ReplicationStatus as j, ReplicationErrorEvent as k, Topology as l };
@@ -136,4 +136,4 @@ interface ClusterCoordinator {
136
136
  close?(): Promise<void>;
137
137
  }
138
138
 
139
- export type { AcquireControllerLeaseInput as A, ClusterCoordinator as C, PromoteEligibleReplicaInput as P, RegisterNodeSessionInput as R, SetReplicationGroupStateInput as S, UpdateInSyncSetInput as U, AcquireControllerLeaseResult as a, CoordinatorNodeSession as b, ReplicationGroupState as c, ReplicationGroupWatcher as d, CoordinatorWatchDisposer as e, CompareAndAdvancePrimaryTermInput as f, CompareAndAdvancePrimaryTermResult as g, AdmitNodeToInSyncSetInput as h, UpdateNodeMaintenanceInput as i, CoordinatorCompatibilityMetadata as j, CoordinatorLease as k, CoordinatorPrimary as l };
139
+ export type { AcquireControllerLeaseInput as A, ClusterCoordinator as C, PromoteEligibleReplicaInput as P, ReplicationGroupState as R, SetReplicationGroupStateInput as S, UpdateInSyncSetInput as U, CoordinatorCompatibilityMetadata as a, AcquireControllerLeaseResult as b, RegisterNodeSessionInput as c, CoordinatorNodeSession as d, ReplicationGroupWatcher as e, CoordinatorWatchDisposer as f, CompareAndAdvancePrimaryTermInput as g, CompareAndAdvancePrimaryTermResult as h, AdmitNodeToInSyncSetInput as i, UpdateNodeMaintenanceInput as j, CoordinatorLease as k, CoordinatorPrimary as l };
@@ -0,0 +1,43 @@
1
+ type LiveQueryState<T> = {
2
+ status: 'pending';
3
+ } | {
4
+ status: 'ready';
5
+ rows: readonly T[];
6
+ revalidating: boolean;
7
+ } | {
8
+ status: 'error';
9
+ error: Error;
10
+ };
11
+ type ResultOp<T> = {
12
+ op: 'insert';
13
+ index: number;
14
+ row: T;
15
+ } | {
16
+ op: 'update';
17
+ index: number;
18
+ row: T;
19
+ } | {
20
+ op: 'delete';
21
+ index: number;
22
+ };
23
+ type LiveUpdate<T> = {
24
+ kind: 'rows';
25
+ } | {
26
+ kind: 'ops';
27
+ ops: readonly ResultOp<T>[];
28
+ } | {
29
+ kind: 'revalidating';
30
+ } | {
31
+ kind: 'error';
32
+ };
33
+ interface LiveQuery<T = Record<string, unknown>> {
34
+ getState(): LiveQueryState<T>;
35
+ subscribe(listener: (update: LiveUpdate<T>) => void): () => void;
36
+ close(): Promise<void>;
37
+ }
38
+ interface LiveQueryOptions {
39
+ rereadJitterMs?: number;
40
+ maxTransactionChanges?: number;
41
+ }
42
+
43
+ export type { LiveQueryOptions as L, ResultOp as R, LiveQuery as a, LiveQueryState as b, LiveUpdate as c };
@@ -0,0 +1,60 @@
1
+ interface HLCTimestamp {
2
+ wallMs: number;
3
+ logical: number;
4
+ nodeId: string;
5
+ }
6
+ interface ReplicationChange {
7
+ table: string;
8
+ operation: 'insert' | 'update' | 'delete' | 'ddl';
9
+ rowId: string;
10
+ primaryKey: Record<string, unknown>;
11
+ hlc: string;
12
+ txId: string;
13
+ nodeId: string;
14
+ newData: Record<string, unknown> | null;
15
+ oldData: Record<string, unknown> | null;
16
+ ddlStatement?: string;
17
+ }
18
+ interface ReplicationBatch {
19
+ sourceNodeId: string;
20
+ batchId: string;
21
+ fromSeq: bigint;
22
+ toSeq: bigint;
23
+ hlcRange: {
24
+ min: string;
25
+ max: string;
26
+ };
27
+ changes: ReplicationChange[];
28
+ checksum: string;
29
+ groupId?: string;
30
+ primaryTerm?: bigint;
31
+ }
32
+ interface ConflictContext {
33
+ table: string;
34
+ rowId: string;
35
+ localChange: ReplicationChange | null;
36
+ remoteChange: ReplicationChange;
37
+ localHlc: string | null;
38
+ remoteHlc: string;
39
+ }
40
+ interface ConflictResolution {
41
+ action: 'accept_remote' | 'keep_local' | 'merge';
42
+ mergedData?: Record<string, unknown>;
43
+ }
44
+ interface ConflictResolver {
45
+ resolve(ctx: ConflictContext): ConflictResolution | Promise<ConflictResolution>;
46
+ }
47
+ interface ApplyResult {
48
+ applied: number;
49
+ skipped: number;
50
+ conflicts: number;
51
+ droppedTables: string[];
52
+ }
53
+ interface SyncTableManifest {
54
+ table: string;
55
+ rowCount: number;
56
+ pkHash?: string;
57
+ batchDigest?: string;
58
+ }
59
+
60
+ export type { ApplyResult as A, ConflictResolver as C, HLCTimestamp as H, ReplicationBatch as R, SyncTableManifest as S, ConflictContext as a, ConflictResolution as b, ReplicationChange as c };
@@ -9,6 +9,35 @@ declare class Transaction {
9
9
  static run<T>(conn: SQLiteConnection, fn: (tx: Transaction) => Promise<T>): Promise<T>;
10
10
  }
11
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
+
12
41
  /** Query parameter types: named (object) or positional (array). */
13
42
  type Params = Record<string, unknown> | unknown[];
14
43
  type WriteConcernLevel = 'local' | 'majority' | 'all';
@@ -29,6 +58,22 @@ interface ClusterReadEndpointInfo {
29
58
  endpoint: string;
30
59
  readConcerns: ReadConcernLevel[];
31
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
+ }
32
77
  interface ClusterStatusInfo {
33
78
  databaseId: string;
34
79
  replicationGroupId?: string;
@@ -39,7 +84,8 @@ interface ClusterStatusInfo {
39
84
  } | null;
40
85
  primaryTerm?: bigint;
41
86
  readEndpoints?: ClusterReadEndpointInfo[];
42
- health: 'healthy' | 'degraded' | 'failing_over' | 'unavailable' | 'repairing' | 'syncing';
87
+ health: NodeHealthState;
88
+ healthReason: NodeHealthReason;
43
89
  }
44
90
  /** Result returned by mutation statements (INSERT, UPDATE, DELETE). */
45
91
  interface ExecuteResult {
@@ -56,6 +102,11 @@ interface ChangeEvent<T = Record<string, unknown>> {
56
102
  oldRow?: T;
57
103
  seq: bigint;
58
104
  timestamp: number;
105
+ hlc?: string;
106
+ origin?: string;
107
+ rowId?: string;
108
+ txId?: string;
109
+ txEnd?: boolean;
59
110
  }
60
111
  /** Context passed to query hooks. */
61
112
  interface QueryHookContext {
@@ -180,6 +231,7 @@ interface SirannonOptions {
180
231
  hooks?: HookConfig;
181
232
  metrics?: MetricsConfig;
182
233
  lifecycle?: LifecycleConfig;
234
+ migrations?: MigrationSource;
183
235
  writerWorker?: boolean | WriterWorkerOptions;
184
236
  }
185
237
  /** Options for scheduled backups. */
@@ -207,169 +259,6 @@ interface SubscriptionBuilder {
207
259
  interface Subscription {
208
260
  unsubscribe(): void;
209
261
  }
210
- /** Context passed to the onRequest middleware hook. */
211
- interface RequestContext {
212
- headers: Record<string, string>;
213
- method: string;
214
- path: string;
215
- databaseId?: string;
216
- remoteAddress: string;
217
- }
218
- /** Return this from an onRequest hook to deny the request with a custom response. */
219
- interface RequestDenial {
220
- status: number;
221
- code: string;
222
- message: string;
223
- }
224
- /** Middleware hook for auth, rate limiting, and request validation. */
225
- type OnRequestHook = (ctx: RequestContext) => undefined | RequestDenial | Promise<undefined | RequestDenial>;
226
- /**
227
- * Durability level in force while a bulk load runs. SQLite sanctions 'off' for
228
- * a from-scratch load that the operator can re-run after a power loss; 'off'
229
- * gives up corruption safety, so it fits only a load that starts from nothing.
230
- * 'normal' keeps WAL-mode corruption safety and suits loads into a database
231
- * that already holds data the operator cannot afford to lose.
232
- */
233
- type BulkLoadDurability = 'off' | 'normal';
234
- interface BulkLoadOptions {
235
- /** Durability during the load. Default: 'off'. */
236
- durability?: BulkLoadDurability;
237
- /**
238
- * Whether this load ends with a WAL checkpoint. Default: true. Set it false
239
- * on every load but the last of a multi-batch import so the one fsyncing
240
- * checkpoint is paid once at the end instead of once per batch; the
241
- * configured durability is still restored after each batch regardless, so an
242
- * abandoned import never leaves the writer at the relaxed level.
243
- */
244
- checkpoint?: boolean;
245
- }
246
- /** Aggregate outcome of a bulk load. Summed rather than per-row so a
247
- * million-row load never holds a million result objects in memory. */
248
- interface BulkLoadResult {
249
- rowsLoaded: number;
250
- changes: number;
251
- }
252
- interface ServerExecutionTarget {
253
- query<T = Record<string, unknown>>(sql: string, params?: Params, options?: QueryOptions): Promise<T[]>;
254
- /**
255
- * Optional single-pass read that returns rows already encoded for the wire
256
- * (safe-range integers as plain numbers, larger integers and BLOBs as tagged
257
- * envelopes). When present the server uses it instead of {@link query}
258
- * followed by a separate tag-encoding walk. A target that omits it stays
259
- * correct: the server falls back to encoding {@link query} rows itself.
260
- */
261
- queryForWire?(sql: string, params?: Params, options?: QueryOptions): Promise<unknown[]>;
262
- execute(sql: string, params?: Params, options?: QueryOptions): Promise<ExecuteResult>;
263
- transaction<T>(fn: (tx: Transaction) => Promise<T>, options?: QueryOptions): Promise<T>;
264
- /**
265
- * Optional entry point for a transaction whose statements are all known
266
- * before it starts, which lets concurrent transactions share one commit. A
267
- * target that omits it stays correct: the server falls back to
268
- * {@link transaction} and runs the statements one at a time.
269
- */
270
- executeTransaction?(statements: readonly {
271
- sql: string;
272
- params?: Params;
273
- }[], options?: QueryOptions): Promise<ExecuteResult[]>;
274
- /**
275
- * Optional bulk-load entry point. Targets that proxy to a remote primary
276
- * may omit it; the server rejects load requests for such targets instead
277
- * of silently degrading to per-statement writes.
278
- */
279
- bulkLoad?(sql: string, paramsBatch: Params[], options?: BulkLoadOptions): Promise<BulkLoadResult>;
280
- }
281
- type ServerExecutionTargetResolver = (databaseId: string) => ServerExecutionTarget | null | undefined | Promise<ServerExecutionTarget | null | undefined>;
282
- /** Options for the standalone HTTP + WS server. */
283
- interface ServerOptions {
284
- host?: string;
285
- port?: number;
286
- cors?: boolean | CorsOptions;
287
- /**
288
- * Maximum HTTP request body and WebSocket message size in bytes. Applied
289
- * identically to both transports. Must be a positive, finite integer no
290
- * larger than 4_294_967_295 (the unsigned 32-bit ceiling uWebSockets.js can
291
- * store; larger values would silently wrap modulo 2^32).
292
- * Default: 1_048_576 (1 MB), matching the general web default and acting as
293
- * a denial-of-service guard on a memory-limited server.
294
- */
295
- maxBodyBytes?: number;
296
- /**
297
- * Maximum bytes buffered per WebSocket connection before the server stops
298
- * absorbing backpressure. A single frame can be as large as `maxBodyBytes`,
299
- * so this must hold several of them; the resolved value is raised to at
300
- * least `maxBodyBytes` and, like `maxBodyBytes`, must not exceed
301
- * 4_294_967_295. When the buffer is exceeded the server closes the
302
- * connection so the client reconnects rather than losing a frame silently.
303
- * Default: the larger of 16 MB and `maxBodyBytes`.
304
- */
305
- maxWebSocketBackpressureBytes?: number;
306
- /**
307
- * How long, in milliseconds, change events are retained for WebSocket CDC
308
- * subscriptions. Retention bounds both on-disk growth of the change log and
309
- * how far back a reconnecting subscriber can resume. Default: 3_600_000
310
- * (one hour).
311
- */
312
- cdcRetentionMs?: number;
313
- onRequest?: OnRequestHook;
314
- resolveExecutionTarget?: ServerExecutionTargetResolver;
315
- getReplicationStatus?: () => ReplicationStatusInfo | null;
316
- getClusterStatus?: (databaseId: string) => ClusterStatusInfo | null;
317
- }
318
- interface ReplicationStatusInfo {
319
- role: string;
320
- writeForwarding: boolean;
321
- peers: number;
322
- localSeq: bigint;
323
- replicationGroupId?: string;
324
- primaryTerm?: bigint;
325
- currentPrimary?: string;
326
- coordinator?: {
327
- connected: boolean;
328
- authority: boolean;
329
- };
330
- controller?: {
331
- state: 'disabled' | 'standby' | 'active' | 'lost';
332
- };
333
- inSyncReplicas?: string[];
334
- laggingReplicas?: string[];
335
- syncState?: string;
336
- readAvailability?: 'available' | 'unavailable';
337
- writeAvailability?: 'available' | 'unavailable';
338
- }
339
- /** CORS configuration. */
340
- interface CorsOptions {
341
- origin?: string | string[];
342
- methods?: string[];
343
- headers?: string[];
344
- }
345
- /** Options for the mountable WebSocket handler. */
346
- interface WSHandlerOptions {
347
- /** Maximum message size in bytes. Default: 1_048_576 (1 MB). */
348
- maxPayloadLength?: number;
349
- /** Change-log retention for CDC subscriptions in milliseconds. Default: 3_600_000. */
350
- cdcRetentionMs?: number;
351
- resolveExecutionTarget?: ServerExecutionTargetResolver;
352
- }
353
- /** Options for the client SDK. */
354
- interface ClientOptions {
355
- /** Transport to use. Default: 'websocket'. */
356
- transport?: 'websocket' | 'http';
357
- /** Custom headers for HTTP requests. */
358
- headers?: Record<string, string>;
359
- /** WebSocket subprotocols sent during the browser-compatible handshake. */
360
- webSocketProtocols?: string | string[];
361
- /** Reconnect on WebSocket disconnect. Default: true. */
362
- autoReconnect?: boolean;
363
- /** Reconnect interval in ms. Default: 1000. */
364
- reconnectInterval?: number;
365
- /**
366
- * Per-request timeout in milliseconds for the WebSocket transport. A bulk
367
- * load or batch of tens of millions of rows can legitimately run longer than
368
- * the default, so raise this for large writes. Set to 0 to wait indefinitely.
369
- * Default: 30000.
370
- */
371
- requestTimeout?: number;
372
- }
373
262
 
374
263
  interface WorkerHostOptions {
375
264
  writeTimeoutMs?: number;
@@ -439,6 +328,7 @@ interface SQLiteConnection {
439
328
  statements: readonly {
440
329
  sql: string;
441
330
  params?: readonly unknown[];
331
+ trusted?: boolean;
442
332
  }[];
443
333
  }[]): Promise<GroupRunOutcome[]>;
444
334
  }
@@ -491,4 +381,4 @@ interface SQLiteDriver {
491
381
  resolveExtensionPath?(extensionPath: string): string;
492
382
  }
493
383
 
494
- export { type WriteConcernLevel as $, type AfterQueryHook as A, type BeforeQueryHook as B, type ChangeEvent as C, type DatabaseOptions as D, type ExecuteResult as E, type DriverCapabilities as F, type DriverWorkerEntry as G, type HookConfig as H, type OpenOptions as I, type ReadConcernLevel as J, type ReplicationStatusInfo as K, type LifecycleConfig as L, type MetricsConfig as M, type RequestContext as N, type OnRequestHook as O, type Params as P, type QueryHookContext as Q, type ReadConcern as R, type SirannonOptions as S, Transaction as T, type RequestDenial as U, type RunResult as V, type WriteConcern as W, type SQLiteStatement as X, type ServerExecutionTarget as Y, type ServerExecutionTargetResolver as Z, type Subscription as _, type SQLiteDriver as a, type WriterWorkerOptions as a0, type BeforeConnectHook as b, type DatabaseOpenHook as c, type DatabaseCloseHook as d, type SQLiteConnection as e, type BackupScheduleOptions as f, type BulkLoadDurability as g, type BulkLoadResult as h, type ServerOptions as i, type WSHandlerOptions as j, type ConnectionHookContext as k, type BeforeSubscribeHook as l, type QueryMetrics as m, type ConnectionMetrics as n, type CDCMetrics as o, type QueryOptions as p, type BulkLoadOptions as q, type SubscriptionBuilder as r, type SynchronousLevel as s, type WorkerHostOptions as t, type BatchSummary as u, type ChangeOperation as v, type ClientOptions as w, type ClusterReadEndpointInfo as x, type ClusterStatusInfo as y, type CorsOptions as z };
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 };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@delali/sirannon-db",
3
3
  "type": "module",
4
- "version": "0.1.7",
4
+ "version": "0.2.0",
5
5
  "description": "A production-grade library that turns SQLite databases into a networked data layer with real-time subscriptions.",
6
6
  "author": "Delali (https://sondelali.com)",
7
7
  "license": "Apache-2.0",
@@ -66,6 +66,18 @@
66
66
  "types": "./dist/client/index.d.ts",
67
67
  "import": "./dist/client/index.mjs"
68
68
  },
69
+ "./client/topology": {
70
+ "types": "./dist/client/topology.d.ts",
71
+ "import": "./dist/client/topology.mjs"
72
+ },
73
+ "./react": {
74
+ "types": "./dist/react/index.d.ts",
75
+ "import": "./dist/react/index.mjs"
76
+ },
77
+ "./codegen": {
78
+ "types": "./dist/codegen/index.d.ts",
79
+ "import": "./dist/codegen/index.mjs"
80
+ },
69
81
  "./replication": {
70
82
  "types": "./dist/replication/index.d.ts",
71
83
  "import": "./dist/replication/index.mjs"
@@ -83,6 +95,22 @@
83
95
  "import": "./dist/transport/grpc.mjs"
84
96
  }
85
97
  },
98
+ "typesVersions": {
99
+ "*": {
100
+ "react": [
101
+ "./dist/react/index.d.ts"
102
+ ],
103
+ "codegen": [
104
+ "./dist/codegen/index.d.ts"
105
+ ],
106
+ "client/topology": [
107
+ "./dist/client/topology.d.ts"
108
+ ]
109
+ }
110
+ },
111
+ "bin": {
112
+ "sirannon-codegen": "./dist/codegen/cli.mjs"
113
+ },
86
114
  "files": [
87
115
  "dist",
88
116
  "LICENSE",
@@ -95,9 +123,10 @@
95
123
  "@bufbuild/protobuf": ">=2.0.0",
96
124
  "@grpc/grpc-js": ">=1.10.0",
97
125
  "better-sqlite3": ">=12.0.0",
98
- "expo-sqlite": ">=14.0.0",
99
126
  "etcd3": ">=1.1.2",
127
+ "expo-sqlite": ">=14.0.0",
100
128
  "grpc-health-check": ">=2.0.0",
129
+ "react": ">=19.0.0",
101
130
  "uWebSockets.js": ">=20.0.0",
102
131
  "wa-sqlite": ">=1.0.0"
103
132
  },
@@ -125,29 +154,38 @@
125
154
  },
126
155
  "wa-sqlite": {
127
156
  "optional": true
157
+ },
158
+ "react": {
159
+ "optional": true
128
160
  }
129
161
  },
130
162
  "devDependencies": {
131
163
  "@bufbuild/protobuf": "2.11.0",
132
- "@grpc/grpc-js": "1.14.3",
164
+ "@grpc/grpc-js": "1.14.4",
133
165
  "@types/better-sqlite3": "7.6.13",
134
- "@types/node": "25.3.3",
166
+ "@types/node": "26.1.2",
167
+ "@types/react": "19.2.15",
168
+ "@types/react-dom": "19.2.3",
135
169
  "@vitest/coverage-v8": "4.0.18",
136
- "better-sqlite3": "12.6.2",
170
+ "better-sqlite3": "13.0.2",
137
171
  "etcd3": "1.1.2",
138
172
  "grpc-health-check": "2.1.0",
139
173
  "grpc-tools": "1.13.1",
174
+ "jsdom": "29.1.1",
175
+ "react": "19.2.6",
176
+ "react-dom": "19.2.6",
140
177
  "selfsigned": "5.5.0",
141
178
  "ts-proto": "2.11.6",
142
179
  "tsup": "8.5.1",
143
180
  "tsx": "4.21.0",
144
181
  "typescript": "5.9.3",
145
- "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.58.0",
182
+ "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.69.0",
146
183
  "vitest": "4.0.18"
147
184
  },
148
185
  "scripts": {
149
186
  "build": "rm -rf dist && tsup",
150
187
  "check:bundle": "node scripts/assert-browser-bundle.mjs",
188
+ "check:types": "node scripts/assert-consumer-types.mjs",
151
189
  "test": "vitest run",
152
190
  "test:coverage": "vitest run --coverage",
153
191
  "test:e2e": "vitest run --config vitest.e2e.config.ts",
@@ -1,35 +0,0 @@
1
- import { query, execute, executeBatch } from './chunk-CW6S3WL5.mjs';
2
-
3
- // src/core/transaction.ts
4
- var Transaction = class _Transaction {
5
- constructor(conn) {
6
- this.conn = conn;
7
- }
8
- _lastInsertRowId = 0;
9
- async query(sql, params) {
10
- return query(this.conn, sql, params);
11
- }
12
- async execute(sql, params) {
13
- const result = await execute(this.conn, sql, params);
14
- this._lastInsertRowId = result.lastInsertRowId;
15
- return result;
16
- }
17
- async executeBatch(sql, paramsBatch) {
18
- const results = await executeBatch(this.conn, sql, paramsBatch);
19
- if (results.length > 0) {
20
- this._lastInsertRowId = results[results.length - 1].lastInsertRowId;
21
- }
22
- return results;
23
- }
24
- get lastInsertRowId() {
25
- return this._lastInsertRowId;
26
- }
27
- static async run(conn, fn) {
28
- return conn.transaction(async (txConn) => {
29
- const tx = new _Transaction(txConn);
30
- return fn(tx);
31
- });
32
- }
33
- };
34
-
35
- export { Transaction };
@@ -1,26 +0,0 @@
1
- import { T as Transaction } from './types-D_hQW1hr.js';
2
-
3
- interface AppliedMigration {
4
- version: number;
5
- name: string;
6
- applied_at: number;
7
- }
8
- interface Migration {
9
- version: number;
10
- name: string;
11
- up: string | ((tx: Transaction) => void | Promise<void>);
12
- down?: string | ((tx: Transaction) => void | Promise<void>);
13
- }
14
- interface AppliedMigrationEntry {
15
- version: number;
16
- name: string;
17
- }
18
- interface MigrationResult {
19
- applied: AppliedMigrationEntry[];
20
- skipped: number;
21
- }
22
- interface RollbackResult {
23
- rolledBack: AppliedMigrationEntry[];
24
- }
25
-
26
- export type { AppliedMigration as A, Migration as M, RollbackResult as R, MigrationResult as a, AppliedMigrationEntry as b };