@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.
- package/.turbo/turbo-build.log +41 -31
- package/CHANGELOG.md +69 -0
- package/dist/adapters.d.ts +4 -7
- package/dist/adapters.d.ts.map +1 -1
- package/dist/adapters.js +18 -302
- package/dist/adapters.js.map +1 -1
- package/dist/db-test.d.ts +120 -18
- package/dist/db-test.d.ts.map +1 -1
- package/dist/db-test.js +203 -55
- package/dist/db-test.js.map +1 -1
- package/dist/durable-hooks.d.ts +6 -2
- package/dist/durable-hooks.d.ts.map +1 -1
- package/dist/durable-hooks.js +10 -5
- package/dist/durable-hooks.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model-checker-actors.d.ts.map +1 -1
- package/dist/model-checker-actors.js +1 -1
- package/dist/model-checker-actors.js.map +1 -1
- package/dist/model-checker-adapter.d.ts +1 -1
- package/dist/model-checker-adapter.d.ts.map +1 -1
- package/dist/model-checker-adapter.js.map +1 -1
- package/dist/model-checker.d.ts.map +1 -1
- package/dist/model-checker.js.map +1 -1
- package/dist/test-adapters/drizzle-pglite.js +116 -0
- package/dist/test-adapters/drizzle-pglite.js.map +1 -0
- package/dist/test-adapters/in-memory.js +39 -0
- package/dist/test-adapters/in-memory.js.map +1 -0
- package/dist/test-adapters/kysely-pglite.js +105 -0
- package/dist/test-adapters/kysely-pglite.js.map +1 -0
- package/dist/test-adapters/kysely-sqlite.js +87 -0
- package/dist/test-adapters/kysely-sqlite.js.map +1 -0
- package/dist/test-adapters/model-checker.js +41 -0
- package/dist/test-adapters/model-checker.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +32 -33
- package/src/adapter-conformance.test.ts +3 -1
- package/src/adapters.ts +24 -455
- package/src/db-roundtrip-guard.test.ts +206 -0
- package/src/db-test.test.ts +131 -77
- package/src/db-test.ts +530 -96
- package/src/durable-hooks.test.ts +58 -0
- package/src/durable-hooks.ts +23 -8
- package/src/index.test.ts +188 -104
- package/src/index.ts +6 -2
- package/src/model-checker-actors.test.ts +5 -2
- package/src/model-checker-actors.ts +2 -1
- package/src/model-checker-adapter.ts +3 -2
- package/src/model-checker.test.ts +4 -1
- package/src/model-checker.ts +4 -3
- package/src/test-adapters/drizzle-pglite.ts +162 -0
- package/src/test-adapters/in-memory.ts +56 -0
- package/src/test-adapters/kysely-pglite.ts +151 -0
- package/src/test-adapters/kysely-sqlite.ts +119 -0
- package/src/test-adapters/model-checker.ts +58 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +1 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @fragno-dev/test@2.0.
|
|
2
|
+
> @fragno-dev/test@2.0.2 build /home/runner/work/fragno/fragno/packages/fragno-test
|
|
3
3
|
> tsdown
|
|
4
4
|
|
|
5
5
|
[34mℹ[39m tsdown [2mv0.15.12[22m powered by rolldown [2mv1.0.0-beta.45[22m
|
|
@@ -7,33 +7,43 @@
|
|
|
7
7
|
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
8
8
|
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
9
9
|
[34mℹ[39m Build start
|
|
10
|
-
[34mℹ[39m [2mdist/[22m[1mindex.js[22m
|
|
11
|
-
[34mℹ[39m [2mdist/[
|
|
12
|
-
[34mℹ[39m [2mdist/[22mmodel-checker
|
|
13
|
-
[34mℹ[39m [2mdist/[
|
|
14
|
-
[34mℹ[39m [2mdist/[
|
|
15
|
-
[34mℹ[39m [2mdist/[
|
|
16
|
-
[34mℹ[39m [2mdist/[22mmodel-checker-actors.js
|
|
17
|
-
[34mℹ[39m [2mdist/[
|
|
18
|
-
[34mℹ[39m [2mdist/[
|
|
19
|
-
[34mℹ[39m [2mdist/[
|
|
20
|
-
[34mℹ[39m [2mdist/[
|
|
21
|
-
[34mℹ[39m [2mdist/[
|
|
22
|
-
[34mℹ[39m [2mdist/[
|
|
23
|
-
[34mℹ[39m [2mdist/[
|
|
24
|
-
[34mℹ[39m [2mdist/[
|
|
25
|
-
[34mℹ[39m [2mdist/[22mmodel-checker-adapter.
|
|
26
|
-
[34mℹ[39m [2mdist/[
|
|
27
|
-
[34mℹ[39m [2mdist/[
|
|
28
|
-
[34mℹ[39m [2mdist/[
|
|
29
|
-
[34mℹ[39m [2mdist/[
|
|
30
|
-
[34mℹ[39m [2mdist/[
|
|
31
|
-
[34mℹ[39m [2mdist/[
|
|
32
|
-
[34mℹ[39m [2mdist/[
|
|
33
|
-
[34mℹ[39m [2mdist/[
|
|
34
|
-
[34mℹ[39m [2mdist/[
|
|
35
|
-
[34mℹ[39m [2mdist/[
|
|
36
|
-
[34mℹ[39m [2mdist/[
|
|
37
|
-
[34mℹ[39m [2mdist/[
|
|
38
|
-
[34mℹ[39m
|
|
39
|
-
[
|
|
10
|
+
[34mℹ[39m [2mdist/[22m[1mindex.js[22m [2m 1.18 kB[22m [2m│ gzip: 0.53 kB[22m
|
|
11
|
+
[34mℹ[39m [2mdist/[22mdb-test.js.map [2m44.78 kB[22m [2m│ gzip: 9.05 kB[22m
|
|
12
|
+
[34mℹ[39m [2mdist/[22mmodel-checker.js.map [2m33.95 kB[22m [2m│ gzip: 8.30 kB[22m
|
|
13
|
+
[34mℹ[39m [2mdist/[22mmodel-checker-actors.js.map [2m28.86 kB[22m [2m│ gzip: 7.07 kB[22m
|
|
14
|
+
[34mℹ[39m [2mdist/[22mmodel-checker.js [2m14.08 kB[22m [2m│ gzip: 3.89 kB[22m
|
|
15
|
+
[34mℹ[39m [2mdist/[22mdb-test.js [2m13.77 kB[22m [2m│ gzip: 3.67 kB[22m
|
|
16
|
+
[34mℹ[39m [2mdist/[22mmodel-checker-actors.js [2m12.86 kB[22m [2m│ gzip: 3.32 kB[22m
|
|
17
|
+
[34mℹ[39m [2mdist/[22mmodel-checker-adapter.js.map [2m 9.08 kB[22m [2m│ gzip: 2.64 kB[22m
|
|
18
|
+
[34mℹ[39m [2mdist/[22mtest-adapters/drizzle-pglite.js.map [2m 8.22 kB[22m [2m│ gzip: 2.69 kB[22m
|
|
19
|
+
[34mℹ[39m [2mdist/[22mtest-adapters/kysely-pglite.js.map [2m 7.28 kB[22m [2m│ gzip: 2.46 kB[22m
|
|
20
|
+
[34mℹ[39m [2mdist/[22mdb-test.d.ts.map [2m 5.84 kB[22m [2m│ gzip: 2.38 kB[22m
|
|
21
|
+
[34mℹ[39m [2mdist/[22mtest-adapters/kysely-sqlite.js.map [2m 5.72 kB[22m [2m│ gzip: 1.99 kB[22m
|
|
22
|
+
[34mℹ[39m [2mdist/[22mmodel-checker.d.ts.map [2m 4.84 kB[22m [2m│ gzip: 1.89 kB[22m
|
|
23
|
+
[34mℹ[39m [2mdist/[22madapters.js.map [2m 4.41 kB[22m [2m│ gzip: 1.12 kB[22m
|
|
24
|
+
[34mℹ[39m [2mdist/[22mtest-adapters/drizzle-pglite.js [2m 4.39 kB[22m [2m│ gzip: 1.47 kB[22m
|
|
25
|
+
[34mℹ[39m [2mdist/[22mmodel-checker-adapter.js [2m 3.98 kB[22m [2m│ gzip: 1.18 kB[22m
|
|
26
|
+
[34mℹ[39m [2mdist/[22mtest-adapters/kysely-pglite.js [2m 3.81 kB[22m [2m│ gzip: 1.31 kB[22m
|
|
27
|
+
[34mℹ[39m [2mdist/[22mindex.js.map [2m 3.70 kB[22m [2m│ gzip: 1.24 kB[22m
|
|
28
|
+
[34mℹ[39m [2mdist/[22mtest-adapters/kysely-sqlite.js [2m 2.90 kB[22m [2m│ gzip: 1.05 kB[22m
|
|
29
|
+
[34mℹ[39m [2mdist/[22mtest-adapters/model-checker.js.map [2m 2.61 kB[22m [2m│ gzip: 1.08 kB[22m
|
|
30
|
+
[34mℹ[39m [2mdist/[22mtest-adapters/in-memory.js.map [2m 2.42 kB[22m [2m│ gzip: 1.01 kB[22m
|
|
31
|
+
[34mℹ[39m [2mdist/[22mmodel-checker-actors.d.ts.map [2m 1.58 kB[22m [2m│ gzip: 0.71 kB[22m
|
|
32
|
+
[34mℹ[39m [2mdist/[22mdurable-hooks.js.map [2m 1.23 kB[22m [2m│ gzip: 0.58 kB[22m
|
|
33
|
+
[34mℹ[39m [2mdist/[22madapters.js [2m 1.22 kB[22m [2m│ gzip: 0.35 kB[22m
|
|
34
|
+
[34mℹ[39m [2mdist/[22mtest-adapters/model-checker.js [2m 1.18 kB[22m [2m│ gzip: 0.54 kB[22m
|
|
35
|
+
[34mℹ[39m [2mdist/[22mmodel-checker-adapter.d.ts.map [2m 1.07 kB[22m [2m│ gzip: 0.53 kB[22m
|
|
36
|
+
[34mℹ[39m [2mdist/[22mtest-adapters/in-memory.js [2m 1.03 kB[22m [2m│ gzip: 0.49 kB[22m
|
|
37
|
+
[34mℹ[39m [2mdist/[22madapters.d.ts.map [2m 0.71 kB[22m [2m│ gzip: 0.39 kB[22m
|
|
38
|
+
[34mℹ[39m [2mdist/[22mindex.d.ts.map [2m 0.58 kB[22m [2m│ gzip: 0.33 kB[22m
|
|
39
|
+
[34mℹ[39m [2mdist/[22mdurable-hooks.js [2m 0.50 kB[22m [2m│ gzip: 0.29 kB[22m
|
|
40
|
+
[34mℹ[39m [2mdist/[22mdurable-hooks.d.ts.map [2m 0.29 kB[22m [2m│ gzip: 0.21 kB[22m
|
|
41
|
+
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.ts[22m[39m [2m 3.57 kB[22m [2m│ gzip: 1.04 kB[22m
|
|
42
|
+
[34mℹ[39m [2mdist/[22m[32mdb-test.d.ts[39m [2m12.33 kB[22m [2m│ gzip: 2.32 kB[22m
|
|
43
|
+
[34mℹ[39m [2mdist/[22m[32mmodel-checker.d.ts[39m [2m 5.67 kB[22m [2m│ gzip: 1.38 kB[22m
|
|
44
|
+
[34mℹ[39m [2mdist/[22m[32mmodel-checker-actors.d.ts[39m [2m 2.04 kB[22m [2m│ gzip: 0.63 kB[22m
|
|
45
|
+
[34mℹ[39m [2mdist/[22m[32mmodel-checker-adapter.d.ts[39m [2m 1.79 kB[22m [2m│ gzip: 0.68 kB[22m
|
|
46
|
+
[34mℹ[39m [2mdist/[22m[32madapters.d.ts[39m [2m 1.62 kB[22m [2m│ gzip: 0.50 kB[22m
|
|
47
|
+
[34mℹ[39m [2mdist/[22m[32mdurable-hooks.d.ts[39m [2m 0.49 kB[22m [2m│ gzip: 0.26 kB[22m
|
|
48
|
+
[34mℹ[39m 38 files, total: 255.60 kB
|
|
49
|
+
[32m✔[39m Build complete in [32m13491ms[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,74 @@
|
|
|
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
|
+
|
|
3
72
|
## 2.0.0
|
|
4
73
|
|
|
5
74
|
### Patch Changes
|
package/dist/adapters.d.ts
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
import "./index.js";
|
|
2
|
-
import {
|
|
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";
|
|
3
5
|
import { drizzle } from "drizzle-orm/pglite";
|
|
4
6
|
import { InMemoryAdapterOptions } from "@fragno-dev/db/adapters/in-memory";
|
|
5
|
-
import {
|
|
6
|
-
import { DatabaseAdapter } from "@fragno-dev/db/adapters";
|
|
7
|
-
import { AnySchema } from "@fragno-dev/db/schema";
|
|
7
|
+
import { Kysely } from "kysely";
|
|
8
8
|
import { SimpleQueryInterface } from "@fragno-dev/db/query";
|
|
9
9
|
|
|
10
10
|
//#region src/adapters.d.ts
|
|
11
11
|
interface KyselySqliteAdapter {
|
|
12
12
|
type: "kysely-sqlite";
|
|
13
13
|
uowConfig?: UnitOfWorkConfig;
|
|
14
|
-
outbox?: OutboxConfig;
|
|
15
14
|
}
|
|
16
15
|
interface KyselyPgliteAdapter {
|
|
17
16
|
type: "kysely-pglite";
|
|
18
17
|
databasePath?: string;
|
|
19
18
|
uowConfig?: UnitOfWorkConfig;
|
|
20
|
-
outbox?: OutboxConfig;
|
|
21
19
|
}
|
|
22
20
|
interface DrizzlePgliteAdapter {
|
|
23
21
|
type: "drizzle-pglite";
|
|
24
22
|
databasePath?: string;
|
|
25
23
|
uowConfig?: UnitOfWorkConfig;
|
|
26
|
-
outbox?: OutboxConfig;
|
|
27
24
|
}
|
|
28
25
|
interface InMemoryAdapterConfig {
|
|
29
26
|
type: "in-memory";
|
package/dist/adapters.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapters.d.ts","names":[],"sources":["../src/adapters.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;
|
|
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,309 +1,25 @@
|
|
|
1
|
-
import { ModelCheckerAdapter } from "./model-checker-adapter.js";
|
|
2
|
-
import { createCommonTestContextMethods } from "./index.js";
|
|
3
|
-
import { Kysely } from "kysely";
|
|
4
|
-
import { SQLocalKysely } from "sqlocal/kysely";
|
|
5
|
-
import { KyselyPGlite } from "kysely-pglite";
|
|
6
|
-
import { drizzle } from "drizzle-orm/pglite";
|
|
7
|
-
import { PGlite } from "@electric-sql/pglite";
|
|
8
|
-
import { InMemoryAdapter } from "@fragno-dev/db/adapters/in-memory";
|
|
9
|
-
import { SqlAdapter } from "@fragno-dev/db/adapters/sql";
|
|
10
|
-
import { rm } from "node:fs/promises";
|
|
11
|
-
import { existsSync } from "node:fs";
|
|
12
|
-
import { PGLiteDriverConfig, SQLocalDriverConfig } from "@fragno-dev/db/drivers";
|
|
13
|
-
import { internalFragmentDef } from "@fragno-dev/db";
|
|
14
|
-
|
|
15
1
|
//#region src/adapters.ts
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
config: {},
|
|
21
|
-
options: {
|
|
22
|
-
databaseAdapter: adapter,
|
|
23
|
-
databaseNamespace: null
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
if (databaseDeps?.schema) {
|
|
27
|
-
await adapter.prepareMigrations(databaseDeps.schema, databaseDeps.namespace).executeWithDriver(adapter.driver, 0);
|
|
28
|
-
return {
|
|
29
|
-
schema: databaseDeps.schema,
|
|
30
|
-
namespace: databaseDeps.namespace
|
|
31
|
-
};
|
|
2
|
+
async function createAdapter(adapterConfig, schemas) {
|
|
3
|
+
if (adapterConfig.type === "kysely-sqlite") {
|
|
4
|
+
const { createKyselySqliteAdapter } = await import("./test-adapters/kysely-sqlite.js");
|
|
5
|
+
return createKyselySqliteAdapter(adapterConfig, schemas);
|
|
32
6
|
}
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
if (!namespace || namespace.length === 0) return null;
|
|
37
|
-
return adapter.namingStrategy.namespaceToSchema(namespace);
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Create Kysely + SQLite adapter using SQLocalKysely (always in-memory)
|
|
41
|
-
* Supports multiple schemas with separate namespaces
|
|
42
|
-
*/
|
|
43
|
-
async function createKyselySqliteAdapter(config, schemas) {
|
|
44
|
-
let internalSchemaConfig;
|
|
45
|
-
const createDatabase = async () => {
|
|
46
|
-
const { dialect } = new SQLocalKysely(":memory:");
|
|
47
|
-
const kysely$1 = new Kysely({ dialect });
|
|
48
|
-
const adapter$1 = new SqlAdapter({
|
|
49
|
-
dialect,
|
|
50
|
-
driverConfig: new SQLocalDriverConfig(),
|
|
51
|
-
uowConfig: config.uowConfig,
|
|
52
|
-
outbox: config.outbox
|
|
53
|
-
});
|
|
54
|
-
internalSchemaConfig = await runInternalFragmentMigrations(adapter$1);
|
|
55
|
-
const ormMap$1 = /* @__PURE__ */ new Map();
|
|
56
|
-
for (const { schema, namespace, migrateToVersion } of schemas) {
|
|
57
|
-
const preparedMigrations = adapter$1.prepareMigrations(schema, namespace);
|
|
58
|
-
if (migrateToVersion !== void 0) await preparedMigrations.execute(0, migrateToVersion, { updateVersionInMigration: false });
|
|
59
|
-
else await preparedMigrations.execute(0, schema.version, { updateVersionInMigration: false });
|
|
60
|
-
const orm = adapter$1.createQueryEngine(schema, namespace);
|
|
61
|
-
ormMap$1.set(namespace, orm);
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
kysely: kysely$1,
|
|
65
|
-
adapter: adapter$1,
|
|
66
|
-
ormMap: ormMap$1
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
let { kysely, adapter, ormMap } = await createDatabase();
|
|
70
|
-
const resetDatabase = async () => {
|
|
71
|
-
const schemasToTruncate = internalSchemaConfig ? [internalSchemaConfig, ...schemas] : schemas;
|
|
72
|
-
for (const { schema, namespace } of schemasToTruncate) for (const tableName of Object.keys(schema.tables)) {
|
|
73
|
-
const physicalTableName = adapter.namingStrategy.tableName(tableName, namespace);
|
|
74
|
-
await kysely.deleteFrom(physicalTableName).execute();
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
const cleanup = async () => {
|
|
78
|
-
await kysely.destroy();
|
|
79
|
-
};
|
|
80
|
-
return {
|
|
81
|
-
testContext: {
|
|
82
|
-
get kysely() {
|
|
83
|
-
return kysely;
|
|
84
|
-
},
|
|
85
|
-
get adapter() {
|
|
86
|
-
return adapter;
|
|
87
|
-
},
|
|
88
|
-
...createCommonTestContextMethods(ormMap),
|
|
89
|
-
resetDatabase,
|
|
90
|
-
cleanup
|
|
91
|
-
},
|
|
92
|
-
get adapter() {
|
|
93
|
-
return adapter;
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Create Kysely + PGLite adapter using kysely-pglite
|
|
99
|
-
* Supports multiple schemas with separate namespaces
|
|
100
|
-
*/
|
|
101
|
-
async function createKyselyPgliteAdapter(config, schemas) {
|
|
102
|
-
const databasePath = config.databasePath;
|
|
103
|
-
let internalSchemaConfig;
|
|
104
|
-
const createDatabase = async () => {
|
|
105
|
-
const kyselyPglite$1 = await KyselyPGlite.create(databasePath);
|
|
106
|
-
const kysely$1 = new Kysely({ dialect: kyselyPglite$1.dialect });
|
|
107
|
-
const adapter$1 = new SqlAdapter({
|
|
108
|
-
dialect: kyselyPglite$1.dialect,
|
|
109
|
-
driverConfig: new PGLiteDriverConfig(),
|
|
110
|
-
uowConfig: config.uowConfig,
|
|
111
|
-
outbox: config.outbox
|
|
112
|
-
});
|
|
113
|
-
internalSchemaConfig = await runInternalFragmentMigrations(adapter$1);
|
|
114
|
-
const ormMap$1 = /* @__PURE__ */ new Map();
|
|
115
|
-
for (const { schema, namespace, migrateToVersion } of schemas) {
|
|
116
|
-
const preparedMigrations = adapter$1.prepareMigrations(schema, namespace);
|
|
117
|
-
if (migrateToVersion !== void 0) await preparedMigrations.execute(0, migrateToVersion, { updateVersionInMigration: false });
|
|
118
|
-
else await preparedMigrations.execute(0, schema.version, { updateVersionInMigration: false });
|
|
119
|
-
const orm = adapter$1.createQueryEngine(schema, namespace);
|
|
120
|
-
ormMap$1.set(namespace, orm);
|
|
121
|
-
}
|
|
122
|
-
return {
|
|
123
|
-
kysely: kysely$1,
|
|
124
|
-
adapter: adapter$1,
|
|
125
|
-
kyselyPglite: kyselyPglite$1,
|
|
126
|
-
ormMap: ormMap$1
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
const { kysely, adapter, kyselyPglite, ormMap } = await createDatabase();
|
|
130
|
-
const resetDatabase = async () => {
|
|
131
|
-
if (databasePath && databasePath !== ":memory:") throw new Error("resetDatabase is only supported for in-memory databases");
|
|
132
|
-
const schemasToTruncate = internalSchemaConfig ? [internalSchemaConfig, ...schemas] : schemas;
|
|
133
|
-
for (const { schema, namespace } of schemasToTruncate) for (const tableName of Object.keys(schema.tables)) {
|
|
134
|
-
const physicalTableName = adapter.namingStrategy.tableName(tableName, namespace);
|
|
135
|
-
const schemaName = resolveSchemaName(adapter, namespace);
|
|
136
|
-
await (schemaName ? kysely.withSchema(schemaName) : kysely).deleteFrom(physicalTableName).execute();
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
const cleanup = async () => {
|
|
140
|
-
await kysely.destroy();
|
|
141
|
-
try {
|
|
142
|
-
await kyselyPglite.client.close();
|
|
143
|
-
} catch {}
|
|
144
|
-
if (databasePath && databasePath !== ":memory:" && existsSync(databasePath)) await rm(databasePath, {
|
|
145
|
-
recursive: true,
|
|
146
|
-
force: true
|
|
147
|
-
});
|
|
148
|
-
};
|
|
149
|
-
return {
|
|
150
|
-
testContext: {
|
|
151
|
-
get kysely() {
|
|
152
|
-
return kysely;
|
|
153
|
-
},
|
|
154
|
-
get adapter() {
|
|
155
|
-
return adapter;
|
|
156
|
-
},
|
|
157
|
-
...createCommonTestContextMethods(ormMap),
|
|
158
|
-
resetDatabase,
|
|
159
|
-
cleanup
|
|
160
|
-
},
|
|
161
|
-
get adapter() {
|
|
162
|
-
return adapter;
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Create Drizzle + PGLite adapter using drizzle-orm/pglite
|
|
168
|
-
* Supports multiple schemas with separate namespaces
|
|
169
|
-
*/
|
|
170
|
-
async function createDrizzlePgliteAdapter(config, schemas) {
|
|
171
|
-
const databasePath = config.databasePath;
|
|
172
|
-
let internalSchemaConfig;
|
|
173
|
-
const createDatabase = async () => {
|
|
174
|
-
const pglite = new PGlite(databasePath);
|
|
175
|
-
const { dialect } = new KyselyPGlite(pglite);
|
|
176
|
-
const adapter$1 = new SqlAdapter({
|
|
177
|
-
dialect,
|
|
178
|
-
driverConfig: new PGLiteDriverConfig(),
|
|
179
|
-
uowConfig: config.uowConfig,
|
|
180
|
-
outbox: config.outbox
|
|
181
|
-
});
|
|
182
|
-
internalSchemaConfig = await runInternalFragmentMigrations(adapter$1);
|
|
183
|
-
const ormMap$1 = /* @__PURE__ */ new Map();
|
|
184
|
-
for (const { schema, namespace, migrateToVersion } of schemas) {
|
|
185
|
-
const preparedMigrations = adapter$1.prepareMigrations(schema, namespace);
|
|
186
|
-
if (migrateToVersion !== void 0) await preparedMigrations.execute(0, migrateToVersion, { updateVersionInMigration: false });
|
|
187
|
-
else await preparedMigrations.execute(0, schema.version, { updateVersionInMigration: false });
|
|
188
|
-
const orm = adapter$1.createQueryEngine(schema, namespace);
|
|
189
|
-
ormMap$1.set(namespace, orm);
|
|
190
|
-
}
|
|
191
|
-
return {
|
|
192
|
-
drizzle: drizzle(pglite),
|
|
193
|
-
adapter: adapter$1,
|
|
194
|
-
pglite,
|
|
195
|
-
ormMap: ormMap$1
|
|
196
|
-
};
|
|
197
|
-
};
|
|
198
|
-
const { drizzle: drizzleDb, adapter, ormMap } = await createDatabase();
|
|
199
|
-
const resetDatabase = async () => {
|
|
200
|
-
if (databasePath && databasePath !== ":memory:") throw new Error("resetDatabase is only supported for in-memory databases");
|
|
201
|
-
const schemasToTruncate = internalSchemaConfig ? [internalSchemaConfig, ...schemas] : schemas;
|
|
202
|
-
for (const { schema, namespace } of schemasToTruncate) {
|
|
203
|
-
const tableNames = Object.keys(schema.tables).slice().reverse();
|
|
204
|
-
for (const tableName of tableNames) {
|
|
205
|
-
const physicalTableName = adapter.namingStrategy.tableName(tableName, namespace);
|
|
206
|
-
const schemaName = resolveSchemaName(adapter, namespace);
|
|
207
|
-
const qualifiedTable = schemaName ? `"${schemaName}"."${physicalTableName}"` : `"${physicalTableName}"`;
|
|
208
|
-
await drizzleDb.execute(`DELETE FROM ${qualifiedTable}`);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
const cleanup = async () => {
|
|
213
|
-
await adapter.close();
|
|
214
|
-
if (databasePath && databasePath !== ":memory:" && existsSync(databasePath)) await rm(databasePath, {
|
|
215
|
-
recursive: true,
|
|
216
|
-
force: true
|
|
217
|
-
});
|
|
218
|
-
};
|
|
219
|
-
return {
|
|
220
|
-
testContext: {
|
|
221
|
-
get drizzle() {
|
|
222
|
-
return drizzleDb;
|
|
223
|
-
},
|
|
224
|
-
get adapter() {
|
|
225
|
-
return adapter;
|
|
226
|
-
},
|
|
227
|
-
...createCommonTestContextMethods(ormMap),
|
|
228
|
-
resetDatabase,
|
|
229
|
-
cleanup
|
|
230
|
-
},
|
|
231
|
-
get adapter() {
|
|
232
|
-
return adapter;
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Create InMemory adapter (no migrations required).
|
|
238
|
-
*/
|
|
239
|
-
async function createInMemoryAdapter(config, schemas) {
|
|
240
|
-
const adapter = new InMemoryAdapter(config.options);
|
|
241
|
-
const ormMap = /* @__PURE__ */ new Map();
|
|
242
|
-
for (const { schema, namespace } of schemas) {
|
|
243
|
-
const orm = adapter.createQueryEngine(schema, namespace);
|
|
244
|
-
ormMap.set(namespace, orm);
|
|
7
|
+
if (adapterConfig.type === "kysely-pglite") {
|
|
8
|
+
const { createKyselyPgliteAdapter } = await import("./test-adapters/kysely-pglite.js");
|
|
9
|
+
return createKyselyPgliteAdapter(adapterConfig, schemas);
|
|
245
10
|
}
|
|
246
|
-
|
|
247
|
-
await
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
...createCommonTestContextMethods(ormMap),
|
|
258
|
-
resetDatabase,
|
|
259
|
-
cleanup
|
|
260
|
-
},
|
|
261
|
-
get adapter() {
|
|
262
|
-
return adapter;
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Create ModelChecker adapter (wraps the in-memory adapter).
|
|
268
|
-
*/
|
|
269
|
-
async function createModelCheckerAdapter(config, schemas) {
|
|
270
|
-
const baseAdapter = new InMemoryAdapter(config.options);
|
|
271
|
-
const adapter = new ModelCheckerAdapter(baseAdapter);
|
|
272
|
-
const ormMap = /* @__PURE__ */ new Map();
|
|
273
|
-
for (const { schema, namespace } of schemas) {
|
|
274
|
-
const orm = adapter.createQueryEngine(schema, namespace);
|
|
275
|
-
ormMap.set(namespace, orm);
|
|
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);
|
|
276
22
|
}
|
|
277
|
-
const resetDatabase = async () => {
|
|
278
|
-
await baseAdapter.reset();
|
|
279
|
-
};
|
|
280
|
-
const cleanup = async () => {
|
|
281
|
-
await adapter.close();
|
|
282
|
-
};
|
|
283
|
-
return {
|
|
284
|
-
testContext: {
|
|
285
|
-
get adapter() {
|
|
286
|
-
return adapter;
|
|
287
|
-
},
|
|
288
|
-
...createCommonTestContextMethods(ormMap),
|
|
289
|
-
resetDatabase,
|
|
290
|
-
cleanup
|
|
291
|
-
},
|
|
292
|
-
get adapter() {
|
|
293
|
-
return adapter;
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Create adapter based on configuration
|
|
299
|
-
* Supports multiple schemas with separate namespaces
|
|
300
|
-
*/
|
|
301
|
-
async function createAdapter(adapterConfig, schemas) {
|
|
302
|
-
if (adapterConfig.type === "kysely-sqlite") return createKyselySqliteAdapter(adapterConfig, schemas);
|
|
303
|
-
else if (adapterConfig.type === "kysely-pglite") return createKyselyPgliteAdapter(adapterConfig, schemas);
|
|
304
|
-
else if (adapterConfig.type === "drizzle-pglite") return createDrizzlePgliteAdapter(adapterConfig, schemas);
|
|
305
|
-
else if (adapterConfig.type === "in-memory") return createInMemoryAdapter(adapterConfig, schemas);
|
|
306
|
-
else if (adapterConfig.type === "model-checker") return createModelCheckerAdapter(adapterConfig, schemas);
|
|
307
23
|
throw new Error(`Unsupported adapter type: ${adapterConfig.type}`);
|
|
308
24
|
}
|
|
309
25
|
|
package/dist/adapters.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapters.js","names":["internalSchemaConfig: SchemaConfig | undefined","kysely","adapter","ormMap","kyselyPglite"],"sources":["../src/adapters.ts"],"sourcesContent":["// Test database adapter helpers and reset logic for fragment suites.\nimport { 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 { InMemoryAdapter, type InMemoryAdapterOptions } from \"@fragno-dev/db/adapters/in-memory\";\nimport { SqlAdapter } from \"@fragno-dev/db/adapters/sql\";\nimport type { AnySchema } from \"@fragno-dev/db/schema\";\nimport type { DatabaseAdapter } from \"@fragno-dev/db/adapters\";\nimport type { UnitOfWorkConfig } from \"@fragno-dev/db/adapters/sql\";\nimport type { OutboxConfig } from \"@fragno-dev/db/adapters/sql\";\nimport { rm } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport type { BaseTestContext } from \".\";\nimport { ModelCheckerAdapter } from \"./model-checker-adapter\";\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 uowConfig?: UnitOfWorkConfig;\n outbox?: OutboxConfig;\n}\n\nexport interface KyselyPgliteAdapter {\n type: \"kysely-pglite\";\n databasePath?: string;\n uowConfig?: UnitOfWorkConfig;\n outbox?: OutboxConfig;\n}\n\nexport interface DrizzlePgliteAdapter {\n type: \"drizzle-pglite\";\n databasePath?: string;\n uowConfig?: UnitOfWorkConfig;\n outbox?: OutboxConfig;\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\n// Schema configuration for multi-schema adapters\nexport interface SchemaConfig {\n schema: AnySchema;\n namespace: string | null;\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 | null) => 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 : T extends InMemoryAdapterConfig | ModelCheckerAdapterConfig\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\nconst runInternalFragmentMigrations = async (\n adapter: SqlAdapter,\n): Promise<SchemaConfig | undefined> => {\n const dependencies = internalFragmentDef.dependencies;\n if (!dependencies) {\n return undefined;\n }\n\n const databaseDeps = dependencies({\n config: {},\n options: { databaseAdapter: adapter, databaseNamespace: null },\n });\n if (databaseDeps?.schema) {\n const migrations = adapter.prepareMigrations(databaseDeps.schema, databaseDeps.namespace);\n await migrations.executeWithDriver(adapter.driver, 0);\n return { schema: databaseDeps.schema, namespace: databaseDeps.namespace };\n }\n return undefined;\n};\n\nconst resolveSchemaName = (\n adapter: DatabaseAdapter<any>, // eslint-disable-line @typescript-eslint/no-explicit-any\n namespace: string | null,\n): string | null => {\n if (adapter.namingStrategy.namespaceScope !== \"schema\") {\n return null;\n }\n if (!namespace || namespace.length === 0) {\n return null;\n }\n return adapter.namingStrategy.namespaceToSchema(namespace);\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 let internalSchemaConfig: SchemaConfig | undefined;\n\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 SqlAdapter\n const adapter = new SqlAdapter({\n dialect,\n driverConfig: new SQLocalDriverConfig(),\n uowConfig: config.uowConfig,\n outbox: config.outbox,\n });\n internalSchemaConfig = await runInternalFragmentMigrations(adapter);\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 | null, 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 const schemasToTruncate = internalSchemaConfig ? [internalSchemaConfig, ...schemas] : schemas;\n\n // For SQLite, truncate all tables by deleting rows\n for (const { schema, namespace } of schemasToTruncate) {\n for (const tableName of Object.keys(schema.tables)) {\n const physicalTableName = adapter.namingStrategy.tableName(tableName, namespace);\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 let internalSchemaConfig: SchemaConfig | undefined;\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 SqlAdapter\n const adapter = new SqlAdapter({\n dialect: kyselyPglite.dialect,\n driverConfig: new PGLiteDriverConfig(),\n uowConfig: config.uowConfig,\n outbox: config.outbox,\n });\n internalSchemaConfig = await runInternalFragmentMigrations(adapter);\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 | null, 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 const schemasToTruncate = internalSchemaConfig ? [internalSchemaConfig, ...schemas] : schemas;\n\n // Truncate all tables\n for (const { schema, namespace } of schemasToTruncate) {\n for (const tableName of Object.keys(schema.tables)) {\n const physicalTableName = adapter.namingStrategy.tableName(tableName, namespace);\n const schemaName = resolveSchemaName(adapter, namespace);\n const scopedKysely = schemaName ? kysely.withSchema(schemaName) : kysely;\n await scopedKysely.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 let internalSchemaConfig: SchemaConfig | undefined;\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 SqlAdapter({\n dialect,\n driverConfig: new PGLiteDriverConfig(),\n uowConfig: config.uowConfig,\n outbox: config.outbox,\n });\n\n internalSchemaConfig = await runInternalFragmentMigrations(adapter);\n\n // Run migrations for all schemas\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const ormMap = new Map<string | null, SimpleQueryInterface<any, any>>();\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 const schemasToTruncate = internalSchemaConfig ? [internalSchemaConfig, ...schemas] : schemas;\n\n // Truncate all tables by deleting rows\n for (const { schema, namespace } of schemasToTruncate) {\n const tableNames = Object.keys(schema.tables).slice().reverse();\n for (const tableName of tableNames) {\n const physicalTableName = adapter.namingStrategy.tableName(tableName, namespace);\n const schemaName = resolveSchemaName(adapter, namespace);\n const qualifiedTable = schemaName\n ? `\"${schemaName}\".\"${physicalTableName}\"`\n : `\"${physicalTableName}\"`;\n await drizzleDb.execute(`DELETE FROM ${qualifiedTable}`);\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 InMemory adapter (no migrations required).\n */\nexport async function createInMemoryAdapter(\n config: InMemoryAdapterConfig,\n schemas: SchemaConfig[],\n): Promise<AdapterFactoryResult<InMemoryAdapterConfig>> {\n const adapter = new InMemoryAdapter(config.options);\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const ormMap = new Map<string | null, SimpleQueryInterface<any, any>>();\n for (const { schema, namespace } of schemas) {\n const orm = adapter.createQueryEngine(schema, namespace);\n ormMap.set(namespace, orm);\n }\n\n const resetDatabase = async () => {\n await adapter.reset();\n };\n\n const cleanup = async () => {\n await adapter.close();\n };\n\n const commonMethods = createCommonTestContextMethods(ormMap);\n\n return {\n testContext: {\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 ModelChecker adapter (wraps the in-memory adapter).\n */\nexport async function createModelCheckerAdapter(\n config: ModelCheckerAdapterConfig,\n schemas: SchemaConfig[],\n): Promise<AdapterFactoryResult<ModelCheckerAdapterConfig>> {\n const baseAdapter = new InMemoryAdapter(config.options);\n const adapter = new ModelCheckerAdapter(baseAdapter);\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const ormMap = new Map<string | null, SimpleQueryInterface<any, any>>();\n for (const { schema, namespace } of schemas) {\n const orm = adapter.createQueryEngine(schema, namespace);\n ormMap.set(namespace, orm);\n }\n\n const resetDatabase = async () => {\n await baseAdapter.reset();\n };\n\n const cleanup = async () => {\n await adapter.close();\n };\n\n const commonMethods = createCommonTestContextMethods(ormMap);\n\n return {\n testContext: {\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 } else if (adapterConfig.type === \"in-memory\") {\n return createInMemoryAdapter(adapterConfig, schemas) as Promise<AdapterFactoryResult<T>>;\n } else if (adapterConfig.type === \"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":";;;;;;;;;;;;;;;AA8FA,MAAM,gCAAgC,OACpC,YACsC;CACtC,MAAM,eAAe,oBAAoB;AACzC,KAAI,CAAC,aACH;CAGF,MAAM,eAAe,aAAa;EAChC,QAAQ,EAAE;EACV,SAAS;GAAE,iBAAiB;GAAS,mBAAmB;GAAM;EAC/D,CAAC;AACF,KAAI,cAAc,QAAQ;AAExB,QADmB,QAAQ,kBAAkB,aAAa,QAAQ,aAAa,UAAU,CACxE,kBAAkB,QAAQ,QAAQ,EAAE;AACrD,SAAO;GAAE,QAAQ,aAAa;GAAQ,WAAW,aAAa;GAAW;;;AAK7E,MAAM,qBACJ,SACA,cACkB;AAClB,KAAI,QAAQ,eAAe,mBAAmB,SAC5C,QAAO;AAET,KAAI,CAAC,aAAa,UAAU,WAAW,EACrC,QAAO;AAET,QAAO,QAAQ,eAAe,kBAAkB,UAAU;;;;;;AAO5D,eAAsB,0BACpB,QACA,SACoD;CACpD,IAAIA;CAGJ,MAAM,iBAAiB,YAAY;EAEjC,MAAM,EAAE,YAAY,IAAI,cAAc,WAAW;EAEjD,MAAMC,WAAS,IAAI,OAAY,EAC7B,SACD,CAAC;EAGF,MAAMC,YAAU,IAAI,WAAW;GAC7B;GACA,cAAc,IAAI,qBAAqB;GACvC,WAAW,OAAO;GAClB,QAAQ,OAAO;GAChB,CAAC;AACF,yBAAuB,MAAM,8BAA8BA,UAAQ;EAInE,MAAMC,2BAAS,IAAI,KAAoD;AAEvE,OAAK,MAAM,EAAE,QAAQ,WAAW,sBAAsB,SAAS;GAE7D,MAAM,qBAAqBD,UAAQ,kBAAkB,QAAQ,UAAU;AACvE,OAAI,qBAAqB,OACvB,OAAM,mBAAmB,QAAQ,GAAG,kBAAkB,EAAE,0B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M,QAAQ,OAAO;;AAKvB,QAAO;EACL,aAAa;GACX,IAAI,UAAU;AACZ,WAAO;;GAET,GAPkB,+BAA+B,OAAO;GAQxD;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;UAChD,cAAc,SAAS,YAChC,QAAO,sBAAsB,eAAe,QAAQ;UAC3C,cAAc,SAAS,gBAChC,QAAO,0BAA0B,eAAe,QAAQ;AAG1D,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"}
|