@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
@@ -1,7 +1,113 @@
1
- export { E as ErrorResponse, a as ExecuteRequest, b as ExecuteResponse, Q as QueryRequest, c as QueryResponse, T as TransactionRequest, d as TransactionResponse, e as TransactionStatement, W as WSChangeMessage, f as WSClientMessage, g as WSErrorMessage, h as WSExecuteMessage, i as WSQueryMessage, j as WSResultMessage, k as WSServerMessage, l as WSSubscribeMessage, m as WSSubscribedMessage, n as WSUnsubscribeMessage, o as WSUnsubscribedMessage, t as toExecuteResponse } from '../protocol-BX1H-_Mz.js';
2
- import { S as Sirannon } from '../sirannon-BJ8Yd1Uf.js';
3
- import { S as ServerOptions, W as WSHandlerOptions } from '../types-DArCObcu.js';
4
- import 'better-sqlite3';
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';
6
+
7
+ /** Body for POST /db/:id/query */
8
+ interface QueryRequest {
9
+ sql: string;
10
+ params?: Record<string, unknown> | unknown[];
11
+ readConcern?: ReadConcern;
12
+ }
13
+ /** Body for POST /db/:id/execute */
14
+ interface ExecuteRequest {
15
+ sql: string;
16
+ params?: Record<string, unknown> | unknown[];
17
+ writeConcern?: WriteConcern;
18
+ }
19
+ /** A single statement within a transaction batch. */
20
+ interface TransactionStatement {
21
+ sql: string;
22
+ params?: Record<string, unknown> | unknown[];
23
+ }
24
+ /** Body for POST /db/:id/transaction */
25
+ interface TransactionRequest {
26
+ statements: TransactionStatement[];
27
+ writeConcern?: WriteConcern;
28
+ }
29
+ /** Response for a successful query. */
30
+ interface QueryResponse {
31
+ rows: Record<string, unknown>[];
32
+ }
33
+ /** Response for a successful execute. */
34
+ interface ExecuteResponse {
35
+ changes: number;
36
+ lastInsertRowId: number | string;
37
+ }
38
+ /** Response for a successful transaction. */
39
+ interface TransactionResponse {
40
+ results: ExecuteResponse[];
41
+ }
42
+ /** Standard error response envelope. */
43
+ interface ErrorResponse {
44
+ error: {
45
+ code: string;
46
+ message: string;
47
+ details?: Record<string, unknown>;
48
+ };
49
+ }
50
+ /** Inbound WS message types. */
51
+ type WSClientMessage = WSSubscribeMessage | WSUnsubscribeMessage | WSQueryMessage | WSExecuteMessage;
52
+ interface WSSubscribeMessage {
53
+ type: 'subscribe';
54
+ id: string;
55
+ table: string;
56
+ filter?: Record<string, unknown>;
57
+ }
58
+ interface WSUnsubscribeMessage {
59
+ type: 'unsubscribe';
60
+ id: string;
61
+ }
62
+ interface WSQueryMessage {
63
+ type: 'query';
64
+ id: string;
65
+ sql: string;
66
+ params?: Record<string, unknown> | unknown[];
67
+ }
68
+ interface WSExecuteMessage {
69
+ type: 'execute';
70
+ id: string;
71
+ sql: string;
72
+ params?: Record<string, unknown> | unknown[];
73
+ }
74
+ /** Outbound WS message types. */
75
+ type WSServerMessage = WSSubscribedMessage | WSUnsubscribedMessage | WSChangeMessage | WSResultMessage | WSErrorMessage;
76
+ interface WSSubscribedMessage {
77
+ type: 'subscribed';
78
+ id: string;
79
+ }
80
+ interface WSUnsubscribedMessage {
81
+ type: 'unsubscribed';
82
+ id: string;
83
+ }
84
+ interface WSChangeMessage {
85
+ type: 'change';
86
+ id: string;
87
+ event: {
88
+ type: 'insert' | 'update' | 'delete';
89
+ table: string;
90
+ row: Record<string, unknown>;
91
+ oldRow?: Record<string, unknown>;
92
+ seq: string;
93
+ timestamp: number;
94
+ };
95
+ }
96
+ interface WSResultMessage {
97
+ type: 'result';
98
+ id: string;
99
+ data: QueryResponse | ExecuteResponse;
100
+ }
101
+ interface WSErrorMessage {
102
+ type: 'error';
103
+ id: string;
104
+ error: {
105
+ code: string;
106
+ message: string;
107
+ };
108
+ }
109
+ /** Convert an ExecuteResult (with possible bigint) to a JSON-safe response. */
110
+ declare function toExecuteResponse(result: ExecuteResult): ExecuteResponse;
5
111
 
