@delali/sirannon-db 0.1.3 → 0.1.5

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 (51) hide show
  1. package/README.md +655 -80
  2. package/dist/backup-scheduler/index.d.ts +3 -0
  3. package/dist/backup-scheduler/index.mjs +2 -0
  4. package/dist/change-tracker-CFTQ9TSn.d.ts +89 -0
  5. package/dist/chunk-3MCMONVP.mjs +115 -0
  6. package/dist/chunk-74UN4DIE.mjs +14 -0
  7. package/dist/chunk-ER7ODTDA.mjs +23 -0
  8. package/dist/chunk-FB2U2Q3Y.mjs +21 -0
  9. package/dist/chunk-GS7T5YMI.mjs +51 -0
  10. package/dist/chunk-O7BHI3CF.mjs +90 -0
  11. package/dist/chunk-PXKAKK2V.mjs +124 -0
  12. package/dist/chunk-UTO3ZAFS.mjs +514 -0
  13. package/dist/chunk-UVMVN3OT.mjs +111 -0
  14. package/dist/client/index.d.ts +137 -44
  15. package/dist/client/index.mjs +726 -26
  16. package/dist/core/index.d.ts +32 -241
  17. package/dist/core/index.mjs +294 -568
  18. package/dist/database-BVY1GqE7.d.ts +95 -0
  19. package/dist/driver/better-sqlite3.d.ts +8 -0
  20. package/dist/driver/better-sqlite3.mjs +63 -0
  21. package/dist/driver/bun.mjs +61 -0
  22. package/dist/driver/expo.mjs +55 -0
  23. package/dist/driver/node.d.ts +8 -0
  24. package/dist/driver/node.mjs +60 -0
  25. package/dist/driver/wa-sqlite.d.ts +34 -0
  26. package/dist/driver/wa-sqlite.mjs +141 -0
  27. package/dist/errors-C00ed08Q.d.ts +101 -0
  28. package/dist/file-migrations/index.d.ts +16 -0
  29. package/dist/file-migrations/index.mjs +128 -0
  30. package/dist/index-CLdNrcPz.d.ts +16 -0
  31. package/dist/replication/coordinator/etcd.d.ts +44 -0
  32. package/dist/replication/coordinator/etcd.mjs +650 -0
  33. package/dist/replication/index.d.ts +491 -0
  34. package/dist/replication/index.mjs +3784 -0
  35. package/dist/server/index.d.ts +121 -54
  36. package/dist/server/index.mjs +347 -114
  37. package/dist/sirannon-Cd-lK6T0.d.ts +31 -0
  38. package/dist/transport/grpc.d.ts +316 -0
  39. package/dist/transport/grpc.mjs +3341 -0
  40. package/dist/transport/memory.d.ts +221 -0
  41. package/dist/transport/memory.mjs +337 -0
  42. package/dist/types-B2byqt0B.d.ts +273 -0
  43. package/dist/types-BEu1I_9_.d.ts +139 -0
  44. package/dist/types-BFSsG77t.d.ts +29 -0
  45. package/dist/types-BeozgNPr.d.ts +26 -0
  46. package/dist/{types-DArCObcu.d.ts → types-D-74JiXb.d.ts} +80 -1
  47. package/dist/vfs-INWQ5DTE.mjs +2 -0
  48. package/package.json +106 -11
  49. package/dist/chunk-VI4UP4RR.mjs +0 -417
  50. package/dist/protocol-BX1H-_Mz.d.ts +0 -104
  51. package/dist/sirannon-BJ8Yd1Uf.d.ts +0 -148
