@framers/sql-storage-adapter 0.7.2 → 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 +20 -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/package.json +139 -24
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for SQL storage adapters.
|
|
3
|
+
*
|
|
4
|
+
* Provides common functionality and enforces consistent behavior across all adapters.
|
|
5
|
+
* Follows the Template Method pattern - subclasses implement adapter-specific logic
|
|
6
|
+
* while the base class handles cross-cutting concerns.
|
|
7
|
+
*
|
|
8
|
+
* ## Responsibilities
|
|
9
|
+
* - Parameter validation and sanitization
|
|
10
|
+
* - Error handling and standardization
|
|
11
|
+
* - Lifecycle management (open/close state tracking)
|
|
12
|
+
* - Performance monitoring with configurable tiers
|
|
13
|
+
* - Query result caching (optional)
|
|
14
|
+
* - Lifecycle hooks for RAG integration
|
|
15
|
+
* - Logging and diagnostics
|
|
16
|
+
*
|
|
17
|
+
* @example Implementing a new adapter
|
|
18
|
+
* ```typescript
|
|
19
|
+
* export class MyAdapter extends BaseStorageAdapter {
|
|
20
|
+
* protected async doOpen(options?: StorageOpenOptions): Promise<void> {
|
|
21
|
+
* // Adapter-specific connection logic
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* protected async doRun(statement: string, parameters?: StorageParameters): Promise<StorageRunResult> {
|
|
25
|
+
* // Adapter-specific mutation logic
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* // ... implement other abstract methods
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example Using with performance tiers and hooks
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const adapter = new MyAdapter({
|
|
35
|
+
* performance: { tier: 'balanced', trackMetrics: true },
|
|
36
|
+
* hooks: {
|
|
37
|
+
* onBeforeWrite: async (ctx) => {
|
|
38
|
+
* // Generate embedding for RAG
|
|
39
|
+
* ctx.metadata = { embedding: await embed(ctx.parameters?.[0]) };
|
|
40
|
+
* return ctx;
|
|
41
|
+
* }
|
|
42
|
+
* }
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
import type { StorageAdapter, StorageCapability, StorageOpenOptions, StorageParameters, StorageRunResult, BatchOperation, BatchResult, PreparedStatement } from '../core/contracts/index.js';
|
|
47
|
+
import type { PerformanceConfig, PerformanceSettings, CacheStats } from '../core/contracts/performance.js';
|
|
48
|
+
import type { StorageHooks } from '../core/contracts/hooks.js';
|
|
49
|
+
/**
|
|
50
|
+
* Options for BaseStorageAdapter configuration.
|
|
51
|
+
*
|
|
52
|
+
* @example Basic options
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const adapter = new MyAdapter({ verbose: true });
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @example With performance tier
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const adapter = new MyAdapter({
|
|
60
|
+
* performance: { tier: 'fast' }
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @example With hooks for RAG
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const adapter = new MyAdapter({
|
|
67
|
+
* hooks: {
|
|
68
|
+
* onAfterWrite: async (ctx, result) => {
|
|
69
|
+
* await updateVectorIndex(result.lastInsertRowid, ctx.metadata?.embedding);
|
|
70
|
+
* }
|
|
71
|
+
* }
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export interface BaseAdapterOptions {
|
|
76
|
+
/** Enable detailed logging (default: false) */
|
|
77
|
+
verbose?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Enable performance tracking and metrics collection.
|
|
80
|
+
* @defaultValue true when tier is 'balanced' or 'accurate'
|
|
81
|
+
*/
|
|
82
|
+
trackPerformance?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Performance tier configuration.
|
|
85
|
+
* Controls caching, batching, validation, and retry behavior.
|
|
86
|
+
* @defaultValue { tier: 'balanced' }
|
|
87
|
+
*/
|
|
88
|
+
performance?: PerformanceConfig;
|
|
89
|
+
/**
|
|
90
|
+
* Lifecycle hooks for extending adapter behavior.
|
|
91
|
+
* Useful for RAG integration, logging, analytics, and auditing.
|
|
92
|
+
*/
|
|
93
|
+
hooks?: StorageHooks;
|
|
94
|
+
/**
|
|
95
|
+
* Validate SQL statements before execution.
|
|
96
|
+
* Convenience option that overrides performance.validateSql.
|
|
97
|
+
* @defaultValue true
|
|
98
|
+
*/
|
|
99
|
+
validateSQL?: boolean;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Performance metrics tracked by the base adapter.
|
|
103
|
+
*/
|
|
104
|
+
export interface AdapterMetrics {
|
|
105
|
+
/** Total number of queries executed */
|
|
106
|
+
totalQueries: number;
|
|
107
|
+
/** Total number of mutations (INSERT/UPDATE/DELETE) */
|
|
108
|
+
totalMutations: number;
|
|
109
|
+
/** Total number of transactions */
|
|
110
|
+
totalTransactions: number;
|
|
111
|
+
/** Total number of errors */
|
|
112
|
+
totalErrors: number;
|
|
113
|
+
/** Average query duration in milliseconds */
|
|
114
|
+
averageQueryDuration: number;
|
|
115
|
+
/** Time when adapter was opened */
|
|
116
|
+
openedAt: Date | null;
|
|
117
|
+
/** Cache statistics (if caching enabled) */
|
|
118
|
+
cache?: CacheStats;
|
|
119
|
+
/** Slow query count */
|
|
120
|
+
slowQueries: number;
|
|
121
|
+
/** Retry count */
|
|
122
|
+
retries: number;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Abstract base class for SQL storage adapters.
|
|
126
|
+
*
|
|
127
|
+
* Implements common functionality shared by all adapters:
|
|
128
|
+
* - State management (open/close tracking)
|
|
129
|
+
* - Parameter validation
|
|
130
|
+
* - Error handling and wrapping
|
|
131
|
+
* - Performance metrics with configurable tiers
|
|
132
|
+
* - Query result caching (tier-dependent)
|
|
133
|
+
* - Lifecycle hooks for RAG and analytics
|
|
134
|
+
* - Logging and diagnostics
|
|
135
|
+
*/
|
|
136
|
+
export declare abstract class BaseStorageAdapter implements StorageAdapter {
|
|
137
|
+
abstract readonly kind: string;
|
|
138
|
+
abstract readonly capabilities: ReadonlySet<StorageCapability>;
|
|
139
|
+
private state;
|
|
140
|
+
protected readonly options: BaseAdapterOptions;
|
|
141
|
+
protected readonly performanceSettings: PerformanceSettings;
|
|
142
|
+
protected readonly hooks: StorageHooks;
|
|
143
|
+
private metrics;
|
|
144
|
+
private queryCache;
|
|
145
|
+
private cacheStats;
|
|
146
|
+
private queryDurations;
|
|
147
|
+
private readonly MAX_DURATION_SAMPLES;
|
|
148
|
+
/**
|
|
149
|
+
* Creates a new adapter instance.
|
|
150
|
+
*
|
|
151
|
+
* @param options - Configuration options for the adapter
|
|
152
|
+
*
|
|
153
|
+
* @example Default balanced tier
|
|
154
|
+
* ```typescript
|
|
155
|
+
* const adapter = new MyAdapter();
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* @example Fast tier for development
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const adapter = new MyAdapter({
|
|
161
|
+
* performance: { tier: 'fast' },
|
|
162
|
+
* verbose: true
|
|
163
|
+
* });
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @example With RAG hooks
|
|
167
|
+
* ```typescript
|
|
168
|
+
* const adapter = new MyAdapter({
|
|
169
|
+
* hooks: {
|
|
170
|
+
* onBeforeWrite: async (ctx) => {
|
|
171
|
+
* ctx.metadata = { embedding: await embed(ctx.parameters) };
|
|
172
|
+
* return ctx;
|
|
173
|
+
* }
|
|
174
|
+
* }
|
|
175
|
+
* });
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
constructor(options?: BaseAdapterOptions);
|
|
179
|
+
/**
|
|
180
|
+
* Opens the adapter connection.
|
|
181
|
+
* Handles state management and delegates to subclass implementation.
|
|
182
|
+
*/
|
|
183
|
+
open(options?: StorageOpenOptions): Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* Executes a mutation statement (INSERT, UPDATE, DELETE).
|
|
186
|
+
*
|
|
187
|
+
* Invokes `onBeforeWrite` and `onAfterWrite` hooks if configured.
|
|
188
|
+
* Supports retry on transient errors based on performance tier.
|
|
189
|
+
*/
|
|
190
|
+
run(statement: string, parameters?: StorageParameters): Promise<StorageRunResult>;
|
|
191
|
+
/**
|
|
192
|
+
* Retrieves a single row.
|
|
193
|
+
*
|
|
194
|
+
* Supports caching based on performance tier and invokes query hooks.
|
|
195
|
+
*/
|
|
196
|
+
get<T = unknown>(statement: string, parameters?: StorageParameters): Promise<T | null>;
|
|
197
|
+
/**
|
|
198
|
+
* Retrieves all rows.
|
|
199
|
+
*
|
|
200
|
+
* Supports caching based on performance tier and invokes query hooks.
|
|
201
|
+
*/
|
|
202
|
+
all<T = unknown>(statement: string, parameters?: StorageParameters): Promise<T[]>;
|
|
203
|
+
/**
|
|
204
|
+
* Executes a SQL script.
|
|
205
|
+
*/
|
|
206
|
+
exec(script: string): Promise<void>;
|
|
207
|
+
/**
|
|
208
|
+
* Executes a transaction.
|
|
209
|
+
*
|
|
210
|
+
* Invokes transaction hooks and invalidates cache on completion.
|
|
211
|
+
*/
|
|
212
|
+
transaction<T>(fn: (trx: StorageAdapter) => Promise<T>): Promise<T>;
|
|
213
|
+
/**
|
|
214
|
+
* Closes the adapter connection.
|
|
215
|
+
*/
|
|
216
|
+
close(): Promise<void>;
|
|
217
|
+
/**
|
|
218
|
+
* Executes a batch of operations (optional).
|
|
219
|
+
*/
|
|
220
|
+
batch(operations: BatchOperation[]): Promise<BatchResult>;
|
|
221
|
+
/**
|
|
222
|
+
* Creates a prepared statement (optional).
|
|
223
|
+
*/
|
|
224
|
+
prepare<T = unknown>(statement: string): PreparedStatement<T>;
|
|
225
|
+
/**
|
|
226
|
+
* Adapter-specific open logic.
|
|
227
|
+
* Called by base class after state validation.
|
|
228
|
+
*/
|
|
229
|
+
protected abstract performOpen(options?: StorageOpenOptions): Promise<void>;
|
|
230
|
+
/**
|
|
231
|
+
* Adapter-specific mutation logic.
|
|
232
|
+
*/
|
|
233
|
+
protected abstract performRun(statement: string, parameters?: StorageParameters): Promise<StorageRunResult>;
|
|
234
|
+
/**
|
|
235
|
+
* Adapter-specific single-row query logic.
|
|
236
|
+
*/
|
|
237
|
+
protected abstract performGet<T>(statement: string, parameters?: StorageParameters): Promise<T | null>;
|
|
238
|
+
/**
|
|
239
|
+
* Adapter-specific multi-row query logic.
|
|
240
|
+
*/
|
|
241
|
+
protected abstract performAll<T>(statement: string, parameters?: StorageParameters): Promise<T[]>;
|
|
242
|
+
/**
|
|
243
|
+
* Adapter-specific script execution logic.
|
|
244
|
+
*/
|
|
245
|
+
protected abstract performExec(script: string): Promise<void>;
|
|
246
|
+
/**
|
|
247
|
+
* Adapter-specific transaction logic.
|
|
248
|
+
*/
|
|
249
|
+
protected abstract performTransaction<T>(fn: (trx: StorageAdapter) => Promise<T>): Promise<T>;
|
|
250
|
+
/**
|
|
251
|
+
* Adapter-specific close logic.
|
|
252
|
+
*/
|
|
253
|
+
protected abstract performClose(): Promise<void>;
|
|
254
|
+
/**
|
|
255
|
+
* Adapter-specific batch logic (optional).
|
|
256
|
+
* Only called if adapter declares 'batch' capability.
|
|
257
|
+
*/
|
|
258
|
+
protected performBatch?(operations: BatchOperation[]): Promise<BatchResult>;
|
|
259
|
+
/**
|
|
260
|
+
* Adapter-specific prepared statement logic (optional).
|
|
261
|
+
* Only called if adapter declares 'prepared' capability.
|
|
262
|
+
*/
|
|
263
|
+
protected performPrepare?<T>(statement: string): PreparedStatement<T>;
|
|
264
|
+
/**
|
|
265
|
+
* Asserts that adapter is in open state.
|
|
266
|
+
* @throws {Error} If adapter is not open
|
|
267
|
+
*/
|
|
268
|
+
protected assertOpen(): void;
|
|
269
|
+
/**
|
|
270
|
+
* Validates SQL statement.
|
|
271
|
+
* @throws {Error} If statement is invalid
|
|
272
|
+
*/
|
|
273
|
+
protected validateStatement(statement: string): void;
|
|
274
|
+
/**
|
|
275
|
+
* Generates a cache key for a query.
|
|
276
|
+
* Includes operation type to prevent get/all cache collisions.
|
|
277
|
+
*/
|
|
278
|
+
private getCacheKey;
|
|
279
|
+
/**
|
|
280
|
+
* Gets a value from cache if valid.
|
|
281
|
+
*/
|
|
282
|
+
private getFromCache;
|
|
283
|
+
/**
|
|
284
|
+
* Sets a value in cache.
|
|
285
|
+
*/
|
|
286
|
+
private setCache;
|
|
287
|
+
/**
|
|
288
|
+
* Invalidates cache entries for specific tables.
|
|
289
|
+
*/
|
|
290
|
+
private invalidateCache;
|
|
291
|
+
/**
|
|
292
|
+
* Clears entire cache.
|
|
293
|
+
*/
|
|
294
|
+
private clearCache;
|
|
295
|
+
/**
|
|
296
|
+
* Evicts least recently used cache entry.
|
|
297
|
+
*/
|
|
298
|
+
private evictLRU;
|
|
299
|
+
/**
|
|
300
|
+
* Updates cache hit ratio.
|
|
301
|
+
*/
|
|
302
|
+
private updateCacheHitRatio;
|
|
303
|
+
/**
|
|
304
|
+
* Executes an operation with retry logic.
|
|
305
|
+
*/
|
|
306
|
+
private executeWithRetry;
|
|
307
|
+
/**
|
|
308
|
+
* Sleep utility for retry delays.
|
|
309
|
+
*/
|
|
310
|
+
private sleep;
|
|
311
|
+
/**
|
|
312
|
+
* Extracts table names from a SQL statement.
|
|
313
|
+
*
|
|
314
|
+
* @remarks
|
|
315
|
+
* Simple regex-based extraction. For complex queries, consider
|
|
316
|
+
* using a proper SQL parser.
|
|
317
|
+
*/
|
|
318
|
+
private extractTables;
|
|
319
|
+
/**
|
|
320
|
+
* Checks if query duration exceeds slow query threshold.
|
|
321
|
+
*/
|
|
322
|
+
private checkSlowQuery;
|
|
323
|
+
/**
|
|
324
|
+
* Wraps an error with adapter context.
|
|
325
|
+
*/
|
|
326
|
+
protected wrapError(message: string, error: unknown): Error;
|
|
327
|
+
/**
|
|
328
|
+
* Logs a message if verbose mode is enabled.
|
|
329
|
+
*/
|
|
330
|
+
protected log(message: string): void;
|
|
331
|
+
/**
|
|
332
|
+
* Logs a warning message (always outputs regardless of verbose).
|
|
333
|
+
*/
|
|
334
|
+
protected logWarn(message: string): void;
|
|
335
|
+
/**
|
|
336
|
+
* Tracks query duration for performance metrics.
|
|
337
|
+
*/
|
|
338
|
+
private trackDuration;
|
|
339
|
+
/**
|
|
340
|
+
* Gets current adapter state.
|
|
341
|
+
*/
|
|
342
|
+
getState(): string;
|
|
343
|
+
/**
|
|
344
|
+
* Gets performance metrics.
|
|
345
|
+
*/
|
|
346
|
+
getMetrics(): Readonly<AdapterMetrics>;
|
|
347
|
+
/**
|
|
348
|
+
* Gets cache statistics.
|
|
349
|
+
*/
|
|
350
|
+
getCacheStats(): Readonly<CacheStats> | null;
|
|
351
|
+
/**
|
|
352
|
+
* Gets current performance settings.
|
|
353
|
+
*/
|
|
354
|
+
getPerformanceSettings(): Readonly<PerformanceSettings>;
|
|
355
|
+
/**
|
|
356
|
+
* Checks if adapter is open.
|
|
357
|
+
*/
|
|
358
|
+
isOpen(): boolean;
|
|
359
|
+
/**
|
|
360
|
+
* Checks if adapter is closed.
|
|
361
|
+
*/
|
|
362
|
+
isClosed(): boolean;
|
|
363
|
+
/**
|
|
364
|
+
* Gets uptime in milliseconds.
|
|
365
|
+
*/
|
|
366
|
+
getUptime(): number;
|
|
367
|
+
}
|
|
368
|
+
//# sourceMappingURL=baseStorageAdapter.d.ts.map
|