@delali/sirannon-db 0.1.1 → 0.1.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.
- package/README.md +282 -77
- package/dist/backup-scheduler/index.d.ts +3 -0
- package/dist/backup-scheduler/index.mjs +2 -0
- package/dist/chunk-74UN4DIE.mjs +14 -0
- package/dist/{chunk-VI4UP4RR.mjs → chunk-AX66KWBR.mjs} +74 -139
- package/dist/chunk-FB2U2Q3Y.mjs +21 -0
- package/dist/chunk-O7BHI3CF.mjs +90 -0
- package/dist/chunk-PXKAKK2V.mjs +124 -0
- package/dist/client/index.d.ts +38 -2
- package/dist/core/index.d.ts +30 -142
- package/dist/core/index.mjs +229 -469
- 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/file-migrations/index.d.ts +16 -0
- package/dist/file-migrations/index.mjs +128 -0
- package/dist/index-hXiis3N-.d.ts +16 -0
- package/dist/server/index.d.ts +110 -54
- package/dist/server/index.mjs +107 -92
- package/dist/{sirannon-BJ8Yd1Uf.d.ts → sirannon-B1oTfebD.d.ts} +30 -58
- package/dist/types-BFSsG77t.d.ts +29 -0
- package/dist/types-DRkJlqex.d.ts +38 -0
- package/dist/{types-DArCObcu.d.ts → types-DtDutWRU.d.ts} +4 -1
- package/dist/vfs-INWQ5DTE.mjs +2 -0
- package/package.json +78 -27
- package/dist/protocol-BX1H-_Mz.d.ts +0 -104
package/dist/core/index.d.ts
CHANGED
|
@@ -1,88 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
4
|
-
import { D as Database
|
|
5
|
-
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* Creates a one-shot backup of the database using VACUUM INTO.
|
|
11
|
-
* Produces a fresh, defragmented copy at the specified destination path.
|
|
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-hXiis3N-.js';
|
|
2
|
+
import { S as SQLiteDriver, a as SQLiteConnection } from '../types-BFSsG77t.js';
|
|
3
|
+
export { D as DriverCapabilities, O as OpenOptions, R as RunResult, b as SQLiteStatement } from '../types-BFSsG77t.js';
|
|
4
|
+
import { D as Database } from '../sirannon-B1oTfebD.js';
|
|
5
|
+
export { H as HookDispose, a as HookEvent, b as HookEventContextMap, c as HookHandler, d as HookRegistry, M as MetricsCollector, S as Sirannon, e as SubscribeHookContext } from '../sirannon-B1oTfebD.js';
|
|
6
|
+
import { D as DatabaseOptions, L as LifecycleConfig, P as Params, E as ExecuteResult } from '../types-DtDutWRU.js';
|
|
7
|
+
export { A as AfterQueryHook, e as BackupScheduleOptions, h as BeforeConnectHook, f as BeforeQueryHook, B as BeforeSubscribeHook, c as CDCMetrics, k as ChangeEvent, l as ChangeOperation, m as ClientOptions, C as ConnectionHookContext, b as ConnectionMetrics, n as CorsOptions, j as DatabaseCloseHook, i as DatabaseOpenHook, H as HookConfig, M as MetricsConfig, O as OnRequestHook, Q as QueryHookContext, a as QueryMetrics, R as RequestContext, o as RequestDenial, S as ServerOptions, g as SirannonOptions, p as Subscription, d as SubscriptionBuilder, W as WSHandlerOptions } from '../types-DtDutWRU.js';
|
|
8
|
+
import { M as Migration, a as MigrationResult, R as RollbackResult } from '../types-DRkJlqex.js';
|
|
9
|
+
export { A as AppliedMigration, b as AppliedMigrationEntry, T as Transaction } from '../types-DRkJlqex.js';
|
|
64
10
|
|
|
65
11
|
interface ConnectionPoolOptions {
|
|
12
|
+
driver: SQLiteDriver;
|
|
66
13
|
path: string;
|
|
67
14
|
readOnly?: boolean;
|
|
68
15
|
readPoolSize?: number;
|
|
69
16
|
walMode?: boolean;
|
|
70
17
|
}
|
|
71
|
-
type SqliteDb$2 = InstanceType<typeof Database>;
|
|
72
18
|
declare class ConnectionPool {
|
|
73
19
|
private readonly writer;
|
|
74
20
|
private readonly readers;
|
|
75
21
|
private readerIndex;
|
|
76
22
|
private closed;
|
|
77
|
-
constructor(
|
|
78
|
-
|
|
79
|
-
|
|
23
|
+
private constructor();
|
|
24
|
+
static create(options: ConnectionPoolOptions): Promise<ConnectionPool>;
|
|
25
|
+
acquireReader(): SQLiteConnection;
|
|
26
|
+
acquireWriter(): SQLiteConnection;
|
|
80
27
|
get readerCount(): number;
|
|
81
28
|
get isReadOnly(): boolean;
|
|
82
|
-
|
|
83
|
-
close(): void;
|
|
29
|
+
close(): Promise<void>;
|
|
84
30
|
}
|
|
85
31
|
|
|
32
|
+
declare function defineDriver(config: SQLiteDriver): SQLiteDriver;
|
|
33
|
+
|
|
86
34
|
/**
|
|
87
35
|
* Base class for all sirannon-db errors. Extend this class to create
|
|
88
36
|
* domain-specific errors that carry a machine-readable {@link code}.
|
|
@@ -183,113 +131,53 @@ declare class ExtensionError extends SirannonError {
|
|
|
183
131
|
constructor(path: string, cause?: string);
|
|
184
132
|
}
|
|
185
133
|
|
|
186
|
-
/**
|
|
187
|
-
* Callbacks the LifecycleManager uses to interact with the database registry
|
|
188
|
-
* (Sirannon). Injected at construction to avoid circular dependencies.
|
|
189
|
-
*/
|
|
190
134
|
interface LifecycleCallbacks {
|
|
191
|
-
open: (id: string, path: string, options?: DatabaseOptions) => Database
|
|
192
|
-
close: (id: string) => void
|
|
135
|
+
open: (id: string, path: string, options?: DatabaseOptions) => Promise<Database>;
|
|
136
|
+
close: (id: string) => Promise<void>;
|
|
193
137
|
count: () => number;
|
|
194
138
|
has: (id: string) => boolean;
|
|
195
139
|
}
|
|
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
140
|
declare class LifecycleManager {
|
|
141
|
+
#private;
|
|
202
142
|
private readonly config;
|
|
203
143
|
private readonly callbacks;
|
|
204
144
|
private readonly lastAccess;
|
|
205
145
|
private idleTimer;
|
|
206
146
|
private _disposed;
|
|
207
147
|
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. */
|
|
148
|
+
resolve(id: string): Promise<Database | undefined>;
|
|
218
149
|
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). */
|
|
150
|
+
checkIdle(): Promise<void>;
|
|
151
|
+
evict(): Promise<void>;
|
|
231
152
|
untrack(id: string): void;
|
|
232
|
-
/** Whether this manager has been disposed. */
|
|
233
153
|
get disposed(): boolean;
|
|
234
|
-
/** The number of databases currently tracked for idle management. */
|
|
235
154
|
get trackedCount(): number;
|
|
236
|
-
/** Shut down the manager: stop the idle timer and clear all state. */
|
|
237
155
|
dispose(): void;
|
|
238
156
|
private ensureNotDisposed;
|
|
239
157
|
}
|
|
240
158
|
|
|
241
|
-
/**
|
|
242
|
-
* Options for {@link createTenantResolver}.
|
|
243
|
-
*/
|
|
244
159
|
interface TenantResolverOptions {
|
|
245
|
-
/** Base directory where tenant database files are stored. */
|
|
246
160
|
basePath: string;
|
|
247
|
-
/** File extension for database files. Default: `'.db'`. */
|
|
248
161
|
extension?: string;
|
|
249
|
-
/** Default options applied to every auto-opened tenant database. */
|
|
250
162
|
defaultOptions?: DatabaseOptions;
|
|
251
163
|
}
|
|
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
164
|
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
165
|
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
166
|
declare function createTenantResolver(options: TenantResolverOptions): (id: string) => {
|
|
277
167
|
path: string;
|
|
278
168
|
options?: DatabaseOptions;
|
|
279
169
|
} | undefined;
|
|
280
170
|
|
|
281
|
-
type SqliteDb$1 = InstanceType<typeof Database>;
|
|
282
171
|
declare class MigrationRunner {
|
|
283
|
-
static run(
|
|
284
|
-
static rollback(
|
|
172
|
+
static run(conn: SQLiteConnection, migrations: Migration[]): Promise<MigrationResult>;
|
|
173
|
+
static rollback(conn: SQLiteConnection, migrations: Migration[], version?: number): Promise<RollbackResult>;
|
|
285
174
|
private static validateMigrations;
|
|
286
175
|
private static getAppliedVersions;
|
|
287
176
|
}
|
|
288
177
|
|
|
289
|
-
|
|
290
|
-
declare function
|
|
291
|
-
declare function
|
|
292
|
-
declare function
|
|
293
|
-
declare function executeBatch(db: SqliteDb, sql: string, paramsBatch: Params[]): ExecuteResult[];
|
|
178
|
+
declare function query<T = Record<string, unknown>>(conn: SQLiteConnection, sql: string, params?: Params): Promise<T[]>;
|
|
179
|
+
declare function queryOne<T = Record<string, unknown>>(conn: SQLiteConnection, sql: string, params?: Params): Promise<T | undefined>;
|
|
180
|
+
declare function execute(conn: SQLiteConnection, sql: string, params?: Params): Promise<ExecuteResult>;
|
|
181
|
+
declare function executeBatch(conn: SQLiteConnection, sql: string, paramsBatch: Params[]): Promise<ExecuteResult[]>;
|
|
294
182
|
|
|
295
|
-
export { BackupError,
|
|
183
|
+
export { BackupError, CDCError, ConnectionPool, ConnectionPoolError, type ConnectionPoolOptions, Database, DatabaseAlreadyExistsError, DatabaseNotFoundError, DatabaseOptions, ExecuteResult, ExtensionError, HookDeniedError, type LifecycleCallbacks, LifecycleConfig, LifecycleManager, MaxDatabasesError, Migration, MigrationError, MigrationResult, MigrationRunner, Params, QueryError, ReadOnlyError, RollbackResult, SQLiteConnection, SQLiteDriver, SirannonError, type TenantResolverOptions, TransactionError, createTenantResolver, defineDriver, execute, executeBatch, query, queryOne, sanitizeTenantId, tenantPath };
|