@geekmidas/testkit 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/Factory-WMhTNZ9S.cjs +56 -0
  2. package/dist/Factory-z2m01hMj.mjs +50 -0
  3. package/dist/Factory.cjs +1 -1
  4. package/dist/Factory.mjs +1 -1
  5. package/dist/KyselyFactory-Bdq1s1Go.cjs +215 -0
  6. package/dist/KyselyFactory-ELiHgHVv.mjs +210 -0
  7. package/dist/KyselyFactory.cjs +3 -3
  8. package/dist/KyselyFactory.mjs +3 -3
  9. package/dist/ObjectionFactory-89p-FFEw.mjs +178 -0
  10. package/dist/ObjectionFactory-C47B03Ot.cjs +183 -0
  11. package/dist/ObjectionFactory.cjs +2 -2
  12. package/dist/ObjectionFactory.mjs +2 -2
  13. package/dist/PostgresKyselyMigrator-Bs31emFd.cjs +87 -0
  14. package/dist/PostgresKyselyMigrator-ChIpZFYB.mjs +81 -0
  15. package/dist/PostgresKyselyMigrator.cjs +2 -2
  16. package/dist/PostgresKyselyMigrator.mjs +2 -2
  17. package/dist/PostgresMigrator-BtAWdLss.cjs +151 -0
  18. package/dist/PostgresMigrator-BzqksJcW.mjs +145 -0
  19. package/dist/PostgresMigrator.cjs +1 -1
  20. package/dist/PostgresMigrator.mjs +1 -1
  21. package/dist/VitestKyselyTransactionIsolator-AfxPJEwR.mjs +58 -0
  22. package/dist/VitestKyselyTransactionIsolator-YWnSJiIH.cjs +63 -0
  23. package/dist/VitestKyselyTransactionIsolator.cjs +2 -2
  24. package/dist/VitestKyselyTransactionIsolator.mjs +2 -2
  25. package/dist/VitestObjectionTransactionIsolator-0uX6DW5G.cjs +66 -0
  26. package/dist/VitestObjectionTransactionIsolator-BZRYy8iW.mjs +61 -0
  27. package/dist/VitestObjectionTransactionIsolator.cjs +4 -0
  28. package/dist/VitestObjectionTransactionIsolator.mjs +4 -0
  29. package/dist/VitestTransactionIsolator-DcOz0LZF.cjs +129 -0
  30. package/dist/VitestTransactionIsolator-kFL36T8x.mjs +117 -0
  31. package/dist/VitestTransactionIsolator.cjs +1 -1
  32. package/dist/VitestTransactionIsolator.mjs +1 -1
  33. package/dist/__tests__/Factory.spec.cjs +1 -1
  34. package/dist/__tests__/Factory.spec.mjs +1 -1
  35. package/dist/__tests__/KyselyFactory.spec.cjs +41 -40
  36. package/dist/__tests__/KyselyFactory.spec.mjs +42 -41
  37. package/dist/__tests__/ObjectionFactory.spec.cjs +3 -3
  38. package/dist/__tests__/ObjectionFactory.spec.mjs +3 -3
  39. package/dist/__tests__/PostgresMigrator.spec.cjs +2 -2
  40. package/dist/__tests__/PostgresMigrator.spec.mjs +2 -2
  41. package/dist/__tests__/faker.spec.cjs +1 -1
  42. package/dist/__tests__/faker.spec.mjs +1 -1
  43. package/dist/__tests__/integration.spec.cjs +11 -8
  44. package/dist/__tests__/integration.spec.mjs +12 -9
  45. package/dist/example.cjs +3 -3
  46. package/dist/example.mjs +3 -3
  47. package/dist/faker-CxKkEeYi.mjs +227 -0
  48. package/dist/faker-SMN4ira4.cjs +263 -0
  49. package/dist/faker.cjs +1 -1
  50. package/dist/faker.mjs +1 -1
  51. package/dist/helpers-CKMlwSYT.mjs +47 -0
  52. package/dist/helpers-H4hO5SZR.cjs +53 -0
  53. package/dist/helpers.cjs +2 -5
  54. package/dist/helpers.mjs +2 -4
  55. package/dist/kysely-B-GOhABm.cjs +72 -0
  56. package/dist/kysely-CqfoKVXs.mjs +67 -0
  57. package/dist/kysely.cjs +11 -15
  58. package/dist/kysely.mjs +9 -15
  59. package/dist/objection.cjs +86 -3
  60. package/dist/objection.mjs +83 -3
  61. package/package.json +2 -2
  62. package/src/Factory.ts +97 -0
  63. package/src/KyselyFactory.ts +180 -0
  64. package/src/ObjectionFactory.ts +145 -3
  65. package/src/PostgresKyselyMigrator.ts +54 -0
  66. package/src/PostgresMigrator.ts +90 -0
  67. package/src/VitestKyselyTransactionIsolator.ts +46 -0
  68. package/src/VitestObjectionTransactionIsolator.ts +73 -0
  69. package/src/VitestTransactionIsolator.ts +99 -2
  70. package/src/__tests__/KyselyFactory.spec.ts +4 -6
  71. package/src/__tests__/integration.spec.ts +8 -3
  72. package/src/faker.ts +158 -7
  73. package/src/helpers.ts +35 -18
  74. package/src/kysely.ts +66 -1
  75. package/src/objection.ts +95 -0
  76. package/dist/Factory-DREHoms3.cjs +0 -15
  77. package/dist/Factory-DlzMkMzb.mjs +0 -9
  78. package/dist/KyselyFactory-BX7Kv2uP.cjs +0 -65
  79. package/dist/KyselyFactory-pOMOFQWE.mjs +0 -60
  80. package/dist/ObjectionFactory-BlkzSEqo.cjs +0 -41
  81. package/dist/ObjectionFactory-ChuX8sZN.mjs +0 -36
  82. package/dist/PostgresKyselyMigrator-D8fm35-s.mjs +0 -27
  83. package/dist/PostgresKyselyMigrator-JTY2LfwD.cjs +0 -33
  84. package/dist/PostgresMigrator-Bz-tnjB6.cjs +0 -67
  85. package/dist/PostgresMigrator-CEoRKTdq.mjs +0 -61
  86. package/dist/VitestKyselyTransactionIsolator-BS3R-V0I.mjs +0 -12
  87. package/dist/VitestKyselyTransactionIsolator-DWSTKIe3.cjs +0 -17
  88. package/dist/VitestTransactionIsolator-BjVXqFs6.mjs +0 -40
  89. package/dist/VitestTransactionIsolator-Bx2c4OzK.cjs +0 -52
  90. package/dist/faker-BwaXA_RF.mjs +0 -85
  91. package/dist/faker-caz-8zt8.cjs +0 -121
  92. package/dist/helpers-B9Jdk_C7.cjs +0 -31
  93. package/dist/helpers-DOiGIkaU.mjs +0 -19
  94. /package/dist/{helpers-DKEBHABj.cjs → helpers-Bnm3Jy9X.cjs} +0 -0
  95. /package/dist/{helpers-BfuX-cjN.mjs → helpers-CukcFAU9.mjs} +0 -0
