@geekmidas/testkit 10.0.0-alpha.98 → 10.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 +160 -0
- package/README.md +0 -74
- package/dist/Factory-BFVnMMCC.mjs +51 -0
- package/dist/Factory-BFVnMMCC.mjs.map +1 -0
- package/dist/Factory-BOX312yd.d.cts +147 -0
- package/dist/Factory-BOX312yd.d.cts.map +1 -0
- package/dist/Factory-BhjUOBWN.cjs +57 -0
- package/dist/Factory-BhjUOBWN.cjs.map +1 -0
- package/dist/Factory-SFupxRC2.d.mts +147 -0
- package/dist/Factory-SFupxRC2.d.mts.map +1 -0
- package/dist/Factory.cjs +2 -51
- package/dist/Factory.d.cts +3 -143
- package/dist/Factory.d.mts +3 -143
- package/dist/Factory.mjs +2 -50
- package/dist/KyselyFactory-BFqVIn_0.cjs +246 -0
- package/dist/KyselyFactory-BFqVIn_0.cjs.map +1 -0
- package/dist/KyselyFactory-DMswpwji.mjs +241 -0
- package/dist/KyselyFactory-DMswpwji.mjs.map +1 -0
- package/dist/KyselyFactory-Dy5zzV4B.d.cts +228 -0
- package/dist/KyselyFactory-Dy5zzV4B.d.cts.map +1 -0
- package/dist/KyselyFactory-vAxYodck.d.mts +228 -0
- package/dist/KyselyFactory-vAxYodck.d.mts.map +1 -0
- package/dist/KyselyFactory.cjs +4 -237
- package/dist/KyselyFactory.d.cts +4 -224
- package/dist/KyselyFactory.d.mts +4 -224
- package/dist/KyselyFactory.mjs +4 -236
- package/dist/ObjectionFactory-BWjB49-i.d.mts +241 -0
- package/dist/ObjectionFactory-BWjB49-i.d.mts.map +1 -0
- package/dist/ObjectionFactory-BeFBYcan.cjs +272 -0
- package/dist/ObjectionFactory-BeFBYcan.cjs.map +1 -0
- package/dist/ObjectionFactory-CD-WFuMJ.d.cts +241 -0
- package/dist/ObjectionFactory-CD-WFuMJ.d.cts.map +1 -0
- package/dist/ObjectionFactory-QCJ7u0Ql.mjs +267 -0
- package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +1 -0
- package/dist/ObjectionFactory.cjs +4 -265
- package/dist/ObjectionFactory.d.cts +4 -237
- package/dist/ObjectionFactory.d.mts +4 -237
- package/dist/ObjectionFactory.mjs +4 -264
- package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts +84 -0
- package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts.map +1 -0
- package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs +101 -0
- package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs.map +1 -0
- package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts +84 -0
- package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts.map +1 -0
- package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs +95 -0
- package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs.map +1 -0
- package/dist/PostgresKyselyMigrator.cjs +3 -94
- package/dist/PostgresKyselyMigrator.d.cts +3 -80
- package/dist/PostgresKyselyMigrator.d.mts +3 -80
- package/dist/PostgresKyselyMigrator.mjs +3 -93
- package/dist/{PostgresMigrator-CDPnnwMJ.d.cts → PostgresMigrator-C_QQ6q35.d.mts} +5 -11
- package/dist/PostgresMigrator-C_QQ6q35.d.mts.map +1 -0
- package/dist/{PostgresMigrator-CDPnnwMJ.d.mts → PostgresMigrator-CeYy-eHF.d.cts} +5 -11
- package/dist/PostgresMigrator-CeYy-eHF.d.cts.map +1 -0
- package/dist/PostgresMigrator-DVAY04qN.mjs +166 -0
- package/dist/PostgresMigrator-DVAY04qN.mjs.map +1 -0
- package/dist/PostgresMigrator-M9jpzOvN.cjs +172 -0
- package/dist/PostgresMigrator-M9jpzOvN.cjs.map +1 -0
- package/dist/PostgresMigrator.cjs +2 -178
- package/dist/PostgresMigrator.d.cts +1 -1
- package/dist/PostgresMigrator.d.mts +1 -1
- package/dist/PostgresMigrator.mjs +2 -175
- package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts +79 -0
- package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts.map +1 -0
- package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts +79 -0
- package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts.map +1 -0
- package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs +123 -0
- package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs.map +1 -0
- package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs +118 -0
- package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs.map +1 -0
- package/dist/PostgresObjectionMigrator.cjs +3 -118
- package/dist/PostgresObjectionMigrator.d.cts +3 -75
- package/dist/PostgresObjectionMigrator.d.mts +3 -75
- package/dist/PostgresObjectionMigrator.mjs +3 -117
- package/dist/VitestKyselyTransactionIsolator-0CqOsuc9.cjs +65 -0
- package/dist/VitestKyselyTransactionIsolator-0CqOsuc9.cjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts +59 -0
- package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts.map +1 -0
- package/dist/VitestKyselyTransactionIsolator-CfSMOFlN.mjs +60 -0
- package/dist/VitestKyselyTransactionIsolator-CfSMOFlN.mjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts +59 -0
- package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts.map +1 -0
- package/dist/VitestKyselyTransactionIsolator.cjs +3 -66
- package/dist/VitestKyselyTransactionIsolator.d.cts +3 -60
- package/dist/VitestKyselyTransactionIsolator.d.mts +3 -60
- package/dist/VitestKyselyTransactionIsolator.mjs +3 -65
- package/dist/VitestObjectionTransactionIsolator-B5J9jjKq.cjs +68 -0
- package/dist/VitestObjectionTransactionIsolator-B5J9jjKq.cjs.map +1 -0
- package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts +60 -0
- package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts.map +1 -0
- package/dist/VitestObjectionTransactionIsolator-CNo40EdC.mjs +63 -0
- package/dist/VitestObjectionTransactionIsolator-CNo40EdC.mjs.map +1 -0
- package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts +60 -0
- package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts.map +1 -0
- package/dist/VitestObjectionTransactionIsolator.cjs +3 -62
- package/dist/VitestObjectionTransactionIsolator.d.cts +3 -56
- package/dist/VitestObjectionTransactionIsolator.d.mts +3 -56
- package/dist/VitestObjectionTransactionIsolator.mjs +3 -61
- package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts +207 -0
- package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts.map +1 -0
- package/dist/VitestTransactionIsolator-CSroc7Df.d.cts +207 -0
- package/dist/VitestTransactionIsolator-CSroc7Df.d.cts.map +1 -0
- package/dist/VitestTransactionIsolator-CtZaOUjH.cjs +193 -0
- package/dist/VitestTransactionIsolator-CtZaOUjH.cjs.map +1 -0
- package/dist/VitestTransactionIsolator-D6ZxLWys.mjs +175 -0
- package/dist/VitestTransactionIsolator-D6ZxLWys.mjs.map +1 -0
- package/dist/VitestTransactionIsolator.cjs +4 -187
- package/dist/VitestTransactionIsolator.d.cts +2 -219
- package/dist/VitestTransactionIsolator.d.mts +2 -219
- package/dist/VitestTransactionIsolator.mjs +2 -184
- package/dist/aws.cjs +4 -3
- package/dist/aws.cjs.map +1 -1
- package/dist/aws.d.cts +8 -3
- package/dist/aws.d.cts.map +1 -1
- package/dist/aws.d.mts +8 -3
- package/dist/aws.d.mts.map +1 -1
- package/dist/aws.mjs +2 -1
- package/dist/aws.mjs.map +1 -1
- package/dist/benchmark.cjs +2 -2
- package/dist/benchmark.cjs.map +1 -1
- package/dist/benchmark.d.cts +6 -4
- package/dist/benchmark.d.cts.map +1 -1
- package/dist/benchmark.d.mts +6 -4
- package/dist/benchmark.d.mts.map +1 -1
- package/dist/benchmark.mjs +1 -1
- package/dist/benchmark.mjs.map +1 -1
- package/dist/better-auth.cjs +15 -31
- package/dist/better-auth.cjs.map +1 -1
- package/dist/better-auth.d.cts +4 -13142
- package/dist/better-auth.d.cts.map +1 -1
- package/dist/better-auth.d.mts +4 -13142
- package/dist/better-auth.d.mts.map +1 -1
- package/dist/better-auth.mjs +13 -29
- package/dist/better-auth.mjs.map +1 -1
- package/dist/{rolldown-runtime-VH7oDXx4.cjs → chunk-CUT6urMc.cjs} +10 -8
- package/dist/directory-Bpz5c5pj.d.cts +13 -0
- package/dist/directory-Bpz5c5pj.d.cts.map +1 -0
- package/dist/directory-BxjqmtCT.mjs +27 -0
- package/dist/directory-BxjqmtCT.mjs.map +1 -0
- package/dist/directory-CVrfTq1I.d.mts +13 -0
- package/dist/directory-CVrfTq1I.d.mts.map +1 -0
- package/dist/directory-DD_xQoSh.cjs +33 -0
- package/dist/directory-DD_xQoSh.cjs.map +1 -0
- package/dist/faker-B14IEMIN.cjs +304 -0
- package/dist/faker-B14IEMIN.cjs.map +1 -0
- package/dist/faker-BGKYFoCT.mjs +262 -0
- package/dist/faker-BGKYFoCT.mjs.map +1 -0
- package/dist/faker-Cg76aFNO.d.cts +166 -0
- package/dist/faker-Cg76aFNO.d.cts.map +1 -0
- package/dist/faker-DHh7xs4u.d.mts +166 -0
- package/dist/faker-DHh7xs4u.d.mts.map +1 -0
- package/dist/faker.cjs +8 -313
- package/dist/faker.d.cts +2 -169
- package/dist/faker.d.mts +2 -169
- package/dist/faker.mjs +2 -305
- package/dist/helpers.cjs +5 -6
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +5 -1
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +5 -1
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +2 -1
- package/dist/helpers.mjs.map +1 -1
- package/dist/initScript.cjs +15 -15
- package/dist/initScript.cjs.map +1 -1
- package/dist/initScript.d.cts +4 -2
- package/dist/initScript.d.cts.map +1 -1
- package/dist/initScript.d.mts +4 -2
- package/dist/initScript.d.mts.map +1 -1
- package/dist/initScript.mjs +12 -10
- package/dist/initScript.mjs.map +1 -1
- package/dist/kysely.cjs +13 -10
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +14 -10
- package/dist/kysely.d.cts.map +1 -1
- package/dist/kysely.d.mts +14 -10
- package/dist/kysely.d.mts.map +1 -1
- package/dist/kysely.mjs +14 -10
- package/dist/kysely.mjs.map +1 -1
- package/dist/logger.cjs +4 -3
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +5 -1
- package/dist/logger.d.cts.map +1 -1
- package/dist/logger.d.mts +5 -1
- package/dist/logger.d.mts.map +1 -1
- package/dist/logger.mjs +2 -1
- package/dist/logger.mjs.map +1 -1
- package/dist/objection.cjs +13 -10
- package/dist/objection.cjs.map +1 -1
- package/dist/objection.d.cts +14 -10
- package/dist/objection.d.cts.map +1 -1
- package/dist/objection.d.mts +14 -10
- package/dist/objection.d.mts.map +1 -1
- package/dist/objection.mjs +14 -10
- package/dist/objection.mjs.map +1 -1
- package/dist/os/directory.cjs +2 -31
- package/dist/os/directory.d.cts +2 -9
- package/dist/os/directory.d.mts +2 -9
- package/dist/os/directory.mjs +2 -25
- package/dist/os/index.cjs +3 -3
- package/dist/os/index.d.cts +1 -1
- package/dist/os/index.d.mts +1 -1
- package/dist/os/index.mjs +3 -2
- package/dist/requestContext.cjs +11 -10
- package/dist/requestContext.cjs.map +1 -1
- package/dist/requestContext.d.cts +9 -5
- package/dist/requestContext.d.cts.map +1 -1
- package/dist/requestContext.d.mts +9 -5
- package/dist/requestContext.d.mts.map +1 -1
- package/dist/requestContext.mjs +3 -2
- package/dist/requestContext.mjs.map +1 -1
- package/dist/timer.cjs +2 -2
- package/dist/timer.cjs.map +1 -1
- package/dist/timer.d.cts +4 -1
- package/dist/timer.d.cts.map +1 -1
- package/dist/timer.d.mts +4 -1
- package/dist/timer.d.mts.map +1 -1
- package/dist/timer.mjs +1 -1
- package/dist/timer.mjs.map +1 -1
- package/package.json +25 -65
- package/src/Factory.ts +174 -0
- package/src/KyselyFactory.ts +391 -0
- package/src/ObjectionFactory.ts +412 -0
- package/src/PostgresKyselyMigrator.ts +104 -0
- package/src/PostgresMigrator.ts +193 -0
- package/src/PostgresObjectionMigrator.ts +138 -0
- package/src/VitestKyselyTransactionIsolator.ts +72 -0
- package/src/VitestObjectionTransactionIsolator.ts +75 -0
- package/src/VitestTransactionIsolator.ts +348 -0
- package/src/__tests__/Factory.spec.ts +178 -0
- package/src/__tests__/KyselyFactory.spec.ts +458 -0
- package/src/__tests__/ObjectionFactory.spec.ts +586 -0
- package/src/__tests__/PostgresKyselyMigrator.spec.ts +794 -0
- package/src/__tests__/PostgresMigrator.spec.ts +471 -0
- package/src/__tests__/PostgresObjectionMigrator.spec.ts +634 -0
- package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +138 -0
- package/src/__tests__/benchmark.spec.ts +140 -0
- package/src/__tests__/better-auth.spec.ts +21 -0
- package/src/__tests__/faker.spec.ts +231 -0
- package/src/__tests__/initScript.spec.ts +332 -0
- package/src/__tests__/integration.spec.ts +610 -0
- package/src/__tests__/requestContext.spec.ts +113 -0
- package/src/__tests__/utilities.spec.ts +211 -0
- package/src/aws.ts +131 -0
- package/src/benchmark.ts +48 -0
- package/src/better-auth.ts +310 -0
- package/src/faker.ts +349 -0
- package/src/helpers.ts +45 -0
- package/src/initScript.ts +122 -0
- package/src/kysely.ts +166 -0
- package/src/logger.ts +18 -0
- package/src/objection.ts +157 -0
- package/src/os/directory.ts +26 -0
- package/src/os/index.ts +1 -0
- package/src/requestContext.ts +119 -0
- package/src/timer.ts +3 -0
- package/test/globalSetup.ts +54 -0
- package/test/helpers.ts +268 -0
- package/test/migrations/1749664623372_user.ts +22 -0
- package/tsconfig.json +9 -0
- package/vitest.config.ts +8 -0
- package/dist/Factory.cjs.map +0 -1
- package/dist/Factory.d.cts.map +0 -1
- package/dist/Factory.d.mts.map +0 -1
- package/dist/Factory.mjs.map +0 -1
- package/dist/KyselyFactory.cjs.map +0 -1
- package/dist/KyselyFactory.d.cts.map +0 -1
- package/dist/KyselyFactory.d.mts.map +0 -1
- package/dist/KyselyFactory.mjs.map +0 -1
- package/dist/ObjectionFactory.cjs.map +0 -1
- package/dist/ObjectionFactory.d.cts.map +0 -1
- package/dist/ObjectionFactory.d.mts.map +0 -1
- package/dist/ObjectionFactory.mjs.map +0 -1
- package/dist/PostgresKyselyMigrator.cjs.map +0 -1
- package/dist/PostgresKyselyMigrator.d.cts.map +0 -1
- package/dist/PostgresKyselyMigrator.d.mts.map +0 -1
- package/dist/PostgresKyselyMigrator.mjs.map +0 -1
- package/dist/PostgresMigrator-CDPnnwMJ.d.cts.map +0 -1
- package/dist/PostgresMigrator-CDPnnwMJ.d.mts.map +0 -1
- package/dist/PostgresMigrator.cjs.map +0 -1
- package/dist/PostgresMigrator.mjs.map +0 -1
- package/dist/PostgresObjectionMigrator.cjs.map +0 -1
- package/dist/PostgresObjectionMigrator.d.cts.map +0 -1
- package/dist/PostgresObjectionMigrator.d.mts.map +0 -1
- package/dist/PostgresObjectionMigrator.mjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator.cjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator.d.cts.map +0 -1
- package/dist/VitestKyselyTransactionIsolator.d.mts.map +0 -1
- package/dist/VitestKyselyTransactionIsolator.mjs.map +0 -1
- package/dist/VitestObjectionTransactionIsolator.cjs.map +0 -1
- package/dist/VitestObjectionTransactionIsolator.d.cts.map +0 -1
- package/dist/VitestObjectionTransactionIsolator.d.mts.map +0 -1
- package/dist/VitestObjectionTransactionIsolator.mjs.map +0 -1
- package/dist/VitestTransactionIsolator.cjs.map +0 -1
- package/dist/VitestTransactionIsolator.d.cts.map +0 -1
- package/dist/VitestTransactionIsolator.d.mts.map +0 -1
- package/dist/VitestTransactionIsolator.mjs.map +0 -1
- package/dist/browser.cjs +0 -149
- package/dist/browser.cjs.map +0 -1
- package/dist/browser.d.cts +0 -62
- package/dist/browser.d.cts.map +0 -1
- package/dist/browser.d.mts +0 -62
- package/dist/browser.d.mts.map +0 -1
- package/dist/browser.mjs +0 -147
- package/dist/browser.mjs.map +0 -1
- package/dist/context.cjs +0 -80
- package/dist/context.cjs.map +0 -1
- package/dist/context.d.cts +0 -55
- package/dist/context.d.cts.map +0 -1
- package/dist/context.d.mts +0 -55
- package/dist/context.d.mts.map +0 -1
- package/dist/context.mjs +0 -73
- package/dist/context.mjs.map +0 -1
- package/dist/faker.cjs.map +0 -1
- package/dist/faker.d.cts.map +0 -1
- package/dist/faker.d.mts.map +0 -1
- package/dist/faker.mjs.map +0 -1
- package/dist/mailbox.cjs +0 -95
- package/dist/mailbox.cjs.map +0 -1
- package/dist/mailbox.d.cts +0 -58
- package/dist/mailbox.d.cts.map +0 -1
- package/dist/mailbox.d.mts +0 -58
- package/dist/mailbox.d.mts.map +0 -1
- package/dist/mailbox.mjs +0 -92
- package/dist/mailbox.mjs.map +0 -1
- package/dist/os/directory.cjs.map +0 -1
- package/dist/os/directory.d.cts.map +0 -1
- package/dist/os/directory.d.mts.map +0 -1
- package/dist/os/directory.mjs.map +0 -1
- package/dist/transactions.cjs +0 -239
- package/dist/transactions.cjs.map +0 -1
- package/dist/transactions.d.cts +0 -44
- package/dist/transactions.d.cts.map +0 -1
- package/dist/transactions.d.mts +0 -44
- package/dist/transactions.d.mts.map +0 -1
- package/dist/transactions.mjs +0 -234
- package/dist/transactions.mjs.map +0 -1
|
@@ -1,265 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Factory implementation for Objection.js ORM, providing test data creation utilities.
|
|
6
|
-
* Extends the base Factory class with Objection.js-specific database operations.
|
|
7
|
-
*
|
|
8
|
-
* @template Builders - Record of builder functions for creating entities
|
|
9
|
-
* @template Seeds - Record of seed functions for complex test scenarios
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* // Define your models with Objection.js
|
|
14
|
-
* class User extends Model {
|
|
15
|
-
* static tableName = 'users';
|
|
16
|
-
* }
|
|
17
|
-
*
|
|
18
|
-
* // Create builders
|
|
19
|
-
* const builders = {
|
|
20
|
-
* user: ObjectionFactory.createBuilder(User, ({ attrs, faker }) => ({
|
|
21
|
-
* id: faker.string.uuid(),
|
|
22
|
-
* name: faker.person.fullName(),
|
|
23
|
-
* email: faker.internet.email(),
|
|
24
|
-
* ...attrs
|
|
25
|
-
* })),
|
|
26
|
-
* post: ObjectionFactory.createBuilder(Post, ({ attrs }) => ({
|
|
27
|
-
* title: 'Test Post',
|
|
28
|
-
* content: 'Test content',
|
|
29
|
-
* ...attrs
|
|
30
|
-
* })),
|
|
31
|
-
* };
|
|
32
|
-
*
|
|
33
|
-
* // Create factory instance
|
|
34
|
-
* const factory = new ObjectionFactory(builders, seeds, knex);
|
|
35
|
-
*
|
|
36
|
-
* // Use in tests
|
|
37
|
-
* const user = await factory.insert('user', { name: 'John Doe' });
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
var ObjectionFactory = class extends Factory {
|
|
41
|
-
builders;
|
|
42
|
-
seeds;
|
|
43
|
-
db;
|
|
44
|
-
/**
|
|
45
|
-
* Creates a typed seed function with proper type inference.
|
|
46
|
-
* Inherits from the base Factory class implementation.
|
|
47
|
-
*
|
|
48
|
-
* @template Seed - The seed function type
|
|
49
|
-
* @param seedFn - The seed function to wrap (receives { attrs, factory, db } object)
|
|
50
|
-
* @returns The same seed function with proper typing
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```typescript
|
|
54
|
-
* const seeds = {
|
|
55
|
-
* userWithPosts: ObjectionFactory.createSeed(
|
|
56
|
-
* async ({ attrs, factory }) => {
|
|
57
|
-
* const user = await factory.insert('user', attrs);
|
|
58
|
-
* await factory.insertMany(3, 'post', { userId: user.id });
|
|
59
|
-
* return user;
|
|
60
|
-
* },
|
|
61
|
-
* ),
|
|
62
|
-
* };
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
static createSeed(seedFn) {
|
|
66
|
-
return Factory.createSeed(seedFn);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Creates a typed builder function for Objection.js models.
|
|
70
|
-
* This is a utility method that helps create builders with proper type inference.
|
|
71
|
-
*
|
|
72
|
-
* @template TModel - The Objection.js Model class type
|
|
73
|
-
* @template Attrs - The attributes type for the builder (defaults to Partial of model)
|
|
74
|
-
* @template Factory - The factory instance type
|
|
75
|
-
* @template Result - The result type (defaults to the model instance)
|
|
76
|
-
*
|
|
77
|
-
* @param ModelClass - The Objection.js Model class
|
|
78
|
-
* @param defaults - Optional function to provide default values (receives destructured context)
|
|
79
|
-
* @param autoInsert - Whether to automatically insert the record (default: true)
|
|
80
|
-
* @returns A builder function that creates and optionally inserts records
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```typescript
|
|
84
|
-
* // Create a simple builder with defaults - destructure only what you need
|
|
85
|
-
* const userBuilder = ObjectionFactory.createBuilder(User,
|
|
86
|
-
* ({ attrs, faker }) => ({
|
|
87
|
-
* id: faker.string.uuid(),
|
|
88
|
-
* name: faker.person.fullName(),
|
|
89
|
-
* email: faker.internet.email(),
|
|
90
|
-
* createdAt: new Date(),
|
|
91
|
-
* ...attrs
|
|
92
|
-
* })
|
|
93
|
-
* );
|
|
94
|
-
*
|
|
95
|
-
* // Only need faker? Just destructure that
|
|
96
|
-
* const leaveTypeBuilder = ObjectionFactory.createBuilder(LeaveType,
|
|
97
|
-
* ({ faker }) => ({
|
|
98
|
-
* name: faker.helpers.arrayElement(['Annual', 'Sick', 'Maternity']),
|
|
99
|
-
* code: faker.string.alpha({ length: 3, casing: 'upper' }),
|
|
100
|
-
* })
|
|
101
|
-
* );
|
|
102
|
-
*
|
|
103
|
-
* // Create a builder that doesn't auto-insert (useful for nested inserts)
|
|
104
|
-
* const addressBuilder = ObjectionFactory.createBuilder(Address,
|
|
105
|
-
* ({ attrs }) => ({
|
|
106
|
-
* street: '123 Main St',
|
|
107
|
-
* city: 'Anytown',
|
|
108
|
-
* ...attrs
|
|
109
|
-
* }),
|
|
110
|
-
* false // Don't auto-insert
|
|
111
|
-
* );
|
|
112
|
-
*
|
|
113
|
-
* // Use with relations
|
|
114
|
-
* const postBuilder = ObjectionFactory.createBuilder(Post,
|
|
115
|
-
* async ({ attrs, factory, faker }) => ({
|
|
116
|
-
* title: faker.lorem.sentence(),
|
|
117
|
-
* content: faker.lorem.paragraphs(),
|
|
118
|
-
* authorId: attrs.authorId || (await factory.insert('user')).id,
|
|
119
|
-
* ...attrs
|
|
120
|
-
* })
|
|
121
|
-
* );
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
static createBuilder(ModelClass, defaults, autoInsert) {
|
|
125
|
-
return async (attrs, factory, db, fakerInstance) => {
|
|
126
|
-
let data = { ...attrs };
|
|
127
|
-
if (defaults) data = {
|
|
128
|
-
...await defaults({
|
|
129
|
-
attrs,
|
|
130
|
-
factory,
|
|
131
|
-
db,
|
|
132
|
-
faker: fakerInstance
|
|
133
|
-
}),
|
|
134
|
-
...data
|
|
135
|
-
};
|
|
136
|
-
const model = ModelClass.fromJson(data);
|
|
137
|
-
if (autoInsert !== false) {
|
|
138
|
-
const insertData = Object.entries(model).reduce((acc, [key, value]) => {
|
|
139
|
-
if (value !== void 0 && key !== "id") acc[key] = value;
|
|
140
|
-
return acc;
|
|
141
|
-
}, {});
|
|
142
|
-
return await ModelClass.query(db).insert(insertData);
|
|
143
|
-
} else return model;
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Creates a new ObjectionFactory instance.
|
|
148
|
-
*
|
|
149
|
-
* @param builders - Record of builder functions for creating individual entities
|
|
150
|
-
* @param seeds - Record of seed functions for creating complex test scenarios
|
|
151
|
-
* @param db - Knex database connection instance
|
|
152
|
-
*/
|
|
153
|
-
constructor(builders, seeds, db) {
|
|
154
|
-
super();
|
|
155
|
-
this.builders = builders;
|
|
156
|
-
this.seeds = seeds;
|
|
157
|
-
this.db = db;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Inserts a single record into the database using the specified builder.
|
|
161
|
-
* Uses Objection.js's insertGraph method to handle nested relations.
|
|
162
|
-
*
|
|
163
|
-
* @template K - The builder name (must be a key of Builders)
|
|
164
|
-
* @param builderName - The name of the builder to use
|
|
165
|
-
* @param attrs - Optional attributes to override builder defaults
|
|
166
|
-
* @returns A promise resolving to the inserted record with all relations
|
|
167
|
-
* @throws Error if the specified builder doesn't exist
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* ```typescript
|
|
171
|
-
* // Insert with defaults
|
|
172
|
-
* const user = await factory.insert('user');
|
|
173
|
-
*
|
|
174
|
-
* // Insert with overrides
|
|
175
|
-
* const adminUser = await factory.insert('user', {
|
|
176
|
-
* email: 'admin@example.com',
|
|
177
|
-
* role: 'admin'
|
|
178
|
-
* });
|
|
179
|
-
*
|
|
180
|
-
* // Insert with nested relations
|
|
181
|
-
* const userWithProfile = await factory.insert('user', {
|
|
182
|
-
* name: 'John Doe',
|
|
183
|
-
* profile: {
|
|
184
|
-
* bio: 'Software Developer',
|
|
185
|
-
* avatar: 'avatar.jpg'
|
|
186
|
-
* }
|
|
187
|
-
* });
|
|
188
|
-
* ```
|
|
189
|
-
*/
|
|
190
|
-
async insert(builderName, attrs) {
|
|
191
|
-
if (!(builderName in this.builders)) throw new Error(`Factory "${builderName}" does not exist. Make sure it is correct and registered in src/test/setup.ts`);
|
|
192
|
-
const result = await this.builders[builderName](attrs || {}, this, this.db, faker);
|
|
193
|
-
if (result && typeof result.$query === "function") {
|
|
194
|
-
const insertData = Object.entries(result).reduce((acc, [key, value]) => {
|
|
195
|
-
if (value !== void 0 && key !== "id") acc[key] = value;
|
|
196
|
-
return acc;
|
|
197
|
-
}, {});
|
|
198
|
-
return await result.constructor.query(this.db).insert(insertData);
|
|
199
|
-
}
|
|
200
|
-
return result;
|
|
201
|
-
}
|
|
202
|
-
async insertMany(count, builderName, attrs) {
|
|
203
|
-
if (!(builderName in this.builders)) throw new Error(`Builder "${builderName}" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`);
|
|
204
|
-
const records = [];
|
|
205
|
-
for (let i = 0; i < count; i++) {
|
|
206
|
-
const newAttrs = typeof attrs === "function" ? await attrs(i, faker) : attrs;
|
|
207
|
-
records.push(this.builders[builderName](newAttrs, this, this.db, faker).then((record) => {
|
|
208
|
-
if (record && typeof record.$query === "function") {
|
|
209
|
-
const insertData = Object.entries(record).reduce((acc, [key, value]) => {
|
|
210
|
-
if (value !== void 0 && key !== "id") acc[key] = value;
|
|
211
|
-
return acc;
|
|
212
|
-
}, {});
|
|
213
|
-
return record.constructor.query(this.db).insert(insertData);
|
|
214
|
-
}
|
|
215
|
-
return record;
|
|
216
|
-
}));
|
|
217
|
-
}
|
|
218
|
-
return Promise.all(records);
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Executes a seed function to create complex test scenarios with multiple related records.
|
|
222
|
-
* Seeds are useful for setting up complete test environments with realistic data relationships.
|
|
223
|
-
*
|
|
224
|
-
* @template K - The seed name (must be a key of Seeds)
|
|
225
|
-
* @param seedName - The name of the seed to execute
|
|
226
|
-
* @param attrs - Optional configuration attributes for the seed
|
|
227
|
-
* @returns The result of the seed function (typically the primary record created)
|
|
228
|
-
* @throws Error if the specified seed doesn't exist
|
|
229
|
-
*
|
|
230
|
-
* @example
|
|
231
|
-
* ```typescript
|
|
232
|
-
* // Execute a simple seed
|
|
233
|
-
* const user = await factory.seed('userWithProfile');
|
|
234
|
-
*
|
|
235
|
-
* // Execute a seed with configuration
|
|
236
|
-
* const author = await factory.seed('authorWithBooks', {
|
|
237
|
-
* bookCount: 5,
|
|
238
|
-
* includeReviews: true
|
|
239
|
-
* });
|
|
240
|
-
*
|
|
241
|
-
* // Use seed result in tests with Objection.js relations
|
|
242
|
-
* const company = await factory.seed('companyWithDepartments', {
|
|
243
|
-
* departmentCount: 3,
|
|
244
|
-
* employeesPerDepartment: 10
|
|
245
|
-
* });
|
|
246
|
-
*
|
|
247
|
-
* // Access eager loaded relations
|
|
248
|
-
* const companyWithRelations = await Company.query()
|
|
249
|
-
* .findById(company.id)
|
|
250
|
-
* .withGraphFetched('[departments.employees]');
|
|
251
|
-
* ```
|
|
252
|
-
*/
|
|
253
|
-
seed(seedName, attrs) {
|
|
254
|
-
if (!(seedName in this.seeds)) throw new Error(`Seed "${seedName}" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`);
|
|
255
|
-
return this.seeds[seedName]({
|
|
256
|
-
attrs: attrs || {},
|
|
257
|
-
factory: this,
|
|
258
|
-
db: this.db
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
//#endregion
|
|
263
|
-
export { ObjectionFactory };
|
|
1
|
+
import "./Factory-BFVnMMCC.mjs";
|
|
2
|
+
import "./faker-BGKYFoCT.mjs";
|
|
3
|
+
import { ObjectionFactory } from "./ObjectionFactory-QCJ7u0Ql.mjs";
|
|
264
4
|
|
|
265
|
-
|
|
5
|
+
export { ObjectionFactory };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { PostgresMigrator } from "./PostgresMigrator-CeYy-eHF.cjs";
|
|
2
|
+
import { Kysely } from "kysely";
|
|
3
|
+
import { MigrationProvider } from "kysely/migration";
|
|
4
|
+
|
|
5
|
+
//#region src/PostgresKyselyMigrator.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* PostgreSQL migrator implementation for Kysely ORM.
|
|
9
|
+
* Extends PostgresMigrator to provide Kysely-specific migration functionality.
|
|
10
|
+
* Automatically creates test databases and applies migrations for testing environments.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { FileMigrationProvider } from 'kysely';
|
|
15
|
+
* import { PostgresKyselyMigrator } from '@geekmidas/testkit';
|
|
16
|
+
*
|
|
17
|
+
* // Create migration provider
|
|
18
|
+
* const provider = new FileMigrationProvider({
|
|
19
|
+
* fs: require('fs'),
|
|
20
|
+
* path: require('path'),
|
|
21
|
+
* migrationFolder: path.join(__dirname, 'migrations')
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Create Kysely instance
|
|
25
|
+
* const db = new Kysely<Database>({
|
|
26
|
+
* dialect: new PostgresDialect({
|
|
27
|
+
* pool: new Pool({ connectionString: uri })
|
|
28
|
+
* })
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Create and use migrator
|
|
32
|
+
* const migrator = new PostgresKyselyMigrator({
|
|
33
|
+
* uri: 'postgresql://localhost:5432/test_db',
|
|
34
|
+
* db,
|
|
35
|
+
* provider
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const cleanup = await migrator.start();
|
|
39
|
+
* // Run tests...
|
|
40
|
+
* await cleanup();
|
|
41
|
+
*
|
|
42
|
+
* // With afterCreate hook to create per-app users
|
|
43
|
+
* import { runInitScript } from '@geekmidas/testkit/postgres';
|
|
44
|
+
*
|
|
45
|
+
* const migrator = new PostgresKyselyMigrator({
|
|
46
|
+
* uri: 'postgresql://localhost:5432/test_db',
|
|
47
|
+
* db,
|
|
48
|
+
* provider,
|
|
49
|
+
* afterCreate: async (uri) => {
|
|
50
|
+
* await runInitScript('docker/postgres/init.sh', uri, env);
|
|
51
|
+
* },
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
declare class PostgresKyselyMigrator extends PostgresMigrator {
|
|
56
|
+
private options;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new PostgresKyselyMigrator instance.
|
|
59
|
+
*
|
|
60
|
+
* @param options - Configuration options
|
|
61
|
+
* @param options.uri - PostgreSQL connection URI
|
|
62
|
+
* @param options.db - Kysely database instance
|
|
63
|
+
* @param options.provider - Migration provider for locating migration files
|
|
64
|
+
* @param options.afterCreate - Optional hook called after database creation but before migrations
|
|
65
|
+
*/
|
|
66
|
+
constructor(options: {
|
|
67
|
+
uri: string;
|
|
68
|
+
db: Kysely<any>;
|
|
69
|
+
provider: MigrationProvider;
|
|
70
|
+
afterCreate?: (uri: string) => Promise<void>;
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* Executes Kysely migrations to the latest version.
|
|
74
|
+
* Implements the abstract migrate() method from PostgresMigrator.
|
|
75
|
+
*
|
|
76
|
+
* @throws Error if migrations fail to apply
|
|
77
|
+
* @returns Promise that resolves when all migrations are applied
|
|
78
|
+
*/
|
|
79
|
+
migrate(): Promise<void>;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=PostgresKyselyMigrator.d.ts.map
|
|
82
|
+
//#endregion
|
|
83
|
+
export { PostgresKyselyMigrator };
|
|
84
|
+
//# sourceMappingURL=PostgresKyselyMigrator-B2M6Gjvv.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostgresKyselyMigrator-B2M6Gjvv.d.cts","names":[],"sources":["../src/PostgresKyselyMigrator.ts"],"sourcesContent":[],"mappings":";;;;;;;;AA2DA;;;;;;;AAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAA/C,sBAAA,SAA+B,gBAAA;;;;;;;;;;;;;QAarC;cACM;mCACqB;;;;;;;;;aAahB"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_PostgresMigrator = require('./PostgresMigrator-M9jpzOvN.cjs');
|
|
3
|
+
const kysely_migration = require_chunk.__toESM(require("kysely/migration"));
|
|
4
|
+
|
|
5
|
+
//#region src/PostgresKyselyMigrator.ts
|
|
6
|
+
/**
|
|
7
|
+
* Default logger instance for migration operations.
|
|
8
|
+
*/
|
|
9
|
+
const logger = console;
|
|
10
|
+
/**
|
|
11
|
+
* PostgreSQL migrator implementation for Kysely ORM.
|
|
12
|
+
* Extends PostgresMigrator to provide Kysely-specific migration functionality.
|
|
13
|
+
* Automatically creates test databases and applies migrations for testing environments.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { FileMigrationProvider } from 'kysely';
|
|
18
|
+
* import { PostgresKyselyMigrator } from '@geekmidas/testkit';
|
|
19
|
+
*
|
|
20
|
+
* // Create migration provider
|
|
21
|
+
* const provider = new FileMigrationProvider({
|
|
22
|
+
* fs: require('fs'),
|
|
23
|
+
* path: require('path'),
|
|
24
|
+
* migrationFolder: path.join(__dirname, 'migrations')
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Create Kysely instance
|
|
28
|
+
* const db = new Kysely<Database>({
|
|
29
|
+
* dialect: new PostgresDialect({
|
|
30
|
+
* pool: new Pool({ connectionString: uri })
|
|
31
|
+
* })
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* // Create and use migrator
|
|
35
|
+
* const migrator = new PostgresKyselyMigrator({
|
|
36
|
+
* uri: 'postgresql://localhost:5432/test_db',
|
|
37
|
+
* db,
|
|
38
|
+
* provider
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* const cleanup = await migrator.start();
|
|
42
|
+
* // Run tests...
|
|
43
|
+
* await cleanup();
|
|
44
|
+
*
|
|
45
|
+
* // With afterCreate hook to create per-app users
|
|
46
|
+
* import { runInitScript } from '@geekmidas/testkit/postgres';
|
|
47
|
+
*
|
|
48
|
+
* const migrator = new PostgresKyselyMigrator({
|
|
49
|
+
* uri: 'postgresql://localhost:5432/test_db',
|
|
50
|
+
* db,
|
|
51
|
+
* provider,
|
|
52
|
+
* afterCreate: async (uri) => {
|
|
53
|
+
* await runInitScript('docker/postgres/init.sh', uri, env);
|
|
54
|
+
* },
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
var PostgresKyselyMigrator = class extends require_PostgresMigrator.PostgresMigrator {
|
|
59
|
+
/**
|
|
60
|
+
* Creates a new PostgresKyselyMigrator instance.
|
|
61
|
+
*
|
|
62
|
+
* @param options - Configuration options
|
|
63
|
+
* @param options.uri - PostgreSQL connection URI
|
|
64
|
+
* @param options.db - Kysely database instance
|
|
65
|
+
* @param options.provider - Migration provider for locating migration files
|
|
66
|
+
* @param options.afterCreate - Optional hook called after database creation but before migrations
|
|
67
|
+
*/
|
|
68
|
+
constructor(options) {
|
|
69
|
+
super(options.uri, options.afterCreate);
|
|
70
|
+
this.options = options;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Executes Kysely migrations to the latest version.
|
|
74
|
+
* Implements the abstract migrate() method from PostgresMigrator.
|
|
75
|
+
*
|
|
76
|
+
* @throws Error if migrations fail to apply
|
|
77
|
+
* @returns Promise that resolves when all migrations are applied
|
|
78
|
+
*/
|
|
79
|
+
async migrate() {
|
|
80
|
+
const migrator = new kysely_migration.Migrator({
|
|
81
|
+
db: this.options.db,
|
|
82
|
+
provider: this.options.provider
|
|
83
|
+
});
|
|
84
|
+
const migrations = await migrator.migrateToLatest();
|
|
85
|
+
if (migrations.error) {
|
|
86
|
+
logger.error(migrations.error, `Failed to apply migrations`);
|
|
87
|
+
throw migrations.error;
|
|
88
|
+
}
|
|
89
|
+
await this.options.db.destroy();
|
|
90
|
+
logger.log(`Applied ${migrations.results?.length} migrations successfully`);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
Object.defineProperty(exports, 'PostgresKyselyMigrator', {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function () {
|
|
98
|
+
return PostgresKyselyMigrator;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
//# sourceMappingURL=PostgresKyselyMigrator-BGBxjnFv.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostgresKyselyMigrator-BGBxjnFv.cjs","names":["PostgresMigrator","options: {\n\t\t\turi: string;\n\t\t\tdb: Kysely<any>;\n\t\t\tprovider: MigrationProvider;\n\t\t\tafterCreate?: (uri: string) => Promise<void>;\n\t\t}","Migrator"],"sources":["../src/PostgresKyselyMigrator.ts"],"sourcesContent":["import type { Kysely } from 'kysely';\n// `Migrator` and the `MigrationProvider` type moved from the root barrel ('kysely')\n// to the 'kysely/migration' subpath in kysely 0.29+.\nimport { type MigrationProvider, Migrator } from 'kysely/migration';\nimport { PostgresMigrator } from './PostgresMigrator';\n\n/**\n * Default logger instance for migration operations.\n */\nconst logger = console;\n\n/**\n * PostgreSQL migrator implementation for Kysely ORM.\n * Extends PostgresMigrator to provide Kysely-specific migration functionality.\n * Automatically creates test databases and applies migrations for testing environments.\n *\n * @example\n * ```typescript\n * import { FileMigrationProvider } from 'kysely';\n * import { PostgresKyselyMigrator } from '@geekmidas/testkit';\n *\n * // Create migration provider\n * const provider = new FileMigrationProvider({\n * fs: require('fs'),\n * path: require('path'),\n * migrationFolder: path.join(__dirname, 'migrations')\n * });\n *\n * // Create Kysely instance\n * const db = new Kysely<Database>({\n * dialect: new PostgresDialect({\n * pool: new Pool({ connectionString: uri })\n * })\n * });\n *\n * // Create and use migrator\n * const migrator = new PostgresKyselyMigrator({\n * uri: 'postgresql://localhost:5432/test_db',\n * db,\n * provider\n * });\n *\n * const cleanup = await migrator.start();\n * // Run tests...\n * await cleanup();\n *\n * // With afterCreate hook to create per-app users\n * import { runInitScript } from '@geekmidas/testkit/postgres';\n *\n * const migrator = new PostgresKyselyMigrator({\n * uri: 'postgresql://localhost:5432/test_db',\n * db,\n * provider,\n * afterCreate: async (uri) => {\n * await runInitScript('docker/postgres/init.sh', uri, env);\n * },\n * });\n * ```\n */\nexport class PostgresKyselyMigrator extends PostgresMigrator {\n\t/**\n\t * Creates a new PostgresKyselyMigrator instance.\n\t *\n\t * @param options - Configuration options\n\t * @param options.uri - PostgreSQL connection URI\n\t * @param options.db - Kysely database instance\n\t * @param options.provider - Migration provider for locating migration files\n\t * @param options.afterCreate - Optional hook called after database creation but before migrations\n\t */\n\tconstructor(\n\t\tprivate options: {\n\t\t\turi: string;\n\t\t\tdb: Kysely<any>;\n\t\t\tprovider: MigrationProvider;\n\t\t\tafterCreate?: (uri: string) => Promise<void>;\n\t\t},\n\t) {\n\t\tsuper(options.uri, options.afterCreate);\n\t}\n\n\t/**\n\t * Executes Kysely migrations to the latest version.\n\t * Implements the abstract migrate() method from PostgresMigrator.\n\t *\n\t * @throws Error if migrations fail to apply\n\t * @returns Promise that resolves when all migrations are applied\n\t */\n\tasync migrate(): Promise<void> {\n\t\tconst migrator = new Migrator({\n\t\t\tdb: this.options.db,\n\t\t\tprovider: this.options.provider,\n\t\t});\n\t\tconst migrations = await migrator.migrateToLatest();\n\n\t\tif (migrations.error) {\n\t\t\tlogger.error(migrations.error, `Failed to apply migrations`);\n\t\t\tthrow migrations.error;\n\t\t}\n\n\t\tawait this.options.db.destroy();\n\n\t\tlogger.log(`Applied ${migrations.results?.length} migrations successfully`);\n\t}\n}\n"],"mappings":";;;;;;;;AASA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDf,IAAa,yBAAb,cAA4CA,0CAAiB;;;;;;;;;;CAU5D,YACSC,SAMP;AACD,QAAM,QAAQ,KAAK,QAAQ,YAAY;EAP/B;CAQR;;;;;;;;CASD,MAAM,UAAyB;EAC9B,MAAM,WAAW,IAAIC,0BAAS;GAC7B,IAAI,KAAK,QAAQ;GACjB,UAAU,KAAK,QAAQ;EACvB;EACD,MAAM,aAAa,MAAM,SAAS,iBAAiB;AAEnD,MAAI,WAAW,OAAO;AACrB,UAAO,MAAM,WAAW,QAAQ,4BAA4B;AAC5D,SAAM,WAAW;EACjB;AAED,QAAM,KAAK,QAAQ,GAAG,SAAS;AAE/B,SAAO,KAAK,UAAU,WAAW,SAAS,OAAO,0BAA0B;CAC3E;AACD"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { PostgresMigrator } from "./PostgresMigrator-C_QQ6q35.mjs";
|
|
2
|
+
import { MigrationProvider } from "kysely/migration";
|
|
3
|
+
import { Kysely } from "kysely";
|
|
4
|
+
|
|
5
|
+
//#region src/PostgresKyselyMigrator.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* PostgreSQL migrator implementation for Kysely ORM.
|
|
9
|
+
* Extends PostgresMigrator to provide Kysely-specific migration functionality.
|
|
10
|
+
* Automatically creates test databases and applies migrations for testing environments.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { FileMigrationProvider } from 'kysely';
|
|
15
|
+
* import { PostgresKyselyMigrator } from '@geekmidas/testkit';
|
|
16
|
+
*
|
|
17
|
+
* // Create migration provider
|
|
18
|
+
* const provider = new FileMigrationProvider({
|
|
19
|
+
* fs: require('fs'),
|
|
20
|
+
* path: require('path'),
|
|
21
|
+
* migrationFolder: path.join(__dirname, 'migrations')
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Create Kysely instance
|
|
25
|
+
* const db = new Kysely<Database>({
|
|
26
|
+
* dialect: new PostgresDialect({
|
|
27
|
+
* pool: new Pool({ connectionString: uri })
|
|
28
|
+
* })
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Create and use migrator
|
|
32
|
+
* const migrator = new PostgresKyselyMigrator({
|
|
33
|
+
* uri: 'postgresql://localhost:5432/test_db',
|
|
34
|
+
* db,
|
|
35
|
+
* provider
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const cleanup = await migrator.start();
|
|
39
|
+
* // Run tests...
|
|
40
|
+
* await cleanup();
|
|
41
|
+
*
|
|
42
|
+
* // With afterCreate hook to create per-app users
|
|
43
|
+
* import { runInitScript } from '@geekmidas/testkit/postgres';
|
|
44
|
+
*
|
|
45
|
+
* const migrator = new PostgresKyselyMigrator({
|
|
46
|
+
* uri: 'postgresql://localhost:5432/test_db',
|
|
47
|
+
* db,
|
|
48
|
+
* provider,
|
|
49
|
+
* afterCreate: async (uri) => {
|
|
50
|
+
* await runInitScript('docker/postgres/init.sh', uri, env);
|
|
51
|
+
* },
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
declare class PostgresKyselyMigrator extends PostgresMigrator {
|
|
56
|
+
private options;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new PostgresKyselyMigrator instance.
|
|
59
|
+
*
|
|
60
|
+
* @param options - Configuration options
|
|
61
|
+
* @param options.uri - PostgreSQL connection URI
|
|
62
|
+
* @param options.db - Kysely database instance
|
|
63
|
+
* @param options.provider - Migration provider for locating migration files
|
|
64
|
+
* @param options.afterCreate - Optional hook called after database creation but before migrations
|
|
65
|
+
*/
|
|
66
|
+
constructor(options: {
|
|
67
|
+
uri: string;
|
|
68
|
+
db: Kysely<any>;
|
|
69
|
+
provider: MigrationProvider;
|
|
70
|
+
afterCreate?: (uri: string) => Promise<void>;
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* Executes Kysely migrations to the latest version.
|
|
74
|
+
* Implements the abstract migrate() method from PostgresMigrator.
|
|
75
|
+
*
|
|
76
|
+
* @throws Error if migrations fail to apply
|
|
77
|
+
* @returns Promise that resolves when all migrations are applied
|
|
78
|
+
*/
|
|
79
|
+
migrate(): Promise<void>;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=PostgresKyselyMigrator.d.ts.map
|
|
82
|
+
//#endregion
|
|
83
|
+
export { PostgresKyselyMigrator };
|
|
84
|
+
//# sourceMappingURL=PostgresKyselyMigrator-CvwXycJE.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostgresKyselyMigrator-CvwXycJE.d.mts","names":[],"sources":["../src/PostgresKyselyMigrator.ts"],"sourcesContent":[],"mappings":";;;;;;;;AA2DA;;;;;;;AAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAA/C,sBAAA,SAA+B,gBAAA;;;;;;;;;;;;;QAarC;cACM;mCACqB;;;;;;;;;aAahB"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { PostgresMigrator } from "./PostgresMigrator-DVAY04qN.mjs";
|
|
2
|
+
import { Migrator } from "kysely/migration";
|
|
3
|
+
|
|
4
|
+
//#region src/PostgresKyselyMigrator.ts
|
|
5
|
+
/**
|
|
6
|
+
* Default logger instance for migration operations.
|
|
7
|
+
*/
|
|
8
|
+
const logger = console;
|
|
9
|
+
/**
|
|
10
|
+
* PostgreSQL migrator implementation for Kysely ORM.
|
|
11
|
+
* Extends PostgresMigrator to provide Kysely-specific migration functionality.
|
|
12
|
+
* Automatically creates test databases and applies migrations for testing environments.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { FileMigrationProvider } from 'kysely';
|
|
17
|
+
* import { PostgresKyselyMigrator } from '@geekmidas/testkit';
|
|
18
|
+
*
|
|
19
|
+
* // Create migration provider
|
|
20
|
+
* const provider = new FileMigrationProvider({
|
|
21
|
+
* fs: require('fs'),
|
|
22
|
+
* path: require('path'),
|
|
23
|
+
* migrationFolder: path.join(__dirname, 'migrations')
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Create Kysely instance
|
|
27
|
+
* const db = new Kysely<Database>({
|
|
28
|
+
* dialect: new PostgresDialect({
|
|
29
|
+
* pool: new Pool({ connectionString: uri })
|
|
30
|
+
* })
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Create and use migrator
|
|
34
|
+
* const migrator = new PostgresKyselyMigrator({
|
|
35
|
+
* uri: 'postgresql://localhost:5432/test_db',
|
|
36
|
+
* db,
|
|
37
|
+
* provider
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* const cleanup = await migrator.start();
|
|
41
|
+
* // Run tests...
|
|
42
|
+
* await cleanup();
|
|
43
|
+
*
|
|
44
|
+
* // With afterCreate hook to create per-app users
|
|
45
|
+
* import { runInitScript } from '@geekmidas/testkit/postgres';
|
|
46
|
+
*
|
|
47
|
+
* const migrator = new PostgresKyselyMigrator({
|
|
48
|
+
* uri: 'postgresql://localhost:5432/test_db',
|
|
49
|
+
* db,
|
|
50
|
+
* provider,
|
|
51
|
+
* afterCreate: async (uri) => {
|
|
52
|
+
* await runInitScript('docker/postgres/init.sh', uri, env);
|
|
53
|
+
* },
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
var PostgresKyselyMigrator = class extends PostgresMigrator {
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new PostgresKyselyMigrator instance.
|
|
60
|
+
*
|
|
61
|
+
* @param options - Configuration options
|
|
62
|
+
* @param options.uri - PostgreSQL connection URI
|
|
63
|
+
* @param options.db - Kysely database instance
|
|
64
|
+
* @param options.provider - Migration provider for locating migration files
|
|
65
|
+
* @param options.afterCreate - Optional hook called after database creation but before migrations
|
|
66
|
+
*/
|
|
67
|
+
constructor(options) {
|
|
68
|
+
super(options.uri, options.afterCreate);
|
|
69
|
+
this.options = options;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Executes Kysely migrations to the latest version.
|
|
73
|
+
* Implements the abstract migrate() method from PostgresMigrator.
|
|
74
|
+
*
|
|
75
|
+
* @throws Error if migrations fail to apply
|
|
76
|
+
* @returns Promise that resolves when all migrations are applied
|
|
77
|
+
*/
|
|
78
|
+
async migrate() {
|
|
79
|
+
const migrator = new Migrator({
|
|
80
|
+
db: this.options.db,
|
|
81
|
+
provider: this.options.provider
|
|
82
|
+
});
|
|
83
|
+
const migrations = await migrator.migrateToLatest();
|
|
84
|
+
if (migrations.error) {
|
|
85
|
+
logger.error(migrations.error, `Failed to apply migrations`);
|
|
86
|
+
throw migrations.error;
|
|
87
|
+
}
|
|
88
|
+
await this.options.db.destroy();
|
|
89
|
+
logger.log(`Applied ${migrations.results?.length} migrations successfully`);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
export { PostgresKyselyMigrator };
|
|
95
|
+
//# sourceMappingURL=PostgresKyselyMigrator-PI0QhvB1.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostgresKyselyMigrator-PI0QhvB1.mjs","names":["options: {\n\t\t\turi: string;\n\t\t\tdb: Kysely<any>;\n\t\t\tprovider: MigrationProvider;\n\t\t\tafterCreate?: (uri: string) => Promise<void>;\n\t\t}"],"sources":["../src/PostgresKyselyMigrator.ts"],"sourcesContent":["import type { Kysely } from 'kysely';\n// `Migrator` and the `MigrationProvider` type moved from the root barrel ('kysely')\n// to the 'kysely/migration' subpath in kysely 0.29+.\nimport { type MigrationProvider, Migrator } from 'kysely/migration';\nimport { PostgresMigrator } from './PostgresMigrator';\n\n/**\n * Default logger instance for migration operations.\n */\nconst logger = console;\n\n/**\n * PostgreSQL migrator implementation for Kysely ORM.\n * Extends PostgresMigrator to provide Kysely-specific migration functionality.\n * Automatically creates test databases and applies migrations for testing environments.\n *\n * @example\n * ```typescript\n * import { FileMigrationProvider } from 'kysely';\n * import { PostgresKyselyMigrator } from '@geekmidas/testkit';\n *\n * // Create migration provider\n * const provider = new FileMigrationProvider({\n * fs: require('fs'),\n * path: require('path'),\n * migrationFolder: path.join(__dirname, 'migrations')\n * });\n *\n * // Create Kysely instance\n * const db = new Kysely<Database>({\n * dialect: new PostgresDialect({\n * pool: new Pool({ connectionString: uri })\n * })\n * });\n *\n * // Create and use migrator\n * const migrator = new PostgresKyselyMigrator({\n * uri: 'postgresql://localhost:5432/test_db',\n * db,\n * provider\n * });\n *\n * const cleanup = await migrator.start();\n * // Run tests...\n * await cleanup();\n *\n * // With afterCreate hook to create per-app users\n * import { runInitScript } from '@geekmidas/testkit/postgres';\n *\n * const migrator = new PostgresKyselyMigrator({\n * uri: 'postgresql://localhost:5432/test_db',\n * db,\n * provider,\n * afterCreate: async (uri) => {\n * await runInitScript('docker/postgres/init.sh', uri, env);\n * },\n * });\n * ```\n */\nexport class PostgresKyselyMigrator extends PostgresMigrator {\n\t/**\n\t * Creates a new PostgresKyselyMigrator instance.\n\t *\n\t * @param options - Configuration options\n\t * @param options.uri - PostgreSQL connection URI\n\t * @param options.db - Kysely database instance\n\t * @param options.provider - Migration provider for locating migration files\n\t * @param options.afterCreate - Optional hook called after database creation but before migrations\n\t */\n\tconstructor(\n\t\tprivate options: {\n\t\t\turi: string;\n\t\t\tdb: Kysely<any>;\n\t\t\tprovider: MigrationProvider;\n\t\t\tafterCreate?: (uri: string) => Promise<void>;\n\t\t},\n\t) {\n\t\tsuper(options.uri, options.afterCreate);\n\t}\n\n\t/**\n\t * Executes Kysely migrations to the latest version.\n\t * Implements the abstract migrate() method from PostgresMigrator.\n\t *\n\t * @throws Error if migrations fail to apply\n\t * @returns Promise that resolves when all migrations are applied\n\t */\n\tasync migrate(): Promise<void> {\n\t\tconst migrator = new Migrator({\n\t\t\tdb: this.options.db,\n\t\t\tprovider: this.options.provider,\n\t\t});\n\t\tconst migrations = await migrator.migrateToLatest();\n\n\t\tif (migrations.error) {\n\t\t\tlogger.error(migrations.error, `Failed to apply migrations`);\n\t\t\tthrow migrations.error;\n\t\t}\n\n\t\tawait this.options.db.destroy();\n\n\t\tlogger.log(`Applied ${migrations.results?.length} migrations successfully`);\n\t}\n}\n"],"mappings":";;;;;;;AASA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDf,IAAa,yBAAb,cAA4C,iBAAiB;;;;;;;;;;CAU5D,YACSA,SAMP;AACD,QAAM,QAAQ,KAAK,QAAQ,YAAY;EAP/B;CAQR;;;;;;;;CASD,MAAM,UAAyB;EAC9B,MAAM,WAAW,IAAI,SAAS;GAC7B,IAAI,KAAK,QAAQ;GACjB,UAAU,KAAK,QAAQ;EACvB;EACD,MAAM,aAAa,MAAM,SAAS,iBAAiB;AAEnD,MAAI,WAAW,OAAO;AACrB,UAAO,MAAM,WAAW,QAAQ,4BAA4B;AAC5D,SAAM,WAAW;EACjB;AAED,QAAM,KAAK,QAAQ,GAAG,SAAS;AAE/B,SAAO,KAAK,UAAU,WAAW,SAAS,OAAO,0BAA0B;CAC3E;AACD"}
|