@geekmidas/testkit 0.0.10 → 0.0.12

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 (97) hide show
  1. package/dist/Factory-Bm44VKa-.d.cts +131 -0
  2. package/dist/Factory-tjCDNgUK.d.mts +131 -0
  3. package/dist/Factory.d.cts +3 -0
  4. package/dist/Factory.d.mts +3 -0
  5. package/dist/KyselyFactory-BoPDDitt.d.cts +200 -0
  6. package/dist/{KyselyFactory-ELiHgHVv.mjs → KyselyFactory-C3Bc3p4L.mjs} +1 -1
  7. package/dist/{KyselyFactory-Bdq1s1Go.cjs → KyselyFactory-CXtfmMfK.cjs} +1 -1
  8. package/dist/KyselyFactory-D82j74t9.d.mts +200 -0
  9. package/dist/KyselyFactory.cjs +2 -2
  10. package/dist/KyselyFactory.d.cts +4 -0
  11. package/dist/KyselyFactory.d.mts +4 -0
  12. package/dist/KyselyFactory.mjs +2 -2
  13. package/dist/ObjectionFactory-BWMTXsxH.d.cts +213 -0
  14. package/dist/ObjectionFactory-CEG5qUrm.d.mts +213 -0
  15. package/dist/{ObjectionFactory-C47B03Ot.cjs → ObjectionFactory-DxIxJagq.cjs} +82 -40
  16. package/dist/{ObjectionFactory-89p-FFEw.mjs → ObjectionFactory-qIICOph3.mjs} +82 -40
  17. package/dist/ObjectionFactory.cjs +2 -1
  18. package/dist/ObjectionFactory.d.cts +4 -0
  19. package/dist/ObjectionFactory.d.mts +4 -0
  20. package/dist/ObjectionFactory.mjs +2 -1
  21. package/dist/PostgresKyselyMigrator-CQ3aUoy_.d.cts +67 -0
  22. package/dist/PostgresKyselyMigrator-_6yHZigp.d.mts +67 -0
  23. package/dist/PostgresKyselyMigrator.d.cts +3 -0
  24. package/dist/PostgresKyselyMigrator.d.mts +3 -0
  25. package/dist/PostgresMigrator-BlvuQl7d.d.mts +84 -0
  26. package/dist/PostgresMigrator-D5UkK1_K.d.cts +84 -0
  27. package/dist/PostgresMigrator.d.cts +2 -0
  28. package/dist/PostgresMigrator.d.mts +2 -0
  29. package/dist/PostgresObjectionMigrator-C69n7vzr.d.mts +77 -0
  30. package/dist/PostgresObjectionMigrator-CZHHcCOv.d.cts +77 -0
  31. package/dist/PostgresObjectionMigrator.d.cts +3 -0
  32. package/dist/PostgresObjectionMigrator.d.mts +3 -0
  33. package/dist/VitestKyselyTransactionIsolator-ClCazkBO.d.mts +56 -0
  34. package/dist/VitestKyselyTransactionIsolator-UE1J-UoP.d.cts +56 -0
  35. package/dist/VitestKyselyTransactionIsolator.d.cts +3 -0
  36. package/dist/VitestKyselyTransactionIsolator.d.mts +3 -0
  37. package/dist/VitestObjectionTransactionIsolator-CO2nTi9r.d.cts +57 -0
  38. package/dist/VitestObjectionTransactionIsolator-D264iuPy.d.mts +57 -0
  39. package/dist/VitestObjectionTransactionIsolator.d.cts +3 -0
  40. package/dist/VitestObjectionTransactionIsolator.d.mts +3 -0
  41. package/dist/VitestTransactionIsolator-DHf2MxmC.d.cts +118 -0
  42. package/dist/VitestTransactionIsolator-Xqyjlmw6.d.mts +118 -0
  43. package/dist/VitestTransactionIsolator.d.cts +2 -0
  44. package/dist/VitestTransactionIsolator.d.mts +2 -0
  45. package/dist/__tests__/Factory.spec.d.cts +1 -0
  46. package/dist/__tests__/Factory.spec.d.mts +1 -0
  47. package/dist/__tests__/KyselyFactory.spec.cjs +2 -2
  48. package/dist/__tests__/KyselyFactory.spec.d.cts +1 -0
  49. package/dist/__tests__/KyselyFactory.spec.d.mts +1 -0
  50. package/dist/__tests__/KyselyFactory.spec.mjs +2 -2
  51. package/dist/__tests__/ObjectionFactory.spec.cjs +117 -1
  52. package/dist/__tests__/ObjectionFactory.spec.d.cts +1 -0
  53. package/dist/__tests__/ObjectionFactory.spec.d.mts +1 -0
  54. package/dist/__tests__/ObjectionFactory.spec.mjs +117 -1
  55. package/dist/__tests__/PostgresMigrator.spec.d.cts +1 -0
  56. package/dist/__tests__/PostgresMigrator.spec.d.mts +1 -0
  57. package/dist/__tests__/PostgresObjectionMigrator.spec.d.cts +1 -0
  58. package/dist/__tests__/PostgresObjectionMigrator.spec.d.mts +1 -0
  59. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.cjs +2 -1
  60. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.cts +1 -0
  61. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.mts +1 -0
  62. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.mjs +2 -1
  63. package/dist/__tests__/faker.spec.cjs +1 -1
  64. package/dist/__tests__/faker.spec.d.cts +1 -0
  65. package/dist/__tests__/faker.spec.d.mts +1 -0
  66. package/dist/__tests__/faker.spec.mjs +1 -1
  67. package/dist/__tests__/integration.spec.cjs +2 -2
  68. package/dist/__tests__/integration.spec.d.cts +1 -0
  69. package/dist/__tests__/integration.spec.d.mts +1 -0
  70. package/dist/__tests__/integration.spec.mjs +2 -2
  71. package/dist/example.cjs +2 -2
  72. package/dist/example.d.cts +26 -0
  73. package/dist/example.d.mts +26 -0
  74. package/dist/example.mjs +2 -2
  75. package/dist/{faker-SMN4ira4.cjs → faker-B14IEMIN.cjs} +41 -1
  76. package/dist/{faker-CxKkEeYi.mjs → faker-BGKYFoCT.mjs} +36 -2
  77. package/dist/faker-ChuHaYMR.d.mts +165 -0
  78. package/dist/faker-km9UhOS6.d.cts +165 -0
  79. package/dist/faker.cjs +2 -1
  80. package/dist/faker.d.cts +2 -0
  81. package/dist/faker.d.mts +2 -0
  82. package/dist/faker.mjs +2 -2
  83. package/dist/helpers.d.cts +41 -0
  84. package/dist/helpers.d.mts +41 -0
  85. package/dist/kysely.cjs +2 -2
  86. package/dist/kysely.d.cts +73 -0
  87. package/dist/kysely.d.mts +73 -0
  88. package/dist/kysely.mjs +2 -2
  89. package/dist/objection.cjs +2 -1
  90. package/dist/objection.d.cts +88 -0
  91. package/dist/objection.d.mts +88 -0
  92. package/dist/objection.mjs +2 -1
  93. package/package.json +5 -5
  94. package/src/ObjectionFactory.ts +156 -13
  95. package/src/__tests__/ObjectionFactory.spec.ts +162 -0
  96. package/src/faker.ts +86 -0
  97. package/PostgresKyselyMigrator.spec +0 -471
