@fragno-dev/test 1.0.2 → 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 (63) hide show
  1. package/.turbo/turbo-build.log +41 -15
  2. package/CHANGELOG.md +112 -0
  3. package/dist/adapters.d.ts +20 -5
  4. package/dist/adapters.d.ts.map +1 -1
  5. package/dist/adapters.js +20 -210
  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 +236 -57
  10. package/dist/db-test.js.map +1 -1
  11. package/dist/durable-hooks.d.ts +11 -0
  12. package/dist/durable-hooks.d.ts.map +1 -0
  13. package/dist/durable-hooks.js +17 -0
  14. package/dist/durable-hooks.js.map +1 -0
  15. package/dist/index.d.ts +9 -5
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +6 -2
  18. package/dist/index.js.map +1 -1
  19. package/dist/model-checker-actors.d.ts +41 -0
  20. package/dist/model-checker-actors.d.ts.map +1 -0
  21. package/dist/model-checker-actors.js +406 -0
  22. package/dist/model-checker-actors.js.map +1 -0
  23. package/dist/model-checker-adapter.d.ts +32 -0
  24. package/dist/model-checker-adapter.d.ts.map +1 -0
  25. package/dist/model-checker-adapter.js +109 -0
  26. package/dist/model-checker-adapter.js.map +1 -0
  27. package/dist/model-checker.d.ts +128 -0
  28. package/dist/model-checker.d.ts.map +1 -0
  29. package/dist/model-checker.js +443 -0
  30. package/dist/model-checker.js.map +1 -0
  31. package/dist/test-adapters/drizzle-pglite.js +116 -0
  32. package/dist/test-adapters/drizzle-pglite.js.map +1 -0
  33. package/dist/test-adapters/in-memory.js +39 -0
  34. package/dist/test-adapters/in-memory.js.map +1 -0
  35. package/dist/test-adapters/kysely-pglite.js +105 -0
  36. package/dist/test-adapters/kysely-pglite.js.map +1 -0
  37. package/dist/test-adapters/kysely-sqlite.js +87 -0
  38. package/dist/test-adapters/kysely-sqlite.js.map +1 -0
  39. package/dist/test-adapters/model-checker.js +41 -0
  40. package/dist/test-adapters/model-checker.js.map +1 -0
  41. package/dist/tsconfig.tsbuildinfo +1 -0
  42. package/package.json +34 -34
  43. package/src/adapter-conformance.test.ts +324 -0
  44. package/src/adapters.ts +52 -320
  45. package/src/db-roundtrip-guard.test.ts +206 -0
  46. package/src/db-test.test.ts +133 -79
  47. package/src/db-test.ts +583 -99
  48. package/src/durable-hooks.test.ts +58 -0
  49. package/src/durable-hooks.ts +28 -0
  50. package/src/index.test.ts +250 -89
  51. package/src/index.ts +45 -6
  52. package/src/model-checker-actors.test.ts +81 -0
  53. package/src/model-checker-actors.ts +643 -0
  54. package/src/model-checker-adapter.ts +201 -0
  55. package/src/model-checker.test.ts +402 -0
  56. package/src/model-checker.ts +800 -0
  57. package/src/test-adapters/drizzle-pglite.ts +162 -0
  58. package/src/test-adapters/in-memory.ts +56 -0
  59. package/src/test-adapters/kysely-pglite.ts +151 -0
  60. package/src/test-adapters/kysely-sqlite.ts +119 -0
  61. package/src/test-adapters/model-checker.ts +58 -0
  62. package/tsconfig.json +1 -1
  63. package/vitest.config.ts +1 -0
@@ -1,5 +1,5 @@
1
1
 
2
- > @fragno-dev/test@1.0.2 build /home/runner/work/fragno/fragno/packages/fragno-test
2
+ > @fragno-dev/test@2.0.2 build /home/runner/work/fragno/fragno/packages/fragno-test
3
3
  > tsdown
4
4
 
5
5
  ℹ tsdown v0.15.12 powered by rolldown v1.0.0-beta.45
@@ -7,17 +7,43 @@
7
7
  ℹ entry: src/index.ts
8
8
  ℹ tsconfig: tsconfig.json
9
9
  ℹ Build start
