@geekmidas/testkit 0.0.11 → 0.0.13
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/README.md +1 -1
- package/dist/{Factory-B9LP1L18.d.cts → Factory-D7P3bKKb.d.mts} +2 -2
- package/dist/{Factory-DiZSNxC0.d.mts → Factory-pNV7ZQ7-.d.cts} +2 -2
- package/dist/Factory.d.cts +2 -2
- package/dist/Factory.d.mts +2 -2
- package/dist/{KyselyFactory-ELiHgHVv.mjs → KyselyFactory-BcYkC0t2.mjs} +2 -2
- package/dist/{KyselyFactory-B-zlLbov.d.mts → KyselyFactory-BrWADI77.d.mts} +3 -3
- package/dist/{KyselyFactory-Bdq1s1Go.cjs → KyselyFactory-Cf0o2YxO.cjs} +2 -2
- package/dist/{KyselyFactory-CrLWxJW4.d.cts → KyselyFactory-DM2dnUXU.d.cts} +3 -3
- package/dist/KyselyFactory.cjs +2 -2
- package/dist/KyselyFactory.d.cts +3 -3
- package/dist/KyselyFactory.d.mts +3 -3
- package/dist/KyselyFactory.mjs +2 -2
- package/dist/{ObjectionFactory-aqM0dDW7.mjs → ObjectionFactory-8hebmnai.mjs} +21 -5
- package/dist/{ObjectionFactory-CJCpvwts.d.mts → ObjectionFactory-B40NQWSe.d.mts} +2 -2
- package/dist/{ObjectionFactory-Wq80ypMM.cjs → ObjectionFactory-CDriunkS.cjs} +21 -5
- package/dist/{ObjectionFactory-vME-wNlq.d.cts → ObjectionFactory-D3l1VuyX.d.cts} +2 -2
- package/dist/ObjectionFactory.cjs +2 -2
- package/dist/ObjectionFactory.d.cts +3 -3
- package/dist/ObjectionFactory.d.mts +3 -3
- package/dist/ObjectionFactory.mjs +2 -2
- package/dist/__tests__/KyselyFactory.spec.cjs +3 -3
- package/dist/__tests__/KyselyFactory.spec.mjs +3 -3
- package/dist/__tests__/ObjectionFactory.spec.cjs +289 -451
- package/dist/__tests__/ObjectionFactory.spec.mjs +290 -452
- package/dist/__tests__/PostgresKyselyMigrator.spec.cjs +397 -0
- package/dist/__tests__/PostgresKyselyMigrator.spec.d.cts +1 -0
- package/dist/__tests__/PostgresKyselyMigrator.spec.d.mts +1 -0
- package/dist/__tests__/PostgresKyselyMigrator.spec.mjs +396 -0
- package/dist/__tests__/PostgresMigrator.spec.cjs +1 -1
- package/dist/__tests__/PostgresMigrator.spec.mjs +1 -1
- package/dist/__tests__/PostgresObjectionMigrator.spec.cjs +1 -1
- package/dist/__tests__/PostgresObjectionMigrator.spec.mjs +1 -1
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.cjs +4 -12
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.mjs +4 -12
- package/dist/__tests__/faker.spec.cjs +1 -1
- package/dist/__tests__/faker.spec.mjs +1 -1
- package/dist/__tests__/integration.spec.cjs +3 -3
- package/dist/__tests__/integration.spec.mjs +3 -3
- package/dist/{faker-SMN4ira4.cjs → faker-B14IEMIN.cjs} +41 -1
- package/dist/{faker-CxKkEeYi.mjs → faker-BGKYFoCT.mjs} +36 -2
- package/dist/{faker-DAiFK3T3.d.cts → faker-BSH1EMtg.d.cts} +13 -3
- package/dist/{faker-nN9Ki6fn.d.mts → faker-C-Iuk_R1.d.mts} +13 -3
- package/dist/faker.cjs +2 -1
- package/dist/faker.d.cts +2 -2
- package/dist/faker.d.mts +2 -2
- package/dist/faker.mjs +2 -2
- package/dist/{helpers-BEmjyUVE.mjs → helpers-B4TXg3Wp.mjs} +11 -36
- package/dist/{helpers-CNMBePuj.cjs → helpers-Bf0nXhbu.cjs} +10 -41
- package/dist/kysely.cjs +2 -2
- package/dist/kysely.d.cts +3 -3
- package/dist/kysely.d.mts +3 -3
- package/dist/kysely.mjs +2 -2
- package/dist/objection.cjs +2 -2
- package/dist/objection.d.cts +3 -3
- package/dist/objection.d.mts +3 -3
- package/dist/objection.mjs +2 -2
- package/package.json +2 -2
- package/src/Factory.ts +4 -1
- package/src/KyselyFactory.ts +6 -2
- package/src/ObjectionFactory.ts +31 -4
- package/src/__tests__/ObjectionFactory.spec.ts +423 -542
- package/src/__tests__/PostgresKyselyMigrator.spec.ts +690 -0
- package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +0 -8
- package/src/faker.ts +86 -0
- package/test/helpers.ts +13 -21
- package/dist/example.cjs +0 -22
- package/dist/example.d.cts +0 -26
- package/dist/example.d.mts +0 -26
- package/dist/example.mjs +0 -22
- package/src/example.ts +0 -45
|
@@ -195,6 +195,36 @@ function resetAllSequences() {
|
|
|
195
195
|
function price() {
|
|
196
196
|
return +faker$1.commerce.price();
|
|
197
197
|
}
|
|
198
|
+
function coordinateInRadius(center, radius) {
|
|
199
|
+
const earth = 6378137;
|
|
200
|
+
const d = radius / earth;
|
|
201
|
+
const theta = 2 * Math.PI * Math.random();
|
|
202
|
+
const r = d * Math.sqrt(Math.random());
|
|
203
|
+
const lat1 = center.lat * Math.PI / 180;
|
|
204
|
+
const lng1 = center.lng * Math.PI / 180;
|
|
205
|
+
const lat2 = Math.asin(Math.sin(lat1) * Math.cos(r) + Math.cos(lat1) * Math.sin(r) * Math.cos(theta));
|
|
206
|
+
const lng2 = lng1 + Math.atan2(Math.sin(theta) * Math.sin(r) * Math.cos(lat1), Math.cos(r) - Math.sin(lat1) * Math.sin(lat2));
|
|
207
|
+
return {
|
|
208
|
+
lat: lat2 * 180 / Math.PI,
|
|
209
|
+
lng: lng2 * 180 / Math.PI
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function coordinateOutsideRadius(center, minRadiusMeters, maxRadiusMeters) {
|
|
213
|
+
const earth = 6378137;
|
|
214
|
+
const minD = minRadiusMeters / earth;
|
|
215
|
+
const maxD = maxRadiusMeters / earth;
|
|
216
|
+
const theta = 2 * Math.PI * Math.random();
|
|
217
|
+
const r = Math.sqrt(minD * minD + (maxD * maxD - minD * minD) * Math.random());
|
|
218
|
+
const lat1 = center.lat * Math.PI / 180;
|
|
219
|
+
const lng1 = center.lng * Math.PI / 180;
|
|
220
|
+
const lat2 = Math.asin(Math.sin(lat1) * Math.cos(r) + Math.cos(lat1) * Math.sin(r) * Math.cos(theta));
|
|
221
|
+
const lng2 = lng1 + Math.atan2(Math.sin(theta) * Math.sin(r) * Math.cos(lat1), Math.cos(r) - Math.sin(lat1) * Math.sin(lat2));
|
|
222
|
+
const normalizedLng = (lng2 * 180 / Math.PI + 540) % 360 - 180;
|
|
223
|
+
return {
|
|
224
|
+
lat: lat2 * 180 / Math.PI,
|
|
225
|
+
lng: normalizedLng
|
|
226
|
+
};
|
|
227
|
+
}
|
|
198
228
|
/**
|
|
199
229
|
* Enhanced faker instance with additional utility methods for testing.
|
|
200
230
|
* Extends @faker-js/faker with custom methods for common test data generation patterns.
|
|
@@ -220,8 +250,12 @@ const faker$1 = Object.freeze(Object.assign({}, faker, {
|
|
|
220
250
|
sequence,
|
|
221
251
|
resetSequence,
|
|
222
252
|
resetAllSequences,
|
|
223
|
-
price
|
|
253
|
+
price,
|
|
254
|
+
coordinates: {
|
|
255
|
+
within: coordinateInRadius,
|
|
256
|
+
outside: coordinateOutsideRadius
|
|
257
|
+
}
|
|
224
258
|
}));
|
|
225
259
|
|
|
226
260
|
//#endregion
|
|
227
|
-
export { faker$1 as faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
261
|
+
export { coordinateInRadius, faker$1 as faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _faker_js_faker0 from "@faker-js/faker";
|
|
2
2
|
|
|
3
3
|
//#region src/faker.d.ts
|
|
4
4
|
|
|
@@ -109,6 +109,12 @@ declare function resetAllSequences(): void;
|
|
|
109
109
|
* ```
|
|
110
110
|
*/
|
|
111
111
|
declare function price(): number;
|
|
112
|
+
type Coordinate = {
|
|
113
|
+
lat: number;
|
|
114
|
+
lng: number;
|
|
115
|
+
};
|
|
116
|
+
declare function coordinateInRadius(center: Coordinate, radius: number): Coordinate;
|
|
117
|
+
declare function coordinateOutsideRadius(center: Coordinate, minRadiusMeters: number, maxRadiusMeters: number): Coordinate;
|
|
112
118
|
/**
|
|
113
119
|
* Enhanced faker instance with additional utility methods for testing.
|
|
114
120
|
* Extends @faker-js/faker with custom methods for common test data generation patterns.
|
|
@@ -128,13 +134,17 @@ declare function price(): number;
|
|
|
128
134
|
* const productPrice = faker.price();
|
|
129
135
|
* ```
|
|
130
136
|
*/
|
|
131
|
-
declare const faker: Readonly<
|
|
137
|
+
declare const faker: Readonly<_faker_js_faker0.Faker & {
|
|
132
138
|
timestamps: typeof timestamps;
|
|
133
139
|
identifier: typeof identifier;
|
|
134
140
|
sequence: typeof sequence;
|
|
135
141
|
resetSequence: typeof resetSequence;
|
|
136
142
|
resetAllSequences: typeof resetAllSequences;
|
|
137
143
|
price: typeof price;
|
|
144
|
+
coordinates: {
|
|
145
|
+
within: typeof coordinateInRadius;
|
|
146
|
+
outside: typeof coordinateOutsideRadius;
|
|
147
|
+
};
|
|
138
148
|
}>;
|
|
139
149
|
/**
|
|
140
150
|
* Type definition for timestamp fields.
|
|
@@ -152,4 +162,4 @@ type Timestamps = {
|
|
|
152
162
|
*/
|
|
153
163
|
type FakerFactory = typeof faker;
|
|
154
164
|
//#endregion
|
|
155
|
-
export { FakerFactory, Timestamps, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
165
|
+
export { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _faker_js_faker0 from "@faker-js/faker";
|
|
2
2
|
|
|
3
3
|
//#region src/faker.d.ts
|
|
4
4
|
|
|
@@ -109,6 +109,12 @@ declare function resetAllSequences(): void;
|
|
|
109
109
|
* ```
|
|
110
110
|
*/
|
|
111
111
|
declare function price(): number;
|
|
112
|
+
type Coordinate = {
|
|
113
|
+
lat: number;
|
|
114
|
+
lng: number;
|
|
115
|
+
};
|
|
116
|
+
declare function coordinateInRadius(center: Coordinate, radius: number): Coordinate;
|
|
117
|
+
declare function coordinateOutsideRadius(center: Coordinate, minRadiusMeters: number, maxRadiusMeters: number): Coordinate;
|
|
112
118
|
/**
|
|
113
119
|
* Enhanced faker instance with additional utility methods for testing.
|
|
114
120
|
* Extends @faker-js/faker with custom methods for common test data generation patterns.
|
|
@@ -128,13 +134,17 @@ declare function price(): number;
|
|
|
128
134
|
* const productPrice = faker.price();
|
|
129
135
|
* ```
|
|
130
136
|
*/
|
|
131
|
-
declare const faker$1: Readonly<
|
|
137
|
+
declare const faker$1: Readonly<_faker_js_faker0.Faker & {
|
|
132
138
|
timestamps: typeof timestamps;
|
|
133
139
|
identifier: typeof identifier;
|
|
134
140
|
sequence: typeof sequence;
|
|
135
141
|
resetSequence: typeof resetSequence;
|
|
136
142
|
resetAllSequences: typeof resetAllSequences;
|
|
137
143
|
price: typeof price;
|
|
144
|
+
coordinates: {
|
|
145
|
+
within: typeof coordinateInRadius;
|
|
146
|
+
outside: typeof coordinateOutsideRadius;
|
|
147
|
+
};
|
|
138
148
|
}>;
|
|
139
149
|
/**
|
|
140
150
|
* Type definition for timestamp fields.
|
|
@@ -152,4 +162,4 @@ type Timestamps = {
|
|
|
152
162
|
*/
|
|
153
163
|
type FakerFactory = typeof faker$1;
|
|
154
164
|
//#endregion
|
|
155
|
-
export { FakerFactory, Timestamps, faker$1 as faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
165
|
+
export { FakerFactory, Timestamps, coordinateInRadius, faker$1 as faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
package/dist/faker.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
const require_faker = require('./faker-
|
|
1
|
+
const require_faker = require('./faker-B14IEMIN.cjs');
|
|
2
2
|
|
|
3
|
+
exports.coordinateInRadius = require_faker.coordinateInRadius;
|
|
3
4
|
exports.faker = require_faker.faker;
|
|
4
5
|
exports.identifier = require_faker.identifier;
|
|
5
6
|
exports.resetAllSequences = require_faker.resetAllSequences;
|
package/dist/faker.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { FakerFactory, Timestamps, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-
|
|
2
|
-
export { FakerFactory, Timestamps, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
1
|
+
import { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-BSH1EMtg.cjs";
|
|
2
|
+
export { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
package/dist/faker.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { FakerFactory, Timestamps, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-
|
|
2
|
-
export { FakerFactory, Timestamps, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
1
|
+
import { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-C-Iuk_R1.mjs";
|
|
2
|
+
export { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
package/dist/faker.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-
|
|
1
|
+
import { coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-BGKYFoCT.mjs";
|
|
2
2
|
|
|
3
|
-
export { faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
3
|
+
export { coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
@@ -24,23 +24,6 @@ function createKnexDb() {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* Test setup helper for Knex/Objection that creates tables within a transaction
|
|
28
|
-
*/
|
|
29
|
-
async function setupKnexTest() {
|
|
30
|
-
const db = createKnexDb();
|
|
31
|
-
const trx = await db.transaction();
|
|
32
|
-
await createTestTablesKnex(trx);
|
|
33
|
-
const cleanup = async () => {
|
|
34
|
-
await trx.rollback();
|
|
35
|
-
await db.destroy();
|
|
36
|
-
};
|
|
37
|
-
return {
|
|
38
|
-
db,
|
|
39
|
-
trx,
|
|
40
|
-
cleanup
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
27
|
* Creates test tables using Kysely
|
|
45
28
|
*/
|
|
46
29
|
async function createTestTables(db) {
|
|
@@ -52,29 +35,21 @@ async function createTestTables(db) {
|
|
|
52
35
|
* Creates test tables using Knex
|
|
53
36
|
*/
|
|
54
37
|
async function createTestTablesKnex(trx) {
|
|
55
|
-
await trx.
|
|
56
|
-
|
|
38
|
+
await trx.raw(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
|
|
39
|
+
await trx.schema.createTableIfNotExists("users", (table) => {
|
|
40
|
+
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
57
41
|
table.string("name").notNullable();
|
|
58
|
-
table.string("email").notNullable().unique();
|
|
59
|
-
table.string("role").defaultTo("user");
|
|
60
|
-
table.timestamp("created_at").defaultTo(trx.fn.now()).notNullable();
|
|
61
|
-
table.timestamp("updated_at").defaultTo(trx.fn.now()).notNullable();
|
|
62
42
|
});
|
|
63
|
-
await trx.schema.
|
|
64
|
-
table.
|
|
43
|
+
await trx.schema.createTableIfNotExists("posts", (table) => {
|
|
44
|
+
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
65
45
|
table.string("title").notNullable();
|
|
66
|
-
table.
|
|
67
|
-
table.bigInteger("user_id").notNullable().references("id").inTable("users").onDelete("cascade");
|
|
68
|
-
table.boolean("published").defaultTo(false);
|
|
69
|
-
table.timestamp("created_at").defaultTo(trx.fn.now()).notNullable();
|
|
70
|
-
table.timestamp("updated_at").defaultTo(trx.fn.now()).notNullable();
|
|
46
|
+
table.uuid("user_id").notNullable().references("id").inTable("users").onDelete("cascade");
|
|
71
47
|
});
|
|
72
|
-
await trx.schema.
|
|
73
|
-
table.
|
|
48
|
+
await trx.schema.createTableIfNotExists("comments", (table) => {
|
|
49
|
+
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
74
50
|
table.text("content").notNullable();
|
|
75
|
-
table.
|
|
76
|
-
table.
|
|
77
|
-
table.timestamp("created_at").defaultTo(trx.fn.now()).notNullable();
|
|
51
|
+
table.uuid("post_id").notNullable().references("id").inTable("posts").onDelete("cascade");
|
|
52
|
+
table.uuid("user_id").notNullable().references("id").inTable("users").onDelete("cascade");
|
|
78
53
|
});
|
|
79
54
|
}
|
|
80
55
|
/**
|
|
@@ -108,4 +83,4 @@ async function createTestDatabase(dbName) {
|
|
|
108
83
|
}
|
|
109
84
|
|
|
110
85
|
//#endregion
|
|
111
|
-
export { TEST_DATABASE_CONFIG, createKnexDb, createTestDatabase, createTestTables, createTestTablesKnex
|
|
86
|
+
export { TEST_DATABASE_CONFIG, createKnexDb, createTestDatabase, createTestTables, createTestTablesKnex };
|
|
@@ -25,23 +25,6 @@ function createKnexDb() {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* Test setup helper for Knex/Objection that creates tables within a transaction
|
|
29
|
-
*/
|
|
30
|
-
async function setupKnexTest() {
|
|
31
|
-
const db = createKnexDb();
|
|
32
|
-
const trx = await db.transaction();
|
|
33
|
-
await createTestTablesKnex(trx);
|
|
34
|
-
const cleanup = async () => {
|
|
35
|
-
await trx.rollback();
|
|
36
|
-
await db.destroy();
|
|
37
|
-
};
|
|
38
|
-
return {
|
|
39
|
-
db,
|
|
40
|
-
trx,
|
|
41
|
-
cleanup
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
28
|
* Creates test tables using Kysely
|
|
46
29
|
*/
|
|
47
30
|
async function createTestTables(db) {
|
|
@@ -53,29 +36,21 @@ async function createTestTables(db) {
|
|
|
53
36
|
* Creates test tables using Knex
|
|
54
37
|
*/
|
|
55
38
|
async function createTestTablesKnex(trx) {
|
|
56
|
-
await trx.
|
|
57
|
-
|
|
39
|
+
await trx.raw(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
|
|
40
|
+
await trx.schema.createTableIfNotExists("users", (table) => {
|
|
41
|
+
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
58
42
|
table.string("name").notNullable();
|
|
59
|
-
table.string("email").notNullable().unique();
|
|
60
|
-
table.string("role").defaultTo("user");
|
|
61
|
-
table.timestamp("created_at").defaultTo(trx.fn.now()).notNullable();
|
|
62
|
-
table.timestamp("updated_at").defaultTo(trx.fn.now()).notNullable();
|
|
63
43
|
});
|
|
64
|
-
await trx.schema.
|
|
65
|
-
table.
|
|
44
|
+
await trx.schema.createTableIfNotExists("posts", (table) => {
|
|
45
|
+
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
66
46
|
table.string("title").notNullable();
|
|
67
|
-
table.
|
|
68
|
-
table.bigInteger("user_id").notNullable().references("id").inTable("users").onDelete("cascade");
|
|
69
|
-
table.boolean("published").defaultTo(false);
|
|
70
|
-
table.timestamp("created_at").defaultTo(trx.fn.now()).notNullable();
|
|
71
|
-
table.timestamp("updated_at").defaultTo(trx.fn.now()).notNullable();
|
|
47
|
+
table.uuid("user_id").notNullable().references("id").inTable("users").onDelete("cascade");
|
|
72
48
|
});
|
|
73
|
-
await trx.schema.
|
|
74
|
-
table.
|
|
49
|
+
await trx.schema.createTableIfNotExists("comments", (table) => {
|
|
50
|
+
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
75
51
|
table.text("content").notNullable();
|
|
76
|
-
table.
|
|
77
|
-
table.
|
|
78
|
-
table.timestamp("created_at").defaultTo(trx.fn.now()).notNullable();
|
|
52
|
+
table.uuid("post_id").notNullable().references("id").inTable("posts").onDelete("cascade");
|
|
53
|
+
table.uuid("user_id").notNullable().references("id").inTable("users").onDelete("cascade");
|
|
79
54
|
});
|
|
80
55
|
}
|
|
81
56
|
/**
|
|
@@ -138,10 +113,4 @@ Object.defineProperty(exports, 'createTestTablesKnex', {
|
|
|
138
113
|
get: function () {
|
|
139
114
|
return createTestTablesKnex;
|
|
140
115
|
}
|
|
141
|
-
});
|
|
142
|
-
Object.defineProperty(exports, 'setupKnexTest', {
|
|
143
|
-
enumerable: true,
|
|
144
|
-
get: function () {
|
|
145
|
-
return setupKnexTest;
|
|
146
|
-
}
|
|
147
116
|
});
|
package/dist/kysely.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require('./Factory-WMhTNZ9S.cjs');
|
|
2
|
-
require('./faker-
|
|
3
|
-
const require_KyselyFactory = require('./KyselyFactory-
|
|
2
|
+
require('./faker-B14IEMIN.cjs');
|
|
3
|
+
const require_KyselyFactory = require('./KyselyFactory-Cf0o2YxO.cjs');
|
|
4
4
|
require('./PostgresMigrator-DFcNdCvD.cjs');
|
|
5
5
|
const require_PostgresKyselyMigrator = require('./PostgresKyselyMigrator-CfytARcA.cjs');
|
|
6
6
|
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-CruLTRRi.cjs');
|
package/dist/kysely.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./faker-
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
1
|
+
import "./faker-BSH1EMtg.cjs";
|
|
2
|
+
import "./Factory-pNV7ZQ7-.cjs";
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-DM2dnUXU.cjs";
|
|
4
4
|
import "./PostgresMigrator-D5UkK1_K.cjs";
|
|
5
5
|
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CQ3aUoy_.cjs";
|
|
6
6
|
import { IsolationLevel } from "./VitestTransactionIsolator-DHf2MxmC.cjs";
|
package/dist/kysely.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./faker-
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
1
|
+
import "./faker-C-Iuk_R1.mjs";
|
|
2
|
+
import "./Factory-D7P3bKKb.mjs";
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-BrWADI77.mjs";
|
|
4
4
|
import "./PostgresMigrator-BlvuQl7d.mjs";
|
|
5
5
|
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-_6yHZigp.mjs";
|
|
6
6
|
import { IsolationLevel } from "./VitestTransactionIsolator-Xqyjlmw6.mjs";
|
package/dist/kysely.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./Factory-z2m01hMj.mjs";
|
|
2
|
-
import "./faker-
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
2
|
+
import "./faker-BGKYFoCT.mjs";
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-BcYkC0t2.mjs";
|
|
4
4
|
import "./PostgresMigrator-DxPC_gGu.mjs";
|
|
5
5
|
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-Bdhl251C.mjs";
|
|
6
6
|
import { IsolationLevel } from "./VitestTransactionIsolator-BWwK-ca6.mjs";
|
package/dist/objection.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require('./Factory-WMhTNZ9S.cjs');
|
|
2
|
-
require('./faker-
|
|
3
|
-
const require_ObjectionFactory = require('./ObjectionFactory-
|
|
2
|
+
require('./faker-B14IEMIN.cjs');
|
|
3
|
+
const require_ObjectionFactory = require('./ObjectionFactory-CDriunkS.cjs');
|
|
4
4
|
require('./PostgresMigrator-DFcNdCvD.cjs');
|
|
5
5
|
const require_PostgresObjectionMigrator = require('./PostgresObjectionMigrator-BG6ymgnt.cjs');
|
|
6
6
|
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-CruLTRRi.cjs');
|
package/dist/objection.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./faker-
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { ObjectionFactory } from "./ObjectionFactory-
|
|
1
|
+
import "./faker-BSH1EMtg.cjs";
|
|
2
|
+
import "./Factory-pNV7ZQ7-.cjs";
|
|
3
|
+
import { ObjectionFactory } from "./ObjectionFactory-D3l1VuyX.cjs";
|
|
4
4
|
import "./PostgresMigrator-D5UkK1_K.cjs";
|
|
5
5
|
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-CZHHcCOv.cjs";
|
|
6
6
|
import { IsolationLevel } from "./VitestTransactionIsolator-DHf2MxmC.cjs";
|
package/dist/objection.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./faker-
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { ObjectionFactory } from "./ObjectionFactory-
|
|
1
|
+
import "./faker-C-Iuk_R1.mjs";
|
|
2
|
+
import "./Factory-D7P3bKKb.mjs";
|
|
3
|
+
import { ObjectionFactory } from "./ObjectionFactory-B40NQWSe.mjs";
|
|
4
4
|
import "./PostgresMigrator-BlvuQl7d.mjs";
|
|
5
5
|
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-C69n7vzr.mjs";
|
|
6
6
|
import { IsolationLevel } from "./VitestTransactionIsolator-Xqyjlmw6.mjs";
|
package/dist/objection.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./Factory-z2m01hMj.mjs";
|
|
2
|
-
import "./faker-
|
|
3
|
-
import { ObjectionFactory } from "./ObjectionFactory-
|
|
2
|
+
import "./faker-BGKYFoCT.mjs";
|
|
3
|
+
import { ObjectionFactory } from "./ObjectionFactory-8hebmnai.mjs";
|
|
4
4
|
import "./PostgresMigrator-DxPC_gGu.mjs";
|
|
5
5
|
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-G4h5FLvU.mjs";
|
|
6
6
|
import { IsolationLevel } from "./VitestTransactionIsolator-BWwK-ca6.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/testkit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -37,6 +37,6 @@
|
|
|
37
37
|
"objection": "~3.1.5",
|
|
38
38
|
"db-errors": "~0.2.3",
|
|
39
39
|
"vitest": "~3.2.4",
|
|
40
|
-
"@geekmidas/envkit": "0.0.
|
|
40
|
+
"@geekmidas/envkit": "0.0.6"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/Factory.ts
CHANGED
|
@@ -71,7 +71,10 @@ export abstract class Factory<
|
|
|
71
71
|
builderName: K,
|
|
72
72
|
attrs?:
|
|
73
73
|
| Parameters<Builders[K]>[0]
|
|
74
|
-
| ((
|
|
74
|
+
| ((
|
|
75
|
+
idx: number,
|
|
76
|
+
faker: FakerFactory,
|
|
77
|
+
) => Promise<Parameters<Builders[K]>[0]>),
|
|
75
78
|
): Promise<Awaited<ReturnType<Builders[K]>>[]>;
|
|
76
79
|
|
|
77
80
|
/**
|
package/src/KyselyFactory.ts
CHANGED
|
@@ -286,7 +286,10 @@ export class KyselyFactory<
|
|
|
286
286
|
async insertMany<K extends keyof Builders>(
|
|
287
287
|
count: number,
|
|
288
288
|
builderName: K,
|
|
289
|
-
attrs: (
|
|
289
|
+
attrs: (
|
|
290
|
+
idx: number,
|
|
291
|
+
faker: FakerFactory,
|
|
292
|
+
) => Promise<Parameters<Builders[K]>[0]>,
|
|
290
293
|
): Promise<Awaited<ReturnType<Builders[K]>>[]>;
|
|
291
294
|
async insertMany<K extends keyof Builders>(
|
|
292
295
|
count: number,
|
|
@@ -304,7 +307,8 @@ export class KyselyFactory<
|
|
|
304
307
|
const promises: Promise<any>[] = [];
|
|
305
308
|
|
|
306
309
|
for (let i = 0; i < count; i++) {
|
|
307
|
-
const newAttrs =
|
|
310
|
+
const newAttrs =
|
|
311
|
+
typeof attrs === 'function' ? await attrs(i, faker) : attrs;
|
|
308
312
|
promises.push(this.insert(builderName, newAttrs));
|
|
309
313
|
}
|
|
310
314
|
|
package/src/ObjectionFactory.ts
CHANGED
|
@@ -144,8 +144,17 @@ export class ObjectionFactory<
|
|
|
144
144
|
// Handle insertion based on autoInsert flag
|
|
145
145
|
if (autoInsert !== false) {
|
|
146
146
|
// Auto insert is enabled by default
|
|
147
|
+
// Extract only defined values for insertion
|
|
148
|
+
const insertData = Object.entries(model).reduce((acc, [key, value]) => {
|
|
149
|
+
if (value !== undefined && key !== 'id') {
|
|
150
|
+
acc[key] = value;
|
|
151
|
+
}
|
|
152
|
+
return acc;
|
|
153
|
+
}, {} as any);
|
|
154
|
+
|
|
155
|
+
// Use static query method to insert data directly
|
|
147
156
|
// @ts-ignore
|
|
148
|
-
const result = await
|
|
157
|
+
const result = await ModelClass.query(db).insert(insertData);
|
|
149
158
|
return result as Result;
|
|
150
159
|
} else {
|
|
151
160
|
// Return model for factory to handle insertion
|
|
@@ -221,7 +230,16 @@ export class ObjectionFactory<
|
|
|
221
230
|
|
|
222
231
|
// If the builder returns a model instance, insert it
|
|
223
232
|
if (result && typeof result.$query === 'function') {
|
|
224
|
-
|
|
233
|
+
// Extract data from model, excluding undefined values and id
|
|
234
|
+
const insertData = Object.entries(result).reduce((acc, [key, value]) => {
|
|
235
|
+
if (value !== undefined && key !== 'id') {
|
|
236
|
+
acc[key] = value;
|
|
237
|
+
}
|
|
238
|
+
return acc;
|
|
239
|
+
}, {} as any);
|
|
240
|
+
|
|
241
|
+
// Use the model's constructor to get the query builder
|
|
242
|
+
return await result.constructor.query(this.db).insert(insertData);
|
|
225
243
|
}
|
|
226
244
|
|
|
227
245
|
// Otherwise, assume the builder handled insertion itself
|
|
@@ -283,14 +301,23 @@ export class ObjectionFactory<
|
|
|
283
301
|
const records: any[] = [];
|
|
284
302
|
for (let i = 0; i < count; i++) {
|
|
285
303
|
const newAttrs =
|
|
286
|
-
typeof attrs === 'function' ? (attrs as any)(i, faker) : attrs;
|
|
304
|
+
typeof attrs === 'function' ? await (attrs as any)(i, faker) : attrs;
|
|
287
305
|
|
|
288
306
|
records.push(
|
|
289
307
|
this.builders[builderName](newAttrs, this, this.db, faker).then(
|
|
290
308
|
(record: any) => {
|
|
291
309
|
// If the builder returns a model instance, insert it
|
|
292
310
|
if (record && typeof record.$query === 'function') {
|
|
293
|
-
|
|
311
|
+
// Extract data from model, excluding undefined values and id
|
|
312
|
+
const insertData = Object.entries(record).reduce((acc, [key, value]) => {
|
|
313
|
+
if (value !== undefined && key !== 'id') {
|
|
314
|
+
acc[key] = value;
|
|
315
|
+
}
|
|
316
|
+
return acc;
|
|
317
|
+
}, {} as any);
|
|
318
|
+
|
|
319
|
+
// Use the model's constructor to get the query builder
|
|
320
|
+
return record.constructor.query(this.db).insert(insertData);
|
|
294
321
|
}
|
|
295
322
|
// Otherwise, assume the builder handled insertion itself
|
|
296
323
|
return record;
|