@geekmidas/testkit 0.2.0 → 0.3.1

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 (75) hide show
  1. package/README.md +110 -16
  2. package/dist/{Factory-z2m01hMj.mjs → Factory-BFVnMMCC.mjs} +2 -2
  3. package/dist/Factory-BFVnMMCC.mjs.map +1 -0
  4. package/dist/{Factory-D7oHtI2D.d.cts → Factory-BK06XuDA.d.cts} +24 -10
  5. package/dist/{Factory-Cmr3s3-s.d.mts → Factory-BcGJjLc8.d.mts} +23 -9
  6. package/dist/{Factory-WMhTNZ9S.cjs → Factory-BhjUOBWN.cjs} +2 -2
  7. package/dist/Factory-BhjUOBWN.cjs.map +1 -0
  8. package/dist/Factory.cjs +1 -1
  9. package/dist/Factory.d.cts +3 -3
  10. package/dist/Factory.d.mts +2 -2
  11. package/dist/Factory.mjs +1 -1
  12. package/dist/{KyselyFactory-DaaCykWP.cjs → KyselyFactory-BFqVIn_0.cjs} +21 -4
  13. package/dist/KyselyFactory-BFqVIn_0.cjs.map +1 -0
  14. package/dist/{KyselyFactory-dYdviox2.d.cts → KyselyFactory-Bu9ssWZP.d.cts} +18 -5
  15. package/dist/{KyselyFactory-BTdygZ-i.d.mts → KyselyFactory-Cj-EultY.d.mts} +17 -4
  16. package/dist/{KyselyFactory-CXY5gJk2.mjs → KyselyFactory-DMswpwji.mjs} +21 -4
  17. package/dist/KyselyFactory-DMswpwji.mjs.map +1 -0
  18. package/dist/KyselyFactory.cjs +2 -2
  19. package/dist/KyselyFactory.d.cts +3 -3
  20. package/dist/KyselyFactory.d.mts +2 -2
  21. package/dist/KyselyFactory.mjs +2 -2
  22. package/dist/{ObjectionFactory-Eb04AOnv.cjs → ObjectionFactory-BeFBYcan.cjs} +21 -4
  23. package/dist/ObjectionFactory-BeFBYcan.cjs.map +1 -0
  24. package/dist/{ObjectionFactory-BagGjikT.d.mts → ObjectionFactory-DL4qkuF1.d.mts} +17 -4
  25. package/dist/{ObjectionFactory-zf2fLKrL.mjs → ObjectionFactory-QCJ7u0Ql.mjs} +21 -4
  26. package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +1 -0
  27. package/dist/{ObjectionFactory-0gUdx8bB.d.cts → ObjectionFactory-tKWZOiYO.d.cts} +18 -5
  28. package/dist/ObjectionFactory.cjs +2 -2
  29. package/dist/ObjectionFactory.d.cts +3 -3
  30. package/dist/ObjectionFactory.d.mts +2 -2
  31. package/dist/ObjectionFactory.mjs +2 -2
  32. package/dist/benchmark.cjs +49 -0
  33. package/dist/benchmark.cjs.map +1 -0
  34. package/dist/benchmark.d.cts +35 -0
  35. package/dist/benchmark.d.mts +35 -0
  36. package/dist/benchmark.mjs +45 -0
  37. package/dist/benchmark.mjs.map +1 -0
  38. package/dist/better-auth.d.cts +2 -2
  39. package/dist/{directory-BUcnztHI.d.cts → directory-BPf1LgNX.d.mts} +3 -3
  40. package/dist/{directory-BXavAeJZ.d.mts → directory-DlkPEzL4.d.cts} +1 -1
  41. package/dist/{faker-Dg3trU4a.d.cts → faker-Cg76aFNO.d.cts} +3 -3
  42. package/dist/faker.d.cts +1 -1
  43. package/dist/kysely.cjs +2 -2
  44. package/dist/kysely.cjs.map +1 -1
  45. package/dist/kysely.d.cts +4 -4
  46. package/dist/kysely.d.mts +3 -3
  47. package/dist/kysely.mjs +2 -2
  48. package/dist/kysely.mjs.map +1 -1
  49. package/dist/objection.cjs +2 -2
  50. package/dist/objection.cjs.map +1 -1
  51. package/dist/objection.d.cts +4 -4
  52. package/dist/objection.d.mts +3 -3
  53. package/dist/objection.mjs +2 -2
  54. package/dist/objection.mjs.map +1 -1
  55. package/dist/os/directory.d.cts +1 -1
  56. package/dist/os/directory.d.mts +1 -1
  57. package/dist/os/index.d.cts +1 -1
  58. package/dist/os/index.d.mts +1 -1
  59. package/package.json +6 -1
  60. package/src/Factory.ts +25 -11
  61. package/src/KyselyFactory.ts +21 -4
  62. package/src/ObjectionFactory.ts +21 -4
  63. package/src/__tests__/Factory.spec.ts +16 -10
  64. package/src/__tests__/KyselyFactory.spec.ts +12 -6
  65. package/src/__tests__/ObjectionFactory.spec.ts +57 -48
  66. package/src/__tests__/integration.spec.ts +16 -8
  67. package/src/benchmark.ts +48 -0
  68. package/src/kysely.ts +1 -0
  69. package/src/objection.ts +1 -0
  70. package/dist/Factory-WMhTNZ9S.cjs.map +0 -1
  71. package/dist/Factory-z2m01hMj.mjs.map +0 -1
  72. package/dist/KyselyFactory-CXY5gJk2.mjs.map +0 -1
  73. package/dist/KyselyFactory-DaaCykWP.cjs.map +0 -1
  74. package/dist/ObjectionFactory-Eb04AOnv.cjs.map +0 -1
  75. package/dist/ObjectionFactory-zf2fLKrL.mjs.map +0 -1