@@ -0,0 +1,56 @@
1
+ import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-Xqyjlmw6.mjs";
2
+ import { Kysely, Transaction } from "kysely";
3
+
4
+ //#region src/VitestKyselyTransactionIsolator.d.ts
5
+
6
+ /**
7
+ * Kysely-specific implementation of the Vitest transaction isolator.
8
+ * Provides automatic transaction rollback for test isolation using Kysely's transaction API.
9
+ * Each test runs within a database transaction that is rolled back after completion,
10
+ * ensuring a clean state between tests without the overhead of recreating data.
11
+ *
12
+ * @template Database - The database schema type
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';
17
+ * import { db } from './database';
18
+ *
19
+ * // Create isolator instance
20
+ * const isolator = new VitestKyselyTransactionIsolator<Database>();
21
+ *
22
+ * // In your test setup
23
+ * beforeEach(async () => {
24
+ * await isolator.start(db);
25
+ * });
26
+ *
27
+ * afterEach(async () => {
28
+ * await isolator.rollback();
29
+ * });
30
+ *
31
+ * // Tests run in isolated transactions
32
+ * it('should create user', async () => {
33
+ * const user = await db.insertInto('users')
34
+ * .values({ name: 'Test User' })
35
+ * .returningAll()
36
+ * .executeTakeFirst();
37
+ *
38
+ * expect(user).toBeDefined();
39
+ * // This data will be rolled back after the test
40
+ * });
41
+ * ```
42
+ */
43
+ declare class VitestKyselyTransactionIsolator<Database> extends VitestPostgresTransactionIsolator<Kysely<Database>, Transaction<Database>> {
44
+ /**
45
+ * Creates a Kysely transaction with the specified isolation level.
46
+ * Implements the abstract transact method from VitestPostgresTransactionIsolator.
47
+ *
48
+ * @param conn - The Kysely database connection
49
+ * @param level - The transaction isolation level
50
+ * @param fn - The function to execute within the transaction
51
+ * @returns Promise that resolves when the transaction completes
52
+ */
53
+ transact(conn: Kysely<Database>, level: IsolationLevel, fn: (trx: Transaction<Database>) => Promise<void>): Promise<void>;
54
+ }
55
+ //#endregion
56
+ export { VitestKyselyTransactionIsolator };
@@ -0,0 +1,56 @@
1
+ import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-DHf2MxmC.cjs";
2
+ import { Kysely, Transaction } from "kysely";
3
+
4
+ //#region src/VitestKyselyTransactionIsolator.d.ts
5
+
6
+ /**
7
+ * Kysely-specific implementation of the Vitest transaction isolator.
8
+ * Provides automatic transaction rollback for test isolation using Kysely's transaction API.
9
+ * Each test runs within a database transaction that is rolled back after completion,
10
+ * ensuring a clean state between tests without the overhead of recreating data.
11
+ *
12
+ * @template Database - The database schema type
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';
17
+ * import { db } from './database';
18
+ *
19
+ * // Create isolator instance
20
+ * const isolator = new VitestKyselyTransactionIsolator<Database>();
21
+ *
22
+ * // In your test setup
23
+ * beforeEach(async () => {
24
+ * await isolator.start(db);
25
+ * });
26
+ *
27
+ * afterEach(async () => {
28
+ * await isolator.rollback();
29
+ * });
30
+ *
31
+ * // Tests run in isolated transactions
32
+ * it('should create user', async () => {
33
+ * const user = await db.insertInto('users')
34
+ * .values({ name: 'Test User' })
35
+ * .returningAll()
36
+ * .executeTakeFirst();
37
+ *
38
+ * expect(user).toBeDefined();
39
+ * // This data will be rolled back after the test
40
+ * });
41
+ * ```
42
+ */
43
+ declare class VitestKyselyTransactionIsolator<Database> extends VitestPostgresTransactionIsolator<Kysely<Database>, Transaction<Database>> {
44
+ /**
45
+ * Creates a Kysely transaction with the specified isolation level.
46
+ * Implements the abstract transact method from VitestPostgresTransactionIsolator.
47
+ *
48
+ * @param conn - The Kysely database connection
49
+ * @param level - The transaction isolation level
50
+ * @param fn - The function to execute within the transaction
51
+ * @returns Promise that resolves when the transaction completes
52
+ */
53
+ transact(conn: Kysely<Database>, level: IsolationLevel, fn: (trx: Transaction<Database>) => Promise<void>): Promise<void>;
54
+ }
55
+ //#endregion
56
+ export { VitestKyselyTransactionIsolator };
@@ -0,0 +1,3 @@
1
+ import "./VitestTransactionIsolator-DHf2MxmC.cjs";
2
+ import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-UE1J-UoP.cjs";
3
+ export { VitestKyselyTransactionIsolator };
@@ -0,0 +1,3 @@
1
+ import "./VitestTransactionIsolator-Xqyjlmw6.mjs";
2
+ import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-ClCazkBO.mjs";
3
+ export { VitestKyselyTransactionIsolator };
@@ -0,0 +1,57 @@
1
+ import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-DHf2MxmC.cjs";
2
+ import { Knex } from "knex";
3
+
4
+ //#region src/VitestObjectionTransactionIsolator.d.ts
5
+
6
+ /**
7
+ * Objection.js-specific implementation of the Vitest transaction isolator.
8
+ * Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.
9
+ * Each test runs within a database transaction that is rolled back after completion,
10
+ * ensuring a clean state between tests without the overhead of recreating data.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';
15
+ * import { knex } from './database';
16
+ * import { User } from './models';
17
+ * import { test } from 'vitest';
18
+ *
19
+ * // Create isolator instance
20
+ * const isolator = new VitestObjectionTransactionIsolator(test);
21
+ *
22
+ * // Use with wrapped test API
23
+ * const isolatedTest = isolator.wrapVitestWithTransaction(knex);
24
+ *
25
+ * isolatedTest('should create user', async ({ trx }) => {
26
+ * const user = await User.query(trx)
27
+ * .insert({ name: 'Test User' });
28
+ *
29
+ * expect(user).toBeDefined();
30
+ * // This data will be rolled back after the test
31
+ * });
32
+ * ```
33
+ */
34
+ declare class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<Knex, Knex.Transaction> {
35
+ /**
36
+ * Creates a Knex transaction with the specified isolation level.
37
+ * Implements the abstract transact method from VitestPostgresTransactionIsolator.
38
+ * This transaction can be used with Objection.js models via Model.query(trx).
39
+ *
40
+ * @param conn - The Knex database connection
41
+ * @param level - The transaction isolation level
42
+ * @param fn - The function to execute within the transaction
43
+ * @returns Promise that resolves when the transaction completes
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {
48
+ * // Use transaction with Objection models
49
+ * await User.query(trx).insert({ name: 'Test' });
50
+ * await Post.query(trx).where('userId', user.id).delete();
51
+ * });
52
+ * ```
53
+ */
54
+ transact(conn: Knex, level: IsolationLevel, fn: (trx: Knex.Transaction) => Promise<void>): Promise<void>;
55
+ }
56
+ //#endregion
57
+ export { VitestObjectionTransactionIsolator };
@@ -0,0 +1,57 @@
1
+ import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-Xqyjlmw6.mjs";
2
+ import { Knex } from "knex";
3
+
4
+ //#region src/VitestObjectionTransactionIsolator.d.ts
5
+
6
+ /**
7
+ * Objection.js-specific implementation of the Vitest transaction isolator.
8
+ * Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.
9
+ * Each test runs within a database transaction that is rolled back after completion,
10
+ * ensuring a clean state between tests without the overhead of recreating data.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';
15
+ * import { knex } from './database';
16
+ * import { User } from './models';
17
+ * import { test } from 'vitest';
18
+ *
19
+ * // Create isolator instance
20
+ * const isolator = new VitestObjectionTransactionIsolator(test);
21
+ *
22
+ * // Use with wrapped test API
23
+ * const isolatedTest = isolator.wrapVitestWithTransaction(knex);
24
+ *
25
+ * isolatedTest('should create user', async ({ trx }) => {
26
+ * const user = await User.query(trx)
27
+ * .insert({ name: 'Test User' });
28
+ *
29
+ * expect(user).toBeDefined();
30
+ * // This data will be rolled back after the test
31
+ * });
32
+ * ```
33
+ */
34
+ declare class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<Knex, Knex.Transaction> {
35
+ /**
36
+ * Creates a Knex transaction with the specified isolation level.
37
+ * Implements the abstract transact method from VitestPostgresTransactionIsolator.
38
+ * This transaction can be used with Objection.js models via Model.query(trx).
39
+ *
40
+ * @param conn - The Knex database connection
41
+ * @param level - The transaction isolation level
42
+ * @param fn - The function to execute within the transaction
43
+ * @returns Promise that resolves when the transaction completes
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {
48
+ * // Use transaction with Objection models
49
+ * await User.query(trx).insert({ name: 'Test' });
50
+ * await Post.query(trx).where('userId', user.id).delete();
51
+ * });
52
+ * ```
53
+ */
54
+ transact(conn: Knex, level: IsolationLevel, fn: (trx: Knex.Transaction) => Promise<void>): Promise<void>;
55
+ }
56
+ //#endregion
57
+ export { VitestObjectionTransactionIsolator };
@@ -0,0 +1,3 @@
1
+ import "./VitestTransactionIsolator-DHf2MxmC.cjs";
2
+ import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-CO2nTi9r.cjs";
3
+ export { VitestObjectionTransactionIsolator };
@@ -0,0 +1,3 @@
1
+ import "./VitestTransactionIsolator-Xqyjlmw6.mjs";
2
+ import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-D264iuPy.mjs";
3
+ export { VitestObjectionTransactionIsolator };
@@ -0,0 +1,118 @@
1
+ import { TestAPI } from "vitest";
2
+
3
+ //#region src/VitestTransactionIsolator.d.ts
4
+
5
+ /**
6
+ * Type definition for test fixtures that provide transaction access.
7
+ * Used with Vitest's test.extend() API to inject transactions into tests.
8
+ *
9
+ * @template Transaction - The transaction type specific to the database driver
10
+ */
11
+ interface DatabaseFixtures<Transaction> {
12
+ /**
13
+ * The database transaction available to the test.
14
+ * All database operations should use this transaction to ensure proper rollback.
15
+ */
16
+ trx: Transaction;
17
+ }
18
+ /**
19
+ * PostgreSQL transaction isolation levels.
20
+ * Controls the visibility of concurrent transactions.
21
+ *
22
+ * @see https://www.postgresql.org/docs/current/transaction-iso.html
23
+ */
24
+ declare enum IsolationLevel {
25
+ /**
26
+ * Lowest isolation level. Allows dirty reads.
27
+ * Not recommended for testing.
28
+ */
29
+ READ_UNCOMMITTED = "READ UNCOMMITTED",
30
+ /**
31
+ * Default PostgreSQL isolation level.
32
+ * Prevents dirty reads but allows non-repeatable reads.
33
+ */
34
+ READ_COMMITTED = "READ COMMITTED",
35
+ /**
36
+ * Prevents dirty reads and non-repeatable reads.
37
+ * Recommended for most test scenarios.
38
+ */
39
+ REPEATABLE_READ = "REPEATABLE READ",
40
+ /**
41
+ * Highest isolation level. Prevents all phenomena.
42
+ * May cause performance overhead in tests.
43
+ */
44
+ SERIALIZABLE = "SERIALIZABLE",
45
+ }
46
+ /**
47
+ * Abstract base class for implementing database transaction isolation in Vitest tests.
48
+ * Provides automatic transaction rollback after each test to maintain test isolation.
49
+ * Subclasses must implement the transact() method for their specific database driver.
50
+ *
51
+ * @template Connection - The database connection type
52
+ * @template Transaction - The transaction type
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * // Implement for your database driver
57
+ * class MyDatabaseIsolator extends VitestPostgresTransactionIsolator<MyDB, MyTx> {
58
+ * async transact(conn: MyDB, level: IsolationLevel, fn: (tx: MyTx) => Promise<void>) {
59
+ * await conn.transaction(level, fn);
60
+ * }
61
+ * }
62
+ *
63
+ * // Use in tests
64
+ * const isolator = new MyDatabaseIsolator(test);
65
+ * const isolatedTest = isolator.wrapVitestWithTransaction(db);
66
+ *
67
+ * isolatedTest('should create user', async ({ trx }) => {
68
+ * await trx.insert('users', { name: 'Test' });
69
+ * // Data is automatically rolled back after test
70
+ * });
71
+ * ```
72
+ */
73
+ declare abstract class VitestPostgresTransactionIsolator<Connection, Transaction> {
74
+ private readonly api;
75
+ /**
76
+ * Abstract method to create a transaction with the specified isolation level.
77
+ * Must be implemented by subclasses for specific database drivers.
78
+ *
79
+ * @param conn - The database connection
80
+ * @param isolationLevel - The transaction isolation level
81
+ * @param fn - The function to execute within the transaction
82
+ * @returns Promise that resolves when the transaction completes
83
+ */
84
+ abstract transact(conn: Connection, isolationLevel: IsolationLevel, fn: (trx: Transaction) => Promise<void>): Promise<void>;
85
+ /**
86
+ * Creates a new VitestPostgresTransactionIsolator instance.
87
+ *
88
+ * @param api - The Vitest test API (usually the `test` export from vitest)
89
+ */
90
+ constructor(api: TestAPI);
91
+ /**
92
+ * Creates a wrapped version of Vitest's test API that provides transaction isolation.
93
+ * Each test will run within a database transaction that is automatically rolled back.
94
+ *
95
+ * @param conn - The database connection to use
96
+ * @param setup - Optional setup function to run within the transaction before each test
97
+ * @param level - The transaction isolation level (defaults to REPEATABLE_READ)
98
+ * @returns A wrapped test API with transaction support
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const isolatedTest = isolator.wrapVitestWithTransaction(db, async (trx) => {
103
+ * // Optional setup: create common test data
104
+ * await trx.insert('settings', { key: 'test', value: 'true' });
105
+ * });
106
+ *
107
+ * isolatedTest('test with transaction', async ({ trx }) => {
108
+ * const user = await trx.insert('users', { name: 'Test' });
109
+ * expect(user).toBeDefined();
110
+ * });
111
+ * ```
112
+ */
113
+ wrapVitestWithTransaction(conn: Connection, setup?: (trx: Transaction) => Promise<void>, level?: IsolationLevel): TestAPI<{
114
+ trx: Transaction;
115
+ }>;
116
+ }
117
+ //#endregion
118
+ export { DatabaseFixtures, IsolationLevel, VitestPostgresTransactionIsolator };
@@ -0,0 +1,118 @@
1
+ import { TestAPI } from "vitest";
2
+
3
+ //#region src/VitestTransactionIsolator.d.ts
4
+
5
+ /**
6
+ * Type definition for test fixtures that provide transaction access.
7
+ * Used with Vitest's test.extend() API to inject transactions into tests.
8
+ *
9
+ * @template Transaction - The transaction type specific to the database driver
10
+ */
11
+ interface DatabaseFixtures<Transaction> {
12
+ /**
13
+ * The database transaction available to the test.
14
+ * All database operations should use this transaction to ensure proper rollback.
15
+ */
16
+ trx: Transaction;
17
+ }
18
+ /**
19
+ * PostgreSQL transaction isolation levels.
20
+ * Controls the visibility of concurrent transactions.
21
+ *
22
+ * @see https://www.postgresql.org/docs/current/transaction-iso.html
23
+ */
24
+ declare enum IsolationLevel {
25
+ /**
26
+ * Lowest isolation level. Allows dirty reads.
27
+ * Not recommended for testing.
28
+ */
29
+ READ_UNCOMMITTED = "READ UNCOMMITTED",
30
+ /**
31
+ * Default PostgreSQL isolation level.
32
+ * Prevents dirty reads but allows non-repeatable reads.
33
+ */
34
+ READ_COMMITTED = "READ COMMITTED",
35
+ /**
36
+ * Prevents dirty reads and non-repeatable reads.
37
+ * Recommended for most test scenarios.
38
+ */
39
+ REPEATABLE_READ = "REPEATABLE READ",
40
+ /**
41
+ * Highest isolation level. Prevents all phenomena.
42
+ * May cause performance overhead in tests.
43
+ */
44
+ SERIALIZABLE = "SERIALIZABLE",
45
+ }
46
+ /**
47
+ * Abstract base class for implementing database transaction isolation in Vitest tests.
48
+ * Provides automatic transaction rollback after each test to maintain test isolation.
49
+ * Subclasses must implement the transact() method for their specific database driver.
50
+ *
51
+ * @template Connection - The database connection type
52
+ * @template Transaction - The transaction type
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * // Implement for your database driver
57
+ * class MyDatabaseIsolator extends VitestPostgresTransactionIsolator<MyDB, MyTx> {
58
+ * async transact(conn: MyDB, level: IsolationLevel, fn: (tx: MyTx) => Promise<void>) {
59
+ * await conn.transaction(level, fn);
60
+ * }
61
+ * }
62
+ *
63
+ * // Use in tests
64
+ * const isolator = new MyDatabaseIsolator(test);
65
+ * const isolatedTest = isolator.wrapVitestWithTransaction(db);
66
+ *
67
+ * isolatedTest('should create user', async ({ trx }) => {
68
+ * await trx.insert('users', { name: 'Test' });
69
+ * // Data is automatically rolled back after test
70
+ * });
71
+ * ```
72
+ */
73
+ declare abstract class VitestPostgresTransactionIsolator<Connection, Transaction> {
74
+ private readonly api;
75
+ /**
76
+ * Abstract method to create a transaction with the specified isolation level.
77
+ * Must be implemented by subclasses for specific database drivers.
78
+ *
79
+ * @param conn - The database connection
80
+ * @param isolationLevel - The transaction isolation level
81
+ * @param fn - The function to execute within the transaction
82
+ * @returns Promise that resolves when the transaction completes
83
+ */
84
+ abstract transact(conn: Connection, isolationLevel: IsolationLevel, fn: (trx: Transaction) => Promise<void>): Promise<void>;
85
+ /**
86
+ * Creates a new VitestPostgresTransactionIsolator instance.
87
+ *
88
+ * @param api - The Vitest test API (usually the `test` export from vitest)
89
+ */
90
+ constructor(api: TestAPI);
91
+ /**
92
+ * Creates a wrapped version of Vitest's test API that provides transaction isolation.
93
+ * Each test will run within a database transaction that is automatically rolled back.
94
+ *
95
+ * @param conn - The database connection to use
96
+ * @param setup - Optional setup function to run within the transaction before each test
97
+ * @param level - The transaction isolation level (defaults to REPEATABLE_READ)
98
+ * @returns A wrapped test API with transaction support
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const isolatedTest = isolator.wrapVitestWithTransaction(db, async (trx) => {
103
+ * // Optional setup: create common test data
104
+ * await trx.insert('settings', { key: 'test', value: 'true' });
105
+ * });
106
+ *
107
+ * isolatedTest('test with transaction', async ({ trx }) => {
108
+ * const user = await trx.insert('users', { name: 'Test' });
109
+ * expect(user).toBeDefined();
110
+ * });
111
+ * ```
112
+ */
113
+ wrapVitestWithTransaction(conn: Connection, setup?: (trx: Transaction) => Promise<void>, level?: IsolationLevel): TestAPI<{
114
+ trx: Transaction;
115
+ }>;
116
+ }
117
+ //#endregion
118
+ export { DatabaseFixtures, IsolationLevel, VitestPostgresTransactionIsolator };
@@ -0,0 +1,2 @@
1
+ import { DatabaseFixtures, IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-DHf2MxmC.cjs";
2
+ export { DatabaseFixtures, IsolationLevel, VitestPostgresTransactionIsolator };
@@ -0,0 +1,2 @@
1
+ import { DatabaseFixtures, IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-Xqyjlmw6.mjs";
2
+ export { DatabaseFixtures, IsolationLevel, VitestPostgresTransactionIsolator };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -1,7 +1,7 @@
1
1
  const require_chunk = require('../chunk-CUT6urMc.cjs');
2
2
  require('../Factory-WMhTNZ9S.cjs');
3
- require('../faker-SMN4ira4.cjs');
4
- const require_KyselyFactory = require('../KyselyFactory-Bdq1s1Go.cjs');
3
+ require('../faker-B14IEMIN.cjs');
4
+ const require_KyselyFactory = require('../KyselyFactory-CXtfmMfK.cjs');
5
5
  require('../PostgresMigrator-DFcNdCvD.cjs');
6
6
  require('../PostgresKyselyMigrator-CfytARcA.cjs');
7
7
  require('../VitestTransactionIsolator-CruLTRRi.cjs');
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -1,6 +1,6 @@
1
1
  import "../Factory-z2m01hMj.mjs";
2
- import "../faker-CxKkEeYi.mjs";
3
- import { KyselyFactory } from "../KyselyFactory-ELiHgHVv.mjs";
2
+ import "../faker-BGKYFoCT.mjs";
3
+ import { KyselyFactory } from "../KyselyFactory-C3Bc3p4L.mjs";
4
4
  import "../PostgresMigrator-DxPC_gGu.mjs";
5
5
  import "../PostgresKyselyMigrator-Bdhl251C.mjs";
6
6
  import "../VitestTransactionIsolator-BWwK-ca6.mjs";
@@ -1,6 +1,7 @@
1
1
  const require_chunk = require('../chunk-CUT6urMc.cjs');
2
2
  require('../Factory-WMhTNZ9S.cjs');
3
- const require_ObjectionFactory = require('../ObjectionFactory-C47B03Ot.cjs');
3
+ const require_faker = require('../faker-B14IEMIN.cjs');
4
+ const require_ObjectionFactory = require('../ObjectionFactory-DxIxJagq.cjs');
4
5
  const require_helpers = require('../helpers-CNMBePuj.cjs');
5
6
  const vitest = require_chunk.__toESM(require("vitest"));
6
7
  const objection = require_chunk.__toESM(require("objection"));
@@ -286,6 +287,121 @@ vitest.describe.skip("ObjectionFactory", () => {
286
287
  (0, vitest.expect)(result).toBe(seedFn);
287
288
  });
288
289
  });