6
112
  declare class SirannonServer {
7
113
  private app;
@@ -10,6 +116,9 @@ declare class SirannonServer {
10
116
  private readonly port;
11
117
  private readonly cors;
12
118
  private readonly onRequestHook;
119
+ private readonly resolveExecutionTarget;
120
+ private readonly getReplicationStatus;
121
+ private readonly getClusterStatus;
13
122
  private readonly sirannon;
14
123
  private readonly wsHandler;
15
124
  constructor(sirannon: Sirannon, options?: ServerOptions);
@@ -20,84 +129,42 @@ declare class SirannonServer {
20
129
  private registerWebSocketRoute;
21
130
  private withCors;
22
131
  private wrapDbRoute;
132
+ private wrapDbGetRoute;
23
133
  }
24
134
  declare function createServer(sirannon: Sirannon, options?: ServerOptions): SirannonServer;
25
135
 
26
- /** Transport-agnostic WebSocket connection. */
27
136
  interface WSConnection {
28
137
  send(data: string): void;
29
138
  close(code?: number, reason?: string): void;
30
139
  }
31
- /**
32
- * Manages WebSocket connections, routes messages to databases, and integrates
33
- * with CDC for real-time change subscriptions.
34
- *
35
- * Designed to be transport-agnostic: any WebSocket implementation can drive
36
- * this handler by calling handleOpen/handleMessage/handleClose with a
37
- * WSConnection adapter.
38
- */
39
140
  declare class WSHandler {
40
141
  private readonly sirannon;
41
142
  private readonly maxPayloadLength;
143
+ private readonly resolveExecutionTarget;
42
144
  private readonly connections;
43
145
  private readonly cdcContexts;
146
+ private readonly cdcPending;
44
147
  private closed;
45
148
  constructor(sirannon: Sirannon, options?: WSHandlerOptions);
46
- /**
47
- * Register a new WebSocket connection for the given database.
48
- *
49
- * Sends an error and closes the connection if the database does not exist,
50
- * is closed, or the handler itself has been shut down.
51
- */
52
- handleOpen(conn: WSConnection, databaseId: string): void;
53
- /**
54
- * Process an incoming WebSocket message.
55
- *
56
- * Validates the JSON payload, extracts the message type and correlation ID,
57
- * and routes to the appropriate handler.
58
- */
149
+ handleOpen(conn: WSConnection, databaseId: string): Promise<void>;
59
150
  handleMessage(conn: WSConnection, data: string): void;
60
- /**
61
- * Clean up after a WebSocket connection closes.
62
- *
63
- * Unsubscribes all active CDC subscriptions for this connection and
64
- * releases the per-database CDC context if no subscribers remain.
65
- */
66
151
  handleClose(conn: WSConnection): void;
67
- /** Number of active WebSocket connections. */
68
152
  get connectionCount(): number;
69
- /**
70
- * Shut down the handler.
71
- *
72
- * Unsubscribes all CDC subscriptions, closes all WebSocket connections
73
- * with code 1001 (Going Away), and releases all CDC resources.
74
- */
75
- close(): void;
153
+ close(): Promise<void>;
76
154
  private handleQuery;
77
155
  private handleExecute;
78
156
  private handleSubscribe;
79
157
  private handleUnsubscribe;
80
- /**
81
- * Get or create a CDC context for the given database.
82
- *
83
- * Opens a separate better-sqlite3 connection for trigger installation and
84
- * change polling. WAL mode and a 5-second busy timeout are set so that
85
- * the CDC connection coexists with the Database class's connection pool.
86
- */
87
158
  private ensureCDC;
88
- /**
89
- * Release CDC resources for a database if no subscribers remain.
90
- *
91
- * Stops the polling loop and closes the dedicated CDC connection.
92
- */
159
+ private createCDCContext;
93
160
  private maybeCleanupCDC;
94
161
  private isValidParams;
162
+ private resolveTarget;
95
163
  private send;
96
164
  private sendError;
97
165
  private sendSirannonError;
98
166
  private sendChange;
99
167
  }
100
- /** Create a transport-agnostic WebSocket handler bound to a Sirannon registry. */
101
168
  declare function createWSHandler(sirannon: Sirannon, options?: WSHandlerOptions): WSHandler;
102
169
 
103
- export { SirannonServer, type WSConnection, WSHandler, createServer, createWSHandler };
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 };