@geekmidas/testkit 10.0.0-alpha.99 → 10.0.0

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 (337) hide show
  1. package/CHANGELOG.md +160 -0
  2. package/README.md +0 -74
  3. package/dist/Factory-BFVnMMCC.mjs +51 -0
  4. package/dist/Factory-BFVnMMCC.mjs.map +1 -0
  5. package/dist/Factory-BOX312yd.d.cts +147 -0
  6. package/dist/Factory-BOX312yd.d.cts.map +1 -0
  7. package/dist/Factory-BhjUOBWN.cjs +57 -0
  8. package/dist/Factory-BhjUOBWN.cjs.map +1 -0
  9. package/dist/Factory-SFupxRC2.d.mts +147 -0
  10. package/dist/Factory-SFupxRC2.d.mts.map +1 -0
  11. package/dist/Factory.cjs +2 -51
  12. package/dist/Factory.d.cts +3 -143
  13. package/dist/Factory.d.mts +3 -143
  14. package/dist/Factory.mjs +2 -50
  15. package/dist/KyselyFactory-BFqVIn_0.cjs +246 -0
  16. package/dist/KyselyFactory-BFqVIn_0.cjs.map +1 -0
  17. package/dist/KyselyFactory-DMswpwji.mjs +241 -0
  18. package/dist/KyselyFactory-DMswpwji.mjs.map +1 -0
  19. package/dist/KyselyFactory-Dy5zzV4B.d.cts +228 -0
  20. package/dist/KyselyFactory-Dy5zzV4B.d.cts.map +1 -0
  21. package/dist/KyselyFactory-vAxYodck.d.mts +228 -0
  22. package/dist/KyselyFactory-vAxYodck.d.mts.map +1 -0
  23. package/dist/KyselyFactory.cjs +4 -237
  24. package/dist/KyselyFactory.d.cts +4 -224
  25. package/dist/KyselyFactory.d.mts +4 -224
  26. package/dist/KyselyFactory.mjs +4 -236
  27. package/dist/ObjectionFactory-BWjB49-i.d.mts +241 -0
  28. package/dist/ObjectionFactory-BWjB49-i.d.mts.map +1 -0
  29. package/dist/ObjectionFactory-BeFBYcan.cjs +272 -0
  30. package/dist/ObjectionFactory-BeFBYcan.cjs.map +1 -0
  31. package/dist/ObjectionFactory-CD-WFuMJ.d.cts +241 -0
  32. package/dist/ObjectionFactory-CD-WFuMJ.d.cts.map +1 -0
  33. package/dist/ObjectionFactory-QCJ7u0Ql.mjs +267 -0
  34. package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +1 -0
  35. package/dist/ObjectionFactory.cjs +4 -265
  36. package/dist/ObjectionFactory.d.cts +4 -237
  37. package/dist/ObjectionFactory.d.mts +4 -237
  38. package/dist/ObjectionFactory.mjs +4 -264
  39. package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts +84 -0
  40. package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts.map +1 -0
  41. package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs +101 -0
  42. package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs.map +1 -0
  43. package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts +84 -0
  44. package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts.map +1 -0
  45. package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs +95 -0
  46. package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs.map +1 -0
  47. package/dist/PostgresKyselyMigrator.cjs +3 -94
  48. package/dist/PostgresKyselyMigrator.d.cts +3 -80
  49. package/dist/PostgresKyselyMigrator.d.mts +3 -80
  50. package/dist/PostgresKyselyMigrator.mjs +3 -93
  51. package/dist/{PostgresMigrator-CDPnnwMJ.d.cts → PostgresMigrator-C_QQ6q35.d.mts} +5 -11
  52. package/dist/PostgresMigrator-C_QQ6q35.d.mts.map +1 -0
  53. package/dist/{PostgresMigrator-CDPnnwMJ.d.mts → PostgresMigrator-CeYy-eHF.d.cts} +5 -11
  54. package/dist/PostgresMigrator-CeYy-eHF.d.cts.map +1 -0
  55. package/dist/PostgresMigrator-DVAY04qN.mjs +166 -0
  56. package/dist/PostgresMigrator-DVAY04qN.mjs.map +1 -0
  57. package/dist/PostgresMigrator-M9jpzOvN.cjs +172 -0
  58. package/dist/PostgresMigrator-M9jpzOvN.cjs.map +1 -0
  59. package/dist/PostgresMigrator.cjs +2 -178
  60. package/dist/PostgresMigrator.d.cts +1 -1
  61. package/dist/PostgresMigrator.d.mts +1 -1
  62. package/dist/PostgresMigrator.mjs +2 -175
  63. package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts +79 -0
  64. package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts.map +1 -0
  65. package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts +79 -0
  66. package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts.map +1 -0
  67. package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs +123 -0
  68. package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs.map +1 -0
  69. package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs +118 -0
  70. package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs.map +1 -0
  71. package/dist/PostgresObjectionMigrator.cjs +3 -118
  72. package/dist/PostgresObjectionMigrator.d.cts +3 -75
  73. package/dist/PostgresObjectionMigrator.d.mts +3 -75
  74. package/dist/PostgresObjectionMigrator.mjs +3 -117
  75. package/dist/VitestKyselyTransactionIsolator-0CqOsuc9.cjs +65 -0
  76. package/dist/VitestKyselyTransactionIsolator-0CqOsuc9.cjs.map +1 -0
  77. package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts +59 -0
  78. package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts.map +1 -0
  79. package/dist/VitestKyselyTransactionIsolator-CfSMOFlN.mjs +60 -0
  80. package/dist/VitestKyselyTransactionIsolator-CfSMOFlN.mjs.map +1 -0
  81. package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts +59 -0
  82. package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts.map +1 -0
  83. package/dist/VitestKyselyTransactionIsolator.cjs +3 -66
  84. package/dist/VitestKyselyTransactionIsolator.d.cts +3 -60
  85. package/dist/VitestKyselyTransactionIsolator.d.mts +3 -60
  86. package/dist/VitestKyselyTransactionIsolator.mjs +3 -65
  87. package/dist/VitestObjectionTransactionIsolator-B5J9jjKq.cjs +68 -0
  88. package/dist/VitestObjectionTransactionIsolator-B5J9jjKq.cjs.map +1 -0
  89. package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts +60 -0
  90. package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts.map +1 -0
  91. package/dist/VitestObjectionTransactionIsolator-CNo40EdC.mjs +63 -0
  92. package/dist/VitestObjectionTransactionIsolator-CNo40EdC.mjs.map +1 -0
  93. package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts +60 -0
  94. package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts.map +1 -0
  95. package/dist/VitestObjectionTransactionIsolator.cjs +3 -62
  96. package/dist/VitestObjectionTransactionIsolator.d.cts +3 -56
  97. package/dist/VitestObjectionTransactionIsolator.d.mts +3 -56
  98. package/dist/VitestObjectionTransactionIsolator.mjs +3 -61
  99. package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts +207 -0
  100. package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts.map +1 -0
  101. package/dist/VitestTransactionIsolator-CSroc7Df.d.cts +207 -0
  102. package/dist/VitestTransactionIsolator-CSroc7Df.d.cts.map +1 -0
  103. package/dist/VitestTransactionIsolator-CtZaOUjH.cjs +193 -0
  104. package/dist/VitestTransactionIsolator-CtZaOUjH.cjs.map +1 -0
  105. package/dist/VitestTransactionIsolator-D6ZxLWys.mjs +175 -0
  106. package/dist/VitestTransactionIsolator-D6ZxLWys.mjs.map +1 -0
  107. package/dist/VitestTransactionIsolator.cjs +4 -187
  108. package/dist/VitestTransactionIsolator.d.cts +2 -219
  109. package/dist/VitestTransactionIsolator.d.mts +2 -219
  110. package/dist/VitestTransactionIsolator.mjs +2 -184
  111. package/dist/aws.cjs +4 -3
  112. package/dist/aws.cjs.map +1 -1
  113. package/dist/aws.d.cts +8 -3
  114. package/dist/aws.d.cts.map +1 -1
  115. package/dist/aws.d.mts +8 -3
  116. package/dist/aws.d.mts.map +1 -1
  117. package/dist/aws.mjs +2 -1
  118. package/dist/aws.mjs.map +1 -1
  119. package/dist/benchmark.cjs +2 -2
  120. package/dist/benchmark.cjs.map +1 -1
  121. package/dist/benchmark.d.cts +6 -4
  122. package/dist/benchmark.d.cts.map +1 -1
  123. package/dist/benchmark.d.mts +6 -4
  124. package/dist/benchmark.d.mts.map +1 -1
  125. package/dist/benchmark.mjs +1 -1
  126. package/dist/benchmark.mjs.map +1 -1
  127. package/dist/better-auth.cjs +15 -31
  128. package/dist/better-auth.cjs.map +1 -1
  129. package/dist/better-auth.d.cts +4 -13142
  130. package/dist/better-auth.d.cts.map +1 -1
  131. package/dist/better-auth.d.mts +4 -13142
  132. package/dist/better-auth.d.mts.map +1 -1
  133. package/dist/better-auth.mjs +13 -29
  134. package/dist/better-auth.mjs.map +1 -1
  135. package/dist/{rolldown-runtime-VH7oDXx4.cjs → chunk-CUT6urMc.cjs} +10 -8
  136. package/dist/directory-Bpz5c5pj.d.cts +13 -0
  137. package/dist/directory-Bpz5c5pj.d.cts.map +1 -0
  138. package/dist/directory-BxjqmtCT.mjs +27 -0
  139. package/dist/directory-BxjqmtCT.mjs.map +1 -0
  140. package/dist/directory-CVrfTq1I.d.mts +13 -0
  141. package/dist/directory-CVrfTq1I.d.mts.map +1 -0
  142. package/dist/directory-DD_xQoSh.cjs +33 -0
  143. package/dist/directory-DD_xQoSh.cjs.map +1 -0
  144. package/dist/faker-B14IEMIN.cjs +304 -0
  145. package/dist/faker-B14IEMIN.cjs.map +1 -0
  146. package/dist/faker-BGKYFoCT.mjs +262 -0
  147. package/dist/faker-BGKYFoCT.mjs.map +1 -0
  148. package/dist/faker-Cg76aFNO.d.cts +166 -0
  149. package/dist/faker-Cg76aFNO.d.cts.map +1 -0
  150. package/dist/faker-DHh7xs4u.d.mts +166 -0
  151. package/dist/faker-DHh7xs4u.d.mts.map +1 -0
  152. package/dist/faker.cjs +8 -313
  153. package/dist/faker.d.cts +2 -169
  154. package/dist/faker.d.mts +2 -169
  155. package/dist/faker.mjs +2 -305
  156. package/dist/helpers.cjs +5 -6
  157. package/dist/helpers.cjs.map +1 -1
  158. package/dist/helpers.d.cts +5 -1
  159. package/dist/helpers.d.cts.map +1 -1
  160. package/dist/helpers.d.mts +5 -1
  161. package/dist/helpers.d.mts.map +1 -1
  162. package/dist/helpers.mjs +2 -1
  163. package/dist/helpers.mjs.map +1 -1
  164. package/dist/initScript.cjs +15 -15
  165. package/dist/initScript.cjs.map +1 -1
  166. package/dist/initScript.d.cts +4 -2
  167. package/dist/initScript.d.cts.map +1 -1
  168. package/dist/initScript.d.mts +4 -2
  169. package/dist/initScript.d.mts.map +1 -1
  170. package/dist/initScript.mjs +12 -10
  171. package/dist/initScript.mjs.map +1 -1
  172. package/dist/kysely.cjs +13 -10
  173. package/dist/kysely.cjs.map +1 -1
  174. package/dist/kysely.d.cts +14 -10
  175. package/dist/kysely.d.cts.map +1 -1
  176. package/dist/kysely.d.mts +14 -10
  177. package/dist/kysely.d.mts.map +1 -1
  178. package/dist/kysely.mjs +14 -10
  179. package/dist/kysely.mjs.map +1 -1
  180. package/dist/logger.cjs +4 -3
  181. package/dist/logger.cjs.map +1 -1
  182. package/dist/logger.d.cts +5 -1
  183. package/dist/logger.d.cts.map +1 -1
  184. package/dist/logger.d.mts +5 -1
  185. package/dist/logger.d.mts.map +1 -1
  186. package/dist/logger.mjs +2 -1
  187. package/dist/logger.mjs.map +1 -1
  188. package/dist/objection.cjs +13 -10
  189. package/dist/objection.cjs.map +1 -1
  190. package/dist/objection.d.cts +14 -10
  191. package/dist/objection.d.cts.map +1 -1
  192. package/dist/objection.d.mts +14 -10
  193. package/dist/objection.d.mts.map +1 -1
  194. package/dist/objection.mjs +14 -10
  195. package/dist/objection.mjs.map +1 -1
  196. package/dist/os/directory.cjs +2 -31
  197. package/dist/os/directory.d.cts +2 -9
  198. package/dist/os/directory.d.mts +2 -9
  199. package/dist/os/directory.mjs +2 -25
  200. package/dist/os/index.cjs +3 -3
  201. package/dist/os/index.d.cts +1 -1
  202. package/dist/os/index.d.mts +1 -1
  203. package/dist/os/index.mjs +3 -2
  204. package/dist/requestContext.cjs +11 -10
  205. package/dist/requestContext.cjs.map +1 -1
  206. package/dist/requestContext.d.cts +9 -5
  207. package/dist/requestContext.d.cts.map +1 -1
  208. package/dist/requestContext.d.mts +9 -5
  209. package/dist/requestContext.d.mts.map +1 -1
  210. package/dist/requestContext.mjs +3 -2
  211. package/dist/requestContext.mjs.map +1 -1
  212. package/dist/timer.cjs +2 -2
  213. package/dist/timer.cjs.map +1 -1
  214. package/dist/timer.d.cts +4 -1
  215. package/dist/timer.d.cts.map +1 -1
  216. package/dist/timer.d.mts +4 -1
  217. package/dist/timer.d.mts.map +1 -1
  218. package/dist/timer.mjs +1 -1
  219. package/dist/timer.mjs.map +1 -1
  220. package/package.json +25 -65
  221. package/src/Factory.ts +174 -0
  222. package/src/KyselyFactory.ts +391 -0
  223. package/src/ObjectionFactory.ts +412 -0
  224. package/src/PostgresKyselyMigrator.ts +104 -0
  225. package/src/PostgresMigrator.ts +193 -0
  226. package/src/PostgresObjectionMigrator.ts +138 -0
  227. package/src/VitestKyselyTransactionIsolator.ts +72 -0
  228. package/src/VitestObjectionTransactionIsolator.ts +75 -0
  229. package/src/VitestTransactionIsolator.ts +348 -0
  230. package/src/__tests__/Factory.spec.ts +178 -0
  231. package/src/__tests__/KyselyFactory.spec.ts +458 -0
  232. package/src/__tests__/ObjectionFactory.spec.ts +586 -0
  233. package/src/__tests__/PostgresKyselyMigrator.spec.ts +794 -0
  234. package/src/__tests__/PostgresMigrator.spec.ts +471 -0
  235. package/src/__tests__/PostgresObjectionMigrator.spec.ts +634 -0
  236. package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +138 -0
  237. package/src/__tests__/benchmark.spec.ts +140 -0
  238. package/src/__tests__/better-auth.spec.ts +21 -0
  239. package/src/__tests__/faker.spec.ts +231 -0
  240. package/src/__tests__/initScript.spec.ts +332 -0
  241. package/src/__tests__/integration.spec.ts +610 -0
  242. package/src/__tests__/requestContext.spec.ts +113 -0
  243. package/src/__tests__/utilities.spec.ts +211 -0
  244. package/src/aws.ts +131 -0
  245. package/src/benchmark.ts +48 -0
  246. package/src/better-auth.ts +310 -0
  247. package/src/faker.ts +349 -0
  248. package/src/helpers.ts +45 -0
  249. package/src/initScript.ts +122 -0
  250. package/src/kysely.ts +166 -0
  251. package/src/logger.ts +18 -0
  252. package/src/objection.ts +157 -0
  253. package/src/os/directory.ts +26 -0
  254. package/src/os/index.ts +1 -0
  255. package/src/requestContext.ts +119 -0
  256. package/src/timer.ts +3 -0
  257. package/test/globalSetup.ts +54 -0
  258. package/test/helpers.ts +268 -0
  259. package/test/migrations/1749664623372_user.ts +22 -0
  260. package/tsconfig.json +9 -0
  261. package/vitest.config.ts +8 -0
  262. package/dist/Factory.cjs.map +0 -1
  263. package/dist/Factory.d.cts.map +0 -1
  264. package/dist/Factory.d.mts.map +0 -1
  265. package/dist/Factory.mjs.map +0 -1
  266. package/dist/KyselyFactory.cjs.map +0 -1
  267. package/dist/KyselyFactory.d.cts.map +0 -1
  268. package/dist/KyselyFactory.d.mts.map +0 -1
  269. package/dist/KyselyFactory.mjs.map +0 -1
  270. package/dist/ObjectionFactory.cjs.map +0 -1
  271. package/dist/ObjectionFactory.d.cts.map +0 -1
  272. package/dist/ObjectionFactory.d.mts.map +0 -1
  273. package/dist/ObjectionFactory.mjs.map +0 -1
  274. package/dist/PostgresKyselyMigrator.cjs.map +0 -1
  275. package/dist/PostgresKyselyMigrator.d.cts.map +0 -1
  276. package/dist/PostgresKyselyMigrator.d.mts.map +0 -1
  277. package/dist/PostgresKyselyMigrator.mjs.map +0 -1
  278. package/dist/PostgresMigrator-CDPnnwMJ.d.cts.map +0 -1
  279. package/dist/PostgresMigrator-CDPnnwMJ.d.mts.map +0 -1
  280. package/dist/PostgresMigrator.cjs.map +0 -1
  281. package/dist/PostgresMigrator.mjs.map +0 -1
  282. package/dist/PostgresObjectionMigrator.cjs.map +0 -1
  283. package/dist/PostgresObjectionMigrator.d.cts.map +0 -1
  284. package/dist/PostgresObjectionMigrator.d.mts.map +0 -1
  285. package/dist/PostgresObjectionMigrator.mjs.map +0 -1
  286. package/dist/VitestKyselyTransactionIsolator.cjs.map +0 -1
  287. package/dist/VitestKyselyTransactionIsolator.d.cts.map +0 -1
  288. package/dist/VitestKyselyTransactionIsolator.d.mts.map +0 -1
  289. package/dist/VitestKyselyTransactionIsolator.mjs.map +0 -1
  290. package/dist/VitestObjectionTransactionIsolator.cjs.map +0 -1
  291. package/dist/VitestObjectionTransactionIsolator.d.cts.map +0 -1
  292. package/dist/VitestObjectionTransactionIsolator.d.mts.map +0 -1
  293. package/dist/VitestObjectionTransactionIsolator.mjs.map +0 -1
  294. package/dist/VitestTransactionIsolator.cjs.map +0 -1
  295. package/dist/VitestTransactionIsolator.d.cts.map +0 -1
  296. package/dist/VitestTransactionIsolator.d.mts.map +0 -1
  297. package/dist/VitestTransactionIsolator.mjs.map +0 -1
  298. package/dist/browser.cjs +0 -149
  299. package/dist/browser.cjs.map +0 -1
  300. package/dist/browser.d.cts +0 -62
  301. package/dist/browser.d.cts.map +0 -1
  302. package/dist/browser.d.mts +0 -62
  303. package/dist/browser.d.mts.map +0 -1
  304. package/dist/browser.mjs +0 -147
  305. package/dist/browser.mjs.map +0 -1
  306. package/dist/context.cjs +0 -80
  307. package/dist/context.cjs.map +0 -1
  308. package/dist/context.d.cts +0 -55
  309. package/dist/context.d.cts.map +0 -1
  310. package/dist/context.d.mts +0 -55
  311. package/dist/context.d.mts.map +0 -1
  312. package/dist/context.mjs +0 -73
  313. package/dist/context.mjs.map +0 -1
  314. package/dist/faker.cjs.map +0 -1
  315. package/dist/faker.d.cts.map +0 -1
  316. package/dist/faker.d.mts.map +0 -1
  317. package/dist/faker.mjs.map +0 -1
  318. package/dist/mailbox.cjs +0 -95
  319. package/dist/mailbox.cjs.map +0 -1
  320. package/dist/mailbox.d.cts +0 -58
  321. package/dist/mailbox.d.cts.map +0 -1
  322. package/dist/mailbox.d.mts +0 -58
  323. package/dist/mailbox.d.mts.map +0 -1
  324. package/dist/mailbox.mjs +0 -92
  325. package/dist/mailbox.mjs.map +0 -1
  326. package/dist/os/directory.cjs.map +0 -1
  327. package/dist/os/directory.d.cts.map +0 -1
  328. package/dist/os/directory.d.mts.map +0 -1
  329. package/dist/os/directory.mjs.map +0 -1
  330. package/dist/transactions.cjs +0 -239
  331. package/dist/transactions.cjs.map +0 -1
  332. package/dist/transactions.d.cts +0 -44
  333. package/dist/transactions.d.cts.map +0 -1
  334. package/dist/transactions.d.mts +0 -44
  335. package/dist/transactions.d.mts.map +0 -1
  336. package/dist/transactions.mjs +0 -234
  337. package/dist/transactions.mjs.map +0 -1
@@ -0,0 +1,172 @@
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const pg = require_chunk.__toESM(require("pg"));
3
+
4
+ //#region src/PostgresMigrator.ts
5
+ const { Client } = pg.default;
6
+ /**
7
+ * Creates a PostgreSQL client connected to the 'postgres' database.
8
+ * Extracts connection details from the provided URI.
9
+ *
10
+ * @param uri - PostgreSQL connection URI
11
+ * @returns Object containing the target database name and client instance
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const { database, db } = await setupClient('postgresql://user:pass@localhost:5432/mydb');
16
+ * // database = 'mydb'
17
+ * // db = Client instance connected to 'postgres' database
18
+ * ```
19
+ */
20
+ async function setupClient(uri) {
21
+ const url = new URL(uri);
22
+ const db = new Client({
23
+ user: url.username,
24
+ password: url.password,
25
+ host: url.hostname,
26
+ port: parseInt(url.port, 10),
27
+ database: "postgres"
28
+ });
29
+ let database = url.pathname.slice(1);
30
+ if (database.includes("?")) database = database.substring(0, database.indexOf("?"));
31
+ return {
32
+ database,
33
+ db
34
+ };
35
+ }
36
+ /**
37
+ * Default logger instance for migration operations.
38
+ */
39
+ const logger = console;
40
+ /**
41
+ * Abstract base class for PostgreSQL database migration utilities.
42
+ * Provides database creation, migration, and cleanup functionality for testing.
43
+ * Subclasses must implement the migrate() method to define migration logic.
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * class MyMigrator extends PostgresMigrator {
48
+ * async migrate(): Promise<void> {
49
+ * // Run your migrations here
50
+ * await this.runMigrations();
51
+ * }
52
+ * }
53
+ *
54
+ * // Use in tests
55
+ * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');
56
+ * const cleanup = await migrator.start();
57
+ *
58
+ * // With afterCreate hook (e.g. run init script to create per-app users)
59
+ * import { runInitScript } from '@geekmidas/testkit/postgres';
60
+ *
61
+ * const migrator = new MyMigrator(
62
+ * 'postgresql://localhost:5432/test_db',
63
+ * async (uri) => {
64
+ * await runInitScript('docker/postgres/init.sh', uri, env);
65
+ * },
66
+ * );
67
+ * const cleanup = await migrator.start();
68
+ *
69
+ * // Run tests...
70
+ *
71
+ * // Clean up
72
+ * await cleanup();
73
+ * ```
74
+ */
75
+ var PostgresMigrator = class PostgresMigrator {
76
+ /**
77
+ * Creates a new PostgresMigrator instance.
78
+ *
79
+ * @param uri - PostgreSQL connection URI
80
+ * @param afterCreate - Optional hook called after database creation but before migrations
81
+ */
82
+ constructor(uri, afterCreate) {
83
+ this.uri = uri;
84
+ this.afterCreate = afterCreate;
85
+ }
86
+ /**
87
+ * Creates a PostgreSQL database if it doesn't already exist.
88
+ * Connects to the 'postgres' database to check and create the target database.
89
+ *
90
+ * @param uri - PostgreSQL connection URI
91
+ * @returns Object indicating whether the database already existed
92
+ * @private
93
+ */
94
+ static async create(uri) {
95
+ const { database, db } = await setupClient(uri);
96
+ try {
97
+ await db.connect();
98
+ const result = await db.query(`SELECT * FROM pg_catalog.pg_database WHERE datname = '${database}'`);
99
+ if (result.rowCount === 0) try {
100
+ await db.query(`CREATE DATABASE "${database}"`);
101
+ } catch (error) {
102
+ if (error?.code === "42P04") return { alreadyExisted: true };
103
+ throw error;
104
+ }
105
+ return { alreadyExisted: result.rowCount ? result.rowCount > 0 : false };
106
+ } finally {
107
+ await db.end();
108
+ }
109
+ }
110
+ /**
111
+ * Drops a PostgreSQL database.
112
+ * Used for cleanup after tests are complete.
113
+ *
114
+ * @param uri - PostgreSQL connection URI
115
+ * @throws Error if database cannot be dropped
116
+ * @private
117
+ */
118
+ static async drop(uri) {
119
+ const { database, db } = await setupClient(uri);
120
+ try {
121
+ await db.connect();
122
+ await db.query(`DROP DATABASE "${database}"`);
123
+ } finally {
124
+ await db.end();
125
+ }
126
+ }
127
+ /**
128
+ * Starts the migration process by creating the database and running migrations.
129
+ * Returns a cleanup function that will drop the database when called.
130
+ *
131
+ * @returns Async cleanup function that drops the created database
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');
136
+ *
137
+ * // Start migrations and get cleanup function
138
+ * const cleanup = await migrator.start();
139
+ *
140
+ * try {
141
+ * // Run your tests here
142
+ * await runTests();
143
+ * } finally {
144
+ * // Always clean up
145
+ * await cleanup();
146
+ * }
147
+ * ```
148
+ */
149
+ async start() {
150
+ const { database, db } = await setupClient(this.uri);
151
+ try {
152
+ await PostgresMigrator.create(this.uri);
153
+ if (this.afterCreate) await this.afterCreate(this.uri);
154
+ await this.migrate();
155
+ logger.log(`Migrating database: ${database}`);
156
+ } finally {
157
+ await db.end();
158
+ }
159
+ return async () => {
160
+ await PostgresMigrator.drop(this.uri);
161
+ };
162
+ }
163
+ };
164
+
165
+ //#endregion
166
+ Object.defineProperty(exports, 'PostgresMigrator', {
167
+ enumerable: true,
168
+ get: function () {
169
+ return PostgresMigrator;
170
+ }
171
+ });
172
+ //# sourceMappingURL=PostgresMigrator-M9jpzOvN.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresMigrator-M9jpzOvN.cjs","names":["uri: string","afterCreate?: (uri: string) => Promise<void>","error: any"],"sources":["../src/PostgresMigrator.ts"],"sourcesContent":["import pg from 'pg';\n\nconst { Client } = pg;\n\n/**\n * Creates a PostgreSQL client connected to the 'postgres' database.\n * Extracts connection details from the provided URI.\n *\n * @param uri - PostgreSQL connection URI\n * @returns Object containing the target database name and client instance\n *\n * @example\n * ```typescript\n * const { database, db } = await setupClient('postgresql://user:pass@localhost:5432/mydb');\n * // database = 'mydb'\n * // db = Client instance connected to 'postgres' database\n * ```\n */\nasync function setupClient(uri: string) {\n\tconst url = new URL(uri);\n\n\tconst db = new Client({\n\t\tuser: url.username,\n\t\tpassword: url.password,\n\t\thost: url.hostname,\n\t\tport: parseInt(url.port, 10),\n\t\tdatabase: 'postgres',\n\t});\n\n\tlet database = url.pathname.slice(1);\n\tif (database.includes('?')) {\n\t\tdatabase = database.substring(0, database.indexOf('?'));\n\t}\n\treturn { database, db };\n}\n\n/**\n * Default logger instance for migration operations.\n */\nconst logger = console;\n\n/**\n * Abstract base class for PostgreSQL database migration utilities.\n * Provides database creation, migration, and cleanup functionality for testing.\n * Subclasses must implement the migrate() method to define migration logic.\n *\n * @example\n * ```typescript\n * class MyMigrator extends PostgresMigrator {\n * async migrate(): Promise<void> {\n * // Run your migrations here\n * await this.runMigrations();\n * }\n * }\n *\n * // Use in tests\n * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');\n * const cleanup = await migrator.start();\n *\n * // With afterCreate hook (e.g. run init script to create per-app users)\n * import { runInitScript } from '@geekmidas/testkit/postgres';\n *\n * const migrator = new MyMigrator(\n * 'postgresql://localhost:5432/test_db',\n * async (uri) => {\n * await runInitScript('docker/postgres/init.sh', uri, env);\n * },\n * );\n * const cleanup = await migrator.start();\n *\n * // Run tests...\n *\n * // Clean up\n * await cleanup();\n * ```\n */\nexport abstract class PostgresMigrator {\n\t/**\n\t * Creates a new PostgresMigrator instance.\n\t *\n\t * @param uri - PostgreSQL connection URI\n\t * @param afterCreate - Optional hook called after database creation but before migrations\n\t */\n\tconstructor(\n\t\tprivate uri: string,\n\t\tprivate afterCreate?: (uri: string) => Promise<void>,\n\t) {}\n\n\t/**\n\t * Abstract method to be implemented by subclasses.\n\t * Should contain the migration logic for setting up database schema.\n\t *\n\t * @returns Promise that resolves when migrations are complete\n\t */\n\tabstract migrate(): Promise<void>;\n\n\t/**\n\t * Creates a PostgreSQL database if it doesn't already exist.\n\t * Connects to the 'postgres' database to check and create the target database.\n\t *\n\t * @param uri - PostgreSQL connection URI\n\t * @returns Object indicating whether the database already existed\n\t * @private\n\t */\n\tprivate static async create(\n\t\turi: string,\n\t): Promise<{ alreadyExisted: boolean }> {\n\t\tconst { database, db } = await setupClient(uri);\n\t\ttry {\n\t\t\tawait db.connect();\n\t\t\tconst result = await db.query(\n\t\t\t\t`SELECT * FROM pg_catalog.pg_database WHERE datname = '${database}'`,\n\t\t\t);\n\n\t\t\tif (result.rowCount === 0) {\n\t\t\t\ttry {\n\t\t\t\t\tawait db.query(`CREATE DATABASE \"${database}\"`);\n\t\t\t\t} catch (error: any) {\n\t\t\t\t\t// 42P04 = duplicate_database — another process created it between our check and create\n\t\t\t\t\tif (error?.code === '42P04') {\n\t\t\t\t\t\treturn { alreadyExisted: true };\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\talreadyExisted: result.rowCount ? result.rowCount > 0 : false,\n\t\t\t};\n\t\t} finally {\n\t\t\tawait db.end();\n\t\t}\n\t}\n\n\t/**\n\t * Drops a PostgreSQL database.\n\t * Used for cleanup after tests are complete.\n\t *\n\t * @param uri - PostgreSQL connection URI\n\t * @throws Error if database cannot be dropped\n\t * @private\n\t */\n\tprivate static async drop(uri: string): Promise<void> {\n\t\tconst { database, db } = await setupClient(uri);\n\t\ttry {\n\t\t\tawait db.connect();\n\t\t\tawait db.query(`DROP DATABASE \"${database}\"`);\n\t\t} finally {\n\t\t\tawait db.end();\n\t\t}\n\t}\n\n\t/**\n\t * Starts the migration process by creating the database and running migrations.\n\t * Returns a cleanup function that will drop the database when called.\n\t *\n\t * @returns Async cleanup function that drops the created database\n\t *\n\t * @example\n\t * ```typescript\n\t * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');\n\t *\n\t * // Start migrations and get cleanup function\n\t * const cleanup = await migrator.start();\n\t *\n\t * try {\n\t * // Run your tests here\n\t * await runTests();\n\t * } finally {\n\t * // Always clean up\n\t * await cleanup();\n\t * }\n\t * ```\n\t */\n\tasync start() {\n\t\tconst { database, db } = await setupClient(this.uri);\n\t\ttry {\n\t\t\tawait PostgresMigrator.create(this.uri);\n\t\t\tif (this.afterCreate) {\n\t\t\t\tawait this.afterCreate(this.uri);\n\t\t\t}\n\t\t\tawait this.migrate();\n\t\t\tlogger.log(`Migrating database: ${database}`);\n\t\t\t// Example: await db.query('CREATE TABLE example (id SERIAL PRIMARY KEY)');\n\t\t} finally {\n\t\t\tawait db.end();\n\t\t}\n\n\t\treturn async () => {\n\t\t\tawait PostgresMigrator.drop(this.uri);\n\t\t};\n\t}\n}\n"],"mappings":";;;;AAEA,MAAM,EAAE,QAAQ,GAAG;;;;;;;;;;;;;;;AAgBnB,eAAe,YAAYA,KAAa;CACvC,MAAM,MAAM,IAAI,IAAI;CAEpB,MAAM,KAAK,IAAI,OAAO;EACrB,MAAM,IAAI;EACV,UAAU,IAAI;EACd,MAAM,IAAI;EACV,MAAM,SAAS,IAAI,MAAM,GAAG;EAC5B,UAAU;CACV;CAED,IAAI,WAAW,IAAI,SAAS,MAAM,EAAE;AACpC,KAAI,SAAS,SAAS,IAAI,CACzB,YAAW,SAAS,UAAU,GAAG,SAAS,QAAQ,IAAI,CAAC;AAExD,QAAO;EAAE;EAAU;CAAI;AACvB;;;;AAKD,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCf,IAAsB,mBAAtB,MAAsB,iBAAiB;;;;;;;CAOtC,YACSA,KACAC,aACP;EAFO;EACA;CACL;;;;;;;;;CAkBJ,aAAqB,OACpBD,KACuC;EACvC,MAAM,EAAE,UAAU,IAAI,GAAG,MAAM,YAAY,IAAI;AAC/C,MAAI;AACH,SAAM,GAAG,SAAS;GAClB,MAAM,SAAS,MAAM,GAAG,OACtB,wDAAwD,SAAS,GAClE;AAED,OAAI,OAAO,aAAa,EACvB,KAAI;AACH,UAAM,GAAG,OAAO,mBAAmB,SAAS,GAAG;GAC/C,SAAQE,OAAY;AAEpB,QAAI,OAAO,SAAS,QACnB,QAAO,EAAE,gBAAgB,KAAM;AAEhC,UAAM;GACN;AAGF,UAAO,EACN,gBAAgB,OAAO,WAAW,OAAO,WAAW,IAAI,MACxD;EACD,UAAS;AACT,SAAM,GAAG,KAAK;EACd;CACD;;;;;;;;;CAUD,aAAqB,KAAKF,KAA4B;EACrD,MAAM,EAAE,UAAU,IAAI,GAAG,MAAM,YAAY,IAAI;AAC/C,MAAI;AACH,SAAM,GAAG,SAAS;AAClB,SAAM,GAAG,OAAO,iBAAiB,SAAS,GAAG;EAC7C,UAAS;AACT,SAAM,GAAG,KAAK;EACd;CACD;;;;;;;;;;;;;;;;;;;;;;;CAwBD,MAAM,QAAQ;EACb,MAAM,EAAE,UAAU,IAAI,GAAG,MAAM,YAAY,KAAK,IAAI;AACpD,MAAI;AACH,SAAM,iBAAiB,OAAO,KAAK,IAAI;AACvC,OAAI,KAAK,YACR,OAAM,KAAK,YAAY,KAAK,IAAI;AAEjC,SAAM,KAAK,SAAS;AACpB,UAAO,KAAK,sBAAsB,SAAS,EAAE;EAE7C,UAAS;AACT,SAAM,GAAG,KAAK;EACd;AAED,SAAO,YAAY;AAClB,SAAM,iBAAiB,KAAK,KAAK,IAAI;EACrC;CACD;AACD"}
@@ -1,179 +1,3 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.cjs");
3
- let pg = require("pg");
4
- pg = require_rolldown_runtime.__toESM(pg, 1);
5
- //#region src/PostgresMigrator.ts
6
- const { Client } = pg.default;
7
- /**
8
- * Creates a PostgreSQL client connected to the 'postgres' database.
9
- * Extracts connection details from the provided URI.
10
- *
11
- * @param uri - PostgreSQL connection URI
12
- * @returns Object containing the target database name and client instance
13
- *
14
- * @example
15
- * ```typescript
16
- * const { database, db } = await setupClient('postgresql://user:pass@localhost:5432/mydb');
17
- * // database = 'mydb'
18
- * // db = Client instance connected to 'postgres' database
19
- * ```
20
- */
21
- async function setupClient(uri) {
22
- const url = new URL(uri);
23
- const db = new Client({
24
- user: url.username,
25
- password: url.password,
26
- host: url.hostname,
27
- port: parseInt(url.port, 10),
28
- database: "postgres"
29
- });
30
- let database = url.pathname.slice(1);
31
- if (database.includes("?")) database = database.substring(0, database.indexOf("?"));
32
- return {
33
- database,
34
- db
35
- };
36
- }
37
- /**
38
- * Default logger instance for migration operations.
39
- */
40
- const logger = console;
41
- /**
42
- * Abstract base class for PostgreSQL database migration utilities.
43
- * Provides database creation, migration, and cleanup functionality for testing.
44
- * Subclasses must implement the migrate() method to define migration logic.
45
- *
46
- * @example
47
- * ```typescript
48
- * class MyMigrator extends PostgresMigrator {
49
- * async migrate(): Promise<void> {
50
- * // Run your migrations here
51
- * await this.runMigrations();
52
- * }
53
- * }
54
- *
55
- * // Use in tests
56
- * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');
57
- * const cleanup = await migrator.start();
58
- *
59
- * // With afterCreate hook (e.g. run init script to create per-app users)
60
- * import { runInitScript } from '@geekmidas/testkit/postgres';
61
- *
62
- * const migrator = new MyMigrator(
63
- * 'postgresql://localhost:5432/test_db',
64
- * async (uri) => {
65
- * await runInitScript('docker/postgres/init.sh', uri, env);
66
- * },
67
- * );
68
- * const cleanup = await migrator.start();
69
- *
70
- * // Run tests...
71
- *
72
- * // Clean up
73
- * await cleanup();
74
- * ```
75
- */
76
- var PostgresMigrator = class PostgresMigrator {
77
- uri;
78
- afterCreate;
79
- /**
80
- * Creates a new PostgresMigrator instance.
81
- *
82
- * @param uri - PostgreSQL connection URI
83
- * @param afterCreate - Optional hook called after database creation but before migrations
84
- */
85
- constructor(uri, afterCreate) {
86
- this.uri = uri;
87
- this.afterCreate = afterCreate;
88
- }
89
- /**
90
- * Creates a PostgreSQL database if it doesn't already exist.
91
- * Connects to the 'postgres' database to check and create the target database.
92
- *
93
- * @param uri - PostgreSQL connection URI
94
- * @returns Object indicating whether the database already existed
95
- * @private
96
- */
97
- static async create(uri) {
98
- const { database, db } = await setupClient(uri);
99
- try {
100
- await db.connect();
101
- const result = await db.query(`SELECT * FROM pg_catalog.pg_database WHERE datname = '${database}'`);
102
- if (result.rowCount === 0) try {
103
- await db.query(`CREATE DATABASE "${database}"`);
104
- } catch (error) {
105
- if (error?.code === "42P04" || error?.code === "23505" && error?.constraint === "pg_database_datname_index") return { alreadyExisted: true };
106
- throw error;
107
- }
108
- return { alreadyExisted: result.rowCount ? result.rowCount > 0 : false };
109
- } finally {
110
- await db.end();
111
- }
112
- }
113
- /**
114
- * Drops a PostgreSQL database.
115
- * Used for cleanup after tests are complete.
116
- *
117
- * @param uri - PostgreSQL connection URI
118
- * @throws Error if database cannot be dropped
119
- * @private
120
- */
121
- static async drop(uri) {
122
- const { database, db } = await setupClient(uri);
123
- try {
124
- await db.connect();
125
- await db.query(`DROP DATABASE "${database}"`);
126
- } finally {
127
- await db.end();
128
- }
129
- }
130
- /**
131
- * Starts the migration process by creating the database and running migrations.
132
- * Returns a cleanup function that drops the database — if this call created
133
- * it.
134
- *
135
- * A database that was already there belongs to whoever made it, and the
136
- * cleanup leaves it alone. `gkm test` provisions the test database before
137
- * the suite starts, with an owner role that may migrate it but not drop it:
138
- * dropping it was never the suite's to do, and failed there as a permission
139
- * error on the way out of an otherwise green run.
140
- *
141
- * @returns Async cleanup function that drops the database if it created it
142
- *
143
- * @example
144
- * ```typescript
145
- * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');
146
- *
147
- * // Start migrations and get cleanup function
148
- * const cleanup = await migrator.start();
149
- *
150
- * try {
151
- * // Run your tests here
152
- * await runTests();
153
- * } finally {
154
- * // Always clean up
155
- * await cleanup();
156
- * }
157
- * ```
158
- */
159
- async start() {
160
- const { database, db } = await setupClient(this.uri);
161
- let created = false;
162
- try {
163
- const { alreadyExisted } = await PostgresMigrator.create(this.uri);
164
- created = !alreadyExisted;
165
- if (this.afterCreate) await this.afterCreate(this.uri);
166
- await this.migrate();
167
- logger.log(`Migrating database: ${database}`);
168
- } finally {
169
- await db.end();
170
- }
171
- return async () => {
172
- if (created) await PostgresMigrator.drop(this.uri);
173
- };
174
- }
175
- };
176
- //#endregion
177
- exports.PostgresMigrator = PostgresMigrator;
1
+ const require_PostgresMigrator = require('./PostgresMigrator-M9jpzOvN.cjs');
178
2
 
179
- //# sourceMappingURL=PostgresMigrator.cjs.map
3
+ exports.PostgresMigrator = require_PostgresMigrator.PostgresMigrator;
@@ -1,2 +1,2 @@
1
- import { t as PostgresMigrator } from "./PostgresMigrator-CDPnnwMJ.cjs";
1
+ import { PostgresMigrator } from "./PostgresMigrator-CeYy-eHF.cjs";
2
2
  export { PostgresMigrator };
@@ -1,2 +1,2 @@
1
- import { t as PostgresMigrator } from "./PostgresMigrator-CDPnnwMJ.mjs";
1
+ import { PostgresMigrator } from "./PostgresMigrator-C_QQ6q35.mjs";
2
2
  export { PostgresMigrator };
@@ -1,176 +1,3 @@
1
- import pg from "pg";
2
- //#region src/PostgresMigrator.ts
3
- const { Client } = pg;
4
- /**
5
- * Creates a PostgreSQL client connected to the 'postgres' database.
6
- * Extracts connection details from the provided URI.
7
- *
8
- * @param uri - PostgreSQL connection URI
9
- * @returns Object containing the target database name and client instance
10
- *
11
- * @example
12
- * ```typescript
13
- * const { database, db } = await setupClient('postgresql://user:pass@localhost:5432/mydb');
14
- * // database = 'mydb'
15
- * // db = Client instance connected to 'postgres' database
16
- * ```
17
- */
18
- async function setupClient(uri) {
19
- const url = new URL(uri);
20
- const db = new Client({
21
- user: url.username,
22
- password: url.password,
23
- host: url.hostname,
24
- port: parseInt(url.port, 10),
25
- database: "postgres"
26
- });
27
- let database = url.pathname.slice(1);
28
- if (database.includes("?")) database = database.substring(0, database.indexOf("?"));
29
- return {
30
- database,
31
- db
32
- };
33
- }
34
- /**
35
- * Default logger instance for migration operations.
36
- */
37
- const logger = console;
38
- /**
39
- * Abstract base class for PostgreSQL database migration utilities.
40
- * Provides database creation, migration, and cleanup functionality for testing.
41
- * Subclasses must implement the migrate() method to define migration logic.
42
- *
43
- * @example
44
- * ```typescript
45
- * class MyMigrator extends PostgresMigrator {
46
- * async migrate(): Promise<void> {
47
- * // Run your migrations here
48
- * await this.runMigrations();
49
- * }
50
- * }
51
- *
52
- * // Use in tests
53
- * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');
54
- * const cleanup = await migrator.start();
55
- *
56
- * // With afterCreate hook (e.g. run init script to create per-app users)
57
- * import { runInitScript } from '@geekmidas/testkit/postgres';
58
- *
59
- * const migrator = new MyMigrator(
60
- * 'postgresql://localhost:5432/test_db',
61
- * async (uri) => {
62
- * await runInitScript('docker/postgres/init.sh', uri, env);
63
- * },
64
- * );
65
- * const cleanup = await migrator.start();
66
- *
67
- * // Run tests...
68
- *
69
- * // Clean up
70
- * await cleanup();
71
- * ```
72
- */
73
- var PostgresMigrator = class PostgresMigrator {
74
- uri;
75
- afterCreate;
76
- /**
77
- * Creates a new PostgresMigrator instance.
78
- *
79
- * @param uri - PostgreSQL connection URI
80
- * @param afterCreate - Optional hook called after database creation but before migrations
81
- */
82
- constructor(uri, afterCreate) {
83
- this.uri = uri;
84
- this.afterCreate = afterCreate;
85
- }
86
- /**
87
- * Creates a PostgreSQL database if it doesn't already exist.
88
- * Connects to the 'postgres' database to check and create the target database.
89
- *
90
- * @param uri - PostgreSQL connection URI
91
- * @returns Object indicating whether the database already existed
92
- * @private
93
- */
94
- static async create(uri) {
95
- const { database, db } = await setupClient(uri);
96
- try {
97
- await db.connect();
98
- const result = await db.query(`SELECT * FROM pg_catalog.pg_database WHERE datname = '${database}'`);
99
- if (result.rowCount === 0) try {
100
- await db.query(`CREATE DATABASE "${database}"`);
101
- } catch (error) {
102
- if (error?.code === "42P04" || error?.code === "23505" && error?.constraint === "pg_database_datname_index") return { alreadyExisted: true };
103
- throw error;
104
- }
105
- return { alreadyExisted: result.rowCount ? result.rowCount > 0 : false };
106
- } finally {
107
- await db.end();
108
- }
109
- }
110
- /**
111
- * Drops a PostgreSQL database.
112
- * Used for cleanup after tests are complete.
113
- *
114
- * @param uri - PostgreSQL connection URI
115
- * @throws Error if database cannot be dropped
116
- * @private
117
- */
118
- static async drop(uri) {
119
- const { database, db } = await setupClient(uri);
120
- try {
121
- await db.connect();
122
- await db.query(`DROP DATABASE "${database}"`);
123
- } finally {
124
- await db.end();
125
- }
126
- }
127
- /**
128
- * Starts the migration process by creating the database and running migrations.
129
- * Returns a cleanup function that drops the database — if this call created
130
- * it.
131
- *
132
- * A database that was already there belongs to whoever made it, and the
133
- * cleanup leaves it alone. `gkm test` provisions the test database before
134
- * the suite starts, with an owner role that may migrate it but not drop it:
135
- * dropping it was never the suite's to do, and failed there as a permission
136
- * error on the way out of an otherwise green run.
137
- *
138
- * @returns Async cleanup function that drops the database if it created it
139
- *
140
- * @example
141
- * ```typescript
142
- * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');
143
- *
144
- * // Start migrations and get cleanup function
145
- * const cleanup = await migrator.start();
146
- *
147
- * try {
148
- * // Run your tests here
149
- * await runTests();
150
- * } finally {
151
- * // Always clean up
152
- * await cleanup();
153
- * }
154
- * ```
155
- */
156
- async start() {
157
- const { database, db } = await setupClient(this.uri);
158
- let created = false;
159
- try {
160
- const { alreadyExisted } = await PostgresMigrator.create(this.uri);
161
- created = !alreadyExisted;
162
- if (this.afterCreate) await this.afterCreate(this.uri);
163
- await this.migrate();
164
- logger.log(`Migrating database: ${database}`);
165
- } finally {
166
- await db.end();
167
- }
168
- return async () => {
169
- if (created) await PostgresMigrator.drop(this.uri);
170
- };
171
- }
172
- };
173
- //#endregion
174
- export { PostgresMigrator };
1
+ import { PostgresMigrator } from "./PostgresMigrator-DVAY04qN.mjs";
175
2
 