@@ -0,0 +1,273 @@
1
+ import { C as ChangeTracker } from './change-tracker-CFTQ9TSn.js';
2
+ import { a as SQLiteConnection } from './types-BFSsG77t.js';
3
+ import { C as ClusterCoordinator, j as CoordinatorCompatibilityMetadata, c as ReplicationGroupState } from './types-BEu1I_9_.js';
4
+
5
+ interface NodeInfo {
6
+ id: string;
7
+ groupId?: string;
8
+ role: 'primary' | 'replica';
9
+ primaryTerm?: bigint;
10
+ protocolVersion?: string;
11
+ joinedAt: number;
12
+ lastSeenAt: number;
13
+ lastAckedSeq: bigint;
14
+ metadata?: Record<string, unknown>;
15
+ }
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
+ interface ReplicationAck {
48
+ batchId: string;
49
+ ackedSeq: bigint;
50
+ nodeId: string;
51
+ groupId?: string;
52
+ primaryTerm?: bigint;
53
+ }
54
+ interface ForwardedTransaction {
55
+ statements: Array<{
56
+ sql: string;
57
+ params?: Record<string, unknown> | unknown[];
58
+ }>;
59
+ requestId: string;
60
+ groupId?: string;
61
+ primaryTerm?: bigint;
62
+ }
63
+ interface ForwardedTransactionResult {
64
+ results: Array<{
65
+ changes: number;
66
+ lastInsertRowId: number | string;
67
+ }>;
68
+ requestId: string;
69
+ groupId?: string;
70
+ primaryTerm?: bigint;
71
+ }
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
+ type TopologyRole = 'primary' | 'replica';
88
+ interface Topology {
89
+ role: TopologyRole;
90
+ canWrite(): boolean;
91
+ shouldReplicateTo(peerId: string, peerRole: TopologyRole): boolean;
92
+ shouldAcceptFrom(peerId: string, peerRole: TopologyRole): boolean;
93
+ requiresConflictResolution(): boolean;
94
+ }
95
+ interface TransportConfig {
96
+ endpoints?: string[];
97
+ localRole?: TopologyRole;
98
+ groupId?: string;
99
+ primaryTerm?: bigint;
100
+ protocolVersion?: string;
101
+ metadata?: Record<string, unknown>;
102
+ }
103
+ interface ReplicationTransport {
104
+ connect(localNodeId: string, config: TransportConfig): Promise<void>;
105
+ disconnect(): Promise<void>;
106
+ send(peerId: string, batch: ReplicationBatch): Promise<void>;
107
+ broadcast(batch: ReplicationBatch): Promise<void>;
108
+ sendAck(peerId: string, ack: ReplicationAck): Promise<void>;
109
+ forward(peerId: string, request: ForwardedTransaction): Promise<ForwardedTransactionResult>;
110
+ requestSync(peerId: string, request: SyncRequest): Promise<void>;
111
+ sendSyncBatch(peerId: string, batch: SyncBatch): Promise<void>;
112
+ sendSyncComplete(peerId: string, complete: SyncComplete): Promise<void>;
113
+ sendSyncAck(peerId: string, ack: SyncAck): Promise<void>;
114
+ onBatchReceived(handler: (batch: ReplicationBatch, fromPeerId: string) => Promise<void>): void;
115
+ onAckReceived(handler: (ack: ReplicationAck, fromPeerId: string) => void): void;
116
+ onForwardReceived(handler: (request: ForwardedTransaction, fromPeerId: string) => Promise<ForwardedTransactionResult>): void;
117
+ onSyncRequested(handler: (request: SyncRequest, fromPeerId: string) => Promise<void>): void;
118
+ onSyncBatchReceived(handler: (batch: SyncBatch, fromPeerId: string) => Promise<void>): void;
119
+ onSyncCompleteReceived(handler: (complete: SyncComplete, fromPeerId: string) => Promise<void>): void;
120
+ onSyncAckReceived(handler: (ack: SyncAck, fromPeerId: string) => void): void;
121
+ onPeerConnected(handler: (peer: NodeInfo) => void): void;
122
+ onPeerDisconnected(handler: (peerId: string) => void): void;
123
+ peers(): ReadonlyMap<string, NodeInfo>;
124
+ }
125
+ interface InFlightBatch {
126
+ batchId: string;
127
+ fromSeq: bigint;
128
+ toSeq: bigint;
129
+ sentAt: number;
130
+ }
131
+ interface PeerState {
132
+ nodeId: string;
133
+ lastAckedSeq: bigint;
134
+ lastSentSeq: bigint;
135
+ lastReceivedHlc: string;
136
+ connected: boolean;
137
+ pendingBatches: number;
138
+ inFlightBatches: InFlightBatch[];
139
+ }
140
+ interface CoordinatorControllerConfig {
141
+ enabled?: boolean;
142
+ holderId?: string;
143
+ leaseTtlMs?: number;
144
+ tickIntervalMs?: number;
145
+ }
146
+ interface CoordinatorModeConfig {
147
+ clusterId: string;
148
+ groupId: string;
149
+ endpoint?: string;
150
+ votingDataBearingNodeIds?: string[];
151
+ coordinator: ClusterCoordinator;
152
+ sessionTtlMs?: number;
153
+ controller?: boolean | CoordinatorControllerConfig;
154
+ compatibility?: CoordinatorCompatibilityMetadata;
155
+ }
156
+ interface ReplicationConfig {
157
+ nodeId?: string;
158
+ topology: Topology;
159
+ transport: ReplicationTransport;
160
+ transportConfig?: TransportConfig;
161
+ writeForwarding?: boolean;
162
+ conflictResolvers?: Record<string, ConflictResolver>;
163
+ defaultConflictResolver?: ConflictResolver;
164
+ batchSize?: number;
165
+ batchIntervalMs?: number;
166
+ maxPendingBatches?: number;
167
+ snapshotThreshold?: number;
168
+ maxClockDriftMs?: number;
169
+ maxBatchChanges?: number;
170
+ ackTimeoutMs?: number;
171
+ onBeforeForwardedQuery?: (sql: string, params?: unknown[] | Record<string, unknown>) => void;
172
+ flowControl?: {
173
+ maxLagSeconds?: number;
174
+ onLagExceeded?: (peerId: string, lagMs: number) => void;
175
+ };
176
+ initialSync?: boolean;
177
+ syncBatchSize?: number;
178
+ maxConcurrentSyncs?: number;
179
+ maxSyncDurationMs?: number;
180
+ maxSyncLagBeforeReady?: number;
181
+ syncAckTimeoutMs?: number;
182
+ catchUpDeadlineMs?: number;
183
+ resumeFromSeq?: bigint;
184
+ snapshotConnectionFactory?: () => Promise<SQLiteConnection>;
185
+ changeTracker?: ChangeTracker;
186
+ coordinator?: CoordinatorModeConfig;
187
+ }
188
+ interface ReplicationStatus {
189
+ nodeId: string;
190
+ role: TopologyRole;
191
+ peers: PeerState[];
192
+ localSeq: bigint;
193
+ replicating: boolean;
194
+ syncState?: SyncState;
195
+ coordinator?: CoordinatorRuntimeStatus;
196
+ }
197
+ interface CoordinatorRuntimeStatus {
198
+ clusterId: string;
199
+ groupId: string;
200
+ currentPrimary: ReplicationGroupState['currentPrimary'];
201
+ primaryTerm: bigint;
202
+ inSyncNodeIds: string[];
203
+ drainingNodeIds: string[];
204
+ repairingNodeIds: string[];
205
+ faultedNodeIds: string[];
206
+ votingDataBearingNodeIds: string[];
207
+ authority: boolean;
208
+ controllerState: 'disabled' | 'standby' | 'active' | 'lost';
209
+ }
210
+ interface ApplyResult {
211
+ applied: number;
212
+ skipped: number;
213
+ conflicts: number;
214
+ droppedTables: string[];
215
+ }
216
+ type SyncPhase = 'pending' | 'syncing' | 'catching-up' | 'ready';
217
+ interface SyncState {
218
+ phase: SyncPhase;
219
+ sourcePeerId: string | null;
220
+ snapshotSeq: bigint | null;
221
+ completedTables: string[];
222
+ totalTables: number;
223
+ startedAt: number | null;
224
+ error: string | null;
225
+ }
226
+ interface SyncRequest {
227
+ requestId: string;
228
+ joinerNodeId: string;
229
+ completedTables: string[];
230
+ groupId?: string;
231
+ primaryTerm?: bigint;
232
+ }
233
+ interface SyncBatch {
234
+ requestId: string;
235
+ table: string;
236
+ batchIndex: number;
237
+ rows: Record<string, unknown>[];
238
+ schema?: string[];
239
+ checksum: string;
240
+ isLastBatchForTable: boolean;
241
+ groupId?: string;
242
+ primaryTerm?: bigint;
243
+ }
244
+ interface SyncTableManifest {
245
+ table: string;
246
+ rowCount: number;
247
+ pkHash: string;
248
+ }
249
+ interface SyncComplete {
250
+ requestId: string;
251
+ snapshotSeq: bigint;
252
+ manifests: SyncTableManifest[];
253
+ groupId?: string;
254
+ primaryTerm?: bigint;
255
+ }
256
+ interface SyncAck {
257
+ requestId: string;
258
+ joinerNodeId: string;
259
+ table: string;
260
+ batchIndex: number;
261
+ success: boolean;
262
+ error?: string;
263
+ groupId?: string;
264
+ primaryTerm?: bigint;
265
+ }
266
+ interface ReplicationErrorEvent {
267
+ error: Error;
268
+ operation: string;
269
+ peerId?: string;
270
+ recoverable: boolean;
271
+ }
272
+
273
+ 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 };
@@ -0,0 +1,139 @@
1
+ type CoordinatorLeaseKind = 'controller' | 'node-session';
2
+ type CoordinatorWatchDisposer = () => void | Promise<void>;
3
+ interface CoordinatorLease {
4
+ id: string;
5
+ kind: CoordinatorLeaseKind;
6
+ clusterId: string;
7
+ holderId: string;
8
+ ttlMs: number;
9
+ grantedAtMs: number;
10
+ expiresAtMs: number;
11
+ metadata?: Record<string, unknown>;
12
+ }
13
+ interface AcquireControllerLeaseInput {
14
+ clusterId: string;
15
+ holderId: string;
16
+ ttlMs: number;
17
+ metadata?: Record<string, unknown>;
18
+ }
19
+ type AcquireControllerLeaseResult = {
20
+ acquired: true;
21
+ lease: CoordinatorLease;
22
+ } | {
23
+ acquired: false;
24
+ lease: CoordinatorLease | null;
25
+ };
26
+ interface CoordinatorCompatibilityMetadata {
27
+ packageVersion?: string;
28
+ specVersion?: string;
29
+ protocolVersion?: string;
30
+ }
31
+ interface RegisterNodeSessionInput {
32
+ clusterId: string;
33
+ nodeId: string;
34
+ ttlMs: number;
35
+ endpoint?: string;
36
+ groupIds?: string[];
37
+ dataBearing?: boolean;
38
+ voting?: boolean;
39
+ compatibility?: CoordinatorCompatibilityMetadata;
40
+ metadata?: Record<string, unknown>;
41
+ }
42
+ interface CoordinatorNodeSession {
43
+ clusterId: string;
44
+ nodeId: string;
45
+ lease: CoordinatorLease;
46
+ endpoint?: string;
47
+ groupIds: string[];
48
+ dataBearing: boolean;
49
+ voting: boolean;
50
+ compatibility?: CoordinatorCompatibilityMetadata;
51
+ metadata?: Record<string, unknown>;
52
+ }
53
+ interface CoordinatorPrimary {
54
+ nodeId: string;
55
+ endpoint?: string;
56
+ }
57
+ interface ReplicationGroupState {
58
+ clusterId: string;
59
+ groupId: string;
60
+ votingDataBearingNodeIds: string[];
61
+ currentPrimary: CoordinatorPrimary | null;
62
+ primaryTerm: bigint;
63
+ durabilityPointSeq: bigint;
64
+ inSyncNodeIds: string[];
65
+ drainingNodeIds: string[];
66
+ repairingNodeIds: string[];
67
+ faultedNodeIds: string[];
68
+ compatibility?: CoordinatorCompatibilityMetadata;
69
+ updatedAtMs: number;
70
+ }
71
+ interface SetReplicationGroupStateInput {
72
+ clusterId: string;
73
+ groupId: string;
74
+ votingDataBearingNodeIds: string[];
75
+ currentPrimary?: CoordinatorPrimary | null;
76
+ primaryTerm?: bigint;
77
+ durabilityPointSeq?: bigint;
78
+ inSyncNodeIds?: string[];
79
+ drainingNodeIds?: string[];
80
+ repairingNodeIds?: string[];
81
+ faultedNodeIds?: string[];
82
+ compatibility?: CoordinatorCompatibilityMetadata;
83
+ }
84
+ interface CompareAndAdvancePrimaryTermInput {
85
+ clusterId: string;
86
+ groupId: string;
87
+ expectedPrimaryTerm: bigint;
88
+ nextPrimary: CoordinatorPrimary;
89
+ }
90
+ interface CompareAndAdvancePrimaryTermResult {
91
+ advanced: boolean;
92
+ state: ReplicationGroupState | null;
93
+ }
94
+ interface UpdateInSyncSetInput {
95
+ clusterId: string;
96
+ groupId: string;
97
+ inSyncNodeIds: string[];
98
+ durabilityPointSeq?: bigint;
99
+ }
100
+ interface AdmitNodeToInSyncSetInput {
101
+ clusterId: string;
102
+ groupId: string;
103
+ nodeId: string;
104
+ sourceNodeId: string;
105
+ appliedSeq: bigint;
106
+ }
107
+ interface UpdateNodeMaintenanceInput {
108
+ clusterId: string;
109
+ groupId: string;
110
+ nodeId: string;
111
+ draining?: boolean;
112
+ repairing?: boolean;
113
+ faulted?: boolean;
114
+ }
115
+ interface PromoteEligibleReplicaInput {
116
+ clusterId: string;
117
+ groupId: string;
118
+ excludeNodeIds?: string[];
119
+ }
120
+ type ReplicationGroupWatcher = (state: ReplicationGroupState) => void;
121
+ interface ClusterCoordinator {
122
+ tryAcquireControllerLease(input: AcquireControllerLeaseInput): Promise<AcquireControllerLeaseResult>;
123
+ renewLease(leaseId: string, ttlMs: number): Promise<boolean>;
124
+ releaseLease(leaseId: string): Promise<boolean>;
125
+ registerNodeSession(input: RegisterNodeSessionInput): Promise<CoordinatorNodeSession>;
126
+ getLiveNodeSession(clusterId: string, nodeId: string): Promise<CoordinatorNodeSession | null>;
127
+ deregisterNodeSession(clusterId: string, nodeId: string): Promise<void>;
128
+ setReplicationGroupState(input: SetReplicationGroupStateInput): Promise<ReplicationGroupState>;
129
+ getReplicationGroupState(clusterId: string, groupId: string): Promise<ReplicationGroupState | null>;
130
+ watchReplicationGroup(clusterId: string, groupId: string, watcher: ReplicationGroupWatcher): CoordinatorWatchDisposer | Promise<CoordinatorWatchDisposer>;
131
+ compareAndAdvancePrimaryTerm(input: CompareAndAdvancePrimaryTermInput): Promise<CompareAndAdvancePrimaryTermResult>;
132
+ updateInSyncSet(input: UpdateInSyncSetInput): Promise<ReplicationGroupState | null>;
133
+ admitNodeToInSyncSet(input: AdmitNodeToInSyncSetInput): Promise<ReplicationGroupState | null>;
134
+ updateNodeMaintenance(input: UpdateNodeMaintenanceInput): Promise<ReplicationGroupState | null>;
135
+ promoteEligibleReplica(input: PromoteEligibleReplicaInput): Promise<ReplicationGroupState>;
136
+ close?(): Promise<void>;
137
+ }
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 };
@@ -0,0 +1,29 @@
1
+ interface RunResult {
2
+ changes: number;
3
+ lastInsertRowId: number | bigint;
4
+ }
5
+ interface SQLiteStatement {
6
+ all<T = unknown>(...params: unknown[]): Promise<T[]>;
7
+ get<T = unknown>(...params: unknown[]): Promise<T | undefined>;
8
+ run(...params: unknown[]): Promise<RunResult>;
9
+ }
10
+ interface SQLiteConnection {
11
+ exec(sql: string): Promise<void>;
12
+ prepare(sql: string): Promise<SQLiteStatement>;
13
+ transaction<T>(fn: (conn: SQLiteConnection) => Promise<T>): Promise<T>;
14
+ close(): Promise<void>;
15
+ }
16
+ interface OpenOptions {
17
+ readonly?: boolean;
18
+ walMode?: boolean;
19
+ }
20
+ interface DriverCapabilities {
21
+ multipleConnections: boolean;
22
+ extensions: boolean;
23
+ }
24
+ interface SQLiteDriver {
25
+ readonly capabilities: DriverCapabilities;
26
+ open(path: string, options?: OpenOptions): Promise<SQLiteConnection>;
27
+ }
28
+
29
+ export type { DriverCapabilities as D, OpenOptions as O, RunResult as R, SQLiteDriver as S, SQLiteConnection as a, SQLiteStatement as b };
@@ -0,0 +1,26 @@
1
+ import { T as Transaction } from './types-D-74JiXb.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 };
@@ -1,5 +1,48 @@
1
+ import { a as SQLiteConnection, S as SQLiteDriver } from './types-BFSsG77t.js';
2
+
3
+ declare class Transaction {
4
+ private readonly conn;
5
+ private _lastInsertRowId;
6
+ constructor(conn: SQLiteConnection);
7
+ query<T = Record<string, unknown>>(sql: string, params?: Params): Promise<T[]>;
8
+ execute(sql: string, params?: Params): Promise<ExecuteResult>;
9
+ executeBatch(sql: string, paramsBatch: Params[]): Promise<ExecuteResult[]>;
10
+ get lastInsertRowId(): number | bigint;
11
+ static run<T>(conn: SQLiteConnection, fn: (tx: Transaction) => Promise<T>): Promise<T>;
12
+ }
13
+
1
14
  /** Query parameter types: named (object) or positional (array). */
