@geekmidas/testkit 0.0.15 → 0.0.17

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 (185) hide show
  1. package/dist/{Factory-D7P3bKKb.d.mts → Factory-BZ8uMoXl.d.cts} +3 -2
  2. package/dist/{Factory-pNV7ZQ7-.d.cts → Factory-CRquB4vz.d.mts} +3 -2
  3. package/dist/Factory-WMhTNZ9S.cjs +2 -1
  4. package/dist/Factory-WMhTNZ9S.cjs.map +1 -0
  5. package/dist/Factory-z2m01hMj.mjs +2 -1
  6. package/dist/Factory-z2m01hMj.mjs.map +1 -0
  7. package/dist/Factory.d.cts +2 -2
  8. package/dist/Factory.d.mts +2 -2
  9. package/dist/{KyselyFactory-72P98y5I.d.mts → KyselyFactory-BDS_QqRT.d.mts} +4 -3
  10. package/dist/KyselyFactory-BcYkC0t2.mjs +2 -1
  11. package/dist/KyselyFactory-BcYkC0t2.mjs.map +1 -0
  12. package/dist/KyselyFactory-Cf0o2YxO.cjs +2 -1
  13. package/dist/KyselyFactory-Cf0o2YxO.cjs.map +1 -0
  14. package/dist/{KyselyFactory-DLBrYWxU.d.cts → KyselyFactory-DRQ83r0o.d.cts} +4 -3
  15. package/dist/KyselyFactory.d.cts +3 -3
  16. package/dist/KyselyFactory.d.mts +3 -3
  17. package/dist/ObjectionFactory-8hebmnai.mjs +2 -1
  18. package/dist/ObjectionFactory-8hebmnai.mjs.map +1 -0
  19. package/dist/{ObjectionFactory-B40NQWSe.d.mts → ObjectionFactory-C3tHvX1d.d.mts} +4 -3
  20. package/dist/{ObjectionFactory-D3l1VuyX.d.cts → ObjectionFactory-C4X78k0B.d.cts} +4 -3
  21. package/dist/ObjectionFactory-CDriunkS.cjs +2 -1
  22. package/dist/ObjectionFactory-CDriunkS.cjs.map +1 -0
  23. package/dist/ObjectionFactory.d.cts +3 -3
  24. package/dist/ObjectionFactory.d.mts +3 -3
  25. package/dist/{PostgresKyselyMigrator-_6yHZigp.d.mts → PostgresKyselyMigrator-CIx3AFSR.d.mts} +3 -2
  26. package/dist/PostgresKyselyMigrator-CQ3aUoy_.d.cts +2 -1
  27. package/dist/PostgresKyselyMigrator-CfytARcA.cjs +2 -1
  28. package/dist/PostgresKyselyMigrator-CfytARcA.cjs.map +1 -0
  29. package/dist/{PostgresKyselyMigrator-Bdhl251C.mjs → PostgresKyselyMigrator-upT-hmrz.mjs} +3 -2
  30. package/dist/PostgresKyselyMigrator-upT-hmrz.mjs.map +1 -0
  31. package/dist/PostgresKyselyMigrator.d.mts +2 -2
  32. package/dist/PostgresKyselyMigrator.mjs +2 -2
  33. package/dist/PostgresMigrator-D5UkK1_K.d.cts +2 -1
  34. package/dist/PostgresMigrator-DFcNdCvD.cjs +2 -1
  35. package/dist/PostgresMigrator-DFcNdCvD.cjs.map +1 -0
  36. package/dist/{PostgresMigrator-BlvuQl7d.d.mts → PostgresMigrator-DQaRxoaY.d.mts} +2 -1
  37. package/dist/{PostgresMigrator-DxPC_gGu.mjs → PostgresMigrator-DbuJGAVy.mjs} +4 -3
  38. package/dist/PostgresMigrator-DbuJGAVy.mjs.map +1 -0
  39. package/dist/PostgresMigrator.d.mts +1 -1
  40. package/dist/PostgresMigrator.mjs +1 -1
  41. package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs +2 -1
  42. package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs.map +1 -0
  43. package/dist/PostgresObjectionMigrator-CZHHcCOv.d.cts +2 -1
  44. package/dist/{PostgresObjectionMigrator-G4h5FLvU.mjs → PostgresObjectionMigrator-DPj2pOpX.mjs} +3 -2
  45. package/dist/PostgresObjectionMigrator-DPj2pOpX.mjs.map +1 -0
  46. package/dist/{PostgresObjectionMigrator-C69n7vzr.d.mts → PostgresObjectionMigrator-D_hCcrQu.d.mts} +3 -2
  47. package/dist/PostgresObjectionMigrator.d.mts +2 -2
  48. package/dist/PostgresObjectionMigrator.mjs +2 -2
  49. package/dist/VitestKyselyTransactionIsolator-BxjlD1YM.mjs +2 -1
  50. package/dist/VitestKyselyTransactionIsolator-BxjlD1YM.mjs.map +1 -0
  51. package/dist/{VitestKyselyTransactionIsolator-CnxpE9cH.d.mts → VitestKyselyTransactionIsolator-COCVfvfr.d.mts} +3 -2
  52. package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs +2 -1
  53. package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs.map +1 -0
  54. package/dist/VitestKyselyTransactionIsolator-DYUYVEh9.d.cts +2 -1
  55. package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
  56. package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs +2 -1
  57. package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs.map +1 -0
  58. package/dist/VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts +2 -1
  59. package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs +2 -1
  60. package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs.map +1 -0
  61. package/dist/{VitestObjectionTransactionIsolator-DIM79dCq.d.mts → VitestObjectionTransactionIsolator-b973r9O1.d.mts} +3 -2
  62. package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
  63. package/dist/VitestTransactionIsolator-BQ5FpLtC.cjs +2 -1
  64. package/dist/VitestTransactionIsolator-BQ5FpLtC.cjs.map +1 -0
  65. package/dist/{VitestTransactionIsolator-zdyiS_SY.d.mts → VitestTransactionIsolator-CsfJBxcb.d.mts} +2 -1
  66. package/dist/VitestTransactionIsolator-CskiiJbW.mjs +2 -1
  67. package/dist/VitestTransactionIsolator-CskiiJbW.mjs.map +1 -0
  68. package/dist/VitestTransactionIsolator-DdLNODZg.d.cts +2 -1
  69. package/dist/VitestTransactionIsolator.d.mts +1 -1
  70. package/dist/aws.cjs +126 -0
  71. package/dist/aws.cjs.map +1 -0
  72. package/dist/aws.d.cts +22 -0
  73. package/dist/aws.d.mts +22 -0
  74. package/dist/aws.mjs +123 -0
  75. package/dist/aws.mjs.map +1 -0
  76. package/dist/better-auth.cjs +245 -0
  77. package/dist/better-auth.cjs.map +1 -0
  78. package/dist/better-auth.d.cts +17 -0
  79. package/dist/better-auth.d.mts +17 -0
  80. package/dist/better-auth.mjs +244 -0
  81. package/dist/better-auth.mjs.map +1 -0
  82. package/dist/directory-B-Ozljzk.mjs +22 -0
  83. package/dist/directory-B-Ozljzk.mjs.map +1 -0
  84. package/dist/directory-B4oYx02C.d.mts +12 -0
  85. package/dist/directory-BUcnztHI.d.cts +12 -0
  86. package/dist/directory-BVC8g7cX.cjs +28 -0
  87. package/dist/directory-BVC8g7cX.cjs.map +1 -0
  88. package/dist/faker-B14IEMIN.cjs +2 -1
  89. package/dist/faker-B14IEMIN.cjs.map +1 -0
  90. package/dist/faker-BGKYFoCT.mjs +2 -1
  91. package/dist/faker-BGKYFoCT.mjs.map +1 -0
  92. package/dist/{faker-C-Iuk_R1.d.mts → faker-Br8MzXil.d.mts} +4 -3
  93. package/dist/{faker-BSH1EMtg.d.cts → faker-Cg76aFNO.d.cts} +4 -3
  94. package/dist/faker.d.cts +1 -1
  95. package/dist/faker.d.mts +1 -1
  96. package/dist/helpers.cjs +48 -2
  97. package/dist/helpers.cjs.map +1 -0
  98. package/dist/helpers.d.cts +2 -1
  99. package/dist/helpers.d.mts +2 -1
  100. package/dist/helpers.mjs +47 -2
  101. package/dist/helpers.mjs.map +1 -0
  102. package/dist/kysely.cjs +65 -2
  103. package/dist/kysely.cjs.map +1 -0
  104. package/dist/kysely.d.cts +5 -4
  105. package/dist/kysely.d.mts +9 -8
  106. package/dist/kysely.mjs +67 -4
  107. package/dist/kysely.mjs.map +1 -0
  108. package/dist/logger.cjs +23 -0
  109. package/dist/logger.cjs.map +1 -0
  110. package/dist/logger.d.cts +11 -0
  111. package/dist/logger.d.mts +11 -0
  112. package/dist/logger.mjs +22 -0
  113. package/dist/logger.mjs.map +1 -0
  114. package/dist/objection.cjs +80 -2
  115. package/dist/objection.cjs.map +1 -0
  116. package/dist/objection.d.cts +5 -4
  117. package/dist/objection.d.mts +9 -8
  118. package/dist/objection.mjs +82 -4
  119. package/dist/objection.mjs.map +1 -0
  120. package/dist/os/directory.cjs +3 -0
  121. package/dist/os/directory.d.cts +2 -0
  122. package/dist/os/directory.d.mts +2 -0
  123. package/dist/os/directory.mjs +3 -0
  124. package/dist/os/index.cjs +3 -0
  125. package/dist/os/index.d.cts +2 -0
  126. package/dist/os/index.d.mts +2 -0
  127. package/dist/os/index.mjs +3 -0
  128. package/dist/timer.cjs +9 -0
  129. package/dist/timer.cjs.map +1 -0
  130. package/dist/timer.d.cts +5 -0
  131. package/dist/timer.d.mts +5 -0
  132. package/dist/timer.mjs +8 -0
  133. package/dist/timer.mjs.map +1 -0
  134. package/package.json +30 -2
  135. package/src/__tests__/better-auth.spec.ts +21 -0
  136. package/src/aws.ts +131 -0
  137. package/src/better-auth.ts +327 -0
  138. package/src/logger.ts +18 -0
  139. package/src/os/directory.ts +21 -0
  140. package/src/os/index.ts +1 -0
  141. package/src/timer.ts +3 -0
  142. package/dist/__tests__/Factory.spec.cjs +0 -139
  143. package/dist/__tests__/Factory.spec.d.cts +0 -1
  144. package/dist/__tests__/Factory.spec.d.mts +0 -1
  145. package/dist/__tests__/Factory.spec.mjs +0 -138
  146. package/dist/__tests__/KyselyFactory.spec.cjs +0 -235
  147. package/dist/__tests__/KyselyFactory.spec.d.cts +0 -1
  148. package/dist/__tests__/KyselyFactory.spec.d.mts +0 -1
  149. package/dist/__tests__/KyselyFactory.spec.mjs +0 -234
  150. package/dist/__tests__/ObjectionFactory.spec.cjs +0 -340
  151. package/dist/__tests__/ObjectionFactory.spec.d.cts +0 -1
  152. package/dist/__tests__/ObjectionFactory.spec.d.mts +0 -1
  153. package/dist/__tests__/ObjectionFactory.spec.mjs +0 -339
  154. package/dist/__tests__/PostgresKyselyMigrator.spec.cjs +0 -397
  155. package/dist/__tests__/PostgresKyselyMigrator.spec.d.cts +0 -1
  156. package/dist/__tests__/PostgresKyselyMigrator.spec.d.mts +0 -1
  157. package/dist/__tests__/PostgresKyselyMigrator.spec.mjs +0 -396
  158. package/dist/__tests__/PostgresMigrator.spec.cjs +0 -256
  159. package/dist/__tests__/PostgresMigrator.spec.d.cts +0 -1
  160. package/dist/__tests__/PostgresMigrator.spec.d.mts +0 -1
  161. package/dist/__tests__/PostgresMigrator.spec.mjs +0 -255
  162. package/dist/__tests__/PostgresObjectionMigrator.spec.cjs +0 -432
  163. package/dist/__tests__/PostgresObjectionMigrator.spec.d.cts +0 -1
  164. package/dist/__tests__/PostgresObjectionMigrator.spec.d.mts +0 -1
  165. package/dist/__tests__/PostgresObjectionMigrator.spec.mjs +0 -431
  166. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.cjs +0 -122
  167. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.cts +0 -1
  168. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.mts +0 -1
  169. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.mjs +0 -121
  170. package/dist/__tests__/faker.spec.cjs +0 -115
  171. package/dist/__tests__/faker.spec.d.cts +0 -1
  172. package/dist/__tests__/faker.spec.d.mts +0 -1
  173. package/dist/__tests__/faker.spec.mjs +0 -114
  174. package/dist/__tests__/integration.spec.cjs +0 -282
  175. package/dist/__tests__/integration.spec.d.cts +0 -1
  176. package/dist/__tests__/integration.spec.d.mts +0 -1
  177. package/dist/__tests__/integration.spec.mjs +0 -281
  178. package/dist/helpers-B4TXg3Wp.mjs +0 -86
  179. package/dist/helpers-Bf0nXhbu.cjs +0 -116
  180. package/dist/helpers-BuPmgzyQ.mjs +0 -47
  181. package/dist/helpers-nEUtQ7eo.cjs +0 -53
  182. package/dist/kysely-C3h7kitU.mjs +0 -67
  183. package/dist/kysely-VU3MwvMD.cjs +0 -72
  184. package/dist/objection-BI7F86qf.mjs +0 -82
  185. package/dist/objection-BpLv_ZfC.cjs +0 -87
@@ -1,4 +1,4 @@
1
- import { FakerFactory } from "./faker-C-Iuk_R1.mjs";
1
+ import { FakerFactory } from "./faker-Cg76aFNO.cjs";
2
2
 
3
3
  //#region src/Factory.d.ts
4
4
 
@@ -128,4 +128,5 @@ type MixedFactoryBuilder<Attrs = any, Factory = any, Result = any, DB = any> = (
128
128
  */
129
129
  type FactorySeed<Attrs = any, Factory = any, Result = any, DB = any> = (attrs: Attrs, factory: Factory, db: DB) => Promise<Result>;
130
130
  //#endregion
131
- export { Factory, FactorySeed, MixedFactoryBuilder };
131
+ export { Factory, FactorySeed, MixedFactoryBuilder };
132
+ //# sourceMappingURL=Factory-BZ8uMoXl.d.cts.map
@@ -1,4 +1,4 @@
1
- import { FakerFactory } from "./faker-BSH1EMtg.cjs";
1
+ import { FakerFactory } from "./faker-Br8MzXil.mjs";
2
2
 
3
3
  //#region src/Factory.d.ts
4
4
 
@@ -128,4 +128,5 @@ type MixedFactoryBuilder<Attrs = any, Factory = any, Result = any, DB = any> = (
128
128
  */
129
129
  type FactorySeed<Attrs = any, Factory = any, Result = any, DB = any> = (attrs: Attrs, factory: Factory, db: DB) => Promise<Result>;
130
130
  //#endregion
131
- export { Factory, FactorySeed, MixedFactoryBuilder };
131
+ export { Factory, FactorySeed, MixedFactoryBuilder };
132
+ //# sourceMappingURL=Factory-CRquB4vz.d.mts.map
@@ -53,4 +53,5 @@ Object.defineProperty(exports, 'Factory', {
53
53
  get: function () {
54
54
  return Factory;
55
55
  }
56
- });
56
+ });
57
+ //# sourceMappingURL=Factory-WMhTNZ9S.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Factory-WMhTNZ9S.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?: Parameters<Seeds[K]>[0],\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 attrs - Configuration attributes for the seed\n * @param factory - The factory instance for creating records\n * @param 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<Attrs = any, Factory = any, Result = any, DB = any> = (\n attrs: Attrs,\n factory: Factory,\n db: DB,\n) => Promise<Result>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,IAAsB,UAAtB,MAGE;;;;;;;;;;;;;;;;;CAiBA,OAAO,WAAqCA,QAAoB;AAC9D,SAAO;CACR;AAyCF"}
@@ -47,4 +47,5 @@ var Factory = class {
47
47
  };