176
- //# sourceMappingURL=PostgresMigrator.mjs.map
3
+ export { PostgresMigrator };
@@ -0,0 +1,79 @@
1
+ import { PostgresMigrator } from "./PostgresMigrator-C_QQ6q35.mjs";
2
+ import { Knex } from "knex";
3
+
4
+ //#region src/PostgresObjectionMigrator.d.ts
5
+
6
+ /**
7
+ * PostgreSQL migrator implementation for Objection.js ORM with Knex.
8
+ * Extends PostgresMigrator to provide Knex-specific migration functionality.
9
+ * Automatically creates test databases and applies migrations for testing environments.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import knex from 'knex';
14
+ * import { PostgresObjectionMigrator } from '@geekmidas/testkit';
15
+ *
16
+ * // Create Knex instance
17
+ * const db = knex({
18
+ * client: 'pg',
19
+ * connection: uri,
20
+ * migrations: {
21
+ * directory: path.join(__dirname, 'migrations'),
22
+ * extension: 'ts'
23
+ * }
24
+ * });
25
+ *
26
+ * // Create and use migrator
27
+ * const migrator = new PostgresObjectionMigrator({
28
+ * uri: 'postgresql://localhost:5432/test_db',
29
+ * knex: db
30
+ * });
31
+ *
32
+ * const cleanup = await migrator.start();
33
+ * // Run tests...
34
+ * await cleanup();
35
+ * ```
36
+ */
37
+ declare class PostgresObjectionMigrator extends PostgresMigrator {
38
+ private options;
39
+ /**
40
+ * Creates a new PostgresObjectionMigrator instance.
41
+ *
42
+ * @param options - Configuration options
43
+ * @param options.uri - PostgreSQL connection URI
44
+ * @param options.knex - Knex database instance configured with migrations
45
+ */
46
+ constructor(options: {
47
+ uri: string;
48
+ knex: Knex;
49
+ });
50
+ /**
51
+ * Executes Knex migrations to the latest version.
52
+ * Implements the abstract migrate() method from PostgresMigrator.
53
+ *
54
+ * @throws Error if migrations fail to apply
55
+ * @returns Promise that resolves when all migrations are applied
56
+ */
57
+ migrate(): Promise<void>;
58
+ /**
59
+ * Rolls back the last batch of migrations.
60
+ * Useful for testing migration rollback scenarios.
61
+ *
62
+ * @returns Promise that resolves when rollback is complete
63
+ */
64
+ rollback(): Promise<void>;
65
+ /**
66
+ * Gets the current migration status.
67
+ * Returns information about completed and pending migrations.
68
+ *
69
+ * @returns Promise with migration status information
70
+ */
71
+ status(): Promise<{
72
+ completed: string[];
73
+ pending: string[];
74
+ }>;
75
+ }
76
+ //# sourceMappingURL=PostgresObjectionMigrator.d.ts.map
77
+ //#endregion
78
+ export { PostgresObjectionMigrator };
79
+ //# sourceMappingURL=PostgresObjectionMigrator-1j6YIB1c.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresObjectionMigrator-1j6YIB1c.d.mts","names":[],"sources":["../src/PostgresObjectionMigrator.ts"],"sourcesContent":[],"mappings":";;;;;;;AAuCA;;;;;;;AAA+D;;;;;;;;;;;;;;;;;;;;;;cAAlD,yBAAA,SAAkC,gBAAA;;;;;;;;;;;UAWtC;;;;;;;;;aAaS;;;;;;;cA8BC;;;;;;;YA4BF"}