2
15
  type Params = Record<string, unknown> | unknown[];
16
+ type WriteConcernLevel = 'local' | 'majority' | 'all';
17
+ interface WriteConcern {
18
+ level: WriteConcernLevel;
19
+ timeoutMs?: number;
20
+ }
21
+ type ReadConcernLevel = 'local' | 'majority' | 'linearizable';
22
+ interface ReadConcern {
23
+ level: ReadConcernLevel;
24
+ }
25
+ interface QueryOptions {
26
+ writeConcern?: WriteConcern;
27
+ readConcern?: ReadConcern;
28
+ }
29
+ interface ClusterReadEndpointInfo {
30
+ nodeId: string;
31
+ endpoint: string;
32
+ readConcerns: ReadConcernLevel[];
33
+ }
34
+ interface ClusterStatusInfo {
35
+ databaseId: string;
36
+ replicationGroupId?: string;
37
+ role?: 'primary' | 'replica';
38
+ currentPrimary?: {
39
+ nodeId: string;
40
+ endpoint?: string;
41
+ } | null;
42
+ primaryTerm?: bigint;
43
+ readEndpoints?: ClusterReadEndpointInfo[];
44
+ health: 'healthy' | 'degraded' | 'failing_over' | 'unavailable' | 'repairing' | 'syncing';
45
+ }
3
46
  /** Result returned by mutation statements (INSERT, UPDATE, DELETE). */