48
48
 
49
49
  //#endregion
50
- export { Factory };
50
+ export { Factory };
51
+ //# sourceMappingURL=Factory-z2m01hMj.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Factory-z2m01hMj.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?: Parameters<Seeds[K]>[0],\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 attrs - Configuration attributes for the seed\n * @param factory - The factory instance for creating records\n * @param 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<Attrs = any, Factory = any, Result = any, DB = any> = (\n attrs: Attrs,\n factory: Factory,\n db: DB,\n) => Promise<Result>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,IAAsB,UAAtB,MAGE;;;;;;;;;;;;;;;;;CAiBA,OAAO,WAAqCA,QAAoB;AAC9D,SAAO;CACR;AAyCF"}
@@ -1,3 +1,3 @@
1
- import "./faker-BSH1EMtg.cjs";
2
- import { Factory, FactorySeed, MixedFactoryBuilder } from "./Factory-pNV7ZQ7-.cjs";
1
+ import "./faker-Cg76aFNO.cjs";
2
+ import { Factory, FactorySeed, MixedFactoryBuilder } from "./Factory-BZ8uMoXl.cjs";
3
3
  export { Factory, FactorySeed, MixedFactoryBuilder };
@@ -1,3 +1,3 @@
1
- import "./faker-C-Iuk_R1.mjs";
2
- import { Factory, FactorySeed, MixedFactoryBuilder } from "./Factory-D7P3bKKb.mjs";
1
+ import "./faker-Br8MzXil.mjs";
2
+ import { Factory, FactorySeed, MixedFactoryBuilder } from "./Factory-CRquB4vz.mjs";
3
3
  export { Factory, FactorySeed, MixedFactoryBuilder };
@@ -1,5 +1,5 @@
1
- import { FakerFactory } from "./faker-C-Iuk_R1.mjs";
2
- import { Factory, FactorySeed } from "./Factory-D7P3bKKb.mjs";
1
+ import { FakerFactory } from "./faker-Br8MzXil.mjs";
2
+ import { Factory, FactorySeed } from "./Factory-CRquB4vz.mjs";
3
3
  import { ControlledTransaction, Insertable, Kysely, Selectable } from "kysely";
4
4
 
5
5
  //#region src/KyselyFactory.d.ts
@@ -197,4 +197,5 @@ declare class KyselyFactory<DB, Builders extends Record<string, any>, Seeds exte
197
197
  seed<K extends keyof Seeds>(seedName: K, attrs?: Parameters<Seeds[K]>[0]): ReturnType<Seeds[K]>;
198
198
  }
199
199
  //#endregion
200
- export { KyselyFactory };
200
+ export { KyselyFactory };
201
+ //# sourceMappingURL=KyselyFactory-BDS_QqRT.d.mts.map
@@ -207,4 +207,5 @@ var KyselyFactory = class extends Factory {
207
207
  };
208
208
 
209
209
  //#endregion
210
- export { KyselyFactory };
210
+ export { KyselyFactory };
211
+ //# sourceMappingURL=KyselyFactory-BcYkC0t2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KyselyFactory-BcYkC0t2.mjs","names":["seedFn: Seed","builders: Builders","seeds: Seeds","db: Kysely<DB> | ControlledTransaction<DB, []>","table: TableName","item?: (\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>","faker: FakerFactory","data: Partial<Insertable<DB[TableName]>>","faker","builderName: K","attrs?: Parameters<Builders[K]>[0]","count: number","attrs?: any","promises: Promise<any>[]","seedName: K","attrs?: Parameters<Seeds[K]>[0]"],"sources":["../src/KyselyFactory.ts"],"sourcesContent":["import type {\n ControlledTransaction,\n Insertable,\n Kysely,\n Selectable,\n} from 'kysely';\nimport { 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, factory, db, 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\n * @returns The same seed function with proper typing\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 item - Optional function to provide default values and transformations\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\n * const userBuilder = KyselyFactory.createBuilder<DB, 'users'>('users',\n * (attrs, factory, db, 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 * // 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 item?: (\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 faker: FakerFactory,\n ) => {\n // Start with attributes\n let data: Partial<Insertable<DB[TableName]>> = { ...attrs };\n\n // Apply defaults\n if (item) {\n const defaults = await item(attrs, factory, db, faker);\n data = { ...defaults, ...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?: Parameters<Seeds[K]>[0],\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](attrs || {}, this, this.db);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,gBAAb,cAIU,QAAyB;;;;;;;;;CASjC,OAAO,WAAqCA,QAAoB;AAC9D,SAAO,QAAQ,WAAW,OAAO;CAClC;;;;;;;;CASD,YACUC,UACAC,OACAC,IACR;AACA,SA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AI,SAAS;CAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BD,KACEC,UACAC,OACsB;AACtB,QAAM,YAAY,KAAK,OACrB,OAAM,IAAI,OACP,QACC,SACD;AAIL,SAAO,KAAK,MAAM,UAAU,SAAS,CAAE,GAAE,MAAM,KAAK,GAAG;CACxD;AACF"}
@@ -212,4 +212,5 @@ Object.defineProperty(exports, 'KyselyFactory', {
212
212
  get: function () {
213
213
  return KyselyFactory;
214
214
  }
215
- });
215
+ });
216
+ //# sourceMappingURL=KyselyFactory-Cf0o2YxO.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KyselyFactory-Cf0o2YxO.cjs","names":["Factory","seedFn: Seed","builders: Builders","seeds: Seeds","db: Kysely<DB> | ControlledTransaction<DB, []>","table: TableName","item?: (\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>","faker: FakerFactory","data: Partial<Insertable<DB[TableName]>>","faker","builderName: K","attrs?: Parameters<Builders[K]>[0]","count: number","attrs?: any","promises: Promise<any>[]","seedName: K","attrs?: Parameters<Seeds[K]>[0]"],"sources":["../src/KyselyFactory.ts"],"sourcesContent":["import type {\n ControlledTransaction,\n Insertable,\n Kysely,\n Selectable,\n} from 'kysely';\nimport { 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, factory, db, 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\n * @returns The same seed function with proper typing\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 item - Optional function to provide default values and transformations\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\n * const userBuilder = KyselyFactory.createBuilder<DB, 'users'>('users',\n * (attrs, factory, db, 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 * // 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 item?: (\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 faker: FakerFactory,\n ) => {\n // Start with attributes\n let data: Partial<Insertable<DB[TableName]>> = { ...attrs };\n\n // Apply defaults\n if (item) {\n const defaults = await item(attrs, factory, db, faker);\n data = { ...defaults, ...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?: Parameters<Seeds[K]>[0],\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](attrs || {}, this, this.db);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;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OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;GAC9B,MAAM,kBACG,UAAU,aAAa,MAAM,MAAM,GAAGL,oBAAM,GAAG;AACxD,YAAS,KAAK,KAAK,OAAO,aAAa,SAAS,CAAC;EAClD;AAED,SAAO,QAAQ,IAAI,SAAS;CAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BD,KACEM,UACAC,OACsB;AACtB,QAAM,YAAY,KAAK,OACrB,OAAM,IAAI,OACP,QACC,SACD;AAIL,SAAO,KAAK,MAAM,UAAU,SAAS,CAAE,GAAE,MAAM,KAAK,GAAG;CACxD;AACF"}
@@ -1,5 +1,5 @@
1
- import { FakerFactory } from "./faker-BSH1EMtg.cjs";
2
- import { Factory, FactorySeed } from "./Factory-pNV7ZQ7-.cjs";
1
+ import { FakerFactory } from "./faker-Cg76aFNO.cjs";
2
+ import { Factory, FactorySeed } from "./Factory-BZ8uMoXl.cjs";
3
3
  import { ControlledTransaction, Insertable, Kysely, Selectable } from "kysely";