10
- ℹ dist/index.js  0.71 kB │ gzip: 0.40 kB
11
- ℹ dist/db-test.js.map 24.19 kB │ gzip: 5.91 kB
12
- ℹ dist/adapters.js.map 16.98 kB │ gzip: 3.34 kB
13
- ℹ dist/adapters.js  7.53 kB │ gzip: 1.45 kB
14
- ℹ dist/db-test.js  7.43 kB │ gzip: 2.18 kB
15
- ℹ dist/db-test.d.ts.map  3.19 kB │ gzip: 1.47 kB
16
- ℹ dist/index.js.map  2.46 kB │ gzip: 0.96 kB
17
- ℹ dist/index.d.ts.map  0.55 kB │ gzip: 0.31 kB
18
- ℹ dist/adapters.d.ts.map  0.42 kB │ gzip: 0.27 kB
19
- ℹ dist/index.d.ts  1.81 kB │ gzip: 0.68 kB
20
- ℹ dist/db-test.d.ts  6.68 kB │ gzip: 1.80 kB
21
- ℹ dist/adapters.d.ts  0.96 kB │ gzip: 0.38 kB
22
- ℹ 12 files, total: 72.92 kB
23
- ✔ Build complete in 13301ms
10
+ ℹ dist/index.js  1.18 kB │ gzip: 0.53 kB
11
+ ℹ dist/db-test.js.map 44.78 kB │ gzip: 9.05 kB
12
+ ℹ dist/model-checker.js.map 33.95 kB │ gzip: 8.30 kB
13
+ ℹ dist/model-checker-actors.js.map 28.86 kB │ gzip: 7.07 kB
14
+ ℹ dist/model-checker.js 14.08 kB │ gzip: 3.89 kB
15
+ ℹ dist/db-test.js 13.77 kB │ gzip: 3.67 kB
16
+ ℹ dist/model-checker-actors.js 12.86 kB │ gzip: 3.32 kB
17
+ ℹ dist/model-checker-adapter.js.map  9.08 kB │ gzip: 2.64 kB
18
+ ℹ dist/test-adapters/drizzle-pglite.js.map  8.22 kB │ gzip: 2.69 kB
19
+ ℹ dist/test-adapters/kysely-pglite.js.map  7.28 kB │ gzip: 2.46 kB
20
+ ℹ dist/db-test.d.ts.map  5.84 kB │ gzip: 2.38 kB
21
+ ℹ dist/test-adapters/kysely-sqlite.js.map  5.72 kB │ gzip: 1.99 kB
22
+ ℹ dist/model-checker.d.ts.map  4.84 kB │ gzip: 1.89 kB
23
+ ℹ dist/adapters.js.map  4.41 kB │ gzip: 1.12 kB
24
+ ℹ dist/test-adapters/drizzle-pglite.js  4.39 kB │ gzip: 1.47 kB
25
+ ℹ dist/model-checker-adapter.js  3.98 kB │ gzip: 1.18 kB
26
+ ℹ dist/test-adapters/kysely-pglite.js  3.81 kB │ gzip: 1.31 kB
27
+ ℹ dist/index.js.map  3.70 kB │ gzip: 1.24 kB
28
+ ℹ dist/test-adapters/kysely-sqlite.js  2.90 kB │ gzip: 1.05 kB
29
+ ℹ dist/test-adapters/model-checker.js.map  2.61 kB │ gzip: 1.08 kB
30
+ ℹ dist/test-adapters/in-memory.js.map  2.42 kB │ gzip: 1.01 kB
31
+ ℹ dist/model-checker-actors.d.ts.map  1.58 kB │ gzip: 0.71 kB
32
+ ℹ dist/durable-hooks.js.map  1.23 kB │ gzip: 0.58 kB
33
+ ℹ dist/adapters.js  1.22 kB │ gzip: 0.35 kB
34
+ ℹ dist/test-adapters/model-checker.js  1.18 kB │ gzip: 0.54 kB
35
+ ℹ dist/model-checker-adapter.d.ts.map  1.07 kB │ gzip: 0.53 kB
36
+ ℹ dist/test-adapters/in-memory.js  1.03 kB │ gzip: 0.49 kB
37
+ ℹ dist/adapters.d.ts.map  0.71 kB │ gzip: 0.39 kB
38
+ ℹ dist/index.d.ts.map  0.58 kB │ gzip: 0.33 kB
39
+ ℹ dist/durable-hooks.js  0.50 kB │ gzip: 0.29 kB
40
+ ℹ dist/durable-hooks.d.ts.map  0.29 kB │ gzip: 0.21 kB
41
+ ℹ dist/index.d.ts  3.57 kB │ gzip: 1.04 kB
42
+ ℹ dist/db-test.d.ts 12.33 kB │ gzip: 2.32 kB
43
+ ℹ dist/model-checker.d.ts  5.67 kB │ gzip: 1.38 kB
44
+ ℹ dist/model-checker-actors.d.ts  2.04 kB │ gzip: 0.63 kB
45
+ ℹ dist/model-checker-adapter.d.ts  1.79 kB │ gzip: 0.68 kB
46
+ ℹ dist/adapters.d.ts  1.62 kB │ gzip: 0.50 kB
47
+ ℹ dist/durable-hooks.d.ts  0.49 kB │ gzip: 0.26 kB
48
+ ℹ 38 files, total: 255.60 kB
49
+ ✔ Build complete in 13491ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,117 @@
1
1
  # @fragno-dev/test
2
2
 
3
+ ## 2.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [0020e39]
8
+ - @fragno-dev/core@0.2.2
9
+ - @fragno-dev/db@0.4.1
10
+
11
+ ## 2.0.1
12
+
13
+ ### Patch Changes
14
+
15
+ - 4d141f8: fix: remove development exports from published packages
16
+ - 01fc2cb: fix: scope db roundtrip guard to route handlers and enable by default in tests
17
+ - c179eb6: feat: add singlePass mode to drainDurableHooks for one-pass processing
18
+ - 0cda225: feat: allow db tests to add fragment factories and instances
19
+ - Updated dependencies [8a96998]
20
+ - Updated dependencies [3e2ff94]
21
+ - Updated dependencies [f34d7d7]
22
+ - Updated dependencies [4d141f8]
23
+ - Updated dependencies [c8841b5]
24
+ - Updated dependencies [83f6223]
25
+ - Updated dependencies [ae54a60]
26
+ - Updated dependencies [7dd7055]
27
+ - Updated dependencies [e178bf4]
28
+ - Updated dependencies [d2f68ba]
29
+ - Updated dependencies [567c3b3]
30
+ - Updated dependencies [75191db]
31
+ - Updated dependencies [d395ad2]
32
+ - Updated dependencies [75407f3]
33
+ - Updated dependencies [8a2da9d]
34
+ - Updated dependencies [bfdd4b1]
35
+ - Updated dependencies [3ffa711]
36
+ - Updated dependencies [c2c3229]
37
+ - Updated dependencies [e559425]
38
+ - Updated dependencies [fc5c256]
39
+ - Updated dependencies [93fa469]
40
+ - Updated dependencies [14e00b1]
41
+ - Updated dependencies [f33286c]
42
+ - Updated dependencies [b3ad7eb]
43
+ - Updated dependencies [95cdf95]
44
+ - Updated dependencies [eabdb9c]
45
+ - Updated dependencies [9eeba53]
46
+ - Updated dependencies [49a9f4f]
47
+ - Updated dependencies [dcba383]
48
+ - Updated dependencies [c895c07]
49
+ - Updated dependencies [ed4b4a0]
50
+ - Updated dependencies [1102ce0]
51
+ - Updated dependencies [2ae432c]
52
+ - Updated dependencies [ad2ef56]
53
+ - Updated dependencies [9f87189]
54
+ - Updated dependencies [0f9b7ef]
55
+ - Updated dependencies [6d043ea]
56
+ - Updated dependencies [fe55a13]
57
+ - Updated dependencies [01fc2cb]
58
+ - Updated dependencies [f4aedad]
59
+ - Updated dependencies [f042c9d]
60
+ - Updated dependencies [0176aa8]
61
+ - Updated dependencies [00f2631]
62
+ - Updated dependencies [c13c1c1]
63
+ - Updated dependencies [0a6c8da]
64
+ - Updated dependencies [7a40517]
65
+ - Updated dependencies [91a2ac0]
66
+ - Updated dependencies [7bda0b2]
67
+ - Updated dependencies [c115600]
68
+ - Updated dependencies [b84a3d0]
69
+ - @fragno-dev/db@0.4.0
70
+ - @fragno-dev/core@0.2.1
71
+
72
+ ## 2.0.0
73
+
74
+ ### Patch Changes
75
+
76
+ - 3e07799: fix: allow durable hook processing to bypass wrapper adapters and widen drain helpers
77
+ - 15e3263: feat(db): require schema names and support namespace-aware SQL naming
78
+ - a79e90d: feat: add trace recording support to model checker runs
79
+ - 5cef16e: feat(db,test): add SQL outbox support and adapter testing configuration.
80
+ - Updated dependencies [f569301]
81
+ - Updated dependencies [dbbbf60]
82
+ - Updated dependencies [3e07799]
83
+ - Updated dependencies [20a98f8]
84
+ - Updated dependencies [1902f30]
85
+ - Updated dependencies [15e3263]
86
+ - Updated dependencies [208cb8e]
87
+ - Updated dependencies [33f671b]
88
+ - Updated dependencies [fc803fc]
89
+ - Updated dependencies [0628c1f]
90
+ - Updated dependencies [7e1eb47]
91
+ - Updated dependencies [301e2f8]
92
+ - Updated dependencies [5f6f90e]
93
+ - Updated dependencies [1dc4e7f]
94
+ - Updated dependencies [2eafef4]
95
+ - Updated dependencies [3c9fbac]
96
+ - Updated dependencies [a5ead11]
97
+ - Updated dependencies [7d7b2b9]
98
+ - Updated dependencies [c4d4cc6]
99
+ - Updated dependencies [d4baad3]
100
+ - Updated dependencies [548bf37]
101
+ - Updated dependencies [a79e90d]
102
+ - Updated dependencies [3041732]
103
+ - Updated dependencies [7e179d1]
104
+ - Updated dependencies [0013fa6]
105
+ - Updated dependencies [7c60341]
106
+ - Updated dependencies [afb06a4]
107
+ - Updated dependencies [53e5f97]
108
+ - Updated dependencies [8e9b6cd]
109
+ - Updated dependencies [c5fd7b3]
110
+ - Updated dependencies [69b9a79]
111
+ - Updated dependencies [5cef16e]
112
+ - @fragno-dev/core@0.2.0
113
+ - @fragno-dev/db@0.3.0
114
+
3
115
  ## 1.0.2
