@delali/sirannon-db 0.1.7 → 0.2.0

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 (72) hide show
  1. package/README.md +117 -969
  2. package/dist/backup-scheduler/index.d.ts +1 -1
  3. package/dist/backup-scheduler/index.mjs +2 -2
  4. package/dist/baseline-Br77Fnhb.d.ts +6 -0
  5. package/dist/{change-tracker-CbmaMO-N.d.ts → change-tracker-DKRVUC3l.d.ts} +5 -8
  6. package/dist/{chunk-DJLX6CAE.mjs → chunk-4ISB7XMA.mjs} +2 -1
  7. package/dist/chunk-5NOIGN5Y.mjs +18 -0
  8. package/dist/chunk-67M7KAH6.mjs +90 -0
  9. package/dist/{chunk-GEZUUIKV.mjs → chunk-D7LAYTKN.mjs} +5 -2
  10. package/dist/{chunk-4IGMIJQK.mjs → chunk-EBJXPQQO.mjs} +59 -20
  11. package/dist/{chunk-BNUTBHHH.mjs → chunk-FHWTZFI4.mjs} +1 -1
  12. package/dist/chunk-GVCNMPOS.mjs +130 -0
  13. package/dist/chunk-H237TXZW.mjs +1407 -0
  14. package/dist/{chunk-HHRMRFFR.mjs → chunk-H6PIVVDN.mjs} +353 -142
  15. package/dist/chunk-HR5CWTLC.mjs +661 -0
  16. package/dist/chunk-JU64Y7HM.mjs +299 -0
  17. package/dist/{chunk-CW6S3WL5.mjs → chunk-JZGINXTN.mjs} +7 -5
  18. package/dist/{chunk-CJLYFDP5.mjs → chunk-LFZ37BSX.mjs} +1 -1
  19. package/dist/chunk-LNY2VVHE.mjs +18 -0
  20. package/dist/chunk-NVQS53NT.mjs +665 -0
  21. package/dist/{chunk-H5AB6NIR.mjs → chunk-O7SLN3GI.mjs} +2 -15
  22. package/dist/chunk-OQVZBEBY.mjs +283 -0
  23. package/dist/{chunk-VLTICJOD.mjs → chunk-PIKHN33N.mjs} +1 -1
  24. package/dist/chunk-TJF5GZSV.mjs +187 -0
  25. package/dist/chunk-TUD5CJ76.mjs +126 -0
  26. package/dist/{chunk-YPYVQJ4C.mjs → chunk-UC3SCMIN.mjs} +9 -1
  27. package/dist/client/index.d.ts +216 -321
  28. package/dist/client/index.mjs +1192 -1342
  29. package/dist/client/topology.d.ts +61 -0
  30. package/dist/client/topology.mjs +682 -0
  31. package/dist/client-base-CLWmH5Ln.d.ts +234 -0
  32. package/dist/codegen/cli.d.ts +2 -0
  33. package/dist/codegen/cli.mjs +11 -0
  34. package/dist/codegen/index.d.ts +30 -0
  35. package/dist/codegen/index.mjs +5 -0
  36. package/dist/core/index.d.ts +37 -16
  37. package/dist/core/index.mjs +2322 -298
  38. package/dist/core/writer-worker.mjs +28 -6
  39. package/dist/{database-DuGp0Rtr.d.ts → database-BY0L5Q2n.d.ts} +59 -14
  40. package/dist/driver/better-sqlite3.d.ts +1 -1
  41. package/dist/driver/better-sqlite3.mjs +6 -6
  42. package/dist/driver/node.d.ts +1 -1
  43. package/dist/driver/node.mjs +6 -6
  44. package/dist/driver/wa-sqlite.d.ts +1 -136
  45. package/dist/{errors-5Nf5ZAEC.d.ts → errors-Bw5MdNCu.d.ts} +5 -1
  46. package/dist/file-migrations/index.d.ts +7 -5
  47. package/dist/file-migrations/index.mjs +42 -37
  48. package/dist/operation-registry-9DcvxcE5.d.ts +45 -0
  49. package/dist/primary-wins-DPAm2AKG.d.ts +61 -0
  50. package/dist/protocol-6KrSq2Hy.d.ts +66 -0
  51. package/dist/react/index.d.ts +20 -0
  52. package/dist/react/index.mjs +137 -0
  53. package/dist/replication/coordinator/etcd.d.ts +5 -3
  54. package/dist/replication/coordinator/etcd.mjs +554 -462
  55. package/dist/replication/index.d.ts +51 -105
  56. package/dist/replication/index.mjs +1415 -2061
  57. package/dist/server/index.d.ts +111 -87
  58. package/dist/server/index.mjs +1917 -489
  59. package/dist/server-options-1JHu8pid.d.ts +191 -0
  60. package/dist/{sirannon-4SspRvP5.d.ts → sirannon-DaQSyhbJ.d.ts} +7 -2
  61. package/dist/transport/grpc.d.ts +7 -4
  62. package/dist/transport/grpc.mjs +191 -97
  63. package/dist/transport/memory.d.ts +5 -134
  64. package/dist/transport/memory.mjs +3 -1
  65. package/dist/{types-BsjobKbl.d.ts → types-B7gmEsZW.d.ts} +8 -61
  66. package/dist/{types-BEu1I_9_.d.ts → types-BsVabqSI.d.ts} +1 -1
  67. package/dist/types-CL6piSnD.d.ts +43 -0
  68. package/dist/types-C_D8IhpO.d.ts +60 -0
  69. package/dist/{types-D_hQW1hr.d.ts → types-zhnRXrsb.d.ts} +55 -165
  70. package/package.json +44 -6
  71. package/dist/chunk-TKGHYWQ6.mjs +0 -35
  72. package/dist/types-D4p4UyDK.d.ts +0 -26
@@ -0,0 +1,191 @@
1
+ import { a as OperationRegistry } from './operation-registry-9DcvxcE5.js';
2
+ import { R as ReplicationBatch, C as ConflictResolver, A as ApplyResult } from './types-C_D8IhpO.js';
3
+ import { N as NodeHealth, P as Params, Q as QueryOptions, E as ExecuteResult, T as Transaction, C as ClusterStatusInfo } from './types-zhnRXrsb.js';
4
+
5
+ interface AppliedMigrationRow {
6
+ version: number;
7
+ name: string;
8
+ checksum: string | null;
9
+ }
10
+
11
+ /** Context passed to the authenticate hook. */
12
+ interface RequestContext {
13
+ headers: Record<string, string>;
14
+ method: string;
15
+ path: string;
16
+ databaseId?: string;
17
+ remoteAddress: string;
18
+ }
19
+ type AuthenticateHook<Identity = unknown> = (ctx: RequestContext) => Identity | undefined | Promise<Identity | undefined>;
20
+ type ClusterStatusAuthorizer = (ctx: RequestContext) => boolean | Promise<boolean>;
21
+ /**
22
+ * Durability level in force while a bulk load runs. SQLite sanctions 'off' for
23
+ * a from-scratch load that the operator can re-run after a power loss; 'off'
24
+ * gives up corruption safety, so it fits only a load that starts from nothing.
25
+ * 'normal' keeps WAL-mode corruption safety and suits loads into a database
26
+ * that already holds data the operator cannot afford to lose.
27
+ */
28
+ type BulkLoadDurability = 'off' | 'normal';
29
+ interface BulkLoadOptions {
30
+ /** Durability during the load. Default: 'off'. */
31
+ durability?: BulkLoadDurability;
32
+ /**
33
+ * Whether this load ends with a WAL checkpoint. Default: true. Set it false
34
+ * on every load but the last of a multi-batch import so the one fsyncing
35
+ * checkpoint is paid once at the end instead of once per batch; the
36
+ * configured durability is still restored after each batch regardless, so an
37
+ * abandoned import never leaves the writer at the relaxed level.
38
+ */
39
+ checkpoint?: boolean;
40
+ }
41
+ /** Aggregate outcome of a bulk load. Summed rather than per-row so a
42
+ * million-row load never holds a million result objects in memory. */
43
+ interface BulkLoadResult {
44
+ rowsLoaded: number;
45
+ changes: number;
46
+ }
47
+ interface ServerExecutionTarget {
48
+ query<T = Record<string, unknown>>(sql: string, params?: Params, options?: QueryOptions): Promise<T[]>;
49
+ /**
50
+ * Optional single-pass read that returns rows already encoded for the wire
51
+ * (safe-range integers as plain numbers, larger integers and BLOBs as tagged
52
+ * envelopes). When present the server uses it instead of {@link query}
53
+ * followed by a separate tag-encoding walk. A target that omits it stays
54
+ * correct: the server falls back to encoding {@link query} rows itself.
55
+ */
56
+ queryForWire?(sql: string, params?: Params, options?: QueryOptions): Promise<unknown[]>;
57
+ execute(sql: string, params?: Params, options?: QueryOptions): Promise<ExecuteResult>;
58
+ transaction<T>(fn: (tx: Transaction) => Promise<T>, options?: QueryOptions): Promise<T>;
59
+ /**
60
+ * Optional entry point for a transaction whose statements are all known
61
+ * before it starts, which lets concurrent transactions share one commit. A
62
+ * target that omits it stays correct: the server falls back to
63
+ * {@link transaction} and runs the statements one at a time.
64
+ */
65
+ executeTransaction?(statements: readonly {
66
+ sql: string;
67
+ params?: Params;
68
+ }[], options?: QueryOptions): Promise<ExecuteResult[]>;
69
+ /**
70
+ * Optional bulk-load entry point. Targets that proxy to a remote primary
71
+ * may omit it; the server rejects load requests for such targets instead
72
+ * of silently degrading to per-statement writes.
73
+ */
74
+ bulkLoad?(sql: string, paramsBatch: Params[], options?: BulkLoadOptions): Promise<BulkLoadResult>;
75
+ applyChanges?(batch: ReplicationBatch, resolver?: ConflictResolver | ((table: string) => ConflictResolver)): Promise<ApplyResult>;
76
+ appliedMigrations?(): Promise<AppliedMigrationRow[]>;
77
+ }
78
+ type ServerExecutionTargetResolver = (databaseId: string) => ServerExecutionTarget | null | undefined | Promise<ServerExecutionTarget | null | undefined>;
79
+ /** Options for the standalone HTTP + WS server. */
80
+ interface ServerOptions<Identity = unknown> {
81
+ host?: string;
82
+ port?: number;
83
+ cors?: boolean | CorsOptions;
84
+ /**
85
+ * Maximum HTTP request body and WebSocket message size in bytes. Applied
86
+ * identically to both transports. Must be a positive, finite integer no
87
+ * larger than 4_294_967_295 (the unsigned 32-bit ceiling uWebSockets.js can
88
+ * store; larger values would silently wrap modulo 2^32).
89
+ * Default: 1_048_576 (1 MB), matching the general web default and acting as
90
+ * a denial-of-service guard on a memory-limited server.
91
+ */
92
+ maxBodyBytes?: number;
93
+ /**
94
+ * Maximum bytes buffered per WebSocket connection before the server stops
95
+ * absorbing backpressure. A single frame can be as large as `maxBodyBytes`,
96
+ * so this must hold several of them; the resolved value is raised to at
97
+ * least `maxBodyBytes` and, like `maxBodyBytes`, must not exceed
98
+ * 4_294_967_295. When the buffer is exceeded the server closes the
99
+ * connection so the client reconnects rather than losing a frame silently.
100
+ * Default: the larger of 16 MB and `maxBodyBytes`.
101
+ */
102
+ maxWebSocketBackpressureBytes?: number;
103
+ /**
104
+ * How long, in milliseconds, change events are retained for WebSocket CDC
105
+ * subscriptions. Retention bounds both on-disk growth of the change log and
106
+ * how far back a reconnecting subscriber can resume. Default: 3_600_000
107
+ * (one hour).
108
+ */
109
+ cdcRetentionMs?: number;
110
+ deviceCursorRetentionMs?: number;
111
+ maxUnacknowledgedChanges?: number;
112
+ authenticate?: AuthenticateHook<Identity>;
113
+ operations?: OperationRegistry<Identity>;
114
+ acceptSql?: boolean;
115
+ resolveExecutionTarget?: ServerExecutionTargetResolver;
116
+ getReplicationStatus?: () => ReplicationStatusInfo | null;
117
+ getClusterStatus?: (databaseId: string) => ClusterStatusInfo | null;
118
+ authorizeClusterStatus?: ClusterStatusAuthorizer;
119
+ }
120
+ interface ReplicationStatusInfo {
121
+ role: string;
122
+ writeForwarding: boolean;
123
+ peers: number;
124
+ localSeq: bigint;
125
+ health: NodeHealth;
126
+ replicationGroupId?: string;
127
+ primaryTerm?: bigint;
128
+ currentPrimary?: string;
129
+ coordinator?: {
130
+ connected: boolean;
131
+ authority: boolean;
132
+ };
133
+ controller?: {
134
+ state: 'disabled' | 'standby' | 'active' | 'lost';
135
+ };
136
+ inSyncReplicas?: string[];
137
+ laggingReplicas?: string[];
138
+ syncState?: string;
139
+ }
140
+ /** CORS configuration. */
141
+ interface CorsOptions {
142
+ origin?: string | string[];
143
+ methods?: string[];
144
+ headers?: string[];
145
+ }
146
+ /** Options for the mountable WebSocket handler. */
147
+ interface WSHandlerOptions<Identity = unknown> {
148
+ /** Maximum message size in bytes. Default: 1_048_576 (1 MB). */
149
+ maxPayloadLength?: number;
150
+ /** Change-log retention for CDC subscriptions in milliseconds. Default: 3_600_000. */
151
+ cdcRetentionMs?: number;
152
+ deviceCursorRetentionMs?: number;
153
+ maxUnacknowledgedChanges?: number;
154
+ acceptSql?: boolean;
155
+ operations?: OperationRegistry<Identity>;
156
+ resolveExecutionTarget?: ServerExecutionTargetResolver;
157
+ }
158
+ /** Options for the client SDK. */
159
+ interface ClientOptions {
160
+ /** Transport to use. Default: 'websocket'. */
161
+ transport?: 'websocket' | 'http';
162
+ /**
163
+ * Custom headers for HTTP requests, and for the WebSocket upgrade in a
164
+ * runtime whose WebSocket carries a handshake header, which Node and Bun do
165
+ * and a browser does not. Constructing a WebSocket-transport client with
166
+ * headers and no {@link ClientOptions.webSocketProtocols} in a runtime that
167
+ * carries none fails with `INVALID_ARGUMENT`. Pass both when a browser client
168
+ * needs each one, and the headers still reach every HTTP request.
169
+ */
170
+ headers?: Record<string, string>;
171
+ /**
172
+ * WebSocket subprotocols offered during the handshake, which is how a browser
173
+ * carries a short-lived credential. The client offers the `sirannon.v1`
174
+ * identifier alongside them and the server selects that identifier, so the
175
+ * credential never comes back in the handshake response.
176
+ */
177
+ webSocketProtocols?: string | string[];
178
+ /** Reconnect on WebSocket disconnect. Default: true. */
179
+ autoReconnect?: boolean;
180
+ /** Reconnect interval in ms. Default: 1000. */
181
+ reconnectInterval?: number;
182
+ /**
183
+ * Per-request timeout in milliseconds for the WebSocket transport. A bulk
184
+ * load or batch of tens of millions of rows can legitimately run longer than
185
+ * the default, so raise this for large writes. Set to 0 to wait indefinitely.
186
+ * Default: 30000.
187
+ */
188
+ requestTimeout?: number;
189
+ }
190
+
191
+ export type { AppliedMigrationRow as A, BulkLoadDurability as B, ClientOptions as C, ReplicationStatusInfo as R, ServerOptions as S, WSHandlerOptions as W, BulkLoadResult as a, BulkLoadOptions as b, AuthenticateHook as c, ClusterStatusAuthorizer as d, CorsOptions as e, RequestContext as f, ServerExecutionTarget as g, ServerExecutionTargetResolver as h };
@@ -1,10 +1,12 @@
1
- import { D as Database } from './database-DuGp0Rtr.js';
2
- import { S as SirannonOptions, a as SQLiteDriver, D as DatabaseOptions, B as BeforeQueryHook, A as AfterQueryHook, b as BeforeConnectHook, c as DatabaseOpenHook, d as DatabaseCloseHook } from './types-D_hQW1hr.js';
1
+ import { D as Database } from './database-BY0L5Q2n.js';
2
+ import { S as SirannonOptions, a as SQLiteDriver, D as DatabaseOptions, M as Migration, B as BeforeQueryHook, A as AfterQueryHook, b as BeforeConnectHook, c as DatabaseOpenHook, d as DatabaseCloseHook } from './types-zhnRXrsb.js';
3
3
 
4
4
  declare class Sirannon {
5
5
  readonly options: SirannonOptions;
6
6
  private readonly dbs;
7
7
  private readonly opening;
8
+ private readonly resolving;
9
+ private migrationSet;
8
10
  private _shutdown;
9
11
  private readonly _driver;
10
12
  private readonly hookRegistry;
@@ -17,6 +19,9 @@ declare class Sirannon {
17
19
  close(id: string): Promise<void>;
18
20
  get(id: string): Database | undefined;
19
21
  resolve(id: string): Promise<Database | undefined>;
22
+ registryMigrations(): Promise<Migration[]>;
23
+ private applyRegistryMigrations;
24
+ private loadMigrationSet;
20
25
  has(id: string): boolean;
21
26
  databases(): Map<string, Database>;
22
27
  shutdown(): Promise<void>;
@@ -1,10 +1,11 @@
1
1
  import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
2
2
  import { Client, ClientDuplexStream, CallOptions, Metadata, ServiceError, ClientUnaryCall, ChannelCredentials, ClientOptions, ServerDuplexStream, Server } from '@grpc/grpc-js';
3
3
  import { HealthImplementation } from 'grpc-health-check';
4
- import { R as ReplicationBatch, a as ReplicationAck, F as ForwardedTransaction, b as ForwardedTransactionResult, N as NodeInfo, S as SyncRequest, c as SyncBatch, d as SyncComplete, e as SyncAck, f as ReplicationTransport, T as TopologyRole, g as TransportConfig } from '../types-BsjobKbl.js';
5
- import '../change-tracker-CbmaMO-N.js';
6
- import '../types-D_hQW1hr.js';
7
- import '../types-BEu1I_9_.js';
4
+ import { R as ReplicationAck, F as ForwardedTransaction, a as ForwardedTransactionResult, N as NodeInfo, S as SyncRequest, b as SyncBatch, c as SyncComplete, d as SyncAck, e as ReplicationTransport, f as TopologyRole, T as TransportConfig } from '../types-B7gmEsZW.js';
5
+ import { R as ReplicationBatch } from '../types-C_D8IhpO.js';
6
+ import '../change-tracker-DKRVUC3l.js';
7
+ import '../types-zhnRXrsb.js';
8
+ import '../types-BsVabqSI.js';
8
9
 
9
10
  interface ColumnValue {
10
11
  nullValue?: boolean | undefined;
@@ -79,6 +80,7 @@ interface SyncRequestPayload {
79
80
  completedTables: string[];
80
81
  groupId: string;
81
82
  primaryTerm: bigint;
83
+ supportsStreamVerification: boolean;
82
84
  }
83
85
  declare const SyncRequestPayload: MessageFns<SyncRequestPayload>;
84
86
  interface SyncBatchPayload {
@@ -106,6 +108,7 @@ interface SyncTableManifest {
106
108
  table: string;
107
109
  rowCount: number;
108
110
  pkHash: string;
111
+ batchDigest: string;
109
112
  }
110
113
  declare const SyncTableManifest: MessageFns<SyncTableManifest>;
111
114
  interface SyncAckPayload {