4
4
 
5
5
  //#region src/KyselyFactory.d.ts
@@ -197,4 +197,5 @@ declare class KyselyFactory<DB, Builders extends Record<string, any>, Seeds exte
197
197
  seed<K extends keyof Seeds>(seedName: K, attrs?: Parameters<Seeds[K]>[0]): ReturnType<Seeds[K]>;
198
198
  }
199
199
  //#endregion
200
- export { KyselyFactory };
200
+ export { KyselyFactory };
201
+ //# sourceMappingURL=KyselyFactory-DRQ83r0o.d.cts.map
@@ -1,4 +1,4 @@
1
- import "./faker-BSH1EMtg.cjs";
2
- import "./Factory-pNV7ZQ7-.cjs";
3
- import { KyselyFactory } from "./KyselyFactory-DLBrYWxU.cjs";
1
+ import "./faker-Cg76aFNO.cjs";
2
+ import "./Factory-BZ8uMoXl.cjs";
3
+ import { KyselyFactory } from "./KyselyFactory-DRQ83r0o.cjs";
4
4
  export { KyselyFactory };
@@ -1,4 +1,4 @@
1
- import "./faker-C-Iuk_R1.mjs";
2
- import "./Factory-D7P3bKKb.mjs";
3
- import { KyselyFactory } from "./KyselyFactory-72P98y5I.mjs";
1
+ import "./faker-Br8MzXil.mjs";
2
+ import "./Factory-CRquB4vz.mjs";
3
+ import { KyselyFactory } from "./KyselyFactory-BDS_QqRT.mjs";
4
4
  export { KyselyFactory };
@@ -233,4 +233,5 @@ var ObjectionFactory = class extends Factory {
233
233
  };
234
234
 
235
235
  //#endregion
236
- export { ObjectionFactory };
236
+ export { ObjectionFactory };
237
+ //# sourceMappingURL=ObjectionFactory-8hebmnai.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObjectionFactory-8hebmnai.mjs","names":["seedFn: Seed","ModelClass: TModel","item?: (\n attrs: Attrs,\n factory: Factory,\n db: Knex,\n faker: FakerFactory,\n ) => Partial<InstanceType<TModel>> | Promise<Partial<InstanceType<TModel>>>","autoInsert?: boolean","attrs: Attrs","factory: Factory","db: Knex","faker: FakerFactory","data: Partial<InstanceType<TModel>>","faker","builders: Builders","seeds: Seeds","builderName: K","attrs?: Parameters<Builders[K]>[0]","count: number","attrs?: any","records: any[]","record: any","seedName: K","attrs?: Parameters<Seeds[K]>[0]"],"sources":["../src/ObjectionFactory.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { Model } from 'objection';\nimport { 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: (attrs) => User.fromJson({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * }),\n * post: (attrs) => Post.fromJson({\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\n * @returns The same seed function with proper typing\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 item - Optional function to provide default values and transformations\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\n * const userBuilder = ObjectionFactory.createBuilder(User,\n * (attrs, factory, db, 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 * // 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) => ({\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 item?: (\n attrs: Attrs,\n factory: Factory,\n db: Knex,\n faker: FakerFactory,\n ) => Partial<InstanceType<TModel>> | 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 faker: FakerFactory,\n ) => {\n // Start with attributes\n let data: Partial<InstanceType<TModel>> = { ...attrs };\n\n // Apply defaults\n if (item) {\n const defaults = await item(attrs, factory, db, faker);\n data = { ...defaults, ...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?: Parameters<Seeds[K]>[0],\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](attrs || {}, this, this.db);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,mBAAb,cAGU,QAAyB;;;;;;;;;CASjC,OAAO,WAAqCA,QAAoB;AAC9D,SAAO,QAAQ,WAAW,OAAO;CAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkDD,OAAO,cAMLC,YACAC,MAMAC,YAMmB;AACnB,SAAO,OACLC,OACAC,SACAC,IACAC,YACG;GAEH,IAAIC,OAAsC,EAAE,GAAG,MAAO;AAGtD,OAAI,MAAM;IACR,MAAM,WAAW,MAAM,KAAK,OAAO,SAAS,IAAIC,QAAM;AACtD,WAAO;KAAE,GAAG;KAAU,GAAG;IAAM;GAChC;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;;;;;;;;CASD,YACUC,UACAC,OACAL,IACR;AACA,SAAO;EAJC;EACA;EACA;CAGT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCD,MAAM,OACJM,aACAC,OAC2C;AAC3C,QAAM,eAAe,KAAK,UACxB,OAAM,IAAI,OACP,WACC,YACD;EAIL,MAAM,SAAS,MAAM,KAAK,SAAS,aACjC,SAAS,C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"./faker-C-Iuk_R1.mjs";
2
- import { Factory, FactorySeed } from "./Factory-D7P3bKKb.mjs";
1
+ import { FakerFactory } from "./faker-Br8MzXil.mjs";
2
+ import { Factory, FactorySeed } from "./Factory-CRquB4vz.mjs";
3
3
  import { Knex } from "knex";
4
4
  import { Model } from "objection";
5
5
 
@@ -210,4 +210,5 @@ declare class ObjectionFactory<Builders extends Record<string, any>, Seeds exten
210
210
  seed<K extends keyof Seeds>(seedName: K, attrs?: Parameters<Seeds[K]>[0]): ReturnType<Seeds[K]>;
211
211
  }
212
212
  //#endregion
213
- export { ObjectionFactory };
213
+ export { ObjectionFactory };
214
+ //# sourceMappingURL=ObjectionFactory-C3tHvX1d.d.mts.map
@@ -1,5 +1,5 @@
1
- import { FakerFactory } from "./faker-BSH1EMtg.cjs";
2
- import { Factory, FactorySeed } from "./Factory-pNV7ZQ7-.cjs";
1
+ import { FakerFactory } from "./faker-Cg76aFNO.cjs";
2
+ import { Factory, FactorySeed } from "./Factory-BZ8uMoXl.cjs";
3
3
  import { Knex } from "knex";
4
4
  import { Model } from "objection";
5
5
 
@@ -210,4 +210,5 @@ declare class ObjectionFactory<Builders extends Record<string, any>, Seeds exten
210
210
  seed<K extends keyof Seeds>(seedName: K, attrs?: Parameters<Seeds[K]>[0]): ReturnType<Seeds[K]>;
211
211
  }
212
212
  //#endregion
213
- export { ObjectionFactory };
213
+ export { ObjectionFactory };
214
+ //# sourceMappingURL=ObjectionFactory-C4X78k0B.d.cts.map
@@ -238,4 +238,5 @@ Object.defineProperty(exports, 'ObjectionFactory', {
238
238
  get: function () {
239
239
  return ObjectionFactory;
240
240
  }
241
- });
241
+ });
242
+ //# sourceMappingURL=ObjectionFactory-CDriunkS.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObjectionFactory-CDriunkS.cjs","names":["Factory","seedFn: Seed","ModelClass: TModel","item?: (\n attrs: Attrs,\n factory: Factory,\n db: Knex,\n faker: FakerFactory,\n ) => Partial<InstanceType<TModel>> | Promise<Partial<InstanceType<TModel>>>","autoInsert?: boolean","attrs: Attrs","factory: Factory","db: Knex","faker: FakerFactory","data: Partial<InstanceType<TModel>>","faker","builders: Builders","seeds: Seeds","builderName: K","attrs?: Parameters<Builders[K]>[0]","count: number","attrs?: any","records: any[]","record: any","seedName: K","attrs?: Parameters<Seeds[K]>[0]"],"sources":["../src/ObjectionFactory.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { Model } from 'objection';\nimport { 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: (attrs) => User.fromJson({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * }),\n * post: (attrs) => Post.fromJson({\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\n * @returns The same seed function with proper typing\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 item - Optional function to provide default values and transformations\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\n * const userBuilder = ObjectionFactory.createBuilder(User,\n * (attrs, factory, db, 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 * // 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) => ({\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 item?: (\n attrs: Attrs,\n factory: Factory,\n db: Knex,\n faker: FakerFactory,\n ) => Partial<InstanceType<TModel>> | 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 faker: FakerFactory,\n ) => {\n // Start with attributes\n let data: Partial<InstanceType<TModel>> = { ...attrs };\n\n // Apply defaults\n if (item) {\n const defaults = await item(attrs, factory, db, faker);\n data = { ...defaults, ...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?: Parameters<Seeds[K]>[0],\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](attrs || {}, this, this.db);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,mBAAb,cAGUA,wBAAyB;;;;;;;;;CASjC,OAAO,WAAqCC,QAAoB;AAC9D,SAAO,wBAAQ,WAAW,OAAO;CAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkDD,OAAO,cAMLC,YACAC,MAMAC,YAMmB;AACnB,SAAO,OACLC,OACA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,GAAG,IAAI,OAAO,KAAK;GAC9B,MAAM,kBACG,UAAU,aAAa,MAAM,AAAC,MAAc,GAAGP,oBAAM,GAAG;AAEjE,WAAQ,KACN,KAAK,SAAS,aAAa,UAAU,MAAM,KAAK,IAAIA,oBAAM,CAAC,KACzD,CAACQ,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,SAAS,CAAE,GAAE,MAAM,KAAK,GAAG;CACxD;AACF"}
@@ -1,4 +1,4 @@
1
- import "./faker-BSH1EMtg.cjs";
2
- import "./Factory-pNV7ZQ7-.cjs";
3
- import { ObjectionFactory } from "./ObjectionFactory-D3l1VuyX.cjs";
1
+ import "./faker-Cg76aFNO.cjs";
2
+ import "./Factory-BZ8uMoXl.cjs";
3
+ import { ObjectionFactory } from "./ObjectionFactory-C4X78k0B.cjs";
4
4
  export { ObjectionFactory };
@@ -1,4 +1,4 @@
1
- import "./faker-C-Iuk_R1.mjs";
2
- import "./Factory-D7P3bKKb.mjs";
3
- import { ObjectionFactory } from "./ObjectionFactory-B40NQWSe.mjs";
1
+ import "./faker-Br8MzXil.mjs";
2
+ import "./Factory-CRquB4vz.mjs";
3
+ import { ObjectionFactory } from "./ObjectionFactory-C3tHvX1d.mjs";
4
4
  export { ObjectionFactory };
@@ -1,4 +1,4 @@
1
- import { PostgresMigrator } from "./PostgresMigrator-BlvuQl7d.mjs";
1
+ import { PostgresMigrator } from "./PostgresMigrator-DQaRxoaY.mjs";
2
2
  import { Kysely, MigrationProvider } from "kysely";
3
3
 
4
4
  //#region src/PostgresKyselyMigrator.d.ts
@@ -64,4 +64,5 @@ declare class PostgresKyselyMigrator extends PostgresMigrator {
64
64
  migrate(): Promise<void>;
65
65
  }
66
66
  //#endregion
67
- export { PostgresKyselyMigrator };
67
+ export { PostgresKyselyMigrator };
68
+ //# sourceMappingURL=PostgresKyselyMigrator-CIx3AFSR.d.mts.map
@@ -64,4 +64,5 @@ declare class PostgresKyselyMigrator extends PostgresMigrator {
64
64
  migrate(): Promise<void>;
65
65
  }
66
66
  //#endregion
67
- export { PostgresKyselyMigrator };
67
+ export { PostgresKyselyMigrator };
68
+ //# sourceMappingURL=PostgresKyselyMigrator-CQ3aUoy_.d.cts.map
@@ -84,4 +84,5 @@ Object.defineProperty(exports, 'PostgresKyselyMigrator', {
84
84
  get: function () {
85
85
  return PostgresKyselyMigrator;
86
86
  }
87
- });
87
+ });
88
+ //# sourceMappingURL=PostgresKyselyMigrator-CfytARcA.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresKyselyMigrator-CfytARcA.cjs","names":["PostgresMigrator","options: {\n uri: string;\n db: Kysely<any>;\n provider: MigrationProvider;\n }","Migrator"],"sources":["../src/PostgresKyselyMigrator.ts"],"sourcesContent":["import { type Kysely, type MigrationProvider, Migrator } from 'kysely';\nimport { PostgresMigrator } from './PostgresMigrator';\n\n/**\n * Default logger instance for migration operations.\n */\nconst logger = console;\n\n/**\n * PostgreSQL migrator implementation for Kysely ORM.\n * Extends PostgresMigrator to provide Kysely-specific migration functionality.\n * Automatically creates test databases and applies migrations for testing environments.\n *\n * @example\n * ```typescript\n * import { FileMigrationProvider } from 'kysely';\n * import { PostgresKyselyMigrator } from '@geekmidas/testkit';\n *\n * // Create migration provider\n * const provider = new FileMigrationProvider({\n * fs: require('fs'),\n * path: require('path'),\n * migrationFolder: path.join(__dirname, 'migrations')\n * });\n *\n * // Create Kysely instance\n * const db = new Kysely<Database>({\n * dialect: new PostgresDialect({\n * pool: new Pool({ connectionString: uri })\n * })\n * });\n *\n * // Create and use migrator\n * const migrator = new PostgresKyselyMigrator({\n * uri: 'postgresql://localhost:5432/test_db',\n * db,\n * provider\n * });\n *\n * const cleanup = await migrator.start();\n * // Run tests...\n * await cleanup();\n * ```\n */\nexport class PostgresKyselyMigrator extends PostgresMigrator {\n /**\n * Creates a new PostgresKyselyMigrator instance.\n *\n * @param options - Configuration options\n * @param options.uri - PostgreSQL connection URI\n * @param options.db - Kysely database instance\n * @param options.provider - Migration provider for locating migration files\n */\n constructor(\n private options: {\n uri: string;\n db: Kysely<any>;\n provider: MigrationProvider;\n },\n ) {\n super(options.uri);\n }\n\n /**\n * Executes Kysely migrations to the latest version.\n * Implements the abstract migrate() method from PostgresMigrator.\n *\n * @throws Error if migrations fail to apply\n * @returns Promise that resolves when all migrations are applied\n */\n async migrate(): Promise<void> {\n const migrator = new Migrator({\n db: this.options.db,\n provider: this.options.provider,\n });\n const migrations = await migrator.migrateToLatest();\n\n if (migrations.error) {\n logger.error(migrations.error, `Failed to apply migrations`);\n throw migrations.error;\n }\n\n await this.options.db.destroy();\n\n logger.log(`Applied ${migrations.results?.length} migrations successfully`);\n }\n}\n"],"mappings":";;;;;;;;AAMA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCf,IAAa,yBAAb,cAA4CA,0CAAiB;;;;;;;;;CAS3D,YACUC,SAKR;AACA,QAAM,QAAQ,IAAI;EANV;CAOT;;;;;;;;CASD,MAAM,UAAyB;EAC7B,MAAM,WAAW,IAAIC,gBAAS;GAC5B,IAAI,KAAK,QAAQ;GACjB,UAAU,KAAK,QAAQ;EACxB;EACD,MAAM,aAAa,MAAM,SAAS,iBAAiB;AAEnD,MAAI,WAAW,OAAO;AACpB,UAAO,MAAM,WAAW,QAAQ,4BAA4B;AAC5D,SAAM,WAAW;EAClB;AAED,QAAM,KAAK,QAAQ,GAAG,SAAS;AAE/B,SAAO,KAAK,UAAU,WAAW,SAAS,OAAO,0BAA0B;CAC5E;AACF"}
@@ -1,4 +1,4 @@
1
- import { PostgresMigrator } from "./PostgresMigrator-DxPC_gGu.mjs";
1
+ import { PostgresMigrator } from "./PostgresMigrator-DbuJGAVy.mjs";
2
2
  import { Migrator } from "kysely";
3
3
 
4
4
  //#region src/PostgresKyselyMigrator.ts
