@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.
- package/README.md +655 -80
- package/dist/backup-scheduler/index.d.ts +3 -0
- package/dist/backup-scheduler/index.mjs +2 -0
- package/dist/change-tracker-CFTQ9TSn.d.ts +89 -0
- package/dist/chunk-3MCMONVP.mjs +115 -0
- package/dist/chunk-74UN4DIE.mjs +14 -0
- package/dist/chunk-ER7ODTDA.mjs +23 -0
- package/dist/chunk-FB2U2Q3Y.mjs +21 -0
- package/dist/chunk-GS7T5YMI.mjs +51 -0
- package/dist/chunk-O7BHI3CF.mjs +90 -0
- package/dist/chunk-PXKAKK2V.mjs +124 -0
- package/dist/chunk-UTO3ZAFS.mjs +514 -0
- package/dist/chunk-UVMVN3OT.mjs +111 -0
- package/dist/client/index.d.ts +137 -44
- package/dist/client/index.mjs +726 -26
- package/dist/core/index.d.ts +32 -241
- package/dist/core/index.mjs +294 -568
- package/dist/database-BVY1GqE7.d.ts +95 -0
- package/dist/driver/better-sqlite3.d.ts +8 -0
- package/dist/driver/better-sqlite3.mjs +63 -0
- package/dist/driver/bun.mjs +61 -0
- package/dist/driver/expo.mjs +55 -0
- package/dist/driver/node.d.ts +8 -0
- package/dist/driver/node.mjs +60 -0
- package/dist/driver/wa-sqlite.d.ts +34 -0
- package/dist/driver/wa-sqlite.mjs +141 -0
- package/dist/errors-C00ed08Q.d.ts +101 -0
- package/dist/file-migrations/index.d.ts +16 -0
- package/dist/file-migrations/index.mjs +128 -0
- package/dist/index-CLdNrcPz.d.ts +16 -0
- package/dist/replication/coordinator/etcd.d.ts +44 -0
- package/dist/replication/coordinator/etcd.mjs +650 -0
- package/dist/replication/index.d.ts +491 -0
- package/dist/replication/index.mjs +3784 -0
- package/dist/server/index.d.ts +121 -54
- package/dist/server/index.mjs +347 -114
- package/dist/sirannon-Cd-lK6T0.d.ts +31 -0
- package/dist/transport/grpc.d.ts +316 -0
- package/dist/transport/grpc.mjs +3341 -0
- package/dist/transport/memory.d.ts +221 -0
- package/dist/transport/memory.mjs +337 -0
- package/dist/types-B2byqt0B.d.ts +273 -0
- package/dist/types-BEu1I_9_.d.ts +139 -0
- package/dist/types-BFSsG77t.d.ts +29 -0
- package/dist/types-BeozgNPr.d.ts +26 -0
- package/dist/{types-DArCObcu.d.ts → types-D-74JiXb.d.ts} +80 -1
- package/dist/vfs-INWQ5DTE.mjs +2 -0
- package/package.json +106 -11
- package/dist/chunk-VI4UP4RR.mjs +0 -417
- package/dist/protocol-BX1H-_Mz.d.ts +0 -104
- package/dist/sirannon-BJ8Yd1Uf.d.ts +0 -148
package/dist/client/index.d.ts
CHANGED
|
@@ -1,12 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/** Query parameter types: named (object) or positional (array). */
|
|
2
|
+
type Params = Record<string, unknown> | unknown[];
|
|
3
|
+
type WriteConcernLevel = 'local' | 'majority' | 'all';
|
|
4
|
+
interface WriteConcern {
|
|
5
|
+
level: WriteConcernLevel;
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
}
|
|
8
|
+
type ReadConcernLevel = 'local' | 'majority' | 'linearizable';
|
|
9
|
+
interface ReadConcern {
|
|
10
|
+
level: ReadConcernLevel;
|
|
11
|
+
}
|
|
12
|
+
interface QueryOptions {
|
|
13
|
+
writeConcern?: WriteConcern;
|
|
14
|
+
readConcern?: ReadConcern;
|
|
15
|
+
}
|
|
16
|
+
/** CDC operation type. */
|
|
17
|
+
type ChangeOperation = 'insert' | 'update' | 'delete';
|
|
18
|
+
/** Event emitted when a watched table row changes. */
|
|
19
|
+
interface ChangeEvent<T = Record<string, unknown>> {
|
|
20
|
+
type: ChangeOperation;
|
|
21
|
+
table: string;
|
|
22
|
+
row: T;
|
|
23
|
+
oldRow?: T;
|
|
24
|
+
seq: bigint;
|
|
25
|
+
timestamp: number;
|
|
26
|
+
}
|
|
27
|
+
/** Options for the client SDK. */
|
|
28
|
+
interface ClientOptions {
|
|
29
|
+
/** Transport to use. Default: 'websocket'. */
|
|
30
|
+
transport?: 'websocket' | 'http';
|
|
31
|
+
/** Custom headers for HTTP requests. */
|
|
32
|
+
headers?: Record<string, string>;
|
|
33
|
+
/** WebSocket subprotocols sent during the browser-compatible handshake. */
|
|
34
|
+
webSocketProtocols?: string | string[];
|
|
35
|
+
/** Reconnect on WebSocket disconnect. Default: true. */
|
|
36
|
+
autoReconnect?: boolean;
|
|
37
|
+
/** Reconnect interval in ms. Default: 1000. */
|
|
38
|
+
reconnectInterval?: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Response for a successful query. */
|
|
42
|
+
interface QueryResponse {
|
|
43
|
+
rows: Record<string, unknown>[];
|
|
44
|
+
}
|
|
45
|
+
/** Response for a successful execute. */
|
|
46
|
+
interface ExecuteResponse {
|
|
47
|
+
changes: number;
|
|
48
|
+
lastInsertRowId: number | string;
|
|
49
|
+
}
|
|
50
|
+
/** Response for a successful transaction. */
|
|
51
|
+
interface TransactionResponse {
|
|
52
|
+
results: ExecuteResponse[];
|
|
53
|
+
}
|
|
3
54
|
|
|
4
55
|
/**
|
|
5
56
|
* Transport layer for communicating with a sirannon-db server.
|
|
6
57
|
* Each transport instance is bound to a specific database.
|
|
7
58
|
*/
|
|
8
59
|
interface Transport {
|
|
9
|
-
query(sql: string, params?: Params): Promise<QueryResponse>;
|
|
60
|
+
query(sql: string, params?: Params, readConcern?: ReadConcern): Promise<QueryResponse>;
|
|
10
61
|
execute(sql: string, params?: Params): Promise<ExecuteResponse>;
|
|
11
62
|
transaction(statements: Array<{
|
|
12
63
|
sql: string;
|
|
@@ -53,7 +104,7 @@ declare class RemoteDatabase {
|
|
|
53
104
|
* )
|
|
54
105
|
* ```
|
|
55
106
|
*/
|
|
56
|
-
query<T = Record<string, unknown>>(sql: string, params?: Params): Promise<T[]>;
|
|
107
|
+
query<T = Record<string, unknown>>(sql: string, params?: Params, options?: QueryOptions): Promise<T[]>;
|
|
57
108
|
/**
|
|
58
109
|
* Execute a mutation (INSERT, UPDATE, DELETE) and return
|
|
59
110
|
* the number of affected rows and last insert row ID.
|
|
@@ -93,45 +144,97 @@ declare class RemoteDatabase {
|
|
|
93
144
|
close(): void;
|
|
94
145
|
}
|
|
95
146
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
*
|
|
105
|
-
* const db = client.database('main')
|
|
106
|
-
* const rows = await db.query('SELECT * FROM users')
|
|
107
|
-
*
|
|
108
|
-
* client.close()
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
147
|
+
interface TopologyAwareClientOptions extends ClientOptions {
|
|
148
|
+
endpoints?: string[];
|
|
149
|
+
primary?: string;
|
|
150
|
+
replicas?: string[];
|
|
151
|
+
readPreference?: 'primary' | 'replica' | 'nearest';
|
|
152
|
+
discovery?: 'static' | 'coordinator';
|
|
153
|
+
readConcern?: ReadConcernLevel;
|
|
154
|
+
}
|
|
111
155
|
declare class SirannonClient {
|
|
112
156
|
private readonly baseUrl;
|
|
113
157
|
private readonly wsBaseUrl;
|
|
114
158
|
private readonly transport;
|
|
115
159
|
private readonly headers;
|
|
160
|
+
private readonly webSocketProtocols;
|
|
116
161
|
private readonly autoReconnect;
|
|
117
162
|
private readonly reconnectInterval;
|
|
118
163
|
private readonly databases;
|
|
119
164
|
private closed;
|
|
165
|
+
private readonly topologyEnabled;
|
|
166
|
+
private readonly primaryUrl;
|
|
167
|
+
private readonly replicaUrls;
|
|
168
|
+
private readonly readPreference;
|
|
169
|
+
private readonly discovery;
|
|
170
|
+
private readonly readConcern;
|
|
171
|
+
private readonly starterEndpoints;
|
|
172
|
+
private readonly clusterRouting;
|
|
173
|
+
private readonly topologyTransports;
|
|
174
|
+
private latencies;
|
|
175
|
+
private latencyMeasuredAt;
|
|
176
|
+
private latencyMeasuring;
|
|
177
|
+
private readonly LATENCY_TTL_MS;
|
|
178
|
+
private removedReplicas;
|
|
120
179
|
constructor(url: string, options?: ClientOptions);
|
|
121
|
-
|
|
122
|
-
* Get a {@link RemoteDatabase} proxy for the given database ID.
|
|
123
|
-
* Returns a cached instance if one already exists for this ID.
|
|
124
|
-
*
|
|
125
|
-
* The underlying transport connection is established lazily on
|
|
126
|
-
* the first operation (query, execute, or subscribe).
|
|
127
|
-
*/
|
|
180
|
+
constructor(options: TopologyAwareClientOptions);
|
|
128
181
|
database(id: string): RemoteDatabase;
|
|
129
|
-
/**
|
|
130
|
-
* Close all database connections and release resources.
|
|
131
|
-
* After calling `close()`, new calls to `database()` will throw.
|
|
132
|
-
*/
|
|
133
182
|
close(): void;
|
|
134
183
|
private createTransport;
|
|
184
|
+
private createTransportForUrl;
|
|
185
|
+
_createTransportForEndpoint(url: string, databaseId: string): Transport;
|
|
186
|
+
_getReadEndpoint(databaseId?: string, readConcern?: ReadConcernLevel): Promise<string>;
|
|
187
|
+
_getWriteEndpoint(databaseId?: string): Promise<string>;
|
|
188
|
+
_getReadConcern(): ReadConcernLevel | undefined;
|
|
189
|
+
_usesCoordinatorDiscovery(): boolean;
|
|
190
|
+
_removeReplica(url: string): void;
|
|
191
|
+
private ensureLatencyMeasured;
|
|
192
|
+
private measureLatencies;
|
|
193
|
+
_refreshClusterRouting(databaseId: string): Promise<void>;
|
|
194
|
+
private ensureClusterRouting;
|
|
195
|
+
private clusterDiscoveryCandidates;
|
|
196
|
+
_unregisterTopologyTransport(databaseId: string, transport: TopologyAwareTransport): void;
|
|
197
|
+
private notifyClusterRoutingChanged;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
declare class TopologyAwareTransport implements Transport {
|
|
201
|
+
private readonly databaseId;
|
|
202
|
+
private readonly client;
|
|
203
|
+
private closed;
|
|
204
|
+
private readTransport;
|
|
205
|
+
private writeTransport;
|
|
206
|
+
private subscriptionTransport;
|
|
207
|
+
private readTransportRequest;
|
|
208
|
+
private writeTransportRequest;
|
|
209
|
+
private subscriptionTransportRequest;
|
|
210
|
+
private subscriptionOperation;
|
|
211
|
+
private activeSubscriptions;
|
|
212
|
+
private nextSubscriptionId;
|
|
213
|
+
private currentReadUrl;
|
|
214
|
+
private currentWriteUrl;
|
|
215
|
+
private currentSubscriptionUrl;
|
|
216
|
+
constructor(databaseId: string, client: SirannonClient);
|
|
217
|
+
query(sql: string, params?: Params): Promise<QueryResponse>;
|
|
218
|
+
execute(sql: string, params?: Params): Promise<ExecuteResponse>;
|
|
219
|
+
transaction(statements: Array<{
|
|
220
|
+
sql: string;
|
|
221
|
+
params?: Params;
|
|
222
|
+
}>): Promise<TransactionResponse>;
|
|
223
|
+
subscribe(table: string, filter: Record<string, unknown> | undefined, callback: (event: ChangeEvent) => void): Promise<RemoteSubscription>;
|
|
224
|
+
_handleClusterRoutingChanged(): Promise<void>;
|
|
225
|
+
close(): void;
|
|
226
|
+
private subscribeOnCurrentEndpoint;
|
|
227
|
+
private createSubscriptionHandle;
|
|
228
|
+
private migrateSubscriptionsToCurrentEndpoint;
|
|
229
|
+
private getReadTransport;
|
|
230
|
+
private resolveReadTransport;
|
|
231
|
+
private getWriteTransport;
|
|
232
|
+
private resolveWriteTransport;
|
|
233
|
+
private getSubscriptionTransport;
|
|
234
|
+
private resolveSubscriptionTransport;
|
|
235
|
+
private closeSubscriptionTransport;
|
|
236
|
+
private withSubscriptionOperation;
|
|
237
|
+
private assertOpen;
|
|
135
238
|
}
|
|
136
239
|
|
|
137
240
|
/**
|
|
@@ -160,7 +263,7 @@ declare class HttpTransport implements Transport {
|
|
|
160
263
|
private readonly headers;
|
|
161
264
|
private closed;
|
|
162
265
|
constructor(baseUrl: string, headers?: Record<string, string>);
|
|
163
|
-
query(sql: string, params?: Params): Promise<QueryResponse>;
|
|
266
|
+
query(sql: string, params?: Params, readConcern?: ReadConcern): Promise<QueryResponse>;
|
|
164
267
|
execute(sql: string, params?: Params): Promise<ExecuteResponse>;
|
|
165
268
|
transaction(statements: Array<{
|
|
166
269
|
sql: string;
|
|
@@ -171,24 +274,13 @@ declare class HttpTransport implements Transport {
|
|
|
171
274
|
private post;
|
|
172
275
|
}
|
|
173
276
|
|
|
174
|
-
/**
|
|
175
|
-
* WebSocket transport for sirannon-db. Connects to
|
|
176
|
-
* `ws(s)://host:port/db/{id}` and supports query, execute,
|
|
177
|
-
* and real-time CDC subscriptions over a single persistent connection.
|
|
178
|
-
*
|
|
179
|
-
* Connections are established lazily on first use and will
|
|
180
|
-
* auto-reconnect (with subscription restoration) when
|
|
181
|
-
* `autoReconnect` is enabled.
|
|
182
|
-
*
|
|
183
|
-
* Transactions are not supported over WebSocket; use
|
|
184
|
-
* {@link HttpTransport} for batch transactions.
|
|
185
|
-
*/
|
|
186
277
|
declare class WebSocketTransport implements Transport {
|
|
187
278
|
private ws;
|
|
188
279
|
private readonly url;
|
|
189
280
|
private readonly autoReconnect;
|
|
190
281
|
private readonly reconnectInterval;
|
|
191
282
|
private readonly requestTimeout;
|
|
283
|
+
private readonly protocols;
|
|
192
284
|
private pendingRequests;
|
|
193
285
|
private activeSubscriptions;
|
|
194
286
|
private idCounter;
|
|
@@ -199,6 +291,7 @@ declare class WebSocketTransport implements Transport {
|
|
|
199
291
|
autoReconnect?: boolean;
|
|
200
292
|
reconnectInterval?: number;
|
|
201
293
|
requestTimeout?: number;
|
|
294
|
+
protocols?: string | string[];
|
|
202
295
|
});
|
|
203
296
|
query(sql: string, params?: Params): Promise<QueryResponse>;
|
|
204
297
|
execute(sql: string, params?: Params): Promise<ExecuteResponse>;
|
|
@@ -220,4 +313,4 @@ declare class WebSocketTransport implements Transport {
|
|
|
220
313
|
private cancelReconnect;
|
|
221
314
|
}
|
|
222
315
|
|
|
223
|
-
export { HttpTransport, RemoteDatabase, RemoteError, type RemoteSubscription, type RemoteSubscriptionBuilder, RemoteSubscriptionBuilderImpl, SirannonClient, type Transport, WebSocketTransport };
|
|
316
|
+
export { HttpTransport, RemoteDatabase, RemoteError, type RemoteSubscription, type RemoteSubscriptionBuilder, RemoteSubscriptionBuilderImpl, SirannonClient, type TopologyAwareClientOptions, type Transport, WebSocketTransport };
|