@delali/sirannon-db 0.1.8 → 0.2.1-next.18

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 (79) hide show
  1. package/README.md +117 -989
  2. package/dist/backup-scheduler/index.d.ts +15 -1
  3. package/dist/backup-scheduler/index.mjs +2 -2
  4. package/dist/baseline-D93hcIEE.d.ts +17 -0
  5. package/dist/{change-tracker-CbmaMO-N.d.ts → change-tracker-DDmXB754.d.ts} +59 -14
  6. package/dist/chunk-2QLXDHAP.mjs +18 -0
  7. package/dist/chunk-7C36BCSN.mjs +18 -0
  8. package/dist/chunk-7FQRQH5Z.mjs +654 -0
  9. package/dist/{chunk-GEZUUIKV.mjs → chunk-7R4ER4FB.mjs} +5 -2
  10. package/dist/{chunk-BNUTBHHH.mjs → chunk-BQFQ65OL.mjs} +1 -1
  11. package/dist/{chunk-H5AB6NIR.mjs → chunk-BTTFW4Z4.mjs} +2 -15
  12. package/dist/{chunk-HHRMRFFR.mjs → chunk-CCZK6LCB.mjs} +374 -150
  13. package/dist/chunk-GVCNMPOS.mjs +130 -0
  14. package/dist/{chunk-CW6S3WL5.mjs → chunk-HCCGEIZ2.mjs} +7 -5
  15. package/dist/chunk-IWGIYDMZ.mjs +90 -0
  16. package/dist/{chunk-CJLYFDP5.mjs → chunk-OUSWVNWT.mjs} +1 -1
  17. package/dist/chunk-P2VJYRVY.mjs +714 -0
  18. package/dist/{chunk-YPYVQJ4C.mjs → chunk-PBRXXISQ.mjs} +12 -1
  19. package/dist/chunk-SBL6GN43.mjs +299 -0
  20. package/dist/chunk-TUD5CJ76.mjs +126 -0
  21. package/dist/{chunk-UXLAO6ZH.mjs → chunk-UPKKSUPA.mjs} +8 -3
  22. package/dist/chunk-VOSJBZ6Q.mjs +187 -0
  23. package/dist/{chunk-VLTICJOD.mjs → chunk-VOYGMAU7.mjs} +9 -1
  24. package/dist/chunk-WJ67DTD6.mjs +1449 -0
  25. package/dist/chunk-XF2HH5E6.mjs +226 -0
  26. package/dist/client/index.d.ts +393 -299
  27. package/dist/client/index.mjs +1265 -1327
  28. package/dist/client/topology.d.ts +109 -0
  29. package/dist/client/topology.mjs +701 -0
  30. package/dist/client-base-CmZO0v3m.d.ts +343 -0
  31. package/dist/codegen/cli.d.ts +2 -0
  32. package/dist/codegen/cli.mjs +11 -0
  33. package/dist/codegen/index.d.ts +120 -0
  34. package/dist/codegen/index.mjs +5 -0
  35. package/dist/core/index.d.ts +201 -18
  36. package/dist/core/index.mjs +2783 -504
  37. package/dist/core/writer-worker.mjs +3 -3
  38. package/dist/database-B5Qv1-cU.d.ts +380 -0
  39. package/dist/driver/better-sqlite3.d.ts +18 -1
  40. package/dist/driver/better-sqlite3.mjs +5 -5
  41. package/dist/driver/bun.d.ts +28 -0
  42. package/dist/driver/expo.d.ts +17 -0
  43. package/dist/driver/node.d.ts +18 -1
  44. package/dist/driver/node.mjs +5 -5
  45. package/dist/driver/wa-sqlite.d.ts +14 -132
  46. package/dist/{errors-5Nf5ZAEC.d.ts → errors-Dei4GdBb.d.ts} +85 -8
  47. package/dist/file-migrations/index.d.ts +59 -5
  48. package/dist/file-migrations/index.mjs +42 -37
  49. package/dist/operation-registry-hlbhqu7q.d.ts +94 -0
  50. package/dist/primary-wins-B0np8JS3.d.ts +85 -0
  51. package/dist/protocol-rqANt-9Q.d.ts +152 -0
  52. package/dist/query-types-DL3LtPvY.d.ts +95 -0
  53. package/dist/react/index.d.ts +75 -0
  54. package/dist/react/index.mjs +137 -0
  55. package/dist/replication/coordinator/etcd.d.ts +66 -4
  56. package/dist/replication/coordinator/etcd.mjs +593 -465
  57. package/dist/replication/index.d.ts +355 -175
  58. package/dist/replication/index.mjs +1515 -2046
  59. package/dist/server/index.d.ts +330 -88
  60. package/dist/server/index.mjs +1895 -454
  61. package/dist/server-options-Dab_Jvd_.d.ts +275 -0
  62. package/dist/sirannon-CMhiJa5Y.d.ts +111 -0
  63. package/dist/transport/grpc.d.ts +95 -8
  64. package/dist/transport/grpc.mjs +251 -114
  65. package/dist/transport/memory.d.ts +50 -149
  66. package/dist/transport/memory.mjs +28 -1
  67. package/dist/types-BCejqzNA.d.ts +63 -0
  68. package/dist/types-CMBcFPhb.d.ts +336 -0
  69. package/dist/types-CjhxcjhA.d.ts +123 -0
  70. package/dist/types-DyrCiWuc.d.ts +499 -0
  71. package/dist/types-rVZKnKN-.d.ts +591 -0
  72. package/package.json +65 -21
  73. package/dist/chunk-TKGHYWQ6.mjs +0 -35
  74. package/dist/database-DuGp0Rtr.d.ts +0 -127
  75. package/dist/sirannon-4SspRvP5.d.ts +0 -31
  76. package/dist/types-BEu1I_9_.d.ts +0 -139
  77. package/dist/types-BsjobKbl.d.ts +0 -274
  78. package/dist/types-D4p4UyDK.d.ts +0 -26
  79. package/dist/types-D_hQW1hr.d.ts +0 -494
