@geekmidas/testkit 10.0.0-alpha.98 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (337) hide show
  1. package/CHANGELOG.md +160 -0
  2. package/README.md +0 -74
  3. package/dist/Factory-BFVnMMCC.mjs +51 -0
  4. package/dist/Factory-BFVnMMCC.mjs.map +1 -0
  5. package/dist/Factory-BOX312yd.d.cts +147 -0
  6. package/dist/Factory-BOX312yd.d.cts.map +1 -0
  7. package/dist/Factory-BhjUOBWN.cjs +57 -0
  8. package/dist/Factory-BhjUOBWN.cjs.map +1 -0
  9. package/dist/Factory-SFupxRC2.d.mts +147 -0
  10. package/dist/Factory-SFupxRC2.d.mts.map +1 -0
  11. package/dist/Factory.cjs +2 -51
  12. package/dist/Factory.d.cts +3 -143
  13. package/dist/Factory.d.mts +3 -143
  14. package/dist/Factory.mjs +2 -50
  15. package/dist/KyselyFactory-BFqVIn_0.cjs +246 -0
  16. package/dist/KyselyFactory-BFqVIn_0.cjs.map +1 -0
  17. package/dist/KyselyFactory-DMswpwji.mjs +241 -0
  18. package/dist/KyselyFactory-DMswpwji.mjs.map +1 -0
  19. package/dist/KyselyFactory-Dy5zzV4B.d.cts +228 -0
  20. package/dist/KyselyFactory-Dy5zzV4B.d.cts.map +1 -0
  21. package/dist/KyselyFactory-vAxYodck.d.mts +228 -0
  22. package/dist/KyselyFactory-vAxYodck.d.mts.map +1 -0
  23. package/dist/KyselyFactory.cjs +4 -237
  24. package/dist/KyselyFactory.d.cts +4 -224
  25. package/dist/KyselyFactory.d.mts +4 -224
  26. package/dist/KyselyFactory.mjs +4 -236
  27. package/dist/ObjectionFactory-BWjB49-i.d.mts +241 -0
  28. package/dist/ObjectionFactory-BWjB49-i.d.mts.map +1 -0
  29. package/dist/ObjectionFactory-BeFBYcan.cjs +272 -0
  30. package/dist/ObjectionFactory-BeFBYcan.cjs.map +1 -0
  31. package/dist/ObjectionFactory-CD-WFuMJ.d.cts +241 -0
  32. package/dist/ObjectionFactory-CD-WFuMJ.d.cts.map +1 -0
  33. package/dist/ObjectionFactory-QCJ7u0Ql.mjs +267 -0
  34. package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +1 -0
  35. package/dist/ObjectionFactory.cjs +4 -265
  36. package/dist/ObjectionFactory.d.cts +4 -237
  37. package/dist/ObjectionFactory.d.mts +4 -237
  38. package/dist/ObjectionFactory.mjs +4 -264
  39. package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts +84 -0
  40. package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts.map +1 -0
  41. package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs +101 -0
  42. package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs.map +1 -0
  43. package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts +84 -0
  44. package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts.map +1 -0
  45. package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs +95 -0
  46. package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs.map +1 -0
  47. package/dist/PostgresKyselyMigrator.cjs +3 -94
  48. package/dist/PostgresKyselyMigrator.d.cts +3 -80
  49. package/dist/PostgresKyselyMigrator.d.mts +3 -80
  50. package/dist/PostgresKyselyMigrator.mjs +3 -93
  51. package/dist/{PostgresMigrator-CDPnnwMJ.d.cts → PostgresMigrator-C_QQ6q35.d.mts} +5 -11
  52. package/dist/PostgresMigrator-C_QQ6q35.d.mts.map +1 -0
  53. package/dist/{PostgresMigrator-CDPnnwMJ.d.mts → PostgresMigrator-CeYy-eHF.d.cts} +5 -11
  54. package/dist/PostgresMigrator-CeYy-eHF.d.cts.map +1 -0
  55. package/dist/PostgresMigrator-DVAY04qN.mjs +166 -0
  56. package/dist/PostgresMigrator-DVAY04qN.mjs.map +1 -0
  57. package/dist/PostgresMigrator-M9jpzOvN.cjs +172 -0
  58. package/dist/PostgresMigrator-M9jpzOvN.cjs.map +1 -0
  59. package/dist/PostgresMigrator.cjs +2 -178
  60. package/dist/PostgresMigrator.d.cts +1 -1
  61. package/dist/PostgresMigrator.d.mts +1 -1
  62. package/dist/PostgresMigrator.mjs +2 -175
  63. package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts +79 -0
  64. package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts.map +1 -0
  65. package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts +79 -0
  66. package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts.map +1 -0
  67. package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs +123 -0
  68. package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs.map +1 -0
  69. package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs +118 -0
  70. package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs.map +1 -0
  71. package/dist/PostgresObjectionMigrator.cjs +3 -118
  72. package/dist/PostgresObjectionMigrator.d.cts +3 -75
  73. package/dist/PostgresObjectionMigrator.d.mts +3 -75
  74. package/dist/PostgresObjectionMigrator.mjs +3 -117
  75. package/dist/VitestKyselyTransactionIsolator-0CqOsuc9.cjs +65 -0
  76. package/dist/VitestKyselyTransactionIsolator-0CqOsuc9.cjs.map +1 -0
  77. package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts +59 -0
  78. package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts.map +1 -0
  79. package/dist/VitestKyselyTransactionIsolator-CfSMOFlN.mjs +60 -0
  80. package/dist/VitestKyselyTransactionIsolator-CfSMOFlN.mjs.map +1 -0
  81. package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts +59 -0
  82. package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts.map +1 -0
  83. package/dist/VitestKyselyTransactionIsolator.cjs +3 -66
  84. package/dist/VitestKyselyTransactionIsolator.d.cts +3 -60
  85. package/dist/VitestKyselyTransactionIsolator.d.mts +3 -60
  86. package/dist/VitestKyselyTransactionIsolator.mjs +3 -65
  87. package/dist/VitestObjectionTransactionIsolator-B5J9jjKq.cjs +68 -0
  88. package/dist/VitestObjectionTransactionIsolator-B5J9jjKq.cjs.map +1 -0
  89. package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts +60 -0
  90. package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts.map +1 -0
  91. package/dist/VitestObjectionTransactionIsolator-CNo40EdC.mjs +63 -0
  92. package/dist/VitestObjectionTransactionIsolator-CNo40EdC.mjs.map +1 -0
  93. package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts +60 -0
  94. package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts.map +1 -0
  95. package/dist/VitestObjectionTransactionIsolator.cjs +3 -62
  96. package/dist/VitestObjectionTransactionIsolator.d.cts +3 -56
  97. package/dist/VitestObjectionTransactionIsolator.d.mts +3 -56
  98. package/dist/VitestObjectionTransactionIsolator.mjs +3 -61
  99. package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts +207 -0
  100. package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts.map +1 -0
  101. package/dist/VitestTransactionIsolator-CSroc7Df.d.cts +207 -0
  102. package/dist/VitestTransactionIsolator-CSroc7Df.d.cts.map +1 -0
  103. package/dist/VitestTransactionIsolator-CtZaOUjH.cjs +193 -0
  104. package/dist/VitestTransactionIsolator-CtZaOUjH.cjs.map +1 -0
  105. package/dist/VitestTransactionIsolator-D6ZxLWys.mjs +175 -0
  106. package/dist/VitestTransactionIsolator-D6ZxLWys.mjs.map +1 -0
  107. package/dist/VitestTransactionIsolator.cjs +4 -187
  108. package/dist/VitestTransactionIsolator.d.cts +2 -219
  109. package/dist/VitestTransactionIsolator.d.mts +2 -219
  110. package/dist/VitestTransactionIsolator.mjs +2 -184
  111. package/dist/aws.cjs +4 -3
  112. package/dist/aws.cjs.map +1 -1
  113. package/dist/aws.d.cts +8 -3
  114. package/dist/aws.d.cts.map +1 -1
  115. package/dist/aws.d.mts +8 -3
  116. package/dist/aws.d.mts.map +1 -1
  117. package/dist/aws.mjs +2 -1
  118. package/dist/aws.mjs.map +1 -1
  119. package/dist/benchmark.cjs +2 -2
  120. package/dist/benchmark.cjs.map +1 -1
  121. package/dist/benchmark.d.cts +6 -4
  122. package/dist/benchmark.d.cts.map +1 -1
  123. package/dist/benchmark.d.mts +6 -4
  124. package/dist/benchmark.d.mts.map +1 -1
  125. package/dist/benchmark.mjs +1 -1
  126. package/dist/benchmark.mjs.map +1 -1
  127. package/dist/better-auth.cjs +15 -31
  128. package/dist/better-auth.cjs.map +1 -1
  129. package/dist/better-auth.d.cts +4 -13142
  130. package/dist/better-auth.d.cts.map +1 -1
  131. package/dist/better-auth.d.mts +4 -13142
  132. package/dist/better-auth.d.mts.map +1 -1
  133. package/dist/better-auth.mjs +13 -29
  134. package/dist/better-auth.mjs.map +1 -1
  135. package/dist/{rolldown-runtime-VH7oDXx4.cjs → chunk-CUT6urMc.cjs} +10 -8
  136. package/dist/directory-Bpz5c5pj.d.cts +13 -0
  137. package/dist/directory-Bpz5c5pj.d.cts.map +1 -0
  138. package/dist/directory-BxjqmtCT.mjs +27 -0
  139. package/dist/directory-BxjqmtCT.mjs.map +1 -0
  140. package/dist/directory-CVrfTq1I.d.mts +13 -0
  141. package/dist/directory-CVrfTq1I.d.mts.map +1 -0
  142. package/dist/directory-DD_xQoSh.cjs +33 -0
  143. package/dist/directory-DD_xQoSh.cjs.map +1 -0
  144. package/dist/faker-B14IEMIN.cjs +304 -0
  145. package/dist/faker-B14IEMIN.cjs.map +1 -0
  146. package/dist/faker-BGKYFoCT.mjs +262 -0
  147. package/dist/faker-BGKYFoCT.mjs.map +1 -0
  148. package/dist/faker-Cg76aFNO.d.cts +166 -0
  149. package/dist/faker-Cg76aFNO.d.cts.map +1 -0
  150. package/dist/faker-DHh7xs4u.d.mts +166 -0
  151. package/dist/faker-DHh7xs4u.d.mts.map +1 -0
  152. package/dist/faker.cjs +8 -313
  153. package/dist/faker.d.cts +2 -169
  154. package/dist/faker.d.mts +2 -169
  155. package/dist/faker.mjs +2 -305
  156. package/dist/helpers.cjs +5 -6
  157. package/dist/helpers.cjs.map +1 -1
  158. package/dist/helpers.d.cts +5 -1
  159. package/dist/helpers.d.cts.map +1 -1
  160. package/dist/helpers.d.mts +5 -1
  161. package/dist/helpers.d.mts.map +1 -1
  162. package/dist/helpers.mjs +2 -1
  163. package/dist/helpers.mjs.map +1 -1
  164. package/dist/initScript.cjs +15 -15
  165. package/dist/initScript.cjs.map +1 -1
  166. package/dist/initScript.d.cts +4 -2
  167. package/dist/initScript.d.cts.map +1 -1
  168. package/dist/initScript.d.mts +4 -2
  169. package/dist/initScript.d.mts.map +1 -1
  170. package/dist/initScript.mjs +12 -10
  171. package/dist/initScript.mjs.map +1 -1
  172. package/dist/kysely.cjs +13 -10
  173. package/dist/kysely.cjs.map +1 -1
  174. package/dist/kysely.d.cts +14 -10
  175. package/dist/kysely.d.cts.map +1 -1
  176. package/dist/kysely.d.mts +14 -10
  177. package/dist/kysely.d.mts.map +1 -1
  178. package/dist/kysely.mjs +14 -10
  179. package/dist/kysely.mjs.map +1 -1
  180. package/dist/logger.cjs +4 -3
  181. package/dist/logger.cjs.map +1 -1
  182. package/dist/logger.d.cts +5 -1
  183. package/dist/logger.d.cts.map +1 -1
  184. package/dist/logger.d.mts +5 -1
  185. package/dist/logger.d.mts.map +1 -1
  186. package/dist/logger.mjs +2 -1
  187. package/dist/logger.mjs.map +1 -1
  188. package/dist/objection.cjs +13 -10
  189. package/dist/objection.cjs.map +1 -1
  190. package/dist/objection.d.cts +14 -10
  191. package/dist/objection.d.cts.map +1 -1
  192. package/dist/objection.d.mts +14 -10
  193. package/dist/objection.d.mts.map +1 -1
  194. package/dist/objection.mjs +14 -10
  195. package/dist/objection.mjs.map +1 -1
  196. package/dist/os/directory.cjs +2 -31
  197. package/dist/os/directory.d.cts +2 -9
  198. package/dist/os/directory.d.mts +2 -9
  199. package/dist/os/directory.mjs +2 -25
  200. package/dist/os/index.cjs +3 -3
  201. package/dist/os/index.d.cts +1 -1
  202. package/dist/os/index.d.mts +1 -1
  203. package/dist/os/index.mjs +3 -2
  204. package/dist/requestContext.cjs +11 -10
  205. package/dist/requestContext.cjs.map +1 -1
  206. package/dist/requestContext.d.cts +9 -5
  207. package/dist/requestContext.d.cts.map +1 -1
  208. package/dist/requestContext.d.mts +9 -5
  209. package/dist/requestContext.d.mts.map +1 -1
  210. package/dist/requestContext.mjs +3 -2
  211. package/dist/requestContext.mjs.map +1 -1
  212. package/dist/timer.cjs +2 -2
  213. package/dist/timer.cjs.map +1 -1
  214. package/dist/timer.d.cts +4 -1
  215. package/dist/timer.d.cts.map +1 -1
  216. package/dist/timer.d.mts +4 -1
  217. package/dist/timer.d.mts.map +1 -1
  218. package/dist/timer.mjs +1 -1
  219. package/dist/timer.mjs.map +1 -1
  220. package/package.json +25 -65
  221. package/src/Factory.ts +174 -0
  222. package/src/KyselyFactory.ts +391 -0
  223. package/src/ObjectionFactory.ts +412 -0
  224. package/src/PostgresKyselyMigrator.ts +104 -0
  225. package/src/PostgresMigrator.ts +193 -0
  226. package/src/PostgresObjectionMigrator.ts +138 -0
  227. package/src/VitestKyselyTransactionIsolator.ts +72 -0
  228. package/src/VitestObjectionTransactionIsolator.ts +75 -0
  229. package/src/VitestTransactionIsolator.ts +348 -0
  230. package/src/__tests__/Factory.spec.ts +178 -0
  231. package/src/__tests__/KyselyFactory.spec.ts +458 -0
  232. package/src/__tests__/ObjectionFactory.spec.ts +586 -0
  233. package/src/__tests__/PostgresKyselyMigrator.spec.ts +794 -0
  234. package/src/__tests__/PostgresMigrator.spec.ts +471 -0
  235. package/src/__tests__/PostgresObjectionMigrator.spec.ts +634 -0
  236. package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +138 -0
  237. package/src/__tests__/benchmark.spec.ts +140 -0
  238. package/src/__tests__/better-auth.spec.ts +21 -0
  239. package/src/__tests__/faker.spec.ts +231 -0
  240. package/src/__tests__/initScript.spec.ts +332 -0
  241. package/src/__tests__/integration.spec.ts +610 -0
  242. package/src/__tests__/requestContext.spec.ts +113 -0
  243. package/src/__tests__/utilities.spec.ts +211 -0
  244. package/src/aws.ts +131 -0
  245. package/src/benchmark.ts +48 -0
  246. package/src/better-auth.ts +310 -0
  247. package/src/faker.ts +349 -0
  248. package/src/helpers.ts +45 -0
  249. package/src/initScript.ts +122 -0
  250. package/src/kysely.ts +166 -0
  251. package/src/logger.ts +18 -0
  252. package/src/objection.ts +157 -0
  253. package/src/os/directory.ts +26 -0
  254. package/src/os/index.ts +1 -0
  255. package/src/requestContext.ts +119 -0
  256. package/src/timer.ts +3 -0
  257. package/test/globalSetup.ts +54 -0
  258. package/test/helpers.ts +268 -0
  259. package/test/migrations/1749664623372_user.ts +22 -0
  260. package/tsconfig.json +9 -0
  261. package/vitest.config.ts +8 -0
  262. package/dist/Factory.cjs.map +0 -1
  263. package/dist/Factory.d.cts.map +0 -1
  264. package/dist/Factory.d.mts.map +0 -1
  265. package/dist/Factory.mjs.map +0 -1
  266. package/dist/KyselyFactory.cjs.map +0 -1
  267. package/dist/KyselyFactory.d.cts.map +0 -1
  268. package/dist/KyselyFactory.d.mts.map +0 -1
  269. package/dist/KyselyFactory.mjs.map +0 -1
  270. package/dist/ObjectionFactory.cjs.map +0 -1
  271. package/dist/ObjectionFactory.d.cts.map +0 -1
  272. package/dist/ObjectionFactory.d.mts.map +0 -1
  273. package/dist/ObjectionFactory.mjs.map +0 -1
  274. package/dist/PostgresKyselyMigrator.cjs.map +0 -1
  275. package/dist/PostgresKyselyMigrator.d.cts.map +0 -1
  276. package/dist/PostgresKyselyMigrator.d.mts.map +0 -1
  277. package/dist/PostgresKyselyMigrator.mjs.map +0 -1
  278. package/dist/PostgresMigrator-CDPnnwMJ.d.cts.map +0 -1
  279. package/dist/PostgresMigrator-CDPnnwMJ.d.mts.map +0 -1
  280. package/dist/PostgresMigrator.cjs.map +0 -1
  281. package/dist/PostgresMigrator.mjs.map +0 -1
  282. package/dist/PostgresObjectionMigrator.cjs.map +0 -1
  283. package/dist/PostgresObjectionMigrator.d.cts.map +0 -1
  284. package/dist/PostgresObjectionMigrator.d.mts.map +0 -1
  285. package/dist/PostgresObjectionMigrator.mjs.map +0 -1
  286. package/dist/VitestKyselyTransactionIsolator.cjs.map +0 -1
  287. package/dist/VitestKyselyTransactionIsolator.d.cts.map +0 -1
  288. package/dist/VitestKyselyTransactionIsolator.d.mts.map +0 -1
  289. package/dist/VitestKyselyTransactionIsolator.mjs.map +0 -1
  290. package/dist/VitestObjectionTransactionIsolator.cjs.map +0 -1
  291. package/dist/VitestObjectionTransactionIsolator.d.cts.map +0 -1
  292. package/dist/VitestObjectionTransactionIsolator.d.mts.map +0 -1
  293. package/dist/VitestObjectionTransactionIsolator.mjs.map +0 -1
  294. package/dist/VitestTransactionIsolator.cjs.map +0 -1
  295. package/dist/VitestTransactionIsolator.d.cts.map +0 -1
  296. package/dist/VitestTransactionIsolator.d.mts.map +0 -1
  297. package/dist/VitestTransactionIsolator.mjs.map +0 -1
  298. package/dist/browser.cjs +0 -149
  299. package/dist/browser.cjs.map +0 -1
  300. package/dist/browser.d.cts +0 -62
  301. package/dist/browser.d.cts.map +0 -1
  302. package/dist/browser.d.mts +0 -62
  303. package/dist/browser.d.mts.map +0 -1
  304. package/dist/browser.mjs +0 -147
  305. package/dist/browser.mjs.map +0 -1
  306. package/dist/context.cjs +0 -80
  307. package/dist/context.cjs.map +0 -1
  308. package/dist/context.d.cts +0 -55
  309. package/dist/context.d.cts.map +0 -1
  310. package/dist/context.d.mts +0 -55
  311. package/dist/context.d.mts.map +0 -1
  312. package/dist/context.mjs +0 -73
  313. package/dist/context.mjs.map +0 -1
  314. package/dist/faker.cjs.map +0 -1
  315. package/dist/faker.d.cts.map +0 -1
  316. package/dist/faker.d.mts.map +0 -1
  317. package/dist/faker.mjs.map +0 -1
  318. package/dist/mailbox.cjs +0 -95
  319. package/dist/mailbox.cjs.map +0 -1
  320. package/dist/mailbox.d.cts +0 -58
  321. package/dist/mailbox.d.cts.map +0 -1
  322. package/dist/mailbox.d.mts +0 -58
  323. package/dist/mailbox.d.mts.map +0 -1
  324. package/dist/mailbox.mjs +0 -92
  325. package/dist/mailbox.mjs.map +0 -1
  326. package/dist/os/directory.cjs.map +0 -1
  327. package/dist/os/directory.d.cts.map +0 -1
  328. package/dist/os/directory.d.mts.map +0 -1
  329. package/dist/os/directory.mjs.map +0 -1
  330. package/dist/transactions.cjs +0 -239
  331. package/dist/transactions.cjs.map +0 -1
  332. package/dist/transactions.d.cts +0 -44
  333. package/dist/transactions.d.cts.map +0 -1
  334. package/dist/transactions.d.mts +0 -44
  335. package/dist/transactions.d.mts.map +0 -1
  336. package/dist/transactions.mjs +0 -234
  337. package/dist/transactions.mjs.map +0 -1
package/dist/faker.mjs CHANGED
@@ -1,306 +1,3 @@
1
- import { faker as faker$1 } from "@faker-js/faker";
2
- //#region src/faker.ts
3
- /**
4
- * Atomic counter implementation for thread-safe sequence generation.
5
- * Provides a clean abstraction for generating sequential numbers in tests.
6
- * While JavaScript is single-threaded, this class makes the intent explicit.
7
- *
8
- * @example
9
- * ```typescript
10
- * const counter = new AtomicCounter(100);
11
- * console.log(counter.increment()); // 101
12
- * console.log(counter.increment()); // 102
13
- * console.log(counter.get()); // 102
14
- * counter.reset(200);
15
- * console.log(counter.increment()); // 201
16
- * ```
17
- */
18
- var AtomicCounter = class {
19
- /**
20
- * The current counter value.
21
- * @private
22
- */
23
- value;
24
- /**
25
- * Creates a new atomic counter.
26
- * @param initialValue - The starting value (default: 0)
27
- */
28
- constructor(initialValue = 0) {
29
- this.value = initialValue;
30
- }
31
- /**
32
- * Increments the counter and returns the new value.
33
- * @returns The incremented value
34
- */
35
- increment() {
36
- return ++this.value;
37
- }
38
- /**
39
- * Gets the current counter value without incrementing.
40
- * @returns The current value
41
- */
42
- get() {
43
- return this.value;
44
- }
45
- /**
46
- * Resets the counter to a specific value.
47
- * @param value - The new value (default: 0)
48
- */
49
- reset(value = 0) {
50
- this.value = value;
51
- }
52
- };
53
- /**
54
- * Generates random timestamp fields for database records.
55
- * Creates a createdAt date in the past and an updatedAt date between creation and now.
56
- * Milliseconds are set to 0 for cleaner database storage.
57
- *
58
- * @returns Object with createdAt and updatedAt Date fields
59
- *
60
- * @example
61
- * ```typescript
62
- * const { createdAt, updatedAt } = timestamps();
63
- * console.log(createdAt); // 2023-05-15T10:30:00.000Z
64
- * console.log(updatedAt); // 2023-11-20T14:45:00.000Z
65
- *
66
- * // Use in factory
67
- * const user = {
68
- * name: 'John Doe',
69
- * ...timestamps()
70
- * };
71
- * ```
72
- */
73
- function timestamps() {
74
- const createdAt = faker.date.past();
75
- const updatedAt = faker.date.between({
76
- from: createdAt,
77
- to: /* @__PURE__ */ new Date()
78
- });
79
- createdAt.setMilliseconds(0);
80
- updatedAt.setMilliseconds(0);
81
- return {
82
- createdAt,
83
- updatedAt
84
- };
85
- }
86
- /**
87
- * Generates a reverse domain name identifier.
88
- * Useful for creating unique identifiers that follow domain naming conventions.
89
- *
90
- * @param suffix - Optional suffix to append to the identifier
91
- * @returns A reverse domain name string (e.g., "com.example.feature123")
92
- *
93
- * @example
94
- * ```typescript
95
- * console.log(identifier()); // "com.example.widget1"
96
- * console.log(identifier('user')); // "org.acme.user"
97
- * console.log(identifier('api')); // "net.demo.api"
98
- * ```
99
- */
100
- function identifier(suffix) {
101
- return [
102
- faker.internet.domainSuffix(),
103
- faker.internet.domainWord(),
104
- suffix ? suffix : faker.internet.domainWord() + sequence("identifier")
105
- ].join(".");
106
- }
107
- /**
108
- * Storage for named sequence counters.
109
- * Each sequence maintains its own independent counter.
110
- * @private
111
- */
112
- const sequences = /* @__PURE__ */ new Map();
113
- /**
114
- * Generates sequential numbers for a named sequence.
115
- * Useful for creating unique IDs or numbered test data.
116
- * Each named sequence maintains its own counter.
117
- *
118
- * @param name - The sequence name (default: 'default')
119
- * @returns The next number in the sequence
120
- *
121
- * @example
122
- * ```typescript
123
- * console.log(sequence()); // 1
124
- * console.log(sequence()); // 2
125
- * console.log(sequence('user')); // 1
126
- * console.log(sequence('user')); // 2
127
- * console.log(sequence()); // 3
128
- *
129
- * // Use in factories
130
- * const email = `user${sequence('email')}@example.com`;
131
- * ```
132
- */
133
- function sequence(name = "default") {
134
- if (!sequences.has(name)) sequences.set(name, new AtomicCounter());
135
- return sequences.get(name).increment();
136
- }
137
- /**
138
- * Resets a named sequence counter to a specific value.
139
- * Useful for resetting sequences between test suites.
140
- *
141
- * @param name - The sequence name to reset (default: 'default')
142
- * @param value - The new starting value (default: 0)
143
- *
144
- * @example
145
- * ```typescript
146
- * sequence('user'); // 1
147
- * sequence('user'); // 2
148
- * resetSequence('user');
149
- * sequence('user'); // 1
150
- *
151
- * resetSequence('order', 1000);
152
- * sequence('order'); // 1001
153
- * ```
154
- */
155
- function resetSequence(name = "default", value = 0) {
156
- if (sequences.has(name)) sequences.get(name).reset(value);
157
- else sequences.set(name, new AtomicCounter(value));
158
- }
159
- /**
160
- * Resets all sequence counters.
161
- * Useful for cleaning up between test suites to ensure predictable sequences.
162
- *
163
- * @example
164
- * ```typescript
165
- * // In test setup
166
- * beforeEach(() => {
167
- * resetAllSequences();
168
- * });
169
- *
170
- * it('starts sequences from 1', () => {
171
- * expect(sequence()).toBe(1);
172
- * expect(sequence('user')).toBe(1);
173
- * });
174
- * ```
175
- */
176
- function resetAllSequences() {
177
- sequences.clear();
178
- }
179
- /**
180
- * Generates a random price as a number.
181
- * Converts faker's string price to a numeric value.
182
- *
183
- * @returns A random price number
184
- *
185
- * @example
186
- * ```typescript
187
- * const productPrice = price(); // 29.99
188
- * const total = price() * quantity; // Numeric calculation
189
- * ```
190
- */
191
- function price() {
192
- return +faker.commerce.price();
193
- }
194
- /**
195
- * A birthdate for someone of the given age today: exactly `min` years old, or
196
- * anywhere from `min` to `max` inclusive.
197
- *
198
- * Through faker's own `date.birthdate`, so seeding faker makes it repeatable.
199
- *
200
- * @param min - The youngest age, in whole years
201
- * @param max - The oldest age, in whole years (default: `min`)
202
- * @returns The birthdate
203
- *
204
- * @example
205
- * ```typescript
206
- * faker.age(18); // someone who is 18 today
207
- * faker.age(18, 24); // someone aged 18 to 24
208
- * ```
209
- */
210
- function age(min, max = min) {
211
- if (min < 0 || max < min) throw new AgeRangeInvalid(min, max);
212
- return faker$1.date.birthdate({
213
- mode: "age",
214
- min,
215
- max
216
- });
217
- }
218
- /** An age range no one can be: a negative age, or an oldest below a youngest. */
219
- var AgeRangeInvalid = class extends Error {
220
- min;
221
- max;
222
- constructor(min, max) {
223
- super(`faker.age(${min}, ${max}) asks for an age no one can be. Pass the youngest age first and the oldest second, neither negative: faker.age(18) or faker.age(18, 24).`);
224
- this.min = min;
225
- this.max = max;
226
- this.name = "AgeRangeInvalid";
227
- }
228
- };
229
- function coordinateInRadius(center, radius) {
230
- const d = radius / 6378137;
231
- const theta = 2 * Math.PI * Math.random();
232
- const r = d * Math.sqrt(Math.random());
233
- const lat1 = center.lat * Math.PI / 180;
234
- const lng1 = center.lng * Math.PI / 180;
235
- const lat2 = Math.asin(Math.sin(lat1) * Math.cos(r) + Math.cos(lat1) * Math.sin(r) * Math.cos(theta));
236
- const lng2 = lng1 + Math.atan2(Math.sin(theta) * Math.sin(r) * Math.cos(lat1), Math.cos(r) - Math.sin(lat1) * Math.sin(lat2));
237
- return {
238
- lat: lat2 * 180 / Math.PI,
239
- lng: lng2 * 180 / Math.PI
240
- };
241
- }
242
- function coordinateOutsideRadius(center, minRadiusMeters, maxRadiusMeters) {
243
- const earth = 6378137;
244
- const minD = minRadiusMeters / earth;
245
- const maxD = maxRadiusMeters / earth;
246
- const theta = 2 * Math.PI * Math.random();
247
- const r = Math.sqrt(minD * minD + (maxD * maxD - minD * minD) * Math.random());
248
- const lat1 = center.lat * Math.PI / 180;
249
- const lng1 = center.lng * Math.PI / 180;
250
- const lat2 = Math.asin(Math.sin(lat1) * Math.cos(r) + Math.cos(lat1) * Math.sin(r) * Math.cos(theta));
251
- const normalizedLng = ((lng1 + Math.atan2(Math.sin(theta) * Math.sin(r) * Math.cos(lat1), Math.cos(r) - Math.sin(lat1) * Math.sin(lat2))) * 180 / Math.PI + 540) % 360 - 180;
252
- return {
253
- lat: lat2 * 180 / Math.PI,
254
- lng: normalizedLng
255
- };
256
- }
257
- /**
258
- * Enhanced faker instance with additional utility methods for testing.
259
- * Extends @faker-js/faker with custom methods for common test data generation patterns.
260
- *
261
- * @example
262
- * ```typescript
263
- * import { faker } from '@geekmidas/testkit';
264
- *
265
- * // Use standard faker methods
266
- * const name = faker.person.fullName();
267
- * const email = faker.internet.email();
268
- *
269
- * // Use custom extensions
270
- * const { createdAt, updatedAt } = faker.timestamps();
271
- * const id = faker.identifier('user');
272
- * const orderNumber = faker.sequence('order');
273
- * const productPrice = faker.price();
274
- * ```
275
- */
276
- /**
277
- * `faker.internet`, with every address lowercase.
278
- *
279
- * An auth server stores addresses lowercased — Better Auth does — so a test
280
- * that signs in as faker's `Ada.Lovelace@…` and reads back `ada.lovelace@…`
281
- * fails only when faker happened to capitalise: a flake, not a bug. The rest
282
- * of the module is faker's own, through the prototype.
283
- */
284
- const internet = Object.assign(Object.create(faker$1.internet), {
285
- email: (...args) => faker$1.internet.email(...args).toLowerCase(),
286
- exampleEmail: (...args) => faker$1.internet.exampleEmail(...args).toLowerCase()
287
- });
288
- const faker = Object.freeze(Object.assign({}, faker$1, {
289
- internet,
290
- seed: (seed) => faker$1.seed(seed),
291
- timestamps,
292
- identifier,
293
- sequence,
294
- resetSequence,
295
- resetAllSequences,
296
- price,
297
- age,
298
- coordinates: {
299
- within: coordinateInRadius,
300
- outside: coordinateOutsideRadius
301
- }
302
- }));
303
- //#endregion
304
- export { AgeRangeInvalid, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
1
+ import { coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-BGKYFoCT.mjs";
305
2
 
306
- //# sourceMappingURL=faker.mjs.map
3
+ export { coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
package/dist/helpers.cjs CHANGED
@@ -1,8 +1,7 @@
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
- let kysely = require("kysely");
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const pg = require_chunk.__toESM(require("pg"));
3
+ const kysely = require_chunk.__toESM(require("kysely"));
4
+
6
5
  //#region src/helpers.ts
7
6
  /**
8
7
  * Creates a Kysely database instance with PostgreSQL dialect and camelCase plugin.
@@ -44,7 +43,7 @@ function createKyselyDb(config) {
44
43
  plugins: [new kysely.CamelCasePlugin()]
45
44
  });
46
45
  }
46
+
47
47
  //#endregion
48
48
  exports.createKyselyDb = createKyselyDb;
49
-
50
49
  //# sourceMappingURL=helpers.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.cjs","names":["Kysely","PostgresDialect","CamelCasePlugin"],"sources":["../src/helpers.ts"],"sourcesContent":["import { CamelCasePlugin, Kysely, PostgresDialect } from 'kysely';\nimport pg from 'pg';\n\n/**\n * Creates a Kysely database instance with PostgreSQL dialect and camelCase plugin.\n * This is a convenience function for quickly setting up a Kysely connection for testing.\n *\n * @template Database - The database schema type\n * @param config - PostgreSQL connection configuration (pg.Pool config)\n * @returns A configured Kysely instance\n *\n * @example\n * ```typescript\n * interface Database {\n * users: UsersTable;\n * posts: PostsTable;\n * }\n *\n * // Create from connection string\n * const db = createKyselyDb<Database>({\n * connectionString: 'postgresql://user:pass@localhost:5432/testdb'\n * });\n *\n * // Create with detailed config\n * const db = createKyselyDb<Database>({\n * host: 'localhost',\n * port: 5432,\n * database: 'testdb',\n * user: 'testuser',\n * password: 'testpass',\n * max: 10 // connection pool size\n * });\n *\n * // Use in tests\n * const users = await db.selectFrom('users').selectAll().execute();\n * ```\n */\nexport function createKyselyDb<Database>(config: any): Kysely<Database> {\n\treturn new Kysely({\n\t\tdialect: new PostgresDialect({\n\t\t\tpool: new pg.Pool(config),\n\t\t}),\n\t\tplugins: [new CamelCasePlugin()],\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,eAAyB,QAA+B;CACvE,OAAO,IAAIA,OAAAA,OAAO;EACjB,SAAS,IAAIC,OAAAA,gBAAgB,EAC5B,MAAM,IAAI,GAAA,QAAG,KAAK,MAAM,EACzB,CAAC;EACD,SAAS,CAAC,IAAIC,OAAAA,gBAAgB,CAAC;CAChC,CAAC;AACF"}
1
+ {"version":3,"file":"helpers.cjs","names":["config: any","Kysely","PostgresDialect","CamelCasePlugin"],"sources":["../src/helpers.ts"],"sourcesContent":["import { CamelCasePlugin, Kysely, PostgresDialect } from 'kysely';\nimport pg from 'pg';\n\n/**\n * Creates a Kysely database instance with PostgreSQL dialect and camelCase plugin.\n * This is a convenience function for quickly setting up a Kysely connection for testing.\n *\n * @template Database - The database schema type\n * @param config - PostgreSQL connection configuration (pg.Pool config)\n * @returns A configured Kysely instance\n *\n * @example\n * ```typescript\n * interface Database {\n * users: UsersTable;\n * posts: PostsTable;\n * }\n *\n * // Create from connection string\n * const db = createKyselyDb<Database>({\n * connectionString: 'postgresql://user:pass@localhost:5432/testdb'\n * });\n *\n * // Create with detailed config\n * const db = createKyselyDb<Database>({\n * host: 'localhost',\n * port: 5432,\n * database: 'testdb',\n * user: 'testuser',\n * password: 'testpass',\n * max: 10 // connection pool size\n * });\n *\n * // Use in tests\n * const users = await db.selectFrom('users').selectAll().execute();\n * ```\n */\nexport function createKyselyDb<Database>(config: any): Kysely<Database> {\n\treturn new Kysely({\n\t\tdialect: new PostgresDialect({\n\t\t\tpool: new pg.Pool(config),\n\t\t}),\n\t\tplugins: [new CamelCasePlugin()],\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,eAAyBA,QAA+B;AACvE,QAAO,IAAIC,cAAO;EACjB,SAAS,IAAIC,uBAAgB,EAC5B,MAAM,IAAI,WAAG,KAAK,QAClB;EACD,SAAS,CAAC,IAAIC,wBAAkB;CAChC;AACD"}
@@ -1,5 +1,7 @@
1
1
  import { Kysely } from "kysely";
2
+
2
3
  //#region src/helpers.d.ts
4
+
3
5
  /**
4
6
  * Creates a Kysely database instance with PostgreSQL dialect and camelCase plugin.
5
7
  * This is a convenience function for quickly setting up a Kysely connection for testing.
@@ -34,6 +36,8 @@ import { Kysely } from "kysely";
34
36
  * const users = await db.selectFrom('users').selectAll().execute();
35
37
  * ```
36
38
  */
37
- export declare function createKyselyDb<Database>(config: any): Kysely<Database>;
39
+ declare function createKyselyDb<Database>(config: any): Kysely<Database>;
40
+ //# sourceMappingURL=helpers.d.ts.map
38
41
  //#endregion
42
+ export { createKyselyDb };
39
43
  //# sourceMappingURL=helpers.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.cts","names":[],"sources":["../src/helpers.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqCgB,eAAe,UAAU,cAAc,OAAO"}
1
+ {"version":3,"file":"helpers.d.cts","names":[],"sources":["../src/helpers.ts"],"sourcesContent":[],"mappings":";;;;;;AAqCA;;;;AAA6D;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAA7C,uCAAuC,OAAO"}
@@ -1,5 +1,7 @@
1
1
  import { Kysely } from "kysely";
2
+
2
3
  //#region src/helpers.d.ts
4
+
3
5
  /**
4
6
  * Creates a Kysely database instance with PostgreSQL dialect and camelCase plugin.
5
7
  * This is a convenience function for quickly setting up a Kysely connection for testing.
@@ -34,6 +36,8 @@ import { Kysely } from "kysely";
34
36
  * const users = await db.selectFrom('users').selectAll().execute();
35
37
  * ```
36
38
  */
37
- export declare function createKyselyDb<Database>(config: any): Kysely<Database>;
39
+ declare function createKyselyDb<Database>(config: any): Kysely<Database>;
40
+ //# sourceMappingURL=helpers.d.ts.map
38
41
  //#endregion
42
+ export { createKyselyDb };
39
43
  //# sourceMappingURL=helpers.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.mts","names":[],"sources":["../src/helpers.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqCgB,eAAe,UAAU,cAAc,OAAO"}
1
+ {"version":3,"file":"helpers.d.mts","names":[],"sources":["../src/helpers.ts"],"sourcesContent":[],"mappings":";;;;;;AAqCA;;;;AAA6D;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAA7C,uCAAuC,OAAO"}
package/dist/helpers.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import pg from "pg";
2
2
  import { CamelCasePlugin, Kysely, PostgresDialect } from "kysely";
3
+
3
4
  //#region src/helpers.ts
4
5
  /**
5
6
  * Creates a Kysely database instance with PostgreSQL dialect and camelCase plugin.
@@ -41,7 +42,7 @@ function createKyselyDb(config) {
41
42
  plugins: [new CamelCasePlugin()]
42
43
  });
43
44
  }
45
+
44
46
  //#endregion
45
47
  export { createKyselyDb };
46
-
47
48
  //# sourceMappingURL=helpers.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.mjs","names":[],"sources":["../src/helpers.ts"],"sourcesContent":["import { CamelCasePlugin, Kysely, PostgresDialect } from 'kysely';\nimport pg from 'pg';\n\n/**\n * Creates a Kysely database instance with PostgreSQL dialect and camelCase plugin.\n * This is a convenience function for quickly setting up a Kysely connection for testing.\n *\n * @template Database - The database schema type\n * @param config - PostgreSQL connection configuration (pg.Pool config)\n * @returns A configured Kysely instance\n *\n * @example\n * ```typescript\n * interface Database {\n * users: UsersTable;\n * posts: PostsTable;\n * }\n *\n * // Create from connection string\n * const db = createKyselyDb<Database>({\n * connectionString: 'postgresql://user:pass@localhost:5432/testdb'\n * });\n *\n * // Create with detailed config\n * const db = createKyselyDb<Database>({\n * host: 'localhost',\n * port: 5432,\n * database: 'testdb',\n * user: 'testuser',\n * password: 'testpass',\n * max: 10 // connection pool size\n * });\n *\n * // Use in tests\n * const users = await db.selectFrom('users').selectAll().execute();\n * ```\n */\nexport function createKyselyDb<Database>(config: any): Kysely<Database> {\n\treturn new Kysely({\n\t\tdialect: new PostgresDialect({\n\t\t\tpool: new pg.Pool(config),\n\t\t}),\n\t\tplugins: [new CamelCasePlugin()],\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,eAAyB,QAA+B;CACvE,OAAO,IAAI,OAAO;EACjB,SAAS,IAAI,gBAAgB,EAC5B,MAAM,IAAI,GAAG,KAAK,MAAM,EACzB,CAAC;EACD,SAAS,CAAC,IAAI,gBAAgB,CAAC;CAChC,CAAC;AACF"}
1
+ {"version":3,"file":"helpers.mjs","names":["config: any"],"sources":["../src/helpers.ts"],"sourcesContent":["import { CamelCasePlugin, Kysely, PostgresDialect } from 'kysely';\nimport pg from 'pg';\n\n/**\n * Creates a Kysely database instance with PostgreSQL dialect and camelCase plugin.\n * This is a convenience function for quickly setting up a Kysely connection for testing.\n *\n * @template Database - The database schema type\n * @param config - PostgreSQL connection configuration (pg.Pool config)\n * @returns A configured Kysely instance\n *\n * @example\n * ```typescript\n * interface Database {\n * users: UsersTable;\n * posts: PostsTable;\n * }\n *\n * // Create from connection string\n * const db = createKyselyDb<Database>({\n * connectionString: 'postgresql://user:pass@localhost:5432/testdb'\n * });\n *\n * // Create with detailed config\n * const db = createKyselyDb<Database>({\n * host: 'localhost',\n * port: 5432,\n * database: 'testdb',\n * user: 'testuser',\n * password: 'testpass',\n * max: 10 // connection pool size\n * });\n *\n * // Use in tests\n * const users = await db.selectFrom('users').selectAll().execute();\n * ```\n */\nexport function createKyselyDb<Database>(config: any): Kysely<Database> {\n\treturn new Kysely({\n\t\tdialect: new PostgresDialect({\n\t\t\tpool: new pg.Pool(config),\n\t\t}),\n\t\tplugins: [new CamelCasePlugin()],\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,eAAyBA,QAA+B;AACvE,QAAO,IAAI,OAAO;EACjB,SAAS,IAAI,gBAAgB,EAC5B,MAAM,IAAI,GAAG,KAAK,QAClB;EACD,SAAS,CAAC,IAAI,iBAAkB;CAChC;AACD"}
@@ -1,8 +1,7 @@
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
- let node_fs = require("node:fs");
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const pg = require_chunk.__toESM(require("pg"));
3
+ const node_fs = require_chunk.__toESM(require("node:fs"));
4
+
6
5
  //#region src/initScript.ts
7
6
  const { Client } = pg.default;
8
7
  /**
@@ -19,14 +18,13 @@ function parseInitScript(content, env) {
19
18
  const lines = content.split("\n");
20
19
  let inHeredoc = false;
21
20
  let currentBlock = [];
22
- for (const line of lines) if (inHeredoc) {
23
- if (/^\s*EOSQL\s*$/.test(line)) {
24
- const sql = substituteEnvVars(currentBlock.join("\n"), env);
25
- blocks.push(sql);
26
- currentBlock = [];
27
- inHeredoc = false;
28
- } else currentBlock.push(line);
29
- } else if (line.includes("<<-EOSQL") || line.includes("<< EOSQL") || line.includes("<<EOSQL")) {
21
+ for (const line of lines) if (inHeredoc) if (/^\s*EOSQL\s*$/.test(line)) {
22
+ const sql = substituteEnvVars(currentBlock.join("\n"), env);
23
+ blocks.push(sql);
24
+ currentBlock = [];
25
+ inHeredoc = false;
26
+ } else currentBlock.push(line);
27
+ else if (line.includes("<<-EOSQL") || line.includes("<< EOSQL") || line.includes("<<EOSQL")) {
30
28
  inHeredoc = true;
31
29
  currentBlock = [];
32
30
  }
@@ -72,7 +70,9 @@ function substituteEnvVars(sql, env) {
72
70
  * ```
73
71
  */
74
72
  async function runInitScript(scriptPath, databaseUrl, env) {
75
- const blocks = parseInitScript((0, node_fs.readFileSync)(scriptPath, "utf-8"), env ?? { ...process.env });
73
+ const content = (0, node_fs.readFileSync)(scriptPath, "utf-8");
74
+ const resolvedEnv = env ?? { ...process.env };
75
+ const blocks = parseInitScript(content, resolvedEnv);
76
76
  if (blocks.length === 0) return;
77
77
  const url = new URL(databaseUrl);
78
78
  const client = new Client({
@@ -89,8 +89,8 @@ async function runInitScript(scriptPath, databaseUrl, env) {
89
89
  await client.end();
90
90
  }
91
91
  }
92
+
92
93
  //#endregion
93
94
  exports.parseInitScript = parseInitScript;
94
95
  exports.runInitScript = runInitScript;
95
-
96
96
  //# sourceMappingURL=initScript.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"initScript.cjs","names":["readFileSync"],"sources":["../src/initScript.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport pg from 'pg';\n\nconst { Client } = pg;\n\n/**\n * Parse a shell init script (like docker/postgres/init.sh) and extract\n * SQL blocks from heredoc sections (<<-EOSQL ... EOSQL).\n *\n * @param content - The shell script content\n * @param env - Environment variables to substitute ($VAR_NAME references)\n * @returns Array of SQL strings ready to execute\n * @internal Exported for testing\n */\nexport function parseInitScript(\n\tcontent: string,\n\tenv: Record<string, string>,\n): string[] {\n\tconst blocks: string[] = [];\n\tconst lines = content.split('\\n');\n\tlet inHeredoc = false;\n\tlet currentBlock: string[] = [];\n\n\tfor (const line of lines) {\n\t\tif (inHeredoc) {\n\t\t\t// Check for heredoc terminator (EOSQL at start of line, with optional leading whitespace)\n\t\t\tif (/^\\s*EOSQL\\s*$/.test(line)) {\n\t\t\t\tconst sql = substituteEnvVars(currentBlock.join('\\n'), env);\n\t\t\t\tblocks.push(sql);\n\t\t\t\tcurrentBlock = [];\n\t\t\t\tinHeredoc = false;\n\t\t\t} else {\n\t\t\t\tcurrentBlock.push(line);\n\t\t\t}\n\t\t} else if (\n\t\t\tline.includes('<<-EOSQL') ||\n\t\t\tline.includes('<< EOSQL') ||\n\t\t\tline.includes('<<EOSQL')\n\t\t) {\n\t\t\tinHeredoc = true;\n\t\t\tcurrentBlock = [];\n\t\t}\n\t}\n\n\treturn blocks;\n}\n\n/**\n * Replace shell variable references ($VAR_NAME and ${VAR_NAME})\n * with values from the provided env object.\n */\nfunction substituteEnvVars(sql: string, env: Record<string, string>): string {\n\t// Replace ${VAR_NAME} syntax\n\tlet result = sql.replace(/\\$\\{(\\w+)\\}/g, (_, name) => env[name] ?? '');\n\t// Replace $VAR_NAME syntax (word boundary after)\n\tresult = result.replace(/\\$(\\w+)/g, (_, name) => env[name] ?? '');\n\t// Unescape bash-escaped dollar signs (\\$ → $) AFTER variable substitution\n\t// This handles PL/pgSQL dollar-quoting like DO \\$\\$ ... END \\$\\$;\n\tresult = result.replace(/\\\\\\$/g, '$');\n\treturn result;\n}\n\n/**\n * Read a postgres init script, parse out the SQL blocks,\n * substitute environment variables, and execute against a database.\n *\n * This is intended to run `docker/postgres/init.sh` against a test database\n * so that per-app users and schemas are created (matching what Docker does\n * on first volume initialization).\n *\n * Uses `CREATE ... IF NOT EXISTS` and `DO $$ ... END $$` wrappers where\n * needed so the script is idempotent.\n *\n * @param scriptPath - Path to the init.sh file\n * @param databaseUrl - PostgreSQL connection URL (should point to the test database)\n *\n * @example\n * ```typescript\n * // In your globalSetup.ts\n * import { runInitScript } from '@geekmidas/testkit/postgres';\n * import { Credentials } from '@geekmidas/envkit/credentials';\n *\n * const cleanup = await migrator.start();\n *\n * // Create per-app users in the test database\n * await runInitScript('docker/postgres/init.sh', Credentials.DATABASE_URL, {\n * ...process.env,\n * ...Credentials,\n * });\n * ```\n */\nexport async function runInitScript(\n\tscriptPath: string,\n\tdatabaseUrl: string,\n\tenv?: Record<string, string>,\n): Promise<void> {\n\tconst content = readFileSync(scriptPath, 'utf-8');\n\tconst resolvedEnv = env ?? ({ ...process.env } as Record<string, string>);\n\tconst blocks = parseInitScript(content, resolvedEnv);\n\n\tif (blocks.length === 0) {\n\t\treturn;\n\t}\n\n\tconst url = new URL(databaseUrl);\n\tconst client = new Client({\n\t\tuser: url.username,\n\t\tpassword: decodeURIComponent(url.password),\n\t\thost: url.hostname,\n\t\tport: parseInt(url.port, 10),\n\t\tdatabase: url.pathname.slice(1),\n\t});\n\n\ttry {\n\t\tawait client.connect();\n\t\tfor (const sql of blocks) {\n\t\t\tawait client.query(sql);\n\t\t}\n\t} finally {\n\t\tawait client.end();\n\t}\n}\n"],"mappings":";;;;;;AAGA,MAAM,EAAE,WAAW,GAAA;;;;;;;;;;AAWnB,SAAgB,gBACf,SACA,KACW;CACX,MAAM,SAAmB,CAAC;CAC1B,MAAM,QAAQ,QAAQ,MAAM,IAAI;CAChC,IAAI,YAAY;CAChB,IAAI,eAAyB,CAAC;CAE9B,KAAK,MAAM,QAAQ,OAClB,IAAI,WAAW;EAEd,IAAI,gBAAgB,KAAK,IAAI,GAAG;GAC/B,MAAM,MAAM,kBAAkB,aAAa,KAAK,IAAI,GAAG,GAAG;GAC1D,OAAO,KAAK,GAAG;GACf,eAAe,CAAC;GAChB,YAAY;EACb,OACC,aAAa,KAAK,IAAI;CAExB,OAAO,IACN,KAAK,SAAS,UAAU,KACxB,KAAK,SAAS,UAAU,KACxB,KAAK,SAAS,SAAS,GACtB;EACD,YAAY;EACZ,eAAe,CAAC;CACjB;CAGD,OAAO;AACR;;;;;AAMA,SAAS,kBAAkB,KAAa,KAAqC;CAE5E,IAAI,SAAS,IAAI,QAAQ,iBAAiB,GAAG,SAAS,IAAI,SAAS,EAAE;CAErE,SAAS,OAAO,QAAQ,aAAa,GAAG,SAAS,IAAI,SAAS,EAAE;CAGhE,SAAS,OAAO,QAAQ,SAAS,GAAG;CACpC,OAAO;AACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,eAAsB,cACrB,YACA,aACA,KACgB;CAGhB,MAAM,SAAS,iBAAA,GAFCA,QAAAA,aAAAA,CAAa,YAAY,OAEJ,GADjB,OAAQ,EAAE,GAAG,QAAQ,IAAI,CACM;CAEnD,IAAI,OAAO,WAAW,GACrB;CAGD,MAAM,MAAM,IAAI,IAAI,WAAW;CAC/B,MAAM,SAAS,IAAI,OAAO;EACzB,MAAM,IAAI;EACV,UAAU,mBAAmB,IAAI,QAAQ;EACzC,MAAM,IAAI;EACV,MAAM,SAAS,IAAI,MAAM,EAAE;EAC3B,UAAU,IAAI,SAAS,MAAM,CAAC;CAC/B,CAAC;CAED,IAAI;EACH,MAAM,OAAO,QAAQ;EACrB,KAAK,MAAM,OAAO,QACjB,MAAM,OAAO,MAAM,GAAG;CAExB,UAAU;EACT,MAAM,OAAO,IAAI;CAClB;AACD"}
1
+ {"version":3,"file":"initScript.cjs","names":["content: string","env: Record<string, string>","blocks: string[]","currentBlock: string[]","sql: string","scriptPath: string","databaseUrl: string","env?: Record<string, string>"],"sources":["../src/initScript.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport pg from 'pg';\n\nconst { Client } = pg;\n\n/**\n * Parse a shell init script (like docker/postgres/init.sh) and extract\n * SQL blocks from heredoc sections (<<-EOSQL ... EOSQL).\n *\n * @param content - The shell script content\n * @param env - Environment variables to substitute ($VAR_NAME references)\n * @returns Array of SQL strings ready to execute\n * @internal Exported for testing\n */\nexport function parseInitScript(\n\tcontent: string,\n\tenv: Record<string, string>,\n): string[] {\n\tconst blocks: string[] = [];\n\tconst lines = content.split('\\n');\n\tlet inHeredoc = false;\n\tlet currentBlock: string[] = [];\n\n\tfor (const line of lines) {\n\t\tif (inHeredoc) {\n\t\t\t// Check for heredoc terminator (EOSQL at start of line, with optional leading whitespace)\n\t\t\tif (/^\\s*EOSQL\\s*$/.test(line)) {\n\t\t\t\tconst sql = substituteEnvVars(currentBlock.join('\\n'), env);\n\t\t\t\tblocks.push(sql);\n\t\t\t\tcurrentBlock = [];\n\t\t\t\tinHeredoc = false;\n\t\t\t} else {\n\t\t\t\tcurrentBlock.push(line);\n\t\t\t}\n\t\t} else if (\n\t\t\tline.includes('<<-EOSQL') ||\n\t\t\tline.includes('<< EOSQL') ||\n\t\t\tline.includes('<<EOSQL')\n\t\t) {\n\t\t\tinHeredoc = true;\n\t\t\tcurrentBlock = [];\n\t\t}\n\t}\n\n\treturn blocks;\n}\n\n/**\n * Replace shell variable references ($VAR_NAME and ${VAR_NAME})\n * with values from the provided env object.\n */\nfunction substituteEnvVars(sql: string, env: Record<string, string>): string {\n\t// Replace ${VAR_NAME} syntax\n\tlet result = sql.replace(/\\$\\{(\\w+)\\}/g, (_, name) => env[name] ?? '');\n\t// Replace $VAR_NAME syntax (word boundary after)\n\tresult = result.replace(/\\$(\\w+)/g, (_, name) => env[name] ?? '');\n\t// Unescape bash-escaped dollar signs (\\$ → $) AFTER variable substitution\n\t// This handles PL/pgSQL dollar-quoting like DO \\$\\$ ... END \\$\\$;\n\tresult = result.replace(/\\\\\\$/g, '$');\n\treturn result;\n}\n\n/**\n * Read a postgres init script, parse out the SQL blocks,\n * substitute environment variables, and execute against a database.\n *\n * This is intended to run `docker/postgres/init.sh` against a test database\n * so that per-app users and schemas are created (matching what Docker does\n * on first volume initialization).\n *\n * Uses `CREATE ... IF NOT EXISTS` and `DO $$ ... END $$` wrappers where\n * needed so the script is idempotent.\n *\n * @param scriptPath - Path to the init.sh file\n * @param databaseUrl - PostgreSQL connection URL (should point to the test database)\n *\n * @example\n * ```typescript\n * // In your globalSetup.ts\n * import { runInitScript } from '@geekmidas/testkit/postgres';\n * import { Credentials } from '@geekmidas/envkit/credentials';\n *\n * const cleanup = await migrator.start();\n *\n * // Create per-app users in the test database\n * await runInitScript('docker/postgres/init.sh', Credentials.DATABASE_URL, {\n * ...process.env,\n * ...Credentials,\n * });\n * ```\n */\nexport async function runInitScript(\n\tscriptPath: string,\n\tdatabaseUrl: string,\n\tenv?: Record<string, string>,\n): Promise<void> {\n\tconst content = readFileSync(scriptPath, 'utf-8');\n\tconst resolvedEnv = env ?? ({ ...process.env } as Record<string, string>);\n\tconst blocks = parseInitScript(content, resolvedEnv);\n\n\tif (blocks.length === 0) {\n\t\treturn;\n\t}\n\n\tconst url = new URL(databaseUrl);\n\tconst client = new Client({\n\t\tuser: url.username,\n\t\tpassword: decodeURIComponent(url.password),\n\t\thost: url.hostname,\n\t\tport: parseInt(url.port, 10),\n\t\tdatabase: url.pathname.slice(1),\n\t});\n\n\ttry {\n\t\tawait client.connect();\n\t\tfor (const sql of blocks) {\n\t\t\tawait client.query(sql);\n\t\t}\n\t} finally {\n\t\tawait client.end();\n\t}\n}\n"],"mappings":";;;;;AAGA,MAAM,EAAE,QAAQ,GAAG;;;;;;;;;;AAWnB,SAAgB,gBACfA,SACAC,KACW;CACX,MAAMC,SAAmB,CAAE;CAC3B,MAAM,QAAQ,QAAQ,MAAM,KAAK;CACjC,IAAI,YAAY;CAChB,IAAIC,eAAyB,CAAE;AAE/B,MAAK,MAAM,QAAQ,MAClB,KAAI,UAEH,KAAI,gBAAgB,KAAK,KAAK,EAAE;EAC/B,MAAM,MAAM,kBAAkB,aAAa,KAAK,KAAK,EAAE,IAAI;AAC3D,SAAO,KAAK,IAAI;AAChB,iBAAe,CAAE;AACjB,cAAY;CACZ,MACA,cAAa,KAAK,KAAK;UAGxB,KAAK,SAAS,WAAW,IACzB,KAAK,SAAS,WAAW,IACzB,KAAK,SAAS,UAAU,EACvB;AACD,cAAY;AACZ,iBAAe,CAAE;CACjB;AAGF,QAAO;AACP;;;;;AAMD,SAAS,kBAAkBC,KAAaH,KAAqC;CAE5E,IAAI,SAAS,IAAI,QAAQ,gBAAgB,CAAC,GAAG,SAAS,IAAI,SAAS,GAAG;AAEtE,UAAS,OAAO,QAAQ,YAAY,CAAC,GAAG,SAAS,IAAI,SAAS,GAAG;AAGjE,UAAS,OAAO,QAAQ,SAAS,IAAI;AACrC,QAAO;AACP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BD,eAAsB,cACrBI,YACAC,aACAC,KACgB;CAChB,MAAM,UAAU,0BAAa,YAAY,QAAQ;CACjD,MAAM,cAAc,OAAQ,EAAE,GAAG,QAAQ,IAAK;CAC9C,MAAM,SAAS,gBAAgB,SAAS,YAAY;AAEpD,KAAI,OAAO,WAAW,EACrB;CAGD,MAAM,MAAM,IAAI,IAAI;CACpB,MAAM,SAAS,IAAI,OAAO;EACzB,MAAM,IAAI;EACV,UAAU,mBAAmB,IAAI,SAAS;EAC1C,MAAM,IAAI;EACV,MAAM,SAAS,IAAI,MAAM,GAAG;EAC5B,UAAU,IAAI,SAAS,MAAM,EAAE;CAC/B;AAED,KAAI;AACH,QAAM,OAAO,SAAS;AACtB,OAAK,MAAM,OAAO,OACjB,OAAM,OAAO,MAAM,IAAI;CAExB,UAAS;AACT,QAAM,OAAO,KAAK;CAClB;AACD"}
@@ -8,7 +8,7 @@
8
8
  * @returns Array of SQL strings ready to execute
9
9
  * @internal Exported for testing
10
10
  */
11
- export declare function parseInitScript(content: string, env: Record<string, string>): string[];
11
+ declare function parseInitScript(content: string, env: Record<string, string>): string[];
12
12
  /**
13
13
  * Read a postgres init script, parse out the SQL blocks,
14
14
  * substitute environment variables, and execute against a database.
@@ -38,6 +38,8 @@ export declare function parseInitScript(content: string, env: Record<string, str
38
38
  * });
39
39
  * ```
40
40
  */
41
- export declare function runInitScript(scriptPath: string, databaseUrl: string, env?: Record<string, string>): Promise<void>;
41
+ declare function runInitScript(scriptPath: string, databaseUrl: string, env?: Record<string, string>): Promise<void>;
42
+ //# sourceMappingURL=initScript.d.ts.map
42
43
  //#endregion
44
+ export { parseInitScript, runInitScript };
43
45
  //# sourceMappingURL=initScript.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"initScript.d.cts","names":[],"sources":["../src/initScript.ts"],"mappings":";;;;;;;;;;wBAcgB,gBACf,iBACA,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2EgB,cACrB,oBACA,qBACA,MAAM,yBACJ"}
1
+ {"version":3,"file":"initScript.d.cts","names":[],"sources":["../src/initScript.ts"],"sourcesContent":[],"mappings":";;AAcA;AA6EA;;;;AAIU;;;iBAjFM,eAAA,uBAEV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2EgB,aAAA,gDAGf,yBACJ"}
@@ -8,7 +8,7 @@
8
8
  * @returns Array of SQL strings ready to execute
9
9
  * @internal Exported for testing
10
10
  */
11
- export declare function parseInitScript(content: string, env: Record<string, string>): string[];
11
+ declare function parseInitScript(content: string, env: Record<string, string>): string[];
12
12
  /**
13
13
  * Read a postgres init script, parse out the SQL blocks,
14
14
  * substitute environment variables, and execute against a database.
@@ -38,6 +38,8 @@ export declare function parseInitScript(content: string, env: Record<string, str
38
38
  * });
39
39
  * ```
40
40
  */
41
- export declare function runInitScript(scriptPath: string, databaseUrl: string, env?: Record<string, string>): Promise<void>;
41
+ declare function runInitScript(scriptPath: string, databaseUrl: string, env?: Record<string, string>): Promise<void>;
42
+ //# sourceMappingURL=initScript.d.ts.map
42
43
  //#endregion
44
+ export { parseInitScript, runInitScript };
43
45
  //# sourceMappingURL=initScript.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"initScript.d.mts","names":[],"sources":["../src/initScript.ts"],"mappings":";;;;;;;;;;wBAcgB,gBACf,iBACA,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2EgB,cACrB,oBACA,qBACA,MAAM,yBACJ"}
1
+ {"version":3,"file":"initScript.d.mts","names":[],"sources":["../src/initScript.ts"],"sourcesContent":[],"mappings":";;AAcA;AA6EA;;;;AAIU;;;iBAjFM,eAAA,uBAEV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2EgB,aAAA,gDAGf,yBACJ"}
@@ -1,5 +1,6 @@
1
1
  import pg from "pg";
2
2
  import { readFileSync } from "node:fs";
3
+
3
4
  //#region src/initScript.ts
4
5
  const { Client } = pg;
5
6
  /**
@@ -16,14 +17,13 @@ function parseInitScript(content, env) {
16
17
  const lines = content.split("\n");
17
18
  let inHeredoc = false;
18
19
  let currentBlock = [];
19
- for (const line of lines) if (inHeredoc) {
20
- if (/^\s*EOSQL\s*$/.test(line)) {
21
- const sql = substituteEnvVars(currentBlock.join("\n"), env);
22
- blocks.push(sql);
23
- currentBlock = [];
24
- inHeredoc = false;
25
- } else currentBlock.push(line);
26
- } else if (line.includes("<<-EOSQL") || line.includes("<< EOSQL") || line.includes("<<EOSQL")) {
20
+ for (const line of lines) if (inHeredoc) if (/^\s*EOSQL\s*$/.test(line)) {
21
+ const sql = substituteEnvVars(currentBlock.join("\n"), env);
22
+ blocks.push(sql);
23
+ currentBlock = [];
24
+ inHeredoc = false;
25
+ } else currentBlock.push(line);
26
+ else if (line.includes("<<-EOSQL") || line.includes("<< EOSQL") || line.includes("<<EOSQL")) {
27
27
  inHeredoc = true;
28
28
  currentBlock = [];
29
29
  }
@@ -69,7 +69,9 @@ function substituteEnvVars(sql, env) {
69
69
  * ```
70
70
  */
71
71
  async function runInitScript(scriptPath, databaseUrl, env) {
72
- const blocks = parseInitScript(readFileSync(scriptPath, "utf-8"), env ?? { ...process.env });
72
+ const content = readFileSync(scriptPath, "utf-8");
73
+ const resolvedEnv = env ?? { ...process.env };
74
+ const blocks = parseInitScript(content, resolvedEnv);
73
75
  if (blocks.length === 0) return;
74
76
  const url = new URL(databaseUrl);
75
77
  const client = new Client({
@@ -86,7 +88,7 @@ async function runInitScript(scriptPath, databaseUrl, env) {
86
88
  await client.end();
87
89
  }
88
90
  }
91
+
89
92
  //#endregion
90
93
  export { parseInitScript, runInitScript };
91
-
92
94
  //# sourceMappingURL=initScript.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"initScript.mjs","names":[],"sources":["../src/initScript.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport pg from 'pg';\n\nconst { Client } = pg;\n\n/**\n * Parse a shell init script (like docker/postgres/init.sh) and extract\n * SQL blocks from heredoc sections (<<-EOSQL ... EOSQL).\n *\n * @param content - The shell script content\n * @param env - Environment variables to substitute ($VAR_NAME references)\n * @returns Array of SQL strings ready to execute\n * @internal Exported for testing\n */\nexport function parseInitScript(\n\tcontent: string,\n\tenv: Record<string, string>,\n): string[] {\n\tconst blocks: string[] = [];\n\tconst lines = content.split('\\n');\n\tlet inHeredoc = false;\n\tlet currentBlock: string[] = [];\n\n\tfor (const line of lines) {\n\t\tif (inHeredoc) {\n\t\t\t// Check for heredoc terminator (EOSQL at start of line, with optional leading whitespace)\n\t\t\tif (/^\\s*EOSQL\\s*$/.test(line)) {\n\t\t\t\tconst sql = substituteEnvVars(currentBlock.join('\\n'), env);\n\t\t\t\tblocks.push(sql);\n\t\t\t\tcurrentBlock = [];\n\t\t\t\tinHeredoc = false;\n\t\t\t} else {\n\t\t\t\tcurrentBlock.push(line);\n\t\t\t}\n\t\t} else if (\n\t\t\tline.includes('<<-EOSQL') ||\n\t\t\tline.includes('<< EOSQL') ||\n\t\t\tline.includes('<<EOSQL')\n\t\t) {\n\t\t\tinHeredoc = true;\n\t\t\tcurrentBlock = [];\n\t\t}\n\t}\n\n\treturn blocks;\n}\n\n/**\n * Replace shell variable references ($VAR_NAME and ${VAR_NAME})\n * with values from the provided env object.\n */\nfunction substituteEnvVars(sql: string, env: Record<string, string>): string {\n\t// Replace ${VAR_NAME} syntax\n\tlet result = sql.replace(/\\$\\{(\\w+)\\}/g, (_, name) => env[name] ?? '');\n\t// Replace $VAR_NAME syntax (word boundary after)\n\tresult = result.replace(/\\$(\\w+)/g, (_, name) => env[name] ?? '');\n\t// Unescape bash-escaped dollar signs (\\$ → $) AFTER variable substitution\n\t// This handles PL/pgSQL dollar-quoting like DO \\$\\$ ... END \\$\\$;\n\tresult = result.replace(/\\\\\\$/g, '$');\n\treturn result;\n}\n\n/**\n * Read a postgres init script, parse out the SQL blocks,\n * substitute environment variables, and execute against a database.\n *\n * This is intended to run `docker/postgres/init.sh` against a test database\n * so that per-app users and schemas are created (matching what Docker does\n * on first volume initialization).\n *\n * Uses `CREATE ... IF NOT EXISTS` and `DO $$ ... END $$` wrappers where\n * needed so the script is idempotent.\n *\n * @param scriptPath - Path to the init.sh file\n * @param databaseUrl - PostgreSQL connection URL (should point to the test database)\n *\n * @example\n * ```typescript\n * // In your globalSetup.ts\n * import { runInitScript } from '@geekmidas/testkit/postgres';\n * import { Credentials } from '@geekmidas/envkit/credentials';\n *\n * const cleanup = await migrator.start();\n *\n * // Create per-app users in the test database\n * await runInitScript('docker/postgres/init.sh', Credentials.DATABASE_URL, {\n * ...process.env,\n * ...Credentials,\n * });\n * ```\n */\nexport async function runInitScript(\n\tscriptPath: string,\n\tdatabaseUrl: string,\n\tenv?: Record<string, string>,\n): Promise<void> {\n\tconst content = readFileSync(scriptPath, 'utf-8');\n\tconst resolvedEnv = env ?? ({ ...process.env } as Record<string, string>);\n\tconst blocks = parseInitScript(content, resolvedEnv);\n\n\tif (blocks.length === 0) {\n\t\treturn;\n\t}\n\n\tconst url = new URL(databaseUrl);\n\tconst client = new Client({\n\t\tuser: url.username,\n\t\tpassword: decodeURIComponent(url.password),\n\t\thost: url.hostname,\n\t\tport: parseInt(url.port, 10),\n\t\tdatabase: url.pathname.slice(1),\n\t});\n\n\ttry {\n\t\tawait client.connect();\n\t\tfor (const sql of blocks) {\n\t\t\tawait client.query(sql);\n\t\t}\n\t} finally {\n\t\tawait client.end();\n\t}\n}\n"],"mappings":";;;AAGA,MAAM,EAAE,WAAW;;;;;;;;;;AAWnB,SAAgB,gBACf,SACA,KACW;CACX,MAAM,SAAmB,CAAC;CAC1B,MAAM,QAAQ,QAAQ,MAAM,IAAI;CAChC,IAAI,YAAY;CAChB,IAAI,eAAyB,CAAC;CAE9B,KAAK,MAAM,QAAQ,OAClB,IAAI,WAAW;EAEd,IAAI,gBAAgB,KAAK,IAAI,GAAG;GAC/B,MAAM,MAAM,kBAAkB,aAAa,KAAK,IAAI,GAAG,GAAG;GAC1D,OAAO,KAAK,GAAG;GACf,eAAe,CAAC;GAChB,YAAY;EACb,OACC,aAAa,KAAK,IAAI;CAExB,OAAO,IACN,KAAK,SAAS,UAAU,KACxB,KAAK,SAAS,UAAU,KACxB,KAAK,SAAS,SAAS,GACtB;EACD,YAAY;EACZ,eAAe,CAAC;CACjB;CAGD,OAAO;AACR;;;;;AAMA,SAAS,kBAAkB,KAAa,KAAqC;CAE5E,IAAI,SAAS,IAAI,QAAQ,iBAAiB,GAAG,SAAS,IAAI,SAAS,EAAE;CAErE,SAAS,OAAO,QAAQ,aAAa,GAAG,SAAS,IAAI,SAAS,EAAE;CAGhE,SAAS,OAAO,QAAQ,SAAS,GAAG;CACpC,OAAO;AACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,eAAsB,cACrB,YACA,aACA,KACgB;CAGhB,MAAM,SAAS,gBAFC,aAAa,YAAY,OAEJ,GADjB,OAAQ,EAAE,GAAG,QAAQ,IAAI,CACM;CAEnD,IAAI,OAAO,WAAW,GACrB;CAGD,MAAM,MAAM,IAAI,IAAI,WAAW;CAC/B,MAAM,SAAS,IAAI,OAAO;EACzB,MAAM,IAAI;EACV,UAAU,mBAAmB,IAAI,QAAQ;EACzC,MAAM,IAAI;EACV,MAAM,SAAS,IAAI,MAAM,EAAE;EAC3B,UAAU,IAAI,SAAS,MAAM,CAAC;CAC/B,CAAC;CAED,IAAI;EACH,MAAM,OAAO,QAAQ;EACrB,KAAK,MAAM,OAAO,QACjB,MAAM,OAAO,MAAM,GAAG;CAExB,UAAU;EACT,MAAM,OAAO,IAAI;CAClB;AACD"}
1
+ {"version":3,"file":"initScript.mjs","names":["content: string","env: Record<string, string>","blocks: string[]","currentBlock: string[]","sql: string","scriptPath: string","databaseUrl: string","env?: Record<string, string>"],"sources":["../src/initScript.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport pg from 'pg';\n\nconst { Client } = pg;\n\n/**\n * Parse a shell init script (like docker/postgres/init.sh) and extract\n * SQL blocks from heredoc sections (<<-EOSQL ... EOSQL).\n *\n * @param content - The shell script content\n * @param env - Environment variables to substitute ($VAR_NAME references)\n * @returns Array of SQL strings ready to execute\n * @internal Exported for testing\n */\nexport function parseInitScript(\n\tcontent: string,\n\tenv: Record<string, string>,\n): string[] {\n\tconst blocks: string[] = [];\n\tconst lines = content.split('\\n');\n\tlet inHeredoc = false;\n\tlet currentBlock: string[] = [];\n\n\tfor (const line of lines) {\n\t\tif (inHeredoc) {\n\t\t\t// Check for heredoc terminator (EOSQL at start of line, with optional leading whitespace)\n\t\t\tif (/^\\s*EOSQL\\s*$/.test(line)) {\n\t\t\t\tconst sql = substituteEnvVars(currentBlock.join('\\n'), env);\n\t\t\t\tblocks.push(sql);\n\t\t\t\tcurrentBlock = [];\n\t\t\t\tinHeredoc = false;\n\t\t\t} else {\n\t\t\t\tcurrentBlock.push(line);\n\t\t\t}\n\t\t} else if (\n\t\t\tline.includes('<<-EOSQL') ||\n\t\t\tline.includes('<< EOSQL') ||\n\t\t\tline.includes('<<EOSQL')\n\t\t) {\n\t\t\tinHeredoc = true;\n\t\t\tcurrentBlock = [];\n\t\t}\n\t}\n\n\treturn blocks;\n}\n\n/**\n * Replace shell variable references ($VAR_NAME and ${VAR_NAME})\n * with values from the provided env object.\n */\nfunction substituteEnvVars(sql: string, env: Record<string, string>): string {\n\t// Replace ${VAR_NAME} syntax\n\tlet result = sql.replace(/\\$\\{(\\w+)\\}/g, (_, name) => env[name] ?? '');\n\t// Replace $VAR_NAME syntax (word boundary after)\n\tresult = result.replace(/\\$(\\w+)/g, (_, name) => env[name] ?? '');\n\t// Unescape bash-escaped dollar signs (\\$ → $) AFTER variable substitution\n\t// This handles PL/pgSQL dollar-quoting like DO \\$\\$ ... END \\$\\$;\n\tresult = result.replace(/\\\\\\$/g, '$');\n\treturn result;\n}\n\n/**\n * Read a postgres init script, parse out the SQL blocks,\n * substitute environment variables, and execute against a database.\n *\n * This is intended to run `docker/postgres/init.sh` against a test database\n * so that per-app users and schemas are created (matching what Docker does\n * on first volume initialization).\n *\n * Uses `CREATE ... IF NOT EXISTS` and `DO $$ ... END $$` wrappers where\n * needed so the script is idempotent.\n *\n * @param scriptPath - Path to the init.sh file\n * @param databaseUrl - PostgreSQL connection URL (should point to the test database)\n *\n * @example\n * ```typescript\n * // In your globalSetup.ts\n * import { runInitScript } from '@geekmidas/testkit/postgres';\n * import { Credentials } from '@geekmidas/envkit/credentials';\n *\n * const cleanup = await migrator.start();\n *\n * // Create per-app users in the test database\n * await runInitScript('docker/postgres/init.sh', Credentials.DATABASE_URL, {\n * ...process.env,\n * ...Credentials,\n * });\n * ```\n */\nexport async function runInitScript(\n\tscriptPath: string,\n\tdatabaseUrl: string,\n\tenv?: Record<string, string>,\n): Promise<void> {\n\tconst content = readFileSync(scriptPath, 'utf-8');\n\tconst resolvedEnv = env ?? ({ ...process.env } as Record<string, string>);\n\tconst blocks = parseInitScript(content, resolvedEnv);\n\n\tif (blocks.length === 0) {\n\t\treturn;\n\t}\n\n\tconst url = new URL(databaseUrl);\n\tconst client = new Client({\n\t\tuser: url.username,\n\t\tpassword: decodeURIComponent(url.password),\n\t\thost: url.hostname,\n\t\tport: parseInt(url.port, 10),\n\t\tdatabase: url.pathname.slice(1),\n\t});\n\n\ttry {\n\t\tawait client.connect();\n\t\tfor (const sql of blocks) {\n\t\t\tawait client.query(sql);\n\t\t}\n\t} finally {\n\t\tawait client.end();\n\t}\n}\n"],"mappings":";;;;AAGA,MAAM,EAAE,QAAQ,GAAG;;;;;;;;;;AAWnB,SAAgB,gBACfA,SACAC,KACW;CACX,MAAMC,SAAmB,CAAE;CAC3B,MAAM,QAAQ,QAAQ,MAAM,KAAK;CACjC,IAAI,YAAY;CAChB,IAAIC,eAAyB,CAAE;AAE/B,MAAK,MAAM,QAAQ,MAClB,KAAI,UAEH,KAAI,gBAAgB,KAAK,KAAK,EAAE;EAC/B,MAAM,MAAM,kBAAkB,aAAa,KAAK,KAAK,EAAE,IAAI;AAC3D,SAAO,KAAK,IAAI;AAChB,iBAAe,CAAE;AACjB,cAAY;CACZ,MACA,cAAa,KAAK,KAAK;UAGxB,KAAK,SAAS,WAAW,IACzB,KAAK,SAAS,WAAW,IACzB,KAAK,SAAS,UAAU,EACvB;AACD,cAAY;AACZ,iBAAe,CAAE;CACjB;AAGF,QAAO;AACP;;;;;AAMD,SAAS,kBAAkBC,KAAaH,KAAqC;CAE5E,IAAI,SAAS,IAAI,QAAQ,gBAAgB,CAAC,GAAG,SAAS,IAAI,SAAS,GAAG;AAEtE,UAAS,OAAO,QAAQ,YAAY,CAAC,GAAG,SAAS,IAAI,SAAS,GAAG;AAGjE,UAAS,OAAO,QAAQ,SAAS,IAAI;AACrC,QAAO;AACP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BD,eAAsB,cACrBI,YACAC,aACAC,KACgB;CAChB,MAAM,UAAU,aAAa,YAAY,QAAQ;CACjD,MAAM,cAAc,OAAQ,EAAE,GAAG,QAAQ,IAAK;CAC9C,MAAM,SAAS,gBAAgB,SAAS,YAAY;AAEpD,KAAI,OAAO,WAAW,EACrB;CAGD,MAAM,MAAM,IAAI,IAAI;CACpB,MAAM,SAAS,IAAI,OAAO;EACzB,MAAM,IAAI;EACV,UAAU,mBAAmB,IAAI,SAAS;EAC1C,MAAM,IAAI;EACV,MAAM,SAAS,IAAI,MAAM,GAAG;EAC5B,UAAU,IAAI,SAAS,MAAM,EAAE;CAC/B;AAED,KAAI;AACH,QAAM,OAAO,SAAS;AACtB,OAAK,MAAM,OAAO,OACjB,OAAM,OAAO,MAAM,IAAI;CAExB,UAAS;AACT,QAAM,OAAO,KAAK;CAClB;AACD"}