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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (295) hide show
  1. package/README.md +74 -0
  2. package/dist/Factory.cjs +51 -2
  3. package/dist/Factory.cjs.map +1 -0
  4. package/dist/Factory.d.cts +143 -3
  5. package/dist/Factory.d.cts.map +1 -0
  6. package/dist/Factory.d.mts +143 -3
  7. package/dist/Factory.d.mts.map +1 -0
  8. package/dist/Factory.mjs +50 -2
  9. package/dist/Factory.mjs.map +1 -0
  10. package/dist/KyselyFactory.cjs +237 -4
  11. package/dist/KyselyFactory.cjs.map +1 -0
  12. package/dist/KyselyFactory.d.cts +224 -4
  13. package/dist/KyselyFactory.d.cts.map +1 -0
  14. package/dist/KyselyFactory.d.mts +224 -4
  15. package/dist/KyselyFactory.d.mts.map +1 -0
  16. package/dist/KyselyFactory.mjs +236 -4
  17. package/dist/KyselyFactory.mjs.map +1 -0
  18. package/dist/ObjectionFactory.cjs +265 -4
  19. package/dist/ObjectionFactory.cjs.map +1 -0
  20. package/dist/ObjectionFactory.d.cts +237 -4
  21. package/dist/ObjectionFactory.d.cts.map +1 -0
  22. package/dist/ObjectionFactory.d.mts +237 -4
  23. package/dist/ObjectionFactory.d.mts.map +1 -0
  24. package/dist/ObjectionFactory.mjs +264 -4
  25. package/dist/ObjectionFactory.mjs.map +1 -0
  26. package/dist/PostgresKyselyMigrator.cjs +94 -3
  27. package/dist/PostgresKyselyMigrator.cjs.map +1 -0
  28. package/dist/PostgresKyselyMigrator.d.cts +80 -3
  29. package/dist/PostgresKyselyMigrator.d.cts.map +1 -0
  30. package/dist/PostgresKyselyMigrator.d.mts +80 -3
  31. package/dist/PostgresKyselyMigrator.d.mts.map +1 -0
  32. package/dist/PostgresKyselyMigrator.mjs +93 -3
  33. package/dist/PostgresKyselyMigrator.mjs.map +1 -0
  34. package/dist/{PostgresMigrator-C_QQ6q35.d.mts → PostgresMigrator-CDPnnwMJ.d.cts} +11 -5
  35. package/dist/PostgresMigrator-CDPnnwMJ.d.cts.map +1 -0
  36. package/dist/{PostgresMigrator-CeYy-eHF.d.cts → PostgresMigrator-CDPnnwMJ.d.mts} +11 -5
  37. package/dist/PostgresMigrator-CDPnnwMJ.d.mts.map +1 -0
  38. package/dist/PostgresMigrator.cjs +178 -2
  39. package/dist/PostgresMigrator.cjs.map +1 -0
  40. package/dist/PostgresMigrator.d.cts +1 -1
  41. package/dist/PostgresMigrator.d.mts +1 -1
  42. package/dist/PostgresMigrator.mjs +175 -2
  43. package/dist/PostgresMigrator.mjs.map +1 -0
  44. package/dist/PostgresObjectionMigrator.cjs +118 -3
  45. package/dist/PostgresObjectionMigrator.cjs.map +1 -0
  46. package/dist/PostgresObjectionMigrator.d.cts +75 -3
  47. package/dist/PostgresObjectionMigrator.d.cts.map +1 -0
  48. package/dist/PostgresObjectionMigrator.d.mts +75 -3
  49. package/dist/PostgresObjectionMigrator.d.mts.map +1 -0
  50. package/dist/PostgresObjectionMigrator.mjs +117 -3
  51. package/dist/PostgresObjectionMigrator.mjs.map +1 -0
  52. package/dist/VitestKyselyTransactionIsolator.cjs +66 -3
  53. package/dist/VitestKyselyTransactionIsolator.cjs.map +1 -0
  54. package/dist/VitestKyselyTransactionIsolator.d.cts +60 -3
  55. package/dist/VitestKyselyTransactionIsolator.d.cts.map +1 -0
  56. package/dist/VitestKyselyTransactionIsolator.d.mts +60 -3
  57. package/dist/VitestKyselyTransactionIsolator.d.mts.map +1 -0
  58. package/dist/VitestKyselyTransactionIsolator.mjs +65 -3
  59. package/dist/VitestKyselyTransactionIsolator.mjs.map +1 -0
  60. package/dist/VitestObjectionTransactionIsolator.cjs +62 -3
  61. package/dist/VitestObjectionTransactionIsolator.cjs.map +1 -0
  62. package/dist/VitestObjectionTransactionIsolator.d.cts +56 -3
  63. package/dist/VitestObjectionTransactionIsolator.d.cts.map +1 -0
  64. package/dist/VitestObjectionTransactionIsolator.d.mts +56 -3
  65. package/dist/VitestObjectionTransactionIsolator.d.mts.map +1 -0
  66. package/dist/VitestObjectionTransactionIsolator.mjs +61 -3
  67. package/dist/VitestObjectionTransactionIsolator.mjs.map +1 -0
  68. package/dist/VitestTransactionIsolator.cjs +187 -4
  69. package/dist/VitestTransactionIsolator.cjs.map +1 -0
  70. package/dist/VitestTransactionIsolator.d.cts +219 -2
  71. package/dist/VitestTransactionIsolator.d.cts.map +1 -0
  72. package/dist/VitestTransactionIsolator.d.mts +219 -2
  73. package/dist/VitestTransactionIsolator.d.mts.map +1 -0
  74. package/dist/VitestTransactionIsolator.mjs +184 -2
  75. package/dist/VitestTransactionIsolator.mjs.map +1 -0
  76. package/dist/aws.cjs +3 -4
  77. package/dist/aws.cjs.map +1 -1
  78. package/dist/aws.d.cts +3 -8
  79. package/dist/aws.d.cts.map +1 -1
  80. package/dist/aws.d.mts +3 -8
  81. package/dist/aws.d.mts.map +1 -1
  82. package/dist/aws.mjs +1 -2
  83. package/dist/aws.mjs.map +1 -1
  84. package/dist/benchmark.cjs +2 -2
  85. package/dist/benchmark.cjs.map +1 -1
  86. package/dist/benchmark.d.cts +4 -6
  87. package/dist/benchmark.d.cts.map +1 -1
  88. package/dist/benchmark.d.mts +4 -6
  89. package/dist/benchmark.d.mts.map +1 -1
  90. package/dist/benchmark.mjs +1 -1
  91. package/dist/benchmark.mjs.map +1 -1
  92. package/dist/better-auth.cjs +17 -8
  93. package/dist/better-auth.cjs.map +1 -1
  94. package/dist/better-auth.d.cts +13142 -5
  95. package/dist/better-auth.d.cts.map +1 -1
  96. package/dist/better-auth.d.mts +13142 -5
  97. package/dist/better-auth.d.mts.map +1 -1
  98. package/dist/better-auth.mjs +15 -6
  99. package/dist/better-auth.mjs.map +1 -1
  100. package/dist/browser.cjs +127 -0
  101. package/dist/browser.cjs.map +1 -0
  102. package/dist/browser.d.cts +47 -0
  103. package/dist/browser.d.cts.map +1 -0
  104. package/dist/browser.d.mts +47 -0
  105. package/dist/browser.d.mts.map +1 -0
  106. package/dist/browser.mjs +125 -0
  107. package/dist/browser.mjs.map +1 -0
  108. package/dist/context.cjs +80 -0
  109. package/dist/context.cjs.map +1 -0
  110. package/dist/context.d.cts +55 -0
  111. package/dist/context.d.cts.map +1 -0
  112. package/dist/context.d.mts +55 -0
  113. package/dist/context.d.mts.map +1 -0
  114. package/dist/context.mjs +73 -0
  115. package/dist/context.mjs.map +1 -0
  116. package/dist/faker.cjs +313 -8
  117. package/dist/faker.cjs.map +1 -0
  118. package/dist/faker.d.cts +169 -2
  119. package/dist/faker.d.cts.map +1 -0
  120. package/dist/faker.d.mts +169 -2
  121. package/dist/faker.d.mts.map +1 -0
  122. package/dist/faker.mjs +305 -2
  123. package/dist/faker.mjs.map +1 -0
  124. package/dist/helpers.cjs +6 -5
  125. package/dist/helpers.cjs.map +1 -1
  126. package/dist/helpers.d.cts +1 -5
  127. package/dist/helpers.d.cts.map +1 -1
  128. package/dist/helpers.d.mts +1 -5
  129. package/dist/helpers.d.mts.map +1 -1
  130. package/dist/helpers.mjs +1 -2
  131. package/dist/helpers.mjs.map +1 -1
  132. package/dist/initScript.cjs +15 -15
  133. package/dist/initScript.cjs.map +1 -1
  134. package/dist/initScript.d.cts +2 -4
  135. package/dist/initScript.d.cts.map +1 -1
  136. package/dist/initScript.d.mts +2 -4
  137. package/dist/initScript.d.mts.map +1 -1
  138. package/dist/initScript.mjs +10 -12
  139. package/dist/initScript.mjs.map +1 -1
  140. package/dist/kysely.cjs +10 -13
  141. package/dist/kysely.cjs.map +1 -1
  142. package/dist/kysely.d.cts +10 -14
  143. package/dist/kysely.d.cts.map +1 -1
  144. package/dist/kysely.d.mts +10 -14
  145. package/dist/kysely.d.mts.map +1 -1
  146. package/dist/kysely.mjs +10 -14
  147. package/dist/kysely.mjs.map +1 -1
  148. package/dist/logger.cjs +3 -4
  149. package/dist/logger.cjs.map +1 -1
  150. package/dist/logger.d.cts +1 -5
  151. package/dist/logger.d.cts.map +1 -1
  152. package/dist/logger.d.mts +1 -5
  153. package/dist/logger.d.mts.map +1 -1
  154. package/dist/logger.mjs +1 -2
  155. package/dist/logger.mjs.map +1 -1
  156. package/dist/mailbox.cjs +95 -0
  157. package/dist/mailbox.cjs.map +1 -0
  158. package/dist/mailbox.d.cts +58 -0
  159. package/dist/mailbox.d.cts.map +1 -0
  160. package/dist/mailbox.d.mts +58 -0
  161. package/dist/mailbox.d.mts.map +1 -0
  162. package/dist/mailbox.mjs +92 -0
  163. package/dist/mailbox.mjs.map +1 -0
  164. package/dist/objection.cjs +10 -13
  165. package/dist/objection.cjs.map +1 -1
  166. package/dist/objection.d.cts +10 -14
  167. package/dist/objection.d.cts.map +1 -1
  168. package/dist/objection.d.mts +10 -14
  169. package/dist/objection.d.mts.map +1 -1
  170. package/dist/objection.mjs +10 -14
  171. package/dist/objection.mjs.map +1 -1
  172. package/dist/os/directory.cjs +31 -2
  173. package/dist/os/directory.cjs.map +1 -0
  174. package/dist/os/directory.d.cts +9 -2
  175. package/dist/os/directory.d.cts.map +1 -0
  176. package/dist/os/directory.d.mts +9 -2
  177. package/dist/os/directory.d.mts.map +1 -0
  178. package/dist/os/directory.mjs +25 -2
  179. package/dist/os/directory.mjs.map +1 -0
  180. package/dist/os/index.cjs +3 -3
  181. package/dist/os/index.d.cts +1 -1
  182. package/dist/os/index.d.mts +1 -1
  183. package/dist/os/index.mjs +2 -3
  184. package/dist/requestContext.cjs +10 -11
  185. package/dist/requestContext.cjs.map +1 -1
  186. package/dist/requestContext.d.cts +4 -8
  187. package/dist/requestContext.d.cts.map +1 -1
  188. package/dist/requestContext.d.mts +4 -8
  189. package/dist/requestContext.d.mts.map +1 -1
  190. package/dist/requestContext.mjs +1 -2
  191. package/dist/requestContext.mjs.map +1 -1
  192. package/dist/{chunk-CUT6urMc.cjs → rolldown-runtime-VH7oDXx4.cjs} +8 -10
  193. package/dist/timer.cjs +2 -2
  194. package/dist/timer.cjs.map +1 -1
  195. package/dist/timer.d.cts +1 -4
  196. package/dist/timer.d.cts.map +1 -1
  197. package/dist/timer.d.mts +1 -4
  198. package/dist/timer.d.mts.map +1 -1
  199. package/dist/timer.mjs +1 -1
  200. package/dist/timer.mjs.map +1 -1
  201. package/dist/transactions.cjs +123 -0
  202. package/dist/transactions.cjs.map +1 -0
  203. package/dist/transactions.d.cts +44 -0
  204. package/dist/transactions.d.cts.map +1 -0
  205. package/dist/transactions.d.mts +44 -0
  206. package/dist/transactions.d.mts.map +1 -0
  207. package/dist/transactions.mjs +118 -0
  208. package/dist/transactions.mjs.map +1 -0
  209. package/package.json +51 -8
  210. package/dist/Factory-AWn1IulI.d.cts +0 -147
  211. package/dist/Factory-AWn1IulI.d.cts.map +0 -1
  212. package/dist/Factory-BFVnMMCC.mjs +0 -51
  213. package/dist/Factory-BFVnMMCC.mjs.map +0 -1
  214. package/dist/Factory-BhjUOBWN.cjs +0 -57
  215. package/dist/Factory-BhjUOBWN.cjs.map +0 -1
  216. package/dist/Factory-C15SSK8_.d.mts +0 -147
  217. package/dist/Factory-C15SSK8_.d.mts.map +0 -1
  218. package/dist/KyselyFactory-BFqVIn_0.cjs +0 -246
  219. package/dist/KyselyFactory-BFqVIn_0.cjs.map +0 -1
  220. package/dist/KyselyFactory-C9Snz24z.d.mts +0 -228
  221. package/dist/KyselyFactory-C9Snz24z.d.mts.map +0 -1
  222. package/dist/KyselyFactory-CxUJCi--.d.cts +0 -228
  223. package/dist/KyselyFactory-CxUJCi--.d.cts.map +0 -1
  224. package/dist/KyselyFactory-DMswpwji.mjs +0 -241
  225. package/dist/KyselyFactory-DMswpwji.mjs.map +0 -1
  226. package/dist/ObjectionFactory-BeFBYcan.cjs +0 -272
  227. package/dist/ObjectionFactory-BeFBYcan.cjs.map +0 -1
  228. package/dist/ObjectionFactory-CYvaa0kU.d.cts +0 -241
  229. package/dist/ObjectionFactory-CYvaa0kU.d.cts.map +0 -1
  230. package/dist/ObjectionFactory-Cf2WI4o_.d.mts +0 -241
  231. package/dist/ObjectionFactory-Cf2WI4o_.d.mts.map +0 -1
  232. package/dist/ObjectionFactory-QCJ7u0Ql.mjs +0 -267
  233. package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +0 -1
  234. package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts +0 -84
  235. package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts.map +0 -1
  236. package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs +0 -101
  237. package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs.map +0 -1
  238. package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts +0 -84
  239. package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts.map +0 -1
  240. package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs +0 -95
  241. package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs.map +0 -1
  242. package/dist/PostgresMigrator-C_QQ6q35.d.mts.map +0 -1
  243. package/dist/PostgresMigrator-CeYy-eHF.d.cts.map +0 -1
  244. package/dist/PostgresMigrator-DVAY04qN.mjs +0 -166
  245. package/dist/PostgresMigrator-DVAY04qN.mjs.map +0 -1
  246. package/dist/PostgresMigrator-M9jpzOvN.cjs +0 -172
  247. package/dist/PostgresMigrator-M9jpzOvN.cjs.map +0 -1
  248. package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts +0 -79
  249. package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts.map +0 -1
  250. package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts +0 -79
  251. package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts.map +0 -1
  252. package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs +0 -123
  253. package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs.map +0 -1
  254. package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs +0 -118
  255. package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs.map +0 -1
  256. package/dist/VitestKyselyTransactionIsolator-1Saieke7.mjs +0 -67
  257. package/dist/VitestKyselyTransactionIsolator-1Saieke7.mjs.map +0 -1
  258. package/dist/VitestKyselyTransactionIsolator-BjJSXryR.cjs +0 -72
  259. package/dist/VitestKyselyTransactionIsolator-BjJSXryR.cjs.map +0 -1
  260. package/dist/VitestKyselyTransactionIsolator-CwlTo6yf.d.mts +0 -64
  261. package/dist/VitestKyselyTransactionIsolator-CwlTo6yf.d.mts.map +0 -1
  262. package/dist/VitestKyselyTransactionIsolator-DJasVuIZ.d.cts +0 -64
  263. package/dist/VitestKyselyTransactionIsolator-DJasVuIZ.d.cts.map +0 -1
  264. package/dist/VitestObjectionTransactionIsolator-B_VSWFum.mjs +0 -63
  265. package/dist/VitestObjectionTransactionIsolator-B_VSWFum.mjs.map +0 -1
  266. package/dist/VitestObjectionTransactionIsolator-CTTjvTPO.d.cts +0 -60
  267. package/dist/VitestObjectionTransactionIsolator-CTTjvTPO.d.cts.map +0 -1
  268. package/dist/VitestObjectionTransactionIsolator-CyZG6nq4.d.mts +0 -60
  269. package/dist/VitestObjectionTransactionIsolator-CyZG6nq4.d.mts.map +0 -1
  270. package/dist/VitestObjectionTransactionIsolator-DDoJTu7e.cjs +0 -68
  271. package/dist/VitestObjectionTransactionIsolator-DDoJTu7e.cjs.map +0 -1
  272. package/dist/VitestTransactionIsolator-BLaw80cx.d.mts +0 -223
  273. package/dist/VitestTransactionIsolator-BLaw80cx.d.mts.map +0 -1
  274. package/dist/VitestTransactionIsolator-CvwPecpl.mjs +0 -188
  275. package/dist/VitestTransactionIsolator-CvwPecpl.mjs.map +0 -1
  276. package/dist/VitestTransactionIsolator-DyiX-QtK.cjs +0 -206
  277. package/dist/VitestTransactionIsolator-DyiX-QtK.cjs.map +0 -1
  278. package/dist/VitestTransactionIsolator-glcxyS_R.d.cts +0 -223
  279. package/dist/VitestTransactionIsolator-glcxyS_R.d.cts.map +0 -1
  280. package/dist/directory-BxjqmtCT.mjs +0 -27
  281. package/dist/directory-BxjqmtCT.mjs.map +0 -1
  282. package/dist/directory-DD_xQoSh.cjs +0 -33
  283. package/dist/directory-DD_xQoSh.cjs.map +0 -1
  284. package/dist/directory-DiQ_DkaF.d.mts +0 -13
  285. package/dist/directory-DiQ_DkaF.d.mts.map +0 -1
  286. package/dist/directory-zIEh5ZPl.d.cts +0 -13
  287. package/dist/directory-zIEh5ZPl.d.cts.map +0 -1
  288. package/dist/faker-B14IEMIN.cjs +0 -304
  289. package/dist/faker-B14IEMIN.cjs.map +0 -1
  290. package/dist/faker-B6bmbGCM.d.mts +0 -166
  291. package/dist/faker-B6bmbGCM.d.mts.map +0 -1
  292. package/dist/faker-BGKYFoCT.mjs +0 -262
  293. package/dist/faker-BGKYFoCT.mjs.map +0 -1
  294. package/dist/faker-DvxiCtxc.d.cts +0 -166
  295. package/dist/faker-DvxiCtxc.d.cts.map +0 -1