4
116
 
5
117
  ### Patch Changes
@@ -1,27 +1,42 @@
1
1
  import "./index.js";
2
- import { Kysely } from "kysely";
3
- import { drizzle } from "drizzle-orm/pglite";
4
2
  import { AnySchema } from "@fragno-dev/db/schema";
3
+ import { DatabaseAdapter } from "@fragno-dev/db/adapters";
4
+ import { UnitOfWorkConfig } from "@fragno-dev/db/adapters/sql";
5
+ import { drizzle } from "drizzle-orm/pglite";
6
+ import { InMemoryAdapterOptions } from "@fragno-dev/db/adapters/in-memory";
7
+ import { Kysely } from "kysely";
5
8
  import { SimpleQueryInterface } from "@fragno-dev/db/query";
6
9
 
7
10
  //#region src/adapters.d.ts
8
11
  interface KyselySqliteAdapter {
9
12
  type: "kysely-sqlite";
13
+ uowConfig?: UnitOfWorkConfig;
10
14
  }
11
15
  interface KyselyPgliteAdapter {
12
16
  type: "kysely-pglite";
13
17
  databasePath?: string;
18
+ uowConfig?: UnitOfWorkConfig;
14
19
  }
15
20
  interface DrizzlePgliteAdapter {
16
21
  type: "drizzle-pglite";
17
22
  databasePath?: string;
23
+ uowConfig?: UnitOfWorkConfig;
24
+ }
25
+ interface InMemoryAdapterConfig {
26
+ type: "in-memory";
27
+ options?: InMemoryAdapterOptions;
28
+ uowConfig?: UnitOfWorkConfig;
29
+ }
30
+ interface ModelCheckerAdapterConfig {
31
+ type: "model-checker";
32
+ options?: InMemoryAdapterOptions;
18
33
  }
19
- type SupportedAdapter = KyselySqliteAdapter | KyselyPgliteAdapter | DrizzlePgliteAdapter;
34
+ type SupportedAdapter = KyselySqliteAdapter | KyselyPgliteAdapter | DrizzlePgliteAdapter | InMemoryAdapterConfig | ModelCheckerAdapterConfig;
20
35
  type AdapterContext<T extends SupportedAdapter> = T extends KyselySqliteAdapter | KyselyPgliteAdapter ? {
21
36
  readonly kysely: Kysely<any>;
22
37
  } : T extends DrizzlePgliteAdapter ? {
23
38
  readonly drizzle: ReturnType<typeof drizzle<any>>;
24
- } : never;
39
+ } : T extends InMemoryAdapterConfig | ModelCheckerAdapterConfig ? {} : never;
25
40
  //#endregion
26
- export { AdapterContext, DrizzlePgliteAdapter, KyselyPgliteAdapter, KyselySqliteAdapter, SupportedAdapter };
41
+ export { AdapterContext, DrizzlePgliteAdapter, InMemoryAdapterConfig, KyselyPgliteAdapter, KyselySqliteAdapter, SupportedAdapter };
27
42
  //# sourceMappingURL=adapters.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"adapters.d.ts","names":[],"sources":["../src/adapters.ts"],"sourcesContent":[],"mappings":";;;;;;;UAkBiB,mBAAA;EAAA,IAAA,EAAA,eAAA;AAIjB;AAKiB,UALA,mBAAA,CAKoB;EAKzB,IAAA,EAAA,eAAgB;EAAG,YAAA,CAAA,EAAA,MAAA;;AAA4C,UAL1D,oBAAA,CAK0D;EAAoB,IAAA,EAAA,gBAAA;EAenF,YAAA,CAAA,EAAA,MAAc;;AAA+B,KAf7C,gBAAA,GAAmB,mBAe0B,GAfJ,mBAeI,GAfkB,oBAelB;KAA7C,yBAAyB,oBAAoB,UACrD,sBACA;mBAEmB;IAEnB,UAAU;oBAEY,kBAAkB"}
