@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/server/index.d.ts
CHANGED
|
@@ -1,7 +1,113 @@
|
|
|
1
|
-
|
|
2
|
-
import { S as Sirannon } from '../sirannon-
|
|
3
|
-
import
|
|
4
|
-
import '
|
|
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 };
|