@@ -1,241 +0,0 @@
1
- import { FakerFactory } from "./faker-B6bmbGCM.mjs";
2
- import { ExtractSeedAttrs, Factory, FactorySeed } from "./Factory-C15SSK8_.mjs";
3
- import { Knex } from "knex";
4
- import { Model } from "objection";
5
-
6
- //#region src/ObjectionFactory.d.ts
7
-
8
- /**
9
- * Factory implementation for Objection.js ORM, providing test data creation utilities.
10
- * Extends the base Factory class with Objection.js-specific database operations.
11
- *
12
- * @template Builders - Record of builder functions for creating entities
13
- * @template Seeds - Record of seed functions for complex test scenarios
14
- *
15
- * @example
16
- * ```typescript
17
- * // Define your models with Objection.js
18
- * class User extends Model {
19
- * static tableName = 'users';
20
- * }
21
- *
22
- * // Create builders
23
- * const builders = {
24
- * user: ObjectionFactory.createBuilder(User, ({ attrs, faker }) => ({
25
- * id: faker.string.uuid(),
26
- * name: faker.person.fullName(),
27
- * email: faker.internet.email(),
28
- * ...attrs
29
- * })),
30
- * post: ObjectionFactory.createBuilder(Post, ({ attrs }) => ({
31
- * title: 'Test Post',
32
- * content: 'Test content',
33
- * ...attrs
34
- * })),
35
- * };
36
- *
37
- * // Create factory instance
38
- * const factory = new ObjectionFactory(builders, seeds, knex);
39
- *
40
- * // Use in tests
41
- * const user = await factory.insert('user', { name: 'John Doe' });
42
- * ```
43
- */
44
- declare class ObjectionFactory<Builders extends Record<string, any>, Seeds extends Record<string, any>> extends Factory<Builders, Seeds> {
45
- private builders;
46
- private seeds;
47
- private db;
48
- /**
49
- * Creates a typed seed function with proper type inference.
50
- * Inherits from the base Factory class implementation.
51
- *
52
- * @template Seed - The seed function type
53
- * @param seedFn - The seed function to wrap (receives { attrs, factory, db } object)
54
- * @returns The same seed function with proper typing
55
- *
56
- * @example
57
- * ```typescript
58
- * const seeds = {
59
- * userWithPosts: ObjectionFactory.createSeed(
60
- * async ({ attrs, factory }) => {
61
- * const user = await factory.insert('user', attrs);
62
- * await factory.insertMany(3, 'post', { userId: user.id });
63
- * return user;
64
- * },
65
- * ),
66
- * };
67
- * ```
68
- */
69
- static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed;
70
- /**
71
- * Creates a typed builder function for Objection.js models.
72
- * This is a utility method that helps create builders with proper type inference.
73
- *
74
- * @template TModel - The Objection.js Model class type
75
- * @template Attrs - The attributes type for the builder (defaults to Partial of model)
76
- * @template Factory - The factory instance type
77
- * @template Result - The result type (defaults to the model instance)
78
- *
79
- * @param ModelClass - The Objection.js Model class
80
- * @param defaults - Optional function to provide default values (receives destructured context)
81
- * @param autoInsert - Whether to automatically insert the record (default: true)
82
- * @returns A builder function that creates and optionally inserts records
83
- *
84
- * @example
85
- * ```typescript
86
- * // Create a simple builder with defaults - destructure only what you need
87
- * const userBuilder = ObjectionFactory.createBuilder(User,
88
- * ({ attrs, faker }) => ({
89
- * id: faker.string.uuid(),
90
- * name: faker.person.fullName(),
91
- * email: faker.internet.email(),
92
- * createdAt: new Date(),
93
- * ...attrs
94
- * })
95
- * );
96
- *
97
- * // Only need faker? Just destructure that
98
- * const leaveTypeBuilder = ObjectionFactory.createBuilder(LeaveType,
99
- * ({ faker }) => ({
100
- * name: faker.helpers.arrayElement(['Annual', 'Sick', 'Maternity']),
101
- * code: faker.string.alpha({ length: 3, casing: 'upper' }),
102
- * })
103
- * );
104
- *
105
- * // Create a builder that doesn't auto-insert (useful for nested inserts)
106
- * const addressBuilder = ObjectionFactory.createBuilder(Address,
107
- * ({ attrs }) => ({
108
- * street: '123 Main St',
109
- * city: 'Anytown',
110
- * ...attrs
111
- * }),
112
- * false // Don't auto-insert
113
- * );
114
- *
115
- * // Use with relations
116
- * const postBuilder = ObjectionFactory.createBuilder(Post,
117
- * async ({ attrs, factory, faker }) => ({
118
- * title: faker.lorem.sentence(),
119
- * content: faker.lorem.paragraphs(),
120
- * authorId: attrs.authorId || (await factory.insert('user')).id,
121
- * ...attrs
122
- * })
123
- * );
124
- * ```
125
- */
126
- static createBuilder<TModel extends typeof Model, Attrs extends Partial<InstanceType<TModel>> = Partial<InstanceType<TModel>>, Factory = any, Result = InstanceType<TModel>>(ModelClass: TModel, defaults?: (context: {
127
- attrs: Attrs;
128
- factory: Factory;
129
- db: Knex;
130
- faker: FakerFactory;
131
- }) => Partial<InstanceType<TModel>> | Promise<Partial<InstanceType<TModel>>>, autoInsert?: boolean): (attrs: Attrs, factory: Factory, db: Knex, faker: FakerFactory) => Promise<Result>;
132
- /**
133
- * Creates a new ObjectionFactory instance.
134
- *
135
- * @param builders - Record of builder functions for creating individual entities
136
- * @param seeds - Record of seed functions for creating complex test scenarios
137
- * @param db - Knex database connection instance
138
- */
139
- constructor(builders: Builders, seeds: Seeds, db: Knex);
140
- /**
141
- * Inserts a single record into the database using the specified builder.
142
- * Uses Objection.js's insertGraph method to handle nested relations.
143
- *
144
- * @template K - The builder name (must be a key of Builders)
145
- * @param builderName - The name of the builder to use
146
- * @param attrs - Optional attributes to override builder defaults
147
- * @returns A promise resolving to the inserted record with all relations
148
- * @throws Error if the specified builder doesn't exist
149
- *
150
- * @example
151
- * ```typescript
152
- * // Insert with defaults
153
- * const user = await factory.insert('user');
154
- *
155
- * // Insert with overrides
156
- * const adminUser = await factory.insert('user', {
157
- * email: 'admin@example.com',
158
- * role: 'admin'
159
- * });
160
- *
161
- * // Insert with nested relations
162
- * const userWithProfile = await factory.insert('user', {
163
- * name: 'John Doe',
164
- * profile: {
165
- * bio: 'Software Developer',
166
- * avatar: 'avatar.jpg'
167
- * }
168
- * });
169
- * ```
170
- */
171
- insert<K extends keyof Builders>(builderName: K, attrs?: Parameters<Builders[K]>[0]): Promise<Awaited<ReturnType<Builders[K]>>>;
172
- /**
173
- * Inserts multiple records into the database using the specified builder.
174
- * Supports both static attributes and dynamic attribute generation via a function.
175
- *
176
- * @param count - The number of records to insert
177
- * @param builderName - The name of the builder to use
178
- * @param attrs - Static attributes or a function that generates attributes for each record
179
- * @returns A promise resolving to an array of inserted records
180
- * @throws Error if the specified builder doesn't exist
181
- *
182
- * @example
183
- * ```typescript
184
- * // Insert multiple with same attributes
185
- * const users = await factory.insertMany(5, 'user', { role: 'member' });
186
- *
187
- * // Insert multiple with dynamic attributes
188
- * const posts = await factory.insertMany(10, 'post', (idx) => ({
189
- * title: `Post ${idx + 1}`,
190
- * content: `Content for post ${idx + 1}`,
191
- * publishedAt: new Date()
192
- * }));
193
- *
194
- * // Create users with sequential emails
195
- * const admins = await factory.insertMany(3, 'user', (idx) => ({
196
- * email: `admin${idx + 1}@example.com`,
197
- * role: 'admin'
198
- * }));
199
- * ```
200
- */
201
- insertMany<K extends keyof Builders>(count: number, builderName: K, attrs?: Parameters<Builders[K]>[0]): Promise<Awaited<ReturnType<Builders[K]>>[]>;
202
- insertMany<K extends keyof Builders>(count: number, builderName: K, attrs: (idx: number, faker: FakerFactory) => Parameters<Builders[K]>[0]): Promise<Awaited<ReturnType<Builders[K]>>[]>;
203
- /**
204
- * Executes a seed function to create complex test scenarios with multiple related records.
205
- * Seeds are useful for setting up complete test environments with realistic data relationships.
206
- *
207
- * @template K - The seed name (must be a key of Seeds)
208
- * @param seedName - The name of the seed to execute
209
- * @param attrs - Optional configuration attributes for the seed
210
- * @returns The result of the seed function (typically the primary record created)
211
- * @throws Error if the specified seed doesn't exist
212
- *
213
- * @example
214
- * ```typescript
215
- * // Execute a simple seed
216
- * const user = await factory.seed('userWithProfile');
217
- *
218
- * // Execute a seed with configuration
219
- * const author = await factory.seed('authorWithBooks', {
220
- * bookCount: 5,
221
- * includeReviews: true
222
- * });
223
- *
224
- * // Use seed result in tests with Objection.js relations
225
- * const company = await factory.seed('companyWithDepartments', {
226
- * departmentCount: 3,
227
- * employeesPerDepartment: 10
228
- * });
229
- *
230
- * // Access eager loaded relations
231
- * const companyWithRelations = await Company.query()
232
- * .findById(company.id)
233
- * .withGraphFetched('[departments.employees]');
234
- * ```
235
- */
236
- seed<K extends keyof Seeds>(seedName: K, attrs?: ExtractSeedAttrs<Seeds[K]>): ReturnType<Seeds[K]>;
237
- }
238
- //# sourceMappingURL=ObjectionFactory.d.ts.map
239
- //#endregion
240
- export { ObjectionFactory };
241
- //# sourceMappingURL=ObjectionFactory-Cf2WI4o_.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ObjectionFactory-Cf2WI4o_.d.mts","names":[],"sources":["../src/ObjectionFactory.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAyCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0Gc,cA1GD,gBA0GC,CAAA,iBAzGI,MAyGJ,CAAA,MAAA,EAAA,GAAA,CAAA,EAAA,cAxGC,MAwGD,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,SAvGJ,OAuGI,CAvGI,QAuGJ,EAvGc,KAuGd,CAAA,CAAA;EAAM,QAAd,QAAA;EAAO,QAqDO,KAAA;EAAQ,QACX,EAAA;EAAK;;;;;;;;;;;;;;;;;;;;;EA2GX,OACuB,UAAA,CAAA,aAnPO,WAmPP,CAAA,CAAA,MAAA,EAnP4B,IAmP5B,CAAA,EAnPmC,IAmPnC;EAAQ;;;;;;;;;;;;;;;;;;;AAzQzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6CAmFO,qBACR,QAAQ,aAAa,WAAW,QAAQ,aAAa,kCAE1D,aAAa,qBAEV;WAEJ;aACE;QACL;WACG;QAEL,QAAQ,aAAa,WACrB,QAAQ,QAAQ,aAAa,0CAGzB,gBACE,aACL,aACG,iBACH,QAAQ;;;;;;;;wBAqDM,iBACH,WACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAoCgB,uBACf,WACL,WAAW,SAAS,SAC1B,QAAQ,QAAQ,WAAW,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BA+DN,sCAEnB,WACL,WAAW,SAAS,SAC1B,QAAQ,QAAQ,WAAW,SAAS;6BACN,sCAEnB,+BACe,iBAAiB,WAAW,SAAS,SAC/D,QAAQ,QAAQ,WAAW,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAgFlB,iBACV,WACF,iBAAiB,MAAM,MAC7B,WAAW,MAAM"}
@@ -1,267 +0,0 @@
1
- import { Factory } from "./Factory-BFVnMMCC.mjs";
2
- import { faker } from "./faker-BGKYFoCT.mjs";
3
-
4
- //#region src/ObjectionFactory.ts
5
- /**
6
- * Factory implementation for Objection.js ORM, providing test data creation utilities.
7
- * Extends the base Factory class with Objection.js-specific database operations.
8
- *
9
- * @template Builders - Record of builder functions for creating entities
10
- * @template Seeds - Record of seed functions for complex test scenarios
11
- *
12
- * @example
13
- * ```typescript
14
- * // Define your models with Objection.js
15
- * class User extends Model {
16
- * static tableName = 'users';
17
- * }
18
- *
19
- * // Create builders
20
- * const builders = {
21
- * user: ObjectionFactory.createBuilder(User, ({ attrs, faker }) => ({
22
- * id: faker.string.uuid(),
23
- * name: faker.person.fullName(),
24
- * email: faker.internet.email(),
25
- * ...attrs
26
- * })),
27
- * post: ObjectionFactory.createBuilder(Post, ({ attrs }) => ({
28
- * title: 'Test Post',
29
- * content: 'Test content',
30
- * ...attrs
31
- * })),
32
- * };
33
- *
34
- * // Create factory instance
35
- * const factory = new ObjectionFactory(builders, seeds, knex);
36
- *
37
- * // Use in tests
38
- * const user = await factory.insert('user', { name: 'John Doe' });
39
- * ```
40
- */
41
- var ObjectionFactory = class extends Factory {
42
- /**
43
- * Creates a typed seed function with proper type inference.
44
- * Inherits from the base Factory class implementation.
45
- *
46
- * @template Seed - The seed function type
47
- * @param seedFn - The seed function to wrap (receives { attrs, factory, db } object)
48
- * @returns The same seed function with proper typing
49
- *
50
- * @example
51
- * ```typescript
52
- * const seeds = {
53
- * userWithPosts: ObjectionFactory.createSeed(
54
- * async ({ attrs, factory }) => {
55
- * const user = await factory.insert('user', attrs);
56
- * await factory.insertMany(3, 'post', { userId: user.id });
57
- * return user;
58
- * },
59
- * ),
60
- * };
61
- * ```
62
- */
63
- static createSeed(seedFn) {
64
- return Factory.createSeed(seedFn);
65
- }
66
- /**
67
- * Creates a typed builder function for Objection.js models.
68
- * This is a utility method that helps create builders with proper type inference.
69
- *
70
- * @template TModel - The Objection.js Model class type
71
- * @template Attrs - The attributes type for the builder (defaults to Partial of model)
72
- * @template Factory - The factory instance type
73
- * @template Result - The result type (defaults to the model instance)
74
- *
75
- * @param ModelClass - The Objection.js Model class
76
- * @param defaults - Optional function to provide default values (receives destructured context)
77
- * @param autoInsert - Whether to automatically insert the record (default: true)
78
- * @returns A builder function that creates and optionally inserts records
79
- *
80
- * @example
81
- * ```typescript
82
- * // Create a simple builder with defaults - destructure only what you need
83
- * const userBuilder = ObjectionFactory.createBuilder(User,
84
- * ({ attrs, faker }) => ({
85
- * id: faker.string.uuid(),
86
- * name: faker.person.fullName(),
87
- * email: faker.internet.email(),
88
- * createdAt: new Date(),
89
- * ...attrs
90
- * })
91
- * );
92
- *
93
- * // Only need faker? Just destructure that
94
- * const leaveTypeBuilder = ObjectionFactory.createBuilder(LeaveType,
95
- * ({ faker }) => ({
96
- * name: faker.helpers.arrayElement(['Annual', 'Sick', 'Maternity']),
97
- * code: faker.string.alpha({ length: 3, casing: 'upper' }),
98
- * })
99
- * );
100
- *
101
- * // Create a builder that doesn't auto-insert (useful for nested inserts)
102
- * const addressBuilder = ObjectionFactory.createBuilder(Address,
103
- * ({ attrs }) => ({
104
- * street: '123 Main St',
105
- * city: 'Anytown',
106
- * ...attrs
107
- * }),
108
- * false // Don't auto-insert
109
- * );
110
- *
111
- * // Use with relations
112
- * const postBuilder = ObjectionFactory.createBuilder(Post,
113
- * async ({ attrs, factory, faker }) => ({
114
- * title: faker.lorem.sentence(),
115
- * content: faker.lorem.paragraphs(),
116
- * authorId: attrs.authorId || (await factory.insert('user')).id,
117
- * ...attrs
118
- * })
119
- * );
120
- * ```
121
- */
122
- static createBuilder(ModelClass, defaults, autoInsert) {
123
- return async (attrs, factory, db, fakerInstance) => {
124
- let data = { ...attrs };
125
- if (defaults) {
126
- const defaultValues = await defaults({
127
- attrs,
128
- factory,
129
- db,
130
- faker: fakerInstance
131
- });
132
- data = {
133
- ...defaultValues,
134
- ...data
135
- };
136
- }
137
- const model = ModelClass.fromJson(data);
138
- if (autoInsert !== false) {
139
- const insertData = Object.entries(model).reduce((acc, [key, value]) => {
140
- if (value !== void 0 && key !== "id") acc[key] = value;
141
- return acc;
142
- }, {});
143
- const result = await ModelClass.query(db).insert(insertData);
144
- return result;
145
- } else return model;
146
- };
147
- }
148
- /**
149
- * Creates a new ObjectionFactory instance.
150
- *
151
- * @param builders - Record of builder functions for creating individual entities
152
- * @param seeds - Record of seed functions for creating complex test scenarios
153
- * @param db - Knex database connection instance
154
- */
155
- constructor(builders, seeds, db) {
156
- super();
157
- this.builders = builders;
158
- this.seeds = seeds;
159
- this.db = db;
160
- }
161
- /**
162
- * Inserts a single record into the database using the specified builder.
163
- * Uses Objection.js's insertGraph method to handle nested relations.
164
- *
165
- * @template K - The builder name (must be a key of Builders)
166
- * @param builderName - The name of the builder to use
167
- * @param attrs - Optional attributes to override builder defaults
168
- * @returns A promise resolving to the inserted record with all relations
169
- * @throws Error if the specified builder doesn't exist
170
- *
171
- * @example
172
- * ```typescript
173
- * // Insert with defaults
174
- * const user = await factory.insert('user');
175
- *
176
- * // Insert with overrides
177
- * const adminUser = await factory.insert('user', {
178
- * email: 'admin@example.com',
179
- * role: 'admin'
180
- * });
181
- *
182
- * // Insert with nested relations
183
- * const userWithProfile = await factory.insert('user', {
184
- * name: 'John Doe',
185
- * profile: {
186
- * bio: 'Software Developer',
187
- * avatar: 'avatar.jpg'
188
- * }
189
- * });
190
- * ```
191
- */
192
- async insert(builderName, attrs) {
193
- if (!(builderName in this.builders)) throw new Error(`Factory "${builderName}" does not exist. Make sure it is correct and registered in src/test/setup.ts`);
194
- const result = await this.builders[builderName](attrs || {}, this, this.db, faker);
195
- if (result && typeof result.$query === "function") {
196
- const insertData = Object.entries(result).reduce((acc, [key, value]) => {
197
- if (value !== void 0 && key !== "id") acc[key] = value;
198
- return acc;
199
- }, {});
200
- return await result.constructor.query(this.db).insert(insertData);
201
- }
202
- return result;
203
- }
204
- async insertMany(count, builderName, attrs) {
205
- if (!(builderName in this.builders)) throw new Error(`Builder "${builderName}" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`);
206
- const records = [];
207
- for (let i = 0; i < count; i++) {
208
- const newAttrs = typeof attrs === "function" ? await attrs(i, faker) : attrs;
209
- records.push(this.builders[builderName](newAttrs, this, this.db, faker).then((record) => {
210
- if (record && typeof record.$query === "function") {
211
- const insertData = Object.entries(record).reduce((acc, [key, value]) => {
212
- if (value !== void 0 && key !== "id") acc[key] = value;
213
- return acc;
214
- }, {});
215
- return record.constructor.query(this.db).insert(insertData);
216
- }
217
- return record;
218
- }));
219
- }
220
- return Promise.all(records);
221
- }
222
- /**
223
- * Executes a seed function to create complex test scenarios with multiple related records.
224
- * Seeds are useful for setting up complete test environments with realistic data relationships.
225
- *
226
- * @template K - The seed name (must be a key of Seeds)
227
- * @param seedName - The name of the seed to execute
228
- * @param attrs - Optional configuration attributes for the seed
229
- * @returns The result of the seed function (typically the primary record created)
230
- * @throws Error if the specified seed doesn't exist
231
- *
232
- * @example
233
- * ```typescript
234
- * // Execute a simple seed
235
- * const user = await factory.seed('userWithProfile');
236
- *
237
- * // Execute a seed with configuration
238
- * const author = await factory.seed('authorWithBooks', {
239
- * bookCount: 5,
240
- * includeReviews: true
241
- * });
242
- *
243
- * // Use seed result in tests with Objection.js relations
244
- * const company = await factory.seed('companyWithDepartments', {
245
- * departmentCount: 3,
246
- * employeesPerDepartment: 10
247
- * });
248
- *
249
- * // Access eager loaded relations
250
- * const companyWithRelations = await Company.query()
251
- * .findById(company.id)
252
- * .withGraphFetched('[departments.employees]');
253
- * ```
254
- */
255
- seed(seedName, attrs) {
256
- if (!(seedName in this.seeds)) throw new Error(`Seed "${seedName}" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`);
257
- return this.seeds[seedName]({
258
- attrs: attrs || {},
259
- factory: this,
260
- db: this.db
261
- });
262
- }
263
- };
264
-
265
- //#endregion
266
- export { ObjectionFactory };
267
- //# sourceMappingURL=ObjectionFactory-QCJ7u0Ql.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ObjectionFactory-QCJ7u0Ql.mjs","names":["seedFn: Seed","ModelClass: TModel","defaults?: (context: {\n\t\t\tattrs: Attrs;\n\t\t\tfactory: Factory;\n\t\t\tdb: Knex;\n\t\t\tfaker: FakerFactory;\n\t\t}) =>\n\t\t\t| Partial<InstanceType<TModel>>\n\t\t\t| Promise<Partial<InstanceType<TModel>>>","autoInsert?: boolean","attrs: Attrs","factory: Factory","db: Knex","fakerInstance: FakerFactory","data: Partial<InstanceType<TModel>>","builders: Builders","seeds: Seeds","builderName: K","attrs?: Parameters<Builders[K]>[0]","count: number","attrs?: any","records: any[]","record: any","seedName: K","attrs?: ExtractSeedAttrs<Seeds[K]>"],"sources":["../src/ObjectionFactory.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { Model } from 'objection';\nimport { type ExtractSeedAttrs, Factory, type FactorySeed } from './Factory';\nimport { type FakerFactory, faker } from './faker';\n\n/**\n * Factory implementation for Objection.js ORM, providing test data creation utilities.\n * Extends the base Factory class with Objection.js-specific database operations.\n *\n * @template Builders - Record of builder functions for creating entities\n * @template Seeds - Record of seed functions for complex test scenarios\n *\n * @example\n * ```typescript\n * // Define your models with Objection.js\n * class User extends Model {\n * static tableName = 'users';\n * }\n *\n * // Create builders\n * const builders = {\n * user: ObjectionFactory.createBuilder(User, ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * })),\n * post: ObjectionFactory.createBuilder(Post, ({ attrs }) => ({\n * title: 'Test Post',\n * content: 'Test content',\n * ...attrs\n * })),\n * };\n *\n * // Create factory instance\n * const factory = new ObjectionFactory(builders, seeds, knex);\n *\n * // Use in tests\n * const user = await factory.insert('user', { name: 'John Doe' });\n * ```\n */\nexport class ObjectionFactory<\n\tBuilders extends Record<string, any>,\n\tSeeds extends Record<string, any>,\n> extends Factory<Builders, Seeds> {\n\t/**\n\t * Creates a typed seed function with proper type inference.\n\t * Inherits from the base Factory class implementation.\n\t *\n\t * @template Seed - The seed function type\n\t * @param seedFn - The seed function to wrap (receives { attrs, factory, db } object)\n\t * @returns The same seed function with proper typing\n\t *\n\t * @example\n\t * ```typescript\n\t * const seeds = {\n\t * userWithPosts: ObjectionFactory.createSeed(\n\t * async ({ attrs, factory }) => {\n\t * const user = await factory.insert('user', attrs);\n\t * await factory.insertMany(3, 'post', { userId: user.id });\n\t * return user;\n\t * },\n\t * ),\n\t * };\n\t * ```\n\t */\n\tstatic override createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n\t\treturn Factory.createSeed(seedFn);\n\t}\n\n\t/**\n\t * Creates a typed builder function for Objection.js models.\n\t * This is a utility method that helps create builders with proper type inference.\n\t *\n\t * @template TModel - The Objection.js Model class type\n\t * @template Attrs - The attributes type for the builder (defaults to Partial of model)\n\t * @template Factory - The factory instance type\n\t * @template Result - The result type (defaults to the model instance)\n\t *\n\t * @param ModelClass - The Objection.js Model class\n\t * @param defaults - Optional function to provide default values (receives destructured context)\n\t * @param autoInsert - Whether to automatically insert the record (default: true)\n\t * @returns A builder function that creates and optionally inserts records\n\t *\n\t * @example\n\t * ```typescript\n\t * // Create a simple builder with defaults - destructure only what you need\n\t * const userBuilder = ObjectionFactory.createBuilder(User,\n\t * ({ attrs, faker }) => ({\n\t * id: faker.string.uuid(),\n\t * name: faker.person.fullName(),\n\t * email: faker.internet.email(),\n\t * createdAt: new Date(),\n\t * ...attrs\n\t * })\n\t * );\n\t *\n\t * // Only need faker? Just destructure that\n\t * const leaveTypeBuilder = ObjectionFactory.createBuilder(LeaveType,\n\t * ({ faker }) => ({\n\t * name: faker.helpers.arrayElement(['Annual', 'Sick', 'Maternity']),\n\t * code: faker.string.alpha({ length: 3, casing: 'upper' }),\n\t * })\n\t * );\n\t *\n\t * // Create a builder that doesn't auto-insert (useful for nested inserts)\n\t * const addressBuilder = ObjectionFactory.createBuilder(Address,\n\t * ({ attrs }) => ({\n\t * street: '123 Main St',\n\t * city: 'Anytown',\n\t * ...attrs\n\t * }),\n\t * false // Don't auto-insert\n\t * );\n\t *\n\t * // Use with relations\n\t * const postBuilder = ObjectionFactory.createBuilder(Post,\n\t * async ({ attrs, factory, faker }) => ({\n\t * title: faker.lorem.sentence(),\n\t * content: faker.lorem.paragraphs(),\n\t * authorId: attrs.authorId || (await factory.insert('user')).id,\n\t * ...attrs\n\t * })\n\t * );\n\t * ```\n\t */\n\tstatic createBuilder<\n\t\tTModel extends typeof Model,\n\t\tAttrs extends Partial<InstanceType<TModel>> = Partial<InstanceType<TModel>>,\n\t\tFactory = any,\n\t\tResult = InstanceType<TModel>,\n\t>(\n\t\tModelClass: TModel,\n\t\tdefaults?: (context: {\n\t\t\tattrs: Attrs;\n\t\t\tfactory: Factory;\n\t\t\tdb: Knex;\n\t\t\tfaker: FakerFactory;\n\t\t}) =>\n\t\t\t| Partial<InstanceType<TModel>>\n\t\t\t| Promise<Partial<InstanceType<TModel>>>,\n\t\tautoInsert?: boolean,\n\t): (\n\t\tattrs: Attrs,\n\t\tfactory: Factory,\n\t\tdb: Knex,\n\t\tfaker: FakerFactory,\n\t) => Promise<Result> {\n\t\treturn async (\n\t\t\tattrs: Attrs,\n\t\t\tfactory: Factory,\n\t\t\tdb: Knex,\n\t\t\tfakerInstance: FakerFactory,\n\t\t) => {\n\t\t\t// Start with attributes\n\t\t\tlet data: Partial<InstanceType<TModel>> = { ...attrs };\n\n\t\t\t// Apply defaults\n\t\t\tif (defaults) {\n\t\t\t\tconst defaultValues = await defaults({\n\t\t\t\t\tattrs,\n\t\t\t\t\tfactory,\n\t\t\t\t\tdb,\n\t\t\t\t\tfaker: fakerInstance,\n\t\t\t\t});\n\t\t\t\tdata = { ...defaultValues, ...data };\n\t\t\t}\n\n\t\t\t// Create model instance\n\t\t\tconst model = ModelClass.fromJson(data) as InstanceType<TModel>;\n\n\t\t\t// Handle insertion based on autoInsert flag\n\t\t\tif (autoInsert !== false) {\n\t\t\t\t// Auto insert is enabled by default\n\t\t\t\t// Extract only defined values for insertion\n\t\t\t\tconst insertData = Object.entries(model).reduce((acc, [key, value]) => {\n\t\t\t\t\tif (value !== undefined && key !== 'id') {\n\t\t\t\t\t\tacc[key] = value;\n\t\t\t\t\t}\n\t\t\t\t\treturn acc;\n\t\t\t\t}, {} as any);\n\n\t\t\t\t// Use static query method to insert data directly\n\t\t\t\tconst result = await ModelClass.query(db).insert(insertData);\n\t\t\t\treturn result as Result;\n\t\t\t} else {\n\t\t\t\t// Return model for factory to handle insertion\n\t\t\t\treturn model as Result;\n\t\t\t}\n\t\t};\n\t}\n\n\t/**\n\t * Creates a new ObjectionFactory instance.\n\t *\n\t * @param builders - Record of builder functions for creating individual entities\n\t * @param seeds - Record of seed functions for creating complex test scenarios\n\t * @param db - Knex database connection instance\n\t */\n\tconstructor(\n\t\tprivate builders: Builders,\n\t\tprivate seeds: Seeds,\n\t\tprivate db: Knex,\n\t) {\n\t\tsuper();\n\t}\n\n\t/**\n\t * Inserts a single record into the database using the specified builder.\n\t * Uses Objection.js's insertGraph method to handle nested relations.\n\t *\n\t * @template K - The builder name (must be a key of Builders)\n\t * @param builderName - The name of the builder to use\n\t * @param attrs - Optional attributes to override builder defaults\n\t * @returns A promise resolving to the inserted record with all relations\n\t * @throws Error if the specified builder doesn't exist\n\t *\n\t * @example\n\t * ```typescript\n\t * // Insert with defaults\n\t * const user = await factory.insert('user');\n\t *\n\t * // Insert with overrides\n\t * const adminUser = await factory.insert('user', {\n\t * email: 'admin@example.com',\n\t * role: 'admin'\n\t * });\n\t *\n\t * // Insert with nested relations\n\t * const userWithProfile = await factory.insert('user', {\n\t * name: 'John Doe',\n\t * profile: {\n\t * bio: 'Software Developer',\n\t * avatar: 'avatar.jpg'\n\t * }\n\t * });\n\t * ```\n\t */\n\tasync insert<K extends keyof Builders>(\n\t\tbuilderName: K,\n\t\tattrs?: Parameters<Builders[K]>[0],\n\t): Promise<Awaited<ReturnType<Builders[K]>>> {\n\t\tif (!(builderName in this.builders)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Factory \"${\n\t\t\t\t\tbuilderName as string\n\t\t\t\t}\" does not exist. Make sure it is correct and registered in src/test/setup.ts`,\n\t\t\t);\n\t\t}\n\n\t\tconst result = await this.builders[builderName](\n\t\t\tattrs || {},\n\t\t\tthis,\n\t\t\tthis.db,\n\t\t\tfaker,\n\t\t);\n\n\t\t// If the builder returns a model instance, insert it\n\t\tif (result && typeof result.$query === 'function') {\n\t\t\t// Extract data from model, excluding undefined values and id\n\t\t\tconst insertData = Object.entries(result).reduce((acc, [key, value]) => {\n\t\t\t\tif (value !== undefined && key !== 'id') {\n\t\t\t\t\tacc[key] = value;\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t}, {} as any);\n\n\t\t\t// Use the model's constructor to get the query builder\n\t\t\treturn await result.constructor.query(this.db).insert(insertData);\n\t\t}\n\n\t\t// Otherwise, assume the builder handled insertion itself\n\t\treturn result;\n\t}\n\t/**\n\t * Inserts multiple records into the database using the specified builder.\n\t * Supports both static attributes and dynamic attribute generation via a function.\n\t *\n\t * @param count - The number of records to insert\n\t * @param builderName - The name of the builder to use\n\t * @param attrs - Static attributes or a function that generates attributes for each record\n\t * @returns A promise resolving to an array of inserted records\n\t * @throws Error if the specified builder doesn't exist\n\t *\n\t * @example\n\t * ```typescript\n\t * // Insert multiple with same attributes\n\t * const users = await factory.insertMany(5, 'user', { role: 'member' });\n\t *\n\t * // Insert multiple with dynamic attributes\n\t * const posts = await factory.insertMany(10, 'post', (idx) => ({\n\t * title: `Post ${idx + 1}`,\n\t * content: `Content for post ${idx + 1}`,\n\t * publishedAt: new Date()\n\t * }));\n\t *\n\t * // Create users with sequential emails\n\t * const admins = await factory.insertMany(3, 'user', (idx) => ({\n\t * email: `admin${idx + 1}@example.com`,\n\t * role: 'admin'\n\t * }));\n\t * ```\n\t */\n\t// Method overloads for better type inference\n\tasync insertMany<K extends keyof Builders>(\n\t\tcount: number,\n\t\tbuilderName: K,\n\t\tattrs?: Parameters<Builders[K]>[0],\n\t): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n\tasync insertMany<K extends keyof Builders>(\n\t\tcount: number,\n\t\tbuilderName: K,\n\t\tattrs: (idx: number, faker: FakerFactory) => Parameters<Builders[K]>[0],\n\t): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n\tasync insertMany<K extends keyof Builders>(\n\t\tcount: number,\n\t\tbuilderName: K,\n\t\tattrs?: any,\n\t): Promise<Awaited<ReturnType<Builders[K]>>[]> {\n\t\tif (!(builderName in this.builders)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Builder \"${\n\t\t\t\t\tbuilderName as string\n\t\t\t\t}\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n\t\t\t);\n\t\t}\n\n\t\tconst records: any[] = [];\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tconst newAttrs =\n\t\t\t\ttypeof attrs === 'function' ? await (attrs as any)(i, faker) : attrs;\n\n\t\t\trecords.push(\n\t\t\t\tthis.builders[builderName](newAttrs, this, this.db, faker).then(\n\t\t\t\t\t(record: any) => {\n\t\t\t\t\t\t// If the builder returns a model instance, insert it\n\t\t\t\t\t\tif (record && typeof record.$query === 'function') {\n\t\t\t\t\t\t\t// Extract data from model, excluding undefined values and id\n\t\t\t\t\t\t\tconst insertData = Object.entries(record).reduce(\n\t\t\t\t\t\t\t\t(acc, [key, value]) => {\n\t\t\t\t\t\t\t\t\tif (value !== undefined && key !== 'id') {\n\t\t\t\t\t\t\t\t\t\tacc[key] = value;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn acc;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{} as any,\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t// Use the model's constructor to get the query builder\n\t\t\t\t\t\t\treturn record.constructor.query(this.db).insert(insertData);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Otherwise, assume the builder handled insertion itself\n\t\t\t\t\t\treturn record;\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\treturn Promise.all(records);\n\t}\n\t/**\n\t * Executes a seed function to create complex test scenarios with multiple related records.\n\t * Seeds are useful for setting up complete test environments with realistic data relationships.\n\t *\n\t * @template K - The seed name (must be a key of Seeds)\n\t * @param seedName - The name of the seed to execute\n\t * @param attrs - Optional configuration attributes for the seed\n\t * @returns The result of the seed function (typically the primary record created)\n\t * @throws Error if the specified seed doesn't exist\n\t *\n\t * @example\n\t * ```typescript\n\t * // Execute a simple seed\n\t * const user = await factory.seed('userWithProfile');\n\t *\n\t * // Execute a seed with configuration\n\t * const author = await factory.seed('authorWithBooks', {\n\t * bookCount: 5,\n\t * includeReviews: true\n\t * });\n\t *\n\t * // Use seed result in tests with Objection.js relations\n\t * const company = await factory.seed('companyWithDepartments', {\n\t * departmentCount: 3,\n\t * employeesPerDepartment: 10\n\t * });\n\t *\n\t * // Access eager loaded relations\n\t * const companyWithRelations = await Company.query()\n\t * .findById(company.id)\n\t * .withGraphFetched('[departments.employees]');\n\t * ```\n\t */\n\tseed<K extends keyof Seeds>(\n\t\tseedName: K,\n\t\tattrs?: ExtractSeedAttrs<Seeds[K]>,\n\t): ReturnType<Seeds[K]> {\n\t\tif (!(seedName in this.seeds)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Seed \"${\n\t\t\t\t\tseedName as string\n\t\t\t\t}\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n\t\t\t);\n\t\t}\n\n\t\treturn this.seeds[seedName]({\n\t\t\tattrs: attrs || {},\n\t\t\tfactory: this,\n\t\t\tdb: this.db,\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,mBAAb,cAGU,QAAyB;;;;;;;;;;;;;;;;;;;;;;CAsBlC,OAAgB,WAAqCA,QAAoB;AACxE,SAAO,QAAQ,WAAW,OAAO;CACjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DD,OAAO,cAMNC,YACAC,UAQAC,YAMoB;AACpB,SAAO,OACNC,OACAC,SACAC,IACAC,kBACI;GAEJ,IAAIC,OAAsC,EAAE,GAAG,MAAO;AAGtD,OAAI,UAAU;IACb,MAAM,gBAAgB,MAAM,SAAS;KACpC;KACA;KACA;KACA,OAAO;IACP,EAAC;AACF,WAAO;KAAE,GAAG;KAAe,GAAG;IAAM;GACpC;GAGD,MAAM,QAAQ,WAAW,SAAS,KAAK;AAGvC,OAAI,eAAe,OAAO;IAGzB,MAAM,aAAa,OAAO,QAAQ,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACtE,SAAI,oBAAuB,QAAQ,KAClC,KAAI,OAAO;AAEZ,YAAO;IACP,GAAE,CAAE,EAAQ;IAGb,MAAM,SAAS,MAAM,WAAW,MAAM,GAAG,CAAC,OAAO,WAAW;AAC5D,WAAO;GACP,MAEA,QAAO;EAER;CACD;;;;;;;;CASD,YACSC,UACAC,OACAJ,IACP;AACD,SAAO;EAJC;EACA;EACA;CAGR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCD,MAAM,OACLK,aACAC,OAC4C;AAC5C,QAAM,eAAe,KAAK,UACzB,OAAM,IAAI,OACR,WACA,YACA;EAIH,MAAM,SAAS,MAAM,KAAK,SAAS,aAClC,SAAS,CAAE,GACX,MACA,KAAK,IACL,MACA;AAGD,MAAI,iBAAiB,OAAO,WAAW,YAAY;GAElD,MAAM,aAAa,OAAO,QAAQ,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACvE,QAAI,oBAAuB,QAAQ,KAClC,KAAI,OAAO;AAEZ,WAAO;GACP,GAAE,CAAE,EAAQ;AAGb,UAAO,MAAM,OAAO,YAAY,MAAM,KAAK,GAAG,CAAC,OAAO,WAAW;EACjE;AAGD,SAAO;CACP;CAyCD,MAAM,WACLC,OACAF,aACAG,OAC8C;AAC9C,QAAM,eAAe,KAAK,UACzB,OAAM,IAAI,OACR,WACA,YACA;EAIH,MAAMC,UAAiB,CAAE;AACzB,OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;GAC/B,MAAM,kBACE,UAAU,aAAa,MAAM,AAAC,MAAc,GAAG,MAAM,GAAG;AAEhE,WAAQ,KACP,KAAK,SAAS,aAAa,UAAU,MAAM,KAAK,IAAI,MAAM,CAAC,KAC1D,CAACC,WAAgB;AAEhB,QAAI,iBAAiB,OAAO,WAAW,YAAY;KAElD,MAAM,aAAa,OAAO,QAAQ,OAAO,CAAC,OACzC,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACtB,UAAI,oBAAuB,QAAQ,KAClC,KAAI,OAAO;AAEZ,aAAO;KACP,GACD,CAAE,EACF;AAGD,YAAO,OAAO,YAAY,MAAM,KAAK,GAAG,CAAC,OAAO,WAAW;IAC3D;AAED,WAAO;GACP,EACD,CACD;EACD;AAED,SAAO,QAAQ,IAAI,QAAQ;CAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCD,KACCC,UACAC,OACuB;AACvB,QAAM,YAAY,KAAK,OACtB,OAAM,IAAI,OACR,QACA,SACA;AAIH,SAAO,KAAK,MAAM,UAAU;GAC3B,OAAO,SAAS,CAAE;GAClB,SAAS;GACT,IAAI,KAAK;EACT,EAAC;CACF;AACD"}
@@ -1,84 +0,0 @@
1
- import { PostgresMigrator } from "./PostgresMigrator-CeYy-eHF.cjs";
2
- import { Kysely } from "kysely";
3
- import { MigrationProvider } from "kysely/migration";
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-B2M6Gjvv.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PostgresKyselyMigrator-B2M6Gjvv.d.cts","names":[],"sources":["../src/PostgresKyselyMigrator.ts"],"sourcesContent":[],"mappings":";;;;;;;;AA2DA;;;;;;;AAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAA/C,sBAAA,SAA+B,gBAAA;;;;;;;;;;;;;QAarC;cACM;mCACqB;;;;;;;;;aAahB"}