@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,8 +1,8 @@
|
|
|
1
1
|
import { startCopyWithoutHoldingWriter } from './chunk-W67A4H2E.mjs';
|
|
2
|
-
import { readLogPosition } from './chunk-
|
|
3
|
-
import { destinationWithDeadline, DEFAULT_DESTINATION_TIMEOUT_MS, assertDeadline, withinDeadline, reportQuietly } from './chunk-
|
|
2
|
+
import { readLogPosition } from './chunk-KJLNYOOL.mjs';
|
|
3
|
+
import { destinationWithDeadline, DEFAULT_DESTINATION_TIMEOUT_MS, assertDeadline, withinDeadline, reportQuietly } from './chunk-R7GBXNTO.mjs';
|
|
4
4
|
import { randomHex, invokeCallerCallback } from './chunk-QBBLSQHQ.mjs';
|
|
5
|
-
import { BackupError, SirannonError } from './chunk-
|
|
5
|
+
import { BackupError, SirannonError } from './chunk-KINDFBQP.mjs';
|
|
6
6
|
import { existsSync, mkdirSync, statSync, readdirSync, lstatSync, rmSync } from 'fs';
|
|
7
7
|
import { resolve, dirname, join, basename, extname } from 'path';
|
|
8
8
|
import { open, mkdtemp, rm } from 'fs/promises';
|
|
@@ -367,12 +367,12 @@ var BackupStreamHost = class _BackupStreamHost {
|
|
|
367
367
|
this.statements = statements;
|
|
368
368
|
}
|
|
369
369
|
/**
|
|
370
|
-
* Opens a connection, loads the compiled extension into it, and
|
|
371
|
-
* statements one
|
|
370
|
+
* Opens a connection, loads the compiled extension into it, and prepares the
|
|
371
|
+
* statements that one backup needs.
|
|
372
372
|
*
|
|
373
|
-
* @param openConnection - Opens the connection the statements
|
|
374
|
-
* @param extensionPath -
|
|
375
|
-
* @returns A host ready to open a stream.
|
|
373
|
+
* @param openConnection - Opens the connection that Sirannon runs the statements on.
|
|
374
|
+
* @param extensionPath - The absolute path of the compiled extension.
|
|
375
|
+
* @returns A host that is ready to open a stream.
|
|
376
376
|
*/
|
|
377
377
|
static async start(openConnection, extensionPath) {
|
|
378
378
|
const connection = await openConnection();
|
|
@@ -391,13 +391,13 @@ var BackupStreamHost = class _BackupStreamHost {
|
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
393
|
/**
|
|
394
|
-
* Opens one stream and returns the identifier that
|
|
394
|
+
* Opens one stream and returns the identifier that appears in the
|
|
395
395
|
* destination URI.
|
|
396
396
|
*
|
|
397
|
-
* @param pieceBytes -
|
|
398
|
-
* @param maxQueuedPieces -
|
|
399
|
-
* @param waitWhenFull - Whether the copy
|
|
400
|
-
* @param stoppedTakerMicroseconds -
|
|
397
|
+
* @param pieceBytes - The size of one whole piece, in bytes.
|
|
398
|
+
* @param maxQueuedPieces - The number of queued pieces at which the extension pauses the copy, when `waitWhenFull` is true.
|
|
399
|
+
* @param waitWhenFull - Whether the extension pauses the copy while the queue is full. When false, the extension queues every piece without a limit.
|
|
400
|
+
* @param stoppedTakerMicroseconds - The time in microseconds without a report from {@link BackupStreamHost.reportStillTaking} after which the extension lets one piece past the full queue.
|
|
401
401
|
* @returns The identifier of the open stream.
|
|
402
402
|
*/
|
|
403
403
|
async open(pieceBytes, maxQueuedPieces, waitWhenFull, stoppedTakerMicroseconds) {
|
|
@@ -413,65 +413,65 @@ var BackupStreamHost = class _BackupStreamHost {
|
|
|
413
413
|
return streamId;
|
|
414
414
|
}
|
|
415
415
|
/**
|
|
416
|
-
* Takes the next whole piece the copy
|
|
416
|
+
* Takes the next whole piece of the copy from the queue.
|
|
417
417
|
*
|
|
418
|
-
* @param streamId -
|
|
419
|
-
* @returns The piece, or null where the
|
|
418
|
+
* @param streamId - The stream to take from.
|
|
419
|
+
* @returns The piece, or null where the queue is empty.
|
|
420
420
|
*/
|
|
421
421
|
async take(streamId) {
|
|
422
422
|
const framed = await this.statements.selectNextPiece(streamId);
|
|
423
423
|
return framed ? decodePiece(framed) : null;
|
|
424
424
|
}
|
|
425
425
|
/**
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
* step. The extension therefore lets one
|
|
430
|
-
* reports stop
|
|
426
|
+
* Tells the extension that Sirannon is still taking pieces. SQLite holds the
|
|
427
|
+
* lock of the database for a whole copy step, so if Sirannon stopped taking
|
|
428
|
+
* pieces while the copy waited on a full queue, every other statement on that
|
|
429
|
+
* database would wait behind that step. The extension therefore lets one
|
|
430
|
+
* piece past the full queue once these reports stop.
|
|
431
431
|
*
|
|
432
|
-
* @param streamId -
|
|
433
|
-
* @returns The pieces the
|
|
432
|
+
* @param streamId - The stream to report on.
|
|
433
|
+
* @returns The number of pieces in the queue.
|
|
434
434
|
*/
|
|
435
435
|
reportStillTaking(streamId) {
|
|
436
436
|
return this.statements.selectQueuedPieces(streamId);
|
|
437
437
|
}
|
|
438
438
|
/**
|
|
439
|
-
*
|
|
439
|
+
* Returns the number of bytes that SQLite has written to a stream.
|
|
440
440
|
*
|
|
441
|
-
* @param streamId -
|
|
442
|
-
* @returns
|
|
441
|
+
* @param streamId - The stream to query.
|
|
442
|
+
* @returns The number of bytes that SQLite has written to this stream.
|
|
443
443
|
*/
|
|
444
444
|
written(streamId) {
|
|
445
445
|
return this.statements.selectBytesWritten(streamId);
|
|
446
446
|
}
|
|
447
447
|
/**
|
|
448
|
-
*
|
|
448
|
+
* Returns the failure that stopped a stream, if any.
|
|
449
449
|
*
|
|
450
|
-
* @param streamId -
|
|
451
|
-
* @returns The failure the extension recorded, or null where it recorded none.
|
|
450
|
+
* @param streamId - The stream to query.
|
|
451
|
+
* @returns The failure that the extension recorded, or null where it recorded none.
|
|
452
452
|
*/
|
|
453
453
|
failure(streamId) {
|
|
454
454
|
return this.statements.selectFailure(streamId);
|
|
455
455
|
}
|
|
456
456
|
/**
|
|
457
|
-
* Closes the file to further writes and queues the pieces the
|
|
458
|
-
* still
|
|
457
|
+
* Closes the file to further writes and queues the two pieces that the
|
|
458
|
+
* extension still holds, which are the first piece and the most recent one.
|
|
459
459
|
*
|
|
460
|
-
* @param streamId -
|
|
461
|
-
* @returns
|
|
460
|
+
* @param streamId - The stream to finish.
|
|
461
|
+
* @returns The size of the finished file, in bytes.
|
|
462
462
|
*/
|
|
463
463
|
finish(streamId) {
|
|
464
464
|
return this.statements.selectFinishedBytes(streamId);
|
|
465
465
|
}
|
|
466
466
|
/**
|
|
467
|
-
* Releases a stream and
|
|
467
|
+
* Releases a stream and every piece that it still holds.
|
|
468
468
|
*
|
|
469
|
-
* @param streamId -
|
|
469
|
+
* @param streamId - The stream to release.
|
|
470
470
|
*/
|
|
471
471
|
async close(streamId) {
|
|
472
472
|
await this.statements.selectReleasedBytes(streamId);
|
|
473
473
|
}
|
|
474
|
-
/** Closes the connection the statements
|
|
474
|
+
/** Closes the connection that Sirannon runs the statements on. */
|
|
475
475
|
async stop() {
|
|
476
476
|
await this.connection.close();
|
|
477
477
|
}
|
|
@@ -705,13 +705,13 @@ var BackupManager = class {
|
|
|
705
705
|
this.streaming = streaming;
|
|
706
706
|
}
|
|
707
707
|
/**
|
|
708
|
-
* Copies the database
|
|
709
|
-
*
|
|
708
|
+
* Copies the database that a connection has open to a file, while other
|
|
709
|
+
* callers go on reading from and writing to that database.
|
|
710
710
|
*
|
|
711
|
-
* @param conn -
|
|
712
|
-
* @param destPath -
|
|
713
|
-
* @param onFirstStep - Called once the
|
|
714
|
-
* @returns
|
|
711
|
+
* @param conn - The writer connection, which SQLite runs the copy on.
|
|
712
|
+
* @param destPath - The path to write the copy to. Sirannon refuses a path where a file already exists.
|
|
713
|
+
* @param onFirstStep - Called once after the first step of the copy, so that the caller can release the writer.
|
|
714
|
+
* @returns The pages that SQLite copies, the time that the copy takes, and the number of times that SQLite restarts it from page one.
|
|
715
715
|
*/
|
|
716
716
|
async backup(conn, destPath, onFirstStep) {
|
|
717
717
|
if (hasControlCharacters(destPath)) {
|
|
@@ -757,11 +757,11 @@ var BackupManager = class {
|
|
|
757
757
|
};
|
|
758
758
|
}
|
|
759
759
|
/**
|
|
760
|
-
* Reads the size of the file a copy
|
|
760
|
+
* Reads the size of the file that a copy writes.
|
|
761
761
|
*
|
|
762
|
-
* @param resolved -
|
|
763
|
-
* @param destPath -
|
|
764
|
-
* @returns
|
|
762
|
+
* @param resolved - The absolute path of that file.
|
|
763
|
+
* @param destPath - The path that the caller names, which Sirannon quotes in any error.
|
|
764
|
+
* @returns The size of the file, in bytes.
|
|
765
765
|
*/
|
|
766
766
|
fileBytes(resolved, destPath) {
|
|
767
767
|
try {
|
|
@@ -771,17 +771,16 @@ var BackupManager = class {
|
|
|
771
771
|
}
|
|
772
772
|
}
|
|
773
773
|
/**
|
|
774
|
-
* Runs the copy
|
|
775
|
-
*
|
|
776
|
-
*
|
|
777
|
-
*
|
|
778
|
-
* one nothing can restore.
|
|
774
|
+
* Runs the copy and deletes its file when the copy fails, so that a partly
|
|
775
|
+
* written database never stays on disk. Rotation would otherwise count that
|
|
776
|
+
* file among the copies it keeps, and it would delete a complete copy to make
|
|
777
|
+
* room for it.
|
|
779
778
|
*
|
|
780
|
-
* Sirannon stops waiting on
|
|
781
|
-
*
|
|
782
|
-
* leave a truncated file in place, and on Windows
|
|
783
|
-
* Sirannon therefore
|
|
784
|
-
*
|
|
779
|
+
* When the stall deadline passes, Sirannon stops waiting on the copy while
|
|
780
|
+
* SQLite goes on writing to the file. Deleting the file under a live copy
|
|
781
|
+
* would leave a truncated file in place, and on Windows the delete would fail.
|
|
782
|
+
* Sirannon therefore deletes the file once the copy stops, although the caller
|
|
783
|
+
* receives the failure straight away.
|
|
785
784
|
*/
|
|
786
785
|
async copyOrClearUp(conn, resolved, destPath, onFirstStep) {
|
|
787
786
|
const abandoned = { copy: null };
|
|
@@ -1155,8 +1154,8 @@ var BackupScheduler = class {
|
|
|
1155
1154
|
/**
|
|
1156
1155
|
* Starts repeating backups and returns a function that stops them.
|
|
1157
1156
|
*
|
|
1158
|
-
* @param conn -
|
|
1159
|
-
* @param request -
|
|
1157
|
+
* @param conn - The connection to the database that Sirannon copies.
|
|
1158
|
+
* @param request - The cron expression, destination directory, retention, and time zone, with the callbacks and the details of the source database.
|
|
1160
1159
|
* @returns A function that stops the schedule.
|
|
1161
1160
|
*/
|
|
1162
1161
|
schedule(conn, request) {
|
|
@@ -1191,16 +1190,17 @@ var BackupScheduler = class {
|
|
|
1191
1190
|
return this.run(conn, { ...request, cron, resolvedDir, maxFiles, timezone, onBackupTimeoutMs });
|
|
1192
1191
|
}
|
|
1193
1192
|
/**
|
|
1194
|
-
*
|
|
1195
|
-
*
|
|
1196
|
-
*
|
|
1197
|
-
*
|
|
1193
|
+
* Returns the database identifier and the source file that every report
|
|
1194
|
+
* names. The caller can supply either of them. Where the caller names no
|
|
1195
|
+
* source file, Sirannon reads the path of the file that SQLite has open, and
|
|
1196
|
+
* it runs that query on the writer connection while no other operation holds
|
|
1197
|
+
* the writer.
|
|
1198
1198
|
*
|
|
1199
|
-
* @param conn -
|
|
1200
|
-
* @param run - The schedule, which holds whichever of the two the caller
|
|
1201
|
-
* @param runExclusive - Runs the
|
|
1202
|
-
* @returns The database identifier and the path of the file
|
|
1203
|
-
* @throws A `BACKUP_ERROR` where the caller
|
|
1199
|
+
* @param conn - The connection that Sirannon copies from.
|
|
1200
|
+
* @param run - The schedule, which holds whichever of the two the caller names.
|
|
1201
|
+
* @param runExclusive - Runs the query while no other operation holds the writer.
|
|
1202
|
+
* @returns The database identifier and the path of the source file.
|
|
1203
|
+
* @throws A `BACKUP_ERROR` where the caller names no source file and SQLite reports no file open on the connection.
|
|
1204
1204
|
*/
|
|
1205
1205
|
async namesFor(conn, run, runExclusive) {
|
|
1206
1206
|
if (run.databaseId !== void 0 && run.sourcePath !== void 0) {
|
|
@@ -1220,10 +1220,11 @@ var BackupScheduler = class {
|
|
|
1220
1220
|
return { databaseId: run.databaseId ?? basename(sourcePath, extname(sourcePath)), sourcePath };
|
|
1221
1221
|
}
|
|
1222
1222
|
/**
|
|
1223
|
-
* Passes one finished copy to the
|
|
1224
|
-
*
|
|
1223
|
+
* Passes the report of one finished copy to the completion callback of the
|
|
1224
|
+
* caller, and fails with `BACKUP_ERROR` once the deadline of that callback
|
|
1225
|
+
* passes. A deadline of zero waits for the callback without a limit.
|
|
1225
1226
|
*
|
|
1226
|
-
* @param report -
|
|
1227
|
+
* @param report - The report of the finished copy.
|
|
1227
1228
|
* @param run - The schedule, which holds the callback and its deadline.
|
|
1228
1229
|
*/
|
|
1229
1230
|
async handToCaller(report, run) {
|