@geekmidas/testkit 0.4.0 → 1.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 (209) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/Factory-BFVnMMCC.mjs.map +1 -1
  3. package/dist/{Factory-c16c27Y6.d.cts → Factory-BOX312yd.d.cts} +3 -2
  4. package/dist/Factory-BOX312yd.d.cts.map +1 -0
  5. package/dist/Factory-BhjUOBWN.cjs.map +1 -1
  6. package/dist/{Factory-BcGJjLc8.d.mts → Factory-SFupxRC2.d.mts} +2 -1
  7. package/dist/Factory-SFupxRC2.d.mts.map +1 -0
  8. package/dist/Factory.d.cts +2 -2
  9. package/dist/Factory.d.mts +1 -1
  10. package/dist/KyselyFactory-BFqVIn_0.cjs.map +1 -1
  11. package/dist/KyselyFactory-DMswpwji.mjs.map +1 -1
  12. package/dist/{KyselyFactory-uZ45h7YU.d.cts → KyselyFactory-Dy5zzV4B.d.cts} +4 -3
  13. package/dist/KyselyFactory-Dy5zzV4B.d.cts.map +1 -0
  14. package/dist/{KyselyFactory-Cj-EultY.d.mts → KyselyFactory-vAxYodck.d.mts} +3 -2
  15. package/dist/KyselyFactory-vAxYodck.d.mts.map +1 -0
  16. package/dist/KyselyFactory.d.cts +3 -3
  17. package/dist/KyselyFactory.d.mts +2 -2
  18. package/dist/{ObjectionFactory-DL4qkuF1.d.mts → ObjectionFactory-BWjB49-i.d.mts} +3 -2
  19. package/dist/ObjectionFactory-BWjB49-i.d.mts.map +1 -0
  20. package/dist/ObjectionFactory-BeFBYcan.cjs.map +1 -1
  21. package/dist/{ObjectionFactory-CdhzKs4f.d.cts → ObjectionFactory-CD-WFuMJ.d.cts} +4 -3
  22. package/dist/ObjectionFactory-CD-WFuMJ.d.cts.map +1 -0
  23. package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +1 -1
  24. package/dist/ObjectionFactory.d.cts +3 -3
  25. package/dist/ObjectionFactory.d.mts +2 -2
  26. package/dist/{PostgresKyselyMigrator-upT-hmrz.mjs → PostgresKyselyMigrator-6sE1KOni.mjs} +2 -2
  27. package/dist/PostgresKyselyMigrator-6sE1KOni.mjs.map +1 -0
  28. package/dist/{PostgresKyselyMigrator-CIx3AFSR.d.mts → PostgresKyselyMigrator-CBltSOq5.d.cts} +3 -2
  29. package/dist/PostgresKyselyMigrator-CBltSOq5.d.cts.map +1 -0
  30. package/dist/{PostgresKyselyMigrator-CfytARcA.cjs → PostgresKyselyMigrator-D6IbPq8t.cjs} +2 -2
  31. package/dist/PostgresKyselyMigrator-D6IbPq8t.cjs.map +1 -0
  32. package/dist/{PostgresKyselyMigrator-CQ3aUoy_.d.cts → PostgresKyselyMigrator-DrVWncqd.d.mts} +3 -2
  33. package/dist/PostgresKyselyMigrator-DrVWncqd.d.mts.map +1 -0
  34. package/dist/PostgresKyselyMigrator.cjs +2 -2
  35. package/dist/PostgresKyselyMigrator.d.cts +2 -2
  36. package/dist/PostgresKyselyMigrator.d.mts +2 -2
  37. package/dist/PostgresKyselyMigrator.mjs +2 -2
  38. package/dist/{PostgresMigrator-DbuJGAVy.mjs → PostgresMigrator-BjjenqSd.mjs} +2 -2
  39. package/dist/PostgresMigrator-BjjenqSd.mjs.map +1 -0
  40. package/dist/{PostgresMigrator-D5UkK1_K.d.cts → PostgresMigrator-Bres0U6E.d.cts} +2 -1
  41. package/dist/PostgresMigrator-Bres0U6E.d.cts.map +1 -0
  42. package/dist/{PostgresMigrator-DFcNdCvD.cjs → PostgresMigrator-D6dQn0x2.cjs} +2 -2
  43. package/dist/PostgresMigrator-D6dQn0x2.cjs.map +1 -0
  44. package/dist/{PostgresMigrator-DQaRxoaY.d.mts → PostgresMigrator-S-YYosAC.d.mts} +2 -1
  45. package/dist/PostgresMigrator-S-YYosAC.d.mts.map +1 -0
  46. package/dist/PostgresMigrator.cjs +1 -1
  47. package/dist/PostgresMigrator.d.cts +1 -1
  48. package/dist/PostgresMigrator.d.mts +1 -1
  49. package/dist/PostgresMigrator.mjs +1 -1
  50. package/dist/{PostgresObjectionMigrator-CZHHcCOv.d.cts → PostgresObjectionMigrator-CPfBAP7r.d.cts} +3 -2
  51. package/dist/PostgresObjectionMigrator-CPfBAP7r.d.cts.map +1 -0
  52. package/dist/{PostgresObjectionMigrator-BG6ymgnt.cjs → PostgresObjectionMigrator-DK8ODIHQ.cjs} +2 -2
  53. package/dist/PostgresObjectionMigrator-DK8ODIHQ.cjs.map +1 -0
  54. package/dist/{PostgresObjectionMigrator-D_hCcrQu.d.mts → PostgresObjectionMigrator-DVEqB5tp.d.mts} +3 -2
  55. package/dist/PostgresObjectionMigrator-DVEqB5tp.d.mts.map +1 -0
  56. package/dist/{PostgresObjectionMigrator-DPj2pOpX.mjs → PostgresObjectionMigrator-D_QxXbIN.mjs} +2 -2
  57. package/dist/PostgresObjectionMigrator-D_QxXbIN.mjs.map +1 -0
  58. package/dist/PostgresObjectionMigrator.cjs +2 -2
  59. package/dist/PostgresObjectionMigrator.d.cts +2 -2
  60. package/dist/PostgresObjectionMigrator.d.mts +2 -2
  61. package/dist/PostgresObjectionMigrator.mjs +2 -2
  62. package/dist/{VitestKyselyTransactionIsolator-D3EZZhjZ.d.cts → VitestKyselyTransactionIsolator-CduJlHoT.d.cts} +4 -3
  63. package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts.map +1 -0
  64. package/dist/{VitestKyselyTransactionIsolator-Dxlp1u0f.d.mts → VitestKyselyTransactionIsolator-Cswnnj0k.d.mts} +4 -3
  65. package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts.map +1 -0
  66. package/dist/{VitestKyselyTransactionIsolator-EvDLk5zg.cjs → VitestKyselyTransactionIsolator-D7RRXOBa.cjs} +2 -2
  67. package/dist/VitestKyselyTransactionIsolator-D7RRXOBa.cjs.map +1 -0
  68. package/dist/{VitestKyselyTransactionIsolator-CNURW8y6.mjs → VitestKyselyTransactionIsolator-DceyIqr4.mjs} +2 -2
  69. package/dist/VitestKyselyTransactionIsolator-DceyIqr4.mjs.map +1 -0
  70. package/dist/VitestKyselyTransactionIsolator.cjs +1 -1
  71. package/dist/VitestKyselyTransactionIsolator.d.cts +2 -2
  72. package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
  73. package/dist/VitestKyselyTransactionIsolator.mjs +1 -1
  74. package/dist/{VitestObjectionTransactionIsolator-1TpsPqfG.d.cts → VitestObjectionTransactionIsolator-BXoR6xdG.d.cts} +4 -3
  75. package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts.map +1 -0
  76. package/dist/{VitestObjectionTransactionIsolator-CM5KTAFA.cjs → VitestObjectionTransactionIsolator-CdLRrzNf.cjs} +2 -2
  77. package/dist/VitestObjectionTransactionIsolator-CdLRrzNf.cjs.map +1 -0
  78. package/dist/{VitestObjectionTransactionIsolator-jQFaCz0u.mjs → VitestObjectionTransactionIsolator-OF2osYY5.mjs} +2 -2
  79. package/dist/VitestObjectionTransactionIsolator-OF2osYY5.mjs.map +1 -0
  80. package/dist/{VitestObjectionTransactionIsolator-i9jIgU8Q.d.mts → VitestObjectionTransactionIsolator-x6hY5j4u.d.mts} +4 -3
  81. package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts.map +1 -0
  82. package/dist/VitestObjectionTransactionIsolator.cjs +1 -1
  83. package/dist/VitestObjectionTransactionIsolator.d.cts +2 -2
  84. package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
  85. package/dist/VitestObjectionTransactionIsolator.mjs +1 -1
  86. package/dist/{VitestTransactionIsolator-BvR19bYn.d.mts → VitestTransactionIsolator-BNWJqh9f.d.mts} +3 -2
  87. package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts.map +1 -0
  88. package/dist/VitestTransactionIsolator-CMfJXZP8.cjs.map +1 -1
  89. package/dist/{VitestTransactionIsolator-CwQaxZLP.d.cts → VitestTransactionIsolator-CSroc7Df.d.cts} +3 -2
  90. package/dist/VitestTransactionIsolator-CSroc7Df.d.cts.map +1 -0
  91. package/dist/VitestTransactionIsolator-DQ7tLqgV.mjs.map +1 -1
  92. package/dist/VitestTransactionIsolator.d.cts +1 -1
  93. package/dist/VitestTransactionIsolator.d.mts +1 -1
  94. package/dist/aws.cjs.map +1 -1
  95. package/dist/aws.d.cts +2 -0
  96. package/dist/aws.d.cts.map +1 -0
  97. package/dist/aws.d.mts +2 -0
  98. package/dist/aws.d.mts.map +1 -0
  99. package/dist/aws.mjs.map +1 -1
  100. package/dist/benchmark.cjs.map +1 -1
  101. package/dist/benchmark.d.cts +1 -0
  102. package/dist/benchmark.d.cts.map +1 -0
  103. package/dist/benchmark.d.mts +1 -0
  104. package/dist/benchmark.d.mts.map +1 -0
  105. package/dist/benchmark.mjs.map +1 -1
  106. package/dist/better-auth.cjs +29 -30
  107. package/dist/better-auth.cjs.map +1 -1
  108. package/dist/better-auth.d.cts +2 -2
  109. package/dist/better-auth.d.cts.map +1 -0
  110. package/dist/better-auth.d.mts.map +1 -0
  111. package/dist/better-auth.mjs +29 -30
  112. package/dist/better-auth.mjs.map +1 -1
  113. package/dist/directory-B-Ozljzk.mjs.map +1 -1
  114. package/dist/directory-BVC8g7cX.cjs.map +1 -1
  115. package/dist/{directory-BXavAeJZ.d.mts → directory-CVrfTq1I.d.mts} +2 -1
  116. package/dist/directory-CVrfTq1I.d.mts.map +1 -0
  117. package/dist/{directory-Mi7tdOuD.d.cts → directory-DAnMWi50.d.cts} +2 -1
  118. package/dist/directory-DAnMWi50.d.cts.map +1 -0
  119. package/dist/faker-B14IEMIN.cjs.map +1 -1
  120. package/dist/faker-BGKYFoCT.mjs.map +1 -1
  121. package/dist/{faker-DvxiCtxc.d.cts → faker-Cg76aFNO.d.cts} +3 -3
  122. package/dist/faker-Cg76aFNO.d.cts.map +1 -0
  123. package/dist/faker-DHh7xs4u.d.mts.map +1 -0
  124. package/dist/faker.d.cts +1 -1
  125. package/dist/helpers.cjs.map +1 -1
  126. package/dist/helpers.d.cts +1 -0
  127. package/dist/helpers.d.cts.map +1 -0
  128. package/dist/helpers.d.mts +1 -0
  129. package/dist/helpers.d.mts.map +1 -0
  130. package/dist/helpers.mjs.map +1 -1
  131. package/dist/kysely.cjs +3 -3
  132. package/dist/kysely.cjs.map +1 -1
  133. package/dist/kysely.d.cts +8 -7
  134. package/dist/kysely.d.cts.map +1 -0
  135. package/dist/kysely.d.mts +7 -6
  136. package/dist/kysely.d.mts.map +1 -0
  137. package/dist/kysely.mjs +3 -3
  138. package/dist/kysely.mjs.map +1 -1
  139. package/dist/logger.cjs.map +1 -1
  140. package/dist/logger.d.cts +1 -0
  141. package/dist/logger.d.cts.map +1 -0
  142. package/dist/logger.d.mts +1 -0
  143. package/dist/logger.d.mts.map +1 -0
  144. package/dist/logger.mjs.map +1 -1
  145. package/dist/objection.cjs +3 -3
  146. package/dist/objection.cjs.map +1 -1
  147. package/dist/objection.d.cts +8 -7
  148. package/dist/objection.d.cts.map +1 -0
  149. package/dist/objection.d.mts +7 -6
  150. package/dist/objection.d.mts.map +1 -0
  151. package/dist/objection.mjs +3 -3
  152. package/dist/objection.mjs.map +1 -1
  153. package/dist/os/directory.d.cts +1 -1
  154. package/dist/os/directory.d.mts +1 -1
  155. package/dist/os/index.d.cts +1 -1
  156. package/dist/os/index.d.mts +1 -1
  157. package/dist/timer.cjs.map +1 -1
  158. package/dist/timer.d.cts +2 -0
  159. package/dist/timer.d.cts.map +1 -0
  160. package/dist/timer.d.mts +2 -0
  161. package/dist/timer.d.mts.map +1 -0
  162. package/dist/timer.mjs.map +1 -1
  163. package/package.json +5 -5
  164. package/src/Factory.ts +72 -72
  165. package/src/KyselyFactory.ts +330 -330
  166. package/src/ObjectionFactory.ts +354 -355
  167. package/src/PostgresKyselyMigrator.ts +37 -37
  168. package/src/PostgresMigrator.ts +107 -107
  169. package/src/PostgresObjectionMigrator.ts +91 -91
  170. package/src/VitestKyselyTransactionIsolator.ts +27 -27
  171. package/src/VitestObjectionTransactionIsolator.ts +39 -39
  172. package/src/VitestTransactionIsolator.ts +196 -195
  173. package/src/__tests__/Factory.spec.ts +163 -155
  174. package/src/__tests__/KyselyFactory.spec.ts +443 -439
  175. package/src/__tests__/ObjectionFactory.spec.ts +563 -557
  176. package/src/__tests__/PostgresKyselyMigrator.spec.ts +641 -641
  177. package/src/__tests__/PostgresMigrator.spec.ts +341 -341
  178. package/src/__tests__/PostgresObjectionMigrator.spec.ts +578 -578
  179. package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +114 -114
  180. package/src/__tests__/benchmark.spec.ts +140 -0
  181. package/src/__tests__/better-auth.spec.ts +15 -15
  182. package/src/__tests__/faker.spec.ts +226 -137
  183. package/src/__tests__/integration.spec.ts +597 -597
  184. package/src/__tests__/utilities.spec.ts +211 -0
  185. package/src/aws.ts +104 -104
  186. package/src/benchmark.ts +12 -12
  187. package/src/better-auth.ts +286 -301
  188. package/src/faker.ts +153 -153
  189. package/src/helpers.ts +6 -6
  190. package/src/kysely.ts +33 -33
  191. package/src/logger.ts +10 -10
  192. package/src/objection.ts +31 -31
  193. package/src/os/directory.ts +11 -10
  194. package/src/timer.ts +1 -1
  195. package/test/globalSetup.ts +45 -45
  196. package/test/helpers.ts +189 -189
  197. package/test/migrations/1749664623372_user.ts +13 -13
  198. package/tsconfig.json +9 -0
  199. package/vitest.config.ts +4 -4
  200. package/dist/PostgresKyselyMigrator-CfytARcA.cjs.map +0 -1
  201. package/dist/PostgresKyselyMigrator-upT-hmrz.mjs.map +0 -1
  202. package/dist/PostgresMigrator-DFcNdCvD.cjs.map +0 -1
  203. package/dist/PostgresMigrator-DbuJGAVy.mjs.map +0 -1
  204. package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs.map +0 -1
  205. package/dist/PostgresObjectionMigrator-DPj2pOpX.mjs.map +0 -1
  206. package/dist/VitestKyselyTransactionIsolator-CNURW8y6.mjs.map +0 -1
  207. package/dist/VitestKyselyTransactionIsolator-EvDLk5zg.cjs.map +0 -1
  208. package/dist/VitestObjectionTransactionIsolator-CM5KTAFA.cjs.map +0 -1
  209. package/dist/VitestObjectionTransactionIsolator-jQFaCz0u.mjs.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @geekmidas/testkit
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [`ff7b115`](https://github.com/geekmidas/toolbox/commit/ff7b11599f60f84ac6cdc73714c853ecf786b2e8) Thanks [@geekmidas](https://github.com/geekmidas)! - Version 1 Stable release
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`ff7b115`](https://github.com/geekmidas/toolbox/commit/ff7b11599f60f84ac6cdc73714c853ecf786b2e8)]:
12
+ - @geekmidas/envkit@1.0.0
13
+ - @geekmidas/logger@1.0.0
@@ -1 +1 @@
1
- {"version":3,"file":"Factory-BFVnMMCC.mjs","names":["seedFn: Seed"],"sources":["../src/Factory.ts"],"sourcesContent":["import type { FakerFactory } from './faker';\n\n/**\n * Abstract base class for database factories used in testing.\n * Provides a standardized interface for creating test data using builder and seed patterns.\n *\n * @template Builders - Record of builder functions for creating individual entities\n * @template Seeds - Record of seed functions for creating complex test scenarios\n *\n * @example\n * ```typescript\n * // Define builders for creating individual records\n * const builders = {\n * user: (attrs) => ({ name: 'Test User', email: 'test@example.com', ...attrs }),\n * post: (attrs) => ({ title: 'Test Post', content: 'Content', ...attrs })\n * };\n *\n * // Define seeds for complex scenarios\n * const seeds = {\n * userWithPosts: async (attrs, factory) => {\n * const user = await factory.insert('user', attrs);\n * await factory.insertMany(3, 'post', { userId: user.id });\n * return user;\n * }\n * };\n * ```\n */\nexport abstract class Factory<\n Builders extends Record<string, any>,\n Seeds extends Record<string, any>,\n> {\n /**\n * Creates a typed seed function with proper type inference.\n * This is a utility method to help with TypeScript type checking when defining seeds.\n *\n * @template Seed - The seed function type\n * @param seedFn - The seed function to wrap\n * @returns The same seed function with proper typing\n *\n * @example\n * ```typescript\n * const userWithPostsSeed = Factory.createSeed(async ({ attrs, factory, db }) => {\n * const user = await factory.insert('user', attrs);\n * return user;\n * });\n * ```\n */\n static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n return seedFn;\n }\n /**\n * Inserts an object into the database using a builder function.\n *\n * @param builderName - The name of the builder to use\n * @param attrs - The attributes to insert\n */\n abstract insert<K extends keyof Builders>(\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>>;\n\n /**\n * Inserts multiple objects into the database\n *\n * @param count - Number of objects to insert\n * @param builderName - The name of the builder to use\n * @param attrs - The attributes to insert\n */\n abstract insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?:\n | Parameters<Builders[K]>[0]\n | ((\n idx: number,\n faker: FakerFactory,\n ) => Promise<Parameters<Builders[K]>[0]>),\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n\n /**\n * Seeds the database using a seed function.\n *\n * @param seedName - The name of the seed to use\n * @returns The result of the seed function\n * @param attrs - The attributes to pass to the seed function\n */\n abstract seed<K extends keyof Seeds>(\n seedName: K,\n attrs?: ExtractSeedAttrs<Seeds[K]>,\n ): ReturnType<Seeds[K]>;\n}\n\n/**\n * Type definition for a factory builder function that can work with different database types.\n * Builders are responsible for creating individual database records with default values and relationships.\n *\n * @template Attrs - The attributes/input type for the builder\n * @template Factory - The factory instance type\n * @template Result - The type of object returned by the builder\n * @template DB - The database connection type (Kysely, Knex, etc.)\n *\n * @param attrs - Partial attributes to override defaults\n * @param factory - The factory instance for creating related records\n * @param db - The database connection\n * @returns The created record or a promise resolving to it\n *\n * @example\n * ```typescript\n * const userBuilder: MixedFactoryBuilder<UserAttrs, Factory, User, Kysely<DB>> =\n * async (attrs, factory, db) => {\n * return {\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * };\n * };\n * ```\n */\nexport type MixedFactoryBuilder<\n Attrs = any,\n Factory = any,\n Result = any,\n DB = any,\n> = (attrs: Attrs, factory: Factory, db: DB) => Result | Promise<Result>;\n\n/**\n * Type definition for a factory seed function used to create complex test scenarios.\n * Seeds typically create multiple related records to set up a complete test environment.\n *\n * @template Attrs - The attributes/input type for the seed\n * @template Factory - The factory instance type\n * @template Result - The type of object returned by the seed\n * @template DB - The database connection type (Kysely, Knex, etc.)\n *\n * @param context - Object containing attrs, factory, and db\n * @param context.attrs - Configuration attributes for the seed\n * @param context.factory - The factory instance for creating records\n * @param context.db - The database connection\n * @returns A promise resolving to the seed result\n *\n * @example\n * ```typescript\n * const userWithPostsSeed: FactorySeed<{ postCount?: number }, Factory, User, DB> =\n * async ({ attrs, factory, db }) => {\n * const user = await factory.insert('user', attrs);\n * const postCount = attrs.postCount || 3;\n *\n * for (let i = 0; i < postCount; i++) {\n * await factory.insert('post', { userId: user.id });\n * }\n *\n * return user;\n * };\n * ```\n */\nexport type FactorySeed<\n Attrs = any,\n Factory = any,\n Result = any,\n DB = any,\n> = (context: { attrs: Attrs; factory: Factory; db: DB }) => Promise<Result>;\n\n/**\n * Helper type to extract the Attrs type from a FactorySeed function.\n * Used internally by Factory implementations to correctly type the seed method parameters.\n */\nexport type ExtractSeedAttrs<T> = T extends (context: {\n attrs: infer A;\n factory: any;\n db: any;\n}) => any\n ? A\n : never;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,IAAsB,UAAtB,MAGE;;;;;;;;;;;;;;;;;CAiBA,OAAO,WAAqCA,QAAoB;AAC9D,SAAO;CACR;AAyCF"}
1
+ {"version":3,"file":"Factory-BFVnMMCC.mjs","names":["seedFn: Seed"],"sources":["../src/Factory.ts"],"sourcesContent":["import type { FakerFactory } from './faker';\n\n/**\n * Abstract base class for database factories used in testing.\n * Provides a standardized interface for creating test data using builder and seed patterns.\n *\n * @template Builders - Record of builder functions for creating individual entities\n * @template Seeds - Record of seed functions for creating complex test scenarios\n *\n * @example\n * ```typescript\n * // Define builders for creating individual records\n * const builders = {\n * user: (attrs) => ({ name: 'Test User', email: 'test@example.com', ...attrs }),\n * post: (attrs) => ({ title: 'Test Post', content: 'Content', ...attrs })\n * };\n *\n * // Define seeds for complex scenarios\n * const seeds = {\n * userWithPosts: async (attrs, factory) => {\n * const user = await factory.insert('user', attrs);\n * await factory.insertMany(3, 'post', { userId: user.id });\n * return user;\n * }\n * };\n * ```\n */\nexport abstract class Factory<\n\tBuilders extends Record<string, any>,\n\tSeeds extends Record<string, any>,\n> {\n\t/**\n\t * Creates a typed seed function with proper type inference.\n\t * This is a utility method to help with TypeScript type checking when defining seeds.\n\t *\n\t * @template Seed - The seed function type\n\t * @param seedFn - The seed function to wrap\n\t * @returns The same seed function with proper typing\n\t *\n\t * @example\n\t * ```typescript\n\t * const userWithPostsSeed = Factory.createSeed(async ({ attrs, factory, db }) => {\n\t * const user = await factory.insert('user', attrs);\n\t * return user;\n\t * });\n\t * ```\n\t */\n\tstatic createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n\t\treturn seedFn;\n\t}\n\t/**\n\t * Inserts an object into the database using a builder function.\n\t *\n\t * @param builderName - The name of the builder to use\n\t * @param attrs - The attributes to insert\n\t */\n\tabstract insert<K extends keyof Builders>(\n\t\tbuilderName: K,\n\t\tattrs?: Parameters<Builders[K]>[0],\n\t): Promise<Awaited<ReturnType<Builders[K]>>>;\n\n\t/**\n\t * Inserts multiple objects into the database\n\t *\n\t * @param count - Number of objects to insert\n\t * @param builderName - The name of the builder to use\n\t * @param attrs - The attributes to insert\n\t */\n\tabstract insertMany<K extends keyof Builders>(\n\t\tcount: number,\n\t\tbuilderName: K,\n\t\tattrs?:\n\t\t\t| Parameters<Builders[K]>[0]\n\t\t\t| ((\n\t\t\t\t\tidx: number,\n\t\t\t\t\tfaker: FakerFactory,\n\t\t\t ) => Promise<Parameters<Builders[K]>[0]>),\n\t): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n\n\t/**\n\t * Seeds the database using a seed function.\n\t *\n\t * @param seedName - The name of the seed to use\n\t * @returns The result of the seed function\n\t * @param attrs - The attributes to pass to the seed function\n\t */\n\tabstract seed<K extends keyof Seeds>(\n\t\tseedName: K,\n\t\tattrs?: ExtractSeedAttrs<Seeds[K]>,\n\t): ReturnType<Seeds[K]>;\n}\n\n/**\n * Type definition for a factory builder function that can work with different database types.\n * Builders are responsible for creating individual database records with default values and relationships.\n *\n * @template Attrs - The attributes/input type for the builder\n * @template Factory - The factory instance type\n * @template Result - The type of object returned by the builder\n * @template DB - The database connection type (Kysely, Knex, etc.)\n *\n * @param attrs - Partial attributes to override defaults\n * @param factory - The factory instance for creating related records\n * @param db - The database connection\n * @returns The created record or a promise resolving to it\n *\n * @example\n * ```typescript\n * const userBuilder: MixedFactoryBuilder<UserAttrs, Factory, User, Kysely<DB>> =\n * async (attrs, factory, db) => {\n * return {\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * };\n * };\n * ```\n */\nexport type MixedFactoryBuilder<\n\tAttrs = any,\n\tFactory = any,\n\tResult = any,\n\tDB = any,\n> = (attrs: Attrs, factory: Factory, db: DB) => Result | Promise<Result>;\n\n/**\n * Type definition for a factory seed function used to create complex test scenarios.\n * Seeds typically create multiple related records to set up a complete test environment.\n *\n * @template Attrs - The attributes/input type for the seed\n * @template Factory - The factory instance type\n * @template Result - The type of object returned by the seed\n * @template DB - The database connection type (Kysely, Knex, etc.)\n *\n * @param context - Object containing attrs, factory, and db\n * @param context.attrs - Configuration attributes for the seed\n * @param context.factory - The factory instance for creating records\n * @param context.db - The database connection\n * @returns A promise resolving to the seed result\n *\n * @example\n * ```typescript\n * const userWithPostsSeed: FactorySeed<{ postCount?: number }, Factory, User, DB> =\n * async ({ attrs, factory, db }) => {\n * const user = await factory.insert('user', attrs);\n * const postCount = attrs.postCount || 3;\n *\n * for (let i = 0; i < postCount; i++) {\n * await factory.insert('post', { userId: user.id });\n * }\n *\n * return user;\n * };\n * ```\n */\nexport type FactorySeed<\n\tAttrs = any,\n\tFactory = any,\n\tResult = any,\n\tDB = any,\n> = (context: { attrs: Attrs; factory: Factory; db: DB }) => Promise<Result>;\n\n/**\n * Helper type to extract the Attrs type from a FactorySeed function.\n * Used internally by Factory implementations to correctly type the seed method parameters.\n */\nexport type ExtractSeedAttrs<T> = T extends (context: {\n\tattrs: infer A;\n\tfactory: any;\n\tdb: any;\n}) => any\n\t? A\n\t: never;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,IAAsB,UAAtB,MAGE;;;;;;;;;;;;;;;;;CAiBD,OAAO,WAAqCA,QAAoB;AAC/D,SAAO;CACP;AAyCD"}
@@ -1,4 +1,4 @@
1
- import { FakerFactory } from "./faker-DvxiCtxc.cjs";
1
+ import { FakerFactory } from "./faker-Cg76aFNO.cjs";
2
2
 
3
3
  //#region src/Factory.d.ts
4
4
 
@@ -141,6 +141,7 @@ type ExtractSeedAttrs<T> = T extends ((context: {
141
141
  factory: any;
142
142
  db: any;
143
143
  }) => any) ? A : never;
144
+ //# sourceMappingURL=Factory.d.ts.map
144
145
  //#endregion
145
146
  export { ExtractSeedAttrs, Factory, FactorySeed, MixedFactoryBuilder };
146
- //# sourceMappingURL=Factory-c16c27Y6.d.cts.map
147
+ //# sourceMappingURL=Factory-BOX312yd.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Factory-BOX312yd.d.cts","names":[],"sources":["../src/Factory.ts"],"sourcesContent":[],"mappings":";;;;;;AA2BA;;;;;;;;;;;;;;;;;;;;;;;AAiD6B,uBAjDP,OAiDO,CAAA,iBAhDX,MAgDW,CAAA,MAAA,EAAA,GAAA,CAAA,EAAA,cA/Cd,MA+Cc,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,CAAA;EAAQ;;;;;;;;;;;;;;;;EAavB,OAAA,UAAA,CAAA,aA1CkB,WA0ClB,CAAA,CAAA,MAAA,EA1CuC,IA0CvC,CAAA,EA1C8C,IA0C9C;EA8BF;;;;;;EAK0C,SAAW,MAAA,CAAA,UAAA,MApEhC,QAoEgC,CAAA,CAAA,WAAA,EAnElD,CAmEkD,EAAA,KAAA,CAAA,EAlEvD,UAkEuD,CAlE5C,QAkE4C,CAlEnC,CAkEmC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAjE7D,OAiE6D,CAjErD,OAiEqD,CAjE7C,UAiE6C,CAjElC,QAiEkC,CAjEzB,CAiEyB,CAAA,CAAA,CAAA,CAAA;EAAM;AAAP;AAgChE;;;;;EAKsD,SAAe,UAAA,CAAA,UAAA,MA7FhC,QA6FgC,CAAA,CAAA,KAAA,EAAA,MAAA,EAAA,WAAA,EA3FtD,CA2FsD,EAAA,KAAA,CAAA,EAzFhE,UAyFgE,CAzFrD,QAyFqD,CAzF5C,CAyF4C,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAtFzD,YAsFyD,EAAA,GArF3D,OAqF2D,CArFnD,UAqFmD,CArFxC,QAqFwC,CArF/B,CAqF+B,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EApFjE,OAoFiE,CApFzD,OAoFyD,CApFjD,UAoFiD,CApFtC,QAoFsC,CApF7B,CAoF6B,CAAA,CAAA,CAAA,EAAA,CAAA;EAAM;AAAP;AAMpE;;;;AAKI;gCAtF2B,iBACnB,WACF,iBAAiB,MAAM,MAC7B,WAAW,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8BT,kFAKA,gBAAgB,aAAa,OAAO,SAAS,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgCrD;SAKW;WAAgB;MAAa;MAAS,QAAQ;;;;;KAMzD,sBAAsB;;;;aAK/B"}
@@ -1 +1 @@
1
- {"version":3,"file":"Factory-BhjUOBWN.cjs","names":["seedFn: Seed"],"sources":["../src/Factory.ts"],"sourcesContent":["import type { FakerFactory } from './faker';\n\n/**\n * Abstract base class for database factories used in testing.\n * Provides a standardized interface for creating test data using builder and seed patterns.\n *\n * @template Builders - Record of builder functions for creating individual entities\n * @template Seeds - Record of seed functions for creating complex test scenarios\n *\n * @example\n * ```typescript\n * // Define builders for creating individual records\n * const builders = {\n * user: (attrs) => ({ name: 'Test User', email: 'test@example.com', ...attrs }),\n * post: (attrs) => ({ title: 'Test Post', content: 'Content', ...attrs })\n * };\n *\n * // Define seeds for complex scenarios\n * const seeds = {\n * userWithPosts: async (attrs, factory) => {\n * const user = await factory.insert('user', attrs);\n * await factory.insertMany(3, 'post', { userId: user.id });\n * return user;\n * }\n * };\n * ```\n */\nexport abstract class Factory<\n Builders extends Record<string, any>,\n Seeds extends Record<string, any>,\n> {\n /**\n * Creates a typed seed function with proper type inference.\n * This is a utility method to help with TypeScript type checking when defining seeds.\n *\n * @template Seed - The seed function type\n * @param seedFn - The seed function to wrap\n * @returns The same seed function with proper typing\n *\n * @example\n * ```typescript\n * const userWithPostsSeed = Factory.createSeed(async ({ attrs, factory, db }) => {\n * const user = await factory.insert('user', attrs);\n * return user;\n * });\n * ```\n */\n static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n return seedFn;\n }\n /**\n * Inserts an object into the database using a builder function.\n *\n * @param builderName - The name of the builder to use\n * @param attrs - The attributes to insert\n */\n abstract insert<K extends keyof Builders>(\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>>;\n\n /**\n * Inserts multiple objects into the database\n *\n * @param count - Number of objects to insert\n * @param builderName - The name of the builder to use\n * @param attrs - The attributes to insert\n */\n abstract insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?:\n | Parameters<Builders[K]>[0]\n | ((\n idx: number,\n faker: FakerFactory,\n ) => Promise<Parameters<Builders[K]>[0]>),\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n\n /**\n * Seeds the database using a seed function.\n *\n * @param seedName - The name of the seed to use\n * @returns The result of the seed function\n * @param attrs - The attributes to pass to the seed function\n */\n abstract seed<K extends keyof Seeds>(\n seedName: K,\n attrs?: ExtractSeedAttrs<Seeds[K]>,\n ): ReturnType<Seeds[K]>;\n}\n\n/**\n * Type definition for a factory builder function that can work with different database types.\n * Builders are responsible for creating individual database records with default values and relationships.\n *\n * @template Attrs - The attributes/input type for the builder\n * @template Factory - The factory instance type\n * @template Result - The type of object returned by the builder\n * @template DB - The database connection type (Kysely, Knex, etc.)\n *\n * @param attrs - Partial attributes to override defaults\n * @param factory - The factory instance for creating related records\n * @param db - The database connection\n * @returns The created record or a promise resolving to it\n *\n * @example\n * ```typescript\n * const userBuilder: MixedFactoryBuilder<UserAttrs, Factory, User, Kysely<DB>> =\n * async (attrs, factory, db) => {\n * return {\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * };\n * };\n * ```\n */\nexport type MixedFactoryBuilder<\n Attrs = any,\n Factory = any,\n Result = any,\n DB = any,\n> = (attrs: Attrs, factory: Factory, db: DB) => Result | Promise<Result>;\n\n/**\n * Type definition for a factory seed function used to create complex test scenarios.\n * Seeds typically create multiple related records to set up a complete test environment.\n *\n * @template Attrs - The attributes/input type for the seed\n * @template Factory - The factory instance type\n * @template Result - The type of object returned by the seed\n * @template DB - The database connection type (Kysely, Knex, etc.)\n *\n * @param context - Object containing attrs, factory, and db\n * @param context.attrs - Configuration attributes for the seed\n * @param context.factory - The factory instance for creating records\n * @param context.db - The database connection\n * @returns A promise resolving to the seed result\n *\n * @example\n * ```typescript\n * const userWithPostsSeed: FactorySeed<{ postCount?: number }, Factory, User, DB> =\n * async ({ attrs, factory, db }) => {\n * const user = await factory.insert('user', attrs);\n * const postCount = attrs.postCount || 3;\n *\n * for (let i = 0; i < postCount; i++) {\n * await factory.insert('post', { userId: user.id });\n * }\n *\n * return user;\n * };\n * ```\n */\nexport type FactorySeed<\n Attrs = any,\n Factory = any,\n Result = any,\n DB = any,\n> = (context: { attrs: Attrs; factory: Factory; db: DB }) => Promise<Result>;\n\n/**\n * Helper type to extract the Attrs type from a FactorySeed function.\n * Used internally by Factory implementations to correctly type the seed method parameters.\n */\nexport type ExtractSeedAttrs<T> = T extends (context: {\n attrs: infer A;\n factory: any;\n db: any;\n}) => any\n ? A\n : never;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,IAAsB,UAAtB,MAGE;;;;;;;;;;;;;;;;;CAiBA,OAAO,WAAqCA,QAAoB;AAC9D,SAAO;CACR;AAyCF"}
1
+ {"version":3,"file":"Factory-BhjUOBWN.cjs","names":["seedFn: Seed"],"sources":["../src/Factory.ts"],"sourcesContent":["import type { FakerFactory } from './faker';\n\n/**\n * Abstract base class for database factories used in testing.\n * Provides a standardized interface for creating test data using builder and seed patterns.\n *\n * @template Builders - Record of builder functions for creating individual entities\n * @template Seeds - Record of seed functions for creating complex test scenarios\n *\n * @example\n * ```typescript\n * // Define builders for creating individual records\n * const builders = {\n * user: (attrs) => ({ name: 'Test User', email: 'test@example.com', ...attrs }),\n * post: (attrs) => ({ title: 'Test Post', content: 'Content', ...attrs })\n * };\n *\n * // Define seeds for complex scenarios\n * const seeds = {\n * userWithPosts: async (attrs, factory) => {\n * const user = await factory.insert('user', attrs);\n * await factory.insertMany(3, 'post', { userId: user.id });\n * return user;\n * }\n * };\n * ```\n */\nexport abstract class Factory<\n\tBuilders extends Record<string, any>,\n\tSeeds extends Record<string, any>,\n> {\n\t/**\n\t * Creates a typed seed function with proper type inference.\n\t * This is a utility method to help with TypeScript type checking when defining seeds.\n\t *\n\t * @template Seed - The seed function type\n\t * @param seedFn - The seed function to wrap\n\t * @returns The same seed function with proper typing\n\t *\n\t * @example\n\t * ```typescript\n\t * const userWithPostsSeed = Factory.createSeed(async ({ attrs, factory, db }) => {\n\t * const user = await factory.insert('user', attrs);\n\t * return user;\n\t * });\n\t * ```\n\t */\n\tstatic createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n\t\treturn seedFn;\n\t}\n\t/**\n\t * Inserts an object into the database using a builder function.\n\t *\n\t * @param builderName - The name of the builder to use\n\t * @param attrs - The attributes to insert\n\t */\n\tabstract insert<K extends keyof Builders>(\n\t\tbuilderName: K,\n\t\tattrs?: Parameters<Builders[K]>[0],\n\t): Promise<Awaited<ReturnType<Builders[K]>>>;\n\n\t/**\n\t * Inserts multiple objects into the database\n\t *\n\t * @param count - Number of objects to insert\n\t * @param builderName - The name of the builder to use\n\t * @param attrs - The attributes to insert\n\t */\n\tabstract insertMany<K extends keyof Builders>(\n\t\tcount: number,\n\t\tbuilderName: K,\n\t\tattrs?:\n\t\t\t| Parameters<Builders[K]>[0]\n\t\t\t| ((\n\t\t\t\t\tidx: number,\n\t\t\t\t\tfaker: FakerFactory,\n\t\t\t ) => Promise<Parameters<Builders[K]>[0]>),\n\t): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n\n\t/**\n\t * Seeds the database using a seed function.\n\t *\n\t * @param seedName - The name of the seed to use\n\t * @returns The result of the seed function\n\t * @param attrs - The attributes to pass to the seed function\n\t */\n\tabstract seed<K extends keyof Seeds>(\n\t\tseedName: K,\n\t\tattrs?: ExtractSeedAttrs<Seeds[K]>,\n\t): ReturnType<Seeds[K]>;\n}\n\n/**\n * Type definition for a factory builder function that can work with different database types.\n * Builders are responsible for creating individual database records with default values and relationships.\n *\n * @template Attrs - The attributes/input type for the builder\n * @template Factory - The factory instance type\n * @template Result - The type of object returned by the builder\n * @template DB - The database connection type (Kysely, Knex, etc.)\n *\n * @param attrs - Partial attributes to override defaults\n * @param factory - The factory instance for creating related records\n * @param db - The database connection\n * @returns The created record or a promise resolving to it\n *\n * @example\n * ```typescript\n * const userBuilder: MixedFactoryBuilder<UserAttrs, Factory, User, Kysely<DB>> =\n * async (attrs, factory, db) => {\n * return {\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * };\n * };\n * ```\n */\nexport type MixedFactoryBuilder<\n\tAttrs = any,\n\tFactory = any,\n\tResult = any,\n\tDB = any,\n> = (attrs: Attrs, factory: Factory, db: DB) => Result | Promise<Result>;\n\n/**\n * Type definition for a factory seed function used to create complex test scenarios.\n * Seeds typically create multiple related records to set up a complete test environment.\n *\n * @template Attrs - The attributes/input type for the seed\n * @template Factory - The factory instance type\n * @template Result - The type of object returned by the seed\n * @template DB - The database connection type (Kysely, Knex, etc.)\n *\n * @param context - Object containing attrs, factory, and db\n * @param context.attrs - Configuration attributes for the seed\n * @param context.factory - The factory instance for creating records\n * @param context.db - The database connection\n * @returns A promise resolving to the seed result\n *\n * @example\n * ```typescript\n * const userWithPostsSeed: FactorySeed<{ postCount?: number }, Factory, User, DB> =\n * async ({ attrs, factory, db }) => {\n * const user = await factory.insert('user', attrs);\n * const postCount = attrs.postCount || 3;\n *\n * for (let i = 0; i < postCount; i++) {\n * await factory.insert('post', { userId: user.id });\n * }\n *\n * return user;\n * };\n * ```\n */\nexport type FactorySeed<\n\tAttrs = any,\n\tFactory = any,\n\tResult = any,\n\tDB = any,\n> = (context: { attrs: Attrs; factory: Factory; db: DB }) => Promise<Result>;\n\n/**\n * Helper type to extract the Attrs type from a FactorySeed function.\n * Used internally by Factory implementations to correctly type the seed method parameters.\n */\nexport type ExtractSeedAttrs<T> = T extends (context: {\n\tattrs: infer A;\n\tfactory: any;\n\tdb: any;\n}) => any\n\t? A\n\t: never;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,IAAsB,UAAtB,MAGE;;;;;;;;;;;;;;;;;CAiBD,OAAO,WAAqCA,QAAoB;AAC/D,SAAO;CACP;AAyCD"}
@@ -141,6 +141,7 @@ type ExtractSeedAttrs<T> = T extends ((context: {
141
141
  factory: any;
142
142
  db: any;
143
143
  }) => any) ? A : never;
144
+ //# sourceMappingURL=Factory.d.ts.map
144
145
  //#endregion
145
146
  export { ExtractSeedAttrs, Factory, FactorySeed, MixedFactoryBuilder };
146
- //# sourceMappingURL=Factory-BcGJjLc8.d.mts.map
147
+ //# sourceMappingURL=Factory-SFupxRC2.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Factory-SFupxRC2.d.mts","names":[],"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AC7B,WAAW,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8BT,kFAKA,gBAAgB,aAAa,OAAO,SAAS,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgCrD;SAKW;WAAgB;MAAa;MAAS,QAAQ;;;;;KAMzD,sBAAsB;;;;aAK/B"}
@@ -1,3 +1,3 @@
1
- import "./faker-DvxiCtxc.cjs";
2
- import { ExtractSeedAttrs, Factory, FactorySeed, MixedFactoryBuilder } from "./Factory-c16c27Y6.cjs";
1
+ import "./faker-Cg76aFNO.cjs";
2
+ import { ExtractSeedAttrs, Factory, FactorySeed, MixedFactoryBuilder } from "./Factory-BOX312yd.cjs";
3
3
  export { ExtractSeedAttrs, Factory, FactorySeed, MixedFactoryBuilder };
@@ -1,3 +1,3 @@
1
1
  import "./faker-DHh7xs4u.mjs";
2
- import { ExtractSeedAttrs, Factory, FactorySeed, MixedFactoryBuilder } from "./Factory-BcGJjLc8.mjs";
2
+ import { ExtractSeedAttrs, Factory, FactorySeed, MixedFactoryBuilder } from "./Factory-SFupxRC2.mjs";
3
3
  export { ExtractSeedAttrs, Factory, FactorySeed, MixedFactoryBuilder };
@@ -1 +1 @@
1
- {"version":3,"file":"KyselyFactory-BFqVIn_0.cjs","names":["Factory","seedFn: Seed","builders: Builders","seeds: Seeds","db: Kysely<DB> | ControlledTransaction<DB, []>","table: TableName","defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Kysely<DB>;\n faker: FakerFactory;\n }) =>\n | Partial<Insertable<DB[TableName]>>\n | Promise<Partial<Insertable<DB[TableName]>>>","autoInsert?: boolean","attrs: Attrs","factory: Factory","db: Kysely<DB>","fakerInstance: FakerFactory","data: Partial<Insertable<DB[TableName]>>","builderName: K","attrs?: Parameters<Builders[K]>[0]","faker","count: number","attrs?: any","promises: Promise<any>[]","seedName: K","attrs?: ExtractSeedAttrs<Seeds[K]>"],"sources":["../src/KyselyFactory.ts"],"sourcesContent":["import type {\n ControlledTransaction,\n Insertable,\n Kysely,\n Selectable,\n} from 'kysely';\nimport { type ExtractSeedAttrs, Factory, type FactorySeed } from './Factory.ts';\nimport { type FakerFactory, faker } from './faker.ts';\n\n/**\n * Factory implementation for Kysely ORM, providing test data creation utilities.\n * Extends the base Factory class with Kysely-specific database operations.\n *\n * @template DB - The database schema type\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 database schema\n * interface Database {\n * users: UsersTable;\n * posts: PostsTable;\n * }\n *\n * // Create builders\n * const builders = {\n * user: KyselyFactory.createBuilder<Database, 'users'>('users', ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * })),\n * post: KyselyFactory.createBuilder<Database, 'posts'>('posts', ({ attrs }) => ({\n * title: 'Test Post',\n * content: 'Test content',\n * ...attrs\n * }))\n * };\n *\n * // Create factory instance\n * const factory = new KyselyFactory(builders, seeds, db);\n *\n * // Use in tests\n * const user = await factory.insert('user', { name: 'John Doe' });\n * ```\n */\nexport class KyselyFactory<\n DB,\n Builders extends Record<string, any>,\n Seeds extends Record<string, any>,\n> extends Factory<Builders, Seeds> {\n /**\n * Creates a typed seed function with proper type inference.\n * Inherits from the base Factory class implementation.\n *\n * @template Seed - The seed function type\n * @param seedFn - The seed function to wrap (receives { attrs, factory, db } object)\n * @returns The same seed function with proper typing\n *\n * @example\n * ```typescript\n * const seeds = {\n * userWithPosts: KyselyFactory.createSeed(\n * async ({ attrs, factory }) => {\n * const user = await factory.insert('user', attrs);\n * await factory.insertMany(3, 'post', { userId: user.id });\n * return user;\n * },\n * ),\n * };\n * ```\n */\n static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n return Factory.createSeed(seedFn);\n }\n\n /**\n * Creates a new KyselyFactory instance.\n *\n * @param builders - Record of builder functions for creating individual entities\n * @param seeds - Record of seed functions for creating complex test scenarios\n * @param db - Kysely database instance or controlled transaction\n */\n constructor(\n private builders: Builders,\n private seeds: Seeds,\n private db: Kysely<DB> | ControlledTransaction<DB, []>,\n ) {\n super();\n }\n\n /**\n * Creates a typed builder function for a specific database table.\n * This is a utility method that helps create builders with proper type inference for Kysely.\n *\n * @template DB - The database schema type\n * @template TableName - The name of the table (must be a key of DB)\n * @template Attrs - The attributes type for the builder (defaults to Partial<Insertable>)\n * @template Factory - The factory instance type\n * @template Result - The result type (defaults to Selectable of the table)\n *\n * @param table - The name of the database table\n * @param defaults - Optional function to provide default values (receives destructured context)\n * @param autoInsert - Whether to automatically insert the record (default: true)\n * @returns A builder function that creates and optionally inserts records\n *\n * @example\n * ```typescript\n * // Create a simple builder with defaults - destructure only what you need\n * const userBuilder = KyselyFactory.createBuilder<DB, 'users'>('users',\n * ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * createdAt: new Date(),\n * ...attrs\n * })\n * );\n *\n * // Only need faker? Just destructure that\n * const leaveTypeBuilder = KyselyFactory.createBuilder<DB, 'leaveTypes'>('leaveTypes',\n * ({ faker }) => ({\n * name: faker.helpers.arrayElement(['Annual', 'Sick', 'Maternity']),\n * code: faker.string.alpha({ length: 3, casing: 'upper' }),\n * })\n * );\n *\n * // Create a builder that doesn't auto-insert (useful for nested inserts)\n * const addressBuilder = KyselyFactory.createBuilder<DB, 'addresses'>('addresses',\n * ({ attrs }) => ({\n * street: '123 Main St',\n * city: 'Anytown',\n * ...attrs\n * }),\n * false // Don't auto-insert\n * );\n * ```\n */\n static createBuilder<\n DB,\n TableName extends keyof DB & string,\n Attrs extends Partial<Insertable<DB[TableName]>> = Partial<\n Insertable<DB[TableName]>\n >,\n Factory = any,\n Result = Selectable<DB[TableName]>,\n >(\n table: TableName,\n defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Kysely<DB>;\n faker: FakerFactory;\n }) =>\n | Partial<Insertable<DB[TableName]>>\n | Promise<Partial<Insertable<DB[TableName]>>>,\n autoInsert?: boolean,\n ): (\n attrs: Attrs,\n factory: Factory,\n db: Kysely<DB>,\n faker: FakerFactory,\n ) => Promise<Result> {\n return async (\n attrs: Attrs,\n factory: Factory,\n db: Kysely<DB>,\n fakerInstance: FakerFactory,\n ) => {\n // Start with attributes\n let data: Partial<Insertable<DB[TableName]>> = { ...attrs };\n\n // Apply defaults\n if (defaults) {\n const defaultValues = await defaults({\n attrs,\n factory,\n db,\n faker: fakerInstance,\n });\n data = { ...defaultValues, ...data };\n }\n\n // Handle insertion based on autoInsert flag\n if (autoInsert !== false) {\n // Auto insert is enabled by default\n const result = await db\n .insertInto(table)\n .values(data as Insertable<DB[TableName]>)\n .returningAll()\n .executeTakeFirst();\n\n if (!result) {\n throw new Error(`Failed to insert into ${table}`);\n }\n\n return result as Result;\n } else {\n // Return object for factory to handle insertion\n return { table, data } as any;\n }\n };\n }\n\n /**\n * Inserts a single record into the database using the specified builder.\n * The builder function is responsible for generating the record data with defaults\n * and the factory handles the actual database insertion.\n *\n * @template K - The builder name (must be a key of Builders)\n * @param builderName - The name of the builder to use\n * @param attrs - Optional attributes to override builder defaults\n * @returns A promise resolving to the inserted record\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert with defaults\n * const user = await factory.insert('user');\n *\n * // Insert with overrides\n * const adminUser = await factory.insert('user', {\n * email: 'admin@example.com',\n * role: 'admin'\n * });\n *\n * // Use the inserted record\n * const post = await factory.insert('post', {\n * userId: user.id,\n * title: 'My First Post'\n * });\n * ```\n */\n async insert<K extends keyof Builders>(\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Factory \"${\n builderName as string\n }\" does not exist. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const result = await this.builders[builderName](\n attrs || {},\n this,\n this.db,\n faker,\n );\n\n // For Kysely, we expect the builder to return an object with table and data properties\n // or to handle the insertion itself and return the inserted record\n if (\n result &&\n typeof result === 'object' &&\n 'table' in result &&\n 'data' in result\n ) {\n // If the builder returns {table: string, data: object}, we insert it\n const inserted = await this.db\n .insertInto(result.table)\n .values(result.data)\n .returningAll()\n .executeTakeFirst();\n\n return inserted as any;\n }\n\n // Otherwise, assume the builder handled the insertion itself\n return result;\n }\n\n /**\n * Inserts multiple records into the database using the specified builder.\n * Supports both static attributes and dynamic attribute generation via a function.\n *\n * @template K - The builder name (must be a key of Builders)\n * @param count - The number of records to insert\n * @param builderName - The name of the builder to use\n * @param attrs - Static attributes or a function that generates attributes for each record\n * @returns A promise resolving to an array of inserted records\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert multiple with same attributes\n * const users = await factory.insertMany(5, 'user', { role: 'member' });\n *\n * // Insert multiple with dynamic attributes\n * const posts = await factory.insertMany(10, 'post', (idx, faker) => ({\n * title: `Post ${idx + 1}`,\n * content: faker.lorem.paragraph(),\n * publishedAt: faker.date.past()\n * }));\n *\n * // Create users with sequential emails\n * const admins = await factory.insertMany(3, 'user', (idx) => ({\n * email: `admin${idx + 1}@example.com`,\n * role: 'admin'\n * }));\n * ```\n */\n // Method overloads for better type inference\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs: (\n idx: number,\n faker: FakerFactory,\n ) => Parameters<Builders[K]>[0] | Promise<Parameters<Builders[K]>[0]>,\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: any,\n ): Promise<Awaited<ReturnType<Builders[K]>>[]> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Builder \"${\n builderName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const promises: Promise<any>[] = [];\n\n for (let i = 0; i < count; i++) {\n const newAttrs =\n typeof attrs === 'function' ? await attrs(i, faker) : attrs;\n promises.push(this.insert(builderName, newAttrs));\n }\n\n return Promise.all(promises);\n }\n\n /**\n * Executes a seed function to create complex test scenarios with multiple related records.\n * Seeds are useful for setting up complete test environments with realistic data relationships.\n *\n * @template K - The seed name (must be a key of Seeds)\n * @param seedName - The name of the seed to execute\n * @param attrs - Optional configuration attributes for the seed\n * @returns The result of the seed function (typically the primary record created)\n * @throws Error if the specified seed doesn't exist\n *\n * @example\n * ```typescript\n * // Execute a simple seed\n * const user = await factory.seed('userWithProfile');\n *\n * // Execute a seed with configuration\n * const author = await factory.seed('authorWithBooks', {\n * bookCount: 5,\n * includeReviews: true\n * });\n *\n * // Use seed result in tests\n * const company = await factory.seed('companyWithDepartments', {\n * departmentCount: 3,\n * employeesPerDepartment: 10\n * });\n * expect(company.departments).toHaveLength(3);\n * ```\n */\n seed<K extends keyof Seeds>(\n seedName: K,\n attrs?: ExtractSeedAttrs<Seeds[K]>,\n ): ReturnType<Seeds[K]> {\n if (!(seedName in this.seeds)) {\n throw new Error(\n `Seed \"${\n seedName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n return this.seeds[seedName]({\n attrs: attrs || {},\n factory: this,\n db: this.db,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,gBAAb,cAIUA,wBAAyB;;;;;;;;;;;;;;;;;;;;;;CAsBjC,OAAO,WAAqCC,QAAoB;AAC9D,SAAO,wBAAQ,WAAW,OAAO;CAClC;;;;;;;;CASD,YACUC,UACAC,OACAC,IACR;AACA,SAAO;EAJC;EACA;EACA;CAGT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDD,OAAO,cASLC,OACAC,UAQAC,YAMmB;AACnB,SAAO,OACLC,OACAC,SACAC,IACAC,kBACG;GAEH,IAAIC,OAA2C,E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M,UAAU;GAC1B,OAAO,SAAS,CAAE;GAClB,SAAS;GACT,IAAI,KAAK;EACV,EAAC;CACH;AACF"}
1
+ {"version":3,"file":"KyselyFactory-BFqVIn_0.cjs","names":["Factory","seedFn: Seed","builders: Builders","seeds: Seeds","db: Kysely<DB> | ControlledTransaction<DB, []>","table: TableName","defaults?: (context: {\n\t\t\tattrs: Attrs;\n\t\t\tfactory: Factory;\n\t\t\tdb: Kysely<DB>;\n\t\t\tfaker: FakerFactory;\n\t\t}) =>\n\t\t\t| Partial<Insertable<DB[TableName]>>\n\t\t\t| Promise<Partial<Insertable<DB[TableName]>>>","autoInsert?: boolean","attrs: Attrs","factory: Factory","db: Kysely<DB>","fakerInstance: FakerFactory","data: Partial<Insertable<DB[TableName]>>","builderName: K","attrs?: Parameters<Builders[K]>[0]","faker","count: number","attrs?: any","promises: Promise<any>[]","seedName: K","attrs?: ExtractSeedAttrs<Seeds[K]>"],"sources":["../src/KyselyFactory.ts"],"sourcesContent":["import type {\n\tControlledTransaction,\n\tInsertable,\n\tKysely,\n\tSelectable,\n} from 'kysely';\nimport { type ExtractSeedAttrs, Factory, type FactorySeed } from './Factory';\nimport { type FakerFactory, faker } from './faker';\n\n/**\n * Factory implementation for Kysely ORM, providing test data creation utilities.\n * Extends the base Factory class with Kysely-specific database operations.\n *\n * @template DB - The database schema type\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 database schema\n * interface Database {\n * users: UsersTable;\n * posts: PostsTable;\n * }\n *\n * // Create builders\n * const builders = {\n * user: KyselyFactory.createBuilder<Database, 'users'>('users', ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * })),\n * post: KyselyFactory.createBuilder<Database, 'posts'>('posts', ({ attrs }) => ({\n * title: 'Test Post',\n * content: 'Test content',\n * ...attrs\n * }))\n * };\n *\n * // Create factory instance\n * const factory = new KyselyFactory(builders, seeds, db);\n *\n * // Use in tests\n * const user = await factory.insert('user', { name: 'John Doe' });\n * ```\n */\nexport class KyselyFactory<\n\tDB,\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: KyselyFactory.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 new KyselyFactory 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 - Kysely database instance or controlled transaction\n\t */\n\tconstructor(\n\t\tprivate builders: Builders,\n\t\tprivate seeds: Seeds,\n\t\tprivate db: Kysely<DB> | ControlledTransaction<DB, []>,\n\t) {\n\t\tsuper();\n\t}\n\n\t/**\n\t * Creates a typed builder function for a specific database table.\n\t * This is a utility method that helps create builders with proper type inference for Kysely.\n\t *\n\t * @template DB - The database schema type\n\t * @template TableName - The name of the table (must be a key of DB)\n\t * @template Attrs - The attributes type for the builder (defaults to Partial<Insertable>)\n\t * @template Factory - The factory instance type\n\t * @template Result - The result type (defaults to Selectable of the table)\n\t *\n\t * @param table - The name of the database table\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 = KyselyFactory.createBuilder<DB, 'users'>('users',\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 = KyselyFactory.createBuilder<DB, 'leaveTypes'>('leaveTypes',\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 = KyselyFactory.createBuilder<DB, 'addresses'>('addresses',\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 */\n\tstatic createBuilder<\n\t\tDB,\n\t\tTableName extends keyof DB & string,\n\t\tAttrs extends Partial<Insertable<DB[TableName]>> = Partial<\n\t\t\tInsertable<DB[TableName]>\n\t\t>,\n\t\tFactory = any,\n\t\tResult = Selectable<DB[TableName]>,\n\t>(\n\t\ttable: TableName,\n\t\tdefaults?: (context: {\n\t\t\tattrs: Attrs;\n\t\t\tfactory: Factory;\n\t\t\tdb: Kysely<DB>;\n\t\t\tfaker: FakerFactory;\n\t\t}) =>\n\t\t\t| Partial<Insertable<DB[TableName]>>\n\t\t\t| Promise<Partial<Insertable<DB[TableName]>>>,\n\t\tautoInsert?: boolean,\n\t): (\n\t\tattrs: Attrs,\n\t\tfactory: Factory,\n\t\tdb: Kysely<DB>,\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: Kysely<DB>,\n\t\t\tfakerInstance: FakerFactory,\n\t\t) => {\n\t\t\t// Start with attributes\n\t\t\tlet data: Partial<Insertable<DB[TableName]>> = { ...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// 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\tconst result = await db\n\t\t\t\t\t.insertInto(table)\n\t\t\t\t\t.values(data as Insertable<DB[TableName]>)\n\t\t\t\t\t.returningAll()\n\t\t\t\t\t.executeTakeFirst();\n\n\t\t\t\tif (!result) {\n\t\t\t\t\tthrow new Error(`Failed to insert into ${table}`);\n\t\t\t\t}\n\n\t\t\t\treturn result as Result;\n\t\t\t} else {\n\t\t\t\t// Return object for factory to handle insertion\n\t\t\t\treturn { table, data } as any;\n\t\t\t}\n\t\t};\n\t}\n\n\t/**\n\t * Inserts a single record into the database using the specified builder.\n\t * The builder function is responsible for generating the record data with defaults\n\t * and the factory handles the actual database insertion.\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\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 * // Use the inserted record\n\t * const post = await factory.insert('post', {\n\t * userId: user.id,\n\t * title: 'My First Post'\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// For Kysely, we expect the builder to return an object with table and data properties\n\t\t// or to handle the insertion itself and return the inserted record\n\t\tif (\n\t\t\tresult &&\n\t\t\ttypeof result === 'object' &&\n\t\t\t'table' in result &&\n\t\t\t'data' in result\n\t\t) {\n\t\t\t// If the builder returns {table: string, data: object}, we insert it\n\t\t\tconst inserted = await this.db\n\t\t\t\t.insertInto(result.table)\n\t\t\t\t.values(result.data)\n\t\t\t\t.returningAll()\n\t\t\t\t.executeTakeFirst();\n\n\t\t\treturn inserted as any;\n\t\t}\n\n\t\t// Otherwise, assume the builder handled the insertion itself\n\t\treturn result;\n\t}\n\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 * @template K - The builder name (must be a key of Builders)\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, faker) => ({\n\t * title: `Post ${idx + 1}`,\n\t * content: faker.lorem.paragraph(),\n\t * publishedAt: faker.date.past()\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: (\n\t\t\tidx: number,\n\t\t\tfaker: FakerFactory,\n\t\t) => Parameters<Builders[K]>[0] | Promise<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 promises: Promise<any>[] = [];\n\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tconst newAttrs =\n\t\t\t\ttypeof attrs === 'function' ? await attrs(i, faker) : attrs;\n\t\t\tpromises.push(this.insert(builderName, newAttrs));\n\t\t}\n\n\t\treturn Promise.all(promises);\n\t}\n\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\n\t * const company = await factory.seed('companyWithDepartments', {\n\t * departmentCount: 3,\n\t * employeesPerDepartment: 10\n\t * });\n\t * expect(company.departments).toHaveLength(3);\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,gBAAb,cAIUA,wBAAyB;;;;;;;;;;;;;;;;;;;;;;CAsBlC,OAAgB,WAAqCC,QAAoB;AACxE,SAAO,wBAAQ,WAAW,OAAO;CACjC;;;;;;;;CASD,YACSC,UACAC,OACAC,IACP;AACD,SAAO;EAJC;EACA;EACA;CAGR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDD,OAAO,cASNC,OACAC,UAQAC,YAMoB;AACpB,SAAO,OACNC,OACAC,SACAC,IACAC,kBACI;GAEJ,IAAIC,OAA2C,EAAE,GAAG,MAAO;AAG3D,OAAI,UAAU;IACb,MAAM,gBAAgB,MAAM,SAAS;KACpC;KACA;KACA;KACA,OAAO;IACP,EAAC;AACF,WAAO;KAAE,GAAG;KAAe,GAAG;IAAM;GACpC;AAGD,OAAI,eAAe,OAAO;IAEzB,MAAM,SAAS,MAAM,GACnB,WAAW,MAAM,CACjB,OAAO,KAAkC,CACzC,cAAc,CACd,kBAAkB;AAEpB,SAAK,OACJ,OAAM,IAAI,OAAO,wBAAwB,MAAM;AAGhD,WAAO;GACP,MAEA,QAAO;IAAE;IAAO;GAAM;EAEvB;CACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BD,MAAM,OACLC,aACAC,OAC4C;AAC5C,QAAM,eAAe,KAAK,UACzB,OAAM,IAAI,OACR,WACA,YACA;EAIH,MAAM,SAAS,MAAM,KAAK,SAAS,aAClC,SAAS,CAAE,GACX,MACA,KAAK,IACLC,oBACA;AAID,MACC,iBACO,WAAW,YAClB,WAAW,UACX,UAAU,QACT;GAED,MAAM,WAAW,MAAM,KAAK,GAC1B,WAAW,OAAO,MAAM,CACxB,OAAO,OAAO,KAAK,CACnB,cAAc,CACd,kBAAkB;AAEpB,UAAO;EACP;AAGD,SAAO;CACP;CA8CD,MAAM,WACLC,OACAH,aACAI,OAC8C;AAC9C,QAAM,eAAe,KAAK,UACzB,OAAM,IAAI,OACR,WACA,YACA;EAIH,MAAMC,WAA2B,CAAE;AAEnC,OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;GAC/B,MAAM,kBACE,UAAU,aAAa,MAAM,MAAM,GAAGH,oBAAM,GAAG;AACvD,YAAS,KAAK,KAAK,OAAO,aAAa,SAAS,CAAC;EACjD;AAED,SAAO,QAAQ,IAAI,SAAS;CAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BD,KACCI,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 +1 @@
1
- {"version":3,"file":"KyselyFactory-DMswpwji.mjs","names":["seedFn: Seed","builders: Builders","seeds: Seeds","db: Kysely<DB> | ControlledTransaction<DB, []>","table: TableName","defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Kysely<DB>;\n faker: FakerFactory;\n }) =>\n | Partial<Insertable<DB[TableName]>>\n | Promise<Partial<Insertable<DB[TableName]>>>","autoInsert?: boolean","attrs: Attrs","factory: Factory","db: Kysely<DB>","fakerInstance: FakerFactory","data: Partial<Insertable<DB[TableName]>>","builderName: K","attrs?: Parameters<Builders[K]>[0]","count: number","attrs?: any","promises: Promise<any>[]","seedName: K","attrs?: ExtractSeedAttrs<Seeds[K]>"],"sources":["../src/KyselyFactory.ts"],"sourcesContent":["import type {\n ControlledTransaction,\n Insertable,\n Kysely,\n Selectable,\n} from 'kysely';\nimport { type ExtractSeedAttrs, Factory, type FactorySeed } from './Factory.ts';\nimport { type FakerFactory, faker } from './faker.ts';\n\n/**\n * Factory implementation for Kysely ORM, providing test data creation utilities.\n * Extends the base Factory class with Kysely-specific database operations.\n *\n * @template DB - The database schema type\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 database schema\n * interface Database {\n * users: UsersTable;\n * posts: PostsTable;\n * }\n *\n * // Create builders\n * const builders = {\n * user: KyselyFactory.createBuilder<Database, 'users'>('users', ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * })),\n * post: KyselyFactory.createBuilder<Database, 'posts'>('posts', ({ attrs }) => ({\n * title: 'Test Post',\n * content: 'Test content',\n * ...attrs\n * }))\n * };\n *\n * // Create factory instance\n * const factory = new KyselyFactory(builders, seeds, db);\n *\n * // Use in tests\n * const user = await factory.insert('user', { name: 'John Doe' });\n * ```\n */\nexport class KyselyFactory<\n DB,\n Builders extends Record<string, any>,\n Seeds extends Record<string, any>,\n> extends Factory<Builders, Seeds> {\n /**\n * Creates a typed seed function with proper type inference.\n * Inherits from the base Factory class implementation.\n *\n * @template Seed - The seed function type\n * @param seedFn - The seed function to wrap (receives { attrs, factory, db } object)\n * @returns The same seed function with proper typing\n *\n * @example\n * ```typescript\n * const seeds = {\n * userWithPosts: KyselyFactory.createSeed(\n * async ({ attrs, factory }) => {\n * const user = await factory.insert('user', attrs);\n * await factory.insertMany(3, 'post', { userId: user.id });\n * return user;\n * },\n * ),\n * };\n * ```\n */\n static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n return Factory.createSeed(seedFn);\n }\n\n /**\n * Creates a new KyselyFactory instance.\n *\n * @param builders - Record of builder functions for creating individual entities\n * @param seeds - Record of seed functions for creating complex test scenarios\n * @param db - Kysely database instance or controlled transaction\n */\n constructor(\n private builders: Builders,\n private seeds: Seeds,\n private db: Kysely<DB> | ControlledTransaction<DB, []>,\n ) {\n super();\n }\n\n /**\n * Creates a typed builder function for a specific database table.\n * This is a utility method that helps create builders with proper type inference for Kysely.\n *\n * @template DB - The database schema type\n * @template TableName - The name of the table (must be a key of DB)\n * @template Attrs - The attributes type for the builder (defaults to Partial<Insertable>)\n * @template Factory - The factory instance type\n * @template Result - The result type (defaults to Selectable of the table)\n *\n * @param table - The name of the database table\n * @param defaults - Optional function to provide default values (receives destructured context)\n * @param autoInsert - Whether to automatically insert the record (default: true)\n * @returns A builder function that creates and optionally inserts records\n *\n * @example\n * ```typescript\n * // Create a simple builder with defaults - destructure only what you need\n * const userBuilder = KyselyFactory.createBuilder<DB, 'users'>('users',\n * ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * createdAt: new Date(),\n * ...attrs\n * })\n * );\n *\n * // Only need faker? Just destructure that\n * const leaveTypeBuilder = KyselyFactory.createBuilder<DB, 'leaveTypes'>('leaveTypes',\n * ({ faker }) => ({\n * name: faker.helpers.arrayElement(['Annual', 'Sick', 'Maternity']),\n * code: faker.string.alpha({ length: 3, casing: 'upper' }),\n * })\n * );\n *\n * // Create a builder that doesn't auto-insert (useful for nested inserts)\n * const addressBuilder = KyselyFactory.createBuilder<DB, 'addresses'>('addresses',\n * ({ attrs }) => ({\n * street: '123 Main St',\n * city: 'Anytown',\n * ...attrs\n * }),\n * false // Don't auto-insert\n * );\n * ```\n */\n static createBuilder<\n DB,\n TableName extends keyof DB & string,\n Attrs extends Partial<Insertable<DB[TableName]>> = Partial<\n Insertable<DB[TableName]>\n >,\n Factory = any,\n Result = Selectable<DB[TableName]>,\n >(\n table: TableName,\n defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Kysely<DB>;\n faker: FakerFactory;\n }) =>\n | Partial<Insertable<DB[TableName]>>\n | Promise<Partial<Insertable<DB[TableName]>>>,\n autoInsert?: boolean,\n ): (\n attrs: Attrs,\n factory: Factory,\n db: Kysely<DB>,\n faker: FakerFactory,\n ) => Promise<Result> {\n return async (\n attrs: Attrs,\n factory: Factory,\n db: Kysely<DB>,\n fakerInstance: FakerFactory,\n ) => {\n // Start with attributes\n let data: Partial<Insertable<DB[TableName]>> = { ...attrs };\n\n // Apply defaults\n if (defaults) {\n const defaultValues = await defaults({\n attrs,\n factory,\n db,\n faker: fakerInstance,\n });\n data = { ...defaultValues, ...data };\n }\n\n // Handle insertion based on autoInsert flag\n if (autoInsert !== false) {\n // Auto insert is enabled by default\n const result = await db\n .insertInto(table)\n .values(data as Insertable<DB[TableName]>)\n .returningAll()\n .executeTakeFirst();\n\n if (!result) {\n throw new Error(`Failed to insert into ${table}`);\n }\n\n return result as Result;\n } else {\n // Return object for factory to handle insertion\n return { table, data } as any;\n }\n };\n }\n\n /**\n * Inserts a single record into the database using the specified builder.\n * The builder function is responsible for generating the record data with defaults\n * and the factory handles the actual database insertion.\n *\n * @template K - The builder name (must be a key of Builders)\n * @param builderName - The name of the builder to use\n * @param attrs - Optional attributes to override builder defaults\n * @returns A promise resolving to the inserted record\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert with defaults\n * const user = await factory.insert('user');\n *\n * // Insert with overrides\n * const adminUser = await factory.insert('user', {\n * email: 'admin@example.com',\n * role: 'admin'\n * });\n *\n * // Use the inserted record\n * const post = await factory.insert('post', {\n * userId: user.id,\n * title: 'My First Post'\n * });\n * ```\n */\n async insert<K extends keyof Builders>(\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Factory \"${\n builderName as string\n }\" does not exist. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const result = await this.builders[builderName](\n attrs || {},\n this,\n this.db,\n faker,\n );\n\n // For Kysely, we expect the builder to return an object with table and data properties\n // or to handle the insertion itself and return the inserted record\n if (\n result &&\n typeof result === 'object' &&\n 'table' in result &&\n 'data' in result\n ) {\n // If the builder returns {table: string, data: object}, we insert it\n const inserted = await this.db\n .insertInto(result.table)\n .values(result.data)\n .returningAll()\n .executeTakeFirst();\n\n return inserted as any;\n }\n\n // Otherwise, assume the builder handled the insertion itself\n return result;\n }\n\n /**\n * Inserts multiple records into the database using the specified builder.\n * Supports both static attributes and dynamic attribute generation via a function.\n *\n * @template K - The builder name (must be a key of Builders)\n * @param count - The number of records to insert\n * @param builderName - The name of the builder to use\n * @param attrs - Static attributes or a function that generates attributes for each record\n * @returns A promise resolving to an array of inserted records\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert multiple with same attributes\n * const users = await factory.insertMany(5, 'user', { role: 'member' });\n *\n * // Insert multiple with dynamic attributes\n * const posts = await factory.insertMany(10, 'post', (idx, faker) => ({\n * title: `Post ${idx + 1}`,\n * content: faker.lorem.paragraph(),\n * publishedAt: faker.date.past()\n * }));\n *\n * // Create users with sequential emails\n * const admins = await factory.insertMany(3, 'user', (idx) => ({\n * email: `admin${idx + 1}@example.com`,\n * role: 'admin'\n * }));\n * ```\n */\n // Method overloads for better type inference\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs: (\n idx: number,\n faker: FakerFactory,\n ) => Parameters<Builders[K]>[0] | Promise<Parameters<Builders[K]>[0]>,\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: any,\n ): Promise<Awaited<ReturnType<Builders[K]>>[]> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Builder \"${\n builderName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const promises: Promise<any>[] = [];\n\n for (let i = 0; i < count; i++) {\n const newAttrs =\n typeof attrs === 'function' ? await attrs(i, faker) : attrs;\n promises.push(this.insert(builderName, newAttrs));\n }\n\n return Promise.all(promises);\n }\n\n /**\n * Executes a seed function to create complex test scenarios with multiple related records.\n * Seeds are useful for setting up complete test environments with realistic data relationships.\n *\n * @template K - The seed name (must be a key of Seeds)\n * @param seedName - The name of the seed to execute\n * @param attrs - Optional configuration attributes for the seed\n * @returns The result of the seed function (typically the primary record created)\n * @throws Error if the specified seed doesn't exist\n *\n * @example\n * ```typescript\n * // Execute a simple seed\n * const user = await factory.seed('userWithProfile');\n *\n * // Execute a seed with configuration\n * const author = await factory.seed('authorWithBooks', {\n * bookCount: 5,\n * includeReviews: true\n * });\n *\n * // Use seed result in tests\n * const company = await factory.seed('companyWithDepartments', {\n * departmentCount: 3,\n * employeesPerDepartment: 10\n * });\n * expect(company.departments).toHaveLength(3);\n * ```\n */\n seed<K extends keyof Seeds>(\n seedName: K,\n attrs?: ExtractSeedAttrs<Seeds[K]>,\n ): ReturnType<Seeds[K]> {\n if (!(seedName in this.seeds)) {\n throw new Error(\n `Seed \"${\n seedName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n return this.seeds[seedName]({\n attrs: attrs || {},\n factory: this,\n db: this.db,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,gBAAb,cAIU,QAAyB;;;;;;;;;;;;;;;;;;;;;;CAsBjC,OAAO,WAAqCA,QAAoB;AAC9D,SAAO,QAAQ,WAAW,OAAO;CAClC;;;;;;;;CASD,YAC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K,OAAO,aAAa,SAAS,CAAC;EAClD;AAED,SAAO,QAAQ,IAAI,SAAS;CAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BD,KACEC,UACAC,OACsB;AACtB,QAAM,YAAY,KAAK,OACrB,OAAM,IAAI,OACP,QACC,SACD;AAIL,SAAO,KAAK,MAAM,UAAU;GAC1B,OAAO,SAAS,CAAE;GAClB,SAAS;GACT,IAAI,KAAK;EACV,EAAC;CACH;AACF"}
1
+ {"version":3,"file":"KyselyFactory-DMswpwji.mjs","names":["seedFn: Seed","builders: Builders","seeds: Seeds","db: Kysely<DB> | ControlledTransaction<DB, []>","table: TableName","defaults?: (context: {\n\t\t\tattrs: Attrs;\n\t\t\tfactory: Factory;\n\t\t\tdb: Kysely<DB>;\n\t\t\tfaker: FakerFactory;\n\t\t}) =>\n\t\t\t| Partial<Insertable<DB[TableName]>>\n\t\t\t| Promise<Partial<Insertable<DB[TableName]>>>","autoInsert?: boolean","attrs: Attrs","factory: Factory","db: Kysely<DB>","fakerInstance: FakerFactory","data: Partial<Insertable<DB[TableName]>>","builderName: K","attrs?: Parameters<Builders[K]>[0]","count: number","attrs?: any","promises: Promise<any>[]","seedName: K","attrs?: ExtractSeedAttrs<Seeds[K]>"],"sources":["../src/KyselyFactory.ts"],"sourcesContent":["import type {\n\tControlledTransaction,\n\tInsertable,\n\tKysely,\n\tSelectable,\n} from 'kysely';\nimport { type ExtractSeedAttrs, Factory, type FactorySeed } from './Factory';\nimport { type FakerFactory, faker } from './faker';\n\n/**\n * Factory implementation for Kysely ORM, providing test data creation utilities.\n * Extends the base Factory class with Kysely-specific database operations.\n *\n * @template DB - The database schema type\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 database schema\n * interface Database {\n * users: UsersTable;\n * posts: PostsTable;\n * }\n *\n * // Create builders\n * const builders = {\n * user: KyselyFactory.createBuilder<Database, 'users'>('users', ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * })),\n * post: KyselyFactory.createBuilder<Database, 'posts'>('posts', ({ attrs }) => ({\n * title: 'Test Post',\n * content: 'Test content',\n * ...attrs\n * }))\n * };\n *\n * // Create factory instance\n * const factory = new KyselyFactory(builders, seeds, db);\n *\n * // Use in tests\n * const user = await factory.insert('user', { name: 'John Doe' });\n * ```\n */\nexport class KyselyFactory<\n\tDB,\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: KyselyFactory.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 new KyselyFactory 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 - Kysely database instance or controlled transaction\n\t */\n\tconstructor(\n\t\tprivate builders: Builders,\n\t\tprivate seeds: Seeds,\n\t\tprivate db: Kysely<DB> | ControlledTransaction<DB, []>,\n\t) {\n\t\tsuper();\n\t}\n\n\t/**\n\t * Creates a typed builder function for a specific database table.\n\t * This is a utility method that helps create builders with proper type inference for Kysely.\n\t *\n\t * @template DB - The database schema type\n\t * @template TableName - The name of the table (must be a key of DB)\n\t * @template Attrs - The attributes type for the builder (defaults to Partial<Insertable>)\n\t * @template Factory - The factory instance type\n\t * @template Result - The result type (defaults to Selectable of the table)\n\t *\n\t * @param table - The name of the database table\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 = KyselyFactory.createBuilder<DB, 'users'>('users',\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 = KyselyFactory.createBuilder<DB, 'leaveTypes'>('leaveTypes',\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 = KyselyFactory.createBuilder<DB, 'addresses'>('addresses',\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 */\n\tstatic createBuilder<\n\t\tDB,\n\t\tTableName extends keyof DB & string,\n\t\tAttrs extends Partial<Insertable<DB[TableName]>> = Partial<\n\t\t\tInsertable<DB[TableName]>\n\t\t>,\n\t\tFactory = any,\n\t\tResult = Selectable<DB[TableName]>,\n\t>(\n\t\ttable: TableName,\n\t\tdefaults?: (context: {\n\t\t\tattrs: Attrs;\n\t\t\tfactory: Factory;\n\t\t\tdb: Kysely<DB>;\n\t\t\tfaker: FakerFactory;\n\t\t}) =>\n\t\t\t| Partial<Insertable<DB[TableName]>>\n\t\t\t| Promise<Partial<Insertable<DB[TableName]>>>,\n\t\tautoInsert?: boolean,\n\t): (\n\t\tattrs: Attrs,\n\t\tfactory: Factory,\n\t\tdb: Kysely<DB>,\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: Kysely<DB>,\n\t\t\tfakerInstance: FakerFactory,\n\t\t) => {\n\t\t\t// Start with attributes\n\t\t\tlet data: Partial<Insertable<DB[TableName]>> = { ...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// 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\tconst result = await db\n\t\t\t\t\t.insertInto(table)\n\t\t\t\t\t.values(data as Insertable<DB[TableName]>)\n\t\t\t\t\t.returningAll()\n\t\t\t\t\t.executeTakeFirst();\n\n\t\t\t\tif (!result) {\n\t\t\t\t\tthrow new Error(`Failed to insert into ${table}`);\n\t\t\t\t}\n\n\t\t\t\treturn result as Result;\n\t\t\t} else {\n\t\t\t\t// Return object for factory to handle insertion\n\t\t\t\treturn { table, data } as any;\n\t\t\t}\n\t\t};\n\t}\n\n\t/**\n\t * Inserts a single record into the database using the specified builder.\n\t * The builder function is responsible for generating the record data with defaults\n\t * and the factory handles the actual database insertion.\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\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 * // Use the inserted record\n\t * const post = await factory.insert('post', {\n\t * userId: user.id,\n\t * title: 'My First Post'\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// For Kysely, we expect the builder to return an object with table and data properties\n\t\t// or to handle the insertion itself and return the inserted record\n\t\tif (\n\t\t\tresult &&\n\t\t\ttypeof result === 'object' &&\n\t\t\t'table' in result &&\n\t\t\t'data' in result\n\t\t) {\n\t\t\t// If the builder returns {table: string, data: object}, we insert it\n\t\t\tconst inserted = await this.db\n\t\t\t\t.insertInto(result.table)\n\t\t\t\t.values(result.data)\n\t\t\t\t.returningAll()\n\t\t\t\t.executeTakeFirst();\n\n\t\t\treturn inserted as any;\n\t\t}\n\n\t\t// Otherwise, assume the builder handled the insertion itself\n\t\treturn result;\n\t}\n\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 * @template K - The builder name (must be a key of Builders)\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, faker) => ({\n\t * title: `Post ${idx + 1}`,\n\t * content: faker.lorem.paragraph(),\n\t * publishedAt: faker.date.past()\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: (\n\t\t\tidx: number,\n\t\t\tfaker: FakerFactory,\n\t\t) => Parameters<Builders[K]>[0] | Promise<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 promises: Promise<any>[] = [];\n\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tconst newAttrs =\n\t\t\t\ttypeof attrs === 'function' ? await attrs(i, faker) : attrs;\n\t\t\tpromises.push(this.insert(builderName, newAttrs));\n\t\t}\n\n\t\treturn Promise.all(promises);\n\t}\n\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\n\t * const company = await factory.seed('companyWithDepartments', {\n\t * departmentCount: 3,\n\t * employeesPerDepartment: 10\n\t * });\n\t * expect(company.departments).toHaveLength(3);\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,gBAAb,cAIU,QAAyB;;;;;;;;;;;;;;;;;;;;;;CAsBlC,OAAgB,WAAqCA,QAAoB;AACxE,SAAO,QAAQ,WAAW,OAAO;CACjC;;;;;;;;CASD,YACSC,UACAC,OACAC,IACP;AACD,SAAO;EAJC;EACA;EACA;CAGR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDD,OAAO,cASNC,OACAC,UAQAC,YAMoB;AACpB,SAAO,OACNC,OACAC,SACAC,IACAC,kBACI;GAEJ,IAAIC,OAA2C,EAAE,GAAG,MAAO;AAG3D,OAAI,UAAU;IACb,MAAM,gBAAgB,MAAM,SAAS;KACpC;KACA;KACA;KACA,OAAO;IACP,EAAC;AACF,WAAO;KAAE,GAAG;KAAe,GAAG;IAAM;GACpC;AAGD,OAAI,eAAe,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orySeed } from "./Factory-c16c27Y6.cjs";
1
+ import { FakerFactory } from "./faker-Cg76aFNO.cjs";
2
+ import { ExtractSeedAttrs, Factory, FactorySeed } from "./Factory-BOX312yd.cjs";
3
3
  import { ControlledTransaction, Insertable, Kysely, Selectable } from "kysely";
4
4
 
5
5
  //#region src/KyselyFactory.d.ts
@@ -222,6 +222,7 @@ declare class KyselyFactory<DB, Builders extends Record<string, any>, Seeds exte
222
222
  */
223
223
  seed<K extends keyof Seeds>(seedName: K, attrs?: ExtractSeedAttrs<Seeds[K]>): ReturnType<Seeds[K]>;
224
224
  }
225
+ //# sourceMappingURL=KyselyFactory.d.ts.map
225
226
  //#endregion
226
227
  export { KyselyFactory };
227
- //# sourceMappingURL=KyselyFactory-uZ45h7YU.d.cts.map
228
+ //# sourceMappingURL=KyselyFactory-Dy5zzV4B.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KyselyFactory-Dy5zzV4B.d.cts","names":[],"sources":["../src/KyselyFactory.ts"],"sourcesContent":[],"mappings":";;;;;;;;AA+CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4GK,cA5GQ,aA4GR,CAAA,EAAA,EAAA,iBA1Ga,MA0Gb,CAAA,MAAA,EAAA,GAAA,CAAA,EAAA,cAzGU,MAyGV,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,SAxGK,OAwGL,CAxGa,QAwGb,EAxGuB,KAwGvB,CAAA,CAAA;EAAO,QACoB,QAAA;EAAE,QAAC,KAAA;EAAS,QAAvB,EAAA;EAAU;;;;;;;;;;;;;;;;;;;;;EAwJf,OACK,UAAA,CAAA,aA5OoB,WA4OpB,CAAA,CAAA,MAAA,EA5OyC,IA4OzC,CAAA,EA5OgD,IA4OhD;EAAQ;;;;;;;EAClB,WACuB,CAAA,QAAA,EAlOd,QAkOc,EAAA,KAAA,EAjOjB,KAiOiB,EAAA,EAAA,EAhOpB,MAgOoB,CAhOb,EAgOa,CAAA,GAhOP,qBAgOO,CAhOe,EAgOf,EAAA,EAAA,CAAA;EAAQ;;;;;;;;;;;;;;;;;;;;;;;AApQzB;;;;;;;;;;;;;;;;;;;;;;;;mDA0FS,2BACV,QAAQ,WAAW,GAAG,eAAe,QAClD,WAAW,GAAG,sCAGN,WAAW,GAAG,oBAEhB;WAEC;aACE;QACL,OAAO;WACJ;QAEL,QAAQ,WAAW,GAAG,eACtB,QAAQ,QAAQ,WAAW,GAAG,8CAG1B,gBACE,aACL,OAAO,YACJ,iBACH,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAuEgB,uBACf,WACL,WAAW,SAAS,SAC1B,QAAQ,QAAQ,WAAW,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAqEN,sCAEnB,WACL,WAAW,SAAS,SAC1B,QAAQ,QAAQ,WAAW,SAAS;6BACN,sCAEnB,+BAGL,iBACH,WAAW,SAAS,SAAS,QAAQ,WAAW,SAAS,UAC5D,QAAQ,QAAQ,WAAW,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAsDlB,iBACV,WACF,iBAAiB,MAAM,MAC7B,WAAW,MAAM"}
@@ -1,5 +1,5 @@
1
1
  import { FakerFactory } from "./faker-DHh7xs4u.mjs";
2
- import { ExtractSeedAttrs, Factory, FactorySeed } from "./Factory-BcGJjLc8.mjs";
2
+ import { ExtractSeedAttrs, Factory, FactorySeed } from "./Factory-SFupxRC2.mjs";
3
3
  import { ControlledTransaction, Insertable, Kysely, Selectable } from "kysely";
4
4
 
5
5
  //#region src/KyselyFactory.d.ts
@@ -222,6 +222,7 @@ declare class KyselyFactory<DB, Builders extends Record<string, any>, Seeds exte
222
222
  */
223
223
  seed<K extends keyof Seeds>(seedName: K, attrs?: ExtractSeedAttrs<Seeds[K]>): ReturnType<Seeds[K]>;
224
224
  }
225
+ //# sourceMappingURL=KyselyFactory.d.ts.map
225
226
  //#endregion
226
227
  export { KyselyFactory };
227
- //# sourceMappingURL=KyselyFactory-Cj-EultY.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SAAS,SAC1B,QAAQ,QAAQ,WAAW,SAAS;6BACN,sCAEnB,+BAGL,iBACH,WAAW,SAAS,SAAS,QAAQ,WAAW,SAAS,UAC5D,QAAQ,QAAQ,WAAW,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAsDlB,iBACV,WACF,iBAAiB,MAAM,MAC7B,WAAW,MAAM"}
@@ -1,4 +1,4 @@
1
- import "./faker-DvxiCtxc.cjs";
2
- import "./Factory-c16c27Y6.cjs";
3
- import { KyselyFactory } from "./KyselyFactory-uZ45h7YU.cjs";
1
+ import "./faker-Cg76aFNO.cjs";
2
+ import "./Factory-BOX312yd.cjs";
3
+ import { KyselyFactory } from "./KyselyFactory-Dy5zzV4B.cjs";
4
4
  export { KyselyFactory };
@@ -1,4 +1,4 @@
1
1
  import "./faker-DHh7xs4u.mjs";
2
- import "./Factory-BcGJjLc8.mjs";
3
- import { KyselyFactory } from "./KyselyFactory-Cj-EultY.mjs";
2
+ import "./Factory-SFupxRC2.mjs";
3
+ import { KyselyFactory } from "./KyselyFactory-vAxYodck.mjs";
4
4
  export { KyselyFactory };
@@ -1,5 +1,5 @@
1
1
  import { FakerFactory } from "./faker-DHh7xs4u.mjs";
2
- import { ExtractSeedAttrs, Factory, FactorySeed } from "./Factory-BcGJjLc8.mjs";
2
+ import { ExtractSeedAttrs, Factory, FactorySeed } from "./Factory-SFupxRC2.mjs";
3
3
  import { Knex } from "knex";
4
4
  import { Model } from "objection";
5
5
 
@@ -235,6 +235,7 @@ declare class ObjectionFactory<Builders extends Record<string, any>, Seeds exten
235
235
  */
236
236
  seed<K extends keyof Seeds>(seedName: K, attrs?: ExtractSeedAttrs<Seeds[K]>): ReturnType<Seeds[K]>;
237
237
  }
238
+ //# sourceMappingURL=ObjectionFactory.d.ts.map
238
239
  //#endregion
239
240
  export { ObjectionFactory };
240
- //# sourceMappingURL=ObjectionFactory-DL4qkuF1.d.mts.map
241
+ //# sourceMappingURL=ObjectionFactory-BWjB49-i.d.mts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ObjectionFactory-BeFBYcan.cjs","names":["Factory","seedFn: Seed","ModelClass: TModel","defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Knex;\n faker: FakerFactory;\n }) =>\n | Partial<InstanceType<TModel>>\n | 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]","faker","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.ts';\nimport { type FakerFactory, faker } from './faker.ts';\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 Builders extends Record<string, any>,\n Seeds extends Record<string, any>,\n> extends Factory<Builders, Seeds> {\n /**\n * Creates a typed seed function with proper type inference.\n * Inherits from the base Factory class implementation.\n *\n * @template Seed - The seed function type\n * @param seedFn - The seed function to wrap (receives { attrs, factory, db } object)\n * @returns The same seed function with proper typing\n *\n * @example\n * ```typescript\n * const seeds = {\n * userWithPosts: ObjectionFactory.createSeed(\n * async ({ attrs, factory }) => {\n * const user = await factory.insert('user', attrs);\n * await factory.insertMany(3, 'post', { userId: user.id });\n * return user;\n * },\n * ),\n * };\n * ```\n */\n static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n return Factory.createSeed(seedFn);\n }\n\n /**\n * Creates a typed builder function for Objection.js models.\n * This is a utility method that helps create builders with proper type inference.\n *\n * @template TModel - The Objection.js Model class type\n * @template Attrs - The attributes type for the builder (defaults to Partial of model)\n * @template Factory - The factory instance type\n * @template Result - The result type (defaults to the model instance)\n *\n * @param ModelClass - The Objection.js Model class\n * @param defaults - Optional function to provide default values (receives destructured context)\n * @param autoInsert - Whether to automatically insert the record (default: true)\n * @returns A builder function that creates and optionally inserts records\n *\n * @example\n * ```typescript\n * // Create a simple builder with defaults - destructure only what you need\n * const userBuilder = ObjectionFactory.createBuilder(User,\n * ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * createdAt: new Date(),\n * ...attrs\n * })\n * );\n *\n * // Only need faker? Just destructure that\n * const leaveTypeBuilder = ObjectionFactory.createBuilder(LeaveType,\n * ({ faker }) => ({\n * name: faker.helpers.arrayElement(['Annual', 'Sick', 'Maternity']),\n * code: faker.string.alpha({ length: 3, casing: 'upper' }),\n * })\n * );\n *\n * // Create a builder that doesn't auto-insert (useful for nested inserts)\n * const addressBuilder = ObjectionFactory.createBuilder(Address,\n * ({ attrs }) => ({\n * street: '123 Main St',\n * city: 'Anytown',\n * ...attrs\n * }),\n * false // Don't auto-insert\n * );\n *\n * // Use with relations\n * const postBuilder = ObjectionFactory.createBuilder(Post,\n * async ({ attrs, factory, faker }) => ({\n * title: faker.lorem.sentence(),\n * content: faker.lorem.paragraphs(),\n * authorId: attrs.authorId || (await factory.insert('user')).id,\n * ...attrs\n * })\n * );\n * ```\n */\n static createBuilder<\n TModel extends typeof Model,\n Attrs extends Partial<InstanceType<TModel>> = Partial<InstanceType<TModel>>,\n Factory = any,\n Result = InstanceType<TModel>,\n >(\n ModelClass: TModel,\n defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Knex;\n faker: FakerFactory;\n }) =>\n | Partial<InstanceType<TModel>>\n | Promise<Partial<InstanceType<TModel>>>,\n autoInsert?: boolean,\n ): (\n attrs: Attrs,\n factory: Factory,\n db: Knex,\n faker: FakerFactory,\n ) => Promise<Result> {\n return async (\n attrs: Attrs,\n factory: Factory,\n db: Knex,\n fakerInstance: FakerFactory,\n ) => {\n // Start with attributes\n let data: Partial<InstanceType<TModel>> = { ...attrs };\n\n // Apply defaults\n if (defaults) {\n const defaultValues = await defaults({\n attrs,\n factory,\n db,\n faker: fakerInstance,\n });\n data = { ...defaultValues, ...data };\n }\n\n // Create model instance\n const model = ModelClass.fromJson(data) as InstanceType<TModel>;\n\n // Handle insertion based on autoInsert flag\n if (autoInsert !== false) {\n // Auto insert is enabled by default\n // Extract only defined values for insertion\n const insertData = Object.entries(model).reduce((acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n }, {} as any);\n\n // Use static query method to insert data directly\n // @ts-ignore\n const result = await ModelClass.query(db).insert(insertData);\n return result as Result;\n } else {\n // Return model for factory to handle insertion\n return model as Result;\n }\n };\n }\n\n /**\n * Creates a new ObjectionFactory instance.\n *\n * @param builders - Record of builder functions for creating individual entities\n * @param seeds - Record of seed functions for creating complex test scenarios\n * @param db - Knex database connection instance\n */\n constructor(\n private builders: Builders,\n private seeds: Seeds,\n private db: Knex,\n ) {\n super();\n }\n\n /**\n * Inserts a single record into the database using the specified builder.\n * Uses Objection.js's insertGraph method to handle nested relations.\n *\n * @template K - The builder name (must be a key of Builders)\n * @param builderName - The name of the builder to use\n * @param attrs - Optional attributes to override builder defaults\n * @returns A promise resolving to the inserted record with all relations\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert with defaults\n * const user = await factory.insert('user');\n *\n * // Insert with overrides\n * const adminUser = await factory.insert('user', {\n * email: 'admin@example.com',\n * role: 'admin'\n * });\n *\n * // Insert with nested relations\n * const userWithProfile = await factory.insert('user', {\n * name: 'John Doe',\n * profile: {\n * bio: 'Software Developer',\n * avatar: 'avatar.jpg'\n * }\n * });\n * ```\n */\n async insert<K extends keyof Builders>(\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Factory \"${\n builderName as string\n }\" does not exist. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const result = await this.builders[builderName](\n attrs || {},\n this,\n this.db,\n faker,\n );\n\n // If the builder returns a model instance, insert it\n if (result && typeof result.$query === 'function') {\n // Extract data from model, excluding undefined values and id\n const insertData = Object.entries(result).reduce((acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n }, {} as any);\n\n // Use the model's constructor to get the query builder\n return await result.constructor.query(this.db).insert(insertData);\n }\n\n // Otherwise, assume the builder handled insertion itself\n return result;\n }\n /**\n * Inserts multiple records into the database using the specified builder.\n * Supports both static attributes and dynamic attribute generation via a function.\n *\n * @param count - The number of records to insert\n * @param builderName - The name of the builder to use\n * @param attrs - Static attributes or a function that generates attributes for each record\n * @returns A promise resolving to an array of inserted records\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert multiple with same attributes\n * const users = await factory.insertMany(5, 'user', { role: 'member' });\n *\n * // Insert multiple with dynamic attributes\n * const posts = await factory.insertMany(10, 'post', (idx) => ({\n * title: `Post ${idx + 1}`,\n * content: `Content for post ${idx + 1}`,\n * publishedAt: new Date()\n * }));\n *\n * // Create users with sequential emails\n * const admins = await factory.insertMany(3, 'user', (idx) => ({\n * email: `admin${idx + 1}@example.com`,\n * role: 'admin'\n * }));\n * ```\n */\n // Method overloads for better type inference\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs: (idx: number, faker: FakerFactory) => Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: any,\n ): Promise<Awaited<ReturnType<Builders[K]>>[]> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Builder \"${\n builderName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const records: any[] = [];\n for (let i = 0; i < count; i++) {\n const newAttrs =\n typeof attrs === 'function' ? await (attrs as any)(i, faker) : attrs;\n\n records.push(\n this.builders[builderName](newAttrs, this, this.db, faker).then(\n (record: any) => {\n // If the builder returns a model instance, insert it\n if (record && typeof record.$query === 'function') {\n // Extract data from model, excluding undefined values and id\n const insertData = Object.entries(record).reduce(\n (acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n },\n {} as any,\n );\n\n // Use the model's constructor to get the query builder\n return record.constructor.query(this.db).insert(insertData);\n }\n // Otherwise, assume the builder handled insertion itself\n return record;\n },\n ),\n );\n }\n\n return Promise.all(records);\n }\n /**\n * Executes a seed function to create complex test scenarios with multiple related records.\n * Seeds are useful for setting up complete test environments with realistic data relationships.\n *\n * @template K - The seed name (must be a key of Seeds)\n * @param seedName - The name of the seed to execute\n * @param attrs - Optional configuration attributes for the seed\n * @returns The result of the seed function (typically the primary record created)\n * @throws Error if the specified seed doesn't exist\n *\n * @example\n * ```typescript\n * // Execute a simple seed\n * const user = await factory.seed('userWithProfile');\n *\n * // Execute a seed with configuration\n * const author = await factory.seed('authorWithBooks', {\n * bookCount: 5,\n * includeReviews: true\n * });\n *\n * // Use seed result in tests with Objection.js relations\n * const company = await factory.seed('companyWithDepartments', {\n * departmentCount: 3,\n * employeesPerDepartment: 10\n * });\n *\n * // Access eager loaded relations\n * const companyWithRelations = await Company.query()\n * .findById(company.id)\n * .withGraphFetched('[departments.employees]');\n * ```\n */\n seed<K extends keyof Seeds>(\n seedName: K,\n attrs?: ExtractSeedAttrs<Seeds[K]>,\n ): ReturnType<Seeds[K]> {\n if (!(seedName in this.seeds)) {\n throw new Error(\n `Seed \"${\n seedName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n return this.seeds[seedName]({\n attrs: attrs || {},\n factory: this,\n db: this.db,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,mBAAb,cAGUA,wBAAyB;;;;;;;;;;;;;;;;;;;;;;CAsBjC,OAAO,WAAqCC,QAAoB;AAC9D,SAAO,wBAAQ,WAAW,OAAO;CAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DD,OAAO,cAMLC,YACAC,UAQAC,YAMmB;AACnB,SAAO,OACLC,OACAC,SACAC,IACAC,kBACG;GAEH,IAAIC,OAAsC,EAAE,GAAG,MAAO;AAGtD,OAAI,UAAU;IACZ,MAAM,gBAAgB,MAAM,SAAS;KACnC;KACA;KACA;KACA,OAAO;IACR,EAAC;AACF,WAAO;KAAE,GAAG;KAAe,GAAG;IAAM;GACrC;GAGD,MAAM,QAAQ,WAAW,SAAS,KAAK;AAGvC,OAAI,eAAe,OAAO;IAGxB,MAAM,aAAa,OAAO,QAAQ,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACrE,SAAI,oBAAuB,QAAQ,KACjC,KAAI,OAAO;AAEb,YAAO;IACR,GAAE,CAAE,EAAQ;IAIb,MAAM,SAAS,MAAM,WAAW,MAAM,GAAG,CAAC,OAAO,WAAW;AAC5D,WAAO;GACR,MAEC,QAAO;EAEV;CACF;;;;;;;;CAS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CAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCD,KACEC,UACAC,OACsB;AACtB,QAAM,YAAY,KAAK,OACrB,OAAM,IAAI,OACP,QACC,SACD;AAIL,SAAO,KAAK,MAAM,UAAU;GAC1B,OAAO,SAAS,CAAE;GAClB,SAAS;GACT,IAAI,KAAK;EACV,EAAC;CACH;AACF"}
1
+ {"version":3,"file":"ObjectionFactory-BeFBYcan.cjs","names":["Factory","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]","faker","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\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.cjs";
1
+ import { FakerFactory } from "./faker-Cg76aFNO.cjs";
2
+ import { ExtractSeedAttrs, Factory, FactorySeed } from "./Factory-BOX312yd.cjs";
3
3
  import { Knex } from "knex";
4
4
  import { Model } from "objection";
5
5
 
@@ -235,6 +235,7 @@ declare class ObjectionFactory<Builders extends Record<string, any>, Seeds exten
235
235
  */
236
236
  seed<K extends keyof Seeds>(seedName: K, attrs?: ExtractSeedAttrs<Seeds[K]>): ReturnType<Seeds[K]>;
237
237
  }
238
+ //# sourceMappingURL=ObjectionFactory.d.ts.map
238
239
  //#endregion
239
240
  export { ObjectionFactory };
240
- //# sourceMappingURL=ObjectionFactory-CdhzKs4f.d.cts.map
241
+ //# sourceMappingURL=ObjectionFactory-CD-WFuMJ.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObjectionFactory-CD-WFuMJ.d.cts","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 +1 @@
1
- {"version":3,"file":"ObjectionFactory-QCJ7u0Ql.mjs","names":["seedFn: Seed","ModelClass: TModel","defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Knex;\n faker: FakerFactory;\n }) =>\n | Partial<InstanceType<TModel>>\n | 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.ts';\nimport { type FakerFactory, faker } from './faker.ts';\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 Builders extends Record<string, any>,\n Seeds extends Record<string, any>,\n> extends Factory<Builders, Seeds> {\n /**\n * Creates a typed seed function with proper type inference.\n * Inherits from the base Factory class implementation.\n *\n * @template Seed - The seed function type\n * @param seedFn - The seed function to wrap (receives { attrs, factory, db } object)\n * @returns The same seed function with proper typing\n *\n * @example\n * ```typescript\n * const seeds = {\n * userWithPosts: ObjectionFactory.createSeed(\n * async ({ attrs, factory }) => {\n * const user = await factory.insert('user', attrs);\n * await factory.insertMany(3, 'post', { userId: user.id });\n * return user;\n * },\n * ),\n * };\n * ```\n */\n static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n return Factory.createSeed(seedFn);\n }\n\n /**\n * Creates a typed builder function for Objection.js models.\n * This is a utility method that helps create builders with proper type inference.\n *\n * @template TModel - The Objection.js Model class type\n * @template Attrs - The attributes type for the builder (defaults to Partial of model)\n * @template Factory - The factory instance type\n * @template Result - The result type (defaults to the model instance)\n *\n * @param ModelClass - The Objection.js Model class\n * @param defaults - Optional function to provide default values (receives destructured context)\n * @param autoInsert - Whether to automatically insert the record (default: true)\n * @returns A builder function that creates and optionally inserts records\n *\n * @example\n * ```typescript\n * // Create a simple builder with defaults - destructure only what you need\n * const userBuilder = ObjectionFactory.createBuilder(User,\n * ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * createdAt: new Date(),\n * ...attrs\n * })\n * );\n *\n * // Only need faker? Just destructure that\n * const leaveTypeBuilder = ObjectionFactory.createBuilder(LeaveType,\n * ({ faker }) => ({\n * name: faker.helpers.arrayElement(['Annual', 'Sick', 'Maternity']),\n * code: faker.string.alpha({ length: 3, casing: 'upper' }),\n * })\n * );\n *\n * // Create a builder that doesn't auto-insert (useful for nested inserts)\n * const addressBuilder = ObjectionFactory.createBuilder(Address,\n * ({ attrs }) => ({\n * street: '123 Main St',\n * city: 'Anytown',\n * ...attrs\n * }),\n * false // Don't auto-insert\n * );\n *\n * // Use with relations\n * const postBuilder = ObjectionFactory.createBuilder(Post,\n * async ({ attrs, factory, faker }) => ({\n * title: faker.lorem.sentence(),\n * content: faker.lorem.paragraphs(),\n * authorId: attrs.authorId || (await factory.insert('user')).id,\n * ...attrs\n * })\n * );\n * ```\n */\n static createBuilder<\n TModel extends typeof Model,\n Attrs extends Partial<InstanceType<TModel>> = Partial<InstanceType<TModel>>,\n Factory = any,\n Result = InstanceType<TModel>,\n >(\n ModelClass: TModel,\n defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Knex;\n faker: FakerFactory;\n }) =>\n | Partial<InstanceType<TModel>>\n | Promise<Partial<InstanceType<TModel>>>,\n autoInsert?: boolean,\n ): (\n attrs: Attrs,\n factory: Factory,\n db: Knex,\n faker: FakerFactory,\n ) => Promise<Result> {\n return async (\n attrs: Attrs,\n factory: Factory,\n db: Knex,\n fakerInstance: FakerFactory,\n ) => {\n // Start with attributes\n let data: Partial<InstanceType<TModel>> = { ...attrs };\n\n // Apply defaults\n if (defaults) {\n const defaultValues = await defaults({\n attrs,\n factory,\n db,\n faker: fakerInstance,\n });\n data = { ...defaultValues, ...data };\n }\n\n // Create model instance\n const model = ModelClass.fromJson(data) as InstanceType<TModel>;\n\n // Handle insertion based on autoInsert flag\n if (autoInsert !== false) {\n // Auto insert is enabled by default\n // Extract only defined values for insertion\n const insertData = Object.entries(model).reduce((acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n }, {} as any);\n\n // Use static query method to insert data directly\n // @ts-ignore\n const result = await ModelClass.query(db).insert(insertData);\n return result as Result;\n } else {\n // Return model for factory to handle insertion\n return model as Result;\n }\n };\n }\n\n /**\n * Creates a new ObjectionFactory instance.\n *\n * @param builders - Record of builder functions for creating individual entities\n * @param seeds - Record of seed functions for creating complex test scenarios\n * @param db - Knex database connection instance\n */\n constructor(\n private builders: Builders,\n private seeds: Seeds,\n private db: Knex,\n ) {\n super();\n }\n\n /**\n * Inserts a single record into the database using the specified builder.\n * Uses Objection.js's insertGraph method to handle nested relations.\n *\n * @template K - The builder name (must be a key of Builders)\n * @param builderName - The name of the builder to use\n * @param attrs - Optional attributes to override builder defaults\n * @returns A promise resolving to the inserted record with all relations\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert with defaults\n * const user = await factory.insert('user');\n *\n * // Insert with overrides\n * const adminUser = await factory.insert('user', {\n * email: 'admin@example.com',\n * role: 'admin'\n * });\n *\n * // Insert with nested relations\n * const userWithProfile = await factory.insert('user', {\n * name: 'John Doe',\n * profile: {\n * bio: 'Software Developer',\n * avatar: 'avatar.jpg'\n * }\n * });\n * ```\n */\n async insert<K extends keyof Builders>(\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Factory \"${\n builderName as string\n }\" does not exist. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const result = await this.builders[builderName](\n attrs || {},\n this,\n this.db,\n faker,\n );\n\n // If the builder returns a model instance, insert it\n if (result && typeof result.$query === 'function') {\n // Extract data from model, excluding undefined values and id\n const insertData = Object.entries(result).reduce((acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n }, {} as any);\n\n // Use the model's constructor to get the query builder\n return await result.constructor.query(this.db).insert(insertData);\n }\n\n // Otherwise, assume the builder handled insertion itself\n return result;\n }\n /**\n * Inserts multiple records into the database using the specified builder.\n * Supports both static attributes and dynamic attribute generation via a function.\n *\n * @param count - The number of records to insert\n * @param builderName - The name of the builder to use\n * @param attrs - Static attributes or a function that generates attributes for each record\n * @returns A promise resolving to an array of inserted records\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert multiple with same attributes\n * const users = await factory.insertMany(5, 'user', { role: 'member' });\n *\n * // Insert multiple with dynamic attributes\n * const posts = await factory.insertMany(10, 'post', (idx) => ({\n * title: `Post ${idx + 1}`,\n * content: `Content for post ${idx + 1}`,\n * publishedAt: new Date()\n * }));\n *\n * // Create users with sequential emails\n * const admins = await factory.insertMany(3, 'user', (idx) => ({\n * email: `admin${idx + 1}@example.com`,\n * role: 'admin'\n * }));\n * ```\n */\n // Method overloads for better type inference\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs: (idx: number, faker: FakerFactory) => Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: any,\n ): Promise<Awaited<ReturnType<Builders[K]>>[]> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Builder \"${\n builderName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const records: any[] = [];\n for (let i = 0; i < count; i++) {\n const newAttrs =\n typeof attrs === 'function' ? await (attrs as any)(i, faker) : attrs;\n\n records.push(\n this.builders[builderName](newAttrs, this, this.db, faker).then(\n (record: any) => {\n // If the builder returns a model instance, insert it\n if (record && typeof record.$query === 'function') {\n // Extract data from model, excluding undefined values and id\n const insertData = Object.entries(record).reduce(\n (acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n },\n {} as any,\n );\n\n // Use the model's constructor to get the query builder\n return record.constructor.query(this.db).insert(insertData);\n }\n // Otherwise, assume the builder handled insertion itself\n return record;\n },\n ),\n );\n }\n\n return Promise.all(records);\n }\n /**\n * Executes a seed function to create complex test scenarios with multiple related records.\n * Seeds are useful for setting up complete test environments with realistic data relationships.\n *\n * @template K - The seed name (must be a key of Seeds)\n * @param seedName - The name of the seed to execute\n * @param attrs - Optional configuration attributes for the seed\n * @returns The result of the seed function (typically the primary record created)\n * @throws Error if the specified seed doesn't exist\n *\n * @example\n * ```typescript\n * // Execute a simple seed\n * const user = await factory.seed('userWithProfile');\n *\n * // Execute a seed with configuration\n * const author = await factory.seed('authorWithBooks', {\n * bookCount: 5,\n * includeReviews: true\n * });\n *\n * // Use seed result in tests with Objection.js relations\n * const company = await factory.seed('companyWithDepartments', {\n * departmentCount: 3,\n * employeesPerDepartment: 10\n * });\n *\n * // Access eager loaded relations\n * const companyWithRelations = await Company.query()\n * .findById(company.id)\n * .withGraphFetched('[departments.employees]');\n * ```\n */\n seed<K extends keyof Seeds>(\n seedName: K,\n attrs?: ExtractSeedAttrs<Seeds[K]>,\n ): ReturnType<Seeds[K]> {\n if (!(seedName in this.seeds)) {\n throw new Error(\n `Seed \"${\n seedName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n return this.seeds[seedName]({\n attrs: attrs || {},\n factory: this,\n db: this.db,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,mBAAb,cAGU,QAAyB;;;;;;;;;;;;;;;;;;;;;;CAsBjC,OAAO,WAAqCA,QAAoB;AAC9D,SAAO,QAAQ,WAAW,OAAO;CAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DD,OAAO,cAMLC,YACAC,UAQAC,YAMmB;AACnB,SAAO,OACLC,OACAC,SACAC,IACAC,kBACG;GAEH,IAAIC,OAAsC,EAAE,GAAG,MAAO;AAGtD,OAAI,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AM,AAAC,MAAc,GAAG,MAAM,GAAG;AAEjE,WAAQ,KACN,KAAK,SAAS,aAAa,UAAU,MAAM,KAAK,IAAI,MAAM,CAAC,KACzD,CAACC,WAAgB;AAEf,QAAI,iBAAiB,OAAO,WAAW,YAAY;KAEjD,MAAM,aAAa,OAAO,QAAQ,OAAO,CAAC,OACxC,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACrB,UAAI,oBAAuB,QAAQ,KACjC,KAAI,OAAO;AAEb,aAAO;KACR,GACD,CAAE,EACH;AAGD,YAAO,OAAO,YAAY,MAAM,KAAK,GAAG,CAAC,OAAO,WAAW;IAC5D;AAED,WAAO;GACR,EACF,CACF;EACF;AAED,SAAO,QAAQ,IAAI,QAAQ;CAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCD,KACEC,UACAC,OACsB;AACtB,QAAM,YAAY,KAAK,OACrB,OAAM,IAAI,OACP,QACC,SACD;AAIL,SAAO,KAAK,MAAM,UAAU;GAC1B,OAAO,SAAS,CAAE;GAClB,SAAS;GACT,IAAI,KAAK;EACV,EAAC;CACH;AACF"}
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,M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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,4 +1,4 @@
1
- import "./faker-DvxiCtxc.cjs";
2
- import "./Factory-c16c27Y6.cjs";
3
- import { ObjectionFactory } from "./ObjectionFactory-CdhzKs4f.cjs";
1
+ import "./faker-Cg76aFNO.cjs";
2
+ import "./Factory-BOX312yd.cjs";
3
+ import { ObjectionFactory } from "./ObjectionFactory-CD-WFuMJ.cjs";
4
4
  export { ObjectionFactory };