@framers/sql-storage-adapter 0.3.5 → 0.4.2
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 +94 -1
- package/dist/adapters/baseStorageAdapter.d.ts +172 -8
- package/dist/adapters/baseStorageAdapter.d.ts.map +1 -1
- package/dist/adapters/baseStorageAdapter.js +487 -21
- package/dist/adapters/baseStorageAdapter.js.map +1 -1
- package/dist/adapters/betterSqliteAdapter.d.ts.map +1 -1
- package/dist/adapters/betterSqliteAdapter.js +8 -0
- package/dist/adapters/betterSqliteAdapter.js.map +1 -1
- package/dist/core/contracts/hooks.d.ts +481 -0
- package/dist/core/contracts/hooks.d.ts.map +1 -0
- package/dist/core/contracts/hooks.js +215 -0
- package/dist/core/contracts/hooks.js.map +1 -0
- package/dist/core/contracts/index.d.ts +10 -0
- package/dist/core/contracts/index.d.ts.map +1 -1
- package/dist/core/contracts/index.js +13 -0
- package/dist/core/contracts/index.js.map +1 -1
- package/dist/core/contracts/performance.d.ts +308 -0
- package/dist/core/contracts/performance.d.ts.map +1 -0
- package/dist/core/contracts/performance.js +186 -0
- package/dist/core/contracts/performance.js.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +18 -0
- package/dist/types/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lifecycle Hooks for SQL Storage Adapter
|
|
3
|
+
*
|
|
4
|
+
* This module defines the hook system that enables extending adapter behavior
|
|
5
|
+
* without modifying core implementations. Hooks are particularly useful for:
|
|
6
|
+
*
|
|
7
|
+
* - **Analytics**: Query logging, performance monitoring
|
|
8
|
+
* - **Auditing**: Write logging, compliance tracking
|
|
9
|
+
* - **Caching**: Custom cache strategies, invalidation
|
|
10
|
+
* - **Transformation**: Query/result modification
|
|
11
|
+
* - **Extensions**: Build higher-level abstractions on top
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
* @module @framers/sql-storage-adapter/hooks
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Hooks are executed in a predictable order:
|
|
18
|
+
* 1. `onBeforeQuery`/`onBeforeWrite` - Before operation execution
|
|
19
|
+
* 2. Operation executes
|
|
20
|
+
* 3. `onAfterQuery`/`onAfterWrite` - After successful execution
|
|
21
|
+
* 4. `onError` - If an error occurred
|
|
22
|
+
*
|
|
23
|
+
* @example Audit logging hook
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { createDatabase, type StorageHooks } from '@framers/sql-storage-adapter';
|
|
26
|
+
*
|
|
27
|
+
* const auditHooks: StorageHooks = {
|
|
28
|
+
* onBeforeWrite: async (context) => {
|
|
29
|
+
* console.log(`[AUDIT] ${context.operation}: ${context.statement}`);
|
|
30
|
+
* return context;
|
|
31
|
+
* }
|
|
32
|
+
* };
|
|
33
|
+
*
|
|
34
|
+
* const db = await createDatabase({ hooks: auditHooks });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
// ============================================================================
|
|
38
|
+
// Hook Utilities
|
|
39
|
+
// ============================================================================
|
|
40
|
+
/**
|
|
41
|
+
* Combines multiple hook objects into a single hook object.
|
|
42
|
+
*
|
|
43
|
+
* When multiple hooks are combined, they execute in order.
|
|
44
|
+
* For transformation hooks (onBefore*, onAfter*), each hook
|
|
45
|
+
* receives the result of the previous hook.
|
|
46
|
+
*
|
|
47
|
+
* @param hooks - Hook objects to combine
|
|
48
|
+
* @returns Combined hook object
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const loggingHooks: StorageHooks = {
|
|
53
|
+
* onBeforeQuery: async (ctx) => {
|
|
54
|
+
* console.log('Query:', ctx.statement);
|
|
55
|
+
* return ctx;
|
|
56
|
+
* }
|
|
57
|
+
* };
|
|
58
|
+
*
|
|
59
|
+
* const metricsHooks: StorageHooks = {
|
|
60
|
+
* onAfterQuery: async (ctx, result) => {
|
|
61
|
+
* metrics.record('query', Date.now() - ctx.startTime);
|
|
62
|
+
* return result;
|
|
63
|
+
* }
|
|
64
|
+
* };
|
|
65
|
+
*
|
|
66
|
+
* const combinedHooks = combineHooks(loggingHooks, metricsHooks);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function combineHooks(...hooks) {
|
|
70
|
+
return {
|
|
71
|
+
onBeforeQuery: async (context) => {
|
|
72
|
+
let ctx = context;
|
|
73
|
+
for (const hook of hooks) {
|
|
74
|
+
if (hook.onBeforeQuery) {
|
|
75
|
+
const result = await hook.onBeforeQuery(ctx);
|
|
76
|
+
if (result === undefined) {
|
|
77
|
+
return undefined; // Early abort
|
|
78
|
+
}
|
|
79
|
+
ctx = result;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return ctx;
|
|
83
|
+
},
|
|
84
|
+
onAfterQuery: async (context, result) => {
|
|
85
|
+
let res = result;
|
|
86
|
+
for (const hook of hooks) {
|
|
87
|
+
if (hook.onAfterQuery) {
|
|
88
|
+
const transformed = await hook.onAfterQuery(context, res);
|
|
89
|
+
if (transformed !== undefined) {
|
|
90
|
+
res = transformed;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return res;
|
|
95
|
+
},
|
|
96
|
+
onBeforeWrite: async (context) => {
|
|
97
|
+
let ctx = context;
|
|
98
|
+
for (const hook of hooks) {
|
|
99
|
+
if (hook.onBeforeWrite) {
|
|
100
|
+
const result = await hook.onBeforeWrite(ctx);
|
|
101
|
+
if (result === undefined) {
|
|
102
|
+
return undefined; // Early abort
|
|
103
|
+
}
|
|
104
|
+
ctx = result;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return ctx;
|
|
108
|
+
},
|
|
109
|
+
onAfterWrite: async (context, result) => {
|
|
110
|
+
for (const hook of hooks) {
|
|
111
|
+
if (hook.onAfterWrite) {
|
|
112
|
+
await hook.onAfterWrite(context, result);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
onBeforeTransaction: async (context) => {
|
|
117
|
+
let ctx = context;
|
|
118
|
+
for (const hook of hooks) {
|
|
119
|
+
if (hook.onBeforeTransaction) {
|
|
120
|
+
const result = await hook.onBeforeTransaction(ctx);
|
|
121
|
+
if (result === undefined) {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
ctx = result;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return ctx;
|
|
128
|
+
},
|
|
129
|
+
onAfterTransaction: async (context) => {
|
|
130
|
+
for (const hook of hooks) {
|
|
131
|
+
if (hook.onAfterTransaction) {
|
|
132
|
+
await hook.onAfterTransaction(context);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
onError: async (error, context) => {
|
|
137
|
+
let err = error;
|
|
138
|
+
for (const hook of hooks) {
|
|
139
|
+
if (hook.onError && err) {
|
|
140
|
+
const result = await hook.onError(err, context);
|
|
141
|
+
if (result === undefined) {
|
|
142
|
+
return undefined; // Error suppressed
|
|
143
|
+
}
|
|
144
|
+
err = result;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return err;
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Creates a hook that only runs for specific operations.
|
|
153
|
+
*
|
|
154
|
+
* @param operations - Operations to filter for
|
|
155
|
+
* @param hooks - Hooks to apply
|
|
156
|
+
* @returns Filtered hooks
|
|
157
|
+
*
|
|
158
|
+
* @example Only log write operations
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const writeOnlyHooks = filterHooks(['run', 'batch'], {
|
|
161
|
+
* onBeforeWrite: async (ctx) => {
|
|
162
|
+
* console.log('Write:', ctx.statement);
|
|
163
|
+
* return ctx;
|
|
164
|
+
* }
|
|
165
|
+
* });
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export function filterHooks(operations, hooks) {
|
|
169
|
+
const operationSet = new Set(operations);
|
|
170
|
+
return {
|
|
171
|
+
onBeforeQuery: hooks.onBeforeQuery
|
|
172
|
+
? async (ctx) => operationSet.has(ctx.operation) ? hooks.onBeforeQuery(ctx) : ctx
|
|
173
|
+
: undefined,
|
|
174
|
+
onAfterQuery: hooks.onAfterQuery
|
|
175
|
+
? async (ctx, result) => operationSet.has(ctx.operation) ? hooks.onAfterQuery(ctx, result) : result
|
|
176
|
+
: undefined,
|
|
177
|
+
onBeforeWrite: hooks.onBeforeWrite
|
|
178
|
+
? async (ctx) => operationSet.has(ctx.operation) ? hooks.onBeforeWrite(ctx) : ctx
|
|
179
|
+
: undefined,
|
|
180
|
+
onAfterWrite: hooks.onAfterWrite
|
|
181
|
+
? async (ctx, result) => { if (operationSet.has(ctx.operation))
|
|
182
|
+
await hooks.onAfterWrite(ctx, result); }
|
|
183
|
+
: undefined,
|
|
184
|
+
onBeforeTransaction: hooks.onBeforeTransaction
|
|
185
|
+
? async (ctx) => operationSet.has(ctx.operation) ? hooks.onBeforeTransaction(ctx) : ctx
|
|
186
|
+
: undefined,
|
|
187
|
+
onAfterTransaction: hooks.onAfterTransaction
|
|
188
|
+
? async (ctx) => { if (operationSet.has(ctx.operation))
|
|
189
|
+
await hooks.onAfterTransaction(ctx); }
|
|
190
|
+
: undefined,
|
|
191
|
+
onError: hooks.onError
|
|
192
|
+
? async (err, ctx) => operationSet.has(ctx.operation) ? hooks.onError(err, ctx) : err
|
|
193
|
+
: undefined,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Generates a unique operation ID.
|
|
198
|
+
*
|
|
199
|
+
* @returns UUID v4 string
|
|
200
|
+
*
|
|
201
|
+
* @internal
|
|
202
|
+
*/
|
|
203
|
+
export function generateOperationId() {
|
|
204
|
+
// Use crypto.randomUUID if available, otherwise fallback
|
|
205
|
+
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
|
206
|
+
return crypto.randomUUID();
|
|
207
|
+
}
|
|
208
|
+
// Fallback UUID v4 generation
|
|
209
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
210
|
+
const r = (Math.random() * 16) | 0;
|
|
211
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
212
|
+
return v.toString(16);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/core/contracts/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AA8aH,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,YAAY,CAAC,GAAG,KAAqB;IACnD,OAAO;QACL,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YAC/B,IAAI,GAAG,GAAG,OAAO,CAAC;YAClB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;oBACvB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;oBAC7C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;wBACzB,OAAO,SAAS,CAAC,CAAC,cAAc;oBAClC,CAAC;oBACD,GAAG,GAAG,MAAM,CAAC;gBACf,CAAC;YACH,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;QAED,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;YACtC,IAAI,GAAG,GAAG,MAAM,CAAC;YACjB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;oBACtB,MAAM,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AAC,CAAC,SAAS;QAEb,OAAO,EAAE,KAAK,CAAC,OAAO;YACpB,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG;YACtF,CAAC,CAAC,SAAS;KACd,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB;IACjC,yDAAyD;IACzD,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACvD,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;IAC7B,CAAC;IAED,8BAA8B;IAC9B,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;QACnE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QACnC,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;QAC1C,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -232,4 +232,14 @@ export declare class StorageResolutionError extends Error {
|
|
|
232
232
|
readonly causes: unknown[];
|
|
233
233
|
constructor(message: string, causes?: unknown[]);
|
|
234
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Performance configuration types for cost/accuracy optimization.
|
|
237
|
+
* See `OPTIMIZATION_GUIDE.md` for detailed usage documentation.
|
|
238
|
+
*/
|
|
239
|
+
export * from './performance';
|
|
240
|
+
/**
|
|
241
|
+
* Lifecycle hooks for extending adapter behavior.
|
|
242
|
+
* Designed for RAG integration, analytics, and auditing.
|
|
243
|
+
*/
|
|
244
|
+
export * from './hooks';
|
|
235
245
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/contracts/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,cAAc,GACd,KAAK,GACL,OAAO,GACP,aAAa,GACb,WAAW,GACX,OAAO,GACP,UAAU,GACV,YAAY,GACZ,MAAM,GACN,QAAQ,CAAA;AAEZ;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,IAAI,GACJ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,UAAU,GAAG,OAAO,CAAC,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,iBAAiB,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,iDAAiD;IACjD,UAAU,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC7B,4CAA4C;IAC5C,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC;CACjD;AAED;;GAEG;AACH,MAAM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AW,iBAAiB,CAAC,CAAC,GAAG,OAAO;IAC5C,GAAG,CAAC,UAAU,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC/D,GAAG,CAAC,UAAU,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACvD,GAAG,CAAC,UAAU,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IAClD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,CAAC;AAElE;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IAClB,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE;gBAA3C,OAAO,EAAE,MAAM,EAAW,MAAM,GAAE,OAAO,EAAO;CAI7D;AAMD;;;GAGG;AACH,cAAc,eAAe,CAAC;AAE9B;;;GAGG;AACH,cAAc,SAAS,CAAC"}
|
|
@@ -15,4 +15,17 @@ export class StorageResolutionError extends Error {
|
|
|
15
15
|
this.name = 'StorageResolutionError';
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
+
// ============================================================================
|
|
19
|
+
// Re-export Performance and Hooks Types
|
|
20
|
+
// ============================================================================
|
|
21
|
+
/**
|
|
22
|
+
* Performance configuration types for cost/accuracy optimization.
|
|
23
|
+
* See `OPTIMIZATION_GUIDE.md` for detailed usage documentation.
|
|
24
|
+
*/
|
|
25
|
+
export * from './performance.js';
|
|
26
|
+
/**
|
|
27
|
+
* Lifecycle hooks for extending adapter behavior.
|
|
28
|
+
* Designed for RAG integration, analytics, and auditing.
|
|
29
|
+
*/
|
|
30
|
+
export * from './hooks.js';
|
|
18
31
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/contracts/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA6PH;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,OAAe,EAAW,SAAoB,EAAE;QAC1D,KAAK,CAAC,OAAO,CAAC,CAAC;QADqB,WAAM,GAAN,MAAM,CAAgB;QAE1D,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/contracts/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA6PH;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,OAAe,EAAW,SAAoB,EAAE;QAC1D,KAAK,CAAC,OAAO,CAAC,CAAC;QADqB,WAAM,GAAN,MAAM,CAAgB;QAE1D,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED,+EAA+E;AAC/E,wCAAwC;AACxC,+EAA+E;AAE/E;;;GAGG;AACH,cAAc,eAAe,CAAC;AAE9B;;;GAGG;AACH,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performance Configuration Types for SQL Storage Adapter
|
|
3
|
+
*
|
|
4
|
+
* This module defines the performance tier system, caching configuration,
|
|
5
|
+
* and optimization options that enable cost/accuracy tradeoffs across
|
|
6
|
+
* all adapter implementations.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
* @module @framers/sql-storage-adapter/performance
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* The performance system is designed to be:
|
|
13
|
+
* - **Platform-agnostic**: Same API across browser, mobile, desktop, cloud
|
|
14
|
+
* - **Extensible**: Hooks and metadata support for custom extensions
|
|
15
|
+
* - **Configurable**: Sensible defaults with full override capability
|
|
16
|
+
* - **Observable**: Built-in metrics and slow query logging
|
|
17
|
+
*
|
|
18
|
+
* @example Basic usage with tier presets
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { createDatabase } from '@framers/sql-storage-adapter';
|
|
21
|
+
*
|
|
22
|
+
* // Development: prioritize speed
|
|
23
|
+
* const devDb = await createDatabase({
|
|
24
|
+
* performance: { tier: 'fast' }
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Production analytics: prioritize accuracy
|
|
28
|
+
* const analyticsDb = await createDatabase({
|
|
29
|
+
* performance: { tier: 'accurate', trackMetrics: true }
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Performance tier presets for common use cases.
|
|
35
|
+
*
|
|
36
|
+
* Each tier provides sensible defaults that can be individually overridden.
|
|
37
|
+
* The tier affects caching, batching, validation, and query optimization.
|
|
38
|
+
*
|
|
39
|
+
* | Tier | Use Case | Caching | Batching | Validation |
|
|
40
|
+
* |------|----------|---------|----------|------------|
|
|
41
|
+
* | `fast` | Development, testing | Aggressive | Yes | Minimal |
|
|
42
|
+
* | `balanced` | General production | Moderate | No | Standard |
|
|
43
|
+
* | `accurate` | Analytics, reporting | Disabled | No | Full |
|
|
44
|
+
* | `efficient` | Mobile, battery-constrained | Moderate | Yes | Minimal |
|
|
45
|
+
* | `custom` | Full manual control | Manual | Manual | Manual |
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Mobile app with battery optimization
|
|
50
|
+
* const db = await createDatabase({
|
|
51
|
+
* performance: { tier: 'efficient' }
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export type PerformanceTier = 'fast' | 'balanced' | 'accurate' | 'efficient' | 'custom';
|
|
56
|
+
/**
|
|
57
|
+
* Default settings for each performance tier.
|
|
58
|
+
*
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
export declare const TIER_DEFAULTS: Record<Exclude<PerformanceTier, 'custom'>, Readonly<PerformanceSettings>>;
|
|
62
|
+
/**
|
|
63
|
+
* Individual performance settings (all fields required).
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
* Used internally after merging tier defaults with user overrides.
|
|
67
|
+
*/
|
|
68
|
+
export interface PerformanceSettings {
|
|
69
|
+
/** Enable query result caching */
|
|
70
|
+
readonly cacheEnabled: boolean;
|
|
71
|
+
/** Cache TTL in milliseconds */
|
|
72
|
+
readonly cacheTtlMs: number;
|
|
73
|
+
/** Maximum cache entries */
|
|
74
|
+
readonly cacheMaxEntries: number;
|
|
75
|
+
/** Enable write batching */
|
|
76
|
+
readonly batchWrites: boolean;
|
|
77
|
+
/** Batch flush interval in ms */
|
|
78
|
+
readonly batchFlushIntervalMs: number;
|
|
79
|
+
/** Maximum batch size before auto-flush */
|
|
80
|
+
readonly batchMaxSize: number;
|
|
81
|
+
/** Validate SQL before execution */
|
|
82
|
+
readonly validateSql: boolean;
|
|
83
|
+
/** Track performance metrics */
|
|
84
|
+
readonly trackMetrics: boolean;
|
|
85
|
+
/** Log slow queries above this threshold in ms */
|
|
86
|
+
readonly slowQueryThresholdMs: number;
|
|
87
|
+
/** Retry transient errors */
|
|
88
|
+
readonly retryOnError: boolean;
|
|
89
|
+
/** Maximum retry attempts */
|
|
90
|
+
readonly maxRetries: number;
|
|
91
|
+
/** Retry delay in ms */
|
|
92
|
+
readonly retryDelayMs: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Performance configuration options provided by users.
|
|
96
|
+
*
|
|
97
|
+
* All fields are optional; unspecified fields use tier defaults.
|
|
98
|
+
*
|
|
99
|
+
* @example Override specific settings while using a tier
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const db = await createDatabase({
|
|
102
|
+
* performance: {
|
|
103
|
+
* tier: 'balanced',
|
|
104
|
+
* cacheTtlMs: 30000, // Override: longer cache
|
|
105
|
+
* trackMetrics: true, // Override: enable metrics
|
|
106
|
+
* }
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export interface PerformanceConfig {
|
|
111
|
+
/**
|
|
112
|
+
* Performance tier preset.
|
|
113
|
+
*
|
|
114
|
+
* @defaultValue 'balanced'
|
|
115
|
+
*/
|
|
116
|
+
tier?: PerformanceTier;
|
|
117
|
+
/**
|
|
118
|
+
* Enable query result caching.
|
|
119
|
+
*
|
|
120
|
+
* When enabled, identical SELECT queries return cached results
|
|
121
|
+
* until the cache TTL expires or cache is invalidated.
|
|
122
|
+
*
|
|
123
|
+
* @remarks
|
|
124
|
+
* - Caching is per-adapter instance (not shared)
|
|
125
|
+
* - Cache is invalidated on any write operation to affected tables
|
|
126
|
+
* - Use `accurate` tier for systems where stale data is unacceptable
|
|
127
|
+
*
|
|
128
|
+
* @defaultValue tier-dependent
|
|
129
|
+
*/
|
|
130
|
+
cacheEnabled?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Cache time-to-live in milliseconds.
|
|
133
|
+
*
|
|
134
|
+
* After this duration, cached query results are considered stale
|
|
135
|
+
* and will be re-fetched on next access.
|
|
136
|
+
*
|
|
137
|
+
* @defaultValue 5000 for balanced tier
|
|
138
|
+
*/
|
|
139
|
+
cacheTtlMs?: number;
|
|
140
|
+
/**
|
|
141
|
+
* Maximum number of cached query results.
|
|
142
|
+
*
|
|
143
|
+
* When exceeded, least-recently-used entries are evicted.
|
|
144
|
+
*
|
|
145
|
+
* @defaultValue 1000 for balanced tier
|
|
146
|
+
*/
|
|
147
|
+
cacheMaxEntries?: number;
|
|
148
|
+
/**
|
|
149
|
+
* Enable write batching.
|
|
150
|
+
*
|
|
151
|
+
* When enabled, write operations (INSERT, UPDATE, DELETE) are
|
|
152
|
+
* collected and executed in batches to reduce I/O operations.
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* - Recommended for mobile/browser environments
|
|
156
|
+
* - Not recommended for systems requiring immediate consistency
|
|
157
|
+
* - Batch is flushed on `batchFlushIntervalMs` or `batchMaxSize`
|
|
158
|
+
*
|
|
159
|
+
* @defaultValue false for balanced tier, true for efficient tier
|
|
160
|
+
*/
|
|
161
|
+
batchWrites?: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Batch flush interval in milliseconds.
|
|
164
|
+
*
|
|
165
|
+
* Accumulated writes are flushed after this interval.
|
|
166
|
+
*
|
|
167
|
+
* @defaultValue 100 for balanced tier
|
|
168
|
+
*/
|
|
169
|
+
batchFlushIntervalMs?: number;
|
|
170
|
+
/**
|
|
171
|
+
* Maximum batch size before auto-flush.
|
|
172
|
+
*
|
|
173
|
+
* When batch reaches this size, it is immediately flushed
|
|
174
|
+
* regardless of the flush interval.
|
|
175
|
+
*
|
|
176
|
+
* @defaultValue 50 for balanced tier
|
|
177
|
+
*/
|
|
178
|
+
batchMaxSize?: number;
|
|
179
|
+
/**
|
|
180
|
+
* Validate SQL statements before execution.
|
|
181
|
+
*
|
|
182
|
+
* Performs basic syntax and injection checks.
|
|
183
|
+
*
|
|
184
|
+
* @defaultValue true for balanced tier
|
|
185
|
+
*/
|
|
186
|
+
validateSql?: boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Track performance metrics.
|
|
189
|
+
*
|
|
190
|
+
* When enabled, the adapter tracks:
|
|
191
|
+
* - Total queries/mutations/transactions
|
|
192
|
+
* - Average query duration
|
|
193
|
+
* - Error counts
|
|
194
|
+
* - Uptime
|
|
195
|
+
*
|
|
196
|
+
* Retrieve metrics via `adapter.getMetrics()`.
|
|
197
|
+
*
|
|
198
|
+
* @defaultValue true for balanced tier
|
|
199
|
+
*/
|
|
200
|
+
trackMetrics?: boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Slow query logging threshold in milliseconds.
|
|
203
|
+
*
|
|
204
|
+
* Queries exceeding this duration are logged at warn level.
|
|
205
|
+
*
|
|
206
|
+
* @defaultValue 100 for balanced tier
|
|
207
|
+
*/
|
|
208
|
+
slowQueryThresholdMs?: number;
|
|
209
|
+
/**
|
|
210
|
+
* Retry operations on transient errors.
|
|
211
|
+
*
|
|
212
|
+
* Transient errors include network timeouts, connection resets,
|
|
213
|
+
* and deadlocks.
|
|
214
|
+
*
|
|
215
|
+
* @defaultValue true for balanced tier
|
|
216
|
+
*/
|
|
217
|
+
retryOnError?: boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Maximum retry attempts.
|
|
220
|
+
*
|
|
221
|
+
* @defaultValue 3 for balanced tier
|
|
222
|
+
*/
|
|
223
|
+
maxRetries?: number;
|
|
224
|
+
/**
|
|
225
|
+
* Delay between retry attempts in milliseconds.
|
|
226
|
+
*
|
|
227
|
+
* Uses exponential backoff: delay * 2^attempt.
|
|
228
|
+
*
|
|
229
|
+
* @defaultValue 100 for balanced tier
|
|
230
|
+
*/
|
|
231
|
+
retryDelayMs?: number;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Cache entry for query results.
|
|
235
|
+
*
|
|
236
|
+
* @internal
|
|
237
|
+
*/
|
|
238
|
+
export interface CacheEntry<T = unknown> {
|
|
239
|
+
/** Cached result data */
|
|
240
|
+
readonly data: T;
|
|
241
|
+
/** Timestamp when entry was created (ms since epoch) */
|
|
242
|
+
readonly createdAt: number;
|
|
243
|
+
/** Timestamp when entry expires (ms since epoch) */
|
|
244
|
+
readonly expiresAt: number;
|
|
245
|
+
/** Tables affected by this query (for invalidation) */
|
|
246
|
+
readonly affectedTables: ReadonlyArray<string>;
|
|
247
|
+
/** Cache hit count for LRU tracking */
|
|
248
|
+
hits: number;
|
|
249
|
+
/** Last access timestamp for LRU tracking */
|
|
250
|
+
lastAccessedAt: number;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Cache statistics for monitoring (public API is readonly).
|
|
254
|
+
*/
|
|
255
|
+
export interface CacheStats {
|
|
256
|
+
/** Total cache hits */
|
|
257
|
+
readonly hits: number;
|
|
258
|
+
/** Total cache misses */
|
|
259
|
+
readonly misses: number;
|
|
260
|
+
/** Hit ratio (hits / (hits + misses)) */
|
|
261
|
+
readonly hitRatio: number;
|
|
262
|
+
/** Current number of entries */
|
|
263
|
+
readonly size: number;
|
|
264
|
+
/** Total bytes used (approximate) */
|
|
265
|
+
readonly bytesUsed: number;
|
|
266
|
+
/** Number of evictions */
|
|
267
|
+
readonly evictions: number;
|
|
268
|
+
/** Number of invalidations */
|
|
269
|
+
readonly invalidations: number;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Mutable version of CacheStats for internal use.
|
|
273
|
+
*/
|
|
274
|
+
export type MutableCacheStats = {
|
|
275
|
+
-readonly [K in keyof CacheStats]: CacheStats[K];
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Resolves performance configuration by merging tier defaults with user overrides.
|
|
279
|
+
*
|
|
280
|
+
* @param config - User-provided performance configuration
|
|
281
|
+
* @returns Fully resolved performance settings
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```typescript
|
|
285
|
+
* const settings = resolvePerformanceConfig({ tier: 'fast', cacheTtlMs: 10000 });
|
|
286
|
+
* // Returns fast tier defaults with cacheTtlMs overridden to 10000
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
export declare function resolvePerformanceConfig(config?: PerformanceConfig): PerformanceSettings;
|
|
290
|
+
/**
|
|
291
|
+
* Checks if an error is transient and should be retried.
|
|
292
|
+
*
|
|
293
|
+
* @param error - The error to check
|
|
294
|
+
* @returns true if the error is transient
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```typescript
|
|
298
|
+
* try {
|
|
299
|
+
* await db.run('INSERT INTO users (name) VALUES (?)', ['Alice']);
|
|
300
|
+
* } catch (error) {
|
|
301
|
+
* if (isTransientError(error)) {
|
|
302
|
+
* // Retry the operation
|
|
303
|
+
* }
|
|
304
|
+
* }
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
export declare function isTransientError(error: unknown): boolean;
|
|
308
|
+
//# sourceMappingURL=performance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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