@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.
Files changed (108) hide show
  1. package/README.md +79 -56
  2. package/dist/backup/index.d.ts +44 -45
  3. package/dist/backup/index.mjs +7 -7
  4. package/dist/backup-scheduler/index.d.ts +42 -41
  5. package/dist/backup-scheduler/index.mjs +4 -4
  6. package/dist/baseline-Co3iIsN_.d.ts +19 -0
  7. package/dist/change-tracker-DqCdeEyx.d.ts +128 -0
  8. package/dist/{chunk-VOSJBZ6Q.mjs → chunk-2ES3DT4A.mjs} +71 -33
  9. package/dist/{chunk-6CMCO7S4.mjs → chunk-2O3PP4CF.mjs} +1 -1
  10. package/dist/{chunk-E7Q7HE46.mjs → chunk-3BZLZ47R.mjs} +26 -26
  11. package/dist/chunk-4KASJKKK.mjs +2501 -0
  12. package/dist/{chunk-MYNI2WFS.mjs → chunk-52XW3Z76.mjs} +40 -8
  13. package/dist/chunk-55YRLSM2.mjs +57 -0
  14. package/dist/{chunk-KDAHYFW7.mjs → chunk-6AOJCNRU.mjs} +5 -5
  15. package/dist/{chunk-KXTYR2OQ.mjs → chunk-A3PHCO6W.mjs} +39 -111
  16. package/dist/chunk-ADNWEHGZ.mjs +299 -0
  17. package/dist/{chunk-2QLXDHAP.mjs → chunk-BLMRNSUG.mjs} +11 -2
  18. package/dist/chunk-BVMZJOVM.mjs +5 -0
  19. package/dist/{chunk-IWGIYDMZ.mjs → chunk-BZWDPF4G.mjs} +1 -1
  20. package/dist/{chunk-YVF2ZJTE.mjs → chunk-CZL4D3BM.mjs} +1 -1
  21. package/dist/{chunk-7SC2TZAS.mjs → chunk-DX4WGJL7.mjs} +2 -2
  22. package/dist/{chunk-45MKELYA.mjs → chunk-ESTZZPT5.mjs} +132 -13
  23. package/dist/{chunk-QP5L5DFJ.mjs → chunk-FJPR2CJX.mjs} +3 -3
  24. package/dist/chunk-HR7K3GZW.mjs +36 -0
  25. package/dist/{chunk-LXCGPZPA.mjs → chunk-IEKIYO4V.mjs} +1 -1
  26. package/dist/{chunk-TUD5CJ76.mjs → chunk-KB4OLJAD.mjs} +26 -19
  27. package/dist/{chunk-PBRXXISQ.mjs → chunk-KINDFBQP.mjs} +3 -2
  28. package/dist/{chunk-E6IMX7RS.mjs → chunk-KJLNYOOL.mjs} +2 -2
  29. package/dist/{chunk-BTTFW4Z4.mjs → chunk-KU32OT4H.mjs} +2 -10
  30. package/dist/{chunk-JQWGHSEH.mjs → chunk-NVSQ2T5Q.mjs} +71 -70
  31. package/dist/{chunk-W4EUTJNT.mjs → chunk-NZGSDALX.mjs} +94 -96
  32. package/dist/{chunk-U445A3C4.mjs → chunk-QGVRRKB2.mjs} +1 -1
  33. package/dist/{chunk-GYCEJNU4.mjs → chunk-R7GBXNTO.mjs} +1 -1
  34. package/dist/{chunk-7C36BCSN.mjs → chunk-VDN6FHU4.mjs} +1 -1
  35. package/dist/{chunk-6IYS4WLH.mjs → chunk-VO3ZWA2G.mjs} +142 -115
  36. package/dist/chunk-WOMADPM4.mjs +12 -0
  37. package/dist/{chunk-OUSWVNWT.mjs → chunk-YCMB6GR4.mjs} +1 -1
  38. package/dist/{chunk-YNTDOFTN.mjs → chunk-YW7IKQ7T.mjs} +1 -1
  39. package/dist/{chunk-M2BEAH5I.mjs → chunk-ZN4HI5FK.mjs} +126 -72
  40. package/dist/{chunk-SBL6GN43.mjs → chunk-ZYWI45EN.mjs} +1 -1
  41. package/dist/client/index.d.ts +135 -137
  42. package/dist/client/index.mjs +177 -82
  43. package/dist/client/topology.d.ts +31 -31
  44. package/dist/client/topology.mjs +42 -23
  45. package/dist/client-base-BxTocU1x.d.ts +398 -0
  46. package/dist/client-streams-YKANXMWO.mjs +112 -0
  47. package/dist/codegen/cli.mjs +4 -4
  48. package/dist/codegen/index.d.ts +36 -29
  49. package/dist/codegen/index.mjs +4 -4
  50. package/dist/core/index.d.ts +130 -115
  51. package/dist/core/index.mjs +387 -297
  52. package/dist/core/writer-worker.mjs +3 -3
  53. package/dist/database-CGDsXW1K.d.ts +959 -0
  54. package/dist/database-backup-DcLhxoa1.d.ts +143 -0
  55. package/dist/driver/better-sqlite3.d.ts +11 -10
  56. package/dist/driver/better-sqlite3.mjs +11 -11
  57. package/dist/driver/bun.d.ts +9 -8
  58. package/dist/driver/expo.d.ts +6 -7
  59. package/dist/driver/node.d.ts +11 -10
  60. package/dist/driver/node.mjs +13 -11
  61. package/dist/driver/wa-sqlite.d.ts +6 -6
  62. package/dist/errors-CJUkQ-KL.d.ts +199 -0
  63. package/dist/file-migrations/index.d.ts +20 -18
  64. package/dist/file-migrations/index.mjs +3 -3
  65. package/dist/forward-rpc-VRWFZXHN.mjs +44 -0
  66. package/dist/operation-registry-CGhNT-Sn.d.ts +96 -0
  67. package/dist/primary-wins-CHNOYuN7.d.ts +81 -0
  68. package/dist/protocol-DFpNNsIT.d.ts +153 -0
  69. package/dist/query-types-5B02ixH0.d.ts +129 -0
  70. package/dist/react/index.d.ts +22 -22
  71. package/dist/replication/coordinator/etcd.d.ts +37 -31
  72. package/dist/replication/coordinator/etcd.mjs +296 -131
  73. package/dist/replication/index.d.ts +201 -161
  74. package/dist/replication/index.mjs +630 -529
  75. package/dist/restore-options-CH8mE-Tb.d.ts +84 -0
  76. package/dist/server/index.d.ts +201 -191
  77. package/dist/server/index.mjs +736 -619
  78. package/dist/server-options-aYtCkefX.d.ts +317 -0
  79. package/dist/server-streams-24XL4T43.mjs +254 -0
  80. package/dist/sirannon-J3EgPVD7.d.ts +179 -0
  81. package/dist/transport/grpc.d.ts +37 -24
  82. package/dist/transport/grpc.mjs +83 -3199
  83. package/dist/transport/memory.d.ts +25 -26
  84. package/dist/transport/memory.mjs +18 -9
  85. package/dist/types-BrAiDGOb.d.ts +505 -0
  86. package/dist/types-CEJG0eFS.d.ts +88 -0
  87. package/dist/types-Dc8oWlxj.d.ts +1580 -0
  88. package/dist/types-DqODKeOq.d.ts +123 -0
  89. package/dist/types-guEKSzMr.d.ts +367 -0
  90. package/package.json +7 -7
  91. package/dist/baseline-D93hcIEE.d.ts +0 -17
  92. package/dist/change-tracker-CjRFuZdB.d.ts +0 -144
  93. package/dist/client-base-Cmd9EVme.d.ts +0 -397
  94. package/dist/database-BLQvqjsw.d.ts +0 -917
  95. package/dist/database-backup-B7oszQ2n.d.ts +0 -141
  96. package/dist/errors-Dei4GdBb.d.ts +0 -196
  97. package/dist/operation-registry-oiPuSYI6.d.ts +0 -94
  98. package/dist/primary-wins-B0np8JS3.d.ts +0 -85
  99. package/dist/protocol-HI-nY8DD.d.ts +0 -152
  100. package/dist/query-types-p1liOP-b.d.ts +0 -127
  101. package/dist/restore-options-CksYsH1l.d.ts +0 -83
  102. package/dist/server-options-Bj5iJnjx.d.ts +0 -292
  103. package/dist/sirannon-BPxC5tC2.d.ts +0 -178
  104. package/dist/types-B0EhgDbr.d.ts +0 -340
  105. package/dist/types-CbjfRwrK.d.ts +0 -499
  106. package/dist/types-CjhxcjhA.d.ts +0 -123
  107. package/dist/types-DPSmjU54.d.ts +0 -1518
  108. 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-E6IMX7RS.mjs';
