@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.
@@ -0,0 +1,186 @@
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
+ * Default settings for each performance tier.
35
+ *
36
+ * @internal
37
+ */
38
+ export const TIER_DEFAULTS = {
39
+ fast: {
40
+ cacheEnabled: true,
41
+ cacheTtlMs: 30000,
42
+ cacheMaxEntries: 500,
43
+ batchWrites: true,
44
+ batchFlushIntervalMs: 50,
45
+ batchMaxSize: 100,
46
+ validateSql: false,
47
+ trackMetrics: false,
48
+ slowQueryThresholdMs: 500,
49
+ retryOnError: false,
50
+ maxRetries: 1,
51
+ retryDelayMs: 100,
52
+ },
53
+ balanced: {
54
+ cacheEnabled: true,
55
+ cacheTtlMs: 5000,
56
+ cacheMaxEntries: 1000,
57
+ batchWrites: false,
58
+ batchFlushIntervalMs: 100,
59
+ batchMaxSize: 50,
60
+ validateSql: true,
61
+ trackMetrics: true,
62
+ slowQueryThresholdMs: 100,
63
+ retryOnError: true,
64
+ maxRetries: 3,
65
+ retryDelayMs: 100,
66
+ },
67
+ accurate: {
68
+ cacheEnabled: false,
69
+ cacheTtlMs: 0,
70
+ cacheMaxEntries: 0,
71
+ batchWrites: false,
72
+ batchFlushIntervalMs: 0,
73
+ batchMaxSize: 1,
74
+ validateSql: true,
75
+ trackMetrics: true,
76
+ slowQueryThresholdMs: 50,
77
+ retryOnError: true,
78
+ maxRetries: 5,
79
+ retryDelayMs: 200,
80
+ },
81
+ efficient: {
82
+ cacheEnabled: true,
83
+ cacheTtlMs: 60000,
84
+ cacheMaxEntries: 200,
85
+ batchWrites: true,
86
+ batchFlushIntervalMs: 500,
87
+ batchMaxSize: 20,
88
+ validateSql: false,
89
+ trackMetrics: false,
90
+ slowQueryThresholdMs: 200,
91
+ retryOnError: true,
92
+ maxRetries: 3,
93
+ retryDelayMs: 500,
94
+ },
95
+ };
96
+ // ============================================================================
97
+ // Utility Functions
98
+ // ============================================================================
99
+ /**
100
+ * Resolves performance configuration by merging tier defaults with user overrides.
101
+ *
102
+ * @param config - User-provided performance configuration
103
+ * @returns Fully resolved performance settings
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * const settings = resolvePerformanceConfig({ tier: 'fast', cacheTtlMs: 10000 });
108
+ * // Returns fast tier defaults with cacheTtlMs overridden to 10000
109
+ * ```
110
+ */
111
+ export function resolvePerformanceConfig(config = {}) {
112
+ const tier = config.tier ?? 'balanced';
113
+ if (tier === 'custom') {
114
+ // Custom tier requires all fields to be specified
115
+ return {
116
+ cacheEnabled: config.cacheEnabled ?? false,
117
+ cacheTtlMs: config.cacheTtlMs ?? 0,
118
+ cacheMaxEntries: config.cacheMaxEntries ?? 0,
119
+ batchWrites: config.batchWrites ?? false,
120
+ batchFlushIntervalMs: config.batchFlushIntervalMs ?? 0,
121
+ batchMaxSize: config.batchMaxSize ?? 1,
122
+ validateSql: config.validateSql ?? true,
123
+ trackMetrics: config.trackMetrics ?? false,
124
+ slowQueryThresholdMs: config.slowQueryThresholdMs ?? 100,
125
+ retryOnError: config.retryOnError ?? false,
126
+ maxRetries: config.maxRetries ?? 1,
127
+ retryDelayMs: config.retryDelayMs ?? 100,
128
+ };
129
+ }
130
+ const defaults = TIER_DEFAULTS[tier];
131
+ return {
132
+ cacheEnabled: config.cacheEnabled ?? defaults.cacheEnabled,
133
+ cacheTtlMs: config.cacheTtlMs ?? defaults.cacheTtlMs,
134
+ cacheMaxEntries: config.cacheMaxEntries ?? defaults.cacheMaxEntries,
135
+ batchWrites: config.batchWrites ?? defaults.batchWrites,
136
+ batchFlushIntervalMs: config.batchFlushIntervalMs ?? defaults.batchFlushIntervalMs,
137
+ batchMaxSize: config.batchMaxSize ?? defaults.batchMaxSize,
138
+ validateSql: config.validateSql ?? defaults.validateSql,
139
+ trackMetrics: config.trackMetrics ?? defaults.trackMetrics,
140
+ slowQueryThresholdMs: config.slowQueryThresholdMs ?? defaults.slowQueryThresholdMs,
141
+ retryOnError: config.retryOnError ?? defaults.retryOnError,
142
+ maxRetries: config.maxRetries ?? defaults.maxRetries,
143
+ retryDelayMs: config.retryDelayMs ?? defaults.retryDelayMs,
144
+ };
145
+ }
146
+ /**
147
+ * Checks if an error is transient and should be retried.
148
+ *
149
+ * @param error - The error to check
150
+ * @returns true if the error is transient
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * try {
155
+ * await db.run('INSERT INTO users (name) VALUES (?)', ['Alice']);
156
+ * } catch (error) {
157
+ * if (isTransientError(error)) {
158
+ * // Retry the operation
159
+ * }
160
+ * }
161
+ * ```
162
+ */
163
+ export function isTransientError(error) {
164
+ if (!(error instanceof Error)) {
165
+ return false;
166
+ }
167
+ const message = error.message.toLowerCase();
168
+ // Common transient error patterns
169
+ const transientPatterns = [
170
+ 'timeout',
171
+ 'connection reset',
172
+ 'connection refused',
173
+ 'econnreset',
174
+ 'econnrefused',
175
+ 'etimedout',
176
+ 'network',
177
+ 'deadlock',
178
+ 'lock wait timeout',
179
+ 'too many connections',
180
+ 'connection pool',
181
+ 'busy',
182
+ 'temporarily unavailable',
183
+ ];
184
+ return transientPatterns.some(pattern => message.includes(pattern));
185
+ }
186
+ //# sourceMappingURL=performance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"performance.js","sourceRoot":"","sources":["../../../src/core/contracts/performance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAmCH;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAA8E;IACtG,IAAI,EAAE;QACJ,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,KAAK;QACjB,eAAe,EAAE,GAAG;QACpB,WAAW,EAAE,IAAI;QACjB,oBAAoB,EAAE,EAAE;QACxB,YAAY,EAAE,GAAG;QACjB,WAAW,EAAE,KAAK;QAClB,YAAY,EAAE,KAAK;QACnB,oBAAoB,EAAE,GAAG;QACzB,YAAY,EAAE,KAAK;QACnB,UAAU,EAAE,CAAC;QACb,YAAY,EAAE,GAAG;KAClB;IACD,QAAQ,EAAE;QACR,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,IAAI;QAChB,eAAe,EAAE,IAAI;QACrB,WAAW,EAAE,KAAK;QAClB,oBAAoB,EAAE,GAAG;QACzB,YAAY,EAAE,EAAE;QAChB,WAAW,EAAE,IAAI;QACjB,YAAY,EAAE,IAAI;QAClB,oBAAoB,EAAE,GAAG;QACzB,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,CAAC;QACb,YAAY,EAAE,GAAG;KAClB;IACD,QAAQ,EAAE;QACR,YAAY,EAAE,KAAK;QACnB,UAAU,EAAE,CAAC;QACb,eAAe,EAAE,CAAC;QAClB,WAAW,EAAE,KAAK;QAClB,oBAAoB,EAAE,CAAC;QACvB,YAAY,EAAE,CAAC;QACf,WAAW,EAAE,IAAI;QACjB,YAAY,EAAE,IAAI;QAClB,oBAAoB,EAAE,EAAE;QACxB,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,UAAU;QACV,mBAAmB;QACnB,sBAAsB;QACtB,iBAAiB;QACjB,MAAM;QACN,yBAAyB;KAC1B,CAAC;IAEF,OAAO,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AACtE,CAAC"}
@@ -2,10 +2,28 @@
2
2
  * Aggregated type exports for scenarios where consumers import from
