@geekmidas/testkit 0.0.17 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +302 -199
  2. package/dist/{Factory-CRquB4vz.d.mts → Factory-Cmr3s3-s.d.mts} +2 -2
  3. package/dist/Factory.d.mts +2 -2
  4. package/dist/{KyselyFactory-DRQ83r0o.d.cts → KyselyFactory-BFygzOlO.d.cts} +21 -8
  5. package/dist/{KyselyFactory-BDS_QqRT.d.mts → KyselyFactory-BTdygZ-i.d.mts} +23 -10
  6. package/dist/{KyselyFactory-BcYkC0t2.mjs → KyselyFactory-CXY5gJk2.mjs} +25 -12
  7. package/dist/KyselyFactory-CXY5gJk2.mjs.map +1 -0
  8. package/dist/{KyselyFactory-Cf0o2YxO.cjs → KyselyFactory-DaaCykWP.cjs} +25 -12
  9. package/dist/KyselyFactory-DaaCykWP.cjs.map +1 -0
  10. package/dist/KyselyFactory.cjs +1 -1
  11. package/dist/KyselyFactory.d.cts +1 -1
  12. package/dist/KyselyFactory.d.mts +3 -3
  13. package/dist/KyselyFactory.mjs +1 -1
  14. package/dist/{ObjectionFactory-C3tHvX1d.d.mts → ObjectionFactory-BagGjikT.d.mts} +26 -13
  15. package/dist/{ObjectionFactory-C4X78k0B.d.cts → ObjectionFactory-CeSIN3kZ.d.cts} +24 -11
  16. package/dist/{ObjectionFactory-CDriunkS.cjs → ObjectionFactory-Eb04AOnv.cjs} +28 -15
  17. package/dist/ObjectionFactory-Eb04AOnv.cjs.map +1 -0
  18. package/dist/{ObjectionFactory-8hebmnai.mjs → ObjectionFactory-zf2fLKrL.mjs} +28 -15
  19. package/dist/ObjectionFactory-zf2fLKrL.mjs.map +1 -0
  20. package/dist/ObjectionFactory.cjs +1 -1
  21. package/dist/ObjectionFactory.d.cts +1 -1
  22. package/dist/ObjectionFactory.d.mts +3 -3
  23. package/dist/ObjectionFactory.mjs +1 -1
  24. package/dist/{VitestKyselyTransactionIsolator-COCVfvfr.d.mts → VitestKyselyTransactionIsolator-4HOeLQ0d.d.cts} +2 -2
  25. package/dist/{VitestKyselyTransactionIsolator-Cst3vFjb.cjs → VitestKyselyTransactionIsolator-DX_VPKS-.cjs} +2 -2
  26. package/dist/{VitestKyselyTransactionIsolator-Cst3vFjb.cjs.map → VitestKyselyTransactionIsolator-DX_VPKS-.cjs.map} +1 -1
  27. package/dist/{VitestKyselyTransactionIsolator-DYUYVEh9.d.cts → VitestKyselyTransactionIsolator-DnyZMaA-.d.mts} +2 -2
  28. package/dist/{VitestKyselyTransactionIsolator-BxjlD1YM.mjs → VitestKyselyTransactionIsolator-XDL3ngs_.mjs} +2 -2
  29. package/dist/{VitestKyselyTransactionIsolator-BxjlD1YM.mjs.map → VitestKyselyTransactionIsolator-XDL3ngs_.mjs.map} +1 -1
  30. package/dist/VitestKyselyTransactionIsolator.cjs +2 -2
  31. package/dist/VitestKyselyTransactionIsolator.d.cts +2 -2
  32. package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
  33. package/dist/VitestKyselyTransactionIsolator.mjs +2 -2
  34. package/dist/{VitestObjectionTransactionIsolator-b973r9O1.d.mts → VitestObjectionTransactionIsolator-COVDlpEo.d.cts} +2 -2
  35. package/dist/{VitestObjectionTransactionIsolator-DzeF4UAq.cjs → VitestObjectionTransactionIsolator-D_tlOtq8.cjs} +2 -2
  36. package/dist/{VitestObjectionTransactionIsolator-DzeF4UAq.cjs.map → VitestObjectionTransactionIsolator-D_tlOtq8.cjs.map} +1 -1
  37. package/dist/{VitestObjectionTransactionIsolator-BU-jXEhz.mjs → VitestObjectionTransactionIsolator-_EhJKu_O.mjs} +2 -2
  38. package/dist/{VitestObjectionTransactionIsolator-BU-jXEhz.mjs.map → VitestObjectionTransactionIsolator-_EhJKu_O.mjs.map} +1 -1
  39. package/dist/{VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts → VitestObjectionTransactionIsolator-lZUSz1w0.d.mts} +2 -2
  40. package/dist/VitestObjectionTransactionIsolator.cjs +2 -2
  41. package/dist/VitestObjectionTransactionIsolator.d.cts +2 -2
  42. package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
  43. package/dist/VitestObjectionTransactionIsolator.mjs +2 -2
  44. package/dist/{VitestTransactionIsolator-CskiiJbW.mjs → VitestTransactionIsolator-BIaMs4c2.mjs} +40 -2
  45. package/dist/VitestTransactionIsolator-BIaMs4c2.mjs.map +1 -0
  46. package/dist/{VitestTransactionIsolator-BQ5FpLtC.cjs → VitestTransactionIsolator-BKIrj3Uy.cjs} +45 -1
  47. package/dist/VitestTransactionIsolator-BKIrj3Uy.cjs.map +1 -0
  48. package/dist/{VitestTransactionIsolator-DdLNODZg.d.cts → VitestTransactionIsolator-CyG_i_Nj.d.cts} +61 -3
  49. package/dist/{VitestTransactionIsolator-CsfJBxcb.d.mts → VitestTransactionIsolator-DWDbnITQ.d.mts} +61 -3
  50. package/dist/VitestTransactionIsolator.cjs +3 -2
  51. package/dist/VitestTransactionIsolator.d.cts +2 -2
  52. package/dist/VitestTransactionIsolator.d.mts +2 -2
  53. package/dist/VitestTransactionIsolator.mjs +2 -2
  54. package/dist/better-auth.cjs +8 -11
  55. package/dist/better-auth.cjs.map +1 -1
  56. package/dist/better-auth.d.cts +2 -2
  57. package/dist/better-auth.d.mts +2 -2
  58. package/dist/better-auth.mjs +8 -11
  59. package/dist/better-auth.mjs.map +1 -1
  60. package/dist/{directory-B4oYx02C.d.mts → directory-BXavAeJZ.d.mts} +3 -3
  61. package/dist/{directory-BUcnztHI.d.cts → directory-DlkPEzL4.d.cts} +3 -3
  62. package/dist/{faker-Br8MzXil.d.mts → faker-DHh7xs4u.d.mts} +3 -3
  63. package/dist/faker.d.mts +1 -1
  64. package/dist/kysely.cjs +58 -4
  65. package/dist/kysely.cjs.map +1 -1
  66. package/dist/kysely.d.cts +58 -5
  67. package/dist/kysely.d.mts +59 -6
  68. package/dist/kysely.mjs +57 -5
  69. package/dist/kysely.mjs.map +1 -1
  70. package/dist/objection.cjs +54 -4
  71. package/dist/objection.cjs.map +1 -1
  72. package/dist/objection.d.cts +54 -5
  73. package/dist/objection.d.mts +55 -6
  74. package/dist/objection.mjs +53 -5
  75. package/dist/objection.mjs.map +1 -1
  76. package/dist/os/directory.d.cts +1 -1
  77. package/dist/os/directory.d.mts +1 -1
  78. package/dist/os/index.d.cts +1 -1
  79. package/dist/os/index.d.mts +1 -1
  80. package/package.json +7 -3
  81. package/src/KyselyFactory.ts +29 -16
  82. package/src/ObjectionFactory.ts +34 -19
  83. package/src/VitestTransactionIsolator.ts +110 -2
  84. package/src/__tests__/KyselyFactory.spec.ts +10 -10
  85. package/src/__tests__/ObjectionFactory.spec.ts +9 -12
  86. package/src/__tests__/integration.spec.ts +171 -14
  87. package/src/better-auth.ts +13 -15
  88. package/src/kysely.ts +66 -0
  89. package/src/objection.ts +61 -0
  90. package/dist/KyselyFactory-BcYkC0t2.mjs.map +0 -1
  91. package/dist/KyselyFactory-Cf0o2YxO.cjs.map +0 -1
  92. package/dist/ObjectionFactory-8hebmnai.mjs.map +0 -1
  93. package/dist/ObjectionFactory-CDriunkS.cjs.map +0 -1
  94. package/dist/VitestTransactionIsolator-BQ5FpLtC.cjs.map +0 -1
  95. package/dist/VitestTransactionIsolator-CskiiJbW.mjs.map +0 -1
