@geekmidas/testkit 0.0.3 → 0.0.5

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 (72) hide show
  1. package/PostgresKyselyMigrator.spec +471 -0
  2. package/dist/{KyselyFactory-DiiWtMYe.cjs → KyselyFactory-BX7Kv2uP.cjs} +11 -12
  3. package/dist/{KyselyFactory-DZewtWtJ.mjs → KyselyFactory-pOMOFQWE.mjs} +11 -12
  4. package/dist/KyselyFactory.cjs +2 -1
  5. package/dist/KyselyFactory.mjs +2 -1
  6. package/dist/ObjectionFactory.cjs +1 -1
  7. package/dist/ObjectionFactory.mjs +1 -1
  8. package/dist/{PostgresKyselyMigrator-ChMJpPrQ.mjs → PostgresKyselyMigrator-D8fm35-s.mjs} +1 -1
  9. package/dist/{PostgresKyselyMigrator-rY3hO_-1.cjs → PostgresKyselyMigrator-JTY2LfwD.cjs} +3 -2
  10. package/dist/PostgresKyselyMigrator.cjs +2 -2
  11. package/dist/PostgresKyselyMigrator.mjs +2 -2
  12. package/dist/{PostgresMigrator-BJ2-5A_b.cjs → PostgresMigrator-Bz-tnjB6.cjs} +2 -39
  13. package/dist/PostgresMigrator.cjs +1 -1
  14. package/dist/PostgresMigrator.mjs +1 -1
  15. package/dist/VitestKyselyTransactionIsolator-BS3R-V0I.mjs +12 -0
  16. package/dist/VitestKyselyTransactionIsolator-DWSTKIe3.cjs +17 -0
  17. package/dist/VitestKyselyTransactionIsolator.cjs +4 -0
  18. package/dist/VitestKyselyTransactionIsolator.mjs +4 -0
  19. package/dist/VitestTransactionIsolator-BjVXqFs6.mjs +40 -0
  20. package/dist/VitestTransactionIsolator-Bx2c4OzK.cjs +52 -0
  21. package/dist/VitestTransactionIsolator.cjs +4 -0
  22. package/dist/VitestTransactionIsolator.mjs +3 -0
  23. package/dist/__tests__/Factory.spec.cjs +139 -0
  24. package/dist/__tests__/Factory.spec.mjs +138 -0
  25. package/dist/__tests__/KyselyFactory.spec.cjs +220 -15008
  26. package/dist/__tests__/KyselyFactory.spec.mjs +218 -15033
  27. package/dist/__tests__/ObjectionFactory.spec.cjs +386 -0
  28. package/dist/__tests__/ObjectionFactory.spec.mjs +385 -0
  29. package/dist/__tests__/PostgresMigrator.spec.cjs +256 -0
  30. package/dist/__tests__/PostgresMigrator.spec.mjs +255 -0
  31. package/dist/__tests__/faker.spec.cjs +115 -0
  32. package/dist/__tests__/faker.spec.mjs +114 -0
  33. package/dist/__tests__/integration.spec.cjs +279 -0
  34. package/dist/__tests__/integration.spec.mjs +278 -0
  35. package/dist/chunk-CUT6urMc.cjs +30 -0
  36. package/dist/example.cjs +2 -1
  37. package/dist/example.mjs +2 -1
  38. package/dist/faker-BwaXA_RF.mjs +85 -0
  39. package/dist/faker-caz-8zt8.cjs +121 -0
  40. package/dist/faker.cjs +8 -0
  41. package/dist/faker.mjs +3 -0
  42. package/dist/helpers-B9Jdk_C7.cjs +31 -0
  43. package/dist/helpers-BfuX-cjN.mjs +111 -0
  44. package/dist/helpers-DKEBHABj.cjs +135 -0
  45. package/dist/helpers-DOiGIkaU.mjs +19 -0
  46. package/dist/helpers.cjs +6 -0
  47. package/dist/helpers.mjs +5 -0
  48. package/dist/kysely.cjs +15 -4
  49. package/dist/kysely.mjs +14 -4
  50. package/dist/objection.cjs +1 -1
  51. package/dist/objection.mjs +1 -1
  52. package/package.json +8 -2
  53. package/src/Factory.ts +3 -1
  54. package/src/KyselyFactory.ts +30 -36
  55. package/src/VitestKyselyTransactionIsolator.ts +23 -0
  56. package/src/VitestTransactionIsolator.ts +70 -0
  57. package/src/__tests__/Factory.spec.ts +164 -0
  58. package/src/__tests__/KyselyFactory.spec.ts +432 -64
  59. package/src/__tests__/ObjectionFactory.spec.ts +532 -0
  60. package/src/__tests__/PostgresMigrator.spec.ts +366 -0
  61. package/src/__tests__/faker.spec.ts +142 -0
  62. package/src/__tests__/integration.spec.ts +442 -0
  63. package/src/faker.ts +112 -0
  64. package/src/helpers.ts +28 -0
  65. package/src/kysely.ts +14 -0
  66. package/test/globalSetup.ts +41 -40
  67. package/test/helpers.ts +273 -0
  68. package/dist/magic-string.es-CxbtJGk_.mjs +0 -1014
  69. package/dist/magic-string.es-KiPEzMtt.cjs +0 -1015
  70. /package/dist/{ObjectionFactory-DeFYWbzt.cjs → ObjectionFactory-BlkzSEqo.cjs} +0 -0
  71. /package/dist/{ObjectionFactory-MAf2m8LI.mjs → ObjectionFactory-ChuX8sZN.mjs} +0 -0
  72. /package/dist/{PostgresMigrator-BKaNTth5.mjs → PostgresMigrator-CEoRKTdq.mjs} +0 -0
