@fragno-dev/test 2.0.0 → 2.0.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.
Files changed (59) hide show
  1. package/.turbo/turbo-build.log +41 -31
  2. package/CHANGELOG.md +69 -0
  3. package/dist/adapters.d.ts +4 -7
  4. package/dist/adapters.d.ts.map +1 -1
  5. package/dist/adapters.js +18 -302
  6. package/dist/adapters.js.map +1 -1
  7. package/dist/db-test.d.ts +120 -18
  8. package/dist/db-test.d.ts.map +1 -1
  9. package/dist/db-test.js +203 -55
  10. package/dist/db-test.js.map +1 -1
  11. package/dist/durable-hooks.d.ts +6 -2
  12. package/dist/durable-hooks.d.ts.map +1 -1
  13. package/dist/durable-hooks.js +10 -5
  14. package/dist/durable-hooks.js.map +1 -1
  15. package/dist/index.d.ts +3 -3
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/model-checker-actors.d.ts.map +1 -1
  20. package/dist/model-checker-actors.js +1 -1
  21. package/dist/model-checker-actors.js.map +1 -1
  22. package/dist/model-checker-adapter.d.ts +1 -1
  23. package/dist/model-checker-adapter.d.ts.map +1 -1
  24. package/dist/model-checker-adapter.js.map +1 -1
  25. package/dist/model-checker.d.ts.map +1 -1
  26. package/dist/model-checker.js.map +1 -1
  27. package/dist/test-adapters/drizzle-pglite.js +116 -0
  28. package/dist/test-adapters/drizzle-pglite.js.map +1 -0
  29. package/dist/test-adapters/in-memory.js +39 -0
  30. package/dist/test-adapters/in-memory.js.map +1 -0
  31. package/dist/test-adapters/kysely-pglite.js +105 -0
  32. package/dist/test-adapters/kysely-pglite.js.map +1 -0
  33. package/dist/test-adapters/kysely-sqlite.js +87 -0
  34. package/dist/test-adapters/kysely-sqlite.js.map +1 -0
  35. package/dist/test-adapters/model-checker.js +41 -0
  36. package/dist/test-adapters/model-checker.js.map +1 -0
  37. package/dist/tsconfig.tsbuildinfo +1 -0
  38. package/package.json +32 -33
  39. package/src/adapter-conformance.test.ts +3 -1
  40. package/src/adapters.ts +24 -455
  41. package/src/db-roundtrip-guard.test.ts +206 -0
  42. package/src/db-test.test.ts +131 -77
  43. package/src/db-test.ts +530 -96
  44. package/src/durable-hooks.test.ts +58 -0
  45. package/src/durable-hooks.ts +23 -8
  46. package/src/index.test.ts +188 -104
  47. package/src/index.ts +6 -2
  48. package/src/model-checker-actors.test.ts +5 -2
  49. package/src/model-checker-actors.ts +2 -1
  50. package/src/model-checker-adapter.ts +3 -2
  51. package/src/model-checker.test.ts +4 -1
  52. package/src/model-checker.ts +4 -3
  53. package/src/test-adapters/drizzle-pglite.ts +162 -0
  54. package/src/test-adapters/in-memory.ts +56 -0
  55. package/src/test-adapters/kysely-pglite.ts +151 -0
  56. package/src/test-adapters/kysely-sqlite.ts +119 -0
  57. package/src/test-adapters/model-checker.ts +58 -0
  58. package/tsconfig.json +1 -1
  59. package/vitest.config.ts +1 -0
package/package.json CHANGED
@@ -1,29 +1,51 @@
1
1
  {
2
2
  "name": "@fragno-dev/test",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
+ "homepage": "https://fragno.dev",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/rejot-dev/fragno.git",
9
+ "directory": "packages/fragno-test"
10
+ },
4
11
  "type": "module",
12
+ "main": "./dist/index.js",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
5
15
  "exports": {
6
16
  ".": {
7
- "development": "./src/index.ts",
8
17
  "types": "./dist/index.d.ts",
9
18
  "default": "./dist/index.js"
10
19
  }
11
20
  },