package/src/helpers.ts CHANGED
@@ -1,23 +1,40 @@
1
- import {
2
- CamelCasePlugin,
3
- Kysely,
4
- PostgresDialect,
5
- type Transaction,
6
- } from 'kysely';
1
+ import { CamelCasePlugin, Kysely, PostgresDialect } from 'kysely';
7
2
  import pg from 'pg';
8
- import { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';
9
- import { IsolationLevel } from './VitestTransactionIsolator';
10
-
11
- export function wrapVitestKyselyTransaction<Database>(
12
- db: Kysely<Database>,
13
- setup?: (trx: Transaction<Database>) => Promise<void>,
14
- level: IsolationLevel = IsolationLevel.REPEATABLE_READ,
15
- ) {
16
- const wrapper = new VitestKyselyTransactionIsolator<Database>();
17
-
18
- return wrapper.wrapVitestWithTransaction(db, setup, level);
19
- }
20
3
 
4
+ /**
5
+ * Creates a Kysely database instance with PostgreSQL dialect and camelCase plugin.
6
+ * This is a convenience function for quickly setting up a Kysely connection for testing.
7
+ *
8
+ * @template Database - The database schema type
9
+ * @param config - PostgreSQL connection configuration (pg.Pool config)
10
+ * @returns A configured Kysely instance
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * interface Database {
15
+ * users: UsersTable;
16
+ * posts: PostsTable;
17
+ * }
18
+ *
19
+ * // Create from connection string
20
+ * const db = createKyselyDb<Database>({
21
+ * connectionString: 'postgresql://user:pass@localhost:5432/testdb'
22
+ * });
23
+ *
24
+ * // Create with detailed config
25
+ * const db = createKyselyDb<Database>({
26
+ * host: 'localhost',
27
+ * port: 5432,
28
+ * database: 'testdb',
29
+ * user: 'testuser',
30
+ * password: 'testpass',
31
+ * max: 10 // connection pool size
32
+ * });
33
+ *
34
+ * // Use in tests
35
+ * const users = await db.selectFrom('users').selectAll().execute();
36
+ * ```
37
+ */
21
38
  export function createKyselyDb<Database>(config: any): Kysely<Database> {
22
39
  return new Kysely({
23
40
  dialect: new PostgresDialect({
package/src/kysely.ts CHANGED
@@ -1,16 +1,81 @@
1
1
  import type { Kysely, Transaction } from 'kysely';
2
+ import type { TestAPI } from 'vitest';
2
3
  import { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';
3
4
  import { IsolationLevel } from './VitestTransactionIsolator';
4
5
 
6
+ /**
7
+ * Kysely-specific exports for test utilities.
8
+ * Provides factories, migrators, and transaction isolators for Kysely ORM.
9
+ */
10
+
5
11
  export { KyselyFactory } from './KyselyFactory';
6
12
  export { PostgresKyselyMigrator } from './PostgresKyselyMigrator';
13
+ export { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';
14
+ export { IsolationLevel } from './VitestTransactionIsolator';
7
15
 
16
+ /**
17
+ * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.
18
+ * Each test runs in an isolated database transaction that is rolled back after completion.
19
+ * This ensures tests don't affect each other's data and run faster than truncating tables.
20
+ *
21
+ * @template Database - The database schema type
22
+ * @param api - The Vitest test API (usually `test` from vitest)
23
+ * @param db - The Kysely database instance
24
+ * @param setup - Optional setup function to run before each test in the transaction
25
+ * @param level - Transaction isolation level (defaults to REPEATABLE_READ)
26
+ * @returns A wrapped test API that provides transaction isolation
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * import { test } from 'vitest';
31
+ * import { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';
32
+ * import { db } from './database';
33
+ *
34
+ * // Create isolated test with automatic rollback
35
+ * const isolatedTest = wrapVitestKyselyTransaction(test, db);
36
+ *
37
+ * // Use in tests - each test gets its own transaction
38
+ * isolatedTest('should create user', async ({ trx }) => {
39
+ * const user = await trx
40
+ * .insertInto('users')
41
+ * .values({ name: 'Test User', email: 'test@example.com' })
42
+ * .returningAll()
43
+ * .executeTakeFirst();
44
+ *
45
+ * expect(user).toBeDefined();
46
+ * // User is automatically rolled back after test
47
+ * });
48
+ *
49
+ * // With setup function for common test data
50
+ * const testWithSetup = wrapVitestKyselyTransaction(
51
+ * test,
52
+ * db,
53
+ * async (trx) => {
54
+ * // Create common test data
55
+ * await trx.insertInto('settings')
56
+ * .values({ key: 'test_mode', value: 'true' })
57
+ * .execute();
58
+ * }
59
+ * );
60
+ *
61
+ * testWithSetup('should have test settings', async ({ trx }) => {
62
+ * const setting = await trx
63
+ * .selectFrom('settings')
64
+ * .where('key', '=', 'test_mode')
65
+ * .selectAll()
66
+ * .executeTakeFirst();
67
+ *
68
+ * expect(setting?.value).toBe('true');
69
+ * });
70
+ * ```
71
+ */
8
72
  export function wrapVitestKyselyTransaction<Database>(
73
+ api: TestAPI,
9
74
  db: Kysely<Database>,
10
75
  setup?: (trx: Transaction<Database>) => Promise<void>,
11
76
  level: IsolationLevel = IsolationLevel.REPEATABLE_READ,
12
77
  ) {
13
- const wrapper = new VitestKyselyTransactionIsolator<Database>();
78
+ const wrapper = new VitestKyselyTransactionIsolator<Database>(api);
14
79
 
15
80
  return wrapper.wrapVitestWithTransaction(db, setup, level);
16
81
  }
package/src/objection.ts CHANGED
@@ -1 +1,96 @@
1
+ import type { Knex } from 'knex';
2
+ import type { TestAPI } from 'vitest';
3
+ import { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';
4
+ import { IsolationLevel } from './VitestTransactionIsolator';
5
+
6
+ /**
7
+ * Objection.js-specific exports for test utilities.
8
+ * Provides factory implementation for creating test data with Objection.js ORM
9
+ * and transaction isolation for test suites.
10
+ */
11
+
1
12
  export { ObjectionFactory } from './ObjectionFactory';
13
+ export { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';
14
+ export { IsolationLevel } from './VitestTransactionIsolator';
15
+
16
+ /**
17
+ * Creates a wrapped Vitest test API with automatic transaction rollback for Objection.js.
18
+ * Each test runs in an isolated database transaction that is rolled back after completion.
19
+ * This ensures tests don't affect each other's data and run faster than truncating tables.
20
+ *
21
+ * @param api - The Vitest test API (usually `test` from vitest)
22
+ * @param knex - The Knex database connection instance
23
+ * @param setup - Optional setup function to run before each test in the transaction
24
+ * @param level - Transaction isolation level (defaults to REPEATABLE_READ)
25
+ * @returns A wrapped test API that provides transaction isolation
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * import { test } from 'vitest';
30
+ * import { wrapVitestObjectionTransaction } from '@geekmidas/testkit/objection';
31
+ * import { knex } from './database';
32
+ * import { User, Post } from './models';
33
+ *
34
+ * // Create isolated test with automatic rollback
35
+ * const isolatedTest = wrapVitestObjectionTransaction(test, knex);
36
+ *
37
+ * // Use in tests - each test gets its own transaction
38
+ * isolatedTest('should create user', async ({ trx }) => {
39
+ * const user = await User.query(trx)
40
+ * .insert({ name: 'Test User', email: 'test@example.com' });
41
+ *
42
+ * expect(user).toBeDefined();
43
+ * // User is automatically rolled back after test
44
+ * });
45
+ *
46
+ * // With setup function for common test data
47
+ * const testWithSetup = wrapVitestObjectionTransaction(
48
+ * test,
49
+ * knex,
50
+ * async (trx) => {
51
+ * // Create common test data
52
+ * await knex('settings')
53
+ * .transacting(trx)
54
+ * .insert({ key: 'test_mode', value: 'true' });
55
+ * }
56
+ * );
57
+ *
58
+ * testWithSetup('should have test settings', async ({ trx }) => {
59
+ * const setting = await knex('settings')
60
+ * .transacting(trx)
61
+ * .where('key', 'test_mode')
62
+ * .first();
63
+ *
64
+ * expect(setting?.value).toBe('true');
65
+ * });
66
+ *
67
+ * // Example with factory and transaction
68
+ * const isolatedTest = wrapVitestObjectionTransaction(test, knex);
69
+ * const factory = new ObjectionFactory(builders, seeds, knex);
70
+ *
71
+ * isolatedTest('creates related data', async ({ trx }) => {
72
+ * // Factory can use the transaction
73
+ * const user = await User.query(trx).insert({ name: 'Author' });
74
+ * const posts = await Post.query(trx).insert([
75
+ * { title: 'Post 1', userId: user.id },
76
+ * { title: 'Post 2', userId: user.id }
77
+ * ]);
78
+ *
79
+ * const userWithPosts = await User.query(trx)
80
+ * .findById(user.id)
81
+ * .withGraphFetched('posts');
82
+ *
83
+ * expect(userWithPosts.posts).toHaveLength(2);
84
+ * });
85
+ * ```
86
+ */
87
+ export function wrapVitestObjectionTransaction(
88
+ api: TestAPI,
89
+ knex: Knex,
90
+ setup?: (trx: Knex.Transaction) => Promise<void>,
91
+ level: IsolationLevel = IsolationLevel.REPEATABLE_READ,
92
+ ) {
93
+ const wrapper = new VitestObjectionTransactionIsolator(api);
94
+
95
+ return wrapper.wrapVitestWithTransaction(knex, setup, level);
96
+ }
@@ -1,15 +0,0 @@
1
-
2
- //#region src/Factory.ts
3
- var Factory = class {
4
- static createSeed(seedFn) {
5
- return seedFn;
6
- }
7
- };
8
-
9
- //#endregion
10
- Object.defineProperty(exports, 'Factory', {
11
- enumerable: true,
12
- get: function () {
13
- return Factory;
14
- }
15
- });
@@ -1,9 +0,0 @@
1
- //#region src/Factory.ts
2
- var Factory = class {
3
- static createSeed(seedFn) {
4
- return seedFn;
5
- }
6
- };
7
-
8
- //#endregion
9
- export { Factory };
@@ -1,65 +0,0 @@
1
- const require_Factory = require('./Factory-DREHoms3.cjs');
2
- const require_faker = require('./faker-caz-8zt8.cjs');
3
-
4
- //#region src/KyselyFactory.ts
5
- var KyselyFactory = class extends require_Factory.Factory {
6
- static createSeed(seedFn) {
7
- return require_Factory.Factory.createSeed(seedFn);
8
- }
9
- constructor(builders, seeds, db) {
10
- super();
11
- this.builders = builders;
12
- this.seeds = seeds;
13
- this.db = db;
14
- }
15
- static createBuilder(table, item, autoInsert) {
16
- return async (attrs, factory, db, faker$1) => {
17
- let data = { ...attrs };
18
- if (item) {
19
- const defaults = await item(attrs, factory, db, faker$1);
20
- data = {
21
- ...defaults,
22
- ...data
23
- };
24
- }
25
- if (autoInsert !== false) {
26
- const result = await db.insertInto(table).values(data).returningAll().executeTakeFirst();
27
- if (!result) throw new Error(`Failed to insert into ${table}`);
28
- return result;
29
- } else return {
30
- table,
31
- data
32
- };
33
- };
34
- }
35
- async insert(builderName, attrs) {
36
- 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`);
37
- const result = await this.builders[builderName](attrs || {}, this, this.db, require_faker.faker);
38
- if (result && typeof result === "object" && "table" in result && "data" in result) {
39
- const inserted = await this.db.insertInto(result.table).values(result.data).returningAll().executeTakeFirst();
40
- return inserted;
41
- }
42
- return result;
43
- }
44
- async insertMany(count, builderName, attrs) {
45
- 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`);
46
- const promises = [];
47
- for (let i = 0; i < count; i++) {
48
- const newAttrs = typeof attrs === "function" ? attrs(i, require_faker.faker) : attrs;
49
- promises.push(this.insert(builderName, newAttrs));
50
- }
51
- return Promise.all(promises);
52
- }
53
- seed(seedName, attrs) {
54
- 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`);
55
- return this.seeds[seedName](attrs || {}, this, this.db);
56
- }
57
- };
58
-
59
- //#endregion
60
- Object.defineProperty(exports, 'KyselyFactory', {
61
- enumerable: true,
62
- get: function () {
63
- return KyselyFactory;
64
- }
65
- });
@@ -1,60 +0,0 @@
1
- import { Factory } from "./Factory-DlzMkMzb.mjs";
2
- import { faker } from "./faker-BwaXA_RF.mjs";
3
-
4
- //#region src/KyselyFactory.ts
5
- var KyselyFactory = class extends Factory {
6
- static createSeed(seedFn) {
7
- return Factory.createSeed(seedFn);
8
- }
9
- constructor(builders, seeds, db) {
10
- super();
11
- this.builders = builders;
12
- this.seeds = seeds;
13
- this.db = db;
14
- }
15
- static createBuilder(table, item, autoInsert) {
16
- return async (attrs, factory, db, faker$1) => {
17
- let data = { ...attrs };
18
- if (item) {
19
- const defaults = await item(attrs, factory, db, faker$1);
20
- data = {
21
- ...defaults,
22
- ...data
23
- };
24
- }
25
- if (autoInsert !== false) {
26
- const result = await db.insertInto(table).values(data).returningAll().executeTakeFirst();
27
- if (!result) throw new Error(`Failed to insert into ${table}`);
28
- return result;
29
- } else return {
30
- table,
31
- data
32
- };
33
- };
34
- }
35
- async insert(builderName, attrs) {
36
- 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`);
37
- const result = await this.builders[builderName](attrs || {}, this, this.db, faker);
38
- if (result && typeof result === "object" && "table" in result && "data" in result) {
39
- const inserted = await this.db.insertInto(result.table).values(result.data).returningAll().executeTakeFirst();
40
- return inserted;
41
- }
42
- return result;
43
- }
44
- async insertMany(count, builderName, attrs) {
45
- 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`);
46
- const promises = [];
47
- for (let i = 0; i < count; i++) {
48
- const newAttrs = typeof attrs === "function" ? attrs(i, faker) : attrs;
49
- promises.push(this.insert(builderName, newAttrs));
50
- }
51
- return Promise.all(promises);
52
- }
53
- seed(seedName, attrs) {
54
- 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`);
55
- return this.seeds[seedName](attrs || {}, this, this.db);
56
- }
57
- };
58
-
59
- //#endregion
60
- export { KyselyFactory };
@@ -1,41 +0,0 @@
1
- const require_Factory = require('./Factory-DREHoms3.cjs');
2
-
3
- //#region src/ObjectionFactory.ts
4
- var ObjectionFactory = class extends require_Factory.Factory {
5
- static createSeed(seedFn) {
6
- return require_Factory.Factory.createSeed(seedFn);
7
- }
8
- constructor(builders, seeds, db) {
9
- super();
10
- this.builders = builders;
11
- this.seeds = seeds;
12
- this.db = db;
13
- }
14
- insert(factory, attrs = {}) {
15
- if (!(factory in this.builders)) throw new Error(`Factory "${factory}" does not exist. Make sure it is correct and registered in src/test/setup.ts`);
16
- return this.builders[factory](attrs, {}, this.db).then((record) => {
17
- return record.$query(this.db).insertGraph(record).execute();
18
- });
19
- }
20
- insertMany(count, builderName, attrs = {}) {
21
- 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`);
22
- const records = [];
23
- for (let i = 0; i < count; i++) {
24
- const newAttrs = typeof attrs === "function" ? attrs(i) : attrs;
25
- records.push(this.builders[builderName](newAttrs, {}, this.db).then((record) => record.$query(this.db).insertGraph(record).execute()));
26
- }
27
- return Promise.all(records);
28
- }
29
- seed(seedName, attrs = {}) {
30
- 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`);
31
- return this.seeds[seedName](attrs, this, this.db);
32
- }
33
- };
34
-
35
- //#endregion
36
- Object.defineProperty(exports, 'ObjectionFactory', {
37
- enumerable: true,
38
- get: function () {
39
- return ObjectionFactory;
40
- }
41
- });
@@ -1,36 +0,0 @@
1
- import { Factory } from "./Factory-DlzMkMzb.mjs";
2
-
3
- //#region src/ObjectionFactory.ts
4
- var ObjectionFactory = class extends Factory {
5
- static createSeed(seedFn) {
6
- return Factory.createSeed(seedFn);
7
- }
8
- constructor(builders, seeds, db) {
9
- super();
10
- this.builders = builders;
11
- this.seeds = seeds;
12
- this.db = db;
13
- }
14
- insert(factory, attrs = {}) {
15
- if (!(factory in this.builders)) throw new Error(`Factory "${factory}" does not exist. Make sure it is correct and registered in src/test/setup.ts`);
16
- return this.builders[factory](attrs, {}, this.db).then((record) => {
17
- return record.$query(this.db).insertGraph(record).execute();
18
- });
19
- }
20
- insertMany(count, builderName, attrs = {}) {
21
- 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`);
22
- const records = [];
23
- for (let i = 0; i < count; i++) {
24
- const newAttrs = typeof attrs === "function" ? attrs(i) : attrs;
25
- records.push(this.builders[builderName](newAttrs, {}, this.db).then((record) => record.$query(this.db).insertGraph(record).execute()));
26
- }
27
- return Promise.all(records);
28
- }
29
- seed(seedName, attrs = {}) {
30
- 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`);
31
- return this.seeds[seedName](attrs, this, this.db);
32
- }
33
- };
34
-
35
- //#endregion
36
- export { ObjectionFactory };
@@ -1,27 +0,0 @@
1
- import { PostgresMigrator } from "./PostgresMigrator-CEoRKTdq.mjs";
2
- import { Migrator } from "kysely";
3
-
4
- //#region src/PostgresKyselyMigrator.ts
5
- const logger = console;
6
- var PostgresKyselyMigrator = class extends PostgresMigrator {
7
- constructor(options) {
8
- super(options.uri);
9
- this.options = options;
10
- }
11
- async migrate() {
12
- const migrator = new Migrator({
13
- db: this.options.db,
14
- provider: this.options.provider
15
- });
16
- const migrations = await migrator.migrateToLatest();
17
- if (migrations.error) {
18
- logger.error(migrations.error, `Failed to apply migrations`);
19
- throw migrations.error;
20
- }
21
- await this.options.db.destroy();
22
- logger.log(`Applied ${migrations.results?.length} migrations successfully`);
23
- }
24
- };
25
-
26
- //#endregion
27
- export { PostgresKyselyMigrator };
@@ -1,33 +0,0 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_PostgresMigrator = require('./PostgresMigrator-Bz-tnjB6.cjs');
3
- const kysely = require_chunk.__toESM(require("kysely"));
4
-
5
- //#region src/PostgresKyselyMigrator.ts
6
- const logger = console;
7
- var PostgresKyselyMigrator = class extends require_PostgresMigrator.PostgresMigrator {
8
- constructor(options) {
9
- super(options.uri);
10
- this.options = options;
11
- }
12
- async migrate() {
13
- const migrator = new kysely.Migrator({
14
- db: this.options.db,
15
- provider: this.options.provider
16
- });
17
- const migrations = await migrator.migrateToLatest();
18
- if (migrations.error) {
19
- logger.error(migrations.error, `Failed to apply migrations`);
20
- throw migrations.error;
21
- }
22
- await this.options.db.destroy();
23
- logger.log(`Applied ${migrations.results?.length} migrations successfully`);
24
- }
25
- };
26
-
27
- //#endregion
28
- Object.defineProperty(exports, 'PostgresKyselyMigrator', {
29
- enumerable: true,
30
- get: function () {
31
- return PostgresKyselyMigrator;
32
- }
33
- });
@@ -1,67 +0,0 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const pg = require_chunk.__toESM(require("pg"));
3
-
4
- //#region src/PostgresMigrator.ts
5
- async function setupClient(uri) {
6
- const url = new URL(uri);
7
- const db = new pg.Client({
8
- user: url.username,
9
- password: url.password,
10
- host: url.hostname,
11
- port: parseInt(url.port),
12
- database: "postgres"
13
- });
14
- let database = url.pathname.slice(1);
15
- if (database.includes("?")) database = database.substring(0, database.indexOf("?"));
16
- return {
17
- database,
18
- db
19
- };
20
- }
21
- const logger = console;
22
- var PostgresMigrator = class PostgresMigrator {
23
- constructor(uri) {
24
- this.uri = uri;
25
- }
26
- static async create(uri) {
27
- const { database, db } = await setupClient(uri);
28
- try {
29
- await db.connect();
30
- const result = await db.query(`SELECT * FROM pg_catalog.pg_database WHERE datname = '${database}'`);
31
- if (result.rowCount === 0) await db.query(`CREATE DATABASE "${database}"`);
32
- return { alreadyExisted: result.rowCount ? result.rowCount > 0 : false };
33
- } finally {
34
- await db.end();
35
- }
36
- }
37
- static async drop(uri) {
38
- const { database, db } = await setupClient(uri);
39
- try {
40
- await db.connect();
41
- await db.query(`DROP DATABASE "${database}"`);
42
- } finally {
43
- await db.end();
44
- }
45
- }
46
- async start() {
47
- const { database, db } = await setupClient(this.uri);
48
- try {
49
- await PostgresMigrator.create(this.uri);
50
- await this.migrate();
51
- logger.log(`Migrating database: ${database}`);
52
- } finally {
53
- await db.end();
54
- }
55
- return async () => {
56
- await PostgresMigrator.drop(this.uri);
57
- };
58
- }
59
- };
60
-
61
- //#endregion
62
- Object.defineProperty(exports, 'PostgresMigrator', {
63
- enumerable: true,
64
- get: function () {
65
- return PostgresMigrator;
66
- }
67
- });
@@ -1,61 +0,0 @@
1
- import { Client } from "pg";
2
-
3
- //#region src/PostgresMigrator.ts
4
- async function setupClient(uri) {
5
- const url = new URL(uri);
6
- const db = new Client({
7
- user: url.username,
8
- password: url.password,
9
- host: url.hostname,
10
- port: parseInt(url.port),
11
- database: "postgres"
12
- });
13
- let database = url.pathname.slice(1);
14
- if (database.includes("?")) database = database.substring(0, database.indexOf("?"));
15
- return {
16
- database,
17
- db
18
- };
19
- }
20
- const logger = console;
21
- var PostgresMigrator = class PostgresMigrator {
22
- constructor(uri) {
23
- this.uri = uri;
24
- }
25
- static async create(uri) {
26
- const { database, db } = await setupClient(uri);
27
- try {
28
- await db.connect();
29
- const result = await db.query(`SELECT * FROM pg_catalog.pg_database WHERE datname = '${database}'`);
30
- if (result.rowCount === 0) await db.query(`CREATE DATABASE "${database}"`);
31
- return { alreadyExisted: result.rowCount ? result.rowCount > 0 : false };
32
- } finally {
33
- await db.end();
34
- }
35
- }
36
- static async drop(uri) {
37
- const { database, db } = await setupClient(uri);
38
- try {
39
- await db.connect();
40
- await db.query(`DROP DATABASE "${database}"`);
41
- } finally {
42
- await db.end();
43
- }
44
- }
45
- async start() {
46
- const { database, db } = await setupClient(this.uri);
47
- try {
48
- await PostgresMigrator.create(this.uri);
49
- await this.migrate();
50
- logger.log(`Migrating database: ${database}`);
51
- } finally {
52
- await db.end();
53
- }
54
- return async () => {
55
- await PostgresMigrator.drop(this.uri);
56
- };
57
- }
58
- };
59
-
60
- //#endregion
61
- export { PostgresMigrator };
@@ -1,12 +0,0 @@
1
- import { VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-BjVXqFs6.mjs";
2
-
3
- //#region src/VitestKyselyTransactionIsolator.ts
4
- var VitestKyselyTransactionIsolator = class extends VitestPostgresTransactionIsolator {
5
- async transact(conn, level, fn) {
6
- const isolationLevel = level.toLocaleLowerCase();
7
- await conn.transaction().setIsolationLevel(isolationLevel).execute(fn);
8
- }
9
- };
10
-
11
- //#endregion
12
- export { VitestKyselyTransactionIsolator };