@@ -0,0 +1,471 @@
1
+ import {
2
+ type Kysely,
3
+ type MigrationProvider,
4
+ type Transaction,
5
+ sql,
6
+ } from 'kysely';
7
+ import {
8
+ type TestAPI,
9
+ afterEach,
10
+ beforeAll,
11
+ beforeEach,
12
+ describe,
13
+ expect,
14
+ vi,
15
+ } from 'vitest';
16
+ import { createTestDatabase } from '../../test/helpers';
17
+ import { PostgresKyselyMigrator } from '../PostgresKyselyMigrator';
18
+ import { PostgresMigrator } from '../PostgresMigrator';
19
+ import { createKyselyDb, wrapVitestKyselyTransaction } from '../helpers';
20
+
21
+ describe.skip('PostgresKyselyMigrator', () => {
22
+ let testDbName: string;
23
+ let cleanupDb: () => Promise<void>;
24
+
25
+ let consoleSpy: any;
26
+ let consoleErrorSpy: any;
27
+ let it: TestAPI<{
28
+ trx: Transaction<any>;
29
+ }>;
30
+
31
+ beforeAll(async () => {
32
+ testDbName = `test_kysely_migrator_${Date.now()}`;
33
+ cleanupDb = await createTestDatabase(testDbName);
34
+ const db = createKyselyDb<any>({
35
+ host: 'localhost',
36
+ port: 5432,
37
+ user: 'geekmidas',
38
+ password: 'geekmidas',
39
+ database: testDbName,
40
+ });
41
+ it = wrapVitestKyselyTransaction(db);
42
+ });
43
+
44
+ beforeEach(() => {
45
+ consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
46
+ consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
47
+ });
48
+
49
+ afterEach(() => {
50
+ consoleSpy.mockRestore();
51
+ consoleErrorSpy.mockRestore();
52
+ });
53
+
54
+ describe.skip('constructor', () => {
55
+ it('should create a PostgresKyselyMigrator instance', ({ trx }) => {
56
+ const provider: MigrationProvider = {
57
+ getMigrations: async () => ({}),
58
+ };
59
+
60
+ const options = {
61
+ uri: `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
62
+ db: trx,
63
+ provider,
64
+ };
65
+
66
+ const migrator = new PostgresKyselyMigrator(options);
67
+
68
+ expect(migrator).toBeInstanceOf(PostgresKyselyMigrator);
69
+ expect(migrator).toBeInstanceOf(PostgresMigrator);
70
+ });
71
+ });
72
+
73
+ describe.skip('migrate method', () => {
74
+ it('should run migrations successfully', async ({ trx }) => {
75
+ const migrations = {
76
+ '001_initial': {
77
+ up: async (db: Kysely<any>) => {
78
+ await db.schema
79
+ .createTable('test_table')
80
+ .addColumn('id', 'serial', (col) => col.primaryKey())
81
+ .addColumn('name', 'varchar', (col) => col.notNull())
82
+ .execute();
83
+ },
84
+ down: async (db: Kysely<any>) => {
85
+ await db.schema.dropTable('test_table').execute();
86
+ },
87
+ },
88
+ '002_add_column': {
89
+ up: async (db: Kysely<any>) => {
90
+ await db.schema
91
+ .alterTable('test_table')
92
+ .addColumn('email', 'varchar')
93
+ .execute();
94
+ },
95
+ down: async (db: Kysely<any>) => {
96
+ await db.schema
97
+ .alterTable('test_table')
98
+ .dropColumn('email')
99
+ .execute();
100
+ },
101
+ },
102
+ };
103
+
104
+ const provider: MigrationProvider = {
105
+ getMigrations: async () => migrations,
106
+ };
107
+
108
+ const options = {
109
+ uri: `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
110
+ db: trx,
111
+ provider,
112
+ };
113
+
114
+ const migrator = new PostgresKyselyMigrator(options);
115
+
116
+ await migrator.migrate();
117
+
118
+ expect(consoleSpy).toHaveBeenCalledWith(
119
+ 'Applied 2 migrations successfully',
120
+ );
121
+
122
+ // Verify the table was created
123
+ const tableResult = await trx
124
+ .selectFrom('information_schema.tables')
125
+ .selectAll()
126
+ .where('table_name', '=', 'test_table')
127
+ .where('table_schema', '=', 'public')
128
+ .execute();
129
+
130
+ expect(tableResult.length).toBe(1);
131
+
132
+ // Verify the column was added
133
+ const columnResult = await trx
134
+ .selectFrom('information_schema.columns')
135
+ .selectAll()
136
+ .where('table_name', '=', 'test_table')
137
+ .where('column_name', '=', 'email')
138
+ .execute();
139
+
140
+ expect(columnResult.length).toBe(1);
141
+ });
142
+
143
+ it('should handle migration errors', async ({ trx }) => {
144
+ const migrations = {
145
+ '001_bad_migration': {
146
+ up: async (db: Kysely<any>) => {
147
+ // This will fail due to invalid SQL
148
+ await db.executeQuery(sql`INVALID SQL SYNTAX`.compile(trx));
149
+ },
150
+ down: async (db: Kysely<any>) => {
151
+ // No-op
152
+ },
153
+ },
154
+ };
155
+
156
+ const provider: MigrationProvider = {
157
+ getMigrations: async () => migrations,
158
+ };
159
+
160
+ const options = {
161
+ uri: `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
162
+ db: trx,
163
+ provider,
164
+ };
165
+
166
+ const migrator = new PostgresKyselyMigrator(options);
167
+
168
+ await expect(migrator.migrate()).rejects.toThrow();
169
+
170
+ expect(consoleErrorSpy).toHaveBeenCalledWith(
171
+ expect.any(Error),
172
+ 'Failed to apply migrations',
173
+ );
174
+ });
175
+
176
+ it('should handle no migrations to apply', async ({ trx }) => {
177
+ const provider: MigrationProvider = {
178
+ getMigrations: async () => ({}), // No migrations
179
+ };
180
+
181
+ const options = {
182
+ uri: `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
183
+ db: trx,
184
+ provider,
185
+ };
186
+
187
+ const migrator = new PostgresKyselyMigrator(options);
188
+
189
+ await migrator.migrate();
190
+
191
+ expect(consoleSpy).toHaveBeenCalledWith(
192
+ 'Applied 0 migrations successfully',
193
+ );
194
+ });
195
+
196
+ it('should handle provider that returns undefined results', async ({
197
+ trx,
198
+ }) => {
199
+ // Create a provider that returns migrations but Kysely reports undefined results
200
+ const provider: MigrationProvider = {
201
+ getMigrations: async () => ({
202
+ '001_test': {
203
+ up: async (db: Kysely<any>) => {
204
+ // Simple migration that should succeed but might return undefined results
205
+ await db.schema
206
+ .createTable('temp_table')
207
+ .addColumn('id', 'serial')
208
+ .ifNotExists()
209
+ .execute();
210
+ await db.schema.dropTable('temp_table').ifExists().execute();
211
+ },
212
+ down: async () => {},
213
+ },
214
+ }),
215
+ };
216
+
217
+ const options = {
218
+ uri: `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
219
+ db: trx,
220
+ provider,
221
+ };
222
+
223
+ const migrator = new PostgresKyselyMigrator(options);
224
+
225
+ await migrator.migrate();
226
+
227
+ // Should handle the case gracefully
228
+ expect(consoleSpy).toHaveBeenCalled();
229
+ });
230
+
231
+ it('should cleanup database connection even if migration throws', async ({
232
+ trx,
233
+ }) => {
234
+ const destroySpy = vi.spyOn(trx, 'destroy');
235
+
236
+ const provider: MigrationProvider = {
237
+ getMigrations: async () => {
238
+ throw new Error('Provider failed');
239
+ },
240
+ };
241
+
242
+ const options = {
243
+ uri: `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
244
+ db: trx,
245
+ provider,
246
+ };
247
+
248
+ const migrator = new PostgresKyselyMigrator(options);
249
+
250
+ await expect(migrator.migrate()).rejects.toThrow('Provider failed');
251
+
252
+ expect(destroySpy).toHaveBeenCalled();
253
+ });
254
+
255
+ it('should handle database destroy errors gracefully', async () => {
256
+ // Create a mock db that will fail on destroy
257
+ const failingDb = {
258
+ destroy: vi
259
+ .fn()
260
+ .mockRejectedValue(new Error('Failed to close connection')),
261
+ } as any;
262
+
263
+ const provider: MigrationProvider = {
264
+ getMigrations: async () => ({}),
265
+ };
266
+
267
+ const options = {
268
+ uri: `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
269
+ db: failingDb,
270
+ provider,
271
+ };
272
+
273
+ const migrator = new PostgresKyselyMigrator(options);
274
+
275
+ // The migrate method should propagate the destroy error
276
+ await expect(migrator.migrate()).rejects.toThrow(
277
+ 'Failed to close connection',
278
+ );
279
+ });
280
+ });
281
+
282
+ describe.skip('integration with Kysely types', () => {
283
+ it('should work with typed database interface', ({ trx }) => {
284
+ interface Database {
285
+ users: {
286
+ id: number;
287
+ name: string;
288
+ email: string;
289
+ };
290
+ posts: {
291
+ id: number;
292
+ title: string;
293
+ userId: number;
294
+ };
295
+ }
296
+
297
+ const typedDb = trx as Kysely<Database>;
298
+ const typedProvider: MigrationProvider = {
299
+ getMigrations: async () => ({}),
300
+ };
301
+
302
+ const options = {
303
+ uri: `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
304
+ db: typedDb,
305
+ provider: typedProvider,
306
+ };
307
+
308
+ const migrator = new PostgresKyselyMigrator(options);
309
+
310
+ expect(migrator).toBeInstanceOf(PostgresKyselyMigrator);
311
+ });
312
+ });
313
+
314
+ describe.skip('logging', () => {
315
+ it('should log correct number of applied migrations', async ({ trx }) => {
316
+ const migrations = {};
317
+ // Create 5 simple migrations
318
+ for (let i = 1; i <= 5; i++) {
319
+ migrations[`00${i}_migration`] = {
320
+ up: async (db: Kysely<any>) => {
321
+ // Simple operation that won't conflict
322
+ await db.executeQuery(
323
+ sql`CREATE TABLE IF NOT EXISTS temp_${sql.raw(`migration_${i}`)} (id SERIAL)`.compile(
324
+ db,
325
+ ),
326
+ );
327
+ await db.executeQuery(
328
+ sql`DROP TABLE IF EXISTS temp_${sql.raw(`migration_${i}`)}`.compile(
329
+ db,
330
+ ),
331
+ );
332
+ },
333
+ down: async () => {},
334
+ };
335
+ }
336
+
337
+ const provider: MigrationProvider = {
338
+ getMigrations: async () => migrations,
339
+ };
340
+
341
+ const options = {
342
+ uri: `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
343
+ db: trx,
344
+ provider,
345
+ };
346
+
347
+ const migrator = new PostgresKyselyMigrator(options);
348
+
349
+ await migrator.migrate();
350
+
351
+ expect(consoleSpy).toHaveBeenCalledWith(
352
+ 'Applied 5 migrations successfully',
353
+ );
354
+ });
355
+
356
+ it('should log errors with context', async ({ trx }) => {
357
+ const migrations = {
358
+ '001_invalid_column': {
359
+ up: async (db: Kysely<any>) => {
360
+ // This will fail with a specific error
361
+ await db.executeQuery(
362
+ sql`SELECT invalid_column FROM non_existent_table`.compile(db),
363
+ );
364
+ },
365
+ down: async () => {},
366
+ },
367
+ };
368
+
369
+ const provider: MigrationProvider = {
370
+ getMigrations: async () => migrations,
371
+ };
372
+
373
+ const options = {
374
+ uri: `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
375
+ db: trx,
376
+ provider,
377
+ };
378
+
379
+ const migrator = new PostgresKyselyMigrator(options);
380
+
381
+ await expect(migrator.migrate()).rejects.toThrow();
382
+
383
+ expect(consoleErrorSpy).toHaveBeenCalledWith(
384
+ expect.any(Error),
385
+ 'Failed to apply migrations',
386
+ );
387
+ });
388
+ });
389
+
390
+ describe.skip('error scenarios', () => {
391
+ it('should handle invalid migration provider', async ({ trx }) => {
392
+ const invalidProvider: MigrationProvider = {
393
+ getMigrations: async () => {
394
+ throw new Error('Invalid migration configuration');
395
+ },
396
+ };
397
+
398
+ const options = {
399
+ uri: `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
400
+ db: trx,
401
+ provider: invalidProvider,
402
+ };
403
+
404
+ const migrator = new PostgresKyselyMigrator(options);
405
+
406
+ await expect(migrator.migrate()).rejects.toThrow(
407
+ 'Invalid migration configuration',
408
+ );
409
+ });
410
+
411
+ it('should handle migration execution errors', async ({ trx }) => {
412
+ const migrations = {
413
+ '001_failing_migration': {
414
+ up: async (db: Kysely<any>) => {
415
+ throw new Error('Migration execution failed');
416
+ },
417
+ down: async () => {},
418
+ },
419
+ };
420
+
421
+ const provider: MigrationProvider = {
422
+ getMigrations: async () => migrations,
423
+ };
424
+
425
+ const options = {
426
+ uri: `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
427
+ db: trx,
428
+ provider,
429
+ };
430
+
431
+ const migrator = new PostgresKyselyMigrator(options);
432
+
433
+ await expect(migrator.migrate()).rejects.toThrow();
434
+ });
435
+ });
436
+
437
+ describe('inheritance', () => {
438
+ it('should properly extend PostgresMigrator', ({ trx }) => {
439
+ const provider: MigrationProvider = {
440
+ getMigrations: async () => ({}),
441
+ };
442
+
443
+ const options = {
444
+ uri: `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
445
+ db: trx,
446
+ provider,
447
+ };
448
+
449
+ const migrator = new PostgresKyselyMigrator(options);
450
+
451
+ expect(migrator).toBeInstanceOf(PostgresMigrator);
452
+ expect(migrator).toBeInstanceOf(PostgresKyselyMigrator);
453
+ });
454
+
455
+ it('should implement the abstract migrate method', ({ trx }) => {
456
+ const provider: MigrationProvider = {
457
+ getMigrations: async () => ({}),
458
+ };
459
+
460
+ const options = {
461
+ uri: `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
462
+ db: trx,
463
+ provider,
464
+ };
465
+
466
+ const migrator = new PostgresKyselyMigrator(options);
467
+
468
+ expect(typeof migrator.migrate).toBe('function');
469
+ });
470
+ });
471
+ });
@@ -1,4 +1,5 @@
1
1
  const require_Factory = require('./Factory-DREHoms3.cjs');
