@delali/sirannon-db 0.1.3 → 0.1.5
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 +655 -80
- package/dist/backup-scheduler/index.d.ts +3 -0
- package/dist/backup-scheduler/index.mjs +2 -0
- package/dist/change-tracker-CFTQ9TSn.d.ts +89 -0
- package/dist/chunk-3MCMONVP.mjs +115 -0
- package/dist/chunk-74UN4DIE.mjs +14 -0
- package/dist/chunk-ER7ODTDA.mjs +23 -0
- package/dist/chunk-FB2U2Q3Y.mjs +21 -0
- package/dist/chunk-GS7T5YMI.mjs +51 -0
- package/dist/chunk-O7BHI3CF.mjs +90 -0
- package/dist/chunk-PXKAKK2V.mjs +124 -0
- package/dist/chunk-UTO3ZAFS.mjs +514 -0
- package/dist/chunk-UVMVN3OT.mjs +111 -0
- package/dist/client/index.d.ts +137 -44
- package/dist/client/index.mjs +726 -26
- package/dist/core/index.d.ts +32 -241
- package/dist/core/index.mjs +294 -568
- package/dist/database-BVY1GqE7.d.ts +95 -0
- package/dist/driver/better-sqlite3.d.ts +8 -0
- package/dist/driver/better-sqlite3.mjs +63 -0
- package/dist/driver/bun.mjs +61 -0
- package/dist/driver/expo.mjs +55 -0
- package/dist/driver/node.d.ts +8 -0
- package/dist/driver/node.mjs +60 -0
- package/dist/driver/wa-sqlite.d.ts +34 -0
- package/dist/driver/wa-sqlite.mjs +141 -0
- package/dist/errors-C00ed08Q.d.ts +101 -0
- package/dist/file-migrations/index.d.ts +16 -0
- package/dist/file-migrations/index.mjs +128 -0
- package/dist/index-CLdNrcPz.d.ts +16 -0
- package/dist/replication/coordinator/etcd.d.ts +44 -0
- package/dist/replication/coordinator/etcd.mjs +650 -0
- package/dist/replication/index.d.ts +491 -0
- package/dist/replication/index.mjs +3784 -0
- package/dist/server/index.d.ts +121 -54
- package/dist/server/index.mjs +347 -114
- package/dist/sirannon-Cd-lK6T0.d.ts +31 -0
- package/dist/transport/grpc.d.ts +316 -0
- package/dist/transport/grpc.mjs +3341 -0
- package/dist/transport/memory.d.ts +221 -0
- package/dist/transport/memory.mjs +337 -0
- package/dist/types-B2byqt0B.d.ts +273 -0
- package/dist/types-BEu1I_9_.d.ts +139 -0
- package/dist/types-BFSsG77t.d.ts +29 -0
- package/dist/types-BeozgNPr.d.ts +26 -0
- package/dist/{types-DArCObcu.d.ts → types-D-74JiXb.d.ts} +80 -1
- package/dist/vfs-INWQ5DTE.mjs +2 -0
- package/package.json +106 -11
- package/dist/chunk-VI4UP4RR.mjs +0 -417
- package/dist/protocol-BX1H-_Mz.d.ts +0 -104
- package/dist/sirannon-BJ8Yd1Uf.d.ts +0 -148
package/dist/core/index.d.ts
CHANGED
|
@@ -1,295 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* The destination file must not already exist. Parent directories are
|
|
14
|
-
* created automatically when missing.
|
|
15
|
-
*
|
|
16
|
-
* Note: there is a narrow TOCTOU window between the existence check and
|
|
17
|
-
* the VACUUM INTO statement. In the unlikely event that another process
|
|
18
|
-
* creates a file at the same path during that window, VACUUM INTO may
|
|
19
|
-
* silently overwrite it depending on the SQLite version.
|
|
20
|
-
*/
|
|
21
|
-
backup(db: SqliteDb$4, destPath: string): void;
|
|
22
|
-
/**
|
|
23
|
-
* Generates a timestamped backup filename.
|
|
24
|
-
*
|
|
25
|
-
* Format: `backup-YYYY-MM-DDTHH-MM-SS-mmmZ.db`
|
|
26
|
-
*
|
|
27
|
-
* Colons and dots in the ISO timestamp are replaced with hyphens so the
|
|
28
|
-
* filename is safe on every major filesystem.
|
|
29
|
-
*/
|
|
30
|
-
generateFilename(): string;
|
|
31
|
-
/**
|
|
32
|
-
* Removes old backup files in {@link dir}, keeping the {@link maxFiles}
|
|
33
|
-
* most recent entries. Only files matching the `backup-*.db` naming
|
|
34
|
-
* convention are considered; other files in the directory are left alone.
|
|
35
|
-
*
|
|
36
|
-
* When {@link maxFiles} is zero or negative the method is a no-op.
|
|
37
|
-
* A non-existent directory is silently ignored.
|
|
38
|
-
*/
|
|
39
|
-
rotate(dir: string, maxFiles: number): void;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
type SqliteDb$3 = InstanceType<typeof Database>;
|
|
43
|
-
declare class BackupScheduler {
|
|
44
|
-
private readonly manager;
|
|
45
|
-
constructor(manager?: BackupManager);
|
|
46
|
-
/**
|
|
47
|
-
* Schedules periodic backups on a cron expression.
|
|
48
|
-
*
|
|
49
|
-
* Each tick creates a timestamped backup file inside {@link options.destDir}
|
|
50
|
-
* and rotates old files so no more than {@link options.maxFiles} (default 5)
|
|
51
|
-
* are retained.
|
|
52
|
-
*
|
|
53
|
-
* Provide {@link options.onError} to receive notification when a scheduled
|
|
54
|
-
* backup fails. Without it, errors are silently discarded to prevent
|
|
55
|
-
* unhandled exceptions from crashing the process.
|
|
56
|
-
*
|
|
57
|
-
* The underlying timer is unreferenced so it won't keep the Node.js
|
|
58
|
-
* process alive on its own (consistent with the CDC polling timer).
|
|
59
|
-
*
|
|
60
|
-
* Returns a cancel function that stops the scheduled job immediately.
|
|
61
|
-
*/
|
|
62
|
-
schedule(db: SqliteDb$3, options: BackupScheduleOptions): () => void;
|
|
63
|
-
}
|
|
1
|
+
export { B as BackupManager, a as BackupScheduler } from '../index-CLdNrcPz.js';
|
|
2
|
+
export { C as ChangeTracker, a as ChangeTrackerOptions } from '../change-tracker-CFTQ9TSn.js';
|
|
3
|
+
import { S as SQLiteDriver, a as SQLiteConnection } from '../types-BFSsG77t.js';
|
|
4
|
+
export { D as DriverCapabilities, O as OpenOptions, R as RunResult, b as SQLiteStatement } from '../types-BFSsG77t.js';
|
|
5
|
+
import { D as Database } from '../database-BVY1GqE7.js';
|
|
6
|
+
export { H as HookDispose, a as HookEvent, b as HookEventContextMap, c as HookHandler, d as HookRegistry, M as MetricsCollector, S as SubscribeHookContext } from '../database-BVY1GqE7.js';
|
|
7
|
+
export { B as BackupError, C as CDCError, a as ConnectionPoolError, D as DatabaseAlreadyExistsError, b as DatabaseNotFoundError, E as ExtensionError, H as HookDeniedError, M as MaxDatabasesError, c as MigrationError, Q as QueryError, R as ReadOnlyError, S as SirannonError, T as TransactionError } from '../errors-C00ed08Q.js';
|
|
8
|
+
import { D as DatabaseOptions, L as LifecycleConfig, P as Params, E as ExecuteResult } from '../types-D-74JiXb.js';
|
|
9
|
+
export { A as AfterQueryHook, m as BackupScheduleOptions, a as BeforeConnectHook, B as BeforeQueryHook, g as BeforeSubscribeHook, j as CDCMetrics, C as ChangeEvent, n as ChangeOperation, o as ClientOptions, p as ClusterReadEndpointInfo, q as ClusterStatusInfo, f as ConnectionHookContext, i as ConnectionMetrics, r as CorsOptions, c as DatabaseCloseHook, b as DatabaseOpenHook, H as HookConfig, M as MetricsConfig, O as OnRequestHook, Q as QueryHookContext, h as QueryMetrics, k as QueryOptions, R as ReadConcern, s as ReadConcernLevel, t as ReplicationStatusInfo, u as RequestContext, v as RequestDenial, w as ServerExecutionTarget, x as ServerExecutionTargetResolver, d as ServerOptions, S as SirannonOptions, y as Subscription, l as SubscriptionBuilder, T as Transaction, e as WSHandlerOptions, W as WriteConcern, z as WriteConcernLevel } from '../types-D-74JiXb.js';
|
|
10
|
+
import { M as Migration, a as MigrationResult, R as RollbackResult } from '../types-BeozgNPr.js';
|
|
11
|
+
export { A as AppliedMigration, b as AppliedMigrationEntry } from '../types-BeozgNPr.js';
|
|
12
|
+
export { S as Sirannon } from '../sirannon-Cd-lK6T0.js';
|
|
64
13
|
|
|
65
14
|
interface ConnectionPoolOptions {
|
|
15
|
+
driver: SQLiteDriver;
|
|
66
16
|
path: string;
|
|
67
17
|
readOnly?: boolean;
|
|
68
18
|
readPoolSize?: number;
|
|
69
19
|
walMode?: boolean;
|
|
70
20
|
}
|
|
71
|
-
type SqliteDb$2 = InstanceType<typeof Database>;
|
|
72
21
|
declare class ConnectionPool {
|
|
73
22
|
private readonly writer;
|
|
74
23
|
private readonly readers;
|
|
75
24
|
private readerIndex;
|
|
76
25
|
private closed;
|
|
77
|
-
constructor(
|
|
78
|
-
|
|
79
|
-
|
|
26
|
+
private constructor();
|
|
27
|
+
static create(options: ConnectionPoolOptions): Promise<ConnectionPool>;
|
|
28
|
+
acquireReader(): SQLiteConnection;
|
|
29
|
+
acquireWriter(): SQLiteConnection;
|
|
80
30
|
get readerCount(): number;
|
|
81
31
|
get isReadOnly(): boolean;
|
|
82
|
-
|
|
83
|
-
close(): void;
|
|
32
|
+
close(): Promise<void>;
|
|
84
33
|
}
|
|
85
34
|
|
|
86
|
-
|
|
87
|
-
* Base class for all sirannon-db errors. Extend this class to create
|
|
88
|
-
* domain-specific errors that carry a machine-readable {@link code}.
|
|
89
|
-
*/
|
|
90
|
-
declare class SirannonError extends Error {
|
|
91
|
-
readonly code: string;
|
|
92
|
-
constructor(message: string, code: string);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Thrown when a database ID cannot be resolved in the registry.
|
|
96
|
-
* This typically means the database was never opened or has already been closed.
|
|
97
|
-
*/
|
|
98
|
-
declare class DatabaseNotFoundError extends SirannonError {
|
|
99
|
-
constructor(id: string);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Thrown when attempting to register a database with an ID that is already
|
|
103
|
-
* in use. Each database ID must be unique within the registry.
|
|
104
|
-
*/
|
|
105
|
-
declare class DatabaseAlreadyExistsError extends SirannonError {
|
|
106
|
-
constructor(id: string);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Thrown when a write operation is attempted on a database that was opened
|
|
110
|
-
* in read-only mode.
|
|
111
|
-
*/
|
|
112
|
-
declare class ReadOnlyError extends SirannonError {
|
|
113
|
-
constructor(id: string);
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Thrown when SQLite fails to execute a statement. The {@link sql} property
|
|
117
|
-
* holds the original SQL string that caused the failure, which is useful for
|
|
118
|
-
* debugging and logging.
|
|
119
|
-
*/
|
|
120
|
-
declare class QueryError extends SirannonError {
|
|
121
|
-
readonly sql: string;
|
|
122
|
-
constructor(message: string, sql: string);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Thrown when a transaction cannot be committed or is forcibly rolled back.
|
|
126
|
-
* Check the message for the underlying cause.
|
|
127
|
-
*/
|
|
128
|
-
declare class TransactionError extends SirannonError {
|
|
129
|
-
constructor(message: string);
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Thrown when a migration step fails. The {@link version} property identifies
|
|
133
|
-
* which schema version triggered the error so the failure can be pinpointed
|
|
134
|
-
* in the migration history.
|
|
135
|
-
*/
|
|
136
|
-
declare class MigrationError extends SirannonError {
|
|
137
|
-
readonly version: number;
|
|
138
|
-
constructor(message: string, version: number, code?: string);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Thrown when a before-hook explicitly rejects an operation. The optional
|
|
142
|
-
* `reason` string is surfaced in the message so callers can distinguish
|
|
143
|
-
* between different hook policies.
|
|
144
|
-
*/
|
|
145
|
-
declare class HookDeniedError extends SirannonError {
|
|
146
|
-
constructor(hookName: string, reason?: string);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Thrown when the change-data-capture pipeline encounters an unrecoverable
|
|
150
|
-
* error, such as a failed event dispatch or a corrupt change record.
|
|
151
|
-
*/
|
|
152
|
-
declare class CDCError extends SirannonError {
|
|
153
|
-
constructor(message: string);
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Thrown when a backup operation fails, whether that is an online backup via
|
|
157
|
-
* the SQLite backup API or a file-level copy.
|
|
158
|
-
*/
|
|
159
|
-
declare class BackupError extends SirannonError {
|
|
160
|
-
constructor(message: string);
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Thrown when the connection pool reaches its limit or is configured with
|
|
164
|
-
* invalid parameters such as a minimum size greater than the maximum.
|
|
165
|
-
*/
|
|
166
|
-
declare class ConnectionPoolError extends SirannonError {
|
|
167
|
-
constructor(message: string);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Thrown when opening a new database would exceed the configured cap on
|
|
171
|
-
* concurrently open databases. Close an existing database before opening
|
|
172
|
-
* another one.
|
|
173
|
-
*/
|
|
174
|
-
declare class MaxDatabasesError extends SirannonError {
|
|
175
|
-
constructor(max: number);
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Thrown when a native SQLite extension cannot be loaded. The `path` argument
|
|
179
|
-
* is the filesystem path passed to `load_extension`, and the optional `cause`
|
|
180
|
-
* string carries the error detail reported by SQLite.
|
|
181
|
-
*/
|
|
182
|
-
declare class ExtensionError extends SirannonError {
|
|
183
|
-
constructor(path: string, cause?: string);
|
|
184
|
-
}
|
|
35
|
+
declare function defineDriver(config: SQLiteDriver): SQLiteDriver;
|
|
185
36
|
|
|
186
|
-
/**
|
|
187
|
-
* Callbacks the LifecycleManager uses to interact with the database registry
|
|
188
|
-
* (Sirannon). Injected at construction to avoid circular dependencies.
|
|
189
|
-
*/
|
|
190
37
|
interface LifecycleCallbacks {
|
|
191
|
-
open: (id: string, path: string, options?: DatabaseOptions) => Database
|
|
192
|
-
close: (id: string) => void
|
|
38
|
+
open: (id: string, path: string, options?: DatabaseOptions) => Promise<Database>;
|
|
39
|
+
close: (id: string) => Promise<void>;
|
|
193
40
|
count: () => number;
|
|
194
41
|
has: (id: string) => boolean;
|
|
195
42
|
}
|
|
196
|
-
/**
|
|
197
|
-
* Manages automatic database lifecycle: on-demand opening via a resolver,
|
|
198
|
-
* idle-timeout based closing, and LRU eviction when the maximum number of
|
|
199
|
-
* open databases is reached.
|
|
200
|
-
*/
|
|
201
43
|
declare class LifecycleManager {
|
|
44
|
+
#private;
|
|
202
45
|
private readonly config;
|
|
203
46
|
private readonly callbacks;
|
|
204
47
|
private readonly lastAccess;
|
|
205
48
|
private idleTimer;
|
|
206
49
|
private _disposed;
|
|
207
50
|
constructor(config: LifecycleConfig, callbacks: LifecycleCallbacks);
|
|
208
|
-
|
|
209
|
-
* Attempt to auto-open a database by ID using the configured resolver.
|
|
210
|
-
* Returns the opened Database, or `undefined` when no resolver is
|
|
211
|
-
* configured or the resolver does not recognise the ID.
|
|
212
|
-
*
|
|
213
|
-
* Throws {@link MaxDatabasesError} when the registry is at capacity and
|
|
214
|
-
* eviction cannot free a slot.
|
|
215
|
-
*/
|
|
216
|
-
resolve(id: string): Database$1 | undefined;
|
|
217
|
-
/** Record an access for the given database ID. */
|
|
51
|
+
resolve(id: string): Promise<Database | undefined>;
|
|
218
52
|
markActive(id: string): void;
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
* configured idle timeout. Also cleans up tracking entries for
|
|
222
|
-
* databases that were closed externally.
|
|
223
|
-
*/
|
|
224
|
-
checkIdle(): void;
|
|
225
|
-
/**
|
|
226
|
-
* Close the least-recently-used tracked database. Called internally
|
|
227
|
-
* by {@link resolve} when `maxOpen` capacity is reached.
|
|
228
|
-
*/
|
|
229
|
-
evict(): void;
|
|
230
|
-
/** Remove a database from idle tracking (e.g. after an explicit close). */
|
|
53
|
+
checkIdle(): Promise<void>;
|
|
54
|
+
evict(): Promise<void>;
|
|
231
55
|
untrack(id: string): void;
|
|
232
|
-
/** Whether this manager has been disposed. */
|
|
233
56
|
get disposed(): boolean;
|
|
234
|
-
/** The number of databases currently tracked for idle management. */
|
|
235
57
|
get trackedCount(): number;
|
|
236
|
-
/** Shut down the manager: stop the idle timer and clear all state. */
|
|
237
58
|
dispose(): void;
|
|
238
59
|
private ensureNotDisposed;
|
|
239
60
|
}
|
|
240
61
|
|
|
241
|
-
/**
|
|
242
|
-
* Options for {@link createTenantResolver}.
|
|
243
|
-
*/
|
|
244
62
|
interface TenantResolverOptions {
|
|
245
|
-
/** Base directory where tenant database files are stored. */
|
|
246
63
|
basePath: string;
|
|
247
|
-
/** File extension for database files. Default: `'.db'`. */
|
|
248
64
|
extension?: string;
|
|
249
|
-
/** Default options applied to every auto-opened tenant database. */
|
|
250
65
|
defaultOptions?: DatabaseOptions;
|
|
251
66
|
}
|
|
252
|
-
/**
|
|
253
|
-
* Validate and sanitize a tenant ID. Returns the ID unchanged when
|
|
254
|
-
* it passes validation, or `undefined` when it is invalid.
|
|
255
|
-
*
|
|
256
|
-
* Rules:
|
|
257
|
-
* - Must be 1–255 characters long
|
|
258
|
-
* - Must start with a letter or digit
|
|
259
|
-
* - May contain letters, digits, hyphens, and underscores
|
|
260
|
-
* - Must not contain `..` (redundant given the regex, but explicit)
|
|
261
|
-
*/
|
|
262
67
|
declare function sanitizeTenantId(id: string): string | undefined;
|
|
263
|
-
/**
|
|
264
|
-
* Build a filesystem path for a tenant database.
|
|
265
|
-
*
|
|
266
|
-
* @throws {Error} when the tenant ID fails validation.
|
|
267
|
-
*/
|
|
268
68
|
declare function tenantPath(basePath: string, tenantId: string, extension?: string): string;
|
|
269
|
-
/**
|
|
270
|
-
* Create a resolver function suitable for {@link LifecycleConfig.autoOpen}.
|
|
271
|
-
* Maps tenant IDs to database file paths under a common base directory.
|
|
272
|
-
*
|
|
273
|
-
* Invalid tenant IDs (path traversal, special characters) cause the
|
|
274
|
-
* resolver to return `undefined`, preventing the database from opening.
|
|
275
|
-
*/
|
|
276
69
|
declare function createTenantResolver(options: TenantResolverOptions): (id: string) => {
|
|
277
70
|
path: string;
|
|
278
71
|
options?: DatabaseOptions;
|
|
279
72
|
} | undefined;
|
|
280
73
|
|
|
281
|
-
type SqliteDb$1 = InstanceType<typeof Database>;
|
|
282
74
|
declare class MigrationRunner {
|
|
283
|
-
static run(
|
|
284
|
-
static rollback(
|
|
75
|
+
static run(conn: SQLiteConnection, migrations: Migration[]): Promise<MigrationResult>;
|
|
76
|
+
static rollback(conn: SQLiteConnection, migrations: Migration[], version?: number): Promise<RollbackResult>;
|
|
285
77
|
private static validateMigrations;
|
|
286
78
|
private static getAppliedVersions;
|
|
287
79
|
}
|
|
288
80
|
|
|
289
|
-
|
|
290
|
-
declare function
|
|
291
|
-
declare function
|
|
292
|
-
declare function
|
|
293
|
-
declare function executeBatch(db: SqliteDb, sql: string, paramsBatch: Params[]): ExecuteResult[];
|
|
81
|
+
declare function query<T = Record<string, unknown>>(conn: SQLiteConnection, sql: string, params?: Params): Promise<T[]>;
|
|
82
|
+
declare function queryOne<T = Record<string, unknown>>(conn: SQLiteConnection, sql: string, params?: Params): Promise<T | undefined>;
|
|
83
|
+
declare function execute(conn: SQLiteConnection, sql: string, params?: Params): Promise<ExecuteResult>;
|
|
84
|
+
declare function executeBatch(conn: SQLiteConnection, sql: string, paramsBatch: Params[]): Promise<ExecuteResult[]>;
|
|
294
85
|
|
|
295
|
-
export {
|
|
86
|
+
export { ConnectionPool, type ConnectionPoolOptions, Database, DatabaseOptions, ExecuteResult, type LifecycleCallbacks, LifecycleConfig, LifecycleManager, Migration, MigrationResult, MigrationRunner, Params, RollbackResult, SQLiteConnection, SQLiteDriver, type TenantResolverOptions, createTenantResolver, defineDriver, execute, executeBatch, query, queryOne, sanitizeTenantId, tenantPath };
|