@geekmidas/testkit 10.0.0-alpha.4 → 10.0.0-alpha.41

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 +17 -8
  93. package/dist/better-auth.cjs.map +1 -1
  94. package/dist/better-auth.d.cts +13142 -5
  95. package/dist/better-auth.d.cts.map +1 -1
  96. package/dist/better-auth.d.mts +13142 -5
  97. package/dist/better-auth.d.mts.map +1 -1
  98. package/dist/better-auth.mjs +15 -6
  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 +313 -8
  117. package/dist/faker.cjs.map +1 -0
  118. package/dist/faker.d.cts +169 -2
  119. package/dist/faker.d.cts.map +1 -0
  120. package/dist/faker.d.mts +169 -2
  121. package/dist/faker.d.mts.map +1 -0
  122. package/dist/faker.mjs +305 -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 +51 -8
  210. package/dist/Factory-AWn1IulI.d.cts +0 -147
  211. package/dist/Factory-AWn1IulI.d.cts.map +0 -1
  212. package/dist/Factory-BFVnMMCC.mjs +0 -51
  213. package/dist/Factory-BFVnMMCC.mjs.map +0 -1
  214. package/dist/Factory-BhjUOBWN.cjs +0 -57
  215. package/dist/Factory-BhjUOBWN.cjs.map +0 -1
  216. package/dist/Factory-C15SSK8_.d.mts +0 -147
  217. package/dist/Factory-C15SSK8_.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-C9Snz24z.d.mts +0 -228
  221. package/dist/KyselyFactory-C9Snz24z.d.mts.map +0 -1
  222. package/dist/KyselyFactory-CxUJCi--.d.cts +0 -228
  223. package/dist/KyselyFactory-CxUJCi--.d.cts.map +0 -1
  224. package/dist/KyselyFactory-DMswpwji.mjs +0 -241
  225. package/dist/KyselyFactory-DMswpwji.mjs.map +0 -1
  226. package/dist/ObjectionFactory-BeFBYcan.cjs +0 -272
  227. package/dist/ObjectionFactory-BeFBYcan.cjs.map +0 -1
  228. package/dist/ObjectionFactory-CYvaa0kU.d.cts +0 -241
  229. package/dist/ObjectionFactory-CYvaa0kU.d.cts.map +0 -1
  230. package/dist/ObjectionFactory-Cf2WI4o_.d.mts +0 -241
  231. package/dist/ObjectionFactory-Cf2WI4o_.d.mts.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-DiQ_DkaF.d.mts +0 -13
  285. package/dist/directory-DiQ_DkaF.d.mts.map +0 -1
  286. package/dist/directory-zIEh5ZPl.d.cts +0 -13
  287. package/dist/directory-zIEh5ZPl.d.cts.map +0 -1
  288. package/dist/faker-B14IEMIN.cjs +0 -304
  289. package/dist/faker-B14IEMIN.cjs.map +0 -1
  290. package/dist/faker-B6bmbGCM.d.mts +0 -166
  291. package/dist/faker-B6bmbGCM.d.mts.map +0 -1
  292. package/dist/faker-BGKYFoCT.mjs +0 -262
  293. package/dist/faker-BGKYFoCT.mjs.map +0 -1
  294. package/dist/faker-DvxiCtxc.d.cts +0 -166
  295. package/dist/faker-DvxiCtxc.d.cts.map +0 -1
