@geekmidas/testkit 0.1.1 → 0.3.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 (108) hide show
  1. package/dist/{Factory-z2m01hMj.mjs → Factory-BFVnMMCC.mjs} +2 -2
  2. package/dist/Factory-BFVnMMCC.mjs.map +1 -0
  3. package/dist/{Factory-DE3hE0WO.d.mts → Factory-BcGJjLc8.d.mts} +24 -10
  4. package/dist/{Factory-WMhTNZ9S.cjs → Factory-BhjUOBWN.cjs} +2 -2
  5. package/dist/Factory-BhjUOBWN.cjs.map +1 -0
  6. package/dist/{Factory-pNV7ZQ7-.d.cts → Factory-IdfEkOeT.d.cts} +24 -10
  7. package/dist/Factory.cjs +1 -1
  8. package/dist/Factory.d.cts +3 -3
  9. package/dist/Factory.d.mts +3 -3
  10. package/dist/Factory.mjs +1 -1
  11. package/dist/{KyselyFactory-DaaCykWP.cjs → KyselyFactory-BFqVIn_0.cjs} +21 -4
  12. package/dist/KyselyFactory-BFqVIn_0.cjs.map +1 -0
  13. package/dist/{KyselyFactory-CPZTUuMB.d.cts → KyselyFactory-Cj-EultY.d.mts} +18 -5
  14. package/dist/{KyselyFactory-CXY5gJk2.mjs → KyselyFactory-DMswpwji.mjs} +21 -4
  15. package/dist/KyselyFactory-DMswpwji.mjs.map +1 -0
  16. package/dist/{KyselyFactory-RAyvZ8Cj.d.mts → KyselyFactory-Dxhi_ZkA.d.cts} +18 -5
  17. package/dist/KyselyFactory.cjs +2 -2
  18. package/dist/KyselyFactory.d.cts +3 -3
  19. package/dist/KyselyFactory.d.mts +3 -3
  20. package/dist/KyselyFactory.mjs +2 -2
  21. package/dist/{ObjectionFactory-BlBicEia.d.mts → ObjectionFactory-BRAkAByP.d.cts} +18 -5
  22. package/dist/{ObjectionFactory-Eb04AOnv.cjs → ObjectionFactory-BeFBYcan.cjs} +21 -4
  23. package/dist/ObjectionFactory-BeFBYcan.cjs.map +1 -0
  24. package/dist/{ObjectionFactory-BwpN4gMX.d.cts → ObjectionFactory-DL4qkuF1.d.mts} +18 -5
  25. package/dist/{ObjectionFactory-zf2fLKrL.mjs → ObjectionFactory-QCJ7u0Ql.mjs} +21 -4
  26. package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +1 -0
  27. package/dist/ObjectionFactory.cjs +2 -2
  28. package/dist/ObjectionFactory.d.cts +3 -3
  29. package/dist/ObjectionFactory.d.mts +3 -3
  30. package/dist/ObjectionFactory.mjs +2 -2
  31. package/dist/{VitestKyselyTransactionIsolator-XDL3ngs_.mjs → VitestKyselyTransactionIsolator-CNURW8y6.mjs} +2 -2
  32. package/dist/{VitestKyselyTransactionIsolator-XDL3ngs_.mjs.map → VitestKyselyTransactionIsolator-CNURW8y6.mjs.map} +1 -1
  33. package/dist/{VitestKyselyTransactionIsolator-DiskaURs.d.mts → VitestKyselyTransactionIsolator-D3EZZhjZ.d.cts} +2 -2
  34. package/dist/{VitestKyselyTransactionIsolator-BqrZDeaT.d.cts → VitestKyselyTransactionIsolator-Dxlp1u0f.d.mts} +2 -2
  35. package/dist/{VitestKyselyTransactionIsolator-DX_VPKS-.cjs → VitestKyselyTransactionIsolator-EvDLk5zg.cjs} +2 -2
  36. package/dist/{VitestKyselyTransactionIsolator-DX_VPKS-.cjs.map → VitestKyselyTransactionIsolator-EvDLk5zg.cjs.map} +1 -1
  37. package/dist/VitestKyselyTransactionIsolator.cjs +2 -2
  38. package/dist/VitestKyselyTransactionIsolator.d.cts +2 -2
  39. package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
  40. package/dist/VitestKyselyTransactionIsolator.mjs +2 -2
  41. package/dist/{VitestObjectionTransactionIsolator-CD2ucJpH.d.cts → VitestObjectionTransactionIsolator-1TpsPqfG.d.cts} +2 -2
  42. package/dist/{VitestObjectionTransactionIsolator-D_tlOtq8.cjs → VitestObjectionTransactionIsolator-CM5KTAFA.cjs} +2 -2
  43. package/dist/{VitestObjectionTransactionIsolator-D_tlOtq8.cjs.map → VitestObjectionTransactionIsolator-CM5KTAFA.cjs.map} +1 -1
  44. package/dist/{VitestObjectionTransactionIsolator-DhQ8XGva.d.mts → VitestObjectionTransactionIsolator-i9jIgU8Q.d.mts} +2 -2
  45. package/dist/{VitestObjectionTransactionIsolator-_EhJKu_O.mjs → VitestObjectionTransactionIsolator-jQFaCz0u.mjs} +2 -2
  46. package/dist/{VitestObjectionTransactionIsolator-_EhJKu_O.mjs.map → VitestObjectionTransactionIsolator-jQFaCz0u.mjs.map} +1 -1
  47. package/dist/VitestObjectionTransactionIsolator.cjs +2 -2
  48. package/dist/VitestObjectionTransactionIsolator.d.cts +2 -2
  49. package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
  50. package/dist/VitestObjectionTransactionIsolator.mjs +2 -2
  51. package/dist/{VitestTransactionIsolator-DLdQlfZ5.d.mts → VitestTransactionIsolator-BvR19bYn.d.mts} +31 -14
  52. package/dist/{VitestTransactionIsolator-BKIrj3Uy.cjs → VitestTransactionIsolator-CMfJXZP8.cjs} +52 -36
  53. package/dist/VitestTransactionIsolator-CMfJXZP8.cjs.map +1 -0
  54. package/dist/{VitestTransactionIsolator-DfA80g2M.d.cts → VitestTransactionIsolator-CwQaxZLP.d.cts} +31 -14
  55. package/dist/{VitestTransactionIsolator-BIaMs4c2.mjs → VitestTransactionIsolator-DQ7tLqgV.mjs} +52 -36
  56. package/dist/VitestTransactionIsolator-DQ7tLqgV.mjs.map +1 -0
  57. package/dist/VitestTransactionIsolator.cjs +1 -1
  58. package/dist/VitestTransactionIsolator.d.cts +2 -2
  59. package/dist/VitestTransactionIsolator.d.mts +2 -2
  60. package/dist/VitestTransactionIsolator.mjs +1 -1
  61. package/dist/benchmark.cjs +49 -0
  62. package/dist/benchmark.cjs.map +1 -0
  63. package/dist/benchmark.d.cts +35 -0
  64. package/dist/benchmark.d.mts +35 -0
  65. package/dist/benchmark.mjs +45 -0
  66. package/dist/benchmark.mjs.map +1 -0
  67. package/dist/better-auth.d.cts +2 -2
  68. package/dist/better-auth.d.mts +2 -2
  69. package/dist/{directory-Q178x53k.d.mts → directory-BXavAeJZ.d.mts} +3 -3
  70. package/dist/{faker-BSH1EMtg.d.cts → faker-CbYiF-8_.d.cts} +3 -3
  71. package/dist/{faker-D9gz7KjY.d.mts → faker-DHh7xs4u.d.mts} +3 -3
  72. package/dist/faker.d.cts +1 -1
  73. package/dist/faker.d.mts +1 -1
  74. package/dist/kysely.cjs +25 -31
  75. package/dist/kysely.cjs.map +1 -1
  76. package/dist/kysely.d.cts +39 -34
  77. package/dist/kysely.d.mts +39 -34
  78. package/dist/kysely.mjs +25 -31
  79. package/dist/kysely.mjs.map +1 -1
  80. package/dist/objection.cjs +25 -49
  81. package/dist/objection.cjs.map +1 -1
  82. package/dist/objection.d.cts +39 -52
  83. package/dist/objection.d.mts +39 -52
  84. package/dist/objection.mjs +25 -49
  85. package/dist/objection.mjs.map +1 -1
  86. package/dist/os/directory.d.mts +1 -1
  87. package/dist/os/index.d.mts +1 -1
  88. package/package.json +6 -1
  89. package/src/Factory.ts +25 -11
  90. package/src/KyselyFactory.ts +21 -4
  91. package/src/ObjectionFactory.ts +21 -4
  92. package/src/VitestTransactionIsolator.ts +67 -16
  93. package/src/__tests__/Factory.spec.ts +16 -10
  94. package/src/__tests__/KyselyFactory.spec.ts +16 -11
  95. package/src/__tests__/ObjectionFactory.spec.ts +61 -53
  96. package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +6 -3
  97. package/src/__tests__/integration.spec.ts +24 -18
  98. package/src/benchmark.ts +48 -0
  99. package/src/kysely.ts +44 -33
  100. package/src/objection.ts +42 -51
  101. package/dist/Factory-WMhTNZ9S.cjs.map +0 -1
  102. package/dist/Factory-z2m01hMj.mjs.map +0 -1
  103. package/dist/KyselyFactory-CXY5gJk2.mjs.map +0 -1
  104. package/dist/KyselyFactory-DaaCykWP.cjs.map +0 -1
  105. package/dist/ObjectionFactory-Eb04AOnv.cjs.map +0 -1
  106. package/dist/ObjectionFactory-zf2fLKrL.mjs.map +0 -1
  107. package/dist/VitestTransactionIsolator-BIaMs4c2.mjs.map +0 -1
  108. package/dist/VitestTransactionIsolator-BKIrj3Uy.cjs.map +0 -1
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Generates an array of test records for benchmark data sets.
3
+ *
4
+ * @param count - Number of records to generate
5
+ * @returns Array of test data objects
6
+ */
7
+ export function generateTestData(
8
+ count: number,
9
+ ): Array<{ id: string; name: string; value: number }> {
10
+ return Array.from({ length: count }, (_, i) => ({
11
+ id: `id-${i}`,
12
+ name: `Item ${i}`,
13
+ value: Math.random() * 1000,
14
+ }));
15
+ }
16
+
17
+ /**
18
+ * Generates unique keys for cache benchmarks to avoid collisions.
19
+ *
20
+ * @param prefix - Key prefix
21
+ * @param count - Number of keys to generate
22
+ * @returns Array of unique cache keys
23
+ */
24
+ export function generateCacheKeys(prefix: string, count: number): string[] {
25
+ return Array.from({ length: count }, (_, i) => `${prefix}:${i}`);
26
+ }
27
+
28
+ /**
29
+ * Generates IP addresses for rate limit benchmarks.
30
+ *
31
+ * @param count - Number of IPs to generate
32
+ * @param subnet - Subnet prefix (default: '192.168.1')
33
+ * @returns Array of IP addresses
34
+ */
35
+ export function generateIpAddresses(
36
+ count: number,
37
+ subnet: string = '192.168.1',
38
+ ): string[] {
39
+ return Array.from({ length: count }, (_, i) => `${subnet}.${i % 256}`);
40
+ }
41
+
42
+ /**
43
+ * Creates a random IP address for rate limit benchmarks.
44
+ */
45
+ export function randomIpAddress(): string {
46
+ const octet = () => Math.floor(Math.random() * 256);
47
+ return `${octet()}.${octet()}.${octet()}.${octet()}`;
48
+ }
package/src/kysely.ts CHANGED
@@ -4,7 +4,7 @@ import { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolat
4
4
  import {
5
5
  type DatabaseConnection,
6
6
  type FixtureCreators,
7
- IsolationLevel,
7
+ type IsolationLevel,
8
8
  extendWithFixtures as baseExtendWithFixtures,
9
9
  } from './VitestTransactionIsolator';
10
10
 
@@ -14,6 +14,7 @@ import {
14
14
  */
15
15
 
16
16
  export { KyselyFactory } from './KyselyFactory';
17
+ export type { ExtractSeedAttrs, FactorySeed } from './Factory';
17
18
  export { PostgresKyselyMigrator } from './PostgresKyselyMigrator';
18
19
  export { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';
19
20
  export { IsolationLevel } from './VitestTransactionIsolator';
@@ -22,8 +23,26 @@ export type {
22
23
  ExtendedDatabaseFixtures,
23
24
  FixtureCreators,
24
25
  TestWithExtendedFixtures,
26
+ TransactionWrapperOptions,
25
27
  } from './VitestTransactionIsolator';
26
28
 
29
+ /**
30
+ * Kysely-specific options for transaction wrapping.
31
+ */
32
+ export interface KyselyTransactionOptions<
33
+ Database,
34
+ Extended extends Record<string, unknown> = {},
35
+ > {
36
+ /** Function that creates or returns a Kysely database instance */
37
+ connection: DatabaseConnection<Kysely<Database>>;
38
+ /** Optional setup function to run within the transaction before each test */
39
+ setup?: (trx: Transaction<Database>) => Promise<void>;
40
+ /** Transaction isolation level (defaults to REPEATABLE_READ) */
41
+ isolationLevel?: IsolationLevel;
42
+ /** Additional fixtures that depend on the transaction */
43
+ fixtures?: FixtureCreators<Transaction<Database>, Extended>;
44
+ }
45
+
27
46
  // Re-export faker and FakerFactory for type portability in declaration files
28
47
  export { faker, type FakerFactory } from './faker';
29
48
 
@@ -33,10 +52,9 @@ export { faker, type FakerFactory } from './faker';
33
52
  * This ensures tests don't affect each other's data and run faster than truncating tables.
34
53
  *
35
54
  * @template Database - The database schema type
55
+ * @template Extended - Additional fixtures to provide
36
56
  * @param api - The Vitest test API (usually `test` from vitest)
37
- * @param db - The Kysely database instance
38
- * @param setup - Optional setup function to run before each test in the transaction
39
- * @param level - Transaction isolation level (defaults to REPEATABLE_READ)
57
+ * @param options - Configuration options for transaction wrapping
40
58
  * @returns A wrapped test API that provides transaction isolation
41
59
  *
42
60
  * @example
@@ -46,7 +64,9 @@ export { faker, type FakerFactory } from './faker';
46
64
  * import { db } from './database';
47
65
  *
48
66
  * // Create isolated test with automatic rollback
49
- * const isolatedTest = wrapVitestKyselyTransaction(test, db);
67
+ * const isolatedTest = wrapVitestKyselyTransaction(test, {
68
+ * connection: db,
69
+ * });
50
70
  *
51
71
  * // Use in tests - each test gets its own transaction
52
72
  * isolatedTest('should create user', async ({ trx }) => {
@@ -57,41 +77,29 @@ export { faker, type FakerFactory } from './faker';
57
77
  * .executeTakeFirst();
58
78
  *
59
79
  * expect(user).toBeDefined();
60
- * // User is automatically rolled back after test
61
80
  * });
62
81
  *
63
- * // With setup function for common test data
64
- * const testWithSetup = wrapVitestKyselyTransaction(
65
- * test,
66
- * db,
67
- * async (trx) => {
68
- * // Create common test data
69
- * await trx.insertInto('settings')
70
- * .values({ key: 'test_mode', value: 'true' })
71
- * .execute();
72
- * }
73
- * );
74
- *
75
- * testWithSetup('should have test settings', async ({ trx }) => {
76
- * const setting = await trx
77
- * .selectFrom('settings')
78
- * .where('key', '=', 'test_mode')
79
- * .selectAll()
80
- * .executeTakeFirst();
82
+ * // With fixtures for factories
83
+ * const it = wrapVitestKyselyTransaction<DB, { factory: Factory }>(test, {
84
+ * connection: db,
85
+ * fixtures: {
86
+ * factory: (trx) => new Factory(trx),
87
+ * },
88
+ * });
81
89
  *
82
- * expect(setting?.value).toBe('true');
90
+ * it('should create user with factory', async ({ trx, factory }) => {
91
+ * const user = await factory.insert('user', { name: 'Test' });
92
+ * expect(user.id).toBeDefined();
83
93
  * });
84
94
  * ```
85
95
  */
86
- export function wrapVitestKyselyTransaction<Database>(
87
- api: TestAPI,
88
- connection: DatabaseConnection<Kysely<Database>>,
89
- setup?: (trx: Transaction<Database>) => Promise<void>,
90
- level: IsolationLevel = IsolationLevel.REPEATABLE_READ,
91
- ) {
96
+ export function wrapVitestKyselyTransaction<
97
+ Database,
98
+ Extended extends Record<string, unknown> = {},
99
+ >(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>) {
92
100
  const wrapper = new VitestKyselyTransactionIsolator<Database>(api);
93
101
 
94
- return wrapper.wrapVitestWithTransaction(connection, setup, level);
102
+ return wrapper.wrapVitestWithTransaction(options);
95
103
  }
96
104
 
97
105
  /**
@@ -118,7 +126,10 @@ export function wrapVitestKyselyTransaction<Database>(
118
126
  * };
119
127
  *
120
128
  * // Create base wrapped test
121
- * const baseTest = wrapVitestKyselyTransaction<DB>(test, db, createTestTables);
129
+ * const baseTest = wrapVitestKyselyTransaction<DB>(test, {
130
+ * connection: db,
131
+ * setup: createTestTables,
132
+ * });
122
133
  *
123
134
  * // Extend with fixtures - each fixture receives the transaction
124
135
  * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(
package/src/objection.ts CHANGED
@@ -4,7 +4,7 @@ import { VitestObjectionTransactionIsolator } from './VitestObjectionTransaction
4
4
  import {
5
5
  type DatabaseConnection,
6
6
  type FixtureCreators,
7
- IsolationLevel,
7
+ type IsolationLevel,
8
8
  extendWithFixtures as baseExtendWithFixtures,
9
9
  } from './VitestTransactionIsolator';
10
10
 
@@ -15,6 +15,7 @@ import {
15
15
  */
16
16
 
17
17
  export { ObjectionFactory } from './ObjectionFactory';
18
+ export type { ExtractSeedAttrs, FactorySeed } from './Factory';
18
19
  export { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';
19
20
  export { IsolationLevel } from './VitestTransactionIsolator';
20
21
  export { PostgresObjectionMigrator } from './PostgresObjectionMigrator';
@@ -23,8 +24,25 @@ export type {
23
24
  ExtendedDatabaseFixtures,
24
25
  FixtureCreators,
25
26
  TestWithExtendedFixtures,
27
+ TransactionWrapperOptions,
26
28
  } from './VitestTransactionIsolator';
27
29
 
30
+ /**
31
+ * Objection.js-specific options for transaction wrapping.
32
+ */
33
+ export interface ObjectionTransactionOptions<
34
+ Extended extends Record<string, unknown> = {},
35
+ > {
36
+ /** Function that creates or returns a Knex database connection */
37
+ connection: DatabaseConnection<Knex>;
38
+ /** Optional setup function to run within the transaction before each test */
39
+ setup?: (trx: Knex.Transaction) => Promise<void>;
40
+ /** Transaction isolation level (defaults to REPEATABLE_READ) */
41
+ isolationLevel?: IsolationLevel;
42
+ /** Additional fixtures that depend on the transaction */
43
+ fixtures?: FixtureCreators<Knex.Transaction, Extended>;
44
+ }
45
+
28
46
  // Re-export faker and FakerFactory for type portability in declaration files
29
47
  export { faker, type FakerFactory } from './faker';
30
48
 
@@ -33,10 +51,9 @@ export { faker, type FakerFactory } from './faker';
33
51
  * Each test runs in an isolated database transaction that is rolled back after completion.
34
52
  * This ensures tests don't affect each other's data and run faster than truncating tables.
35
53
  *
54
+ * @template Extended - Additional fixtures to provide
36
55
  * @param api - The Vitest test API (usually `test` from vitest)
37
- * @param conn - The Knex database connection instance
38
- * @param setup - Optional setup function to run before each test in the transaction
39
- * @param level - Transaction isolation level (defaults to REPEATABLE_READ)
56
+ * @param options - Configuration options for transaction wrapping
40
57
  * @returns A wrapped test API that provides transaction isolation
41
58
  *
42
59
  * @example
@@ -44,10 +61,12 @@ export { faker, type FakerFactory } from './faker';
44
61
  * import { test } from 'vitest';
45
62
  * import { wrapVitestObjectionTransaction } from '@geekmidas/testkit/objection';
46
63
  * import { knex } from './database';
47
- * import { User, Post } from './models';
64
+ * import { User } from './models';
48
65
  *
49
66
  * // Create isolated test with automatic rollback
50
- * const isolatedTest = wrapVitestObjectionTransaction(test, knex);
67
+ * const isolatedTest = wrapVitestObjectionTransaction(test, {
68
+ * connection: knex,
69
+ * });
51
70
  *
52
71
  * // Use in tests - each test gets its own transaction
53
72
  * isolatedTest('should create user', async ({ trx }) => {
@@ -55,59 +74,28 @@ export { faker, type FakerFactory } from './faker';
55
74
  * .insert({ name: 'Test User', email: 'test@example.com' });
56
75
  *
57
76
  * expect(user).toBeDefined();
58
- * // User is automatically rolled back after test
59
77
  * });
60
78
  *
61
- * // With setup function for common test data
62
- * const testWithSetup = wrapVitestObjectionTransaction(
63
- * test,
64
- * knex,
65
- * async (trx) => {
66
- * // Create common test data
67
- * await knex('settings')
68
- * .transacting(trx)
69
- * .insert({ key: 'test_mode', value: 'true' });
70
- * }
71
- * );
72
- *
73
- * testWithSetup('should have test settings', async ({ trx }) => {
74
- * const setting = await knex('settings')
75
- * .transacting(trx)
76
- * .where('key', 'test_mode')
77
- * .first();
78
- *
79
- * expect(setting?.value).toBe('true');
79
+ * // With fixtures for factories
80
+ * const it = wrapVitestObjectionTransaction<{ factory: Factory }>(test, {
81
+ * connection: knex,
82
+ * fixtures: {
83
+ * factory: (trx) => new Factory(trx),
84
+ * },
80
85
  * });
81
86
  *
82
- * // Example with factory and transaction
83
- * const isolatedTest = wrapVitestObjectionTransaction(test, knex);
84
- * const factory = new ObjectionFactory(builders, seeds, knex);
85
- *
86
- * isolatedTest('creates related data', async ({ trx }) => {
87
- * // Factory can use the transaction
88
- * const user = await User.query(trx).insert({ name: 'Author' });
89
- * const posts = await Post.query(trx).insert([
90
- * { title: 'Post 1', userId: user.id },
91
- * { title: 'Post 2', userId: user.id }
92
- * ]);
93
- *
94
- * const userWithPosts = await User.query(trx)
95
- * .findById(user.id)
96
- * .withGraphFetched('posts');
97
- *
98
- * expect(userWithPosts.posts).toHaveLength(2);
87
+ * it('should create user with factory', async ({ trx, factory }) => {
88
+ * const user = await factory.insert('user', { name: 'Test' });
89
+ * expect(user.id).toBeDefined();
99
90
  * });
100
91
  * ```
101
92
  */
102
- export function wrapVitestObjectionTransaction(
103
- api: TestAPI,
104
- conn: DatabaseConnection<Knex>,
105
- setup?: (trx: Knex.Transaction) => Promise<void>,
106
- level: IsolationLevel = IsolationLevel.REPEATABLE_READ,
107
- ) {
93
+ export function wrapVitestObjectionTransaction<
94
+ Extended extends Record<string, unknown> = {},
95
+ >(api: TestAPI, options: ObjectionTransactionOptions<Extended>) {
108
96
  const wrapper = new VitestObjectionTransactionIsolator(api);
109
97
 
110
- return wrapper.wrapVitestWithTransaction(conn, setup, level);
98
+ return wrapper.wrapVitestWithTransaction(options);
111
99
  }
112
100
 
113
101
  /**
@@ -134,7 +122,10 @@ export function wrapVitestObjectionTransaction(
134
122
  * };
135
123
  *
136
124
  * // Create base wrapped test
137
- * const baseTest = wrapVitestObjectionTransaction(test, knex, createTestTables);
125
+ * const baseTest = wrapVitestObjectionTransaction(test, {
126
+ * connection: knex,
127
+ * setup: createTestTables,
128
+ * });
138
129
  *
139
130
  * // Extend with fixtures - each fixture receives the transaction
140
131
  * const it = extendWithFixtures<{ factory: ObjectionFactory<typeof builders, {}> }>(
@@ -1 +0,0 @@
1
- {"version":3,"file":"Factory-WMhTNZ9S.cjs","names":["seedFn: Seed"],"sources":["../src/Factory.ts"],"sourcesContent":["import type { FakerFactory } from './faker';\n\n/**\n * Abstract base class for database factories used in testing.\n * Provides a standardized interface for creating test data using builder and seed patterns.\n *\n * @template Builders - Record of builder functions for creating individual entities\n * @template Seeds - Record of seed functions for creating complex test scenarios\n *\n * @example\n * ```typescript\n * // Define builders for creating individual records\n * const builders = {\n * user: (attrs) => ({ name: 'Test User', email: 'test@example.com', ...attrs }),\n * post: (attrs) => ({ title: 'Test Post', content: 'Content', ...attrs })\n * };\n *\n * // Define seeds for complex scenarios\n * const seeds = {\n * userWithPosts: async (attrs, factory) => {\n * const user = await factory.insert('user', attrs);\n * await factory.insertMany(3, 'post', { userId: user.id });\n * return user;\n * }\n * };\n * ```\n */\nexport abstract class Factory<\n Builders extends Record<string, any>,\n Seeds extends Record<string, any>,\n> {\n /**\n * Creates a typed seed function with proper type inference.\n * This is a utility method to help with TypeScript type checking when defining seeds.\n *\n * @template Seed - The seed function type\n * @param seedFn - The seed function to wrap\n * @returns The same seed function with proper typing\n *\n * @example\n * ```typescript\n * const userWithPostsSeed = Factory.createSeed(async (attrs, factory, db) => {\n * const user = await factory.insert('user', attrs);\n * return user;\n * });\n * ```\n */\n static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n return seedFn;\n }\n /**\n * Inserts an object into the database using a builder function.\n *\n * @param builderName - The name of the builder to use\n * @param attrs - The attributes to insert\n */\n abstract insert<K extends keyof Builders>(\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>>;\n\n /**\n * Inserts multiple objects into the database\n *\n * @param count - Number of objects to insert\n * @param builderName - The name of the builder to use\n * @param attrs - The attributes to insert\n */\n abstract insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?:\n | Parameters<Builders[K]>[0]\n | ((\n idx: number,\n faker: FakerFactory,\n ) => Promise<Parameters<Builders[K]>[0]>),\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n\n /**\n * Seeds the database using a seed function.\n *\n * @param seedName - The name of the seed to use\n * @returns The result of the seed function\n * @param attrs - The attributes to pass to the seed function\n */\n abstract seed<K extends keyof Seeds>(\n seedName: K,\n attrs?: Parameters<Seeds[K]>[0],\n ): ReturnType<Seeds[K]>;\n}\n\n/**\n * Type definition for a factory builder function that can work with different database types.\n * Builders are responsible for creating individual database records with default values and relationships.\n *\n * @template Attrs - The attributes/input type for the builder\n * @template Factory - The factory instance type\n * @template Result - The type of object returned by the builder\n * @template DB - The database connection type (Kysely, Knex, etc.)\n *\n * @param attrs - Partial attributes to override defaults\n * @param factory - The factory instance for creating related records\n * @param db - The database connection\n * @returns The created record or a promise resolving to it\n *\n * @example\n * ```typescript\n * const userBuilder: MixedFactoryBuilder<UserAttrs, Factory, User, Kysely<DB>> =\n * async (attrs, factory, db) => {\n * return {\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * };\n * };\n * ```\n */\nexport type MixedFactoryBuilder<\n Attrs = any,\n Factory = any,\n Result = any,\n DB = any,\n> = (attrs: Attrs, factory: Factory, db: DB) => Result | Promise<Result>;\n\n/**\n * Type definition for a factory seed function used to create complex test scenarios.\n * Seeds typically create multiple related records to set up a complete test environment.\n *\n * @template Attrs - The attributes/input type for the seed\n * @template Factory - The factory instance type\n * @template Result - The type of object returned by the seed\n * @template DB - The database connection type (Kysely, Knex, etc.)\n *\n * @param attrs - Configuration attributes for the seed\n * @param factory - The factory instance for creating records\n * @param db - The database connection\n * @returns A promise resolving to the seed result\n *\n * @example\n * ```typescript\n * const userWithPostsSeed: FactorySeed<{ postCount?: number }, Factory, User, DB> =\n * async (attrs, factory, db) => {\n * const user = await factory.insert('user', attrs);\n * const postCount = attrs.postCount || 3;\n *\n * for (let i = 0; i < postCount; i++) {\n * await factory.insert('post', { userId: user.id });\n * }\n *\n * return user;\n * };\n * ```\n */\nexport type FactorySeed<Attrs = any, Factory = any, Result = any, DB = any> = (\n attrs: Attrs,\n factory: Factory,\n db: DB,\n) => Promise<Result>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,IAAsB,UAAtB,MAGE;;;;;;;;;;;;;;;;;CAiBA,OAAO,WAAqCA,QAAoB;AAC9D,SAAO;CACR;AAyCF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Factory-z2m01hMj.mjs","names":["seedFn: Seed"],"sources":["../src/Factory.ts"],"sourcesContent":["import type { FakerFactory } from './faker';\n\n/**\n * Abstract base class for database factories used in testing.\n * Provides a standardized interface for creating test data using builder and seed patterns.\n *\n * @template Builders - Record of builder functions for creating individual entities\n * @template Seeds - Record of seed functions for creating complex test scenarios\n *\n * @example\n * ```typescript\n * // Define builders for creating individual records\n * const builders = {\n * user: (attrs) => ({ name: 'Test User', email: 'test@example.com', ...attrs }),\n * post: (attrs) => ({ title: 'Test Post', content: 'Content', ...attrs })\n * };\n *\n * // Define seeds for complex scenarios\n * const seeds = {\n * userWithPosts: async (attrs, factory) => {\n * const user = await factory.insert('user', attrs);\n * await factory.insertMany(3, 'post', { userId: user.id });\n * return user;\n * }\n * };\n * ```\n */\nexport abstract class Factory<\n Builders extends Record<string, any>,\n Seeds extends Record<string, any>,\n> {\n /**\n * Creates a typed seed function with proper type inference.\n * This is a utility method to help with TypeScript type checking when defining seeds.\n *\n * @template Seed - The seed function type\n * @param seedFn - The seed function to wrap\n * @returns The same seed function with proper typing\n *\n * @example\n * ```typescript\n * const userWithPostsSeed = Factory.createSeed(async (attrs, factory, db) => {\n * const user = await factory.insert('user', attrs);\n * return user;\n * });\n * ```\n */\n static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n return seedFn;\n }\n /**\n * Inserts an object into the database using a builder function.\n *\n * @param builderName - The name of the builder to use\n * @param attrs - The attributes to insert\n */\n abstract insert<K extends keyof Builders>(\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>>;\n\n /**\n * Inserts multiple objects into the database\n *\n * @param count - Number of objects to insert\n * @param builderName - The name of the builder to use\n * @param attrs - The attributes to insert\n */\n abstract insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?:\n | Parameters<Builders[K]>[0]\n | ((\n idx: number,\n faker: FakerFactory,\n ) => Promise<Parameters<Builders[K]>[0]>),\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n\n /**\n * Seeds the database using a seed function.\n *\n * @param seedName - The name of the seed to use\n * @returns The result of the seed function\n * @param attrs - The attributes to pass to the seed function\n */\n abstract seed<K extends keyof Seeds>(\n seedName: K,\n attrs?: Parameters<Seeds[K]>[0],\n ): ReturnType<Seeds[K]>;\n}\n\n/**\n * Type definition for a factory builder function that can work with different database types.\n * Builders are responsible for creating individual database records with default values and relationships.\n *\n * @template Attrs - The attributes/input type for the builder\n * @template Factory - The factory instance type\n * @template Result - The type of object returned by the builder\n * @template DB - The database connection type (Kysely, Knex, etc.)\n *\n * @param attrs - Partial attributes to override defaults\n * @param factory - The factory instance for creating related records\n * @param db - The database connection\n * @returns The created record or a promise resolving to it\n *\n * @example\n * ```typescript\n * const userBuilder: MixedFactoryBuilder<UserAttrs, Factory, User, Kysely<DB>> =\n * async (attrs, factory, db) => {\n * return {\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * };\n * };\n * ```\n */\nexport type MixedFactoryBuilder<\n Attrs = any,\n Factory = any,\n Result = any,\n DB = any,\n> = (attrs: Attrs, factory: Factory, db: DB) => Result | Promise<Result>;\n\n/**\n * Type definition for a factory seed function used to create complex test scenarios.\n * Seeds typically create multiple related records to set up a complete test environment.\n *\n * @template Attrs - The attributes/input type for the seed\n * @template Factory - The factory instance type\n * @template Result - The type of object returned by the seed\n * @template DB - The database connection type (Kysely, Knex, etc.)\n *\n * @param attrs - Configuration attributes for the seed\n * @param factory - The factory instance for creating records\n * @param db - The database connection\n * @returns A promise resolving to the seed result\n *\n * @example\n * ```typescript\n * const userWithPostsSeed: FactorySeed<{ postCount?: number }, Factory, User, DB> =\n * async (attrs, factory, db) => {\n * const user = await factory.insert('user', attrs);\n * const postCount = attrs.postCount || 3;\n *\n * for (let i = 0; i < postCount; i++) {\n * await factory.insert('post', { userId: user.id });\n * }\n *\n * return user;\n * };\n * ```\n */\nexport type FactorySeed<Attrs = any, Factory = any, Result = any, DB = any> = (\n attrs: Attrs,\n factory: Factory,\n db: DB,\n) => Promise<Result>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,IAAsB,UAAtB,MAGE;;;;;;;;;;;;;;;;;CAiBA,OAAO,WAAqCA,QAAoB;AAC9D,SAAO;CACR;AAyCF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"KyselyFactory-CXY5gJk2.mjs","names":["seedFn: Seed","builders: Builders","seeds: Seeds","db: Kysely<DB> | ControlledTransaction<DB, []>","table: TableName","defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Kysely<DB>;\n faker: FakerFactory;\n }) =>\n | Partial<Insertable<DB[TableName]>>\n | Promise<Partial<Insertable<DB[TableName]>>>","autoInsert?: boolean","attrs: Attrs","factory: Factory","db: Kysely<DB>","fakerInstance: FakerFactory","data: Partial<Insertable<DB[TableName]>>","builderName: K","attrs?: Parameters<Builders[K]>[0]","count: number","attrs?: any","promises: Promise<any>[]","seedName: K","attrs?: Parameters<Seeds[K]>[0]"],"sources":["../src/KyselyFactory.ts"],"sourcesContent":["import type {\n ControlledTransaction,\n Insertable,\n Kysely,\n Selectable,\n} from 'kysely';\nimport { Factory, type FactorySeed } from './Factory.ts';\nimport { type FakerFactory, faker } from './faker.ts';\n\n/**\n * Factory implementation for Kysely ORM, providing test data creation utilities.\n * Extends the base Factory class with Kysely-specific database operations.\n *\n * @template DB - The database schema type\n * @template Builders - Record of builder functions for creating entities\n * @template Seeds - Record of seed functions for complex test scenarios\n *\n * @example\n * ```typescript\n * // Define your database schema\n * interface Database {\n * users: UsersTable;\n * posts: PostsTable;\n * }\n *\n * // Create builders\n * const builders = {\n * user: KyselyFactory.createBuilder<Database, 'users'>('users', ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * })),\n * post: KyselyFactory.createBuilder<Database, 'posts'>('posts', ({ attrs }) => ({\n * title: 'Test Post',\n * content: 'Test content',\n * ...attrs\n * }))\n * };\n *\n * // Create factory instance\n * const factory = new KyselyFactory(builders, seeds, db);\n *\n * // Use in tests\n * const user = await factory.insert('user', { name: 'John Doe' });\n * ```\n */\nexport class KyselyFactory<\n DB,\n Builders extends Record<string, any>,\n Seeds extends Record<string, any>,\n> extends Factory<Builders, Seeds> {\n /**\n * Creates a typed seed function with proper type inference.\n * Inherits from the base Factory class implementation.\n *\n * @template Seed - The seed function type\n * @param seedFn - The seed function to wrap\n * @returns The same seed function with proper typing\n */\n static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n return Factory.createSeed(seedFn);\n }\n\n /**\n * Creates a new KyselyFactory instance.\n *\n * @param builders - Record of builder functions for creating individual entities\n * @param seeds - Record of seed functions for creating complex test scenarios\n * @param db - Kysely database instance or controlled transaction\n */\n constructor(\n private builders: Builders,\n private seeds: Seeds,\n private db: Kysely<DB> | ControlledTransaction<DB, []>,\n ) {\n super();\n }\n\n /**\n * Creates a typed builder function for a specific database table.\n * This is a utility method that helps create builders with proper type inference for Kysely.\n *\n * @template DB - The database schema type\n * @template TableName - The name of the table (must be a key of DB)\n * @template Attrs - The attributes type for the builder (defaults to Partial<Insertable>)\n * @template Factory - The factory instance type\n * @template Result - The result type (defaults to Selectable of the table)\n *\n * @param table - The name of the database table\n * @param defaults - Optional function to provide default values (receives destructured context)\n * @param autoInsert - Whether to automatically insert the record (default: true)\n * @returns A builder function that creates and optionally inserts records\n *\n * @example\n * ```typescript\n * // Create a simple builder with defaults - destructure only what you need\n * const userBuilder = KyselyFactory.createBuilder<DB, 'users'>('users',\n * ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * createdAt: new Date(),\n * ...attrs\n * })\n * );\n *\n * // Only need faker? Just destructure that\n * const leaveTypeBuilder = KyselyFactory.createBuilder<DB, 'leaveTypes'>('leaveTypes',\n * ({ faker }) => ({\n * name: faker.helpers.arrayElement(['Annual', 'Sick', 'Maternity']),\n * code: faker.string.alpha({ length: 3, casing: 'upper' }),\n * })\n * );\n *\n * // Create a builder that doesn't auto-insert (useful for nested inserts)\n * const addressBuilder = KyselyFactory.createBuilder<DB, 'addresses'>('addresses',\n * ({ attrs }) => ({\n * street: '123 Main St',\n * city: 'Anytown',\n * ...attrs\n * }),\n * false // Don't auto-insert\n * );\n * ```\n */\n static createBuilder<\n DB,\n TableName extends keyof DB & string,\n Attrs extends Partial<Insertable<DB[TableName]>> = Partial<\n Insertable<DB[TableName]>\n >,\n Factory = any,\n Result = Selectable<DB[TableName]>,\n >(\n table: TableName,\n defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Kysely<DB>;\n faker: FakerFactory;\n }) =>\n | Partial<Insertable<DB[TableName]>>\n | Promise<Partial<Insertable<DB[TableName]>>>,\n autoInsert?: boolean,\n ): (\n attrs: Attrs,\n factory: Factory,\n db: Kysely<DB>,\n faker: FakerFactory,\n ) => Promise<Result> {\n return async (\n attrs: Attrs,\n factory: Factory,\n db: Kysely<DB>,\n fakerInstance: FakerFactory,\n ) => {\n // Start with attributes\n let data: Partial<Insertable<DB[TableName]>> = { ...attrs };\n\n // Apply defaults\n if (defaults) {\n const defaultValues = await defaults({\n attrs,\n factory,\n db,\n faker: fakerInstance,\n });\n data = { ...defaultValues, ...data };\n }\n\n // Handle insertion based on autoInsert flag\n if (autoInsert !== false) {\n // Auto insert is enabled by default\n const result = await db\n .insertInto(table)\n .values(data as Insertable<DB[TableName]>)\n .returningAll()\n .executeTakeFirst();\n\n if (!result) {\n throw new Error(`Failed to insert into ${table}`);\n }\n\n return result as Result;\n } else {\n // Return object for factory to handle insertion\n return { table, data } as any;\n }\n };\n }\n\n /**\n * Inserts a single record into the database using the specified builder.\n * The builder function is responsible for generating the record data with defaults\n * and the factory handles the actual database insertion.\n *\n * @template K - The builder name (must be a key of Builders)\n * @param builderName - The name of the builder to use\n * @param attrs - Optional attributes to override builder defaults\n * @returns A promise resolving to the inserted record\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert with defaults\n * const user = await factory.insert('user');\n *\n * // Insert with overrides\n * const adminUser = await factory.insert('user', {\n * email: 'admin@example.com',\n * role: 'admin'\n * });\n *\n * // Use the inserted record\n * const post = await factory.insert('post', {\n * userId: user.id,\n * title: 'My First Post'\n * });\n * ```\n */\n async insert<K extends keyof Builders>(\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Factory \"${\n builderName as string\n }\" does not exist. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const result = await this.builders[builderName](\n attrs || {},\n this,\n this.db,\n faker,\n );\n\n // For Kysely, we expect the builder to return an object with table and data properties\n // or to handle the insertion itself and return the inserted record\n if (\n result &&\n typeof result === 'object' &&\n 'table' in result &&\n 'data' in result\n ) {\n // If the builder returns {table: string, data: object}, we insert it\n const inserted = await this.db\n .insertInto(result.table)\n .values(result.data)\n .returningAll()\n .executeTakeFirst();\n\n return inserted as any;\n }\n\n // Otherwise, assume the builder handled the insertion itself\n return result;\n }\n\n /**\n * Inserts multiple records into the database using the specified builder.\n * Supports both static attributes and dynamic attribute generation via a function.\n *\n * @template K - The builder name (must be a key of Builders)\n * @param count - The number of records to insert\n * @param builderName - The name of the builder to use\n * @param attrs - Static attributes or a function that generates attributes for each record\n * @returns A promise resolving to an array of inserted records\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert multiple with same attributes\n * const users = await factory.insertMany(5, 'user', { role: 'member' });\n *\n * // Insert multiple with dynamic attributes\n * const posts = await factory.insertMany(10, 'post', (idx, faker) => ({\n * title: `Post ${idx + 1}`,\n * content: faker.lorem.paragraph(),\n * publishedAt: faker.date.past()\n * }));\n *\n * // Create users with sequential emails\n * const admins = await factory.insertMany(3, 'user', (idx) => ({\n * email: `admin${idx + 1}@example.com`,\n * role: 'admin'\n * }));\n * ```\n */\n // Method overloads for better type inference\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs: (\n idx: number,\n faker: FakerFactory,\n ) => Parameters<Builders[K]>[0] | Promise<Parameters<Builders[K]>[0]>,\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: any,\n ): Promise<Awaited<ReturnType<Builders[K]>>[]> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Builder \"${\n builderName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const promises: Promise<any>[] = [];\n\n for (let i = 0; i < count; i++) {\n const newAttrs =\n typeof attrs === 'function' ? await attrs(i, faker) : attrs;\n promises.push(this.insert(builderName, newAttrs));\n }\n\n return Promise.all(promises);\n }\n\n /**\n * Executes a seed function to create complex test scenarios with multiple related records.\n * Seeds are useful for setting up complete test environments with realistic data relationships.\n *\n * @template K - The seed name (must be a key of Seeds)\n * @param seedName - The name of the seed to execute\n * @param attrs - Optional configuration attributes for the seed\n * @returns The result of the seed function (typically the primary record created)\n * @throws Error if the specified seed doesn't exist\n *\n * @example\n * ```typescript\n * // Execute a simple seed\n * const user = await factory.seed('userWithProfile');\n *\n * // Execute a seed with configuration\n * const author = await factory.seed('authorWithBooks', {\n * bookCount: 5,\n * includeReviews: true\n * });\n *\n * // Use seed result in tests\n * const company = await factory.seed('companyWithDepartments', {\n * departmentCount: 3,\n * employeesPerDepartment: 10\n * });\n * expect(company.departments).toHaveLength(3);\n * ```\n */\n seed<K extends keyof Seeds>(\n seedName: K,\n attrs?: Parameters<Seeds[K]>[0],\n ): ReturnType<Seeds[K]> {\n if (!(seedName in this.seeds)) {\n throw new Error(\n `Seed \"${\n seedName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n return this.seeds[seedName](attrs || {}, this, this.db);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,gBAAb,cAIU,QAAyB;;;;;;;;;CASjC,OAAO,WAAqCA,QAAoB;AAC9D,SAAO,QAAQ,WAAW,OAAO;CAClC;;;;;;;;CASD,YACUC,UACAC,OACAC,IACR;AACA,SAAO;EAJC;EACA;EACA;CAGT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDD,OAAO,cASLC,OACAC,UAQAC,YAMmB;AACnB,SAAO,OACLC,OACAC,SACAC,IACAC,kBACG;GAEH,IAAIC,OAA2C,EAAE,GAAG,MAAO;AAG3D,OAAI,UAAU;IACZ,MAAM,gBAAgB,MAAM,SAAS;KACnC;KACA;KACA;KACA,OAAO;IACR,EAAC;AACF,WAAO;KAAE,GAAG;KAAe,GAAG;IAAM;GACrC;AAGD,OAAI,eAAe,OAAO;IAExB,MAAM,SAAS,MAAM,GAClB,WAAW,MAAM,CACjB,OAAO,KAAkC,CACzC,cAAc,CACd,kBAAkB;AAErB,SAAK,OACH,OAAM,IAAI,OAAO,wBAAwB,MAAM;AAGjD,WAAO;GACR,MAEC,QAAO;IAAE;IAAO;GAAM;EAEzB;CACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BD,MAAM,OACJC,aACAC,OAC2C;AAC3C,QAAM,eAAe,KAAK,UACxB,OAAM,IAAI,OACP,WACC,YACD;EAIL,MAAM,SAAS,MAAM,KAAK,SAAS,aACjC,SAAS,CAAE,GACX,MACA,KAAK,IACL,MACD;AAID,MACE,iBACO,WAAW,YAClB,WAAW,UACX,UAAU,QACV;GAEA,MAAM,WAAW,MAAM,KAAK,GACzB,WAAW,OAAO,MAAM,CACxB,OAAO,OAAO,KAAK,CACnB,cAAc,CACd,kBAAkB;AAErB,UAAO;EACR;AAGD,SAAO;CACR;CA8CD,MAAM,WACJC,OACAF,aACAG,OAC6C;AAC7C,QAAM,eAAe,KAAK,UACxB,OAAM,IAAI,OACP,WACC,YACD;EAIL,MAAMC,WAA2B,CAAE;AAEnC,OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;GAC9B,MAAM,kBACG,UAAU,aAAa,MAAM,MAAM,GAAG,MAAM,GAAG;AACxD,YAAS,KAAK,KAAK,OAAO,aAAa,SAAS,CAAC;EAClD;AAED,SAAO,QAAQ,IAAI,SAAS;CAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BD,KACEC,UACAC,OACsB;AACtB,QAAM,YAAY,KAAK,OACrB,OAAM,IAAI,OACP,QACC,SACD;AAIL,SAAO,KAAK,MAAM,UAAU,SAAS,CAAE,GAAE,MAAM,KAAK,GAAG;CACxD;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"KyselyFactory-DaaCykWP.cjs","names":["Factory","seedFn: Seed","builders: Builders","seeds: Seeds","db: Kysely<DB> | ControlledTransaction<DB, []>","table: TableName","defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Kysely<DB>;\n faker: FakerFactory;\n }) =>\n | Partial<Insertable<DB[TableName]>>\n | Promise<Partial<Insertable<DB[TableName]>>>","autoInsert?: boolean","attrs: Attrs","factory: Factory","db: Kysely<DB>","fakerInstance: FakerFactory","data: Partial<Insertable<DB[TableName]>>","builderName: K","attrs?: Parameters<Builders[K]>[0]","faker","count: number","attrs?: any","promises: Promise<any>[]","seedName: K","attrs?: Parameters<Seeds[K]>[0]"],"sources":["../src/KyselyFactory.ts"],"sourcesContent":["import type {\n ControlledTransaction,\n Insertable,\n Kysely,\n Selectable,\n} from 'kysely';\nimport { Factory, type FactorySeed } from './Factory.ts';\nimport { type FakerFactory, faker } from './faker.ts';\n\n/**\n * Factory implementation for Kysely ORM, providing test data creation utilities.\n * Extends the base Factory class with Kysely-specific database operations.\n *\n * @template DB - The database schema type\n * @template Builders - Record of builder functions for creating entities\n * @template Seeds - Record of seed functions for complex test scenarios\n *\n * @example\n * ```typescript\n * // Define your database schema\n * interface Database {\n * users: UsersTable;\n * posts: PostsTable;\n * }\n *\n * // Create builders\n * const builders = {\n * user: KyselyFactory.createBuilder<Database, 'users'>('users', ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * })),\n * post: KyselyFactory.createBuilder<Database, 'posts'>('posts', ({ attrs }) => ({\n * title: 'Test Post',\n * content: 'Test content',\n * ...attrs\n * }))\n * };\n *\n * // Create factory instance\n * const factory = new KyselyFactory(builders, seeds, db);\n *\n * // Use in tests\n * const user = await factory.insert('user', { name: 'John Doe' });\n * ```\n */\nexport class KyselyFactory<\n DB,\n Builders extends Record<string, any>,\n Seeds extends Record<string, any>,\n> extends Factory<Builders, Seeds> {\n /**\n * Creates a typed seed function with proper type inference.\n * Inherits from the base Factory class implementation.\n *\n * @template Seed - The seed function type\n * @param seedFn - The seed function to wrap\n * @returns The same seed function with proper typing\n */\n static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n return Factory.createSeed(seedFn);\n }\n\n /**\n * Creates a new KyselyFactory instance.\n *\n * @param builders - Record of builder functions for creating individual entities\n * @param seeds - Record of seed functions for creating complex test scenarios\n * @param db - Kysely database instance or controlled transaction\n */\n constructor(\n private builders: Builders,\n private seeds: Seeds,\n private db: Kysely<DB> | ControlledTransaction<DB, []>,\n ) {\n super();\n }\n\n /**\n * Creates a typed builder function for a specific database table.\n * This is a utility method that helps create builders with proper type inference for Kysely.\n *\n * @template DB - The database schema type\n * @template TableName - The name of the table (must be a key of DB)\n * @template Attrs - The attributes type for the builder (defaults to Partial<Insertable>)\n * @template Factory - The factory instance type\n * @template Result - The result type (defaults to Selectable of the table)\n *\n * @param table - The name of the database table\n * @param defaults - Optional function to provide default values (receives destructured context)\n * @param autoInsert - Whether to automatically insert the record (default: true)\n * @returns A builder function that creates and optionally inserts records\n *\n * @example\n * ```typescript\n * // Create a simple builder with defaults - destructure only what you need\n * const userBuilder = KyselyFactory.createBuilder<DB, 'users'>('users',\n * ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * createdAt: new Date(),\n * ...attrs\n * })\n * );\n *\n * // Only need faker? Just destructure that\n * const leaveTypeBuilder = KyselyFactory.createBuilder<DB, 'leaveTypes'>('leaveTypes',\n * ({ faker }) => ({\n * name: faker.helpers.arrayElement(['Annual', 'Sick', 'Maternity']),\n * code: faker.string.alpha({ length: 3, casing: 'upper' }),\n * })\n * );\n *\n * // Create a builder that doesn't auto-insert (useful for nested inserts)\n * const addressBuilder = KyselyFactory.createBuilder<DB, 'addresses'>('addresses',\n * ({ attrs }) => ({\n * street: '123 Main St',\n * city: 'Anytown',\n * ...attrs\n * }),\n * false // Don't auto-insert\n * );\n * ```\n */\n static createBuilder<\n DB,\n TableName extends keyof DB & string,\n Attrs extends Partial<Insertable<DB[TableName]>> = Partial<\n Insertable<DB[TableName]>\n >,\n Factory = any,\n Result = Selectable<DB[TableName]>,\n >(\n table: TableName,\n defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Kysely<DB>;\n faker: FakerFactory;\n }) =>\n | Partial<Insertable<DB[TableName]>>\n | Promise<Partial<Insertable<DB[TableName]>>>,\n autoInsert?: boolean,\n ): (\n attrs: Attrs,\n factory: Factory,\n db: Kysely<DB>,\n faker: FakerFactory,\n ) => Promise<Result> {\n return async (\n attrs: Attrs,\n factory: Factory,\n db: Kysely<DB>,\n fakerInstance: FakerFactory,\n ) => {\n // Start with attributes\n let data: Partial<Insertable<DB[TableName]>> = { ...attrs };\n\n // Apply defaults\n if (defaults) {\n const defaultValues = await defaults({\n attrs,\n factory,\n db,\n faker: fakerInstance,\n });\n data = { ...defaultValues, ...data };\n }\n\n // Handle insertion based on autoInsert flag\n if (autoInsert !== false) {\n // Auto insert is enabled by default\n const result = await db\n .insertInto(table)\n .values(data as Insertable<DB[TableName]>)\n .returningAll()\n .executeTakeFirst();\n\n if (!result) {\n throw new Error(`Failed to insert into ${table}`);\n }\n\n return result as Result;\n } else {\n // Return object for factory to handle insertion\n return { table, data } as any;\n }\n };\n }\n\n /**\n * Inserts a single record into the database using the specified builder.\n * The builder function is responsible for generating the record data with defaults\n * and the factory handles the actual database insertion.\n *\n * @template K - The builder name (must be a key of Builders)\n * @param builderName - The name of the builder to use\n * @param attrs - Optional attributes to override builder defaults\n * @returns A promise resolving to the inserted record\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert with defaults\n * const user = await factory.insert('user');\n *\n * // Insert with overrides\n * const adminUser = await factory.insert('user', {\n * email: 'admin@example.com',\n * role: 'admin'\n * });\n *\n * // Use the inserted record\n * const post = await factory.insert('post', {\n * userId: user.id,\n * title: 'My First Post'\n * });\n * ```\n */\n async insert<K extends keyof Builders>(\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Factory \"${\n builderName as string\n }\" does not exist. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const result = await this.builders[builderName](\n attrs || {},\n this,\n this.db,\n faker,\n );\n\n // For Kysely, we expect the builder to return an object with table and data properties\n // or to handle the insertion itself and return the inserted record\n if (\n result &&\n typeof result === 'object' &&\n 'table' in result &&\n 'data' in result\n ) {\n // If the builder returns {table: string, data: object}, we insert it\n const inserted = await this.db\n .insertInto(result.table)\n .values(result.data)\n .returningAll()\n .executeTakeFirst();\n\n return inserted as any;\n }\n\n // Otherwise, assume the builder handled the insertion itself\n return result;\n }\n\n /**\n * Inserts multiple records into the database using the specified builder.\n * Supports both static attributes and dynamic attribute generation via a function.\n *\n * @template K - The builder name (must be a key of Builders)\n * @param count - The number of records to insert\n * @param builderName - The name of the builder to use\n * @param attrs - Static attributes or a function that generates attributes for each record\n * @returns A promise resolving to an array of inserted records\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert multiple with same attributes\n * const users = await factory.insertMany(5, 'user', { role: 'member' });\n *\n * // Insert multiple with dynamic attributes\n * const posts = await factory.insertMany(10, 'post', (idx, faker) => ({\n * title: `Post ${idx + 1}`,\n * content: faker.lorem.paragraph(),\n * publishedAt: faker.date.past()\n * }));\n *\n * // Create users with sequential emails\n * const admins = await factory.insertMany(3, 'user', (idx) => ({\n * email: `admin${idx + 1}@example.com`,\n * role: 'admin'\n * }));\n * ```\n */\n // Method overloads for better type inference\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs: (\n idx: number,\n faker: FakerFactory,\n ) => Parameters<Builders[K]>[0] | Promise<Parameters<Builders[K]>[0]>,\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: any,\n ): Promise<Awaited<ReturnType<Builders[K]>>[]> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Builder \"${\n builderName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const promises: Promise<any>[] = [];\n\n for (let i = 0; i < count; i++) {\n const newAttrs =\n typeof attrs === 'function' ? await attrs(i, faker) : attrs;\n promises.push(this.insert(builderName, newAttrs));\n }\n\n return Promise.all(promises);\n }\n\n /**\n * Executes a seed function to create complex test scenarios with multiple related records.\n * Seeds are useful for setting up complete test environments with realistic data relationships.\n *\n * @template K - The seed name (must be a key of Seeds)\n * @param seedName - The name of the seed to execute\n * @param attrs - Optional configuration attributes for the seed\n * @returns The result of the seed function (typically the primary record created)\n * @throws Error if the specified seed doesn't exist\n *\n * @example\n * ```typescript\n * // Execute a simple seed\n * const user = await factory.seed('userWithProfile');\n *\n * // Execute a seed with configuration\n * const author = await factory.seed('authorWithBooks', {\n * bookCount: 5,\n * includeReviews: true\n * });\n *\n * // Use seed result in tests\n * const company = await factory.seed('companyWithDepartments', {\n * departmentCount: 3,\n * employeesPerDepartment: 10\n * });\n * expect(company.departments).toHaveLength(3);\n * ```\n */\n seed<K extends keyof Seeds>(\n seedName: K,\n attrs?: Parameters<Seeds[K]>[0],\n ): ReturnType<Seeds[K]> {\n if (!(seedName in this.seeds)) {\n throw new Error(\n `Seed \"${\n seedName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n return this.seeds[seedName](attrs || {}, this, this.db);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,gBAAb,cAIUA,wBAAyB;;;;;;;;;CASjC,OAAO,WAAqCC,QAAoB;AAC9D,SAAO,wBAAQ,WAAW,OAAO;CAClC;;;;;;;;CASD,YACUC,UACAC,OACAC,IACR;AACA,SAAO;EAJC;EACA;EACA;CAGT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDD,OAAO,cASLC,OACAC,UAQAC,YAMmB;AACnB,SAAO,OACLC,OACAC,SACAC,IACAC,kBACG;GAEH,IAAIC,OAA2C,EAAE,GAAG,MAAO;AAG3D,OAAI,UAAU;IACZ,MAAM,gBAAgB,MAAM,SAAS;KACnC;KACA;KACA;KACA,OAAO;IACR,EAAC;AACF,WAAO;KAAE,GAAG;KAAe,GAAG;IAAM;GACrC;AAGD,OAAI,eAAe,OAAO;IAExB,MAAM,SAAS,MAAM,GAClB,WAAW,MAAM,CACjB,OAAO,KAAkC,CACzC,cAAc,CACd,kBAAkB;AAErB,SAAK,OACH,OAAM,IAAI,OAAO,wBAAwB,MAAM;AAGjD,WAAO;GACR,MAEC,QAAO;IAAE;IAAO;GAAM;EAEzB;CACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BD,MAAM,OACJC,aACAC,OAC2C;AAC3C,QAAM,eAAe,KAAK,UACxB,OAAM,IAAI,OACP,WACC,YACD;EAIL,MAAM,SAAS,MAAM,KAAK,SAAS,aACjC,SAAS,CAAE,GACX,MACA,KAAK,IACLC,oBACD;AAID,MACE,iBACO,WAAW,YAClB,WAAW,UACX,UAAU,QACV;GAEA,MAAM,WAAW,MAAM,KAAK,GACzB,WAAW,OAAO,MAAM,CACxB,OAAO,OAAO,KAAK,CACnB,cAAc,CACd,kBAAkB;AAErB,UAAO;EACR;AAGD,SAAO;CACR;CA8CD,MAAM,WACJC,OACAH,aACAI,OAC6C;AAC7C,QAAM,eAAe,KAAK,UACxB,OAAM,IAAI,OACP,WACC,YACD;EAIL,MAAMC,WAA2B,CAAE;AAEnC,OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;GAC9B,MAAM,kBACG,UAAU,aAAa,MAAM,MAAM,GAAGH,oBAAM,GAAG;AACxD,YAAS,KAAK,KAAK,OAAO,aAAa,SAAS,CAAC;EAClD;AAED,SAAO,QAAQ,IAAI,SAAS;CAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BD,KACEI,UACAC,OACsB;AACtB,QAAM,YAAY,KAAK,OACrB,OAAM,IAAI,OACP,QACC,SACD;AAIL,SAAO,KAAK,MAAM,UAAU,SAAS,CAAE,GAAE,MAAM,KAAK,GAAG;CACxD;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"ObjectionFactory-Eb04AOnv.cjs","names":["Factory","seedFn: Seed","ModelClass: TModel","defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Knex;\n faker: FakerFactory;\n }) =>\n | Partial<InstanceType<TModel>>\n | Promise<Partial<InstanceType<TModel>>>","autoInsert?: boolean","attrs: Attrs","factory: Factory","db: Knex","fakerInstance: FakerFactory","data: Partial<InstanceType<TModel>>","builders: Builders","seeds: Seeds","builderName: K","attrs?: Parameters<Builders[K]>[0]","faker","count: number","attrs?: any","records: any[]","record: any","seedName: K","attrs?: Parameters<Seeds[K]>[0]"],"sources":["../src/ObjectionFactory.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { Model } from 'objection';\nimport { Factory, type FactorySeed } from './Factory.ts';\nimport { type FakerFactory, faker } from './faker.ts';\n\n/**\n * Factory implementation for Objection.js ORM, providing test data creation utilities.\n * Extends the base Factory class with Objection.js-specific database operations.\n *\n * @template Builders - Record of builder functions for creating entities\n * @template Seeds - Record of seed functions for complex test scenarios\n *\n * @example\n * ```typescript\n * // Define your models with Objection.js\n * class User extends Model {\n * static tableName = 'users';\n * }\n *\n * // Create builders\n * const builders = {\n * user: ObjectionFactory.createBuilder(User, ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * })),\n * post: ObjectionFactory.createBuilder(Post, ({ attrs }) => ({\n * title: 'Test Post',\n * content: 'Test content',\n * ...attrs\n * })),\n * };\n *\n * // Create factory instance\n * const factory = new ObjectionFactory(builders, seeds, knex);\n *\n * // Use in tests\n * const user = await factory.insert('user', { name: 'John Doe' });\n * ```\n */\nexport class ObjectionFactory<\n Builders extends Record<string, any>,\n Seeds extends Record<string, any>,\n> extends Factory<Builders, Seeds> {\n /**\n * Creates a typed seed function with proper type inference.\n * Inherits from the base Factory class implementation.\n *\n * @template Seed - The seed function type\n * @param seedFn - The seed function to wrap\n * @returns The same seed function with proper typing\n */\n static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n return Factory.createSeed(seedFn);\n }\n\n /**\n * Creates a typed builder function for Objection.js models.\n * This is a utility method that helps create builders with proper type inference.\n *\n * @template TModel - The Objection.js Model class type\n * @template Attrs - The attributes type for the builder (defaults to Partial of model)\n * @template Factory - The factory instance type\n * @template Result - The result type (defaults to the model instance)\n *\n * @param ModelClass - The Objection.js Model class\n * @param defaults - Optional function to provide default values (receives destructured context)\n * @param autoInsert - Whether to automatically insert the record (default: true)\n * @returns A builder function that creates and optionally inserts records\n *\n * @example\n * ```typescript\n * // Create a simple builder with defaults - destructure only what you need\n * const userBuilder = ObjectionFactory.createBuilder(User,\n * ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * createdAt: new Date(),\n * ...attrs\n * })\n * );\n *\n * // Only need faker? Just destructure that\n * const leaveTypeBuilder = ObjectionFactory.createBuilder(LeaveType,\n * ({ faker }) => ({\n * name: faker.helpers.arrayElement(['Annual', 'Sick', 'Maternity']),\n * code: faker.string.alpha({ length: 3, casing: 'upper' }),\n * })\n * );\n *\n * // Create a builder that doesn't auto-insert (useful for nested inserts)\n * const addressBuilder = ObjectionFactory.createBuilder(Address,\n * ({ attrs }) => ({\n * street: '123 Main St',\n * city: 'Anytown',\n * ...attrs\n * }),\n * false // Don't auto-insert\n * );\n *\n * // Use with relations\n * const postBuilder = ObjectionFactory.createBuilder(Post,\n * async ({ attrs, factory, faker }) => ({\n * title: faker.lorem.sentence(),\n * content: faker.lorem.paragraphs(),\n * authorId: attrs.authorId || (await factory.insert('user')).id,\n * ...attrs\n * })\n * );\n * ```\n */\n static createBuilder<\n TModel extends typeof Model,\n Attrs extends Partial<InstanceType<TModel>> = Partial<InstanceType<TModel>>,\n Factory = any,\n Result = InstanceType<TModel>,\n >(\n ModelClass: TModel,\n defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Knex;\n faker: FakerFactory;\n }) =>\n | Partial<InstanceType<TModel>>\n | Promise<Partial<InstanceType<TModel>>>,\n autoInsert?: boolean,\n ): (\n attrs: Attrs,\n factory: Factory,\n db: Knex,\n faker: FakerFactory,\n ) => Promise<Result> {\n return async (\n attrs: Attrs,\n factory: Factory,\n db: Knex,\n fakerInstance: FakerFactory,\n ) => {\n // Start with attributes\n let data: Partial<InstanceType<TModel>> = { ...attrs };\n\n // Apply defaults\n if (defaults) {\n const defaultValues = await defaults({\n attrs,\n factory,\n db,\n faker: fakerInstance,\n });\n data = { ...defaultValues, ...data };\n }\n\n // Create model instance\n const model = ModelClass.fromJson(data) as InstanceType<TModel>;\n\n // Handle insertion based on autoInsert flag\n if (autoInsert !== false) {\n // Auto insert is enabled by default\n // Extract only defined values for insertion\n const insertData = Object.entries(model).reduce((acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n }, {} as any);\n\n // Use static query method to insert data directly\n // @ts-ignore\n const result = await ModelClass.query(db).insert(insertData);\n return result as Result;\n } else {\n // Return model for factory to handle insertion\n return model as Result;\n }\n };\n }\n\n /**\n * Creates a new ObjectionFactory instance.\n *\n * @param builders - Record of builder functions for creating individual entities\n * @param seeds - Record of seed functions for creating complex test scenarios\n * @param db - Knex database connection instance\n */\n constructor(\n private builders: Builders,\n private seeds: Seeds,\n private db: Knex,\n ) {\n super();\n }\n\n /**\n * Inserts a single record into the database using the specified builder.\n * Uses Objection.js's insertGraph method to handle nested relations.\n *\n * @template K - The builder name (must be a key of Builders)\n * @param builderName - The name of the builder to use\n * @param attrs - Optional attributes to override builder defaults\n * @returns A promise resolving to the inserted record with all relations\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert with defaults\n * const user = await factory.insert('user');\n *\n * // Insert with overrides\n * const adminUser = await factory.insert('user', {\n * email: 'admin@example.com',\n * role: 'admin'\n * });\n *\n * // Insert with nested relations\n * const userWithProfile = await factory.insert('user', {\n * name: 'John Doe',\n * profile: {\n * bio: 'Software Developer',\n * avatar: 'avatar.jpg'\n * }\n * });\n * ```\n */\n async insert<K extends keyof Builders>(\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Factory \"${\n builderName as string\n }\" does not exist. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const result = await this.builders[builderName](\n attrs || {},\n this,\n this.db,\n faker,\n );\n\n // If the builder returns a model instance, insert it\n if (result && typeof result.$query === 'function') {\n // Extract data from model, excluding undefined values and id\n const insertData = Object.entries(result).reduce((acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n }, {} as any);\n\n // Use the model's constructor to get the query builder\n return await result.constructor.query(this.db).insert(insertData);\n }\n\n // Otherwise, assume the builder handled insertion itself\n return result;\n }\n /**\n * Inserts multiple records into the database using the specified builder.\n * Supports both static attributes and dynamic attribute generation via a function.\n *\n * @param count - The number of records to insert\n * @param builderName - The name of the builder to use\n * @param attrs - Static attributes or a function that generates attributes for each record\n * @returns A promise resolving to an array of inserted records\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert multiple with same attributes\n * const users = await factory.insertMany(5, 'user', { role: 'member' });\n *\n * // Insert multiple with dynamic attributes\n * const posts = await factory.insertMany(10, 'post', (idx) => ({\n * title: `Post ${idx + 1}`,\n * content: `Content for post ${idx + 1}`,\n * publishedAt: new Date()\n * }));\n *\n * // Create users with sequential emails\n * const admins = await factory.insertMany(3, 'user', (idx) => ({\n * email: `admin${idx + 1}@example.com`,\n * role: 'admin'\n * }));\n * ```\n */\n // Method overloads for better type inference\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs: (idx: number, faker: FakerFactory) => Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: any,\n ): Promise<Awaited<ReturnType<Builders[K]>>[]> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Builder \"${\n builderName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const records: any[] = [];\n for (let i = 0; i < count; i++) {\n const newAttrs =\n typeof attrs === 'function' ? await (attrs as any)(i, faker) : attrs;\n\n records.push(\n this.builders[builderName](newAttrs, this, this.db, faker).then(\n (record: any) => {\n // If the builder returns a model instance, insert it\n if (record && typeof record.$query === 'function') {\n // Extract data from model, excluding undefined values and id\n const insertData = Object.entries(record).reduce(\n (acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n },\n {} as any,\n );\n\n // Use the model's constructor to get the query builder\n return record.constructor.query(this.db).insert(insertData);\n }\n // Otherwise, assume the builder handled insertion itself\n return record;\n },\n ),\n );\n }\n\n return Promise.all(records);\n }\n /**\n * Executes a seed function to create complex test scenarios with multiple related records.\n * Seeds are useful for setting up complete test environments with realistic data relationships.\n *\n * @template K - The seed name (must be a key of Seeds)\n * @param seedName - The name of the seed to execute\n * @param attrs - Optional configuration attributes for the seed\n * @returns The result of the seed function (typically the primary record created)\n * @throws Error if the specified seed doesn't exist\n *\n * @example\n * ```typescript\n * // Execute a simple seed\n * const user = await factory.seed('userWithProfile');\n *\n * // Execute a seed with configuration\n * const author = await factory.seed('authorWithBooks', {\n * bookCount: 5,\n * includeReviews: true\n * });\n *\n * // Use seed result in tests with Objection.js relations\n * const company = await factory.seed('companyWithDepartments', {\n * departmentCount: 3,\n * employeesPerDepartment: 10\n * });\n *\n * // Access eager loaded relations\n * const companyWithRelations = await Company.query()\n * .findById(company.id)\n * .withGraphFetched('[departments.employees]');\n * ```\n */\n seed<K extends keyof Seeds>(\n seedName: K,\n attrs?: Parameters<Seeds[K]>[0],\n ): ReturnType<Seeds[K]> {\n if (!(seedName in this.seeds)) {\n throw new Error(\n `Seed \"${\n seedName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n return this.seeds[seedName](attrs || {}, this, this.db);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,mBAAb,cAGUA,wBAAyB;;;;;;;;;CASjC,OAAO,WAAqCC,QAAoB;AAC9D,SAAO,wBAAQ,WAAW,OAAO;CAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DD,OAAO,cAMLC,YACAC,UAQAC,YAMmB;AACnB,SAAO,OACLC,OACAC,SACAC,IACAC,kBACG;GAEH,IAAIC,OAAsC,EAAE,GAAG,MAAO;AAGtD,OAAI,UAAU;IACZ,MAAM,gBAAgB,MAAM,SAAS;KACnC;KACA;KACA;KACA,OAAO;IACR,EAAC;AACF,WAAO;KAAE,GAAG;KAAe,GAAG;IAAM;GACrC;GAGD,MAAM,QAAQ,WAAW,SAAS,KAAK;AAGvC,OAAI,eAAe,OAAO;IAGxB,MAAM,aAAa,OAAO,QAAQ,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACrE,SAAI,oBAAuB,QAAQ,KACjC,KAAI,OAAO;AAEb,YAAO;IACR,GAAE,CAAE,EAAQ;IAIb,MAAM,SAAS,MAAM,WAAW,MAAM,GAAG,CAAC,OAAO,WAAW;AAC5D,WAAO;GACR,MAEC,QAAO;EAEV;CACF;;;;;;;;CASD,YACUC,UACAC,OACAJ,IACR;AACA,SAAO;EAJC;EACA;EACA;CAGT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCD,MAAM,OACJK,aACAC,OAC2C;AAC3C,QAAM,eAAe,KAAK,UACxB,OAAM,IAAI,OACP,WACC,YACD;EAIL,MAAM,SAAS,MAAM,KAAK,SAAS,aACjC,SAAS,CAAE,GACX,MACA,KAAK,IACLC,oBACD;AAGD,MAAI,iBAAiB,OAAO,WAAW,YAAY;GAEjD,MAAM,aAAa,OAAO,QAAQ,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACtE,QAAI,oBAAuB,QAAQ,KACjC,KAAI,OAAO;AAEb,WAAO;GACR,GAAE,CAAE,EAAQ;AAGb,UAAO,MAAM,OAAO,YAAY,MAAM,KAAK,GAAG,CAAC,OAAO,WAAW;EAClE;AAGD,SAAO;CACR;CAyCD,MAAM,WACJC,OACAH,aACAI,OAC6C;AAC7C,QAAM,eAAe,KAAK,UACxB,OAAM,IAAI,OACP,WACC,YACD;EAIL,MAAMC,UAAiB,CAAE;AACzB,OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;GAC9B,MAAM,kBACG,UAAU,aAAa,MAAM,AAAC,MAAc,GAAGH,oBAAM,GAAG;AAEjE,WAAQ,KACN,KAAK,SAAS,aAAa,UAAU,MAAM,KAAK,IAAIA,oBAAM,CAAC,KACzD,CAACI,WAAgB;AAEf,QAAI,iBAAiB,OAAO,WAAW,YAAY;KAEjD,MAAM,aAAa,OAAO,QAAQ,OAAO,CAAC,OACxC,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACrB,UAAI,oBAAuB,QAAQ,KACjC,KAAI,OAAO;AAEb,aAAO;KACR,GACD,CAAE,EACH;AAGD,YAAO,OAAO,YAAY,MAAM,KAAK,GAAG,CAAC,OAAO,WAAW;IAC5D;AAED,WAAO;GACR,EACF,CACF;EACF;AAED,SAAO,QAAQ,IAAI,QAAQ;CAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCD,KACEC,UACAC,OACsB;AACtB,QAAM,YAAY,KAAK,OACrB,OAAM,IAAI,OACP,QACC,SACD;AAIL,SAAO,KAAK,MAAM,UAAU,SAAS,CAAE,GAAE,MAAM,KAAK,GAAG;CACxD;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"ObjectionFactory-zf2fLKrL.mjs","names":["seedFn: Seed","ModelClass: TModel","defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Knex;\n faker: FakerFactory;\n }) =>\n | Partial<InstanceType<TModel>>\n | Promise<Partial<InstanceType<TModel>>>","autoInsert?: boolean","attrs: Attrs","factory: Factory","db: Knex","fakerInstance: FakerFactory","data: Partial<InstanceType<TModel>>","builders: Builders","seeds: Seeds","builderName: K","attrs?: Parameters<Builders[K]>[0]","count: number","attrs?: any","records: any[]","record: any","seedName: K","attrs?: Parameters<Seeds[K]>[0]"],"sources":["../src/ObjectionFactory.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { Model } from 'objection';\nimport { Factory, type FactorySeed } from './Factory.ts';\nimport { type FakerFactory, faker } from './faker.ts';\n\n/**\n * Factory implementation for Objection.js ORM, providing test data creation utilities.\n * Extends the base Factory class with Objection.js-specific database operations.\n *\n * @template Builders - Record of builder functions for creating entities\n * @template Seeds - Record of seed functions for complex test scenarios\n *\n * @example\n * ```typescript\n * // Define your models with Objection.js\n * class User extends Model {\n * static tableName = 'users';\n * }\n *\n * // Create builders\n * const builders = {\n * user: ObjectionFactory.createBuilder(User, ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * })),\n * post: ObjectionFactory.createBuilder(Post, ({ attrs }) => ({\n * title: 'Test Post',\n * content: 'Test content',\n * ...attrs\n * })),\n * };\n *\n * // Create factory instance\n * const factory = new ObjectionFactory(builders, seeds, knex);\n *\n * // Use in tests\n * const user = await factory.insert('user', { name: 'John Doe' });\n * ```\n */\nexport class ObjectionFactory<\n Builders extends Record<string, any>,\n Seeds extends Record<string, any>,\n> extends Factory<Builders, Seeds> {\n /**\n * Creates a typed seed function with proper type inference.\n * Inherits from the base Factory class implementation.\n *\n * @template Seed - The seed function type\n * @param seedFn - The seed function to wrap\n * @returns The same seed function with proper typing\n */\n static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n return Factory.createSeed(seedFn);\n }\n\n /**\n * Creates a typed builder function for Objection.js models.\n * This is a utility method that helps create builders with proper type inference.\n *\n * @template TModel - The Objection.js Model class type\n * @template Attrs - The attributes type for the builder (defaults to Partial of model)\n * @template Factory - The factory instance type\n * @template Result - The result type (defaults to the model instance)\n *\n * @param ModelClass - The Objection.js Model class\n * @param defaults - Optional function to provide default values (receives destructured context)\n * @param autoInsert - Whether to automatically insert the record (default: true)\n * @returns A builder function that creates and optionally inserts records\n *\n * @example\n * ```typescript\n * // Create a simple builder with defaults - destructure only what you need\n * const userBuilder = ObjectionFactory.createBuilder(User,\n * ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * createdAt: new Date(),\n * ...attrs\n * })\n * );\n *\n * // Only need faker? Just destructure that\n * const leaveTypeBuilder = ObjectionFactory.createBuilder(LeaveType,\n * ({ faker }) => ({\n * name: faker.helpers.arrayElement(['Annual', 'Sick', 'Maternity']),\n * code: faker.string.alpha({ length: 3, casing: 'upper' }),\n * })\n * );\n *\n * // Create a builder that doesn't auto-insert (useful for nested inserts)\n * const addressBuilder = ObjectionFactory.createBuilder(Address,\n * ({ attrs }) => ({\n * street: '123 Main St',\n * city: 'Anytown',\n * ...attrs\n * }),\n * false // Don't auto-insert\n * );\n *\n * // Use with relations\n * const postBuilder = ObjectionFactory.createBuilder(Post,\n * async ({ attrs, factory, faker }) => ({\n * title: faker.lorem.sentence(),\n * content: faker.lorem.paragraphs(),\n * authorId: attrs.authorId || (await factory.insert('user')).id,\n * ...attrs\n * })\n * );\n * ```\n */\n static createBuilder<\n TModel extends typeof Model,\n Attrs extends Partial<InstanceType<TModel>> = Partial<InstanceType<TModel>>,\n Factory = any,\n Result = InstanceType<TModel>,\n >(\n ModelClass: TModel,\n defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Knex;\n faker: FakerFactory;\n }) =>\n | Partial<InstanceType<TModel>>\n | Promise<Partial<InstanceType<TModel>>>,\n autoInsert?: boolean,\n ): (\n attrs: Attrs,\n factory: Factory,\n db: Knex,\n faker: FakerFactory,\n ) => Promise<Result> {\n return async (\n attrs: Attrs,\n factory: Factory,\n db: Knex,\n fakerInstance: FakerFactory,\n ) => {\n // Start with attributes\n let data: Partial<InstanceType<TModel>> = { ...attrs };\n\n // Apply defaults\n if (defaults) {\n const defaultValues = await defaults({\n attrs,\n factory,\n db,\n faker: fakerInstance,\n });\n data = { ...defaultValues, ...data };\n }\n\n // Create model instance\n const model = ModelClass.fromJson(data) as InstanceType<TModel>;\n\n // Handle insertion based on autoInsert flag\n if (autoInsert !== false) {\n // Auto insert is enabled by default\n // Extract only defined values for insertion\n const insertData = Object.entries(model).reduce((acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n }, {} as any);\n\n // Use static query method to insert data directly\n // @ts-ignore\n const result = await ModelClass.query(db).insert(insertData);\n return result as Result;\n } else {\n // Return model for factory to handle insertion\n return model as Result;\n }\n };\n }\n\n /**\n * Creates a new ObjectionFactory instance.\n *\n * @param builders - Record of builder functions for creating individual entities\n * @param seeds - Record of seed functions for creating complex test scenarios\n * @param db - Knex database connection instance\n */\n constructor(\n private builders: Builders,\n private seeds: Seeds,\n private db: Knex,\n ) {\n super();\n }\n\n /**\n * Inserts a single record into the database using the specified builder.\n * Uses Objection.js's insertGraph method to handle nested relations.\n *\n * @template K - The builder name (must be a key of Builders)\n * @param builderName - The name of the builder to use\n * @param attrs - Optional attributes to override builder defaults\n * @returns A promise resolving to the inserted record with all relations\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert with defaults\n * const user = await factory.insert('user');\n *\n * // Insert with overrides\n * const adminUser = await factory.insert('user', {\n * email: 'admin@example.com',\n * role: 'admin'\n * });\n *\n * // Insert with nested relations\n * const userWithProfile = await factory.insert('user', {\n * name: 'John Doe',\n * profile: {\n * bio: 'Software Developer',\n * avatar: 'avatar.jpg'\n * }\n * });\n * ```\n */\n async insert<K extends keyof Builders>(\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Factory \"${\n builderName as string\n }\" does not exist. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const result = await this.builders[builderName](\n attrs || {},\n this,\n this.db,\n faker,\n );\n\n // If the builder returns a model instance, insert it\n if (result && typeof result.$query === 'function') {\n // Extract data from model, excluding undefined values and id\n const insertData = Object.entries(result).reduce((acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n }, {} as any);\n\n // Use the model's constructor to get the query builder\n return await result.constructor.query(this.db).insert(insertData);\n }\n\n // Otherwise, assume the builder handled insertion itself\n return result;\n }\n /**\n * Inserts multiple records into the database using the specified builder.\n * Supports both static attributes and dynamic attribute generation via a function.\n *\n * @param count - The number of records to insert\n * @param builderName - The name of the builder to use\n * @param attrs - Static attributes or a function that generates attributes for each record\n * @returns A promise resolving to an array of inserted records\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert multiple with same attributes\n * const users = await factory.insertMany(5, 'user', { role: 'member' });\n *\n * // Insert multiple with dynamic attributes\n * const posts = await factory.insertMany(10, 'post', (idx) => ({\n * title: `Post ${idx + 1}`,\n * content: `Content for post ${idx + 1}`,\n * publishedAt: new Date()\n * }));\n *\n * // Create users with sequential emails\n * const admins = await factory.insertMany(3, 'user', (idx) => ({\n * email: `admin${idx + 1}@example.com`,\n * role: 'admin'\n * }));\n * ```\n */\n // Method overloads for better type inference\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs: (idx: number, faker: FakerFactory) => Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: any,\n ): Promise<Awaited<ReturnType<Builders[K]>>[]> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Builder \"${\n builderName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const records: any[] = [];\n for (let i = 0; i < count; i++) {\n const newAttrs =\n typeof attrs === 'function' ? await (attrs as any)(i, faker) : attrs;\n\n records.push(\n this.builders[builderName](newAttrs, this, this.db, faker).then(\n (record: any) => {\n // If the builder returns a model instance, insert it\n if (record && typeof record.$query === 'function') {\n // Extract data from model, excluding undefined values and id\n const insertData = Object.entries(record).reduce(\n (acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n },\n {} as any,\n );\n\n // Use the model's constructor to get the query builder\n return record.constructor.query(this.db).insert(insertData);\n }\n // Otherwise, assume the builder handled insertion itself\n return record;\n },\n ),\n );\n }\n\n return Promise.all(records);\n }\n /**\n * Executes a seed function to create complex test scenarios with multiple related records.\n * Seeds are useful for setting up complete test environments with realistic data relationships.\n *\n * @template K - The seed name (must be a key of Seeds)\n * @param seedName - The name of the seed to execute\n * @param attrs - Optional configuration attributes for the seed\n * @returns The result of the seed function (typically the primary record created)\n * @throws Error if the specified seed doesn't exist\n *\n * @example\n * ```typescript\n * // Execute a simple seed\n * const user = await factory.seed('userWithProfile');\n *\n * // Execute a seed with configuration\n * const author = await factory.seed('authorWithBooks', {\n * bookCount: 5,\n * includeReviews: true\n * });\n *\n * // Use seed result in tests with Objection.js relations\n * const company = await factory.seed('companyWithDepartments', {\n * departmentCount: 3,\n * employeesPerDepartment: 10\n * });\n *\n * // Access eager loaded relations\n * const companyWithRelations = await Company.query()\n * .findById(company.id)\n * .withGraphFetched('[departments.employees]');\n * ```\n */\n seed<K extends keyof Seeds>(\n seedName: K,\n attrs?: Parameters<Seeds[K]>[0],\n ): ReturnType<Seeds[K]> {\n if (!(seedName in this.seeds)) {\n throw new Error(\n `Seed \"${\n seedName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n return this.seeds[seedName](attrs || {}, this, this.db);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,mBAAb,cAGU,QAAyB;;;;;;;;;CASjC,OAAO,WAAqCA,QAAoB;AAC9D,SAAO,QAAQ,WAAW,OAAO;CAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DD,OAAO,cAMLC,YACAC,UAQAC,YAMmB;AACnB,SAAO,OACLC,OACAC,SACAC,IACAC,kBACG;GAEH,IAAIC,OAAsC,EAAE,GAAG,MAAO;AAGtD,OAAI,UAAU;IACZ,MAAM,gBAAgB,MAAM,SAAS;KACnC;KACA;KACA;KACA,OAAO;IACR,EAAC;AACF,WAAO;KAAE,GAAG;KAAe,GAAG;IAAM;GACrC;GAGD,MAAM,QAAQ,WAAW,SAAS,KAAK;AAGvC,OAAI,eAAe,OAAO;IAGxB,MAAM,aAAa,OAAO,QAAQ,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACrE,SAAI,oBAAuB,QAAQ,KACjC,KAAI,OAAO;AAEb,YAAO;IACR,GAAE,CAAE,EAAQ;IAIb,MAAM,SAAS,MAAM,WAAW,MAAM,GAAG,CAAC,OAAO,WAAW;AAC5D,WAAO;GACR,MAEC,QAAO;EAEV;CACF;;;;;;;;CASD,YACUC,UACAC,OACAJ,IACR;AACA,SAAO;EAJC;EACA;EACA;CAGT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCD,MAAM,OACJK,aACAC,OAC2C;AAC3C,QAAM,eAAe,KAAK,UACxB,OAAM,IAAI,OACP,WACC,YACD;EAIL,MAAM,SAAS,MAAM,KAAK,SAAS,aACjC,SAAS,CAAE,GACX,MACA,KAAK,IACL,MACD;AAGD,MAAI,iBAAiB,OAAO,WAAW,YAAY;GAEjD,MAAM,aAAa,OAAO,QAAQ,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACtE,QAAI,oBAAuB,QAAQ,KACjC,KAAI,OAAO;AAEb,WAAO;GACR,GAAE,CAAE,EAAQ;AAGb,UAAO,MAAM,OAAO,YAAY,MAAM,KAAK,GAAG,CAAC,OAAO,WAAW;EAClE;AAGD,SAAO;CACR;CAyCD,MAAM,WACJC,OACAF,aACAG,OAC6C;AAC7C,QAAM,eAAe,KAAK,UACxB,OAAM,IAAI,OACP,WACC,YACD;EAIL,MAAMC,UAAiB,CAAE;AACzB,OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;GAC9B,MAAM,kBACG,UAAU,aAAa,MAAM,AAAC,MAAc,GAAG,MAAM,GAAG;AAEjE,WAAQ,KACN,KAAK,SAAS,aAAa,UAAU,MAAM,KAAK,IAAI,MAAM,CAAC,KACzD,CAACC,WAAgB;AAEf,QAAI,iBAAiB,OAAO,WAAW,YAAY;KAEjD,MAAM,aAAa,OAAO,QAAQ,OAAO,CAAC,OACxC,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACrB,UAAI,oBAAuB,QAAQ,KACjC,KAAI,OAAO;AAEb,aAAO;KACR,GACD,CAAE,EACH;AAGD,YAAO,OAAO,YAAY,MAAM,KAAK,GAAG,CAAC,OAAO,WAAW;IAC5D;AAED,WAAO;GACR,EACF,CACF;EACF;AAED,SAAO,QAAQ,IAAI,QAAQ;CAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCD,KACEC,UACAC,OACsB;AACtB,QAAM,YAAY,KAAK,OACrB,OAAM,IAAI,OACP,QACC,SACD;AAIL,SAAO,KAAK,MAAM,UAAU,SAAS,CAAE,GAAE,MAAM,KAAK,GAAG;CACxD;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"VitestTransactionIsolator-BIaMs4c2.mjs","names":["api: TestAPI","createConnection: DatabaseConnection<TConn>","setup?: (trx: Transaction) => Promise<void>","level: IsolationLevel","use: (value: Transaction) => Promise<void>","testError: Error | undefined","wrappedTest: T","fixtures: FixtureCreators<Transaction, Extended>","fixtureDefinitions: Record<string, any>","use: (value: unknown) => Promise<void>"],"sources":["../src/VitestTransactionIsolator.ts"],"sourcesContent":["import type { TestAPI } from 'vitest';\n\n/**\n * Type definition for test fixtures that provide transaction access.\n * Used with Vitest's test.extend() API to inject transactions into tests.\n *\n * @template Transaction - The transaction type specific to the database driver\n * @template Extended - Additional context properties provided by the extend function\n */\nexport interface DatabaseFixtures<Transaction, Extended = object> {\n /**\n * The database transaction available to the test.\n * All database operations should use this transaction to ensure proper rollback.\n */\n trx: Transaction;\n}\n\n/**\n * Combined fixtures type that merges the base transaction fixture with extended context.\n */\nexport type ExtendedDatabaseFixtures<\n Transaction,\n Extended = object,\n> = DatabaseFixtures<Transaction> & Extended;\n\n/**\n * Function type for extending test context with additional properties.\n * Receives the transaction and returns additional context to be merged with { trx }.\n *\n * @template Transaction - The transaction type\n * @template Extended - The type of additional context to provide\n *\n * @example\n * ```typescript\n * const extendContext: ExtendContextFn<Transaction<DB>, { factory: KyselyFactory }> =\n * (trx) => ({ factory: new KyselyFactory(builders, seeds, trx) });\n * ```\n */\nexport type ExtendContextFn<Transaction, Extended> = (\n trx: Transaction,\n) => Extended | Promise<Extended>;\n\n/**\n * PostgreSQL transaction isolation levels.\n * Controls the visibility of concurrent transactions.\n *\n * @see https://www.postgresql.org/docs/current/transaction-iso.html\n */\nexport enum IsolationLevel {\n /**\n * Lowest isolation level. Allows dirty reads.\n * Not recommended for testing.\n */\n READ_UNCOMMITTED = 'READ UNCOMMITTED',\n /**\n * Default PostgreSQL isolation level.\n * Prevents dirty reads but allows non-repeatable reads.\n */\n READ_COMMITTED = 'READ COMMITTED',\n /**\n * Prevents dirty reads and non-repeatable reads.\n * Recommended for most test scenarios.\n */\n REPEATABLE_READ = 'REPEATABLE READ',\n /**\n * Highest isolation level. Prevents all phenomena.\n * May cause performance overhead in tests.\n */\n SERIALIZABLE = 'SERIALIZABLE',\n}\n\n/**\n * Abstract base class for implementing database transaction isolation in Vitest tests.\n * Provides automatic transaction rollback after each test to maintain test isolation.\n * Subclasses must implement the transact() method for their specific database driver.\n *\n * @template TConn - The database connection type\n * @template Transaction - The transaction type\n *\n * @example\n * ```typescript\n * // Implement for your database driver\n * class MyDatabaseIsolator extends VitestPostgresTransactionIsolator<MyDB, MyTx> {\n * async transact(conn: MyDB, level: IsolationLevel, fn: (tx: MyTx) => Promise<void>) {\n * await conn.transaction(level, fn);\n * }\n * }\n *\n * // Use in tests\n * const isolator = new MyDatabaseIsolator(test);\n * const isolatedTest = isolator.wrapVitestWithTransaction(db);\n *\n * isolatedTest('should create user', async ({ trx }) => {\n * await trx.insert('users', { name: 'Test' });\n * // Data is automatically rolled back after test\n * });\n * ```\n */\nexport abstract class VitestPostgresTransactionIsolator<TConn, Transaction> {\n /**\n * Abstract method to create a transaction with the specified isolation level.\n * Must be implemented by subclasses for specific database drivers.\n *\n * @param conn - The database connection\n * @param isolationLevel - The transaction isolation level\n * @param fn - The function to execute within the transaction\n * @returns Promise that resolves when the transaction completes\n */\n abstract transact(\n conn: TConn,\n isolationLevel: IsolationLevel,\n fn: (trx: Transaction) => Promise<void>,\n ): Promise<void>;\n\n abstract destroy(conn: TConn): Promise<void>;\n /**\n * Creates a new VitestPostgresTransactionIsolator instance.\n *\n * @param api - The Vitest test API (usually the `test` export from vitest)\n */\n constructor(private readonly api: TestAPI) {}\n\n /**\n * Creates a wrapped version of Vitest's test API that provides transaction isolation.\n * Each test will run within a database transaction that is automatically rolled back.\n *\n * @param conn - The database connection to use\n * @param setup - Optional setup function to run within the transaction before each test\n * @param level - The transaction isolation level (defaults to REPEATABLE_READ)\n * @returns A wrapped test API with transaction support\n *\n * @example\n * ```typescript\n * const isolatedTest = isolator.wrapVitestWithTransaction(db, async (trx) => {\n * // Optional setup: create common test data\n * await trx.insert('settings', { key: 'test', value: 'true' });\n * });\n *\n * isolatedTest('test with transaction', async ({ trx }) => {\n * const user = await trx.insert('users', { name: 'Test' });\n * expect(user).toBeDefined();\n * });\n * ```\n */\n wrapVitestWithTransaction(\n createConnection: DatabaseConnection<TConn>,\n setup?: (trx: Transaction) => Promise<void>,\n level: IsolationLevel = IsolationLevel.REPEATABLE_READ,\n ) {\n return this.api.extend<DatabaseFixtures<Transaction>>({\n // This fixture automatically provides a transaction to each test\n trx: async ({}, use: (value: Transaction) => Promise<void>) => {\n // Create a custom error class for rollback\n class TestRollback extends Error {\n constructor() {\n super('Test rollback');\n this.name = 'TestRollback';\n }\n }\n\n let testError: Error | undefined;\n const conn = await createConnection();\n try {\n await this.transact(conn, level, async (transaction) => {\n try {\n // Provide the transaction to the test\n await setup?.(transaction);\n await use(transaction);\n } catch (error) {\n // Capture any test errors\n testError = error as Error;\n }\n\n // Always throw to trigger rollback\n throw new TestRollback();\n });\n } catch (error) {\n // Only rethrow if it's not our rollback error\n if (!(error instanceof TestRollback)) {\n throw error;\n }\n\n // If the test had an error, throw it now\n if (testError) {\n throw testError;\n }\n } finally {\n await this.destroy(conn);\n }\n },\n });\n }\n}\n\nexport type DatabaseConnectionFn<Conn> = () => Conn | Promise<Conn>;\nexport type DatabaseConnection<Conn> = DatabaseConnectionFn<Conn>;\n\n/**\n * Type for fixture creator functions that depend on the transaction.\n * Each function receives the transaction and returns the fixture value.\n */\nexport type FixtureCreators<\n Transaction,\n Extended extends Record<string, unknown>,\n> = {\n [K in keyof Extended]: (\n trx: Transaction,\n ) => Extended[K] | Promise<Extended[K]>;\n};\n\n/**\n * The test API returned by extendWithFixtures.\n * Provides access to both the transaction (trx) and all extended fixtures.\n *\n * @template Transaction - The transaction type\n * @template Extended - The type of additional fixtures provided\n * @template BaseTest - The base wrapped test type\n */\nexport type TestWithExtendedFixtures<\n Transaction,\n Extended extends Record<string, unknown>,\n BaseTest extends ReturnType<TestAPI['extend']> = ReturnType<\n TestAPI['extend']\n >,\n> = BaseTest & {\n <C extends object>(\n name: string,\n fn: (\n context: DatabaseFixtures<Transaction> & Extended & C,\n ) => Promise<void>,\n ): void;\n <C extends object>(\n name: string,\n options: object,\n fn: (\n context: DatabaseFixtures<Transaction> & Extended & C,\n ) => Promise<void>,\n ): void;\n};\n\n/**\n * Extends a wrapped test API with additional fixtures that depend on the transaction.\n * This allows composing test context with factories, repositories, or other helpers.\n *\n * @template Transaction - The transaction type\n * @template Extended - The type of additional context to provide\n * @param wrappedTest - The base wrapped test from wrapVitestWithTransaction\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 { wrapVitestKyselyTransaction, extendWithFixtures } from '@geekmidas/testkit/kysely';\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestKyselyTransaction(test, db, createTestTables);\n *\n * // Extend with fixtures\n * const it = extendWithFixtures(baseTest, {\n * factory: (trx) => new KyselyFactory(builders, seeds, trx),\n * userRepo: (trx) => new UserRepository(trx),\n * });\n *\n * // Use in tests - trx and all fixtures are available\n * it('should create user with factory', async ({ trx, factory, userRepo }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user).toBeDefined();\n * });\n * ```\n */\nexport function extendWithFixtures<\n Transaction,\n Extended extends Record<string, unknown>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends ReturnType<TestAPI['extend']> = any,\n>(\n wrappedTest: T,\n fixtures: FixtureCreators<Transaction, Extended>,\n): TestWithExtendedFixtures<Transaction, Extended, T> {\n // Build fixture definitions for Vitest's extend API\n const fixtureDefinitions: Record<string, any> = {};\n\n for (const [key, creator] of Object.entries(fixtures)) {\n fixtureDefinitions[key] = async (\n { trx }: { trx: Transaction },\n use: (value: unknown) => Promise<void>,\n ) => {\n const value = await (creator as (trx: Transaction) => unknown)(trx);\n await use(value);\n };\n }\n\n return (wrappedTest as any).extend(fixtureDefinitions);\n}\n"],"mappings":";;;;;;;AAgDA,IAAY,4DAAL;;;;;AAKL;;;;;AAKA;;;;;AAKA;;;;;AAKA;;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BD,IAAsB,oCAAtB,MAA4E;;;;;;CAsB1E,YAA6BA,KAAc;EAAd;CAAgB;;;;;;;;;;;;;;;;;;;;;;;CAwB7C,0BACEC,kBACAC,OACAC,QAAwB,eAAe,iBACvC;AACA,SAAO,KAAK,IAAI,OAAsC,EAEpD,KAAK,OAAO,EAAE,EAAEC,QAA+C;GAE7D,MAAM,qBAAqB,MAAM;IAC/B,cAAc;AACZ,WAAM,gBAAgB;AACtB,UAAK,OAAO;IACb;GACF;GAED,IAAIC;GACJ,MAAM,OAAO,MAAM,kBAAkB;AACrC,OAAI;AACF,UAAM,KAAK,SAAS,MAAM,OAAO,OAAO,gBAAgB;AACtD,SAAI;AAEF,YAAM,QAAQ,YAAY;AAC1B,YAAM,IAAI,YAAY;KACvB,SAAQ,OAAO;AAEd,kBAAY;KACb;AAGD,WAAM,IAAI;IACX,EAAC;GACH,SAAQ,OAAO;AAEd,UAAM,iBAAiB,cACrB,OAAM;AAIR,QAAI,UACF,OAAM;GAET,UAAS;AACR,UAAM,KAAK,QAAQ,KAAK;GACzB;EACF,EACF,EAAC;CACH;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8ED,SAAgB,mBAMdC,aACAC,UACoD;CAEpD,MAAMC,qBAA0C,CAAE;AAElD,MAAK,MAAM,CAAC,KAAK,QAAQ,IAAI,OAAO,QAAQ,SAAS,CACnD,oBAAmB,OAAO,OACxB,EAAE,KAA2B,EAC7BC,QACG;EACH,MAAM,QAAQ,MAAM,AAAC,QAA0C,IAAI;AACnE,QAAM,IAAI,MAAM;CACjB;AAGH,QAAO,AAAC,YAAoB,OAAO,mBAAmB;AACvD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"VitestTransactionIsolator-BKIrj3Uy.cjs","names":["api: TestAPI","createConnection: DatabaseConnection<TConn>","setup?: (trx: Transaction) => Promise<void>","level: IsolationLevel","use: (value: Transaction) => Promise<void>","testError: Error | undefined","wrappedTest: T","fixtures: FixtureCreators<Transaction, Extended>","fixtureDefinitions: Record<string, any>","use: (value: unknown) => Promise<void>"],"sources":["../src/VitestTransactionIsolator.ts"],"sourcesContent":["import type { TestAPI } from 'vitest';\n\n/**\n * Type definition for test fixtures that provide transaction access.\n * Used with Vitest's test.extend() API to inject transactions into tests.\n *\n * @template Transaction - The transaction type specific to the database driver\n * @template Extended - Additional context properties provided by the extend function\n */\nexport interface DatabaseFixtures<Transaction, Extended = object> {\n /**\n * The database transaction available to the test.\n * All database operations should use this transaction to ensure proper rollback.\n */\n trx: Transaction;\n}\n\n/**\n * Combined fixtures type that merges the base transaction fixture with extended context.\n */\nexport type ExtendedDatabaseFixtures<\n Transaction,\n Extended = object,\n> = DatabaseFixtures<Transaction> & Extended;\n\n/**\n * Function type for extending test context with additional properties.\n * Receives the transaction and returns additional context to be merged with { trx }.\n *\n * @template Transaction - The transaction type\n * @template Extended - The type of additional context to provide\n *\n * @example\n * ```typescript\n * const extendContext: ExtendContextFn<Transaction<DB>, { factory: KyselyFactory }> =\n * (trx) => ({ factory: new KyselyFactory(builders, seeds, trx) });\n * ```\n */\nexport type ExtendContextFn<Transaction, Extended> = (\n trx: Transaction,\n) => Extended | Promise<Extended>;\n\n/**\n * PostgreSQL transaction isolation levels.\n * Controls the visibility of concurrent transactions.\n *\n * @see https://www.postgresql.org/docs/current/transaction-iso.html\n */\nexport enum IsolationLevel {\n /**\n * Lowest isolation level. Allows dirty reads.\n * Not recommended for testing.\n */\n READ_UNCOMMITTED = 'READ UNCOMMITTED',\n /**\n * Default PostgreSQL isolation level.\n * Prevents dirty reads but allows non-repeatable reads.\n */\n READ_COMMITTED = 'READ COMMITTED',\n /**\n * Prevents dirty reads and non-repeatable reads.\n * Recommended for most test scenarios.\n */\n REPEATABLE_READ = 'REPEATABLE READ',\n /**\n * Highest isolation level. Prevents all phenomena.\n * May cause performance overhead in tests.\n */\n SERIALIZABLE = 'SERIALIZABLE',\n}\n\n/**\n * Abstract base class for implementing database transaction isolation in Vitest tests.\n * Provides automatic transaction rollback after each test to maintain test isolation.\n * Subclasses must implement the transact() method for their specific database driver.\n *\n * @template TConn - The database connection type\n * @template Transaction - The transaction type\n *\n * @example\n * ```typescript\n * // Implement for your database driver\n * class MyDatabaseIsolator extends VitestPostgresTransactionIsolator<MyDB, MyTx> {\n * async transact(conn: MyDB, level: IsolationLevel, fn: (tx: MyTx) => Promise<void>) {\n * await conn.transaction(level, fn);\n * }\n * }\n *\n * // Use in tests\n * const isolator = new MyDatabaseIsolator(test);\n * const isolatedTest = isolator.wrapVitestWithTransaction(db);\n *\n * isolatedTest('should create user', async ({ trx }) => {\n * await trx.insert('users', { name: 'Test' });\n * // Data is automatically rolled back after test\n * });\n * ```\n */\nexport abstract class VitestPostgresTransactionIsolator<TConn, Transaction> {\n /**\n * Abstract method to create a transaction with the specified isolation level.\n * Must be implemented by subclasses for specific database drivers.\n *\n * @param conn - The database connection\n * @param isolationLevel - The transaction isolation level\n * @param fn - The function to execute within the transaction\n * @returns Promise that resolves when the transaction completes\n */\n abstract transact(\n conn: TConn,\n isolationLevel: IsolationLevel,\n fn: (trx: Transaction) => Promise<void>,\n ): Promise<void>;\n\n abstract destroy(conn: TConn): Promise<void>;\n /**\n * Creates a new VitestPostgresTransactionIsolator instance.\n *\n * @param api - The Vitest test API (usually the `test` export from vitest)\n */\n constructor(private readonly api: TestAPI) {}\n\n /**\n * Creates a wrapped version of Vitest's test API that provides transaction isolation.\n * Each test will run within a database transaction that is automatically rolled back.\n *\n * @param conn - The database connection to use\n * @param setup - Optional setup function to run within the transaction before each test\n * @param level - The transaction isolation level (defaults to REPEATABLE_READ)\n * @returns A wrapped test API with transaction support\n *\n * @example\n * ```typescript\n * const isolatedTest = isolator.wrapVitestWithTransaction(db, async (trx) => {\n * // Optional setup: create common test data\n * await trx.insert('settings', { key: 'test', value: 'true' });\n * });\n *\n * isolatedTest('test with transaction', async ({ trx }) => {\n * const user = await trx.insert('users', { name: 'Test' });\n * expect(user).toBeDefined();\n * });\n * ```\n */\n wrapVitestWithTransaction(\n createConnection: DatabaseConnection<TConn>,\n setup?: (trx: Transaction) => Promise<void>,\n level: IsolationLevel = IsolationLevel.REPEATABLE_READ,\n ) {\n return this.api.extend<DatabaseFixtures<Transaction>>({\n // This fixture automatically provides a transaction to each test\n trx: async ({}, use: (value: Transaction) => Promise<void>) => {\n // Create a custom error class for rollback\n class TestRollback extends Error {\n constructor() {\n super('Test rollback');\n this.name = 'TestRollback';\n }\n }\n\n let testError: Error | undefined;\n const conn = await createConnection();\n try {\n await this.transact(conn, level, async (transaction) => {\n try {\n // Provide the transaction to the test\n await setup?.(transaction);\n await use(transaction);\n } catch (error) {\n // Capture any test errors\n testError = error as Error;\n }\n\n // Always throw to trigger rollback\n throw new TestRollback();\n });\n } catch (error) {\n // Only rethrow if it's not our rollback error\n if (!(error instanceof TestRollback)) {\n throw error;\n }\n\n // If the test had an error, throw it now\n if (testError) {\n throw testError;\n }\n } finally {\n await this.destroy(conn);\n }\n },\n });\n }\n}\n\nexport type DatabaseConnectionFn<Conn> = () => Conn | Promise<Conn>;\nexport type DatabaseConnection<Conn> = DatabaseConnectionFn<Conn>;\n\n/**\n * Type for fixture creator functions that depend on the transaction.\n * Each function receives the transaction and returns the fixture value.\n */\nexport type FixtureCreators<\n Transaction,\n Extended extends Record<string, unknown>,\n> = {\n [K in keyof Extended]: (\n trx: Transaction,\n ) => Extended[K] | Promise<Extended[K]>;\n};\n\n/**\n * The test API returned by extendWithFixtures.\n * Provides access to both the transaction (trx) and all extended fixtures.\n *\n * @template Transaction - The transaction type\n * @template Extended - The type of additional fixtures provided\n * @template BaseTest - The base wrapped test type\n */\nexport type TestWithExtendedFixtures<\n Transaction,\n Extended extends Record<string, unknown>,\n BaseTest extends ReturnType<TestAPI['extend']> = ReturnType<\n TestAPI['extend']\n >,\n> = BaseTest & {\n <C extends object>(\n name: string,\n fn: (\n context: DatabaseFixtures<Transaction> & Extended & C,\n ) => Promise<void>,\n ): void;\n <C extends object>(\n name: string,\n options: object,\n fn: (\n context: DatabaseFixtures<Transaction> & Extended & C,\n ) => Promise<void>,\n ): void;\n};\n\n/**\n * Extends a wrapped test API with additional fixtures that depend on the transaction.\n * This allows composing test context with factories, repositories, or other helpers.\n *\n * @template Transaction - The transaction type\n * @template Extended - The type of additional context to provide\n * @param wrappedTest - The base wrapped test from wrapVitestWithTransaction\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 { wrapVitestKyselyTransaction, extendWithFixtures } from '@geekmidas/testkit/kysely';\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestKyselyTransaction(test, db, createTestTables);\n *\n * // Extend with fixtures\n * const it = extendWithFixtures(baseTest, {\n * factory: (trx) => new KyselyFactory(builders, seeds, trx),\n * userRepo: (trx) => new UserRepository(trx),\n * });\n *\n * // Use in tests - trx and all fixtures are available\n * it('should create user with factory', async ({ trx, factory, userRepo }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user).toBeDefined();\n * });\n * ```\n */\nexport function extendWithFixtures<\n Transaction,\n Extended extends Record<string, unknown>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends ReturnType<TestAPI['extend']> = any,\n>(\n wrappedTest: T,\n fixtures: FixtureCreators<Transaction, Extended>,\n): TestWithExtendedFixtures<Transaction, Extended, T> {\n // Build fixture definitions for Vitest's extend API\n const fixtureDefinitions: Record<string, any> = {};\n\n for (const [key, creator] of Object.entries(fixtures)) {\n fixtureDefinitions[key] = async (\n { trx }: { trx: Transaction },\n use: (value: unknown) => Promise<void>,\n ) => {\n const value = await (creator as (trx: Transaction) => unknown)(trx);\n await use(value);\n };\n }\n\n return (wrappedTest as any).extend(fixtureDefinitions);\n}\n"],"mappings":";;;;;;;;AAgDA,IAAY,4DAAL;;;;;AAKL;;;;;AAKA;;;;;AAKA;;;;;AAKA;;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BD,IAAsB,oCAAtB,MAA4E;;;;;;CAsB1E,YAA6BA,KAAc;EAAd;CAAgB;;;;;;;;;;;;;;;;;;;;;;;CAwB7C,0BACEC,kBACAC,OACAC,QAAwB,eAAe,iBACvC;AACA,SAAO,KAAK,IAAI,OAAsC,EAEpD,KAAK,OAAO,EAAE,EAAEC,QAA+C;GAE7D,MAAM,qBAAqB,MAAM;IAC/B,cAAc;AACZ,WAAM,gBAAgB;AACtB,UAAK,OAAO;IACb;GACF;GAED,IAAIC;GACJ,MAAM,OAAO,MAAM,kBAAkB;AACrC,OAAI;AACF,UAAM,KAAK,SAAS,MAAM,OAAO,OAAO,gBAAgB;AACtD,SAAI;AAEF,YAAM,QAAQ,YAAY;AAC1B,YAAM,IAAI,YAAY;KACvB,SAAQ,OAAO;AAEd,kBAAY;KACb;AAGD,WAAM,IAAI;IACX,EAAC;GACH,SAAQ,OAAO;AAEd,UAAM,iBAAiB,cACrB,OAAM;AAIR,QAAI,UACF,OAAM;GAET,UAAS;AACR,UAAM,KAAK,QAAQ,KAAK;GACzB;EACF,EACF,EAAC;CACH;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8ED,SAAgB,mBAMdC,aACAC,UACoD;CAEpD,MAAMC,qBAA0C,CAAE;AAElD,MAAK,MAAM,CAAC,KAAK,QAAQ,IAAI,OAAO,QAAQ,SAAS,CACnD,oBAAmB,OAAO,OACxB,EAAE,KAA2B,EAC7BC,QACG;EACH,MAAM,QAAQ,MAAM,AAAC,QAA0C,IAAI;AACnE,QAAM,IAAI,MAAM;CACjB;AAGH,QAAO,AAAC,YAAoB,OAAO,mBAAmB;AACvD"}