@@ -1,4 +1,5 @@
1
- import { e as SQLiteConnection, f as BackupScheduleOptions } from '../types-D_hQW1hr.js';
1
+ import { e as SQLiteConnection, f as BackupScheduleOptions } from '../types-rVZKnKN-.js';
2
+ import '../query-types-DL3LtPvY.js';
2
3
 
3
4
  declare class BackupManager {
4
5
  backup(conn: SQLiteConnection, destPath: string): Promise<void>;
@@ -8,9 +9,22 @@ declare class BackupManager {
8
9
 
9
10
  /** Runs a backup while the caller's writer lock is held, so it never shares the writer connection with another write. */
10
11
  type RunExclusive = (op: () => Promise<void>) => Promise<void>;
12
+ /**
13
+ * @public
14
+ *
15
+ * Repeats a database backup on a cron schedule and keeps a bounded number of files.
16
+ */
11
17
  declare class BackupScheduler {
12
18
  private readonly manager;
13
19
  constructor(manager?: BackupManager);
20
+ /**
21
+ * Starts repeating backups and returns a function that stops them.
22
+ *
23
+ * @param conn - Connection to the database being copied.
24
+ * @param options - Cron expression, destination directory, retention, time zone, and failure callback.
25
+ * @param runExclusive - Runs each copy with the database's writer held so that no write commits mid-copy.
26
+ * @returns A function that stops the schedule.
27
+ */
14
28
  schedule(conn: SQLiteConnection, options: BackupScheduleOptions, runExclusive?: RunExclusive): () => void;
15
29
  private run;
16
30
  }
@@ -1,2 +1,2 @@
1
- export { BackupScheduler } from '../chunk-VLTICJOD.mjs';
2
- import '../chunk-YPYVQJ4C.mjs';
1
+ export { BackupScheduler } from '../chunk-VOYGMAU7.mjs';
2
+ import '../chunk-PBRXXISQ.mjs';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Marks the migration an existing database starts from, so earlier versions are recorded without running.
3
+ *
4
+ * @public
5
+ */
6
+ interface BaselineFileOption {
7
+ /**
8
+ * Version of the migration carrying the baseline.
9
+ */
10
+ version: number;
11
+ /**
12
+ * Highest version this baseline covers.
13
+ */
14
+ through: number;
15
+ }
16
+
17
+ export type { BaselineFileOption as B };
@@ -1,25 +1,59 @@
1
- import { e as SQLiteConnection, C as ChangeEvent } from './types-D_hQW1hr.js';
1
+ import { e as SQLiteConnection } from './types-rVZKnKN-.js';
2
+ import { C as ChangeEvent } from './query-types-DL3LtPvY.js';
2
3
 
4
+ /**
5
+ * How long a change tracker keeps changes, and how much it reads at a time.
6
+ *
7
+ * @public
8
+ */
3
9
  interface ChangeTrackerOptions {
10
+ /**
11
+ * Milliseconds a change stays readable before it is pruned. Default: 3_600_000 (one hour).
12
+ */
4
13
  retention?: number;
14
+ /**
15
+ * Name of the table changes are recorded in.
16
+ */
5
17
  changesTable?: string;
18
+ /**
19
+ * Changes read in one poll. Default: 1000.
20
+ */
6
21
  pollBatchSize?: number;
7
- replication?: boolean;
8
22
  }
9
23
 
24
+ /**
25
+ * Records every change to the tables you watch so that subscribers and replication can read them in order.
26
+ *
27
+ * Construct one, watch the tables you want captured, and pass it to a replication engine or leave it to the database that owns it.
28
+ *
29
+ * @public
30
+ */
10
31
  declare class ChangeTracker {
11
32
  private readonly watched;
12
33
  private lastSeq;
13
34
  private readonly retentionMs;
14
35
  private readonly changesTable;
15
36
  private readonly pollBatchSize;
16
- private readonly replication;
17
37
  private changesTableReady;
38
+ private changesTableEnsured;
18
39
  private watchedTablesCache;
19
40
  private readonly stmtCache;
20
41
  private pruneBoundary;
42
+ private lastPollAtTxBoundary;
21
43
  constructor(options?: ChangeTrackerOptions);
44
+ /**
45
+ * Starts recording changes to a table by installing its change-capture triggers.
46
+ *
47
+ * @param conn - Writer connection the triggers are created on.
48
+ * @param table - Name of the table to watch.
49
+ */
22
50
  watch(conn: SQLiteConnection, table: string): Promise<void>;
51
+ /**
52
+ * Stops recording changes to a table and drops its triggers.
53
+ *
54
+ * @param conn - Writer connection the triggers are dropped from.
55
+ * @param table - Name of the table to stop watching.
56
+ */
23
57
  unwatch(conn: SQLiteConnection, table: string): Promise<void>;
24
58
  /**
25
59
  * Rebuilds CDC triggers for every watched table directly on the supplied
@@ -45,6 +79,8 @@ declare class ChangeTracker {
45
79
  * `conn`. The cached column list is updated on success.
46
80
  * - Any other error (driver failure, identifier validation failure) is
47
81
  * rethrown so the caller's transaction can roll back deterministically.
82
+ *
83
+ * @internal
48
84
  */
49
85
  refreshAllTriggersUsingConnection(conn: SQLiteConnection): Promise<void>;
50
86
  /**
@@ -66,33 +102,42 @@ declare class ChangeTracker {
66
102
  * re-installed triggers compiled against the new schema. Those triggers
67
103
  * are dropped here so the recreated table starts with a clean slate and
68
104
  * the caller must explicitly `watch` it again.
105
+ *
106
+ * @internal
69
107
  */
70
108
  pruneDroppedTables(conn: SQLiteConnection, tables: readonly string[]): Promise<void>;
109
+ /** @internal */
71
110
  poll(conn: SQLiteConnection): Promise<ChangeEvent[]>;
72
- /** The highest seq already polled; live subscribers receive events beyond it. */
111
+ /** @internal */
112
+ get pollEndedAtTxBoundary(): boolean;
113
+ /**
114
+ * The highest seq already polled; live subscribers receive events beyond it.
115
+ *
116
+ * @internal
117
+ */
73
118
  get cursor(): bigint;
119
+ /** @internal */
120
+ readSinceTables(conn: SQLiteConnection, tables: readonly string[], afterSeq: bigint, upToSeq: bigint, limit: number): Promise<ChangeEvent[]>;
74
121
  /**
75
- * Reads retained changes for one table with seq in `(afterSeq, upToSeq]`,
76
- * ordered ascending and capped at `limit`. Used to replay history to a
77
- * resuming subscriber without disturbing the shared poll cursor.
122
+ * The lowest retained seq, or `null` when the change log is empty.
123
+ *
124
+ * @internal
78
125
  */
79
- readSince(conn: SQLiteConnection, table: string, afterSeq: bigint, upToSeq: bigint, limit: number): Promise<ChangeEvent[]>;
80
- /** The lowest retained seq, or `null` when the change log is empty. */
81
126
  getMinSeq(conn: SQLiteConnection): Promise<bigint | null>;
82
- private rowToEvent;
127
+ /** @internal */
83
128
  advanceToLatest(conn: SQLiteConnection): Promise<void>;
129
+ /** @internal */
84
130
  cleanup(conn: SQLiteConnection): Promise<number>;
131
+ /** @internal */
85
132
  setPruneBoundary(seq: bigint): void;
133
+ /** @internal */
86
134
  clearPruneBoundary(): void;
135
+ /** @internal */
87
136
  get watchedTables(): ReadonlySet<string>;
88
137
  private computeSeqBound;
89
138
  private assertIdentifier;
90
139
  private detectChangesTable;
91
140
  private ensureChangesTable;
92
- private getColumns;
93
- private getPkColumns;
94
- private dropTriggers;
95
- private getStmt;
96
141
  private installTriggers;
97
142
  }
98
143
 
@@ -0,0 +1,18 @@
1
+ import { SirannonError } from './chunk-PBRXXISQ.mjs';
2
+
3
+ // src/core/sync/errors.ts
4
+ var ReplicationError = class extends SirannonError {
5
+ constructor(message, code = "REPLICATION_ERROR", details) {
6
+ super(message, code);
7
+ this.details = details;
8
+ this.name = "ReplicationError";
9
+ }
10
+ };
11
+ var BatchValidationError = class extends ReplicationError {
12
+ constructor(message) {
13
+ super(message, "BATCH_VALIDATION_ERROR");
14
+ this.name = "BatchValidationError";
15
+ }
16
+ };
17
+
18
+ export { BatchValidationError, ReplicationError };
@@ -0,0 +1,18 @@
1
+ import { MigrationError } from './chunk-PBRXXISQ.mjs';
2
+
3
+ // src/core/migrations/lazy-down.ts
4
+ var LAZY_DOWN_SQL = /* @__PURE__ */ Symbol("sirannon.file-migration.lazy-down");
5
+
6
+ // src/core/migrations/filename.ts
7
+ var MIGRATION_FILENAME_PATTERN = /^(\d+)_(\w+)\.(up|down)\.sql$/;
8
+ function parseMigrationFilename(filename) {
9
+ const match = MIGRATION_FILENAME_PATTERN.exec(filename);
10
+ if (!match) return null;
11
+ const version = parseInt(match[1], 10);
12
+ if (!Number.isFinite(version) || version <= 0 || !Number.isSafeInteger(version)) {
13
+ throw new MigrationError(`Invalid migration version: ${match[1]}`, version, "MIGRATION_VALIDATION_ERROR");
14
+ }
15
+ return { version, name: match[2], direction: match[3] };
16
+ }
17
+
18
+ export { LAZY_DOWN_SQL, MIGRATION_FILENAME_PATTERN, parseMigrationFilename };