@geekmidas/testkit 10.0.0-alpha.3 → 10.0.0-alpha.31

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 (295) hide show
  1. package/README.md +74 -0
  2. package/dist/Factory.cjs +51 -2
  3. package/dist/Factory.cjs.map +1 -0
  4. package/dist/Factory.d.cts +143 -3
  5. package/dist/Factory.d.cts.map +1 -0
  6. package/dist/Factory.d.mts +143 -3
  7. package/dist/Factory.d.mts.map +1 -0
  8. package/dist/Factory.mjs +50 -2
  9. package/dist/Factory.mjs.map +1 -0
  10. package/dist/KyselyFactory.cjs +237 -4
  11. package/dist/KyselyFactory.cjs.map +1 -0
  12. package/dist/KyselyFactory.d.cts +224 -4
  13. package/dist/KyselyFactory.d.cts.map +1 -0
  14. package/dist/KyselyFactory.d.mts +224 -4
  15. package/dist/KyselyFactory.d.mts.map +1 -0
  16. package/dist/KyselyFactory.mjs +236 -4
  17. package/dist/KyselyFactory.mjs.map +1 -0
  18. package/dist/ObjectionFactory.cjs +265 -4
  19. package/dist/ObjectionFactory.cjs.map +1 -0
  20. package/dist/ObjectionFactory.d.cts +237 -4
  21. package/dist/ObjectionFactory.d.cts.map +1 -0
  22. package/dist/ObjectionFactory.d.mts +237 -4
  23. package/dist/ObjectionFactory.d.mts.map +1 -0
  24. package/dist/ObjectionFactory.mjs +264 -4
  25. package/dist/ObjectionFactory.mjs.map +1 -0
  26. package/dist/PostgresKyselyMigrator.cjs +94 -3
  27. package/dist/PostgresKyselyMigrator.cjs.map +1 -0
  28. package/dist/PostgresKyselyMigrator.d.cts +80 -3
  29. package/dist/PostgresKyselyMigrator.d.cts.map +1 -0
  30. package/dist/PostgresKyselyMigrator.d.mts +80 -3
  31. package/dist/PostgresKyselyMigrator.d.mts.map +1 -0
  32. package/dist/PostgresKyselyMigrator.mjs +93 -3
  33. package/dist/PostgresKyselyMigrator.mjs.map +1 -0
  34. package/dist/{PostgresMigrator-C_QQ6q35.d.mts → PostgresMigrator-CDPnnwMJ.d.cts} +11 -5
  35. package/dist/PostgresMigrator-CDPnnwMJ.d.cts.map +1 -0
  36. package/dist/{PostgresMigrator-CeYy-eHF.d.cts → PostgresMigrator-CDPnnwMJ.d.mts} +11 -5
  37. package/dist/PostgresMigrator-CDPnnwMJ.d.mts.map +1 -0
  38. package/dist/PostgresMigrator.cjs +178 -2
  39. package/dist/PostgresMigrator.cjs.map +1 -0
  40. package/dist/PostgresMigrator.d.cts +1 -1
  41. package/dist/PostgresMigrator.d.mts +1 -1
  42. package/dist/PostgresMigrator.mjs +175 -2
  43. package/dist/PostgresMigrator.mjs.map +1 -0
  44. package/dist/PostgresObjectionMigrator.cjs +118 -3
  45. package/dist/PostgresObjectionMigrator.cjs.map +1 -0
  46. package/dist/PostgresObjectionMigrator.d.cts +75 -3
  47. package/dist/PostgresObjectionMigrator.d.cts.map +1 -0
  48. package/dist/PostgresObjectionMigrator.d.mts +75 -3
  49. package/dist/PostgresObjectionMigrator.d.mts.map +1 -0
  50. package/dist/PostgresObjectionMigrator.mjs +117 -3
  51. package/dist/PostgresObjectionMigrator.mjs.map +1 -0
  52. package/dist/VitestKyselyTransactionIsolator.cjs +66 -3
  53. package/dist/VitestKyselyTransactionIsolator.cjs.map +1 -0
  54. package/dist/VitestKyselyTransactionIsolator.d.cts +60 -3
  55. package/dist/VitestKyselyTransactionIsolator.d.cts.map +1 -0
  56. package/dist/VitestKyselyTransactionIsolator.d.mts +60 -3
  57. package/dist/VitestKyselyTransactionIsolator.d.mts.map +1 -0
  58. package/dist/VitestKyselyTransactionIsolator.mjs +65 -3
  59. package/dist/VitestKyselyTransactionIsolator.mjs.map +1 -0
  60. package/dist/VitestObjectionTransactionIsolator.cjs +62 -3
  61. package/dist/VitestObjectionTransactionIsolator.cjs.map +1 -0
  62. package/dist/VitestObjectionTransactionIsolator.d.cts +56 -3
  63. package/dist/VitestObjectionTransactionIsolator.d.cts.map +1 -0
  64. package/dist/VitestObjectionTransactionIsolator.d.mts +56 -3
  65. package/dist/VitestObjectionTransactionIsolator.d.mts.map +1 -0
  66. package/dist/VitestObjectionTransactionIsolator.mjs +61 -3
  67. package/dist/VitestObjectionTransactionIsolator.mjs.map +1 -0
  68. package/dist/VitestTransactionIsolator.cjs +187 -4
  69. package/dist/VitestTransactionIsolator.cjs.map +1 -0
  70. package/dist/VitestTransactionIsolator.d.cts +219 -2
  71. package/dist/VitestTransactionIsolator.d.cts.map +1 -0
  72. package/dist/VitestTransactionIsolator.d.mts +219 -2
  73. package/dist/VitestTransactionIsolator.d.mts.map +1 -0
  74. package/dist/VitestTransactionIsolator.mjs +184 -2
  75. package/dist/VitestTransactionIsolator.mjs.map +1 -0
  76. package/dist/aws.cjs +3 -4
  77. package/dist/aws.cjs.map +1 -1
  78. package/dist/aws.d.cts +3 -8
  79. package/dist/aws.d.cts.map +1 -1
  80. package/dist/aws.d.mts +3 -8
  81. package/dist/aws.d.mts.map +1 -1
  82. package/dist/aws.mjs +1 -2
  83. package/dist/aws.mjs.map +1 -1
  84. package/dist/benchmark.cjs +2 -2
  85. package/dist/benchmark.cjs.map +1 -1
  86. package/dist/benchmark.d.cts +4 -6
  87. package/dist/benchmark.d.cts.map +1 -1
  88. package/dist/benchmark.d.mts +4 -6
  89. package/dist/benchmark.d.mts.map +1 -1
  90. package/dist/benchmark.mjs +1 -1
  91. package/dist/benchmark.mjs.map +1 -1
  92. package/dist/better-auth.cjs +31 -15
  93. package/dist/better-auth.cjs.map +1 -1
  94. package/dist/better-auth.d.cts +13142 -4
  95. package/dist/better-auth.d.cts.map +1 -1
  96. package/dist/better-auth.d.mts +13142 -4
  97. package/dist/better-auth.d.mts.map +1 -1
  98. package/dist/better-auth.mjs +29 -13
  99. package/dist/better-auth.mjs.map +1 -1
  100. package/dist/browser.cjs +127 -0
  101. package/dist/browser.cjs.map +1 -0
  102. package/dist/browser.d.cts +47 -0
  103. package/dist/browser.d.cts.map +1 -0
  104. package/dist/browser.d.mts +47 -0
  105. package/dist/browser.d.mts.map +1 -0
  106. package/dist/browser.mjs +125 -0
  107. package/dist/browser.mjs.map +1 -0
  108. package/dist/context.cjs +80 -0
  109. package/dist/context.cjs.map +1 -0
  110. package/dist/context.d.cts +55 -0
  111. package/dist/context.d.cts.map +1 -0
  112. package/dist/context.d.mts +55 -0
  113. package/dist/context.d.mts.map +1 -0
  114. package/dist/context.mjs +73 -0
  115. package/dist/context.mjs.map +1 -0
  116. package/dist/faker.cjs +262 -8
  117. package/dist/faker.cjs.map +1 -0
  118. package/dist/faker.d.cts +162 -2
  119. package/dist/faker.d.cts.map +1 -0
  120. package/dist/faker.d.mts +162 -2
  121. package/dist/faker.d.mts.map +1 -0
  122. package/dist/faker.mjs +255 -2
  123. package/dist/faker.mjs.map +1 -0
  124. package/dist/helpers.cjs +6 -5
  125. package/dist/helpers.cjs.map +1 -1
  126. package/dist/helpers.d.cts +1 -5
  127. package/dist/helpers.d.cts.map +1 -1
  128. package/dist/helpers.d.mts +1 -5
  129. package/dist/helpers.d.mts.map +1 -1
  130. package/dist/helpers.mjs +1 -2
  131. package/dist/helpers.mjs.map +1 -1
  132. package/dist/initScript.cjs +15 -15
  133. package/dist/initScript.cjs.map +1 -1
  134. package/dist/initScript.d.cts +2 -4
  135. package/dist/initScript.d.cts.map +1 -1
  136. package/dist/initScript.d.mts +2 -4
  137. package/dist/initScript.d.mts.map +1 -1
  138. package/dist/initScript.mjs +10 -12
  139. package/dist/initScript.mjs.map +1 -1
  140. package/dist/kysely.cjs +10 -13
  141. package/dist/kysely.cjs.map +1 -1
  142. package/dist/kysely.d.cts +10 -14
  143. package/dist/kysely.d.cts.map +1 -1
  144. package/dist/kysely.d.mts +10 -14
  145. package/dist/kysely.d.mts.map +1 -1
  146. package/dist/kysely.mjs +10 -14
  147. package/dist/kysely.mjs.map +1 -1
  148. package/dist/logger.cjs +3 -4
  149. package/dist/logger.cjs.map +1 -1
  150. package/dist/logger.d.cts +1 -5
  151. package/dist/logger.d.cts.map +1 -1
  152. package/dist/logger.d.mts +1 -5
  153. package/dist/logger.d.mts.map +1 -1
  154. package/dist/logger.mjs +1 -2
  155. package/dist/logger.mjs.map +1 -1
  156. package/dist/mailbox.cjs +95 -0
  157. package/dist/mailbox.cjs.map +1 -0
  158. package/dist/mailbox.d.cts +58 -0
  159. package/dist/mailbox.d.cts.map +1 -0
  160. package/dist/mailbox.d.mts +58 -0
  161. package/dist/mailbox.d.mts.map +1 -0
  162. package/dist/mailbox.mjs +92 -0
  163. package/dist/mailbox.mjs.map +1 -0
  164. package/dist/objection.cjs +10 -13
  165. package/dist/objection.cjs.map +1 -1
  166. package/dist/objection.d.cts +10 -14
  167. package/dist/objection.d.cts.map +1 -1
  168. package/dist/objection.d.mts +10 -14
  169. package/dist/objection.d.mts.map +1 -1
  170. package/dist/objection.mjs +10 -14
  171. package/dist/objection.mjs.map +1 -1
  172. package/dist/os/directory.cjs +31 -2
  173. package/dist/os/directory.cjs.map +1 -0
  174. package/dist/os/directory.d.cts +9 -2
  175. package/dist/os/directory.d.cts.map +1 -0
  176. package/dist/os/directory.d.mts +9 -2
  177. package/dist/os/directory.d.mts.map +1 -0
  178. package/dist/os/directory.mjs +25 -2
  179. package/dist/os/directory.mjs.map +1 -0
  180. package/dist/os/index.cjs +3 -3
  181. package/dist/os/index.d.cts +1 -1
  182. package/dist/os/index.d.mts +1 -1
  183. package/dist/os/index.mjs +2 -3
  184. package/dist/requestContext.cjs +10 -11
  185. package/dist/requestContext.cjs.map +1 -1
  186. package/dist/requestContext.d.cts +4 -8
  187. package/dist/requestContext.d.cts.map +1 -1
  188. package/dist/requestContext.d.mts +4 -8
  189. package/dist/requestContext.d.mts.map +1 -1
  190. package/dist/requestContext.mjs +1 -2
  191. package/dist/requestContext.mjs.map +1 -1
  192. package/dist/{chunk-CUT6urMc.cjs → rolldown-runtime-VH7oDXx4.cjs} +8 -10
  193. package/dist/timer.cjs +2 -2
  194. package/dist/timer.cjs.map +1 -1
  195. package/dist/timer.d.cts +1 -4
  196. package/dist/timer.d.cts.map +1 -1
  197. package/dist/timer.d.mts +1 -4
  198. package/dist/timer.d.mts.map +1 -1
  199. package/dist/timer.mjs +1 -1
  200. package/dist/timer.mjs.map +1 -1
  201. package/dist/transactions.cjs +123 -0
  202. package/dist/transactions.cjs.map +1 -0
  203. package/dist/transactions.d.cts +44 -0
  204. package/dist/transactions.d.cts.map +1 -0
  205. package/dist/transactions.d.mts +44 -0
  206. package/dist/transactions.d.mts.map +1 -0
  207. package/dist/transactions.mjs +118 -0
  208. package/dist/transactions.mjs.map +1 -0
  209. package/package.json +59 -16
  210. package/dist/Factory-BFVnMMCC.mjs +0 -51
  211. package/dist/Factory-BFVnMMCC.mjs.map +0 -1
  212. package/dist/Factory-BOX312yd.d.cts +0 -147
  213. package/dist/Factory-BOX312yd.d.cts.map +0 -1
  214. package/dist/Factory-BhjUOBWN.cjs +0 -57
  215. package/dist/Factory-BhjUOBWN.cjs.map +0 -1
  216. package/dist/Factory-C6W78ulZ.d.mts +0 -147
  217. package/dist/Factory-C6W78ulZ.d.mts.map +0 -1
  218. package/dist/KyselyFactory-BFqVIn_0.cjs +0 -246
  219. package/dist/KyselyFactory-BFqVIn_0.cjs.map +0 -1
  220. package/dist/KyselyFactory-Cc2UmOJk.d.mts +0 -228
  221. package/dist/KyselyFactory-Cc2UmOJk.d.mts.map +0 -1
  222. package/dist/KyselyFactory-DMswpwji.mjs +0 -241
  223. package/dist/KyselyFactory-DMswpwji.mjs.map +0 -1
  224. package/dist/KyselyFactory-Dy5zzV4B.d.cts +0 -228
  225. package/dist/KyselyFactory-Dy5zzV4B.d.cts.map +0 -1
  226. package/dist/ObjectionFactory-BYnPr9ZP.d.mts +0 -241
  227. package/dist/ObjectionFactory-BYnPr9ZP.d.mts.map +0 -1
  228. package/dist/ObjectionFactory-BeFBYcan.cjs +0 -272
  229. package/dist/ObjectionFactory-BeFBYcan.cjs.map +0 -1
  230. package/dist/ObjectionFactory-CD-WFuMJ.d.cts +0 -241
  231. package/dist/ObjectionFactory-CD-WFuMJ.d.cts.map +0 -1
  232. package/dist/ObjectionFactory-QCJ7u0Ql.mjs +0 -267
  233. package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +0 -1
  234. package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts +0 -84
  235. package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts.map +0 -1
  236. package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs +0 -101
  237. package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs.map +0 -1
  238. package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts +0 -84
  239. package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts.map +0 -1
  240. package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs +0 -95
  241. package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs.map +0 -1
  242. package/dist/PostgresMigrator-C_QQ6q35.d.mts.map +0 -1
  243. package/dist/PostgresMigrator-CeYy-eHF.d.cts.map +0 -1
  244. package/dist/PostgresMigrator-DVAY04qN.mjs +0 -166
  245. package/dist/PostgresMigrator-DVAY04qN.mjs.map +0 -1
  246. package/dist/PostgresMigrator-M9jpzOvN.cjs +0 -172
  247. package/dist/PostgresMigrator-M9jpzOvN.cjs.map +0 -1
  248. package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts +0 -79
  249. package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts.map +0 -1
  250. package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts +0 -79
  251. package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts.map +0 -1
  252. package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs +0 -123
  253. package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs.map +0 -1
  254. package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs +0 -118
  255. package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs.map +0 -1
  256. package/dist/VitestKyselyTransactionIsolator-1Saieke7.mjs +0 -67
  257. package/dist/VitestKyselyTransactionIsolator-1Saieke7.mjs.map +0 -1
  258. package/dist/VitestKyselyTransactionIsolator-BjJSXryR.cjs +0 -72
  259. package/dist/VitestKyselyTransactionIsolator-BjJSXryR.cjs.map +0 -1
  260. package/dist/VitestKyselyTransactionIsolator-CwlTo6yf.d.mts +0 -64
  261. package/dist/VitestKyselyTransactionIsolator-CwlTo6yf.d.mts.map +0 -1
  262. package/dist/VitestKyselyTransactionIsolator-DJasVuIZ.d.cts +0 -64
  263. package/dist/VitestKyselyTransactionIsolator-DJasVuIZ.d.cts.map +0 -1
  264. package/dist/VitestObjectionTransactionIsolator-B_VSWFum.mjs +0 -63
  265. package/dist/VitestObjectionTransactionIsolator-B_VSWFum.mjs.map +0 -1
  266. package/dist/VitestObjectionTransactionIsolator-CTTjvTPO.d.cts +0 -60
  267. package/dist/VitestObjectionTransactionIsolator-CTTjvTPO.d.cts.map +0 -1
  268. package/dist/VitestObjectionTransactionIsolator-CyZG6nq4.d.mts +0 -60
  269. package/dist/VitestObjectionTransactionIsolator-CyZG6nq4.d.mts.map +0 -1
  270. package/dist/VitestObjectionTransactionIsolator-DDoJTu7e.cjs +0 -68
  271. package/dist/VitestObjectionTransactionIsolator-DDoJTu7e.cjs.map +0 -1
  272. package/dist/VitestTransactionIsolator-BLaw80cx.d.mts +0 -223
  273. package/dist/VitestTransactionIsolator-BLaw80cx.d.mts.map +0 -1
  274. package/dist/VitestTransactionIsolator-CvwPecpl.mjs +0 -188
  275. package/dist/VitestTransactionIsolator-CvwPecpl.mjs.map +0 -1
  276. package/dist/VitestTransactionIsolator-DyiX-QtK.cjs +0 -206
  277. package/dist/VitestTransactionIsolator-DyiX-QtK.cjs.map +0 -1
  278. package/dist/VitestTransactionIsolator-glcxyS_R.d.cts +0 -223
  279. package/dist/VitestTransactionIsolator-glcxyS_R.d.cts.map +0 -1
  280. package/dist/directory-BxjqmtCT.mjs +0 -27
  281. package/dist/directory-BxjqmtCT.mjs.map +0 -1
  282. package/dist/directory-DD_xQoSh.cjs +0 -33
  283. package/dist/directory-DD_xQoSh.cjs.map +0 -1
  284. package/dist/directory-DGOcVlKD.d.cts +0 -13
  285. package/dist/directory-DGOcVlKD.d.cts.map +0 -1
  286. package/dist/directory-DiQ_DkaF.d.mts +0 -13
  287. package/dist/directory-DiQ_DkaF.d.mts.map +0 -1
  288. package/dist/faker-B14IEMIN.cjs +0 -304
  289. package/dist/faker-B14IEMIN.cjs.map +0 -1
  290. package/dist/faker-BGKYFoCT.mjs +0 -262
  291. package/dist/faker-BGKYFoCT.mjs.map +0 -1
  292. package/dist/faker-Cg76aFNO.d.cts +0 -166
  293. package/dist/faker-Cg76aFNO.d.cts.map +0 -1
  294. package/dist/faker-D9gz7KjY.d.mts +0 -166
  295. package/dist/faker-D9gz7KjY.d.mts.map +0 -1