1
+ {"version":3,"file":"adapters.d.ts","names":[],"sources":["../src/adapters.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;UAUiB,mBAAA;;EAAA,SAAA,CAAA,EAEH,gBAFsB;AAKpC;AAMiB,UANA,mBAAA,CAMoB;EAMpB,IAAA,EAAA,eAAA;EAMA,YAAA,CAAA,EAAA,MAAA;EAKL,SAAA,CAAA,EApBE,gBAoBc;;AAExB,UAnBa,oBAAA,CAmBb;EACA,IAAA,EAAA,gBAAA;EACA,YAAA,CAAA,EAAA,MAAA;EACA,SAAA,CAAA,EAnBU,gBAmBV;;AAYQ,UA5BK,qBAAA,CA4BS;EAAW,IAAA,EAAA,WAAA;EAAoB,OAAA,CAAA,EA1B7C,sBA0B6C;EACrD,SAAA,CAAA,EA1BU,gBA0BV;;AAGmB,UA1BN,yBAAA,CA0BM;EAEnB,IAAA,EAAA,eAAA;EAAU,OAAA,CAAA,EA1BF,sBA0BE;;AAEY,KAzBd,gBAAA,GACR,mBAwBsB,GAvBtB,mBAuBsB,GAtBtB,oBAsBsB,GArBtB,qBAqBsB,GApBtB,yBAoBsB;KARd,yBAAyB,oBAAoB,UACrD,sBACA;mBAEmB;IAEnB,UAAU;oBAEY,kBAAkB;IAEtC,UAAU,wBAAwB"}
package/dist/adapters.js CHANGED
@@ -1,215 +1,25 @@
1
- import { createCommonTestContextMethods } from "./index.js";
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 { KyselyAdapter } from "@fragno-dev/db/adapters/kysely";
8
- import { DrizzleAdapter } from "@fragno-dev/db/adapters/drizzle";
9
- import { rm } from "node:fs/promises";
10
- import { existsSync } from "node:fs";
11
- import { PGLiteDriverConfig, SQLocalDriverConfig } from "@fragno-dev/db/drivers";
12
- import { internalFragmentDef } from "@fragno-dev/db";
13
-
14
1
  //#region src/adapters.ts
15
- /**
16
- * Create Kysely + SQLite adapter using SQLocalKysely (always in-memory)
17
- * Supports multiple schemas with separate namespaces
18
- */
19
- async function createKyselySqliteAdapter(_config, schemas) {
20
- const createDatabase = async () => {
21
- const { dialect } = new SQLocalKysely(":memory:");
22
- const kysely$1 = new Kysely({ dialect });
23
- const adapter$1 = new KyselyAdapter({
24
- dialect,
25
- driverConfig: new SQLocalDriverConfig()
26
- });
27
- const ormMap$1 = /* @__PURE__ */ new Map();
28
- for (const { schema, namespace, migrateToVersion } of schemas) {
29
- const preparedMigrations = adapter$1.prepareMigrations(schema, namespace);
30
- if (migrateToVersion !== void 0) await preparedMigrations.execute(0, migrateToVersion, { updateVersionInMigration: false });
31
- else await preparedMigrations.execute(0, schema.version, { updateVersionInMigration: false });
32
- const orm = adapter$1.createQueryEngine(schema, namespace);
33
- ormMap$1.set(namespace, orm);
34
- }
35
- return {
36
- kysely: kysely$1,
37
- adapter: adapter$1,
38
- ormMap: ormMap$1
39
- };
40
- };
41
- let { kysely, adapter, ormMap } = await createDatabase();
42
- const resetDatabase = async () => {
43
- for (const { schema, namespace } of schemas) {
44
- const mapper = adapter.createTableNameMapper(namespace);
45
- for (const tableName of Object.keys(schema.tables)) {
46
- const physicalTableName = mapper.toPhysical(tableName);
47
- await kysely.deleteFrom(physicalTableName).execute();
48
- }
49
- }
50
- };
51
- const cleanup = async () => {
52
- await kysely.destroy();
53
- };
54
- return {
55
- testContext: {
56
- get kysely() {
57
- return kysely;
58
- },
59
- get adapter() {
60
- return adapter;
61
- },
62
- ...createCommonTestContextMethods(ormMap),
63
- resetDatabase,
64
- cleanup
65
- },
66
- get adapter() {
67
- return adapter;
68
- }
69
- };
70
- }
71
- /**
72
- * Create Kysely + PGLite adapter using kysely-pglite
73
- * Supports multiple schemas with separate namespaces
74
- */
75
- async function createKyselyPgliteAdapter(config, schemas) {
76
- const databasePath = config.databasePath;
77
- const createDatabase = async () => {
78
- const kyselyPglite$1 = await KyselyPGlite.create(databasePath);
79
- const kysely$1 = new Kysely({ dialect: kyselyPglite$1.dialect });
80
- const adapter$1 = new KyselyAdapter({
81
- dialect: kyselyPglite$1.dialect,
82
- driverConfig: new PGLiteDriverConfig()
83
- });
84
- const ormMap$1 = /* @__PURE__ */ new Map();
85
- for (const { schema, namespace, migrateToVersion } of schemas) {
86
- const preparedMigrations = adapter$1.prepareMigrations(schema, namespace);
87
- if (migrateToVersion !== void 0) await preparedMigrations.execute(0, migrateToVersion, { updateVersionInMigration: false });
88
- else await preparedMigrations.execute(0, schema.version, { updateVersionInMigration: false });
89
- const orm = adapter$1.createQueryEngine(schema, namespace);
90
- ormMap$1.set(namespace, orm);
91
- }
92
- return {
93
- kysely: kysely$1,
94
- adapter: adapter$1,
95
- kyselyPglite: kyselyPglite$1,
96
- ormMap: ormMap$1
97
- };
98
- };
99
- const { kysely, adapter, kyselyPglite, ormMap } = await createDatabase();
100
- const resetDatabase = async () => {
101
- if (databasePath && databasePath !== ":memory:") throw new Error("resetDatabase is only supported for in-memory databases");
102
- for (const { schema, namespace } of schemas) {
103
- const mapper = adapter.createTableNameMapper(namespace);
104
- for (const tableName of Object.keys(schema.tables)) {
105
- const physicalTableName = mapper.toPhysical(tableName);
106
- await kysely.deleteFrom(physicalTableName).execute();
107
- }
108
- }
109
- };
110
- const cleanup = async () => {
111
- await kysely.destroy();
112
- try {
113
- await kyselyPglite.client.close();
114
- } catch {}
115
- if (databasePath && databasePath !== ":memory:" && existsSync(databasePath)) await rm(databasePath, {
116
- recursive: true,
117
- force: true
118
- });
119
- };
120
- return {
121
- testContext: {
122
- get kysely() {
123
- return kysely;
124
- },
125
- get adapter() {
126
- return adapter;
127
- },
128
- ...createCommonTestContextMethods(ormMap),
129
- resetDatabase,
130
- cleanup
131
- },
132
- get adapter() {
133
- return adapter;
134
- }
135
- };
136
- }
137
- /**
138
- * Create Drizzle + PGLite adapter using drizzle-orm/pglite
139
- * Supports multiple schemas with separate namespaces
140
- */
141
- async function createDrizzlePgliteAdapter(config, schemas) {
142
- const databasePath = config.databasePath;
143
- const createDatabase = async () => {
144
- const pglite = new PGlite(databasePath);
145
- const { dialect } = new KyselyPGlite(pglite);
146
- const adapter$1 = new DrizzleAdapter({
147
- dialect,
148
- driverConfig: new PGLiteDriverConfig()
149
- });
150
- const ormMap$1 = /* @__PURE__ */ new Map();
151
- const databaseDeps = internalFragmentDef.dependencies?.({
152
- config: {},
153
- options: { databaseAdapter: adapter$1 }
154
- });
155
- if (databaseDeps?.schema) await adapter$1.prepareMigrations(databaseDeps.schema, databaseDeps.namespace).executeWithDriver(adapter$1.driver, 0);
156
- for (const { schema, namespace, migrateToVersion } of schemas) {
157
- const preparedMigrations = adapter$1.prepareMigrations(schema, namespace);
158
- if (migrateToVersion !== void 0) await preparedMigrations.execute(0, migrateToVersion, { updateVersionInMigration: false });
159
- else await preparedMigrations.execute(0, schema.version, { updateVersionInMigration: false });
160
- const orm = adapter$1.createQueryEngine(schema, namespace);
161
- ormMap$1.set(namespace, orm);
162
- }
163
- return {
164
- drizzle: drizzle(pglite),
165
- adapter: adapter$1,
166
- pglite,
167
- ormMap: ormMap$1
168
- };
169
- };
170
- const { drizzle: drizzleDb, adapter, ormMap } = await createDatabase();
171
- const resetDatabase = async () => {
172
- if (databasePath && databasePath !== ":memory:") throw new Error("resetDatabase is only supported for in-memory databases");
173
- for (const { schema, namespace } of schemas) {
174
- const mapper = adapter.createTableNameMapper(namespace);
175
- for (const tableName of Object.keys(schema.tables)) {
176
- const physicalTableName = mapper.toPhysical(tableName);
177
- await drizzleDb.execute(`DELETE FROM "${physicalTableName}"`);
178
- }
179
- }
180
- };
181
- const cleanup = async () => {
182
- await adapter.close();
183
- if (databasePath && databasePath !== ":memory:" && existsSync(databasePath)) await rm(databasePath, {
184
- recursive: true,
185
- force: true
186
- });
187
- };
188
- return {
189
- testContext: {
190
- get drizzle() {
191
- return drizzleDb;
192
- },
193
- get adapter() {
194
- return adapter;
195
- },
196
- ...createCommonTestContextMethods(ormMap),
197
- resetDatabase,
198
- cleanup
199
- },
200
- get adapter() {
201
- return adapter;
202
- }
203
- };
204
- }
205
- /**
206
- * Create adapter based on configuration
207
- * Supports multiple schemas with separate namespaces
208
- */
209
2
  async function createAdapter(adapterConfig, schemas) {
210
- if (adapterConfig.type === "kysely-sqlite") return createKyselySqliteAdapter(adapterConfig, schemas);
211
- else if (adapterConfig.type === "kysely-pglite") return createKyselyPgliteAdapter(adapterConfig, schemas);
212
- else if (adapterConfig.type === "drizzle-pglite") return createDrizzlePgliteAdapter(adapterConfig, schemas);
3
+ if (adapterConfig.type === "kysely-sqlite") {
4
+ const { createKyselySqliteAdapter } = await import("./test-adapters/kysely-sqlite.js");
5
+ return createKyselySqliteAdapter(adapterConfig, schemas);
6
+ }
7
+ if (adapterConfig.type === "kysely-pglite") {
8
+ const { createKyselyPgliteAdapter } = await import("./test-adapters/kysely-pglite.js");
9
+ return createKyselyPgliteAdapter(adapterConfig, schemas);
10
+ }
11
+ if (adapterConfig.type === "drizzle-pglite") {
12
+ const { createDrizzlePgliteAdapter } = await import("./test-adapters/drizzle-pglite.js");
13
+ return createDrizzlePgliteAdapter(adapterConfig, schemas);
14
+ }
15
+ if (adapterConfig.type === "in-memory") {
16
+ const { createInMemoryAdapter } = await import("./test-adapters/in-memory.js");
17
+ return createInMemoryAdapter(adapterConfig, schemas);
18
+ }
19
+ if (adapterConfig.type === "model-checker") {
20
+ const { createModelCheckerAdapter } = await import("./test-adapters/model-checker.js");
21
+ return createModelCheckerAdapter(adapterConfig, schemas);
22
+ }
213
23
  throw new Error(`Unsupported adapter type: ${adapterConfig.type}`);
214
24
  }
215
25
 
@@ -1 +1 @@
1
- {"version":3,"file":"adapters.js","names":["kysely","adapter","ormMap","kyselyPglite"],"sources":["../src/adapters.ts"],"sourcesContent":["import { Kysely } from \"kysely\";\nimport { SQLocalKysely } from \"sqlocal/kysely\";\nimport { KyselyPGlite } from \"kysely-pglite\";\nimport { drizzle } from \"drizzle-orm/pglite\";\nimport { PGlite } from \"@electric-sql/pglite\";\nimport { KyselyAdapter } from \"@fragno-dev/db/adapters/kysely\";\nimport { DrizzleAdapter } from \"@fragno-dev/db/adapters/drizzle\";\nimport type { AnySchema } from \"@fragno-dev/db/schema\";\nimport type { DatabaseAdapter } from \"@fragno-dev/db/adapters\";\nimport { rm } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport type { BaseTestContext } from \".\";\nimport { createCommonTestContextMethods } from \".\";\nimport { PGLiteDriverConfig, SQLocalDriverConfig } from \"@fragno-dev/db/drivers\";\nimport { internalFragmentDef } from \"@fragno-dev/db\";\nimport type { SimpleQueryInterface } from \"@fragno-dev/db/query\";\n\n// Adapter configuration types\nexport interface KyselySqliteAdapter {\n type: \"kysely-sqlite\";\n}\n\nexport interface KyselyPgliteAdapter {\n type: \"kysely-pglite\";\n databasePath?: string;\n}\n\nexport interface DrizzlePgliteAdapter {\n type: \"drizzle-pglite\";\n databasePath?: string;\n}\n\nexport type SupportedAdapter = KyselySqliteAdapter | KyselyPgliteAdapter | DrizzlePgliteAdapter;\n\n// Schema configuration for multi-schema adapters\nexport interface SchemaConfig {\n schema: AnySchema;\n namespace: string;\n migrateToVersion?: number;\n}\n\n// Internal test context extends BaseTestContext with getOrm (not exposed publicly)\ninterface InternalTestContext extends BaseTestContext {\n getOrm: <TSchema extends AnySchema>(namespace: string) => SimpleQueryInterface<TSchema>;\n}\n\n// Conditional return types based on adapter (adapter-specific properties only)\nexport type AdapterContext<T extends SupportedAdapter> = T extends\n | KyselySqliteAdapter\n | KyselyPgliteAdapter\n ? {\n readonly kysely: Kysely<any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n }\n : T extends DrizzlePgliteAdapter\n ? {\n readonly drizzle: ReturnType<typeof drizzle<any>>; // eslint-disable-line @typescript-eslint/no-explicit-any\n }\n : never;\n\n// Factory function return type\ninterface AdapterFactoryResult<T extends SupportedAdapter> {\n testContext: InternalTestContext & AdapterContext<T>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n adapter: DatabaseAdapter<any>;\n}\n\n/**\n * Create Kysely + SQLite adapter using SQLocalKysely (always in-memory)\n * Supports multiple schemas with separate namespaces\n */\nexport async function createKyselySqliteAdapter(\n _config: KyselySqliteAdapter,\n schemas: SchemaConfig[],\n): Promise<AdapterFactoryResult<KyselySqliteAdapter>> {\n // Helper to create a new database instance and run migrations for all schemas\n const createDatabase = async () => {\n // Create SQLocalKysely instance (always in-memory for tests)\n const { dialect } = new SQLocalKysely(\":memory:\");\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const kysely = new Kysely<any>({\n dialect,\n });\n\n // Create KyselyAdapter\n const adapter = new KyselyAdapter({\n dialect,\n driverConfig: new SQLocalDriverConfig(),\n });\n\n // Run migrations for all schemas in order\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const ormMap = new Map<string, SimpleQueryInterface<any, any>>();\n\n for (const { schema, namespace, migrateToVersion } of schemas) {\n // Run migrations\n const preparedMigrations = adapter.prepareMigrations(schema, namespace);\n if (migrateToVersion !== undefined) {\n await preparedMigrations.execute(0, migrateToVersion, { updateVersionInMigration: false });\n } else {\n await preparedMigrations.execute(0, schema.version, { updateVersionInMigration: false });\n }\n\n // Create ORM instance and store in map\n const orm = adapter.createQueryEngine(schema, namespace);\n ormMap.set(namespace, orm);\n }\n\n return { kysely, adapter, ormMap };\n };\n\n // Create initial database\n let { kysely, adapter, ormMap } = await createDatabase();\n\n // Reset database function - truncates all tables (only supported for in-memory databases)\n const resetDatabase = async () => {\n // For SQLite, truncate all tables by deleting rows\n for (const { schema, namespace } of schemas) {\n const mapper = adapter.createTableNameMapper(namespace);\n for (const tableName of Object.keys(schema.tables)) {\n const physicalTableName = mapper.toPhysical(tableName);\n await kysely.deleteFrom(physicalTableName).execute();\n }\n }\n };\n\n // Cleanup function - closes connections (no files to delete for in-memory)\n const cleanup = async () => {\n await kysely.destroy();\n };\n\n const commonMethods = createCommonTestContextMethods(ormMap);\n\n return {\n testContext: {\n get kysely() {\n return kysely;\n },\n get adapter() {\n return adapter;\n },\n ...commonMethods,\n resetDatabase,\n cleanup,\n },\n get adapter() {\n return adapter;\n },\n };\n}\n\n/**\n * Create Kysely + PGLite adapter using kysely-pglite\n * Supports multiple schemas with separate namespaces\n */\nexport async function createKyselyPgliteAdapter(\n config: KyselyPgliteAdapter,\n schemas: SchemaConfig[],\n): Promise<AdapterFactoryResult<KyselyPgliteAdapter>> {\n const databasePath = config.databasePath;\n\n // Helper to create a new database instance and run migrations for all schemas\n const createDatabase = async () => {\n // Create KyselyPGlite instance\n const kyselyPglite = await KyselyPGlite.create(databasePath);\n\n // Create Kysely instance with PGlite dialect\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const kysely = new Kysely<any>({\n dialect: kyselyPglite.dialect,\n });\n\n // Create KyselyAdapter\n const adapter = new KyselyAdapter({\n dialect: kyselyPglite.dialect,\n driverConfig: new PGLiteDriverConfig(),\n });\n\n // Run migrations for all schemas in order\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const ormMap = new Map<string, SimpleQueryInterface<any, any>>();\n\n for (const { schema, namespace, migrateToVersion } of schemas) {\n // Run migrations\n const preparedMigrations = adapter.prepareMigrations(schema, namespace);\n if (migrateToVersion !== undefined) {\n await preparedMigrations.execute(0, migrateToVersion, { updateVersionInMigration: false });\n } else {\n await preparedMigrations.execute(0, schema.version, { updateVersionInMigration: false });\n }\n\n // Create ORM instance and store in map\n const orm = adapter.createQueryEngine(schema, namespace);\n ormMap.set(namespace, orm);\n }\n\n return { kysely, adapter, kyselyPglite, ormMap };\n };\n\n // Create initial database\n const { kysely, adapter, kyselyPglite, ormMap } = await createDatabase();\n\n // Reset database function - truncates all tables (only supported for in-memory databases)\n const resetDatabase = async () => {\n if (databasePath && databasePath !== \":memory:\") {\n throw new Error(\"resetDatabase is only supported for in-memory databases\");\n }\n\n // Truncate all tables\n for (const { schema, namespace } of schemas) {\n const mapper = adapter.createTableNameMapper(namespace);\n for (const tableName of Object.keys(schema.tables)) {\n const physicalTableName = mapper.toPhysical(tableName);\n await kysely.deleteFrom(physicalTableName).execute();\n }\n }\n };\n\n // Cleanup function - closes connections and deletes database directory\n const cleanup = async () => {\n await kysely.destroy();\n\n try {\n await kyselyPglite.client.close();\n } catch {\n // Ignore if already closed\n }\n\n // Delete the database directory if it exists and is a file path\n if (databasePath && databasePath !== \":memory:\" && existsSync(databasePath)) {\n await rm(databasePath, { recursive: true, force: true });\n }\n };\n\n const commonMethods = createCommonTestContextMethods(ormMap);\n\n return {\n testContext: {\n get kysely() {\n return kysely;\n },\n get adapter() {\n return adapter;\n },\n ...commonMethods,\n resetDatabase,\n cleanup,\n },\n get adapter() {\n return adapter;\n },\n };\n}\n\n/**\n * Create Drizzle + PGLite adapter using drizzle-orm/pglite\n * Supports multiple schemas with separate namespaces\n */\nexport async function createDrizzlePgliteAdapter(\n config: DrizzlePgliteAdapter,\n schemas: SchemaConfig[],\n): Promise<AdapterFactoryResult<DrizzlePgliteAdapter>> {\n const databasePath = config.databasePath;\n\n // Helper to create a new database instance and run migrations for all schemas\n const createDatabase = async () => {\n const pglite = new PGlite(databasePath);\n\n const { dialect } = new KyselyPGlite(pglite);\n\n const adapter = new DrizzleAdapter({\n dialect,\n driverConfig: new PGLiteDriverConfig(),\n });\n\n // Run migrations for all schemas\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const ormMap = new Map<string, SimpleQueryInterface<any, any>>();\n\n const databaseDeps = internalFragmentDef.dependencies?.({\n config: {},\n options: { databaseAdapter: adapter },\n });\n if (databaseDeps?.schema) {\n const migrations = adapter.prepareMigrations(databaseDeps.schema, databaseDeps.namespace);\n await migrations.executeWithDriver(adapter.driver, 0);\n }\n\n for (const { schema, namespace, migrateToVersion } of schemas) {\n const preparedMigrations = adapter.prepareMigrations(schema, namespace);\n if (migrateToVersion !== undefined) {\n await preparedMigrations.execute(0, migrateToVersion, { updateVersionInMigration: false });\n } else {\n await preparedMigrations.execute(0, schema.version, { updateVersionInMigration: false });\n }\n\n // Create ORM instance and store in map\n const orm = adapter.createQueryEngine(schema, namespace);\n ormMap.set(namespace, orm);\n }\n\n // Create Drizzle instance for backward compatibility (if needed)\n const db = drizzle(pglite) as any; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n return { drizzle: db, adapter, pglite, ormMap };\n };\n\n // Create initial database\n const { drizzle: drizzleDb, adapter, ormMap } = await createDatabase();\n\n // Reset database function - truncates all tables (only supported for in-memory databases)\n const resetDatabase = async () => {\n if (databasePath && databasePath !== \":memory:\") {\n throw new Error(\"resetDatabase is only supported for in-memory databases\");\n }\n\n // Truncate all tables by deleting rows\n for (const { schema, namespace } of schemas) {\n const mapper = adapter.createTableNameMapper(namespace);\n for (const tableName of Object.keys(schema.tables)) {\n const physicalTableName = mapper.toPhysical(tableName);\n await drizzleDb.execute(`DELETE FROM \"${physicalTableName}\"`);\n }\n }\n };\n\n // Cleanup function - closes connections and deletes database directory\n const cleanup = async () => {\n // Close the adapter (which will handle closing the underlying database connection)\n await adapter.close();\n\n // Delete the database directory if it exists and is a file path\n if (databasePath && databasePath !== \":memory:\" && existsSync(databasePath)) {\n await rm(databasePath, { recursive: true, force: true });\n }\n };\n\n const commonMethods = createCommonTestContextMethods(ormMap);\n\n return {\n testContext: {\n get drizzle() {\n return drizzleDb;\n },\n get adapter() {\n return adapter;\n },\n ...commonMethods,\n resetDatabase,\n cleanup,\n },\n get adapter() {\n return adapter;\n },\n };\n}\n\n/**\n * Create adapter based on configuration\n * Supports multiple schemas with separate namespaces\n */\nexport async function createAdapter<T extends SupportedAdapter>(\n adapterConfig: T,\n schemas: SchemaConfig[],\n): Promise<AdapterFactoryResult<T>> {\n if (adapterConfig.type === \"kysely-sqlite\") {\n return createKyselySqliteAdapter(adapterConfig, schemas) as Promise<AdapterFactoryResult<T>>;\n } else if (adapterConfig.type === \"kysely-pglite\") {\n return createKyselyPgliteAdapter(adapterConfig, schemas) as Promise<AdapterFactoryResult<T>>;\n } else if (adapterConfig.type === \"drizzle-pglite\") {\n return createDrizzlePgliteAdapter(adapterConfig, schemas) as Promise<AdapterFactoryResult<T>>;\n }\n\n throw new Error(`Unsupported adapter type: ${(adapterConfig as SupportedAdapter).type}`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsEA,eAAsB,0BACpB,SACA,SACoD;CAEpD,MAAM,iBAAiB,YAAY;EAEjC,MAAM,EAAE,YAAY,IAAI,cAAc,WAAW;EAEjD,MAAMA,WAAS,IAAI,OAAY,EAC7B,SACD,CAAC;EAGF,MAAMC,YAAU,IAAI,cAAc;GAChC;GACA,cAAc,IAAI,qBAAqB;GACxC,CAAC;EAIF,MAAMC,2BAAS,IAAI,KAA6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;AAGrB,MAAI,gBAAgB,iBAAiB,cAAc,WAAW,aAAa,CACzE,OAAM,GAAG,cAAc;GAAE,WAAW;GAAM,OAAO;GAAM,CAAC;;AAM5D,QAAO;EACL,aAAa;GACX,IAAI,UAAU;AACZ,WAAO;;GAET,IAAI,UAAU;AACZ,WAAO;;GAET,GAVkB,+BAA+B,OAAO;GAWxD;GACA;GACD;EACD,IAAI,UAAU;AACZ,UAAO;;EAEV;;;;;;AAOH,eAAsB,cACpB,eACA,SACkC;AAClC,KAAI,cAAc,SAAS,gBACzB,QAAO,0BAA0B,eAAe,QAAQ;UAC/C,cAAc,SAAS,gBAChC,QAAO,0BAA0B,eAAe,QAAQ;UAC/C,cAAc,SAAS,iBAChC,QAAO,2BAA2B,eAAe,QAAQ;AAG3D,OAAM,IAAI,MAAM,6BAA8B,cAAmC,OAAO"}
1
+ {"version":3,"file":"adapters.js","names":[],"sources":["../src/adapters.ts"],"sourcesContent":["import type { DatabaseAdapter } from \"@fragno-dev/db/adapters\";\nimport type { InMemoryAdapterOptions } from \"@fragno-dev/db/adapters/in-memory\";\nimport type { UnitOfWorkConfig } from \"@fragno-dev/db/adapters/sql\";\nimport type { SimpleQueryInterface } from \"@fragno-dev/db/query\";\nimport type { AnySchema } from \"@fragno-dev/db/schema\";\nimport type { drizzle } from \"drizzle-orm/pglite\";\nimport type { Kysely } from \"kysely\";\n\nimport type { BaseTestContext } from \".\";\n\nexport interface KyselySqliteAdapter {\n type: \"kysely-sqlite\";\n uowConfig?: UnitOfWorkConfig;\n}\n\nexport interface KyselyPgliteAdapter {\n type: \"kysely-pglite\";\n databasePath?: string;\n uowConfig?: UnitOfWorkConfig;\n}\n\nexport interface DrizzlePgliteAdapter {\n type: \"drizzle-pglite\";\n databasePath?: string;\n uowConfig?: UnitOfWorkConfig;\n}\n\nexport interface InMemoryAdapterConfig {\n type: \"in-memory\";\n options?: InMemoryAdapterOptions;\n uowConfig?: UnitOfWorkConfig;\n}\n\nexport interface ModelCheckerAdapterConfig {\n type: \"model-checker\";\n options?: InMemoryAdapterOptions;\n}\n\nexport type SupportedAdapter =\n | KyselySqliteAdapter\n | KyselyPgliteAdapter\n | DrizzlePgliteAdapter\n | InMemoryAdapterConfig\n | ModelCheckerAdapterConfig;\n\nexport interface SchemaConfig {\n schema: AnySchema;\n namespace: string | null;\n migrateToVersion?: number;\n}\n\ninterface InternalTestContext extends BaseTestContext {\n getOrm: <TSchema extends AnySchema>(namespace: string | null) => SimpleQueryInterface<TSchema>;\n}\n\nexport type AdapterContext<T extends SupportedAdapter> = T extends\n | KyselySqliteAdapter\n | KyselyPgliteAdapter\n ? {\n readonly kysely: Kysely<any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n }\n : T extends DrizzlePgliteAdapter\n ? {\n readonly drizzle: ReturnType<typeof drizzle<any>>; // eslint-disable-line @typescript-eslint/no-explicit-any\n }\n : T extends InMemoryAdapterConfig | ModelCheckerAdapterConfig\n ? {}\n : never;\n\nexport interface AdapterFactoryResult<T extends SupportedAdapter> {\n testContext: InternalTestContext & AdapterContext<T>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n adapter: DatabaseAdapter<any>;\n}\n\nexport async function createAdapter<T extends SupportedAdapter>(\n adapterConfig: T,\n schemas: SchemaConfig[],\n): Promise<AdapterFactoryResult<T>> {\n if (adapterConfig.type === \"kysely-sqlite\") {\n const { createKyselySqliteAdapter } = await import(\"./test-adapters/kysely-sqlite\");\n return createKyselySqliteAdapter(adapterConfig, schemas) as Promise<AdapterFactoryResult<T>>;\n }\n\n if (adapterConfig.type === \"kysely-pglite\") {\n const { createKyselyPgliteAdapter } = await import(\"./test-adapters/kysely-pglite\");\n return createKyselyPgliteAdapter(adapterConfig, schemas) as Promise<AdapterFactoryResult<T>>;\n }\n\n if (adapterConfig.type === \"drizzle-pglite\") {\n const { createDrizzlePgliteAdapter } = await import(\"./test-adapters/drizzle-pglite\");\n return createDrizzlePgliteAdapter(adapterConfig, schemas) as Promise<AdapterFactoryResult<T>>;\n }\n\n if (adapterConfig.type === \"in-memory\") {\n const { createInMemoryAdapter } = await import(\"./test-adapters/in-memory\");\n return createInMemoryAdapter(adapterConfig, schemas) as Promise<AdapterFactoryResult<T>>;\n }\n\n if (adapterConfig.type === \"model-checker\") {\n const { createModelCheckerAdapter } = await import(\"./test-adapters/model-checker\");\n return createModelCheckerAdapter(adapterConfig, schemas) as Promise<AdapterFactoryResult<T>>;\n }\n\n throw new Error(`Unsupported adapter type: ${(adapterConfig as SupportedAdapter).type}`);\n}\n"],"mappings":";AA2EA,eAAsB,cACpB,eACA,SACkC;AAClC,KAAI,cAAc,SAAS,iBAAiB;EAC1C,MAAM,EAAE,8BAA8B,MAAM,OAAO;AACnD,SAAO,0BAA0B,eAAe,QAAQ;;AAG1D,KAAI,cAAc,SAAS,iBAAiB;EAC1C,MAAM,EAAE,8BAA8B,MAAM,OAAO;AACnD,SAAO,0BAA0B,eAAe,QAAQ;;AAG1D,KAAI,cAAc,SAAS,kBAAkB;EAC3C,MAAM,EAAE,+BAA+B,MAAM,OAAO;AACpD,SAAO,2BAA2B,eAAe,QAAQ;;AAG3D,KAAI,cAAc,SAAS,aAAa;EACtC,MAAM,EAAE,0BAA0B,MAAM,OAAO;AAC/C,SAAO,sBAAsB,eAAe,QAAQ;;AAGtD,KAAI,cAAc,SAAS,iBAAiB;EAC1C,MAAM,EAAE,8BAA8B,MAAM,OAAO;AACnD,SAAO,0BAA0B,eAAe,QAAQ;;AAG1D,OAAM,IAAI,MAAM,6BAA8B,cAAmC,OAAO"}