@@ -1 +0,0 @@
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,79 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,79 +0,0 @@
1
- import { PostgresMigrator } from "./PostgresMigrator-CeYy-eHF.cjs";
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-DHVC9h_P.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PostgresObjectionMigrator-DHVC9h_P.d.cts","names":[],"sources":["../src/PostgresObjectionMigrator.ts"],"sourcesContent":[],"mappings":";;;;;;;AAuCA;;;;;;;AAA+D;;;;;;;;;;;;;;;;;;;;;;cAAlD,yBAAA,SAAkC,gBAAA;;;;;;;;;;;UAWtC;;;;;;;;;aAaS;;;;;;;cA8BC;;;;;;;YA4BF"}
@@ -1,123 +0,0 @@
1
- const require_PostgresMigrator = require('./PostgresMigrator-M9jpzOvN.cjs');
2
-
3
- //#region src/PostgresObjectionMigrator.ts
4
- /**
5
- * Default logger instance for migration operations.
6
- */
7
- const logger = console;
8
- /**
9
- * PostgreSQL migrator implementation for Objection.js ORM with Knex.
10
- * Extends PostgresMigrator to provide Knex-specific migration functionality.
11
- * Automatically creates test databases and applies migrations for testing environments.
12
- *
13
- * @example
14
- * ```typescript
15
- * import knex from 'knex';
16
- * import { PostgresObjectionMigrator } from '@geekmidas/testkit';
17
- *
18
- * // Create Knex instance
19
- * const db = knex({
20
- * client: 'pg',
21
- * connection: uri,
22
- * migrations: {
23
- * directory: path.join(__dirname, 'migrations'),
24
- * extension: 'ts'
25
- * }
26
- * });
27
- *
28
- * // Create and use migrator
29
- * const migrator = new PostgresObjectionMigrator({
30
- * uri: 'postgresql://localhost:5432/test_db',
31
- * knex: db
32
- * });
33
- *
34
- * const cleanup = await migrator.start();
35
- * // Run tests...
36
- * await cleanup();
37
- * ```
38
- */
39
- var PostgresObjectionMigrator = class extends require_PostgresMigrator.PostgresMigrator {
40
- /**
41
- * Creates a new PostgresObjectionMigrator instance.
42
- *
43
- * @param options - Configuration options
44
- * @param options.uri - PostgreSQL connection URI
45
- * @param options.knex - Knex database instance configured with migrations
46
- */
47
- constructor(options) {
48
- super(options.uri);
49
- this.options = options;
50
- }
51
- /**
52
- * Executes Knex migrations to the latest version.
53
- * Implements the abstract migrate() method from PostgresMigrator.
54
- *
55
- * @throws Error if migrations fail to apply
56
- * @returns Promise that resolves when all migrations are applied
57
- */
58
- async migrate() {
59
- try {
60
- const [batchNo, migrations] = await this.options.knex.migrate.latest();
61
- if (migrations.length > 0) {
62
- logger.log(`Applied batch ${batchNo} with ${migrations.length} migrations:`);
63
- migrations.forEach((migration) => {
64
- logger.log(` - ${migration}`);
65
- });
66
- } else logger.log("No pending migrations to apply");
67
- } catch (error) {
68
- logger.error("Failed to apply migrations:", error);
69
- throw error;
70
- } finally {
71
- await this.options.knex.destroy();
72
- }
73
- }
74
- /**
75
- * Rolls back the last batch of migrations.
76
- * Useful for testing migration rollback scenarios.
77
- *
78
- * @returns Promise that resolves when rollback is complete
79
- */
80
- async rollback() {
81
- try {
82
- const [batchNo, migrations] = await this.options.knex.migrate.rollback();
83
- if (migrations.length > 0) {
84
- logger.log(`Rolled back batch ${batchNo} with ${migrations.length} migrations:`);
85
- migrations.forEach((migration) => {
86
- logger.log(` - ${migration}`);
87
- });
88
- } else logger.log("No migrations to rollback");
89
- } catch (error) {
90
- logger.error("Failed to rollback migrations:", error);
91
- throw error;
92
- } finally {
93
- await this.options.knex.destroy();
94
- }
95
- }
96
- /**
97
- * Gets the current migration status.
98
- * Returns information about completed and pending migrations.
99
- *
100
- * @returns Promise with migration status information
101
- */
102
- async status() {
103
- try {
104
- const completed = await this.options.knex.migrate.list();
105
- const [, pending] = await this.options.knex.migrate.currentVersion();
106
- return {
107
- completed: Array.isArray(completed[0]) ? completed[0] : [],
108
- pending: Array.isArray(pending) ? pending : []
109
- };
110
- } finally {
111
- await this.options.knex.destroy();
112
- }
113
- }
114
- };
115
-
116
- //#endregion
117
- Object.defineProperty(exports, 'PostgresObjectionMigrator', {
118
- enumerable: true,
119
- get: function () {
120
- return PostgresObjectionMigrator;
121
- }
122
- });
123
- //# sourceMappingURL=PostgresObjectionMigrator-DSaPhwjY.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PostgresObjectionMigrator-DSaPhwjY.cjs","names":["PostgresMigrator","options: {\n\t\t\turi: string;\n\t\t\tknex: Knex;\n\t\t}","migration: string"],"sources":["../src/PostgresObjectionMigrator.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport { PostgresMigrator } from './PostgresMigrator';\n\n/**\n * Default logger instance for migration operations.\n */\nconst logger = console;\n\n/**\n * PostgreSQL migrator implementation for Objection.js ORM with Knex.\n * Extends PostgresMigrator to provide Knex-specific migration functionality.\n * Automatically creates test databases and applies migrations for testing environments.\n *\n * @example\n * ```typescript\n * import knex from 'knex';\n * import { PostgresObjectionMigrator } from '@geekmidas/testkit';\n *\n * // Create Knex instance\n * const db = knex({\n * client: 'pg',\n * connection: uri,\n * migrations: {\n * directory: path.join(__dirname, 'migrations'),\n * extension: 'ts'\n * }\n * });\n *\n * // Create and use migrator\n * const migrator = new PostgresObjectionMigrator({\n * uri: 'postgresql://localhost:5432/test_db',\n * knex: db\n * });\n *\n * const cleanup = await migrator.start();\n * // Run tests...\n * await cleanup();\n * ```\n */\nexport class PostgresObjectionMigrator extends PostgresMigrator {\n\t/**\n\t * Creates a new PostgresObjectionMigrator instance.\n\t *\n\t * @param options - Configuration options\n\t * @param options.uri - PostgreSQL connection URI\n\t * @param options.knex - Knex database instance configured with migrations\n\t */\n\tconstructor(\n\t\tprivate options: {\n\t\t\turi: string;\n\t\t\tknex: Knex;\n\t\t},\n\t) {\n\t\tsuper(options.uri);\n\t}\n\n\t/**\n\t * Executes Knex migrations to the latest version.\n\t * Implements the abstract migrate() method from PostgresMigrator.\n\t *\n\t * @throws Error if migrations fail to apply\n\t * @returns Promise that resolves when all migrations are applied\n\t */\n\tasync migrate(): Promise<void> {\n\t\ttry {\n\t\t\t// Run migrations to latest\n\t\t\tconst [batchNo, migrations] = await this.options.knex.migrate.latest();\n\n\t\t\tif (migrations.length > 0) {\n\t\t\t\tlogger.log(\n\t\t\t\t\t`Applied batch ${batchNo} with ${migrations.length} migrations:`,\n\t\t\t\t);\n\t\t\t\tmigrations.forEach((migration: string) => {\n\t\t\t\t\tlogger.log(` - ${migration}`);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tlogger.log('No pending migrations to apply');\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogger.error('Failed to apply migrations:', error);\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\t// Always destroy the connection pool\n\t\t\tawait this.options.knex.destroy();\n\t\t}\n\t}\n\n\t/**\n\t * Rolls back the last batch of migrations.\n\t * Useful for testing migration rollback scenarios.\n\t *\n\t * @returns Promise that resolves when rollback is complete\n\t */\n\tasync rollback(): Promise<void> {\n\t\ttry {\n\t\t\tconst [batchNo, migrations] = await this.options.knex.migrate.rollback();\n\n\t\t\tif (migrations.length > 0) {\n\t\t\t\tlogger.log(\n\t\t\t\t\t`Rolled back batch ${batchNo} with ${migrations.length} migrations:`,\n\t\t\t\t);\n\t\t\t\tmigrations.forEach((migration: string) => {\n\t\t\t\t\tlogger.log(` - ${migration}`);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tlogger.log('No migrations to rollback');\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogger.error('Failed to rollback migrations:', error);\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tawait this.options.knex.destroy();\n\t\t}\n\t}\n\n\t/**\n\t * Gets the current migration status.\n\t * Returns information about completed and pending migrations.\n\t *\n\t * @returns Promise with migration status information\n\t */\n\tasync status(): Promise<{\n\t\tcompleted: string[];\n\t\tpending: string[];\n\t}> {\n\t\ttry {\n\t\t\tconst completed = await this.options.knex.migrate.list();\n\t\t\tconst [, pending] = await this.options.knex.migrate.currentVersion();\n\n\t\t\treturn {\n\t\t\t\tcompleted: Array.isArray(completed[0]) ? completed[0] : [],\n\t\t\t\tpending: Array.isArray(pending) ? pending : [],\n\t\t\t};\n\t\t} finally {\n\t\t\tawait this.options.knex.destroy();\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;AAMA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCf,IAAa,4BAAb,cAA+CA,0CAAiB;;;;;;;;CAQ/D,YACSC,SAIP;AACD,QAAM,QAAQ,IAAI;EALV;CAMR;;;;;;;;CASD,MAAM,UAAyB;AAC9B,MAAI;GAEH,MAAM,CAAC,SAAS,WAAW,GAAG,MAAM,KAAK,QAAQ,KAAK,QAAQ,QAAQ;AAEtE,OAAI,WAAW,SAAS,GAAG;AAC1B,WAAO,KACL,gBAAgB,QAAQ,QAAQ,WAAW,OAAO,cACnD;AACD,eAAW,QAAQ,CAACC,cAAsB;AACzC,YAAO,KAAK,MAAM,UAAU,EAAE;IAC9B,EAAC;GACF,MACA,QAAO,IAAI,iCAAiC;EAE7C,SAAQ,OAAO;AACf,UAAO,MAAM,+BAA+B,MAAM;AAClD,SAAM;EACN,UAAS;AAET,SAAM,KAAK,QAAQ,KAAK,SAAS;EACjC;CACD;;;;;;;CAQD,MAAM,WAA0B;AAC/B,MAAI;GACH,MAAM,CAAC,SAAS,WAAW,GAAG,MAAM,KAAK,QAAQ,KAAK,QAAQ,UAAU;AAExE,OAAI,WAAW,SAAS,GAAG;AAC1B,WAAO,KACL,oBAAoB,QAAQ,QAAQ,WAAW,OAAO,cACvD;AACD,eAAW,QAAQ,CAACA,cAAsB;AACzC,YAAO,KAAK,MAAM,UAAU,EAAE;IAC9B,EAAC;GACF,MACA,QAAO,IAAI,4BAA4B;EAExC,SAAQ,OAAO;AACf,UAAO,MAAM,kCAAkC,MAAM;AACrD,SAAM;EACN,UAAS;AACT,SAAM,KAAK,QAAQ,KAAK,SAAS;EACjC;CACD;;;;;;;CAQD,MAAM,SAGH;AACF,MAAI;GACH,MAAM,YAAY,MAAM,KAAK,QAAQ,KAAK,QAAQ,MAAM;GACxD,MAAM,GAAG,QAAQ,GAAG,MAAM,KAAK,QAAQ,KAAK,QAAQ,gBAAgB;AAEpE,UAAO;IACN,WAAW,MAAM,QAAQ,UAAU,GAAG,GAAG,UAAU,KAAK,CAAE;IAC1D,SAAS,MAAM,QAAQ,QAAQ,GAAG,UAAU,CAAE;GAC9C;EACD,UAAS;AACT,SAAM,KAAK,QAAQ,KAAK,SAAS;EACjC;CACD;AACD"}
@@ -1,118 +0,0 @@
1
- import { PostgresMigrator } from "./PostgresMigrator-DVAY04qN.mjs";
2
-
3
- //#region src/PostgresObjectionMigrator.ts
4
- /**
5
- * Default logger instance for migration operations.
6
- */
7
- const logger = console;
8
- /**
9
- * PostgreSQL migrator implementation for Objection.js ORM with Knex.
10
- * Extends PostgresMigrator to provide Knex-specific migration functionality.
11
- * Automatically creates test databases and applies migrations for testing environments.
12
- *
13
- * @example
14
- * ```typescript
15
- * import knex from 'knex';
16
- * import { PostgresObjectionMigrator } from '@geekmidas/testkit';
17
- *
18
- * // Create Knex instance
19
- * const db = knex({
20
- * client: 'pg',
21
- * connection: uri,
22
- * migrations: {
23
- * directory: path.join(__dirname, 'migrations'),
24
- * extension: 'ts'
25
- * }
26
- * });
27
- *
28
- * // Create and use migrator
29
- * const migrator = new PostgresObjectionMigrator({
30
- * uri: 'postgresql://localhost:5432/test_db',
31
- * knex: db
32
- * });
33
- *
34
- * const cleanup = await migrator.start();
35
- * // Run tests...
36
- * await cleanup();
37
- * ```
38
- */
39
- var PostgresObjectionMigrator = class extends PostgresMigrator {
40
- /**
41
- * Creates a new PostgresObjectionMigrator instance.
42
- *
43
- * @param options - Configuration options
44
- * @param options.uri - PostgreSQL connection URI
45
- * @param options.knex - Knex database instance configured with migrations
46
- */
47
- constructor(options) {
48
- super(options.uri);
49
- this.options = options;
50
- }
51
- /**
52
- * Executes Knex migrations to the latest version.
53
- * Implements the abstract migrate() method from PostgresMigrator.
54
- *
55
- * @throws Error if migrations fail to apply
56
- * @returns Promise that resolves when all migrations are applied
57
- */
58
- async migrate() {
59
- try {
60
- const [batchNo, migrations] = await this.options.knex.migrate.latest();
61
- if (migrations.length > 0) {
62
- logger.log(`Applied batch ${batchNo} with ${migrations.length} migrations:`);
63
- migrations.forEach((migration) => {
64
- logger.log(` - ${migration}`);
65
- });
66
- } else logger.log("No pending migrations to apply");
67
- } catch (error) {
68
- logger.error("Failed to apply migrations:", error);
69
- throw error;
70
- } finally {
71
- await this.options.knex.destroy();
72
- }
73
- }
74
- /**
75
- * Rolls back the last batch of migrations.
76
- * Useful for testing migration rollback scenarios.
77
- *
78
- * @returns Promise that resolves when rollback is complete
79
- */
80
- async rollback() {
81
- try {
82
- const [batchNo, migrations] = await this.options.knex.migrate.rollback();
83
- if (migrations.length > 0) {
84
- logger.log(`Rolled back batch ${batchNo} with ${migrations.length} migrations:`);
85
- migrations.forEach((migration) => {
86
- logger.log(` - ${migration}`);
87
- });
88
- } else logger.log("No migrations to rollback");
89
- } catch (error) {
90
- logger.error("Failed to rollback migrations:", error);
91
- throw error;
92
- } finally {
93
- await this.options.knex.destroy();
94
- }
95
- }
96
- /**
97
- * Gets the current migration status.
98
- * Returns information about completed and pending migrations.
99
- *
100
- * @returns Promise with migration status information
101
- */
102
- async status() {
103
- try {
104
- const completed = await this.options.knex.migrate.list();
105
- const [, pending] = await this.options.knex.migrate.currentVersion();
106
- return {
107
- completed: Array.isArray(completed[0]) ? completed[0] : [],
108
- pending: Array.isArray(pending) ? pending : []
109
- };
110
- } finally {
111
- await this.options.knex.destroy();
112
- }
113
- }
114
- };
115
-
116
- //#endregion
117
- export { PostgresObjectionMigrator };
118
- //# sourceMappingURL=PostgresObjectionMigrator-DjPKdUbm.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PostgresObjectionMigrator-DjPKdUbm.mjs","names":["options: {\n\t\t\turi: string;\n\t\t\tknex: Knex;\n\t\t}","migration: string"],"sources":["../src/PostgresObjectionMigrator.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport { PostgresMigrator } from './PostgresMigrator';\n\n/**\n * Default logger instance for migration operations.\n */\nconst logger = console;\n\n/**\n * PostgreSQL migrator implementation for Objection.js ORM with Knex.\n * Extends PostgresMigrator to provide Knex-specific migration functionality.\n * Automatically creates test databases and applies migrations for testing environments.\n *\n * @example\n * ```typescript\n * import knex from 'knex';\n * import { PostgresObjectionMigrator } from '@geekmidas/testkit';\n *\n * // Create Knex instance\n * const db = knex({\n * client: 'pg',\n * connection: uri,\n * migrations: {\n * directory: path.join(__dirname, 'migrations'),\n * extension: 'ts'\n * }\n * });\n *\n * // Create and use migrator\n * const migrator = new PostgresObjectionMigrator({\n * uri: 'postgresql://localhost:5432/test_db',\n * knex: db\n * });\n *\n * const cleanup = await migrator.start();\n * // Run tests...\n * await cleanup();\n * ```\n */\nexport class PostgresObjectionMigrator extends PostgresMigrator {\n\t/**\n\t * Creates a new PostgresObjectionMigrator instance.\n\t *\n\t * @param options - Configuration options\n\t * @param options.uri - PostgreSQL connection URI\n\t * @param options.knex - Knex database instance configured with migrations\n\t */\n\tconstructor(\n\t\tprivate options: {\n\t\t\turi: string;\n\t\t\tknex: Knex;\n\t\t},\n\t) {\n\t\tsuper(options.uri);\n\t}\n\n\t/**\n\t * Executes Knex migrations to the latest version.\n\t * Implements the abstract migrate() method from PostgresMigrator.\n\t *\n\t * @throws Error if migrations fail to apply\n\t * @returns Promise that resolves when all migrations are applied\n\t */\n\tasync migrate(): Promise<void> {\n\t\ttry {\n\t\t\t// Run migrations to latest\n\t\t\tconst [batchNo, migrations] = await this.options.knex.migrate.latest();\n\n\t\t\tif (migrations.length > 0) {\n\t\t\t\tlogger.log(\n\t\t\t\t\t`Applied batch ${batchNo} with ${migrations.length} migrations:`,\n\t\t\t\t);\n\t\t\t\tmigrations.forEach((migration: string) => {\n\t\t\t\t\tlogger.log(` - ${migration}`);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tlogger.log('No pending migrations to apply');\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogger.error('Failed to apply migrations:', error);\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\t// Always destroy the connection pool\n\t\t\tawait this.options.knex.destroy();\n\t\t}\n\t}\n\n\t/**\n\t * Rolls back the last batch of migrations.\n\t * Useful for testing migration rollback scenarios.\n\t *\n\t * @returns Promise that resolves when rollback is complete\n\t */\n\tasync rollback(): Promise<void> {\n\t\ttry {\n\t\t\tconst [batchNo, migrations] = await this.options.knex.migrate.rollback();\n\n\t\t\tif (migrations.length > 0) {\n\t\t\t\tlogger.log(\n\t\t\t\t\t`Rolled back batch ${batchNo} with ${migrations.length} migrations:`,\n\t\t\t\t);\n\t\t\t\tmigrations.forEach((migration: string) => {\n\t\t\t\t\tlogger.log(` - ${migration}`);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tlogger.log('No migrations to rollback');\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogger.error('Failed to rollback migrations:', error);\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tawait this.options.knex.destroy();\n\t\t}\n\t}\n\n\t/**\n\t * Gets the current migration status.\n\t * Returns information about completed and pending migrations.\n\t *\n\t * @returns Promise with migration status information\n\t */\n\tasync status(): Promise<{\n\t\tcompleted: string[];\n\t\tpending: string[];\n\t}> {\n\t\ttry {\n\t\t\tconst completed = await this.options.knex.migrate.list();\n\t\t\tconst [, pending] = await this.options.knex.migrate.currentVersion();\n\n\t\t\treturn {\n\t\t\t\tcompleted: Array.isArray(completed[0]) ? completed[0] : [],\n\t\t\t\tpending: Array.isArray(pending) ? pending : [],\n\t\t\t};\n\t\t} finally {\n\t\t\tawait this.options.knex.destroy();\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;AAMA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCf,IAAa,4BAAb,cAA+C,iBAAiB;;;;;;;;CAQ/D,YACSA,SAIP;AACD,QAAM,QAAQ,IAAI;EALV;CAMR;;;;;;;;CASD,MAAM,UAAyB;AAC9B,MAAI;GAEH,MAAM,CAAC,SAAS,WAAW,GAAG,MAAM,KAAK,QAAQ,KAAK,QAAQ,QAAQ;AAEtE,OAAI,WAAW,SAAS,GAAG;AAC1B,WAAO,KACL,gBAAgB,QAAQ,QAAQ,WAAW,OAAO,cACnD;AACD,eAAW,QAAQ,CAACC,cAAsB;AACzC,YAAO,KAAK,MAAM,UAAU,EAAE;IAC9B,EAAC;GACF,MACA,QAAO,IAAI,iCAAiC;EAE7C,SAAQ,OAAO;AACf,UAAO,MAAM,+BAA+B,MAAM;AAClD,SAAM;EACN,UAAS;AAET,SAAM,KAAK,QAAQ,KAAK,SAAS;EACjC;CACD;;;;;;;CAQD,MAAM,WAA0B;AAC/B,MAAI;GACH,MAAM,CAAC,SAAS,WAAW,GAAG,MAAM,KAAK,QAAQ,KAAK,QAAQ,UAAU;AAExE,OAAI,WAAW,SAAS,GAAG;AAC1B,WAAO,KACL,oBAAoB,QAAQ,QAAQ,WAAW,OAAO,cACvD;AACD,eAAW,QAAQ,CAACA,cAAsB;AACzC,YAAO,KAAK,MAAM,UAAU,EAAE;IAC9B,EAAC;GACF,MACA,QAAO,IAAI,4BAA4B;EAExC,SAAQ,OAAO;AACf,UAAO,MAAM,kCAAkC,MAAM;AACrD,SAAM;EACN,UAAS;AACT,SAAM,KAAK,QAAQ,KAAK,SAAS;EACjC;CACD;;;;;;;CAQD,MAAM,SAGH;AACF,MAAI;GACH,MAAM,YAAY,MAAM,KAAK,QAAQ,KAAK,QAAQ,MAAM;GACxD,MAAM,GAAG,QAAQ,GAAG,MAAM,KAAK,QAAQ,KAAK,QAAQ,gBAAgB;AAEpE,UAAO;IACN,WAAW,MAAM,QAAQ,UAAU,GAAG,GAAG,UAAU,KAAK,CAAE;IAC1D,SAAS,MAAM,QAAQ,QAAQ,GAAG,UAAU,CAAE;GAC9C;EACD,UAAS;AACT,SAAM,KAAK,QAAQ,KAAK,SAAS;EACjC;CACD;AACD"}
@@ -1,67 +0,0 @@
1
- import { VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-CvwPecpl.mjs";
2
-
3
- //#region src/VitestKyselyTransactionIsolator.ts
4
- /**
5
- * Kysely-specific implementation of the Vitest transaction isolator.
6
- * Provides automatic transaction rollback for test isolation using Kysely's transaction API.
7
- * Each test runs within a database transaction that is rolled back after completion,
8
- * ensuring a clean state between tests without the overhead of recreating data.
9
- *
10
- * @template Database - The database schema type
11
- *
12
- * @example
13
- * ```typescript
14
- * import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';
15
- * import { db } from './database';
16
- *
17
- * // Create isolator instance
18
- * const isolator = new VitestKyselyTransactionIsolator<Database>();
19
- *
20
- * // In your test setup
21
- * beforeEach(async () => {
22
- * await isolator.start(db);
23
- * });
24
- *
25
- * afterEach(async () => {
26
- * await isolator.rollback();
27
- * });
28
- *
29
- * // Tests run in isolated transactions
30
- * it('should create user', async () => {
31
- * const user = await db.insertInto('users')
32
- * .values({ name: 'Test User' })
33
- * .returningAll()
34
- * .executeTakeFirst();
35
- *
36
- * expect(user).toBeDefined();
37
- * // This data will be rolled back after the test
38
- * });
39
- * ```
40
- */
41
- var VitestKyselyTransactionIsolator = class extends VitestPostgresTransactionIsolator {
42
- /**
43
- * Closes the pool. Safe to implement now that it runs in the file's
44
- * teardown rather than after every test, where it would have closed the
45
- * connection the next test was about to use.
46
- */
47
- async destroy(conn) {
48
- return conn.destroy();
49
- }
50
- /**
51
- * Creates a Kysely transaction with the specified isolation level.
52
- * Implements the abstract transact method from VitestPostgresTransactionIsolator.
53
- *
54
- * @param conn - The Kysely database connection
55
- * @param level - The transaction isolation level
56
- * @param fn - The function to execute within the transaction
57
- * @returns Promise that resolves when the transaction completes
58
- */
59
- async transact(conn, level, fn) {
60
- const isolationLevel = level.toLocaleLowerCase();
61
- await conn.transaction().setIsolationLevel(isolationLevel).execute(fn);
62
- }
63
- };
64
-
65
- //#endregion
66
- export { VitestKyselyTransactionIsolator };
67
- //# sourceMappingURL=VitestKyselyTransactionIsolator-1Saieke7.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"VitestKyselyTransactionIsolator-1Saieke7.mjs","names":["conn: Kysely<Database>","level: IsolationLevel","fn: (trx: Transaction<Database>) => Promise<void>"],"sources":["../src/VitestKyselyTransactionIsolator.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport {\n\ttype IsolationLevel,\n\tVitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Kysely's transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @template Database - The database schema type\n *\n * @example\n * ```typescript\n * import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';\n * import { db } from './database';\n *\n * // Create isolator instance\n * const isolator = new VitestKyselyTransactionIsolator<Database>();\n *\n * // In your test setup\n * beforeEach(async () => {\n * await isolator.start(db);\n * });\n *\n * afterEach(async () => {\n * await isolator.rollback();\n * });\n *\n * // Tests run in isolated transactions\n * it('should create user', async () => {\n * const user = await db.insertInto('users')\n * .values({ name: 'Test User' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestKyselyTransactionIsolator<\n\tDatabase,\n> extends VitestPostgresTransactionIsolator<\n\tKysely<Database>,\n\tTransaction<Database>\n> {\n\t/**\n\t * Closes the pool. Safe to implement now that it runs in the file's\n\t * teardown rather than after every test, where it would have closed the\n\t * connection the next test was about to use.\n\t */\n\tasync destroy(conn: Kysely<Database>): Promise<void> {\n\t\treturn conn.destroy();\n\t}\n\t/**\n\t * Creates a Kysely transaction with the specified isolation level.\n\t * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n\t *\n\t * @param conn - The Kysely database connection\n\t * @param level - The transaction isolation level\n\t * @param fn - The function to execute within the transaction\n\t * @returns Promise that resolves when the transaction completes\n\t */\n\tasync transact(\n\t\tconn: Kysely<Database>,\n\t\tlevel: IsolationLevel,\n\t\tfn: (trx: Transaction<Database>) => Promise<void>,\n\t): Promise<void> {\n\t\tconst isolationLevel =\n\t\t\tlevel.toLocaleLowerCase() as Lowercase<IsolationLevel>;\n\t\tawait conn.transaction().setIsolationLevel(isolationLevel).execute(fn);\n\t}\n\t// Implement any Kysely-specific transaction logic here\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,kCAAb,cAEU,kCAGR;;;;;;CAMD,MAAM,QAAQA,MAAuC;AACpD,SAAO,KAAK,SAAS;CACrB;;;;;;;;;;CAUD,MAAM,SACLA,MACAC,OACAC,IACgB;EAChB,MAAM,iBACL,MAAM,mBAAmB;AAC1B,QAAM,KAAK,aAAa,CAAC,kBAAkB,eAAe,CAAC,QAAQ,GAAG;CACtE;AAED"}
@@ -1,72 +0,0 @@
1
- const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-DyiX-QtK.cjs');
2
-
3
- //#region src/VitestKyselyTransactionIsolator.ts
4
- /**
5
- * Kysely-specific implementation of the Vitest transaction isolator.
6
- * Provides automatic transaction rollback for test isolation using Kysely's transaction API.
7
- * Each test runs within a database transaction that is rolled back after completion,
8
- * ensuring a clean state between tests without the overhead of recreating data.
9
- *
10
- * @template Database - The database schema type
11
- *
12
- * @example
13
- * ```typescript
14
- * import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';
15
- * import { db } from './database';
16
- *
17
- * // Create isolator instance
18
- * const isolator = new VitestKyselyTransactionIsolator<Database>();
19
- *
20
- * // In your test setup
21
- * beforeEach(async () => {
22
- * await isolator.start(db);
23
- * });
24
- *
25
- * afterEach(async () => {
26
- * await isolator.rollback();
27
- * });
28
- *
29
- * // Tests run in isolated transactions
30
- * it('should create user', async () => {
31
- * const user = await db.insertInto('users')
32
- * .values({ name: 'Test User' })
33
- * .returningAll()
34
- * .executeTakeFirst();
35
- *
36
- * expect(user).toBeDefined();
37
- * // This data will be rolled back after the test
38
- * });
39
- * ```
40
- */
41
- var VitestKyselyTransactionIsolator = class extends require_VitestTransactionIsolator.VitestPostgresTransactionIsolator {
42
- /**
43
- * Closes the pool. Safe to implement now that it runs in the file's
44
- * teardown rather than after every test, where it would have closed the
45
- * connection the next test was about to use.
46
- */
47
- async destroy(conn) {
48
- return conn.destroy();
49
- }
50
- /**
51
- * Creates a Kysely transaction with the specified isolation level.
52
- * Implements the abstract transact method from VitestPostgresTransactionIsolator.
53
- *
54
- * @param conn - The Kysely database connection
55
- * @param level - The transaction isolation level
56
- * @param fn - The function to execute within the transaction
57
- * @returns Promise that resolves when the transaction completes
58
- */
59
- async transact(conn, level, fn) {
60
- const isolationLevel = level.toLocaleLowerCase();
61
- await conn.transaction().setIsolationLevel(isolationLevel).execute(fn);
62
- }
63
- };
64
-
65
- //#endregion
66
- Object.defineProperty(exports, 'VitestKyselyTransactionIsolator', {
67
- enumerable: true,
68
- get: function () {
69
- return VitestKyselyTransactionIsolator;
70
- }
71
- });
72
- //# sourceMappingURL=VitestKyselyTransactionIsolator-BjJSXryR.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"VitestKyselyTransactionIsolator-BjJSXryR.cjs","names":["VitestPostgresTransactionIsolator","conn: Kysely<Database>","level: IsolationLevel","fn: (trx: Transaction<Database>) => Promise<void>"],"sources":["../src/VitestKyselyTransactionIsolator.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport {\n\ttype IsolationLevel,\n\tVitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Kysely's transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @template Database - The database schema type\n *\n * @example\n * ```typescript\n * import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';\n * import { db } from './database';\n *\n * // Create isolator instance\n * const isolator = new VitestKyselyTransactionIsolator<Database>();\n *\n * // In your test setup\n * beforeEach(async () => {\n * await isolator.start(db);\n * });\n *\n * afterEach(async () => {\n * await isolator.rollback();\n * });\n *\n * // Tests run in isolated transactions\n * it('should create user', async () => {\n * const user = await db.insertInto('users')\n * .values({ name: 'Test User' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestKyselyTransactionIsolator<\n\tDatabase,\n> extends VitestPostgresTransactionIsolator<\n\tKysely<Database>,\n\tTransaction<Database>\n> {\n\t/**\n\t * Closes the pool. Safe to implement now that it runs in the file's\n\t * teardown rather than after every test, where it would have closed the\n\t * connection the next test was about to use.\n\t */\n\tasync destroy(conn: Kysely<Database>): Promise<void> {\n\t\treturn conn.destroy();\n\t}\n\t/**\n\t * Creates a Kysely transaction with the specified isolation level.\n\t * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n\t *\n\t * @param conn - The Kysely database connection\n\t * @param level - The transaction isolation level\n\t * @param fn - The function to execute within the transaction\n\t * @returns Promise that resolves when the transaction completes\n\t */\n\tasync transact(\n\t\tconn: Kysely<Database>,\n\t\tlevel: IsolationLevel,\n\t\tfn: (trx: Transaction<Database>) => Promise<void>,\n\t): Promise<void> {\n\t\tconst isolationLevel =\n\t\t\tlevel.toLocaleLowerCase() as Lowercase<IsolationLevel>;\n\t\tawait conn.transaction().setIsolationLevel(isolationLevel).execute(fn);\n\t}\n\t// Implement any Kysely-specific transaction logic here\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,kCAAb,cAEUA,oEAGR;;;;;;CAMD,MAAM,QAAQC,MAAuC;AACpD,SAAO,KAAK,SAAS;CACrB;;;;;;;;;;CAUD,MAAM,SACLA,MACAC,OACAC,IACgB;EAChB,MAAM,iBACL,MAAM,mBAAmB;AAC1B,QAAM,KAAK,aAAa,CAAC,kBAAkB,eAAe,CAAC,QAAQ,GAAG;CACtE;AAED"}