12
- "main": "./dist/index.js",
13
- "module": "./dist/index.js",
14
- "types": "./dist/index.d.ts",
15
21
  "dependencies": {
16
22
  "@standard-schema/spec": "^1.1.0",
17
23
  "kysely": "^0.28.10",
18
- "sqlocal": "^0.15.2"
24
+ "sqlocal": "^0.15.2",
25
+ "@fragno-dev/core": "0.2.2",
26
+ "@fragno-dev/db": "0.4.1"
27
+ },
28
+ "devDependencies": {
29
+ "@electric-sql/pglite": "^0.3.15",
30
+ "@libsql/client": "^0.14.0",
31
+ "@types/node": "^22.19.7",
32
+ "@vitest/coverage-istanbul": "^4.1.0",
33
+ "drizzle-kit": "^0.31.8",
34
+ "drizzle-orm": "^0.44.7",
35
+ "kysely-pglite": "^0.6.1",
36
+ "superjson": "^2.2.1",
37
+ "vitest": "^4.1.4",
38
+ "zod": "^4.3.5",
39
+ "@fragno-dev/core": "0.2.2",
40
+ "@fragno-dev/db": "0.4.1",
41
+ "@fragno-private/typescript-config": "0.0.1",
42
+ "@fragno-private/vitest-config": "0.0.0"
19
43
  },
20
44
  "peerDependencies": {
21
45
  "@electric-sql/pglite": "^0.3.11",
22
46
  "drizzle-kit": "^0.31.7",
23
47
  "drizzle-orm": "^0.44.7",
24
- "kysely-pglite": "^0.6.1",
25
- "@fragno-dev/core": "0.2.0",
26
- "@fragno-dev/db": "0.3.0"
48
+ "kysely-pglite": "^0.6.1"
27
49
  },
28
50
  "peerDependenciesMeta": {
29
51
  "@electric-sql/pglite": {
@@ -39,33 +61,10 @@
39
61
  "optional": true
40
62
  }
41
63
  },
42
- "devDependencies": {
43
- "@electric-sql/pglite": "^0.3.15",
44
- "@libsql/client": "^0.14.0",
45
- "@types/node": "^22.19.7",
46
- "@vitest/coverage-istanbul": "^3.2.4",
47
- "drizzle-kit": "^0.31.8",
48
- "drizzle-orm": "^0.44.7",
49
- "kysely-pglite": "^0.6.1",
50
- "superjson": "^2.2.1",
51
- "vitest": "^3.2.4",
52
- "zod": "^4.3.5",
53
- "@fragno-dev/core": "0.2.0",
54
- "@fragno-dev/db": "0.3.0",
55
- "@fragno-private/typescript-config": "0.0.1",
56
- "@fragno-private/vitest-config": "0.0.0"
57
- },
58
- "repository": {
59
- "type": "git",
60
- "url": "https://github.com/rejot-dev/fragno.git",
61
- "directory": "packages/fragno-test"
62
- },
63
- "homepage": "https://fragno.dev",
64
- "license": "MIT",
65
64
  "scripts": {
66
65
  "build": "tsdown",
67
66
  "build:watch": "tsdown --watch",
68
- "types:check": "tsc --noEmit",
67
+ "types:check": "tsgo --noEmit",
69
68
  "test": "vitest run",
70
69
  "test:watch": "vitest --watch"
71
70
  }
@@ -1,6 +1,8 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { column, idColumn, referenceColumn, schema } from "@fragno-dev/db/schema";
2
+
3
3
  import type { SimpleQueryInterface } from "@fragno-dev/db/query";
4
+ import { column, idColumn, referenceColumn, schema } from "@fragno-dev/db/schema";
5
+
4
6
  import { createAdapter, type SupportedAdapter } from "./adapters";
5
7
 
6
8
  const conformanceSchema = schema("conformance", (s) =>
package/src/adapters.ts CHANGED
@@ -1,43 +1,28 @@
1
- // Test database adapter helpers and reset logic for fragment suites.
2
- import { Kysely } from "kysely";
3
- import { SQLocalKysely } from "sqlocal/kysely";
4
- import { KyselyPGlite } from "kysely-pglite";
5
- import { drizzle } from "drizzle-orm/pglite";
6
- import { PGlite } from "@electric-sql/pglite";
7
- import { InMemoryAdapter, type InMemoryAdapterOptions } from "@fragno-dev/db/adapters/in-memory";
8
- import { SqlAdapter } from "@fragno-dev/db/adapters/sql";
9
- import type { AnySchema } from "@fragno-dev/db/schema";
10
1
  import type { DatabaseAdapter } from "@fragno-dev/db/adapters";
2
+ import type { InMemoryAdapterOptions } from "@fragno-dev/db/adapters/in-memory";
11
3
  import type { UnitOfWorkConfig } from "@fragno-dev/db/adapters/sql";
12
- import type { OutboxConfig } from "@fragno-dev/db/adapters/sql";
13
- import { rm } from "node:fs/promises";
14
- import { existsSync } from "node:fs";
15
- import type { BaseTestContext } from ".";
16
- import { ModelCheckerAdapter } from "./model-checker-adapter";
17
- import { createCommonTestContextMethods } from ".";
18
- import { PGLiteDriverConfig, SQLocalDriverConfig } from "@fragno-dev/db/drivers";
19
- import { internalFragmentDef } from "@fragno-dev/db";
20
4
  import type { SimpleQueryInterface } from "@fragno-dev/db/query";
5
+ import type { AnySchema } from "@fragno-dev/db/schema";
6
+ import type { drizzle } from "drizzle-orm/pglite";
7
+ import type { Kysely } from "kysely";
8
+
9
+ import type { BaseTestContext } from ".";
21
10
 
22
- // Adapter configuration types
23
11
  export interface KyselySqliteAdapter {
24
12
  type: "kysely-sqlite";
25
13
  uowConfig?: UnitOfWorkConfig;
26
- outbox?: OutboxConfig;
27
14
  }
28
15
 
29
16
  export interface KyselyPgliteAdapter {
30
17
  type: "kysely-pglite";
31
18
  databasePath?: string;
32
19
  uowConfig?: UnitOfWorkConfig;
33
- outbox?: OutboxConfig;
34
20
  }
35
21
 
36
22
  export interface DrizzlePgliteAdapter {
37
23
  type: "drizzle-pglite";
38
24
  databasePath?: string;
39
25
  uowConfig?: UnitOfWorkConfig;
40
- outbox?: OutboxConfig;
41
26
  }
42
27
 
43
28
  export interface InMemoryAdapterConfig {
@@ -58,19 +43,16 @@ export type SupportedAdapter =
58
43
  | InMemoryAdapterConfig
59
44
  | ModelCheckerAdapterConfig;
60
45
 
61
- // Schema configuration for multi-schema adapters
62
46
  export interface SchemaConfig {
63
47
  schema: AnySchema;
64
48
  namespace: string | null;
65
49
  migrateToVersion?: number;
66
50
  }
67
51
 
68
- // Internal test context extends BaseTestContext with getOrm (not exposed publicly)
69
52
  interface InternalTestContext extends BaseTestContext {
70
53
  getOrm: <TSchema extends AnySchema>(namespace: string | null) => SimpleQueryInterface<TSchema>;
71
54
  }
72
55
 
73
- // Conditional return types based on adapter (adapter-specific properties only)
74
56
  export type AdapterContext<T extends SupportedAdapter> = T extends
75
57
  | KyselySqliteAdapter
76
58
  | KyselyPgliteAdapter
@@ -85,451 +67,38 @@ export type AdapterContext<T extends SupportedAdapter> = T extends
85
67
  ? {}
86
68
  : never;
87
69
 
88
- // Factory function return type
89
- interface AdapterFactoryResult<T extends SupportedAdapter> {
70
+ export interface AdapterFactoryResult<T extends SupportedAdapter> {
90
71
  testContext: InternalTestContext & AdapterContext<T>;
91
72
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
73
  adapter: DatabaseAdapter<any>;
93
74
  }
94
75
 
95
- const runInternalFragmentMigrations = async (
96
- adapter: SqlAdapter,
97
- ): Promise<SchemaConfig | undefined> => {
98
- const dependencies = internalFragmentDef.dependencies;
99
- if (!dependencies) {
100
- return undefined;
101
- }
102
-
103
- const databaseDeps = dependencies({
104
- config: {},
105
- options: { databaseAdapter: adapter, databaseNamespace: null },
106
- });
107
- if (databaseDeps?.schema) {
108
- const migrations = adapter.prepareMigrations(databaseDeps.schema, databaseDeps.namespace);
109
- await migrations.executeWithDriver(adapter.driver, 0);
110
- return { schema: databaseDeps.schema, namespace: databaseDeps.namespace };
111
- }
112
- return undefined;
113
- };
114
-
115
- const resolveSchemaName = (
116
- adapter: DatabaseAdapter<any>, // eslint-disable-line @typescript-eslint/no-explicit-any
117
- namespace: string | null,
118
- ): string | null => {
119
- if (adapter.namingStrategy.namespaceScope !== "schema") {
120
- return null;
121
- }
122
- if (!namespace || namespace.length === 0) {
123
- return null;
124
- }
125
- return adapter.namingStrategy.namespaceToSchema(namespace);
126
- };
127
-
128
- /**
129
- * Create Kysely + SQLite adapter using SQLocalKysely (always in-memory)
130
- * Supports multiple schemas with separate namespaces
131
- */
132
- export async function createKyselySqliteAdapter(
133
- config: KyselySqliteAdapter,
134
- schemas: SchemaConfig[],
135
- ): Promise<AdapterFactoryResult<KyselySqliteAdapter>> {
136
- let internalSchemaConfig: SchemaConfig | undefined;
137
-
138
- // Helper to create a new database instance and run migrations for all schemas
139
- const createDatabase = async () => {
140
- // Create SQLocalKysely instance (always in-memory for tests)
141
- const { dialect } = new SQLocalKysely(":memory:");
142
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
- const kysely = new Kysely<any>({
144
- dialect,
145
- });
146
-
147
- // Create SqlAdapter
148
- const adapter = new SqlAdapter({
149
- dialect,
150
- driverConfig: new SQLocalDriverConfig(),
151
- uowConfig: config.uowConfig,
152
- outbox: config.outbox,
153
- });
154
- internalSchemaConfig = await runInternalFragmentMigrations(adapter);
155
-
156
- // Run migrations for all schemas in order
157
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
158
- const ormMap = new Map<string | null, SimpleQueryInterface<any, any>>();
159
-
160
- for (const { schema, namespace, migrateToVersion } of schemas) {
161
- // Run migrations
162
- const preparedMigrations = adapter.prepareMigrations(schema, namespace);
163
- if (migrateToVersion !== undefined) {
164
- await preparedMigrations.execute(0, migrateToVersion, { updateVersionInMigration: false });
165
- } else {
166
- await preparedMigrations.execute(0, schema.version, { updateVersionInMigration: false });
167
- }
168
-
169
- // Create ORM instance and store in map
170
- const orm = adapter.createQueryEngine(schema, namespace);
171
- ormMap.set(namespace, orm);
172
- }
173
-
174
- return { kysely, adapter, ormMap };
175
- };
176
-
177
- // Create initial database
178
- let { kysely, adapter, ormMap } = await createDatabase();
179
-
180
- // Reset database function - truncates all tables (only supported for in-memory databases)
181
- const resetDatabase = async () => {
182
- const schemasToTruncate = internalSchemaConfig ? [internalSchemaConfig, ...schemas] : schemas;
183
-
184
- // For SQLite, truncate all tables by deleting rows
185
- for (const { schema, namespace } of schemasToTruncate) {
186
- for (const tableName of Object.keys(schema.tables)) {
187
- const physicalTableName = adapter.namingStrategy.tableName(tableName, namespace);
188
- await kysely.deleteFrom(physicalTableName).execute();
189
- }
190
- }
191
- };
192
-
193
- // Cleanup function - closes connections (no files to delete for in-memory)
194
- const cleanup = async () => {
195
- await kysely.destroy();
196
- };
197
-
198
- const commonMethods = createCommonTestContextMethods(ormMap);
199
-
200
- return {
201
- testContext: {
202
- get kysely() {
203
- return kysely;
204
- },
205
- get adapter() {
206
- return adapter;
207
- },
208
- ...commonMethods,
209
- resetDatabase,
210
- cleanup,
211
- },
212
- get adapter() {
213
- return adapter;
214
- },
215
- };
216
- }
217
-
218
- /**
219
- * Create Kysely + PGLite adapter using kysely-pglite
220
- * Supports multiple schemas with separate namespaces
221
- */
222
- export async function createKyselyPgliteAdapter(
223
- config: KyselyPgliteAdapter,
224
- schemas: SchemaConfig[],
225
- ): Promise<AdapterFactoryResult<KyselyPgliteAdapter>> {
226
- const databasePath = config.databasePath;
227
- let internalSchemaConfig: SchemaConfig | undefined;
228
-
229
- // Helper to create a new database instance and run migrations for all schemas
230
- const createDatabase = async () => {
231
- // Create KyselyPGlite instance
232
- const kyselyPglite = await KyselyPGlite.create(databasePath);
233
-
234
- // Create Kysely instance with PGlite dialect
235
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
236
- const kysely = new Kysely<any>({
237
- dialect: kyselyPglite.dialect,
238
- });
239
-
240
- // Create SqlAdapter
241
- const adapter = new SqlAdapter({
242
- dialect: kyselyPglite.dialect,
243
- driverConfig: new PGLiteDriverConfig(),
244
- uowConfig: config.uowConfig,
245
- outbox: config.outbox,
246
- });
247
- internalSchemaConfig = await runInternalFragmentMigrations(adapter);
248
-
249
- // Run migrations for all schemas in order
250
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
251
- const ormMap = new Map<string | null, SimpleQueryInterface<any, any>>();
252
-
253
- for (const { schema, namespace, migrateToVersion } of schemas) {
254
- // Run migrations
255
- const preparedMigrations = adapter.prepareMigrations(schema, namespace);
256
- if (migrateToVersion !== undefined) {
257
- await preparedMigrations.execute(0, migrateToVersion, { updateVersionInMigration: false });
258
- } else {
259
- await preparedMigrations.execute(0, schema.version, { updateVersionInMigration: false });
260
- }
261
-
262
- // Create ORM instance and store in map
263
- const orm = adapter.createQueryEngine(schema, namespace);
264
- ormMap.set(namespace, orm);
265
- }
266
-
267
- return { kysely, adapter, kyselyPglite, ormMap };
268
- };
269
-
270
- // Create initial database
271
- const { kysely, adapter, kyselyPglite, ormMap } = await createDatabase();
272
-
273
- // Reset database function - truncates all tables (only supported for in-memory databases)
274
- const resetDatabase = async () => {
275
- if (databasePath && databasePath !== ":memory:") {
276
- throw new Error("resetDatabase is only supported for in-memory databases");
277
- }
278
-
279
- const schemasToTruncate = internalSchemaConfig ? [internalSchemaConfig, ...schemas] : schemas;
280
-
281
- // Truncate all tables
282
- for (const { schema, namespace } of schemasToTruncate) {
283
- for (const tableName of Object.keys(schema.tables)) {
284
- const physicalTableName = adapter.namingStrategy.tableName(tableName, namespace);
285
- const schemaName = resolveSchemaName(adapter, namespace);
286
- const scopedKysely = schemaName ? kysely.withSchema(schemaName) : kysely;
287
- await scopedKysely.deleteFrom(physicalTableName).execute();
288
- }
289
- }
290
- };
291
-
292
- // Cleanup function - closes connections and deletes database directory
293
- const cleanup = async () => {
294
- await kysely.destroy();
295
-
296
- try {
297
- await kyselyPglite.client.close();
298
- } catch {
299
- // Ignore if already closed
300
- }
301
-
302
- // Delete the database directory if it exists and is a file path
303
- if (databasePath && databasePath !== ":memory:" && existsSync(databasePath)) {
304
- await rm(databasePath, { recursive: true, force: true });
305
- }
306
- };
307
-
308
- const commonMethods = createCommonTestContextMethods(ormMap);
309
-
310
- return {
311
- testContext: {
312
- get kysely() {
313
- return kysely;
314
- },
315
- get adapter() {
316
- return adapter;
317
- },
318
- ...commonMethods,
319
- resetDatabase,
320
- cleanup,
321
- },
322
- get adapter() {
323
- return adapter;
324
- },
325
- };
326
- }
327
-
328
- /**
329
- * Create Drizzle + PGLite adapter using drizzle-orm/pglite
330
- * Supports multiple schemas with separate namespaces
331
- */
332
- export async function createDrizzlePgliteAdapter(
333
- config: DrizzlePgliteAdapter,
334
- schemas: SchemaConfig[],
335
- ): Promise<AdapterFactoryResult<DrizzlePgliteAdapter>> {
336
- const databasePath = config.databasePath;
337
- let internalSchemaConfig: SchemaConfig | undefined;
338
-
339
- // Helper to create a new database instance and run migrations for all schemas
340
- const createDatabase = async () => {
341
- const pglite = new PGlite(databasePath);
342
-
343
- const { dialect } = new KyselyPGlite(pglite);
344
-
345
- const adapter = new SqlAdapter({
346
- dialect,
347
- driverConfig: new PGLiteDriverConfig(),
348
- uowConfig: config.uowConfig,
349
- outbox: config.outbox,
350
- });
351
-
352
- internalSchemaConfig = await runInternalFragmentMigrations(adapter);
353
-
354
- // Run migrations for all schemas
355
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
356
- const ormMap = new Map<string | null, SimpleQueryInterface<any, any>>();
357
-
358
- for (const { schema, namespace, migrateToVersion } of schemas) {
359
- const preparedMigrations = adapter.prepareMigrations(schema, namespace);
360
- if (migrateToVersion !== undefined) {
361
- await preparedMigrations.execute(0, migrateToVersion, { updateVersionInMigration: false });
362
- } else {
363
- await preparedMigrations.execute(0, schema.version, { updateVersionInMigration: false });
364
- }
365
-
366
- // Create ORM instance and store in map
367
- const orm = adapter.createQueryEngine(schema, namespace);
368
- ormMap.set(namespace, orm);
369
- }
370
-
371
- // Create Drizzle instance for backward compatibility (if needed)
372
- const db = drizzle(pglite) as any; // eslint-disable-line @typescript-eslint/no-explicit-any
373
-
374
- return { drizzle: db, adapter, pglite, ormMap };
375
- };
376
-
377
- // Create initial database
378
- const { drizzle: drizzleDb, adapter, ormMap } = await createDatabase();
379
-
380
- // Reset database function - truncates all tables (only supported for in-memory databases)
381
- const resetDatabase = async () => {
382
- if (databasePath && databasePath !== ":memory:") {
383
- throw new Error("resetDatabase is only supported for in-memory databases");
384
- }
385
-
386
- const schemasToTruncate = internalSchemaConfig ? [internalSchemaConfig, ...schemas] : schemas;
387
-
388
- // Truncate all tables by deleting rows
389
- for (const { schema, namespace } of schemasToTruncate) {
390
- const tableNames = Object.keys(schema.tables).slice().reverse();
391
- for (const tableName of tableNames) {
392
- const physicalTableName = adapter.namingStrategy.tableName(tableName, namespace);
393
- const schemaName = resolveSchemaName(adapter, namespace);
394
- const qualifiedTable = schemaName
395
- ? `"${schemaName}"."${physicalTableName}"`
396
- : `"${physicalTableName}"`;
397
- await drizzleDb.execute(`DELETE FROM ${qualifiedTable}`);
398
- }
399
- }
400
- };
401
-
402
- // Cleanup function - closes connections and deletes database directory
403
- const cleanup = async () => {
404
- // Close the adapter (which will handle closing the underlying database connection)
405
- await adapter.close();
406
-
407
- // Delete the database directory if it exists and is a file path
408
- if (databasePath && databasePath !== ":memory:" && existsSync(databasePath)) {
409
- await rm(databasePath, { recursive: true, force: true });
410
- }
411
- };
412
-
413
- const commonMethods = createCommonTestContextMethods(ormMap);
414
-
415
- return {
416
- testContext: {
417
- get drizzle() {
418
- return drizzleDb;
419
- },
420
- get adapter() {
421
- return adapter;
422
- },
423
- ...commonMethods,
424
- resetDatabase,
425
- cleanup,
426
- },
427
- get adapter() {
428
- return adapter;
429
- },
430
- };
431
- }
432
-
433
- /**
434
- * Create InMemory adapter (no migrations required).
435
- */
436
- export async function createInMemoryAdapter(
437
- config: InMemoryAdapterConfig,
438
- schemas: SchemaConfig[],
439
- ): Promise<AdapterFactoryResult<InMemoryAdapterConfig>> {
440
- const adapter = new InMemoryAdapter(config.options);
441
-
442
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
443
- const ormMap = new Map<string | null, SimpleQueryInterface<any, any>>();
444
- for (const { schema, namespace } of schemas) {
445
- const orm = adapter.createQueryEngine(schema, namespace);
446
- ormMap.set(namespace, orm);
447
- }
448
-
449
- const resetDatabase = async () => {
450
- await adapter.reset();
451
- };
452
-
453
- const cleanup = async () => {
454
- await adapter.close();
455
- };
456
-
457
- const commonMethods = createCommonTestContextMethods(ormMap);
458
-
459
- return {
460
- testContext: {
461
- get adapter() {
462
- return adapter;
463
- },
464
- ...commonMethods,
465
- resetDatabase,
466
- cleanup,
467
- },
468
- get adapter() {
469
- return adapter;
470
- },
471
- };
472
- }
473
-
474
- /**
475
- * Create ModelChecker adapter (wraps the in-memory adapter).
476
- */
477
- export async function createModelCheckerAdapter(
478
- config: ModelCheckerAdapterConfig,
479
- schemas: SchemaConfig[],
480
- ): Promise<AdapterFactoryResult<ModelCheckerAdapterConfig>> {
481
- const baseAdapter = new InMemoryAdapter(config.options);
482
- const adapter = new ModelCheckerAdapter(baseAdapter);
483
-
484
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
485
- const ormMap = new Map<string | null, SimpleQueryInterface<any, any>>();
486
- for (const { schema, namespace } of schemas) {
487
- const orm = adapter.createQueryEngine(schema, namespace);
488
- ormMap.set(namespace, orm);
489
- }
490
-
491
- const resetDatabase = async () => {
492
- await baseAdapter.reset();
493
- };
494
-
495
- const cleanup = async () => {
496
- await adapter.close();
497
- };
498
-
499
- const commonMethods = createCommonTestContextMethods(ormMap);
500
-
501
- return {
502
- testContext: {
503
- get adapter() {
504
- return adapter;
505
- },
506
- ...commonMethods,
507
- resetDatabase,
508
- cleanup,
509
- },
510
- get adapter() {
511
- return adapter;
512
- },
513
- };
514
- }
515
-
516
- /**
517
- * Create adapter based on configuration
518
- * Supports multiple schemas with separate namespaces
519
- */
520
76
  export async function createAdapter<T extends SupportedAdapter>(
521
77
  adapterConfig: T,
522
78
  schemas: SchemaConfig[],
523
79
  ): Promise<AdapterFactoryResult<T>> {
524
80
  if (adapterConfig.type === "kysely-sqlite") {
81
+ const { createKyselySqliteAdapter } = await import("./test-adapters/kysely-sqlite");
525
82
  return createKyselySqliteAdapter(adapterConfig, schemas) as Promise<AdapterFactoryResult<T>>;
526
- } else if (adapterConfig.type === "kysely-pglite") {
83
+ }
84
+
85
+ if (adapterConfig.type === "kysely-pglite") {
86
+ const { createKyselyPgliteAdapter } = await import("./test-adapters/kysely-pglite");
527
87
  return createKyselyPgliteAdapter(adapterConfig, schemas) as Promise<AdapterFactoryResult<T>>;
528
- } else if (adapterConfig.type === "drizzle-pglite") {
88
+ }
89
+
90
+ if (adapterConfig.type === "drizzle-pglite") {
91
+ const { createDrizzlePgliteAdapter } = await import("./test-adapters/drizzle-pglite");
529
92
  return createDrizzlePgliteAdapter(adapterConfig, schemas) as Promise<AdapterFactoryResult<T>>;
530
- } else if (adapterConfig.type === "in-memory") {
93
+ }
94
+
95
+ if (adapterConfig.type === "in-memory") {
96
+ const { createInMemoryAdapter } = await import("./test-adapters/in-memory");
531
97
  return createInMemoryAdapter(adapterConfig, schemas) as Promise<AdapterFactoryResult<T>>;
532
- } else if (adapterConfig.type === "model-checker") {
98
+ }
99
+
100
+ if (adapterConfig.type === "model-checker") {
101
+ const { createModelCheckerAdapter } = await import("./test-adapters/model-checker");
533
102
  return createModelCheckerAdapter(adapterConfig, schemas) as Promise<AdapterFactoryResult<T>>;
534
103
  }
535
104