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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (295) hide show
  1. package/README.md +74 -0
  2. package/dist/Factory.cjs +51 -2
  3. package/dist/Factory.cjs.map +1 -0
  4. package/dist/Factory.d.cts +143 -3
  5. package/dist/Factory.d.cts.map +1 -0
  6. package/dist/Factory.d.mts +143 -3
  7. package/dist/Factory.d.mts.map +1 -0
  8. package/dist/Factory.mjs +50 -2
  9. package/dist/Factory.mjs.map +1 -0
  10. package/dist/KyselyFactory.cjs +237 -4
  11. package/dist/KyselyFactory.cjs.map +1 -0
  12. package/dist/KyselyFactory.d.cts +224 -4
  13. package/dist/KyselyFactory.d.cts.map +1 -0
  14. package/dist/KyselyFactory.d.mts +224 -4
  15. package/dist/KyselyFactory.d.mts.map +1 -0
  16. package/dist/KyselyFactory.mjs +236 -4
  17. package/dist/KyselyFactory.mjs.map +1 -0
  18. package/dist/ObjectionFactory.cjs +265 -4
  19. package/dist/ObjectionFactory.cjs.map +1 -0
  20. package/dist/ObjectionFactory.d.cts +237 -4
  21. package/dist/ObjectionFactory.d.cts.map +1 -0
  22. package/dist/ObjectionFactory.d.mts +237 -4
  23. package/dist/ObjectionFactory.d.mts.map +1 -0
  24. package/dist/ObjectionFactory.mjs +264 -4
  25. package/dist/ObjectionFactory.mjs.map +1 -0
  26. package/dist/PostgresKyselyMigrator.cjs +94 -3
  27. package/dist/PostgresKyselyMigrator.cjs.map +1 -0
  28. package/dist/PostgresKyselyMigrator.d.cts +80 -3
  29. package/dist/PostgresKyselyMigrator.d.cts.map +1 -0
  30. package/dist/PostgresKyselyMigrator.d.mts +80 -3
  31. package/dist/PostgresKyselyMigrator.d.mts.map +1 -0
  32. package/dist/PostgresKyselyMigrator.mjs +93 -3
  33. package/dist/PostgresKyselyMigrator.mjs.map +1 -0
  34. package/dist/{PostgresMigrator-C_QQ6q35.d.mts → PostgresMigrator-CDPnnwMJ.d.cts} +11 -5
  35. package/dist/PostgresMigrator-CDPnnwMJ.d.cts.map +1 -0
  36. package/dist/{PostgresMigrator-CeYy-eHF.d.cts → PostgresMigrator-CDPnnwMJ.d.mts} +11 -5
  37. package/dist/PostgresMigrator-CDPnnwMJ.d.mts.map +1 -0
  38. package/dist/PostgresMigrator.cjs +178 -2
  39. package/dist/PostgresMigrator.cjs.map +1 -0
  40. package/dist/PostgresMigrator.d.cts +1 -1
  41. package/dist/PostgresMigrator.d.mts +1 -1
  42. package/dist/PostgresMigrator.mjs +175 -2
  43. package/dist/PostgresMigrator.mjs.map +1 -0
  44. package/dist/PostgresObjectionMigrator.cjs +118 -3
  45. package/dist/PostgresObjectionMigrator.cjs.map +1 -0
  46. package/dist/PostgresObjectionMigrator.d.cts +75 -3
  47. package/dist/PostgresObjectionMigrator.d.cts.map +1 -0
  48. package/dist/PostgresObjectionMigrator.d.mts +75 -3
  49. package/dist/PostgresObjectionMigrator.d.mts.map +1 -0
  50. package/dist/PostgresObjectionMigrator.mjs +117 -3
  51. package/dist/PostgresObjectionMigrator.mjs.map +1 -0
  52. package/dist/VitestKyselyTransactionIsolator.cjs +66 -3
  53. package/dist/VitestKyselyTransactionIsolator.cjs.map +1 -0
  54. package/dist/VitestKyselyTransactionIsolator.d.cts +60 -3
  55. package/dist/VitestKyselyTransactionIsolator.d.cts.map +1 -0
  56. package/dist/VitestKyselyTransactionIsolator.d.mts +60 -3
  57. package/dist/VitestKyselyTransactionIsolator.d.mts.map +1 -0
  58. package/dist/VitestKyselyTransactionIsolator.mjs +65 -3
  59. package/dist/VitestKyselyTransactionIsolator.mjs.map +1 -0
  60. package/dist/VitestObjectionTransactionIsolator.cjs +62 -3
  61. package/dist/VitestObjectionTransactionIsolator.cjs.map +1 -0
  62. package/dist/VitestObjectionTransactionIsolator.d.cts +56 -3
  63. package/dist/VitestObjectionTransactionIsolator.d.cts.map +1 -0
  64. package/dist/VitestObjectionTransactionIsolator.d.mts +56 -3
  65. package/dist/VitestObjectionTransactionIsolator.d.mts.map +1 -0
  66. package/dist/VitestObjectionTransactionIsolator.mjs +61 -3
  67. package/dist/VitestObjectionTransactionIsolator.mjs.map +1 -0
  68. package/dist/VitestTransactionIsolator.cjs +187 -4
  69. package/dist/VitestTransactionIsolator.cjs.map +1 -0
  70. package/dist/VitestTransactionIsolator.d.cts +219 -2
  71. package/dist/VitestTransactionIsolator.d.cts.map +1 -0
  72. package/dist/VitestTransactionIsolator.d.mts +219 -2
  73. package/dist/VitestTransactionIsolator.d.mts.map +1 -0
  74. package/dist/VitestTransactionIsolator.mjs +184 -2
  75. package/dist/VitestTransactionIsolator.mjs.map +1 -0
  76. package/dist/aws.cjs +3 -4
  77. package/dist/aws.cjs.map +1 -1
  78. package/dist/aws.d.cts +3 -8
  79. package/dist/aws.d.cts.map +1 -1
  80. package/dist/aws.d.mts +3 -8
  81. package/dist/aws.d.mts.map +1 -1
  82. package/dist/aws.mjs +1 -2
  83. package/dist/aws.mjs.map +1 -1
  84. package/dist/benchmark.cjs +2 -2
  85. package/dist/benchmark.cjs.map +1 -1
  86. package/dist/benchmark.d.cts +4 -6
  87. package/dist/benchmark.d.cts.map +1 -1
  88. package/dist/benchmark.d.mts +4 -6
  89. package/dist/benchmark.d.mts.map +1 -1
  90. package/dist/benchmark.mjs +1 -1
  91. package/dist/benchmark.mjs.map +1 -1
  92. package/dist/better-auth.cjs +31 -15
  93. package/dist/better-auth.cjs.map +1 -1
  94. package/dist/better-auth.d.cts +13142 -4
  95. package/dist/better-auth.d.cts.map +1 -1
  96. package/dist/better-auth.d.mts +13142 -4
  97. package/dist/better-auth.d.mts.map +1 -1
  98. package/dist/better-auth.mjs +29 -13
  99. package/dist/better-auth.mjs.map +1 -1
  100. package/dist/browser.cjs +127 -0
  101. package/dist/browser.cjs.map +1 -0
  102. package/dist/browser.d.cts +47 -0
  103. package/dist/browser.d.cts.map +1 -0
  104. package/dist/browser.d.mts +47 -0
  105. package/dist/browser.d.mts.map +1 -0
  106. package/dist/browser.mjs +125 -0
  107. package/dist/browser.mjs.map +1 -0
  108. package/dist/context.cjs +80 -0
  109. package/dist/context.cjs.map +1 -0
  110. package/dist/context.d.cts +55 -0
  111. package/dist/context.d.cts.map +1 -0
  112. package/dist/context.d.mts +55 -0
  113. package/dist/context.d.mts.map +1 -0
  114. package/dist/context.mjs +73 -0
  115. package/dist/context.mjs.map +1 -0
  116. package/dist/faker.cjs +262 -8
  117. package/dist/faker.cjs.map +1 -0
  118. package/dist/faker.d.cts +162 -2
  119. package/dist/faker.d.cts.map +1 -0
  120. package/dist/faker.d.mts +162 -2
  121. package/dist/faker.d.mts.map +1 -0
  122. package/dist/faker.mjs +255 -2
  123. package/dist/faker.mjs.map +1 -0
  124. package/dist/helpers.cjs +6 -5
  125. package/dist/helpers.cjs.map +1 -1
  126. package/dist/helpers.d.cts +1 -5
  127. package/dist/helpers.d.cts.map +1 -1
  128. package/dist/helpers.d.mts +1 -5
  129. package/dist/helpers.d.mts.map +1 -1
  130. package/dist/helpers.mjs +1 -2
  131. package/dist/helpers.mjs.map +1 -1
  132. package/dist/initScript.cjs +15 -15
  133. package/dist/initScript.cjs.map +1 -1
  134. package/dist/initScript.d.cts +2 -4
  135. package/dist/initScript.d.cts.map +1 -1
  136. package/dist/initScript.d.mts +2 -4
  137. package/dist/initScript.d.mts.map +1 -1
  138. package/dist/initScript.mjs +10 -12
  139. package/dist/initScript.mjs.map +1 -1
  140. package/dist/kysely.cjs +10 -13
  141. package/dist/kysely.cjs.map +1 -1
  142. package/dist/kysely.d.cts +10 -14
  143. package/dist/kysely.d.cts.map +1 -1
  144. package/dist/kysely.d.mts +10 -14
  145. package/dist/kysely.d.mts.map +1 -1
  146. package/dist/kysely.mjs +10 -14
  147. package/dist/kysely.mjs.map +1 -1
  148. package/dist/logger.cjs +3 -4
  149. package/dist/logger.cjs.map +1 -1
  150. package/dist/logger.d.cts +1 -5
  151. package/dist/logger.d.cts.map +1 -1
  152. package/dist/logger.d.mts +1 -5
  153. package/dist/logger.d.mts.map +1 -1
  154. package/dist/logger.mjs +1 -2
  155. package/dist/logger.mjs.map +1 -1
  156. package/dist/mailbox.cjs +95 -0
  157. package/dist/mailbox.cjs.map +1 -0
  158. package/dist/mailbox.d.cts +58 -0
  159. package/dist/mailbox.d.cts.map +1 -0
  160. package/dist/mailbox.d.mts +58 -0
  161. package/dist/mailbox.d.mts.map +1 -0
  162. package/dist/mailbox.mjs +92 -0
  163. package/dist/mailbox.mjs.map +1 -0
  164. package/dist/objection.cjs +10 -13
  165. package/dist/objection.cjs.map +1 -1
  166. package/dist/objection.d.cts +10 -14
  167. package/dist/objection.d.cts.map +1 -1
  168. package/dist/objection.d.mts +10 -14
  169. package/dist/objection.d.mts.map +1 -1
  170. package/dist/objection.mjs +10 -14
  171. package/dist/objection.mjs.map +1 -1
  172. package/dist/os/directory.cjs +31 -2
  173. package/dist/os/directory.cjs.map +1 -0
  174. package/dist/os/directory.d.cts +9 -2
  175. package/dist/os/directory.d.cts.map +1 -0
  176. package/dist/os/directory.d.mts +9 -2
  177. package/dist/os/directory.d.mts.map +1 -0
  178. package/dist/os/directory.mjs +25 -2
  179. package/dist/os/directory.mjs.map +1 -0
  180. package/dist/os/index.cjs +3 -3
  181. package/dist/os/index.d.cts +1 -1
  182. package/dist/os/index.d.mts +1 -1
  183. package/dist/os/index.mjs +2 -3
  184. package/dist/requestContext.cjs +10 -11
  185. package/dist/requestContext.cjs.map +1 -1
  186. package/dist/requestContext.d.cts +4 -8
  187. package/dist/requestContext.d.cts.map +1 -1
  188. package/dist/requestContext.d.mts +4 -8
  189. package/dist/requestContext.d.mts.map +1 -1
  190. package/dist/requestContext.mjs +1 -2
  191. package/dist/requestContext.mjs.map +1 -1
  192. package/dist/{chunk-CUT6urMc.cjs → rolldown-runtime-VH7oDXx4.cjs} +8 -10
  193. package/dist/timer.cjs +2 -2
  194. package/dist/timer.cjs.map +1 -1
  195. package/dist/timer.d.cts +1 -4
  196. package/dist/timer.d.cts.map +1 -1
  197. package/dist/timer.d.mts +1 -4
  198. package/dist/timer.d.mts.map +1 -1
  199. package/dist/timer.mjs +1 -1
  200. package/dist/timer.mjs.map +1 -1
  201. package/dist/transactions.cjs +123 -0
  202. package/dist/transactions.cjs.map +1 -0
  203. package/dist/transactions.d.cts +44 -0
  204. package/dist/transactions.d.cts.map +1 -0
  205. package/dist/transactions.d.mts +44 -0
  206. package/dist/transactions.d.mts.map +1 -0
  207. package/dist/transactions.mjs +118 -0
  208. package/dist/transactions.mjs.map +1 -0
  209. package/package.json +59 -16
  210. package/dist/Factory-BFVnMMCC.mjs +0 -51
  211. package/dist/Factory-BFVnMMCC.mjs.map +0 -1
  212. package/dist/Factory-BOX312yd.d.cts +0 -147
  213. package/dist/Factory-BOX312yd.d.cts.map +0 -1
  214. package/dist/Factory-BhjUOBWN.cjs +0 -57
  215. package/dist/Factory-BhjUOBWN.cjs.map +0 -1
  216. package/dist/Factory-C6W78ulZ.d.mts +0 -147
  217. package/dist/Factory-C6W78ulZ.d.mts.map +0 -1
  218. package/dist/KyselyFactory-BFqVIn_0.cjs +0 -246
  219. package/dist/KyselyFactory-BFqVIn_0.cjs.map +0 -1
  220. package/dist/KyselyFactory-Cc2UmOJk.d.mts +0 -228
  221. package/dist/KyselyFactory-Cc2UmOJk.d.mts.map +0 -1
  222. package/dist/KyselyFactory-DMswpwji.mjs +0 -241
  223. package/dist/KyselyFactory-DMswpwji.mjs.map +0 -1
  224. package/dist/KyselyFactory-Dy5zzV4B.d.cts +0 -228
  225. package/dist/KyselyFactory-Dy5zzV4B.d.cts.map +0 -1
  226. package/dist/ObjectionFactory-BYnPr9ZP.d.mts +0 -241
  227. package/dist/ObjectionFactory-BYnPr9ZP.d.mts.map +0 -1
  228. package/dist/ObjectionFactory-BeFBYcan.cjs +0 -272
  229. package/dist/ObjectionFactory-BeFBYcan.cjs.map +0 -1
  230. package/dist/ObjectionFactory-CD-WFuMJ.d.cts +0 -241
  231. package/dist/ObjectionFactory-CD-WFuMJ.d.cts.map +0 -1
  232. package/dist/ObjectionFactory-QCJ7u0Ql.mjs +0 -267
  233. package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +0 -1
  234. package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts +0 -84
  235. package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts.map +0 -1
  236. package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs +0 -101
  237. package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs.map +0 -1
  238. package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts +0 -84
  239. package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts.map +0 -1
  240. package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs +0 -95
  241. package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs.map +0 -1
  242. package/dist/PostgresMigrator-C_QQ6q35.d.mts.map +0 -1
  243. package/dist/PostgresMigrator-CeYy-eHF.d.cts.map +0 -1
  244. package/dist/PostgresMigrator-DVAY04qN.mjs +0 -166
  245. package/dist/PostgresMigrator-DVAY04qN.mjs.map +0 -1
  246. package/dist/PostgresMigrator-M9jpzOvN.cjs +0 -172
  247. package/dist/PostgresMigrator-M9jpzOvN.cjs.map +0 -1
  248. package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts +0 -79
  249. package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts.map +0 -1
  250. package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts +0 -79
  251. package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts.map +0 -1
  252. package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs +0 -123
  253. package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs.map +0 -1
  254. package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs +0 -118
  255. package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs.map +0 -1
  256. package/dist/VitestKyselyTransactionIsolator-1Saieke7.mjs +0 -67
  257. package/dist/VitestKyselyTransactionIsolator-1Saieke7.mjs.map +0 -1
  258. package/dist/VitestKyselyTransactionIsolator-BjJSXryR.cjs +0 -72
  259. package/dist/VitestKyselyTransactionIsolator-BjJSXryR.cjs.map +0 -1
  260. package/dist/VitestKyselyTransactionIsolator-CwlTo6yf.d.mts +0 -64
  261. package/dist/VitestKyselyTransactionIsolator-CwlTo6yf.d.mts.map +0 -1
  262. package/dist/VitestKyselyTransactionIsolator-DJasVuIZ.d.cts +0 -64
  263. package/dist/VitestKyselyTransactionIsolator-DJasVuIZ.d.cts.map +0 -1
  264. package/dist/VitestObjectionTransactionIsolator-B_VSWFum.mjs +0 -63
  265. package/dist/VitestObjectionTransactionIsolator-B_VSWFum.mjs.map +0 -1
  266. package/dist/VitestObjectionTransactionIsolator-CTTjvTPO.d.cts +0 -60
  267. package/dist/VitestObjectionTransactionIsolator-CTTjvTPO.d.cts.map +0 -1
  268. package/dist/VitestObjectionTransactionIsolator-CyZG6nq4.d.mts +0 -60
  269. package/dist/VitestObjectionTransactionIsolator-CyZG6nq4.d.mts.map +0 -1
  270. package/dist/VitestObjectionTransactionIsolator-DDoJTu7e.cjs +0 -68
  271. package/dist/VitestObjectionTransactionIsolator-DDoJTu7e.cjs.map +0 -1
  272. package/dist/VitestTransactionIsolator-BLaw80cx.d.mts +0 -223
  273. package/dist/VitestTransactionIsolator-BLaw80cx.d.mts.map +0 -1
  274. package/dist/VitestTransactionIsolator-CvwPecpl.mjs +0 -188
  275. package/dist/VitestTransactionIsolator-CvwPecpl.mjs.map +0 -1
  276. package/dist/VitestTransactionIsolator-DyiX-QtK.cjs +0 -206
  277. package/dist/VitestTransactionIsolator-DyiX-QtK.cjs.map +0 -1
  278. package/dist/VitestTransactionIsolator-glcxyS_R.d.cts +0 -223
  279. package/dist/VitestTransactionIsolator-glcxyS_R.d.cts.map +0 -1
  280. package/dist/directory-BxjqmtCT.mjs +0 -27
  281. package/dist/directory-BxjqmtCT.mjs.map +0 -1
  282. package/dist/directory-DD_xQoSh.cjs +0 -33
  283. package/dist/directory-DD_xQoSh.cjs.map +0 -1
  284. package/dist/directory-DGOcVlKD.d.cts +0 -13
  285. package/dist/directory-DGOcVlKD.d.cts.map +0 -1
  286. package/dist/directory-DiQ_DkaF.d.mts +0 -13
  287. package/dist/directory-DiQ_DkaF.d.mts.map +0 -1
  288. package/dist/faker-B14IEMIN.cjs +0 -304
  289. package/dist/faker-B14IEMIN.cjs.map +0 -1
  290. package/dist/faker-BGKYFoCT.mjs +0 -262
  291. package/dist/faker-BGKYFoCT.mjs.map +0 -1
  292. package/dist/faker-Cg76aFNO.d.cts +0 -166
  293. package/dist/faker-Cg76aFNO.d.cts.map +0 -1
  294. package/dist/faker-D9gz7KjY.d.mts +0 -166
  295. package/dist/faker-D9gz7KjY.d.mts.map +0 -1
