@delali/sirannon-db 0.1.3 → 0.1.4
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 +276 -77
- package/dist/backup-scheduler/index.d.ts +3 -0
- package/dist/backup-scheduler/index.mjs +2 -0
- package/dist/chunk-74UN4DIE.mjs +14 -0
- package/dist/{chunk-VI4UP4RR.mjs → chunk-AX66KWBR.mjs} +74 -139
- package/dist/chunk-FB2U2Q3Y.mjs +21 -0
- package/dist/chunk-O7BHI3CF.mjs +90 -0
- package/dist/chunk-PXKAKK2V.mjs +124 -0
- package/dist/client/index.d.ts +38 -2
- package/dist/core/index.d.ts +30 -142
- package/dist/core/index.mjs +229 -469
- 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/file-migrations/index.d.ts +16 -0
- package/dist/file-migrations/index.mjs +128 -0
- package/dist/index-hXiis3N-.d.ts +16 -0
- package/dist/server/index.d.ts +110 -54
- package/dist/server/index.mjs +107 -92
- package/dist/{sirannon-BJ8Yd1Uf.d.ts → sirannon-B1oTfebD.d.ts} +30 -58
- package/dist/types-BFSsG77t.d.ts +29 -0
- package/dist/types-DRkJlqex.d.ts +38 -0
- package/dist/{types-DArCObcu.d.ts → types-DtDutWRU.d.ts} +4 -1
- package/dist/vfs-INWQ5DTE.mjs +2 -0
- package/package.json +58 -7
- package/dist/protocol-BX1H-_Mz.d.ts +0 -104
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { S as SQLiteDriver } from './types-BFSsG77t.js';
|
|
2
|
+
import { Q as QueryHookContext, C as ConnectionHookContext, B as BeforeSubscribeHook, H as HookConfig, M as MetricsConfig, a as QueryMetrics, b as ConnectionMetrics, c as CDCMetrics, D as DatabaseOptions, P as Params, E as ExecuteResult, d as SubscriptionBuilder, e as BackupScheduleOptions, f as BeforeQueryHook, A as AfterQueryHook, g as SirannonOptions, h as BeforeConnectHook, i as DatabaseOpenHook, j as DatabaseCloseHook } from './types-DtDutWRU.js';
|
|
3
|
+
import { T as Transaction, M as Migration, a as MigrationResult, R as RollbackResult } from './types-DRkJlqex.js';
|
|
3
4
|
|
|
4
5
|
type HookEvent = 'beforeQuery' | 'afterQuery' | 'beforeConnect' | 'databaseOpen' | 'databaseClose' | 'beforeSubscribe';
|
|
5
6
|
type SubscribeHookContext = Parameters<BeforeSubscribeHook>[0];
|
|
@@ -32,47 +33,12 @@ declare class HookRegistry {
|
|
|
32
33
|
declare class MetricsCollector {
|
|
33
34
|
private config;
|
|
34
35
|
constructor(config?: MetricsConfig);
|
|
35
|
-
trackQuery<T>(fn: () => T
|
|
36
|
+
trackQuery<T>(fn: () => Promise<T>, context: Omit<QueryMetrics, 'durationMs' | 'error'>): Promise<T>;
|
|
36
37
|
trackConnection(metrics: ConnectionMetrics): void;
|
|
37
38
|
trackCDCEvent(metrics: CDCMetrics): void;
|
|
38
39
|
get active(): boolean;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
type SqliteDb = InstanceType<typeof Database$1>;
|
|
42
|
-
declare class Transaction {
|
|
43
|
-
private readonly db;
|
|
44
|
-
private _lastInsertRowId;
|
|
45
|
-
constructor(db: SqliteDb);
|
|
46
|
-
query<T = Record<string, unknown>>(sql: string, params?: Params): T[];
|
|
47
|
-
execute(sql: string, params?: Params): ExecuteResult;
|
|
48
|
-
executeBatch(sql: string, paramsBatch: Params[]): ExecuteResult[];
|
|
49
|
-
get lastInsertRowId(): number | bigint;
|
|
50
|
-
static run<T>(db: SqliteDb, fn: (tx: Transaction) => T): T;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
interface AppliedMigration {
|
|
54
|
-
version: number;
|
|
55
|
-
name: string;
|
|
56
|
-
applied_at: number;
|
|
57
|
-
}
|
|
58
|
-
interface Migration {
|
|
59
|
-
version: number;
|
|
60
|
-
name: string;
|
|
61
|
-
up: string | ((tx: Transaction) => void);
|
|
62
|
-
down?: string | ((tx: Transaction) => void);
|
|
63
|
-
}
|
|
64
|
-
interface AppliedMigrationEntry {
|
|
65
|
-
version: number;
|
|
66
|
-
name: string;
|
|
67
|
-
}
|
|
68
|
-
interface MigrationResult {
|
|
69
|
-
applied: AppliedMigrationEntry[];
|
|
70
|
-
skipped: number;
|
|
71
|
-
}
|
|
72
|
-
interface RollbackResult {
|
|
73
|
-
rolledBack: AppliedMigrationEntry[];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
42
|
interface DatabaseInternals {
|
|
77
43
|
parentHooks?: HookRegistry;
|
|
78
44
|
metrics?: MetricsCollector;
|
|
@@ -82,6 +48,7 @@ declare class Database {
|
|
|
82
48
|
readonly path: string;
|
|
83
49
|
readonly readOnly: boolean;
|
|
84
50
|
private readonly pool;
|
|
51
|
+
private readonly driver;
|
|
85
52
|
private readonly closeListeners;
|
|
86
53
|
private _closed;
|
|
87
54
|
private changeTracker;
|
|
@@ -95,24 +62,25 @@ declare class Database {
|
|
|
95
62
|
private readonly backupManager;
|
|
96
63
|
private readonly backupScheduler;
|
|
97
64
|
private readonly scheduledBackupCancellers;
|
|
98
|
-
constructor(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
65
|
+
private constructor();
|
|
66
|
+
static create(id: string, path: string, driver: SQLiteDriver, options?: DatabaseOptions, internals?: DatabaseInternals): Promise<Database>;
|
|
67
|
+
query<T = Record<string, unknown>>(sql: string, params?: Params): Promise<T[]>;
|
|
68
|
+
queryOne<T = Record<string, unknown>>(sql: string, params?: Params): Promise<T | undefined>;
|
|
69
|
+
execute(sql: string, params?: Params): Promise<ExecuteResult>;
|
|
70
|
+
executeBatch(sql: string, paramsBatch: Params[]): Promise<ExecuteResult[]>;
|
|
71
|
+
transaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T>;
|
|
72
|
+
watch(table: string): Promise<void>;
|
|
73
|
+
unwatch(table: string): Promise<void>;
|
|
106
74
|
on(table: string): SubscriptionBuilder;
|
|
107
|
-
migrate(
|
|
108
|
-
rollback(
|
|
109
|
-
backup(destPath: string): void
|
|
75
|
+
migrate(migrations: Migration[]): Promise<MigrationResult>;
|
|
76
|
+
rollback(migrations: Migration[], version?: number): Promise<RollbackResult>;
|
|
77
|
+
backup(destPath: string): Promise<void>;
|
|
110
78
|
scheduleBackup(options: BackupScheduleOptions): void;
|
|
111
|
-
loadExtension(extensionPath: string): void
|
|
79
|
+
loadExtension(extensionPath: string): Promise<void>;
|
|
112
80
|
onBeforeQuery(hook: BeforeQueryHook): void;
|
|
113
81
|
onAfterQuery(hook: AfterQueryHook): void;
|
|
114
|
-
addCloseListener(fn: () => void): void;
|
|
115
|
-
close(): void
|
|
82
|
+
addCloseListener(fn: () => void | Promise<void>): void;
|
|
83
|
+
close(): Promise<void>;
|
|
116
84
|
get closed(): boolean;
|
|
117
85
|
get readerCount(): number;
|
|
118
86
|
private ensureOpen;
|
|
@@ -124,19 +92,23 @@ declare class Database {
|
|
|
124
92
|
}
|
|
125
93
|
|
|
126
94
|
declare class Sirannon {
|
|
127
|
-
readonly options
|
|
95
|
+
readonly options: SirannonOptions;
|
|
128
96
|
private readonly dbs;
|
|
97
|
+
private readonly opening;
|
|
129
98
|
private _shutdown;
|
|
99
|
+
private readonly _driver;
|
|
130
100
|
private readonly hookRegistry;
|
|
131
101
|
private readonly metricsCollector;
|
|
132
102
|
private readonly lifecycleManager;
|
|
133
|
-
constructor(options
|
|
134
|
-
|
|
135
|
-
|
|
103
|
+
constructor(options: SirannonOptions);
|
|
104
|
+
get driver(): SQLiteDriver;
|
|
105
|
+
open(id: string, path: string, options?: DatabaseOptions): Promise<Database>;
|
|
106
|
+
close(id: string): Promise<void>;
|
|
136
107
|
get(id: string): Database | undefined;
|
|
108
|
+
resolve(id: string): Promise<Database | undefined>;
|
|
137
109
|
has(id: string): boolean;
|
|
138
110
|
databases(): Map<string, Database>;
|
|
139
|
-
shutdown(): void
|
|
111
|
+
shutdown(): Promise<void>;
|
|
140
112
|
onBeforeQuery(hook: BeforeQueryHook): void;
|
|
141
113
|
onAfterQuery(hook: AfterQueryHook): void;
|
|
142
114
|
onBeforeConnect(hook: BeforeConnectHook): void;
|
|
@@ -145,4 +117,4 @@ declare class Sirannon {
|
|
|
145
117
|
private ensureRunning;
|
|
146
118
|
}
|
|
147
119
|
|
|
148
|
-
export {
|
|
120
|
+
export { Database as D, type HookDispose as H, MetricsCollector as M, Sirannon as S, type HookEvent as a, type HookEventContextMap as b, type HookHandler as c, HookRegistry as d, type SubscribeHookContext as e };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
interface RunResult {
|
|
2
|
+
changes: number;
|
|
3
|
+
lastInsertRowId: number | bigint;
|
|
4
|
+
}
|
|
5
|
+
interface SQLiteStatement {
|
|
6
|
+
all<T = unknown>(...params: unknown[]): Promise<T[]>;
|
|
7
|
+
get<T = unknown>(...params: unknown[]): Promise<T | undefined>;
|
|
8
|
+
run(...params: unknown[]): Promise<RunResult>;
|
|
9
|
+
}
|
|
10
|
+
interface SQLiteConnection {
|
|
11
|
+
exec(sql: string): Promise<void>;
|
|
12
|
+
prepare(sql: string): Promise<SQLiteStatement>;
|
|
13
|
+
transaction<T>(fn: (conn: SQLiteConnection) => Promise<T>): Promise<T>;
|
|
14
|
+
close(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
interface OpenOptions {
|
|
17
|
+
readonly?: boolean;
|
|
18
|
+
walMode?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface DriverCapabilities {
|
|
21
|
+
multipleConnections: boolean;
|
|
22
|
+
extensions: boolean;
|
|
23
|
+
}
|
|
24
|
+
interface SQLiteDriver {
|
|
25
|
+
readonly capabilities: DriverCapabilities;
|
|
26
|
+
open(path: string, options?: OpenOptions): Promise<SQLiteConnection>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type { DriverCapabilities as D, OpenOptions as O, RunResult as R, SQLiteDriver as S, SQLiteConnection as a, SQLiteStatement as b };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { a as SQLiteConnection } from './types-BFSsG77t.js';
|
|
2
|
+
import { P as Params, E as ExecuteResult } from './types-DtDutWRU.js';
|
|
3
|
+
|
|
4
|
+
declare class Transaction {
|
|
5
|
+
private readonly conn;
|
|
6
|
+
private _lastInsertRowId;
|
|
7
|
+
constructor(conn: SQLiteConnection);
|
|
8
|
+
query<T = Record<string, unknown>>(sql: string, params?: Params): Promise<T[]>;
|
|
9
|
+
execute(sql: string, params?: Params): Promise<ExecuteResult>;
|
|
10
|
+
executeBatch(sql: string, paramsBatch: Params[]): Promise<ExecuteResult[]>;
|
|
11
|
+
get lastInsertRowId(): number | bigint;
|
|
12
|
+
static run<T>(conn: SQLiteConnection, fn: (tx: Transaction) => Promise<T>): Promise<T>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface AppliedMigration {
|
|
16
|
+
version: number;
|
|
17
|
+
name: string;
|
|
18
|
+
applied_at: number;
|
|
19
|
+
}
|
|
20
|
+
interface Migration {
|
|
21
|
+
version: number;
|
|
22
|
+
name: string;
|
|
23
|
+
up: string | ((tx: Transaction) => void | Promise<void>);
|
|
24
|
+
down?: string | ((tx: Transaction) => void | Promise<void>);
|
|
25
|
+
}
|
|
26
|
+
interface AppliedMigrationEntry {
|
|
27
|
+
version: number;
|
|
28
|
+
name: string;
|
|
29
|
+
}
|
|
30
|
+
interface MigrationResult {
|
|
31
|
+
applied: AppliedMigrationEntry[];
|
|
32
|
+
skipped: number;
|
|
33
|
+
}
|
|
34
|
+
interface RollbackResult {
|
|
35
|
+
rolledBack: AppliedMigrationEntry[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { type AppliedMigration as A, type Migration as M, type RollbackResult as R, Transaction as T, type MigrationResult as a, type AppliedMigrationEntry as b };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { S as SQLiteDriver } from './types-BFSsG77t.js';
|
|
2
|
+
|
|
1
3
|
/** Query parameter types: named (object) or positional (array). */
|
|
2
4
|
type Params = Record<string, unknown> | unknown[];
|
|
3
5
|
/** Result returned by mutation statements (INSERT, UPDATE, DELETE). */
|
|
@@ -113,6 +115,7 @@ interface DatabaseOptions {
|
|
|
113
115
|
}
|
|
114
116
|
/** Top-level options for the Sirannon database registry. */
|
|
115
117
|
interface SirannonOptions {
|
|
118
|
+
driver: SQLiteDriver;
|
|
116
119
|
hooks?: HookConfig;
|
|
117
120
|
metrics?: MetricsConfig;
|
|
118
121
|
lifecycle?: LifecycleConfig;
|
|
@@ -183,4 +186,4 @@ interface ClientOptions {
|
|
|
183
186
|
reconnectInterval?: number;
|
|
184
187
|
}
|
|
185
188
|
|
|
186
|
-
export type { AfterQueryHook as A,
|
|
189
|
+
export type { AfterQueryHook as A, BeforeSubscribeHook as B, ConnectionHookContext as C, DatabaseOptions as D, ExecuteResult as E, HookConfig as H, LifecycleConfig as L, MetricsConfig as M, OnRequestHook as O, Params as P, QueryHookContext as Q, RequestContext as R, ServerOptions as S, WSHandlerOptions as W, QueryMetrics as a, ConnectionMetrics as b, CDCMetrics as c, SubscriptionBuilder as d, BackupScheduleOptions as e, BeforeQueryHook as f, SirannonOptions as g, BeforeConnectHook as h, DatabaseOpenHook as i, DatabaseCloseHook as j, ChangeEvent as k, ChangeOperation as l, ClientOptions as m, CorsOptions as n, RequestDenial as o, Subscription as p };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delali/sirannon-db",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"description": "A production-grade library that turns SQLite databases into a networked data layer with real-time subscriptions.",
|
|
6
6
|
"author": "Delali (https://sondelali.com)",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -22,13 +22,42 @@
|
|
|
22
22
|
"subscriptions",
|
|
23
23
|
"websocket",
|
|
24
24
|
"embedded",
|
|
25
|
-
"better-sqlite3"
|
|
25
|
+
"better-sqlite3",
|
|
26
|
+
"wa-sqlite",
|
|
27
|
+
"expo-sqlite",
|
|
28
|
+
"pluggable"
|
|
26
29
|
],
|
|
27
30
|
"exports": {
|
|
28
31
|
".": {
|
|
29
32
|
"types": "./dist/core/index.d.ts",
|
|
30
33
|
"import": "./dist/core/index.mjs"
|
|
31
34
|
},
|
|
35
|
+
"./driver/better-sqlite3": {
|
|
36
|
+
"types": "./dist/driver/better-sqlite3.d.ts",
|
|
37
|
+
"import": "./dist/driver/better-sqlite3.mjs"
|
|
38
|
+
},
|
|
39
|
+
"./driver/node": {
|
|
40
|
+
"types": "./dist/driver/node.d.ts",
|
|
41
|
+
"import": "./dist/driver/node.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./driver/bun": {
|
|
44
|
+
"import": "./dist/driver/bun.mjs"
|
|
45
|
+
},
|
|
46
|
+
"./driver/wa-sqlite": {
|
|
47
|
+
"types": "./dist/driver/wa-sqlite.d.ts",
|
|
48
|
+
"import": "./dist/driver/wa-sqlite.mjs"
|
|
49
|
+
},
|
|
50
|
+
"./driver/expo": {
|
|
51
|
+
"import": "./dist/driver/expo.mjs"
|
|
52
|
+
},
|
|
53
|
+
"./file-migrations": {
|
|
54
|
+
"types": "./dist/file-migrations/index.d.ts",
|
|
55
|
+
"import": "./dist/file-migrations/index.mjs"
|
|
56
|
+
},
|
|
57
|
+
"./backup-scheduler": {
|
|
58
|
+
"types": "./dist/backup-scheduler/index.d.ts",
|
|
59
|
+
"import": "./dist/backup-scheduler/index.mjs"
|
|
60
|
+
},
|
|
32
61
|
"./server": {
|
|
33
62
|
"types": "./dist/server/index.d.ts",
|
|
34
63
|
"import": "./dist/server/index.mjs"
|
|
@@ -46,26 +75,48 @@
|
|
|
46
75
|
"engines": {
|
|
47
76
|
"node": ">=22"
|
|
48
77
|
},
|
|
49
|
-
"
|
|
50
|
-
"better-sqlite3": "12.
|
|
51
|
-
"
|
|
52
|
-
"
|
|
78
|
+
"peerDependencies": {
|
|
79
|
+
"better-sqlite3": ">=12.0.0",
|
|
80
|
+
"wa-sqlite": ">=1.0.0",
|
|
81
|
+
"expo-sqlite": ">=14.0.0",
|
|
82
|
+
"croner": ">=10.0.0",
|
|
83
|
+
"uWebSockets.js": ">=20.0.0"
|
|
84
|
+
},
|
|
85
|
+
"peerDependenciesMeta": {
|
|
86
|
+
"better-sqlite3": {
|
|
87
|
+
"optional": true
|
|
88
|
+
},
|
|
89
|
+
"wa-sqlite": {
|
|
90
|
+
"optional": true
|
|
91
|
+
},
|
|
92
|
+
"expo-sqlite": {
|
|
93
|
+
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"croner": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"uWebSockets.js": {
|
|
99
|
+
"optional": true
|
|
100
|
+
}
|
|
53
101
|
},
|
|
54
102
|
"devDependencies": {
|
|
55
103
|
"@types/better-sqlite3": "7.6.13",
|
|
56
104
|
"@types/node": "25.3.3",
|
|
57
105
|
"@types/pg": "8.11.10",
|
|
58
106
|
"@vitest/coverage-v8": "4.0.18",
|
|
107
|
+
"better-sqlite3": "12.6.2",
|
|
108
|
+
"croner": "10.0.1",
|
|
59
109
|
"pg": "8.19.0",
|
|
60
110
|
"simple-statistics": "7.8.7",
|
|
61
111
|
"tinybench": "6.0.0",
|
|
62
112
|
"tsup": "8.5.1",
|
|
63
113
|
"tsx": "4.21.0",
|
|
64
114
|
"typescript": "5.9.3",
|
|
115
|
+
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.58.0",
|
|
65
116
|
"vitest": "4.0.18"
|
|
66
117
|
},
|
|
67
118
|
"scripts": {
|
|
68
|
-
"build": "tsup",
|
|
119
|
+
"build": "rm -rf dist && tsup",
|
|
69
120
|
"test": "vitest run",
|
|
70
121
|
"test:coverage": "vitest run --coverage",
|
|
71
122
|
"typecheck": "tsc --noEmit",
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { E as ExecuteResult } from './types-DArCObcu.js';
|
|
2
|
-
|
|
3
|
-
/** Body for POST /db/:id/query */
|
|
4
|
-
interface QueryRequest {
|
|
5
|
-
sql: string;
|
|
6
|
-
params?: Record<string, unknown> | unknown[];
|
|
7
|
-
}
|
|
8
|
-
/** Body for POST /db/:id/execute */
|
|
9
|
-
interface ExecuteRequest {
|
|
10
|
-
sql: string;
|
|
11
|
-
params?: Record<string, unknown> | unknown[];
|
|
12
|
-
}
|
|
13
|
-
/** A single statement within a transaction batch. */
|
|
14
|
-
interface TransactionStatement {
|
|
15
|
-
sql: string;
|
|
16
|
-
params?: Record<string, unknown> | unknown[];
|
|
17
|
-
}
|
|
18
|
-
/** Body for POST /db/:id/transaction */
|
|
19
|
-
interface TransactionRequest {
|
|
20
|
-
statements: TransactionStatement[];
|
|
21
|
-
}
|
|
22
|
-
/** Response for a successful query. */
|
|
23
|
-
interface QueryResponse {
|
|
24
|
-
rows: Record<string, unknown>[];
|
|
25
|
-
}
|
|
26
|
-
/** Response for a successful execute. */
|
|
27
|
-
interface ExecuteResponse {
|
|
28
|
-
changes: number;
|
|
29
|
-
lastInsertRowId: number | string;
|
|
30
|
-
}
|
|
31
|
-
/** Response for a successful transaction. */
|
|
32
|
-
interface TransactionResponse {
|
|
33
|
-
results: ExecuteResponse[];
|
|
34
|
-
}
|
|
35
|
-
/** Standard error response envelope. */
|
|
36
|
-
interface ErrorResponse {
|
|
37
|
-
error: {
|
|
38
|
-
code: string;
|
|
39
|
-
message: string;
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
/** Inbound WS message types. */
|
|
43
|
-
type WSClientMessage = WSSubscribeMessage | WSUnsubscribeMessage | WSQueryMessage | WSExecuteMessage;
|
|
44
|
-
interface WSSubscribeMessage {
|
|
45
|
-
type: 'subscribe';
|
|
46
|
-
id: string;
|
|
47
|
-
table: string;
|
|
48
|
-
filter?: Record<string, unknown>;
|
|
49
|
-
}
|
|
50
|
-
interface WSUnsubscribeMessage {
|
|
51
|
-
type: 'unsubscribe';
|
|
52
|
-
id: string;
|
|
53
|
-
}
|
|
54
|
-
interface WSQueryMessage {
|
|
55
|
-
type: 'query';
|
|
56
|
-
id: string;
|
|
57
|
-
sql: string;
|
|
58
|
-
params?: Record<string, unknown> | unknown[];
|
|
59
|
-
}
|
|
60
|
-
interface WSExecuteMessage {
|
|
61
|
-
type: 'execute';
|
|
62
|
-
id: string;
|
|
63
|
-
sql: string;
|
|
64
|
-
params?: Record<string, unknown> | unknown[];
|
|
65
|
-
}
|
|
66
|
-
/** Outbound WS message types. */
|
|
67
|
-
type WSServerMessage = WSSubscribedMessage | WSUnsubscribedMessage | WSChangeMessage | WSResultMessage | WSErrorMessage;
|
|
68
|
-
interface WSSubscribedMessage {
|
|
69
|
-
type: 'subscribed';
|
|
70
|
-
id: string;
|
|
71
|
-
}
|
|
72
|
-
interface WSUnsubscribedMessage {
|
|
73
|
-
type: 'unsubscribed';
|
|
74
|
-
id: string;
|
|
75
|
-
}
|
|
76
|
-
interface WSChangeMessage {
|
|
77
|
-
type: 'change';
|
|
78
|
-
id: string;
|
|
79
|
-
event: {
|
|
80
|
-
type: 'insert' | 'update' | 'delete';
|
|
81
|
-
table: string;
|
|
82
|
-
row: Record<string, unknown>;
|
|
83
|
-
oldRow?: Record<string, unknown>;
|
|
84
|
-
seq: string;
|
|
85
|
-
timestamp: number;
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
interface WSResultMessage {
|
|
89
|
-
type: 'result';
|
|
90
|
-
id: string;
|
|
91
|
-
data: QueryResponse | ExecuteResponse;
|
|
92
|
-
}
|
|
93
|
-
interface WSErrorMessage {
|
|
94
|
-
type: 'error';
|
|
95
|
-
id: string;
|
|
96
|
-
error: {
|
|
97
|
-
code: string;
|
|
98
|
-
message: string;
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
/** Convert an ExecuteResult (with possible bigint) to a JSON-safe response. */
|
|
102
|
-
declare function toExecuteResponse(result: ExecuteResult): ExecuteResponse;
|
|
103
|
-
|
|
104
|
-
export { type ErrorResponse as E, type QueryRequest as Q, type TransactionRequest as T, type WSChangeMessage as W, type ExecuteRequest as a, type ExecuteResponse as b, type QueryResponse as c, type TransactionResponse as d, type TransactionStatement as e, type WSClientMessage as f, type WSErrorMessage as g, type WSExecuteMessage as h, type WSQueryMessage as i, type WSResultMessage as j, type WSServerMessage as k, type WSSubscribeMessage as l, type WSSubscribedMessage as m, type WSUnsubscribeMessage as n, type WSUnsubscribedMessage as o, toExecuteResponse as t };
|