@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,70 +1,23 @@
1
- import { W as WriteConcern, g as BulkLoadDurability, h as BulkLoadResult, R as ReadConcern, E as ExecuteResult, i as ServerOptions, j as WSHandlerOptions } from '../types-D_hQW1hr.js';
2
- import { S as Sirannon } from '../sirannon-4SspRvP5.js';
3
- import '../database-DuGp0Rtr.js';
4
- import '../types-D4p4UyDK.js';
1
+ import { T as TransactionStatement, Q as QueryResponse, E as ExecuteResponse, a as TransactionResponse, B as BatchResponse, L as LoadResponse, A as AckResponse } from '../protocol-6KrSq2Hy.js';
2
+ export { b as BatchRequest, c as ErrorResponse, d as ExecuteRequest, e as LoadRequest, f as QueryRequest, g as TransactionRequest, t as toExecuteResponse } from '../protocol-6KrSq2Hy.js';
3
+ import { S as Sirannon } from '../sirannon-DaQSyhbJ.js';
4
+ import { B as BulkLoadDurability, S as ServerOptions, W as WSHandlerOptions } from '../server-options-1JHu8pid.js';
5
+ import { W as WriteConcern, R as ReadConcern } from '../types-zhnRXrsb.js';
6
+ import '../database-BY0L5Q2n.js';
7
+ import '../types-C_D8IhpO.js';
8
+ import '../types-CL6piSnD.js';
9
+ import '../operation-registry-9DcvxcE5.js';
5
10
 
6
- interface QueryRequest {
7
- sql: string;
8
- params?: Record<string, unknown> | unknown[];
9
- readConcern?: ReadConcern;
10
- }
11
- interface ExecuteRequest {
12
- sql: string;
13
- params?: Record<string, unknown> | unknown[];
14
- writeConcern?: WriteConcern;
15
- }
16
- interface TransactionStatement {
17
- sql: string;
18
- params?: Record<string, unknown> | unknown[];
19
- }
20
- interface TransactionRequest {
21
- statements: TransactionStatement[];
22
- writeConcern?: WriteConcern;
23
- }
24
- /** The whole batch commits atomically in one server-side transaction with one fsync. */
25
- interface BatchRequest {
26
- sql: string;
27
- paramsBatch: (Record<string, unknown> | unknown[])[];
28
- writeConcern?: WriteConcern;
29
- }
30
- interface QueryResponse {
31
- rows: Record<string, unknown>[];
32
- }
33
- interface ExecuteResponse {
34
- changes: number;
35
- lastInsertRowId: number | string;
36
- }
37
- interface TransactionResponse {
38
- results: ExecuteResponse[];
39
- }
40
- interface BatchResponse {
41
- results: ExecuteResponse[];
42
- }
43
- /**
44
- * Loads rows with relaxed writer durability; the configured durability is
45
- * restored before the response is sent, and a load interrupted by a crash is
46
- * recovered by re-running it.
47
- */
48
- interface LoadRequest {
49
- sql: string;
50
- paramsBatch: (Record<string, unknown> | unknown[])[];
51
- durability?: BulkLoadDurability;
52
- checkpoint?: boolean;
53
- }
54
- type LoadResponse = BulkLoadResult;
55
- interface ErrorResponse {
56
- error: {
57
- code: string;
58
- message: string;
59
- details?: Record<string, unknown>;
60
- };
61
- }
62
- type WSClientMessage = WSSubscribeMessage | WSUnsubscribeMessage | WSQueryMessage | WSExecuteMessage | WSTransactionMessage | WSBatchMessage | WSLoadMessage;
11
+ type WSClientMessage = WSSubscribeMessage | WSUnsubscribeMessage | WSAckMessage | WSQueryMessage | WSExecuteMessage | WSTransactionMessage | WSBatchMessage | WSLoadMessage;
63
12
  interface WSSubscribeMessage {
64
13
  type: 'subscribe';
65
14
  id: string;
66
- table: string;
15
+ table?: string;
16
+ tables?: string[];
67
17
  filter?: Record<string, unknown>;
18
+ name?: string;
19
+ args?: Record<string, unknown>;
20
+ registryDigest?: string;
68
21
  /**
69
22
  * Highest `seq` the client has already processed. When present, the server
70
23
  * replays every retained change with a greater seq before delivering live
@@ -79,22 +32,43 @@ interface WSSubscribeMessage {
79
32
  * resync rather than replay foreign rows against it.
80
33
  */
81
34
  epoch?: string;
35
+ deviceId?: string;
36
+ schemaVersion?: number;
37
+ /**
38
+ * Declares that this device stages pulled changes durably and
39
+ * acknowledges staged sequences. The server then packs several events
40
+ * into each `changes` frame and paces the delivery window continuously
41
+ * instead of per transaction. Meaningful only with `deviceId`.
42
+ */
43
+ stagedStream?: boolean;
82
44
  }
83
45
  interface WSUnsubscribeMessage {
84
46
  type: 'unsubscribe';
85
47
  id: string;
86
48
  }
49
+ interface WSAckMessage {
50
+ type: 'ack';
51
+ id: string;
52
+ deviceId: string;
53
+ seq: string;
54
+ }
87
55
  interface WSQueryMessage {
88
56
  type: 'query';
89
57
  id: string;
90
- sql: string;
58
+ sql?: string;
91
59
  params?: Record<string, unknown> | unknown[];
60
+ name?: string;
61
+ args?: Record<string, unknown>;
62
+ readConcern?: ReadConcern;
92
63
  }
93
64
  interface WSExecuteMessage {
94
65
  type: 'execute';
95
66
  id: string;
96
- sql: string;
67
+ sql?: string;
97
68
  params?: Record<string, unknown> | unknown[];
69
+ name?: string;
70
+ args?: Record<string, unknown>;
71
+ writeConcern?: WriteConcern;
98
72
  }
99
73
  /**
100
74
  * Runs every statement in one server-side transaction and replies once with
@@ -122,10 +96,34 @@ interface WSLoadMessage {
122
96
  durability?: BulkLoadDurability;
123
97
  checkpoint?: boolean;
124
98
  }
125
- type WSServerMessage = WSSubscribedMessage | WSUnsubscribedMessage | WSChangeMessage | WSResultMessage | WSErrorMessage;
99
+ type WSServerMessage = WSSubscribedMessage | WSUnsubscribedMessage | WSChangeMessage | WSChangesMessage | WSLiveMessage | WSResultMessage | WSErrorMessage;
100
+ type WSLiveOp = {
101
+ op: 'insert';
102
+ index: number;
103
+ row: unknown;
104
+ } | {
105
+ op: 'update';
106
+ index: number;
107
+ row: unknown;
108
+ } | {
109
+ op: 'delete';
110
+ index: number;
111
+ };
112
+ interface WSLiveMessage {
113
+ type: 'live';
114
+ id: string;
115
+ ops?: WSLiveOp[];
116
+ rows?: unknown[];
117
+ revalidating?: boolean;
118
+ }
126
119
  interface WSSubscribedMessage {
127
120
  type: 'subscribed';
128
121
  id: string;
122
+ /**
123
+ * How far a device may run ahead of its acknowledged cursor before the
124
+ * server holds delivery. Present only for a device subscription.
125
+ */
126
+ maxUnacknowledgedChanges?: number;
129
127
  /**
130
128
  * The seq the subscription is live from. A client that has not yet seen any
131
129
  * change adopts this as its resume cursor, so a reconnect during an idle
@@ -144,27 +142,44 @@ interface WSSubscribedMessage {
144
142
  * database forces a resync instead of a silent replay of unrelated rows.
145
143
  */
146
144
  epoch?: string;
145
+ rows?: unknown[];
147
146
  }
148
147
  interface WSUnsubscribedMessage {
149
148
  type: 'unsubscribed';
150
149
  id: string;
151
150
  }
151
+ interface WSWireChangeEvent {
152
+ type: 'insert' | 'update' | 'delete';
153
+ table: string;
154
+ row: Record<string, unknown>;
155
+ oldRow?: Record<string, unknown>;
156
+ seq: string;
157
+ timestamp: number;
158
+ hlc?: string;
159
+ origin?: string;
160
+ rowId?: string;
161
+ txId?: string;
162
+ txEnd?: boolean;
163
+ }
152
164
  interface WSChangeMessage {
153
165
  type: 'change';
154
166
  id: string;
155
- event: {
156
- type: 'insert' | 'update' | 'delete';
157
- table: string;
158
- row: Record<string, unknown>;
159
- oldRow?: Record<string, unknown>;
160
- seq: string;
161
- timestamp: number;
162
- };
167
+ event: WSWireChangeEvent;
168
+ }
169
+ /**
170
+ * Several change events in one frame, in ascending seq order. Sent only on
171
+ * a device subscription that requested `stagedStream`; the events carry the
172
+ * same fields as a `change` frame's event.
173
+ */
174
+ interface WSChangesMessage {
175
+ type: 'changes';
176
+ id: string;
177
+ events: WSWireChangeEvent[];
163
178
  }
164
179
  interface WSResultMessage {
165
180
  type: 'result';
166
181
  id: string;
167
- data: QueryResponse | ExecuteResponse | TransactionResponse | BatchResponse | LoadResponse;
182
+ data: QueryResponse | ExecuteResponse | TransactionResponse | BatchResponse | LoadResponse | AckResponse;
168
183
  }
169
184
  interface WSErrorMessage {
170
185
  type: 'error';
@@ -174,23 +189,26 @@ interface WSErrorMessage {
174
189
  message: string;
175
190
  };
176
191
  }
177
- declare function toExecuteResponse(result: ExecuteResult): ExecuteResponse;
178
192
 
179
- declare class SirannonServer {
193
+ declare class SirannonServer<Identity = unknown> {
180
194
  private app;
181
195
  private listenSocket;
182
196
  private readonly host;
183
197
  private readonly port;
184
198
  private readonly cors;
185
- private readonly onRequestHook;
199
+ private readonly authenticateHook;
200
+ private readonly acceptSql;
201
+ private readonly operations;
202
+ private readonly registryDigest;
186
203
  private readonly resolveExecutionTarget;
187
204
  private readonly getReplicationStatus;
188
205
  private readonly getClusterStatus;
206
+ private readonly authorizeClusterStatus;
189
207
  private readonly sirannon;
190
208
  private readonly wsHandler;
191
209
  private readonly maxBodyBytes;
192
210
  private readonly maxWsBackpressureBytes;
193
- constructor(sirannon: Sirannon, options?: ServerOptions);
211
+ constructor(sirannon: Sirannon, options?: ServerOptions<Identity>);
194
212
  listen(): Promise<void>;
195
213
  close(): Promise<void>;
196
214
  get listeningPort(): number;
@@ -198,9 +216,10 @@ declare class SirannonServer {
198
216
  private registerWebSocketRoute;
199
217
  private withCors;
200
218
  private wrapDbRoute;
219
+ private wrapOperationRoute;
201
220
  private wrapDbGetRoute;
202
221
  }
203
- declare function createServer(sirannon: Sirannon, options?: ServerOptions): SirannonServer;
222
+ declare function createServer<Identity = unknown>(sirannon: Sirannon, options?: ServerOptions<Identity>): SirannonServer<Identity>;
204
223
 
205
224
  /**
206
225
  * Result of writing a frame to a WebSocket connection.
@@ -218,15 +237,18 @@ interface WSConnection {
218
237
  close(code?: number, reason?: string): void;
219
238
  }
220
239
 
221
- declare class WSHandler {
240
+ declare class WSHandler<Identity = unknown> {
222
241
  private readonly sirannon;
223
242
  private readonly maxPayloadLength;
224
243
  private readonly resolveExecutionTarget;
225
244
  private readonly connections;
226
245
  private readonly cdc;
246
+ private readonly maxUnacknowledgedChanges;
247
+ private readonly acceptSql;
248
+ private readonly operations;
227
249
  private closed;
228
- constructor(sirannon: Sirannon, options?: WSHandlerOptions);
229
- handleOpen(conn: WSConnection, databaseId: string): Promise<void>;
250
+ constructor(sirannon: Sirannon, options?: WSHandlerOptions<Identity>);
251
+ handleOpen(conn: WSConnection, databaseId: string, identity?: unknown): Promise<void>;
230
252
  /**
231
253
  * Tears down a connection whose outbound buffer overflowed. Closing lets the
232
254
  * client reject in-flight requests and reconnect; guarding on `overloaded`
@@ -234,20 +256,22 @@ declare class WSHandler {
234
256
  */
235
257
  handleOverload(conn: WSConnection): void;
236
258
  handleMessage(conn: WSConnection, data: string): void;
259
+ handleSocketDrain(conn: WSConnection): void;
237
260
  handleClose(conn: WSConnection): void;
238
261
  get connectionCount(): number;
239
262
  close(): Promise<void>;
240
263
  private operationContext;
241
- private handleSubscribe;
242
- private subscribeLive;
243
- private subscribeResuming;
264
+ private namedContext;
265
+ private liveDeps;
266
+ private subscribeDeps;
244
267
  private handleUnsubscribe;
245
268
  private resolveTarget;
246
269
  private send;
247
270
  private sendError;
248
271
  private sendSirannonError;
249
272
  private sendChange;
273
+ private sendText;
250
274
  }
251
- declare function createWSHandler(sirannon: Sirannon, options?: WSHandlerOptions): WSHandler;
275
+ declare function createWSHandler<Identity = unknown>(sirannon: Sirannon, options?: WSHandlerOptions<Identity>): WSHandler<Identity>;
252
276
 
253
- export { type BatchRequest, type BatchResponse, type ErrorResponse, type ExecuteRequest, type ExecuteResponse, type LoadRequest, type LoadResponse, type QueryRequest, type QueryResponse, SirannonServer, type TransactionRequest, type TransactionResponse, type TransactionStatement, type WSBatchMessage, type WSChangeMessage, type WSClientMessage, type WSConnection, type WSErrorMessage, type WSExecuteMessage, WSHandler, type WSLoadMessage, type WSQueryMessage, type WSResultMessage, type WSServerMessage, type WSSubscribeMessage, type WSSubscribedMessage, type WSTransactionMessage, type WSUnsubscribeMessage, type WSUnsubscribedMessage, createServer, createWSHandler, toExecuteResponse };
277
+ export { BatchResponse, ExecuteResponse, LoadResponse, QueryResponse, SirannonServer, TransactionResponse, TransactionStatement, type WSBatchMessage, type WSChangeMessage, type WSClientMessage, type WSConnection, type WSErrorMessage, type WSExecuteMessage, WSHandler, type WSLoadMessage, type WSQueryMessage, type WSResultMessage, type WSServerMessage, type WSSubscribeMessage, type WSSubscribedMessage, type WSTransactionMessage, type WSUnsubscribeMessage, type WSUnsubscribedMessage, createServer, createWSHandler };