4
47
  interface ExecuteResult {
5
48
  changes: number;
@@ -22,6 +65,8 @@ interface QueryHookContext {
22
65
  sql: string;
23
66
  params?: Params;
24
67
  metadata?: Record<string, unknown>;
68
+ writeConcern?: WriteConcern;
69
+ readConcern?: ReadConcern;
25
70
  }
26
71
  /** Hook invoked before a query is executed. Throw to deny. */
27
72
  type BeforeQueryHook = (ctx: QueryHookContext) => void | Promise<void>;
@@ -113,6 +158,7 @@ interface DatabaseOptions {
113
158
  }
114
159
  /** Top-level options for the Sirannon database registry. */
115
160
  interface SirannonOptions {
161
+ driver: SQLiteDriver;
116
162
  hooks?: HookConfig;
117
163
  metrics?: MetricsConfig;
118
164
  lifecycle?: LifecycleConfig;
@@ -153,12 +199,42 @@ interface RequestDenial {
153
199
  }
154
200
  /** Middleware hook for auth, rate limiting, and request validation. */
155
201
  type OnRequestHook = (ctx: RequestContext) => undefined | RequestDenial | Promise<undefined | RequestDenial>;
202
+ interface ServerExecutionTarget {
203
+ query<T = Record<string, unknown>>(sql: string, params?: Params, options?: QueryOptions): Promise<T[]>;
204
+ execute(sql: string, params?: Params, options?: QueryOptions): Promise<ExecuteResult>;
205
+ transaction<T>(fn: (tx: Transaction) => Promise<T>, options?: QueryOptions): Promise<T>;
206
+ }
207
+ type ServerExecutionTargetResolver = (databaseId: string) => ServerExecutionTarget | null | undefined | Promise<ServerExecutionTarget | null | undefined>;
156
208
  /** Options for the standalone HTTP + WS server. */
157
209
  interface ServerOptions {
158
210
  host?: string;
159
211
  port?: number;
160
212
  cors?: boolean | CorsOptions;
161
213
  onRequest?: OnRequestHook;
214
+ resolveExecutionTarget?: ServerExecutionTargetResolver;
215
+ getReplicationStatus?: () => ReplicationStatusInfo | null;
216
+ getClusterStatus?: (databaseId: string) => ClusterStatusInfo | null;
217
+ }
218
+ interface ReplicationStatusInfo {
219
+ role: string;
220
+ writeForwarding: boolean;
221
+ peers: number;
222
+ localSeq: bigint;
223
+ replicationGroupId?: string;
224
+ primaryTerm?: bigint;
225
+ currentPrimary?: string;
226
+ coordinator?: {
227
+ connected: boolean;
228
+ authority: boolean;
229
+ };
230
+ controller?: {
231
+ state: 'disabled' | 'standby' | 'active' | 'lost';
232
+ };
233
+ inSyncReplicas?: string[];
234
+ laggingReplicas?: string[];
235
+ syncState?: string;
236
+ readAvailability?: 'available' | 'unavailable';
237
+ writeAvailability?: 'available' | 'unavailable';
162
238
  }
163
239
  /** CORS configuration. */
164
240
  interface CorsOptions {
@@ -170,6 +246,7 @@ interface CorsOptions {
170
246
  interface WSHandlerOptions {
171
247
  /** Maximum message size in bytes. Default: 1_048_576 (1 MB). */
172
248
  maxPayloadLength?: number;
249
+ resolveExecutionTarget?: ServerExecutionTargetResolver;
173
250
  }
174
251
  /** Options for the client SDK. */
175
252
  interface ClientOptions {
@@ -177,10 +254,12 @@ interface ClientOptions {
177
254
  transport?: 'websocket' | 'http';
178
255
  /** Custom headers for HTTP requests. */
179
256
  headers?: Record<string, string>;
257
+ /** WebSocket subprotocols sent during the browser-compatible handshake. */
258
+ webSocketProtocols?: string | string[];
180
259
  /** Reconnect on WebSocket disconnect. Default: true. */
181
260
  autoReconnect?: boolean;
182
261
  /** Reconnect interval in ms. Default: 1000. */
183
262
  reconnectInterval?: number;
184
263
  }
185
264
 
186
- export type { AfterQueryHook as A, BackupScheduleOptions as B, CDCMetrics as C, DatabaseOptions as D, ExecuteResult as E, HookConfig as H, LifecycleConfig as L, MetricsConfig as M, OnRequestHook as O, Params as P, QueryHookContext as Q, RequestContext as R, ServerOptions as S, WSHandlerOptions as W, BeforeConnectHook as a, BeforeQueryHook as b, BeforeSubscribeHook as c, ChangeEvent as d, ChangeOperation as e, ClientOptions as f, ConnectionHookContext as g, ConnectionMetrics as h, CorsOptions as i, DatabaseCloseHook as j, DatabaseOpenHook as k, QueryMetrics as l, RequestDenial as m, SirannonOptions as n, Subscription as o, SubscriptionBuilder as p };
265
+ export { type AfterQueryHook as A, type BeforeQueryHook as B, type ChangeEvent as C, type DatabaseOptions as D, type ExecuteResult as E, type HookConfig as H, type LifecycleConfig as L, type MetricsConfig as M, type OnRequestHook as O, type Params as P, type QueryHookContext as Q, type ReadConcern as R, type SirannonOptions as S, Transaction as T, type WriteConcern as W, type BeforeConnectHook as a, type DatabaseOpenHook as b, type DatabaseCloseHook as c, type ServerOptions as d, type WSHandlerOptions as e, type ConnectionHookContext as f, type BeforeSubscribeHook as g, type QueryMetrics as h, type ConnectionMetrics as i, type CDCMetrics as j, type QueryOptions as k, type SubscriptionBuilder as l, type BackupScheduleOptions as m, type ChangeOperation as n, type ClientOptions as o, type ClusterReadEndpointInfo as p, type ClusterStatusInfo as q, type CorsOptions as r, type ReadConcernLevel as s, type ReplicationStatusInfo as t, type RequestContext as u, type RequestDenial as v, type ServerExecutionTarget as w, type ServerExecutionTargetResolver as x, type Subscription as y, type WriteConcernLevel as z };
@@ -0,0 +1,2 @@
1
+ export { AccessHandlePoolVFS } from 'wa-sqlite/src/examples/AccessHandlePoolVFS.js';
2
+ export { IDBBatchAtomicVFS } from 'wa-sqlite/src/examples/IDBBatchAtomicVFS.js';