3
3
  * "@framers/sql-storage-adapter/types". Ensures Node's specifier
4
4
  * resolution finds an index module alongside the compiled artifacts.
5
+ *
6
+ * @packageDocumentation
7
+ * @module @framers/sql-storage-adapter/types
8
+ *
9
+ * @remarks
10
+ * This module re-exports all public types from the sql-storage-adapter package.
11
+ * Import from here when you only need types without runtime code.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import type {
16
+ * StorageAdapter,
17
+ * PerformanceConfig,
18
+ * StorageHooks
19
+ * } from '@framers/sql-storage-adapter/types';
20
+ * ```
5
21
  */
6
22
  export * from '../core/contracts';
7
23
  export * from '../core/contracts/context';
8
24
  export * from '../core/contracts/events';
9
25
  export * from '../core/contracts/extensions';
10
26
  export * from '../core/contracts/limitations';
27
+ export * from '../core/contracts/performance';
28
+ export * from '../core/contracts/hooks';
11
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC"}
@@ -2,10 +2,28 @@
2
2
  * Aggregated type exports for scenarios where consumers import from
3
3
  * "@framers/sql-storage-adapter/types". Ensures Node's specifier
4
4
  * resolution finds an index module alongside the compiled artifacts.
5
+ *
6
+ * @packageDocumentation
7
+ * @module @framers/sql-storage-adapter/types
8
+ *
9
+ * @remarks
10
+ * This module re-exports all public types from the sql-storage-adapter package.
11
+ * Import from here when you only need types without runtime code.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import type {
16
+ * StorageAdapter,
17
+ * PerformanceConfig,
18
+ * StorageHooks
19
+ * } from '@framers/sql-storage-adapter/types';
20
+ * ```
5
21
  */