@@ -78,4 +78,5 @@ var PostgresKyselyMigrator = class extends PostgresMigrator {
78
78
  };
79
79
 
80
80
  //#endregion
81
- export { PostgresKyselyMigrator };
81
+ export { PostgresKyselyMigrator };
82
+ //# sourceMappingURL=PostgresKyselyMigrator-upT-hmrz.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresKyselyMigrator-upT-hmrz.mjs","names":["options: {\n uri: string;\n db: Kysely<any>;\n provider: MigrationProvider;\n }"],"sources":["../src/PostgresKyselyMigrator.ts"],"sourcesContent":["import { type Kysely, type MigrationProvider, Migrator } from 'kysely';\nimport { PostgresMigrator } from './PostgresMigrator';\n\n/**\n * Default logger instance for migration operations.\n */\nconst logger = console;\n\n/**\n * PostgreSQL migrator implementation for Kysely ORM.\n * Extends PostgresMigrator to provide Kysely-specific migration functionality.\n * Automatically creates test databases and applies migrations for testing environments.\n *\n * @example\n * ```typescript\n * import { FileMigrationProvider } from 'kysely';\n * import { PostgresKyselyMigrator } from '@geekmidas/testkit';\n *\n * // Create migration provider\n * const provider = new FileMigrationProvider({\n * fs: require('fs'),\n * path: require('path'),\n * migrationFolder: path.join(__dirname, 'migrations')\n * });\n *\n * // Create Kysely instance\n * const db = new Kysely<Database>({\n * dialect: new PostgresDialect({\n * pool: new Pool({ connectionString: uri })\n * })\n * });\n *\n * // Create and use migrator\n * const migrator = new PostgresKyselyMigrator({\n * uri: 'postgresql://localhost:5432/test_db',\n * db,\n * provider\n * });\n *\n * const cleanup = await migrator.start();\n * // Run tests...\n * await cleanup();\n * ```\n */\nexport class PostgresKyselyMigrator extends PostgresMigrator {\n /**\n * Creates a new PostgresKyselyMigrator instance.\n *\n * @param options - Configuration options\n * @param options.uri - PostgreSQL connection URI\n * @param options.db - Kysely database instance\n * @param options.provider - Migration provider for locating migration files\n */\n constructor(\n private options: {\n uri: string;\n db: Kysely<any>;\n provider: MigrationProvider;\n },\n ) {\n super(options.uri);\n }\n\n /**\n * Executes Kysely migrations to the latest version.\n * Implements the abstract migrate() method from PostgresMigrator.\n *\n * @throws Error if migrations fail to apply\n * @returns Promise that resolves when all migrations are applied\n */\n async migrate(): Promise<void> {\n const migrator = new Migrator({\n db: this.options.db,\n provider: this.options.provider,\n });\n const migrations = await migrator.migrateToLatest();\n\n if (migrations.error) {\n logger.error(migrations.error, `Failed to apply migrations`);\n throw migrations.error;\n }\n\n await this.options.db.destroy();\n\n logger.log(`Applied ${migrations.results?.length} migrations successfully`);\n }\n}\n"],"mappings":";;;;;;;AAMA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCf,IAAa,yBAAb,cAA4C,iBAAiB;;;;;;;;;CAS3D,YACUA,SAKR;AACA,QAAM,QAAQ,IAAI;EANV;CAOT;;;;;;;;CASD,MAAM,UAAyB;EAC7B,MAAM,WAAW,IAAI,SAAS;GAC5B,IAAI,KAAK,QAAQ;GACjB,UAAU,KAAK,QAAQ;EACxB;EACD,MAAM,aAAa,MAAM,SAAS,iBAAiB;AAEnD,MAAI,WAAW,OAAO;AACpB,UAAO,MAAM,WAAW,QAAQ,4BAA4B;AAC5D,SAAM,WAAW;EAClB;AAED,QAAM,KAAK,QAAQ,GAAG,SAAS;AAE/B,SAAO,KAAK,UAAU,WAAW,SAAS,OAAO,0BAA0B;CAC5E;AACF"}
@@ -1,3 +1,3 @@
1
- import "./PostgresMigrator-BlvuQl7d.mjs";
2
- import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-_6yHZigp.mjs";
1
+ import "./PostgresMigrator-DQaRxoaY.mjs";
2
+ import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CIx3AFSR.mjs";
3
3
  export { PostgresKyselyMigrator };
@@ -1,4 +1,4 @@
1
- import "./PostgresMigrator-DxPC_gGu.mjs";
2
- import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-Bdhl251C.mjs";
1
+ import "./PostgresMigrator-DbuJGAVy.mjs";
2
+ import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-upT-hmrz.mjs";
3
3
 
4
4
  export { PostgresKyselyMigrator };
@@ -81,4 +81,5 @@ declare abstract class PostgresMigrator {
81
81
  start(): Promise<() => Promise<void>>;
82
82
  }
83
83
  //#endregion
