@delali/sirannon-db 0.3.4-next.62 → 0.3.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 +79 -56
- package/dist/backup/index.d.ts +44 -45
- package/dist/backup/index.mjs +7 -7
- package/dist/backup-scheduler/index.d.ts +42 -41
- package/dist/backup-scheduler/index.mjs +4 -4
- package/dist/baseline-Co3iIsN_.d.ts +19 -0
- package/dist/change-tracker-DqCdeEyx.d.ts +128 -0
- package/dist/{chunk-VOSJBZ6Q.mjs → chunk-2ES3DT4A.mjs} +71 -33
- package/dist/{chunk-6CMCO7S4.mjs → chunk-2O3PP4CF.mjs} +1 -1
- package/dist/{chunk-E7Q7HE46.mjs → chunk-3BZLZ47R.mjs} +26 -26
- package/dist/chunk-4KASJKKK.mjs +2501 -0
- package/dist/{chunk-MYNI2WFS.mjs → chunk-52XW3Z76.mjs} +40 -8
- package/dist/chunk-55YRLSM2.mjs +57 -0
- package/dist/{chunk-KDAHYFW7.mjs → chunk-6AOJCNRU.mjs} +5 -5
- package/dist/{chunk-KXTYR2OQ.mjs → chunk-A3PHCO6W.mjs} +39 -111
- package/dist/chunk-ADNWEHGZ.mjs +299 -0
- package/dist/{chunk-2QLXDHAP.mjs → chunk-BLMRNSUG.mjs} +11 -2
- package/dist/chunk-BVMZJOVM.mjs +5 -0
- package/dist/{chunk-IWGIYDMZ.mjs → chunk-BZWDPF4G.mjs} +1 -1
- package/dist/{chunk-YVF2ZJTE.mjs → chunk-CZL4D3BM.mjs} +1 -1
- package/dist/{chunk-7SC2TZAS.mjs → chunk-DX4WGJL7.mjs} +2 -2
- package/dist/{chunk-45MKELYA.mjs → chunk-ESTZZPT5.mjs} +132 -13
- package/dist/{chunk-QP5L5DFJ.mjs → chunk-FJPR2CJX.mjs} +3 -3
- package/dist/chunk-HR7K3GZW.mjs +36 -0
- package/dist/{chunk-LXCGPZPA.mjs → chunk-IEKIYO4V.mjs} +1 -1
- package/dist/{chunk-TUD5CJ76.mjs → chunk-KB4OLJAD.mjs} +26 -19
- package/dist/{chunk-PBRXXISQ.mjs → chunk-KINDFBQP.mjs} +3 -2
- package/dist/{chunk-E6IMX7RS.mjs → chunk-KJLNYOOL.mjs} +2 -2
- package/dist/{chunk-BTTFW4Z4.mjs → chunk-KU32OT4H.mjs} +2 -10
- package/dist/{chunk-JQWGHSEH.mjs → chunk-NVSQ2T5Q.mjs} +71 -70
- package/dist/{chunk-W4EUTJNT.mjs → chunk-NZGSDALX.mjs} +94 -96
- package/dist/{chunk-U445A3C4.mjs → chunk-QGVRRKB2.mjs} +1 -1
- package/dist/{chunk-GYCEJNU4.mjs → chunk-R7GBXNTO.mjs} +1 -1
- package/dist/{chunk-7C36BCSN.mjs → chunk-VDN6FHU4.mjs} +1 -1
- package/dist/{chunk-6IYS4WLH.mjs → chunk-VO3ZWA2G.mjs} +142 -115
- package/dist/chunk-WOMADPM4.mjs +12 -0
- package/dist/{chunk-OUSWVNWT.mjs → chunk-YCMB6GR4.mjs} +1 -1
- package/dist/{chunk-YNTDOFTN.mjs → chunk-YW7IKQ7T.mjs} +1 -1
- package/dist/{chunk-M2BEAH5I.mjs → chunk-ZN4HI5FK.mjs} +126 -72
- package/dist/{chunk-SBL6GN43.mjs → chunk-ZYWI45EN.mjs} +1 -1
- package/dist/client/index.d.ts +135 -137
- package/dist/client/index.mjs +177 -82
- package/dist/client/topology.d.ts +31 -31
- package/dist/client/topology.mjs +42 -23
- package/dist/client-base-BxTocU1x.d.ts +398 -0
- package/dist/client-streams-YKANXMWO.mjs +112 -0
- package/dist/codegen/cli.mjs +4 -4
- package/dist/codegen/index.d.ts +36 -29
- package/dist/codegen/index.mjs +4 -4
- package/dist/core/index.d.ts +130 -115
- package/dist/core/index.mjs +387 -297
- package/dist/core/writer-worker.mjs +3 -3
- package/dist/database-CGDsXW1K.d.ts +959 -0
- package/dist/database-backup-DcLhxoa1.d.ts +143 -0
- package/dist/driver/better-sqlite3.d.ts +11 -10
- package/dist/driver/better-sqlite3.mjs +11 -11
- package/dist/driver/bun.d.ts +9 -8
- package/dist/driver/expo.d.ts +6 -7
- package/dist/driver/node.d.ts +11 -10
- package/dist/driver/node.mjs +13 -11
- package/dist/driver/wa-sqlite.d.ts +6 -6
- package/dist/errors-CJUkQ-KL.d.ts +199 -0
- package/dist/file-migrations/index.d.ts +20 -18
- package/dist/file-migrations/index.mjs +3 -3
- package/dist/forward-rpc-VRWFZXHN.mjs +44 -0
- package/dist/operation-registry-CGhNT-Sn.d.ts +96 -0
- package/dist/primary-wins-CHNOYuN7.d.ts +81 -0
- package/dist/protocol-DFpNNsIT.d.ts +153 -0
- package/dist/query-types-5B02ixH0.d.ts +129 -0
- package/dist/react/index.d.ts +22 -22
- package/dist/replication/coordinator/etcd.d.ts +37 -31
- package/dist/replication/coordinator/etcd.mjs +296 -131
- package/dist/replication/index.d.ts +201 -161
- package/dist/replication/index.mjs +630 -529
- package/dist/restore-options-CH8mE-Tb.d.ts +84 -0
- package/dist/server/index.d.ts +201 -191
- package/dist/server/index.mjs +736 -619
- package/dist/server-options-aYtCkefX.d.ts +317 -0
- package/dist/server-streams-24XL4T43.mjs +254 -0
- package/dist/sirannon-J3EgPVD7.d.ts +179 -0
- package/dist/transport/grpc.d.ts +37 -24
- package/dist/transport/grpc.mjs +83 -3199
- package/dist/transport/memory.d.ts +25 -26
- package/dist/transport/memory.mjs +18 -9
- package/dist/types-BrAiDGOb.d.ts +505 -0
- package/dist/types-CEJG0eFS.d.ts +88 -0
- package/dist/types-Dc8oWlxj.d.ts +1580 -0
- package/dist/types-DqODKeOq.d.ts +123 -0
- package/dist/types-guEKSzMr.d.ts +367 -0
- package/package.json +7 -7
- package/dist/baseline-D93hcIEE.d.ts +0 -17
- package/dist/change-tracker-CjRFuZdB.d.ts +0 -144
- package/dist/client-base-Cmd9EVme.d.ts +0 -397
- package/dist/database-BLQvqjsw.d.ts +0 -917
- package/dist/database-backup-B7oszQ2n.d.ts +0 -141
- package/dist/errors-Dei4GdBb.d.ts +0 -196
- package/dist/operation-registry-oiPuSYI6.d.ts +0 -94
- package/dist/primary-wins-B0np8JS3.d.ts +0 -85
- package/dist/protocol-HI-nY8DD.d.ts +0 -152
- package/dist/query-types-p1liOP-b.d.ts +0 -127
- package/dist/restore-options-CksYsH1l.d.ts +0 -83
- package/dist/server-options-Bj5iJnjx.d.ts +0 -292
- package/dist/sirannon-BPxC5tC2.d.ts +0 -178
- package/dist/types-B0EhgDbr.d.ts +0 -340
- package/dist/types-CbjfRwrK.d.ts +0 -499
- package/dist/types-CjhxcjhA.d.ts +0 -123
- package/dist/types-DPSmjU54.d.ts +0 -1518
- package/dist/types-DTO4CYhW.d.ts +0 -88
|
@@ -1,65 +1,67 @@
|
|
|
1
|
-
import { B as BaselineFileOption } from '../baseline-
|
|
2
|
-
import { M as Migration } from '../types-
|
|
3
|
-
import '../query-types-
|
|
1
|
+
import { B as BaselineFileOption } from '../baseline-Co3iIsN_.js';
|
|
2
|
+
import { M as Migration } from '../types-Dc8oWlxj.js';
|
|
3
|
+
import '../query-types-5B02ixH0.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Configures how {@link loadMigrations} builds migrations from a directory of files.
|
|
7
7
|
*
|
|
8
8
|
* @public
|
|
9
9
|
*/
|
|
10
10
|
interface LoadMigrationsOptions {
|
|
11
11
|
/**
|
|
12
|
-
* Marks
|
|
12
|
+
* Marks one migration as a baseline, which a new database runs in place of the earlier versions.
|
|
13
13
|
*/
|
|
14
14
|
baseline?: BaselineFileOption;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Describes one migration that {@link scanDirectory} finds on disk, with the paths of its up and down files.
|
|
18
18
|
*
|
|
19
19
|
* @public
|
|
20
20
|
*/
|
|
21
21
|
interface ScannedMigration {
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* The version number at the start of the file name.
|
|
24
24
|
*/
|
|
25
25
|
version: number;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* The migration name between the version and the direction.
|
|
28
28
|
*/
|
|
29
29
|
name: string;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* The path of the file with the SQL that applies the migration.
|
|
32
32
|
*/
|
|
33
33
|
upPath: string;
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* The path of the file with the SQL that undoes the migration, or `null` when the directory has no down file for it.
|
|
36
36
|
*/
|
|
37
37
|
downPath: string | null;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
40
|
+
* Returns the migrations in a directory, in ascending version order, and skips each file whose name has another form.
|
|
41
41
|
*
|
|
42
|
-
* @param dirPath -
|
|
42
|
+
* @param dirPath - The directory that holds the migration files.
|
|
43
43
|
* @returns One entry per migration, with the paths of its up and down files.
|
|
44
|
-
* @throws
|
|
44
|
+
* @throws A `MigrationError` when the path is unsafe or names no directory, when two file names share a version, or when a version has no up file.
|
|
45
45
|
*
|
|
46
46
|
* @public
|
|
47
47
|
*/
|
|
48
48
|
declare function scanDirectory(dirPath: string): ScannedMigration[];
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
50
|
+
* Returns migrations with the SQL from each scanned migration's up file. The
|
|
51
|
+
* migrations hold only the up SQL, and {@link loadMigrations} adds the down
|
|
52
|
+
* file read that a rollback uses.
|
|
51
53
|
*
|
|
52
|
-
* @param scanned -
|
|
54
|
+
* @param scanned - The migrations that {@link scanDirectory} returns.
|
|
53
55
|
* @returns The migrations, in ascending version order.
|
|
54
56
|
*
|
|
55
57
|
* @public
|
|
56
58
|
*/
|
|
57
59
|
declare function readUpMigrations(scanned: ScannedMigration[]): Migration[];
|
|
58
60
|
/**
|
|
59
|
-
*
|
|
61
|
+
* Returns the migrations from a directory of migration files, and reads each down file only when you roll that migration back.
|
|
60
62
|
*
|
|
61
|
-
* @param dirPath -
|
|
62
|
-
* @param options - The baseline
|
|
63
|
+
* @param dirPath - The directory that holds the migration files.
|
|
64
|
+
* @param options - The baseline, when one migration replaces the earlier versions for a new database.
|
|
63
65
|
* @returns The migrations, in ascending version order.
|
|
64
66
|
*
|
|
65
67
|
* @public
|
|
@@ -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-VDN6FHU4.mjs';
|
|
2
|
+
import { applyBaselineOption } from '../chunk-BZWDPF4G.mjs';
|
|
3
|
+
import { MigrationError } from '../chunk-KINDFBQP.mjs';
|
|
4
4
|
import { statSync, readdirSync, readFileSync } from 'fs';
|
|
5
5
|
import { resolve, join } from 'path';
|
|
6
6
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { toForwardRequest } from './chunk-ADNWEHGZ.mjs';
|
|
2
|
+
import { TransportError } from './chunk-KU32OT4H.mjs';
|
|
3
|
+
import './chunk-BLMRNSUG.mjs';
|
|
4
|
+
import { SirannonError } from './chunk-KINDFBQP.mjs';
|
|
5
|
+
import { Metadata } from '@grpc/grpc-js';
|
|
6
|
+
|
|
7
|
+
function forwardOverRpc(entry, request, deadlineMs) {
|
|
8
|
+
const protoRequest = toForwardRequest(request);
|
|
9
|
+
const deadline = new Date(Date.now() + deadlineMs);
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
entry.client.forward(
|
|
12
|
+
protoRequest,
|
|
13
|
+
new Metadata(),
|
|
14
|
+
{ deadline },
|
|
15
|
+
(err, response) => {
|
|
16
|
+
if (err) {
|
|
17
|
+
reject(new TransportError(`Forward RPC failed: ${err.message}`));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (!response) {
|
|
21
|
+
reject(new TransportError("Forward RPC returned empty response"));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (response.error) {
|
|
25
|
+
reject(
|
|
26
|
+
response.errorCode ? new SirannonError(response.error, response.errorCode) : new TransportError(`Forward RPC error: ${response.error}`)
|
|
27
|
+
);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
resolve({
|
|
31
|
+
requestId: response.requestId,
|
|
32
|
+
results: response.results.map((r) => ({
|
|
33
|
+
changes: r.changes,
|
|
34
|
+
lastInsertRowId: Number(r.lastInsertRowId)
|
|
35
|
+
})),
|
|
36
|
+
groupId: response.groupId || void 0,
|
|
37
|
+
primaryTerm: response.primaryTerm === 0n ? void 0 : response.primaryTerm
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { forwardOverRpc };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { P as Params } from './query-types-5B02ixH0.js';
|
|
2
|
+
|
|
3
|
+
/** One statement that a registered operation executes, with its parameters.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
interface OperationStatement {
|
|
7
|
+
/** The statement to execute. */
|
|
8
|
+
sql: string;
|
|
9
|
+
/** The parameters to bind to that statement. */
|
|
10
|
+
params?: Params;
|
|
11
|
+
}
|
|
12
|
+
/** The values that a caller passes when it invokes a registered operation by name.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
type OperationArguments = Record<string, unknown>;
|
|
16
|
+
/** A read that a caller invokes by name, so that the caller sends no SQL over the network.
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
interface ReadOperation<Identity = unknown> {
|
|
20
|
+
/** The argument names that this operation accepts from the caller. */
|
|
21
|
+
args?: readonly string[];
|
|
22
|
+
/** The arguments that the server fills from the authenticated identity; a request that supplies one of them fails with `ARGUMENT_NOT_ALLOWED`. */
|
|
23
|
+
fromIdentity?: Readonly<Record<string, keyof Identity & string>>;
|
|
24
|
+
/**
|
|
25
|
+
* The column names of each row that this read returns. Code generation builds
|
|
26
|
+
* a typed row from this list, and when the list is absent, it takes the
|
|
27
|
+
* columns from the statement text, but only for an operation that takes no
|
|
28
|
+
* arguments, because the statement text can change with the arguments.
|
|
29
|
+
*/
|
|
30
|
+
columns?: readonly string[];
|
|
31
|
+
/** Builds the statement that this read executes for a given set of arguments. */
|
|
32
|
+
statement(args: OperationArguments): OperationStatement;
|
|
33
|
+
}
|
|
34
|
+
/** A write that a caller invokes by name; the server executes every statement that it returns in one transaction.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
interface WriteOperation<Identity = unknown> {
|
|
38
|
+
/** The argument names that this operation accepts from the caller. */
|
|
39
|
+
args?: readonly string[];
|
|
40
|
+
/** The arguments that the server fills from the authenticated identity; a request that supplies one of them fails with `ARGUMENT_NOT_ALLOWED`. */
|
|
41
|
+
fromIdentity?: Readonly<Record<string, keyof Identity & string>>;
|
|
42
|
+
/** Builds the statements that this write executes for a given set of arguments. */
|
|
43
|
+
statements(args: OperationArguments): OperationStatement | readonly OperationStatement[];
|
|
44
|
+
}
|
|
45
|
+
/** The reads and writes that callers may invoke by name on a database.
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
interface DatabaseOperations<Identity = unknown> {
|
|
49
|
+
/** The reads that callers may invoke, keyed by operation name. */
|
|
50
|
+
reads?: Readonly<Record<string, ReadOperation<Identity>>>;
|
|
51
|
+
/** The writes that callers may invoke, keyed by operation name. */
|
|
52
|
+
writes?: Readonly<Record<string, WriteOperation<Identity>>>;
|
|
53
|
+
}
|
|
54
|
+
/** Every database's registered operations, keyed by database identifier.
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
type OperationRegistry<Identity = unknown> = Readonly<Record<string, DatabaseOperations<Identity>>>;
|
|
58
|
+
/**
|
|
59
|
+
* A named operation that a remote caller invokes, typed with the argument and
|
|
60
|
+
* row types of the registered operation. Only `name` exists at runtime, and
|
|
61
|
+
* `types` stays unassigned so that the compiler can infer both type parameters
|
|
62
|
+
* at the call site. Code generation emits one reference per registered
|
|
63
|
+
* operation.
|
|
64
|
+
*
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
interface OperationRef<Args = OperationArguments, Row = Record<string, unknown>> {
|
|
68
|
+
/** The name that the server registered this operation under. */
|
|
69
|
+
readonly name: string;
|
|
70
|
+
/** A field for type inference only, which stays unassigned at runtime. */
|
|
71
|
+
readonly types?: {
|
|
72
|
+
args: Args;
|
|
73
|
+
row: Row;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Builds a typed reference to a registered operation, so that a call site infers its
|
|
78
|
+
* argument and row types from the name alone.
|
|
79
|
+
*
|
|
80
|
+
* @param name - The name that the server registered the operation under.
|
|
81
|
+
* @returns A reference with that name and the two inferred types.
|
|
82
|
+
*
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
declare function operationRef<Args = OperationArguments, Row = Record<string, unknown>>(name: string): OperationRef<Args, Row>;
|
|
86
|
+
/**
|
|
87
|
+
* Returns the operation name from either a plain string or a typed reference.
|
|
88
|
+
*
|
|
89
|
+
* @param operation - The name itself, or a reference built by {@link operationRef}.
|
|
90
|
+
* @returns The registered operation name.
|
|
91
|
+
*
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
94
|
+
declare function operationName(operation: string | OperationRef<never, never>): string;
|
|
95
|
+
|
|
96
|
+
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 };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { C as ConflictResolver, a as ConflictContext, b as ConflictResolution } from './types-DqODKeOq.js';
|
|
2
|
+
|
|
3
|
+
type ColumnVersionGetter = (table: string, rowId: string) => Promise<Map<string, {
|
|
4
|
+
hlc: string;
|
|
5
|
+
nodeId: string;
|
|
6
|
+
}>>;
|
|
7
|
+
/**
|
|
8
|
+
* Resolves a conflict column by column, and returns a merged row with both sides' changes when the two sides changed different columns.
|
|
9
|
+
*
|
|
10
|
+
* The resolver compares the local row and the remote row with the remote
|
|
11
|
+
* change's `oldData` to find the columns that each side changed. When the two
|
|
12
|
+
* sets share no column, the resolver returns one row that holds both sides'
|
|
13
|
+
* changes. For each column that both sides changed, the resolver compares the
|
|
14
|
+
* remote HLC with that column's stamp from `getColumnVersions`, and it takes
|
|
15
|
+
* the remote value when the remote stamp is higher, or equal with a higher
|
|
16
|
+
* node ID. When the row has no column stamps, the resolver applies whole-row
|
|
17
|
+
* {@link LWWResolver}.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
declare class FieldMergeResolver implements ConflictResolver {
|
|
22
|
+
private readonly getColumnVersions;
|
|
23
|
+
private readonly lww;
|
|
24
|
+
constructor(getColumnVersions: ColumnVersionGetter);
|
|
25
|
+
/**
|
|
26
|
+
* Returns the resolution for one conflicting row, merging changes to different columns and settling each column that both sides changed by its per-column stamp.
|
|
27
|
+
*
|
|
28
|
+
* @param ctx - The local and incoming versions of one row.
|
|
29
|
+
* @returns The version to keep, or the merged row.
|
|
30
|
+
*/
|
|
31
|
+
resolve(ctx: ConflictContext): Promise<ConflictResolution>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Resolves a conflict by keeping the write with the higher hybrid logical clock (HLC) timestamp.
|
|
36
|
+
*
|
|
37
|
+
* The resolver accepts every remote delete without comparing timestamps, so a
|
|
38
|
+
* delete wins over a concurrent update. It also accepts the remote write
|
|
39
|
+
* when the local row has no timestamp. When the two timestamps are equal, the
|
|
40
|
+
* resolver accepts the remote write only if its node ID sorts higher, so that
|
|
41
|
+
* every node reaches the same resolution without coordination. Sirannon uses
|
|
42
|
+
* this resolver by default, and {@link PrimaryWinsResolver} and
|
|
43
|
+
* {@link FieldMergeResolver} fall back to it.
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
declare class LWWResolver implements ConflictResolver {
|
|
48
|
+
/**
|
|
49
|
+
* Returns the incoming row when its stamp is higher, and the local row otherwise.
|
|
50
|
+
*
|
|
51
|
+
* @param ctx - The local and incoming versions of one row.
|
|
52
|
+
* @returns Which version to write.
|
|
53
|
+
*/
|
|
54
|
+
resolve(ctx: ConflictContext): ConflictResolution;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Resolves a conflict in favour of the node that you name as primary.
|
|
59
|
+
*
|
|
60
|
+
* The resolver accepts a remote change that the primary wrote, and it keeps a
|
|
61
|
+
* local change that the primary wrote. When neither change comes from the
|
|
62
|
+
* primary, as with two replicas that sync through a relay, the resolver falls
|
|
63
|
+
* back to {@link LWWResolver}. Use it in a primary-replica topology where the
|
|
64
|
+
* primary's write always wins over a replica's.
|
|
65
|
+
*
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
declare class PrimaryWinsResolver implements ConflictResolver {
|
|
69
|
+
private readonly primaryNodeId;
|
|
70
|
+
private readonly lww;
|
|
71
|
+
constructor(primaryNodeId: string);
|
|
72
|
+
/**
|
|
73
|
+
* Returns the version that the primary node wrote, or the last-writer-wins result when neither version comes from the primary.
|
|
74
|
+
*
|
|
75
|
+
* @param ctx - The local and incoming versions of one row.
|
|
76
|
+
* @returns Which version to write.
|
|
77
|
+
*/
|
|
78
|
+
resolve(ctx: ConflictContext): ConflictResolution;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { FieldMergeResolver as F, LWWResolver as L, PrimaryWinsResolver as P };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { W as WriteConcern, R as ReadConcern, E as ExecuteResult } from './query-types-5B02ixH0.js';
|
|
2
|
+
import { B as BulkLoadDurability, a as BulkLoadResult } from './server-options-aYtCkefX.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Body of `POST /db/{id}/query`.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
interface QueryRequest {
|
|
10
|
+
/** The statement to execute. */
|
|
11
|
+
sql: string;
|
|
12
|
+
/** The values to bind to the statement, by name or by position. */
|
|
13
|
+
params?: Record<string, unknown> | unknown[];
|
|
14
|
+
/** The read concern that 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 execute. */
|
|
24
|
+
sql: string;
|
|
25
|
+
/** The values to bind to the statement, by name or by position. */
|
|
26
|
+
params?: Record<string, unknown> | unknown[];
|
|
27
|
+
/** The acknowledgements that the server waits for before it confirms this write. */
|
|
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 execute. */
|
|
37
|
+
sql: string;
|
|
38
|
+
/** The values to bind to the statement, by name or by position. */
|
|
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 execute, in order. */
|
|
48
|
+
statements: TransactionStatement[];
|
|
49
|
+
/** The acknowledgements that the server waits for before it confirms the transaction. */
|
|
50
|
+
writeConcern?: WriteConcern;
|
|
51
|
+
}
|
|
52
|
+
/** The body of `POST /db/{id}/batch`, which the server commits atomically in one transaction with one fsync.
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
interface BatchRequest {
|
|
56
|
+
/** The statement to execute for each parameter set. */
|
|
57
|
+
sql: string;
|
|
58
|
+
/** One parameter set for each execution of the statement. */
|
|
59
|
+
paramsBatch: (Record<string, unknown> | unknown[])[];
|
|
60
|
+
/** The acknowledgements that the server waits for before it confirms the batch. */
|
|
61
|
+
writeConcern?: WriteConcern;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The body that a read route returns.
|
|
65
|
+
*
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
interface QueryResponse {
|
|
69
|
+
/** The rows that the statement returned, with blobs and large integers in their tagged wire form. */
|
|
70
|
+
rows: Record<string, unknown>[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The body that a write route returns.
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
interface ExecuteResponse {
|
|
78
|
+
/** The number of rows that the statement inserted, updated, or deleted. */
|
|
79
|
+
changes: number;
|
|
80
|
+
/** The row id that SQLite assigned to the last inserted row, as a decimal string when it exceeds the safe integer range. */
|
|
81
|
+
lastInsertRowId: number | string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The body that a transaction route returns.
|
|
85
|
+
*
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
interface TransactionResponse {
|
|
89
|
+
/** One result per statement, in the order that the transaction executed them. */
|
|
90
|
+
results: ExecuteResponse[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The body that a batch route returns.
|
|
94
|
+
*
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
interface BatchResponse {
|
|
98
|
+
/** One result per parameter set, in order. */
|
|
99
|
+
results: ExecuteResponse[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The body of `POST /db/{id}/load`, which loads rows while the server relaxes the
|
|
103
|
+
* writer's durability. The server restores the configured durability before it
|
|
104
|
+
* sends the response. When the process crashes during a load, SQLite rolls back the
|
|
105
|
+
* uncommitted rows, so the client can send the load again.
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
interface LoadRequest {
|
|
110
|
+
/** The statement to execute for each parameter set. */
|
|
111
|
+
sql: string;
|
|
112
|
+
/** One parameter set per row. */
|
|
113
|
+
paramsBatch: (Record<string, unknown> | unknown[])[];
|
|
114
|
+
/** The writer's durability level during the load. Defaults to 'off'. */
|
|
115
|
+
durability?: BulkLoadDurability;
|
|
116
|
+
/** Whether the server checkpoints the WAL after this load. Defaults to true, so set it to false on every batch except the last of a multi-batch import. */
|
|
117
|
+
checkpoint?: boolean;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* How many rows a bulk load applied and how many rows changed.
|
|
121
|
+
*
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
type LoadResponse = BulkLoadResult;
|
|
125
|
+
interface AckResponse {
|
|
126
|
+
acked: boolean;
|
|
127
|
+
seq: string;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The body that every failed route returns.
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
interface ErrorResponse {
|
|
135
|
+
/** A machine-readable code, a human-readable message, and any details that the route adds. */
|
|
136
|
+
error: {
|
|
137
|
+
code: string;
|
|
138
|
+
message: string;
|
|
139
|
+
details?: Record<string, unknown>;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Converts a write result into its wire form, and encodes a row id beyond the
|
|
144
|
+
* safe integer range as a decimal string.
|
|
145
|
+
*
|
|
146
|
+
* @param result - The result that the local write returns.
|
|
147
|
+
* @returns The result in its wire form.
|
|
148
|
+
*
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
declare function toExecuteResponse(result: ExecuteResult): ExecuteResponse;
|
|
152
|
+
|
|
153
|
+
export { type AckResponse as A, type BatchResponse as B, type ExecuteResponse as E, type LoadResponse as L, type QueryResponse as Q, type TransactionResponse as T, type TransactionStatement 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,129 @@
|
|
|
1
|
+
/** The values to bind to a statement, as an object for named parameters or an array for positional ones.
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
type Params = Record<string, unknown> | unknown[];
|
|
5
|
+
/** Which nodes must acknowledge a write before the call returns.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
type WriteConcernLevel = 'local' | 'majority' | 'all';
|
|
9
|
+
/** Which nodes must acknowledge a write, and how long the caller waits for their acknowledgements.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
interface WriteConcern {
|
|
13
|
+
/** Which nodes must acknowledge the write before the call returns. */
|
|
14
|
+
level: WriteConcernLevel;
|
|
15
|
+
/** The number of milliseconds to wait for those acknowledgements before the call fails. */
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
}
|
|
18
|
+
/** How current the data must be before a node serves a read.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
type ReadConcernLevel = 'local' | 'majority' | 'linearizable';
|
|
22
|
+
/** How current the data must be before a node serves a read.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
interface ReadConcern {
|
|
26
|
+
/** The level that the node must confirm before it responds. */
|
|
27
|
+
level: ReadConcernLevel;
|
|
28
|
+
}
|
|
29
|
+
/** Per-statement settings that you pass with the SQL and its parameters.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
interface QueryOptions {
|
|
33
|
+
/** The acknowledgements that a write waits for; in coordinator mode, the replication engine applies 'majority' when you omit it. */
|
|
34
|
+
writeConcern?: WriteConcern;
|
|
35
|
+
/** How current the data must be for a read; in coordinator mode, the replication engine enforces it and applies 'majority' when you omit it, while in static mode the engine ignores the setting. */
|
|
36
|
+
readConcern?: ReadConcern;
|
|
37
|
+
}
|
|
38
|
+
/** The result of a write statement such as INSERT, UPDATE, or DELETE.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
interface ExecuteResult {
|
|
42
|
+
/** The number of rows that the statement inserted, updated, or deleted. */
|
|
43
|
+
changes: number;
|
|
44
|
+
/** The row id that SQLite assigned to the last inserted row. */
|
|
45
|
+
lastInsertRowId: number | bigint;
|
|
46
|
+
}
|
|
47
|
+
/** The kind of change that a change event records.
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
type ChangeOperation = 'insert' | 'update' | 'delete';
|
|
51
|
+
/** The event that Sirannon delivers when a row in a watched table changes.
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
interface ChangeEvent<T = Record<string, unknown>> {
|
|
55
|
+
/** Whether the change inserted, updated, or deleted the row. */
|
|
56
|
+
type: ChangeOperation;
|
|
57
|
+
/** The table that contains the row. */
|
|
58
|
+
table: string;
|
|
59
|
+
/** The row after the change; for a delete, this is an empty object and {@link ChangeEvent.oldRow} contains the previous row. */
|
|
60
|
+
row: T;
|
|
61
|
+
/** The row before an update or a delete. */
|
|
62
|
+
oldRow?: T;
|
|
63
|
+
/** The position of this change in the database's change log, which a subscriber resumes from. */
|
|
64
|
+
seq: bigint;
|
|
65
|
+
/** The time when Sirannon recorded the change, in milliseconds since the Unix epoch. */
|
|
66
|
+
timestamp: number;
|
|
67
|
+
/** The hybrid logical clock stamp that the writing node gave this change. */
|
|
68
|
+
hlc?: string;
|
|
69
|
+
/** The identifier of the node that wrote the change. */
|
|
70
|
+
origin?: string;
|
|
71
|
+
/** The primary key of the changed row, encoded as a string. */
|
|
72
|
+
rowId?: string;
|
|
73
|
+
/** The identifier of the transaction that made this change. */
|
|
74
|
+
txId?: string;
|
|
75
|
+
/** True on the last change of a transaction, so that a consumer can apply the whole transaction at once. */
|
|
76
|
+
txEnd?: boolean;
|
|
77
|
+
}
|
|
78
|
+
/** Builds a change subscription with an optional filter.
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
interface SubscriptionBuilder {
|
|
82
|
+
/**
|
|
83
|
+
* Narrows the subscription to rows whose columns equal the given values.
|
|
84
|
+
*
|
|
85
|
+
* Sirannon delivers an update that moves a row into the matching set as an
|
|
86
|
+
* insert with no `oldRow`, and an update that moves a row out of the set as a
|
|
87
|
+
* delete with the old row and an empty `row`. It delivers an update that keeps
|
|
88
|
+
* the row in the set unchanged, and no event for an update whose row is
|
|
89
|
+
* outside the set both before and after. A synthesised event looks the same as
|
|
90
|
+
* a real insert or delete, so read `type` as the row entering or leaving the
|
|
91
|
+
* filter.
|
|
92
|
+
*/
|
|
93
|
+
filter(conditions: Record<string, unknown>): SubscriptionBuilder;
|
|
94
|
+
/**
|
|
95
|
+
* Starts the subscription and calls the callback for each matching change.
|
|
96
|
+
*
|
|
97
|
+
* Sirannon never awaits the promise that your callback returns, so two calls to
|
|
98
|
+
* an asynchronous callback can overlap; chain the work onto one promise when
|
|
99
|
+
* each change has to finish before the next one starts. Sirannon passes a throw
|
|
100
|
+
* or a rejection from the callback to `options.onError`, and still delivers the
|
|
101
|
+
* change to every other subscriber on this table.
|
|
102
|
+
*
|
|
103
|
+
* @typeParam T - The shape of the table's rows, which types `row` and `oldRow`.
|
|
104
|
+
* @param callback - The function that Sirannon calls with each change that this subscription matches.
|
|
105
|
+
* @param options - The subscription options, including `onError`, which Sirannon calls with a failure of the callback or of the change-log poll.
|
|
106
|
+
* @returns A handle whose `unsubscribe` ends the subscription.
|
|
107
|
+
*/
|
|
108
|
+
subscribe<T = Record<string, unknown>>(callback: (event: ChangeEvent<T>) => void, options?: SubscriptionOptions): Subscription;
|
|
109
|
+
}
|
|
110
|
+
/** The failure reporter for a change subscription.
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
113
|
+
interface SubscriptionOptions {
|
|
114
|
+
/**
|
|
115
|
+
* Sirannon calls this with the failure of a change callback, and with the
|
|
116
|
+
* failure that stops the change-log poll after ten consecutive errors.
|
|
117
|
+
* Sirannon discards anything that this reporter throws.
|
|
118
|
+
*/
|
|
119
|
+
onError?: (error: Error) => void;
|
|
120
|
+
}
|
|
121
|
+
/** The handle of an active subscription.
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
interface Subscription {
|
|
125
|
+
/** Ends the subscription, after which Sirannon delivers no further events to the callback. */
|
|
126
|
+
unsubscribe(): void;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export type { ChangeEvent as C, ExecuteResult as E, Params as P, QueryOptions as Q, ReadConcern as R, Subscription as S, WriteConcern as W, ReadConcernLevel as a, ChangeOperation as b, SubscriptionBuilder as c, SubscriptionOptions as d, WriteConcernLevel as e };
|