@geekmidas/testkit 10.0.0-alpha.4 → 10.0.0-alpha.40
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.
- package/README.md +74 -0
- package/dist/Factory.cjs +51 -2
- package/dist/Factory.cjs.map +1 -0
- package/dist/Factory.d.cts +143 -3
- package/dist/Factory.d.cts.map +1 -0
- package/dist/Factory.d.mts +143 -3
- package/dist/Factory.d.mts.map +1 -0
- package/dist/Factory.mjs +50 -2
- package/dist/Factory.mjs.map +1 -0
- package/dist/KyselyFactory.cjs +237 -4
- package/dist/KyselyFactory.cjs.map +1 -0
- package/dist/KyselyFactory.d.cts +224 -4
- package/dist/KyselyFactory.d.cts.map +1 -0
- package/dist/KyselyFactory.d.mts +224 -4
- package/dist/KyselyFactory.d.mts.map +1 -0
- package/dist/KyselyFactory.mjs +236 -4
- package/dist/KyselyFactory.mjs.map +1 -0
- package/dist/ObjectionFactory.cjs +265 -4
- package/dist/ObjectionFactory.cjs.map +1 -0
- package/dist/ObjectionFactory.d.cts +237 -4
- package/dist/ObjectionFactory.d.cts.map +1 -0
- package/dist/ObjectionFactory.d.mts +237 -4
- package/dist/ObjectionFactory.d.mts.map +1 -0
- package/dist/ObjectionFactory.mjs +264 -4
- package/dist/ObjectionFactory.mjs.map +1 -0
- package/dist/PostgresKyselyMigrator.cjs +94 -3
- package/dist/PostgresKyselyMigrator.cjs.map +1 -0
- package/dist/PostgresKyselyMigrator.d.cts +80 -3
- package/dist/PostgresKyselyMigrator.d.cts.map +1 -0
- package/dist/PostgresKyselyMigrator.d.mts +80 -3
- package/dist/PostgresKyselyMigrator.d.mts.map +1 -0
- package/dist/PostgresKyselyMigrator.mjs +93 -3
- package/dist/PostgresKyselyMigrator.mjs.map +1 -0
- package/dist/{PostgresMigrator-C_QQ6q35.d.mts → PostgresMigrator-CDPnnwMJ.d.cts} +11 -5
- package/dist/PostgresMigrator-CDPnnwMJ.d.cts.map +1 -0
- package/dist/{PostgresMigrator-CeYy-eHF.d.cts → PostgresMigrator-CDPnnwMJ.d.mts} +11 -5
- package/dist/PostgresMigrator-CDPnnwMJ.d.mts.map +1 -0
- package/dist/PostgresMigrator.cjs +178 -2
- package/dist/PostgresMigrator.cjs.map +1 -0
- package/dist/PostgresMigrator.d.cts +1 -1
- package/dist/PostgresMigrator.d.mts +1 -1
- package/dist/PostgresMigrator.mjs +175 -2
- package/dist/PostgresMigrator.mjs.map +1 -0
- package/dist/PostgresObjectionMigrator.cjs +118 -3
- package/dist/PostgresObjectionMigrator.cjs.map +1 -0
- package/dist/PostgresObjectionMigrator.d.cts +75 -3
- package/dist/PostgresObjectionMigrator.d.cts.map +1 -0
- package/dist/PostgresObjectionMigrator.d.mts +75 -3
- package/dist/PostgresObjectionMigrator.d.mts.map +1 -0
- package/dist/PostgresObjectionMigrator.mjs +117 -3
- package/dist/PostgresObjectionMigrator.mjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator.cjs +66 -3
- package/dist/VitestKyselyTransactionIsolator.cjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator.d.cts +60 -3
- package/dist/VitestKyselyTransactionIsolator.d.cts.map +1 -0
- package/dist/VitestKyselyTransactionIsolator.d.mts +60 -3
- package/dist/VitestKyselyTransactionIsolator.d.mts.map +1 -0
- package/dist/VitestKyselyTransactionIsolator.mjs +65 -3
- package/dist/VitestKyselyTransactionIsolator.mjs.map +1 -0
- package/dist/VitestObjectionTransactionIsolator.cjs +62 -3
- package/dist/VitestObjectionTransactionIsolator.cjs.map +1 -0
- package/dist/VitestObjectionTransactionIsolator.d.cts +56 -3
- package/dist/VitestObjectionTransactionIsolator.d.cts.map +1 -0
- package/dist/VitestObjectionTransactionIsolator.d.mts +56 -3
- package/dist/VitestObjectionTransactionIsolator.d.mts.map +1 -0
- package/dist/VitestObjectionTransactionIsolator.mjs +61 -3
- package/dist/VitestObjectionTransactionIsolator.mjs.map +1 -0
- package/dist/VitestTransactionIsolator.cjs +187 -4
- package/dist/VitestTransactionIsolator.cjs.map +1 -0
- package/dist/VitestTransactionIsolator.d.cts +219 -2
- package/dist/VitestTransactionIsolator.d.cts.map +1 -0
- package/dist/VitestTransactionIsolator.d.mts +219 -2
- package/dist/VitestTransactionIsolator.d.mts.map +1 -0
- package/dist/VitestTransactionIsolator.mjs +184 -2
- package/dist/VitestTransactionIsolator.mjs.map +1 -0
- package/dist/aws.cjs +3 -4
- package/dist/aws.cjs.map +1 -1
- package/dist/aws.d.cts +3 -8
- package/dist/aws.d.cts.map +1 -1
- package/dist/aws.d.mts +3 -8
- package/dist/aws.d.mts.map +1 -1
- package/dist/aws.mjs +1 -2
- package/dist/aws.mjs.map +1 -1
- package/dist/benchmark.cjs +2 -2
- package/dist/benchmark.cjs.map +1 -1
- package/dist/benchmark.d.cts +4 -6
- package/dist/benchmark.d.cts.map +1 -1
- package/dist/benchmark.d.mts +4 -6
- package/dist/benchmark.d.mts.map +1 -1
- package/dist/benchmark.mjs +1 -1
- package/dist/benchmark.mjs.map +1 -1
- package/dist/better-auth.cjs +17 -8
- package/dist/better-auth.cjs.map +1 -1
- package/dist/better-auth.d.cts +13142 -5
- package/dist/better-auth.d.cts.map +1 -1
- package/dist/better-auth.d.mts +13142 -5
- package/dist/better-auth.d.mts.map +1 -1
- package/dist/better-auth.mjs +15 -6
- package/dist/better-auth.mjs.map +1 -1
- package/dist/browser.cjs +127 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +47 -0
- package/dist/browser.d.cts.map +1 -0
- package/dist/browser.d.mts +47 -0
- package/dist/browser.d.mts.map +1 -0
- package/dist/browser.mjs +125 -0
- package/dist/browser.mjs.map +1 -0
- package/dist/context.cjs +80 -0
- package/dist/context.cjs.map +1 -0
- package/dist/context.d.cts +55 -0
- package/dist/context.d.cts.map +1 -0
- package/dist/context.d.mts +55 -0
- package/dist/context.d.mts.map +1 -0
- package/dist/context.mjs +73 -0
- package/dist/context.mjs.map +1 -0
- package/dist/faker.cjs +276 -8
- package/dist/faker.cjs.map +1 -0
- package/dist/faker.d.cts +145 -2
- package/dist/faker.d.cts.map +1 -0
- package/dist/faker.d.mts +145 -2
- package/dist/faker.d.mts.map +1 -0
- package/dist/faker.mjs +269 -2
- package/dist/faker.mjs.map +1 -0
- package/dist/helpers.cjs +6 -5
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +1 -5
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +1 -5
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +1 -2
- package/dist/helpers.mjs.map +1 -1
- package/dist/initScript.cjs +15 -15
- package/dist/initScript.cjs.map +1 -1
- package/dist/initScript.d.cts +2 -4
- package/dist/initScript.d.cts.map +1 -1
- package/dist/initScript.d.mts +2 -4
- package/dist/initScript.d.mts.map +1 -1
- package/dist/initScript.mjs +10 -12
- package/dist/initScript.mjs.map +1 -1
- package/dist/kysely.cjs +10 -13
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +10 -14
- package/dist/kysely.d.cts.map +1 -1
- package/dist/kysely.d.mts +10 -14
- package/dist/kysely.d.mts.map +1 -1
- package/dist/kysely.mjs +10 -14
- package/dist/kysely.mjs.map +1 -1
- package/dist/logger.cjs +3 -4
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +1 -5
- package/dist/logger.d.cts.map +1 -1
- package/dist/logger.d.mts +1 -5
- package/dist/logger.d.mts.map +1 -1
- package/dist/logger.mjs +1 -2
- package/dist/logger.mjs.map +1 -1
- package/dist/mailbox.cjs +95 -0
- package/dist/mailbox.cjs.map +1 -0
- package/dist/mailbox.d.cts +58 -0
- package/dist/mailbox.d.cts.map +1 -0
- package/dist/mailbox.d.mts +58 -0
- package/dist/mailbox.d.mts.map +1 -0
- package/dist/mailbox.mjs +92 -0
- package/dist/mailbox.mjs.map +1 -0
- package/dist/objection.cjs +10 -13
- package/dist/objection.cjs.map +1 -1
- package/dist/objection.d.cts +10 -14
- package/dist/objection.d.cts.map +1 -1
- package/dist/objection.d.mts +10 -14
- package/dist/objection.d.mts.map +1 -1
- package/dist/objection.mjs +10 -14
- package/dist/objection.mjs.map +1 -1
- package/dist/os/directory.cjs +31 -2
- package/dist/os/directory.cjs.map +1 -0
- package/dist/os/directory.d.cts +9 -2
- package/dist/os/directory.d.cts.map +1 -0
- package/dist/os/directory.d.mts +9 -2
- package/dist/os/directory.d.mts.map +1 -0
- package/dist/os/directory.mjs +25 -2
- package/dist/os/directory.mjs.map +1 -0
- package/dist/os/index.cjs +3 -3
- package/dist/os/index.d.cts +1 -1
- package/dist/os/index.d.mts +1 -1
- package/dist/os/index.mjs +2 -3
- package/dist/requestContext.cjs +10 -11
- package/dist/requestContext.cjs.map +1 -1
- package/dist/requestContext.d.cts +4 -8
- package/dist/requestContext.d.cts.map +1 -1
- package/dist/requestContext.d.mts +4 -8
- package/dist/requestContext.d.mts.map +1 -1
- package/dist/requestContext.mjs +1 -2
- package/dist/requestContext.mjs.map +1 -1
- package/dist/{chunk-CUT6urMc.cjs → rolldown-runtime-VH7oDXx4.cjs} +8 -10
- package/dist/timer.cjs +2 -2
- package/dist/timer.cjs.map +1 -1
- package/dist/timer.d.cts +1 -4
- package/dist/timer.d.cts.map +1 -1
- package/dist/timer.d.mts +1 -4
- package/dist/timer.d.mts.map +1 -1
- package/dist/timer.mjs +1 -1
- package/dist/timer.mjs.map +1 -1
- package/dist/transactions.cjs +123 -0
- package/dist/transactions.cjs.map +1 -0
- package/dist/transactions.d.cts +44 -0
- package/dist/transactions.d.cts.map +1 -0
- package/dist/transactions.d.mts +44 -0
- package/dist/transactions.d.mts.map +1 -0
- package/dist/transactions.mjs +118 -0
- package/dist/transactions.mjs.map +1 -0
- package/package.json +51 -8
- package/dist/Factory-AWn1IulI.d.cts +0 -147
- package/dist/Factory-AWn1IulI.d.cts.map +0 -1
- package/dist/Factory-BFVnMMCC.mjs +0 -51
- package/dist/Factory-BFVnMMCC.mjs.map +0 -1
- package/dist/Factory-BhjUOBWN.cjs +0 -57
- package/dist/Factory-BhjUOBWN.cjs.map +0 -1
- package/dist/Factory-C15SSK8_.d.mts +0 -147
- package/dist/Factory-C15SSK8_.d.mts.map +0 -1
- package/dist/KyselyFactory-BFqVIn_0.cjs +0 -246
- package/dist/KyselyFactory-BFqVIn_0.cjs.map +0 -1
- package/dist/KyselyFactory-C9Snz24z.d.mts +0 -228
- package/dist/KyselyFactory-C9Snz24z.d.mts.map +0 -1
- package/dist/KyselyFactory-CxUJCi--.d.cts +0 -228
- package/dist/KyselyFactory-CxUJCi--.d.cts.map +0 -1
- package/dist/KyselyFactory-DMswpwji.mjs +0 -241
- package/dist/KyselyFactory-DMswpwji.mjs.map +0 -1
- package/dist/ObjectionFactory-BeFBYcan.cjs +0 -272
- package/dist/ObjectionFactory-BeFBYcan.cjs.map +0 -1
- package/dist/ObjectionFactory-CYvaa0kU.d.cts +0 -241
- package/dist/ObjectionFactory-CYvaa0kU.d.cts.map +0 -1
- package/dist/ObjectionFactory-Cf2WI4o_.d.mts +0 -241
- package/dist/ObjectionFactory-Cf2WI4o_.d.mts.map +0 -1
- package/dist/ObjectionFactory-QCJ7u0Ql.mjs +0 -267
- package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +0 -1
- package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts +0 -84
- package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts.map +0 -1
- package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs +0 -101
- package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs.map +0 -1
- package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts +0 -84
- package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts.map +0 -1
- package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs +0 -95
- package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs.map +0 -1
- package/dist/PostgresMigrator-C_QQ6q35.d.mts.map +0 -1
- package/dist/PostgresMigrator-CeYy-eHF.d.cts.map +0 -1
- package/dist/PostgresMigrator-DVAY04qN.mjs +0 -166
- package/dist/PostgresMigrator-DVAY04qN.mjs.map +0 -1
- package/dist/PostgresMigrator-M9jpzOvN.cjs +0 -172
- package/dist/PostgresMigrator-M9jpzOvN.cjs.map +0 -1
- package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts +0 -79
- package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts.map +0 -1
- package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts +0 -79
- package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts.map +0 -1
- package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs +0 -123
- package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs.map +0 -1
- package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs +0 -118
- package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-1Saieke7.mjs +0 -67
- package/dist/VitestKyselyTransactionIsolator-1Saieke7.mjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-BjJSXryR.cjs +0 -72
- package/dist/VitestKyselyTransactionIsolator-BjJSXryR.cjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-CwlTo6yf.d.mts +0 -64
- package/dist/VitestKyselyTransactionIsolator-CwlTo6yf.d.mts.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-DJasVuIZ.d.cts +0 -64
- package/dist/VitestKyselyTransactionIsolator-DJasVuIZ.d.cts.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-B_VSWFum.mjs +0 -63
- package/dist/VitestObjectionTransactionIsolator-B_VSWFum.mjs.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-CTTjvTPO.d.cts +0 -60
- package/dist/VitestObjectionTransactionIsolator-CTTjvTPO.d.cts.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-CyZG6nq4.d.mts +0 -60
- package/dist/VitestObjectionTransactionIsolator-CyZG6nq4.d.mts.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-DDoJTu7e.cjs +0 -68
- package/dist/VitestObjectionTransactionIsolator-DDoJTu7e.cjs.map +0 -1
- package/dist/VitestTransactionIsolator-BLaw80cx.d.mts +0 -223
- package/dist/VitestTransactionIsolator-BLaw80cx.d.mts.map +0 -1
- package/dist/VitestTransactionIsolator-CvwPecpl.mjs +0 -188
- package/dist/VitestTransactionIsolator-CvwPecpl.mjs.map +0 -1
- package/dist/VitestTransactionIsolator-DyiX-QtK.cjs +0 -206
- package/dist/VitestTransactionIsolator-DyiX-QtK.cjs.map +0 -1
- package/dist/VitestTransactionIsolator-glcxyS_R.d.cts +0 -223
- package/dist/VitestTransactionIsolator-glcxyS_R.d.cts.map +0 -1
- package/dist/directory-BxjqmtCT.mjs +0 -27
- package/dist/directory-BxjqmtCT.mjs.map +0 -1
- package/dist/directory-DD_xQoSh.cjs +0 -33
- package/dist/directory-DD_xQoSh.cjs.map +0 -1
- package/dist/directory-DiQ_DkaF.d.mts +0 -13
- package/dist/directory-DiQ_DkaF.d.mts.map +0 -1
- package/dist/directory-zIEh5ZPl.d.cts +0 -13
- package/dist/directory-zIEh5ZPl.d.cts.map +0 -1
- package/dist/faker-B14IEMIN.cjs +0 -304
- package/dist/faker-B14IEMIN.cjs.map +0 -1
- package/dist/faker-B6bmbGCM.d.mts +0 -166
- package/dist/faker-B6bmbGCM.d.mts.map +0 -1
- package/dist/faker-BGKYFoCT.mjs +0 -262
- package/dist/faker-BGKYFoCT.mjs.map +0 -1
- package/dist/faker-DvxiCtxc.d.cts +0 -166
- package/dist/faker-DvxiCtxc.d.cts.map +0 -1
|
@@ -1,4 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_VitestTransactionIsolator = require("./VitestTransactionIsolator.cjs");
|
|
3
|
+
//#region src/VitestKyselyTransactionIsolator.ts
|
|
4
|
+
/**
|
|
5
|
+
* Kysely-specific implementation of the Vitest transaction isolator.
|
|
6
|
+
* Provides automatic transaction rollback for test isolation using Kysely's transaction API.
|
|
7
|
+
* Each test runs within a database transaction that is rolled back after completion,
|
|
8
|
+
* ensuring a clean state between tests without the overhead of recreating data.
|
|
9
|
+
*
|
|
10
|
+
* @template Database - The database schema type
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';
|
|
15
|
+
* import { db } from './database';
|
|
16
|
+
*
|
|
17
|
+
* // Create isolator instance
|
|
18
|
+
* const isolator = new VitestKyselyTransactionIsolator<Database>();
|
|
19
|
+
*
|
|
20
|
+
* // In your test setup
|
|
21
|
+
* beforeEach(async () => {
|
|
22
|
+
* await isolator.start(db);
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* afterEach(async () => {
|
|
26
|
+
* await isolator.rollback();
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Tests run in isolated transactions
|
|
30
|
+
* it('should create user', async () => {
|
|
31
|
+
* const user = await db.insertInto('users')
|
|
32
|
+
* .values({ name: 'Test User' })
|
|
33
|
+
* .returningAll()
|
|
34
|
+
* .executeTakeFirst();
|
|
35
|
+
*
|
|
36
|
+
* expect(user).toBeDefined();
|
|
37
|
+
* // This data will be rolled back after the test
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
var VitestKyselyTransactionIsolator = class extends require_VitestTransactionIsolator.VitestPostgresTransactionIsolator {
|
|
42
|
+
/**
|
|
43
|
+
* Closes the pool. Safe to implement now that it runs in the file's
|
|
44
|
+
* teardown rather than after every test, where it would have closed the
|
|
45
|
+
* connection the next test was about to use.
|
|
46
|
+
*/
|
|
47
|
+
async destroy(conn) {
|
|
48
|
+
return conn.destroy();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a Kysely transaction with the specified isolation level.
|
|
52
|
+
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
53
|
+
*
|
|
54
|
+
* @param conn - The Kysely database connection
|
|
55
|
+
* @param level - The transaction isolation level
|
|
56
|
+
* @param fn - The function to execute within the transaction
|
|
57
|
+
* @returns Promise that resolves when the transaction completes
|
|
58
|
+
*/
|
|
59
|
+
async transact(conn, level, fn) {
|
|
60
|
+
const isolationLevel = level.toLocaleLowerCase();
|
|
61
|
+
await conn.transaction().setIsolationLevel(isolationLevel).execute(fn);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
exports.VitestKyselyTransactionIsolator = VitestKyselyTransactionIsolator;
|
|
3
66
|
|
|
4
|
-
|
|
67
|
+
//# sourceMappingURL=VitestKyselyTransactionIsolator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestKyselyTransactionIsolator.cjs","names":["VitestPostgresTransactionIsolator"],"sources":["../src/VitestKyselyTransactionIsolator.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport {\n\ttype IsolationLevel,\n\tVitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Kysely's transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @template Database - The database schema type\n *\n * @example\n * ```typescript\n * import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';\n * import { db } from './database';\n *\n * // Create isolator instance\n * const isolator = new VitestKyselyTransactionIsolator<Database>();\n *\n * // In your test setup\n * beforeEach(async () => {\n * await isolator.start(db);\n * });\n *\n * afterEach(async () => {\n * await isolator.rollback();\n * });\n *\n * // Tests run in isolated transactions\n * it('should create user', async () => {\n * const user = await db.insertInto('users')\n * .values({ name: 'Test User' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestKyselyTransactionIsolator<\n\tDatabase,\n> extends VitestPostgresTransactionIsolator<\n\tKysely<Database>,\n\tTransaction<Database>\n> {\n\t/**\n\t * Closes the pool. Safe to implement now that it runs in the file's\n\t * teardown rather than after every test, where it would have closed the\n\t * connection the next test was about to use.\n\t */\n\tasync destroy(conn: Kysely<Database>): Promise<void> {\n\t\treturn conn.destroy();\n\t}\n\t/**\n\t * Creates a Kysely transaction with the specified isolation level.\n\t * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n\t *\n\t * @param conn - The Kysely database connection\n\t * @param level - The transaction isolation level\n\t * @param fn - The function to execute within the transaction\n\t * @returns Promise that resolves when the transaction completes\n\t */\n\tasync transact(\n\t\tconn: Kysely<Database>,\n\t\tlevel: IsolationLevel,\n\t\tfn: (trx: Transaction<Database>) => Promise<void>,\n\t): Promise<void> {\n\t\tconst isolationLevel =\n\t\t\tlevel.toLocaleLowerCase() as Lowercase<IsolationLevel>;\n\t\tawait conn.transaction().setIsolationLevel(isolationLevel).execute(fn);\n\t}\n\t// Implement any Kysely-specific transaction logic here\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,kCAAb,cAEUA,kCAAAA,kCAGR;;;;;;CAMD,MAAM,QAAQ,MAAuC;EACpD,OAAO,KAAK,QAAQ;CACrB;;;;;;;;;;CAUA,MAAM,SACL,MACA,OACA,IACgB;EAChB,MAAM,iBACL,MAAM,kBAAkB;EACzB,MAAM,KAAK,YAAY,CAAC,CAAC,kBAAkB,cAAc,CAAC,CAAC,QAAQ,EAAE;CACtE;AAED"}
|
|
@@ -1,3 +1,60 @@
|
|
|
1
|
-
import "./VitestTransactionIsolator
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator.cjs";
|
|
2
|
+
import { Kysely, Transaction } from "kysely";
|
|
3
|
+
//#region src/VitestKyselyTransactionIsolator.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Kysely-specific implementation of the Vitest transaction isolator.
|
|
6
|
+
* Provides automatic transaction rollback for test isolation using Kysely's transaction API.
|
|
7
|
+
* Each test runs within a database transaction that is rolled back after completion,
|
|
8
|
+
* ensuring a clean state between tests without the overhead of recreating data.
|
|
9
|
+
*
|
|
10
|
+
* @template Database - The database schema type
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';
|
|
15
|
+
* import { db } from './database';
|
|
16
|
+
*
|
|
17
|
+
* // Create isolator instance
|
|
18
|
+
* const isolator = new VitestKyselyTransactionIsolator<Database>();
|
|
19
|
+
*
|
|
20
|
+
* // In your test setup
|
|
21
|
+
* beforeEach(async () => {
|
|
22
|
+
* await isolator.start(db);
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* afterEach(async () => {
|
|
26
|
+
* await isolator.rollback();
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Tests run in isolated transactions
|
|
30
|
+
* it('should create user', async () => {
|
|
31
|
+
* const user = await db.insertInto('users')
|
|
32
|
+
* .values({ name: 'Test User' })
|
|
33
|
+
* .returningAll()
|
|
34
|
+
* .executeTakeFirst();
|
|
35
|
+
*
|
|
36
|
+
* expect(user).toBeDefined();
|
|
37
|
+
* // This data will be rolled back after the test
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare class VitestKyselyTransactionIsolator<Database> extends VitestPostgresTransactionIsolator<Kysely<Database>, Transaction<Database>> {
|
|
42
|
+
/**
|
|
43
|
+
* Closes the pool. Safe to implement now that it runs in the file's
|
|
44
|
+
* teardown rather than after every test, where it would have closed the
|
|
45
|
+
* connection the next test was about to use.
|
|
46
|
+
*/
|
|
47
|
+
destroy(conn: Kysely<Database>): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Creates a Kysely transaction with the specified isolation level.
|
|
50
|
+
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
51
|
+
*
|
|
52
|
+
* @param conn - The Kysely database connection
|
|
53
|
+
* @param level - The transaction isolation level
|
|
54
|
+
* @param fn - The function to execute within the transaction
|
|
55
|
+
* @returns Promise that resolves when the transaction completes
|
|
56
|
+
*/
|
|
57
|
+
transact(conn: Kysely<Database>, level: IsolationLevel, fn: (trx: Transaction<Database>) => Promise<void>): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//# sourceMappingURL=VitestKyselyTransactionIsolator.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestKyselyTransactionIsolator.d.cts","names":[],"sources":["../src/VitestKyselyTransactionIsolator.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA2Ca,gCACZ,kBACS,kCACT,OAAO,WACP,YAAY;;;;;;EAON,QAAQ,MAAM,OAAO,YAAY;;;;;;;;;;EAYjC,SACL,MAAM,OAAO,WACb,OAAO,gBACP,KAAK,KAAK,YAAY,cAAc,gBAClC"}
|
|
@@ -1,3 +1,60 @@
|
|
|
1
|
-
import "./VitestTransactionIsolator
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator.mjs";
|
|
2
|
+
import { Kysely, Transaction } from "kysely";
|
|
3
|
+
//#region src/VitestKyselyTransactionIsolator.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Kysely-specific implementation of the Vitest transaction isolator.
|
|
6
|
+
* Provides automatic transaction rollback for test isolation using Kysely's transaction API.
|
|
7
|
+
* Each test runs within a database transaction that is rolled back after completion,
|
|
8
|
+
* ensuring a clean state between tests without the overhead of recreating data.
|
|
9
|
+
*
|
|
10
|
+
* @template Database - The database schema type
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';
|
|
15
|
+
* import { db } from './database';
|
|
16
|
+
*
|
|
17
|
+
* // Create isolator instance
|
|
18
|
+
* const isolator = new VitestKyselyTransactionIsolator<Database>();
|
|
19
|
+
*
|
|
20
|
+
* // In your test setup
|
|
21
|
+
* beforeEach(async () => {
|
|
22
|
+
* await isolator.start(db);
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* afterEach(async () => {
|
|
26
|
+
* await isolator.rollback();
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Tests run in isolated transactions
|
|
30
|
+
* it('should create user', async () => {
|
|
31
|
+
* const user = await db.insertInto('users')
|
|
32
|
+
* .values({ name: 'Test User' })
|
|
33
|
+
* .returningAll()
|
|
34
|
+
* .executeTakeFirst();
|
|
35
|
+
*
|
|
36
|
+
* expect(user).toBeDefined();
|
|
37
|
+
* // This data will be rolled back after the test
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare class VitestKyselyTransactionIsolator<Database> extends VitestPostgresTransactionIsolator<Kysely<Database>, Transaction<Database>> {
|
|
42
|
+
/**
|
|
43
|
+
* Closes the pool. Safe to implement now that it runs in the file's
|
|
44
|
+
* teardown rather than after every test, where it would have closed the
|
|
45
|
+
* connection the next test was about to use.
|
|
46
|
+
*/
|
|
47
|
+
destroy(conn: Kysely<Database>): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Creates a Kysely transaction with the specified isolation level.
|
|
50
|
+
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
51
|
+
*
|
|
52
|
+
* @param conn - The Kysely database connection
|
|
53
|
+
* @param level - The transaction isolation level
|
|
54
|
+
* @param fn - The function to execute within the transaction
|
|
55
|
+
* @returns Promise that resolves when the transaction completes
|
|
56
|
+
*/
|
|
57
|
+
transact(conn: Kysely<Database>, level: IsolationLevel, fn: (trx: Transaction<Database>) => Promise<void>): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//# sourceMappingURL=VitestKyselyTransactionIsolator.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestKyselyTransactionIsolator.d.mts","names":[],"sources":["../src/VitestKyselyTransactionIsolator.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA2Ca,gCACZ,kBACS,kCACT,OAAO,WACP,YAAY;;;;;;EAON,QAAQ,MAAM,OAAO,YAAY;;;;;;;;;;EAYjC,SACL,MAAM,OAAO,WACb,OAAO,gBACP,KAAK,KAAK,YAAY,cAAc,gBAClC"}
|
|
@@ -1,4 +1,66 @@
|
|
|
1
|
-
import "./VitestTransactionIsolator
|
|
2
|
-
|
|
1
|
+
import { VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator.mjs";
|
|
2
|
+
//#region src/VitestKyselyTransactionIsolator.ts
|
|
3
|
+
/**
|
|
4
|
+
* Kysely-specific implementation of the Vitest transaction isolator.
|
|
5
|
+
* Provides automatic transaction rollback for test isolation using Kysely's transaction API.
|
|
6
|
+
* Each test runs within a database transaction that is rolled back after completion,
|
|
7
|
+
* ensuring a clean state between tests without the overhead of recreating data.
|
|
8
|
+
*
|
|
9
|
+
* @template Database - The database schema type
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';
|
|
14
|
+
* import { db } from './database';
|
|
15
|
+
*
|
|
16
|
+
* // Create isolator instance
|
|
17
|
+
* const isolator = new VitestKyselyTransactionIsolator<Database>();
|
|
18
|
+
*
|
|
19
|
+
* // In your test setup
|
|
20
|
+
* beforeEach(async () => {
|
|
21
|
+
* await isolator.start(db);
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* afterEach(async () => {
|
|
25
|
+
* await isolator.rollback();
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* // Tests run in isolated transactions
|
|
29
|
+
* it('should create user', async () => {
|
|
30
|
+
* const user = await db.insertInto('users')
|
|
31
|
+
* .values({ name: 'Test User' })
|
|
32
|
+
* .returningAll()
|
|
33
|
+
* .executeTakeFirst();
|
|
34
|
+
*
|
|
35
|
+
* expect(user).toBeDefined();
|
|
36
|
+
* // This data will be rolled back after the test
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
var VitestKyselyTransactionIsolator = class extends VitestPostgresTransactionIsolator {
|
|
41
|
+
/**
|
|
42
|
+
* Closes the pool. Safe to implement now that it runs in the file's
|
|
43
|
+
* teardown rather than after every test, where it would have closed the
|
|
44
|
+
* connection the next test was about to use.
|
|
45
|
+
*/
|
|
46
|
+
async destroy(conn) {
|
|
47
|
+
return conn.destroy();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a Kysely transaction with the specified isolation level.
|
|
51
|
+
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
52
|
+
*
|
|
53
|
+
* @param conn - The Kysely database connection
|
|
54
|
+
* @param level - The transaction isolation level
|
|
55
|
+
* @param fn - The function to execute within the transaction
|
|
56
|
+
* @returns Promise that resolves when the transaction completes
|
|
57
|
+
*/
|
|
58
|
+
async transact(conn, level, fn) {
|
|
59
|
+
const isolationLevel = level.toLocaleLowerCase();
|
|
60
|
+
await conn.transaction().setIsolationLevel(isolationLevel).execute(fn);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { VitestKyselyTransactionIsolator };
|
|
3
65
|
|
|
4
|
-
|
|
66
|
+
//# sourceMappingURL=VitestKyselyTransactionIsolator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestKyselyTransactionIsolator.mjs","names":[],"sources":["../src/VitestKyselyTransactionIsolator.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport {\n\ttype IsolationLevel,\n\tVitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Kysely's transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @template Database - The database schema type\n *\n * @example\n * ```typescript\n * import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';\n * import { db } from './database';\n *\n * // Create isolator instance\n * const isolator = new VitestKyselyTransactionIsolator<Database>();\n *\n * // In your test setup\n * beforeEach(async () => {\n * await isolator.start(db);\n * });\n *\n * afterEach(async () => {\n * await isolator.rollback();\n * });\n *\n * // Tests run in isolated transactions\n * it('should create user', async () => {\n * const user = await db.insertInto('users')\n * .values({ name: 'Test User' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestKyselyTransactionIsolator<\n\tDatabase,\n> extends VitestPostgresTransactionIsolator<\n\tKysely<Database>,\n\tTransaction<Database>\n> {\n\t/**\n\t * Closes the pool. Safe to implement now that it runs in the file's\n\t * teardown rather than after every test, where it would have closed the\n\t * connection the next test was about to use.\n\t */\n\tasync destroy(conn: Kysely<Database>): Promise<void> {\n\t\treturn conn.destroy();\n\t}\n\t/**\n\t * Creates a Kysely transaction with the specified isolation level.\n\t * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n\t *\n\t * @param conn - The Kysely database connection\n\t * @param level - The transaction isolation level\n\t * @param fn - The function to execute within the transaction\n\t * @returns Promise that resolves when the transaction completes\n\t */\n\tasync transact(\n\t\tconn: Kysely<Database>,\n\t\tlevel: IsolationLevel,\n\t\tfn: (trx: Transaction<Database>) => Promise<void>,\n\t): Promise<void> {\n\t\tconst isolationLevel =\n\t\t\tlevel.toLocaleLowerCase() as Lowercase<IsolationLevel>;\n\t\tawait conn.transaction().setIsolationLevel(isolationLevel).execute(fn);\n\t}\n\t// Implement any Kysely-specific transaction logic here\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,kCAAb,cAEU,kCAGR;;;;;;CAMD,MAAM,QAAQ,MAAuC;EACpD,OAAO,KAAK,QAAQ;CACrB;;;;;;;;;;CAUA,MAAM,SACL,MACA,OACA,IACgB;EAChB,MAAM,iBACL,MAAM,kBAAkB;EACzB,MAAM,KAAK,YAAY,CAAC,CAAC,kBAAkB,cAAc,CAAC,CAAC,QAAQ,EAAE;CACtE;AAED"}
|
|
@@ -1,4 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_VitestTransactionIsolator = require("./VitestTransactionIsolator.cjs");
|
|
3
|
+
//#region src/VitestObjectionTransactionIsolator.ts
|
|
4
|
+
/**
|
|
5
|
+
* Objection.js-specific implementation of the Vitest transaction isolator.
|
|
6
|
+
* Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.
|
|
7
|
+
* Each test runs within a database transaction that is rolled back after completion,
|
|
8
|
+
* ensuring a clean state between tests without the overhead of recreating data.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';
|
|
13
|
+
* import { knex } from './database';
|
|
14
|
+
* import { User } from './models';
|
|
15
|
+
* import { test } from 'vitest';
|
|
16
|
+
*
|
|
17
|
+
* // Create isolator instance
|
|
18
|
+
* const isolator = new VitestObjectionTransactionIsolator(test);
|
|
19
|
+
*
|
|
20
|
+
* // Use with wrapped test API
|
|
21
|
+
* const isolatedTest = isolator.wrapVitestWithTransaction(knex);
|
|
22
|
+
*
|
|
23
|
+
* isolatedTest('should create user', async ({ trx }) => {
|
|
24
|
+
* const user = await User.query(trx)
|
|
25
|
+
* .insert({ name: 'Test User' });
|
|
26
|
+
*
|
|
27
|
+
* expect(user).toBeDefined();
|
|
28
|
+
* // This data will be rolled back after the test
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
var VitestObjectionTransactionIsolator = class extends require_VitestTransactionIsolator.VitestPostgresTransactionIsolator {
|
|
33
|
+
async destroy(_conn) {}
|
|
34
|
+
/**
|
|
35
|
+
* Creates a Knex transaction with the specified isolation level.
|
|
36
|
+
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
37
|
+
* This transaction can be used with Objection.js models via Model.query(trx).
|
|
38
|
+
*
|
|
39
|
+
* @param conn - The Knex database connection
|
|
40
|
+
* @param level - The transaction isolation level
|
|
41
|
+
* @param fn - The function to execute within the transaction
|
|
42
|
+
* @returns Promise that resolves when the transaction completes
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {
|
|
47
|
+
* // Use transaction with Objection models
|
|
48
|
+
* await User.query(trx).insert({ name: 'Test' });
|
|
49
|
+
* await Post.query(trx).where('userId', user.id).delete();
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
async transact(connection, level, fn) {
|
|
54
|
+
const isolationLevel = level.toLowerCase();
|
|
55
|
+
await connection.transaction(async (trx) => {
|
|
56
|
+
await fn(trx);
|
|
57
|
+
}, { isolationLevel });
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
//#endregion
|
|
61
|
+
exports.VitestObjectionTransactionIsolator = VitestObjectionTransactionIsolator;
|
|
3
62
|
|
|
4
|
-
|
|
63
|
+
//# sourceMappingURL=VitestObjectionTransactionIsolator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestObjectionTransactionIsolator.cjs","names":["VitestPostgresTransactionIsolator"],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport {\n\ttype IsolationLevel,\n\tVitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @example\n * ```typescript\n * import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';\n * import { knex } from './database';\n * import { User } from './models';\n * import { test } from 'vitest';\n *\n * // Create isolator instance\n * const isolator = new VitestObjectionTransactionIsolator(test);\n *\n * // Use with wrapped test API\n * const isolatedTest = isolator.wrapVitestWithTransaction(knex);\n *\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User' });\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<\n\tKnex,\n\tKnex.Transaction\n> {\n\tasync destroy(_conn: Knex<any, any[]>): Promise<void> {}\n\t/**\n\t * Creates a Knex transaction with the specified isolation level.\n\t * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n\t * This transaction can be used with Objection.js models via Model.query(trx).\n\t *\n\t * @param conn - The Knex database connection\n\t * @param level - The transaction isolation level\n\t * @param fn - The function to execute within the transaction\n\t * @returns Promise that resolves when the transaction completes\n\t *\n\t * @example\n\t * ```typescript\n\t * await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {\n\t * // Use transaction with Objection models\n\t * await User.query(trx).insert({ name: 'Test' });\n\t * await Post.query(trx).where('userId', user.id).delete();\n\t * });\n\t * ```\n\t */\n\tasync transact(\n\t\tconnection: Knex,\n\t\tlevel: IsolationLevel,\n\t\tfn: (trx: Knex.Transaction) => Promise<void>,\n\t): Promise<void> {\n\t\tconst isolationLevel = level.toLowerCase() as Lowercase<IsolationLevel>;\n\n\t\tawait connection.transaction(\n\t\t\tasync (trx) => {\n\t\t\t\tawait fn(trx);\n\t\t\t},\n\t\t\t{\n\t\t\t\tisolationLevel,\n\t\t\t},\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,qCAAb,cAAwDA,kCAAAA,kCAGtD;CACD,MAAM,QAAQ,OAAwC,CAAC;;;;;;;;;;;;;;;;;;;;CAoBvD,MAAM,SACL,YACA,OACA,IACgB;EAChB,MAAM,iBAAiB,MAAM,YAAY;EAEzC,MAAM,WAAW,YAChB,OAAO,QAAQ;GACd,MAAM,GAAG,GAAG;EACb,GACA,EACC,eACD,CACD;CACD;AACD"}
|
|
@@ -1,3 +1,56 @@
|
|
|
1
|
-
import "./VitestTransactionIsolator
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator.cjs";
|
|
2
|
+
import { Knex } from "knex";
|
|
3
|
+
//#region src/VitestObjectionTransactionIsolator.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Objection.js-specific implementation of the Vitest transaction isolator.
|
|
6
|
+
* Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.
|
|
7
|
+
* Each test runs within a database transaction that is rolled back after completion,
|
|
8
|
+
* ensuring a clean state between tests without the overhead of recreating data.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';
|
|
13
|
+
* import { knex } from './database';
|
|
14
|
+
* import { User } from './models';
|
|
15
|
+
* import { test } from 'vitest';
|
|
16
|
+
*
|
|
17
|
+
* // Create isolator instance
|
|
18
|
+
* const isolator = new VitestObjectionTransactionIsolator(test);
|
|
19
|
+
*
|
|
20
|
+
* // Use with wrapped test API
|
|
21
|
+
* const isolatedTest = isolator.wrapVitestWithTransaction(knex);
|
|
22
|
+
*
|
|
23
|
+
* isolatedTest('should create user', async ({ trx }) => {
|
|
24
|
+
* const user = await User.query(trx)
|
|
25
|
+
* .insert({ name: 'Test User' });
|
|
26
|
+
*
|
|
27
|
+
* expect(user).toBeDefined();
|
|
28
|
+
* // This data will be rolled back after the test
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<Knex, Knex.Transaction> {
|
|
33
|
+
destroy(_conn: Knex<any, any[]>): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a Knex transaction with the specified isolation level.
|
|
36
|
+
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
37
|
+
* This transaction can be used with Objection.js models via Model.query(trx).
|
|
38
|
+
*
|
|
39
|
+
* @param conn - The Knex database connection
|
|
40
|
+
* @param level - The transaction isolation level
|
|
41
|
+
* @param fn - The function to execute within the transaction
|
|
42
|
+
* @returns Promise that resolves when the transaction completes
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {
|
|
47
|
+
* // Use transaction with Objection models
|
|
48
|
+
* await User.query(trx).insert({ name: 'Test' });
|
|
49
|
+
* await Post.query(trx).where('userId', user.id).delete();
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
transact(connection: Knex, level: IsolationLevel, fn: (trx: Knex.Transaction) => Promise<void>): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//# sourceMappingURL=VitestObjectionTransactionIsolator.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestObjectionTransactionIsolator.d.cts","names":[],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAkCa,2CAA2C,kCACvD,MACA,KAAK;EAEC,QAAQ,OAAO,mBAAmB;;;;;;;;;;;;;;;;;;;;EAoBlC,SACL,YAAY,MACZ,OAAO,gBACP,KAAK,KAAK,KAAK,gBAAgB,gBAC7B"}
|
|
@@ -1,3 +1,56 @@
|
|
|
1
|
-
import "./VitestTransactionIsolator
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator.mjs";
|
|
2
|
+
import { Knex } from "knex";
|
|
3
|
+
//#region src/VitestObjectionTransactionIsolator.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Objection.js-specific implementation of the Vitest transaction isolator.
|
|
6
|
+
* Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.
|
|
7
|
+
* Each test runs within a database transaction that is rolled back after completion,
|
|
8
|
+
* ensuring a clean state between tests without the overhead of recreating data.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';
|
|
13
|
+
* import { knex } from './database';
|
|
14
|
+
* import { User } from './models';
|
|
15
|
+
* import { test } from 'vitest';
|
|
16
|
+
*
|
|
17
|
+
* // Create isolator instance
|
|
18
|
+
* const isolator = new VitestObjectionTransactionIsolator(test);
|
|
19
|
+
*
|
|
20
|
+
* // Use with wrapped test API
|
|
21
|
+
* const isolatedTest = isolator.wrapVitestWithTransaction(knex);
|
|
22
|
+
*
|
|
23
|
+
* isolatedTest('should create user', async ({ trx }) => {
|
|
24
|
+
* const user = await User.query(trx)
|
|
25
|
+
* .insert({ name: 'Test User' });
|
|
26
|
+
*
|
|
27
|
+
* expect(user).toBeDefined();
|
|
28
|
+
* // This data will be rolled back after the test
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<Knex, Knex.Transaction> {
|
|
33
|
+
destroy(_conn: Knex<any, any[]>): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a Knex transaction with the specified isolation level.
|
|
36
|
+
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
37
|
+
* This transaction can be used with Objection.js models via Model.query(trx).
|
|
38
|
+
*
|
|
39
|
+
* @param conn - The Knex database connection
|
|
40
|
+
* @param level - The transaction isolation level
|
|
41
|
+
* @param fn - The function to execute within the transaction
|
|
42
|
+
* @returns Promise that resolves when the transaction completes
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {
|
|
47
|
+
* // Use transaction with Objection models
|
|
48
|
+
* await User.query(trx).insert({ name: 'Test' });
|
|
49
|
+
* await Post.query(trx).where('userId', user.id).delete();
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
transact(connection: Knex, level: IsolationLevel, fn: (trx: Knex.Transaction) => Promise<void>): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//# sourceMappingURL=VitestObjectionTransactionIsolator.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestObjectionTransactionIsolator.d.mts","names":[],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAkCa,2CAA2C,kCACvD,MACA,KAAK;EAEC,QAAQ,OAAO,mBAAmB;;;;;;;;;;;;;;;;;;;;EAoBlC,SACL,YAAY,MACZ,OAAO,gBACP,KAAK,KAAK,KAAK,gBAAgB,gBAC7B"}
|
|
@@ -1,4 +1,62 @@
|
|
|
1
|
-
import "./VitestTransactionIsolator
|
|
2
|
-
|
|
1
|
+
import { VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator.mjs";
|
|
2
|
+
//#region src/VitestObjectionTransactionIsolator.ts
|
|
3
|
+
/**
|
|
4
|
+
* Objection.js-specific implementation of the Vitest transaction isolator.
|
|
5
|
+
* Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.
|
|
6
|
+
* Each test runs within a database transaction that is rolled back after completion,
|
|
7
|
+
* ensuring a clean state between tests without the overhead of recreating data.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';
|
|
12
|
+
* import { knex } from './database';
|
|
13
|
+
* import { User } from './models';
|
|
14
|
+
* import { test } from 'vitest';
|
|
15
|
+
*
|
|
16
|
+
* // Create isolator instance
|
|
17
|
+
* const isolator = new VitestObjectionTransactionIsolator(test);
|
|
18
|
+
*
|
|
19
|
+
* // Use with wrapped test API
|
|
20
|
+
* const isolatedTest = isolator.wrapVitestWithTransaction(knex);
|
|
21
|
+
*
|
|
22
|
+
* isolatedTest('should create user', async ({ trx }) => {
|
|
23
|
+
* const user = await User.query(trx)
|
|
24
|
+
* .insert({ name: 'Test User' });
|
|
25
|
+
*
|
|
26
|
+
* expect(user).toBeDefined();
|
|
27
|
+
* // This data will be rolled back after the test
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
var VitestObjectionTransactionIsolator = class extends VitestPostgresTransactionIsolator {
|
|
32
|
+
async destroy(_conn) {}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a Knex transaction with the specified isolation level.
|
|
35
|
+
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
36
|
+
* This transaction can be used with Objection.js models via Model.query(trx).
|
|
37
|
+
*
|
|
38
|
+
* @param conn - The Knex database connection
|
|
39
|
+
* @param level - The transaction isolation level
|
|
40
|
+
* @param fn - The function to execute within the transaction
|
|
41
|
+
* @returns Promise that resolves when the transaction completes
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {
|
|
46
|
+
* // Use transaction with Objection models
|
|
47
|
+
* await User.query(trx).insert({ name: 'Test' });
|
|
48
|
+
* await Post.query(trx).where('userId', user.id).delete();
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
async transact(connection, level, fn) {
|
|
53
|
+
const isolationLevel = level.toLowerCase();
|
|
54
|
+
await connection.transaction(async (trx) => {
|
|
55
|
+
await fn(trx);
|
|
56
|
+
}, { isolationLevel });
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
export { VitestObjectionTransactionIsolator };
|
|
3
61
|
|
|
4
|
-
|
|
62
|
+
//# sourceMappingURL=VitestObjectionTransactionIsolator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestObjectionTransactionIsolator.mjs","names":[],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport {\n\ttype IsolationLevel,\n\tVitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @example\n * ```typescript\n * import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';\n * import { knex } from './database';\n * import { User } from './models';\n * import { test } from 'vitest';\n *\n * // Create isolator instance\n * const isolator = new VitestObjectionTransactionIsolator(test);\n *\n * // Use with wrapped test API\n * const isolatedTest = isolator.wrapVitestWithTransaction(knex);\n *\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User' });\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<\n\tKnex,\n\tKnex.Transaction\n> {\n\tasync destroy(_conn: Knex<any, any[]>): Promise<void> {}\n\t/**\n\t * Creates a Knex transaction with the specified isolation level.\n\t * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n\t * This transaction can be used with Objection.js models via Model.query(trx).\n\t *\n\t * @param conn - The Knex database connection\n\t * @param level - The transaction isolation level\n\t * @param fn - The function to execute within the transaction\n\t * @returns Promise that resolves when the transaction completes\n\t *\n\t * @example\n\t * ```typescript\n\t * await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {\n\t * // Use transaction with Objection models\n\t * await User.query(trx).insert({ name: 'Test' });\n\t * await Post.query(trx).where('userId', user.id).delete();\n\t * });\n\t * ```\n\t */\n\tasync transact(\n\t\tconnection: Knex,\n\t\tlevel: IsolationLevel,\n\t\tfn: (trx: Knex.Transaction) => Promise<void>,\n\t): Promise<void> {\n\t\tconst isolationLevel = level.toLowerCase() as Lowercase<IsolationLevel>;\n\n\t\tawait connection.transaction(\n\t\t\tasync (trx) => {\n\t\t\t\tawait fn(trx);\n\t\t\t},\n\t\t\t{\n\t\t\t\tisolationLevel,\n\t\t\t},\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,qCAAb,cAAwD,kCAGtD;CACD,MAAM,QAAQ,OAAwC,CAAC;;;;;;;;;;;;;;;;;;;;CAoBvD,MAAM,SACL,YACA,OACA,IACgB;EAChB,MAAM,iBAAiB,MAAM,YAAY;EAEzC,MAAM,WAAW,YAChB,OAAO,QAAQ;GACd,MAAM,GAAG,GAAG;EACb,GACA,EACC,eACD,CACD;CACD;AACD"}
|