84
- export { PostgresMigrator };
84
+ export { PostgresMigrator };
85
+ //# sourceMappingURL=PostgresMigrator-D5UkK1_K.d.cts.map
@@ -149,4 +149,5 @@ Object.defineProperty(exports, 'PostgresMigrator', {
149
149
  get: function () {
150
150
  return PostgresMigrator;
151
151
  }
152
- });
152
+ });
153
+ //# sourceMappingURL=PostgresMigrator-DFcNdCvD.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresMigrator-DFcNdCvD.cjs","names":["uri: string"],"sources":["../src/PostgresMigrator.ts"],"sourcesContent":["import pg from 'pg';\n\nconst { Client } = pg;\n\n/**\n * Creates a PostgreSQL client connected to the 'postgres' database.\n * Extracts connection details from the provided URI.\n *\n * @param uri - PostgreSQL connection URI\n * @returns Object containing the target database name and client instance\n *\n * @example\n * ```typescript\n * const { database, db } = await setupClient('postgresql://user:pass@localhost:5432/mydb');\n * // database = 'mydb'\n * // db = Client instance connected to 'postgres' database\n * ```\n */\nasync function setupClient(uri: string) {\n const url = new URL(uri);\n\n const db = new Client({\n user: url.username,\n password: url.password,\n host: url.hostname,\n port: parseInt(url.port),\n database: 'postgres',\n });\n\n let database = url.pathname.slice(1);\n if (database.includes('?')) {\n database = database.substring(0, database.indexOf('?'));\n }\n return { database, db };\n}\n\n/**\n * Default logger instance for migration operations.\n */\nconst logger = console;\n\n/**\n * Abstract base class for PostgreSQL database migration utilities.\n * Provides database creation, migration, and cleanup functionality for testing.\n * Subclasses must implement the migrate() method to define migration logic.\n *\n * @example\n * ```typescript\n * class MyMigrator extends PostgresMigrator {\n * async migrate(): Promise<void> {\n * // Run your migrations here\n * await this.runMigrations();\n * }\n * }\n *\n * // Use in tests\n * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');\n * const cleanup = await migrator.start();\n *\n * // Run tests...\n *\n * // Clean up\n * await cleanup();\n * ```\n */\nexport abstract class PostgresMigrator {\n /**\n * Creates a new PostgresMigrator instance.\n *\n * @param uri - PostgreSQL connection URI\n */\n constructor(private uri: string) {}\n\n /**\n * Abstract method to be implemented by subclasses.\n * Should contain the migration logic for setting up database schema.\n *\n * @returns Promise that resolves when migrations are complete\n */\n abstract migrate(): Promise<void>;\n\n /**\n * Creates a PostgreSQL database if it doesn't already exist.\n * Connects to the 'postgres' database to check and create the target database.\n *\n * @param uri - PostgreSQL connection URI\n * @returns Object indicating whether the database already existed\n * @private\n */\n private static async create(\n uri: string,\n ): Promise<{ alreadyExisted: boolean }> {\n const { database, db } = await setupClient(uri);\n try {\n await db.connect();\n const result = await db.query(\n `SELECT * FROM pg_catalog.pg_database WHERE datname = '${database}'`,\n );\n\n if (result.rowCount === 0) {\n await db.query(`CREATE DATABASE \"${database}\"`);\n }\n\n return {\n alreadyExisted: result.rowCount ? result.rowCount > 0 : false,\n };\n } finally {\n await db.end();\n }\n }\n\n /**\n * Drops a PostgreSQL database.\n * Used for cleanup after tests are complete.\n *\n * @param uri - PostgreSQL connection URI\n * @throws Error if database cannot be dropped\n * @private\n */\n private static async drop(uri: string): Promise<void> {\n const { database, db } = await setupClient(uri);\n try {\n await db.connect();\n await db.query(`DROP DATABASE \"${database}\"`);\n } finally {\n await db.end();\n }\n }\n\n /**\n * Starts the migration process by creating the database and running migrations.\n * Returns a cleanup function that will drop the database when called.\n *\n * @returns Async cleanup function that drops the created database\n *\n * @example\n * ```typescript\n * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');\n *\n * // Start migrations and get cleanup function\n * const cleanup = await migrator.start();\n *\n * try {\n * // Run your tests here\n * await runTests();\n * } finally {\n * // Always clean up\n * await cleanup();\n * }\n * ```\n */\n async start() {\n const { database, db } = await setupClient(this.uri);\n try {\n await PostgresMigrator.create(this.uri);\n // Implement migration logic here\n await this.migrate();\n logger.log(`Migrating database: ${database}`);\n // Example: await db.query('CREATE TABLE example (id SERIAL PRIMARY KEY)');\n } finally {\n await db.end();\n }\n\n return async () => {\n await PostgresMigrator.drop(this.uri);\n };\n }\n}\n"],"mappings":";;;;AAEA,MAAM,EAAE,QAAQ,GAAG;;;;;;;;;;;;;;;AAgBnB,eAAe,YAAYA,KAAa;CACtC,MAAM,MAAM,IAAI,IAAI;CAEpB,MAAM,KAAK,IAAI,OAAO;EACpB,MAAM,IAAI;EACV,UAAU,IAAI;EACd,MAAM,IAAI;EACV,MAAM,SAAS,IAAI,KAAK;EACxB,UAAU;CACX;CAED,IAAI,WAAW,IAAI,SAAS,MAAM,EAAE;AACpC,KAAI,SAAS,SAAS,IAAI,CACxB,YAAW,SAAS,UAAU,GAAG,SAAS,QAAQ,IAAI,CAAC;AAEzD,QAAO;EAAE;EAAU;CAAI;AACxB;;;;AAKD,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;AA0Bf,IAAsB,mBAAtB,MAAsB,iBAAiB;;;;;;CAMrC,YAAoBA,KAAa;EAAb;CAAe;;;;;;;;;CAkBnC,aAAqB,OACnBA,KACsC;EACtC,MAAM,EAAE,UAAU,IAAI,GAAG,MAAM,YAAY,IAAI;AAC/C,MAAI;AACF,SAAM,GAAG,SAAS;GAClB,MAAM,SAAS,MAAM,GAAG,OACrB,wDAAwD,SAAS,GACnE;AAED,OAAI,OAAO,aAAa,EACtB,OAAM,GAAG,OAAO,mBAAmB,SAAS,GAAG;AAGjD,UAAO,EACL,gBAAgB,OAAO,WAAW,OAAO,WAAW,IAAI,MACzD;EACF,UAAS;AACR,SAAM,GAAG,KAAK;EACf;CACF;;;;;;;;;CAUD,aAAqB,KAAKA,KAA4B;EACpD,MAAM,EAAE,UAAU,IAAI,GAAG,MAAM,YAAY,IAAI;AAC/C,MAAI;AACF,SAAM,GAAG,SAAS;AAClB,SAAM,GAAG,OAAO,iBAAiB,SAAS,GAAG;EAC9C,UAAS;AACR,SAAM,GAAG,KAAK;EACf;CACF;;;;;;;;;;;;;;;;;;;;;;;CAwBD,MAAM,QAAQ;EACZ,MAAM,EAAE,UAAU,IAAI,GAAG,MAAM,YAAY,KAAK,IAAI;AACpD,MAAI;AACF,SAAM,iBAAiB,OAAO,KAAK,IAAI;AAEvC,SAAM,KAAK,SAAS;AACpB,UAAO,KAAK,sBAAsB,SAAS,EAAE;EAE9C,UAAS;AACR,SAAM,GAAG,KAAK;EACf;AAED,SAAO,YAAY;AACjB,SAAM,iBAAiB,KAAK,KAAK,IAAI;EACtC;CACF;AACF"}
@@ -81,4 +81,5 @@ declare abstract class PostgresMigrator {
81
81
  start(): Promise<() => Promise<void>>;
82
82
  }
83
83
  //#endregion
84
- export { PostgresMigrator };
84
+ export { PostgresMigrator };
85
+ //# sourceMappingURL=PostgresMigrator-DQaRxoaY.d.mts.map
@@ -1,7 +1,7 @@
1
1
  import pg from "pg";
2
2
 
3
3
  //#region src/PostgresMigrator.ts
4
- const { Client: Client$1 } = pg;
4
+ const { Client } = pg;
5
5
  /**
6
6
  * Creates a PostgreSQL client connected to the 'postgres' database.
7
7
  * Extracts connection details from the provided URI.
@@ -18,7 +18,7 @@ const { Client: Client$1 } = pg;
18
18
  */
