@delali/sirannon-db 0.1.4 → 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.
@@ -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,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,7 +1,48 @@
1
- import { S as SQLiteDriver } from './types-BFSsG77t.js';
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
+ }
2
13
 
3
14
  /** Query parameter types: named (object) or positional (array). */
4
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
+ }
5
46
  /** Result returned by mutation statements (INSERT, UPDATE, DELETE). */
6
47
  interface ExecuteResult {
7
48
  changes: number;
@@ -24,6 +65,8 @@ interface QueryHookContext {
24
65
  sql: string;
25
66
  params?: Params;
26
67
  metadata?: Record<string, unknown>;
68
+ writeConcern?: WriteConcern;
69
+ readConcern?: ReadConcern;
27
70
  }
28
71
  /** Hook invoked before a query is executed. Throw to deny. */
29
72
  type BeforeQueryHook = (ctx: QueryHookContext) => void | Promise<void>;
@@ -156,12 +199,42 @@ interface RequestDenial {
156
199
  }
157
200
  /** Middleware hook for auth, rate limiting, and request validation. */
158
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>;
159
208
  /** Options for the standalone HTTP + WS server. */
160
209
  interface ServerOptions {
161
210
  host?: string;
162
211
  port?: number;
163
212
  cors?: boolean | CorsOptions;
164
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';
165
238
  }
166
239
  /** CORS configuration. */
167
240
  interface CorsOptions {
@@ -173,6 +246,7 @@ interface CorsOptions {
173
246
  interface WSHandlerOptions {
174
247
  /** Maximum message size in bytes. Default: 1_048_576 (1 MB). */
175
248
  maxPayloadLength?: number;
249
+ resolveExecutionTarget?: ServerExecutionTargetResolver;
176
250
  }
177
251
  /** Options for the client SDK. */
178
252
  interface ClientOptions {
@@ -180,10 +254,12 @@ interface ClientOptions {
180
254
  transport?: 'websocket' | 'http';
181
255
  /** Custom headers for HTTP requests. */
182
256
  headers?: Record<string, string>;
257
+ /** WebSocket subprotocols sent during the browser-compatible handshake. */
258
+ webSocketProtocols?: string | string[];
183
259
  /** Reconnect on WebSocket disconnect. Default: true. */
184
260
  autoReconnect?: boolean;
185
261
  /** Reconnect interval in ms. Default: 1000. */
186
262
  reconnectInterval?: number;
187
263
  }
188
264
 
189
- export type { AfterQueryHook as A, BeforeSubscribeHook as B, ConnectionHookContext 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, QueryMetrics as a, ConnectionMetrics as b, CDCMetrics as c, SubscriptionBuilder as d, BackupScheduleOptions as e, BeforeQueryHook as f, SirannonOptions as g, BeforeConnectHook as h, DatabaseOpenHook as i, DatabaseCloseHook as j, ChangeEvent as k, ChangeOperation as l, ClientOptions as m, CorsOptions as n, RequestDenial as o, Subscription 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 };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@delali/sirannon-db",
3
3
  "type": "module",
4
- "version": "0.1.4",
4
+ "version": "0.1.5",
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",
@@ -65,6 +65,22 @@
65
65
  "./client": {
66
66
  "types": "./dist/client/index.d.ts",
67
67
  "import": "./dist/client/index.mjs"
68
+ },
69
+ "./replication": {
70
+ "types": "./dist/replication/index.d.ts",
71
+ "import": "./dist/replication/index.mjs"
72
+ },
73
+ "./replication/coordinator/etcd": {
74
+ "types": "./dist/replication/coordinator/etcd.d.ts",
75
+ "import": "./dist/replication/coordinator/etcd.mjs"
76
+ },
77
+ "./transport/memory": {
78
+ "types": "./dist/transport/memory.d.ts",
79
+ "import": "./dist/transport/memory.mjs"
80
+ },
81
+ "./transport/grpc": {
82
+ "types": "./dist/transport/grpc.d.ts",
83
+ "import": "./dist/transport/grpc.mjs"
68
84
  }
69
85
  },
70
86
  "files": [
@@ -76,39 +92,62 @@
76
92
  "node": ">=22"
77
93
  },
78
94
  "peerDependencies": {
95
+ "@bufbuild/protobuf": ">=2.0.0",
96
+ "@grpc/grpc-js": ">=1.10.0",
79
97
  "better-sqlite3": ">=12.0.0",
80
- "wa-sqlite": ">=1.0.0",
81
- "expo-sqlite": ">=14.0.0",
82
98
  "croner": ">=10.0.0",
83
- "uWebSockets.js": ">=20.0.0"
99
+ "expo-sqlite": ">=14.0.0",
100
+ "etcd3": ">=1.1.2",
101
+ "grpc-health-check": ">=2.0.0",
102
+ "uWebSockets.js": ">=20.0.0",
103
+ "wa-sqlite": ">=1.0.0"
84
104
  },
85
105
  "peerDependenciesMeta": {
106
+ "@bufbuild/protobuf": {
107
+ "optional": true
108
+ },
109
+ "@grpc/grpc-js": {
110
+ "optional": true
111
+ },
86
112
  "better-sqlite3": {
87
113
  "optional": true
88
114
  },
89
- "wa-sqlite": {
115
+ "croner": {
90
116
  "optional": true
91
117
  },
92
118
  "expo-sqlite": {
93
119
  "optional": true
94
120
  },
95
- "croner": {
121
+ "etcd3": {
122
+ "optional": true
123
+ },
124
+ "grpc-health-check": {
96
125
  "optional": true
97
126
  },
98
127
  "uWebSockets.js": {
99
128
  "optional": true
129
+ },
130
+ "wa-sqlite": {
131
+ "optional": true
100
132
  }
101
133
  },
102
134
  "devDependencies": {
135
+ "@bufbuild/protobuf": "2.11.0",
136
+ "@grpc/grpc-js": "1.14.3",
103
137
  "@types/better-sqlite3": "7.6.13",
104
138
  "@types/node": "25.3.3",
105
- "@types/pg": "8.11.10",
139
+ "@types/pg": "8.20.0",
106
140
  "@vitest/coverage-v8": "4.0.18",
107
141
  "better-sqlite3": "12.6.2",
108
142
  "croner": "10.0.1",
109
- "pg": "8.19.0",
143
+ "etcd3": "1.1.2",
144
+ "grpc-health-check": "2.1.0",
145
+ "grpc-tools": "1.13.1",
146
+ "pg": "8.20.0",
147
+ "selfsigned": "5.5.0",
110
148
  "simple-statistics": "7.8.7",
111
149
  "tinybench": "6.0.0",
150
+ "ts-proto": "2.11.6",
112
151
  "tsup": "8.5.1",
113
152
  "tsx": "4.21.0",
114
153
  "typescript": "5.9.3",
@@ -119,7 +158,10 @@
119
158
  "build": "rm -rf dist && tsup",
120
159
  "test": "vitest run",
121
160
  "test:coverage": "vitest run --coverage",
122
- "typecheck": "tsc --noEmit",
161
+ "test:e2e": "vitest run --config vitest.e2e.config.ts",
162
+ "test:failover": "vitest run --config vitest.failover.config.ts",
163
+ "test:soak": "vitest run --config vitest.soak.config.ts",
164
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
123
165
  "lint": "biome check .",
124
166
  "lint:fix": "biome check --write .",
125
167
  "format": "biome format --write .",
@@ -128,11 +170,13 @@
128
170
  "bench:ycsb": "node --expose-gc --import tsx benchmarks/ycsb/workload-a.ts",
129
171
  "bench:oltp": "node --expose-gc --import tsx benchmarks/oltp/tpc-c-lite.ts",
130
172
  "bench:scaling": "node --expose-gc --import tsx benchmarks/scaling/concurrency.ts",
173
+ "bench:pool": "node --expose-gc --import tsx benchmarks/scaling/pool-sweep.ts",
131
174
  "bench:cdc": "node --expose-gc --import tsx benchmarks/sirannon/cdc-latency.ts",
132
175
  "bench:docker": "node --import tsx benchmarks/run-docker.ts",
133
176
  "bench:docker:e2e": "node --import tsx benchmarks/run-e2e.ts",
134
177
  "bench:docker:engine": "node --expose-gc --import tsx benchmarks/run-engine.ts",
135
178
  "bench:statistical": "node --expose-gc --import tsx benchmarks/run-statistical.ts",
136
- "bench:charts": "python3 benchmarks/scripts/generate-charts.py benchmarks/results/"
179
+ "bench:charts": "python3 benchmarks/scripts/generate-charts.py benchmarks/results/",
180
+ "proto:gen": "grpc_tools_node_protoc --plugin=protoc-gen-ts_proto=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=src/transport/grpc/generated --ts_proto_opt=forceLong=bigint --ts_proto_opt=esModuleInterop=true --ts_proto_opt=outputServices=grpc-js --ts_proto_opt=env=node -I src/transport/grpc/proto src/transport/grpc/proto/replication.proto"
137
181
  }
138
182
  }