@@ -1,7 +1,7 @@
1
- import * as vitest0 from "vitest";
1
+ import * as vitest6 from "vitest";
2
2
 
3
3
  //#region src/os/directory.d.ts
4
- declare const itWithDir: vitest0.TestAPI<{
4
+ declare const itWithDir: vitest6.TestAPI<{
5
5
  dir: string;
6
6
  }>;
7
7
  interface DirectoryFixtures {
@@ -9,4 +9,4 @@ interface DirectoryFixtures {
9
9
  }
10
10
  //#endregion
11
11
  export { DirectoryFixtures, itWithDir };
12
- //# sourceMappingURL=directory-BUcnztHI.d.cts.map
12
+ //# sourceMappingURL=directory-DlkPEzL4.d.cts.map
@@ -1,4 +1,4 @@
1
- import * as _faker_js_faker2 from "@faker-js/faker";
1
+ import * as _faker_js_faker1 from "@faker-js/faker";
2
2
 
3
3
  //#region src/faker.d.ts
4
4
 
@@ -134,7 +134,7 @@ declare function coordinateOutsideRadius(center: Coordinate, minRadiusMeters: nu
134
134
  * const productPrice = faker.price();
135
135
  * ```
136
136
  */
137
- declare const faker$1: Readonly<_faker_js_faker2.Faker & {
137
+ declare const faker$1: Readonly<_faker_js_faker1.Faker & {
138
138
  timestamps: typeof timestamps;
139
139
  identifier: typeof identifier;
140
140
  sequence: typeof sequence;
@@ -163,4 +163,4 @@ type Timestamps = {
163
163
  type FakerFactory = typeof faker$1;
164
164
  //#endregion
165
165
  export { FakerFactory, Timestamps, coordinateInRadius, faker$1 as faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
166
- //# sourceMappingURL=faker-Br8MzXil.d.mts.map
166
+ //# sourceMappingURL=faker-DHh7xs4u.d.mts.map
package/dist/faker.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-Br8MzXil.mjs";
1
+ import { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-DHh7xs4u.mjs";
2
2
  export { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
package/dist/kysely.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  require('./Factory-WMhTNZ9S.cjs');
2
- require('./faker-B14IEMIN.cjs');
3
- const require_KyselyFactory = require('./KyselyFactory-Cf0o2YxO.cjs');
2
+ const require_faker = require('./faker-B14IEMIN.cjs');
3
+ const require_KyselyFactory = require('./KyselyFactory-DaaCykWP.cjs');
4
4
  require('./PostgresMigrator-DFcNdCvD.cjs');
5
5
  const require_PostgresKyselyMigrator = require('./PostgresKyselyMigrator-CfytARcA.cjs');
6
- const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BQ5FpLtC.cjs');
7
- const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-Cst3vFjb.cjs');
6
+ const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BKIrj3Uy.cjs');
7
+ const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-DX_VPKS-.cjs');
8
8
 
9
9
  //#region src/kysely.ts
10
10
  /**
@@ -67,11 +67,65 @@ function wrapVitestKyselyTransaction(api, connection, setup, level = require_Vit
67
67
  const wrapper = new require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator(api);
68
68
  return wrapper.wrapVitestWithTransaction(connection, setup, level);
69
69
  }
70
+ /**
71
+ * Extends a Kysely transaction-wrapped test with additional fixtures.
72
+ * Each fixture receives the transaction and can create dependencies like factories or repositories.
73
+ *
74
+ * @template Database - The database schema type
75
+ * @template Extended - The type of additional fixtures to provide
76
+ * @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction
77
+ * @param fixtures - Object mapping fixture names to creator functions
78
+ * @returns An extended test API with both trx and the additional fixtures
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * import { test } from 'vitest';
83
+ * import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';
84
+ *
85
+ * // Define your builders
86
+ * const builders = {
87
+ * user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({
88
+ * name: faker.person.fullName(),
89
+ * email: faker.internet.email(),
90
+ * })),
91
+ * };
92
+ *
93
+ * // Create base wrapped test
94
+ * const baseTest = wrapVitestKyselyTransaction<DB>(test, db, createTestTables);
95
+ *
96
+ * // Extend with fixtures - each fixture receives the transaction
97
+ * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(
98
+ * baseTest,
99
+ * {
100
+ * factory: (trx) => new KyselyFactory(builders, {}, trx),
101
+ * }
102
+ * );
103
+ *
104
+ * // Use in tests - both trx and factory are available
105
+ * it('should create user with factory', async ({ trx, factory }) => {
106
+ * const user = await factory.insert('user', { name: 'Test User' });
107
+ * expect(user.id).toBeDefined();
108
+ *
109
+ * // Verify in database
110
+ * const found = await trx
111
+ * .selectFrom('users')
112
+ * .where('id', '=', user.id)
113
+ * .selectAll()
114
+ * .executeTakeFirst();
115
+ * expect(found?.name).toBe('Test User');
116
+ * });
117
+ * ```
118
+ */
119
+ function extendWithFixtures$1(wrappedTest, fixtures) {
120
+ return require_VitestTransactionIsolator.extendWithFixtures(wrappedTest, fixtures);
121
+ }
70
122
 
71
123
  //#endregion
72
124
  exports.IsolationLevel = require_VitestTransactionIsolator.IsolationLevel;
73
125
  exports.KyselyFactory = require_KyselyFactory.KyselyFactory;
74
126
  exports.PostgresKyselyMigrator = require_PostgresKyselyMigrator.PostgresKyselyMigrator;
75
127
  exports.VitestKyselyTransactionIsolator = require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator;
128
+ exports.extendWithFixtures = extendWithFixtures$1;
129
+ exports.faker = require_faker.faker;
76
130
  exports.wrapVitestKyselyTransaction = wrapVitestKyselyTransaction;
77
131
  //# sourceMappingURL=kysely.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"kysely.cjs","names":["api: TestAPI","connection: DatabaseConnection<Kysely<Database>>","setup?: (trx: Transaction<Database>) => Promise<void>","level: IsolationLevel","IsolationLevel","VitestKyselyTransactionIsolator"],"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 IsolationLevel,\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';\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 * @param api - The Vitest test API (usually `test` from vitest)\n * @param db - The Kysely database instance\n * @param setup - Optional setup function to run before each test in the transaction\n * @param level - Transaction isolation level (defaults to REPEATABLE_READ)\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, db);\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 * // User is automatically rolled back after test\n * });\n *\n * // With setup function for common test data\n * const testWithSetup = wrapVitestKyselyTransaction(\n * test,\n * db,\n * async (trx) => {\n * // Create common test data\n * await trx.insertInto('settings')\n * .values({ key: 'test_mode', value: 'true' })\n * .execute();\n * }\n * );\n *\n * testWithSetup('should have test settings', async ({ trx }) => {\n * const setting = await trx\n * .selectFrom('settings')\n * .where('key', '=', 'test_mode')\n * .selectAll()\n * .executeTakeFirst();\n *\n * expect(setting?.value).toBe('true');\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<Database>(\n api: TestAPI,\n connection: DatabaseConnection<Kysely<Database>>,\n setup?: (trx: Transaction<Database>) => Promise<void>,\n level: IsolationLevel = IsolationLevel.REPEATABLE_READ,\n) {\n const wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n return wrapper.wrapVitestWithTransaction(connection, setup, level);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,SAAgB,4BACdA,KACAC,YACAC,OACAC,QAAwBC,iDAAe,iBACvC;CACA,MAAM,UAAU,IAAIC,wEAA0C;AAE9D,QAAO,QAAQ,0BAA0B,YAAY,OAAO,MAAM;AACnE"}
1
+ {"version":3,"file":"kysely.cjs","names":["api: TestAPI","connection: DatabaseConnection<Kysely<Database>>","setup?: (trx: Transaction<Database>) => Promise<void>","level: IsolationLevel","IsolationLevel","VitestKyselyTransactionIsolator","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 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 { FixtureCreators } from './VitestTransactionIsolator';\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 * @param api - The Vitest test API (usually `test` from vitest)\n * @param db - The Kysely database instance\n * @param setup - Optional setup function to run before each test in the transaction\n * @param level - Transaction isolation level (defaults to REPEATABLE_READ)\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, db);\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 * // User is automatically rolled back after test\n * });\n *\n * // With setup function for common test data\n * const testWithSetup = wrapVitestKyselyTransaction(\n * test,\n * db,\n * async (trx) => {\n * // Create common test data\n * await trx.insertInto('settings')\n * .values({ key: 'test_mode', value: 'true' })\n * .execute();\n * }\n * );\n *\n * testWithSetup('should have test settings', async ({ trx }) => {\n * const setting = await trx\n * .selectFrom('settings')\n * .where('key', '=', 'test_mode')\n * .selectAll()\n * .executeTakeFirst();\n *\n * expect(setting?.value).toBe('true');\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<Database>(\n api: TestAPI,\n connection: DatabaseConnection<Kysely<Database>>,\n setup?: (trx: Transaction<Database>) => Promise<void>,\n level: IsolationLevel = IsolationLevel.REPEATABLE_READ,\n) {\n const wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n return wrapper.wrapVitestWithTransaction(connection, setup, level);\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, db, createTestTables);\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFA,SAAgB,4BACdA,KACAC,YACAC,OACAC,QAAwBC,iDAAe,iBACvC;CACA,MAAM,UAAU,IAAIC,wEAA0C;AAE9D,QAAO,QAAQ,0BAA0B,YAAY,OAAO,MAAM;AACnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDD,SAAgBC,qBAIdC,aAAgBC,UAA4D;AAC5E,QAAO,qDACL,aACA,SACD;AACF"}
package/dist/kysely.d.cts CHANGED
@@ -1,10 +1,10 @@
1
- import "./faker-Cg76aFNO.cjs";
1
+ import { FakerFactory, faker } from "./faker-Cg76aFNO.cjs";
2
2
  import "./Factory-BZ8uMoXl.cjs";
3
- import { KyselyFactory } from "./KyselyFactory-DRQ83r0o.cjs";
3
+ import { KyselyFactory } from "./KyselyFactory-BFygzOlO.cjs";
4
4
  import "./PostgresMigrator-D5UkK1_K.cjs";
5
5
  import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CQ3aUoy_.cjs";
6
- import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-DdLNODZg.cjs";
7
- import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-DYUYVEh9.cjs";
6
+ import { DatabaseConnection, DatabaseFixtures, FixtureCreators, IsolationLevel } from "./VitestTransactionIsolator-CyG_i_Nj.cjs";
7
+ import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-4HOeLQ0d.cjs";
8
8
  import { Kysely, Transaction } from "kysely";
9
9
  import { TestAPI } from "vitest";
10
10
 
@@ -69,6 +69,59 @@ import { TestAPI } from "vitest";
69
69
  declare function wrapVitestKyselyTransaction<Database>(api: TestAPI, connection: DatabaseConnection<Kysely<Database>>, setup?: (trx: Transaction<Database>) => Promise<void>, level?: IsolationLevel): TestAPI<{
70
70
  trx: Transaction<Database>;
71
71
  }>;
72
+ /**
73
+ * Extends a Kysely transaction-wrapped test with additional fixtures.
74
+ * Each fixture receives the transaction and can create dependencies like factories or repositories.
75
+ *
76
+ * @template Database - The database schema type
77
+ * @template Extended - The type of additional fixtures to provide
78
+ * @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction
79
+ * @param fixtures - Object mapping fixture names to creator functions
80
+ * @returns An extended test API with both trx and the additional fixtures
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * import { test } from 'vitest';
85
+ * import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';
86
+ *
87
+ * // Define your builders
88
+ * const builders = {
89
+ * user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({
90
+ * name: faker.person.fullName(),
91
+ * email: faker.internet.email(),
92
+ * })),
93
+ * };
94
+ *
95
+ * // Create base wrapped test
96
+ * const baseTest = wrapVitestKyselyTransaction<DB>(test, db, createTestTables);
97
+ *
98
+ * // Extend with fixtures - each fixture receives the transaction
99
+ * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(
100
+ * baseTest,
101
+ * {
102
+ * factory: (trx) => new KyselyFactory(builders, {}, trx),
103
+ * }
104
+ * );
105
+ *
106
+ * // Use in tests - both trx and factory are available
107
+ * it('should create user with factory', async ({ trx, factory }) => {
108
+ * const user = await factory.insert('user', { name: 'Test User' });
109
+ * expect(user.id).toBeDefined();
110
+ *
111
+ * // Verify in database
112
+ * const found = await trx
113
+ * .selectFrom('users')
114
+ * .where('id', '=', user.id)
115
+ * .selectAll()
116
+ * .executeTakeFirst();
117
+ * expect(found?.name).toBe('Test User');
118
+ * });
119
+ * ```
120
+ */
121
+ declare function extendWithFixtures<Database, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>): T & {
122
+ <C extends object>(name: string, fn: (context: DatabaseFixtures<Transaction<Database>, object> & Extended & C) => Promise<void>): void;
123
+ <C extends object>(name: string, options: object, fn: (context: DatabaseFixtures<Transaction<Database>, object> & Extended & C) => Promise<void>): void;
124
+ };
72
125
  //#endregion
73
- export { IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, wrapVitestKyselyTransaction };
126
+ export { FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
74
127
  //# sourceMappingURL=kysely.d.cts.map
package/dist/kysely.d.mts CHANGED
@@ -1,10 +1,10 @@
1
- import "./faker-Br8MzXil.mjs";
2
- import "./Factory-CRquB4vz.mjs";
3
- import { KyselyFactory } from "./KyselyFactory-BDS_QqRT.mjs";
1
+ import { FakerFactory, faker } from "./faker-DHh7xs4u.mjs";
2
+ import "./Factory-Cmr3s3-s.mjs";
3
+ import { KyselyFactory } from "./KyselyFactory-BTdygZ-i.mjs";
4
4
  import "./PostgresMigrator-DQaRxoaY.mjs";
5
5
  import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CIx3AFSR.mjs";
6
- import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-CsfJBxcb.mjs";
7
- import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-COCVfvfr.mjs";
6
+ import { DatabaseConnection, DatabaseFixtures, FixtureCreators, IsolationLevel } from "./VitestTransactionIsolator-DWDbnITQ.mjs";
7
+ import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-DnyZMaA-.mjs";
8
8
  import { Kysely, Transaction } from "kysely";
9
9
  import { TestAPI } from "vitest";
10
10
 
@@ -69,6 +69,59 @@ import { TestAPI } from "vitest";
69
69
  declare function wrapVitestKyselyTransaction<Database>(api: TestAPI, connection: DatabaseConnection<Kysely<Database>>, setup?: (trx: Transaction<Database>) => Promise<void>, level?: IsolationLevel): TestAPI<{
70
70
  trx: Transaction<Database>;
71
71
  }>;
72
+ /**
73
+ * Extends a Kysely transaction-wrapped test with additional fixtures.
74
+ * Each fixture receives the transaction and can create dependencies like factories or repositories.
75
+ *
76
+ * @template Database - The database schema type
77
+ * @template Extended - The type of additional fixtures to provide
78
+ * @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction
79
+ * @param fixtures - Object mapping fixture names to creator functions
80
+ * @returns An extended test API with both trx and the additional fixtures
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * import { test } from 'vitest';
85
+ * import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';
86
+ *
87
+ * // Define your builders
88
+ * const builders = {
89
+ * user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({
90
+ * name: faker.person.fullName(),
91
+ * email: faker.internet.email(),
92
+ * })),
93
+ * };
94
+ *
95
+ * // Create base wrapped test
96
+ * const baseTest = wrapVitestKyselyTransaction<DB>(test, db, createTestTables);
97
+ *
98
+ * // Extend with fixtures - each fixture receives the transaction
99
+ * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(
100
+ * baseTest,
101
+ * {
102
+ * factory: (trx) => new KyselyFactory(builders, {}, trx),
103
+ * }
104
+ * );
105
+ *
106
+ * // Use in tests - both trx and factory are available
107
+ * it('should create user with factory', async ({ trx, factory }) => {
108
+ * const user = await factory.insert('user', { name: 'Test User' });
109
+ * expect(user.id).toBeDefined();
110
+ *
111
+ * // Verify in database
112
+ * const found = await trx
113
+ * .selectFrom('users')
114
+ * .where('id', '=', user.id)
115
+ * .selectAll()
116
+ * .executeTakeFirst();
117
+ * expect(found?.name).toBe('Test User');
118
+ * });
119
+ * ```
120
+ */
121
+ declare function extendWithFixtures<Database, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>): T & {
122
+ <C extends object>(name: string, fn: (context: DatabaseFixtures<Transaction<Database>, object> & Extended & C) => Promise<void>): void;
123
+ <C extends object>(name: string, options: object, fn: (context: DatabaseFixtures<Transaction<Database>, object> & Extended & C) => Promise<void>): void;
124
+ };
72
125
  //#endregion
73
- export { IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, wrapVitestKyselyTransaction };
126
+ export { FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
74
127
  //# sourceMappingURL=kysely.d.mts.map
package/dist/kysely.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import "./Factory-z2m01hMj.mjs";
2
- import "./faker-BGKYFoCT.mjs";
3
- import { KyselyFactory } from "./KyselyFactory-BcYkC0t2.mjs";
2
+ import { faker } from "./faker-BGKYFoCT.mjs";
3
+ import { KyselyFactory } from "./KyselyFactory-CXY5gJk2.mjs";
4
4
  import "./PostgresMigrator-DbuJGAVy.mjs";
5
5
  import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-upT-hmrz.mjs";
6
- import { IsolationLevel } from "./VitestTransactionIsolator-CskiiJbW.mjs";
7
- import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-BxjlD1YM.mjs";
6
+ import { IsolationLevel, extendWithFixtures } from "./VitestTransactionIsolator-BIaMs4c2.mjs";
7
+ import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-XDL3ngs_.mjs";
8
8
 
9
9
  //#region src/kysely.ts
10
10
  /**
@@ -67,7 +67,59 @@ function wrapVitestKyselyTransaction(api, connection, setup, level = IsolationLe
67
67
  const wrapper = new VitestKyselyTransactionIsolator(api);
68
68
  return wrapper.wrapVitestWithTransaction(connection, setup, level);
69
69
  }
70
+ /**
71
+ * Extends a Kysely transaction-wrapped test with additional fixtures.
72
+ * Each fixture receives the transaction and can create dependencies like factories or repositories.
73
+ *
74
+ * @template Database - The database schema type
75
+ * @template Extended - The type of additional fixtures to provide
76
+ * @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction
77
+ * @param fixtures - Object mapping fixture names to creator functions
78
+ * @returns An extended test API with both trx and the additional fixtures
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * import { test } from 'vitest';
83
+ * import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';
84
+ *
85
+ * // Define your builders
86
+ * const builders = {
87
+ * user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({
88
+ * name: faker.person.fullName(),
89
+ * email: faker.internet.email(),
90
+ * })),
91
+ * };
92
+ *
93
+ * // Create base wrapped test
94
+ * const baseTest = wrapVitestKyselyTransaction<DB>(test, db, createTestTables);
95
+ *
96
+ * // Extend with fixtures - each fixture receives the transaction
97
+ * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(
98
+ * baseTest,
99
+ * {
100
+ * factory: (trx) => new KyselyFactory(builders, {}, trx),
101
+ * }
102
+ * );
103
+ *
104
+ * // Use in tests - both trx and factory are available
105
+ * it('should create user with factory', async ({ trx, factory }) => {
106
+ * const user = await factory.insert('user', { name: 'Test User' });
107
+ * expect(user.id).toBeDefined();
108
+ *
109
+ * // Verify in database
110
+ * const found = await trx
111
+ * .selectFrom('users')
112
+ * .where('id', '=', user.id)
113
+ * .selectAll()
114
+ * .executeTakeFirst();
115
+ * expect(found?.name).toBe('Test User');
116
+ * });
117
+ * ```
118
+ */
119
+ function extendWithFixtures$1(wrappedTest, fixtures) {
120
+ return extendWithFixtures(wrappedTest, fixtures);
121
+ }
70
122
 
71
123
  //#endregion
72
- export { IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, wrapVitestKyselyTransaction };
124
+ export { IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, extendWithFixtures$1 as extendWithFixtures, faker, wrapVitestKyselyTransaction };
73
125
  //# sourceMappingURL=kysely.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"kysely.mjs","names":["api: TestAPI","connection: DatabaseConnection<Kysely<Database>>","setup?: (trx: Transaction<Database>) => Promise<void>","level: IsolationLevel"],"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 IsolationLevel,\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';\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 * @param api - The Vitest test API (usually `test` from vitest)\n * @param db - The Kysely database instance\n * @param setup - Optional setup function to run before each test in the transaction\n * @param level - Transaction isolation level (defaults to REPEATABLE_READ)\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, db);\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 * // User is automatically rolled back after test\n * });\n *\n * // With setup function for common test data\n * const testWithSetup = wrapVitestKyselyTransaction(\n * test,\n * db,\n * async (trx) => {\n * // Create common test data\n * await trx.insertInto('settings')\n * .values({ key: 'test_mode', value: 'true' })\n * .execute();\n * }\n * );\n *\n * testWithSetup('should have test settings', async ({ trx }) => {\n * const setting = await trx\n * .selectFrom('settings')\n * .where('key', '=', 'test_mode')\n * .selectAll()\n * .executeTakeFirst();\n *\n * expect(setting?.value).toBe('true');\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<Database>(\n api: TestAPI,\n connection: DatabaseConnection<Kysely<Database>>,\n setup?: (trx: Transaction<Database>) => Promise<void>,\n level: IsolationLevel = IsolationLevel.REPEATABLE_READ,\n) {\n const wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n return wrapper.wrapVitestWithTransaction(connection, setup, level);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,SAAgB,4BACdA,KACAC,YACAC,OACAC,QAAwB,eAAe,iBACvC;CACA,MAAM,UAAU,IAAI,gCAA0C;AAE9D,QAAO,QAAQ,0BAA0B,YAAY,OAAO,MAAM;AACnE"}
1
+ {"version":3,"file":"kysely.mjs","names":["api: TestAPI","connection: DatabaseConnection<Kysely<Database>>","setup?: (trx: Transaction<Database>) => Promise<void>","level: IsolationLevel","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 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 { FixtureCreators } from './VitestTransactionIsolator';\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 * @param api - The Vitest test API (usually `test` from vitest)\n * @param db - The Kysely database instance\n * @param setup - Optional setup function to run before each test in the transaction\n * @param level - Transaction isolation level (defaults to REPEATABLE_READ)\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, db);\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 * // User is automatically rolled back after test\n * });\n *\n * // With setup function for common test data\n * const testWithSetup = wrapVitestKyselyTransaction(\n * test,\n * db,\n * async (trx) => {\n * // Create common test data\n * await trx.insertInto('settings')\n * .values({ key: 'test_mode', value: 'true' })\n * .execute();\n * }\n * );\n *\n * testWithSetup('should have test settings', async ({ trx }) => {\n * const setting = await trx\n * .selectFrom('settings')\n * .where('key', '=', 'test_mode')\n * .selectAll()\n * .executeTakeFirst();\n *\n * expect(setting?.value).toBe('true');\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<Database>(\n api: TestAPI,\n connection: DatabaseConnection<Kysely<Database>>,\n setup?: (trx: Transaction<Database>) => Promise<void>,\n level: IsolationLevel = IsolationLevel.REPEATABLE_READ,\n) {\n const wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n return wrapper.wrapVitestWithTransaction(connection, setup, level);\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, db, createTestTables);\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFA,SAAgB,4BACdA,KACAC,YACAC,OACAC,QAAwB,eAAe,iBACvC;CACA,MAAM,UAAU,IAAI,gCAA0C;AAE9D,QAAO,QAAQ,0BAA0B,YAAY,OAAO,MAAM;AACnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDD,SAAgBC,qBAIdC,aAAgBC,UAA4D;AAC5E,QAAO,mBACL,aACA,SACD;AACF"}
@@ -1,10 +1,10 @@
1
1
  require('./Factory-WMhTNZ9S.cjs');
2
- require('./faker-B14IEMIN.cjs');
3
- const require_ObjectionFactory = require('./ObjectionFactory-CDriunkS.cjs');
2
+ const require_faker = require('./faker-B14IEMIN.cjs');
3
+ const require_ObjectionFactory = require('./ObjectionFactory-Eb04AOnv.cjs');
4
4
  require('./PostgresMigrator-DFcNdCvD.cjs');
5
5
  const require_PostgresObjectionMigrator = require('./PostgresObjectionMigrator-BG6ymgnt.cjs');
6
- const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BQ5FpLtC.cjs');
7
- const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-DzeF4UAq.cjs');
6
+ const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BKIrj3Uy.cjs');
7
+ const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-D_tlOtq8.cjs');
8
8
 
9
9
  //#region src/objection.ts
10
10
  /**
@@ -82,11 +82,61 @@ function wrapVitestObjectionTransaction(api, conn, setup, level = require_Vitest
82
82
  const wrapper = new require_VitestObjectionTransactionIsolator.VitestObjectionTransactionIsolator(api);
83
83
  return wrapper.wrapVitestWithTransaction(conn, setup, level);
84
84
  }
85
+ /**
86
+ * Extends an Objection.js transaction-wrapped test with additional fixtures.
87
+ * Each fixture receives the transaction and can create dependencies like factories or repositories.
88
+ *
89
+ * @template Extended - The type of additional fixtures to provide
90
+ * @param wrappedTest - The base wrapped test from wrapVitestObjectionTransaction
91
+ * @param fixtures - Object mapping fixture names to creator functions
92
+ * @returns An extended test API with both trx and the additional fixtures
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * import { test } from 'vitest';
97
+ * import { wrapVitestObjectionTransaction, extendWithFixtures, ObjectionFactory } from '@geekmidas/testkit/objection';
98
+ * import { User } from './models';
99
+ *
100
+ * // Define your builders
101
+ * const builders = {
102
+ * user: ObjectionFactory.createBuilder(User, ({ faker }) => ({
103
+ * name: faker.person.fullName(),
104
+ * email: faker.internet.email(),
105
+ * })),
106
+ * };
107
+ *
108
+ * // Create base wrapped test
109
+ * const baseTest = wrapVitestObjectionTransaction(test, knex, createTestTables);
110
+ *
111
+ * // Extend with fixtures - each fixture receives the transaction
112
+ * const it = extendWithFixtures<{ factory: ObjectionFactory<typeof builders, {}> }>(
113
+ * baseTest,
114
+ * {
115
+ * factory: (trx) => new ObjectionFactory(builders, {}, trx),
116
+ * }
117
+ * );
118
+ *
119
+ * // Use in tests - both trx and factory are available
120
+ * it('should create user with factory', async ({ trx, factory }) => {
121
+ * const user = await factory.insert('user', { name: 'Test User' });
122
+ * expect(user.id).toBeDefined();
123
+ *
124
+ * // Verify in database
125
+ * const found = await User.query(trx).findById(user.id);
126
+ * expect(found?.name).toBe('Test User');
127
+ * });
128
+ * ```
129
+ */
130
+ function extendWithFixtures$1(wrappedTest, fixtures) {
131
+ return require_VitestTransactionIsolator.extendWithFixtures(wrappedTest, fixtures);
132
+ }
85
133
 
86
134
  //#endregion
87
135
  exports.IsolationLevel = require_VitestTransactionIsolator.IsolationLevel;
88
136
  exports.ObjectionFactory = require_ObjectionFactory.ObjectionFactory;
89
137
  exports.PostgresObjectionMigrator = require_PostgresObjectionMigrator.PostgresObjectionMigrator;
90
138
  exports.VitestObjectionTransactionIsolator = require_VitestObjectionTransactionIsolator.VitestObjectionTransactionIsolator;
139
+ exports.extendWithFixtures = extendWithFixtures$1;
140
+ exports.faker = require_faker.faker;
91
141
  exports.wrapVitestObjectionTransaction = wrapVitestObjectionTransaction;
92
142
  //# sourceMappingURL=objection.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"objection.cjs","names":["api: TestAPI","conn: DatabaseConnection<Knex>","setup?: (trx: Knex.Transaction) => Promise<void>","level: IsolationLevel","IsolationLevel","VitestObjectionTransactionIsolator"],"sources":["../src/objection.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { TestAPI } from 'vitest';\nimport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nimport {\n type DatabaseConnection,\n IsolationLevel,\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';\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 * @param api - The Vitest test API (usually `test` from vitest)\n * @param conn - The Knex database connection instance\n * @param setup - Optional setup function to run before each test in the transaction\n * @param level - Transaction isolation level (defaults to REPEATABLE_READ)\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, Post } from './models';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestObjectionTransaction(test, knex);\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 * // User is automatically rolled back after test\n * });\n *\n * // With setup function for common test data\n * const testWithSetup = wrapVitestObjectionTransaction(\n * test,\n * knex,\n * async (trx) => {\n * // Create common test data\n * await knex('settings')\n * .transacting(trx)\n * .insert({ key: 'test_mode', value: 'true' });\n * }\n * );\n *\n * testWithSetup('should have test settings', async ({ trx }) => {\n * const setting = await knex('settings')\n * .transacting(trx)\n * .where('key', 'test_mode')\n * .first();\n *\n * expect(setting?.value).toBe('true');\n * });\n *\n * // Example with factory and transaction\n * const isolatedTest = wrapVitestObjectionTransaction(test, knex);\n * const factory = new ObjectionFactory(builders, seeds, knex);\n *\n * isolatedTest('creates related data', async ({ trx }) => {\n * // Factory can use the transaction\n * const user = await User.query(trx).insert({ name: 'Author' });\n * const posts = await Post.query(trx).insert([\n * { title: 'Post 1', userId: user.id },\n * { title: 'Post 2', userId: user.id }\n * ]);\n *\n * const userWithPosts = await User.query(trx)\n * .findById(user.id)\n * .withGraphFetched('posts');\n *\n * expect(userWithPosts.posts).toHaveLength(2);\n * });\n * ```\n */\nexport function wrapVitestObjectionTransaction(\n api: TestAPI,\n conn: DatabaseConnection<Knex>,\n setup?: (trx: Knex.Transaction) => Promise<void>,\n level: IsolationLevel = IsolationLevel.REPEATABLE_READ,\n) {\n const wrapper = new VitestObjectionTransactionIsolator(api);\n\n return wrapper.wrapVitestWithTransaction(conn, setup, level);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0FA,SAAgB,+BACdA,KACAC,MACAC,OACAC,QAAwBC,iDAAe,iBACvC;CACA,MAAM,UAAU,IAAIC,8EAAmC;AAEvD,QAAO,QAAQ,0BAA0B,MAAM,OAAO,MAAM;AAC7D"}
1
+ {"version":3,"file":"objection.cjs","names":["api: TestAPI","conn: DatabaseConnection<Knex>","setup?: (trx: Knex.Transaction) => Promise<void>","level: IsolationLevel","IsolationLevel","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 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 { FixtureCreators } from './VitestTransactionIsolator';\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 * @param api - The Vitest test API (usually `test` from vitest)\n * @param conn - The Knex database connection instance\n * @param setup - Optional setup function to run before each test in the transaction\n * @param level - Transaction isolation level (defaults to REPEATABLE_READ)\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, Post } from './models';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestObjectionTransaction(test, knex);\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 * // User is automatically rolled back after test\n * });\n *\n * // With setup function for common test data\n * const testWithSetup = wrapVitestObjectionTransaction(\n * test,\n * knex,\n * async (trx) => {\n * // Create common test data\n * await knex('settings')\n * .transacting(trx)\n * .insert({ key: 'test_mode', value: 'true' });\n * }\n * );\n *\n * testWithSetup('should have test settings', async ({ trx }) => {\n * const setting = await knex('settings')\n * .transacting(trx)\n * .where('key', 'test_mode')\n * .first();\n *\n * expect(setting?.value).toBe('true');\n * });\n *\n * // Example with factory and transaction\n * const isolatedTest = wrapVitestObjectionTransaction(test, knex);\n * const factory = new ObjectionFactory(builders, seeds, knex);\n *\n * isolatedTest('creates related data', async ({ trx }) => {\n * // Factory can use the transaction\n * const user = await User.query(trx).insert({ name: 'Author' });\n * const posts = await Post.query(trx).insert([\n * { title: 'Post 1', userId: user.id },\n * { title: 'Post 2', userId: user.id }\n * ]);\n *\n * const userWithPosts = await User.query(trx)\n * .findById(user.id)\n * .withGraphFetched('posts');\n *\n * expect(userWithPosts.posts).toHaveLength(2);\n * });\n * ```\n */\nexport function wrapVitestObjectionTransaction(\n api: TestAPI,\n conn: DatabaseConnection<Knex>,\n setup?: (trx: Knex.Transaction) => Promise<void>,\n level: IsolationLevel = IsolationLevel.REPEATABLE_READ,\n) {\n const wrapper = new VitestObjectionTransactionIsolator(api);\n\n return wrapper.wrapVitestWithTransaction(conn, setup, level);\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, knex, createTestTables);\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,SAAgB,+BACdA,KACAC,MACAC,OACAC,QAAwBC,iDAAe,iBACvC;CACA,MAAM,UAAU,IAAIC,8EAAmC;AAEvD,QAAO,QAAQ,0BAA0B,MAAM,OAAO,MAAM;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CD,SAAgBC,qBAGdC,aAAgBC,UAAuD;AACvE,QAAO,qDACL,aACA,SACD;AACF"}
@@ -1,10 +1,10 @@
1
- import "./faker-Cg76aFNO.cjs";
1
+ import { FakerFactory, faker } from "./faker-Cg76aFNO.cjs";
2
2
  import "./Factory-BZ8uMoXl.cjs";
3
- import { ObjectionFactory } from "./ObjectionFactory-C4X78k0B.cjs";
3
+ import { ObjectionFactory } from "./ObjectionFactory-CeSIN3kZ.cjs";
4
4
  import "./PostgresMigrator-D5UkK1_K.cjs";
5
5
  import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-CZHHcCOv.cjs";
6
- import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-DdLNODZg.cjs";
7
- import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-CJ4ds5Qv.cjs";
6
+ import { DatabaseConnection, DatabaseFixtures, FixtureCreators, IsolationLevel } from "./VitestTransactionIsolator-CyG_i_Nj.cjs";
7
+ import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-COVDlpEo.cjs";
8
8
  import { Knex } from "knex";
9
9
  import { TestAPI } from "vitest";
10
10
 
@@ -84,6 +84,55 @@ import { TestAPI } from "vitest";
84
84
  declare function wrapVitestObjectionTransaction(api: TestAPI, conn: DatabaseConnection<Knex>, setup?: (trx: Knex.Transaction) => Promise<void>, level?: IsolationLevel): TestAPI<{
85
85
  trx: Knex.Transaction<any, any[]>;
86
86
  }>;
87
+ /**
88
+ * Extends an Objection.js transaction-wrapped test with additional fixtures.
89
+ * Each fixture receives the transaction and can create dependencies like factories or repositories.
90
+ *
91
+ * @template Extended - The type of additional fixtures to provide
92
+ * @param wrappedTest - The base wrapped test from wrapVitestObjectionTransaction
93
+ * @param fixtures - Object mapping fixture names to creator functions
94
+ * @returns An extended test API with both trx and the additional fixtures
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * import { test } from 'vitest';
99
+ * import { wrapVitestObjectionTransaction, extendWithFixtures, ObjectionFactory } from '@geekmidas/testkit/objection';
100
+ * import { User } from './models';
101
+ *
102
+ * // Define your builders
103
+ * const builders = {
104
+ * user: ObjectionFactory.createBuilder(User, ({ faker }) => ({
105
+ * name: faker.person.fullName(),
106
+ * email: faker.internet.email(),
107
+ * })),
108
+ * };
109
+ *
110
+ * // Create base wrapped test
111
+ * const baseTest = wrapVitestObjectionTransaction(test, knex, createTestTables);
112
+ *
113
+ * // Extend with fixtures - each fixture receives the transaction
114
+ * const it = extendWithFixtures<{ factory: ObjectionFactory<typeof builders, {}> }>(
115
+ * baseTest,
116
+ * {
117
+ * factory: (trx) => new ObjectionFactory(builders, {}, trx),
118
+ * }
119
+ * );
120
+ *
121
+ * // Use in tests - both trx and factory are available
122
+ * it('should create user with factory', async ({ trx, factory }) => {
123
+ * const user = await factory.insert('user', { name: 'Test User' });
124
+ * expect(user.id).toBeDefined();
125
+ *
126
+ * // Verify in database
127
+ * const found = await User.query(trx).findById(user.id);
128
+ * expect(found?.name).toBe('Test User');
129
+ * });
130
+ * ```
131
+ */
132
+ declare function extendWithFixtures<Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Knex.Transaction, Extended>): T & {
133
+ <C extends object>(name: string, fn: (context: DatabaseFixtures<Knex.Transaction<any, any[]>, object> & Extended & C) => Promise<void>): void;
134
+ <C extends object>(name: string, options: object, fn: (context: DatabaseFixtures<Knex.Transaction<any, any[]>, object> & Extended & C) => Promise<void>): void;
135
+ };
87
136
  //#endregion
88
- export { IsolationLevel, ObjectionFactory, PostgresObjectionMigrator, VitestObjectionTransactionIsolator, wrapVitestObjectionTransaction };
137
+ export { FakerFactory, FixtureCreators, IsolationLevel, ObjectionFactory, PostgresObjectionMigrator, VitestObjectionTransactionIsolator, extendWithFixtures, faker, wrapVitestObjectionTransaction };
89
138
  //# sourceMappingURL=objection.d.cts.map