@geekmidas/testkit 10.0.0-alpha.11 → 10.0.0-alpha.13

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 (262) hide show
  1. package/dist/Factory.cjs +51 -2
  2. package/dist/Factory.cjs.map +1 -0
  3. package/dist/Factory.d.cts +143 -3
  4. package/dist/Factory.d.cts.map +1 -0
  5. package/dist/Factory.d.mts +143 -3
  6. package/dist/Factory.d.mts.map +1 -0
  7. package/dist/Factory.mjs +50 -2
  8. package/dist/Factory.mjs.map +1 -0
  9. package/dist/KyselyFactory.cjs +237 -4
  10. package/dist/KyselyFactory.cjs.map +1 -0
  11. package/dist/KyselyFactory.d.cts +224 -4
  12. package/dist/KyselyFactory.d.cts.map +1 -0
  13. package/dist/KyselyFactory.d.mts +224 -4
  14. package/dist/KyselyFactory.d.mts.map +1 -0
  15. package/dist/KyselyFactory.mjs +236 -4
  16. package/dist/KyselyFactory.mjs.map +1 -0
  17. package/dist/ObjectionFactory.cjs +265 -4
  18. package/dist/ObjectionFactory.cjs.map +1 -0
  19. package/dist/ObjectionFactory.d.cts +237 -4
  20. package/dist/ObjectionFactory.d.cts.map +1 -0
  21. package/dist/ObjectionFactory.d.mts +237 -4
  22. package/dist/ObjectionFactory.d.mts.map +1 -0
  23. package/dist/ObjectionFactory.mjs +264 -4
  24. package/dist/ObjectionFactory.mjs.map +1 -0
  25. package/dist/PostgresKyselyMigrator.cjs +94 -3
  26. package/dist/PostgresKyselyMigrator.cjs.map +1 -0
  27. package/dist/PostgresKyselyMigrator.d.cts +80 -3
  28. package/dist/PostgresKyselyMigrator.d.cts.map +1 -0
  29. package/dist/PostgresKyselyMigrator.d.mts +80 -3
  30. package/dist/PostgresKyselyMigrator.d.mts.map +1 -0
  31. package/dist/PostgresKyselyMigrator.mjs +93 -3
  32. package/dist/PostgresKyselyMigrator.mjs.map +1 -0
  33. package/dist/{PostgresMigrator-C_QQ6q35.d.mts → PostgresMigrator-CoHQ95cT.d.cts} +2 -3
  34. package/dist/PostgresMigrator-CoHQ95cT.d.cts.map +1 -0
  35. package/dist/{PostgresMigrator-CeYy-eHF.d.cts → PostgresMigrator-CoHQ95cT.d.mts} +2 -3
  36. package/dist/PostgresMigrator-CoHQ95cT.d.mts.map +1 -0
  37. package/dist/PostgresMigrator.cjs +169 -2
  38. package/dist/PostgresMigrator.cjs.map +1 -0
  39. package/dist/PostgresMigrator.d.cts +1 -1
  40. package/dist/PostgresMigrator.d.mts +1 -1
  41. package/dist/PostgresMigrator.mjs +166 -2
  42. package/dist/PostgresMigrator.mjs.map +1 -0
  43. package/dist/PostgresObjectionMigrator.cjs +118 -3
  44. package/dist/PostgresObjectionMigrator.cjs.map +1 -0
  45. package/dist/PostgresObjectionMigrator.d.cts +75 -3
  46. package/dist/PostgresObjectionMigrator.d.cts.map +1 -0
  47. package/dist/PostgresObjectionMigrator.d.mts +75 -3
  48. package/dist/PostgresObjectionMigrator.d.mts.map +1 -0
  49. package/dist/PostgresObjectionMigrator.mjs +117 -3
  50. package/dist/PostgresObjectionMigrator.mjs.map +1 -0
  51. package/dist/VitestKyselyTransactionIsolator.cjs +66 -3
  52. package/dist/VitestKyselyTransactionIsolator.cjs.map +1 -0
  53. package/dist/VitestKyselyTransactionIsolator.d.cts +60 -3
  54. package/dist/VitestKyselyTransactionIsolator.d.cts.map +1 -0
  55. package/dist/VitestKyselyTransactionIsolator.d.mts +60 -3
  56. package/dist/VitestKyselyTransactionIsolator.d.mts.map +1 -0
  57. package/dist/VitestKyselyTransactionIsolator.mjs +65 -3
  58. package/dist/VitestKyselyTransactionIsolator.mjs.map +1 -0
  59. package/dist/VitestObjectionTransactionIsolator.cjs +62 -3
  60. package/dist/VitestObjectionTransactionIsolator.cjs.map +1 -0
  61. package/dist/VitestObjectionTransactionIsolator.d.cts +56 -3
  62. package/dist/VitestObjectionTransactionIsolator.d.cts.map +1 -0
  63. package/dist/VitestObjectionTransactionIsolator.d.mts +56 -3
  64. package/dist/VitestObjectionTransactionIsolator.d.mts.map +1 -0
  65. package/dist/VitestObjectionTransactionIsolator.mjs +61 -3
  66. package/dist/VitestObjectionTransactionIsolator.mjs.map +1 -0
  67. package/dist/VitestTransactionIsolator.cjs +187 -4
  68. package/dist/VitestTransactionIsolator.cjs.map +1 -0
  69. package/dist/VitestTransactionIsolator.d.cts +219 -2
  70. package/dist/VitestTransactionIsolator.d.cts.map +1 -0
  71. package/dist/VitestTransactionIsolator.d.mts +219 -2
  72. package/dist/VitestTransactionIsolator.d.mts.map +1 -0
  73. package/dist/VitestTransactionIsolator.mjs +184 -2
  74. package/dist/VitestTransactionIsolator.mjs.map +1 -0
  75. package/dist/aws.cjs +3 -4
  76. package/dist/aws.cjs.map +1 -1
  77. package/dist/aws.d.cts +3 -8
  78. package/dist/aws.d.cts.map +1 -1
  79. package/dist/aws.d.mts +3 -8
  80. package/dist/aws.d.mts.map +1 -1
  81. package/dist/aws.mjs +1 -2
  82. package/dist/aws.mjs.map +1 -1
  83. package/dist/benchmark.cjs +2 -2
  84. package/dist/benchmark.cjs.map +1 -1
  85. package/dist/benchmark.d.cts +4 -6
  86. package/dist/benchmark.d.cts.map +1 -1
  87. package/dist/benchmark.d.mts +4 -6
  88. package/dist/benchmark.d.mts.map +1 -1
  89. package/dist/benchmark.mjs +1 -1
  90. package/dist/benchmark.mjs.map +1 -1
  91. package/dist/better-auth.cjs +17 -8
  92. package/dist/better-auth.cjs.map +1 -1
  93. package/dist/better-auth.d.cts +13142 -5
  94. package/dist/better-auth.d.cts.map +1 -1
  95. package/dist/better-auth.d.mts +13142 -5
  96. package/dist/better-auth.d.mts.map +1 -1
  97. package/dist/better-auth.mjs +15 -6
  98. package/dist/better-auth.mjs.map +1 -1
  99. package/dist/faker.cjs +262 -8
  100. package/dist/faker.cjs.map +1 -0
  101. package/dist/faker.d.cts +162 -2
  102. package/dist/faker.d.cts.map +1 -0
  103. package/dist/faker.d.mts +162 -2
  104. package/dist/faker.d.mts.map +1 -0
  105. package/dist/faker.mjs +255 -2
  106. package/dist/faker.mjs.map +1 -0
  107. package/dist/helpers.cjs +6 -5
  108. package/dist/helpers.cjs.map +1 -1
  109. package/dist/helpers.d.cts +1 -5
  110. package/dist/helpers.d.cts.map +1 -1
  111. package/dist/helpers.d.mts +1 -5
  112. package/dist/helpers.d.mts.map +1 -1
  113. package/dist/helpers.mjs +1 -2
  114. package/dist/helpers.mjs.map +1 -1
  115. package/dist/initScript.cjs +15 -15
  116. package/dist/initScript.cjs.map +1 -1
  117. package/dist/initScript.d.cts +2 -4
  118. package/dist/initScript.d.cts.map +1 -1
  119. package/dist/initScript.d.mts +2 -4
  120. package/dist/initScript.d.mts.map +1 -1
  121. package/dist/initScript.mjs +10 -12
  122. package/dist/initScript.mjs.map +1 -1
  123. package/dist/kysely.cjs +10 -13
  124. package/dist/kysely.cjs.map +1 -1
  125. package/dist/kysely.d.cts +10 -14
  126. package/dist/kysely.d.cts.map +1 -1
  127. package/dist/kysely.d.mts +10 -14
  128. package/dist/kysely.d.mts.map +1 -1
  129. package/dist/kysely.mjs +10 -14
  130. package/dist/kysely.mjs.map +1 -1
  131. package/dist/logger.cjs +3 -4
  132. package/dist/logger.cjs.map +1 -1
  133. package/dist/logger.d.cts +1 -5
  134. package/dist/logger.d.cts.map +1 -1
  135. package/dist/logger.d.mts +1 -5
  136. package/dist/logger.d.mts.map +1 -1
  137. package/dist/logger.mjs +1 -2
  138. package/dist/logger.mjs.map +1 -1
  139. package/dist/objection.cjs +10 -13
  140. package/dist/objection.cjs.map +1 -1
  141. package/dist/objection.d.cts +10 -14
  142. package/dist/objection.d.cts.map +1 -1
  143. package/dist/objection.d.mts +10 -14
  144. package/dist/objection.d.mts.map +1 -1
  145. package/dist/objection.mjs +10 -14
  146. package/dist/objection.mjs.map +1 -1
  147. package/dist/os/directory.cjs +31 -2
  148. package/dist/os/directory.cjs.map +1 -0
  149. package/dist/os/directory.d.cts +9 -2
  150. package/dist/os/directory.d.cts.map +1 -0
  151. package/dist/os/directory.d.mts +9 -2
  152. package/dist/os/directory.d.mts.map +1 -0
  153. package/dist/os/directory.mjs +25 -2
  154. package/dist/os/directory.mjs.map +1 -0
  155. package/dist/os/index.cjs +3 -3
  156. package/dist/os/index.d.cts +1 -1
  157. package/dist/os/index.d.mts +1 -1
  158. package/dist/os/index.mjs +2 -3
  159. package/dist/requestContext.cjs +10 -11
  160. package/dist/requestContext.cjs.map +1 -1
  161. package/dist/requestContext.d.cts +4 -8
  162. package/dist/requestContext.d.cts.map +1 -1
  163. package/dist/requestContext.d.mts +4 -8
  164. package/dist/requestContext.d.mts.map +1 -1
  165. package/dist/requestContext.mjs +1 -2
  166. package/dist/requestContext.mjs.map +1 -1
  167. package/dist/{chunk-CUT6urMc.cjs → rolldown-runtime-VH7oDXx4.cjs} +8 -10
  168. package/dist/timer.cjs +2 -2
  169. package/dist/timer.cjs.map +1 -1
  170. package/dist/timer.d.cts +1 -4
  171. package/dist/timer.d.cts.map +1 -1
  172. package/dist/timer.d.mts +1 -4
  173. package/dist/timer.d.mts.map +1 -1
  174. package/dist/timer.mjs +1 -1
  175. package/dist/timer.mjs.map +1 -1
  176. package/package.json +10 -8
  177. package/dist/Factory-BFVnMMCC.mjs +0 -51
  178. package/dist/Factory-BFVnMMCC.mjs.map +0 -1
  179. package/dist/Factory-BhjUOBWN.cjs +0 -57
  180. package/dist/Factory-BhjUOBWN.cjs.map +0 -1
  181. package/dist/Factory-Bx0AJXZB.d.cts +0 -147
  182. package/dist/Factory-Bx0AJXZB.d.cts.map +0 -1
  183. package/dist/Factory-C6W78ulZ.d.mts +0 -147
  184. package/dist/Factory-C6W78ulZ.d.mts.map +0 -1
  185. package/dist/KyselyFactory-BFqVIn_0.cjs +0 -246
  186. package/dist/KyselyFactory-BFqVIn_0.cjs.map +0 -1
  187. package/dist/KyselyFactory-Cc2UmOJk.d.mts +0 -228
  188. package/dist/KyselyFactory-Cc2UmOJk.d.mts.map +0 -1
  189. package/dist/KyselyFactory-DMswpwji.mjs +0 -241
  190. package/dist/KyselyFactory-DMswpwji.mjs.map +0 -1
  191. package/dist/KyselyFactory-KLeKH43i.d.cts +0 -228
  192. package/dist/KyselyFactory-KLeKH43i.d.cts.map +0 -1
  193. package/dist/ObjectionFactory-BYnPr9ZP.d.mts +0 -241
  194. package/dist/ObjectionFactory-BYnPr9ZP.d.mts.map +0 -1
  195. package/dist/ObjectionFactory-BeFBYcan.cjs +0 -272
  196. package/dist/ObjectionFactory-BeFBYcan.cjs.map +0 -1
  197. package/dist/ObjectionFactory-QCJ7u0Ql.mjs +0 -267
  198. package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +0 -1
  199. package/dist/ObjectionFactory-aMGvAKt9.d.cts +0 -241
  200. package/dist/ObjectionFactory-aMGvAKt9.d.cts.map +0 -1
  201. package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts +0 -84
  202. package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts.map +0 -1
  203. package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs +0 -101
  204. package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs.map +0 -1
  205. package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts +0 -84
  206. package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts.map +0 -1
  207. package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs +0 -95
  208. package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs.map +0 -1
  209. package/dist/PostgresMigrator-C_QQ6q35.d.mts.map +0 -1
  210. package/dist/PostgresMigrator-CeYy-eHF.d.cts.map +0 -1
  211. package/dist/PostgresMigrator-DVAY04qN.mjs +0 -166
  212. package/dist/PostgresMigrator-DVAY04qN.mjs.map +0 -1
  213. package/dist/PostgresMigrator-M9jpzOvN.cjs +0 -172
  214. package/dist/PostgresMigrator-M9jpzOvN.cjs.map +0 -1
  215. package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts +0 -79
  216. package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts.map +0 -1
  217. package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts +0 -79
  218. package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts.map +0 -1
  219. package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs +0 -123
  220. package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs.map +0 -1
  221. package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs +0 -118
  222. package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs.map +0 -1
  223. package/dist/VitestKyselyTransactionIsolator-1Saieke7.mjs +0 -67
  224. package/dist/VitestKyselyTransactionIsolator-1Saieke7.mjs.map +0 -1
  225. package/dist/VitestKyselyTransactionIsolator-BjJSXryR.cjs +0 -72
  226. package/dist/VitestKyselyTransactionIsolator-BjJSXryR.cjs.map +0 -1
  227. package/dist/VitestKyselyTransactionIsolator-CwlTo6yf.d.mts +0 -64
  228. package/dist/VitestKyselyTransactionIsolator-CwlTo6yf.d.mts.map +0 -1
  229. package/dist/VitestKyselyTransactionIsolator-DJasVuIZ.d.cts +0 -64
  230. package/dist/VitestKyselyTransactionIsolator-DJasVuIZ.d.cts.map +0 -1
  231. package/dist/VitestObjectionTransactionIsolator-B_VSWFum.mjs +0 -63
  232. package/dist/VitestObjectionTransactionIsolator-B_VSWFum.mjs.map +0 -1
  233. package/dist/VitestObjectionTransactionIsolator-CTTjvTPO.d.cts +0 -60
  234. package/dist/VitestObjectionTransactionIsolator-CTTjvTPO.d.cts.map +0 -1
  235. package/dist/VitestObjectionTransactionIsolator-CyZG6nq4.d.mts +0 -60
  236. package/dist/VitestObjectionTransactionIsolator-CyZG6nq4.d.mts.map +0 -1
  237. package/dist/VitestObjectionTransactionIsolator-DDoJTu7e.cjs +0 -68
  238. package/dist/VitestObjectionTransactionIsolator-DDoJTu7e.cjs.map +0 -1
  239. package/dist/VitestTransactionIsolator-BLaw80cx.d.mts +0 -223
  240. package/dist/VitestTransactionIsolator-BLaw80cx.d.mts.map +0 -1
  241. package/dist/VitestTransactionIsolator-CvwPecpl.mjs +0 -188
  242. package/dist/VitestTransactionIsolator-CvwPecpl.mjs.map +0 -1
  243. package/dist/VitestTransactionIsolator-DyiX-QtK.cjs +0 -206
  244. package/dist/VitestTransactionIsolator-DyiX-QtK.cjs.map +0 -1
  245. package/dist/VitestTransactionIsolator-glcxyS_R.d.cts +0 -223
  246. package/dist/VitestTransactionIsolator-glcxyS_R.d.cts.map +0 -1
  247. package/dist/directory-BxjqmtCT.mjs +0 -27
  248. package/dist/directory-BxjqmtCT.mjs.map +0 -1
  249. package/dist/directory-C6DuuNyc.d.cts +0 -13
  250. package/dist/directory-C6DuuNyc.d.cts.map +0 -1
  251. package/dist/directory-DD_xQoSh.cjs +0 -33
  252. package/dist/directory-DD_xQoSh.cjs.map +0 -1
  253. package/dist/directory-DiQ_DkaF.d.mts +0 -13
  254. package/dist/directory-DiQ_DkaF.d.mts.map +0 -1
  255. package/dist/faker-B14IEMIN.cjs +0 -304
  256. package/dist/faker-B14IEMIN.cjs.map +0 -1
  257. package/dist/faker-BGKYFoCT.mjs +0 -262
  258. package/dist/faker-BGKYFoCT.mjs.map +0 -1
  259. package/dist/faker-BSH1EMtg.d.cts +0 -166
  260. package/dist/faker-BSH1EMtg.d.cts.map +0 -1
  261. package/dist/faker-D9gz7KjY.d.mts +0 -166
  262. package/dist/faker-D9gz7KjY.d.mts.map +0 -1