package/dist/kysely.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { FakerFactory, faker } from "./faker-Dg3trU4a.cjs";
2
- import "./Factory-D7oHtI2D.cjs";
3
- import { KyselyFactory } from "./KyselyFactory-dYdviox2.cjs";
1
+ import { FakerFactory, faker } from "./faker-Cg76aFNO.cjs";
2
+ import { ExtractSeedAttrs, FactorySeed } from "./Factory-BK06XuDA.cjs";
3
+ import { KyselyFactory } from "./KyselyFactory-Bu9ssWZP.cjs";
4
4
  import "./PostgresMigrator-D5UkK1_K.cjs";
5
5
  import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CQ3aUoy_.cjs";
6
6
  import { DatabaseConnection, DatabaseFixtures, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions } from "./VitestTransactionIsolator-CwQaxZLP.cjs";
@@ -125,5 +125,5 @@ declare function wrapVitestKyselyTransaction<Database, Extended extends Record<s
125
125
  */
126
126
  declare function extendWithFixtures<Database, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>): TestWithExtendedFixtures<Transaction<Database>, Extended, T>;
127
127
  //#endregion
128
- export { DatabaseFixtures, ExtendedDatabaseFixtures, FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, KyselyTransactionOptions, PostgresKyselyMigrator, TestWithExtendedFixtures, TransactionWrapperOptions, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
128
+ export { DatabaseFixtures, ExtendedDatabaseFixtures, ExtractSeedAttrs, FactorySeed, FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, KyselyTransactionOptions, PostgresKyselyMigrator, TestWithExtendedFixtures, TransactionWrapperOptions, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
129
129
  //# sourceMappingURL=kysely.d.cts.map
package/dist/kysely.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FakerFactory, faker } from "./faker-DHh7xs4u.mjs";
2
- import "./Factory-Cmr3s3-s.mjs";
3
- import { KyselyFactory } from "./KyselyFactory-BTdygZ-i.mjs";
2
+ import { ExtractSeedAttrs, FactorySeed } from "./Factory-BcGJjLc8.mjs";
3
+ import { KyselyFactory } from "./KyselyFactory-Cj-EultY.mjs";
4
4
  import "./PostgresMigrator-DQaRxoaY.mjs";
5
5
  import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CIx3AFSR.mjs";
6
6
  import { DatabaseConnection, DatabaseFixtures, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions } from "./VitestTransactionIsolator-BvR19bYn.mjs";
@@ -125,5 +125,5 @@ declare function wrapVitestKyselyTransaction<Database, Extended extends Record<s
125
125
  */
126
126
  declare function extendWithFixtures<Database, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>): TestWithExtendedFixtures<Transaction<Database>, Extended, T>;
127
127
  //#endregion
