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

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 +276 -8
  117. package/dist/faker.cjs.map +1 -0
  118. package/dist/faker.d.cts +145 -2
  119. package/dist/faker.d.cts.map +1 -0
  120. package/dist/faker.d.mts +145 -2
  121. package/dist/faker.d.mts.map +1 -0
  122. package/dist/faker.mjs +269 -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,3 +1,80 @@
1
- import "./PostgresMigrator-CeYy-eHF.cjs";
2
- import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-B2M6Gjvv.cjs";
3
- export { PostgresKyselyMigrator };
1
+ import { t as PostgresMigrator } from "./PostgresMigrator-CDPnnwMJ.cjs";
2
+ import { Kysely } from "kysely";
3
+ import { MigrationProvider } from "kysely/migration";
4
+ //#region src/PostgresKyselyMigrator.d.ts
5
+ /**
6
+ * PostgreSQL migrator implementation for Kysely ORM.
7
+ * Extends PostgresMigrator to provide Kysely-specific migration functionality.
8
+ * Automatically creates test databases and applies migrations for testing environments.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { FileMigrationProvider } from 'kysely';
13
+ * import { PostgresKyselyMigrator } from '@geekmidas/testkit';
14
+ *
15
+ * // Create migration provider
16
+ * const provider = new FileMigrationProvider({
17
+ * fs: require('fs'),
18
+ * path: require('path'),
19
+ * migrationFolder: path.join(__dirname, 'migrations')
20
+ * });
21
+ *
22
+ * // Create Kysely instance
23
+ * const db = new Kysely<Database>({
24
+ * dialect: new PostgresDialect({
25
+ * pool: new Pool({ connectionString: uri })
26
+ * })
27
+ * });
28
+ *
29
+ * // Create and use migrator
30
+ * const migrator = new PostgresKyselyMigrator({
31
+ * uri: 'postgresql://localhost:5432/test_db',
32
+ * db,
33
+ * provider
34
+ * });
35
+ *
36
+ * const cleanup = await migrator.start();
37
+ * // Run tests...
38
+ * await cleanup();
39
+ *
40
+ * // With afterCreate hook to create per-app users
41
+ * import { runInitScript } from '@geekmidas/testkit/postgres';
42
+ *
43
+ * const migrator = new PostgresKyselyMigrator({
44
+ * uri: 'postgresql://localhost:5432/test_db',
45
+ * db,
46
+ * provider,
47
+ * afterCreate: async (uri) => {
48
+ * await runInitScript('docker/postgres/init.sh', uri, env);
49
+ * },
50
+ * });
51
+ * ```
52
+ */
53
+ export declare class PostgresKyselyMigrator extends PostgresMigrator {
54
+ private options;
55
+ /**
56
+ * Creates a new PostgresKyselyMigrator instance.
57
+ *
58
+ * @param options - Configuration options
59
+ * @param options.uri - PostgreSQL connection URI
60
+ * @param options.db - Kysely database instance
61
+ * @param options.provider - Migration provider for locating migration files
62
+ * @param options.afterCreate - Optional hook called after database creation but before migrations
63
+ */
64
+ constructor(options: {
65
+ uri: string;
66
+ db: Kysely<any>;
67
+ provider: MigrationProvider;
68
+ afterCreate?: (uri: string) => Promise<void>;
69
+ });
70
+ /**
71
+ * Executes Kysely migrations to the latest version.
72
+ * Implements the abstract migrate() method from PostgresMigrator.
73
+ *
74
+ * @throws Error if migrations fail to apply
75
+ * @returns Promise that resolves when all migrations are applied
76
+ */
77
+ migrate(): Promise<void>;
78
+ }
79
+ //#endregion
80
+ //# sourceMappingURL=PostgresKyselyMigrator.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresKyselyMigrator.d.cts","names":[],"sources":["../src/PostgresKyselyMigrator.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA2Da,+BAA+B;UAWlC;;;;;;;;;;EADT,YACS;IACP;IACA,IAAI;IACJ,UAAU;IACV,eAAe,gBAAgB;;;;;;;;;EAa3B,WAAW"}
@@ -1,3 +1,80 @@
1
- import "./PostgresMigrator-C_QQ6q35.mjs";
2
- import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CvwXycJE.mjs";
3
- export { PostgresKyselyMigrator };
1
+ import { t as PostgresMigrator } from "./PostgresMigrator-CDPnnwMJ.mjs";
2
+ import { MigrationProvider } from "kysely/migration";
3
+ import { Kysely } from "kysely";
4
+ //#region src/PostgresKyselyMigrator.d.ts
5
+ /**
6
+ * PostgreSQL migrator implementation for Kysely ORM.
7
+ * Extends PostgresMigrator to provide Kysely-specific migration functionality.
8
+ * Automatically creates test databases and applies migrations for testing environments.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { FileMigrationProvider } from 'kysely';
13
+ * import { PostgresKyselyMigrator } from '@geekmidas/testkit';
14
+ *
15
+ * // Create migration provider
16
+ * const provider = new FileMigrationProvider({
17
+ * fs: require('fs'),
18
+ * path: require('path'),
19
+ * migrationFolder: path.join(__dirname, 'migrations')
20
+ * });
21
+ *
22
+ * // Create Kysely instance
23
+ * const db = new Kysely<Database>({
24
+ * dialect: new PostgresDialect({
25
+ * pool: new Pool({ connectionString: uri })
26
+ * })
27
+ * });
28
+ *
29
+ * // Create and use migrator
30
+ * const migrator = new PostgresKyselyMigrator({
31
+ * uri: 'postgresql://localhost:5432/test_db',
32
+ * db,
33
+ * provider
34
+ * });
35
+ *
36
+ * const cleanup = await migrator.start();
37
+ * // Run tests...
38
+ * await cleanup();
39
+ *
40
+ * // With afterCreate hook to create per-app users
41
+ * import { runInitScript } from '@geekmidas/testkit/postgres';
42
+ *
43
+ * const migrator = new PostgresKyselyMigrator({
44
+ * uri: 'postgresql://localhost:5432/test_db',
45
+ * db,
46
+ * provider,
47
+ * afterCreate: async (uri) => {
48
+ * await runInitScript('docker/postgres/init.sh', uri, env);
49
+ * },
50
+ * });
51
+ * ```
52
+ */
53
+ export declare class PostgresKyselyMigrator extends PostgresMigrator {
54
+ private options;
55
+ /**
56
+ * Creates a new PostgresKyselyMigrator instance.
57
+ *
58
+ * @param options - Configuration options
59
+ * @param options.uri - PostgreSQL connection URI
60
+ * @param options.db - Kysely database instance
61
+ * @param options.provider - Migration provider for locating migration files
62
+ * @param options.afterCreate - Optional hook called after database creation but before migrations
63
+ */
64
+ constructor(options: {
65
+ uri: string;
66
+ db: Kysely<any>;
67
+ provider: MigrationProvider;
68
+ afterCreate?: (uri: string) => Promise<void>;
69
+ });
70
+ /**
71
+ * Executes Kysely migrations to the latest version.
72
+ * Implements the abstract migrate() method from PostgresMigrator.
73
+ *
74
+ * @throws Error if migrations fail to apply
75
+ * @returns Promise that resolves when all migrations are applied
76
+ */
77
+ migrate(): Promise<void>;
78
+ }
79
+ //#endregion
80
+ //# sourceMappingURL=PostgresKyselyMigrator.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresKyselyMigrator.d.mts","names":[],"sources":["../src/PostgresKyselyMigrator.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA2Da,+BAA+B;UAWlC;;;;;;;;;;EADT,YACS;IACP;IACA,IAAI;IACJ,UAAU;IACV,eAAe,gBAAgB;;;;;;;;;EAa3B,WAAW"}
@@ -1,4 +1,94 @@
1
- import "./PostgresMigrator-DVAY04qN.mjs";
2
- import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-PI0QhvB1.mjs";
1
+ import { PostgresMigrator } from "./PostgresMigrator.mjs";
2
+ import { Migrator } from "kysely/migration";
3
+ //#region src/PostgresKyselyMigrator.ts
4
+ /**
5
+ * Default logger instance for migration operations.
6
+ */
7
+ const logger = console;
8
+ /**
9
+ * PostgreSQL migrator implementation for Kysely ORM.
10
+ * Extends PostgresMigrator to provide Kysely-specific migration functionality.
11
+ * Automatically creates test databases and applies migrations for testing environments.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { FileMigrationProvider } from 'kysely';
16
+ * import { PostgresKyselyMigrator } from '@geekmidas/testkit';
17
+ *
18
+ * // Create migration provider
19
+ * const provider = new FileMigrationProvider({
20
+ * fs: require('fs'),
21
+ * path: require('path'),
22
+ * migrationFolder: path.join(__dirname, 'migrations')
23
+ * });
24
+ *
25
+ * // Create Kysely instance
26
+ * const db = new Kysely<Database>({
27
+ * dialect: new PostgresDialect({
28
+ * pool: new Pool({ connectionString: uri })
29
+ * })
30
+ * });
31
+ *
32
+ * // Create and use migrator
33
+ * const migrator = new PostgresKyselyMigrator({
34
+ * uri: 'postgresql://localhost:5432/test_db',
35
+ * db,
36
+ * provider
37
+ * });
38
+ *
39
+ * const cleanup = await migrator.start();
40
+ * // Run tests...
41
+ * await cleanup();
42
+ *
43
+ * // With afterCreate hook to create per-app users
44
+ * import { runInitScript } from '@geekmidas/testkit/postgres';
45
+ *
46
+ * const migrator = new PostgresKyselyMigrator({
47
+ * uri: 'postgresql://localhost:5432/test_db',
48
+ * db,
49
+ * provider,
50
+ * afterCreate: async (uri) => {
51
+ * await runInitScript('docker/postgres/init.sh', uri, env);
52
+ * },
53
+ * });
54
+ * ```
55
+ */
56
+ var PostgresKyselyMigrator = class extends PostgresMigrator {
57
+ options;
58
+ /**
59
+ * Creates a new PostgresKyselyMigrator instance.
60
+ *
61
+ * @param options - Configuration options
62
+ * @param options.uri - PostgreSQL connection URI
63
+ * @param options.db - Kysely database instance
64
+ * @param options.provider - Migration provider for locating migration files
65
+ * @param options.afterCreate - Optional hook called after database creation but before migrations
66
+ */
67
+ constructor(options) {
68
+ super(options.uri, options.afterCreate);
69
+ this.options = options;
70
+ }
71
+ /**
72
+ * Executes Kysely migrations to the latest version.
73
+ * Implements the abstract migrate() method from PostgresMigrator.
74
+ *
75
+ * @throws Error if migrations fail to apply
76
+ * @returns Promise that resolves when all migrations are applied
77
+ */
78
+ async migrate() {
79
+ const migrations = await new Migrator({
80
+ db: this.options.db,
81
+ provider: this.options.provider
82
+ }).migrateToLatest();
83
+ if (migrations.error) {
84
+ logger.error(migrations.error, `Failed to apply migrations`);
85
+ throw migrations.error;
86
+ }
87
+ await this.options.db.destroy();
88
+ logger.log(`Applied ${migrations.results?.length} migrations successfully`);
89
+ }
90
+ };
91
+ //#endregion
92
+ export { PostgresKyselyMigrator };
3
93
 
