@geekmidas/testkit 0.0.6 → 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 +10 -10
  36. package/dist/__tests__/KyselyFactory.spec.mjs +10 -10
  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 +10 -10
  44. package/dist/__tests__/integration.spec.mjs +10 -10
  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 +1 -1
  54. package/dist/helpers.mjs +1 -1
  55. package/dist/kysely-B-GOhABm.cjs +72 -0
  56. package/dist/kysely-CqfoKVXs.mjs +67 -0
  57. package/dist/kysely.cjs +10 -8
  58. package/dist/kysely.mjs +9 -9
  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 +95 -0
  70. package/src/faker.ts +158 -7
  71. package/src/helpers.ts +34 -0
  72. package/src/kysely.ts +63 -0
  73. package/src/objection.ts +95 -0
  74. package/dist/Factory-DREHoms3.cjs +0 -15
  75. package/dist/Factory-DlzMkMzb.mjs +0 -9
  76. package/dist/KyselyFactory-BX7Kv2uP.cjs +0 -65
  77. package/dist/KyselyFactory-pOMOFQWE.mjs +0 -60
  78. package/dist/ObjectionFactory-BlkzSEqo.cjs +0 -41
  79. package/dist/ObjectionFactory-ChuX8sZN.mjs +0 -36
  80. package/dist/PostgresKyselyMigrator-D8fm35-s.mjs +0 -27
  81. package/dist/PostgresKyselyMigrator-JTY2LfwD.cjs +0 -33
  82. package/dist/PostgresMigrator-Bz-tnjB6.cjs +0 -67
  83. package/dist/PostgresMigrator-CEoRKTdq.mjs +0 -61
  84. package/dist/VitestKyselyTransactionIsolator-D-qpeVKO.mjs +0 -12
  85. package/dist/VitestKyselyTransactionIsolator-jF6Ohyu_.cjs +0 -17
  86. package/dist/VitestTransactionIsolator-BK9UsrKt.cjs +0 -53
  87. package/dist/VitestTransactionIsolator-e-R3p_X8.mjs +0 -41
  88. package/dist/faker-BwaXA_RF.mjs +0 -85
  89. package/dist/faker-caz-8zt8.cjs +0 -121
  90. package/dist/helpers-DN4sJO4i.mjs +0 -13
  91. package/dist/helpers-DOtYCEvZ.cjs +0 -19
  92. package/dist/kysely-C1-aHdnU.mjs +0 -11
  93. package/dist/kysely-DL3C2eM4.cjs +0 -16
  94. /package/dist/{helpers-B2CfbaTC.cjs → helpers-Bnm3Jy9X.cjs} +0 -0
  95. /package/dist/{helpers-Rf5F71r9.mjs → helpers-CukcFAU9.mjs} +0 -0