19
19
  async function setupClient(uri) {
20
20
  const url = new URL(uri);
21
- const db = new Client$1({
21
+ const db = new Client({
22
22
  user: url.username,
23
23
  password: url.password,
24
24
  host: url.hostname,
@@ -143,4 +143,5 @@ var PostgresMigrator = class PostgresMigrator {
143
143
  };
144
144
 
145
145
  //#endregion
146
- export { PostgresMigrator };
146
+ export { PostgresMigrator };
147
+ //# sourceMappingURL=PostgresMigrator-DbuJGAVy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresMigrator-DbuJGAVy.mjs","names":["uri: string"],"sources":["../src/PostgresMigrator.ts"],"sourcesContent":["import pg from 'pg';\n\nconst { Client } = pg;\n\n/**\n * Creates a PostgreSQL client connected to the 'postgres' database.\n * Extracts connection details from the provided URI.\n *\n * @param uri - PostgreSQL connection URI\n * @returns Object containing the target database name and client instance\n *\n * @example\n * ```typescript\n * const { database, db } = await setupClient('postgresql://user:pass@localhost:5432/mydb');\n * // database = 'mydb'\n * // db = Client instance connected to 'postgres' database\n * ```\n */\nasync function setupClient(uri: string) {\n const url = new URL(uri);\n\n const db = new Client({\n user: url.username,\n password: url.password,\n host: url.hostname,\n port: parseInt(url.port),\n database: 'postgres',\n });\n\n let database = url.pathname.slice(1);\n if (database.includes('?')) {\n database = database.substring(0, database.indexOf('?'));\n }\n return { database, db };\n}\n\n/**\n * Default logger instance for migration operations.\n */\nconst logger = console;\n\n/**\n * Abstract base class for PostgreSQL database migration utilities.\n * Provides database creation, migration, and cleanup functionality for testing.\n * Subclasses must implement the migrate() method to define migration logic.\n *\n * @example\n * ```typescript\n * class MyMigrator extends PostgresMigrator {\n * async migrate(): Promise<void> {\n * // Run your migrations here\n * await this.runMigrations();\n * }\n * }\n *\n * // Use in tests\n * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');\n * const cleanup = await migrator.start();\n *\n * // Run tests...\n *\n * // Clean up\n * await cleanup();\n * ```\n */\nexport abstract class PostgresMigrator {\n /**\n * Creates a new PostgresMigrator instance.\n *\n * @param uri - PostgreSQL connection URI\n */\n constructor(private uri: string) {}\n\n /**\n * Abstract method to be implemented by subclasses.\n * Should contain the migration logic for setting up database schema.\n *\n * @returns Promise that resolves when migrations are complete\n */\n abstract migrate(): Promise<void>;\n\n /**\n * Creates a PostgreSQL database if it doesn't already exist.\n * Connects to the 'postgres' database to check and create the target database.\n *\n * @param uri - PostgreSQL connection URI\n * @returns Object indicating whether the database already existed\n * @private\n */\n private static async create(\n uri: string,\n ): Promise<{ alreadyExisted: boolean }> {\n const { database, db } = await setupClient(uri);\n try {\n await db.connect();\n const result = await db.query(\n `SELECT * FROM pg_catalog.pg_database WHERE datname = '${database}'`,\n );\n\n if (result.rowCount === 0) {\n await db.query(`CREATE DATABASE \"${database}\"`);\n }\n\n return {\n alreadyExisted: result.rowCount ? result.rowCount > 0 : false,\n };\n } finally {\n await db.end();\n }\n }\n\n /**\n * Drops a PostgreSQL database.\n * Used for cleanup after tests are complete.\n *\n * @param uri - PostgreSQL connection URI\n * @throws Error if database cannot be dropped\n * @private\n */\n private static async drop(uri: string): Promise<void> {\n const { database, db } = await setupClient(uri);\n try {\n await db.connect();\n await db.query(`DROP DATABASE \"${database}\"`);\n } finally {\n await db.end();\n }\n }\n\n /**\n * Starts the migration process by creating the database and running migrations.\n * Returns a cleanup function that will drop the database when called.\n *\n * @returns Async cleanup function that drops the created database\n *\n * @example\n * ```typescript\n * const migrator = new MyMigrator('postgresql://localhost:5432/test_db');\n *\n * // Start migrations and get cleanup function\n * const cleanup = await migrator.start();\n *\n * try {\n * // Run your tests here\n * await runTests();\n * } finally {\n * // Always clean up\n * await cleanup();\n * }\n * ```\n */\n async start() {\n const { database, db } = await setupClient(this.uri);\n try {\n await PostgresMigrator.create(this.uri);\n // Implement migration logic here\n await this.migrate();\n logger.log(`Migrating database: ${database}`);\n // Example: await db.query('CREATE TABLE example (id SERIAL PRIMARY KEY)');\n } finally {\n await db.end();\n }\n\n return async () => {\n await PostgresMigrator.drop(this.uri);\n };\n }\n}\n"],"mappings":";;;AAEA,MAAM,EAAE,QAAQ,GAAG;;;;;;;;;;;;;;;AAgBnB,eAAe,YAAYA,KAAa;CACtC,MAAM,MAAM,IAAI,IAAI;CAEpB,MAAM,KAAK,IAAI,OAAO;EACpB,MAAM,IAAI;EACV,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M,iBAAiB,KAAK,KAAK,IAAI;EACtC;CACF;AACF"}
@@ -1,2 +1,2 @@
1
- import { PostgresMigrator } from "./PostgresMigrator-BlvuQl7d.mjs";
1
+ import { PostgresMigrator } from "./PostgresMigrator-DQaRxoaY.mjs";
2
2
  export { PostgresMigrator };
@@ -1,3 +1,3 @@
1
- import { PostgresMigrator } from "./PostgresMigrator-DxPC_gGu.mjs";
1
+ import { PostgresMigrator } from "./PostgresMigrator-DbuJGAVy.mjs";
2
2
 
3
3
  export { PostgresMigrator };
@@ -119,4 +119,5 @@ Object.defineProperty(exports, 'PostgresObjectionMigrator', {
119
119
  get: function () {
120
120
  return PostgresObjectionMigrator;
121
121
  }
122
- });
122
+ });
123
+ //# sourceMappingURL=PostgresObjectionMigrator-BG6ymgnt.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresObjectionMigrator-BG6ymgnt.cjs","names":["PostgresMigrator","options: {\n uri: string;\n knex: Knex;\n }","migration: string"],"sources":["../src/PostgresObjectionMigrator.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport { PostgresMigrator } from './PostgresMigrator';\n\n/**\n * Default logger instance for migration operations.\n */\nconst logger = console;\n\n/**\n * PostgreSQL migrator implementation for Objection.js ORM with Knex.\n * Extends PostgresMigrator to provide Knex-specific migration functionality.\n * Automatically creates test databases and applies migrations for testing environments.\n *\n * @example\n * ```typescript\n * import knex from 'knex';\n * import { PostgresObjectionMigrator } from '@geekmidas/testkit';\n *\n * // Create Knex instance\n * const db = knex({\n * client: 'pg',\n * connection: uri,\n * migrations: {\n * directory: path.join(__dirname, 'migrations'),\n * extension: 'ts'\n * }\n * });\n *\n * // Create and use migrator\n * const migrator = new PostgresObjectionMigrator({\n * uri: 'postgresql://localhost:5432/test_db',\n * knex: db\n * });\n *\n * const cleanup = await migrator.start();\n * // Run tests...\n * await cleanup();\n * ```\n */\nexport class PostgresObjectionMigrator extends PostgresMigrator {\n /**\n * Creates a new PostgresObjectionMigrator instance.\n *\n * @param options - Configuration options\n * @param options.uri - PostgreSQL connection URI\n * @param options.knex - Knex database instance configured with migrations\n */\n constructor(\n private options: {\n uri: string;\n knex: Knex;\n },\n ) {\n super(options.uri);\n }\n\n /**\n * Executes Knex migrations to the latest version.\n * Implements the abstract migrate() method from PostgresMigrator.\n *\n * @throws Error if migrations fail to apply\n * @returns Promise that resolves when all migrations are applied\n */\n async migrate(): Promise<void> {\n try {\n // Run migrations to latest\n const [batchNo, migrations] = await this.options.knex.migrate.latest();\n\n if (migrations.length > 0) {\n logger.log(\n `Applied batch ${batchNo} with ${migrations.length} migrations:`,\n );\n migrations.forEach((migration: string) => {\n logger.log(` - ${migration}`);\n });\n } else {\n logger.log('No pending migrations to apply');\n }\n } catch (error) {\n logger.error('Failed to apply migrations:', error);\n throw error;\n } finally {\n // Always destroy the connection pool\n await this.options.knex.destroy();\n }\n }\n\n /**\n * Rolls back the last batch of migrations.\n * Useful for testing migration rollback scenarios.\n *\n * @returns Promise that resolves when rollback is complete\n */\n async rollback(): Promise<void> {\n try {\n const [batchNo, migrations] = await this.options.knex.migrate.rollback();\n\n if (migrations.length > 0) {\n logger.log(\n `Rolled back batch ${batchNo} with ${migrations.length} migrations:`,\n );\n migrations.forEach((migration: string) => {\n logger.log(` - ${migration}`);\n });\n } else {\n logger.log('No migrations to rollback');\n }\n } catch (error) {\n logger.error('Failed to rollback migrations:', error);\n throw error;\n } finally {\n await this.options.knex.destroy();\n }\n }\n\n /**\n * Gets the current migration status.\n * Returns information about completed and pending migrations.\n *\n * @returns Promise with migration status information\n */\n async status(): Promise<{\n completed: string[];\n pending: string[];\n }> {\n try {\n const completed = await this.options.knex.migrate.list();\n const [, pending] = await this.options.knex.migrate.currentVersion();\n\n return {\n completed: Array.isArray(completed[0]) ? completed[0] : [],\n pending: Array.isArray(pending) ? pending : [],\n };\n } finally {\n await this.options.knex.destroy();\n }\n }\n}\n"],"mappings":";;;;;;AAMA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;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,MAAM,QAAQ,QAAQ,GAAG,UAAU,CAAE;GAC/C;EACF,UAAS;AACR,SAAM,KAAK,QAAQ,KAAK,SAAS;EAClC;CACF;AACF"}
@@ -74,4 +74,5 @@ declare class PostgresObjectionMigrator extends PostgresMigrator {
74
74
  }>;
75
75
  }
76
76
  //#endregion
77
- export { PostgresObjectionMigrator };
77
+ export { PostgresObjectionMigrator };
78
+ //# sourceMappingURL=PostgresObjectionMigrator-CZHHcCOv.d.cts.map