4
- export { PostgresKyselyMigrator };
94
+ //# sourceMappingURL=PostgresKyselyMigrator.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresKyselyMigrator.mjs","names":[],"sources":["../src/PostgresKyselyMigrator.ts"],"sourcesContent":["import type { Kysely } from 'kysely';\n// `Migrator` and the `MigrationProvider` type moved from the root barrel ('kysely')\n// to the 'kysely/migration' subpath in kysely 0.29+.\nimport { type MigrationProvider, Migrator } from 'kysely/migration';\nimport { PostgresMigrator } from './PostgresMigrator';\n\n/**\n * Default logger instance for migration operations.\n */\nconst logger = console;\n\n/**\n * PostgreSQL migrator implementation for Kysely ORM.\n * Extends PostgresMigrator to provide Kysely-specific migration functionality.\n * Automatically creates test databases and applies migrations for testing environments.\n *\n * @example\n * ```typescript\n * import { FileMigrationProvider } from 'kysely';\n * import { PostgresKyselyMigrator } from '@geekmidas/testkit';\n *\n * // Create migration provider\n * const provider = new FileMigrationProvider({\n * fs: require('fs'),\n * path: require('path'),\n * migrationFolder: path.join(__dirname, 'migrations')\n * });\n *\n * // Create Kysely instance\n * const db = new Kysely<Database>({\n * dialect: new PostgresDialect({\n * pool: new Pool({ connectionString: uri })\n * })\n * });\n *\n * // Create and use migrator\n * const migrator = new PostgresKyselyMigrator({\n * uri: 'postgresql://localhost:5432/test_db',\n * db,\n * provider\n * });\n *\n * const cleanup = await migrator.start();\n * // Run tests...\n * await cleanup();\n *\n * // With afterCreate hook to create per-app users\n * import { runInitScript } from '@geekmidas/testkit/postgres';\n *\n * const migrator = new PostgresKyselyMigrator({\n * uri: 'postgresql://localhost:5432/test_db',\n * db,\n * provider,\n * afterCreate: async (uri) => {\n * await runInitScript('docker/postgres/init.sh', uri, env);\n * },\n * });\n * ```\n */\nexport class PostgresKyselyMigrator extends PostgresMigrator {\n\t/**\n\t * Creates a new PostgresKyselyMigrator instance.\n\t *\n\t * @param options - Configuration options\n\t * @param options.uri - PostgreSQL connection URI\n\t * @param options.db - Kysely database instance\n\t * @param options.provider - Migration provider for locating migration files\n\t * @param options.afterCreate - Optional hook called after database creation but before migrations\n\t */\n\tconstructor(\n\t\tprivate options: {\n\t\t\turi: string;\n\t\t\tdb: Kysely<any>;\n\t\t\tprovider: MigrationProvider;\n\t\t\tafterCreate?: (uri: string) => Promise<void>;\n\t\t},\n\t) {\n\t\tsuper(options.uri, options.afterCreate);\n\t}\n\n\t/**\n\t * Executes Kysely 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\tconst migrator = new Migrator({\n\t\t\tdb: this.options.db,\n\t\t\tprovider: this.options.provider,\n\t\t});\n\t\tconst migrations = await migrator.migrateToLatest();\n\n\t\tif (migrations.error) {\n\t\t\tlogger.error(migrations.error, `Failed to apply migrations`);\n\t\t\tthrow migrations.error;\n\t\t}\n\n\t\tawait this.options.db.destroy();\n\n\t\tlogger.log(`Applied ${migrations.results?.length} migrations successfully`);\n\t}\n}\n"],"mappings":";;;;;;AASA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDf,IAAa,yBAAb,cAA4C,iBAAiB;CAWnD;;;;;;;;;;CADT,YACC,SAMC;EACD,MAAM,QAAQ,KAAK,QAAQ,WAAW;EAP9B,KAAA,UAAA;CAQT;;;;;;;;CASA,MAAM,UAAyB;EAK9B,MAAM,aAAa,MAAM,IAJJ,SAAS;GAC7B,IAAI,KAAK,QAAQ;GACjB,UAAU,KAAK,QAAQ;EACxB,CACgC,CAAC,CAAC,gBAAgB;EAElD,IAAI,WAAW,OAAO;GACrB,OAAO,MAAM,WAAW,OAAO,4BAA4B;GAC3D,MAAM,WAAW;EAClB;EAEA,MAAM,KAAK,QAAQ,GAAG,QAAQ;EAE9B,OAAO,IAAI,WAAW,WAAW,SAAS,OAAO,yBAAyB;CAC3E;AACD"}
@@ -71,9 +71,16 @@ declare abstract class PostgresMigrator {
71
71
  private static drop;
72
72
  /**
73
73
  * Starts the migration process by creating the database and running migrations.
74
- * Returns a cleanup function that will drop the database when called.
74
+ * Returns a cleanup function that drops the database — if this call created
75
+ * it.
75
76
  *
76
- * @returns Async cleanup function that drops the created database
77
+ * A database that was already there belongs to whoever made it, and the
78
+ * cleanup leaves it alone. `gkm test` provisions the test database before
79
+ * the suite starts, with an owner role that may migrate it but not drop it:
80
+ * dropping it was never the suite's to do, and failed there as a permission
81
+ * error on the way out of an otherwise green run.
82
+ *
83
+ * @returns Async cleanup function that drops the database if it created it
77
84
  *
78
85
  * @example
79
86
  * ```typescript
@@ -93,7 +100,6 @@ declare abstract class PostgresMigrator {
93
100
  */
94
101
  start(): Promise<() => Promise<void>>;
95
102
  }