@@ -8,7 +8,7 @@
8
8
  * @returns Array of SQL strings ready to execute
9
9
  * @internal Exported for testing
10
10
  */
11
- declare function parseInitScript(content: string, env: Record<string, string>): string[];
11
+ export declare function parseInitScript(content: string, env: Record<string, string>): string[];
12
12
  /**
13
13
  * Read a postgres init script, parse out the SQL blocks,
14
14
  * substitute environment variables, and execute against a database.
@@ -38,8 +38,6 @@ declare function parseInitScript(content: string, env: Record<string, string>):
38
38
  * });
39
39
  * ```
40
40
  */
41
- declare function runInitScript(scriptPath: string, databaseUrl: string, env?: Record<string, string>): Promise<void>;
42
- //# sourceMappingURL=initScript.d.ts.map
41
+ export declare function runInitScript(scriptPath: string, databaseUrl: string, env?: Record<string, string>): Promise<void>;
43
42
  //#endregion
44
- export { parseInitScript, runInitScript };
45
43
  //# sourceMappingURL=initScript.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"initScript.d.cts","names":[],"sources":["../src/initScript.ts"],"sourcesContent":[],"mappings":";;AAcA;AA6EA;;;;AAIU;;;iBAjFM,eAAA,uBAEV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2EgB,aAAA,gDAGf,yBACJ"}
1
+ {"version":3,"file":"initScript.d.cts","names":[],"sources":["../src/initScript.ts"],"mappings":";;;;;;;;;;wBAcgB,gBACf,iBACA,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2EgB,cACrB,oBACA,qBACA,MAAM,yBACJ"}
@@ -8,7 +8,7 @@
8
8
  * @returns Array of SQL strings ready to execute
9
9
  * @internal Exported for testing
10
10
  */
11
- declare function parseInitScript(content: string, env: Record<string, string>): string[];
11
+ export declare function parseInitScript(content: string, env: Record<string, string>): string[];
12
12
  /**
13
13
  * Read a postgres init script, parse out the SQL blocks,
14
14
  * substitute environment variables, and execute against a database.
@@ -38,8 +38,6 @@ declare function parseInitScript(content: string, env: Record<string, string>):
38
38
  * });
39
39
  * ```
40
40
  */
41
- declare function runInitScript(scriptPath: string, databaseUrl: string, env?: Record<string, string>): Promise<void>;
42
- //# sourceMappingURL=initScript.d.ts.map
41
+ export declare function runInitScript(scriptPath: string, databaseUrl: string, env?: Record<string, string>): Promise<void>;
43
42
  //#endregion
44
- export { parseInitScript, runInitScript };
45
43
  //# sourceMappingURL=initScript.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"initScript.d.mts","names":[],"sources":["../src/initScript.ts"],"sourcesContent":[],"mappings":";;AAcA;AA6EA;;;;AAIU;;;iBAjFM,eAAA,uBAEV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2EgB,aAAA,gDAGf,yBACJ"}