@@ -1,4 +1,66 @@
1
- import "./VitestTransactionIsolator-CvwPecpl.mjs";
2
- import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-1Saieke7.mjs";
1
+ import { VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator.mjs";
2
+ //#region src/VitestKyselyTransactionIsolator.ts
3
+ /**
4
+ * Kysely-specific implementation of the Vitest transaction isolator.
5
+ * Provides automatic transaction rollback for test isolation using Kysely's transaction API.
6
+ * Each test runs within a database transaction that is rolled back after completion,
7
+ * ensuring a clean state between tests without the overhead of recreating data.
8
+ *
9
+ * @template Database - The database schema type
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';
14
+ * import { db } from './database';
15
+ *
16
+ * // Create isolator instance
17
+ * const isolator = new VitestKyselyTransactionIsolator<Database>();
18
+ *
19
+ * // In your test setup
20
+ * beforeEach(async () => {
21
+ * await isolator.start(db);
22
+ * });
23
+ *
24
+ * afterEach(async () => {
25
+ * await isolator.rollback();
26
+ * });
27
+ *
28
+ * // Tests run in isolated transactions
29
+ * it('should create user', async () => {
30
+ * const user = await db.insertInto('users')
31
+ * .values({ name: 'Test User' })
32
+ * .returningAll()
33
+ * .executeTakeFirst();
34
+ *
35
+ * expect(user).toBeDefined();
36
+ * // This data will be rolled back after the test
37
+ * });
38
+ * ```
39
+ */
40
+ var VitestKyselyTransactionIsolator = class extends VitestPostgresTransactionIsolator {
41
+ /**
42
+ * Closes the pool. Safe to implement now that it runs in the file's
43
+ * teardown rather than after every test, where it would have closed the
44
+ * connection the next test was about to use.
45
+ */
46
+ async destroy(conn) {
47
+ return conn.destroy();
48
+ }
49
+ /**
50
+ * Creates a Kysely transaction with the specified isolation level.
51
+ * Implements the abstract transact method from VitestPostgresTransactionIsolator.
52
+ *
53
+ * @param conn - The Kysely database connection
54
+ * @param level - The transaction isolation level
55
+ * @param fn - The function to execute within the transaction
56
+ * @returns Promise that resolves when the transaction completes
57
+ */
58
+ async transact(conn, level, fn) {
59
+ const isolationLevel = level.toLocaleLowerCase();
60
+ await conn.transaction().setIsolationLevel(isolationLevel).execute(fn);
61
+ }
62
+ };
63
+ //#endregion
64
+ export { VitestKyselyTransactionIsolator };
3
65
 
4
- export { VitestKyselyTransactionIsolator };
66
+ //# sourceMappingURL=VitestKyselyTransactionIsolator.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VitestKyselyTransactionIsolator.mjs","names":[],"sources":["../src/VitestKyselyTransactionIsolator.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport {\n\ttype IsolationLevel,\n\tVitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Kysely's transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @template Database - The database schema type\n *\n * @example\n * ```typescript\n * import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';\n * import { db } from './database';\n *\n * // Create isolator instance\n * const isolator = new VitestKyselyTransactionIsolator<Database>();\n *\n * // In your test setup\n * beforeEach(async () => {\n * await isolator.start(db);\n * });\n *\n * afterEach(async () => {\n * await isolator.rollback();\n * });\n *\n * // Tests run in isolated transactions\n * it('should create user', async () => {\n * const user = await db.insertInto('users')\n * .values({ name: 'Test User' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestKyselyTransactionIsolator<\n\tDatabase,\n> extends VitestPostgresTransactionIsolator<\n\tKysely<Database>,\n\tTransaction<Database>\n> {\n\t/**\n\t * Closes the pool. Safe to implement now that it runs in the file's\n\t * teardown rather than after every test, where it would have closed the\n\t * connection the next test was about to use.\n\t */\n\tasync destroy(conn: Kysely<Database>): Promise<void> {\n\t\treturn conn.destroy();\n\t}\n\t/**\n\t * Creates a Kysely transaction with the specified isolation level.\n\t * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n\t *\n\t * @param conn - The Kysely database connection\n\t * @param level - The transaction isolation level\n\t * @param fn - The function to execute within the transaction\n\t * @returns Promise that resolves when the transaction completes\n\t */\n\tasync transact(\n\t\tconn: Kysely<Database>,\n\t\tlevel: IsolationLevel,\n\t\tfn: (trx: Transaction<Database>) => Promise<void>,\n\t): Promise<void> {\n\t\tconst isolationLevel =\n\t\t\tlevel.toLocaleLowerCase() as Lowercase<IsolationLevel>;\n\t\tawait conn.transaction().setIsolationLevel(isolationLevel).execute(fn);\n\t}\n\t// Implement any Kysely-specific transaction logic here\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,kCAAb,cAEU,kCAGR;;;;;;CAMD,MAAM,QAAQ,MAAuC;EACpD,OAAO,KAAK,QAAQ;CACrB;;;;;;;;;;CAUA,MAAM,SACL,MACA,OACA,IACgB;EAChB,MAAM,iBACL,MAAM,kBAAkB;EACzB,MAAM,KAAK,YAAY,CAAC,CAAC,kBAAkB,cAAc,CAAC,CAAC,QAAQ,EAAE;CACtE;AAED"}
@@ -1,4 +1,63 @@
1
- require('./VitestTransactionIsolator-DyiX-QtK.cjs');
2
- const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-DDoJTu7e.cjs');
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_VitestTransactionIsolator = require("./VitestTransactionIsolator.cjs");
3
+ //#region src/VitestObjectionTransactionIsolator.ts
4
+ /**
5
+ * Objection.js-specific implementation of the Vitest transaction isolator.
6
+ * Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.
7
+ * Each test runs within a database transaction that is rolled back after completion,
8
+ * ensuring a clean state between tests without the overhead of recreating data.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';
13
+ * import { knex } from './database';
14
+ * import { User } from './models';
15
+ * import { test } from 'vitest';
16
+ *
17
+ * // Create isolator instance
18
+ * const isolator = new VitestObjectionTransactionIsolator(test);
19
+ *
20
+ * // Use with wrapped test API
21
+ * const isolatedTest = isolator.wrapVitestWithTransaction(knex);
22
+ *
23
+ * isolatedTest('should create user', async ({ trx }) => {
24
+ * const user = await User.query(trx)
25
+ * .insert({ name: 'Test User' });
26
+ *
27
+ * expect(user).toBeDefined();
28
+ * // This data will be rolled back after the test
29
+ * });
30
+ * ```
31
+ */
32
+ var VitestObjectionTransactionIsolator = class extends require_VitestTransactionIsolator.VitestPostgresTransactionIsolator {
33
+ async destroy(_conn) {}
34
+ /**
35
+ * Creates a Knex transaction with the specified isolation level.
36
+ * Implements the abstract transact method from VitestPostgresTransactionIsolator.
37
+ * This transaction can be used with Objection.js models via Model.query(trx).
38
+ *
39
+ * @param conn - The Knex database connection
40
+ * @param level - The transaction isolation level
41
+ * @param fn - The function to execute within the transaction
42
+ * @returns Promise that resolves when the transaction completes
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {
47
+ * // Use transaction with Objection models
48
+ * await User.query(trx).insert({ name: 'Test' });
49
+ * await Post.query(trx).where('userId', user.id).delete();
50
+ * });
51
+ * ```
52
+ */
53
+ async transact(connection, level, fn) {
54
+ const isolationLevel = level.toLowerCase();
55
+ await connection.transaction(async (trx) => {
56
+ await fn(trx);
57
+ }, { isolationLevel });
58
+ }
59
+ };
60
+ //#endregion
61
+ exports.VitestObjectionTransactionIsolator = VitestObjectionTransactionIsolator;
3
62
 
4
- exports.VitestObjectionTransactionIsolator = require_VitestObjectionTransactionIsolator.VitestObjectionTransactionIsolator;
63
+ //# sourceMappingURL=VitestObjectionTransactionIsolator.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VitestObjectionTransactionIsolator.cjs","names":["VitestPostgresTransactionIsolator"],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport {\n\ttype IsolationLevel,\n\tVitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @example\n * ```typescript\n * import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';\n * import { knex } from './database';\n * import { User } from './models';\n * import { test } from 'vitest';\n *\n * // Create isolator instance\n * const isolator = new VitestObjectionTransactionIsolator(test);\n *\n * // Use with wrapped test API\n * const isolatedTest = isolator.wrapVitestWithTransaction(knex);\n *\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User' });\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<\n\tKnex,\n\tKnex.Transaction\n> {\n\tasync destroy(_conn: Knex<any, any[]>): Promise<void> {}\n\t/**\n\t * Creates a Knex transaction with the specified isolation level.\n\t * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n\t * This transaction can be used with Objection.js models via Model.query(trx).\n\t *\n\t * @param conn - The Knex database connection\n\t * @param level - The transaction isolation level\n\t * @param fn - The function to execute within the transaction\n\t * @returns Promise that resolves when the transaction completes\n\t *\n\t * @example\n\t * ```typescript\n\t * await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {\n\t * // Use transaction with Objection models\n\t * await User.query(trx).insert({ name: 'Test' });\n\t * await Post.query(trx).where('userId', user.id).delete();\n\t * });\n\t * ```\n\t */\n\tasync transact(\n\t\tconnection: Knex,\n\t\tlevel: IsolationLevel,\n\t\tfn: (trx: Knex.Transaction) => Promise<void>,\n\t): Promise<void> {\n\t\tconst isolationLevel = level.toLowerCase() as Lowercase<IsolationLevel>;\n\n\t\tawait connection.transaction(\n\t\t\tasync (trx) => {\n\t\t\t\tawait fn(trx);\n\t\t\t},\n\t\t\t{\n\t\t\t\tisolationLevel,\n\t\t\t},\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,qCAAb,cAAwDA,kCAAAA,kCAGtD;CACD,MAAM,QAAQ,OAAwC,CAAC;;;;;;;;;;;;;;;;;;;;CAoBvD,MAAM,SACL,YACA,OACA,IACgB;EAChB,MAAM,iBAAiB,MAAM,YAAY;EAEzC,MAAM,WAAW,YAChB,OAAO,QAAQ;GACd,MAAM,GAAG,GAAG;EACb,GACA,EACC,eACD,CACD;CACD;AACD"}
@@ -1,3 +1,56 @@
1
- import "./VitestTransactionIsolator-glcxyS_R.cjs";
2
- import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-CTTjvTPO.cjs";
3
- export { VitestObjectionTransactionIsolator };
1
+ import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator.cjs";
2
+ import { Knex } from "knex";
3
+ //#region src/VitestObjectionTransactionIsolator.d.ts
4
+ /**
5
+ * Objection.js-specific implementation of the Vitest transaction isolator.
6
+ * Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.
7
+ * Each test runs within a database transaction that is rolled back after completion,
8
+ * ensuring a clean state between tests without the overhead of recreating data.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';
13
+ * import { knex } from './database';
14
+ * import { User } from './models';
15
+ * import { test } from 'vitest';
16
+ *
17
+ * // Create isolator instance
18
+ * const isolator = new VitestObjectionTransactionIsolator(test);
19
+ *
20
+ * // Use with wrapped test API
21
+ * const isolatedTest = isolator.wrapVitestWithTransaction(knex);
22
+ *
23
+ * isolatedTest('should create user', async ({ trx }) => {
24
+ * const user = await User.query(trx)
25
+ * .insert({ name: 'Test User' });
26
+ *
27
+ * expect(user).toBeDefined();
28
+ * // This data will be rolled back after the test
29
+ * });
30
+ * ```
31
+ */
32
+ export declare class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<Knex, Knex.Transaction> {
33
+ destroy(_conn: Knex<any, any[]>): Promise<void>;
34
+ /**
35
+ * Creates a Knex transaction with the specified isolation level.
36
+ * Implements the abstract transact method from VitestPostgresTransactionIsolator.
37
+ * This transaction can be used with Objection.js models via Model.query(trx).
38
+ *
39
+ * @param conn - The Knex database connection
40
+ * @param level - The transaction isolation level
41
+ * @param fn - The function to execute within the transaction
42
+ * @returns Promise that resolves when the transaction completes
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {
47
+ * // Use transaction with Objection models
48
+ * await User.query(trx).insert({ name: 'Test' });
49
+ * await Post.query(trx).where('userId', user.id).delete();
50
+ * });
51
+ * ```
52
+ */
53
+ transact(connection: Knex, level: IsolationLevel, fn: (trx: Knex.Transaction) => Promise<void>): Promise<void>;
54
+ }
55
+ //#endregion
56
+ //# sourceMappingURL=VitestObjectionTransactionIsolator.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VitestObjectionTransactionIsolator.d.cts","names":[],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAkCa,2CAA2C,kCACvD,MACA,KAAK;EAEC,QAAQ,OAAO,mBAAmB;;;;;;;;;;;;;;;;;;;;EAoBlC,SACL,YAAY,MACZ,OAAO,gBACP,KAAK,KAAK,KAAK,gBAAgB,gBAC7B"}
@@ -1,3 +1,56 @@
1
- import "./VitestTransactionIsolator-BLaw80cx.mjs";
2
- import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-CyZG6nq4.mjs";
3
- export { VitestObjectionTransactionIsolator };
1
+ import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator.mjs";
2
+ import { Knex } from "knex";
3
+ //#region src/VitestObjectionTransactionIsolator.d.ts
4
+ /**
5
+ * Objection.js-specific implementation of the Vitest transaction isolator.
6
+ * Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.
7
+ * Each test runs within a database transaction that is rolled back after completion,
8
+ * ensuring a clean state between tests without the overhead of recreating data.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';
13
+ * import { knex } from './database';
14
+ * import { User } from './models';
15
+ * import { test } from 'vitest';
16
+ *
17
+ * // Create isolator instance
18
+ * const isolator = new VitestObjectionTransactionIsolator(test);
19
+ *
20
+ * // Use with wrapped test API
21
+ * const isolatedTest = isolator.wrapVitestWithTransaction(knex);
22
+ *
23
+ * isolatedTest('should create user', async ({ trx }) => {
24
+ * const user = await User.query(trx)
25
+ * .insert({ name: 'Test User' });
26
+ *
27
+ * expect(user).toBeDefined();
28
+ * // This data will be rolled back after the test
29
+ * });
30
+ * ```
31
+ */
32
+ export declare class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<Knex, Knex.Transaction> {
33
+ destroy(_conn: Knex<any, any[]>): Promise<void>;
34
+ /**
35
+ * Creates a Knex transaction with the specified isolation level.
36
+ * Implements the abstract transact method from VitestPostgresTransactionIsolator.
37
+ * This transaction can be used with Objection.js models via Model.query(trx).
38
+ *
39
+ * @param conn - The Knex database connection
40
+ * @param level - The transaction isolation level
41
+ * @param fn - The function to execute within the transaction
42
+ * @returns Promise that resolves when the transaction completes
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {
47
+ * // Use transaction with Objection models
48
+ * await User.query(trx).insert({ name: 'Test' });
49
+ * await Post.query(trx).where('userId', user.id).delete();
50
+ * });
51
+ * ```
52
+ */
53
+ transact(connection: Knex, level: IsolationLevel, fn: (trx: Knex.Transaction) => Promise<void>): Promise<void>;
54
+ }
55
+ //#endregion
56
+ //# sourceMappingURL=VitestObjectionTransactionIsolator.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VitestObjectionTransactionIsolator.d.mts","names":[],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAkCa,2CAA2C,kCACvD,MACA,KAAK;EAEC,QAAQ,OAAO,mBAAmB;;;;;;;;;;;;;;;;;;;;EAoBlC,SACL,YAAY,MACZ,OAAO,gBACP,KAAK,KAAK,KAAK,gBAAgB,gBAC7B"}
@@ -1,4 +1,62 @@
1
- import "./VitestTransactionIsolator-CvwPecpl.mjs";
2
- import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-B_VSWFum.mjs";
1
+ import { VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator.mjs";
2
+ //#region src/VitestObjectionTransactionIsolator.ts
3
+ /**
4
+ * Objection.js-specific implementation of the Vitest transaction isolator.
5
+ * Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.
6
+ * Each test runs within a database transaction that is rolled back after completion,
7
+ * ensuring a clean state between tests without the overhead of recreating data.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';
12
+ * import { knex } from './database';
13
+ * import { User } from './models';
14
+ * import { test } from 'vitest';
15
+ *
16
+ * // Create isolator instance
17
+ * const isolator = new VitestObjectionTransactionIsolator(test);
18
+ *
19
+ * // Use with wrapped test API
20
+ * const isolatedTest = isolator.wrapVitestWithTransaction(knex);
21
+ *
22
+ * isolatedTest('should create user', async ({ trx }) => {
23
+ * const user = await User.query(trx)
24
+ * .insert({ name: 'Test User' });
25
+ *
26
+ * expect(user).toBeDefined();
27
+ * // This data will be rolled back after the test
28
+ * });
29
+ * ```
30
+ */
31
+ var VitestObjectionTransactionIsolator = class extends VitestPostgresTransactionIsolator {
32
+ async destroy(_conn) {}
33
+ /**
34
+ * Creates a Knex transaction with the specified isolation level.
35
+ * Implements the abstract transact method from VitestPostgresTransactionIsolator.
36
+ * This transaction can be used with Objection.js models via Model.query(trx).
37
+ *
38
+ * @param conn - The Knex database connection
39
+ * @param level - The transaction isolation level
40
+ * @param fn - The function to execute within the transaction
41
+ * @returns Promise that resolves when the transaction completes
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {
46
+ * // Use transaction with Objection models
47
+ * await User.query(trx).insert({ name: 'Test' });
48
+ * await Post.query(trx).where('userId', user.id).delete();
49
+ * });
50
+ * ```
51
+ */
52
+ async transact(connection, level, fn) {
53
+ const isolationLevel = level.toLowerCase();
54
+ await connection.transaction(async (trx) => {
55
+ await fn(trx);
56
+ }, { isolationLevel });
57
+ }
58
+ };
59
+ //#endregion
60
+ export { VitestObjectionTransactionIsolator };
3
61
 
4
- export { VitestObjectionTransactionIsolator };
62
+ //# sourceMappingURL=VitestObjectionTransactionIsolator.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VitestObjectionTransactionIsolator.mjs","names":[],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport {\n\ttype IsolationLevel,\n\tVitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @example\n * ```typescript\n * import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';\n * import { knex } from './database';\n * import { User } from './models';\n * import { test } from 'vitest';\n *\n * // Create isolator instance\n * const isolator = new VitestObjectionTransactionIsolator(test);\n *\n * // Use with wrapped test API\n * const isolatedTest = isolator.wrapVitestWithTransaction(knex);\n *\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User' });\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<\n\tKnex,\n\tKnex.Transaction\n> {\n\tasync destroy(_conn: Knex<any, any[]>): Promise<void> {}\n\t/**\n\t * Creates a Knex transaction with the specified isolation level.\n\t * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n\t * This transaction can be used with Objection.js models via Model.query(trx).\n\t *\n\t * @param conn - The Knex database connection\n\t * @param level - The transaction isolation level\n\t * @param fn - The function to execute within the transaction\n\t * @returns Promise that resolves when the transaction completes\n\t *\n\t * @example\n\t * ```typescript\n\t * await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {\n\t * // Use transaction with Objection models\n\t * await User.query(trx).insert({ name: 'Test' });\n\t * await Post.query(trx).where('userId', user.id).delete();\n\t * });\n\t * ```\n\t */\n\tasync transact(\n\t\tconnection: Knex,\n\t\tlevel: IsolationLevel,\n\t\tfn: (trx: Knex.Transaction) => Promise<void>,\n\t): Promise<void> {\n\t\tconst isolationLevel = level.toLowerCase() as Lowercase<IsolationLevel>;\n\n\t\tawait connection.transaction(\n\t\t\tasync (trx) => {\n\t\t\t\tawait fn(trx);\n\t\t\t},\n\t\t\t{\n\t\t\t\tisolationLevel,\n\t\t\t},\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,qCAAb,cAAwD,kCAGtD;CACD,MAAM,QAAQ,OAAwC,CAAC;;;;;;;;;;;;;;;;;;;;CAoBvD,MAAM,SACL,YACA,OACA,IACgB;EAChB,MAAM,iBAAiB,MAAM,YAAY;EAEzC,MAAM,WAAW,YAChB,OAAO,QAAQ;GACd,MAAM,GAAG,GAAG;EACb,GACA,EACC,eACD,CACD;CACD;AACD"}
@@ -1,5 +1,188 @@
1
- const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-DyiX-QtK.cjs');
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _geekmidas_envkit = require("@geekmidas/envkit");
3
+ let _geekmidas_services = require("@geekmidas/services");
4
+ //#region src/VitestTransactionIsolator.ts
5
+ /**
6
+ * PostgreSQL transaction isolation levels.
7
+ * Controls the visibility of concurrent transactions.
8
+ *
9
+ * @see https://www.postgresql.org/docs/current/transaction-iso.html
10
+ */
11
+ let IsolationLevel = /* @__PURE__ */ function(IsolationLevel) {
12
+ /**
13
+ * Lowest isolation level. Allows dirty reads.
14
+ * Not recommended for testing.
15
+ */
16
+ IsolationLevel["READ_UNCOMMITTED"] = "READ UNCOMMITTED";
17
+ /**
18
+ * Default PostgreSQL isolation level.
19
+ * Prevents dirty reads but allows non-repeatable reads.
20
+ */
21
+ IsolationLevel["READ_COMMITTED"] = "READ COMMITTED";
22
+ /**
23
+ * Prevents dirty reads and non-repeatable reads.
24
+ * Recommended for most test scenarios.
25
+ */
26
+ IsolationLevel["REPEATABLE_READ"] = "REPEATABLE READ";
27
+ /**
28
+ * Highest isolation level. Prevents all phenomena.
29
+ * May cause performance overhead in tests.
30
+ */
31
+ IsolationLevel["SERIALIZABLE"] = "SERIALIZABLE";
32
+ return IsolationLevel;
33
+ }({});
34
+ /**
35
+ * Abstract base class for implementing database transaction isolation in Vitest tests.
36
+ * Provides automatic transaction rollback after each test to maintain test isolation.
37
+ * Subclasses must implement the transact() method for their specific database driver.
38
+ *
39
+ * @template TConn - The database connection type
40
+ * @template Transaction - The transaction type
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * // Implement for your database driver
45
+ * class MyDatabaseIsolator extends VitestPostgresTransactionIsolator<MyDB, MyTx> {
46
+ * async transact(conn: MyDB, level: IsolationLevel, fn: (tx: MyTx) => Promise<void>) {
47
+ * await conn.transaction(level, fn);
48
+ * }
49
+ * }
50
+ *
51
+ * // Use in tests
52
+ * const isolator = new MyDatabaseIsolator(test);
53
+ * const isolatedTest = isolator.wrapVitestWithTransaction(db);
54
+ *
55
+ * isolatedTest('should create user', async ({ trx }) => {
56
+ * await trx.insert('users', { name: 'Test' });
57
+ * // Data is automatically rolled back after test
58
+ * });
59
+ * ```
60
+ */
61
+ var VitestPostgresTransactionIsolator = class {
62
+ api;
63
+ /**
64
+ * Creates a new VitestPostgresTransactionIsolator instance.
65
+ *
66
+ * @param api - The Vitest test API (usually the `test` export from vitest)
67
+ */
68
+ constructor(api) {
69
+ this.api = api;
70
+ }
71
+ /**
72
+ * Creates a wrapped version of Vitest's test API that provides transaction isolation.
73
+ * Each test will run within a database transaction that is automatically rolled back.
74
+ *
75
+ * @param options - Configuration options for transaction wrapping
76
+ * @returns A wrapped test API with transaction support
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const isolatedTest = isolator.wrapVitestWithTransaction({
81
+ * connection: db,
82
+ * setup: async (trx) => {
83
+ * await trx.insert('settings', { key: 'test', value: 'true' });
84
+ * },
85
+ * fixtures: {
86
+ * factory: (trx) => new Factory(trx),
87
+ * },
88
+ * });
89
+ *
90
+ * isolatedTest('test with transaction', async ({ trx, factory }) => {
91
+ * const user = await factory.insert('user', { name: 'Test' });
92
+ * expect(user).toBeDefined();
93
+ * });
94
+ * ```
95
+ */
96
+ wrapVitestWithTransaction(options) {
97
+ const { connection, setup, isolationLevel = "REPEATABLE READ", fixtures } = options;
98
+ let resolved;
99
+ const resolveConnection = async () => {
100
+ if (resolved === void 0) resolved = await (isConstruct(connection) ? connection.service.register({
101
+ envParser: new _geekmidas_envkit.EnvironmentParser({ ...process.env }),
102
+ context: _geekmidas_services.serviceContext
103
+ }) : connection());
104
+ return resolved;
105
+ };
106
+ const additionalFixtures = {};
107
+ if (fixtures) for (const [key, creator] of Object.entries(fixtures)) additionalFixtures[key] = async ({ trx }, use) => {
108
+ await use(await creator(trx));
109
+ };
110
+ return this.api.extend({
111
+ trx: async ({}, use) => {
112
+ class TestRollback extends Error {
113
+ constructor() {
114
+ super("Test rollback");
115
+ this.name = "TestRollback";
116
+ }
117
+ }
118
+ let testError;
119
+ const conn = await resolveConnection();
120
+ try {
121
+ await this.transact(conn, isolationLevel, async (transaction) => {
122
+ try {
123
+ await setup?.(transaction);
124
+ await use(transaction);
125
+ } catch (error) {
126
+ testError = error;
127
+ }
128
+ throw new TestRollback();
129
+ });
130
+ } catch (error) {
131
+ if (!(error instanceof TestRollback)) throw error;
132
+ if (testError) throw testError;
133
+ }
134
+ },
135
+ ...additionalFixtures
136
+ });
137
+ }
138
+ };
139
+ /** A construct is distinguished from a factory by owning a service. */
140
+ function isConstruct(connection) {
141
+ return typeof connection !== "function";
142
+ }
143
+ /**
144
+ * Extends a wrapped test API with additional fixtures that depend on the transaction.
145
+ * This allows composing test context with factories, repositories, or other helpers.
146
+ *
147
+ * @template Transaction - The transaction type
148
+ * @template Extended - The type of additional context to provide
149
+ * @param wrappedTest - The base wrapped test from wrapVitestWithTransaction
150
+ * @param fixtures - Object mapping fixture names to creator functions
151
+ * @returns An extended test API with both trx and the additional fixtures
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * import { wrapVitestKyselyTransaction, extendWithFixtures } from '@geekmidas/testkit/kysely';
156
+ *
157
+ * // Create base wrapped test
158
+ * const baseTest = wrapVitestKyselyTransaction(test, {
159
+ * connection: db,
160
+ * setup: createTestTables,
161
+ * });
162
+ *
163
+ * // Extend with fixtures
164
+ * const it = extendWithFixtures(baseTest, {
165
+ * factory: (trx) => new KyselyFactory(builders, seeds, trx),
166
+ * userRepo: (trx) => new UserRepository(trx),
167
+ * });
168
+ *
169
+ * // Use in tests - trx and all fixtures are available
170
+ * it('should create user with factory', async ({ trx, factory, userRepo }) => {
171
+ * const user = await factory.insert('user', { name: 'Test' });
172
+ * expect(user).toBeDefined();
173
+ * });
174
+ * ```
175
+ */
176
+ function extendWithFixtures(wrappedTest, fixtures) {
177
+ const fixtureDefinitions = {};
178
+ for (const [key, creator] of Object.entries(fixtures)) fixtureDefinitions[key] = async ({ trx }, use) => {
179
+ await use(await creator(trx));
180
+ };
181
+ return wrappedTest.extend(fixtureDefinitions);
182
+ }
183
+ //#endregion
184
+ exports.IsolationLevel = IsolationLevel;
185
+ exports.VitestPostgresTransactionIsolator = VitestPostgresTransactionIsolator;
186
+ exports.extendWithFixtures = extendWithFixtures;
2
187
 
3
- exports.IsolationLevel = require_VitestTransactionIsolator.IsolationLevel;
4
- exports.VitestPostgresTransactionIsolator = require_VitestTransactionIsolator.VitestPostgresTransactionIsolator;
5
- exports.extendWithFixtures = require_VitestTransactionIsolator.extendWithFixtures;
188
+ //# sourceMappingURL=VitestTransactionIsolator.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VitestTransactionIsolator.cjs","names":["EnvironmentParser","serviceContext"],"sources":["../src/VitestTransactionIsolator.ts"],"sourcesContent":["import { EnvironmentParser } from '@geekmidas/envkit';\nimport { type Service, serviceContext } from '@geekmidas/services';\nimport type { TestAPI } from 'vitest';\n\n/**\n * Type definition for test fixtures that provide transaction access.\n * Used with Vitest's test.extend() API to inject transactions into tests.\n *\n * @template Transaction - The transaction type specific to the database driver\n * @template Extended - Additional context properties provided by the extend function\n */\nexport interface DatabaseFixtures<Transaction, _Extended = object> {\n\t/**\n\t * The database transaction available to the test.\n\t * All database operations should use this transaction to ensure proper rollback.\n\t */\n\ttrx: Transaction;\n}\n\n/**\n * Combined fixtures type that merges the base transaction fixture with extended context.\n */\nexport type ExtendedDatabaseFixtures<\n\tTransaction,\n\tExtended = object,\n> = DatabaseFixtures<Transaction> & Extended;\n\n/**\n * Function type for extending test context with additional properties.\n * Receives the transaction and returns additional context to be merged with { trx }.\n *\n * @template Transaction - The transaction type\n * @template Extended - The type of additional context to provide\n *\n * @example\n * ```typescript\n * const extendContext: ExtendContextFn<Transaction<DB>, { factory: KyselyFactory }> =\n * (trx) => ({ factory: new KyselyFactory(builders, seeds, trx) });\n * ```\n */\nexport type ExtendContextFn<Transaction, Extended> = (\n\ttrx: Transaction,\n) => Extended | Promise<Extended>;\n\n/**\n * PostgreSQL transaction isolation levels.\n * Controls the visibility of concurrent transactions.\n *\n * @see https://www.postgresql.org/docs/current/transaction-iso.html\n */\nexport enum IsolationLevel {\n\t/**\n\t * Lowest isolation level. Allows dirty reads.\n\t * Not recommended for testing.\n\t */\n\tREAD_UNCOMMITTED = 'READ UNCOMMITTED',\n\t/**\n\t * Default PostgreSQL isolation level.\n\t * Prevents dirty reads but allows non-repeatable reads.\n\t */\n\tREAD_COMMITTED = 'READ COMMITTED',\n\t/**\n\t * Prevents dirty reads and non-repeatable reads.\n\t * Recommended for most test scenarios.\n\t */\n\tREPEATABLE_READ = 'REPEATABLE READ',\n\t/**\n\t * Highest isolation level. Prevents all phenomena.\n\t * May cause performance overhead in tests.\n\t */\n\tSERIALIZABLE = 'SERIALIZABLE',\n}\n\n/**\n * Abstract base class for implementing database transaction isolation in Vitest tests.\n * Provides automatic transaction rollback after each test to maintain test isolation.\n * Subclasses must implement the transact() method for their specific database driver.\n *\n * @template TConn - The database connection type\n * @template Transaction - The transaction type\n *\n * @example\n * ```typescript\n * // Implement for your database driver\n * class MyDatabaseIsolator extends VitestPostgresTransactionIsolator<MyDB, MyTx> {\n * async transact(conn: MyDB, level: IsolationLevel, fn: (tx: MyTx) => Promise<void>) {\n * await conn.transaction(level, fn);\n * }\n * }\n *\n * // Use in tests\n * const isolator = new MyDatabaseIsolator(test);\n * const isolatedTest = isolator.wrapVitestWithTransaction(db);\n *\n * isolatedTest('should create user', async ({ trx }) => {\n * await trx.insert('users', { name: 'Test' });\n * // Data is automatically rolled back after test\n * });\n * ```\n */\nexport abstract class VitestPostgresTransactionIsolator<TConn, Transaction> {\n\t/**\n\t * Abstract method to create a transaction with the specified isolation level.\n\t * Must be implemented by subclasses for specific database drivers.\n\t *\n\t * @param conn - The database connection\n\t * @param isolationLevel - The transaction isolation level\n\t * @param fn - The function to execute within the transaction\n\t * @returns Promise that resolves when the transaction completes\n\t */\n\tabstract transact(\n\t\tconn: TConn,\n\t\tisolationLevel: IsolationLevel,\n\t\tfn: (trx: Transaction) => Promise<void>,\n\t): Promise<void>;\n\n\tabstract destroy(conn: TConn): Promise<void>;\n\t/**\n\t * Creates a new VitestPostgresTransactionIsolator instance.\n\t *\n\t * @param api - The Vitest test API (usually the `test` export from vitest)\n\t */\n\tconstructor(private readonly api: TestAPI) {}\n\n\t/**\n\t * Creates a wrapped version of Vitest's test API that provides transaction isolation.\n\t * Each test will run within a database transaction that is automatically rolled back.\n\t *\n\t * @param options - Configuration options for transaction wrapping\n\t * @returns A wrapped test API with transaction support\n\t *\n\t * @example\n\t * ```typescript\n\t * const isolatedTest = isolator.wrapVitestWithTransaction({\n\t * connection: db,\n\t * setup: async (trx) => {\n\t * await trx.insert('settings', { key: 'test', value: 'true' });\n\t * },\n\t * fixtures: {\n\t * factory: (trx) => new Factory(trx),\n\t * },\n\t * });\n\t *\n\t * isolatedTest('test with transaction', async ({ trx, factory }) => {\n\t * const user = await factory.insert('user', { name: 'Test' });\n\t * expect(user).toBeDefined();\n\t * });\n\t * ```\n\t */\n\twrapVitestWithTransaction<Extended extends Record<string, unknown> = {}>(\n\t\toptions: TransactionWrapperOptions<TConn, Transaction, Extended>,\n\t) {\n\t\tconst {\n\t\t\tconnection,\n\t\t\tsetup,\n\t\t\tisolationLevel = IsolationLevel.REPEATABLE_READ,\n\t\t\tfixtures,\n\t\t} = options;\n\n\t\t// Resolved once per file, not once per test. The fixture below runs for\n\t\t// every test, and opening a pool each time leaves one connection per test\n\t\t// alive — a file of fifty tests exhausts the server.\n\t\tlet resolved: TConn | undefined;\n\t\tconst resolveConnection = async (): Promise<TConn> => {\n\t\t\tif (resolved === undefined) {\n\t\t\t\tresolved = await (isConstruct(connection)\n\t\t\t\t\t? connection.service.register({\n\t\t\t\t\t\t\t// Spread: `process.env` is a ProcessEnv, not a plain object.\n\t\t\t\t\t\t\tenvParser: new EnvironmentParser({ ...process.env }),\n\t\t\t\t\t\t\tcontext: serviceContext,\n\t\t\t\t\t\t})\n\t\t\t\t\t: connection());\n\t\t\t}\n\t\t\treturn resolved;\n\t\t};\n\n\t\t// Build fixture definitions for additional fixtures that depend on trx\n\t\tconst additionalFixtures: Record<string, unknown> = {};\n\t\tif (fixtures) {\n\t\t\tfor (const [key, creator] of Object.entries(fixtures)) {\n\t\t\t\tadditionalFixtures[key] = async (\n\t\t\t\t\t{ trx }: { trx: Transaction },\n\t\t\t\t\tuse: (value: unknown) => Promise<void>,\n\t\t\t\t) => {\n\t\t\t\t\tconst value = await (creator as (trx: Transaction) => unknown)(trx);\n\t\t\t\t\tawait use(value);\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\ttype CombinedFixtures = DatabaseFixtures<Transaction> & Extended;\n\n\t\t// Cast to bypass Vitest's strict fixture typing which can't infer\n\t\t// dynamically built fixture objects\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tconst api = this.api as TestAPI & {\n\t\t\textend: <T>(fixtures: any) => TestAPI<T>;\n\t\t};\n\n\t\treturn api.extend<CombinedFixtures>({\n\t\t\t// This fixture automatically provides a transaction to each test\n\t\t\t// biome-ignore lint/correctness/noEmptyPattern: this has to be like this to satisfy Biome\n\t\t\ttrx: async ({}: {}, use: (value: Transaction) => Promise<void>) => {\n\t\t\t\t// Create a custom error class for rollback\n\t\t\t\tclass TestRollback extends Error {\n\t\t\t\t\tconstructor() {\n\t\t\t\t\t\tsuper('Test rollback');\n\t\t\t\t\t\tthis.name = 'TestRollback';\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlet testError: Error | undefined;\n\t\t\t\tconst conn = await resolveConnection();\n\t\t\t\ttry {\n\t\t\t\t\tawait this.transact(conn, isolationLevel, async (transaction) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Provide the transaction to the test\n\t\t\t\t\t\t\tawait setup?.(transaction);\n\t\t\t\t\t\t\tawait use(transaction);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t// Capture any test errors\n\t\t\t\t\t\t\ttestError = error as Error;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Always throw to trigger rollback\n\t\t\t\t\t\tthrow new TestRollback();\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Only rethrow if it's not our rollback error\n\t\t\t\t\tif (!(error instanceof TestRollback)) {\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\n\t\t\t\t\t// If the test had an error, throw it now\n\t\t\t\t\tif (testError) {\n\t\t\t\t\t\tthrow testError;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\t...additionalFixtures,\n\t\t});\n\t}\n}\n\nexport type DatabaseConnectionFn<Conn> = () => Conn | Promise<Conn>;\n\n/**\n * Where a connection comes from: a construct, or a function returning one.\n *\n * A construct is preferred, because it builds the client through the same\n * `connect()` production uses. A hand-rolled client missing `CamelCasePlugin`\n * writes `createdAt` where the app writes `created_at`, and the test passes\n * while production does not. The URL is read from `process.env`.\n */\nexport type DatabaseConnection<Conn> =\n\t| DatabaseConnectionFn<Conn>\n\t| ConnectableConstruct<Conn>;\n\n/** A construct is distinguished from a factory by owning a service. */\nfunction isConstruct<Conn>(\n\tconnection: DatabaseConnection<Conn>,\n): connection is ConnectableConstruct<Conn> {\n\treturn typeof connection !== 'function';\n}\n\n/**\n * Options for wrapping Vitest tests with database transaction isolation.\n */\n/**\n * Anything that owns a service handing back a connection — a database\n * construct, structurally, so testkit depends on no construct package.\n */\nexport interface ConnectableConstruct<TConn> {\n\treadonly service: Service<string, TConn>;\n}\n\nexport interface TransactionWrapperOptions<\n\tTConn,\n\tTransaction,\n\tExtended extends Record<string, unknown> = {},\n> {\n\t/** Where the connection comes from — a construct, or a function returning one */\n\tconnection: DatabaseConnection<TConn>;\n\t/** Optional setup function to run within the transaction before each test */\n\tsetup?: (trx: Transaction) => Promise<void>;\n\t/** Transaction isolation level (defaults to REPEATABLE_READ) */\n\tisolationLevel?: IsolationLevel;\n\t/** Additional fixtures that depend on the transaction */\n\tfixtures?: FixtureCreators<Transaction, Extended>;\n}\n\n/**\n * Type for fixture creator functions that depend on the transaction.\n * Each function receives the transaction and returns the fixture value.\n */\nexport type FixtureCreators<\n\tTransaction,\n\tExtended extends Record<string, unknown>,\n> = {\n\t[K in keyof Extended]: (\n\t\ttrx: Transaction,\n\t) => Extended[K] | Promise<Extended[K]>;\n};\n\n/**\n * The test API returned by extendWithFixtures.\n * Provides access to both the transaction (trx) and all extended fixtures.\n *\n * @template Transaction - The transaction type\n * @template Extended - The type of additional fixtures provided\n * @template BaseTest - The base wrapped test type\n */\nexport type TestWithExtendedFixtures<\n\tTransaction,\n\tExtended extends Record<string, unknown>,\n\tBaseTest extends ReturnType<TestAPI['extend']> = ReturnType<\n\t\tTestAPI['extend']\n\t>,\n> = BaseTest & {\n\t<C extends object>(\n\t\tname: string,\n\t\tfn: (\n\t\t\tcontext: DatabaseFixtures<Transaction> & Extended & C,\n\t\t) => Promise<void>,\n\t): void;\n\t<C extends object>(\n\t\tname: string,\n\t\toptions: object,\n\t\tfn: (\n\t\t\tcontext: DatabaseFixtures<Transaction> & Extended & C,\n\t\t) => Promise<void>,\n\t): void;\n};\n\n/**\n * Extends a wrapped test API with additional fixtures that depend on the transaction.\n * This allows composing test context with factories, repositories, or other helpers.\n *\n * @template Transaction - The transaction type\n * @template Extended - The type of additional context to provide\n * @param wrappedTest - The base wrapped test from wrapVitestWithTransaction\n * @param fixtures - Object mapping fixture names to creator functions\n * @returns An extended test API with both trx and the additional fixtures\n *\n * @example\n * ```typescript\n * import { wrapVitestKyselyTransaction, extendWithFixtures } from '@geekmidas/testkit/kysely';\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestKyselyTransaction(test, {\n * connection: db,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures\n * const it = extendWithFixtures(baseTest, {\n * factory: (trx) => new KyselyFactory(builders, seeds, trx),\n * userRepo: (trx) => new UserRepository(trx),\n * });\n *\n * // Use in tests - trx and all fixtures are available\n * it('should create user with factory', async ({ trx, factory, userRepo }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user).toBeDefined();\n * });\n * ```\n */\nexport function extendWithFixtures<\n\tTransaction,\n\tExtended extends Record<string, unknown>,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tT extends ReturnType<TestAPI['extend']> = any,\n>(\n\twrappedTest: T,\n\tfixtures: FixtureCreators<Transaction, Extended>,\n): TestWithExtendedFixtures<Transaction, Extended, T> {\n\t// Build fixture definitions for Vitest's extend API\n\tconst fixtureDefinitions: Record<string, any> = {};\n\n\tfor (const [key, creator] of Object.entries(fixtures)) {\n\t\tfixtureDefinitions[key] = async (\n\t\t\t{ trx }: { trx: Transaction },\n\t\t\tuse: (value: unknown) => Promise<void>,\n\t\t) => {\n\t\t\tconst value = await (creator as (trx: Transaction) => unknown)(trx);\n\t\t\tawait use(value);\n\t\t};\n\t}\n\n\treturn (wrappedTest as any).extend(fixtureDefinitions);\n}\n"],"mappings":";;;;;;;;;;AAkDA,IAAY,iBAAL,yBAAA,gBAAA;;;;;CAKN,eAAA,sBAAA;;;;;CAKA,eAAA,oBAAA;;;;;CAKA,eAAA,qBAAA;;;;;CAKA,eAAA,kBAAA;;AACD,EAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAsB,oCAAtB,MAA4E;CAsB9C;;;;;;CAA7B,YAAY,KAA+B;EAAd,KAAA,MAAA;CAAe;;;;;;;;;;;;;;;;;;;;;;;;;;CA2B5C,0BACC,SACC;EACD,MAAM,EACL,YACA,OACA,iBAAA,mBACA,aACG;EAKJ,IAAI;EACJ,MAAM,oBAAoB,YAA4B;GACrD,IAAI,aAAa,KAAA,GAChB,WAAW,OAAO,YAAY,UAAU,IACrC,WAAW,QAAQ,SAAS;IAE5B,WAAW,IAAIA,kBAAAA,kBAAkB,EAAE,GAAG,QAAQ,IAAI,CAAC;IACnD,SAASC,oBAAAA;GACV,CAAC,IACA,WAAW;GAEf,OAAO;EACR;EAGA,MAAM,qBAA8C,CAAC;EACrD,IAAI,UACH,KAAK,MAAM,CAAC,KAAK,YAAY,OAAO,QAAQ,QAAQ,GACnD,mBAAmB,OAAO,OACzB,EAAE,OACF,QACI;GAEJ,MAAM,IAAI,MADW,QAA0C,GAAG,CACnD;EAChB;EAaF,OAJY,KAAK,IAIN,OAAyB;GAGnC,KAAK,OAAO,IAAQ,QAA+C;IAElE,MAAM,qBAAqB,MAAM;KAChC,cAAc;MACb,MAAM,eAAe;MACrB,KAAK,OAAO;KACb;IACD;IAEA,IAAI;IACJ,MAAM,OAAO,MAAM,kBAAkB;IACrC,IAAI;KACH,MAAM,KAAK,SAAS,MAAM,gBAAgB,OAAO,gBAAgB;MAChE,IAAI;OAEH,MAAM,QAAQ,WAAW;OACzB,MAAM,IAAI,WAAW;MACtB,SAAS,OAAO;OAEf,YAAY;MACb;MAGA,MAAM,IAAI,aAAa;KACxB,CAAC;IACF,SAAS,OAAO;KAEf,IAAI,EAAE,iBAAiB,eACtB,MAAM;KAIP,IAAI,WACH,MAAM;IAER;GACD;GACA,GAAG;EACJ,CAAC;CACF;AACD;;AAiBA,SAAS,YACR,YAC2C;CAC3C,OAAO,OAAO,eAAe;AAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwGA,SAAgB,mBAMf,aACA,UACqD;CAErD,MAAM,qBAA0C,CAAC;CAEjD,KAAK,MAAM,CAAC,KAAK,YAAY,OAAO,QAAQ,QAAQ,GACnD,mBAAmB,OAAO,OACzB,EAAE,OACF,QACI;EAEJ,MAAM,IAAI,MADW,QAA0C,GAAG,CACnD;CAChB;CAGD,OAAQ,YAAoB,OAAO,kBAAkB;AACtD"}