96
- //# sourceMappingURL=PostgresMigrator.d.ts.map
97
103
  //#endregion
98
- export { PostgresMigrator };
99
- //# sourceMappingURL=PostgresMigrator-C_QQ6q35.d.mts.map
104
+ export { PostgresMigrator as t };
105
+ //# sourceMappingURL=PostgresMigrator-CDPnnwMJ.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresMigrator-CDPnnwMJ.d.cts","names":[],"sources":["../src/PostgresMigrator.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBA4EsB;UAQZ;UACA;;;;;;;EAFT,YACS,aACA,gBAAe,gBAAgB;;;;;;;WAS/B,WAAW;;;;;;;;;iBAUC;;;;;;;;;iBA4CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuCf,SAAK,cAAA"}
@@ -71,9 +71,16 @@ declare abstract class PostgresMigrator {
71
71
  private static drop;
72
72
  /**
73
73
  * Starts the migration process by creating the database and running migrations.
74
- * Returns a cleanup function that will drop the database when called.
74
+ * Returns a cleanup function that drops the database — if this call created
75
+ * it.
75
76
  *
76
- * @returns Async cleanup function that drops the created database
77
+ * A database that was already there belongs to whoever made it, and the
78
+ * cleanup leaves it alone. `gkm test` provisions the test database before
79
+ * the suite starts, with an owner role that may migrate it but not drop it:
80
+ * dropping it was never the suite's to do, and failed there as a permission
81
+ * error on the way out of an otherwise green run.
82
+ *
83
+ * @returns Async cleanup function that drops the database if it created it
77
84
  *
78
85
  * @example
79
86
  * ```typescript
@@ -93,7 +100,6 @@ declare abstract class PostgresMigrator {
93
100
  */
94
101
  start(): Promise<() => Promise<void>>;
95
102
  }
96
- //# sourceMappingURL=PostgresMigrator.d.ts.map
97
103
  //#endregion
98
- export { PostgresMigrator };
99
- //# sourceMappingURL=PostgresMigrator-CeYy-eHF.d.cts.map
104
+ export { PostgresMigrator as t };
105
+ //# sourceMappingURL=PostgresMigrator-CDPnnwMJ.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresMigrator-CDPnnwMJ.d.mts","names":[],"sources":["../src/PostgresMigrator.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBA4EsB;UAQZ;UACA;;;;;;;EAFT,YACS,aACA,gBAAe,gBAAgB;;;;;;;WAS/B,WAAW;;;;;;;;;iBAUC;;;;;;;;;iBA4CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuCf,SAAK,cAAA"}
@@ -1,3 +1,179 @@
1
- const require_PostgresMigrator = require('./PostgresMigrator-M9jpzOvN.cjs');
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;
2
178
 
3
- exports.PostgresMigrator = require_PostgresMigrator.PostgresMigrator;
179
+ //# sourceMappingURL=PostgresMigrator.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresMigrator.cjs","names":[],"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// Another process created it between our check and our create. Postgres\n\t\t\t\t\t// reports that as 42P04 (duplicate_database) — or, when the two creates\n\t\t\t\t\t// race inside the catalog itself, as 23505 on pg_database's name index.\n\t\t\t\t\tif (\n\t\t\t\t\t\terror?.code === '42P04' ||\n\t\t\t\t\t\t(error?.code === '23505' &&\n\t\t\t\t\t\t\terror?.constraint === 'pg_database_datname_index')\n\t\t\t\t\t) {\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 drops the database — if this call created\n\t * it.\n\t *\n\t * A database that was already there belongs to whoever made it, and the\n\t * cleanup leaves it alone. `gkm test` provisions the test database before\n\t * the suite starts, with an owner role that may migrate it but not drop it:\n\t * dropping it was never the suite's to do, and failed there as a permission\n\t * error on the way out of an otherwise green run.\n\t *\n\t * @returns Async cleanup function that drops the database if it created it\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\tlet created = false;\n\t\ttry {\n\t\t\tconst { alreadyExisted } = await PostgresMigrator.create(this.uri);\n\t\t\tcreated = !alreadyExisted;\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\tif (created) await PostgresMigrator.drop(this.uri);\n\t\t};\n\t}\n}\n"],"mappings":";;;;;AAEA,MAAM,EAAE,WAAW,GAAA;;;;;;;;;;;;;;;AAgBnB,eAAe,YAAY,KAAa;CACvC,MAAM,MAAM,IAAI,IAAI,GAAG;CAEvB,MAAM,KAAK,IAAI,OAAO;EACrB,MAAM,IAAI;EACV,UAAU,IAAI;EACd,MAAM,IAAI;EACV,MAAM,SAAS,IAAI,MAAM,EAAE;EAC3B,UAAU;CACX,CAAC;CAED,IAAI,WAAW,IAAI,SAAS,MAAM,CAAC;CACnC,IAAI,SAAS,SAAS,GAAG,GACxB,WAAW,SAAS,UAAU,GAAG,SAAS,QAAQ,GAAG,CAAC;CAEvD,OAAO;EAAE;EAAU;CAAG;AACvB;;;;AAKA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCf,IAAsB,mBAAtB,MAAsB,iBAAiB;CAQ7B;CACA;;;;;;;CAFT,YACC,KACA,aACC;EAFO,KAAA,MAAA;EACA,KAAA,cAAA;CACN;;;;;;;;;CAkBH,aAAqB,OACpB,KACuC;EACvC,MAAM,EAAE,UAAU,OAAO,MAAM,YAAY,GAAG;EAC9C,IAAI;GACH,MAAM,GAAG,QAAQ;GACjB,MAAM,SAAS,MAAM,GAAG,MACvB,yDAAyD,SAAS,EACnE;GAEA,IAAI,OAAO,aAAa,GACvB,IAAI;IACH,MAAM,GAAG,MAAM,oBAAoB,SAAS,EAAE;GAC/C,SAAS,OAAY;IAIpB,IACC,OAAO,SAAS,WACf,OAAO,SAAS,WAChB,OAAO,eAAe,6BAEvB,OAAO,EAAE,gBAAgB,KAAK;IAE/B,MAAM;GACP;GAGD,OAAO,EACN,gBAAgB,OAAO,WAAW,OAAO,WAAW,IAAI,MACzD;EACD,UAAU;GACT,MAAM,GAAG,IAAI;EACd;CACD;;;;;;;;;CAUA,aAAqB,KAAK,KAA4B;EACrD,MAAM,EAAE,UAAU,OAAO,MAAM,YAAY,GAAG;EAC9C,IAAI;GACH,MAAM,GAAG,QAAQ;GACjB,MAAM,GAAG,MAAM,kBAAkB,SAAS,EAAE;EAC7C,UAAU;GACT,MAAM,GAAG,IAAI;EACd;CACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BA,MAAM,QAAQ;EACb,MAAM,EAAE,UAAU,OAAO,MAAM,YAAY,KAAK,GAAG;EACnD,IAAI,UAAU;EACd,IAAI;GACH,MAAM,EAAE,mBAAmB,MAAM,iBAAiB,OAAO,KAAK,GAAG;GACjE,UAAU,CAAC;GACX,IAAI,KAAK,aACR,MAAM,KAAK,YAAY,KAAK,GAAG;GAEhC,MAAM,KAAK,QAAQ;GACnB,OAAO,IAAI,uBAAuB,UAAU;EAE7C,UAAU;GACT,MAAM,GAAG,IAAI;EACd;EAEA,OAAO,YAAY;GAClB,IAAI,SAAS,MAAM,iBAAiB,KAAK,KAAK,GAAG;EAClD;CACD;AACD"}
@@ -1,2 +1,2 @@
1
- import { PostgresMigrator } from "./PostgresMigrator-CeYy-eHF.cjs";
1
+ import { t as PostgresMigrator } from "./PostgresMigrator-CDPnnwMJ.cjs";
2
2
  export { PostgresMigrator };
@@ -1,2 +1,2 @@
1
- import { PostgresMigrator } from "./PostgresMigrator-C_QQ6q35.mjs";
1
+ import { t as PostgresMigrator } from "./PostgresMigrator-CDPnnwMJ.mjs";
2
2
  export { PostgresMigrator };