@delali/sirannon-db 0.2.0 → 0.2.1
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/dist/backup-scheduler/index.d.ts +15 -1
- package/dist/backup-scheduler/index.mjs +2 -2
- package/dist/baseline-D93hcIEE.d.ts +17 -0
- package/dist/{change-tracker-DKRVUC3l.d.ts → change-tracker-DDmXB754.d.ts} +56 -8
- package/dist/{chunk-5NOIGN5Y.mjs → chunk-2QLXDHAP.mjs} +1 -1
- package/dist/{chunk-LNY2VVHE.mjs → chunk-7C36BCSN.mjs} +1 -1
- package/dist/{chunk-NVQS53NT.mjs → chunk-7FQRQH5Z.mjs} +53 -64
- package/dist/{chunk-D7LAYTKN.mjs → chunk-7R4ER4FB.mjs} +1 -1
- package/dist/{chunk-FHWTZFI4.mjs → chunk-BQFQ65OL.mjs} +1 -1
- package/dist/{chunk-O7SLN3GI.mjs → chunk-BTTFW4Z4.mjs} +1 -1
- package/dist/{chunk-H6PIVVDN.mjs → chunk-CCZK6LCB.mjs} +38 -25
- package/dist/{chunk-JZGINXTN.mjs → chunk-HCCGEIZ2.mjs} +2 -2
- package/dist/{chunk-67M7KAH6.mjs → chunk-IWGIYDMZ.mjs} +1 -1
- package/dist/{chunk-LFZ37BSX.mjs → chunk-OUSWVNWT.mjs} +1 -1
- package/dist/{chunk-HR5CWTLC.mjs → chunk-P2VJYRVY.mjs} +60 -7
- package/dist/{chunk-UC3SCMIN.mjs → chunk-PBRXXISQ.mjs} +3 -0
- package/dist/{chunk-JU64Y7HM.mjs → chunk-SBL6GN43.mjs} +1 -1
- package/dist/{chunk-EBJXPQQO.mjs → chunk-UPKKSUPA.mjs} +2 -2
- package/dist/{chunk-TJF5GZSV.mjs → chunk-VOSJBZ6Q.mjs} +1 -1
- package/dist/{chunk-PIKHN33N.mjs → chunk-VOYGMAU7.mjs} +9 -1
- package/dist/{chunk-H237TXZW.mjs → chunk-WJ67DTD6.mjs} +48 -6
- package/dist/{chunk-OQVZBEBY.mjs → chunk-XF2HH5E6.mjs} +4 -61
- package/dist/client/index.d.ts +211 -12
- package/dist/client/index.mjs +155 -67
- package/dist/client/topology.d.ts +55 -7
- package/dist/client/topology.mjs +20 -1
- package/dist/{client-base-CLWmH5Ln.d.ts → client-base-CmZO0v3m.d.ts} +133 -24
- package/dist/codegen/cli.mjs +3 -3
- package/dist/codegen/index.d.ts +92 -2
- package/dist/codegen/index.mjs +3 -3
- package/dist/core/index.d.ts +177 -15
- package/dist/core/index.mjs +2481 -2226
- package/dist/core/writer-worker.mjs +3 -3
- package/dist/database-B5Qv1-cU.d.ts +380 -0
- package/dist/driver/better-sqlite3.d.ts +18 -1
- package/dist/driver/better-sqlite3.mjs +5 -5
- package/dist/driver/bun.d.ts +28 -0
- package/dist/driver/expo.d.ts +17 -0
- package/dist/driver/node.d.ts +18 -1
- package/dist/driver/node.mjs +5 -5
- package/dist/driver/wa-sqlite.d.ts +18 -1
- package/dist/{errors-Bw5MdNCu.d.ts → errors-Dei4GdBb.d.ts} +80 -7
- package/dist/file-migrations/index.d.ts +54 -2
- package/dist/file-migrations/index.mjs +3 -3
- package/dist/{operation-registry-9DcvxcE5.d.ts → operation-registry-hlbhqu7q.d.ts} +50 -1
- package/dist/{primary-wins-DPAm2AKG.d.ts → primary-wins-B0np8JS3.d.ts} +25 -1
- package/dist/protocol-rqANt-9Q.d.ts +152 -0
- package/dist/query-types-DL3LtPvY.d.ts +95 -0
- package/dist/react/index.d.ts +58 -3
- package/dist/replication/coordinator/etcd.d.ts +63 -3
- package/dist/replication/coordinator/etcd.mjs +82 -46
- package/dist/replication/index.d.ts +329 -95
- package/dist/replication/index.mjs +256 -141
- package/dist/server/index.d.ts +230 -12
- package/dist/server/index.mjs +63 -50
- package/dist/{server-options-1JHu8pid.d.ts → server-options-Dab_Jvd_.d.ts} +96 -12
- package/dist/sirannon-CMhiJa5Y.d.ts +111 -0
- package/dist/transport/grpc.d.ts +93 -9
- package/dist/transport/grpc.mjs +63 -20
- package/dist/transport/memory.d.ts +50 -20
- package/dist/transport/memory.mjs +25 -0
- package/dist/{types-CL6piSnD.d.ts → types-BCejqzNA.d.ts} +20 -0
- package/dist/types-CMBcFPhb.d.ts +336 -0
- package/dist/types-CjhxcjhA.d.ts +123 -0
- package/dist/types-DyrCiWuc.d.ts +499 -0
- package/dist/types-rVZKnKN-.d.ts +591 -0
- package/package.json +7 -1
- package/dist/baseline-Br77Fnhb.d.ts +0 -6
- package/dist/database-BY0L5Q2n.d.ts +0 -172
- package/dist/protocol-6KrSq2Hy.d.ts +0 -66
- package/dist/sirannon-DaQSyhbJ.d.ts +0 -36
- package/dist/types-B7gmEsZW.d.ts +0 -221
- package/dist/types-BsVabqSI.d.ts +0 -139
- package/dist/types-C_D8IhpO.d.ts +0 -60
- package/dist/types-zhnRXrsb.d.ts +0 -384
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Base class for all sirannon-db errors. Extend this class to create
|
|
3
|
-
* domain-specific errors that carry a machine-readable {@link code}.
|
|
3
|
+
* domain-specific errors that carry a machine-readable {@link SirannonError.code}.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
4
6
|
*/
|
|
5
7
|
declare class SirannonError extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Machine-readable code the server maps to an HTTP status.
|
|
10
|
+
*/
|
|
6
11
|
readonly code: string;
|
|
7
|
-
constructor(message: string,
|
|
12
|
+
constructor(message: string,
|
|
13
|
+
/**
|
|
14
|
+
* Machine-readable code the server maps to an HTTP status.
|
|
15
|
+
*/
|
|
16
|
+
code: string);
|
|
8
17
|
}
|
|
9
18
|
/**
|
|
10
19
|
* Thrown when a database ID cannot be resolved in the registry.
|
|
11
20
|
* This typically means the database was never opened or has already been closed.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
12
23
|
*/
|
|
13
24
|
declare class DatabaseNotFoundError extends SirannonError {
|
|
14
25
|
constructor(id: string);
|
|
@@ -16,6 +27,8 @@ declare class DatabaseNotFoundError extends SirannonError {
|
|
|
16
27
|
/**
|
|
17
28
|
* Thrown when attempting to register a database with an ID that is already
|
|
18
29
|
* in use. Each database ID must be unique within the registry.
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
19
32
|
*/
|
|
20
33
|
declare class DatabaseAlreadyExistsError extends SirannonError {
|
|
21
34
|
constructor(id: string);
|
|
@@ -23,50 +36,84 @@ declare class DatabaseAlreadyExistsError extends SirannonError {
|
|
|
23
36
|
/**
|
|
24
37
|
* Thrown when a write operation is attempted on a database that was opened
|
|
25
38
|
* in read-only mode.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
26
41
|
*/
|
|
27
42
|
declare class ReadOnlyError extends SirannonError {
|
|
28
43
|
constructor(id: string);
|
|
29
44
|
}
|
|
30
45
|
/**
|
|
31
|
-
* Thrown when SQLite fails to execute a statement. The {@link sql} property
|
|
46
|
+
* Thrown when SQLite fails to execute a statement. The {@link QueryError.sql} property
|
|
32
47
|
* holds the original SQL string that caused the failure, which is useful for
|
|
33
48
|
* debugging and logging.
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
34
51
|
*/
|
|
35
52
|
declare class QueryError extends SirannonError {
|
|
53
|
+
/**
|
|
54
|
+
* The statement that failed.
|
|
55
|
+
*/
|
|
36
56
|
readonly sql: string;
|
|
37
|
-
constructor(message: string,
|
|
57
|
+
constructor(message: string,
|
|
58
|
+
/**
|
|
59
|
+
* The statement that failed.
|
|
60
|
+
*/
|
|
61
|
+
sql: string);
|
|
38
62
|
}
|
|
39
63
|
/**
|
|
40
64
|
* Thrown when a transaction cannot be committed or is forcibly rolled back.
|
|
41
65
|
* Check the message for the underlying cause.
|
|
66
|
+
*
|
|
67
|
+
* @public
|
|
42
68
|
*/
|
|
43
69
|
declare class TransactionError extends SirannonError {
|
|
44
70
|
constructor(message: string);
|
|
45
71
|
}
|
|
46
72
|
/**
|
|
47
|
-
* Thrown when a migration step fails. The {@link version} property identifies
|
|
73
|
+
* Thrown when a migration step fails. The {@link MigrationError.version} property identifies
|
|
48
74
|
* which schema version triggered the error so the failure can be pinpointed
|
|
49
75
|
* in the migration history.
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
50
78
|
*/
|
|
51
79
|
declare class MigrationError extends SirannonError {
|
|
80
|
+
/**
|
|
81
|
+
* Version of the migration that failed.
|
|
82
|
+
*/
|
|
52
83
|
readonly version: number;
|
|
53
|
-
constructor(message: string,
|
|
84
|
+
constructor(message: string,
|
|
85
|
+
/**
|
|
86
|
+
* Version of the migration that failed.
|
|
87
|
+
*/
|
|
88
|
+
version: number, code?: string);
|
|
54
89
|
}
|
|
55
90
|
/**
|
|
56
91
|
* Thrown when a before-hook explicitly rejects an operation. The optional
|
|
57
92
|
* `reason` string is surfaced in the message so callers can distinguish
|
|
58
93
|
* between different hook policies.
|
|
94
|
+
*
|
|
95
|
+
* @public
|
|
59
96
|
*/
|
|
60
97
|
declare class HookDeniedError extends SirannonError {
|
|
61
98
|
constructor(hookName: string, reason?: string);
|
|
62
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Refuses one request with a status of your own. Throw it from an authenticate hook or a registered operation.
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
63
105
|
declare class RequestDeniedError extends SirannonError {
|
|
106
|
+
/**
|
|
107
|
+
* HTTP status the server answers the refused request with.
|
|
108
|
+
*/
|
|
64
109
|
readonly status: number;
|
|
65
110
|
constructor(status: number, code: string, message: string);
|
|
66
111
|
}
|
|
67
112
|
/**
|
|
68
113
|
* Thrown when the change-data-capture pipeline encounters an unrecoverable
|
|
69
114
|
* error, such as a failed event dispatch or a corrupt change record.
|
|
115
|
+
*
|
|
116
|
+
* @public
|
|
70
117
|
*/
|
|
71
118
|
declare class CDCError extends SirannonError {
|
|
72
119
|
constructor(message: string);
|
|
@@ -76,6 +123,8 @@ declare class CDCError extends SirannonError {
|
|
|
76
123
|
* internal bookkeeping tables and SQLite's own catalogue are off limits to the
|
|
77
124
|
* query API so a caller cannot read or corrupt the change log, replication
|
|
78
125
|
* ledger, or schema catalogue.
|
|
126
|
+
*
|
|
127
|
+
* @public
|
|
79
128
|
*/
|
|
80
129
|
declare class ForbiddenSqlError extends SirannonError {
|
|
81
130
|
constructor(message: string);
|
|
@@ -83,6 +132,8 @@ declare class ForbiddenSqlError extends SirannonError {
|
|
|
83
132
|
/**
|
|
84
133
|
* Thrown when a backup operation fails, whether that is an online backup via
|
|
85
134
|
* the SQLite backup API or a file-level copy.
|
|
135
|
+
*
|
|
136
|
+
* @public
|
|
86
137
|
*/
|
|
87
138
|
declare class BackupError extends SirannonError {
|
|
88
139
|
constructor(message: string);
|
|
@@ -90,6 +141,8 @@ declare class BackupError extends SirannonError {
|
|
|
90
141
|
/**
|
|
91
142
|
* Thrown when the connection pool reaches its limit or is configured with
|
|
92
143
|
* invalid parameters such as a minimum size greater than the maximum.
|
|
144
|
+
*
|
|
145
|
+
* @public
|
|
93
146
|
*/
|
|
94
147
|
declare class ConnectionPoolError extends SirannonError {
|
|
95
148
|
constructor(message: string);
|
|
@@ -98,6 +151,8 @@ declare class ConnectionPoolError extends SirannonError {
|
|
|
98
151
|
* Thrown when opening a new database would exceed the configured cap on
|
|
99
152
|
* concurrently open databases. Close an existing database before opening
|
|
100
153
|
* another one.
|
|
154
|
+
*
|
|
155
|
+
* @public
|
|
101
156
|
*/
|
|
102
157
|
declare class MaxDatabasesError extends SirannonError {
|
|
103
158
|
constructor(max: number);
|
|
@@ -105,16 +160,34 @@ declare class MaxDatabasesError extends SirannonError {
|
|
|
105
160
|
/**
|
|
106
161
|
* Thrown when more writes are pending than the writer-worker limit allows. It
|
|
107
162
|
* signals load shedding, so the server maps it to a 503 with a Retry-After hint.
|
|
163
|
+
*
|
|
164
|
+
* @public
|
|
108
165
|
*/
|
|
109
166
|
declare class WriteOverloadError extends SirannonError {
|
|
167
|
+
/**
|
|
168
|
+
* Number of pending writes the database accepts before it refuses more.
|
|
169
|
+
*/
|
|
110
170
|
readonly limit: number;
|
|
171
|
+
/**
|
|
172
|
+
* Milliseconds the caller should wait before retrying.
|
|
173
|
+
*/
|
|
111
174
|
readonly retryAfterMs: number;
|
|
112
|
-
constructor(
|
|
175
|
+
constructor(
|
|
176
|
+
/**
|
|
177
|
+
* Number of pending writes the database accepts before it refuses more.
|
|
178
|
+
*/
|
|
179
|
+
limit: number,
|
|
180
|
+
/**
|
|
181
|
+
* Milliseconds the caller should wait before retrying.
|
|
182
|
+
*/
|
|
183
|
+
retryAfterMs: number);
|
|
113
184
|
}
|
|
114
185
|
/**
|
|
115
186
|
* Thrown when a native SQLite extension cannot be loaded. The `path` argument
|
|
116
187
|
* is the filesystem path passed to `load_extension`, and the optional `cause`
|
|
117
188
|
* string carries the error detail reported by SQLite.
|
|
189
|
+
*
|
|
190
|
+
* @public
|
|
118
191
|
*/
|
|
119
192
|
declare class ExtensionError extends SirannonError {
|
|
120
193
|
constructor(path: string, cause?: string);
|
|
@@ -1,17 +1,69 @@
|
|
|
1
|
-
import { B as BaselineFileOption } from '../baseline-
|
|
2
|
-
import { M as Migration } from '../types-
|
|
1
|
+
import { B as BaselineFileOption } from '../baseline-D93hcIEE.js';
|
|
2
|
+
import { M as Migration } from '../types-rVZKnKN-.js';
|
|
3
|
+
import '../query-types-DL3LtPvY.js';
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*
|
|
8
|
+
* How a directory of migration files is turned into migrations.
|
|
9
|
+
*/
|
|
4
10
|
interface LoadMigrationsOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Marks the migration an existing database starts from.
|
|
13
|
+
*/
|
|
5
14
|
baseline?: BaselineFileOption;
|
|
6
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*
|
|
19
|
+
* One migration found on disk, with the paths of its up and down files.
|
|
20
|
+
*/
|
|
7
21
|
interface ScannedMigration {
|
|
22
|
+
/**
|
|
23
|
+
* Version number the file name starts with.
|
|
24
|
+
*/
|
|
8
25
|
version: number;
|
|
26
|
+
/**
|
|
27
|
+
* Migration name between the version and the direction.
|
|
28
|
+
*/
|
|
9
29
|
name: string;
|
|
30
|
+
/**
|
|
31
|
+
* Path of the file that applies the migration.
|
|
32
|
+
*/
|
|
10
33
|
upPath: string;
|
|
34
|
+
/**
|
|
35
|
+
* Path of the file that undoes it, or null when the migration has none.
|
|
36
|
+
*/
|
|
11
37
|
downPath: string | null;
|
|
12
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* @public
|
|
41
|
+
*
|
|
42
|
+
* Lists the migration files in a directory, in ascending version order.
|
|
43
|
+
*
|
|
44
|
+
* @param dirPath - Directory holding the migration files.
|
|
45
|
+
* @returns One entry per migration, with the paths of its up and down files.
|
|
46
|
+
* @throws When the path is unsafe or a file name does not parse.
|
|
47
|
+
*/
|
|
13
48
|
declare function scanDirectory(dirPath: string): ScannedMigration[];
|
|
49
|
+
/**
|
|
50
|
+
* @public
|
|
51
|
+
*
|
|
52
|
+
* Reads the up files of scanned migrations, leaving each down file to be read only if a rollback needs it.
|
|
53
|
+
*
|
|
54
|
+
* @param scanned - Migrations found by {@link scanDirectory}.
|
|
55
|
+
* @returns The migrations, in ascending version order.
|
|
56
|
+
*/
|
|
14
57
|
declare function readUpMigrations(scanned: ScannedMigration[]): Migration[];
|
|
58
|
+
/**
|
|
59
|
+
* @public
|
|
60
|
+
*
|
|
61
|
+
* Reads a directory of migration files and returns the migrations to apply.
|
|
62
|
+
*
|
|
63
|
+
* @param dirPath - Directory holding the migration files.
|
|
64
|
+
* @param options - The baseline to apply, when an existing database starts from one.
|
|
65
|
+
* @returns The migrations, in ascending version order.
|
|
66
|
+
*/
|
|
15
67
|
declare function loadMigrations(dirPath: string, options?: LoadMigrationsOptions): Migration[];
|
|
16
68
|
|
|
17
69
|
export { type LoadMigrationsOptions, type ScannedMigration, loadMigrations, readUpMigrations, scanDirectory };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { parseMigrationFilename, LAZY_DOWN_SQL } from '../chunk-
|
|
2
|
-
import { applyBaselineOption } from '../chunk-
|
|
3
|
-
import { MigrationError } from '../chunk-
|
|
1
|
+
import { parseMigrationFilename, LAZY_DOWN_SQL } from '../chunk-7C36BCSN.mjs';
|
|
2
|
+
import { applyBaselineOption } from '../chunk-IWGIYDMZ.mjs';
|
|
3
|
+
import { MigrationError } from '../chunk-PBRXXISQ.mjs';
|
|
4
4
|
import { statSync, readdirSync, readFileSync } from 'fs';
|
|
5
5
|
import { resolve, join } from 'path';
|
|
6
6
|
|
|
@@ -1,12 +1,25 @@
|
|
|
1
|
-
import { P as Params } from './types-
|
|
1
|
+
import { P as Params } from './query-types-DL3LtPvY.js';
|
|
2
2
|
|
|
3
|
+
/** One statement a registered operation runs, with its parameters bound.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
3
6
|
interface OperationStatement {
|
|
7
|
+
/** The statement to run. */
|
|
4
8
|
sql: string;
|
|
9
|
+
/** Parameters bound to that statement. */
|
|
5
10
|
params?: Params;
|
|
6
11
|
}
|
|
12
|
+
/** Values a caller passes when it invokes a registered operation by name.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
7
15
|
type OperationArguments = Record<string, unknown>;
|
|
16
|
+
/** A read a caller invokes by name, so the server accepts no SQL from the network.
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
8
19
|
interface ReadOperation<Identity = unknown> {
|
|
20
|
+
/** Argument names this operation accepts from the caller. */
|
|
9
21
|
args?: readonly string[];
|
|
22
|
+
/** Arguments the server fills from the authenticated identity, so a caller cannot supply them. */
|
|
10
23
|
fromIdentity?: Readonly<Record<string, keyof Identity & string>>;
|
|
11
24
|
/**
|
|
12
25
|
* The columns every row of this read carries. Code generation emits a typed
|
|
@@ -14,32 +27,68 @@ interface ReadOperation<Identity = unknown> {
|
|
|
14
27
|
* operation takes no arguments, because arguments choose the statement.
|
|
15
28
|
*/
|
|
16
29
|
columns?: readonly string[];
|
|
30
|
+
/** Builds the statement this read runs for a given set of arguments. */
|
|
17
31
|
statement(args: OperationArguments): OperationStatement;
|
|
18
32
|
}
|
|
33
|
+
/** A write a caller invokes by name. The server runs every statement it returns in one transaction.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
19
36
|
interface WriteOperation<Identity = unknown> {
|
|
37
|
+
/** Argument names this operation accepts from the caller. */
|
|
20
38
|
args?: readonly string[];
|
|
39
|
+
/** Arguments the server fills from the authenticated identity, so a caller cannot supply them. */
|
|
21
40
|
fromIdentity?: Readonly<Record<string, keyof Identity & string>>;
|
|
41
|
+
/** Builds the statements this write runs for a given set of arguments. */
|
|
22
42
|
statements(args: OperationArguments): OperationStatement | readonly OperationStatement[];
|
|
23
43
|
}
|
|
44
|
+
/** The reads and writes one database exposes by name.
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
24
47
|
interface DatabaseOperations<Identity = unknown> {
|
|
48
|
+
/** Reads callers may invoke, keyed by operation name. */
|
|
25
49
|
reads?: Readonly<Record<string, ReadOperation<Identity>>>;
|
|
50
|
+
/** Writes callers may invoke, keyed by operation name. */
|
|
26
51
|
writes?: Readonly<Record<string, WriteOperation<Identity>>>;
|
|
27
52
|
}
|
|
53
|
+
/** Every database's registered operations, keyed by database identifier.
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
28
56
|
type OperationRegistry<Identity = unknown> = Readonly<Record<string, DatabaseOperations<Identity>>>;
|
|
29
57
|
/**
|
|
30
58
|
* A named operation a remote caller invokes, carrying the argument and row
|
|
31
59
|
* types of the registered operation. Only `name` exists at runtime; `types`
|
|
32
60
|
* is never assigned and is present so both type parameters are inferable at
|
|
33
61
|
* the call site. Code generation emits one reference per registered operation.
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
34
64
|
*/
|
|
35
65
|
interface OperationRef<Args = OperationArguments, Row = Record<string, unknown>> {
|
|
66
|
+
/** Name the server registered this operation under. */
|
|
36
67
|
readonly name: string;
|
|
68
|
+
/** Present for type inference only, and never assigned at runtime. */
|
|
37
69
|
readonly types?: {
|
|
38
70
|
args: Args;
|
|
39
71
|
row: Row;
|
|
40
72
|
};
|
|
41
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Builds a typed reference to a registered operation so that a call site infers its
|
|
76
|
+
* argument and row types from the name alone.
|
|
77
|
+
*
|
|
78
|
+
* @param name - Name the server registered the operation under.
|
|
79
|
+
* @returns A reference carrying that name and the two inferred types.
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
42
83
|
declare function operationRef<Args = OperationArguments, Row = Record<string, unknown>>(name: string): OperationRef<Args, Row>;
|
|
84
|
+
/**
|
|
85
|
+
* Reads the operation name out of either a plain string or a typed reference.
|
|
86
|
+
*
|
|
87
|
+
* @param operation - The name itself, or a reference built by {@link operationRef}.
|
|
88
|
+
* @returns The registered operation name.
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
43
92
|
declare function operationName(operation: string | OperationRef<never, never>): string;
|
|
44
93
|
|
|
45
94
|
export { type DatabaseOperations as D, type OperationRef as O, type ReadOperation as R, type WriteOperation as W, type OperationRegistry as a, type OperationArguments as b, type OperationStatement as c, operationRef as d, operationName as o };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ConflictResolver, a as ConflictContext, b as ConflictResolution } from './types-
|
|
1
|
+
import { C as ConflictResolver, a as ConflictContext, b as ConflictResolution } from './types-CjhxcjhA.js';
|
|
2
2
|
|
|
3
3
|
type ColumnVersionGetter = (table: string, rowId: string) => Promise<Map<string, {
|
|
4
4
|
hlc: string;
|
|
@@ -15,11 +15,19 @@ type ColumnVersionGetter = (table: string, rowId: string) => Promise<Map<string,
|
|
|
15
15
|
* injected `getColumnVersions` callback) determine which side's value wins
|
|
16
16
|
* for each contested column. If no column version metadata exists, the
|
|
17
17
|
* resolver falls back to whole-row LWW.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
18
20
|
*/
|
|
19
21
|
declare class FieldMergeResolver implements ConflictResolver {
|
|
20
22
|
private readonly getColumnVersions;
|
|
21
23
|
private readonly lww;
|
|
22
24
|
constructor(getColumnVersions: ColumnVersionGetter);
|
|
25
|
+
/**
|
|
26
|
+
* Merges columns only one side changed, and settles overlapping columns by their per-column stamps.
|
|
27
|
+
*
|
|
28
|
+
* @param ctx - The local and incoming versions of one row.
|
|
29
|
+
* @returns Which version to write, or the merged row.
|
|
30
|
+
*/
|
|
23
31
|
resolve(ctx: ConflictContext): Promise<ConflictResolution>;
|
|
24
32
|
}
|
|
25
33
|
|
|
@@ -36,8 +44,16 @@ declare class FieldMergeResolver implements ConflictResolver {
|
|
|
36
44
|
* resolution without coordination. This is the default resolver and the
|
|
37
45
|
* fallback used by PrimaryWinsResolver and FieldMergeResolver when they
|
|
38
46
|
* cannot make a more specific decision.
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
39
49
|
*/
|
|
40
50
|
declare class LWWResolver implements ConflictResolver {
|
|
51
|
+
/**
|
|
52
|
+
* Takes the incoming row when its stamp is higher, and keeps the local row otherwise.
|
|
53
|
+
*
|
|
54
|
+
* @param ctx - The local and incoming versions of one row.
|
|
55
|
+
* @returns Which version to write.
|
|
56
|
+
*/
|
|
41
57
|
resolve(ctx: ConflictContext): ConflictResolution;
|
|
42
58
|
}
|
|
43
59
|
|
|
@@ -50,11 +66,19 @@ declare class LWWResolver implements ConflictResolver {
|
|
|
50
66
|
* the decision falls back to LWW ordering. This resolver is designed for
|
|
51
67
|
* primary-replica topologies where the primary is the authoritative source of
|
|
52
68
|
* truth and replica-side writes should never override it.
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
53
71
|
*/
|
|
54
72
|
declare class PrimaryWinsResolver implements ConflictResolver {
|
|
55
73
|
private readonly primaryNodeId;
|
|
56
74
|
private readonly lww;
|
|
57
75
|
constructor(primaryNodeId: string);
|
|
76
|
+
/**
|
|
77
|
+
* Takes the version authored by the configured primary node, and falls back to last-writer-wins otherwise.
|
|
78
|
+
*
|
|
79
|
+
* @param ctx - The local and incoming versions of one row.
|
|
80
|
+
* @returns Which version to write.
|
|
81
|
+
*/
|
|
58
82
|
resolve(ctx: ConflictContext): ConflictResolution;
|
|
59
83
|
}
|
|
60
84
|
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { W as WriteConcern, R as ReadConcern, E as ExecuteResult } from './query-types-DL3LtPvY.js';
|
|
2
|
+
import { B as BulkLoadDurability, a as BulkLoadResult } from './server-options-Dab_Jvd_.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Body of `POST /db/{id}/query`.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
interface QueryRequest {
|
|
10
|
+
/** The statement to run. */
|
|
11
|
+
sql: string;
|
|
12
|
+
/** Values bound to the statement, named or positional. */
|
|
13
|
+
params?: Record<string, unknown> | unknown[];
|
|
14
|
+
/** Currency this read requires. */
|
|
15
|
+
readConcern?: ReadConcern;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Body of `POST /db/{id}/execute`.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
interface ExecuteRequest {
|
|
23
|
+
/** The statement to run. */
|
|
24
|
+
sql: string;
|
|
25
|
+
/** Values bound to the statement, named or positional. */
|
|
26
|
+
params?: Record<string, unknown> | unknown[];
|
|
27
|
+
/** Acknowledgements this write waits for. */
|
|
28
|
+
writeConcern?: WriteConcern;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* One statement inside a transaction or a registered write.
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
interface TransactionStatement {
|
|
36
|
+
/** The statement to run. */
|
|
37
|
+
sql: string;
|
|
38
|
+
/** Values bound to the statement, named or positional. */
|
|
39
|
+
params?: Record<string, unknown> | unknown[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Body of `POST /db/{id}/transaction`, whose statements all succeed or all fail.
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
interface TransactionRequest {
|
|
47
|
+
/** The statements to run, in order. */
|
|
48
|
+
statements: TransactionStatement[];
|
|
49
|
+
/** Acknowledgements the transaction waits for. */
|
|
50
|
+
writeConcern?: WriteConcern;
|
|
51
|
+
}
|
|
52
|
+
/** The whole batch commits atomically in one server-side transaction with one fsync.
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
interface BatchRequest {
|
|
56
|
+
/** The statement to run for each parameter set. */
|
|
57
|
+
sql: string;
|
|
58
|
+
/** One parameter set per run. */
|
|
59
|
+
paramsBatch: (Record<string, unknown> | unknown[])[];
|
|
60
|
+
/** Acknowledgements the batch waits for. */
|
|
61
|
+
writeConcern?: WriteConcern;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* What a read route answers with.
|
|
65
|
+
*
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
interface QueryResponse {
|
|
69
|
+
/** The rows the statement produced, with blobs and large integers in their tagged wire form. */
|
|
70
|
+
rows: Record<string, unknown>[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* What a write route answers with.
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
interface ExecuteResponse {
|
|
78
|
+
/** Number of rows the statement inserted, updated, or deleted. */
|
|
79
|
+
changes: number;
|
|
80
|
+
/** Row id SQLite assigned to the last inserted row, as a decimal string when it exceeds the safe range. */
|
|
81
|
+
lastInsertRowId: number | string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* What a transaction route answers with.
|
|
85
|
+
*
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
interface TransactionResponse {
|
|
89
|
+
/** One result per statement, in the order the transaction ran them. */
|
|
90
|
+
results: ExecuteResponse[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* What a batch route answers with.
|
|
94
|
+
*
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
interface BatchResponse {
|
|
98
|
+
/** One result per parameter set, in order. */
|
|
99
|
+
results: ExecuteResponse[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Loads rows with relaxed writer durability; the configured durability is
|
|
103
|
+
* restored before the response is sent, and a load interrupted by a crash is
|
|
104
|
+
* recovered by re-running it.
|
|
105
|
+
*
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
interface LoadRequest {
|
|
109
|
+
/** The statement to run for each parameter set. */
|
|
110
|
+
sql: string;
|
|
111
|
+
/** One parameter set per row. */
|
|
112
|
+
paramsBatch: (Record<string, unknown> | unknown[])[];
|
|
113
|
+
/** Durability in force while the load runs. Default: 'off'. */
|
|
114
|
+
durability?: BulkLoadDurability;
|
|
115
|
+
/** Whether this load ends with a checkpoint. Set it false on every batch but the last of a multi-batch import. */
|
|
116
|
+
checkpoint?: boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* How many rows a bulk load applied and how many rows changed.
|
|
120
|
+
*
|
|
121
|
+
* @public
|
|
122
|
+
*/
|
|
123
|
+
type LoadResponse = BulkLoadResult;
|
|
124
|
+
interface AckResponse {
|
|
125
|
+
acked: boolean;
|
|
126
|
+
seq: string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The body every failed route answers with.
|
|
130
|
+
*
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
133
|
+
interface ErrorResponse {
|
|
134
|
+
/** Machine-readable code, human-readable message, and anything else the route attached. */
|
|
135
|
+
error: {
|
|
136
|
+
code: string;
|
|
137
|
+
message: string;
|
|
138
|
+
details?: Record<string, unknown>;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Turns a write result into its wire form, encoding a row id beyond the safe
|
|
143
|
+
* integer range as a decimal string.
|
|
144
|
+
*
|
|
145
|
+
* @param result - What the write reported locally.
|
|
146
|
+
* @returns The result as it crosses the wire.
|
|
147
|
+
*
|
|
148
|
+
* @public
|
|
149
|
+
*/
|
|
150
|
+
declare function toExecuteResponse(result: ExecuteResult): ExecuteResponse;
|
|
151
|
+
|
|
152
|
+
export { type AckResponse as A, type BatchResponse as B, type ExecuteResponse as E, type LoadResponse as L, type QueryResponse as Q, type TransactionStatement as T, type TransactionResponse as a, type BatchRequest as b, type ErrorResponse as c, type ExecuteRequest as d, type LoadRequest as e, type QueryRequest as f, type TransactionRequest as g, toExecuteResponse as t };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/** Query parameter types: named (object) or positional (array).
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
type Params = Record<string, unknown> | unknown[];
|
|
5
|
+
/** How many nodes must acknowledge a write before it returns.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
type WriteConcernLevel = 'local' | 'majority' | 'all';
|
|
9
|
+
/** How many nodes must acknowledge a write, and how long the caller waits for them.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
interface WriteConcern {
|
|
13
|
+
/** Number of acknowledgements the write waits for. */
|
|
14
|
+
level: WriteConcernLevel;
|
|
15
|
+
/** Milliseconds to wait for those acknowledgements before the write fails. */
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
}
|
|
18
|
+
/** How current a read has to be before the node will serve it.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
type ReadConcernLevel = 'local' | 'majority' | 'linearizable';
|
|
22
|
+
/** How current a read has to be before the node will serve it.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
interface ReadConcern {
|
|
26
|
+
/** Currency the node must prove before it answers. */
|
|
27
|
+
level: ReadConcernLevel;
|
|
28
|
+
}
|
|
29
|
+
/** Per-statement settings you pass alongside the SQL and its parameters.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
interface QueryOptions {
|
|
33
|
+
/** Acknowledgements a write waits for. Coordinator mode applies 'majority' when you omit it. */
|
|
34
|
+
writeConcern?: WriteConcern;
|
|
35
|
+
/** Currency a read requires. Coordinator mode enforces it and static mode ignores it. */
|
|
36
|
+
readConcern?: ReadConcern;
|
|
37
|
+
}
|
|
38
|
+
/** Result returned by mutation statements (INSERT, UPDATE, DELETE).
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
interface ExecuteResult {
|
|
42
|
+
/** Number of rows the statement inserted, updated, or deleted. */
|
|
43
|
+
changes: number;
|
|
44
|
+
/** Row id SQLite assigned to the last inserted row. */
|
|
45
|
+
lastInsertRowId: number | bigint;
|
|
46
|
+
}
|
|
47
|
+
/** CDC operation type.
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
type ChangeOperation = 'insert' | 'update' | 'delete';
|
|
51
|
+
/** Event emitted when a watched table row changes.
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
interface ChangeEvent<T = Record<string, unknown>> {
|
|
55
|
+
/** Whether the row was inserted, updated, or deleted. */
|
|
56
|
+
type: ChangeOperation;
|
|
57
|
+
/** Table the row belongs to. */
|
|
58
|
+
table: string;
|
|
59
|
+
/** The row as it stands after the change. A delete carries the row as it was. */
|
|
60
|
+
row: T;
|
|
61
|
+
/** The row as it stood before an update or a delete. */
|
|
62
|
+
oldRow?: T;
|
|
63
|
+
/** Position of this change in the database's change log. Subscribers resume from it. */
|
|
64
|
+
seq: bigint;
|
|
65
|
+
/** Milliseconds since the Unix epoch, taken when the change was recorded. */
|
|
66
|
+
timestamp: number;
|
|
67
|
+
/** Hybrid logical clock stamp the writing node gave this change. */
|
|
68
|
+
hlc?: string;
|
|
69
|
+
/** Identifier of the node that authored the change. */
|
|
70
|
+
origin?: string;
|
|
71
|
+
/** Primary key of the changed row, encoded as a string. */
|
|
72
|
+
rowId?: string;
|
|
73
|
+
/** Identifier of the transaction that produced this change. */
|
|
74
|
+
txId?: string;
|
|
75
|
+
/** Set on the last change of a transaction, so a consumer applies the whole transaction at once. */
|
|
76
|
+
txEnd?: boolean;
|
|
77
|
+
}
|
|
78
|
+
/** Builder for creating CDC subscriptions with optional filters.
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
interface SubscriptionBuilder {
|
|
82
|
+
/** Narrows the subscription to rows whose columns equal the given values. */
|
|
83
|
+
filter(conditions: Record<string, unknown>): SubscriptionBuilder;
|
|
84
|
+
/** Starts the subscription and calls back on each change. */
|
|
85
|
+
subscribe(callback: (event: ChangeEvent) => void): Subscription;
|
|
86
|
+
}
|
|
87
|
+
/** Handle for an active subscription.
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
interface Subscription {
|
|
91
|
+
/** Ends the subscription, so the callback receives no further events. */
|
|
92
|
+
unsubscribe(): void;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type { ChangeEvent as C, ExecuteResult as E, Params as P, QueryOptions as Q, ReadConcern as R, SubscriptionBuilder as S, WriteConcern as W, ReadConcernLevel as a, ChangeOperation as b, Subscription as c, WriteConcernLevel as d };
|