1
+ {"version":3,"file":"initScript.d.mts","names":[],"sources":["../src/initScript.ts"],"mappings":";;;;;;;;;;wBAcgB,gBACf,iBACA,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2EgB,cACrB,oBACA,qBACA,MAAM,yBACJ"}
@@ -1,6 +1,5 @@
1
1
  import pg from "pg";
2
2
  import { readFileSync } from "node:fs";
3
-
4
3
  //#region src/initScript.ts
5
4
  const { Client } = pg;
6
5
  /**
@@ -17,13 +16,14 @@ function parseInitScript(content, env) {
17
16
  const lines = content.split("\n");
18
17
  let inHeredoc = false;
19
18
  let currentBlock = [];
20
- for (const line of lines) if (inHeredoc) if (/^\s*EOSQL\s*$/.test(line)) {
21
- const sql = substituteEnvVars(currentBlock.join("\n"), env);
22
- blocks.push(sql);
23
- currentBlock = [];
24
- inHeredoc = false;
25
- } else currentBlock.push(line);
26
- else if (line.includes("<<-EOSQL") || line.includes("<< EOSQL") || line.includes("<<EOSQL")) {
19
+ for (const line of lines) if (inHeredoc) {
20
+ if (/^\s*EOSQL\s*$/.test(line)) {
21
+ const sql = substituteEnvVars(currentBlock.join("\n"), env);
22
+ blocks.push(sql);
23
+ currentBlock = [];
24
+ inHeredoc = false;
25
+ } else currentBlock.push(line);
26
+ } else if (line.includes("<<-EOSQL") || line.includes("<< EOSQL") || line.includes("<<EOSQL")) {
27
27
  inHeredoc = true;
28
28
  currentBlock = [];
29
29
  }
@@ -69,9 +69,7 @@ function substituteEnvVars(sql, env) {
69
69
  * ```
70
70
  */
71
71
  async function runInitScript(scriptPath, databaseUrl, env) {
72
- const content = readFileSync(scriptPath, "utf-8");
73
- const resolvedEnv = env ?? { ...process.env };
74
- const blocks = parseInitScript(content, resolvedEnv);
72
+ const blocks = parseInitScript(readFileSync(scriptPath, "utf-8"), env ?? { ...process.env });
75
73
  if (blocks.length === 0) return;
76
74
  const url = new URL(databaseUrl);
77
75
  const client = new Client({
@@ -88,7 +86,7 @@ async function runInitScript(scriptPath, databaseUrl, env) {
88
86
  await client.end();
89
87
  }
90
88
  }
91
-
92
89
  //#endregion
93
90
  export { parseInitScript, runInitScript };
91
+
94
92
  //# sourceMappingURL=initScript.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"initScript.mjs","names":["content: string","env: Record<string, string>","blocks: string[]","currentBlock: string[]","sql: string","scriptPath: string","databaseUrl: string","env?: Record<string, string>"],"sources":["../src/initScript.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport pg from 'pg';\n\nconst { Client } = pg;\n\n/**\n * Parse a shell init script (like docker/postgres/init.sh) and extract\n * SQL blocks from heredoc sections (<<-EOSQL ... EOSQL).\n *\n * @param content - The shell script content\n * @param env - Environment variables to substitute ($VAR_NAME references)\n * @returns Array of SQL strings ready to execute\n * @internal Exported for testing\n */\nexport function parseInitScript(\n\tcontent: string,\n\tenv: Record<string, string>,\n): string[] {\n\tconst blocks: string[] = [];\n\tconst lines = content.split('\\n');\n\tlet inHeredoc = false;\n\tlet currentBlock: string[] = [];\n\n\tfor (const line of lines) {\n\t\tif (inHeredoc) {\n\t\t\t// Check for heredoc terminator (EOSQL at start of line, with optional leading whitespace)\n\t\t\tif (/^\\s*EOSQL\\s*$/.test(line)) {\n\t\t\t\tconst sql = substituteEnvVars(currentBlock.join('\\n'), env);\n\t\t\t\tblocks.push(sql);\n\t\t\t\tcurrentBlock = [];\n\t\t\t\tinHeredoc = false;\n\t\t\t} else {\n\t\t\t\tcurrentBlock.push(line);\n\t\t\t}\n\t\t} else if (\n\t\t\tline.includes('<<-EOSQL') ||\n\t\t\tline.includes('<< EOSQL') ||\n\t\t\tline.includes('<<EOSQL')\n\t\t) {\n\t\t\tinHeredoc = true;\n\t\t\tcurrentBlock = [];\n\t\t}\n\t}\n\n\treturn blocks;\n}\n\n/**\n * Replace shell variable references ($VAR_NAME and ${VAR_NAME})\n * with values from the provided env object.\n */\nfunction substituteEnvVars(sql: string, env: Record<string, string>): string {\n\t// Replace ${VAR_NAME} syntax\n\tlet result = sql.replace(/\\$\\{(\\w+)\\}/g, (_, name) => env[name] ?? '');\n\t// Replace $VAR_NAME syntax (word boundary after)\n\tresult = result.replace(/\\$(\\w+)/g, (_, name) => env[name] ?? '');\n\t// Unescape bash-escaped dollar signs (\\$ → $) AFTER variable substitution\n\t// This handles PL/pgSQL dollar-quoting like DO \\$\\$ ... END \\$\\$;\n\tresult = result.replace(/\\\\\\$/g, '$');\n\treturn result;\n}\n\n/**\n * Read a postgres init script, parse out the SQL blocks,\n * substitute environment variables, and execute against a database.\n *\n * This is intended to run `docker/postgres/init.sh` against a test database\n * so that per-app users and schemas are created (matching what Docker does\n * on first volume initialization).\n *\n * Uses `CREATE ... IF NOT EXISTS` and `DO $$ ... END $$` wrappers where\n * needed so the script is idempotent.\n *\n * @param scriptPath - Path to the init.sh file\n * @param databaseUrl - PostgreSQL connection URL (should point to the test database)\n *\n * @example\n * ```typescript\n * // In your globalSetup.ts\n * import { runInitScript } from '@geekmidas/testkit/postgres';\n * import { Credentials } from '@geekmidas/envkit/credentials';\n *\n * const cleanup = await migrator.start();\n *\n * // Create per-app users in the test database\n * await runInitScript('docker/postgres/init.sh', Credentials.DATABASE_URL, {\n * ...process.env,\n * ...Credentials,\n * });\n * ```\n */\nexport async function runInitScript(\n\tscriptPath: string,\n\tdatabaseUrl: string,\n\tenv?: Record<string, string>,\n): Promise<void> {\n\tconst content = readFileSync(scriptPath, 'utf-8');\n\tconst resolvedEnv = env ?? ({ ...process.env } as Record<string, string>);\n\tconst blocks = parseInitScript(content, resolvedEnv);\n\n\tif (blocks.length === 0) {\n\t\treturn;\n\t}\n\n\tconst url = new URL(databaseUrl);\n\tconst client = new Client({\n\t\tuser: url.username,\n\t\tpassword: decodeURIComponent(url.password),\n\t\thost: url.hostname,\n\t\tport: parseInt(url.port, 10),\n\t\tdatabase: url.pathname.slice(1),\n\t});\n\n\ttry {\n\t\tawait client.connect();\n\t\tfor (const sql of blocks) {\n\t\t\tawait client.query(sql);\n\t\t}\n\t} finally {\n\t\tawait client.end();\n\t}\n}\n"],"mappings":";;;;AAGA,MAAM,EAAE,QAAQ,GAAG;;;;;;;;;;AAWnB,SAAgB,gBACfA,SACAC,KACW;CACX,MAAMC,SAAmB,CAAE;CAC3B,MAAM,QAAQ,QAAQ,MAAM,KAAK;CACjC,IAAI,YAAY;CAChB,IAAIC,eAAyB,CAAE;AAE/B,MAAK,MAAM,QAAQ,MAClB,KAAI,UAEH,KAAI,gBAAgB,KAAK,KAAK,EAAE;EAC/B,MAAM,MAAM,kBAAkB,aAAa,KAAK,KAAK,EAAE,IAAI;AAC3D,SAAO,KAAK,IAAI;AAChB,iBAAe,CAAE;AACjB,cAAY;CACZ,MACA,cAAa,KAAK,KAAK;UAGxB,KAAK,SAAS,WAAW,IACzB,KAAK,SAAS,WAAW,IACzB,KAAK,SAAS,UAAU,EACvB;AACD,cAAY;AACZ,iBAAe,CAAE;CACjB;AAGF,QAAO;AACP;;;;;AAMD,SAAS,kBAAkBC,KAAaH,KAAqC;CAE5E,IAAI,SAAS,IAAI,QAAQ,gBAAgB,CAAC,GAAG,SAAS,IAAI,SAAS,GAAG;AAEtE,UAAS,OAAO,QAAQ,YAAY,CAAC,GAAG,SAAS,IAAI,SAAS,GAAG;AAGjE,UAAS,OAAO,QAAQ,SAAS,IAAI;AACrC,QAAO;AACP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BD,eAAsB,cACrBI,YACAC,aACAC,KACgB;CAChB,MAAM,UAAU,aAAa,YAAY,QAAQ;CACjD,MAAM,cAAc,OAAQ,EAAE,GAAG,QAAQ,IAAK;CAC9C,MAAM,SAAS,gBAAgB,SAAS,YAAY;AAEpD,KAAI,OAAO,WAAW,EACrB;CAGD,MAAM,MAAM,IAAI,IAAI;CACpB,MAAM,SAAS,IAAI,OAAO;EACzB,MAAM,IAAI;EACV,UAAU,mBAAmB,IAAI,SAAS;EAC1C,MAAM,IAAI;EACV,MAAM,SAAS,IAAI,MAAM,GAAG;EAC5B,UAAU,IAAI,SAAS,MAAM,EAAE;CAC/B;AAED,KAAI;AACH,QAAM,OAAO,SAAS;AACtB,OAAK,MAAM,OAAO,OACjB,OAAM,OAAO,MAAM,IAAI;CAExB,UAAS;AACT,QAAM,OAAO,KAAK;CAClB;AACD"}
1
+ {"version":3,"file":"initScript.mjs","names":[],"sources":["../src/initScript.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport pg from 'pg';\n\nconst { Client } = pg;\n\n/**\n * Parse a shell init script (like docker/postgres/init.sh) and extract\n * SQL blocks from heredoc sections (<<-EOSQL ... EOSQL).\n *\n * @param content - The shell script content\n * @param env - Environment variables to substitute ($VAR_NAME references)\n * @returns Array of SQL strings ready to execute\n * @internal Exported for testing\n */\nexport function parseInitScript(\n\tcontent: string,\n\tenv: Record<string, string>,\n): string[] {\n\tconst blocks: string[] = [];\n\tconst lines = content.split('\\n');\n\tlet inHeredoc = false;\n\tlet currentBlock: string[] = [];\n\n\tfor (const line of lines) {\n\t\tif (inHeredoc) {\n\t\t\t// Check for heredoc terminator (EOSQL at start of line, with optional leading whitespace)\n\t\t\tif (/^\\s*EOSQL\\s*$/.test(line)) {\n\t\t\t\tconst sql = substituteEnvVars(currentBlock.join('\\n'), env);\n\t\t\t\tblocks.push(sql);\n\t\t\t\tcurrentBlock = [];\n\t\t\t\tinHeredoc = false;\n\t\t\t} else {\n\t\t\t\tcurrentBlock.push(line);\n\t\t\t}\n\t\t} else if (\n\t\t\tline.includes('<<-EOSQL') ||\n\t\t\tline.includes('<< EOSQL') ||\n\t\t\tline.includes('<<EOSQL')\n\t\t) {\n\t\t\tinHeredoc = true;\n\t\t\tcurrentBlock = [];\n\t\t}\n\t}\n\n\treturn blocks;\n}\n\n/**\n * Replace shell variable references ($VAR_NAME and ${VAR_NAME})\n * with values from the provided env object.\n */\nfunction substituteEnvVars(sql: string, env: Record<string, string>): string {\n\t// Replace ${VAR_NAME} syntax\n\tlet result = sql.replace(/\\$\\{(\\w+)\\}/g, (_, name) => env[name] ?? '');\n\t// Replace $VAR_NAME syntax (word boundary after)\n\tresult = result.replace(/\\$(\\w+)/g, (_, name) => env[name] ?? '');\n\t// Unescape bash-escaped dollar signs (\\$ → $) AFTER variable substitution\n\t// This handles PL/pgSQL dollar-quoting like DO \\$\\$ ... END \\$\\$;\n\tresult = result.replace(/\\\\\\$/g, '$');\n\treturn result;\n}\n\n/**\n * Read a postgres init script, parse out the SQL blocks,\n * substitute environment variables, and execute against a database.\n *\n * This is intended to run `docker/postgres/init.sh` against a test database\n * so that per-app users and schemas are created (matching what Docker does\n * on first volume initialization).\n *\n * Uses `CREATE ... IF NOT EXISTS` and `DO $$ ... END $$` wrappers where\n * needed so the script is idempotent.\n *\n * @param scriptPath - Path to the init.sh file\n * @param databaseUrl - PostgreSQL connection URL (should point to the test database)\n *\n * @example\n * ```typescript\n * // In your globalSetup.ts\n * import { runInitScript } from '@geekmidas/testkit/postgres';\n * import { Credentials } from '@geekmidas/envkit/credentials';\n *\n * const cleanup = await migrator.start();\n *\n * // Create per-app users in the test database\n * await runInitScript('docker/postgres/init.sh', Credentials.DATABASE_URL, {\n * ...process.env,\n * ...Credentials,\n * });\n * ```\n */\nexport async function runInitScript(\n\tscriptPath: string,\n\tdatabaseUrl: string,\n\tenv?: Record<string, string>,\n): Promise<void> {\n\tconst content = readFileSync(scriptPath, 'utf-8');\n\tconst resolvedEnv = env ?? ({ ...process.env } as Record<string, string>);\n\tconst blocks = parseInitScript(content, resolvedEnv);\n\n\tif (blocks.length === 0) {\n\t\treturn;\n\t}\n\n\tconst url = new URL(databaseUrl);\n\tconst client = new Client({\n\t\tuser: url.username,\n\t\tpassword: decodeURIComponent(url.password),\n\t\thost: url.hostname,\n\t\tport: parseInt(url.port, 10),\n\t\tdatabase: url.pathname.slice(1),\n\t});\n\n\ttry {\n\t\tawait client.connect();\n\t\tfor (const sql of blocks) {\n\t\t\tawait client.query(sql);\n\t\t}\n\t} finally {\n\t\tawait client.end();\n\t}\n}\n"],"mappings":";;;AAGA,MAAM,EAAE,WAAW;;;;;;;;;;AAWnB,SAAgB,gBACf,SACA,KACW;CACX,MAAM,SAAmB,CAAC;CAC1B,MAAM,QAAQ,QAAQ,MAAM,IAAI;CAChC,IAAI,YAAY;CAChB,IAAI,eAAyB,CAAC;CAE9B,KAAK,MAAM,QAAQ,OAClB,IAAI,WAAW;EAEd,IAAI,gBAAgB,KAAK,IAAI,GAAG;GAC/B,MAAM,MAAM,kBAAkB,aAAa,KAAK,IAAI,GAAG,GAAG;GAC1D,OAAO,KAAK,GAAG;GACf,eAAe,CAAC;GAChB,YAAY;EACb,OACC,aAAa,KAAK,IAAI;CAExB,OAAO,IACN,KAAK,SAAS,UAAU,KACxB,KAAK,SAAS,UAAU,KACxB,KAAK,SAAS,SAAS,GACtB;EACD,YAAY;EACZ,eAAe,CAAC;CACjB;CAGD,OAAO;AACR;;;;;AAMA,SAAS,kBAAkB,KAAa,KAAqC;CAE5E,IAAI,SAAS,IAAI,QAAQ,iBAAiB,GAAG,SAAS,IAAI,SAAS,EAAE;CAErE,SAAS,OAAO,QAAQ,aAAa,GAAG,SAAS,IAAI,SAAS,EAAE;CAGhE,SAAS,OAAO,QAAQ,SAAS,GAAG;CACpC,OAAO;AACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,eAAsB,cACrB,YACA,aACA,KACgB;CAGhB,MAAM,SAAS,gBAFC,aAAa,YAAY,OAEJ,GADjB,OAAQ,EAAE,GAAG,QAAQ,IAAI,CACM;CAEnD,IAAI,OAAO,WAAW,GACrB;CAGD,MAAM,MAAM,IAAI,IAAI,WAAW;CAC/B,MAAM,SAAS,IAAI,OAAO;EACzB,MAAM,IAAI;EACV,UAAU,mBAAmB,IAAI,QAAQ;EACzC,MAAM,IAAI;EACV,MAAM,SAAS,IAAI,MAAM,EAAE;EAC3B,UAAU,IAAI,SAAS,MAAM,CAAC;CAC/B,CAAC;CAED,IAAI;EACH,MAAM,OAAO,QAAQ;EACrB,KAAK,MAAM,OAAO,QACjB,MAAM,OAAO,MAAM,GAAG;CAExB,UAAU;EACT,MAAM,OAAO,IAAI;CAClB;AACD"}
package/dist/kysely.cjs CHANGED
@@ -1,11 +1,9 @@
1
- require('./Factory-BhjUOBWN.cjs');
2
- const require_faker = require('./faker-B14IEMIN.cjs');
3
- const require_KyselyFactory = require('./KyselyFactory-BFqVIn_0.cjs');
4
- require('./PostgresMigrator-M9jpzOvN.cjs');
5
- const require_PostgresKyselyMigrator = require('./PostgresKyselyMigrator-BGBxjnFv.cjs');
6
- const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-DyiX-QtK.cjs');
7
- const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-BjJSXryR.cjs');
8
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_faker = require("./faker.cjs");
3
+ const require_KyselyFactory = require("./KyselyFactory.cjs");
4
+ const require_PostgresKyselyMigrator = require("./PostgresKyselyMigrator.cjs");
5
+ const require_VitestTransactionIsolator = require("./VitestTransactionIsolator.cjs");
6
+ const require_VitestKyselyTransactionIsolator = require("./VitestKyselyTransactionIsolator.cjs");
9
7
  //#region src/kysely.ts
10
8
  /**
11
9
  * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.
@@ -55,8 +53,7 @@ const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransacti
55
53
  * ```
56
54
  */
57
55
  function wrapVitestKyselyTransaction(api, options) {
58
- const wrapper = new require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator(api);
59
- return wrapper.wrapVitestWithTransaction(options);
56
+ return new require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator(api).wrapVitestWithTransaction(options);
60
57
  }
61
58
  /**
62
59
  * Extends a Kysely transaction-wrapped test with additional fixtures.
@@ -110,16 +107,16 @@ function wrapVitestKyselyTransaction(api, options) {
110
107
  * });
111
108
  * ```
112
109
  */
113
- function extendWithFixtures$1(wrappedTest, fixtures) {
110
+ function extendWithFixtures(wrappedTest, fixtures) {
114
111
  return require_VitestTransactionIsolator.extendWithFixtures(wrappedTest, fixtures);
115
112
  }
116
-
117
113
  //#endregion
118
114
  exports.IsolationLevel = require_VitestTransactionIsolator.IsolationLevel;
119
115
  exports.KyselyFactory = require_KyselyFactory.KyselyFactory;
120
116
  exports.PostgresKyselyMigrator = require_PostgresKyselyMigrator.PostgresKyselyMigrator;
121
117
  exports.VitestKyselyTransactionIsolator = require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator;
122
- exports.extendWithFixtures = extendWithFixtures$1;
118
+ exports.extendWithFixtures = extendWithFixtures;
123
119
  exports.faker = require_faker.faker;
124
120
  exports.wrapVitestKyselyTransaction = wrapVitestKyselyTransaction;
121
+
125
122
  //# sourceMappingURL=kysely.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"kysely.cjs","names":["api: TestAPI","options: KyselyTransactionOptions<Database, Extended>","VitestKyselyTransactionIsolator","extendWithFixtures","wrappedTest: T","fixtures: FixtureCreators<Transaction<Database>, Extended>"],"sources":["../src/kysely.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport type { TestAPI } from 'vitest';\nimport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nimport {\n\textendWithFixtures as baseExtendWithFixtures,\n\ttype DatabaseConnection,\n\ttype FixtureCreators,\n\ttype IsolationLevel,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific exports for test utilities.\n * Provides factories, migrators, and transaction isolators for Kysely ORM.\n */\n\nexport type { ExtractSeedAttrs, FactorySeed } from './Factory';\nexport { KyselyFactory } from './KyselyFactory';\nexport { PostgresKyselyMigrator } from './PostgresKyselyMigrator';\nexport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nexport type {\n\tDatabaseFixtures,\n\tExtendedDatabaseFixtures,\n\tFixtureCreators,\n\tTestWithExtendedFixtures,\n\tTransactionWrapperOptions,\n} from './VitestTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific options for transaction wrapping.\n */\nexport interface KyselyTransactionOptions<\n\tDatabase,\n\tExtended extends Record<string, unknown> = {},\n> {\n\t/** Function that creates or returns a Kysely database instance */\n\tconnection: DatabaseConnection<Kysely<Database>>;\n\t/** Optional setup function to run within the transaction before each test */\n\tsetup?: (trx: Transaction<Database>) => 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<Database>, Extended>;\n}\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { type FakerFactory, faker } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Database - The database schema type\n * @template Extended - Additional fixtures to provide\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param options - Configuration options for transaction wrapping\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';\n * import { db } from './database';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestKyselyTransaction(test, {\n * connection: db,\n * });\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await trx\n * .insertInto('users')\n * .values({ name: 'Test User', email: 'test@example.com' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * });\n *\n * // With fixtures for factories\n * const it = wrapVitestKyselyTransaction<DB, { factory: Factory }>(test, {\n * connection: db,\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user.id).toBeDefined();\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<\n\tDatabase,\n\tExtended extends Record<string, unknown> = {},\n>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>) {\n\tconst wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n\treturn wrapper.wrapVitestWithTransaction(options);\n}\n\n/**\n * Extends a Kysely transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Database - The database schema type\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction\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 { test } from 'vitest';\n * import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';\n *\n * // Define your builders\n * const builders = {\n * user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestKyselyTransaction<DB>(test, {\n * connection: db,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new KyselyFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await trx\n * .selectFrom('users')\n * .where('id', '=', user.id)\n * .selectAll()\n * .executeTakeFirst();\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n\tDatabase,\n\tExtended extends Record<string, unknown>,\n\tT extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>) {\n\treturn baseExtendWithFixtures<Transaction<Database>, Extended, T>(\n\t\twrappedTest,\n\t\tfixtures,\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,4BAGdA,KAAcC,SAAuD;CACtE,MAAM,UAAU,IAAIC,wEAA0C;AAE9D,QAAO,QAAQ,0BAA0B,QAAQ;AACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDD,SAAgBC,qBAIdC,aAAgBC,UAA4D;AAC7E,QAAO,qDACN,aACA,SACA;AACD"}
1
+ {"version":3,"file":"kysely.cjs","names":["VitestKyselyTransactionIsolator","baseExtendWithFixtures"],"sources":["../src/kysely.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport type { TestAPI } from 'vitest';\nimport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nimport {\n\textendWithFixtures as baseExtendWithFixtures,\n\ttype DatabaseConnection,\n\ttype FixtureCreators,\n\ttype IsolationLevel,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific exports for test utilities.\n * Provides factories, migrators, and transaction isolators for Kysely ORM.\n */\n\nexport type { ExtractSeedAttrs, FactorySeed } from './Factory';\nexport { KyselyFactory } from './KyselyFactory';\nexport { PostgresKyselyMigrator } from './PostgresKyselyMigrator';\nexport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nexport type {\n\tDatabaseFixtures,\n\tExtendedDatabaseFixtures,\n\tFixtureCreators,\n\tTestWithExtendedFixtures,\n\tTransactionWrapperOptions,\n} from './VitestTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific options for transaction wrapping.\n */\nexport interface KyselyTransactionOptions<\n\tDatabase,\n\tExtended extends Record<string, unknown> = {},\n> {\n\t/** Function that creates or returns a Kysely database instance */\n\tconnection: DatabaseConnection<Kysely<Database>>;\n\t/** Optional setup function to run within the transaction before each test */\n\tsetup?: (trx: Transaction<Database>) => 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<Database>, Extended>;\n}\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { type FakerFactory, faker } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Database - The database schema type\n * @template Extended - Additional fixtures to provide\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param options - Configuration options for transaction wrapping\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';\n * import { db } from './database';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestKyselyTransaction(test, {\n * connection: db,\n * });\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await trx\n * .insertInto('users')\n * .values({ name: 'Test User', email: 'test@example.com' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * });\n *\n * // With fixtures for factories\n * const it = wrapVitestKyselyTransaction<DB, { factory: Factory }>(test, {\n * connection: db,\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user.id).toBeDefined();\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<\n\tDatabase,\n\tExtended extends Record<string, unknown> = {},\n>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>) {\n\tconst wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n\treturn wrapper.wrapVitestWithTransaction(options);\n}\n\n/**\n * Extends a Kysely transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Database - The database schema type\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction\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 { test } from 'vitest';\n * import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';\n *\n * // Define your builders\n * const builders = {\n * user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestKyselyTransaction<DB>(test, {\n * connection: db,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new KyselyFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await trx\n * .selectFrom('users')\n * .where('id', '=', user.id)\n * .selectAll()\n * .executeTakeFirst();\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n\tDatabase,\n\tExtended extends Record<string, unknown>,\n\tT extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>) {\n\treturn baseExtendWithFixtures<Transaction<Database>, Extended, T>(\n\t\twrappedTest,\n\t\tfixtures,\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,4BAGd,KAAc,SAAuD;CAGtE,OAAO,IAFaA,wCAAAA,gCAA0C,GAEjD,CAAC,CAAC,0BAA0B,OAAO;AACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,mBAId,aAAgB,UAA4D;CAC7E,OAAOC,kCAAAA,mBACN,aACA,QACD;AACD"}
package/dist/kysely.d.cts CHANGED
@@ -1,19 +1,16 @@
1
- import { FakerFactory, faker } from "./faker-Cg76aFNO.cjs";
2
- import { ExtractSeedAttrs, FactorySeed } from "./Factory-BOX312yd.cjs";
3
- import { KyselyFactory } from "./KyselyFactory-Dy5zzV4B.cjs";
4
- import "./PostgresMigrator-CeYy-eHF.cjs";
5
- import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-B2M6Gjvv.cjs";
6
- import { DatabaseConnection, DatabaseFixtures, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions } from "./VitestTransactionIsolator-glcxyS_R.cjs";
7
- import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-DJasVuIZ.cjs";
1
+ import { FakerFactory, faker } from "./faker.cjs";
2
+ import { ExtractSeedAttrs, FactorySeed } from "./Factory.cjs";
3
+ import { KyselyFactory } from "./KyselyFactory.cjs";
4
+ import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator.cjs";
5
+ import { DatabaseConnection, DatabaseFixtures, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions } from "./VitestTransactionIsolator.cjs";
6
+ import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator.cjs";
8
7
  import { Kysely, Transaction } from "kysely";
9
8
  import { TestAPI } from "vitest";
10
-
11
9
  //#region src/kysely.d.ts
12
-
13
10
  /**
14
11
  * Kysely-specific options for transaction wrapping.
15
12
  */
16
- interface KyselyTransactionOptions<Database, Extended extends Record<string, unknown> = {}> {
13
+ export interface KyselyTransactionOptions<Database, Extended extends Record<string, unknown> = {}> {
17
14
  /** Function that creates or returns a Kysely database instance */
18
15
  connection: DatabaseConnection<Kysely<Database>>;
19
16
  /** Optional setup function to run within the transaction before each test */
@@ -70,7 +67,7 @@ interface KyselyTransactionOptions<Database, Extended extends Record<string, unk
70
67
  * });
71
68
  * ```
72
69
  */
73
- declare function wrapVitestKyselyTransaction<Database, Extended extends Record<string, unknown> = {}>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>): TestAPI<DatabaseFixtures<Transaction<Database>, object> & Extended>;
70
+ export declare function wrapVitestKyselyTransaction<Database, Extended extends Record<string, unknown> = {}>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>): TestAPI<DatabaseFixtures<Transaction<Database>, object> & Extended>;
74
71
  /**
75
72
  * Extends a Kysely transaction-wrapped test with additional fixtures.
76
73
  * Each fixture receives the transaction and can create dependencies like factories or repositories.
@@ -123,8 +120,7 @@ declare function wrapVitestKyselyTransaction<Database, Extended extends Record<s
123
120
  * });
124
121
  * ```
125
122
  */
126
- declare function extendWithFixtures<Database, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>): TestWithExtendedFixtures<Transaction<Database>, Extended, T>;
127
- //# sourceMappingURL=kysely.d.ts.map
123
+ export declare function extendWithFixtures<Database, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>): TestWithExtendedFixtures<Transaction<Database>, Extended, T>;
128
124
  //#endregion
129
- export { DatabaseFixtures, ExtendedDatabaseFixtures, ExtractSeedAttrs, FactorySeed, FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, KyselyTransactionOptions, PostgresKyselyMigrator, TestWithExtendedFixtures, TransactionWrapperOptions, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
125
+ export { type DatabaseFixtures, type ExtendedDatabaseFixtures, type ExtractSeedAttrs, type FactorySeed, type FakerFactory, type FixtureCreators, IsolationLevel, KyselyFactory, PostgresKyselyMigrator, type TestWithExtendedFixtures, type TransactionWrapperOptions, VitestKyselyTransactionIsolator, faker };
130
126
  //# sourceMappingURL=kysely.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"kysely.d.cts","names":[],"sources":["../src/kysely.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;AAoCa,UALI,wBAKJ,CAAA,QAAA,EAAA,iBAHK,MAGL,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA;EAAkB;EAEI,UAApB,EAFF,kBAEE,CAFiB,MAEjB,CAFwB,QAExB,CAAA,CAAA;EAAW;EAAsB,KAE9B,CAAA,EAAA,CAAA,GAAA,EAFH,WAEG,CAFS,QAET,CAAA,EAAA,GAFuB,OAEvB,CAAA,IAAA,CAAA;EAAc;EAEgB,cAApB,CAAA,EAFV,cAEU;EAAW;EAAoB,QAA/C,CAAA,EAAA,eAAA,CAAgB,WAAhB,CAA4B,QAA5B,CAAA,EAAuC,QAAvC,CAAA;AAAe;;;;;;;;;;;;AAwD0C;AA0DrE;;;;;;;;;;;;;;;;;AAI4E;;;;;;;;;;;;;;;;;;iBAjE5D,uDAEE,mCACX,kBAAkB,yBAAyB,UAAU,YAAS,QAAA,iBAAA,YAAA,qBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0DrD,8CAEE,mCACP,WAAW,qBAAqB,WAAW,iCACvC,aAAa,gBAAgB,YAAY,WAAW,YAAS,yBAAA,YAAA,WAAA,UAAA"}
1
+ {"version":3,"file":"kysely.d.cts","names":["_$__VitestTransactionIsolator0.DatabaseFixtures","_$__VitestTransactionIsolator0.TestWithExtendedFixtures"],"sources":["../src/kysely.ts"],"mappings":";;;;;;;;;;;;iBA+BiB,yBAChB,UACA,iBAAiB;;EAGjB,YAAY,mBAAmB,OAAO;;EAEtC,SAAS,KAAK,YAAY,cAAc;;EAExC,iBAAiB;;EAEjB,WAAW,gBAAgB,YAAY,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqDnC,4BACf,UACA,iBAAiB,8BAChB,KAAK,SAAS,SAAS,yBAAyB,UAAU,YAAS,QAAAA,iBAAA,YAAA,qBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA0DrD,mBACf,UACA,iBAAiB,yBACjB,UAAU,WAAW,qBAAqB,WAAW,oBACpD,aAAa,GAAG,UAAU,gBAAgB,YAAY,WAAW,YAASC,yBAAA,YAAA,WAAA,UAAA"}
package/dist/kysely.d.mts CHANGED
@@ -1,19 +1,16 @@
1
- import { FakerFactory, faker } from "./faker-D9gz7KjY.mjs";
2
- import { ExtractSeedAttrs, FactorySeed } from "./Factory-C6W78ulZ.mjs";
3
- import { KyselyFactory } from "./KyselyFactory-Cc2UmOJk.mjs";
4
- import "./PostgresMigrator-C_QQ6q35.mjs";
5
- import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CvwXycJE.mjs";
6
- import { DatabaseConnection, DatabaseFixtures, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions } from "./VitestTransactionIsolator-BLaw80cx.mjs";
7
- import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-CwlTo6yf.mjs";
1
+ import { FakerFactory, faker } from "./faker.mjs";
2
+ import { ExtractSeedAttrs, FactorySeed } from "./Factory.mjs";
3
+ import { KyselyFactory } from "./KyselyFactory.mjs";
4
+ import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator.mjs";
5
+ import { DatabaseConnection, DatabaseFixtures, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions } from "./VitestTransactionIsolator.mjs";
6
+ import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator.mjs";
8
7
  import { TestAPI } from "vitest";
9
8
  import { Kysely, Transaction } from "kysely";
10
-
11
9
  //#region src/kysely.d.ts
12
-
13
10
  /**
14
11
  * Kysely-specific options for transaction wrapping.
15
12
  */
16
- interface KyselyTransactionOptions<Database, Extended extends Record<string, unknown> = {}> {
13
+ export interface KyselyTransactionOptions<Database, Extended extends Record<string, unknown> = {}> {
17
14
  /** Function that creates or returns a Kysely database instance */
18
15
  connection: DatabaseConnection<Kysely<Database>>;
19
16
  /** Optional setup function to run within the transaction before each test */
@@ -70,7 +67,7 @@ interface KyselyTransactionOptions<Database, Extended extends Record<string, unk
70
67
  * });
71
68
  * ```
72
69
  */
73
- declare function wrapVitestKyselyTransaction<Database, Extended extends Record<string, unknown> = {}>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>): TestAPI<DatabaseFixtures<Transaction<Database>, object> & Extended>;
70
+ export declare function wrapVitestKyselyTransaction<Database, Extended extends Record<string, unknown> = {}>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>): TestAPI<DatabaseFixtures<Transaction<Database>, object> & Extended>;
74
71
  /**
75
72
  * Extends a Kysely transaction-wrapped test with additional fixtures.
76
73
  * Each fixture receives the transaction and can create dependencies like factories or repositories.
@@ -123,8 +120,7 @@ declare function wrapVitestKyselyTransaction<Database, Extended extends Record<s
123
120
  * });
124
121
  * ```
125
122
  */
126
- declare function extendWithFixtures<Database, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>): TestWithExtendedFixtures<Transaction<Database>, Extended, T>;
127
- //# sourceMappingURL=kysely.d.ts.map
123
+ export declare function extendWithFixtures<Database, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>): TestWithExtendedFixtures<Transaction<Database>, Extended, T>;
128
124
  //#endregion
129
- export { DatabaseFixtures, ExtendedDatabaseFixtures, ExtractSeedAttrs, FactorySeed, FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, KyselyTransactionOptions, PostgresKyselyMigrator, TestWithExtendedFixtures, TransactionWrapperOptions, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
125
+ export { type DatabaseFixtures, type ExtendedDatabaseFixtures, type ExtractSeedAttrs, type FactorySeed, type FakerFactory, type FixtureCreators, IsolationLevel, KyselyFactory, PostgresKyselyMigrator, type TestWithExtendedFixtures, type TransactionWrapperOptions, VitestKyselyTransactionIsolator, faker };
130
126
  //# sourceMappingURL=kysely.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"kysely.d.mts","names":[],"sources":["../src/kysely.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;AAoCa,UALI,wBAKJ,CAAA,QAAA,EAAA,iBAHK,MAGL,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA;EAAkB;EAEI,UAApB,EAFF,kBAEE,CAFiB,MAEjB,CAFwB,QAExB,CAAA,CAAA;EAAW;EAAsB,KAE9B,CAAA,EAAA,CAAA,GAAA,EAFH,WAEG,CAFS,QAET,CAAA,EAAA,GAFuB,OAEvB,CAAA,IAAA,CAAA;EAAc;EAEgB,cAApB,CAAA,EAFV,cAEU;EAAW;EAAoB,QAA/C,CAAA,EAAA,eAAA,CAAgB,WAAhB,CAA4B,QAA5B,CAAA,EAAuC,QAAvC,CAAA;AAAe;;;;;;;;;;;;AAwD0C;AA0DrE;;;;;;;;;;;;;;;;;AAI4E;;;;;;;;;;;;;;;;;;iBAjE5D,uDAEE,mCACX,kBAAkB,yBAAyB,UAAU,YAAS,QAAA,iBAAA,YAAA,qBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0DrD,8CAEE,mCACP,WAAW,qBAAqB,WAAW,iCACvC,aAAa,gBAAgB,YAAY,WAAW,YAAS,yBAAA,YAAA,WAAA,UAAA"}
1
+ {"version":3,"file":"kysely.d.mts","names":["_$__VitestTransactionIsolator0.DatabaseFixtures","_$__VitestTransactionIsolator0.TestWithExtendedFixtures"],"sources":["../src/kysely.ts"],"mappings":";;;;;;;;;;;;iBA+BiB,yBAChB,UACA,iBAAiB;;EAGjB,YAAY,mBAAmB,OAAO;;EAEtC,SAAS,KAAK,YAAY,cAAc;;EAExC,iBAAiB;;EAEjB,WAAW,gBAAgB,YAAY,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqDnC,4BACf,UACA,iBAAiB,8BAChB,KAAK,SAAS,SAAS,yBAAyB,UAAU,YAAS,QAAAA,iBAAA,YAAA,qBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA0DrD,mBACf,UACA,iBAAiB,yBACjB,UAAU,WAAW,qBAAqB,WAAW,oBACpD,aAAa,GAAG,UAAU,gBAAgB,YAAY,WAAW,YAASC,yBAAA,YAAA,WAAA,UAAA"}
package/dist/kysely.mjs CHANGED
@@ -1,11 +1,8 @@
1
- import "./Factory-BFVnMMCC.mjs";
2
- import { faker } from "./faker-BGKYFoCT.mjs";
3
- import { KyselyFactory } from "./KyselyFactory-DMswpwji.mjs";
4
- import "./PostgresMigrator-DVAY04qN.mjs";
5
- import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-PI0QhvB1.mjs";
6
- import { IsolationLevel, extendWithFixtures } from "./VitestTransactionIsolator-CvwPecpl.mjs";
7
- import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-1Saieke7.mjs";
8
-
1
+ import { faker } from "./faker.mjs";
2
+ import { KyselyFactory } from "./KyselyFactory.mjs";
3
+ import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator.mjs";
4
+ import { IsolationLevel, extendWithFixtures as extendWithFixtures$1 } from "./VitestTransactionIsolator.mjs";
5
+ import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator.mjs";
9
6
  //#region src/kysely.ts
10
7
  /**
11
8
  * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.
@@ -55,8 +52,7 @@ import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolat
55
52
  * ```
56
53
  */
57
54
  function wrapVitestKyselyTransaction(api, options) {
58
- const wrapper = new VitestKyselyTransactionIsolator(api);
59
- return wrapper.wrapVitestWithTransaction(options);
55
+ return new VitestKyselyTransactionIsolator(api).wrapVitestWithTransaction(options);
60
56
  }
61
57
  /**
62
58
  * Extends a Kysely transaction-wrapped test with additional fixtures.
@@ -110,10 +106,10 @@ function wrapVitestKyselyTransaction(api, options) {
110
106
  * });
111
107
  * ```
112
108
  */
113
- function extendWithFixtures$1(wrappedTest, fixtures) {
114
- return extendWithFixtures(wrappedTest, fixtures);
109
+ function extendWithFixtures(wrappedTest, fixtures) {
110
+ return extendWithFixtures$1(wrappedTest, fixtures);
115
111
  }
116
-
117
112
  //#endregion
118
- export { IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, extendWithFixtures$1 as extendWithFixtures, faker, wrapVitestKyselyTransaction };
113
+ export { IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
114
+
119
115
  //# sourceMappingURL=kysely.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"kysely.mjs","names":["api: TestAPI","options: KyselyTransactionOptions<Database, Extended>","extendWithFixtures","wrappedTest: T","fixtures: FixtureCreators<Transaction<Database>, Extended>"],"sources":["../src/kysely.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport type { TestAPI } from 'vitest';\nimport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nimport {\n\textendWithFixtures as baseExtendWithFixtures,\n\ttype DatabaseConnection,\n\ttype FixtureCreators,\n\ttype IsolationLevel,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific exports for test utilities.\n * Provides factories, migrators, and transaction isolators for Kysely ORM.\n */\n\nexport type { ExtractSeedAttrs, FactorySeed } from './Factory';\nexport { KyselyFactory } from './KyselyFactory';\nexport { PostgresKyselyMigrator } from './PostgresKyselyMigrator';\nexport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nexport type {\n\tDatabaseFixtures,\n\tExtendedDatabaseFixtures,\n\tFixtureCreators,\n\tTestWithExtendedFixtures,\n\tTransactionWrapperOptions,\n} from './VitestTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific options for transaction wrapping.\n */\nexport interface KyselyTransactionOptions<\n\tDatabase,\n\tExtended extends Record<string, unknown> = {},\n> {\n\t/** Function that creates or returns a Kysely database instance */\n\tconnection: DatabaseConnection<Kysely<Database>>;\n\t/** Optional setup function to run within the transaction before each test */\n\tsetup?: (trx: Transaction<Database>) => 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<Database>, Extended>;\n}\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { type FakerFactory, faker } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Database - The database schema type\n * @template Extended - Additional fixtures to provide\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param options - Configuration options for transaction wrapping\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';\n * import { db } from './database';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestKyselyTransaction(test, {\n * connection: db,\n * });\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await trx\n * .insertInto('users')\n * .values({ name: 'Test User', email: 'test@example.com' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * });\n *\n * // With fixtures for factories\n * const it = wrapVitestKyselyTransaction<DB, { factory: Factory }>(test, {\n * connection: db,\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user.id).toBeDefined();\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<\n\tDatabase,\n\tExtended extends Record<string, unknown> = {},\n>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>) {\n\tconst wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n\treturn wrapper.wrapVitestWithTransaction(options);\n}\n\n/**\n * Extends a Kysely transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Database - The database schema type\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction\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 { test } from 'vitest';\n * import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';\n *\n * // Define your builders\n * const builders = {\n * user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestKyselyTransaction<DB>(test, {\n * connection: db,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new KyselyFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await trx\n * .selectFrom('users')\n * .where('id', '=', user.id)\n * .selectAll()\n * .executeTakeFirst();\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n\tDatabase,\n\tExtended extends Record<string, unknown>,\n\tT extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>) {\n\treturn baseExtendWithFixtures<Transaction<Database>, Extended, T>(\n\t\twrappedTest,\n\t\tfixtures,\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,4BAGdA,KAAcC,SAAuD;CACtE,MAAM,UAAU,IAAI,gCAA0C;AAE9D,QAAO,QAAQ,0BAA0B,QAAQ;AACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDD,SAAgBC,qBAIdC,aAAgBC,UAA4D;AAC7E,QAAO,mBACN,aACA,SACA;AACD"}
1
+ {"version":3,"file":"kysely.mjs","names":["baseExtendWithFixtures"],"sources":["../src/kysely.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport type { TestAPI } from 'vitest';\nimport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nimport {\n\textendWithFixtures as baseExtendWithFixtures,\n\ttype DatabaseConnection,\n\ttype FixtureCreators,\n\ttype IsolationLevel,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific exports for test utilities.\n * Provides factories, migrators, and transaction isolators for Kysely ORM.\n */\n\nexport type { ExtractSeedAttrs, FactorySeed } from './Factory';\nexport { KyselyFactory } from './KyselyFactory';\nexport { PostgresKyselyMigrator } from './PostgresKyselyMigrator';\nexport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nexport type {\n\tDatabaseFixtures,\n\tExtendedDatabaseFixtures,\n\tFixtureCreators,\n\tTestWithExtendedFixtures,\n\tTransactionWrapperOptions,\n} from './VitestTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific options for transaction wrapping.\n */\nexport interface KyselyTransactionOptions<\n\tDatabase,\n\tExtended extends Record<string, unknown> = {},\n> {\n\t/** Function that creates or returns a Kysely database instance */\n\tconnection: DatabaseConnection<Kysely<Database>>;\n\t/** Optional setup function to run within the transaction before each test */\n\tsetup?: (trx: Transaction<Database>) => 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<Database>, Extended>;\n}\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { type FakerFactory, faker } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Database - The database schema type\n * @template Extended - Additional fixtures to provide\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param options - Configuration options for transaction wrapping\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';\n * import { db } from './database';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestKyselyTransaction(test, {\n * connection: db,\n * });\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await trx\n * .insertInto('users')\n * .values({ name: 'Test User', email: 'test@example.com' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * });\n *\n * // With fixtures for factories\n * const it = wrapVitestKyselyTransaction<DB, { factory: Factory }>(test, {\n * connection: db,\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user.id).toBeDefined();\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<\n\tDatabase,\n\tExtended extends Record<string, unknown> = {},\n>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>) {\n\tconst wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n\treturn wrapper.wrapVitestWithTransaction(options);\n}\n\n/**\n * Extends a Kysely transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Database - The database schema type\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction\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 { test } from 'vitest';\n * import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';\n *\n * // Define your builders\n * const builders = {\n * user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestKyselyTransaction<DB>(test, {\n * connection: db,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new KyselyFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await trx\n * .selectFrom('users')\n * .where('id', '=', user.id)\n * .selectAll()\n * .executeTakeFirst();\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n\tDatabase,\n\tExtended extends Record<string, unknown>,\n\tT extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>) {\n\treturn baseExtendWithFixtures<Transaction<Database>, Extended, T>(\n\t\twrappedTest,\n\t\tfixtures,\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,4BAGd,KAAc,SAAuD;CAGtE,OAAO,IAFa,gCAA0C,GAEjD,CAAC,CAAC,0BAA0B,OAAO;AACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,mBAId,aAAgB,UAA4D;CAC7E,OAAOA,qBACN,aACA,QACD;AACD"}
package/dist/logger.cjs CHANGED
@@ -1,6 +1,5 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const vitest = require_chunk.__toESM(require("vitest"));
3
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let vitest = require("vitest");
4
3
  //#region src/logger.ts
5
4
  /**
6
5
  * Creates a mock Logger for testing
@@ -17,7 +16,7 @@ function createMockLogger() {
17
16
  };
18
17
  return logger;
19
18
  }
20
-
21
19
  //#endregion
22
20
  exports.createMockLogger = createMockLogger;
21
+
23
22
  //# sourceMappingURL=logger.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.cjs","names":["logger: Logger"],"sources":["../src/logger.ts"],"sourcesContent":["import type { Logger } from '@geekmidas/logger';\nimport { vi } from 'vitest';\n\n/**\n * Creates a mock Logger for testing\n */\nexport function createMockLogger(): Logger {\n\tconst logger: Logger = {\n\t\tdebug: vi.fn(),\n\t\tinfo: vi.fn(),\n\t\twarn: vi.fn(),\n\t\terror: vi.fn(),\n\t\tfatal: vi.fn(),\n\t\ttrace: vi.fn(),\n\t\tchild: vi.fn(() => logger),\n\t};\n\treturn logger;\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,mBAA2B;CAC1C,MAAMA,SAAiB;EACtB,OAAO,UAAG,IAAI;EACd,MAAM,UAAG,IAAI;EACb,MAAM,UAAG,IAAI;EACb,OAAO,UAAG,IAAI;EACd,OAAO,UAAG,IAAI;EACd,OAAO,UAAG,IAAI;EACd,OAAO,UAAG,GAAG,MAAM,OAAO;CAC1B;AACD,QAAO;AACP"}
1
+ {"version":3,"file":"logger.cjs","names":["vi"],"sources":["../src/logger.ts"],"sourcesContent":["import type { Logger } from '@geekmidas/logger';\nimport { vi } from 'vitest';\n\n/**\n * Creates a mock Logger for testing\n */\nexport function createMockLogger(): Logger {\n\tconst logger: Logger = {\n\t\tdebug: vi.fn(),\n\t\tinfo: vi.fn(),\n\t\twarn: vi.fn(),\n\t\terror: vi.fn(),\n\t\tfatal: vi.fn(),\n\t\ttrace: vi.fn(),\n\t\tchild: vi.fn(() => logger),\n\t};\n\treturn logger;\n}\n"],"mappings":";;;;;;AAMA,SAAgB,mBAA2B;CAC1C,MAAM,SAAiB;EACtB,OAAOA,OAAAA,GAAG,GAAG;EACb,MAAMA,OAAAA,GAAG,GAAG;EACZ,MAAMA,OAAAA,GAAG,GAAG;EACZ,OAAOA,OAAAA,GAAG,GAAG;EACb,OAAOA,OAAAA,GAAG,GAAG;EACb,OAAOA,OAAAA,GAAG,GAAG;EACb,OAAOA,OAAAA,GAAG,SAAS,MAAM;CAC1B;CACA,OAAO;AACR"}
package/dist/logger.d.cts CHANGED
@@ -1,12 +1,8 @@
1
1
  import { Logger } from "@geekmidas/logger";
2
-
3
2
  //#region src/logger.d.ts
4
-
5
3
  /**
6
4
  * Creates a mock Logger for testing
7
5
  */
8
- declare function createMockLogger(): Logger;
9
- //# sourceMappingURL=logger.d.ts.map
6
+ export declare function createMockLogger(): Logger;
10
7
  //#endregion
11
- export { createMockLogger };
12
8
  //# sourceMappingURL=logger.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.cts","names":[],"sources":["../src/logger.ts"],"sourcesContent":[],"mappings":";;;;;;AAMA;iBAAgB,gBAAA,CAAA,GAAoB"}
1
+ {"version":3,"file":"logger.d.cts","names":[],"sources":["../src/logger.ts"],"mappings":";;;;;wBAMgB,oBAAoB"}
package/dist/logger.d.mts CHANGED
@@ -1,12 +1,8 @@
1
1
  import { Logger } from "@geekmidas/logger";
2
-
3
2
  //#region src/logger.d.ts
4
-
5
3
  /**
6
4
  * Creates a mock Logger for testing
7
5
  */
8
- declare function createMockLogger(): Logger;
9
- //# sourceMappingURL=logger.d.ts.map
6
+ export declare function createMockLogger(): Logger;
10
7
  //#endregion
11
- export { createMockLogger };
12
8
  //# sourceMappingURL=logger.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.mts","names":[],"sources":["../src/logger.ts"],"sourcesContent":[],"mappings":";;;;;;AAMA;iBAAgB,gBAAA,CAAA,GAAoB"}
1
+ {"version":3,"file":"logger.d.mts","names":[],"sources":["../src/logger.ts"],"mappings":";;;;;wBAMgB,oBAAoB"}
package/dist/logger.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { vi } from "vitest";
2
-
3
2
  //#region src/logger.ts
4
3
  /**
5
4
  * Creates a mock Logger for testing
@@ -16,7 +15,7 @@ function createMockLogger() {
16
15
  };
17
16
  return logger;
18
17
  }
19
-
20
18
  //#endregion
21
19
  export { createMockLogger };
20
+
22
21
  //# sourceMappingURL=logger.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.mjs","names":["logger: Logger"],"sources":["../src/logger.ts"],"sourcesContent":["import type { Logger } from '@geekmidas/logger';\nimport { vi } from 'vitest';\n\n/**\n * Creates a mock Logger for testing\n */\nexport function createMockLogger(): Logger {\n\tconst logger: Logger = {\n\t\tdebug: vi.fn(),\n\t\tinfo: vi.fn(),\n\t\twarn: vi.fn(),\n\t\terror: vi.fn(),\n\t\tfatal: vi.fn(),\n\t\ttrace: vi.fn(),\n\t\tchild: vi.fn(() => logger),\n\t};\n\treturn logger;\n}\n"],"mappings":";;;;;;AAMA,SAAgB,mBAA2B;CAC1C,MAAMA,SAAiB;EACtB,OAAO,GAAG,IAAI;EACd,MAAM,GAAG,IAAI;EACb,MAAM,GAAG,IAAI;EACb,OAAO,GAAG,IAAI;EACd,OAAO,GAAG,IAAI;EACd,OAAO,GAAG,IAAI;EACd,OAAO,GAAG,GAAG,MAAM,OAAO;CAC1B;AACD,QAAO;AACP"}
1
+ {"version":3,"file":"logger.mjs","names":[],"sources":["../src/logger.ts"],"sourcesContent":["import type { Logger } from '@geekmidas/logger';\nimport { vi } from 'vitest';\n\n/**\n * Creates a mock Logger for testing\n */\nexport function createMockLogger(): Logger {\n\tconst logger: Logger = {\n\t\tdebug: vi.fn(),\n\t\tinfo: vi.fn(),\n\t\twarn: vi.fn(),\n\t\terror: vi.fn(),\n\t\tfatal: vi.fn(),\n\t\ttrace: vi.fn(),\n\t\tchild: vi.fn(() => logger),\n\t};\n\treturn logger;\n}\n"],"mappings":";;;;;AAMA,SAAgB,mBAA2B;CAC1C,MAAM,SAAiB;EACtB,OAAO,GAAG,GAAG;EACb,MAAM,GAAG,GAAG;EACZ,MAAM,GAAG,GAAG;EACZ,OAAO,GAAG,GAAG;EACb,OAAO,GAAG,GAAG;EACb,OAAO,GAAG,GAAG;EACb,OAAO,GAAG,SAAS,MAAM;CAC1B;CACA,OAAO;AACR"}
@@ -0,0 +1,95 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/mailbox.ts
3
+ /**
4
+ * The mail a test sent, read from Mailpit.
5
+ *
6
+ * Locally, mail goes over real SMTP to Mailpit — the same client, the same
7
+ * message, only the host differs. A test reads what arrived through Mailpit's
8
+ * HTTP API, so a magic link is signed in with by opening the email that was
9
+ * actually sent rather than a token pulled from somewhere else.
10
+ *
11
+ * Mailpit has one inbox for everything, and transactions do not reach it, so a
12
+ * test keeps to its own mail by address: a unique recipient per test, read by
13
+ * `to:`, and cleared afterwards.
14
+ */
15
+ /** How long `last()` waits for mail that is still on its way. */
16
+ const DEFAULT_TIMEOUT = 5e3;
17
+ const POLL_INTERVAL = 50;
18
+ /** A way to read the mail sent to one address. */
19
+ function createMailbox(options) {
20
+ const inbox = options.inbox.replace(/\/$/, "");
21
+ const timeout = options.timeout ?? DEFAULT_TIMEOUT;
22
+ const get = (path, init) => (options.fetch ?? globalThis.fetch)(`${inbox}${path}`, init);
23
+ return (address) => {
24
+ const query = `?query=${encodeURIComponent(`to:"${address}"`)}`;
25
+ const all = async () => {
26
+ const found = await json(await get(`/api/v1/search${query}`), inbox);
27
+ return Promise.all(found.messages.map(async ({ ID }) => email(await json(await get(`/api/v1/message/${ID}`), inbox))));
28
+ };
29
+ return {
30
+ all,
31
+ async last() {
32
+ const deadline = Date.now() + timeout;
33
+ for (;;) {
34
+ const [newest] = await all();
35
+ if (newest) return newest;
36
+ if (Date.now() >= deadline) throw new NoMail(address, timeout);
37
+ await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
38
+ }
39
+ },
40
+ async clear() {
41
+ const response = await get(`/api/v1/search${query}`, { method: "DELETE" });
42
+ if (!response.ok) throw new InboxUnreachable(inbox, response.status);
43
+ }
44
+ };
45
+ };
46
+ }
47
+ async function json(response, inbox) {
48
+ if (!response.ok) throw new InboxUnreachable(inbox, response.status);
49
+ return await response.json();
50
+ }
51
+ function email(message) {
52
+ const links = [...new Set([...(message.HTML ?? "").matchAll(/href="(https?:\/\/[^"]+)"/g), ...(message.Text ?? "").matchAll(/(https?:\/\/[^\s<>"]+)/g)].map(([, url]) => decodeEntities(url)))];
53
+ return {
54
+ id: message.ID,
55
+ from: message.From.Address,
56
+ to: message.To.map(({ Address }) => Address),
57
+ subject: message.Subject,
58
+ text: message.Text ?? "",
59
+ html: message.HTML ?? "",
60
+ links,
61
+ link: links[0]
62
+ };
63
+ }
64
+ /** `&amp;` in an HTML attribute is `&` in the URL it names. */
65
+ function decodeEntities(url) {
66
+ return url.replaceAll("&amp;", "&");
67
+ }
68
+ /** No email to an address arrived in time. */
69
+ var NoMail = class extends Error {
70
+ address;
71
+ timeout;
72
+ constructor(address, timeout) {
73
+ super(`No email to ${address} arrived within ${timeout}ms. Check that the code under test sends it, and to that address.`);
74
+ this.address = address;
75
+ this.timeout = timeout;
76
+ this.name = "NoMail";
77
+ }
78
+ };
79
+ /** Mailpit did not answer. */
80
+ var InboxUnreachable = class extends Error {
81
+ inbox;
82
+ status;
83
+ constructor(inbox, status) {
84
+ super(`Mailpit at ${inbox} answered ${status}. Is it running? \`gkm test\` starts it when the app declares an Email construct.`);
85
+ this.inbox = inbox;
86
+ this.status = status;
87
+ this.name = "InboxUnreachable";
88
+ }
89
+ };
90
+ //#endregion
91
+ exports.InboxUnreachable = InboxUnreachable;
92
+ exports.NoMail = NoMail;
93
+ exports.createMailbox = createMailbox;
94
+
95
+ //# sourceMappingURL=mailbox.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mailbox.cjs","names":[],"sources":["../src/mailbox.ts"],"sourcesContent":["/**\n * The mail a test sent, read from Mailpit.\n *\n * Locally, mail goes over real SMTP to Mailpit — the same client, the same\n * message, only the host differs. A test reads what arrived through Mailpit's\n * HTTP API, so a magic link is signed in with by opening the email that was\n * actually sent rather than a token pulled from somewhere else.\n *\n * Mailpit has one inbox for everything, and transactions do not reach it, so a\n * test keeps to its own mail by address: a unique recipient per test, read by\n * `to:`, and cleared afterwards.\n */\n\n/** How long `last()` waits for mail that is still on its way. */\nconst DEFAULT_TIMEOUT = 5_000;\nconst POLL_INTERVAL = 50;\n\nexport interface MailboxOptions {\n\t/** Mailpit's HTTP address — what `gkm test` injects as `<ID>_INBOX_URL`. */\n\tinbox: string;\n\t/** The `fetch` to read it with. Defaults to the global one. */\n\tfetch?: typeof fetch;\n\t/** How long `last()` waits for mail to arrive. */\n\ttimeout?: number;\n}\n\n/** One email, as it arrived. */\nexport interface Email {\n\tid: string;\n\tfrom: string;\n\tto: string[];\n\tsubject: string;\n\ttext: string;\n\thtml: string;\n\t/** Every `http(s)` link in the email, in order. */\n\tlinks: string[];\n\t/** The first link — the one a sign-in or confirmation email is about. */\n\tlink: string | undefined;\n}\n\nexport interface Mailbox {\n\t/** The newest email to this address, waiting for one if none has arrived. */\n\tlast(): Promise<Email>;\n\t/** Every email to this address, newest first. */\n\tall(): Promise<Email[]>;\n\t/** Delete every email to this address. */\n\tclear(): Promise<void>;\n}\n\n/** A way to read the mail sent to one address. */\nexport function createMailbox(\n\toptions: MailboxOptions,\n): (address: string) => Mailbox {\n\tconst inbox = options.inbox.replace(/\\/$/, '');\n\tconst timeout = options.timeout ?? DEFAULT_TIMEOUT;\n\tconst get = (path: string, init?: RequestInit) =>\n\t\t(options.fetch ?? globalThis.fetch)(`${inbox}${path}`, init);\n\n\treturn (address) => {\n\t\tconst query = `?query=${encodeURIComponent(`to:\"${address}\"`)}`;\n\n\t\tconst all = async (): Promise<Email[]> => {\n\t\t\tconst found = await json<SearchResult>(\n\t\t\t\tawait get(`/api/v1/search${query}`),\n\t\t\t\tinbox,\n\t\t\t);\n\t\t\treturn Promise.all(\n\t\t\t\tfound.messages.map(async ({ ID }) =>\n\t\t\t\t\temail(await json<Message>(await get(`/api/v1/message/${ID}`), inbox)),\n\t\t\t\t),\n\t\t\t);\n\t\t};\n\n\t\treturn {\n\t\t\tall,\n\t\t\tasync last() {\n\t\t\t\tconst deadline = Date.now() + timeout;\n\t\t\t\tfor (;;) {\n\t\t\t\t\tconst [newest] = await all();\n\t\t\t\t\tif (newest) return newest;\n\t\t\t\t\tif (Date.now() >= deadline) throw new NoMail(address, timeout);\n\t\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));\n\t\t\t\t}\n\t\t\t},\n\t\t\tasync clear() {\n\t\t\t\tconst response = await get(`/api/v1/search${query}`, {\n\t\t\t\t\tmethod: 'DELETE',\n\t\t\t\t});\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tthrow new InboxUnreachable(inbox, response.status);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t};\n}\n\ninterface SearchResult {\n\tmessages: { ID: string }[];\n}\n\ninterface Message {\n\tID: string;\n\tFrom: { Address: string };\n\tTo: { Address: string }[];\n\tSubject: string;\n\tText: string;\n\tHTML: string;\n}\n\nasync function json<T>(response: Response, inbox: string): Promise<T> {\n\tif (!response.ok) throw new InboxUnreachable(inbox, response.status);\n\treturn (await response.json()) as T;\n}\n\nfunction email(message: Message): Email {\n\tconst links = [\n\t\t...new Set(\n\t\t\t[\n\t\t\t\t...(message.HTML ?? '').matchAll(/href=\"(https?:\\/\\/[^\"]+)\"/g),\n\t\t\t\t...(message.Text ?? '').matchAll(/(https?:\\/\\/[^\\s<>\"]+)/g),\n\t\t\t].map(([, url]) => decodeEntities(url!)),\n\t\t),\n\t];\n\n\treturn {\n\t\tid: message.ID,\n\t\tfrom: message.From.Address,\n\t\tto: message.To.map(({ Address }) => Address),\n\t\tsubject: message.Subject,\n\t\ttext: message.Text ?? '',\n\t\thtml: message.HTML ?? '',\n\t\tlinks,\n\t\tlink: links[0],\n\t};\n}\n\n/** `&amp;` in an HTML attribute is `&` in the URL it names. */\nfunction decodeEntities(url: string): string {\n\treturn url.replaceAll('&amp;', '&');\n}\n\n/** No email to an address arrived in time. */\nexport class NoMail extends Error {\n\tconstructor(\n\t\treadonly address: string,\n\t\treadonly timeout: number,\n\t) {\n\t\tsuper(\n\t\t\t`No email to ${address} arrived within ${timeout}ms. Check that the ` +\n\t\t\t\t`code under test sends it, and to that address.`,\n\t\t);\n\t\tthis.name = 'NoMail';\n\t}\n}\n\n/** Mailpit did not answer. */\nexport class InboxUnreachable extends Error {\n\tconstructor(\n\t\treadonly inbox: string,\n\t\treadonly status: number,\n\t) {\n\t\tsuper(\n\t\t\t`Mailpit at ${inbox} answered ${status}. Is it running? \\`gkm test\\` ` +\n\t\t\t\t`starts it when the app declares an Email construct.`,\n\t\t);\n\t\tthis.name = 'InboxUnreachable';\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,MAAM,kBAAkB;AACxB,MAAM,gBAAgB;;AAmCtB,SAAgB,cACf,SAC+B;CAC/B,MAAM,QAAQ,QAAQ,MAAM,QAAQ,OAAO,EAAE;CAC7C,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,OAAO,MAAc,UACzB,QAAQ,SAAS,WAAW,MAAA,CAAO,GAAG,QAAQ,QAAQ,IAAI;CAE5D,QAAQ,YAAY;EACnB,MAAM,QAAQ,UAAU,mBAAmB,OAAO,QAAQ,EAAE;EAE5D,MAAM,MAAM,YAA8B;GACzC,MAAM,QAAQ,MAAM,KACnB,MAAM,IAAI,iBAAiB,OAAO,GAClC,KACD;GACA,OAAO,QAAQ,IACd,MAAM,SAAS,IAAI,OAAO,EAAE,SAC3B,MAAM,MAAM,KAAc,MAAM,IAAI,mBAAmB,IAAI,GAAG,KAAK,CAAC,CACrE,CACD;EACD;EAEA,OAAO;GACN;GACA,MAAM,OAAO;IACZ,MAAM,WAAW,KAAK,IAAI,IAAI;IAC9B,SAAS;KACR,MAAM,CAAC,UAAU,MAAM,IAAI;KAC3B,IAAI,QAAQ,OAAO;KACnB,IAAI,KAAK,IAAI,KAAK,UAAU,MAAM,IAAI,OAAO,SAAS,OAAO;KAC7D,MAAM,IAAI,SAAS,YAAY,WAAW,SAAS,aAAa,CAAC;IAClE;GACD;GACA,MAAM,QAAQ;IACb,MAAM,WAAW,MAAM,IAAI,iBAAiB,SAAS,EACpD,QAAQ,SACT,CAAC;IACD,IAAI,CAAC,SAAS,IACb,MAAM,IAAI,iBAAiB,OAAO,SAAS,MAAM;GAEnD;EACD;CACD;AACD;AAeA,eAAe,KAAQ,UAAoB,OAA2B;CACrE,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,iBAAiB,OAAO,SAAS,MAAM;CACnE,OAAQ,MAAM,SAAS,KAAK;AAC7B;AAEA,SAAS,MAAM,SAAyB;CACvC,MAAM,QAAQ,CACb,GAAG,IAAI,IACN,CACC,IAAI,QAAQ,QAAQ,GAAA,CAAI,SAAS,4BAA4B,GAC7D,IAAI,QAAQ,QAAQ,GAAA,CAAI,SAAS,yBAAyB,CAC3D,CAAC,CAAC,KAAK,GAAG,SAAS,eAAe,GAAI,CAAC,CACxC,CACD;CAEA,OAAO;EACN,IAAI,QAAQ;EACZ,MAAM,QAAQ,KAAK;EACnB,IAAI,QAAQ,GAAG,KAAK,EAAE,cAAc,OAAO;EAC3C,SAAS,QAAQ;EACjB,MAAM,QAAQ,QAAQ;EACtB,MAAM,QAAQ,QAAQ;EACtB;EACA,MAAM,MAAM;CACb;AACD;;AAGA,SAAS,eAAe,KAAqB;CAC5C,OAAO,IAAI,WAAW,SAAS,GAAG;AACnC;;AAGA,IAAa,SAAb,cAA4B,MAAM;CAEvB;CACA;CAFV,YACC,SACA,SACC;EACD,MACC,eAAe,QAAQ,kBAAkB,QAAQ,kEAElD;EANS,KAAA,UAAA;EACA,KAAA,UAAA;EAMT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,mBAAb,cAAsC,MAAM;CAEjC;CACA;CAFV,YACC,OACA,QACC;EACD,MACC,cAAc,MAAM,YAAY,OAAO,kFAExC;EANS,KAAA,QAAA;EACA,KAAA,SAAA;EAMT,KAAK,OAAO;CACb;AACD"}