6
22
  export * from '../core/contracts/index.js';
7
23
  export * from '../core/contracts/context.js';
8
24
  export * from '../core/contracts/events.js';
9
25
  export * from '../core/contracts/extensions.js';
10
26
  export * from '../core/contracts/limitations.js';
27
+ export * from '../core/contracts/performance.js';
28
+ export * from '../core/contracts/hooks.js';
11
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@framers/sql-storage-adapter",
3
- "version": "0.3.5",
3
+ "version": "0.4.2",
4
4
  "description": "Robust cross-platform SQL storage abstraction with automatic fallbacks and runtime detection",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -24,8 +24,8 @@
24
24
  ],
25
25
  "scripts": {
26
26
  "clean": "rimraf dist tsconfig.build.tsbuildinfo",
27
- "build": "pnpm run clean && pnpm exec tsc -p tsconfig.build.json && node scripts/fix-esm-imports.mjs",
28
- "prepublishOnly": "pnpm run build && pnpm run test",
27
+ "build": "npm run clean && npx tsc -p tsconfig.build.json && node scripts/fix-esm-imports.mjs",
28
+ "prepublishOnly": "npm run build && npm run test",
29
29
  "lint": "eslint \"src/**/*.{ts,tsx}\"",
30
30
  "lint:fix": "eslint \"src/**/*.{ts,tsx}\" --fix",
31
31
  "format": "prettier --write \"src/**/*.{ts,tsx,json,md}\"",
@@ -70,7 +70,7 @@
70
70
  "url": "https://github.com/framersai/sql-storage-adapter/issues",
71
71
  "email": "team@frame.dev"
72
72
  },
73
- "homepage": "https://framersai.github.io/sql-storage-adapter",
73
+ "homepage": "https://framersai.github.io/sql-storage-adapter/",
74
74
  "sideEffects": false,
75
75
  "devDependencies": {
76
76
  "@aws-sdk/client-s3": "^3.709.0",