2
+ const require_faker = require('./faker-caz-8zt8.cjs');
2
3
 
3
4
  //#region src/KyselyFactory.ts
4
5
  var KyselyFactory = class extends require_Factory.Factory {
@@ -11,31 +12,29 @@ var KyselyFactory = class extends require_Factory.Factory {
11
12
  this.seeds = seeds;
12
13
  this.db = db;
13
14
  }
14
- static createBuilder(config) {
15
- return async (attrs, factory, db) => {
15
+ static createBuilder(table, item, autoInsert) {
16
+ return async (attrs, factory, db, faker$1) => {
16
17
  let data = { ...attrs };
17
- if (config.defaults) {
18
- const defaults = await config.defaults(attrs, factory, db);
18
+ if (item) {
19
+ const defaults = await item(attrs, factory, db, faker$1);
19
20
  data = {
20
21
  ...defaults,
21
22
  ...data
22
23
  };
23
24
  }
24
- if (config.transform) data = await config.transform(data, factory, db);
25
- if (config.autoInsert !== false) {
26
- const result = await db.insertInto(config.table).values(data).returningAll().executeTakeFirst();
27
- if (!result) throw new Error(`Failed to insert into ${config.table}`);
28
- if (config.relations) await config.relations(result, attrs, factory, db);
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}`);
29
28
  return result;
30
29
  } else return {
31
- table: config.table,
30
+ table,
32
31
  data
33
32
  };
34
33
  };
35
34
  }
36
35
  async insert(builderName, attrs) {
37
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`);
38
- const result = await this.builders[builderName](attrs || {}, this, this.db);
37
+ const result = await this.builders[builderName](attrs || {}, this, this.db, require_faker.faker);
39
38
  if (result && typeof result === "object" && "table" in result && "data" in result) {
40
39
  const inserted = await this.db.insertInto(result.table).values(result.data).returningAll().executeTakeFirst();
41
40
  return inserted;
@@ -46,7 +45,7 @@ var KyselyFactory = class extends require_Factory.Factory {
46
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`);
47
46
  const promises = [];
48
47
  for (let i = 0; i < count; i++) {
49
- const newAttrs = typeof attrs === "function" ? attrs(i) : attrs;
48
+ const newAttrs = typeof attrs === "function" ? attrs(i, require_faker.faker) : attrs;
50
49
  promises.push(this.insert(builderName, newAttrs));
51
50
  }
52
51
  return Promise.all(promises);
@@ -1,4 +1,5 @@
1
1
  import { Factory } from "./Factory-DlzMkMzb.mjs";
2
+ import { faker } from "./faker-BwaXA_RF.mjs";
2
3
 
3
4
  //#region src/KyselyFactory.ts
4
5
  var KyselyFactory = class extends Factory {
@@ -11,31 +12,29 @@ var KyselyFactory = class extends Factory {
11
12
  this.seeds = seeds;
12
13
  this.db = db;
13
14
  }
14
- static createBuilder(config) {
15
- return async (attrs, factory, db) => {
15
+ static createBuilder(table, item, autoInsert) {
16
+ return async (attrs, factory, db, faker$1) => {
16
17
  let data = { ...attrs };
17
- if (config.defaults) {
18
- const defaults = await config.defaults(attrs, factory, db);
18
+ if (item) {
19
+ const defaults = await item(attrs, factory, db, faker$1);
19
20
  data = {
20
21
  ...defaults,
21
22
  ...data
22
23
  };
23
24
  }
24
- if (config.transform) data = await config.transform(data, factory, db);
25
- if (config.autoInsert !== false) {
26
- const result = await db.insertInto(config.table).values(data).returningAll().executeTakeFirst();
27
- if (!result) throw new Error(`Failed to insert into ${config.table}`);
28
- if (config.relations) await config.relations(result, attrs, factory, db);
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}`);
29
28
  return result;
30
29
  } else return {
31
- table: config.table,
30
+ table,
32
31
  data
33
32
  };
34
33
  };
35
34
  }
36
35
  async insert(builderName, attrs) {
37
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`);
38
- const result = await this.builders[builderName](attrs || {}, this, this.db);
37
+ const result = await this.builders[builderName](attrs || {}, this, this.db, faker);
39
38
  if (result && typeof result === "object" && "table" in result && "data" in result) {
40
39
  const inserted = await this.db.insertInto(result.table).values(result.data).returningAll().executeTakeFirst();
41
40
  return inserted;
@@ -46,7 +45,7 @@ var KyselyFactory = class extends Factory {
46
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`);
47
46
  const promises = [];
48
47
  for (let i = 0; i < count; i++) {
49
- const newAttrs = typeof attrs === "function" ? attrs(i) : attrs;
48
+ const newAttrs = typeof attrs === "function" ? attrs(i, faker) : attrs;
50
49
  promises.push(this.insert(builderName, newAttrs));
51
50
  }
52
51
  return Promise.all(promises);
@@ -1,4 +1,5 @@
1
1
  require('./Factory-DREHoms3.cjs');
2
- const require_KyselyFactory = require('./KyselyFactory-DiiWtMYe.cjs');
2
+ require('./faker-caz-8zt8.cjs');
3
+ const require_KyselyFactory = require('./KyselyFactory-BX7Kv2uP.cjs');
3
4
 
4
5
  exports.KyselyFactory = require_KyselyFactory.KyselyFactory;
@@ -1,4 +1,5 @@
1
1
  import "./Factory-DlzMkMzb.mjs";
2
- import { KyselyFactory } from "./KyselyFactory-DZewtWtJ.mjs";
2
+ import "./faker-BwaXA_RF.mjs";
3
+ import { KyselyFactory } from "./KyselyFactory-pOMOFQWE.mjs";
3
4
 
4
5
  export { KyselyFactory };
@@ -1,4 +1,4 @@
1
1
  require('./Factory-DREHoms3.cjs');
2
- const require_ObjectionFactory = require('./ObjectionFactory-DeFYWbzt.cjs');
2
+ const require_ObjectionFactory = require('./ObjectionFactory-BlkzSEqo.cjs');
3
3
 
4
4
  exports.ObjectionFactory = require_ObjectionFactory.ObjectionFactory;
@@ -1,4 +1,4 @@
1
1
  import "./Factory-DlzMkMzb.mjs";
2
- import { ObjectionFactory } from "./ObjectionFactory-MAf2m8LI.mjs";
2
+ import { ObjectionFactory } from "./ObjectionFactory-ChuX8sZN.mjs";
3
3
 
4
4
  export { ObjectionFactory };
@@ -1,4 +1,4 @@
1
- import { PostgresMigrator } from "./PostgresMigrator-BKaNTth5.mjs";
1
+ import { PostgresMigrator } from "./PostgresMigrator-CEoRKTdq.mjs";
2
2
  import { Migrator } from "kysely";
3
3
 
4
4
  //#region src/PostgresKyselyMigrator.ts
@@ -1,5 +1,6 @@
1
- const require_PostgresMigrator = require('./PostgresMigrator-BJ2-5A_b.cjs');
2
- const kysely = require_PostgresMigrator.__toESM(require("kysely"));
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"));
3
4
 
4
5
  //#region src/PostgresKyselyMigrator.ts
5
6
  const logger = console;
@@ -1,4 +1,4 @@
1
- require('./PostgresMigrator-BJ2-5A_b.cjs');
2
- const require_PostgresKyselyMigrator = require('./PostgresKyselyMigrator-rY3hO_-1.cjs');
1
+ require('./PostgresMigrator-Bz-tnjB6.cjs');
2
+ const require_PostgresKyselyMigrator = require('./PostgresKyselyMigrator-JTY2LfwD.cjs');
3
3
 
4
4
  exports.PostgresKyselyMigrator = require_PostgresKyselyMigrator.PostgresKyselyMigrator;
@@ -1,4 +1,4 @@
1
- import "./PostgresMigrator-BKaNTth5.mjs";
2
- import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-ChMJpPrQ.mjs";
1
+ import "./PostgresMigrator-CEoRKTdq.mjs";
2
+ import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-D8fm35-s.mjs";
3
3
 
4
4
  export { PostgresKyselyMigrator };