@superfunctions/db 0.1.0
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 +341 -0
- package/dist/adapter/capabilities.d.ts +51 -0
- package/dist/adapter/capabilities.d.ts.map +1 -0
- package/dist/adapter/capabilities.js +56 -0
- package/dist/adapter/capabilities.js.map +1 -0
- package/dist/adapter/errors.d.ts +111 -0
- package/dist/adapter/errors.d.ts.map +1 -0
- package/dist/adapter/errors.js +172 -0
- package/dist/adapter/errors.js.map +1 -0
- package/dist/adapter/factory.d.ts +10 -0
- package/dist/adapter/factory.d.ts.map +1 -0
- package/dist/adapter/factory.js +232 -0
- package/dist/adapter/factory.js.map +1 -0
- package/dist/adapter/types.d.ts +255 -0
- package/dist/adapter/types.d.ts.map +1 -0
- package/dist/adapter/types.js +5 -0
- package/dist/adapter/types.js.map +1 -0
- package/dist/adapters/drizzle/index.d.ts +20 -0
- package/dist/adapters/drizzle/index.d.ts.map +1 -0
- package/dist/adapters/drizzle/index.js +346 -0
- package/dist/adapters/drizzle/index.js.map +1 -0
- package/dist/adapters/index.d.ts +12 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +12 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/kysely/index.d.ts +18 -0
- package/dist/adapters/kysely/index.d.ts.map +1 -0
- package/dist/adapters/kysely/index.js +305 -0
- package/dist/adapters/kysely/index.js.map +1 -0
- package/dist/adapters/memory/index.d.ts +17 -0
- package/dist/adapters/memory/index.d.ts.map +1 -0
- package/dist/adapters/memory/index.js +362 -0
- package/dist/adapters/memory/index.js.map +1 -0
- package/dist/adapters/prisma/index.d.ts +16 -0
- package/dist/adapters/prisma/index.d.ts.map +1 -0
- package/dist/adapters/prisma/index.js +247 -0
- package/dist/adapters/prisma/index.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations/runtime-validation.d.ts +7 -0
- package/dist/migrations/runtime-validation.d.ts.map +1 -0
- package/dist/migrations/runtime-validation.js +40 -0
- package/dist/migrations/runtime-validation.js.map +1 -0
- package/dist/migrations/schema-tracker.d.ts +56 -0
- package/dist/migrations/schema-tracker.d.ts.map +1 -0
- package/dist/migrations/schema-tracker.js +121 -0
- package/dist/migrations/schema-tracker.js.map +1 -0
- package/dist/testing/contract-tests.d.ts +64 -0
- package/dist/testing/contract-tests.d.ts.map +1 -0
- package/dist/testing/contract-tests.js +391 -0
- package/dist/testing/contract-tests.js.map +1 -0
- package/dist/testing/index.d.ts +10 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +10 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mocks.d.ts +92 -0
- package/dist/testing/mocks.d.ts.map +1 -0
- package/dist/testing/mocks.js +197 -0
- package/dist/testing/mocks.js.map +1 -0
- package/dist/utils/namespace.d.ts +49 -0
- package/dist/utils/namespace.d.ts.map +1 -0
- package/dist/utils/namespace.js +85 -0
- package/dist/utils/namespace.js.map +1 -0
- package/package.json +87 -0
package/README.md
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
# @superfunctions/db
|
|
2
|
+
|
|
3
|
+
Shared database adapter system for Superfunctions libraries. Provides a unified interface for interacting with databases across multiple ORMs (Drizzle, Prisma, Kysely, MongoDB).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **๐ Multiple ORM Support**: Works with Drizzle, Prisma, Kysely, MongoDB
|
|
8
|
+
- **๐ฏ Type Safe**: Full TypeScript support with strict types
|
|
9
|
+
- **๐ Unified Interface**: Single adapter interface across all ORMs
|
|
10
|
+
- **๐ฆ Namespace Isolation**: Prevent table name conflicts between libraries
|
|
11
|
+
- **โก Progressive Enhancement**: Adapters declare capabilities, libraries adapt accordingly
|
|
12
|
+
- **๐งช Testing Utilities**: Built-in memory adapter and testing tools
|
|
13
|
+
- **๐ง Schema Management**: Version tracking and migration support
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @superfunctions/db
|
|
19
|
+
|
|
20
|
+
# Plus your ORM of choice (optional peer dependencies)
|
|
21
|
+
npm install drizzle-orm # For Drizzle
|
|
22
|
+
npm install @prisma/client # For Prisma
|
|
23
|
+
npm install kysely # For Kysely
|
|
24
|
+
npm install mongodb # For MongoDB
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### Using with a Library
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { SendFn } from '@superfunctions/sendFn';
|
|
33
|
+
import { memoryAdapter } from '@superfunctions/db/adapters';
|
|
34
|
+
|
|
35
|
+
// Create adapter
|
|
36
|
+
const adapter = memoryAdapter({
|
|
37
|
+
namespace: { enabled: true }
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Initialize library with adapter
|
|
41
|
+
const sendFn = SendFn({
|
|
42
|
+
database: adapter,
|
|
43
|
+
namespace: 'sendFn'
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Use the library
|
|
47
|
+
await sendFn.sendEmail({
|
|
48
|
+
to: 'user@example.com',
|
|
49
|
+
subject: 'Hello',
|
|
50
|
+
body: 'World'
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Creating a Custom Adapter
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { createAdapterFactory } from '@superfunctions/db';
|
|
58
|
+
import type { AdapterFactoryOptions } from '@superfunctions/db';
|
|
59
|
+
|
|
60
|
+
export function myCustomAdapter(db: any, config: any) {
|
|
61
|
+
return createAdapterFactory({
|
|
62
|
+
config: {
|
|
63
|
+
adapterId: 'my-custom',
|
|
64
|
+
adapterName: 'My Custom Adapter',
|
|
65
|
+
capabilities: {
|
|
66
|
+
types: {
|
|
67
|
+
json: true,
|
|
68
|
+
dates: true,
|
|
69
|
+
booleans: true,
|
|
70
|
+
// ...
|
|
71
|
+
},
|
|
72
|
+
// ...
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
adapter: (context) => ({
|
|
76
|
+
async create(params) {
|
|
77
|
+
// Implementation
|
|
78
|
+
},
|
|
79
|
+
// ... other methods
|
|
80
|
+
}),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Core Concepts
|
|
86
|
+
|
|
87
|
+
### Adapter Interface
|
|
88
|
+
|
|
89
|
+
All adapters implement a unified interface:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
interface Adapter {
|
|
93
|
+
// CRUD operations
|
|
94
|
+
create(params: CreateParams): Promise<T>;
|
|
95
|
+
findOne(params: FindOneParams): Promise<T | null>;
|
|
96
|
+
findMany(params: FindManyParams): Promise<T[]>;
|
|
97
|
+
update(params: UpdateParams): Promise<T>;
|
|
98
|
+
delete(params: DeleteParams): Promise<void>;
|
|
99
|
+
|
|
100
|
+
// Batch operations
|
|
101
|
+
createMany(params: CreateManyParams): Promise<T[]>;
|
|
102
|
+
updateMany(params: UpdateManyParams): Promise<number>;
|
|
103
|
+
deleteMany(params: DeleteManyParams): Promise<number>;
|
|
104
|
+
|
|
105
|
+
// Advanced
|
|
106
|
+
upsert(params: UpsertParams): Promise<T>;
|
|
107
|
+
count(params: CountParams): Promise<number>;
|
|
108
|
+
transaction<R>(callback: (trx: TransactionAdapter) => Promise<R>): Promise<R>;
|
|
109
|
+
|
|
110
|
+
// Lifecycle
|
|
111
|
+
initialize(): Promise<void>;
|
|
112
|
+
isHealthy(): Promise<HealthStatus>;
|
|
113
|
+
close(): Promise<void>;
|
|
114
|
+
|
|
115
|
+
// Schema management
|
|
116
|
+
getSchemaVersion(namespace: string): Promise<number>;
|
|
117
|
+
setSchemaVersion(namespace: string, version: number): Promise<void>;
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Capabilities System
|
|
122
|
+
|
|
123
|
+
Adapters declare their capabilities, and libraries adapt accordingly:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
const adapter = memoryAdapter();
|
|
127
|
+
|
|
128
|
+
if (adapter.capabilities.operations.batch) {
|
|
129
|
+
// Use batch operations
|
|
130
|
+
await adapter.createMany({ model: 'users', data: users });
|
|
131
|
+
} else {
|
|
132
|
+
// Fallback to sequential
|
|
133
|
+
for (const user of users) {
|
|
134
|
+
await adapter.create({ model: 'users', data: user });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Namespace Isolation
|
|
140
|
+
|
|
141
|
+
Prevent table name conflicts when multiple libraries use the same database:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
const adapter = memoryAdapter({
|
|
145
|
+
namespace: {
|
|
146
|
+
enabled: true,
|
|
147
|
+
separator: '_'
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// Library A
|
|
152
|
+
const sendFn = SendFn({ database: adapter, namespace: 'sendFn' });
|
|
153
|
+
// Tables: sendFn_email_log, sendFn_templates
|
|
154
|
+
|
|
155
|
+
// Library B
|
|
156
|
+
const webFn = WebFn({ database: adapter, namespace: 'webFn' });
|
|
157
|
+
// Tables: webFn_jobs, webFn_results
|
|
158
|
+
|
|
159
|
+
// No conflicts!
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Built-in Adapters
|
|
163
|
+
|
|
164
|
+
### Memory Adapter
|
|
165
|
+
|
|
166
|
+
In-memory adapter for testing and development:
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { memoryAdapter } from '@superfunctions/db/adapters';
|
|
170
|
+
|
|
171
|
+
const adapter = memoryAdapter({
|
|
172
|
+
namespace: { enabled: true },
|
|
173
|
+
debug: true
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Drizzle Adapter
|
|
178
|
+
|
|
179
|
+
For Drizzle ORM (PostgreSQL, MySQL, SQLite):
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
183
|
+
import { users, posts } from './schema';
|
|
184
|
+
import { drizzleAdapter } from '@superfunctions/db/adapters';
|
|
185
|
+
|
|
186
|
+
const db = drizzle(pool);
|
|
187
|
+
const adapter = drizzleAdapter({
|
|
188
|
+
db,
|
|
189
|
+
dialect: 'postgres', // 'postgres' | 'mysql' | 'sqlite'
|
|
190
|
+
schema: { users, posts }, // model name โ drizzle table
|
|
191
|
+
upsertKeys: { users: 'email' }, // conflict targets
|
|
192
|
+
schemaVersionsTable, // optional
|
|
193
|
+
debug: false
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
**Features:**
|
|
198
|
+
- Full CRUD with where/orderBy/select
|
|
199
|
+
- Batch operations
|
|
200
|
+
- Transactions (async for Postgres/MySQL)
|
|
201
|
+
- Upsert with conflict resolution
|
|
202
|
+
- All where operators: eq, ne, gt, gte, lt, lte, in, not_in, contains, starts_with, ends_with
|
|
203
|
+
|
|
204
|
+
### Prisma Adapter
|
|
205
|
+
|
|
206
|
+
For Prisma ORM:
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import { PrismaClient } from '@prisma/client';
|
|
210
|
+
import { prismaAdapter } from '@superfunctions/db/adapters';
|
|
211
|
+
|
|
212
|
+
const prisma = new PrismaClient();
|
|
213
|
+
const adapter = prismaAdapter({
|
|
214
|
+
prisma,
|
|
215
|
+
modelMap: { users: 'user', posts: 'post' }, // model โ Prisma model name
|
|
216
|
+
schemaVersionsTable: 'schemaVersions', // optional
|
|
217
|
+
debug: false
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
**Features:**
|
|
222
|
+
- Full where clause translation with AND/OR
|
|
223
|
+
- Select projection and orderBy
|
|
224
|
+
- Batch operations
|
|
225
|
+
- Transaction support via `$transaction`
|
|
226
|
+
- Upsert with unique constraints
|
|
227
|
+
|
|
228
|
+
### Kysely Adapter
|
|
229
|
+
|
|
230
|
+
For Kysely query builder:
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
import { Kysely, PostgresDialect } from 'kysely';
|
|
234
|
+
import { kyselyAdapter } from '@superfunctions/db/adapters';
|
|
235
|
+
|
|
236
|
+
const db = new Kysely<Database>({
|
|
237
|
+
dialect: new PostgresDialect({ pool })
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const adapter = kyselyAdapter({
|
|
241
|
+
db,
|
|
242
|
+
dialect: 'postgres', // 'postgres' | 'mysql' | 'sqlite'
|
|
243
|
+
schema: { users: 'users', posts: 'posts' }, // model โ table name
|
|
244
|
+
schemaVersionsTable: '__schema_versions', // optional
|
|
245
|
+
debug: false
|
|
246
|
+
});
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**Features:**
|
|
250
|
+
- Type-safe query building
|
|
251
|
+
- Full CRUD with all operators
|
|
252
|
+
- Transactions
|
|
253
|
+
- Upsert (INSERT...ON CONFLICT)
|
|
254
|
+
- Multi-dialect support
|
|
255
|
+
|
|
256
|
+
### MongoDB Adapter (Coming Soon)
|
|
257
|
+
|
|
258
|
+
For MongoDB (planned for v1.1 or community contribution)
|
|
259
|
+
|
|
260
|
+
## Testing
|
|
261
|
+
|
|
262
|
+
Use the built-in memory adapter for testing:
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
import { memoryAdapter } from '@superfunctions/db/testing';
|
|
266
|
+
import { describe, it, expect } from 'vitest';
|
|
267
|
+
|
|
268
|
+
describe('My Library', () => {
|
|
269
|
+
it('should create records', async () => {
|
|
270
|
+
const adapter = memoryAdapter();
|
|
271
|
+
|
|
272
|
+
const result = await adapter.create({
|
|
273
|
+
model: 'users',
|
|
274
|
+
data: { name: 'John' }
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
expect(result).toHaveProperty('id');
|
|
278
|
+
expect(result.name).toBe('John');
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## TypeScript
|
|
284
|
+
|
|
285
|
+
Full TypeScript support with strict types:
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
import type {
|
|
289
|
+
Adapter,
|
|
290
|
+
CreateParams,
|
|
291
|
+
WhereClause,
|
|
292
|
+
TableSchema
|
|
293
|
+
} from '@superfunctions/db';
|
|
294
|
+
|
|
295
|
+
const adapter: Adapter = memoryAdapter();
|
|
296
|
+
|
|
297
|
+
const params: CreateParams = {
|
|
298
|
+
model: 'users',
|
|
299
|
+
data: { name: 'John' }
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
const user = await adapter.create(params);
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## Error Handling
|
|
306
|
+
|
|
307
|
+
Standardized error classes across all adapters:
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
import {
|
|
311
|
+
AdapterError,
|
|
312
|
+
NotFoundError,
|
|
313
|
+
ConnectionError
|
|
314
|
+
} from '@superfunctions/db';
|
|
315
|
+
|
|
316
|
+
try {
|
|
317
|
+
await adapter.findOne({ model: 'users', where: [{ field: 'id', operator: 'eq', value: '123' }] });
|
|
318
|
+
} catch (error) {
|
|
319
|
+
if (error instanceof NotFoundError) {
|
|
320
|
+
console.log('User not found');
|
|
321
|
+
} else if (error instanceof ConnectionError) {
|
|
322
|
+
console.log('Database connection failed');
|
|
323
|
+
} else if (error instanceof AdapterError) {
|
|
324
|
+
console.log('Adapter error:', error.code);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
## License
|
|
330
|
+
|
|
331
|
+
Apache-2.0
|
|
332
|
+
|
|
333
|
+
## Contributing
|
|
334
|
+
|
|
335
|
+
Contributions welcome! See [Contributing Guide](../../CONTRIBUTING.md) for details.
|
|
336
|
+
|
|
337
|
+
## Related Packages
|
|
338
|
+
|
|
339
|
+
- `@superfunctions/cli` - Schema management and migrations
|
|
340
|
+
- `@superfunctions/sendFn` - Email functionality (example library)
|
|
341
|
+
- `@superfunctions/webFn` - Web scraping (example library)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability system for adapter feature detection
|
|
3
|
+
*/
|
|
4
|
+
import type { TransactionIsolation } from './types.js';
|
|
5
|
+
export interface AdapterCapabilities {
|
|
6
|
+
types: {
|
|
7
|
+
json: boolean;
|
|
8
|
+
dates: boolean;
|
|
9
|
+
booleans: boolean;
|
|
10
|
+
bigint: boolean;
|
|
11
|
+
uuid: boolean;
|
|
12
|
+
enum: boolean;
|
|
13
|
+
};
|
|
14
|
+
operations: {
|
|
15
|
+
batch: boolean;
|
|
16
|
+
upsert: boolean;
|
|
17
|
+
streaming: boolean;
|
|
18
|
+
fulltext: boolean;
|
|
19
|
+
returning: boolean;
|
|
20
|
+
};
|
|
21
|
+
transactions: {
|
|
22
|
+
supported: boolean;
|
|
23
|
+
nested: boolean;
|
|
24
|
+
isolation?: TransactionIsolation[];
|
|
25
|
+
};
|
|
26
|
+
performance: {
|
|
27
|
+
maxBatchSize?: number;
|
|
28
|
+
supportsJoins: boolean;
|
|
29
|
+
supportsPreparedStatements: boolean;
|
|
30
|
+
};
|
|
31
|
+
schema: {
|
|
32
|
+
migrations: boolean;
|
|
33
|
+
constraints: boolean;
|
|
34
|
+
indexes: boolean;
|
|
35
|
+
};
|
|
36
|
+
advanced: {
|
|
37
|
+
customIdGeneration: boolean;
|
|
38
|
+
numericIds: boolean;
|
|
39
|
+
schemaNamespaces: boolean;
|
|
40
|
+
customTypes: boolean;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Default capabilities - conservative defaults that work everywhere
|
|
45
|
+
*/
|
|
46
|
+
export declare const DEFAULT_CAPABILITIES: AdapterCapabilities;
|
|
47
|
+
/**
|
|
48
|
+
* Merge partial capabilities with defaults
|
|
49
|
+
*/
|
|
50
|
+
export declare function mergeCapabilities(partial: Partial<AdapterCapabilities>): AdapterCapabilities;
|
|
51
|
+
//# sourceMappingURL=capabilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/adapter/capabilities.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD,MAAM,WAAW,mBAAmB;IAElC,KAAK,EAAE;QACL,IAAI,EAAE,OAAO,CAAC;QACd,KAAK,EAAE,OAAO,CAAC;QACf,QAAQ,EAAE,OAAO,CAAC;QAClB,MAAM,EAAE,OAAO,CAAC;QAChB,IAAI,EAAE,OAAO,CAAC;QACd,IAAI,EAAE,OAAO,CAAC;KACf,CAAC;IAGF,UAAU,EAAE;QACV,KAAK,EAAE,OAAO,CAAC;QACf,MAAM,EAAE,OAAO,CAAC;QAChB,SAAS,EAAE,OAAO,CAAC;QACnB,QAAQ,EAAE,OAAO,CAAC;QAClB,SAAS,EAAE,OAAO,CAAC;KACpB,CAAC;IAGF,YAAY,EAAE;QACZ,SAAS,EAAE,OAAO,CAAC;QACnB,MAAM,EAAE,OAAO,CAAC;QAChB,SAAS,CAAC,EAAE,oBAAoB,EAAE,CAAC;KACpC,CAAC;IAGF,WAAW,EAAE;QACX,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,OAAO,CAAC;QACvB,0BAA0B,EAAE,OAAO,CAAC;KACrC,CAAC;IAGF,MAAM,EAAE;QACN,UAAU,EAAE,OAAO,CAAC;QACpB,WAAW,EAAE,OAAO,CAAC;QACrB,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IAGF,QAAQ,EAAE;QACR,kBAAkB,EAAE,OAAO,CAAC;QAC5B,UAAU,EAAE,OAAO,CAAC;QACpB,gBAAgB,EAAE,OAAO,CAAC;QAC1B,WAAW,EAAE,OAAO,CAAC;KACtB,CAAC;CACH;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,mBAmClC,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,OAAO,CAAC,mBAAmB,CAAC,GACpC,mBAAmB,CASrB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability system for adapter feature detection
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Default capabilities - conservative defaults that work everywhere
|
|
6
|
+
*/
|
|
7
|
+
export const DEFAULT_CAPABILITIES = {
|
|
8
|
+
types: {
|
|
9
|
+
json: false,
|
|
10
|
+
dates: true,
|
|
11
|
+
booleans: true,
|
|
12
|
+
bigint: false,
|
|
13
|
+
uuid: false,
|
|
14
|
+
enum: false,
|
|
15
|
+
},
|
|
16
|
+
operations: {
|
|
17
|
+
batch: false,
|
|
18
|
+
upsert: false,
|
|
19
|
+
streaming: false,
|
|
20
|
+
fulltext: false,
|
|
21
|
+
returning: false,
|
|
22
|
+
},
|
|
23
|
+
transactions: {
|
|
24
|
+
supported: false,
|
|
25
|
+
nested: false,
|
|
26
|
+
},
|
|
27
|
+
performance: {
|
|
28
|
+
supportsJoins: false,
|
|
29
|
+
supportsPreparedStatements: false,
|
|
30
|
+
},
|
|
31
|
+
schema: {
|
|
32
|
+
migrations: false,
|
|
33
|
+
constraints: false,
|
|
34
|
+
indexes: false,
|
|
35
|
+
},
|
|
36
|
+
advanced: {
|
|
37
|
+
customIdGeneration: false,
|
|
38
|
+
numericIds: false,
|
|
39
|
+
schemaNamespaces: false,
|
|
40
|
+
customTypes: false,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Merge partial capabilities with defaults
|
|
45
|
+
*/
|
|
46
|
+
export function mergeCapabilities(partial) {
|
|
47
|
+
return {
|
|
48
|
+
types: { ...DEFAULT_CAPABILITIES.types, ...partial.types },
|
|
49
|
+
operations: { ...DEFAULT_CAPABILITIES.operations, ...partial.operations },
|
|
50
|
+
transactions: { ...DEFAULT_CAPABILITIES.transactions, ...partial.transactions },
|
|
51
|
+
performance: { ...DEFAULT_CAPABILITIES.performance, ...partial.performance },
|
|
52
|
+
schema: { ...DEFAULT_CAPABILITIES.schema, ...partial.schema },
|
|
53
|
+
advanced: { ...DEFAULT_CAPABILITIES.advanced, ...partial.advanced },
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=capabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../src/adapter/capabilities.ts"],"names":[],"mappings":"AAAA;;GAEG;AAsDH;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAwB;IACvD,KAAK,EAAE;QACL,IAAI,EAAE,KAAK;QACX,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,KAAK;KACZ;IACD,UAAU,EAAE;QACV,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE,KAAK;QACb,SAAS,EAAE,KAAK;QAChB,QAAQ,EAAE,KAAK;QACf,SAAS,EAAE,KAAK;KACjB;IACD,YAAY,EAAE;QACZ,SAAS,EAAE,KAAK;QAChB,MAAM,EAAE,KAAK;KACd;IACD,WAAW,EAAE;QACX,aAAa,EAAE,KAAK;QACpB,0BAA0B,EAAE,KAAK;KAClC;IACD,MAAM,EAAE;QACN,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE,KAAK;QAClB,OAAO,EAAE,KAAK;KACf;IACD,QAAQ,EAAE;QACR,kBAAkB,EAAE,KAAK;QACzB,UAAU,EAAE,KAAK;QACjB,gBAAgB,EAAE,KAAK;QACvB,WAAW,EAAE,KAAK;KACnB;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAAqC;IAErC,OAAO;QACL,KAAK,EAAE,EAAE,GAAG,oBAAoB,CAAC,KAAK,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE;QAC1D,UAAU,EAAE,EAAE,GAAG,oBAAoB,CAAC,UAAU,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE;QACzE,YAAY,EAAE,EAAE,GAAG,oBAAoB,CAAC,YAAY,EAAE,GAAG,OAAO,CAAC,YAAY,EAAE;QAC/E,WAAW,EAAE,EAAE,GAAG,oBAAoB,CAAC,WAAW,EAAE,GAAG,OAAO,CAAC,WAAW,EAAE;QAC5E,MAAM,EAAE,EAAE,GAAG,oBAAoB,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE;QAC7D,QAAQ,EAAE,EAAE,GAAG,oBAAoB,CAAC,QAAQ,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE;KACpE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error system for adapters
|
|
3
|
+
*/
|
|
4
|
+
import type { WhereClause } from './types.js';
|
|
5
|
+
export declare enum AdapterErrorCode {
|
|
6
|
+
CONNECTION_FAILED = "ADAPTER_CONNECTION_FAILED",
|
|
7
|
+
CONNECTION_TIMEOUT = "ADAPTER_CONNECTION_TIMEOUT",
|
|
8
|
+
CONNECTION_CLOSED = "ADAPTER_CONNECTION_CLOSED",
|
|
9
|
+
QUERY_FAILED = "ADAPTER_QUERY_FAILED",
|
|
10
|
+
QUERY_TIMEOUT = "ADAPTER_QUERY_TIMEOUT",
|
|
11
|
+
INVALID_QUERY = "ADAPTER_INVALID_QUERY",
|
|
12
|
+
CONSTRAINT_VIOLATION = "ADAPTER_CONSTRAINT_VIOLATION",
|
|
13
|
+
NOT_FOUND = "ADAPTER_NOT_FOUND",
|
|
14
|
+
DUPLICATE_KEY = "ADAPTER_DUPLICATE_KEY",
|
|
15
|
+
INVALID_DATA = "ADAPTER_INVALID_DATA",
|
|
16
|
+
TRANSACTION_FAILED = "ADAPTER_TRANSACTION_FAILED",
|
|
17
|
+
TRANSACTION_DEADLOCK = "ADAPTER_TRANSACTION_DEADLOCK",
|
|
18
|
+
SCHEMA_INVALID = "ADAPTER_SCHEMA_INVALID",
|
|
19
|
+
SCHEMA_CONFLICT = "ADAPTER_SCHEMA_CONFLICT",
|
|
20
|
+
MIGRATION_FAILED = "ADAPTER_MIGRATION_FAILED",
|
|
21
|
+
OPERATION_NOT_SUPPORTED = "ADAPTER_OPERATION_NOT_SUPPORTED",
|
|
22
|
+
BATCH_SIZE_EXCEEDED = "ADAPTER_BATCH_SIZE_EXCEEDED",
|
|
23
|
+
UNKNOWN_ERROR = "ADAPTER_UNKNOWN_ERROR"
|
|
24
|
+
}
|
|
25
|
+
export interface AdapterErrorOptions {
|
|
26
|
+
cause?: unknown;
|
|
27
|
+
context?: Record<string, any>;
|
|
28
|
+
retryable?: boolean;
|
|
29
|
+
severity?: 'fatal' | 'error' | 'warning';
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Base adapter error class
|
|
33
|
+
*/
|
|
34
|
+
export declare class AdapterError extends Error {
|
|
35
|
+
readonly code: AdapterErrorCode;
|
|
36
|
+
readonly options?: AdapterErrorOptions | undefined;
|
|
37
|
+
readonly name: string;
|
|
38
|
+
readonly timestamp: Date;
|
|
39
|
+
constructor(code: AdapterErrorCode, message: string, options?: AdapterErrorOptions | undefined);
|
|
40
|
+
isRetryable(): boolean;
|
|
41
|
+
toJSON(): {
|
|
42
|
+
name: string;
|
|
43
|
+
code: AdapterErrorCode;
|
|
44
|
+
message: string;
|
|
45
|
+
timestamp: string;
|
|
46
|
+
context: Record<string, any> | undefined;
|
|
47
|
+
retryable: boolean;
|
|
48
|
+
severity: "fatal" | "error" | "warning";
|
|
49
|
+
};
|
|
50
|
+
static from(error: unknown, code?: AdapterErrorCode): AdapterError;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Connection error - fatal, retryable
|
|
54
|
+
*/
|
|
55
|
+
export declare class ConnectionError extends AdapterError {
|
|
56
|
+
readonly name = "ConnectionError";
|
|
57
|
+
constructor(message: string, options?: AdapterErrorOptions);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Constraint violation error - not retryable
|
|
61
|
+
*/
|
|
62
|
+
export declare class ConstraintViolationError extends AdapterError {
|
|
63
|
+
readonly constraint: string;
|
|
64
|
+
readonly name = "ConstraintViolationError";
|
|
65
|
+
constructor(message: string, constraint: string);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Not found error - not retryable
|
|
69
|
+
*/
|
|
70
|
+
export declare class NotFoundError extends AdapterError {
|
|
71
|
+
readonly name = "NotFoundError";
|
|
72
|
+
constructor(model: string, where: WhereClause[]);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Duplicate key error - not retryable
|
|
76
|
+
*/
|
|
77
|
+
export declare class DuplicateKeyError extends AdapterError {
|
|
78
|
+
readonly key: string;
|
|
79
|
+
readonly name = "DuplicateKeyError";
|
|
80
|
+
constructor(message: string, key: string);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Query failed error - may be retryable
|
|
84
|
+
*/
|
|
85
|
+
export declare class QueryFailedError extends AdapterError {
|
|
86
|
+
readonly name = "QueryFailedError";
|
|
87
|
+
constructor(message: string, options?: AdapterErrorOptions);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Transaction failed error - may be retryable
|
|
91
|
+
*/
|
|
92
|
+
export declare class TransactionError extends AdapterError {
|
|
93
|
+
readonly name = "TransactionError";
|
|
94
|
+
constructor(message: string, options?: AdapterErrorOptions);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Schema validation error - not retryable
|
|
98
|
+
*/
|
|
99
|
+
export declare class SchemaValidationError extends AdapterError {
|
|
100
|
+
readonly errors: string[];
|
|
101
|
+
readonly name = "SchemaValidationError";
|
|
102
|
+
constructor(message: string, errors: string[]);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Operation not supported error - not retryable
|
|
106
|
+
*/
|
|
107
|
+
export declare class OperationNotSupportedError extends AdapterError {
|
|
108
|
+
readonly name = "OperationNotSupportedError";
|
|
109
|
+
constructor(operation: string, adapterName: string);
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/adapter/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,oBAAY,gBAAgB;IAE1B,iBAAiB,8BAA8B;IAC/C,kBAAkB,+BAA+B;IACjD,iBAAiB,8BAA8B;IAG/C,YAAY,yBAAyB;IACrC,aAAa,0BAA0B;IACvC,aAAa,0BAA0B;IAGvC,oBAAoB,iCAAiC;IACrD,SAAS,sBAAsB;IAC/B,aAAa,0BAA0B;IACvC,YAAY,yBAAyB;IAGrC,kBAAkB,+BAA+B;IACjD,oBAAoB,iCAAiC;IAGrD,cAAc,2BAA2B;IACzC,eAAe,4BAA4B;IAC3C,gBAAgB,6BAA6B;IAG7C,uBAAuB,oCAAoC;IAC3D,mBAAmB,gCAAgC;IAGnD,aAAa,0BAA0B;CACxC;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;CAC1C;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;aAKnB,IAAI,EAAE,gBAAgB;aAEtB,OAAO,CAAC,EAAE,mBAAmB;IAN/C,SAAyB,IAAI,EAAE,MAAM,CAAkB;IACvD,SAAgB,SAAS,EAAE,IAAI,CAAC;gBAGd,IAAI,EAAE,gBAAgB,EACtC,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,mBAAmB,YAAA;IAW/C,WAAW,IAAI,OAAO;IAItB,MAAM;;;;;;;;;IAYN,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,mBAAiC,GAAG,YAAY;CAOjF;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,YAAY;IAC/C,SAAyB,IAAI,qBAAqB;gBAEtC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB;CAO3D;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,YAAY;aAGX,UAAU,EAAE,MAAM;IAF/D,SAAyB,IAAI,8BAA8B;gBAE/C,OAAO,EAAE,MAAM,EAAkB,UAAU,EAAE,MAAM;CAMhE;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,YAAY;IAC7C,SAAyB,IAAI,mBAAmB;gBAEpC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE;CAMhD;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,YAAY;aAGJ,GAAG,EAAE,MAAM;IAFxD,SAAyB,IAAI,uBAAuB;gBAExC,OAAO,EAAE,MAAM,EAAkB,GAAG,EAAE,MAAM;CAMzD;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,SAAyB,IAAI,sBAAsB;gBAEvC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB;CAG3D;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,SAAyB,IAAI,sBAAsB;gBAEvC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB;CAM3D;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,YAAY;aAGR,MAAM,EAAE,MAAM,EAAE;IAF7D,SAAyB,IAAI,2BAA2B;gBAE5C,OAAO,EAAE,MAAM,EAAkB,MAAM,EAAE,MAAM,EAAE;CAM9D;AAED;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,YAAY;IAC1D,SAAyB,IAAI,gCAAgC;gBAEjD,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;CAUnD"}
|