128
- export { DatabaseFixtures, ExtendedDatabaseFixtures, FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, KyselyTransactionOptions, PostgresKyselyMigrator, TestWithExtendedFixtures, TransactionWrapperOptions, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
128
+ export { DatabaseFixtures, ExtendedDatabaseFixtures, ExtractSeedAttrs, FactorySeed, FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, KyselyTransactionOptions, PostgresKyselyMigrator, TestWithExtendedFixtures, TransactionWrapperOptions, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
129
129
  //# sourceMappingURL=kysely.d.mts.map
package/dist/kysely.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import "./Factory-z2m01hMj.mjs";
1
+ import "./Factory-BFVnMMCC.mjs";
2
2
  import { faker } from "./faker-BGKYFoCT.mjs";
3
- import { KyselyFactory } from "./KyselyFactory-CXY5gJk2.mjs";
3
+ import { KyselyFactory } from "./KyselyFactory-DMswpwji.mjs";
4
4
  import "./PostgresMigrator-DbuJGAVy.mjs";
5
5
  import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-upT-hmrz.mjs";
6
6
  import { IsolationLevel, extendWithFixtures } from "./VitestTransactionIsolator-DQ7tLqgV.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"kysely.mjs","names":["api: TestAPI","options: KyselyTransactionOptions<Database, Extended>","extendWithFixtures","wrappedTest: T","fixtures: FixtureCreators<Transaction<Database>, Extended>"],"sources":["../src/kysely.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport type { TestAPI } from 'vitest';\nimport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nimport {\n type DatabaseConnection,\n type FixtureCreators,\n type IsolationLevel,\n extendWithFixtures as baseExtendWithFixtures,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific exports for test utilities.\n * Provides factories, migrators, and transaction isolators for Kysely ORM.\n */\n\nexport { KyselyFactory } from './KyselyFactory';\nexport { PostgresKyselyMigrator } from './PostgresKyselyMigrator';\nexport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\nexport type {\n DatabaseFixtures,\n ExtendedDatabaseFixtures,\n FixtureCreators,\n TestWithExtendedFixtures,\n TransactionWrapperOptions,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific options for transaction wrapping.\n */\nexport interface KyselyTransactionOptions<\n Database,\n Extended extends Record<string, unknown> = {},\n> {\n /** Function that creates or returns a Kysely database instance */\n connection: DatabaseConnection<Kysely<Database>>;\n /** Optional setup function to run within the transaction before each test */\n setup?: (trx: Transaction<Database>) => Promise<void>;\n /** Transaction isolation level (defaults to REPEATABLE_READ) */\n isolationLevel?: IsolationLevel;\n /** Additional fixtures that depend on the transaction */\n fixtures?: FixtureCreators<Transaction<Database>, Extended>;\n}\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { faker, type FakerFactory } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Database - The database schema type\n * @template Extended - Additional fixtures to provide\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param options - Configuration options for transaction wrapping\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';\n * import { db } from './database';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestKyselyTransaction(test, {\n * connection: db,\n * });\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await trx\n * .insertInto('users')\n * .values({ name: 'Test User', email: 'test@example.com' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * });\n *\n * // With fixtures for factories\n * const it = wrapVitestKyselyTransaction<DB, { factory: Factory }>(test, {\n * connection: db,\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user.id).toBeDefined();\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<\n Database,\n Extended extends Record<string, unknown> = {},\n>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>) {\n const wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n return wrapper.wrapVitestWithTransaction(options);\n}\n\n/**\n * Extends a Kysely transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Database - The database schema type\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction\n * @param fixtures - Object mapping fixture names to creator functions\n * @returns An extended test API with both trx and the additional fixtures\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';\n *\n * // Define your builders\n * const builders = {\n * user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestKyselyTransaction<DB>(test, {\n * connection: db,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new KyselyFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await trx\n * .selectFrom('users')\n * .where('id', '=', user.id)\n * .selectAll()\n * .executeTakeFirst();\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n Database,\n Extended extends Record<string, unknown>,\n T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>) {\n return baseExtendWithFixtures<Transaction<Database>, Extended, T>(\n wrappedTest,\n fixtures,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8FA,SAAgB,4BAGdA,KAAcC,SAAuD;CACrE,MAAM,UAAU,IAAI,gCAA0C;AAE9D,QAAO,QAAQ,0BAA0B,QAAQ;AAClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDD,SAAgBC,qBAIdC,aAAgBC,UAA4D;AAC5E,QAAO,mBACL,aACA,SACD;AACF"}
1
+ {"version":3,"file":"kysely.mjs","names":["api: TestAPI","options: KyselyTransactionOptions<Database, Extended>","extendWithFixtures","wrappedTest: T","fixtures: FixtureCreators<Transaction<Database>, Extended>"],"sources":["../src/kysely.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport type { TestAPI } from 'vitest';\nimport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nimport {\n type DatabaseConnection,\n type FixtureCreators,\n type IsolationLevel,\n extendWithFixtures as baseExtendWithFixtures,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific exports for test utilities.\n * Provides factories, migrators, and transaction isolators for Kysely ORM.\n */\n\nexport { KyselyFactory } from './KyselyFactory';\nexport type { ExtractSeedAttrs, FactorySeed } from './Factory';\nexport { PostgresKyselyMigrator } from './PostgresKyselyMigrator';\nexport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\nexport type {\n DatabaseFixtures,\n ExtendedDatabaseFixtures,\n FixtureCreators,\n TestWithExtendedFixtures,\n TransactionWrapperOptions,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific options for transaction wrapping.\n */\nexport interface KyselyTransactionOptions<\n Database,\n Extended extends Record<string, unknown> = {},\n> {\n /** Function that creates or returns a Kysely database instance */\n connection: DatabaseConnection<Kysely<Database>>;\n /** Optional setup function to run within the transaction before each test */\n setup?: (trx: Transaction<Database>) => Promise<void>;\n /** Transaction isolation level (defaults to REPEATABLE_READ) */\n isolationLevel?: IsolationLevel;\n /** Additional fixtures that depend on the transaction */\n fixtures?: FixtureCreators<Transaction<Database>, Extended>;\n}\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { faker, type FakerFactory } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Database - The database schema type\n * @template Extended - Additional fixtures to provide\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param options - Configuration options for transaction wrapping\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';\n * import { db } from './database';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestKyselyTransaction(test, {\n * connection: db,\n * });\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await trx\n * .insertInto('users')\n * .values({ name: 'Test User', email: 'test@example.com' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * });\n *\n * // With fixtures for factories\n * const it = wrapVitestKyselyTransaction<DB, { factory: Factory }>(test, {\n * connection: db,\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user.id).toBeDefined();\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<\n Database,\n Extended extends Record<string, unknown> = {},\n>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>) {\n const wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n return wrapper.wrapVitestWithTransaction(options);\n}\n\n/**\n * Extends a Kysely transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Database - The database schema type\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction\n * @param fixtures - Object mapping fixture names to creator functions\n * @returns An extended test API with both trx and the additional fixtures\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';\n *\n * // Define your builders\n * const builders = {\n * user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestKyselyTransaction<DB>(test, {\n * connection: db,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new KyselyFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await trx\n * .selectFrom('users')\n * .where('id', '=', user.id)\n * .selectAll()\n * .executeTakeFirst();\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n Database,\n Extended extends Record<string, unknown>,\n T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>) {\n return baseExtendWithFixtures<Transaction<Database>, Extended, T>(\n wrappedTest,\n fixtures,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,4BAGdA,KAAcC,SAAuD;CACrE,MAAM,UAAU,IAAI,gCAA0C;AAE9D,QAAO,QAAQ,0BAA0B,QAAQ;AAClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDD,SAAgBC,qBAIdC,aAAgBC,UAA4D;AAC5E,QAAO,mBACL,aACA,SACD;AACF"}
@@ -1,6 +1,6 @@
1
- require('./Factory-WMhTNZ9S.cjs');
1
+ require('./Factory-BhjUOBWN.cjs');
2
2
  const require_faker = require('./faker-B14IEMIN.cjs');
3
- const require_ObjectionFactory = require('./ObjectionFactory-Eb04AOnv.cjs');
3
+ const require_ObjectionFactory = require('./ObjectionFactory-BeFBYcan.cjs');
4
4
  require('./PostgresMigrator-DFcNdCvD.cjs');
5
5
  const require_PostgresObjectionMigrator = require('./PostgresObjectionMigrator-BG6ymgnt.cjs');
6
6
  const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-CMfJXZP8.cjs');
@@ -1 +1 @@
1
- {"version":3,"file":"objection.cjs","names":["api: TestAPI","options: ObjectionTransactionOptions<Extended>","VitestObjectionTransactionIsolator","extendWithFixtures","wrappedTest: T","fixtures: FixtureCreators<Knex.Transaction, Extended>"],"sources":["../src/objection.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { TestAPI } from 'vitest';\nimport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nimport {\n type DatabaseConnection,\n type FixtureCreators,\n type IsolationLevel,\n extendWithFixtures as baseExtendWithFixtures,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific exports for test utilities.\n * Provides factory implementation for creating test data with Objection.js ORM\n * and transaction isolation for test suites.\n */\n\nexport { ObjectionFactory } from './ObjectionFactory';\nexport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\nexport { PostgresObjectionMigrator } from './PostgresObjectionMigrator';\nexport type {\n DatabaseFixtures,\n ExtendedDatabaseFixtures,\n FixtureCreators,\n TestWithExtendedFixtures,\n TransactionWrapperOptions,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific options for transaction wrapping.\n */\nexport interface ObjectionTransactionOptions<\n Extended extends Record<string, unknown> = {},\n> {\n /** Function that creates or returns a Knex database connection */\n connection: DatabaseConnection<Knex>;\n /** Optional setup function to run within the transaction before each test */\n setup?: (trx: Knex.Transaction) => Promise<void>;\n /** Transaction isolation level (defaults to REPEATABLE_READ) */\n isolationLevel?: IsolationLevel;\n /** Additional fixtures that depend on the transaction */\n fixtures?: FixtureCreators<Knex.Transaction, Extended>;\n}\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { faker, type FakerFactory } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Objection.js.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Extended - Additional fixtures to provide\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param options - Configuration options for transaction wrapping\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestObjectionTransaction } from '@geekmidas/testkit/objection';\n * import { knex } from './database';\n * import { User } from './models';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestObjectionTransaction(test, {\n * connection: knex,\n * });\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User', email: 'test@example.com' });\n *\n * expect(user).toBeDefined();\n * });\n *\n * // With fixtures for factories\n * const it = wrapVitestObjectionTransaction<{ factory: Factory }>(test, {\n * connection: knex,\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user.id).toBeDefined();\n * });\n * ```\n */\nexport function wrapVitestObjectionTransaction<\n Extended extends Record<string, unknown> = {},\n>(api: TestAPI, options: ObjectionTransactionOptions<Extended>) {\n const wrapper = new VitestObjectionTransactionIsolator(api);\n\n return wrapper.wrapVitestWithTransaction(options);\n}\n\n/**\n * Extends an Objection.js transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestObjectionTransaction\n * @param fixtures - Object mapping fixture names to creator functions\n * @returns An extended test API with both trx and the additional fixtures\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestObjectionTransaction, extendWithFixtures, ObjectionFactory } from '@geekmidas/testkit/objection';\n * import { User } from './models';\n *\n * // Define your builders\n * const builders = {\n * user: ObjectionFactory.createBuilder(User, ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestObjectionTransaction(test, {\n * connection: knex,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<{ factory: ObjectionFactory<typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new ObjectionFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await User.query(trx).findById(user.id);\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n Extended extends Record<string, unknown>,\n T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Knex.Transaction, Extended>) {\n return baseExtendWithFixtures<Knex.Transaction, Extended, T>(\n wrappedTest,\n fixtures,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2FA,SAAgB,+BAEdA,KAAcC,SAAgD;CAC9D,MAAM,UAAU,IAAIC,8EAAmC;AAEvD,QAAO,QAAQ,0BAA0B,QAAQ;AAClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDD,SAAgBC,qBAGdC,aAAgBC,UAAuD;AACvE,QAAO,qDACL,aACA,SACD;AACF"}
1
+ {"version":3,"file":"objection.cjs","names":["api: TestAPI","options: ObjectionTransactionOptions<Extended>","VitestObjectionTransactionIsolator","extendWithFixtures","wrappedTest: T","fixtures: FixtureCreators<Knex.Transaction, Extended>"],"sources":["../src/objection.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { TestAPI } from 'vitest';\nimport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nimport {\n type DatabaseConnection,\n type FixtureCreators,\n type IsolationLevel,\n extendWithFixtures as baseExtendWithFixtures,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific exports for test utilities.\n * Provides factory implementation for creating test data with Objection.js ORM\n * and transaction isolation for test suites.\n */\n\nexport { ObjectionFactory } from './ObjectionFactory';\nexport type { ExtractSeedAttrs, FactorySeed } from './Factory';\nexport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\nexport { PostgresObjectionMigrator } from './PostgresObjectionMigrator';\nexport type {\n DatabaseFixtures,\n ExtendedDatabaseFixtures,\n FixtureCreators,\n TestWithExtendedFixtures,\n TransactionWrapperOptions,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific options for transaction wrapping.\n */\nexport interface ObjectionTransactionOptions<\n Extended extends Record<string, unknown> = {},\n> {\n /** Function that creates or returns a Knex database connection */\n connection: DatabaseConnection<Knex>;\n /** Optional setup function to run within the transaction before each test */\n setup?: (trx: Knex.Transaction) => Promise<void>;\n /** Transaction isolation level (defaults to REPEATABLE_READ) */\n isolationLevel?: IsolationLevel;\n /** Additional fixtures that depend on the transaction */\n fixtures?: FixtureCreators<Knex.Transaction, Extended>;\n}\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { faker, type FakerFactory } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Objection.js.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Extended - Additional fixtures to provide\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param options - Configuration options for transaction wrapping\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestObjectionTransaction } from '@geekmidas/testkit/objection';\n * import { knex } from './database';\n * import { User } from './models';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestObjectionTransaction(test, {\n * connection: knex,\n * });\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User', email: 'test@example.com' });\n *\n * expect(user).toBeDefined();\n * });\n *\n * // With fixtures for factories\n * const it = wrapVitestObjectionTransaction<{ factory: Factory }>(test, {\n * connection: knex,\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user.id).toBeDefined();\n * });\n * ```\n */\nexport function wrapVitestObjectionTransaction<\n Extended extends Record<string, unknown> = {},\n>(api: TestAPI, options: ObjectionTransactionOptions<Extended>) {\n const wrapper = new VitestObjectionTransactionIsolator(api);\n\n return wrapper.wrapVitestWithTransaction(options);\n}\n\n/**\n * Extends an Objection.js transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestObjectionTransaction\n * @param fixtures - Object mapping fixture names to creator functions\n * @returns An extended test API with both trx and the additional fixtures\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestObjectionTransaction, extendWithFixtures, ObjectionFactory } from '@geekmidas/testkit/objection';\n * import { User } from './models';\n *\n * // Define your builders\n * const builders = {\n * user: ObjectionFactory.createBuilder(User, ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestObjectionTransaction(test, {\n * connection: knex,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<{ factory: ObjectionFactory<typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new ObjectionFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await User.query(trx).findById(user.id);\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n Extended extends Record<string, unknown>,\n T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Knex.Transaction, Extended>) {\n return baseExtendWithFixtures<Knex.Transaction, Extended, T>(\n wrappedTest,\n fixtures,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4FA,SAAgB,+BAEdA,KAAcC,SAAgD;CAC9D,MAAM,UAAU,IAAIC,8EAAmC;AAEvD,QAAO,QAAQ,0BAA0B,QAAQ;AAClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDD,SAAgBC,qBAGdC,aAAgBC,UAAuD;AACvE,QAAO,qDACL,aACA,SACD;AACF"}
@@ -1,6 +1,6 @@
1
- import { FakerFactory, faker } from "./faker-Dg3trU4a.cjs";
2
- import "./Factory-D7oHtI2D.cjs";
3
- import { ObjectionFactory } from "./ObjectionFactory-0gUdx8bB.cjs";
1
+ import { FakerFactory, faker } from "./faker-Cg76aFNO.cjs";
2
+ import { ExtractSeedAttrs, FactorySeed } from "./Factory-BK06XuDA.cjs";
3
+ import { ObjectionFactory } from "./ObjectionFactory-tKWZOiYO.cjs";
4
4
  import "./PostgresMigrator-D5UkK1_K.cjs";
5
5
  import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-CZHHcCOv.cjs";
6
6
  import { DatabaseConnection, DatabaseFixtures, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions } from "./VitestTransactionIsolator-CwQaxZLP.cjs";
@@ -118,5 +118,5 @@ declare function wrapVitestObjectionTransaction<Extended extends Record<string,
118
118
  */
119
119
  declare function extendWithFixtures<Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Knex.Transaction, Extended>): TestWithExtendedFixtures<Knex.Transaction<any, any[]>, Extended, T>;
120
120
  //#endregion
121
- export { DatabaseFixtures, ExtendedDatabaseFixtures, FakerFactory, FixtureCreators, IsolationLevel, ObjectionFactory, ObjectionTransactionOptions, PostgresObjectionMigrator, TestWithExtendedFixtures, TransactionWrapperOptions, VitestObjectionTransactionIsolator, extendWithFixtures, faker, wrapVitestObjectionTransaction };
121
+ export { DatabaseFixtures, ExtendedDatabaseFixtures, ExtractSeedAttrs, FactorySeed, FakerFactory, FixtureCreators, IsolationLevel, ObjectionFactory, ObjectionTransactionOptions, PostgresObjectionMigrator, TestWithExtendedFixtures, TransactionWrapperOptions, VitestObjectionTransactionIsolator, extendWithFixtures, faker, wrapVitestObjectionTransaction };
122
122
  //# sourceMappingURL=objection.d.cts.map
@@ -1,6 +1,6 @@
1
1
  import { FakerFactory, faker } from "./faker-DHh7xs4u.mjs";
2
- import "./Factory-Cmr3s3-s.mjs";
3
- import { ObjectionFactory } from "./ObjectionFactory-BagGjikT.mjs";
2
+ import { ExtractSeedAttrs, FactorySeed } from "./Factory-BcGJjLc8.mjs";
3
+ import { ObjectionFactory } from "./ObjectionFactory-DL4qkuF1.mjs";
4
4
  import "./PostgresMigrator-DQaRxoaY.mjs";
5
5
  import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-D_hCcrQu.mjs";
6
6
  import { DatabaseConnection, DatabaseFixtures, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions } from "./VitestTransactionIsolator-BvR19bYn.mjs";
@@ -118,5 +118,5 @@ declare function wrapVitestObjectionTransaction<Extended extends Record<string,
118
118
  */
119
119
  declare function extendWithFixtures<Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Knex.Transaction, Extended>): TestWithExtendedFixtures<Knex.Transaction<any, any[]>, Extended, T>;
120
120
  //#endregion
121
- export { DatabaseFixtures, ExtendedDatabaseFixtures, FakerFactory, FixtureCreators, IsolationLevel, ObjectionFactory, ObjectionTransactionOptions, PostgresObjectionMigrator, TestWithExtendedFixtures, TransactionWrapperOptions, VitestObjectionTransactionIsolator, extendWithFixtures, faker, wrapVitestObjectionTransaction };
121
+ export { DatabaseFixtures, ExtendedDatabaseFixtures, ExtractSeedAttrs, FactorySeed, FakerFactory, FixtureCreators, IsolationLevel, ObjectionFactory, ObjectionTransactionOptions, PostgresObjectionMigrator, TestWithExtendedFixtures, TransactionWrapperOptions, VitestObjectionTransactionIsolator, extendWithFixtures, faker, wrapVitestObjectionTransaction };
122
122
  //# sourceMappingURL=objection.d.mts.map
@@ -1,6 +1,6 @@
1
- import "./Factory-z2m01hMj.mjs";
1
+ import "./Factory-BFVnMMCC.mjs";
2
2
  import { faker } from "./faker-BGKYFoCT.mjs";
3
- import { ObjectionFactory } from "./ObjectionFactory-zf2fLKrL.mjs";
3
+ import { ObjectionFactory } from "./ObjectionFactory-QCJ7u0Ql.mjs";
4
4
  import "./PostgresMigrator-DbuJGAVy.mjs";
5
5
  import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-DPj2pOpX.mjs";
6
6
  import { IsolationLevel, extendWithFixtures } from "./VitestTransactionIsolator-DQ7tLqgV.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"objection.mjs","names":["api: TestAPI","options: ObjectionTransactionOptions<Extended>","extendWithFixtures","wrappedTest: T","fixtures: FixtureCreators<Knex.Transaction, Extended>"],"sources":["../src/objection.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { TestAPI } from 'vitest';\nimport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nimport {\n type DatabaseConnection,\n type FixtureCreators,\n type IsolationLevel,\n extendWithFixtures as baseExtendWithFixtures,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific exports for test utilities.\n * Provides factory implementation for creating test data with Objection.js ORM\n * and transaction isolation for test suites.\n */\n\nexport { ObjectionFactory } from './ObjectionFactory';\nexport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\nexport { PostgresObjectionMigrator } from './PostgresObjectionMigrator';\nexport type {\n DatabaseFixtures,\n ExtendedDatabaseFixtures,\n FixtureCreators,\n TestWithExtendedFixtures,\n TransactionWrapperOptions,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific options for transaction wrapping.\n */\nexport interface ObjectionTransactionOptions<\n Extended extends Record<string, unknown> = {},\n> {\n /** Function that creates or returns a Knex database connection */\n connection: DatabaseConnection<Knex>;\n /** Optional setup function to run within the transaction before each test */\n setup?: (trx: Knex.Transaction) => Promise<void>;\n /** Transaction isolation level (defaults to REPEATABLE_READ) */\n isolationLevel?: IsolationLevel;\n /** Additional fixtures that depend on the transaction */\n fixtures?: FixtureCreators<Knex.Transaction, Extended>;\n}\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { faker, type FakerFactory } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Objection.js.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Extended - Additional fixtures to provide\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param options - Configuration options for transaction wrapping\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestObjectionTransaction } from '@geekmidas/testkit/objection';\n * import { knex } from './database';\n * import { User } from './models';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestObjectionTransaction(test, {\n * connection: knex,\n * });\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User', email: 'test@example.com' });\n *\n * expect(user).toBeDefined();\n * });\n *\n * // With fixtures for factories\n * const it = wrapVitestObjectionTransaction<{ factory: Factory }>(test, {\n * connection: knex,\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user.id).toBeDefined();\n * });\n * ```\n */\nexport function wrapVitestObjectionTransaction<\n Extended extends Record<string, unknown> = {},\n>(api: TestAPI, options: ObjectionTransactionOptions<Extended>) {\n const wrapper = new VitestObjectionTransactionIsolator(api);\n\n return wrapper.wrapVitestWithTransaction(options);\n}\n\n/**\n * Extends an Objection.js transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestObjectionTransaction\n * @param fixtures - Object mapping fixture names to creator functions\n * @returns An extended test API with both trx and the additional fixtures\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestObjectionTransaction, extendWithFixtures, ObjectionFactory } from '@geekmidas/testkit/objection';\n * import { User } from './models';\n *\n * // Define your builders\n * const builders = {\n * user: ObjectionFactory.createBuilder(User, ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestObjectionTransaction(test, {\n * connection: knex,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<{ factory: ObjectionFactory<typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new ObjectionFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await User.query(trx).findById(user.id);\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n Extended extends Record<string, unknown>,\n T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Knex.Transaction, Extended>) {\n return baseExtendWithFixtures<Knex.Transaction, Extended, T>(\n wrappedTest,\n fixtures,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2FA,SAAgB,+BAEdA,KAAcC,SAAgD;CAC9D,MAAM,UAAU,IAAI,mCAAmC;AAEvD,QAAO,QAAQ,0BAA0B,QAAQ;AAClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDD,SAAgBC,qBAGdC,aAAgBC,UAAuD;AACvE,QAAO,mBACL,aACA,SACD;AACF"}
1
+ {"version":3,"file":"objection.mjs","names":["api: TestAPI","options: ObjectionTransactionOptions<Extended>","extendWithFixtures","wrappedTest: T","fixtures: FixtureCreators<Knex.Transaction, Extended>"],"sources":["../src/objection.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { TestAPI } from 'vitest';\nimport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nimport {\n type DatabaseConnection,\n type FixtureCreators,\n type IsolationLevel,\n extendWithFixtures as baseExtendWithFixtures,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific exports for test utilities.\n * Provides factory implementation for creating test data with Objection.js ORM\n * and transaction isolation for test suites.\n */\n\nexport { ObjectionFactory } from './ObjectionFactory';\nexport type { ExtractSeedAttrs, FactorySeed } from './Factory';\nexport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\nexport { PostgresObjectionMigrator } from './PostgresObjectionMigrator';\nexport type {\n DatabaseFixtures,\n ExtendedDatabaseFixtures,\n FixtureCreators,\n TestWithExtendedFixtures,\n TransactionWrapperOptions,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific options for transaction wrapping.\n */\nexport interface ObjectionTransactionOptions<\n Extended extends Record<string, unknown> = {},\n> {\n /** Function that creates or returns a Knex database connection */\n connection: DatabaseConnection<Knex>;\n /** Optional setup function to run within the transaction before each test */\n setup?: (trx: Knex.Transaction) => Promise<void>;\n /** Transaction isolation level (defaults to REPEATABLE_READ) */\n isolationLevel?: IsolationLevel;\n /** Additional fixtures that depend on the transaction */\n fixtures?: FixtureCreators<Knex.Transaction, Extended>;\n}\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { faker, type FakerFactory } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Objection.js.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Extended - Additional fixtures to provide\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param options - Configuration options for transaction wrapping\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestObjectionTransaction } from '@geekmidas/testkit/objection';\n * import { knex } from './database';\n * import { User } from './models';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestObjectionTransaction(test, {\n * connection: knex,\n * });\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User', email: 'test@example.com' });\n *\n * expect(user).toBeDefined();\n * });\n *\n * // With fixtures for factories\n * const it = wrapVitestObjectionTransaction<{ factory: Factory }>(test, {\n * connection: knex,\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user.id).toBeDefined();\n * });\n * ```\n */\nexport function wrapVitestObjectionTransaction<\n Extended extends Record<string, unknown> = {},\n>(api: TestAPI, options: ObjectionTransactionOptions<Extended>) {\n const wrapper = new VitestObjectionTransactionIsolator(api);\n\n return wrapper.wrapVitestWithTransaction(options);\n}\n\n/**\n * Extends an Objection.js transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestObjectionTransaction\n * @param fixtures - Object mapping fixture names to creator functions\n * @returns An extended test API with both trx and the additional fixtures\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestObjectionTransaction, extendWithFixtures, ObjectionFactory } from '@geekmidas/testkit/objection';\n * import { User } from './models';\n *\n * // Define your builders\n * const builders = {\n * user: ObjectionFactory.createBuilder(User, ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestObjectionTransaction(test, {\n * connection: knex,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<{ factory: ObjectionFactory<typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new ObjectionFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await User.query(trx).findById(user.id);\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n Extended extends Record<string, unknown>,\n T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Knex.Transaction, Extended>) {\n return baseExtendWithFixtures<Knex.Transaction, Extended, T>(\n wrappedTest,\n fixtures,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4FA,SAAgB,+BAEdA,KAAcC,SAAgD;CAC9D,MAAM,UAAU,IAAI,mCAAmC;AAEvD,QAAO,QAAQ,0BAA0B,QAAQ;AAClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDD,SAAgBC,qBAGdC,aAAgBC,UAAuD;AACvE,QAAO,mBACL,aACA,SACD;AACF"}
@@ -1,2 +1,2 @@
1
- import { DirectoryFixtures, itWithDir } from "../directory-BUcnztHI.cjs";
1
+ import { DirectoryFixtures, itWithDir } from "../directory-DlkPEzL4.cjs";
2
2
  export { DirectoryFixtures, itWithDir };
@@ -1,2 +1,2 @@
1
- import { DirectoryFixtures, itWithDir } from "../directory-BXavAeJZ.mjs";
1
+ import { DirectoryFixtures, itWithDir } from "../directory-BPf1LgNX.mjs";
2
2
  export { DirectoryFixtures, itWithDir };
@@ -1,2 +1,2 @@
1
- import { itWithDir } from "../directory-BUcnztHI.cjs";
1
+ import { itWithDir } from "../directory-DlkPEzL4.cjs";
2
2
  export { itWithDir };
@@ -1,2 +1,2 @@
1
- import { itWithDir } from "../directory-BXavAeJZ.mjs";
1
+ import { itWithDir } from "../directory-BPf1LgNX.mjs";
2
2
  export { itWithDir };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/testkit",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -43,6 +43,11 @@
43
43
  "types": "./dist/better-auth.d.ts",
44
44
  "import": "./dist/better-auth.mjs",
45
45
  "require": "./dist/better-auth.cjs"
46
+ },
47
+ "./benchmark": {
48
+ "types": "./dist/benchmark.d.ts",
49
+ "import": "./dist/benchmark.mjs",
50
+ "require": "./dist/benchmark.cjs"
46
51
  }
47
52
  },
48
53
  "dependencies": {
package/src/Factory.ts CHANGED
@@ -39,7 +39,7 @@ export abstract class Factory<
39
39
  *
40
40
  * @example
41
41
  * ```typescript
42
- * const userWithPostsSeed = Factory.createSeed(async (attrs, factory, db) => {
42
+ * const userWithPostsSeed = Factory.createSeed(async ({ attrs, factory, db }) => {
43
43
  * const user = await factory.insert('user', attrs);
44
44
  * return user;
45
45
  * });
@@ -86,7 +86,7 @@ export abstract class Factory<
86
86
  */
87
87
  abstract seed<K extends keyof Seeds>(
88
88
  seedName: K,
89
- attrs?: Parameters<Seeds[K]>[0],
89
+ attrs?: ExtractSeedAttrs<Seeds[K]>,
90
90
  ): ReturnType<Seeds[K]>;
91
91
  }
92
92
 
@@ -133,15 +133,16 @@ export type MixedFactoryBuilder<
133
133
  * @template Result - The type of object returned by the seed
134
134
  * @template DB - The database connection type (Kysely, Knex, etc.)
135
135
  *
136
- * @param attrs - Configuration attributes for the seed
137
- * @param factory - The factory instance for creating records
138
- * @param db - The database connection
136
+ * @param context - Object containing attrs, factory, and db
137
+ * @param context.attrs - Configuration attributes for the seed
138
+ * @param context.factory - The factory instance for creating records
139
+ * @param context.db - The database connection
139
140
  * @returns A promise resolving to the seed result
140
141
  *
141
142
  * @example
142
143
  * ```typescript
143
144
  * const userWithPostsSeed: FactorySeed<{ postCount?: number }, Factory, User, DB> =
144
- * async (attrs, factory, db) => {
145
+ * async ({ attrs, factory, db }) => {
145
146
  * const user = await factory.insert('user', attrs);
146
147
  * const postCount = attrs.postCount || 3;
147
148
  *
@@ -153,8 +154,21 @@ export type MixedFactoryBuilder<
153
154
  * };
154
155
  * ```
155
156
  */
156
- export type FactorySeed<Attrs = any, Factory = any, Result = any, DB = any> = (
157
- attrs: Attrs,
158
- factory: Factory,
159
- db: DB,
160
- ) => Promise<Result>;
157
+ export type FactorySeed<
158
+ Attrs = any,
159
+ Factory = any,
160
+ Result = any,
161
+ DB = any,
162
+ > = (context: { attrs: Attrs; factory: Factory; db: DB }) => Promise<Result>;
163
+
164
+ /**
165
+ * Helper type to extract the Attrs type from a FactorySeed function.
166
+ * Used internally by Factory implementations to correctly type the seed method parameters.
167
+ */
168
+ export type ExtractSeedAttrs<T> = T extends (context: {
169
+ attrs: infer A;
170
+ factory: any;
171
+ db: any;
172
+ }) => any
173
+ ? A
174
+ : never;
@@ -4,7 +4,7 @@ import type {
4
4
  Kysely,
5
5
  Selectable,
6
6
  } from 'kysely';
7
- import { Factory, type FactorySeed } from './Factory.ts';
7
+ import { type ExtractSeedAttrs, Factory, type FactorySeed } from './Factory.ts';
8
8
  import { type FakerFactory, faker } from './faker.ts';
9
9
 
10
10
  /**
@@ -55,8 +55,21 @@ export class KyselyFactory<
55
55
  * Inherits from the base Factory class implementation.
56
56
  *
57
57
  * @template Seed - The seed function type
58
- * @param seedFn - The seed function to wrap
58
+ * @param seedFn - The seed function to wrap (receives { attrs, factory, db } object)
59
59
  * @returns The same seed function with proper typing
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const seeds = {
64
+ * userWithPosts: KyselyFactory.createSeed(
65
+ * async ({ attrs, factory }) => {
66
+ * const user = await factory.insert('user', attrs);
67
+ * await factory.insertMany(3, 'post', { userId: user.id });
68
+ * return user;
69
+ * },
70
+ * ),
71
+ * };
72
+ * ```
60
73
  */
61
74
  static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {
62
75
  return Factory.createSeed(seedFn);
@@ -359,7 +372,7 @@ export class KyselyFactory<
359
372
  */
360
373
  seed<K extends keyof Seeds>(
361
374
  seedName: K,
362
- attrs?: Parameters<Seeds[K]>[0],
375
+ attrs?: ExtractSeedAttrs<Seeds[K]>,
363
376
  ): ReturnType<Seeds[K]> {
364
377
  if (!(seedName in this.seeds)) {
365
378
  throw new Error(
@@ -369,6 +382,10 @@ export class KyselyFactory<
369
382
  );
370
383
  }
371
384
 
372
- return this.seeds[seedName](attrs || {}, this, this.db);
385
+ return this.seeds[seedName]({
386
+ attrs: attrs || {},
387
+ factory: this,
388
+ db: this.db,
389
+ });
373
390
  }
374
391
  }
@@ -1,6 +1,6 @@
1
1
  import type { Knex } from 'knex';
2
2
  import type { Model } from 'objection';
3
- import { Factory, type FactorySeed } from './Factory.ts';
3
+ import { type ExtractSeedAttrs, Factory, type FactorySeed } from './Factory.ts';
4
4
  import { type FakerFactory, faker } from './faker.ts';
5
5
 
6
6
  /**
@@ -48,8 +48,21 @@ export class ObjectionFactory<
48
48
  * Inherits from the base Factory class implementation.
49
49
  *
50
50
  * @template Seed - The seed function type
51
- * @param seedFn - The seed function to wrap
51
+ * @param seedFn - The seed function to wrap (receives { attrs, factory, db } object)
52
52
  * @returns The same seed function with proper typing
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const seeds = {
57
+ * userWithPosts: ObjectionFactory.createSeed(
58
+ * async ({ attrs, factory }) => {
59
+ * const user = await factory.insert('user', attrs);
60
+ * await factory.insertMany(3, 'post', { userId: user.id });
61
+ * return user;
62
+ * },
63
+ * ),
64
+ * };
65
+ * ```
53
66
  */
54
67
  static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {
55
68
  return Factory.createSeed(seedFn);
@@ -381,7 +394,7 @@ export class ObjectionFactory<
381
394
  */
382
395
  seed<K extends keyof Seeds>(
383
396
  seedName: K,
384
- attrs?: Parameters<Seeds[K]>[0],
397
+ attrs?: ExtractSeedAttrs<Seeds[K]>,
385
398
  ): ReturnType<Seeds[K]> {
386
399
  if (!(seedName in this.seeds)) {
387
400
  throw new Error(
@@ -391,6 +404,10 @@ export class ObjectionFactory<
391
404
  );
392
405
  }
393
406
 
394
- return this.seeds[seedName](attrs || {}, this, this.db);
407
+ return this.seeds[seedName]({
408
+ attrs: attrs || {},
409
+ factory: this,
410
+ db: this.db,
411
+ });
395
412
  }
396
413
  }
@@ -46,7 +46,11 @@ describe('Factory', () => {
46
46
 
47
47
  describe('createSeed static method', () => {
48
48
  it('should return the seed function unchanged', () => {
49
- const seedFn = async (attrs: any, factory: any, db: any) => {
49
+ const seedFn = async ({
50
+ attrs,
51
+ factory,
52
+ db,
53
+ }: { attrs: any; factory: any; db: any }) => {
50
54
  return { id: 1, name: 'test' };
51
55
  };
52
56
 
@@ -57,12 +61,14 @@ describe('Factory', () => {
57
61
  });
58
62
 
59
63
  it('should work with different seed function signatures', () => {
60
- const simpleSeed = () => Promise.resolve({ simple: true });
61
- const complexSeed = async (
62
- attrs: { name: string },
63
- factory: any,
64
- db: any,
65
- ) => {
64
+ const simpleSeed = async () => ({ simple: true });
65
+ const complexSeed = async ({
66
+ attrs,
67
+ }: {
68
+ attrs: { name: string };
69
+ factory: any;
70
+ db: any;
71
+ }) => {
66
72
  return { name: attrs.name, created: true };
67
73
  };
68
74
 
@@ -124,8 +130,8 @@ describe('Factory', () => {
124
130
  });
125
131
 
126
132
  it('should properly type FactorySeed', () => {
127
- // Test that FactorySeed requires async return
128
- const seed: FactorySeed = async (attrs, factory, db) => ({
133
+ // Test that FactorySeed requires async return with object parameter
134
+ const seed: FactorySeed = async ({ attrs, factory, db }) => ({
129
135
  seeded: true,
130
136
  });
131
137
 
@@ -155,7 +161,7 @@ describe('Factory types', () => {
155
161
  TestFactory,
156
162
  { created: number },
157
163
  any
158
- > = async (attrs, factory, db) => {
164
+ > = async ({ attrs }) => {
159
165
  return { created: attrs.count };
160
166
  };
161
167
 
@@ -279,7 +279,10 @@ describe('KyselyFactory', () => {
279
279
 
280
280
  const seeds = {
281
281
  createAdminUser: KyselyFactory.createSeed(
282
- async (attrs: { name?: string }, factory: any, db: any) => {
282
+ async ({
283
+ attrs,
284
+ factory,
285
+ }: { attrs: { name?: string }; factory: any; db: any }) => {
283
286
  return await factory.insert('user', {
284
287
  name: attrs.name || 'Admin User',
285
288
  email: 'admin@example.com',
@@ -319,11 +322,14 @@ describe('KyselyFactory', () => {
319
322
 
320
323
  const seeds = {
321
324
  createCustomUser: KyselyFactory.createSeed(
322
- async (
323
- attrs: { name: string; email: string },
324
- factory: any,
325
- db: any,
326
- ) => {
325
+ async ({
326
+ attrs,
327
+ factory,
328
+ }: {
329
+ attrs: { name: string; email: string };
330
+ factory: any;
331
+ db: any;
332
+ }) => {
327
333
  return await factory.insert('user', attrs);
328
334
  },
329
335
  ),