290
+ (0, vitest.describe)("createBuilder static method", () => {
291
+ (0, vitest.it)("should create a builder function with auto-insert", async () => {
292
+ const userBuilder = require_ObjectionFactory.ObjectionFactory.createBuilder(User, (attrs, factory$1, db$1, faker$1) => ({
293
+ name: faker$1.person.fullName(),
294
+ email: faker$1.internet.email(),
295
+ role: "user",
296
+ createdAt: /* @__PURE__ */ new Date(),
297
+ updatedAt: /* @__PURE__ */ new Date(),
298
+ ...attrs
299
+ }));
300
+ const builders = { user: userBuilder };
301
+ factory = new require_ObjectionFactory.ObjectionFactory(builders, {}, trx);
302
+ const result = await factory.insert("user", { name: "Test User" });
303
+ (0, vitest.expect)(result).toBeInstanceOf(User);
304
+ (0, vitest.expect)(result.name).toBe("Test User");
305
+ (0, vitest.expect)(result.email).toMatch(/@/);
306
+ (0, vitest.expect)(result.id).toBeDefined();
307
+ });
308
+ (0, vitest.it)("should create a builder function without auto-insert", async () => {
309
+ const userBuilder = require_ObjectionFactory.ObjectionFactory.createBuilder(User, (attrs) => ({
310
+ name: "No Insert User",
311
+ email: "noinsert@example.com",
312
+ role: "user",
313
+ createdAt: /* @__PURE__ */ new Date(),
314
+ updatedAt: /* @__PURE__ */ new Date(),
315
+ ...attrs
316
+ }), false);
317
+ const builders = { user: userBuilder };
318
+ factory = new require_ObjectionFactory.ObjectionFactory(builders, {}, trx);
319
+ const result = await factory.insert("user");
320
+ (0, vitest.expect)(result).toBeInstanceOf(User);
321
+ (0, vitest.expect)(result.name).toBe("No Insert User");
322
+ (0, vitest.expect)(result.id).toBeDefined();
323
+ });
324
+ (0, vitest.it)("should pass all parameters to the item function", async () => {
325
+ let capturedFactory;
326
+ let capturedDb;
327
+ let capturedFaker;
328
+ const userBuilder = require_ObjectionFactory.ObjectionFactory.createBuilder(User, (attrs, factory$1, db$1, fakerInstance) => {
329
+ capturedFactory = factory$1;
330
+ capturedDb = db$1;
331
+ capturedFaker = fakerInstance;
332
+ return {
333
+ name: "Test User",
334
+ email: "test@example.com",
335
+ role: "user",
336
+ createdAt: /* @__PURE__ */ new Date(),
337
+ updatedAt: /* @__PURE__ */ new Date(),
338
+ ...attrs
339
+ };
340
+ });
341
+ const builders = { user: userBuilder };
342
+ factory = new require_ObjectionFactory.ObjectionFactory(builders, {}, trx);
343
+ await factory.insert("user");
344
+ (0, vitest.expect)(capturedFactory).toBe(factory);
345
+ (0, vitest.expect)(capturedDb).toBe(trx);
346
+ (0, vitest.expect)(capturedFaker).toBe(require_faker.faker);
347
+ });
348
+ (0, vitest.it)("should handle async item functions", async () => {
349
+ const userBuilder = require_ObjectionFactory.ObjectionFactory.createBuilder(User, async (attrs, factory$1, db$1, faker$1) => {
350
+ await new Promise((resolve) => setTimeout(resolve, 10));
351
+ return {
352
+ name: "Async User",
353
+ email: faker$1.internet.email(),
354
+ role: "user",
355
+ createdAt: /* @__PURE__ */ new Date(),
356
+ updatedAt: /* @__PURE__ */ new Date(),
357
+ ...attrs
358
+ };
359
+ });
360
+ const builders = { user: userBuilder };
361
+ factory = new require_ObjectionFactory.ObjectionFactory(builders, {}, trx);
362
+ const result = await factory.insert("user");
363
+ (0, vitest.expect)(result).toBeInstanceOf(User);
364
+ (0, vitest.expect)(result.name).toBe("Async User");
365
+ (0, vitest.expect)(result.id).toBeDefined();
366
+ });
367
+ (0, vitest.it)("should work without item function", async () => {
368
+ const userBuilder = require_ObjectionFactory.ObjectionFactory.createBuilder(User);
369
+ const builders = { user: userBuilder };
370
+ factory = new require_ObjectionFactory.ObjectionFactory(builders, {}, trx);
371
+ const attrs = {
372
+ name: "Manual User",
373
+ email: "manual@example.com",
374
+ role: "user",
375
+ createdAt: /* @__PURE__ */ new Date(),
376
+ updatedAt: /* @__PURE__ */ new Date()
377
+ };
378
+ const result = await factory.insert("user", attrs);
379
+ (0, vitest.expect)(result).toBeInstanceOf(User);
380
+ (0, vitest.expect)(result.name).toBe("Manual User");
381
+ (0, vitest.expect)(result.email).toBe("manual@example.com");
382
+ (0, vitest.expect)(result.id).toBeDefined();
383
+ });
384
+ (0, vitest.it)("should allow overriding default values", async () => {
385
+ const userBuilder = require_ObjectionFactory.ObjectionFactory.createBuilder(User, (attrs, factory$1, db$1, faker$1) => ({
386
+ name: "Default Name",
387
+ email: "default@example.com",
388
+ role: "user",
389
+ createdAt: /* @__PURE__ */ new Date(),
390
+ updatedAt: /* @__PURE__ */ new Date(),
391
+ ...attrs
392
+ }));
393
+ const builders = { user: userBuilder };
394
+ factory = new require_ObjectionFactory.ObjectionFactory(builders, {}, trx);
395
+ const result = await factory.insert("user", {
396
+ name: "Override Name",
397
+ email: "override@example.com"
398
+ });
399
+ (0, vitest.expect)(result).toBeInstanceOf(User);
400
+ (0, vitest.expect)(result.name).toBe("Override Name");
401
+ (0, vitest.expect)(result.email).toBe("override@example.com");
402
+ (0, vitest.expect)(result.role).toBe("user");
403
+ });
404
+ });
289
405
  (0, vitest.describe)("error handling", () => {
290
406
  (0, vitest.it)("should handle builder errors gracefully", async () => {
291
407
  const userBuilder = async (attrs, factory$1, db$1) => {
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };