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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/dist/Factory.cjs +51 -2
  2. package/dist/Factory.cjs.map +1 -0
  3. package/dist/Factory.d.cts +143 -3
  4. package/dist/Factory.d.cts.map +1 -0
  5. package/dist/Factory.d.mts +143 -3
  6. package/dist/Factory.d.mts.map +1 -0
  7. package/dist/Factory.mjs +50 -2
  8. package/dist/Factory.mjs.map +1 -0
  9. package/dist/KyselyFactory.cjs +237 -4
  10. package/dist/KyselyFactory.cjs.map +1 -0
  11. package/dist/KyselyFactory.d.cts +224 -4
  12. package/dist/KyselyFactory.d.cts.map +1 -0
  13. package/dist/KyselyFactory.d.mts +224 -4
  14. package/dist/KyselyFactory.d.mts.map +1 -0
  15. package/dist/KyselyFactory.mjs +236 -4
  16. package/dist/KyselyFactory.mjs.map +1 -0
  17. package/dist/ObjectionFactory.cjs +265 -4
  18. package/dist/ObjectionFactory.cjs.map +1 -0
  19. package/dist/ObjectionFactory.d.cts +237 -4
  20. package/dist/ObjectionFactory.d.cts.map +1 -0
  21. package/dist/ObjectionFactory.d.mts +237 -4
  22. package/dist/ObjectionFactory.d.mts.map +1 -0
  23. package/dist/ObjectionFactory.mjs +264 -4
  24. package/dist/ObjectionFactory.mjs.map +1 -0
  25. package/dist/PostgresKyselyMigrator.cjs +94 -3
  26. package/dist/PostgresKyselyMigrator.cjs.map +1 -0
  27. package/dist/PostgresKyselyMigrator.d.cts +80 -3
  28. package/dist/PostgresKyselyMigrator.d.cts.map +1 -0
  29. package/dist/PostgresKyselyMigrator.d.mts +80 -3
  30. package/dist/PostgresKyselyMigrator.d.mts.map +1 -0
  31. package/dist/PostgresKyselyMigrator.mjs +93 -3
  32. package/dist/PostgresKyselyMigrator.mjs.map +1 -0
  33. package/dist/{PostgresMigrator-C_QQ6q35.d.mts → PostgresMigrator-CoHQ95cT.d.cts} +2 -3
  34. package/dist/PostgresMigrator-CoHQ95cT.d.cts.map +1 -0
  35. package/dist/{PostgresMigrator-CeYy-eHF.d.cts → PostgresMigrator-CoHQ95cT.d.mts} +2 -3
  36. package/dist/PostgresMigrator-CoHQ95cT.d.mts.map +1 -0
  37. package/dist/PostgresMigrator.cjs +169 -2
  38. package/dist/PostgresMigrator.cjs.map +1 -0
  39. package/dist/PostgresMigrator.d.cts +1 -1
  40. package/dist/PostgresMigrator.d.mts +1 -1
  41. package/dist/PostgresMigrator.mjs +166 -2
  42. package/dist/PostgresMigrator.mjs.map +1 -0
  43. package/dist/PostgresObjectionMigrator.cjs +118 -3
  44. package/dist/PostgresObjectionMigrator.cjs.map +1 -0
  45. package/dist/PostgresObjectionMigrator.d.cts +75 -3
  46. package/dist/PostgresObjectionMigrator.d.cts.map +1 -0
  47. package/dist/PostgresObjectionMigrator.d.mts +75 -3
  48. package/dist/PostgresObjectionMigrator.d.mts.map +1 -0
  49. package/dist/PostgresObjectionMigrator.mjs +117 -3
  50. package/dist/PostgresObjectionMigrator.mjs.map +1 -0
  51. package/dist/VitestKyselyTransactionIsolator.cjs +66 -3
  52. package/dist/VitestKyselyTransactionIsolator.cjs.map +1 -0
  53. package/dist/VitestKyselyTransactionIsolator.d.cts +60 -3
  54. package/dist/VitestKyselyTransactionIsolator.d.cts.map +1 -0
  55. package/dist/VitestKyselyTransactionIsolator.d.mts +60 -3
  56. package/dist/VitestKyselyTransactionIsolator.d.mts.map +1 -0
  57. package/dist/VitestKyselyTransactionIsolator.mjs +65 -3
  58. package/dist/VitestKyselyTransactionIsolator.mjs.map +1 -0
  59. package/dist/VitestObjectionTransactionIsolator.cjs +62 -3
  60. package/dist/VitestObjectionTransactionIsolator.cjs.map +1 -0
  61. package/dist/VitestObjectionTransactionIsolator.d.cts +56 -3
  62. package/dist/VitestObjectionTransactionIsolator.d.cts.map +1 -0
  63. package/dist/VitestObjectionTransactionIsolator.d.mts +56 -3
  64. package/dist/VitestObjectionTransactionIsolator.d.mts.map +1 -0
  65. package/dist/VitestObjectionTransactionIsolator.mjs +61 -3
  66. package/dist/VitestObjectionTransactionIsolator.mjs.map +1 -0
  67. package/dist/VitestTransactionIsolator.cjs +187 -4
  68. package/dist/VitestTransactionIsolator.cjs.map +1 -0
  69. package/dist/VitestTransactionIsolator.d.cts +219 -2
  70. package/dist/VitestTransactionIsolator.d.cts.map +1 -0
  71. package/dist/VitestTransactionIsolator.d.mts +219 -2
  72. package/dist/VitestTransactionIsolator.d.mts.map +1 -0
  73. package/dist/VitestTransactionIsolator.mjs +184 -2
  74. package/dist/VitestTransactionIsolator.mjs.map +1 -0
  75. package/dist/aws.cjs +3 -4
  76. package/dist/aws.cjs.map +1 -1
  77. package/dist/aws.d.cts +3 -8
  78. package/dist/aws.d.cts.map +1 -1
  79. package/dist/aws.d.mts +3 -8
  80. package/dist/aws.d.mts.map +1 -1
  81. package/dist/aws.mjs +1 -2
  82. package/dist/aws.mjs.map +1 -1
  83. package/dist/benchmark.cjs +2 -2
  84. package/dist/benchmark.cjs.map +1 -1
  85. package/dist/benchmark.d.cts +4 -6
  86. package/dist/benchmark.d.cts.map +1 -1
  87. package/dist/benchmark.d.mts +4 -6
  88. package/dist/benchmark.d.mts.map +1 -1
  89. package/dist/benchmark.mjs +1 -1
  90. package/dist/benchmark.mjs.map +1 -1
  91. package/dist/better-auth.cjs +17 -8
  92. package/dist/better-auth.cjs.map +1 -1
  93. package/dist/better-auth.d.cts +13142 -5
  94. package/dist/better-auth.d.cts.map +1 -1
  95. package/dist/better-auth.d.mts +13142 -5
  96. package/dist/better-auth.d.mts.map +1 -1
  97. package/dist/better-auth.mjs +15 -6
  98. package/dist/better-auth.mjs.map +1 -1
  99. package/dist/faker.cjs +262 -8
  100. package/dist/faker.cjs.map +1 -0
  101. package/dist/faker.d.cts +162 -2
  102. package/dist/faker.d.cts.map +1 -0
  103. package/dist/faker.d.mts +162 -2
  104. package/dist/faker.d.mts.map +1 -0
  105. package/dist/faker.mjs +255 -2
  106. package/dist/faker.mjs.map +1 -0
  107. package/dist/helpers.cjs +6 -5
  108. package/dist/helpers.cjs.map +1 -1
  109. package/dist/helpers.d.cts +1 -5
  110. package/dist/helpers.d.cts.map +1 -1
  111. package/dist/helpers.d.mts +1 -5
  112. package/dist/helpers.d.mts.map +1 -1
  113. package/dist/helpers.mjs +1 -2
  114. package/dist/helpers.mjs.map +1 -1
  115. package/dist/initScript.cjs +15 -15
  116. package/dist/initScript.cjs.map +1 -1
  117. package/dist/initScript.d.cts +2 -4
  118. package/dist/initScript.d.cts.map +1 -1
  119. package/dist/initScript.d.mts +2 -4
  120. package/dist/initScript.d.mts.map +1 -1
  121. package/dist/initScript.mjs +10 -12
  122. package/dist/initScript.mjs.map +1 -1
  123. package/dist/kysely.cjs +10 -13
  124. package/dist/kysely.cjs.map +1 -1
  125. package/dist/kysely.d.cts +10 -14
  126. package/dist/kysely.d.cts.map +1 -1
  127. package/dist/kysely.d.mts +10 -14
  128. package/dist/kysely.d.mts.map +1 -1
  129. package/dist/kysely.mjs +10 -14
  130. package/dist/kysely.mjs.map +1 -1
  131. package/dist/logger.cjs +3 -4
  132. package/dist/logger.cjs.map +1 -1
  133. package/dist/logger.d.cts +1 -5
  134. package/dist/logger.d.cts.map +1 -1
  135. package/dist/logger.d.mts +1 -5
  136. package/dist/logger.d.mts.map +1 -1
  137. package/dist/logger.mjs +1 -2
  138. package/dist/logger.mjs.map +1 -1
  139. package/dist/objection.cjs +10 -13
  140. package/dist/objection.cjs.map +1 -1
  141. package/dist/objection.d.cts +10 -14
  142. package/dist/objection.d.cts.map +1 -1
  143. package/dist/objection.d.mts +10 -14
  144. package/dist/objection.d.mts.map +1 -1
  145. package/dist/objection.mjs +10 -14
  146. package/dist/objection.mjs.map +1 -1
  147. package/dist/os/directory.cjs +31 -2
  148. package/dist/os/directory.cjs.map +1 -0
  149. package/dist/os/directory.d.cts +9 -2
  150. package/dist/os/directory.d.cts.map +1 -0
  151. package/dist/os/directory.d.mts +9 -2
  152. package/dist/os/directory.d.mts.map +1 -0
  153. package/dist/os/directory.mjs +25 -2
  154. package/dist/os/directory.mjs.map +1 -0
  155. package/dist/os/index.cjs +3 -3
  156. package/dist/os/index.d.cts +1 -1
  157. package/dist/os/index.d.mts +1 -1
  158. package/dist/os/index.mjs +2 -3
  159. package/dist/requestContext.cjs +10 -11
  160. package/dist/requestContext.cjs.map +1 -1
  161. package/dist/requestContext.d.cts +4 -8
  162. package/dist/requestContext.d.cts.map +1 -1
  163. package/dist/requestContext.d.mts +4 -8
  164. package/dist/requestContext.d.mts.map +1 -1
  165. package/dist/requestContext.mjs +1 -2
  166. package/dist/requestContext.mjs.map +1 -1
  167. package/dist/{chunk-CUT6urMc.cjs → rolldown-runtime-VH7oDXx4.cjs} +8 -10
  168. package/dist/timer.cjs +2 -2
  169. package/dist/timer.cjs.map +1 -1
  170. package/dist/timer.d.cts +1 -4
  171. package/dist/timer.d.cts.map +1 -1
  172. package/dist/timer.d.mts +1 -4
  173. package/dist/timer.d.mts.map +1 -1
  174. package/dist/timer.mjs +1 -1
  175. package/dist/timer.mjs.map +1 -1
  176. package/package.json +10 -8
  177. package/dist/Factory-BFVnMMCC.mjs +0 -51
  178. package/dist/Factory-BFVnMMCC.mjs.map +0 -1
  179. package/dist/Factory-BhjUOBWN.cjs +0 -57
  180. package/dist/Factory-BhjUOBWN.cjs.map +0 -1
  181. package/dist/Factory-Bx0AJXZB.d.cts +0 -147
  182. package/dist/Factory-Bx0AJXZB.d.cts.map +0 -1
  183. package/dist/Factory-C6W78ulZ.d.mts +0 -147
  184. package/dist/Factory-C6W78ulZ.d.mts.map +0 -1
  185. package/dist/KyselyFactory-BFqVIn_0.cjs +0 -246
  186. package/dist/KyselyFactory-BFqVIn_0.cjs.map +0 -1
  187. package/dist/KyselyFactory-Cc2UmOJk.d.mts +0 -228
  188. package/dist/KyselyFactory-Cc2UmOJk.d.mts.map +0 -1
  189. package/dist/KyselyFactory-DMswpwji.mjs +0 -241
  190. package/dist/KyselyFactory-DMswpwji.mjs.map +0 -1
  191. package/dist/KyselyFactory-KLeKH43i.d.cts +0 -228
  192. package/dist/KyselyFactory-KLeKH43i.d.cts.map +0 -1
  193. package/dist/ObjectionFactory-BYnPr9ZP.d.mts +0 -241
  194. package/dist/ObjectionFactory-BYnPr9ZP.d.mts.map +0 -1
  195. package/dist/ObjectionFactory-BeFBYcan.cjs +0 -272
  196. package/dist/ObjectionFactory-BeFBYcan.cjs.map +0 -1
  197. package/dist/ObjectionFactory-QCJ7u0Ql.mjs +0 -267
  198. package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +0 -1
  199. package/dist/ObjectionFactory-aMGvAKt9.d.cts +0 -241
  200. package/dist/ObjectionFactory-aMGvAKt9.d.cts.map +0 -1
  201. package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts +0 -84
  202. package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts.map +0 -1
  203. package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs +0 -101
  204. package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs.map +0 -1
  205. package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts +0 -84
  206. package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts.map +0 -1
  207. package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs +0 -95
  208. package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs.map +0 -1
  209. package/dist/PostgresMigrator-C_QQ6q35.d.mts.map +0 -1
  210. package/dist/PostgresMigrator-CeYy-eHF.d.cts.map +0 -1
  211. package/dist/PostgresMigrator-DVAY04qN.mjs +0 -166
  212. package/dist/PostgresMigrator-DVAY04qN.mjs.map +0 -1
  213. package/dist/PostgresMigrator-M9jpzOvN.cjs +0 -172
  214. package/dist/PostgresMigrator-M9jpzOvN.cjs.map +0 -1
  215. package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts +0 -79
  216. package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts.map +0 -1
  217. package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts +0 -79
  218. package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts.map +0 -1
  219. package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs +0 -123
  220. package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs.map +0 -1
  221. package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs +0 -118
  222. package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs.map +0 -1
  223. package/dist/VitestKyselyTransactionIsolator-1Saieke7.mjs +0 -67
  224. package/dist/VitestKyselyTransactionIsolator-1Saieke7.mjs.map +0 -1
  225. package/dist/VitestKyselyTransactionIsolator-BjJSXryR.cjs +0 -72
  226. package/dist/VitestKyselyTransactionIsolator-BjJSXryR.cjs.map +0 -1
  227. package/dist/VitestKyselyTransactionIsolator-CwlTo6yf.d.mts +0 -64
  228. package/dist/VitestKyselyTransactionIsolator-CwlTo6yf.d.mts.map +0 -1
  229. package/dist/VitestKyselyTransactionIsolator-DJasVuIZ.d.cts +0 -64
  230. package/dist/VitestKyselyTransactionIsolator-DJasVuIZ.d.cts.map +0 -1
  231. package/dist/VitestObjectionTransactionIsolator-B_VSWFum.mjs +0 -63
  232. package/dist/VitestObjectionTransactionIsolator-B_VSWFum.mjs.map +0 -1
  233. package/dist/VitestObjectionTransactionIsolator-CTTjvTPO.d.cts +0 -60
  234. package/dist/VitestObjectionTransactionIsolator-CTTjvTPO.d.cts.map +0 -1
  235. package/dist/VitestObjectionTransactionIsolator-CyZG6nq4.d.mts +0 -60
  236. package/dist/VitestObjectionTransactionIsolator-CyZG6nq4.d.mts.map +0 -1
  237. package/dist/VitestObjectionTransactionIsolator-DDoJTu7e.cjs +0 -68
  238. package/dist/VitestObjectionTransactionIsolator-DDoJTu7e.cjs.map +0 -1
  239. package/dist/VitestTransactionIsolator-BLaw80cx.d.mts +0 -223
  240. package/dist/VitestTransactionIsolator-BLaw80cx.d.mts.map +0 -1
  241. package/dist/VitestTransactionIsolator-CvwPecpl.mjs +0 -188
  242. package/dist/VitestTransactionIsolator-CvwPecpl.mjs.map +0 -1
  243. package/dist/VitestTransactionIsolator-DyiX-QtK.cjs +0 -206
  244. package/dist/VitestTransactionIsolator-DyiX-QtK.cjs.map +0 -1
  245. package/dist/VitestTransactionIsolator-glcxyS_R.d.cts +0 -223
  246. package/dist/VitestTransactionIsolator-glcxyS_R.d.cts.map +0 -1
  247. package/dist/directory-BxjqmtCT.mjs +0 -27
  248. package/dist/directory-BxjqmtCT.mjs.map +0 -1
  249. package/dist/directory-C6DuuNyc.d.cts +0 -13
  250. package/dist/directory-C6DuuNyc.d.cts.map +0 -1
  251. package/dist/directory-DD_xQoSh.cjs +0 -33
  252. package/dist/directory-DD_xQoSh.cjs.map +0 -1
  253. package/dist/directory-DiQ_DkaF.d.mts +0 -13
  254. package/dist/directory-DiQ_DkaF.d.mts.map +0 -1
  255. package/dist/faker-B14IEMIN.cjs +0 -304
  256. package/dist/faker-B14IEMIN.cjs.map +0 -1
  257. package/dist/faker-BGKYFoCT.mjs +0 -262
  258. package/dist/faker-BGKYFoCT.mjs.map +0 -1
  259. package/dist/faker-BSH1EMtg.d.cts +0 -166
  260. package/dist/faker-BSH1EMtg.d.cts.map +0 -1
  261. package/dist/faker-D9gz7KjY.d.mts +0 -166
  262. package/dist/faker-D9gz7KjY.d.mts.map +0 -1
@@ -1,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-CoHQ95cT.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;;;;;;;;;;EAAA,YAAA;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-CoHQ95cT.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;;;;;;;;;;EAAA,YAAA;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"}
@@ -93,7 +93,6 @@ declare abstract class PostgresMigrator {
93
93
  */
94
94
  start(): Promise<() => Promise<void>>;
95
95
  }
96
- //# sourceMappingURL=PostgresMigrator.d.ts.map
97
96
  //#endregion
98
- export { PostgresMigrator };
99
- //# sourceMappingURL=PostgresMigrator-C_QQ6q35.d.mts.map
97
+ export { PostgresMigrator as t };
98
+ //# sourceMappingURL=PostgresMigrator-CoHQ95cT.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresMigrator-CoHQ95cT.d.cts","names":[],"sources":["../src/PostgresMigrator.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBA4EsB;UAQZ;UACA;;;;;;;EADA,YAAA,aACA,gBAAe,gBAAgB;;;;;;;WAS/B,WAAW;;;;;;;;;iBAUC;;;;;;;;;iBAsCA;;;;;;;;;;;;;;;;;;;;;;;EAgCf,SAAK,cAAA"}
@@ -93,7 +93,6 @@ declare abstract class PostgresMigrator {
93
93
  */
94
94
  start(): Promise<() => Promise<void>>;
95
95
  }
96
- //# sourceMappingURL=PostgresMigrator.d.ts.map
97
96
  //#endregion
98
- export { PostgresMigrator };
99
- //# sourceMappingURL=PostgresMigrator-CeYy-eHF.d.cts.map
97
+ export { PostgresMigrator as t };
98
+ //# sourceMappingURL=PostgresMigrator-CoHQ95cT.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresMigrator-CoHQ95cT.d.mts","names":[],"sources":["../src/PostgresMigrator.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBA4EsB;UAQZ;UACA;;;;;;;EADA,YAAA,aACA,gBAAe,gBAAgB;;;;;;;WAS/B,WAAW;;;;;;;;;iBAUC;;;;;;;;;iBAsCA;;;;;;;;;;;;;;;;;;;;;;;EAgCf,SAAK,cAAA"}
@@ -1,3 +1,170 @@
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") 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 will drop the database when called.
133
+ *
134
+ * @returns Async cleanup function that drops the created database
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');
139
+ *
140
+ * // Start migrations and get cleanup function
141
+ * const cleanup = await migrator.start();
142
+ *
143
+ * try {
144
+ * // Run your tests here
145
+ * await runTests();
146
+ * } finally {
147
+ * // Always clean up
148
+ * await cleanup();
149
+ * }
150
+ * ```
151
+ */
152
+ async start() {
153
+ const { database, db } = await setupClient(this.uri);
154
+ try {
155
+ await PostgresMigrator.create(this.uri);
156
+ if (this.afterCreate) await this.afterCreate(this.uri);
157
+ await this.migrate();
158
+ logger.log(`Migrating database: ${database}`);
159
+ } finally {
160
+ await db.end();
161
+ }
162
+ return async () => {
163
+ await PostgresMigrator.drop(this.uri);
164
+ };
165
+ }
166
+ };
167
+ //#endregion
168
+ exports.PostgresMigrator = PostgresMigrator;
2
169
 
3
- exports.PostgresMigrator = require_PostgresMigrator.PostgresMigrator;
170
+ //# 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// 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,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;IAEpB,IAAI,OAAO,SAAS,SACnB,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;;;;;;;;;;;;;;;;;;;;;;;CAwBA,MAAM,QAAQ;EACb,MAAM,EAAE,UAAU,OAAO,MAAM,YAAY,KAAK,GAAG;EACnD,IAAI;GACH,MAAM,iBAAiB,OAAO,KAAK,GAAG;GACtC,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,MAAM,iBAAiB,KAAK,KAAK,GAAG;EACrC;CACD;AACD"}
@@ -1,2 +1,2 @@
1
- import { PostgresMigrator } from "./PostgresMigrator-CeYy-eHF.cjs";
1
+ import { t as PostgresMigrator } from "./PostgresMigrator-CoHQ95cT.cjs";
2
2
  export { PostgresMigrator };
@@ -1,2 +1,2 @@
1
- import { PostgresMigrator } from "./PostgresMigrator-C_QQ6q35.mjs";
1
+ import { t as PostgresMigrator } from "./PostgresMigrator-CoHQ95cT.mjs";
2
2
  export { PostgresMigrator };
@@ -1,3 +1,167 @@
1
- import { PostgresMigrator } from "./PostgresMigrator-DVAY04qN.mjs";
1
+ import pg from "pg";
2
+ //#region src/PostgresMigrator.ts
3
+ const { Client } = pg;
4
+ /**
5
+ * Creates a PostgreSQL client connected to the 'postgres' database.
6
+ * Extracts connection details from the provided URI.
7
+ *
8
+ * @param uri - PostgreSQL connection URI
9
+ * @returns Object containing the target database name and client instance
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const { database, db } = await setupClient('postgresql://user:pass@localhost:5432/mydb');
14
+ * // database = 'mydb'
15
+ * // db = Client instance connected to 'postgres' database
16
+ * ```
17
+ */
18
+ async function setupClient(uri) {
19
+ const url = new URL(uri);
20
+ const db = new Client({
21
+ user: url.username,
22
+ password: url.password,
23
+ host: url.hostname,
24
+ port: parseInt(url.port, 10),
25
+ database: "postgres"
26
+ });
27
+ let database = url.pathname.slice(1);
28
+ if (database.includes("?")) database = database.substring(0, database.indexOf("?"));
29
+ return {
30
+ database,
31
+ db
32
+ };
33
+ }
34
+ /**
35
+ * Default logger instance for migration operations.
36
+ */
37
+ const logger = console;
38
+ /**
39
+ * Abstract base class for PostgreSQL database migration utilities.
40
+ * Provides database creation, migration, and cleanup functionality for testing.
41
+ * Subclasses must implement the migrate() method to define migration logic.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * class MyMigrator extends PostgresMigrator {
46
+ * async migrate(): Promise<void> {
47
+ * // Run your migrations here
48
+ * await this.runMigrations();
49
+ * }
50
+ * }
51
+ *
52
+ * // Use in tests
53
+ * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');
54
+ * const cleanup = await migrator.start();
55
+ *
56
+ * // With afterCreate hook (e.g. run init script to create per-app users)
57
+ * import { runInitScript } from '@geekmidas/testkit/postgres';
58
+ *
59
+ * const migrator = new MyMigrator(
60
+ * 'postgresql://localhost:5432/test_db',
61
+ * async (uri) => {
62
+ * await runInitScript('docker/postgres/init.sh', uri, env);
63
+ * },
64
+ * );
65
+ * const cleanup = await migrator.start();
66
+ *
67
+ * // Run tests...
68
+ *
69
+ * // Clean up
70
+ * await cleanup();
71
+ * ```
72
+ */
73
+ var PostgresMigrator = class PostgresMigrator {
74
+ uri;
75
+ afterCreate;
76
+ /**
77
+ * Creates a new PostgresMigrator instance.
78
+ *
79
+ * @param uri - PostgreSQL connection URI
80
+ * @param afterCreate - Optional hook called after database creation but before migrations
81
+ */
82
+ constructor(uri, afterCreate) {
83
+ this.uri = uri;
84
+ this.afterCreate = afterCreate;
85
+ }
86
+ /**
87
+ * Creates a PostgreSQL database if it doesn't already exist.
88
+ * Connects to the 'postgres' database to check and create the target database.
89
+ *
90
+ * @param uri - PostgreSQL connection URI
91
+ * @returns Object indicating whether the database already existed
92
+ * @private
93
+ */
94
+ static async create(uri) {
95
+ const { database, db } = await setupClient(uri);
96
+ try {
97
+ await db.connect();
98
+ const result = await db.query(`SELECT * FROM pg_catalog.pg_database WHERE datname = '${database}'`);
99
+ if (result.rowCount === 0) try {
100
+ await db.query(`CREATE DATABASE "${database}"`);
101
+ } catch (error) {
102
+ if (error?.code === "42P04") return { alreadyExisted: true };
103
+ throw error;
104
+ }
105
+ return { alreadyExisted: result.rowCount ? result.rowCount > 0 : false };
106
+ } finally {
107
+ await db.end();
108
+ }
109
+ }
110
+ /**
111
+ * Drops a PostgreSQL database.
112
+ * Used for cleanup after tests are complete.
113
+ *
114
+ * @param uri - PostgreSQL connection URI
115
+ * @throws Error if database cannot be dropped
116
+ * @private
117
+ */
118
+ static async drop(uri) {
119
+ const { database, db } = await setupClient(uri);
120
+ try {
121
+ await db.connect();
122
+ await db.query(`DROP DATABASE "${database}"`);
123
+ } finally {
124
+ await db.end();
125
+ }
126
+ }
127
+ /**
128
+ * Starts the migration process by creating the database and running migrations.
129
+ * Returns a cleanup function that will drop the database when called.
130
+ *
131
+ * @returns Async cleanup function that drops the created database
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');
136
+ *
137
+ * // Start migrations and get cleanup function
138
+ * const cleanup = await migrator.start();
139
+ *
140
+ * try {
141
+ * // Run your tests here
142
+ * await runTests();
143
+ * } finally {
144
+ * // Always clean up
145
+ * await cleanup();
146
+ * }
147
+ * ```
148
+ */
149
+ async start() {
150
+ const { database, db } = await setupClient(this.uri);
151
+ try {
152
+ await PostgresMigrator.create(this.uri);
153
+ if (this.afterCreate) await this.afterCreate(this.uri);
154
+ await this.migrate();
155
+ logger.log(`Migrating database: ${database}`);
156
+ } finally {
157
+ await db.end();
158
+ }
159
+ return async () => {
160
+ await PostgresMigrator.drop(this.uri);
161
+ };
162
+ }
163
+ };
164
+ //#endregion
165
+ export { PostgresMigrator };
2
166
 
3
- export { PostgresMigrator };
167
+ //# sourceMappingURL=PostgresMigrator.mjs.map