@geekmidas/testkit 0.4.0 → 1.0.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.
- package/CHANGELOG.md +13 -0
- package/dist/Factory-BFVnMMCC.mjs.map +1 -1
- package/dist/{Factory-c16c27Y6.d.cts → Factory-BOX312yd.d.cts} +3 -2
- package/dist/Factory-BOX312yd.d.cts.map +1 -0
- package/dist/Factory-BhjUOBWN.cjs.map +1 -1
- package/dist/{Factory-BcGJjLc8.d.mts → Factory-SFupxRC2.d.mts} +2 -1
- package/dist/Factory-SFupxRC2.d.mts.map +1 -0
- package/dist/Factory.d.cts +2 -2
- package/dist/Factory.d.mts +1 -1
- package/dist/KyselyFactory-BFqVIn_0.cjs.map +1 -1
- package/dist/KyselyFactory-DMswpwji.mjs.map +1 -1
- package/dist/{KyselyFactory-uZ45h7YU.d.cts → KyselyFactory-Dy5zzV4B.d.cts} +4 -3
- package/dist/KyselyFactory-Dy5zzV4B.d.cts.map +1 -0
- package/dist/{KyselyFactory-Cj-EultY.d.mts → KyselyFactory-vAxYodck.d.mts} +3 -2
- package/dist/KyselyFactory-vAxYodck.d.mts.map +1 -0
- package/dist/KyselyFactory.d.cts +3 -3
- package/dist/KyselyFactory.d.mts +2 -2
- package/dist/{ObjectionFactory-DL4qkuF1.d.mts → ObjectionFactory-BWjB49-i.d.mts} +3 -2
- package/dist/ObjectionFactory-BWjB49-i.d.mts.map +1 -0
- package/dist/ObjectionFactory-BeFBYcan.cjs.map +1 -1
- package/dist/{ObjectionFactory-CdhzKs4f.d.cts → ObjectionFactory-CD-WFuMJ.d.cts} +4 -3
- package/dist/ObjectionFactory-CD-WFuMJ.d.cts.map +1 -0
- package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +1 -1
- package/dist/ObjectionFactory.d.cts +3 -3
- package/dist/ObjectionFactory.d.mts +2 -2
- package/dist/{PostgresKyselyMigrator-upT-hmrz.mjs → PostgresKyselyMigrator-6sE1KOni.mjs} +2 -2
- package/dist/PostgresKyselyMigrator-6sE1KOni.mjs.map +1 -0
- package/dist/{PostgresKyselyMigrator-CIx3AFSR.d.mts → PostgresKyselyMigrator-CBltSOq5.d.cts} +3 -2
- package/dist/PostgresKyselyMigrator-CBltSOq5.d.cts.map +1 -0
- package/dist/{PostgresKyselyMigrator-CfytARcA.cjs → PostgresKyselyMigrator-D6IbPq8t.cjs} +2 -2
- package/dist/PostgresKyselyMigrator-D6IbPq8t.cjs.map +1 -0
- package/dist/{PostgresKyselyMigrator-CQ3aUoy_.d.cts → PostgresKyselyMigrator-DrVWncqd.d.mts} +3 -2
- package/dist/PostgresKyselyMigrator-DrVWncqd.d.mts.map +1 -0
- package/dist/PostgresKyselyMigrator.cjs +2 -2
- package/dist/PostgresKyselyMigrator.d.cts +2 -2
- package/dist/PostgresKyselyMigrator.d.mts +2 -2
- package/dist/PostgresKyselyMigrator.mjs +2 -2
- package/dist/{PostgresMigrator-DbuJGAVy.mjs → PostgresMigrator-BjjenqSd.mjs} +2 -2
- package/dist/PostgresMigrator-BjjenqSd.mjs.map +1 -0
- package/dist/{PostgresMigrator-D5UkK1_K.d.cts → PostgresMigrator-Bres0U6E.d.cts} +2 -1
- package/dist/PostgresMigrator-Bres0U6E.d.cts.map +1 -0
- package/dist/{PostgresMigrator-DFcNdCvD.cjs → PostgresMigrator-D6dQn0x2.cjs} +2 -2
- package/dist/PostgresMigrator-D6dQn0x2.cjs.map +1 -0
- package/dist/{PostgresMigrator-DQaRxoaY.d.mts → PostgresMigrator-S-YYosAC.d.mts} +2 -1
- package/dist/PostgresMigrator-S-YYosAC.d.mts.map +1 -0
- package/dist/PostgresMigrator.cjs +1 -1
- package/dist/PostgresMigrator.d.cts +1 -1
- package/dist/PostgresMigrator.d.mts +1 -1
- package/dist/PostgresMigrator.mjs +1 -1
- package/dist/{PostgresObjectionMigrator-CZHHcCOv.d.cts → PostgresObjectionMigrator-CPfBAP7r.d.cts} +3 -2
- package/dist/PostgresObjectionMigrator-CPfBAP7r.d.cts.map +1 -0
- package/dist/{PostgresObjectionMigrator-BG6ymgnt.cjs → PostgresObjectionMigrator-DK8ODIHQ.cjs} +2 -2
- package/dist/PostgresObjectionMigrator-DK8ODIHQ.cjs.map +1 -0
- package/dist/{PostgresObjectionMigrator-D_hCcrQu.d.mts → PostgresObjectionMigrator-DVEqB5tp.d.mts} +3 -2
- package/dist/PostgresObjectionMigrator-DVEqB5tp.d.mts.map +1 -0
- package/dist/{PostgresObjectionMigrator-DPj2pOpX.mjs → PostgresObjectionMigrator-D_QxXbIN.mjs} +2 -2
- package/dist/PostgresObjectionMigrator-D_QxXbIN.mjs.map +1 -0
- package/dist/PostgresObjectionMigrator.cjs +2 -2
- package/dist/PostgresObjectionMigrator.d.cts +2 -2
- package/dist/PostgresObjectionMigrator.d.mts +2 -2
- package/dist/PostgresObjectionMigrator.mjs +2 -2
- package/dist/{VitestKyselyTransactionIsolator-D3EZZhjZ.d.cts → VitestKyselyTransactionIsolator-CduJlHoT.d.cts} +4 -3
- package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-Dxlp1u0f.d.mts → VitestKyselyTransactionIsolator-Cswnnj0k.d.mts} +4 -3
- package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-EvDLk5zg.cjs → VitestKyselyTransactionIsolator-D7RRXOBa.cjs} +2 -2
- package/dist/VitestKyselyTransactionIsolator-D7RRXOBa.cjs.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-CNURW8y6.mjs → VitestKyselyTransactionIsolator-DceyIqr4.mjs} +2 -2
- package/dist/VitestKyselyTransactionIsolator-DceyIqr4.mjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator.cjs +1 -1
- package/dist/VitestKyselyTransactionIsolator.d.cts +2 -2
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestKyselyTransactionIsolator.mjs +1 -1
- package/dist/{VitestObjectionTransactionIsolator-1TpsPqfG.d.cts → VitestObjectionTransactionIsolator-BXoR6xdG.d.cts} +4 -3
- package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-CM5KTAFA.cjs → VitestObjectionTransactionIsolator-CdLRrzNf.cjs} +2 -2
- package/dist/VitestObjectionTransactionIsolator-CdLRrzNf.cjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-jQFaCz0u.mjs → VitestObjectionTransactionIsolator-OF2osYY5.mjs} +2 -2
- package/dist/VitestObjectionTransactionIsolator-OF2osYY5.mjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-i9jIgU8Q.d.mts → VitestObjectionTransactionIsolator-x6hY5j4u.d.mts} +4 -3
- package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts.map +1 -0
- package/dist/VitestObjectionTransactionIsolator.cjs +1 -1
- package/dist/VitestObjectionTransactionIsolator.d.cts +2 -2
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator.mjs +1 -1
- package/dist/{VitestTransactionIsolator-BvR19bYn.d.mts → VitestTransactionIsolator-BNWJqh9f.d.mts} +3 -2
- package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts.map +1 -0
- package/dist/VitestTransactionIsolator-CMfJXZP8.cjs.map +1 -1
- package/dist/{VitestTransactionIsolator-CwQaxZLP.d.cts → VitestTransactionIsolator-CSroc7Df.d.cts} +3 -2
- package/dist/VitestTransactionIsolator-CSroc7Df.d.cts.map +1 -0
- package/dist/VitestTransactionIsolator-DQ7tLqgV.mjs.map +1 -1
- package/dist/VitestTransactionIsolator.d.cts +1 -1
- package/dist/VitestTransactionIsolator.d.mts +1 -1
- package/dist/aws.cjs.map +1 -1
- package/dist/aws.d.cts +2 -0
- package/dist/aws.d.cts.map +1 -0
- package/dist/aws.d.mts +2 -0
- package/dist/aws.d.mts.map +1 -0
- package/dist/aws.mjs.map +1 -1
- package/dist/benchmark.cjs.map +1 -1
- package/dist/benchmark.d.cts +1 -0
- package/dist/benchmark.d.cts.map +1 -0
- package/dist/benchmark.d.mts +1 -0
- package/dist/benchmark.d.mts.map +1 -0
- package/dist/benchmark.mjs.map +1 -1
- package/dist/better-auth.cjs +29 -30
- package/dist/better-auth.cjs.map +1 -1
- package/dist/better-auth.d.cts +2 -2
- package/dist/better-auth.d.cts.map +1 -0
- package/dist/better-auth.d.mts.map +1 -0
- package/dist/better-auth.mjs +29 -30
- package/dist/better-auth.mjs.map +1 -1
- package/dist/directory-B-Ozljzk.mjs.map +1 -1
- package/dist/directory-BVC8g7cX.cjs.map +1 -1
- package/dist/{directory-BXavAeJZ.d.mts → directory-CVrfTq1I.d.mts} +2 -1
- package/dist/directory-CVrfTq1I.d.mts.map +1 -0
- package/dist/{directory-Mi7tdOuD.d.cts → directory-DAnMWi50.d.cts} +2 -1
- package/dist/directory-DAnMWi50.d.cts.map +1 -0
- package/dist/faker-B14IEMIN.cjs.map +1 -1
- package/dist/faker-BGKYFoCT.mjs.map +1 -1
- package/dist/{faker-DvxiCtxc.d.cts → faker-Cg76aFNO.d.cts} +3 -3
- package/dist/faker-Cg76aFNO.d.cts.map +1 -0
- package/dist/faker-DHh7xs4u.d.mts.map +1 -0
- package/dist/faker.d.cts +1 -1
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +1 -0
- package/dist/helpers.d.cts.map +1 -0
- package/dist/helpers.d.mts +1 -0
- package/dist/helpers.d.mts.map +1 -0
- package/dist/helpers.mjs.map +1 -1
- package/dist/kysely.cjs +3 -3
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +8 -7
- package/dist/kysely.d.cts.map +1 -0
- package/dist/kysely.d.mts +7 -6
- package/dist/kysely.d.mts.map +1 -0
- package/dist/kysely.mjs +3 -3
- package/dist/kysely.mjs.map +1 -1
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +1 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +1 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs.map +1 -1
- package/dist/objection.cjs +3 -3
- package/dist/objection.cjs.map +1 -1
- package/dist/objection.d.cts +8 -7
- package/dist/objection.d.cts.map +1 -0
- package/dist/objection.d.mts +7 -6
- package/dist/objection.d.mts.map +1 -0
- package/dist/objection.mjs +3 -3
- package/dist/objection.mjs.map +1 -1
- package/dist/os/directory.d.cts +1 -1
- package/dist/os/directory.d.mts +1 -1
- package/dist/os/index.d.cts +1 -1
- package/dist/os/index.d.mts +1 -1
- package/dist/timer.cjs.map +1 -1
- package/dist/timer.d.cts +2 -0
- package/dist/timer.d.cts.map +1 -0
- package/dist/timer.d.mts +2 -0
- package/dist/timer.d.mts.map +1 -0
- package/dist/timer.mjs.map +1 -1
- package/package.json +5 -5
- package/src/Factory.ts +72 -72
- package/src/KyselyFactory.ts +330 -330
- package/src/ObjectionFactory.ts +354 -355
- package/src/PostgresKyselyMigrator.ts +37 -37
- package/src/PostgresMigrator.ts +107 -107
- package/src/PostgresObjectionMigrator.ts +91 -91
- package/src/VitestKyselyTransactionIsolator.ts +27 -27
- package/src/VitestObjectionTransactionIsolator.ts +39 -39
- package/src/VitestTransactionIsolator.ts +196 -195
- package/src/__tests__/Factory.spec.ts +163 -155
- package/src/__tests__/KyselyFactory.spec.ts +443 -439
- package/src/__tests__/ObjectionFactory.spec.ts +563 -557
- package/src/__tests__/PostgresKyselyMigrator.spec.ts +641 -641
- package/src/__tests__/PostgresMigrator.spec.ts +341 -341
- package/src/__tests__/PostgresObjectionMigrator.spec.ts +578 -578
- package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +114 -114
- package/src/__tests__/benchmark.spec.ts +140 -0
- package/src/__tests__/better-auth.spec.ts +15 -15
- package/src/__tests__/faker.spec.ts +226 -137
- package/src/__tests__/integration.spec.ts +597 -597
- package/src/__tests__/utilities.spec.ts +211 -0
- package/src/aws.ts +104 -104
- package/src/benchmark.ts +12 -12
- package/src/better-auth.ts +286 -301
- package/src/faker.ts +153 -153
- package/src/helpers.ts +6 -6
- package/src/kysely.ts +33 -33
- package/src/logger.ts +10 -10
- package/src/objection.ts +31 -31
- package/src/os/directory.ts +11 -10
- package/src/timer.ts +1 -1
- package/test/globalSetup.ts +45 -45
- package/test/helpers.ts +189 -189
- package/test/migrations/1749664623372_user.ts +13 -13
- package/tsconfig.json +9 -0
- package/vitest.config.ts +4 -4
- package/dist/PostgresKyselyMigrator-CfytARcA.cjs.map +0 -1
- package/dist/PostgresKyselyMigrator-upT-hmrz.mjs.map +0 -1
- package/dist/PostgresMigrator-DFcNdCvD.cjs.map +0 -1
- package/dist/PostgresMigrator-DbuJGAVy.mjs.map +0 -1
- package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs.map +0 -1
- package/dist/PostgresObjectionMigrator-DPj2pOpX.mjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-CNURW8y6.mjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-EvDLk5zg.cjs.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-CM5KTAFA.cjs.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-jQFaCz0u.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-
|
|
1
|
+
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-BNWJqh9f.mjs";
|
|
2
2
|
import { Knex } from "knex";
|
|
3
3
|
|
|
4
4
|
//#region src/VitestObjectionTransactionIsolator.d.ts
|
|
@@ -32,7 +32,7 @@ import { Knex } from "knex";
|
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
34
|
declare class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<Knex, Knex.Transaction> {
|
|
35
|
-
destroy(
|
|
35
|
+
destroy(_conn: Knex<any, any[]>): Promise<void>;
|
|
36
36
|
/**
|
|
37
37
|
* Creates a Knex transaction with the specified isolation level.
|
|
38
38
|
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
@@ -54,6 +54,7 @@ declare class VitestObjectionTransactionIsolator extends VitestPostgresTransacti
|
|
|
54
54
|
*/
|
|
55
55
|
transact(connection: Knex, level: IsolationLevel, fn: (trx: Knex.Transaction) => Promise<void>): Promise<void>;
|
|
56
56
|
}
|
|
57
|
+
//# sourceMappingURL=VitestObjectionTransactionIsolator.d.ts.map
|
|
57
58
|
//#endregion
|
|
58
59
|
export { VitestObjectionTransactionIsolator };
|
|
59
|
-
//# sourceMappingURL=VitestObjectionTransactionIsolator-
|
|
60
|
+
//# sourceMappingURL=VitestObjectionTransactionIsolator-x6hY5j4u.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestObjectionTransactionIsolator-x6hY5j4u.d.mts","names":[],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"sourcesContent":[],"mappings":";;;;;;;AAkCA;;;;;;;;;;;;AAAyF;;;;;;;;;;;;;;cAA5E,kCAAA,SAA2C,kCACvD,MACA,IAAA,CAAK;iBAEgB,mBAAmB;;;;;;;;;;;;;;;;;;;;uBAqB3B,aACL,0BACG,IAAA,CAAK,gBAAgB,gBAC7B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
require('./VitestTransactionIsolator-CMfJXZP8.cjs');
|
|
2
|
-
const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-
|
|
2
|
+
const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-CdLRrzNf.cjs');
|
|
3
3
|
|
|
4
4
|
exports.VitestObjectionTransactionIsolator = require_VitestObjectionTransactionIsolator.VitestObjectionTransactionIsolator;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./VitestTransactionIsolator-
|
|
2
|
-
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-
|
|
1
|
+
import "./VitestTransactionIsolator-CSroc7Df.cjs";
|
|
2
|
+
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-BXoR6xdG.cjs";
|
|
3
3
|
export { VitestObjectionTransactionIsolator };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./VitestTransactionIsolator-
|
|
2
|
-
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-
|
|
1
|
+
import "./VitestTransactionIsolator-BNWJqh9f.mjs";
|
|
2
|
+
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-x6hY5j4u.mjs";
|
|
3
3
|
export { VitestObjectionTransactionIsolator };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "./VitestTransactionIsolator-DQ7tLqgV.mjs";
|
|
2
|
-
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-
|
|
2
|
+
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-OF2osYY5.mjs";
|
|
3
3
|
|
|
4
4
|
export { VitestObjectionTransactionIsolator };
|
package/dist/{VitestTransactionIsolator-BvR19bYn.d.mts → VitestTransactionIsolator-BNWJqh9f.d.mts}
RENAMED
|
@@ -9,7 +9,7 @@ import { TestAPI } from "vitest";
|
|
|
9
9
|
* @template Transaction - The transaction type specific to the database driver
|
|
10
10
|
* @template Extended - Additional context properties provided by the extend function
|
|
11
11
|
*/
|
|
12
|
-
interface DatabaseFixtures<Transaction,
|
|
12
|
+
interface DatabaseFixtures<Transaction, _Extended = object> {
|
|
13
13
|
/**
|
|
14
14
|
* The database transaction available to the test.
|
|
15
15
|
* All database operations should use this transaction to ensure proper rollback.
|
|
@@ -201,6 +201,7 @@ type TestWithExtendedFixtures<Transaction, Extended extends Record<string, unkno
|
|
|
201
201
|
* ```
|
|
202
202
|
*/
|
|
203
203
|
declare function extendWithFixtures<Transaction, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = any>(wrappedTest: T, fixtures: FixtureCreators<Transaction, Extended>): TestWithExtendedFixtures<Transaction, Extended, T>;
|
|
204
|
+
//# sourceMappingURL=VitestTransactionIsolator.d.ts.map
|
|
204
205
|
//#endregion
|
|
205
206
|
export { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, ExtendContextFn, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions, VitestPostgresTransactionIsolator, extendWithFixtures };
|
|
206
|
-
//# sourceMappingURL=VitestTransactionIsolator-
|
|
207
|
+
//# sourceMappingURL=VitestTransactionIsolator-BNWJqh9f.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestTransactionIsolator-BNWJqh9f.d.mts","names":[],"sources":["../src/VitestTransactionIsolator.ts"],"sourcesContent":[],"mappings":";;;;;;AASA;AAWA;;;;AAGoC,UAdnB,gBAcmB,CAAA,WAAA,EAAA,YAAA,MAAA,CAAA,CAAA;EAAQ;AAe5C;;;EACiB,GACZ,EA1BC,WA0BD;;;AAAkB;AAQvB;AAkDsB,KA9EV,wBA8EU,CAAA,WAAiC,EAAA,WAAA,MAAA,CAAA,GA3EnD,gBA2EmD,CA3ElC,WA2EkC,CAAA,GA3EnB,QA2EmB;;;;;;;;;;;;;;AAkD5C,KA9GC,eA8GD,CAAA,WAAA,EAAA,QAAA,CAAA,GAAA,CAAA,GAAA,EA7GL,WA6GK,EAAA,GA5GN,QA4GM,GA5GK,OA4GL,CA5Ga,QA4Gb,CAAA;;;;;AAAuD;AA6ElE;AAAgC,aAjLpB,cAAA;EAiLoB;;;AAA6B;EACjD,gBAAA,GAAA,kBAAkB;EAAA;;;AAA6B;EAK1C,cAAA,GAAA,gBAAyB;EAAA;;;;EAMX,eAEhB,GAAA,iBAAA;EAAW;;;;EAIuB,YAArC,GAAA,cAAA;AAAe;AAO3B;;;;;;;;;;AAM2B;AAW3B;;;;;;;;;;;;;;;;AAiBuD,uBA1LjC,iCA0LiC,CAAA,KAAA,EAAA,WAAA,CAAA,CAAA;EAAC,iBACjD,GAAA;EAAO;AAqCd;;;;;;;;EAOgD,SAArC,QAAA,CAAA,IAAA,EA5NH,KA4NG,EAAA,cAAA,EA3NO,cA2NP,EAAA,EAAA,EAAA,CAAA,GAAA,EA1NC,WA0ND,EAAA,GA1NiB,OA0NjB,CAAA,IAAA,CAAA,CAAA,EAzNP,OAyNO,CAAA,IAAA,CAAA;EAAe,SACE,OAAA,CAAA,IAAA,EAxNJ,KAwNI,CAAA,EAxNI,OAwNJ,CAAA,IAAA,CAAA;EAAW;;;AAAZ;;mBAlNQ;;;;;;;;;;;;;;;;;;;;;;;;;;6CA2BS,uCACjC,0BAA0B,OAAO,aAAa,YAAS,QAAA,iBAAA,uBAAA;;KA6EtD,mCAAmC,OAAO,QAAQ;KAClD,2BAA2B,qBAAqB;;;;UAK3C,+DAGC;;cAGL,mBAAmB;;gBAEjB,gBAAgB;;mBAEb;;aAEN,gBAAgB,aAAa;;;;;;KAO7B,8CAEM,yCAEL,iBACN,gBACD,SAAS,KAAK,QAAQ,SAAS;;;;;;;;;KAWzB,uDAEM,0CACA,WAAW,qBAAqB,WAChD,sBAEE;iDAIQ,iBAAiB,eAAe,WAAW,MAChD;kEAMK,iBAAiB,eAAe,WAAW,MAChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqCS,iDAEE,mCAEP,WAAW,uCAER,aACH,gBAAgB,aAAa,YACrC,yBAAyB,aAAa,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VitestTransactionIsolator-CMfJXZP8.cjs","names":["api: TestAPI","options: TransactionWrapperOptions<TConn, Transaction, Extended>","additionalFixtures: Record<string, unknown>","use: (value: unknown) => Promise<void>","use: (value: Transaction) => Promise<void>","testError: Error | undefined","wrappedTest: T","fixtures: FixtureCreators<Transaction, Extended>","fixtureDefinitions: Record<string, any>"],"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 options - Configuration options for transaction wrapping\n * @returns A wrapped test API with transaction support\n *\n * @example\n * ```typescript\n * const isolatedTest = isolator.wrapVitestWithTransaction({\n * connection: db,\n * setup: async (trx) => {\n * await trx.insert('settings', { key: 'test', value: 'true' });\n * },\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * isolatedTest('test with transaction', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user).toBeDefined();\n * });\n * ```\n */\n wrapVitestWithTransaction<Extended extends Record<string, unknown> = {}>(\n options: TransactionWrapperOptions<TConn, Transaction, Extended>,\n ) {\n const {\n connection,\n setup,\n isolationLevel = IsolationLevel.REPEATABLE_READ,\n fixtures,\n } = options;\n\n // Build fixture definitions for additional fixtures that depend on trx\n const additionalFixtures: Record<string, unknown> = {};\n if (fixtures) {\n for (const [key, creator] of Object.entries(fixtures)) {\n additionalFixtures[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\n type CombinedFixtures = DatabaseFixtures<Transaction> & Extended;\n\n // Cast to bypass Vitest's strict fixture typing which can't infer\n // dynamically built fixture objects\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const extendFn = this.api.extend as <T>(fixtures: any) => TestAPI<T>;\n\n return extendFn<CombinedFixtures>({\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 connection();\n try {\n await this.transact(conn, isolationLevel, 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 ...additionalFixtures,\n });\n }\n}\n\nexport type DatabaseConnectionFn<Conn> = () => Conn | Promise<Conn>;\nexport type DatabaseConnection<Conn> = DatabaseConnectionFn<Conn>;\n\n/**\n * Options for wrapping Vitest tests with database transaction isolation.\n */\nexport interface TransactionWrapperOptions<\n TConn,\n Transaction,\n Extended extends Record<string, unknown> = {},\n> {\n /** Function that creates or returns a database connection */\n connection: DatabaseConnection<TConn>;\n /** Optional setup function to run within the transaction before each test */\n setup?: (trx: Transaction) => Promise<void>;\n /** Transaction isolation level (defaults to REPEATABLE_READ) */\n isolationLevel?: IsolationLevel;\n /** Additional fixtures that depend on the transaction */\n fixtures?: FixtureCreators<Transaction, Extended>;\n}\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, {\n * connection: db,\n * setup: createTestTables,\n * });\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;;;;;;;;;;;;;;;;;;;;;;;;;;CA2B7C,0BACEC,SACA;EACA,MAAM,EACJ,YACA,OACA,iBAAiB,eAAe,iBAChC,UACD,GAAG;EAGJ,MAAMC,qBAA8C,CAAE;AACtD,MAAI,SACF,MAAK,MAAM,CAAC,KAAK,QAAQ,IAAI,OAAO,QAAQ,SAAS,CACnD,oBAAmB,OAAO,OACxB,EAAE,KAA2B,EAC7BC,QACG;GACH,MAAM,QAAQ,MAAM,AAAC,QAA0C,IAAI;AACnE,SAAM,IAAI,MAAM;EACjB;EASL,MAAM,WAAW,KAAK,IAAI;AAE1B,SAAO,SAA2B;GAEhC,KAAK,OAAO,EAAE,EAAEC,QAA+C;IAE7D,MAAM,qBAAqB,MAAM;KAC/B,cAAc;AACZ,YAAM,gBAAgB;AACtB,WAAK,OAAO;KACb;IACF;IAED,IAAIC;IACJ,MAAM,OAAO,MAAM,YAAY;AAC/B,QAAI;AACF,WAAM,KAAK,SAAS,MAAM,gBAAgB,OAAO,gBAAgB;AAC/D,UAAI;AAEF,aAAM,QAAQ,YAAY;AAC1B,aAAM,IAAI,YAAY;MACvB,SAAQ,OAAO;AAEd,mBAAY;MACb;AAGD,YAAM,IAAI;KACX,EAAC;IACH,SAAQ,OAAO;AAEd,WAAM,iBAAiB,cACrB,OAAM;AAIR,SAAI,UACF,OAAM;IAET,UAAS;AACR,WAAM,KAAK,QAAQ,KAAK;IACzB;GACF;GACD,GAAG;EACJ,EAAC;CACH;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmGD,SAAgB,mBAMdC,aACAC,UACoD;CAEpD,MAAMC,qBAA0C,CAAE;AAElD,MAAK,MAAM,CAAC,KAAK,QAAQ,IAAI,OAAO,QAAQ,SAAS,CACnD,oBAAmB,OAAO,OACxB,EAAE,KAA2B,EAC7BL,QACG;EACH,MAAM,QAAQ,MAAM,AAAC,QAA0C,IAAI;AACnE,QAAM,IAAI,MAAM;CACjB;AAGH,QAAO,AAAC,YAAoB,OAAO,mBAAmB;AACvD"}
|
|
1
|
+
{"version":3,"file":"VitestTransactionIsolator-CMfJXZP8.cjs","names":["api: TestAPI","options: TransactionWrapperOptions<TConn, Transaction, Extended>","additionalFixtures: Record<string, unknown>","use: (value: unknown) => Promise<void>","use: (value: Transaction) => Promise<void>","testError: Error | undefined","wrappedTest: T","fixtures: FixtureCreators<Transaction, Extended>","fixtureDefinitions: Record<string, any>"],"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\t/**\n\t * The database transaction available to the test.\n\t * All database operations should use this transaction to ensure proper rollback.\n\t */\n\ttrx: Transaction;\n}\n\n/**\n * Combined fixtures type that merges the base transaction fixture with extended context.\n */\nexport type ExtendedDatabaseFixtures<\n\tTransaction,\n\tExtended = 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\ttrx: 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\t/**\n\t * Lowest isolation level. Allows dirty reads.\n\t * Not recommended for testing.\n\t */\n\tREAD_UNCOMMITTED = 'READ UNCOMMITTED',\n\t/**\n\t * Default PostgreSQL isolation level.\n\t * Prevents dirty reads but allows non-repeatable reads.\n\t */\n\tREAD_COMMITTED = 'READ COMMITTED',\n\t/**\n\t * Prevents dirty reads and non-repeatable reads.\n\t * Recommended for most test scenarios.\n\t */\n\tREPEATABLE_READ = 'REPEATABLE READ',\n\t/**\n\t * Highest isolation level. Prevents all phenomena.\n\t * May cause performance overhead in tests.\n\t */\n\tSERIALIZABLE = '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\t/**\n\t * Abstract method to create a transaction with the specified isolation level.\n\t * Must be implemented by subclasses for specific database drivers.\n\t *\n\t * @param conn - The database connection\n\t * @param isolationLevel - 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\tabstract transact(\n\t\tconn: TConn,\n\t\tisolationLevel: IsolationLevel,\n\t\tfn: (trx: Transaction) => Promise<void>,\n\t): Promise<void>;\n\n\tabstract destroy(conn: TConn): Promise<void>;\n\t/**\n\t * Creates a new VitestPostgresTransactionIsolator instance.\n\t *\n\t * @param api - The Vitest test API (usually the `test` export from vitest)\n\t */\n\tconstructor(private readonly api: TestAPI) {}\n\n\t/**\n\t * Creates a wrapped version of Vitest's test API that provides transaction isolation.\n\t * Each test will run within a database transaction that is automatically rolled back.\n\t *\n\t * @param options - Configuration options for transaction wrapping\n\t * @returns A wrapped test API with transaction support\n\t *\n\t * @example\n\t * ```typescript\n\t * const isolatedTest = isolator.wrapVitestWithTransaction({\n\t * connection: db,\n\t * setup: async (trx) => {\n\t * await trx.insert('settings', { key: 'test', value: 'true' });\n\t * },\n\t * fixtures: {\n\t * factory: (trx) => new Factory(trx),\n\t * },\n\t * });\n\t *\n\t * isolatedTest('test with transaction', async ({ trx, factory }) => {\n\t * const user = await factory.insert('user', { name: 'Test' });\n\t * expect(user).toBeDefined();\n\t * });\n\t * ```\n\t */\n\twrapVitestWithTransaction<Extended extends Record<string, unknown> = {}>(\n\t\toptions: TransactionWrapperOptions<TConn, Transaction, Extended>,\n\t) {\n\t\tconst {\n\t\t\tconnection,\n\t\t\tsetup,\n\t\t\tisolationLevel = IsolationLevel.REPEATABLE_READ,\n\t\t\tfixtures,\n\t\t} = options;\n\n\t\t// Build fixture definitions for additional fixtures that depend on trx\n\t\tconst additionalFixtures: Record<string, unknown> = {};\n\t\tif (fixtures) {\n\t\t\tfor (const [key, creator] of Object.entries(fixtures)) {\n\t\t\t\tadditionalFixtures[key] = async (\n\t\t\t\t\t{ trx }: { trx: Transaction },\n\t\t\t\t\tuse: (value: unknown) => Promise<void>,\n\t\t\t\t) => {\n\t\t\t\t\tconst value = await (creator as (trx: Transaction) => unknown)(trx);\n\t\t\t\t\tawait use(value);\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\ttype CombinedFixtures = DatabaseFixtures<Transaction> & Extended;\n\n\t\t// Cast to bypass Vitest's strict fixture typing which can't infer\n\t\t// dynamically built fixture objects\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tconst extendFn = this.api.extend as <T>(fixtures: any) => TestAPI<T>;\n\n\t\treturn extendFn<CombinedFixtures>({\n\t\t\t// This fixture automatically provides a transaction to each test\n\t\t\t// biome-ignore lint/correctness/noEmptyPattern: this has to be like this to satisfy Biome\n\t\t\ttrx: async ({}: {}, use: (value: Transaction) => Promise<void>) => {\n\t\t\t\t// Create a custom error class for rollback\n\t\t\t\tclass TestRollback extends Error {\n\t\t\t\t\tconstructor() {\n\t\t\t\t\t\tsuper('Test rollback');\n\t\t\t\t\t\tthis.name = 'TestRollback';\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlet testError: Error | undefined;\n\t\t\t\tconst conn = await connection();\n\t\t\t\ttry {\n\t\t\t\t\tawait this.transact(conn, isolationLevel, async (transaction) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Provide the transaction to the test\n\t\t\t\t\t\t\tawait setup?.(transaction);\n\t\t\t\t\t\t\tawait use(transaction);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t// Capture any test errors\n\t\t\t\t\t\t\ttestError = error as Error;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Always throw to trigger rollback\n\t\t\t\t\t\tthrow new TestRollback();\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Only rethrow if it's not our rollback error\n\t\t\t\t\tif (!(error instanceof TestRollback)) {\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\n\t\t\t\t\t// If the test had an error, throw it now\n\t\t\t\t\tif (testError) {\n\t\t\t\t\t\tthrow testError;\n\t\t\t\t\t}\n\t\t\t\t} finally {\n\t\t\t\t\tawait this.destroy(conn);\n\t\t\t\t}\n\t\t\t},\n\t\t\t...additionalFixtures,\n\t\t});\n\t}\n}\n\nexport type DatabaseConnectionFn<Conn> = () => Conn | Promise<Conn>;\nexport type DatabaseConnection<Conn> = DatabaseConnectionFn<Conn>;\n\n/**\n * Options for wrapping Vitest tests with database transaction isolation.\n */\nexport interface TransactionWrapperOptions<\n\tTConn,\n\tTransaction,\n\tExtended extends Record<string, unknown> = {},\n> {\n\t/** Function that creates or returns a database connection */\n\tconnection: DatabaseConnection<TConn>;\n\t/** Optional setup function to run within the transaction before each test */\n\tsetup?: (trx: Transaction) => Promise<void>;\n\t/** Transaction isolation level (defaults to REPEATABLE_READ) */\n\tisolationLevel?: IsolationLevel;\n\t/** Additional fixtures that depend on the transaction */\n\tfixtures?: FixtureCreators<Transaction, Extended>;\n}\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\tTransaction,\n\tExtended extends Record<string, unknown>,\n> = {\n\t[K in keyof Extended]: (\n\t\ttrx: Transaction,\n\t) => 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\tTransaction,\n\tExtended extends Record<string, unknown>,\n\tBaseTest extends ReturnType<TestAPI['extend']> = ReturnType<\n\t\tTestAPI['extend']\n\t>,\n> = BaseTest & {\n\t<C extends object>(\n\t\tname: string,\n\t\tfn: (\n\t\t\tcontext: DatabaseFixtures<Transaction> & Extended & C,\n\t\t) => Promise<void>,\n\t): void;\n\t<C extends object>(\n\t\tname: string,\n\t\toptions: object,\n\t\tfn: (\n\t\t\tcontext: DatabaseFixtures<Transaction> & Extended & C,\n\t\t) => Promise<void>,\n\t): 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, {\n * connection: db,\n * setup: createTestTables,\n * });\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\tTransaction,\n\tExtended extends Record<string, unknown>,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tT extends ReturnType<TestAPI['extend']> = any,\n>(\n\twrappedTest: T,\n\tfixtures: FixtureCreators<Transaction, Extended>,\n): TestWithExtendedFixtures<Transaction, Extended, T> {\n\t// Build fixture definitions for Vitest's extend API\n\tconst fixtureDefinitions: Record<string, any> = {};\n\n\tfor (const [key, creator] of Object.entries(fixtures)) {\n\t\tfixtureDefinitions[key] = async (\n\t\t\t{ trx }: { trx: Transaction },\n\t\t\tuse: (value: unknown) => Promise<void>,\n\t\t) => {\n\t\t\tconst value = await (creator as (trx: Transaction) => unknown)(trx);\n\t\t\tawait use(value);\n\t\t};\n\t}\n\n\treturn (wrappedTest as any).extend(fixtureDefinitions);\n}\n"],"mappings":";;;;;;;;AAgDA,IAAY,4DAAL;;;;;AAKN;;;;;AAKA;;;;;AAKA;;;;;AAKA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BD,IAAsB,oCAAtB,MAA4E;;;;;;CAsB3E,YAA6BA,KAAc;EAAd;CAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;CA2B7C,0BACCC,SACC;EACD,MAAM,EACL,YACA,OACA,iBAAiB,eAAe,iBAChC,UACA,GAAG;EAGJ,MAAMC,qBAA8C,CAAE;AACtD,MAAI,SACH,MAAK,MAAM,CAAC,KAAK,QAAQ,IAAI,OAAO,QAAQ,SAAS,CACpD,oBAAmB,OAAO,OACzB,EAAE,KAA2B,EAC7BC,QACI;GACJ,MAAM,QAAQ,MAAM,AAAC,QAA0C,IAAI;AACnE,SAAM,IAAI,MAAM;EAChB;EASH,MAAM,WAAW,KAAK,IAAI;AAE1B,SAAO,SAA2B;GAGjC,KAAK,OAAO,EAAM,EAAEC,QAA+C;IAElE,MAAM,qBAAqB,MAAM;KAChC,cAAc;AACb,YAAM,gBAAgB;AACtB,WAAK,OAAO;KACZ;IACD;IAED,IAAIC;IACJ,MAAM,OAAO,MAAM,YAAY;AAC/B,QAAI;AACH,WAAM,KAAK,SAAS,MAAM,gBAAgB,OAAO,gBAAgB;AAChE,UAAI;AAEH,aAAM,QAAQ,YAAY;AAC1B,aAAM,IAAI,YAAY;MACtB,SAAQ,OAAO;AAEf,mBAAY;MACZ;AAGD,YAAM,IAAI;KACV,EAAC;IACF,SAAQ,OAAO;AAEf,WAAM,iBAAiB,cACtB,OAAM;AAIP,SAAI,UACH,OAAM;IAEP,UAAS;AACT,WAAM,KAAK,QAAQ,KAAK;IACxB;GACD;GACD,GAAG;EACH,EAAC;CACF;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmGD,SAAgB,mBAMfC,aACAC,UACqD;CAErD,MAAMC,qBAA0C,CAAE;AAElD,MAAK,MAAM,CAAC,KAAK,QAAQ,IAAI,OAAO,QAAQ,SAAS,CACpD,oBAAmB,OAAO,OACzB,EAAE,KAA2B,EAC7BL,QACI;EACJ,MAAM,QAAQ,MAAM,AAAC,QAA0C,IAAI;AACnE,QAAM,IAAI,MAAM;CAChB;AAGF,QAAO,AAAC,YAAoB,OAAO,mBAAmB;AACtD"}
|
package/dist/{VitestTransactionIsolator-CwQaxZLP.d.cts → VitestTransactionIsolator-CSroc7Df.d.cts}
RENAMED
|
@@ -9,7 +9,7 @@ import { TestAPI } from "vitest";
|
|
|
9
9
|
* @template Transaction - The transaction type specific to the database driver
|
|
10
10
|
* @template Extended - Additional context properties provided by the extend function
|
|
11
11
|
*/
|
|
12
|
-
interface DatabaseFixtures<Transaction,
|
|
12
|
+
interface DatabaseFixtures<Transaction, _Extended = object> {
|
|
13
13
|
/**
|
|
14
14
|
* The database transaction available to the test.
|
|
15
15
|
* All database operations should use this transaction to ensure proper rollback.
|
|
@@ -201,6 +201,7 @@ type TestWithExtendedFixtures<Transaction, Extended extends Record<string, unkno
|
|
|
201
201
|
* ```
|
|
202
202
|
*/
|
|
203
203
|
declare function extendWithFixtures<Transaction, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = any>(wrappedTest: T, fixtures: FixtureCreators<Transaction, Extended>): TestWithExtendedFixtures<Transaction, Extended, T>;
|
|
204
|
+
//# sourceMappingURL=VitestTransactionIsolator.d.ts.map
|
|
204
205
|
//#endregion
|
|
205
206
|
export { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, ExtendContextFn, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions, VitestPostgresTransactionIsolator, extendWithFixtures };
|
|
206
|
-
//# sourceMappingURL=VitestTransactionIsolator-
|
|
207
|
+
//# sourceMappingURL=VitestTransactionIsolator-CSroc7Df.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestTransactionIsolator-CSroc7Df.d.cts","names":[],"sources":["../src/VitestTransactionIsolator.ts"],"sourcesContent":[],"mappings":";;;;;;AASA;AAWA;;;;AAGoC,UAdnB,gBAcmB,CAAA,WAAA,EAAA,YAAA,MAAA,CAAA,CAAA;EAAQ;AAe5C;;;EACiB,GACZ,EA1BC,WA0BD;;;AAAkB;AAQvB;AAkDsB,KA9EV,wBA8EU,CAAA,WAAiC,EAAA,WAAA,MAAA,CAAA,GA3EnD,gBA2EmD,CA3ElC,WA2EkC,CAAA,GA3EnB,QA2EmB;;;;;;;;;;;;;;AAkD5C,KA9GC,eA8GD,CAAA,WAAA,EAAA,QAAA,CAAA,GAAA,CAAA,GAAA,EA7GL,WA6GK,EAAA,GA5GN,QA4GM,GA5GK,OA4GL,CA5Ga,QA4Gb,CAAA;;;;;AAAuD;AA6ElE;AAAgC,aAjLpB,cAAA;EAiLoB;;;AAA6B;EACjD,gBAAA,GAAA,kBAAkB;EAAA;;;AAA6B;EAK1C,cAAA,GAAA,gBAAyB;EAAA;;;;EAMX,eAEhB,GAAA,iBAAA;EAAW;;;;EAIuB,YAArC,GAAA,cAAA;AAAe;AAO3B;;;;;;;;;;AAM2B;AAW3B;;;;;;;;;;;;;;;;AAiBuD,uBA1LjC,iCA0LiC,CAAA,KAAA,EAAA,WAAA,CAAA,CAAA;EAAC,iBACjD,GAAA;EAAO;AAqCd;;;;;;;;EAOgD,SAArC,QAAA,CAAA,IAAA,EA5NH,KA4NG,EAAA,cAAA,EA3NO,cA2NP,EAAA,EAAA,EAAA,CAAA,GAAA,EA1NC,WA0ND,EAAA,GA1NiB,OA0NjB,CAAA,IAAA,CAAA,CAAA,EAzNP,OAyNO,CAAA,IAAA,CAAA;EAAe,SACE,OAAA,CAAA,IAAA,EAxNJ,KAwNI,CAAA,EAxNI,OAwNJ,CAAA,IAAA,CAAA;EAAW;;;AAAZ;;mBAlNQ;;;;;;;;;;;;;;;;;;;;;;;;;;6CA2BS,uCACjC,0BAA0B,OAAO,aAAa,YAAS,QAAA,iBAAA,uBAAA;;KA6EtD,mCAAmC,OAAO,QAAQ;KAClD,2BAA2B,qBAAqB;;;;UAK3C,+DAGC;;cAGL,mBAAmB;;gBAEjB,gBAAgB;;mBAEb;;aAEN,gBAAgB,aAAa;;;;;;KAO7B,8CAEM,yCAEL,iBACN,gBACD,SAAS,KAAK,QAAQ,SAAS;;;;;;;;;KAWzB,uDAEM,0CACA,WAAW,qBAAqB,WAChD,sBAEE;iDAIQ,iBAAiB,eAAe,WAAW,MAChD;kEAMK,iBAAiB,eAAe,WAAW,MAChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqCS,iDAEE,mCAEP,WAAW,uCAER,aACH,gBAAgB,aAAa,YACrC,yBAAyB,aAAa,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VitestTransactionIsolator-DQ7tLqgV.mjs","names":["api: TestAPI","options: TransactionWrapperOptions<TConn, Transaction, Extended>","additionalFixtures: Record<string, unknown>","use: (value: unknown) => Promise<void>","use: (value: Transaction) => Promise<void>","testError: Error | undefined","wrappedTest: T","fixtures: FixtureCreators<Transaction, Extended>","fixtureDefinitions: Record<string, any>"],"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 options - Configuration options for transaction wrapping\n * @returns A wrapped test API with transaction support\n *\n * @example\n * ```typescript\n * const isolatedTest = isolator.wrapVitestWithTransaction({\n * connection: db,\n * setup: async (trx) => {\n * await trx.insert('settings', { key: 'test', value: 'true' });\n * },\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * isolatedTest('test with transaction', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user).toBeDefined();\n * });\n * ```\n */\n wrapVitestWithTransaction<Extended extends Record<string, unknown> = {}>(\n options: TransactionWrapperOptions<TConn, Transaction, Extended>,\n ) {\n const {\n connection,\n setup,\n isolationLevel = IsolationLevel.REPEATABLE_READ,\n fixtures,\n } = options;\n\n // Build fixture definitions for additional fixtures that depend on trx\n const additionalFixtures: Record<string, unknown> = {};\n if (fixtures) {\n for (const [key, creator] of Object.entries(fixtures)) {\n additionalFixtures[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\n type CombinedFixtures = DatabaseFixtures<Transaction> & Extended;\n\n // Cast to bypass Vitest's strict fixture typing which can't infer\n // dynamically built fixture objects\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const extendFn = this.api.extend as <T>(fixtures: any) => TestAPI<T>;\n\n return extendFn<CombinedFixtures>({\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 connection();\n try {\n await this.transact(conn, isolationLevel, 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 ...additionalFixtures,\n });\n }\n}\n\nexport type DatabaseConnectionFn<Conn> = () => Conn | Promise<Conn>;\nexport type DatabaseConnection<Conn> = DatabaseConnectionFn<Conn>;\n\n/**\n * Options for wrapping Vitest tests with database transaction isolation.\n */\nexport interface TransactionWrapperOptions<\n TConn,\n Transaction,\n Extended extends Record<string, unknown> = {},\n> {\n /** Function that creates or returns a database connection */\n connection: DatabaseConnection<TConn>;\n /** Optional setup function to run within the transaction before each test */\n setup?: (trx: Transaction) => Promise<void>;\n /** Transaction isolation level (defaults to REPEATABLE_READ) */\n isolationLevel?: IsolationLevel;\n /** Additional fixtures that depend on the transaction */\n fixtures?: FixtureCreators<Transaction, Extended>;\n}\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, {\n * connection: db,\n * setup: createTestTables,\n * });\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;;;;;;;;;;;;;;;;;;;;;;;;;;CA2B7C,0BACEC,SACA;EACA,MAAM,EACJ,YACA,OACA,iBAAiB,eAAe,iBAChC,UACD,GAAG;EAGJ,MAAMC,qBAA8C,CAAE;AACtD,MAAI,SACF,MAAK,MAAM,CAAC,KAAK,QAAQ,IAAI,OAAO,QAAQ,SAAS,CACnD,oBAAmB,OAAO,OACxB,EAAE,KAA2B,EAC7BC,QACG;GACH,MAAM,QAAQ,MAAM,AAAC,QAA0C,IAAI;AACnE,SAAM,IAAI,MAAM;EACjB;EASL,MAAM,WAAW,KAAK,IAAI;AAE1B,SAAO,SAA2B;GAEhC,KAAK,OAAO,EAAE,EAAEC,QAA+C;IAE7D,MAAM,qBAAqB,MAAM;KAC/B,cAAc;AACZ,YAAM,gBAAgB;AACtB,WAAK,OAAO;KACb;IACF;IAED,IAAIC;IACJ,MAAM,OAAO,MAAM,YAAY;AAC/B,QAAI;AACF,WAAM,KAAK,SAAS,MAAM,gBAAgB,OAAO,gBAAgB;AAC/D,UAAI;AAEF,aAAM,QAAQ,YAAY;AAC1B,aAAM,IAAI,YAAY;MACvB,SAAQ,OAAO;AAEd,mBAAY;MACb;AAGD,YAAM,IAAI;KACX,EAAC;IACH,SAAQ,OAAO;AAEd,WAAM,iBAAiB,cACrB,OAAM;AAIR,SAAI,UACF,OAAM;IAET,UAAS;AACR,WAAM,KAAK,QAAQ,KAAK;IACzB;GACF;GACD,GAAG;EACJ,EAAC;CACH;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmGD,SAAgB,mBAMdC,aACAC,UACoD;CAEpD,MAAMC,qBAA0C,CAAE;AAElD,MAAK,MAAM,CAAC,KAAK,QAAQ,IAAI,OAAO,QAAQ,SAAS,CACnD,oBAAmB,OAAO,OACxB,EAAE,KAA2B,EAC7BL,QACG;EACH,MAAM,QAAQ,MAAM,AAAC,QAA0C,IAAI;AACnE,QAAM,IAAI,MAAM;CACjB;AAGH,QAAO,AAAC,YAAoB,OAAO,mBAAmB;AACvD"}
|
|
1
|
+
{"version":3,"file":"VitestTransactionIsolator-DQ7tLqgV.mjs","names":["api: TestAPI","options: TransactionWrapperOptions<TConn, Transaction, Extended>","additionalFixtures: Record<string, unknown>","use: (value: unknown) => Promise<void>","use: (value: Transaction) => Promise<void>","testError: Error | undefined","wrappedTest: T","fixtures: FixtureCreators<Transaction, Extended>","fixtureDefinitions: Record<string, any>"],"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\t/**\n\t * The database transaction available to the test.\n\t * All database operations should use this transaction to ensure proper rollback.\n\t */\n\ttrx: Transaction;\n}\n\n/**\n * Combined fixtures type that merges the base transaction fixture with extended context.\n */\nexport type ExtendedDatabaseFixtures<\n\tTransaction,\n\tExtended = 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\ttrx: 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\t/**\n\t * Lowest isolation level. Allows dirty reads.\n\t * Not recommended for testing.\n\t */\n\tREAD_UNCOMMITTED = 'READ UNCOMMITTED',\n\t/**\n\t * Default PostgreSQL isolation level.\n\t * Prevents dirty reads but allows non-repeatable reads.\n\t */\n\tREAD_COMMITTED = 'READ COMMITTED',\n\t/**\n\t * Prevents dirty reads and non-repeatable reads.\n\t * Recommended for most test scenarios.\n\t */\n\tREPEATABLE_READ = 'REPEATABLE READ',\n\t/**\n\t * Highest isolation level. Prevents all phenomena.\n\t * May cause performance overhead in tests.\n\t */\n\tSERIALIZABLE = '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\t/**\n\t * Abstract method to create a transaction with the specified isolation level.\n\t * Must be implemented by subclasses for specific database drivers.\n\t *\n\t * @param conn - The database connection\n\t * @param isolationLevel - 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\tabstract transact(\n\t\tconn: TConn,\n\t\tisolationLevel: IsolationLevel,\n\t\tfn: (trx: Transaction) => Promise<void>,\n\t): Promise<void>;\n\n\tabstract destroy(conn: TConn): Promise<void>;\n\t/**\n\t * Creates a new VitestPostgresTransactionIsolator instance.\n\t *\n\t * @param api - The Vitest test API (usually the `test` export from vitest)\n\t */\n\tconstructor(private readonly api: TestAPI) {}\n\n\t/**\n\t * Creates a wrapped version of Vitest's test API that provides transaction isolation.\n\t * Each test will run within a database transaction that is automatically rolled back.\n\t *\n\t * @param options - Configuration options for transaction wrapping\n\t * @returns A wrapped test API with transaction support\n\t *\n\t * @example\n\t * ```typescript\n\t * const isolatedTest = isolator.wrapVitestWithTransaction({\n\t * connection: db,\n\t * setup: async (trx) => {\n\t * await trx.insert('settings', { key: 'test', value: 'true' });\n\t * },\n\t * fixtures: {\n\t * factory: (trx) => new Factory(trx),\n\t * },\n\t * });\n\t *\n\t * isolatedTest('test with transaction', async ({ trx, factory }) => {\n\t * const user = await factory.insert('user', { name: 'Test' });\n\t * expect(user).toBeDefined();\n\t * });\n\t * ```\n\t */\n\twrapVitestWithTransaction<Extended extends Record<string, unknown> = {}>(\n\t\toptions: TransactionWrapperOptions<TConn, Transaction, Extended>,\n\t) {\n\t\tconst {\n\t\t\tconnection,\n\t\t\tsetup,\n\t\t\tisolationLevel = IsolationLevel.REPEATABLE_READ,\n\t\t\tfixtures,\n\t\t} = options;\n\n\t\t// Build fixture definitions for additional fixtures that depend on trx\n\t\tconst additionalFixtures: Record<string, unknown> = {};\n\t\tif (fixtures) {\n\t\t\tfor (const [key, creator] of Object.entries(fixtures)) {\n\t\t\t\tadditionalFixtures[key] = async (\n\t\t\t\t\t{ trx }: { trx: Transaction },\n\t\t\t\t\tuse: (value: unknown) => Promise<void>,\n\t\t\t\t) => {\n\t\t\t\t\tconst value = await (creator as (trx: Transaction) => unknown)(trx);\n\t\t\t\t\tawait use(value);\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\ttype CombinedFixtures = DatabaseFixtures<Transaction> & Extended;\n\n\t\t// Cast to bypass Vitest's strict fixture typing which can't infer\n\t\t// dynamically built fixture objects\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tconst extendFn = this.api.extend as <T>(fixtures: any) => TestAPI<T>;\n\n\t\treturn extendFn<CombinedFixtures>({\n\t\t\t// This fixture automatically provides a transaction to each test\n\t\t\t// biome-ignore lint/correctness/noEmptyPattern: this has to be like this to satisfy Biome\n\t\t\ttrx: async ({}: {}, use: (value: Transaction) => Promise<void>) => {\n\t\t\t\t// Create a custom error class for rollback\n\t\t\t\tclass TestRollback extends Error {\n\t\t\t\t\tconstructor() {\n\t\t\t\t\t\tsuper('Test rollback');\n\t\t\t\t\t\tthis.name = 'TestRollback';\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlet testError: Error | undefined;\n\t\t\t\tconst conn = await connection();\n\t\t\t\ttry {\n\t\t\t\t\tawait this.transact(conn, isolationLevel, async (transaction) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Provide the transaction to the test\n\t\t\t\t\t\t\tawait setup?.(transaction);\n\t\t\t\t\t\t\tawait use(transaction);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t// Capture any test errors\n\t\t\t\t\t\t\ttestError = error as Error;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Always throw to trigger rollback\n\t\t\t\t\t\tthrow new TestRollback();\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Only rethrow if it's not our rollback error\n\t\t\t\t\tif (!(error instanceof TestRollback)) {\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\n\t\t\t\t\t// If the test had an error, throw it now\n\t\t\t\t\tif (testError) {\n\t\t\t\t\t\tthrow testError;\n\t\t\t\t\t}\n\t\t\t\t} finally {\n\t\t\t\t\tawait this.destroy(conn);\n\t\t\t\t}\n\t\t\t},\n\t\t\t...additionalFixtures,\n\t\t});\n\t}\n}\n\nexport type DatabaseConnectionFn<Conn> = () => Conn | Promise<Conn>;\nexport type DatabaseConnection<Conn> = DatabaseConnectionFn<Conn>;\n\n/**\n * Options for wrapping Vitest tests with database transaction isolation.\n */\nexport interface TransactionWrapperOptions<\n\tTConn,\n\tTransaction,\n\tExtended extends Record<string, unknown> = {},\n> {\n\t/** Function that creates or returns a database connection */\n\tconnection: DatabaseConnection<TConn>;\n\t/** Optional setup function to run within the transaction before each test */\n\tsetup?: (trx: Transaction) => Promise<void>;\n\t/** Transaction isolation level (defaults to REPEATABLE_READ) */\n\tisolationLevel?: IsolationLevel;\n\t/** Additional fixtures that depend on the transaction */\n\tfixtures?: FixtureCreators<Transaction, Extended>;\n}\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\tTransaction,\n\tExtended extends Record<string, unknown>,\n> = {\n\t[K in keyof Extended]: (\n\t\ttrx: Transaction,\n\t) => 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\tTransaction,\n\tExtended extends Record<string, unknown>,\n\tBaseTest extends ReturnType<TestAPI['extend']> = ReturnType<\n\t\tTestAPI['extend']\n\t>,\n> = BaseTest & {\n\t<C extends object>(\n\t\tname: string,\n\t\tfn: (\n\t\t\tcontext: DatabaseFixtures<Transaction> & Extended & C,\n\t\t) => Promise<void>,\n\t): void;\n\t<C extends object>(\n\t\tname: string,\n\t\toptions: object,\n\t\tfn: (\n\t\t\tcontext: DatabaseFixtures<Transaction> & Extended & C,\n\t\t) => Promise<void>,\n\t): 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, {\n * connection: db,\n * setup: createTestTables,\n * });\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\tTransaction,\n\tExtended extends Record<string, unknown>,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tT extends ReturnType<TestAPI['extend']> = any,\n>(\n\twrappedTest: T,\n\tfixtures: FixtureCreators<Transaction, Extended>,\n): TestWithExtendedFixtures<Transaction, Extended, T> {\n\t// Build fixture definitions for Vitest's extend API\n\tconst fixtureDefinitions: Record<string, any> = {};\n\n\tfor (const [key, creator] of Object.entries(fixtures)) {\n\t\tfixtureDefinitions[key] = async (\n\t\t\t{ trx }: { trx: Transaction },\n\t\t\tuse: (value: unknown) => Promise<void>,\n\t\t) => {\n\t\t\tconst value = await (creator as (trx: Transaction) => unknown)(trx);\n\t\t\tawait use(value);\n\t\t};\n\t}\n\n\treturn (wrappedTest as any).extend(fixtureDefinitions);\n}\n"],"mappings":";;;;;;;AAgDA,IAAY,4DAAL;;;;;AAKN;;;;;AAKA;;;;;AAKA;;;;;AAKA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BD,IAAsB,oCAAtB,MAA4E;;;;;;CAsB3E,YAA6BA,KAAc;EAAd;CAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;CA2B7C,0BACCC,SACC;EACD,MAAM,EACL,YACA,OACA,iBAAiB,eAAe,iBAChC,UACA,GAAG;EAGJ,MAAMC,qBAA8C,CAAE;AACtD,MAAI,SACH,MAAK,MAAM,CAAC,KAAK,QAAQ,IAAI,OAAO,QAAQ,SAAS,CACpD,oBAAmB,OAAO,OACzB,EAAE,KAA2B,EAC7BC,QACI;GACJ,MAAM,QAAQ,MAAM,AAAC,QAA0C,IAAI;AACnE,SAAM,IAAI,MAAM;EAChB;EASH,MAAM,WAAW,KAAK,IAAI;AAE1B,SAAO,SAA2B;GAGjC,KAAK,OAAO,EAAM,EAAEC,QAA+C;IAElE,MAAM,qBAAqB,MAAM;KAChC,cAAc;AACb,YAAM,gBAAgB;AACtB,WAAK,OAAO;KACZ;IACD;IAED,IAAIC;IACJ,MAAM,OAAO,MAAM,YAAY;AAC/B,QAAI;AACH,WAAM,KAAK,SAAS,MAAM,gBAAgB,OAAO,gBAAgB;AAChE,UAAI;AAEH,aAAM,QAAQ,YAAY;AAC1B,aAAM,IAAI,YAAY;MACtB,SAAQ,OAAO;AAEf,mBAAY;MACZ;AAGD,YAAM,IAAI;KACV,EAAC;IACF,SAAQ,OAAO;AAEf,WAAM,iBAAiB,cACtB,OAAM;AAIP,SAAI,UACH,OAAM;IAEP,UAAS;AACT,WAAM,KAAK,QAAQ,KAAK;IACxB;GACD;GACD,GAAG;EACH,EAAC;CACF;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmGD,SAAgB,mBAMfC,aACAC,UACqD;CAErD,MAAMC,qBAA0C,CAAE;AAElD,MAAK,MAAM,CAAC,KAAK,QAAQ,IAAI,OAAO,QAAQ,SAAS,CACpD,oBAAmB,OAAO,OACzB,EAAE,KAA2B,EAC7BL,QACI;EACJ,MAAM,QAAQ,MAAM,AAAC,QAA0C,IAAI;AACnE,QAAM,IAAI,MAAM;CAChB;AAGF,QAAO,AAAC,YAAoB,OAAO,mBAAmB;AACtD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, ExtendContextFn, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions, VitestPostgresTransactionIsolator, extendWithFixtures } from "./VitestTransactionIsolator-
|
|
1
|
+
import { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, ExtendContextFn, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions, VitestPostgresTransactionIsolator, extendWithFixtures } from "./VitestTransactionIsolator-CSroc7Df.cjs";
|
|
2
2
|
export { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, ExtendContextFn, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions, VitestPostgresTransactionIsolator, extendWithFixtures };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, ExtendContextFn, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions, VitestPostgresTransactionIsolator, extendWithFixtures } from "./VitestTransactionIsolator-
|
|
1
|
+
import { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, ExtendContextFn, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions, VitestPostgresTransactionIsolator, extendWithFixtures } from "./VitestTransactionIsolator-BNWJqh9f.mjs";
|
|
2
2
|
export { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, ExtendContextFn, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions, VitestPostgresTransactionIsolator, extendWithFixtures };
|
package/dist/aws.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws.cjs","names":["overrides: Partial<APIGatewayProxyEvent>","overrides: Partial<APIGatewayProxyEventV2>"],"sources":["../src/aws.ts"],"sourcesContent":["import type {\n
|
|
1
|
+
{"version":3,"file":"aws.cjs","names":["overrides: Partial<APIGatewayProxyEvent>","overrides: Partial<APIGatewayProxyEventV2>"],"sources":["../src/aws.ts"],"sourcesContent":["import type {\n\tAPIGatewayProxyEvent,\n\tAPIGatewayProxyEventV2,\n\tContext,\n} from 'aws-lambda';\nimport { vi } from 'vitest';\n\n/**\n * Shared test utilities for AWS Lambda adapter testing\n */\n\n/**\n * Creates a mock AWS Lambda Context for testing\n */\nexport function createMockContext(): Context {\n\treturn {\n\t\tawsRequestId: 'test-request-id',\n\t\tcallbackWaitsForEmptyEventLoop: false,\n\t\tfunctionName: 'test-function',\n\t\tfunctionVersion: '1',\n\t\tinvokedFunctionArn:\n\t\t\t'arn:aws:lambda:us-east-1:123456789012:function:test-function',\n\t\tmemoryLimitInMB: '128',\n\t\tlogGroupName: '/aws/lambda/test-function',\n\t\tlogStreamName: '2024/01/01/[$LATEST]abcdef123456',\n\t\tgetRemainingTimeInMillis: () => 5000,\n\t\tdone: vi.fn(),\n\t\tfail: vi.fn(),\n\t\tsucceed: vi.fn(),\n\t};\n}\n\n/**\n * Creates a mock AWS API Gateway V1 (REST API) event for testing\n */\nexport function createMockV1Event(\n\toverrides: Partial<APIGatewayProxyEvent> = {},\n): APIGatewayProxyEvent {\n\treturn {\n\t\tbody: null,\n\t\theaders: {\n\t\t\t'content-type': 'application/json',\n\t\t\t'user-agent': 'test-agent',\n\t\t\thost: 'test.example.com',\n\t\t},\n\t\tmultiValueHeaders: {},\n\t\thttpMethod: 'GET',\n\t\tisBase64Encoded: false,\n\t\tpath: '/test',\n\t\tpathParameters: null,\n\t\tqueryStringParameters: null,\n\t\tmultiValueQueryStringParameters: null,\n\t\tstageVariables: null,\n\t\trequestContext: {\n\t\t\taccountId: '123456789012',\n\t\t\tapiId: 'api-id',\n\t\t\tauthorizer: null,\n\t\t\tprotocol: 'HTTP/1.1',\n\t\t\thttpMethod: 'GET',\n\t\t\tpath: '/test',\n\t\t\tstage: 'test',\n\t\t\trequestId: 'request-id',\n\t\t\trequestTimeEpoch: 1704067200000,\n\t\t\tresourceId: 'resource-id',\n\t\t\tresourcePath: '/test',\n\t\t\tidentity: {\n\t\t\t\taccessKey: null,\n\t\t\t\taccountId: null,\n\t\t\t\tapiKey: null,\n\t\t\t\tapiKeyId: null,\n\t\t\t\tcaller: null,\n\t\t\t\tcognitoAuthenticationProvider: null,\n\t\t\t\tcognitoAuthenticationType: null,\n\t\t\t\tcognitoIdentityId: null,\n\t\t\t\tcognitoIdentityPoolId: null,\n\t\t\t\tprincipalOrgId: null,\n\t\t\t\tsourceIp: '127.0.0.1',\n\t\t\t\tuser: null,\n\t\t\t\tuserAgent: 'test-agent',\n\t\t\t\tuserArn: null,\n\t\t\t\tclientCert: null,\n\t\t\t},\n\t\t},\n\t\tresource: '/test',\n\t\t...overrides,\n\t};\n}\n\n/**\n * Creates a mock AWS API Gateway V2 (HTTP API) event for testing\n */\nexport function createMockV2Event(\n\toverrides: Partial<APIGatewayProxyEventV2> = {},\n): APIGatewayProxyEventV2 {\n\treturn {\n\t\tversion: '2.0',\n\t\trouteKey: 'GET /test',\n\t\trawPath: '/test',\n\t\trawQueryString: '',\n\t\theaders: {\n\t\t\t'content-type': 'application/json',\n\t\t\t'user-agent': 'test-agent',\n\t\t\thost: 'test.example.com',\n\t\t},\n\t\trequestContext: {\n\t\t\taccountId: '123456789012',\n\t\t\tapiId: 'api-id',\n\t\t\tdomainName: 'test.example.com',\n\t\t\tdomainPrefix: 'api',\n\t\t\trequestId: 'request-id',\n\t\t\trouteKey: 'GET /test',\n\t\t\tstage: 'test',\n\t\t\ttime: '01/Jan/2024:00:00:00 +0000',\n\t\t\ttimeEpoch: 1704067200000,\n\t\t\thttp: {\n\t\t\t\tmethod: 'GET',\n\t\t\t\tpath: '/test',\n\t\t\t\tprotocol: 'HTTP/1.1',\n\t\t\t\tsourceIp: '127.0.0.1',\n\t\t\t\tuserAgent: 'test-agent',\n\t\t\t},\n\t\t},\n\t\tbody: undefined,\n\t\tpathParameters: undefined,\n\t\tisBase64Encoded: false,\n\t\tstageVariables: undefined,\n\t\tqueryStringParameters: undefined,\n\t\tcookies: undefined,\n\t\t...overrides,\n\t};\n}\n"],"mappings":";;;;;;;;;;AAcA,SAAgB,oBAA6B;AAC5C,QAAO;EACN,cAAc;EACd,gCAAgC;EAChC,cAAc;EACd,iBAAiB;EACjB,oBACC;EACD,iBAAiB;EACjB,cAAc;EACd,eAAe;EACf,0BAA0B,MAAM;EAChC,MAAM,UAAG,IAAI;EACb,MAAM,UAAG,IAAI;EACb,SAAS,UAAG,IAAI;CAChB;AACD;;;;AAKD,SAAgB,kBACfA,YAA2C,CAAE,GACtB;AACvB,QAAO;EACN,MAAM;EACN,SAAS;GACR,gBAAgB;GAChB,cAAc;GACd,MAAM;EACN;EACD,mBAAmB,CAAE;EACrB,YAAY;EACZ,iBAAiB;EACjB,MAAM;EACN,gBAAgB;EAChB,uBAAuB;EACvB,iCAAiC;EACjC,gBAAgB;EAChB,gBAAgB;GACf,WAAW;GACX,OAAO;GACP,YAAY;GACZ,UAAU;GACV,YAAY;GACZ,MAAM;GACN,OAAO;GACP,WAAW;GACX,kBAAkB;GAClB,YAAY;GACZ,cAAc;GACd,UAAU;IACT,WAAW;IACX,WAAW;IACX,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,+BAA+B;IAC/B,2BAA2B;IAC3B,mBAAmB;IACnB,uBAAuB;IACvB,gBAAgB;IAChB,UAAU;IACV,MAAM;IACN,WAAW;IACX,SAAS;IACT,YAAY;GACZ;EACD;EACD,UAAU;EACV,GAAG;CACH;AACD;;;;AAKD,SAAgB,kBACfC,YAA6C,CAAE,GACtB;AACzB,QAAO;EACN,SAAS;EACT,UAAU;EACV,SAAS;EACT,gBAAgB;EAChB,SAAS;GACR,gBAAgB;GAChB,cAAc;GACd,MAAM;EACN;EACD,gBAAgB;GACf,WAAW;GACX,OAAO;GACP,YAAY;GACZ,cAAc;GACd,WAAW;GACX,UAAU;GACV,OAAO;GACP,MAAM;GACN,WAAW;GACX,MAAM;IACL,QAAQ;IACR,MAAM;IACN,UAAU;IACV,UAAU;IACV,WAAW;GACX;EACD;EACD;EACA;EACA,iBAAiB;EACjB;EACA;EACA;EACA,GAAG;CACH;AACD"}
|
package/dist/aws.d.cts
CHANGED
|
@@ -17,6 +17,8 @@ declare function createMockV1Event(overrides?: Partial<APIGatewayProxyEvent>): A
|
|
|
17
17
|
* Creates a mock AWS API Gateway V2 (HTTP API) event for testing
|
|
18
18
|
*/
|
|
19
19
|
declare function createMockV2Event(overrides?: Partial<APIGatewayProxyEventV2>): APIGatewayProxyEventV2;
|
|
20
|
+
//# sourceMappingURL=aws.d.ts.map
|
|
21
|
+
|
|
20
22
|
//#endregion
|
|
21
23
|
export { createMockContext, createMockV1Event, createMockV2Event };
|
|
22
24
|
//# sourceMappingURL=aws.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws.d.cts","names":[],"sources":["../src/aws.ts"],"sourcesContent":[],"mappings":";;;;;;AAcA;AAqBA;;;AACY,iBAtBI,iBAAA,CAAA,CAsBJ,EAtByB,OAsBzB;;AACW;AAsDvB;AAAiC,iBAxDjB,iBAAA,CAwDiB,SAAA,CAAA,EAvDrB,OAuDqB,CAvDb,oBAuDa,CAAA,CAAA,EAtD9B,oBAsD8B;;;;AAER,iBAFT,iBAAA,CAES,SAAA,CAAA,EADb,OACa,CADL,sBACK,CAAA,CAAA,EAAtB,sBAAsB"}
|
package/dist/aws.d.mts
CHANGED
|
@@ -17,6 +17,8 @@ declare function createMockV1Event(overrides?: Partial<APIGatewayProxyEvent>): A
|
|
|
17
17
|
* Creates a mock AWS API Gateway V2 (HTTP API) event for testing
|
|
18
18
|
*/
|
|
19
19
|
declare function createMockV2Event(overrides?: Partial<APIGatewayProxyEventV2>): APIGatewayProxyEventV2;
|
|
20
|
+
//# sourceMappingURL=aws.d.ts.map
|
|
21
|
+
|
|
20
22
|
//#endregion
|
|
21
23
|
export { createMockContext, createMockV1Event, createMockV2Event };
|
|
22
24
|
//# sourceMappingURL=aws.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws.d.mts","names":[],"sources":["../src/aws.ts"],"sourcesContent":[],"mappings":";;;;;;AAcA;AAqBA;;;AACY,iBAtBI,iBAAA,CAAA,CAsBJ,EAtByB,OAsBzB;;AACW;AAsDvB;AAAiC,iBAxDjB,iBAAA,CAwDiB,SAAA,CAAA,EAvDrB,OAuDqB,CAvDb,oBAuDa,CAAA,CAAA,EAtD9B,oBAsD8B;;;;AAER,iBAFT,iBAAA,CAES,SAAA,CAAA,EADb,OACa,CADL,sBACK,CAAA,CAAA,EAAtB,sBAAsB"}
|
package/dist/aws.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws.mjs","names":["overrides: Partial<APIGatewayProxyEvent>","overrides: Partial<APIGatewayProxyEventV2>"],"sources":["../src/aws.ts"],"sourcesContent":["import type {\n
|
|
1
|
+
{"version":3,"file":"aws.mjs","names":["overrides: Partial<APIGatewayProxyEvent>","overrides: Partial<APIGatewayProxyEventV2>"],"sources":["../src/aws.ts"],"sourcesContent":["import type {\n\tAPIGatewayProxyEvent,\n\tAPIGatewayProxyEventV2,\n\tContext,\n} from 'aws-lambda';\nimport { vi } from 'vitest';\n\n/**\n * Shared test utilities for AWS Lambda adapter testing\n */\n\n/**\n * Creates a mock AWS Lambda Context for testing\n */\nexport function createMockContext(): Context {\n\treturn {\n\t\tawsRequestId: 'test-request-id',\n\t\tcallbackWaitsForEmptyEventLoop: false,\n\t\tfunctionName: 'test-function',\n\t\tfunctionVersion: '1',\n\t\tinvokedFunctionArn:\n\t\t\t'arn:aws:lambda:us-east-1:123456789012:function:test-function',\n\t\tmemoryLimitInMB: '128',\n\t\tlogGroupName: '/aws/lambda/test-function',\n\t\tlogStreamName: '2024/01/01/[$LATEST]abcdef123456',\n\t\tgetRemainingTimeInMillis: () => 5000,\n\t\tdone: vi.fn(),\n\t\tfail: vi.fn(),\n\t\tsucceed: vi.fn(),\n\t};\n}\n\n/**\n * Creates a mock AWS API Gateway V1 (REST API) event for testing\n */\nexport function createMockV1Event(\n\toverrides: Partial<APIGatewayProxyEvent> = {},\n): APIGatewayProxyEvent {\n\treturn {\n\t\tbody: null,\n\t\theaders: {\n\t\t\t'content-type': 'application/json',\n\t\t\t'user-agent': 'test-agent',\n\t\t\thost: 'test.example.com',\n\t\t},\n\t\tmultiValueHeaders: {},\n\t\thttpMethod: 'GET',\n\t\tisBase64Encoded: false,\n\t\tpath: '/test',\n\t\tpathParameters: null,\n\t\tqueryStringParameters: null,\n\t\tmultiValueQueryStringParameters: null,\n\t\tstageVariables: null,\n\t\trequestContext: {\n\t\t\taccountId: '123456789012',\n\t\t\tapiId: 'api-id',\n\t\t\tauthorizer: null,\n\t\t\tprotocol: 'HTTP/1.1',\n\t\t\thttpMethod: 'GET',\n\t\t\tpath: '/test',\n\t\t\tstage: 'test',\n\t\t\trequestId: 'request-id',\n\t\t\trequestTimeEpoch: 1704067200000,\n\t\t\tresourceId: 'resource-id',\n\t\t\tresourcePath: '/test',\n\t\t\tidentity: {\n\t\t\t\taccessKey: null,\n\t\t\t\taccountId: null,\n\t\t\t\tapiKey: null,\n\t\t\t\tapiKeyId: null,\n\t\t\t\tcaller: null,\n\t\t\t\tcognitoAuthenticationProvider: null,\n\t\t\t\tcognitoAuthenticationType: null,\n\t\t\t\tcognitoIdentityId: null,\n\t\t\t\tcognitoIdentityPoolId: null,\n\t\t\t\tprincipalOrgId: null,\n\t\t\t\tsourceIp: '127.0.0.1',\n\t\t\t\tuser: null,\n\t\t\t\tuserAgent: 'test-agent',\n\t\t\t\tuserArn: null,\n\t\t\t\tclientCert: null,\n\t\t\t},\n\t\t},\n\t\tresource: '/test',\n\t\t...overrides,\n\t};\n}\n\n/**\n * Creates a mock AWS API Gateway V2 (HTTP API) event for testing\n */\nexport function createMockV2Event(\n\toverrides: Partial<APIGatewayProxyEventV2> = {},\n): APIGatewayProxyEventV2 {\n\treturn {\n\t\tversion: '2.0',\n\t\trouteKey: 'GET /test',\n\t\trawPath: '/test',\n\t\trawQueryString: '',\n\t\theaders: {\n\t\t\t'content-type': 'application/json',\n\t\t\t'user-agent': 'test-agent',\n\t\t\thost: 'test.example.com',\n\t\t},\n\t\trequestContext: {\n\t\t\taccountId: '123456789012',\n\t\t\tapiId: 'api-id',\n\t\t\tdomainName: 'test.example.com',\n\t\t\tdomainPrefix: 'api',\n\t\t\trequestId: 'request-id',\n\t\t\trouteKey: 'GET /test',\n\t\t\tstage: 'test',\n\t\t\ttime: '01/Jan/2024:00:00:00 +0000',\n\t\t\ttimeEpoch: 1704067200000,\n\t\t\thttp: {\n\t\t\t\tmethod: 'GET',\n\t\t\t\tpath: '/test',\n\t\t\t\tprotocol: 'HTTP/1.1',\n\t\t\t\tsourceIp: '127.0.0.1',\n\t\t\t\tuserAgent: 'test-agent',\n\t\t\t},\n\t\t},\n\t\tbody: undefined,\n\t\tpathParameters: undefined,\n\t\tisBase64Encoded: false,\n\t\tstageVariables: undefined,\n\t\tqueryStringParameters: undefined,\n\t\tcookies: undefined,\n\t\t...overrides,\n\t};\n}\n"],"mappings":";;;;;;;;;AAcA,SAAgB,oBAA6B;AAC5C,QAAO;EACN,cAAc;EACd,gCAAgC;EAChC,cAAc;EACd,iBAAiB;EACjB,oBACC;EACD,iBAAiB;EACjB,cAAc;EACd,eAAe;EACf,0BAA0B,MAAM;EAChC,MAAM,GAAG,IAAI;EACb,MAAM,GAAG,IAAI;EACb,SAAS,GAAG,IAAI;CAChB;AACD;;;;AAKD,SAAgB,kBACfA,YAA2C,CAAE,GACtB;AACvB,QAAO;EACN,MAAM;EACN,SAAS;GACR,gBAAgB;GAChB,cAAc;GACd,MAAM;EACN;EACD,mBAAmB,CAAE;EACrB,YAAY;EACZ,iBAAiB;EACjB,MAAM;EACN,gBAAgB;EAChB,uBAAuB;EACvB,iCAAiC;EACjC,gBAAgB;EAChB,gBAAgB;GACf,WAAW;GACX,OAAO;GACP,YAAY;GACZ,UAAU;GACV,YAAY;GACZ,MAAM;GACN,OAAO;GACP,WAAW;GACX,kBAAkB;GAClB,YAAY;GACZ,cAAc;GACd,UAAU;IACT,WAAW;IACX,WAAW;IACX,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,+BAA+B;IAC/B,2BAA2B;IAC3B,mBAAmB;IACnB,uBAAuB;IACvB,gBAAgB;IAChB,UAAU;IACV,MAAM;IACN,WAAW;IACX,SAAS;IACT,YAAY;GACZ;EACD;EACD,UAAU;EACV,GAAG;CACH;AACD;;;;AAKD,SAAgB,kBACfC,YAA6C,CAAE,GACtB;AACzB,QAAO;EACN,SAAS;EACT,UAAU;EACV,SAAS;EACT,gBAAgB;EAChB,SAAS;GACR,gBAAgB;GAChB,cAAc;GACd,MAAM;EACN;EACD,gBAAgB;GACf,WAAW;GACX,OAAO;GACP,YAAY;GACZ,cAAc;GACd,WAAW;GACX,UAAU;GACV,OAAO;GACP,MAAM;GACN,WAAW;GACX,MAAM;IACL,QAAQ;IACR,MAAM;IACN,UAAU;IACV,UAAU;IACV,WAAW;GACX;EACD;EACD;EACA;EACA,iBAAiB;EACjB;EACA;EACA;EACA,GAAG;CACH;AACD"}
|
package/dist/benchmark.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"benchmark.cjs","names":["count: number","prefix: string","subnet: string"],"sources":["../src/benchmark.ts"],"sourcesContent":["/**\n * Generates an array of test records for benchmark data sets.\n *\n * @param count - Number of records to generate\n * @returns Array of test data objects\n */\nexport function generateTestData(\n
|
|
1
|
+
{"version":3,"file":"benchmark.cjs","names":["count: number","prefix: string","subnet: string"],"sources":["../src/benchmark.ts"],"sourcesContent":["/**\n * Generates an array of test records for benchmark data sets.\n *\n * @param count - Number of records to generate\n * @returns Array of test data objects\n */\nexport function generateTestData(\n\tcount: number,\n): Array<{ id: string; name: string; value: number }> {\n\treturn Array.from({ length: count }, (_, i) => ({\n\t\tid: `id-${i}`,\n\t\tname: `Item ${i}`,\n\t\tvalue: Math.random() * 1000,\n\t}));\n}\n\n/**\n * Generates unique keys for cache benchmarks to avoid collisions.\n *\n * @param prefix - Key prefix\n * @param count - Number of keys to generate\n * @returns Array of unique cache keys\n */\nexport function generateCacheKeys(prefix: string, count: number): string[] {\n\treturn Array.from({ length: count }, (_, i) => `${prefix}:${i}`);\n}\n\n/**\n * Generates IP addresses for rate limit benchmarks.\n *\n * @param count - Number of IPs to generate\n * @param subnet - Subnet prefix (default: '192.168.1')\n * @returns Array of IP addresses\n */\nexport function generateIpAddresses(\n\tcount: number,\n\tsubnet: string = '192.168.1',\n): string[] {\n\treturn Array.from({ length: count }, (_, i) => `${subnet}.${i % 256}`);\n}\n\n/**\n * Creates a random IP address for rate limit benchmarks.\n */\nexport function randomIpAddress(): string {\n\tconst octet = () => Math.floor(Math.random() * 256);\n\treturn `${octet()}.${octet()}.${octet()}.${octet()}`;\n}\n"],"mappings":";;;;;;;;AAMA,SAAgB,iBACfA,OACqD;AACrD,QAAO,MAAM,KAAK,EAAE,QAAQ,MAAO,GAAE,CAAC,GAAG,OAAO;EAC/C,KAAK,KAAK,EAAE;EACZ,OAAO,OAAO,EAAE;EAChB,OAAO,KAAK,QAAQ,GAAG;CACvB,GAAE;AACH;;;;;;;;AASD,SAAgB,kBAAkBC,QAAgBD,OAAyB;AAC1E,QAAO,MAAM,KAAK,EAAE,QAAQ,MAAO,GAAE,CAAC,GAAG,OAAO,EAAE,OAAO,GAAG,EAAE,EAAE;AAChE;;;;;;;;AASD,SAAgB,oBACfA,OACAE,SAAiB,aACN;AACX,QAAO,MAAM,KAAK,EAAE,QAAQ,MAAO,GAAE,CAAC,GAAG,OAAO,EAAE,OAAO,GAAG,IAAI,IAAI,EAAE;AACtE;;;;AAKD,SAAgB,kBAA0B;CACzC,MAAM,QAAQ,MAAM,KAAK,MAAM,KAAK,QAAQ,GAAG,IAAI;AACnD,SAAQ,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC;AACnD"}
|
package/dist/benchmark.d.cts
CHANGED
|
@@ -30,6 +30,7 @@ declare function generateIpAddresses(count: number, subnet?: string): string[];
|
|
|
30
30
|
* Creates a random IP address for rate limit benchmarks.
|
|
31
31
|
*/
|
|
32
32
|
declare function randomIpAddress(): string;
|
|
33
|
+
//# sourceMappingURL=benchmark.d.ts.map
|
|
33
34
|
//#endregion
|
|
34
35
|
export { generateCacheKeys, generateIpAddresses, generateTestData, randomIpAddress };
|
|
35
36
|
//# sourceMappingURL=benchmark.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"benchmark.d.cts","names":[],"sources":["../src/benchmark.ts"],"sourcesContent":[],"mappings":";;AAMA;AAiBA;AAWA;AAUA;;iBAtCgB,gBAAA,iBAEb;;;;;;;;;;;;iBAea,iBAAA;;;;;;;;iBAWA,mBAAA;;;;iBAUA,eAAA,CAAA"}
|
package/dist/benchmark.d.mts
CHANGED
|
@@ -30,6 +30,7 @@ declare function generateIpAddresses(count: number, subnet?: string): string[];
|
|
|
30
30
|
* Creates a random IP address for rate limit benchmarks.
|
|
31
31
|
*/
|
|
32
32
|
declare function randomIpAddress(): string;
|
|
33
|
+
//# sourceMappingURL=benchmark.d.ts.map
|
|
33
34
|
//#endregion
|
|
34
35
|
export { generateCacheKeys, generateIpAddresses, generateTestData, randomIpAddress };
|
|
35
36
|
//# sourceMappingURL=benchmark.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"benchmark.d.mts","names":[],"sources":["../src/benchmark.ts"],"sourcesContent":[],"mappings":";;AAMA;AAiBA;AAWA;AAUA;;iBAtCgB,gBAAA,iBAEb;;;;;;;;;;;;iBAea,iBAAA;;;;;;;;iBAWA,mBAAA;;;;iBAUA,eAAA,CAAA"}
|
package/dist/benchmark.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"benchmark.mjs","names":["count: number","prefix: string","subnet: string"],"sources":["../src/benchmark.ts"],"sourcesContent":["/**\n * Generates an array of test records for benchmark data sets.\n *\n * @param count - Number of records to generate\n * @returns Array of test data objects\n */\nexport function generateTestData(\n
|
|
1
|
+
{"version":3,"file":"benchmark.mjs","names":["count: number","prefix: string","subnet: string"],"sources":["../src/benchmark.ts"],"sourcesContent":["/**\n * Generates an array of test records for benchmark data sets.\n *\n * @param count - Number of records to generate\n * @returns Array of test data objects\n */\nexport function generateTestData(\n\tcount: number,\n): Array<{ id: string; name: string; value: number }> {\n\treturn Array.from({ length: count }, (_, i) => ({\n\t\tid: `id-${i}`,\n\t\tname: `Item ${i}`,\n\t\tvalue: Math.random() * 1000,\n\t}));\n}\n\n/**\n * Generates unique keys for cache benchmarks to avoid collisions.\n *\n * @param prefix - Key prefix\n * @param count - Number of keys to generate\n * @returns Array of unique cache keys\n */\nexport function generateCacheKeys(prefix: string, count: number): string[] {\n\treturn Array.from({ length: count }, (_, i) => `${prefix}:${i}`);\n}\n\n/**\n * Generates IP addresses for rate limit benchmarks.\n *\n * @param count - Number of IPs to generate\n * @param subnet - Subnet prefix (default: '192.168.1')\n * @returns Array of IP addresses\n */\nexport function generateIpAddresses(\n\tcount: number,\n\tsubnet: string = '192.168.1',\n): string[] {\n\treturn Array.from({ length: count }, (_, i) => `${subnet}.${i % 256}`);\n}\n\n/**\n * Creates a random IP address for rate limit benchmarks.\n */\nexport function randomIpAddress(): string {\n\tconst octet = () => Math.floor(Math.random() * 256);\n\treturn `${octet()}.${octet()}.${octet()}.${octet()}`;\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,iBACfA,OACqD;AACrD,QAAO,MAAM,KAAK,EAAE,QAAQ,MAAO,GAAE,CAAC,GAAG,OAAO;EAC/C,KAAK,KAAK,EAAE;EACZ,OAAO,OAAO,EAAE;EAChB,OAAO,KAAK,QAAQ,GAAG;CACvB,GAAE;AACH;;;;;;;;AASD,SAAgB,kBAAkBC,QAAgBD,OAAyB;AAC1E,QAAO,MAAM,KAAK,EAAE,QAAQ,MAAO,GAAE,CAAC,GAAG,OAAO,EAAE,OAAO,GAAG,EAAE,EAAE;AAChE;;;;;;;;AASD,SAAgB,oBACfA,OACAE,SAAiB,aACN;AACX,QAAO,MAAM,KAAK,EAAE,QAAQ,MAAO,GAAE,CAAC,GAAG,OAAO,EAAE,OAAO,GAAG,IAAI,IAAI,EAAE;AACtE;;;;AAKD,SAAgB,kBAA0B;CACzC,MAAM,QAAQ,MAAM,KAAK,MAAM,KAAK,QAAQ,GAAG,IAAI;AACnD,SAAQ,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC;AACnD"}
|
package/dist/better-auth.cjs
CHANGED
|
@@ -99,29 +99,21 @@ const memoryAdapter = (config = {}, store = /* @__PURE__ */ new Map()) => {
|
|
|
99
99
|
supportsBooleans: true,
|
|
100
100
|
supportsNumericIds: false
|
|
101
101
|
},
|
|
102
|
-
adapter: ({ debugLog,
|
|
103
|
-
create: async ({ data, model
|
|
102
|
+
adapter: ({ debugLog, getModelName, transformWhereClause }) => ({
|
|
103
|
+
create: async ({ data, model }) => {
|
|
104
104
|
debugLog("CREATE", {
|
|
105
105
|
model,
|
|
106
106
|
data
|
|
107
107
|
});
|
|
108
108
|
const modelName = getModelName(model);
|
|
109
109
|
const modelData = storeInstance.getModel(modelName);
|
|
110
|
-
const
|
|
111
|
-
if (!
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
});
|
|
116
|
-
if (data.email_address) modelData.set(transformedData.id, {
|
|
117
|
-
...transformedData,
|
|
118
|
-
email: data.email_address
|
|
119
|
-
});
|
|
120
|
-
const created = modelData.get(transformedData.id);
|
|
121
|
-
const out = await transformOutput(created, model, select);
|
|
122
|
-
return out;
|
|
110
|
+
const record = data;
|
|
111
|
+
if (!record.id) record.id = crypto.randomUUID();
|
|
112
|
+
const id = record.id;
|
|
113
|
+
modelData.set(id, { ...record });
|
|
114
|
+
return modelData.get(id);
|
|
123
115
|
},
|
|
124
|
-
findOne: async ({ where, model
|
|
116
|
+
findOne: async ({ where, model }) => {
|
|
125
117
|
debugLog("FIND_ONE", {
|
|
126
118
|
model,
|
|
127
119
|
where
|
|
@@ -132,10 +124,7 @@ const memoryAdapter = (config = {}, store = /* @__PURE__ */ new Map()) => {
|
|
|
132
124
|
model,
|
|
133
125
|
where
|
|
134
126
|
});
|
|
135
|
-
for (const record of modelData.values()) if (matchesWhere(record, transformedWhere))
|
|
136
|
-
const t = await transformOutput(record, model, select);
|
|
137
|
-
return t;
|
|
138
|
-
}
|
|
127
|
+
for (const record of modelData.values()) if (matchesWhere(record, transformedWhere)) return record;
|
|
139
128
|
return null;
|
|
140
129
|
},
|
|
141
130
|
findMany: async ({ where, model, limit, offset, sortBy }) => {
|
|
@@ -153,7 +142,7 @@ const memoryAdapter = (config = {}, store = /* @__PURE__ */ new Map()) => {
|
|
|
153
142
|
if (sortBy) results = applySorting(results, sortBy);
|
|
154
143
|
if (offset) results = results.slice(offset);
|
|
155
144
|
if (limit) results = results.slice(0, limit);
|
|
156
|
-
return
|
|
145
|
+
return results;
|
|
157
146
|
},
|
|
158
147
|
update: async ({ where, update, model }) => {
|
|
159
148
|
debugLog("UPDATE", {
|
|
@@ -167,13 +156,12 @@ const memoryAdapter = (config = {}, store = /* @__PURE__ */ new Map()) => {
|
|
|
167
156
|
where
|
|
168
157
|
});
|
|
169
158
|
for (const [id, record] of modelData.entries()) if (matchesWhere(record, transformedWhere)) {
|
|
170
|
-
const transformedData = await transformInput(update, model, "update");
|
|
171
159
|
const updated = {
|
|
172
160
|
...record,
|
|
173
|
-
...
|
|
161
|
+
...update
|
|
174
162
|
};
|
|
175
163
|
modelData.set(id, updated);
|
|
176
|
-
return
|
|
164
|
+
return updated;
|
|
177
165
|
}
|
|
178
166
|
return null;
|
|
179
167
|
},
|
|
@@ -189,11 +177,10 @@ const memoryAdapter = (config = {}, store = /* @__PURE__ */ new Map()) => {
|
|
|
189
177
|
where
|
|
190
178
|
});
|
|
191
179
|
let count = 0;
|
|
192
|
-
const transformedData = await transformInput(update, model, "update");
|
|
193
180
|
for (const [id, record] of modelData.entries()) if (matchesWhere(record, transformedWhere)) {
|
|
194
181
|
modelData.set(id, {
|
|
195
182
|
...record,
|
|
196
|
-
...
|
|
183
|
+
...update
|
|
197
184
|
});
|
|
198
185
|
count++;
|
|
199
186
|
}
|
|
@@ -206,7 +193,11 @@ const memoryAdapter = (config = {}, store = /* @__PURE__ */ new Map()) => {
|
|
|
206
193
|
});
|
|
207
194
|
const modelName = getModelName(model);
|
|
208
195
|
const modelData = storeInstance.getModel(modelName);
|
|
209
|
-
|
|
196
|
+
const transformedWhere = transformWhereClause({
|
|
197
|
+
model,
|
|
198
|
+
where
|
|
199
|
+
});
|
|
200
|
+
for (const [id, record] of modelData.entries()) if (matchesWhere(record, transformedWhere)) {
|
|
210
201
|
modelData.delete(id);
|
|
211
202
|
return;
|
|
212
203
|
}
|
|
@@ -218,15 +209,23 @@ const memoryAdapter = (config = {}, store = /* @__PURE__ */ new Map()) => {
|
|
|
218
209
|
});
|
|
219
210
|
const modelName = getModelName(model);
|
|
220
211
|
const modelData = storeInstance.getModel(modelName);
|
|
212
|
+
const transformedWhere = transformWhereClause({
|
|
213
|
+
model,
|
|
214
|
+
where
|
|
215
|
+
});
|
|
221
216
|
const toDelete = [];
|
|
222
|
-
for (const [id, record] of modelData.entries()) if (matchesWhere(record,
|
|
223
|
-
|
|
217
|
+
for (const [id, record] of modelData.entries()) if (matchesWhere(record, transformedWhere)) toDelete.push(id);
|
|
218
|
+
for (const id of toDelete) modelData.delete(id);
|
|
224
219
|
return toDelete.length;
|
|
225
220
|
},
|
|
226
221
|
count: async ({ where, model }) => {
|
|
227
222
|
const modelName = getModelName(model);
|
|
228
223
|
const modelData = storeInstance.getModel(modelName);
|
|
229
|
-
|
|
224
|
+
const transformedWhere = transformWhereClause({
|
|
225
|
+
model,
|
|
226
|
+
where
|
|
227
|
+
});
|
|
228
|
+
return Array.from(modelData.values()).filter((record) => matchesWhere(record, transformedWhere)).length;
|
|
230
229
|
}
|
|
231
230
|
})
|
|
232
231
|
});
|