@@ -1,101 +0,0 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_PostgresMigrator = require('./PostgresMigrator-M9jpzOvN.cjs');
3
- const kysely_migration = require_chunk.__toESM(require("kysely/migration"));
4
-
5
- //#region src/PostgresKyselyMigrator.ts
6
- /**
7
- * Default logger instance for migration operations.
8
- */
9
- const logger = console;
10
- /**
11
- * PostgreSQL migrator implementation for Kysely ORM.
12
- * Extends PostgresMigrator to provide Kysely-specific migration functionality.
13
- * Automatically creates test databases and applies migrations for testing environments.
14
- *
15
- * @example
16
- * ```typescript
17
- * import { FileMigrationProvider } from 'kysely';
18
- * import { PostgresKyselyMigrator } from '@geekmidas/testkit';
19
- *
20
- * // Create migration provider
21
- * const provider = new FileMigrationProvider({
22
- * fs: require('fs'),
23
- * path: require('path'),
24
- * migrationFolder: path.join(__dirname, 'migrations')
25
- * });
26
- *
27
- * // Create Kysely instance
28
- * const db = new Kysely<Database>({
29
- * dialect: new PostgresDialect({
30
- * pool: new Pool({ connectionString: uri })
31
- * })
32
- * });
33
- *
34
- * // Create and use migrator
35
- * const migrator = new PostgresKyselyMigrator({
36
- * uri: 'postgresql://localhost:5432/test_db',
37
- * db,
38
- * provider
39
- * });
40
- *
41
- * const cleanup = await migrator.start();
42
- * // Run tests...
43
- * await cleanup();
44
- *
45
- * // With afterCreate hook to create per-app users
46
- * import { runInitScript } from '@geekmidas/testkit/postgres';
47
- *
48
- * const migrator = new PostgresKyselyMigrator({
49
- * uri: 'postgresql://localhost:5432/test_db',
50
- * db,
51
- * provider,
52
- * afterCreate: async (uri) => {
53
- * await runInitScript('docker/postgres/init.sh', uri, env);
54
- * },
55
- * });
56
- * ```
57
- */
58
- var PostgresKyselyMigrator = class extends require_PostgresMigrator.PostgresMigrator {
59
- /**
60
- * Creates a new PostgresKyselyMigrator instance.
61
- *
62
- * @param options - Configuration options
63
- * @param options.uri - PostgreSQL connection URI
64
- * @param options.db - Kysely database instance
65
- * @param options.provider - Migration provider for locating migration files
66
- * @param options.afterCreate - Optional hook called after database creation but before migrations
67
- */
68
- constructor(options) {
69
- super(options.uri, options.afterCreate);
70
- this.options = options;
71
- }
72
- /**
73
- * Executes Kysely migrations to the latest version.
74
- * Implements the abstract migrate() method from PostgresMigrator.
75
- *
76
- * @throws Error if migrations fail to apply
77
- * @returns Promise that resolves when all migrations are applied
78
- */
79
- async migrate() {
80
- const migrator = new kysely_migration.Migrator({
81
- db: this.options.db,
82
- provider: this.options.provider
83
- });
84
- const migrations = await migrator.migrateToLatest();
85
- if (migrations.error) {
86
- logger.error(migrations.error, `Failed to apply migrations`);
87
- throw migrations.error;
88
- }
89
- await this.options.db.destroy();
90
- logger.log(`Applied ${migrations.results?.length} migrations successfully`);
91
- }
92
- };
93
-
94
- //#endregion
95
- Object.defineProperty(exports, 'PostgresKyselyMigrator', {
96
- enumerable: true,
97
- get: function () {
98
- return PostgresKyselyMigrator;
99
- }
100
- });
101
- //# sourceMappingURL=PostgresKyselyMigrator-BGBxjnFv.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PostgresKyselyMigrator-BGBxjnFv.cjs","names":["PostgresMigrator","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}","Migrator"],"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,cAA4CA,0CAAiB;;;;;;;;;;CAU5D,YACSC,SAMP;AACD,QAAM,QAAQ,KAAK,QAAQ,YAAY;EAP/B;CAQR;;;;;;;;CASD,MAAM,UAAyB;EAC9B,MAAM,WAAW,IAAIC,0BAAS;GAC7B,IAAI,KAAK,QAAQ;GACjB,UAAU,KAAK,QAAQ;EACvB;EACD,MAAM,aAAa,MAAM,SAAS,iBAAiB;AAEnD,MAAI,WAAW,OAAO;AACrB,UAAO,MAAM,WAAW,QAAQ,4BAA4B;AAC5D,SAAM,WAAW;EACjB;AAED,QAAM,KAAK,QAAQ,GAAG,SAAS;AAE/B,SAAO,KAAK,UAAU,WAAW,SAAS,OAAO,0BAA0B;CAC3E;AACD"}
@@ -1,84 +0,0 @@
1
- import { PostgresMigrator } from "./PostgresMigrator-C_QQ6q35.mjs";
2
- import { MigrationProvider } from "kysely/migration";
3
- import { Kysely } from "kysely";
4
-
5
- //#region src/PostgresKyselyMigrator.d.ts
6
-
7
- /**
8
- * PostgreSQL migrator implementation for Kysely ORM.
9
- * Extends PostgresMigrator to provide Kysely-specific migration functionality.
10
- * Automatically creates test databases and applies migrations for testing environments.
11
- *
12
- * @example
13
- * ```typescript
14
- * import { FileMigrationProvider } from 'kysely';
15
- * import { PostgresKyselyMigrator } from '@geekmidas/testkit';
16
- *
17
- * // Create migration provider
18
- * const provider = new FileMigrationProvider({
19
- * fs: require('fs'),
20
- * path: require('path'),
21
- * migrationFolder: path.join(__dirname, 'migrations')
22
- * });
23
- *
24
- * // Create Kysely instance
25
- * const db = new Kysely<Database>({
26
- * dialect: new PostgresDialect({
27
- * pool: new Pool({ connectionString: uri })
28
- * })
29
- * });
30
- *
31
- * // Create and use migrator
32
- * const migrator = new PostgresKyselyMigrator({
33
- * uri: 'postgresql://localhost:5432/test_db',
34
- * db,
35
- * provider
36
- * });
37
- *
38
- * const cleanup = await migrator.start();
39
- * // Run tests...
40
- * await cleanup();
41
- *
42
- * // With afterCreate hook to create per-app users
43
- * import { runInitScript } from '@geekmidas/testkit/postgres';
44
- *
45
- * const migrator = new PostgresKyselyMigrator({
46
- * uri: 'postgresql://localhost:5432/test_db',
47
- * db,
48
- * provider,
49
- * afterCreate: async (uri) => {
50
- * await runInitScript('docker/postgres/init.sh', uri, env);
51
- * },
52
- * });
53
- * ```
54
- */
55
- declare class PostgresKyselyMigrator extends PostgresMigrator {
56
- private options;
57
- /**
58
- * Creates a new PostgresKyselyMigrator instance.
59
- *
60
- * @param options - Configuration options
61
- * @param options.uri - PostgreSQL connection URI
62
- * @param options.db - Kysely database instance
63
- * @param options.provider - Migration provider for locating migration files
64
- * @param options.afterCreate - Optional hook called after database creation but before migrations
65
- */
66
- constructor(options: {
67
- uri: string;
68
- db: Kysely<any>;
69
- provider: MigrationProvider;
70
- afterCreate?: (uri: string) => Promise<void>;
71
- });
72
- /**
73
- * Executes Kysely migrations to the latest version.
74
- * Implements the abstract migrate() method from PostgresMigrator.
75
- *
76
- * @throws Error if migrations fail to apply
77
- * @returns Promise that resolves when all migrations are applied
78
- */
79
- migrate(): Promise<void>;
80
- }
81
- //# sourceMappingURL=PostgresKyselyMigrator.d.ts.map
82
- //#endregion
83
- export { PostgresKyselyMigrator };
84
- //# sourceMappingURL=PostgresKyselyMigrator-CvwXycJE.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PostgresKyselyMigrator-CvwXycJE.d.mts","names":[],"sources":["../src/PostgresKyselyMigrator.ts"],"sourcesContent":[],"mappings":";;;;;;;;AA2DA;;;;;;;AAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAA/C,sBAAA,SAA+B,gBAAA;;;;;;;;;;;;;QAarC;cACM;mCACqB;;;;;;;;;aAahB"}
@@ -1,95 +0,0 @@
1
- import { PostgresMigrator } from "./PostgresMigrator-DVAY04qN.mjs";
2
- import { Migrator } from "kysely/migration";
3
-
4
- //#region src/PostgresKyselyMigrator.ts
5
- /**
6
- * Default logger instance for migration operations.
7
- */
8
- const logger = console;
9
- /**
10
- * PostgreSQL migrator implementation for Kysely ORM.
11
- * Extends PostgresMigrator to provide Kysely-specific migration functionality.
12
- * Automatically creates test databases and applies migrations for testing environments.
13
- *
14
- * @example
15
- * ```typescript
16
- * import { FileMigrationProvider } from 'kysely';
17
- * import { PostgresKyselyMigrator } from '@geekmidas/testkit';
18
- *
19
- * // Create migration provider
20
- * const provider = new FileMigrationProvider({
21
- * fs: require('fs'),
22
- * path: require('path'),
23
- * migrationFolder: path.join(__dirname, 'migrations')
24
- * });
25
- *
26
- * // Create Kysely instance
27
- * const db = new Kysely<Database>({
28
- * dialect: new PostgresDialect({
29
- * pool: new Pool({ connectionString: uri })
30
- * })
31
- * });
32
- *
33
- * // Create and use migrator
34
- * const migrator = new PostgresKyselyMigrator({
35
- * uri: 'postgresql://localhost:5432/test_db',
36
- * db,
37
- * provider
38
- * });
39
- *
40
- * const cleanup = await migrator.start();
41
- * // Run tests...
42
- * await cleanup();
43
- *
44
- * // With afterCreate hook to create per-app users
45
- * import { runInitScript } from '@geekmidas/testkit/postgres';
46
- *
47
- * const migrator = new PostgresKyselyMigrator({
48
- * uri: 'postgresql://localhost:5432/test_db',
49
- * db,
50
- * provider,
51
- * afterCreate: async (uri) => {
52
- * await runInitScript('docker/postgres/init.sh', uri, env);
53
- * },
54
- * });
55
- * ```
56
- */
57
- var PostgresKyselyMigrator = class extends PostgresMigrator {
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 migrator = new Migrator({
80
- db: this.options.db,
81
- provider: this.options.provider
82
- });
83
- const migrations = await migrator.migrateToLatest();
84
- if (migrations.error) {
85
- logger.error(migrations.error, `Failed to apply migrations`);
86
- throw migrations.error;
87
- }
88
- await this.options.db.destroy();
89
- logger.log(`Applied ${migrations.results?.length} migrations successfully`);
90
- }
91
- };
92
-
93
- //#endregion
94
- export { PostgresKyselyMigrator };
95
- //# sourceMappingURL=PostgresKyselyMigrator-PI0QhvB1.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PostgresKyselyMigrator-PI0QhvB1.mjs","names":["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}"],"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;;;;;;;;;;CAU5D,YACSA,SAMP;AACD,QAAM,QAAQ,KAAK,QAAQ,YAAY;EAP/B;CAQR;;;;;;;;CASD,MAAM,UAAyB;EAC9B,MAAM,WAAW,IAAI,SAAS;GAC7B,IAAI,KAAK,QAAQ;GACjB,UAAU,KAAK,QAAQ;EACvB;EACD,MAAM,aAAa,MAAM,SAAS,iBAAiB;AAEnD,MAAI,WAAW,OAAO;AACrB,UAAO,MAAM,WAAW,QAAQ,4BAA4B;AAC5D,SAAM,WAAW;EACjB;AAED,QAAM,KAAK,QAAQ,GAAG,SAAS;AAE/B,SAAO,KAAK,UAAU,WAAW,SAAS,OAAO,0BAA0B;CAC3E;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"PostgresMigrator-C_QQ6q35.d.mts","names":[],"sources":["../src/PostgresMigrator.ts"],"sourcesContent":[],"mappings":";;AA4EA;;;;;;AAkGY;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAlGU,gBAAA;;;;;;;;;2DASmB;;;;;;;sBASpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAgFT,cAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"PostgresMigrator-CeYy-eHF.d.cts","names":[],"sources":["../src/PostgresMigrator.ts"],"sourcesContent":[],"mappings":";;AA4EA;;;;;;AAkGY;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAlGU,gBAAA;;;;;;;;;2DASmB;;;;;;;sBASpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAgFT,cAAA"}
@@ -1,166 +0,0 @@
1
- import pg from "pg";
2
-
3
- //#region src/PostgresMigrator.ts
4
- const { Client } = pg;
5
- /**
6
- * Creates a PostgreSQL client connected to the 'postgres' database.
7
- * Extracts connection details from the provided URI.
8
- *
9
- * @param uri - PostgreSQL connection URI
10
- * @returns Object containing the target database name and client instance
11
- *
12
- * @example
13
- * ```typescript
14
- * const { database, db } = await setupClient('postgresql://user:pass@localhost:5432/mydb');
15
- * // database = 'mydb'
16
- * // db = Client instance connected to 'postgres' database
17
- * ```
18
- */
19
- async function setupClient(uri) {
20
- const url = new URL(uri);
21
- const db = new Client({
22
- user: url.username,
23
- password: url.password,
24
- host: url.hostname,
25
- port: parseInt(url.port, 10),
26
- database: "postgres"
27
- });
28
- let database = url.pathname.slice(1);
29
- if (database.includes("?")) database = database.substring(0, database.indexOf("?"));
30
- return {
31
- database,
32
- db
33
- };
34
- }
35
- /**
36
- * Default logger instance for migration operations.
37
- */
38
- const logger = console;
39
- /**
40
- * Abstract base class for PostgreSQL database migration utilities.
41
- * Provides database creation, migration, and cleanup functionality for testing.
42
- * Subclasses must implement the migrate() method to define migration logic.
43
- *
44
- * @example
45
- * ```typescript
46
- * class MyMigrator extends PostgresMigrator {
47
- * async migrate(): Promise<void> {
48
- * // Run your migrations here
49
- * await this.runMigrations();
50
- * }
51
- * }
52
- *
53
- * // Use in tests
54
- * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');
55
- * const cleanup = await migrator.start();
56
- *
57
- * // With afterCreate hook (e.g. run init script to create per-app users)
58
- * import { runInitScript } from '@geekmidas/testkit/postgres';
59
- *
60
- * const migrator = new MyMigrator(
61
- * 'postgresql://localhost:5432/test_db',
62
- * async (uri) => {
63
- * await runInitScript('docker/postgres/init.sh', uri, env);
64
- * },
65
- * );
66
- * const cleanup = await migrator.start();
67
- *
68
- * // Run tests...
69
- *
70
- * // Clean up
71
- * await cleanup();
72
- * ```
73
- */
74
- var PostgresMigrator = class PostgresMigrator {
75
- /**
76
- * Creates a new PostgresMigrator instance.
77
- *
78
- * @param uri - PostgreSQL connection URI
79
- * @param afterCreate - Optional hook called after database creation but before migrations
80
- */
81
- constructor(uri, afterCreate) {
82
- this.uri = uri;
83
- this.afterCreate = afterCreate;
84
- }
85
- /**
86
- * Creates a PostgreSQL database if it doesn't already exist.
87
- * Connects to the 'postgres' database to check and create the target database.
88
- *
89
- * @param uri - PostgreSQL connection URI
90
- * @returns Object indicating whether the database already existed
91
- * @private
92
- */
93
- static async create(uri) {
94
- const { database, db } = await setupClient(uri);
95
- try {
96
- await db.connect();
97
- const result = await db.query(`SELECT * FROM pg_catalog.pg_database WHERE datname = '${database}'`);
98
- if (result.rowCount === 0) try {
99
- await db.query(`CREATE DATABASE "${database}"`);
100
- } catch (error) {
101
- if (error?.code === "42P04") return { alreadyExisted: true };
102
- throw error;
103
- }
104
- return { alreadyExisted: result.rowCount ? result.rowCount > 0 : false };
105
- } finally {
106
- await db.end();
107
- }
108
- }
109
- /**
110
- * Drops a PostgreSQL database.
111
- * Used for cleanup after tests are complete.
112
- *
113
- * @param uri - PostgreSQL connection URI
114
- * @throws Error if database cannot be dropped
115
- * @private
116
- */
117
- static async drop(uri) {
118
- const { database, db } = await setupClient(uri);
119
- try {
120
- await db.connect();
121
- await db.query(`DROP DATABASE "${database}"`);
122
- } finally {
123
- await db.end();
124
- }
125
- }
126
- /**
127
- * Starts the migration process by creating the database and running migrations.
128
- * Returns a cleanup function that will drop the database when called.
129
- *
130
- * @returns Async cleanup function that drops the created database
131
- *
132
- * @example
133
- * ```typescript
134
- * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');
135
- *
136
- * // Start migrations and get cleanup function
137
- * const cleanup = await migrator.start();
138
- *
139
- * try {
140
- * // Run your tests here
141
- * await runTests();
142
- * } finally {
143
- * // Always clean up
144
- * await cleanup();
145
- * }
146
- * ```
147
- */
148
- async start() {
149
- const { database, db } = await setupClient(this.uri);
150
- try {
151
- await PostgresMigrator.create(this.uri);
152
- if (this.afterCreate) await this.afterCreate(this.uri);
153
- await this.migrate();
154
- logger.log(`Migrating database: ${database}`);
155
- } finally {
156
- await db.end();
157
- }
158
- return async () => {
159
- await PostgresMigrator.drop(this.uri);
160
- };
161
- }
162
- };
163
-
164
- //#endregion
165
- export { PostgresMigrator };
166
- //# sourceMappingURL=PostgresMigrator-DVAY04qN.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PostgresMigrator-DVAY04qN.mjs","names":["uri: string","afterCreate?: (uri: string) => Promise<void>","error: any"],"sources":["../src/PostgresMigrator.ts"],"sourcesContent":["import pg from 'pg';\n\nconst { Client } = pg;\n\n/**\n * Creates a PostgreSQL client connected to the 'postgres' database.\n * Extracts connection details from the provided URI.\n *\n * @param uri - PostgreSQL connection URI\n * @returns Object containing the target database name and client instance\n *\n * @example\n * ```typescript\n * const { database, db } = await setupClient('postgresql://user:pass@localhost:5432/mydb');\n * // database = 'mydb'\n * // db = Client instance connected to 'postgres' database\n * ```\n */\nasync function setupClient(uri: string) {\n\tconst url = new URL(uri);\n\n\tconst db = new Client({\n\t\tuser: url.username,\n\t\tpassword: url.password,\n\t\thost: url.hostname,\n\t\tport: parseInt(url.port, 10),\n\t\tdatabase: 'postgres',\n\t});\n\n\tlet database = url.pathname.slice(1);\n\tif (database.includes('?')) {\n\t\tdatabase = database.substring(0, database.indexOf('?'));\n\t}\n\treturn { database, db };\n}\n\n/**\n * Default logger instance for migration operations.\n */\nconst logger = console;\n\n/**\n * Abstract base class for PostgreSQL database migration utilities.\n * Provides database creation, migration, and cleanup functionality for testing.\n * Subclasses must implement the migrate() method to define migration logic.\n *\n * @example\n * ```typescript\n * class MyMigrator extends PostgresMigrator {\n * async migrate(): Promise<void> {\n * // Run your migrations here\n * await this.runMigrations();\n * }\n * }\n *\n * // Use in tests\n * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');\n * const cleanup = await migrator.start();\n *\n * // With afterCreate hook (e.g. run init script to create per-app users)\n * import { runInitScript } from '@geekmidas/testkit/postgres';\n *\n * const migrator = new MyMigrator(\n * 'postgresql://localhost:5432/test_db',\n * async (uri) => {\n * await runInitScript('docker/postgres/init.sh', uri, env);\n * },\n * );\n * const cleanup = await migrator.start();\n *\n * // Run tests...\n *\n * // Clean up\n * await cleanup();\n * ```\n */\nexport abstract class PostgresMigrator {\n\t/**\n\t * Creates a new PostgresMigrator instance.\n\t *\n\t * @param uri - PostgreSQL connection URI\n\t * @param afterCreate - Optional hook called after database creation but before migrations\n\t */\n\tconstructor(\n\t\tprivate uri: string,\n\t\tprivate afterCreate?: (uri: string) => Promise<void>,\n\t) {}\n\n\t/**\n\t * Abstract method to be implemented by subclasses.\n\t * Should contain the migration logic for setting up database schema.\n\t *\n\t * @returns Promise that resolves when migrations are complete\n\t */\n\tabstract migrate(): Promise<void>;\n\n\t/**\n\t * Creates a PostgreSQL database if it doesn't already exist.\n\t * Connects to the 'postgres' database to check and create the target database.\n\t *\n\t * @param uri - PostgreSQL connection URI\n\t * @returns Object indicating whether the database already existed\n\t * @private\n\t */\n\tprivate static async create(\n\t\turi: string,\n\t): Promise<{ alreadyExisted: boolean }> {\n\t\tconst { database, db } = await setupClient(uri);\n\t\ttry {\n\t\t\tawait db.connect();\n\t\t\tconst result = await db.query(\n\t\t\t\t`SELECT * FROM pg_catalog.pg_database WHERE datname = '${database}'`,\n\t\t\t);\n\n\t\t\tif (result.rowCount === 0) {\n\t\t\t\ttry {\n\t\t\t\t\tawait db.query(`CREATE DATABASE \"${database}\"`);\n\t\t\t\t} catch (error: any) {\n\t\t\t\t\t// 42P04 = duplicate_database — another process created it between our check and create\n\t\t\t\t\tif (error?.code === '42P04') {\n\t\t\t\t\t\treturn { alreadyExisted: true };\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\talreadyExisted: result.rowCount ? result.rowCount > 0 : false,\n\t\t\t};\n\t\t} finally {\n\t\t\tawait db.end();\n\t\t}\n\t}\n\n\t/**\n\t * Drops a PostgreSQL database.\n\t * Used for cleanup after tests are complete.\n\t *\n\t * @param uri - PostgreSQL connection URI\n\t * @throws Error if database cannot be dropped\n\t * @private\n\t */\n\tprivate static async drop(uri: string): Promise<void> {\n\t\tconst { database, db } = await setupClient(uri);\n\t\ttry {\n\t\t\tawait db.connect();\n\t\t\tawait db.query(`DROP DATABASE \"${database}\"`);\n\t\t} finally {\n\t\t\tawait db.end();\n\t\t}\n\t}\n\n\t/**\n\t * Starts the migration process by creating the database and running migrations.\n\t * Returns a cleanup function that will drop the database when called.\n\t *\n\t * @returns Async cleanup function that drops the created database\n\t *\n\t * @example\n\t * ```typescript\n\t * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');\n\t *\n\t * // Start migrations and get cleanup function\n\t * const cleanup = await migrator.start();\n\t *\n\t * try {\n\t * // Run your tests here\n\t * await runTests();\n\t * } finally {\n\t * // Always clean up\n\t * await cleanup();\n\t * }\n\t * ```\n\t */\n\tasync start() {\n\t\tconst { database, db } = await setupClient(this.uri);\n\t\ttry {\n\t\t\tawait PostgresMigrator.create(this.uri);\n\t\t\tif (this.afterCreate) {\n\t\t\t\tawait this.afterCreate(this.uri);\n\t\t\t}\n\t\t\tawait this.migrate();\n\t\t\tlogger.log(`Migrating database: ${database}`);\n\t\t\t// Example: await db.query('CREATE TABLE example (id SERIAL PRIMARY KEY)');\n\t\t} finally {\n\t\t\tawait db.end();\n\t\t}\n\n\t\treturn async () => {\n\t\t\tawait PostgresMigrator.drop(this.uri);\n\t\t};\n\t}\n}\n"],"mappings":";;;AAEA,MAAM,EAAE,QAAQ,GAAG;;;;;;;;;;;;;;;AAgBnB,eAAe,YAAYA,KAAa;CACvC,MAAM,MAAM,IAAI,IAAI;CAEpB,MAAM,KAAK,IAAI,OAAO;EACrB,MAAM,IAAI;EACV,UAAU,IAAI;EACd,MAAM,IAAI;EACV,MAAM,SAAS,IAAI,MAAM,GAAG;EAC5B,UAAU;CACV;CAED,IAAI,WAAW,IAAI,SAAS,MAAM,EAAE;AACpC,KAAI,SAAS,SAAS,IAAI,CACzB,YAAW,SAAS,UAAU,GAAG,SAAS,QAAQ,IAAI,CAAC;AAExD,QAAO;EAAE;EAAU;CAAI;AACvB;;;;AAKD,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCf,IAAsB,mBAAtB,MAAsB,iBAAiB;;;;;;;CAOtC,YACSA,KACAC,aACP;EAFO;EACA;CACL;;;;;;;;;CAkBJ,aAAqB,OACpBD,KACuC;EACvC,MAAM,EAAE,UAAU,IAAI,GAAG,MAAM,YAAY,IAAI;AAC/C,MAAI;AACH,SAAM,GAAG,SAAS;GAClB,MAAM,SAAS,MAAM,GAAG,OACtB,wDAAwD,SAAS,GAClE;AAED,OAAI,OAAO,aAAa,EACvB,KAAI;AACH,UAAM,GAAG,OAAO,mBAAmB,SAAS,GAAG;GAC/C,SAAQE,OAAY;AAEpB,QAAI,OAAO,SAAS,QACnB,QAAO,EAAE,gBAAgB,KAAM;AAEhC,UAAM;GACN;AAGF,UAAO,EACN,gBAAgB,OAAO,WAAW,OAAO,WAAW,IAAI,MACxD;EACD,UAAS;AACT,SAAM,GAAG,KAAK;EACd;CACD;;;;;;;;;CAUD,aAAqB,KAAKF,KAA4B;EACrD,MAAM,EAAE,UAAU,IAAI,GAAG,MAAM,YAAY,IAAI;AAC/C,MAAI;AACH,SAAM,GAAG,SAAS;AAClB,SAAM,GAAG,OAAO,iBAAiB,SAAS,GAAG;EAC7C,UAAS;AACT,SAAM,GAAG,KAAK;EACd;CACD;;;;;;;;;;;;;;;;;;;;;;;CAwBD,MAAM,QAAQ;EACb,MAAM,EAAE,UAAU,IAAI,GAAG,MAAM,YAAY,KAAK,IAAI;AACpD,MAAI;AACH,SAAM,iBAAiB,OAAO,KAAK,IAAI;AACvC,OAAI,KAAK,YACR,OAAM,KAAK,YAAY,KAAK,IAAI;AAEjC,SAAM,KAAK,SAAS;AACpB,UAAO,KAAK,sBAAsB,SAAS,EAAE;EAE7C,UAAS;AACT,SAAM,GAAG,KAAK;EACd;AAED,SAAO,YAAY;AAClB,SAAM,iBAAiB,KAAK,KAAK,IAAI;EACrC;CACD;AACD"}
@@ -1,172 +0,0 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const pg = require_chunk.__toESM(require("pg"));
3
-
4
- //#region src/PostgresMigrator.ts
5
- const { Client } = pg.default;
6
- /**
7
- * Creates a PostgreSQL client connected to the 'postgres' database.
8
- * Extracts connection details from the provided URI.
9
- *
10
- * @param uri - PostgreSQL connection URI
11
- * @returns Object containing the target database name and client instance
12
- *
13
- * @example
14
- * ```typescript
15
- * const { database, db } = await setupClient('postgresql://user:pass@localhost:5432/mydb');
16
- * // database = 'mydb'
17
- * // db = Client instance connected to 'postgres' database
18
- * ```
19
- */
20
- async function setupClient(uri) {
21
- const url = new URL(uri);
22
- const db = new Client({
23
- user: url.username,
24
- password: url.password,
25
- host: url.hostname,
26
- port: parseInt(url.port, 10),
27
- database: "postgres"
28
- });
29
- let database = url.pathname.slice(1);
30
- if (database.includes("?")) database = database.substring(0, database.indexOf("?"));
31
- return {
32
- database,
33
- db
34
- };
35
- }
36
- /**
37
- * Default logger instance for migration operations.
38
- */
39
- const logger = console;
40
- /**
41
- * Abstract base class for PostgreSQL database migration utilities.
42
- * Provides database creation, migration, and cleanup functionality for testing.
43
- * Subclasses must implement the migrate() method to define migration logic.
44
- *
45
- * @example
46
- * ```typescript
47
- * class MyMigrator extends PostgresMigrator {
48
- * async migrate(): Promise<void> {
49
- * // Run your migrations here
50
- * await this.runMigrations();
51
- * }
52
- * }
53
- *
54
- * // Use in tests
55
- * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');
56
- * const cleanup = await migrator.start();
57
- *
58
- * // With afterCreate hook (e.g. run init script to create per-app users)
59
- * import { runInitScript } from '@geekmidas/testkit/postgres';
60
- *
61
- * const migrator = new MyMigrator(
62
- * 'postgresql://localhost:5432/test_db',
63
- * async (uri) => {
64
- * await runInitScript('docker/postgres/init.sh', uri, env);
65
- * },
66
- * );
67
- * const cleanup = await migrator.start();
68
- *
69
- * // Run tests...
70
- *
71
- * // Clean up
72
- * await cleanup();
73
- * ```
74
- */
75
- var PostgresMigrator = class PostgresMigrator {
76
- /**
77
- * Creates a new PostgresMigrator instance.
78
- *
79
- * @param uri - PostgreSQL connection URI
80
- * @param afterCreate - Optional hook called after database creation but before migrations
81
- */
82
- constructor(uri, afterCreate) {
83
- this.uri = uri;
84
- this.afterCreate = afterCreate;
85
- }
86
- /**
87
- * Creates a PostgreSQL database if it doesn't already exist.
88
- * Connects to the 'postgres' database to check and create the target database.
89
- *
90
- * @param uri - PostgreSQL connection URI
91
- * @returns Object indicating whether the database already existed
92
- * @private
93
- */
94
- static async create(uri) {
95
- const { database, db } = await setupClient(uri);
96
- try {
97
- await db.connect();
98
- const result = await db.query(`SELECT * FROM pg_catalog.pg_database WHERE datname = '${database}'`);
99
- if (result.rowCount === 0) try {
100
- await db.query(`CREATE DATABASE "${database}"`);
101
- } catch (error) {
102
- if (error?.code === "42P04") return { alreadyExisted: true };
103
- throw error;
104
- }
105
- return { alreadyExisted: result.rowCount ? result.rowCount > 0 : false };
106
- } finally {
107
- await db.end();
108
- }
109
- }
110
- /**
111
- * Drops a PostgreSQL database.
112
- * Used for cleanup after tests are complete.
113
- *
114
- * @param uri - PostgreSQL connection URI
115
- * @throws Error if database cannot be dropped
116
- * @private
117
- */
118
- static async drop(uri) {
119
- const { database, db } = await setupClient(uri);
120
- try {
121
- await db.connect();
122
- await db.query(`DROP DATABASE "${database}"`);
123
- } finally {
124
- await db.end();
125
- }
126
- }
127
- /**
128
- * Starts the migration process by creating the database and running migrations.
129
- * Returns a cleanup function that will drop the database when called.
130
- *
131
- * @returns Async cleanup function that drops the created database
132
- *
133
- * @example
134
- * ```typescript
135
- * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');
136
- *
137
- * // Start migrations and get cleanup function
138
- * const cleanup = await migrator.start();
139
- *
140
- * try {
141
- * // Run your tests here
142
- * await runTests();
143
- * } finally {
144
- * // Always clean up
145
- * await cleanup();
146
- * }
147
- * ```
148
- */
149
- async start() {
150
- const { database, db } = await setupClient(this.uri);
151
- try {
152
- await PostgresMigrator.create(this.uri);
153
- if (this.afterCreate) await this.afterCreate(this.uri);
154
- await this.migrate();
155
- logger.log(`Migrating database: ${database}`);
156
- } finally {
157
- await db.end();
158
- }
159
- return async () => {
160
- await PostgresMigrator.drop(this.uri);
161
- };
162
- }
163
- };
164
-
165
- //#endregion
166
- Object.defineProperty(exports, 'PostgresMigrator', {
167
- enumerable: true,
168
- get: function () {
169
- return PostgresMigrator;
170
- }
171
- });
172
- //# sourceMappingURL=PostgresMigrator-M9jpzOvN.cjs.map