3
- import { destinationWithDeadline, DEFAULT_DESTINATION_TIMEOUT_MS, assertDeadline, withinDeadline, reportQuietly } from './chunk-GYCEJNU4.mjs';
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-PBRXXISQ.mjs';
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 compiles the
371
- * statements one run needs.
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 run on.
374
- * @param extensionPath - Absolute path of the compiled extension.
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 names it in the
394
+ * Opens one stream and returns the identifier that appears in the
395
395
  * destination URI.
396
396
  *
397
- * @param pieceBytes - Bytes one whole piece holds.
398
- * @param maxQueuedPieces - Pieces the extension holds before it stops taking more.
399
- * @param waitWhenFull - Whether the copy waits for the destination to catch up rather than queueing further pieces.
400
- * @param stoppedTakerMicroseconds - How long the extension waits without a report from {@link BackupStreamHost.reportStillTaking} before it lets a piece through anyway.
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 has produced.
416
+ * Takes the next whole piece of the copy from the queue.
417
417
  *
418
- * @param streamId - Stream to take from.
419
- * @returns The piece, or null where the copy has produced none since the last call.
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
- * Reports that this run is still taking pieces. SQLite holds the database's
427
- * own lock for the whole of a copy step, so a run that stopped reporting
428
- * would leave every other statement on that database waiting behind that
429
- * step. The extension therefore lets one piece past its cap once these
430
- * reports stop arriving.
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 - Stream to report against.
433
- * @returns The pieces the extension is holding.
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
- * Reports how many bytes of the copy have reached the extension.
439
+ * Returns the number of bytes that SQLite has written to a stream.
440
440
  *
441
- * @param streamId - Stream to ask about.
442
- * @returns Bytes SQLite has written to this stream.
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
- * Reports what stopped a stream, where anything did.
448
+ * Returns the failure that stopped a stream, if any.
449
449
  *
450
- * @param streamId - Stream to ask about.
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 extension was
458
- * still holding, which are the first piece and the last one.
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 - Stream to finish.
461
- * @returns Bytes the finished file holds.
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 everything it still held.
467
+ * Releases a stream and every piece that it still holds.
468
468
  *
469
- * @param streamId - Stream to release.
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 ran on. */
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 behind a connection to a file, while that database
709
- * stays open for reads and writes.
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 - Connection the copy runs on, which must be the connection that writes.
712
- * @param destPath - Path to write the copy to. A file already there stops the copy.
713
- * @param onFirstStep - Called once the copy's first step is done, so the caller can hand the writer back.
714
- * @returns What the copy moved, how long it took, and how often it restarted.
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 wrote.
760
+ * Reads the size of the file that a copy writes.
761
761
  *
762
- * @param resolved - Absolute path of that file.
763
- * @param destPath - Path the caller named, which the error states.
764
- * @returns Bytes it holds.
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, and removes the file it was writing where that copy fails, so
775
- * that a database missing its later pages never stays on disk as though the
776
- * copy had finished. Sirannon would otherwise count that half-written file
777
- * among the copies it keeps, and it would evict a whole copy to make room for
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 a copy once the stall deadline passes, and SQLite
781
- * keeps writing that copy to the file. A removal that raced a live copy would
782
- * leave a truncated file in place, and on Windows it would fail outright.
783
- * Sirannon therefore removes the file only once the copy stops, while the
784
- * caller receives the failure at once and waits for none of that.
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 - Connection to the database being copied.
1159
- * @param request - Cron expression, destination directory, retention, and time zone, along with the callbacks and the database the copies come from.
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
- * Works out the database and the file every report names. A caller may supply
1195
- * either of them, and Sirannon reads the file SQLite has open where the caller
1196
- * named none. Sirannon puts that question to the connection that writes, so it
1197
- * asks with nothing else holding the writer.
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 - Connection the copies come from.
1200
- * @param run - The schedule, which holds whichever of the two the caller named.
1201
- * @param runExclusive - Runs the question with nothing else holding the writer.
1202
- * @returns The database identifier and the path of the file the copies come from.
1203
- * @throws A `BACKUP_ERROR` where the caller named no source file and SQLite has none open.
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 caller's completion callback, and stops
1224
- * waiting on that callback once its deadline passes.
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 - What the copy produced.
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) {