@@ -0,0 +1,178 @@
1
+ import { Factory } from "./Factory-z2m01hMj.mjs";
2
+
3
+ //#region src/ObjectionFactory.ts
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: (attrs) => User.fromJson({
21
+ * id: faker.string.uuid(),
22
+ * name: faker.person.fullName(),
23
+ * email: faker.internet.email(),
24
+ * ...attrs
25
+ * }),
26
+ * post: (attrs) => Post.fromJson({
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
+ /**
42
+ * Creates a typed seed function with proper type inference.
43
+ * Inherits from the base Factory class implementation.
44
+ *
45
+ * @template Seed - The seed function type
46
+ * @param seedFn - The seed function to wrap
47
+ * @returns The same seed function with proper typing
48
+ */
49
+ static createSeed(seedFn) {
50
+ return Factory.createSeed(seedFn);
51
+ }
52
+ /**
53
+ * Creates a new ObjectionFactory instance.
54
+ *
55
+ * @param builders - Record of builder functions for creating individual entities
56
+ * @param seeds - Record of seed functions for creating complex test scenarios
57
+ * @param db - Knex database connection instance
58
+ */
59
+ constructor(builders, seeds, db) {
60
+ super();
61
+ this.builders = builders;
62
+ this.seeds = seeds;
63
+ this.db = db;
64
+ }
65
+ /**
66
+ * Inserts a single record into the database using the specified builder.
67
+ * Uses Objection.js's insertGraph method to handle nested relations.
68
+ *
69
+ * @param factory - The name of the builder to use
70
+ * @param attrs - Optional attributes to override builder defaults
71
+ * @returns A promise resolving to the inserted record with all relations
72
+ * @throws Error if the specified builder doesn't exist
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * // Insert with defaults
77
+ * const user = await factory.insert('user');
78
+ *
79
+ * // Insert with overrides
80
+ * const adminUser = await factory.insert('user', {
81
+ * email: 'admin@example.com',
82
+ * role: 'admin'
83
+ * });
84
+ *
85
+ * // Insert with nested relations
86
+ * const userWithProfile = await factory.insert('user', {
87
+ * name: 'John Doe',
88
+ * profile: {
89
+ * bio: 'Software Developer',
90
+ * avatar: 'avatar.jpg'
91
+ * }
92
+ * });
93
+ * ```
94
+ */
95
+ insert(factory, attrs = {}) {
96
+ 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`);
97
+ return this.builders[factory](attrs, {}, this.db).then((record) => {
98
+ return record.$query(this.db).insertGraph(record).execute();
99
+ });
100
+ }
101
+ /**
102
+ * Inserts multiple records into the database using the specified builder.
103
+ * Supports both static attributes and dynamic attribute generation via a function.
104
+ *
105
+ * @param count - The number of records to insert
106
+ * @param builderName - The name of the builder to use
107
+ * @param attrs - Static attributes or a function that generates attributes for each record
108
+ * @returns A promise resolving to an array of inserted records
109
+ * @throws Error if the specified builder doesn't exist
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * // Insert multiple with same attributes
114
+ * const users = await factory.insertMany(5, 'user', { role: 'member' });
115
+ *
116
+ * // Insert multiple with dynamic attributes
117
+ * const posts = await factory.insertMany(10, 'post', (idx) => ({
118
+ * title: `Post ${idx + 1}`,
119
+ * content: `Content for post ${idx + 1}`,
120
+ * publishedAt: new Date()
121
+ * }));
122
+ *
123
+ * // Create users with sequential emails
124
+ * const admins = await factory.insertMany(3, 'user', (idx) => ({
125
+ * email: `admin${idx + 1}@example.com`,
126
+ * role: 'admin'
127
+ * }));
128
+ * ```
129
+ */
130
+ insertMany(count, builderName, attrs = {}) {
131
+ 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`);
132
+ const records = [];
133
+ for (let i = 0; i < count; i++) {
134
+ const newAttrs = typeof attrs === "function" ? attrs(i) : attrs;
135
+ records.push(this.builders[builderName](newAttrs, {}, this.db).then((record) => record.$query(this.db).insertGraph(record).execute()));
136
+ }
137
+ return Promise.all(records);
138
+ }
139
+ /**
140
+ * Executes a seed function to create complex test scenarios with multiple related records.
141
+ * Seeds are useful for setting up complete test environments with realistic data relationships.
142
+ *
143
+ * @param seedName - The name of the seed to execute
144
+ * @param attrs - Optional configuration attributes for the seed
145
+ * @returns The result of the seed function (typically the primary record created)
146
+ * @throws Error if the specified seed doesn't exist
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * // Execute a simple seed
151
+ * const user = await factory.seed('userWithProfile');
152
+ *
153
+ * // Execute a seed with configuration
154
+ * const author = await factory.seed('authorWithBooks', {
155
+ * bookCount: 5,
156
+ * includeReviews: true
157
+ * });
158
+ *
159
+ * // Use seed result in tests with Objection.js relations
160
+ * const company = await factory.seed('companyWithDepartments', {
161
+ * departmentCount: 3,
162
+ * employeesPerDepartment: 10
163
+ * });
164
+ *
165
+ * // Access eager loaded relations
166
+ * const companyWithRelations = await Company.query()
167
+ * .findById(company.id)
168
+ * .withGraphFetched('[departments.employees]');
169
+ * ```
170
+ */
171
+ seed(seedName, attrs = {}) {
172
+ 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`);
173
+ return this.seeds[seedName](attrs, this, this.db);
174
+ }
175
+ };
176
+
177
+ //#endregion
178
+ export { ObjectionFactory };
@@ -0,0 +1,183 @@
1
+ const require_Factory = require('./Factory-WMhTNZ9S.cjs');
2
+
3
+ //#region src/ObjectionFactory.ts
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: (attrs) => User.fromJson({
21
+ * id: faker.string.uuid(),
22
+ * name: faker.person.fullName(),
23
+ * email: faker.internet.email(),
24
+ * ...attrs
25
+ * }),
26
+ * post: (attrs) => Post.fromJson({
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 require_Factory.Factory {
41
+ /**
42
+ * Creates a typed seed function with proper type inference.
43
+ * Inherits from the base Factory class implementation.
44
+ *
45
+ * @template Seed - The seed function type
46
+ * @param seedFn - The seed function to wrap
47
+ * @returns The same seed function with proper typing
48
+ */
49
+ static createSeed(seedFn) {
50
+ return require_Factory.Factory.createSeed(seedFn);
51
+ }
52
+ /**
53
+ * Creates a new ObjectionFactory instance.
54
+ *
55
+ * @param builders - Record of builder functions for creating individual entities
56
+ * @param seeds - Record of seed functions for creating complex test scenarios
57
+ * @param db - Knex database connection instance
58
+ */
59
+ constructor(builders, seeds, db) {
60
+ super();
61
+ this.builders = builders;
62
+ this.seeds = seeds;
63
+ this.db = db;
64
+ }
65
+ /**
66
+ * Inserts a single record into the database using the specified builder.
67
+ * Uses Objection.js's insertGraph method to handle nested relations.
68
+ *
69
+ * @param factory - The name of the builder to use
70
+ * @param attrs - Optional attributes to override builder defaults
71
+ * @returns A promise resolving to the inserted record with all relations
72
+ * @throws Error if the specified builder doesn't exist
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * // Insert with defaults
77
+ * const user = await factory.insert('user');
78
+ *
79
+ * // Insert with overrides
80
+ * const adminUser = await factory.insert('user', {
81
+ * email: 'admin@example.com',
82
+ * role: 'admin'
83
+ * });
84
+ *
85
+ * // Insert with nested relations
86
+ * const userWithProfile = await factory.insert('user', {
87
+ * name: 'John Doe',
88
+ * profile: {
89
+ * bio: 'Software Developer',
90
+ * avatar: 'avatar.jpg'
91
+ * }
92
+ * });
93
+ * ```
94
+ */
95
+ insert(factory, attrs = {}) {
96
+ 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`);
97
+ return this.builders[factory](attrs, {}, this.db).then((record) => {
98
+ return record.$query(this.db).insertGraph(record).execute();
99
+ });
100
+ }
101
+ /**
102
+ * Inserts multiple records into the database using the specified builder.
103
+ * Supports both static attributes and dynamic attribute generation via a function.
104
+ *
105
+ * @param count - The number of records to insert
106
+ * @param builderName - The name of the builder to use
107
+ * @param attrs - Static attributes or a function that generates attributes for each record
108
+ * @returns A promise resolving to an array of inserted records
109
+ * @throws Error if the specified builder doesn't exist
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * // Insert multiple with same attributes
114
+ * const users = await factory.insertMany(5, 'user', { role: 'member' });
115
+ *
116
+ * // Insert multiple with dynamic attributes
117
+ * const posts = await factory.insertMany(10, 'post', (idx) => ({
118
+ * title: `Post ${idx + 1}`,
119
+ * content: `Content for post ${idx + 1}`,
120
+ * publishedAt: new Date()
121
+ * }));
122
+ *
123
+ * // Create users with sequential emails
124
+ * const admins = await factory.insertMany(3, 'user', (idx) => ({
125
+ * email: `admin${idx + 1}@example.com`,
126
+ * role: 'admin'
127
+ * }));
128
+ * ```
129
+ */
130
+ insertMany(count, builderName, attrs = {}) {
131
+ 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`);
132
+ const records = [];
133
+ for (let i = 0; i < count; i++) {
134
+ const newAttrs = typeof attrs === "function" ? attrs(i) : attrs;
135
+ records.push(this.builders[builderName](newAttrs, {}, this.db).then((record) => record.$query(this.db).insertGraph(record).execute()));
136
+ }
137
+ return Promise.all(records);
138
+ }
139
+ /**
140
+ * Executes a seed function to create complex test scenarios with multiple related records.
141
+ * Seeds are useful for setting up complete test environments with realistic data relationships.
142
+ *
143
+ * @param seedName - The name of the seed to execute
144
+ * @param attrs - Optional configuration attributes for the seed
145
+ * @returns The result of the seed function (typically the primary record created)
146
+ * @throws Error if the specified seed doesn't exist
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * // Execute a simple seed
151
+ * const user = await factory.seed('userWithProfile');
152
+ *
153
+ * // Execute a seed with configuration
154
+ * const author = await factory.seed('authorWithBooks', {
155
+ * bookCount: 5,
156
+ * includeReviews: true
157
+ * });
158
+ *
159
+ * // Use seed result in tests with Objection.js relations
160
+ * const company = await factory.seed('companyWithDepartments', {
161
+ * departmentCount: 3,
162
+ * employeesPerDepartment: 10
163
+ * });
164
+ *
165
+ * // Access eager loaded relations
166
+ * const companyWithRelations = await Company.query()
167
+ * .findById(company.id)
168
+ * .withGraphFetched('[departments.employees]');
169
+ * ```
170
+ */
171
+ seed(seedName, attrs = {}) {
172
+ 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`);
173
+ return this.seeds[seedName](attrs, this, this.db);
174
+ }
175
+ };
176
+
177
+ //#endregion
178
+ Object.defineProperty(exports, 'ObjectionFactory', {
179
+ enumerable: true,
180
+ get: function () {
181
+ return ObjectionFactory;
182
+ }
183
+ });
@@ -1,4 +1,4 @@
1
- require('./Factory-DREHoms3.cjs');
2
- const require_ObjectionFactory = require('./ObjectionFactory-BlkzSEqo.cjs');
1
+ require('./Factory-WMhTNZ9S.cjs');
2
+ const require_ObjectionFactory = require('./ObjectionFactory-C47B03Ot.cjs');
3
3
 
4
4
  exports.ObjectionFactory = require_ObjectionFactory.ObjectionFactory;
@@ -1,4 +1,4 @@
1
- import "./Factory-DlzMkMzb.mjs";
2
- import { ObjectionFactory } from "./ObjectionFactory-ChuX8sZN.mjs";
1
+ import "./Factory-z2m01hMj.mjs";
2
+ import { ObjectionFactory } from "./ObjectionFactory-89p-FFEw.mjs";
3
3
 
4
4
  export { ObjectionFactory };
@@ -0,0 +1,87 @@
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const require_PostgresMigrator = require('./PostgresMigrator-BtAWdLss.cjs');
3
+ const kysely = require_chunk.__toESM(require("kysely"));
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
+ */
46
+ var PostgresKyselyMigrator = class extends require_PostgresMigrator.PostgresMigrator {
47
+ /**
48
+ * Creates a new PostgresKyselyMigrator instance.
49
+ *
50
+ * @param options - Configuration options
51
+ * @param options.uri - PostgreSQL connection URI
52
+ * @param options.db - Kysely database instance
53
+ * @param options.provider - Migration provider for locating migration files
54
+ */
55
+ constructor(options) {
56
+ super(options.uri);
57
+ this.options = options;
58
+ }
59
+ /**
60
+ * Executes Kysely migrations to the latest version.
61
+ * Implements the abstract migrate() method from PostgresMigrator.
62
+ *
63
+ * @throws Error if migrations fail to apply
64
+ * @returns Promise that resolves when all migrations are applied
65
+ */
66
+ async migrate() {
67
+ const migrator = new kysely.Migrator({
68
+ db: this.options.db,
69
+ provider: this.options.provider
70
+ });
71
+ const migrations = await migrator.migrateToLatest();
72
+ if (migrations.error) {
73
+ logger.error(migrations.error, `Failed to apply migrations`);
74
+ throw migrations.error;
75
+ }
76
+ await this.options.db.destroy();
77
+ logger.log(`Applied ${migrations.results?.length} migrations successfully`);
78
+ }
79
+ };
80
+
81
+ //#endregion
82
+ Object.defineProperty(exports, 'PostgresKyselyMigrator', {
83
+ enumerable: true,
84
+ get: function () {
85
+ return PostgresKyselyMigrator;
86
+ }
87
+ });
@@ -0,0 +1,81 @@
1
+ import { PostgresMigrator } from "./PostgresMigrator-BzqksJcW.mjs";
2
+ import { Migrator } from "kysely";
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
+ */
45
+ var PostgresKyselyMigrator = class extends PostgresMigrator {
46
+ /**
47
+ * Creates a new PostgresKyselyMigrator instance.
48
+ *
49
+ * @param options - Configuration options
50
+ * @param options.uri - PostgreSQL connection URI
51
+ * @param options.db - Kysely database instance
52
+ * @param options.provider - Migration provider for locating migration files
53
+ */
54
+ constructor(options) {
55
+ super(options.uri);
56
+ this.options = options;
57
+ }
58
+ /**
59
+ * Executes Kysely migrations to the latest version.
60
+ * Implements the abstract migrate() method from PostgresMigrator.
61
+ *
62
+ * @throws Error if migrations fail to apply
63
+ * @returns Promise that resolves when all migrations are applied
64
+ */
65
+ async migrate() {
66
+ const migrator = new Migrator({
67
+ db: this.options.db,
68
+ provider: this.options.provider
69
+ });
70
+ const migrations = await migrator.migrateToLatest();
71
+ if (migrations.error) {
72
+ logger.error(migrations.error, `Failed to apply migrations`);
73
+ throw migrations.error;
74
+ }
75
+ await this.options.db.destroy();
76
+ logger.log(`Applied ${migrations.results?.length} migrations successfully`);
77
+ }
78
+ };
79
+
80
+ //#endregion
81
+ export { PostgresKyselyMigrator };
@@ -1,4 +1,4 @@
1
- require('./PostgresMigrator-Bz-tnjB6.cjs');
2
- const require_PostgresKyselyMigrator = require('./PostgresKyselyMigrator-JTY2LfwD.cjs');
1
+ require('./PostgresMigrator-BtAWdLss.cjs');
2
+ const require_PostgresKyselyMigrator = require('./PostgresKyselyMigrator-Bs31emFd.cjs');
3
3
 
4
4
  exports.PostgresKyselyMigrator = require_PostgresKyselyMigrator.PostgresKyselyMigrator;
@@ -1,4 +1,4 @@
1
- import "./PostgresMigrator-CEoRKTdq.mjs";
2
- import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-D8fm35-s.mjs";
1
+ import "./PostgresMigrator-BzqksJcW.mjs";
2
+ import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-ChIpZFYB.mjs";
3
3
 
4
4
  export { PostgresKyselyMigrator };