@delali/sirannon-db 0.1.6 → 0.1.8

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 (54) hide show
  1. package/README.md +154 -19
  2. package/dist/backup-scheduler/index.d.ts +18 -3
  3. package/dist/backup-scheduler/index.mjs +2 -2
  4. package/dist/{change-tracker-CFTQ9TSn.d.ts → change-tracker-CbmaMO-N.d.ts} +12 -2
  5. package/dist/chunk-4ISB7XMA.mjs +21 -0
  6. package/dist/chunk-BNUTBHHH.mjs +22 -0
  7. package/dist/chunk-CJLYFDP5.mjs +26 -0
  8. package/dist/chunk-CW6S3WL5.mjs +222 -0
  9. package/dist/chunk-DVWQD3GF.mjs +49 -0
  10. package/dist/chunk-GEZUUIKV.mjs +268 -0
  11. package/dist/{chunk-UVMVN3OT.mjs → chunk-H5AB6NIR.mjs} +1 -1
  12. package/dist/{chunk-UTO3ZAFS.mjs → chunk-HHRMRFFR.mjs} +148 -28
  13. package/dist/chunk-TKGHYWQ6.mjs +35 -0
  14. package/dist/chunk-UXLAO6ZH.mjs +352 -0
  15. package/dist/chunk-VLTICJOD.mjs +470 -0
  16. package/dist/{chunk-O7BHI3CF.mjs → chunk-YPYVQJ4C.mjs} +15 -1
  17. package/dist/client/index.d.ts +107 -15
  18. package/dist/client/index.mjs +348 -37
  19. package/dist/core/index.d.ts +70 -13
  20. package/dist/core/index.mjs +635 -192
  21. package/dist/core/writer-worker.d.ts +2 -0
  22. package/dist/core/writer-worker.mjs +129 -0
  23. package/dist/{database-BVY1GqE7.d.ts → database-DuGp0Rtr.d.ts} +51 -19
  24. package/dist/driver/better-sqlite3.d.ts +1 -1
  25. package/dist/driver/better-sqlite3.mjs +44 -6
  26. package/dist/driver/bun.mjs +35 -6
  27. package/dist/driver/expo.mjs +2 -2
  28. package/dist/driver/node.d.ts +1 -1
  29. package/dist/driver/node.mjs +48 -5
  30. package/dist/driver/wa-sqlite.d.ts +109 -0
  31. package/dist/driver/wa-sqlite.mjs +30 -2
  32. package/dist/{errors-C00ed08Q.d.ts → errors-5Nf5ZAEC.d.ts} +19 -1
  33. package/dist/file-migrations/index.d.ts +2 -3
  34. package/dist/file-migrations/index.mjs +1 -1
  35. package/dist/replication/coordinator/etcd.mjs +2 -2
  36. package/dist/replication/index.d.ts +7 -8
  37. package/dist/replication/index.mjs +79 -78
  38. package/dist/server/index.d.ts +111 -28
  39. package/dist/server/index.mjs +1016 -384
  40. package/dist/{sirannon-Cd-lK6T0.d.ts → sirannon-4SspRvP5.d.ts} +3 -3
  41. package/dist/transport/grpc.d.ts +3 -4
  42. package/dist/transport/grpc.mjs +2 -2
  43. package/dist/{types-Lc7ywFx7.d.ts → types-BsjobKbl.d.ts} +2 -2
  44. package/dist/{types-BeozgNPr.d.ts → types-D4p4UyDK.d.ts} +1 -1
  45. package/dist/types-D_hQW1hr.d.ts +494 -0
  46. package/package.json +3 -23
  47. package/dist/chunk-3MCMONVP.mjs +0 -115
  48. package/dist/chunk-74UN4DIE.mjs +0 -14
  49. package/dist/chunk-FB2U2Q3Y.mjs +0 -21
  50. package/dist/chunk-GS7T5YMI.mjs +0 -51
  51. package/dist/chunk-PXKAKK2V.mjs +0 -124
  52. package/dist/index-CLdNrcPz.d.ts +0 -16
  53. package/dist/types-BFSsG77t.d.ts +0 -29
  54. package/dist/types-D-74JiXb.d.ts +0 -265
@@ -1,45 +1,57 @@
1
- import { W as WriteConcern, R as ReadConcern, E as ExecuteResult, d as ServerOptions, e as WSHandlerOptions } from '../types-D-74JiXb.js';
2
- import { S as Sirannon } from '../sirannon-Cd-lK6T0.js';
3
- import '../types-BFSsG77t.js';
4
- import '../database-BVY1GqE7.js';
5
- import '../types-BeozgNPr.js';
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';
6
5
 
7
- /** Body for POST /db/:id/query */
8
6
  interface QueryRequest {
9
7
  sql: string;
10
8
  params?: Record<string, unknown> | unknown[];
11
9
  readConcern?: ReadConcern;
12
10
  }
13
- /** Body for POST /db/:id/execute */
14
11
  interface ExecuteRequest {
15
12
  sql: string;
16
13
  params?: Record<string, unknown> | unknown[];
17
14
  writeConcern?: WriteConcern;
18
15
  }
19
- /** A single statement within a transaction batch. */
20
16
  interface TransactionStatement {
21
17
  sql: string;
22
18
  params?: Record<string, unknown> | unknown[];
23
19
  }
24
- /** Body for POST /db/:id/transaction */
25
20
  interface TransactionRequest {
26
21
  statements: TransactionStatement[];
27
22
  writeConcern?: WriteConcern;
28
23
  }
29
- /** Response for a successful query. */
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
30
  interface QueryResponse {
31
31
  rows: Record<string, unknown>[];
32
32
  }
33
- /** Response for a successful execute. */
34
33
  interface ExecuteResponse {
35
34
  changes: number;
36
35
  lastInsertRowId: number | string;
37
36
  }
38
- /** Response for a successful transaction. */
39
37
  interface TransactionResponse {
40
38
  results: ExecuteResponse[];
41
39
  }
42
- /** Standard error response envelope. */
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;
43
55
  interface ErrorResponse {
44
56
  error: {
45
57
  code: string;
@@ -47,13 +59,26 @@ interface ErrorResponse {
47
59
  details?: Record<string, unknown>;
48
60
  };
49
61
  }
50
- /** Inbound WS message types. */
51
- type WSClientMessage = WSSubscribeMessage | WSUnsubscribeMessage | WSQueryMessage | WSExecuteMessage;
62
+ type WSClientMessage = WSSubscribeMessage | WSUnsubscribeMessage | WSQueryMessage | WSExecuteMessage | WSTransactionMessage | WSBatchMessage | WSLoadMessage;
52
63
  interface WSSubscribeMessage {
53
64
  type: 'subscribe';
54
65
  id: string;
55
66
  table: string;
56
67
  filter?: Record<string, unknown>;
68
+ /**
69
+ * Highest `seq` the client has already processed. When present, the server
70
+ * replays every retained change with a greater seq before delivering live
71
+ * events, so a reconnecting subscriber does not miss changes. Sent as a
72
+ * decimal string to preserve values beyond `Number.MAX_SAFE_INTEGER`.
73
+ */
74
+ sinceSeq?: string;
75
+ /**
76
+ * The `epoch` the server reported when this cursor was issued. A `sinceSeq`
77
+ * only means something within the sequence space that produced it, so a
78
+ * mismatch tells the server the cursor came from another database and it must
79
+ * resync rather than replay foreign rows against it.
80
+ */
81
+ epoch?: string;
57
82
  }
58
83
  interface WSUnsubscribeMessage {
59
84
  type: 'unsubscribe';
@@ -71,11 +96,54 @@ interface WSExecuteMessage {
71
96
  sql: string;
72
97
  params?: Record<string, unknown> | unknown[];
73
98
  }
74
- /** Outbound WS message types. */
99
+ /**
100
+ * Runs every statement in one server-side transaction and replies once with
101
+ * all results. The client is never in the loop between statements, so the
102
+ * single writer lock is held only for the duration of local execution.
103
+ */
104
+ interface WSTransactionMessage {
105
+ type: 'transaction';
106
+ id: string;
107
+ statements: TransactionStatement[];
108
+ writeConcern?: WriteConcern;
109
+ }
110
+ interface WSBatchMessage {
111
+ type: 'batch';
112
+ id: string;
113
+ sql: string;
114
+ paramsBatch: (Record<string, unknown> | unknown[])[];
115
+ writeConcern?: WriteConcern;
116
+ }
117
+ interface WSLoadMessage {
118
+ type: 'load';
119
+ id: string;
120
+ sql: string;
121
+ paramsBatch: (Record<string, unknown> | unknown[])[];
122
+ durability?: BulkLoadDurability;
123
+ checkpoint?: boolean;
124
+ }
75
125
  type WSServerMessage = WSSubscribedMessage | WSUnsubscribedMessage | WSChangeMessage | WSResultMessage | WSErrorMessage;
76
126
  interface WSSubscribedMessage {
77
127
  type: 'subscribed';
78
128
  id: string;
129
+ /**
130
+ * The seq the subscription is live from. A client that has not yet seen any
131
+ * change adopts this as its resume cursor, so a reconnect during an idle
132
+ * spell still replays what it missed instead of silently skipping it.
133
+ */
134
+ seq?: string;
135
+ /**
136
+ * Set when a requested `sinceSeq` fell below the retained history, so the
137
+ * gap cannot be replayed. The subscription still starts live from now; the
138
+ * client must treat its prior state as stale and re-read.
139
+ */
140
+ resync?: boolean;
141
+ /**
142
+ * Identifies the sequence space this subscription streams from. The client
143
+ * stores it and echoes it when resuming, so a cursor carried to a different
144
+ * database forces a resync instead of a silent replay of unrelated rows.
145
+ */
146
+ epoch?: string;
79
147
  }
80
148
  interface WSUnsubscribedMessage {
81
149
  type: 'unsubscribed';
@@ -96,7 +164,7 @@ interface WSChangeMessage {
96
164
  interface WSResultMessage {
97
165
  type: 'result';
98
166
  id: string;
99
- data: QueryResponse | ExecuteResponse;
167
+ data: QueryResponse | ExecuteResponse | TransactionResponse | BatchResponse | LoadResponse;
100
168
  }
101
169
  interface WSErrorMessage {
102
170
  type: 'error';
@@ -106,7 +174,6 @@ interface WSErrorMessage {
106
174
  message: string;
107
175
  };
108
176
  }
109
- /** Convert an ExecuteResult (with possible bigint) to a JSON-safe response. */
110
177
  declare function toExecuteResponse(result: ExecuteResult): ExecuteResponse;
111
178
 
112
179
  declare class SirannonServer {
@@ -121,6 +188,8 @@ declare class SirannonServer {
121
188
  private readonly getClusterStatus;
122
189
  private readonly sirannon;
123
190
  private readonly wsHandler;
191
+ private readonly maxBodyBytes;
192
+ private readonly maxWsBackpressureBytes;
124
193
  constructor(sirannon: Sirannon, options?: ServerOptions);
125
194
  listen(): Promise<void>;
126
195
  close(): Promise<void>;
@@ -133,32 +202,46 @@ declare class SirannonServer {
133
202
  }
134
203
  declare function createServer(sirannon: Sirannon, options?: ServerOptions): SirannonServer;
135
204
 
205
+ /**
206
+ * Result of writing a frame to a WebSocket connection.
207
+ *
208
+ * - `sent`: delivered with no backpressure.
209
+ * - `buffered`: accepted into the socket's outbound buffer under the
210
+ * backpressure limit; it will drain over time and must not be resent.
211
+ * - `dropped`: rejected because it would exceed the backpressure limit, so
212
+ * the frame was not delivered. The caller must fail loud rather than treat
213
+ * the request as answered.
214
+ */
215
+ type WSSendOutcome = 'sent' | 'buffered' | 'dropped';
136
216
  interface WSConnection {
137
- send(data: string): void;
217
+ send(data: string): WSSendOutcome;
138
218
  close(code?: number, reason?: string): void;
139
219
  }
220
+
140
221
  declare class WSHandler {
141
222
  private readonly sirannon;
142
223
  private readonly maxPayloadLength;
143
224
  private readonly resolveExecutionTarget;
144
225
  private readonly connections;
145
- private readonly cdcContexts;
146
- private readonly cdcPending;
226
+ private readonly cdc;
147
227
  private closed;
148
228
  constructor(sirannon: Sirannon, options?: WSHandlerOptions);
149
229
  handleOpen(conn: WSConnection, databaseId: string): Promise<void>;
230
+ /**
231
+ * Tears down a connection whose outbound buffer overflowed. Closing lets the
232
+ * client reject in-flight requests and reconnect; guarding on `overloaded`
233
+ * keeps a burst of dropped frames from repeatedly re-closing the socket.
234
+ */
235
+ handleOverload(conn: WSConnection): void;
150
236
  handleMessage(conn: WSConnection, data: string): void;
151
237
  handleClose(conn: WSConnection): void;
152
238
  get connectionCount(): number;
153
239
  close(): Promise<void>;
154
- private handleQuery;
155
- private handleExecute;
240
+ private operationContext;
156
241
  private handleSubscribe;
242
+ private subscribeLive;
243
+ private subscribeResuming;
157
244
  private handleUnsubscribe;
158
- private ensureCDC;
159
- private createCDCContext;
160
- private maybeCleanupCDC;
161
- private isValidParams;
162
245
  private resolveTarget;
163
246
  private send;
164
247
  private sendError;
@@ -167,4 +250,4 @@ declare class WSHandler {
167
250
  }
168
251
  declare function createWSHandler(sirannon: Sirannon, options?: WSHandlerOptions): WSHandler;
169
252
 
170
- export { type ErrorResponse, type ExecuteRequest, type ExecuteResponse, type QueryRequest, type QueryResponse, SirannonServer, type TransactionRequest, type TransactionResponse, type TransactionStatement, type WSChangeMessage, type WSClientMessage, type WSConnection, type WSErrorMessage, type WSExecuteMessage, WSHandler, type WSQueryMessage, type WSResultMessage, type WSServerMessage, type WSSubscribeMessage, type WSSubscribedMessage, type WSUnsubscribeMessage, type WSUnsubscribedMessage, createServer, createWSHandler, toExecuteResponse };
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 };