@framers/sql-storage-adapter 0.7.1 → 0.7.3
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 +43 -0
- package/dist/adapters/electron/preload.cjs +289 -0
- package/dist/adapters/electron/renderer.d.ts +9 -0
- package/dist/adapters/electron/renderer.d.ts.map +1 -0
- package/dist/adapters/electron/renderer.js +8 -0
- package/dist/adapters/electron/renderer.js.map +1 -0
- package/dist/cjs/adapters/__tests__/indexedDbAdapter.spec.d.ts +2 -0
- package/dist/cjs/adapters/__tests__/indexedDbAdapter.spec.js +133 -0
- package/dist/cjs/adapters/baseStorageAdapter.d.ts +368 -0
- package/dist/cjs/adapters/baseStorageAdapter.js +744 -0
- package/dist/cjs/adapters/betterSqliteAdapter.d.ts +124 -0
- package/dist/cjs/adapters/betterSqliteAdapter.js +334 -0
- package/dist/cjs/adapters/capacitorSqliteAdapter.d.ts +83 -0
- package/dist/cjs/adapters/capacitorSqliteAdapter.js +250 -0
- package/dist/cjs/adapters/electron/electronMainAdapter.d.ts +251 -0
- package/dist/cjs/adapters/electron/electronMainAdapter.js +392 -0
- package/dist/cjs/adapters/electron/electronRendererAdapter.d.ts +177 -0
- package/dist/cjs/adapters/electron/electronRendererAdapter.js +283 -0
- package/dist/cjs/adapters/electron/index.d.ts +74 -0
- package/dist/cjs/adapters/electron/index.js +86 -0
- package/dist/cjs/adapters/electron/ipc/channels.d.ts +196 -0
- package/dist/cjs/adapters/electron/ipc/channels.js +127 -0
- package/dist/cjs/adapters/electron/ipc/index.d.ts +11 -0
- package/dist/cjs/adapters/electron/ipc/index.js +38 -0
- package/dist/cjs/adapters/electron/ipc/protocol.d.ts +78 -0
- package/dist/cjs/adapters/electron/ipc/protocol.js +341 -0
- package/dist/cjs/adapters/electron/ipc/types.d.ts +248 -0
- package/dist/cjs/adapters/electron/ipc/types.js +15 -0
- package/dist/cjs/adapters/electron/migration/autoMigrator.d.ts +184 -0
- package/dist/cjs/adapters/electron/migration/autoMigrator.js +441 -0
- package/dist/cjs/adapters/electron/migration/index.d.ts +9 -0
- package/dist/cjs/adapters/electron/migration/index.js +29 -0
- package/dist/cjs/adapters/electron/preload.d.ts +126 -0
- package/dist/cjs/adapters/electron/preload.js +233 -0
- package/dist/cjs/adapters/electron/recovery/corruptionDetector.d.ts +214 -0
- package/dist/cjs/adapters/electron/recovery/corruptionDetector.js +359 -0
- package/dist/cjs/adapters/electron/recovery/index.d.ts +11 -0
- package/dist/cjs/adapters/electron/recovery/index.js +34 -0
- package/dist/cjs/adapters/electron/recovery/walCheckpoint.d.ts +186 -0
- package/dist/cjs/adapters/electron/recovery/walCheckpoint.js +263 -0
- package/dist/cjs/adapters/electron/renderer.d.ts +9 -0
- package/dist/cjs/adapters/electron/renderer.js +33 -0
- package/dist/cjs/adapters/electron/window/index.d.ts +9 -0
- package/dist/cjs/adapters/electron/window/index.js +29 -0
- package/dist/cjs/adapters/electron/window/windowManager.d.ts +190 -0
- package/dist/cjs/adapters/electron/window/windowManager.js +321 -0
- package/dist/cjs/adapters/indexedDbAdapter.d.ts +490 -0
- package/dist/cjs/adapters/indexedDbAdapter.js +993 -0
- package/dist/cjs/adapters/postgresAdapter.d.ts +424 -0
- package/dist/cjs/adapters/postgresAdapter.js +889 -0
- package/dist/cjs/adapters/sqlJsAdapter.d.ts +64 -0
- package/dist/cjs/adapters/sqlJsAdapter.js +268 -0
- package/dist/cjs/adapters/supabase.d.ts +58 -0
- package/dist/cjs/adapters/supabase.js +401 -0
- package/dist/cjs/codecs/BrowserBlobCodec.d.ts +14 -0
- package/dist/cjs/codecs/BrowserBlobCodec.js +57 -0
- package/dist/cjs/codecs/NodeBlobCodec.d.ts +14 -0
- package/dist/cjs/codecs/NodeBlobCodec.js +59 -0
- package/dist/cjs/core/contracts/blobCodec.d.ts +15 -0
- package/dist/cjs/core/contracts/blobCodec.js +15 -0
- package/dist/cjs/core/contracts/context.d.ts +221 -0
- package/dist/cjs/core/contracts/context.js +15 -0
- package/dist/cjs/core/contracts/dialect.d.ts +154 -0
- package/dist/cjs/core/contracts/dialect.js +15 -0
- package/dist/cjs/core/contracts/events.d.ts +225 -0
- package/dist/cjs/core/contracts/events.js +15 -0
- package/dist/cjs/core/contracts/exporter.d.ts +13 -0
- package/dist/cjs/core/contracts/exporter.js +15 -0
- package/dist/cjs/core/contracts/extensions.d.ts +73 -0
- package/dist/cjs/core/contracts/extensions.js +15 -0
- package/dist/cjs/core/contracts/features.d.ts +25 -0
- package/dist/cjs/core/contracts/features.js +61 -0
- package/dist/cjs/core/contracts/fts.d.ts +66 -0
- package/dist/cjs/core/contracts/fts.js +15 -0
- package/dist/cjs/core/contracts/hooks.d.ts +481 -0
- package/dist/cjs/core/contracts/hooks.js +140 -0
- package/dist/cjs/core/contracts/index.d.ts +260 -0
- package/dist/cjs/core/contracts/index.js +41 -0
- package/dist/cjs/core/contracts/limitations.d.ts +46 -0
- package/dist/cjs/core/contracts/limitations.js +218 -0
- package/dist/cjs/core/contracts/performance.d.ts +308 -0
- package/dist/cjs/core/contracts/performance.js +144 -0
- package/dist/cjs/core/database.d.ts +220 -0
- package/dist/cjs/core/database.js +136 -0
- package/dist/cjs/core/portable.d.ts +23 -0
- package/dist/cjs/core/portable.js +66 -0
- package/dist/cjs/core/resolver.d.ts +77 -0
- package/dist/cjs/core/resolver.js +235 -0
- package/dist/cjs/dialects/PostgresDialect.d.ts +35 -0
- package/dist/cjs/dialects/PostgresDialect.js +143 -0
- package/dist/cjs/dialects/SqliteDialect.d.ts +35 -0
- package/dist/cjs/dialects/SqliteDialect.js +142 -0
- package/dist/cjs/dialects/shared.d.ts +17 -0
- package/dist/cjs/dialects/shared.js +90 -0
- package/dist/cjs/exporters/PostgresExporter.d.ts +14 -0
- package/dist/cjs/exporters/PostgresExporter.js +61 -0
- package/dist/cjs/exporters/SqliteFileExporter.d.ts +16 -0
- package/dist/cjs/exporters/SqliteFileExporter.js +43 -0
- package/dist/cjs/features/backup/cloudBackup.d.ts +219 -0
- package/dist/cjs/features/backup/cloudBackup.js +209 -0
- package/dist/cjs/features/kv/idb.d.ts +79 -0
- package/dist/cjs/features/kv/idb.js +32 -0
- package/dist/cjs/features/kv/index.d.ts +14 -0
- package/dist/cjs/features/kv/index.js +40 -0
- package/dist/cjs/features/kv/indexedDbKeyValueStore.d.ts +77 -0
- package/dist/cjs/features/kv/indexedDbKeyValueStore.js +116 -0
- package/dist/cjs/features/kv/keyValueStore.d.ts +48 -0
- package/dist/cjs/features/kv/keyValueStore.js +67 -0
- package/dist/cjs/features/kv/sqlKeyValueStore.d.ts +34 -0
- package/dist/cjs/features/kv/sqlKeyValueStore.js +81 -0
- package/dist/cjs/features/kv/valueCodec.d.ts +35 -0
- package/dist/cjs/features/kv/valueCodec.js +426 -0
- package/dist/cjs/features/migrations/dataExport.d.ts +77 -0
- package/dist/cjs/features/migrations/dataExport.js +194 -0
- package/dist/cjs/features/migrations/dataImport.d.ts +54 -0
- package/dist/cjs/features/migrations/dataImport.js +300 -0
- package/dist/cjs/features/migrations/migration.d.ts +89 -0
- package/dist/cjs/features/migrations/migration.js +187 -0
- package/dist/cjs/features/migrations/schemaMigrations.d.ts +93 -0
- package/dist/cjs/features/migrations/schemaMigrations.js +220 -0
- package/dist/cjs/features/sync/conflicts/conflictResolver.d.ts +222 -0
- package/dist/cjs/features/sync/conflicts/conflictResolver.js +366 -0
- package/dist/cjs/features/sync/conflicts/index.d.ts +9 -0
- package/dist/cjs/features/sync/conflicts/index.js +21 -0
- package/dist/cjs/features/sync/crossPlatformSync.d.ts +281 -0
- package/dist/cjs/features/sync/crossPlatformSync.js +551 -0
- package/dist/cjs/features/sync/devices/deviceManager.d.ts +243 -0
- package/dist/cjs/features/sync/devices/deviceManager.js +450 -0
- package/dist/cjs/features/sync/devices/index.d.ts +10 -0
- package/dist/cjs/features/sync/devices/index.js +21 -0
- package/dist/cjs/features/sync/index.d.ts +37 -0
- package/dist/cjs/features/sync/index.js +111 -0
- package/dist/cjs/features/sync/protocol/index.d.ts +11 -0
- package/dist/cjs/features/sync/protocol/index.js +23 -0
- package/dist/cjs/features/sync/protocol/messages.d.ts +348 -0
- package/dist/cjs/features/sync/protocol/messages.js +215 -0
- package/dist/cjs/features/sync/protocol/vectorClock.d.ts +164 -0
- package/dist/cjs/features/sync/protocol/vectorClock.js +256 -0
- package/dist/cjs/features/sync/syncManager.d.ts +348 -0
- package/dist/cjs/features/sync/syncManager.js +455 -0
- package/dist/cjs/features/sync/tables/index.d.ts +10 -0
- package/dist/cjs/features/sync/tables/index.js +21 -0
- package/dist/cjs/features/sync/tables/syncLogManager.d.ts +216 -0
- package/dist/cjs/features/sync/tables/syncLogManager.js +423 -0
- package/dist/cjs/features/sync/transport/httpTransport.d.ts +123 -0
- package/dist/cjs/features/sync/transport/httpTransport.js +346 -0
- package/dist/cjs/features/sync/transport/index.d.ts +12 -0
- package/dist/cjs/features/sync/transport/index.js +25 -0
- package/dist/cjs/features/sync/transport/transport.d.ts +259 -0
- package/dist/cjs/features/sync/transport/transport.js +163 -0
- package/dist/cjs/features/sync/transport/websocketTransport.d.ts +126 -0
- package/dist/cjs/features/sync/transport/websocketTransport.js +342 -0
- package/dist/cjs/fts/PostgresFts.d.ts +29 -0
- package/dist/cjs/fts/PostgresFts.js +77 -0
- package/dist/cjs/fts/SqliteFts5.d.ts +22 -0
- package/dist/cjs/fts/SqliteFts5.js +58 -0
- package/dist/cjs/index.d.ts +30 -0
- package/dist/cjs/index.js +101 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/shared/connectionGate.d.ts +94 -0
- package/dist/cjs/shared/connectionGate.js +77 -0
- package/dist/cjs/shared/errors.d.ts +23 -0
- package/dist/cjs/shared/errors.js +45 -0
- package/dist/cjs/shared/logger.d.ts +26 -0
- package/dist/cjs/shared/logger.js +40 -0
- package/dist/cjs/shared/parameterUtils.d.ts +16 -0
- package/dist/cjs/shared/parameterUtils.js +59 -0
- package/dist/cjs/shared/postgresTarget.d.ts +11 -0
- package/dist/cjs/shared/postgresTarget.js +30 -0
- package/dist/cjs/shared/segment.d.ts +43 -0
- package/dist/cjs/shared/segment.js +63 -0
- package/dist/cjs/shared/serializedTransaction.d.ts +14 -0
- package/dist/cjs/shared/serializedTransaction.js +74 -0
- package/dist/cjs/shared/splitSqlStatements.d.ts +27 -0
- package/dist/cjs/shared/splitSqlStatements.js +163 -0
- package/dist/cjs/shared/sqlPlaceholders.d.ts +48 -0
- package/dist/cjs/shared/sqlPlaceholders.js +263 -0
- package/dist/cjs/types/index.d.ts +29 -0
- package/dist/cjs/types/index.js +33 -0
- package/dist/core/portable.d.ts +23 -0
- package/dist/core/portable.d.ts.map +1 -0
- package/dist/core/portable.js +23 -0
- package/dist/core/portable.js.map +1 -0
- package/dist/features/migrations/schemaMigrations.d.ts +93 -0
- package/dist/features/migrations/schemaMigrations.d.ts.map +1 -0
- package/dist/features/migrations/schemaMigrations.js +216 -0
- package/dist/features/migrations/schemaMigrations.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +139 -24
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Core type definitions for the SQL storage adapter abstraction.
|
|
4
|
+
*
|
|
5
|
+
* This package provides a unified interface for SQL storage across multiple platforms,
|
|
6
|
+
* with automatic fallback mechanisms and runtime detection.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Supported storage capability flags.
|
|
10
|
+
*
|
|
11
|
+
* These flags indicate what features are available for each adapter implementation.
|
|
12
|
+
* Consumers should check these capabilities before attempting operations that may
|
|
13
|
+
* not be universally supported.
|
|
14
|
+
*/
|
|
15
|
+
export type StorageCapability = 'sync' | 'transactions' | 'wal' | 'locks' | 'persistence' | 'streaming' | 'batch' | 'prepared' | 'concurrent' | 'json' | 'arrays';
|
|
16
|
+
/**
|
|
17
|
+
* Parameter payload accepted by storage statements.
|
|
18
|
+
*
|
|
19
|
+
* Parameters can be provided in multiple formats:
|
|
20
|
+
* - Named parameters: `{ name: 'John', age: 30 }` for statements like `WHERE name = @name`
|
|
21
|
+
* - Positional parameters: `['John', 30]` for statements like `WHERE name = ? AND age = ?`
|
|
22
|
+
* - No parameters: `undefined` or `null` for parameterless queries
|
|
23
|
+
*/
|
|
24
|
+
export type StorageParameters = undefined | null | Record<string, unknown> | Array<string | number | null | Uint8Array | unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* Result metadata for mutation statements (INSERT, UPDATE, DELETE).
|
|
27
|
+
*/
|
|
28
|
+
export interface StorageRunResult {
|
|
29
|
+
/** Number of rows affected by the statement. */
|
|
30
|
+
changes: number;
|
|
31
|
+
/** Row identifier (if available) returned by the underlying engine. */
|
|
32
|
+
lastInsertRowid?: string | number | null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Batch operation descriptor for bulk operations.
|
|
36
|
+
*/
|
|
37
|
+
export interface BatchOperation {
|
|
38
|
+
/** SQL statement to execute */
|
|
39
|
+
statement: string;
|
|
40
|
+
/** Parameters for this specific operation */
|
|
41
|
+
parameters?: StorageParameters;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Result of a batch operation execution.
|
|
45
|
+
*/
|
|
46
|
+
export interface BatchResult {
|
|
47
|
+
/** Number of successfully executed operations */
|
|
48
|
+
successful: number;
|
|
49
|
+
/** Number of failed operations */
|
|
50
|
+
failed: number;
|
|
51
|
+
/** Individual results for each operation (if adapter supports it) */
|
|
52
|
+
results?: StorageRunResult[];
|
|
53
|
+
/** Errors for failed operations (if any) */
|
|
54
|
+
errors?: Array<{
|
|
55
|
+
index: number;
|
|
56
|
+
error: Error;
|
|
57
|
+
}>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Options accepted when opening a storage adapter.
|
|
61
|
+
*/
|
|
62
|
+
export interface StorageOpenOptions {
|
|
63
|
+
/** Absolute path to the primary database file (when applicable). */
|
|
64
|
+
filePath?: string;
|
|
65
|
+
/** Connection string (PostgreSQL, etc.). */
|
|
66
|
+
connectionString?: string;
|
|
67
|
+
/** Optional flag to force read-only mode. */
|
|
68
|
+
readOnly?: boolean;
|
|
69
|
+
/** Arbitrary adapter-specific options bag. */
|
|
70
|
+
adapterOptions?: Record<string, unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* SQLite: `true` turns foreign-key enforcement on and `false` turns it off
|
|
73
|
+
* (`PRAGMA foreign_keys`) when the adapter opens, and the setting holds
|
|
74
|
+
* when sql.js reopens its connection (a save, an export, an import). Left
|
|
75
|
+
* out, each engine keeps its default: better-sqlite3 is built with
|
|
76
|
+
* `SQLITE_DEFAULT_FOREIGN_KEYS=1` and enforces them; sql.js, IndexedDB and
|
|
77
|
+
* Capacitor do not. PostgreSQL always enforces foreign keys and ignores this.
|
|
78
|
+
*/
|
|
79
|
+
foreignKeys?: boolean;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Core SQL storage adapter interface.
|
|
83
|
+
*
|
|
84
|
+
* Every adapter implementation must fulfill this contract to ensure
|
|
85
|
+
* compatibility across different SQL backends. Check the `capabilities`
|
|
86
|
+
* property to determine which optional features are supported.
|
|
87
|
+
*
|
|
88
|
+
* ## Error Handling
|
|
89
|
+
* All methods should throw meaningful errors when operations fail.
|
|
90
|
+
* Adapters should not silently fail or return undefined on errors.
|
|
91
|
+
*
|
|
92
|
+
* ## Thread Safety
|
|
93
|
+
* Adapters should document their thread-safety guarantees. SQLite adapters
|
|
94
|
+
* typically don't support concurrent writes, while PostgreSQL does.
|
|
95
|
+
*/
|
|
96
|
+
export interface StorageAdapter {
|
|
97
|
+
/** Identifier for logging/diagnostics (e.g., 'better-sqlite3', 'postgres'). */
|
|
98
|
+
readonly kind: string;
|
|
99
|
+
/** Capability flags indicating supported features. */
|
|
100
|
+
readonly capabilities: ReadonlySet<StorageCapability>;
|
|
101
|
+
/**
|
|
102
|
+
* Opens the underlying connection or initializes the backing store.
|
|
103
|
+
*
|
|
104
|
+
* @throws {Error} If connection cannot be established
|
|
105
|
+
* @example
|
|
106
|
+
* await adapter.open({ filePath: '/path/to/db.sqlite3' });
|
|
107
|
+
*/
|
|
108
|
+
open(options?: StorageOpenOptions): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Executes a mutation statement (INSERT, UPDATE, DELETE).
|
|
111
|
+
*
|
|
112
|
+
* @param statement - SQL statement to execute
|
|
113
|
+
* @param parameters - Optional parameters for the statement
|
|
114
|
+
* @returns Metadata about affected rows
|
|
115
|
+
* @throws {Error} If statement execution fails
|
|
116
|
+
* @example
|
|
117
|
+
* const result = await adapter.run('INSERT INTO users (name) VALUES (?)', ['John']);
|
|
118
|
+
* console.log(`Inserted with ID: ${result.lastInsertRowid}`);
|
|
119
|
+
*/
|
|
120
|
+
run(statement: string, parameters?: StorageParameters): Promise<StorageRunResult>;
|
|
121
|
+
/**
|
|
122
|
+
* Retrieves a single row (or null if none found).
|
|
123
|
+
*
|
|
124
|
+
* @param statement - SQL SELECT statement
|
|
125
|
+
* @param parameters - Optional parameters for the statement
|
|
126
|
+
* @returns First row or null if no results
|
|
127
|
+
* @throws {Error} If query execution fails
|
|
128
|
+
* @example
|
|
129
|
+
* const user = await adapter.get<User>('SELECT * FROM users WHERE id = ?', [123]);
|
|
130
|
+
*/
|
|
131
|
+
get<T = unknown>(statement: string, parameters?: StorageParameters): Promise<T | null>;
|
|
132
|
+
/**
|
|
133
|
+
* Retrieves all rows returned by the statement.
|
|
134
|
+
*
|
|
135
|
+
* WARNING: For large result sets, this loads everything into memory.
|
|
136
|
+
* Consider using streaming (if supported) for large queries.
|
|
137
|
+
*
|
|
138
|
+
* @param statement - SQL SELECT statement
|
|
139
|
+
* @param parameters - Optional parameters for the statement
|
|
140
|
+
* @returns Array of all matching rows (empty array if none)
|
|
141
|
+
* @throws {Error} If query execution fails
|
|
142
|
+
* @example
|
|
143
|
+
* const users = await adapter.all<User>('SELECT * FROM users WHERE age > ?', [18]);
|
|
144
|
+
*/
|
|
145
|
+
all<T = unknown>(statement: string, parameters?: StorageParameters): Promise<T[]>;
|
|
146
|
+
/**
|
|
147
|
+
* Executes a script containing multiple SQL statements.
|
|
148
|
+
*
|
|
149
|
+
* Statements are typically delimited by semicolons. This is useful for
|
|
150
|
+
* running migrations or initialization scripts. No results are returned.
|
|
151
|
+
*
|
|
152
|
+
* @param script - SQL script with multiple statements
|
|
153
|
+
* @throws {Error} If any statement in the script fails
|
|
154
|
+
* @example
|
|
155
|
+
* await adapter.exec(`
|
|
156
|
+
* CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);
|
|
157
|
+
* CREATE INDEX idx_users_name ON users(name);
|
|
158
|
+
* `);
|
|
159
|
+
*/
|
|
160
|
+
exec(script: string): Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* Executes a callback within a database transaction.
|
|
163
|
+
*
|
|
164
|
+
* The transaction is automatically committed on success or rolled back
|
|
165
|
+
* on error. Nested transactions may not be supported by all adapters.
|
|
166
|
+
*
|
|
167
|
+
* @param fn - Async callback to execute within the transaction
|
|
168
|
+
* @returns Result of the callback function
|
|
169
|
+
* @throws {Error} Transaction is rolled back and error is re-thrown
|
|
170
|
+
* @example
|
|
171
|
+
* const result = await adapter.transaction(async (trx) => {
|
|
172
|
+
* await trx.run('INSERT INTO accounts (balance) VALUES (?)', [100]);
|
|
173
|
+
* await trx.run('INSERT INTO logs (action) VALUES (?)', ['account_created']);
|
|
174
|
+
* return { success: true };
|
|
175
|
+
* });
|
|
176
|
+
*/
|
|
177
|
+
transaction<T>(fn: (trx: StorageAdapter) => Promise<T>): Promise<T>;
|
|
178
|
+
/**
|
|
179
|
+
* Closes the underlying connection and releases resources.
|
|
180
|
+
*
|
|
181
|
+
* After calling close(), the adapter should not be used again.
|
|
182
|
+
* Always close adapters when done to prevent resource leaks.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* try {
|
|
186
|
+
* await adapter.open();
|
|
187
|
+
* // ... use adapter ...
|
|
188
|
+
* } finally {
|
|
189
|
+
* await adapter.close();
|
|
190
|
+
* }
|
|
191
|
+
*/
|
|
192
|
+
close(): Promise<void>;
|
|
193
|
+
/**
|
|
194
|
+
* Executes multiple operations in a batch (if supported).
|
|
195
|
+
*
|
|
196
|
+
* This is more efficient than executing operations individually,
|
|
197
|
+
* especially for bulk inserts. Check if 'batch' capability is present.
|
|
198
|
+
*
|
|
199
|
+
* @param operations - Array of operations to execute
|
|
200
|
+
* @returns Batch execution results
|
|
201
|
+
* @throws {Error} If adapter doesn't support batch operations
|
|
202
|
+
* @example
|
|
203
|
+
* if (adapter.capabilities.has('batch')) {
|
|
204
|
+
* const result = await adapter.batch([
|
|
205
|
+
* { statement: 'INSERT INTO users (name) VALUES (?)', parameters: ['Alice'] },
|
|
206
|
+
* { statement: 'INSERT INTO users (name) VALUES (?)', parameters: ['Bob'] }
|
|
207
|
+
* ]);
|
|
208
|
+
* }
|
|
209
|
+
*/
|
|
210
|
+
batch?(operations: BatchOperation[]): Promise<BatchResult>;
|
|
211
|
+
/**
|
|
212
|
+
* Returns a prepared statement for repeated execution (if supported).
|
|
213
|
+
*
|
|
214
|
+
* Prepared statements improve performance for frequently executed queries
|
|
215
|
+
* and provide better protection against SQL injection. Check if 'prepared'
|
|
216
|
+
* capability is present.
|
|
217
|
+
*
|
|
218
|
+
* @param statement - SQL statement to prepare
|
|
219
|
+
* @returns Prepared statement handle
|
|
220
|
+
* @throws {Error} If adapter doesn't support prepared statements
|
|
221
|
+
*/
|
|
222
|
+
prepare?<T = unknown>(statement: string): PreparedStatement<T>;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Prepared statement interface for repeated query execution.
|
|
226
|
+
*/
|
|
227
|
+
export interface PreparedStatement<T = unknown> {
|
|
228
|
+
run(parameters?: StorageParameters): Promise<StorageRunResult>;
|
|
229
|
+
get(parameters?: StorageParameters): Promise<T | null>;
|
|
230
|
+
all(parameters?: StorageParameters): Promise<T[]>;
|
|
231
|
+
finalize(): Promise<void>;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Shape of adapter factories returned by resolver modules.
|
|
235
|
+
*/
|
|
236
|
+
export type StorageAdapterFactory = () => Promise<StorageAdapter>;
|
|
237
|
+
/**
|
|
238
|
+
* Error thrown when no adapter can be resolved.
|
|
239
|
+
*/
|
|
240
|
+
export declare class StorageResolutionError extends Error {
|
|
241
|
+
readonly causes: unknown[];
|
|
242
|
+
constructor(message: string, causes?: unknown[]);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Performance configuration types for cost/accuracy optimization.
|
|
246
|
+
* See `OPTIMIZATION_GUIDE.md` for detailed usage documentation.
|
|
247
|
+
*/
|
|
248
|
+
export * from './performance.js';
|
|
249
|
+
/**
|
|
250
|
+
* Lifecycle hooks for extending adapter behavior.
|
|
251
|
+
* Designed for RAG integration, analytics, and auditing.
|
|
252
|
+
*/
|
|
253
|
+
export * from './hooks.js';
|
|
254
|
+
export type { SqlDialect, JsonValueType, CastType, IntervalUnit, DateBucketUnit, ColumnKind } from './dialect.js';
|
|
255
|
+
export type { IFullTextSearch } from './fts.js';
|
|
256
|
+
export type { IBlobCodec } from './blobCodec.js';
|
|
257
|
+
export type { IDatabaseExporter } from './exporter.js';
|
|
258
|
+
export type { StorageFeatures } from './features.js';
|
|
259
|
+
export { createStorageFeatures } from './features.js';
|
|
260
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var contracts_exports = {};
|
|
20
|
+
__export(contracts_exports, {
|
|
21
|
+
StorageResolutionError: () => StorageResolutionError,
|
|
22
|
+
createStorageFeatures: () => import_features.createStorageFeatures
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(contracts_exports);
|
|
25
|
+
__reExport(contracts_exports, require("./performance.js"), module.exports);
|
|
26
|
+
__reExport(contracts_exports, require("./hooks.js"), module.exports);
|
|
27
|
+
var import_features = require("./features.js");
|
|
28
|
+
class StorageResolutionError extends Error {
|
|
29
|
+
constructor(message, causes = []) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.causes = causes;
|
|
32
|
+
this.name = "StorageResolutionError";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
StorageResolutionError,
|
|
38
|
+
createStorageFeatures,
|
|
39
|
+
...require("./performance.js"),
|
|
40
|
+
...require("./hooks.js")
|
|
41
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter-specific limitation definitions.
|
|
3
|
+
*
|
|
4
|
+
* This module provides concrete limitation specifications for each
|
|
5
|
+
* supported database adapter, enabling runtime introspection and
|
|
6
|
+
* automatic constraint enforcement.
|
|
7
|
+
*/
|
|
8
|
+
import type { AdapterLimitations } from './context.js';
|
|
9
|
+
/**
|
|
10
|
+
* Limitations for better-sqlite3 adapter.
|
|
11
|
+
*/
|
|
12
|
+
export declare const BETTER_SQLITE3_LIMITATIONS: AdapterLimitations;
|
|
13
|
+
/**
|
|
14
|
+
* Limitations for SQL.js adapter (WebAssembly SQLite).
|
|
15
|
+
*/
|
|
16
|
+
export declare const SQLJS_LIMITATIONS: AdapterLimitations;
|
|
17
|
+
/**
|
|
18
|
+
* Limitations for Capacitor SQLite adapter (mobile).
|
|
19
|
+
*/
|
|
20
|
+
export declare const CAPACITOR_SQLITE_LIMITATIONS: AdapterLimitations;
|
|
21
|
+
/**
|
|
22
|
+
* Limitations for PostgreSQL adapter.
|
|
23
|
+
*/
|
|
24
|
+
export declare const POSTGRES_LIMITATIONS: AdapterLimitations;
|
|
25
|
+
/**
|
|
26
|
+
* Limitations for Supabase adapter (PostgreSQL with extensions).
|
|
27
|
+
*/
|
|
28
|
+
export declare const SUPABASE_LIMITATIONS: AdapterLimitations;
|
|
29
|
+
/**
|
|
30
|
+
* Map adapter kinds to their limitation definitions.
|
|
31
|
+
*/
|
|
32
|
+
export declare const ADAPTER_LIMITATIONS_MAP: {
|
|
33
|
+
readonly 'better-sqlite3': AdapterLimitations;
|
|
34
|
+
readonly sqljs: AdapterLimitations;
|
|
35
|
+
readonly capacitor: AdapterLimitations;
|
|
36
|
+
readonly postgres: AdapterLimitations;
|
|
37
|
+
readonly supabase: AdapterLimitations;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Get limitations for a specific adapter kind.
|
|
41
|
+
*
|
|
42
|
+
* @param kind - Adapter kind
|
|
43
|
+
* @returns Adapter limitations
|
|
44
|
+
*/
|
|
45
|
+
export declare function getLimitationsForAdapter(kind: keyof typeof ADAPTER_LIMITATIONS_MAP): AdapterLimitations;
|
|
46
|
+
//# sourceMappingURL=limitations.d.ts.map
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var limitations_exports = {};
|
|
19
|
+
__export(limitations_exports, {
|
|
20
|
+
ADAPTER_LIMITATIONS_MAP: () => ADAPTER_LIMITATIONS_MAP,
|
|
21
|
+
BETTER_SQLITE3_LIMITATIONS: () => BETTER_SQLITE3_LIMITATIONS,
|
|
22
|
+
CAPACITOR_SQLITE_LIMITATIONS: () => CAPACITOR_SQLITE_LIMITATIONS,
|
|
23
|
+
POSTGRES_LIMITATIONS: () => POSTGRES_LIMITATIONS,
|
|
24
|
+
SQLJS_LIMITATIONS: () => SQLJS_LIMITATIONS,
|
|
25
|
+
SUPABASE_LIMITATIONS: () => SUPABASE_LIMITATIONS,
|
|
26
|
+
getLimitationsForAdapter: () => getLimitationsForAdapter
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(limitations_exports);
|
|
29
|
+
function createPerformanceCharacteristics(concurrency, persistence, transactionIsolation, usesConnectionPool, asyncExecution) {
|
|
30
|
+
return {
|
|
31
|
+
concurrency,
|
|
32
|
+
persistence,
|
|
33
|
+
transactionIsolation,
|
|
34
|
+
usesConnectionPool,
|
|
35
|
+
asyncExecution
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const BETTER_SQLITE3_LIMITATIONS = {
|
|
39
|
+
maxConnections: 1,
|
|
40
|
+
// Single connection (SQLite limitation)
|
|
41
|
+
maxStatementLength: 1e6,
|
|
42
|
+
// 1MB
|
|
43
|
+
maxBatchSize: void 0,
|
|
44
|
+
// No hard limit, but memory constrained
|
|
45
|
+
maxParameterSize: void 0,
|
|
46
|
+
// Limited by available memory
|
|
47
|
+
supportedDataTypes: ["INTEGER", "REAL", "TEXT", "BLOB", "NULL"],
|
|
48
|
+
unsupportedFeatures: ["streaming", "concurrent", "json", "arrays"],
|
|
49
|
+
performanceCharacteristics: createPerformanceCharacteristics(
|
|
50
|
+
"single",
|
|
51
|
+
"file",
|
|
52
|
+
["SERIALIZABLE"],
|
|
53
|
+
// SQLite only supports serializable
|
|
54
|
+
false,
|
|
55
|
+
// No connection pooling
|
|
56
|
+
false
|
|
57
|
+
// Synchronous by default
|
|
58
|
+
),
|
|
59
|
+
constraints: {
|
|
60
|
+
supportsWAL: true,
|
|
61
|
+
supportsInMemory: true,
|
|
62
|
+
requiresFilePath: false
|
|
63
|
+
// Can use :memory:
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const SQLJS_LIMITATIONS = {
|
|
67
|
+
maxConnections: 1,
|
|
68
|
+
// Single connection
|
|
69
|
+
maxStatementLength: 1e6,
|
|
70
|
+
// 1MB
|
|
71
|
+
maxBatchSize: void 0,
|
|
72
|
+
maxParameterSize: void 0,
|
|
73
|
+
supportedDataTypes: ["INTEGER", "REAL", "TEXT", "BLOB", "NULL"],
|
|
74
|
+
unsupportedFeatures: ["streaming", "concurrent", "json", "arrays", "wal", "locks"],
|
|
75
|
+
performanceCharacteristics: createPerformanceCharacteristics(
|
|
76
|
+
"single",
|
|
77
|
+
"memory",
|
|
78
|
+
// Typically in-memory or manual file persistence
|
|
79
|
+
["SERIALIZABLE"],
|
|
80
|
+
false,
|
|
81
|
+
true
|
|
82
|
+
// Async wrapper over sync WASM
|
|
83
|
+
),
|
|
84
|
+
constraints: {
|
|
85
|
+
supportsWAL: false,
|
|
86
|
+
supportsInMemory: true,
|
|
87
|
+
requiresFilePath: false,
|
|
88
|
+
requiresWASM: true,
|
|
89
|
+
browserCompatible: true
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const CAPACITOR_SQLITE_LIMITATIONS = {
|
|
93
|
+
maxConnections: 1,
|
|
94
|
+
// Mobile SQLite single connection
|
|
95
|
+
maxStatementLength: 1e6,
|
|
96
|
+
maxBatchSize: void 0,
|
|
97
|
+
maxParameterSize: void 0,
|
|
98
|
+
supportedDataTypes: ["INTEGER", "REAL", "TEXT", "BLOB", "NULL"],
|
|
99
|
+
unsupportedFeatures: ["streaming", "concurrent", "json", "arrays"],
|
|
100
|
+
performanceCharacteristics: createPerformanceCharacteristics(
|
|
101
|
+
"single",
|
|
102
|
+
"file",
|
|
103
|
+
["SERIALIZABLE"],
|
|
104
|
+
false,
|
|
105
|
+
true
|
|
106
|
+
// Async through Capacitor bridge
|
|
107
|
+
),
|
|
108
|
+
constraints: {
|
|
109
|
+
supportsWAL: true,
|
|
110
|
+
supportsInMemory: false,
|
|
111
|
+
// Mobile requires file persistence
|
|
112
|
+
requiresFilePath: true,
|
|
113
|
+
requiresCapacitor: true,
|
|
114
|
+
mobileOnly: true
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const POSTGRES_LIMITATIONS = {
|
|
118
|
+
maxConnections: 100,
|
|
119
|
+
// Default pool size (configurable)
|
|
120
|
+
maxStatementLength: 1073741824,
|
|
121
|
+
// 1GB theoretical limit
|
|
122
|
+
maxBatchSize: 1e3,
|
|
123
|
+
// Recommended batch size
|
|
124
|
+
maxParameterSize: 1073741824,
|
|
125
|
+
// 1GB for BYTEA/TEXT
|
|
126
|
+
supportedDataTypes: [
|
|
127
|
+
"INTEGER",
|
|
128
|
+
"BIGINT",
|
|
129
|
+
"SMALLINT",
|
|
130
|
+
"SERIAL",
|
|
131
|
+
"BIGSERIAL",
|
|
132
|
+
"REAL",
|
|
133
|
+
"DOUBLE PRECISION",
|
|
134
|
+
"NUMERIC",
|
|
135
|
+
"DECIMAL",
|
|
136
|
+
"TEXT",
|
|
137
|
+
"VARCHAR",
|
|
138
|
+
"CHAR",
|
|
139
|
+
"BYTEA",
|
|
140
|
+
"BOOLEAN",
|
|
141
|
+
"DATE",
|
|
142
|
+
"TIME",
|
|
143
|
+
"TIMESTAMP",
|
|
144
|
+
"TIMESTAMPTZ",
|
|
145
|
+
"JSON",
|
|
146
|
+
"JSONB",
|
|
147
|
+
"UUID",
|
|
148
|
+
"ARRAY",
|
|
149
|
+
"HSTORE",
|
|
150
|
+
"XML"
|
|
151
|
+
],
|
|
152
|
+
unsupportedFeatures: ["wal"],
|
|
153
|
+
// WAL is PostgreSQL-specific, not exposed as capability
|
|
154
|
+
performanceCharacteristics: createPerformanceCharacteristics(
|
|
155
|
+
"pooled",
|
|
156
|
+
"network",
|
|
157
|
+
["READ UNCOMMITTED", "READ COMMITTED", "REPEATABLE READ", "SERIALIZABLE"],
|
|
158
|
+
true,
|
|
159
|
+
// Connection pooling
|
|
160
|
+
true
|
|
161
|
+
// Fully async
|
|
162
|
+
),
|
|
163
|
+
constraints: {
|
|
164
|
+
supportsWAL: false,
|
|
165
|
+
// Not relevant for client connections
|
|
166
|
+
supportsInMemory: false,
|
|
167
|
+
requiresFilePath: false,
|
|
168
|
+
requiresNetwork: true,
|
|
169
|
+
supportsReplication: true,
|
|
170
|
+
supportsPartitioning: true
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
const SUPABASE_LIMITATIONS = {
|
|
174
|
+
maxConnections: 15,
|
|
175
|
+
// Supabase free tier default
|
|
176
|
+
maxStatementLength: 1073741824,
|
|
177
|
+
maxBatchSize: 1e3,
|
|
178
|
+
maxParameterSize: 1073741824,
|
|
179
|
+
supportedDataTypes: [
|
|
180
|
+
...POSTGRES_LIMITATIONS.supportedDataTypes,
|
|
181
|
+
"VECTOR"
|
|
182
|
+
// pgvector extension
|
|
183
|
+
],
|
|
184
|
+
unsupportedFeatures: [],
|
|
185
|
+
performanceCharacteristics: createPerformanceCharacteristics("pooled", "network", ["READ COMMITTED", "REPEATABLE READ", "SERIALIZABLE"], true, true),
|
|
186
|
+
constraints: {
|
|
187
|
+
supportsWAL: false,
|
|
188
|
+
supportsInMemory: false,
|
|
189
|
+
requiresFilePath: false,
|
|
190
|
+
requiresNetwork: true,
|
|
191
|
+
supportsReplication: true,
|
|
192
|
+
supportsPartitioning: true,
|
|
193
|
+
supportsRowLevelSecurity: true,
|
|
194
|
+
supportsRealtimeSubscriptions: true,
|
|
195
|
+
// Supabase-specific
|
|
196
|
+
managedService: true
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
const ADAPTER_LIMITATIONS_MAP = {
|
|
200
|
+
"better-sqlite3": BETTER_SQLITE3_LIMITATIONS,
|
|
201
|
+
"sqljs": SQLJS_LIMITATIONS,
|
|
202
|
+
"capacitor": CAPACITOR_SQLITE_LIMITATIONS,
|
|
203
|
+
"postgres": POSTGRES_LIMITATIONS,
|
|
204
|
+
"supabase": SUPABASE_LIMITATIONS
|
|
205
|
+
};
|
|
206
|
+
function getLimitationsForAdapter(kind) {
|
|
207
|
+
return ADAPTER_LIMITATIONS_MAP[kind];
|
|
208
|
+
}
|
|
209
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
210
|
+
0 && (module.exports = {
|
|
211
|
+
ADAPTER_LIMITATIONS_MAP,
|
|
212
|
+
BETTER_SQLITE3_LIMITATIONS,
|
|
213
|
+
CAPACITOR_SQLITE_LIMITATIONS,
|
|
214
|
+
POSTGRES_LIMITATIONS,
|
|
215
|
+
SQLJS_LIMITATIONS,
|
|
216
|
+
SUPABASE_LIMITATIONS,
|
|
217
|
+
getLimitationsForAdapter
|
|
218
|
+
});
|