@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,127 +0,0 @@
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 an empty object here and the previous row in {@link ChangeEvent.oldRow}. */
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
- /**
83
- * Narrows the subscription to rows whose columns equal the given values.
84
- *
85
- * The filter reports membership of the matching set, so an update that moves a row
86
- * into the set arrives as an insert carrying no `oldRow`, and one that moves a row
87
- * out arrives as a delete carrying the old row and an empty `row`. An update that
88
- * leaves the row in the set arrives unchanged, and one that never touches the set
89
- * is not delivered. A synthesised event is indistinguishable from a real insert or
90
- * delete, so read `type` as the row's arrival or departure from the filter.
91
- */
92
- filter(conditions: Record<string, unknown>): SubscriptionBuilder;
93
- /**
94
- * Starts the subscription and calls back on each change.
95
- *
96
- * The subscription never waits for what your callback returns, so two calls to an
97
- * asynchronous callback can overlap. Chain the work onto one promise where each change
98
- * has to finish before the next one starts. A throw, and a rejection of what the callback
99
- * returns, both arrive at `options.onError`, and every other subscriber on this table
100
- * still receives the change.
101
- *
102
- * @typeParam T - Shape of the rows this table holds, which types `row` and `oldRow`.
103
- * @param callback - Receives each change this subscription matches.
104
- * @param options - Carries `onError`, which receives a failure of the callback or of the change-log poll.
105
- * @returns A handle whose `unsubscribe` ends the subscription.
106
- */
107
- subscribe<T = Record<string, unknown>>(callback: (event: ChangeEvent<T>) => void, options?: SubscriptionOptions): Subscription;
108
- }
109
- /** Reporters a change subscription attaches when it starts.
110
- * @public
111
- */
112
- interface SubscriptionOptions {
113
- /**
114
- * Receives the failure of a change callback, and the failure that stops the change-log
115
- * poll after repeated errors. Sirannon drops whatever this reporter itself throws.
116
- */
117
- onError?: (error: Error) => void;
118
- }
119
- /** Handle for an active subscription.
120
- * @public
121
- */
122
- interface Subscription {
123
- /** Ends the subscription, so the callback receives no further events. */
124
- unsubscribe(): void;
125
- }
126
-
127
- 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 };
@@ -1,83 +0,0 @@
1
- import { B as BackupDestination, S as SQLiteDriver } from './types-DPSmjU54.js';
2
-
3
- /** How far one restore has got, reported after every piece it fetches.
4
- * @public
5
- */
6
- interface BackupRestoreProgress {
7
- /** Whether the restore is fetching the full copy or replaying the change pieces on top of it. */
8
- phase: 'full-copy' | 'changes';
9
- /** Pieces the restore has fetched. */
10
- piecesFetched: number;
11
- /** Bytes it has fetched. */
12
- bytesFetched: number;
13
- /** Change pieces it has replayed. */
14
- changesApplied: number;
15
- /** Change pieces the plan holds altogether. */
16
- changesTotal: number;
17
- }
18
- /**
19
- * How Sirannon rebuilds a database from a moment you name.
20
- *
21
- * @public
22
- */
23
- interface BackupRestoreOptions {
24
- /** Where the backups and their records are stored. */
25
- destination: BackupDestination;
26
- /** Driver the restore opens the rebuilt database through, so it can fold each batch of changes in. */
27
- driver: SQLiteDriver;
28
- /** Path Sirannon writes the rebuilt database to. A file already there stops the restore unless you set {@link BackupRestoreOptions.replaceExisting}. */
29
- destPath: string;
30
- /**
31
- * Whether to replace a database already at that path. It defaults to false,
32
- * because a restore removes the write-ahead log beside the path it writes to
33
- * and any commit that log still held would go with it. Set this where you
34
- * mean to restore over a database you no longer want.
35
- */
36
- replaceExisting?: boolean;
37
- /** Epoch milliseconds you want back. Defaults to now, which reaches the newest backup the destination holds. */
38
- moment?: number;
39
- /** Name the list of chains is stored under. Defaults to `sirannon-backup-chain`. */
40
- chainName?: string;
41
- /**
42
- * How many change pieces to replay between one checkpoint and the next.
43
- * Defaults to 16, and 4096 is the most it accepts. This is what bounds the
44
- * log the restore writes beside the database, so lower it where disk is tight
45
- * and raise it where a long chain takes too many checkpoints.
46
- */
47
- batchSize?: number;
48
- /** Milliseconds one call to the destination may take before the restore stops with an error. Defaults to 10 minutes, and zero leaves the calls unbounded. */
49
- destinationTimeoutMs?: number;
50
- /** Called after every piece the restore fetches. */
51
- onProgress?: (progress: BackupRestoreProgress) => void;
52
- }
53
- /** What one finished restore produced.
54
- * @public
55
- */
56
- interface BackupRestoreReport {
57
- /** The chain the restore read. */
58
- chainId: string;
59
- /** Path of the rebuilt database. */
60
- destPath: string;
61
- /** Name the full copy underneath it is stored under. */
62
- baseName: string;
63
- /** Epoch milliseconds the rebuilt database reflects, which is when the last piece replayed was captured. */
64
- restoresTo: number;
65
- /** Pieces the restore fetched, counting the full copy and every change piece. */
66
- pieceCount: number;
67
- /** Bytes it fetched. */
68
- bytesFetched: number;
69
- /** Change pieces it replayed. */
70
- changesApplied: number;
71
- /** Log frames those pieces held. */
72
- framesApplied: number;
73
- /** Batches it replayed them in, each one folded into the database by a checkpoint of its own. */
74
- batchCount: number;
75
- /** Epoch milliseconds the restore started. */
76
- startedAt: number;
77
- /** Epoch milliseconds it finished. */
78
- finishedAt: number;
79
- /** Milliseconds it took. */
80
- durationMs: number;
81
- }
82
-
83
- export type { BackupRestoreOptions as B, BackupRestoreReport as a, BackupRestoreProgress as b };
@@ -1,292 +0,0 @@
1
- import { a as OperationRegistry } from './operation-registry-oiPuSYI6.js';
2
- import { R as ReplicationBatch, C as ConflictResolver, A as ApplyResult } from './types-CjhxcjhA.js';
3
- import { N as NodeHealth, T as Transaction, H as ClusterStatusInfo } from './types-DPSmjU54.js';
4
- import { P as Params, Q as QueryOptions, E as ExecuteResult } from './query-types-p1liOP-b.js';
5
-
6
- /**
7
- * One migration a database has already applied, as its catalogue records it.
8
- *
9
- * @public
10
- */
11
- interface AppliedMigrationRow {
12
- /** Version number the migration carries. */
13
- version: number;
14
- /** Name the migration carries. */
15
- name: string;
16
- /** Hash of the SQL that applied it, and null where a function applied it or the database predates checksums. */
17
- checksum: string | null;
18
- }
19
-
20
- /** Context passed to the authenticate hook.
21
- * @public
22
- */
23
- interface RequestContext {
24
- /** Request headers, with every name lower-cased. */
25
- headers: Record<string, string>;
26
- /** HTTP method of the request, or the method of a WebSocket upgrade. */
27
- method: string;
28
- /** Path the request arrived on. */
29
- path: string;
30
- /** Identifier of the database the route addresses. */
31
- databaseId?: string;
32
- /** Address the request came from. */
33
- remoteAddress: string;
34
- }
35
- /**
36
- * Identifies the caller behind a request. Return the identity registered
37
- * operations then read, and throw a {@link RequestDeniedError} to refuse the
38
- * request with a status of your own.
39
- *
40
- * @public
41
- */
42
- type AuthenticateHook<Identity = unknown> = (ctx: RequestContext) => Identity | undefined | Promise<Identity | undefined>;
43
- /** Reports whether a caller may read the addresses of every node in the group.
44
- * @public
45
- */
46
- type ClusterStatusAuthorizer = (ctx: RequestContext) => boolean | Promise<boolean>;
47
- /**
48
- * Durability level in force while a bulk load runs. SQLite sanctions 'off' for
49
- * a from-scratch load that the operator can re-run after a power loss; 'off'
50
- * gives up corruption safety, so it fits only a load that starts from nothing.
51
- * 'normal' keeps WAL-mode corruption safety and suits loads into a database
52
- * that already holds data the operator cannot afford to lose.
53
- *
54
- * @public
55
- */
56
- type BulkLoadDurability = 'off' | 'normal';
57
- /** Settings for one bulk load.
58
- * @public
59
- */
60
- interface BulkLoadOptions {
61
- /** Durability during the load. Default: 'off'. */
62
- durability?: BulkLoadDurability;
63
- /**
64
- * Whether this load ends with a WAL checkpoint. Default: true. Set it false
65
- * on every load but the last of a multi-batch import so the one fsyncing
66
- * checkpoint is paid once at the end instead of once per batch; the
67
- * configured durability is still restored after each batch regardless, so an
68
- * abandoned import never leaves the writer at the relaxed level.
69
- */
70
- checkpoint?: boolean;
71
- }
72
- /** Aggregate outcome of a bulk load. Summed rather than per-row so a
73
- * million-row load never holds a million result objects in memory.
74
- * @public
75
- */
76
- interface BulkLoadResult {
77
- /** Number of parameter sets the load applied. */
78
- rowsLoaded: number;
79
- /** Number of rows the load inserted, updated, or deleted. */
80
- changes: number;
81
- }
82
- /**
83
- * What the server runs statements against for one database. A local
84
- * `Database` satisfies it, and so does a proxy that forwards to another node.
85
- *
86
- * @public
87
- */
88
- interface ServerExecutionTarget {
89
- /** Runs a read and returns the rows. */
90
- query<T = Record<string, unknown>>(sql: string, params?: Params, options?: QueryOptions): Promise<T[]>;
91
- /**
92
- * Optional single-pass read that returns rows already encoded for the wire
93
- * (safe-range integers as plain numbers, larger integers and BLOBs as tagged
94
- * envelopes). When present the server uses it instead of {@link ServerExecutionTarget.query}
95
- * followed by a separate tag-encoding walk. A target that omits it stays
96
- * correct: the server falls back to encoding {@link ServerExecutionTarget.query} rows itself.
97
- */
98
- queryForWire?(sql: string, params?: Params, options?: QueryOptions): Promise<unknown[]>;
99
- /** Runs one write and returns the change count and last inserted row id. */
100
- execute(sql: string, params?: Params, options?: QueryOptions): Promise<ExecuteResult>;
101
- /** Runs a function inside one transaction. */
102
- transaction<T>(fn: (tx: Transaction) => Promise<T>, options?: QueryOptions): Promise<T>;
103
- /**
104
- * Optional entry point for a transaction whose statements are all known
105
- * before it starts, which lets concurrent transactions share one commit. A
106
- * target that omits it stays correct: the server falls back to
107
- * {@link ServerExecutionTarget.transaction} and runs the statements one at a time.
108
- */
109
- executeTransaction?(statements: readonly {
110
- sql: string;
111
- params?: Params;
112
- }[], options?: QueryOptions): Promise<ExecuteResult[]>;
113
- /**
114
- * Optional bulk-load entry point. Targets that proxy to a remote primary
115
- * may omit it; the server rejects load requests for such targets instead
116
- * of silently degrading to per-statement writes.
117
- */
118
- bulkLoad?(sql: string, paramsBatch: Params[], options?: BulkLoadOptions): Promise<BulkLoadResult>;
119
- /** Optional device-sync entry point that applies a batch of changes a device pushed. */
120
- applyChanges?(batch: ReplicationBatch, resolver?: ConflictResolver | ((table: string) => ConflictResolver)): Promise<ApplyResult>;
121
- /** Optional listing of the migrations this database has applied. */
122
- appliedMigrations?(): Promise<AppliedMigrationRow[]>;
123
- }
124
- /**
125
- * Finds what the server should run a database's statements against.
126
- *
127
- * @public
128
- */
129
- type ServerExecutionTargetResolver = (databaseId: string) => ServerExecutionTarget | null | undefined | Promise<ServerExecutionTarget | null | undefined>;
130
- /** Options for the standalone HTTP + WS server.
131
- * @public
132
- */
133
- interface ServerOptions<Identity = unknown> {
134
- /** Address the server binds to. Default: '127.0.0.1'. */
135
- host?: string;
136
- /** Port the server binds to. Default: 9876. */
137
- port?: number;
138
- /** Cross-origin rules the server answers browser requests with. */
139
- cors?: boolean | CorsOptions;
140
- /**
141
- * Maximum HTTP request body and WebSocket message size in bytes. Applied
142
- * identically to both transports. Must be a positive, finite integer no
143
- * larger than 4_294_967_295 (the unsigned 32-bit ceiling uWebSockets.js can
144
- * store; larger values would silently wrap modulo 2^32).
145
- * Default: 1_048_576 (1 MB), matching the general web default and acting as
146
- * a denial-of-service guard on a memory-limited server.
147
- */
148
- maxBodyBytes?: number;
149
- /**
150
- * Maximum bytes buffered per WebSocket connection before the server stops
151
- * absorbing backpressure. A single frame can be as large as `maxBodyBytes`,
152
- * so this must hold several of them; the resolved value is raised to at
153
- * least `maxBodyBytes` and, like `maxBodyBytes`, must not exceed
154
- * 4_294_967_295. When the buffer is exceeded the server closes the
155
- * connection so the client reconnects rather than losing a frame silently.
156
- * Default: the larger of 16 MB and `maxBodyBytes`.
157
- */
158
- maxWebSocketBackpressureBytes?: number;
159
- /**
160
- * How long, in milliseconds, change events are retained for WebSocket CDC
161
- * subscriptions. Retention bounds both on-disk growth of the change log and
162
- * how far back a reconnecting subscriber can resume. Default: 3_600_000
163
- * (one hour).
164
- */
165
- cdcRetentionMs?: number;
166
- /** How long, in milliseconds, a device's sync cursor is kept after its last contact. */
167
- deviceCursorRetentionMs?: number;
168
- /** Changes a device may leave unacknowledged before the server stops sending more. */
169
- maxUnacknowledgedChanges?: number;
170
- /** Runs before every database route and every WebSocket upgrade, and names the caller. */
171
- authenticate?: AuthenticateHook<Identity>;
172
- /** Statements callers may invoke by name. Without these, only SQL routes serve reads and writes. */
173
- operations?: OperationRegistry<Identity>;
174
- /** Opens the five statement routes and their WebSocket messages. Default: false. */
175
- acceptSql?: boolean;
176
- /**
177
- * Opens the route that rebuilds a database from its backups. A restore
178
- * replaces the database that is serving traffic, so the route stays shut
179
- * until you open it here, and a server that opens it without an
180
- * `authenticate` hook refuses to start. Default: false.
181
- */
182
- acceptBackupRestore?: boolean;
183
- /** Finds what the server runs a database's statements against. */
184
- resolveExecutionTarget?: ServerExecutionTargetResolver;
185
- /** Supplies the replication figures the readiness endpoint reports. */
186
- getReplicationStatus?: () => ReplicationStatusInfo | null;
187
- /** Supplies what `GET /db/{id}/cluster` reports for one database. */
188
- getClusterStatus?: (databaseId: string) => ClusterStatusInfo | null;
189
- /** Reports whether a caller may read the addresses of every node in the group. */
190
- authorizeClusterStatus?: ClusterStatusAuthorizer;
191
- }
192
- /** Replication figures one node reports through its readiness endpoint.
193
- * @public
194
- */
195
- interface ReplicationStatusInfo {
196
- /** Whether this node accepts writes or serves reads. */
197
- role: string;
198
- /** Whether this node forwards writes to the primary. */
199
- writeForwarding: boolean;
200
- /** Number of peers the node is connected to. */
201
- peers: number;
202
- /** Highest change-log position this node has recorded locally. */
203
- localSeq: bigint;
204
- /** What the node can do right now, and the condition behind it. */
205
- health: NodeHealth;
206
- /** Identifier of the replication group the node belongs to. */
207
- replicationGroupId?: string;
208
- /** The primary term this node reports as current. */
209
- primaryTerm?: bigint;
210
- /** Identifier of the primary this node reports as current. */
211
- currentPrimary?: string;
212
- /** Whether the node reaches its cluster coordinator, and whether it holds write authority. */
213
- coordinator?: {
214
- connected: boolean;
215
- authority: boolean;
216
- };
217
- /** Whether this node runs the group's controller loop. */
218
- controller?: {
219
- state: 'disabled' | 'standby' | 'active' | 'lost';
220
- };
221
- /** Identifiers of the replicas the group counts as in sync. */
222
- inSyncReplicas?: string[];
223
- /** Identifiers of the replicas that have fallen behind. */
224
- laggingReplicas?: string[];
225
- /** Where this node stands in first sync. */
226
- syncState?: string;
227
- }
228
- /** CORS configuration.
229
- * @public
230
- */
231
- interface CorsOptions {
232
- /** Origins the server allows. */
233
- origin?: string | string[];
234
- /** Methods the server allows. */
235
- methods?: string[];
236
- /** Request headers the server allows. */
237
- headers?: string[];
238
- }
239
- /**
240
- * Options for the mountable WebSocket handler.
241
- *
242
- * @internal
243
- */
244
- interface WSHandlerOptions<Identity = unknown> {
245
- /** Maximum message size in bytes. Default: 1_048_576 (1 MB). */
246
- maxPayloadLength?: number;
247
- /** Outbound bytes a socket may hold before a device stream pauses itself. Default: 16 MB. */
248
- maxBackpressureBytes?: number;
249
- /** Change-log retention for CDC subscriptions in milliseconds. Default: 3_600_000. */
250
- cdcRetentionMs?: number;
251
- deviceCursorRetentionMs?: number;
252
- maxUnacknowledgedChanges?: number;
253
- acceptSql?: boolean;
254
- operations?: OperationRegistry<Identity>;
255
- resolveExecutionTarget?: ServerExecutionTargetResolver;
256
- }
257
- /** Options for the client SDK.
258
- * @public
259
- */
260
- interface ClientOptions {
261
- /** Transport to use. Default: 'websocket'. */
262
- transport?: 'websocket' | 'http';
263
- /**
264
- * Custom headers for HTTP requests, and for the WebSocket upgrade in a
265
- * runtime whose WebSocket carries a handshake header, which Node and Bun do
266
- * and a browser does not. Constructing a WebSocket-transport client with
267
- * headers and no {@link ClientOptions.webSocketProtocols} in a runtime that
268
- * carries none fails with `INVALID_ARGUMENT`. Pass both when a browser client
269
- * needs each one, and the headers still reach every HTTP request.
270
- */
271
- headers?: Record<string, string>;
272
- /**
273
- * WebSocket subprotocols offered during the handshake, which is how a browser
274
- * carries a short-lived credential. The client offers the `sirannon.v1`
275
- * identifier alongside them and the server selects that identifier, so the
276
- * credential never comes back in the handshake response.
277
- */
278
- webSocketProtocols?: string | string[];
279
- /** Reconnect on WebSocket disconnect. Default: true. */
280
- autoReconnect?: boolean;
281
- /** Reconnect interval in ms. Default: 1000. */
282
- reconnectInterval?: number;
283
- /**
284
- * Per-request timeout in milliseconds for the WebSocket transport. A bulk
285
- * load or batch of tens of millions of rows can legitimately run longer than
286
- * the default, so raise this for large writes. Set to 0 to wait indefinitely.
287
- * Default: 30000.
288
- */
289
- requestTimeout?: number;
290
- }
291
-
292
- export type { AppliedMigrationRow as A, BulkLoadDurability as B, ClientOptions as C, RequestContext as R, ServerOptions as S, WSHandlerOptions as W, BulkLoadResult as a, AuthenticateHook as b, BulkLoadOptions as c, ClusterStatusAuthorizer as d, CorsOptions as e, ReplicationStatusInfo as f, ServerExecutionTarget as g, ServerExecutionTargetResolver as h };
@@ -1,178 +0,0 @@
1
- import { H as HookRegistry, D as Database, a as HookDispose } from './database-BLQvqjsw.js';
2
- import { a as SirannonOptions, S as SQLiteDriver, D as DatabaseOptions, M as Migration, b as BeforeQueryHook, A as AfterQueryHook, c as BeforeConnectHook, d as DatabaseOpenHook, e as DatabaseCloseHook } from './types-DPSmjU54.js';
3
-
4
- /** What one database taken out of service produced.
5
- * @internal
6
- */
7
- type OfflineOutcome<T> = {
8
- /** True where the action returned. */
9
- ok: true;
10
- /** What the action produced. */
11
- value: T;
12
- /** What the reopen threw, where it threw. The action's own result still stands. */
13
- reopenFailure?: unknown;
14
- } | {
15
- /** False where the action threw. */
16
- ok: false;
17
- /** What the action threw. */
18
- failure: unknown;
19
- /** What the reopen threw, where it threw. */
20
- reopenFailure?: unknown;
21
- };
22
-
23
- /**
24
- * A registry of open SQLite databases, keyed by identifier.
25
- *
26
- * It opens each database through one driver, applies shared hooks, metrics, and migrations, and closes idle databases when you configure a lifecycle.
27
- *
28
- * @public
29
- */
30
- declare class Sirannon {
31
- private readonly dbs;
32
- private readonly openedWith;
33
- private readonly offline;
34
- private readonly offlineWork;
35
- private readonly opening;
36
- private readonly resolving;
37
- private _shutdown;
38
- private readonly _driver;
39
- private readonly _hookRegistry;
40
- private readonly metricsCollector;
41
- private readonly lifecycleManager;
42
- private readonly migrations;
43
- /** The driver, hooks, metrics, lifecycle, migrations, and writer-worker default this registry was built with. */
44
- readonly options: SirannonOptions;
45
- /**
46
- * Builds a registry.
47
- *
48
- * @param options - Driver, hooks, metrics, lifecycle, migrations, and the writer-worker default.
49
- */
50
- constructor(options: SirannonOptions);
51
- /** @internal */
52
- get driver(): SQLiteDriver;
53
- /** @internal */
54
- get hookRegistry(): HookRegistry;
55
- /**
56
- * Opens a database and registers it under an identifier.
57
- *
58
- * @param id - Identifier callers reach this database by.
59
- * @param path - File path of the SQLite database.
60
- * @param options - Pool size, journal mode, durability, and change-capture settings.
61
- * @returns The open database.
62
- * @throws When the identifier is already registered.
63
- */
64
- open(id: string, path: string, options?: DatabaseOptions): Promise<Database>;
65
- private withRegistryDefaults;
66
- /**
67
- * Closes one database and removes it from the registry.
68
- *
69
- * @param id - Identifier of the database to close.
70
- */
71
- close(id: string): Promise<void>;
72
- /**
73
- * Closes one database, calls an action against the file behind it, and then
74
- * opens that database again under the same identifier with the settings it
75
- * had before.
76
- *
77
- * A restore rebuilds a database at the path it already occupies, so no
78
- * connection may be open on that file while Sirannon replaces its bytes. The
79
- * identifier answers nothing until that database is open again, though an
80
- * action that failed still leaves a database open at the end.
81
- *
82
- * @param id - Identifier of the database to take offline.
83
- * @param action - Runs with the database closed, and receives its file path.
84
- * @returns Whether the action returned, what it produced or threw, and what a failed reopen threw.
85
- * @throws When no database is open under the identifier, when it refuses writes, or when the close fails.
86
- *
87
- * @internal
88
- */
89
- withDatabaseOffline<T>(id: string, action: (path: string) => Promise<T>): Promise<OfflineOutcome<T>>;
90
- /**
91
- * Returns an already-open database.
92
- *
93
- * @param id - Identifier of the database.
94
- * @returns The database, or undefined when none is open under that identifier.
95
- */
96
- get(id: string): Database | undefined;
97
- /**
98
- * Returns an open database, opening it through the lifecycle resolver where it is not open yet.
99
- *
100
- * This is the call an in-process application makes for a database the registry opens on first
101
- * use through the `lifecycle.autoOpen` resolver, such as one file per tenant. Concurrent calls
102
- * for the same unopened identifier share one open, so each receives the same database or the
103
- * same error.
104
- *
105
- * @param id - Identifier of the database.
106
- * @returns The database, or undefined when none is open and the resolver names no path for it.
107
- */
108
- resolve(id: string): Promise<Database | undefined>;
109
- /**
110
- * Returns the registry migration set every database applies as it opens.
111
- *
112
- * Where the set came from a function, the registry calls that function once and
113
- * caches what it returned, so this reports the same list on every call.
114
- *
115
- * @returns The migrations declared in `SirannonOptions.migrations`, or an empty list where none are.
116
- */
117
- registryMigrations(): Promise<Migration[]>;
118
- /**
119
- * Reports whether a database is open under an identifier.
120
- *
121
- * @param id - Identifier to check.
122
- * @returns True when the registry holds an open database under it.
123
- */
124
- has(id: string): boolean;
125
- /**
126
- * Returns every database this registry currently holds open.
127
- *
128
- * @returns The open databases, keyed by identifier.
129
- */
130
- databases(): Map<string, Database>;
131
- /**
132
- * Closes every open database and stops the lifecycle timers.
133
- *
134
- * A database whose file Sirannon is replacing delays the shutdown until that
135
- * work finishes, since a process that exits part-way through would leave the
136
- * path with no database on it at all.
137
- */
138
- shutdown(): Promise<void>;
139
- /**
140
- * Registers a hook that runs before each statement on every database in this registry. Throw from it to refuse the statement.
141
- *
142
- * @param hook - Receives the statement, its parameters, and the concerns it carries.
143
- * @returns A function that removes the hook.
144
- */
145
- onBeforeQuery(hook: BeforeQueryHook): HookDispose;
146
- /**
147
- * Registers a hook that runs after each statement on every database in this registry.
148
- *
149
- * @param hook - Receives the statement and how long it took.
150
- * @returns A function that removes the hook.
151
- */
152
- onAfterQuery(hook: AfterQueryHook): HookDispose;
153
- /**
154
- * Registers a hook that runs before a database connection opens.
155
- *
156
- * @param hook - Receives the database identifier and its file path.
157
- * @returns A function that removes the hook.
158
- */
159
- onBeforeConnect(hook: BeforeConnectHook): HookDispose;
160
- /**
161
- * Registers a hook that runs once a database is open.
162
- *
163
- * @param hook - Receives the database identifier and its file path.
164
- * @returns A function that removes the hook.
165
- */
166
- onDatabaseOpen(hook: DatabaseOpenHook): HookDispose;
167
- /**
168
- * Registers a hook that runs once a database is closed.
169
- *
170
- * @param hook - Receives the database identifier and its file path.
171
- * @returns A function that removes the hook.
172
- */
173
- onDatabaseClose(hook: DatabaseCloseHook): HookDispose;
174
- private ensureRunning;
175
- private ensureOpenAllowed;
176
- }
177
-
178
- export { Sirannon as S };