@geekmidas/testkit 0.0.5 → 0.0.6

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 (34) hide show
  1. package/dist/{VitestKyselyTransactionIsolator-BS3R-V0I.mjs → VitestKyselyTransactionIsolator-D-qpeVKO.mjs} +1 -1
  2. package/dist/{VitestKyselyTransactionIsolator-DWSTKIe3.cjs → VitestKyselyTransactionIsolator-jF6Ohyu_.cjs} +1 -1
  3. package/dist/VitestKyselyTransactionIsolator.cjs +2 -2
  4. package/dist/VitestKyselyTransactionIsolator.mjs +2 -2
  5. package/dist/{VitestTransactionIsolator-Bx2c4OzK.cjs → VitestTransactionIsolator-BK9UsrKt.cjs} +4 -3
  6. package/dist/{VitestTransactionIsolator-BjVXqFs6.mjs → VitestTransactionIsolator-e-R3p_X8.mjs} +4 -3
  7. package/dist/VitestTransactionIsolator.cjs +1 -1
  8. package/dist/VitestTransactionIsolator.mjs +1 -1
  9. package/dist/__tests__/KyselyFactory.spec.cjs +38 -37
  10. package/dist/__tests__/KyselyFactory.spec.mjs +39 -38
  11. package/dist/__tests__/ObjectionFactory.spec.cjs +1 -1
  12. package/dist/__tests__/ObjectionFactory.spec.mjs +1 -1
  13. package/dist/__tests__/PostgresMigrator.spec.cjs +1 -1
  14. package/dist/__tests__/PostgresMigrator.spec.mjs +1 -1
  15. package/dist/__tests__/integration.spec.cjs +8 -5
  16. package/dist/__tests__/integration.spec.mjs +9 -6
  17. package/dist/helpers-DN4sJO4i.mjs +13 -0
  18. package/dist/helpers-DOtYCEvZ.cjs +19 -0
  19. package/dist/helpers.cjs +2 -5
  20. package/dist/helpers.mjs +2 -4
  21. package/dist/kysely-C1-aHdnU.mjs +11 -0
  22. package/dist/kysely-DL3C2eM4.cjs +16 -0
  23. package/dist/kysely.cjs +4 -10
  24. package/dist/kysely.mjs +3 -9
  25. package/package.json +1 -1
  26. package/src/VitestTransactionIsolator.ts +4 -2
  27. package/src/__tests__/KyselyFactory.spec.ts +4 -6
  28. package/src/__tests__/integration.spec.ts +8 -3
  29. package/src/helpers.ts +1 -18
  30. package/src/kysely.ts +3 -1
  31. package/dist/helpers-B9Jdk_C7.cjs +0 -31
  32. package/dist/helpers-DOiGIkaU.mjs +0 -19
  33. /package/dist/{helpers-DKEBHABj.cjs → helpers-B2CfbaTC.cjs} +0 -0
  34. /package/dist/{helpers-BfuX-cjN.mjs → helpers-Rf5F71r9.mjs} +0 -0
@@ -1,4 +1,4 @@
1
- import { VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-BjVXqFs6.mjs";
1
+ import { VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-e-R3p_X8.mjs";
2
2
 
3
3
  //#region src/VitestKyselyTransactionIsolator.ts
4
4
  var VitestKyselyTransactionIsolator = class extends VitestPostgresTransactionIsolator {
@@ -1,4 +1,4 @@
1
- const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-Bx2c4OzK.cjs');
1
+ const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BK9UsrKt.cjs');
2
2
 
3
3
  //#region src/VitestKyselyTransactionIsolator.ts
4
4
  var VitestKyselyTransactionIsolator = class extends require_VitestTransactionIsolator.VitestPostgresTransactionIsolator {
@@ -1,4 +1,4 @@
1
- require('./VitestTransactionIsolator-Bx2c4OzK.cjs');
2
- const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-DWSTKIe3.cjs');
1
+ require('./VitestTransactionIsolator-BK9UsrKt.cjs');
2
+ const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-jF6Ohyu_.cjs');
3
3
 
4
4
  exports.VitestKyselyTransactionIsolator = require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator;
@@ -1,4 +1,4 @@
1
- import "./VitestTransactionIsolator-BjVXqFs6.mjs";
2
- import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-BS3R-V0I.mjs";
1
+ import "./VitestTransactionIsolator-e-R3p_X8.mjs";
2
+ import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-D-qpeVKO.mjs";
3
3
 
4
4
  export { VitestKyselyTransactionIsolator };
@@ -1,5 +1,3 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const vitest = require_chunk.__toESM(require("vitest"));
3
1
 
4
2
  //#region src/VitestTransactionIsolator.ts
5
3
  let IsolationLevel = /* @__PURE__ */ function(IsolationLevel$1) {
@@ -10,8 +8,11 @@ let IsolationLevel = /* @__PURE__ */ function(IsolationLevel$1) {
10
8
  return IsolationLevel$1;
11
9
  }({});
12
10
  var VitestPostgresTransactionIsolator = class {
11
+ constructor(api) {
12
+ this.api = api;
13
+ }
13
14
  wrapVitestWithTransaction(conn, setup, level = IsolationLevel.REPEATABLE_READ) {
14
- return vitest.test.extend({ trx: async ({}, use) => {
15
+ return this.api.extend({ trx: async ({}, use) => {
15
16
  class TestRollback extends Error {
16
17
  constructor() {
17
18
  super("Test rollback");
@@ -1,5 +1,3 @@
1
- import { test } from "vitest";
2
-
3
1
  //#region src/VitestTransactionIsolator.ts
4
2
  let IsolationLevel = /* @__PURE__ */ function(IsolationLevel$1) {
5
3
  IsolationLevel$1["READ_UNCOMMITTED"] = "READ UNCOMMITTED";
@@ -9,8 +7,11 @@ let IsolationLevel = /* @__PURE__ */ function(IsolationLevel$1) {
9
7
  return IsolationLevel$1;
10
8
  }({});
11
9
  var VitestPostgresTransactionIsolator = class {
10
+ constructor(api) {
11
+ this.api = api;
12
+ }
12
13
  wrapVitestWithTransaction(conn, setup, level = IsolationLevel.REPEATABLE_READ) {
13
- return test.extend({ trx: async ({}, use) => {
14
+ return this.api.extend({ trx: async ({}, use) => {
14
15
  class TestRollback extends Error {
15
16
  constructor() {
16
17
  super("Test rollback");
@@ -1,4 +1,4 @@
1
- const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-Bx2c4OzK.cjs');
1
+ const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BK9UsrKt.cjs');
2
2
 
3
3
  exports.IsolationLevel = require_VitestTransactionIsolator.IsolationLevel;
4
4
  exports.VitestPostgresTransactionIsolator = require_VitestTransactionIsolator.VitestPostgresTransactionIsolator;
@@ -1,3 +1,3 @@
1
- import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-BjVXqFs6.mjs";
1
+ import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-e-R3p_X8.mjs";
2
2
 
3
3
  export { IsolationLevel, VitestPostgresTransactionIsolator };
@@ -2,32 +2,33 @@ const require_chunk = require('../chunk-CUT6urMc.cjs');
2
2
  require('../Factory-DREHoms3.cjs');
3
3
  require('../faker-caz-8zt8.cjs');
4
4
  const require_KyselyFactory = require('../KyselyFactory-BX7Kv2uP.cjs');
5
- require('../VitestTransactionIsolator-Bx2c4OzK.cjs');
6
- require('../VitestKyselyTransactionIsolator-DWSTKIe3.cjs');
7
- const require_helpers = require('../helpers-B9Jdk_C7.cjs');
8
- const require_helpers$1 = require('../helpers-DKEBHABj.cjs');
5
+ require('../PostgresMigrator-Bz-tnjB6.cjs');
6
+ require('../PostgresKyselyMigrator-JTY2LfwD.cjs');
7
+ require('../VitestTransactionIsolator-BK9UsrKt.cjs');
8
+ require('../VitestKyselyTransactionIsolator-jF6Ohyu_.cjs');
9
+ const require_helpers = require('../helpers-DOtYCEvZ.cjs');
10
+ const require_kysely = require('../kysely-DL3C2eM4.cjs');
11
+ const require_helpers$1 = require('../helpers-B2CfbaTC.cjs');
9
12
  const pg = require_chunk.__toESM(require("pg"));
10
13
  const vitest = require_chunk.__toESM(require("vitest"));
11
14
 
12
15
  //#region src/__tests__/KyselyFactory.spec.ts
13
16
  const db = require_helpers.createKyselyDb(require_helpers$1.TEST_DATABASE_CONFIG);
14
- const itWithTransaction = require_helpers.wrapVitestKyselyTransaction(db, require_helpers$1.createTestTables);
17
+ const itWithTransaction = require_kysely.wrapVitestKyselyTransaction(vitest.it, db, require_helpers$1.createTestTables);
15
18
  const int8TypeId = 20;
16
19
  pg.default.types.setTypeParser(int8TypeId, (val) => {
17
20
  return parseInt(val, 10);
18
21
  });
19
22
  (0, vitest.describe)("KyselyFactory", () => {
20
- let db$1;
21
- let trx;
22
23
  (0, vitest.describe)("KyselyFactory.insert", () => {
23
- itWithTransaction("should insert a record with defaults", async ({ trx: trx$1 }) => {
24
+ itWithTransaction("should insert a record with defaults", async ({ trx }) => {
24
25
  const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
25
26
  name: "John Doe",
26
27
  email: `user${Date.now()}@example.com`,
27
28
  createdAt: /* @__PURE__ */ new Date()
28
29
  }));
29
30
  const builders = { user: userBuilder };
30
- const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx$1);
31
+ const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
31
32
  const user = await factory.insert("user");
32
33
  (0, vitest.expect)(user).toBeDefined();
33
34
  (0, vitest.expect)(user.id).toBeDefined();
@@ -36,14 +37,14 @@ pg.default.types.setTypeParser(int8TypeId, (val) => {
36
37
  (0, vitest.expect)(user.email).toContain("@example.com");
37
38
  (0, vitest.expect)(user.createdAt).toBeInstanceOf(Date);
38
39
  });
39
- itWithTransaction("should override defaults with provided attributes", async ({ trx: trx$1 }) => {
40
+ itWithTransaction("should override defaults with provided attributes", async ({ trx }) => {
40
41
  const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
41
42
  name: "John Doe",
42
43
  email: `user${Date.now()}@example.com`,
43
44
  createdAt: /* @__PURE__ */ new Date()
44
45
  }));
45
46
  const builders = { user: userBuilder };
46
- const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx$1);
47
+ const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
47
48
  const customEmail = "custom@test.com";
48
49
  const customName = "Jane Smith";
49
50
  const user = await factory.insert("user", {
@@ -53,7 +54,7 @@ pg.default.types.setTypeParser(int8TypeId, (val) => {
53
54
  (0, vitest.expect)(user.name).toBe(customName);
54
55
  (0, vitest.expect)(user.email).toBe(customEmail);
55
56
  });
56
- itWithTransaction("should handle relations", async ({ trx: trx$1 }) => {
57
+ itWithTransaction("should handle relations", async ({ trx }) => {
57
58
  const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
58
59
  name: "John Doe",
59
60
  email: `user${Date.now()}@example.com`,
@@ -79,27 +80,27 @@ pg.default.types.setTypeParser(int8TypeId, (val) => {
79
80
  user: userBuilder,
80
81
  post: postBuilder
81
82
  };
82
- const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx$1);
83
+ const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
83
84
  const post = await factory.insert("post", { title: "Test Post" });
84
85
  (0, vitest.expect)(post).toBeDefined();
85
86
  (0, vitest.expect)(post.title).toBe("Test Post");
86
87
  (0, vitest.expect)(post.userId).toBeDefined();
87
88
  (0, vitest.expect)(typeof post.userId).toBe("number");
88
89
  });
89
- itWithTransaction("should throw error for non-existent builder", async ({ trx: trx$1 }) => {
90
- const factory = new require_KyselyFactory.KyselyFactory({}, {}, trx$1);
90
+ itWithTransaction("should throw error for non-existent builder", async ({ trx }) => {
91
+ const factory = new require_KyselyFactory.KyselyFactory({}, {}, trx);
91
92
  await (0, vitest.expect)(factory.insert("nonExistent")).rejects.toThrow("Factory \"nonExistent\" does not exist");
92
93
  });
93
94
  });
94
95
  (0, vitest.describe)("KyselyFactory.insertMany", () => {
95
- itWithTransaction("should insert multiple records with same attributes", async ({ trx: trx$1 }) => {
96
+ itWithTransaction("should insert multiple records with same attributes", async ({ trx }) => {
96
97
  const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
97
98
  name: "John Doe",
98
99
  email: `user${Date.now()}-${Math.random()}@example.com`,
99
100
  createdAt: /* @__PURE__ */ new Date()
100
101
  }));
101
102
  const builders = { user: userBuilder };
102
- const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx$1);
103
+ const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
103
104
  const users = await factory.insertMany(3, "user");
104
105
  (0, vitest.expect)(users).toHaveLength(3);
105
106
  users.forEach((user, index) => {
@@ -108,26 +109,26 @@ pg.default.types.setTypeParser(int8TypeId, (val) => {
108
109
  (0, vitest.expect)(user.email).toContain("@example.com");
109
110
  });
110
111
  });
111
- itWithTransaction("should insert multiple records with dynamic attributes", async ({ trx: trx$1 }) => {
112
+ itWithTransaction("should insert multiple records with dynamic attributes", async ({ trx }) => {
112
113
  const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
113
114
  email: `user${Date.now()}-${Math.random()}@example.com`,
114
115
  createdAt: /* @__PURE__ */ new Date()
115
116
  }));
116
117
  const builders = { user: userBuilder };
117
- const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx$1);
118
+ const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
118
119
  const users = await factory.insertMany(3, "user", (idx) => ({ name: `User ${idx}` }));
119
120
  (0, vitest.expect)(users).toHaveLength(3);
120
121
  users.forEach((user, index) => {
121
122
  (0, vitest.expect)(user.name).toBe(`User ${index}`);
122
123
  });
123
124
  });
124
- itWithTransaction("should throw error for non-existent builder", async ({ trx: trx$1 }) => {
125
- const factory = new require_KyselyFactory.KyselyFactory({}, {}, trx$1);
125
+ itWithTransaction("should throw error for non-existent builder", async ({ trx }) => {
126
+ const factory = new require_KyselyFactory.KyselyFactory({}, {}, trx);
126
127
  await (0, vitest.expect)(factory.insertMany(2, "nonExistent")).rejects.toThrow("Builder \"nonExistent\" is not registered");
127
128
  });
128
129
  });
129
130
  (0, vitest.describe)("KyselyFactory.createBuilder", () => {
130
- itWithTransaction("should work with async defaults", async ({ trx: trx$1 }) => {
131
+ itWithTransaction("should work with async defaults", async ({ trx }) => {
131
132
  let counter = 0;
132
133
  const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => {
133
134
  await new Promise((resolve) => setTimeout(resolve, 10));
@@ -139,7 +140,7 @@ pg.default.types.setTypeParser(int8TypeId, (val) => {
139
140
  };
140
141
  });
141
142
  const builders = { user: userBuilder };
142
- const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx$1);
143
+ const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
143
144
  const user1 = await factory.insert("user");
144
145
  const user2 = await factory.insert("user");
145
146
  (0, vitest.expect)(user1.name).toBe("Async User 1");
@@ -147,36 +148,36 @@ pg.default.types.setTypeParser(int8TypeId, (val) => {
147
148
  });
148
149
  });
149
150
  (0, vitest.describe)("KyselyFactory.seed", () => {
150
- itWithTransaction("should execute seed functions", async ({ trx: trx$1 }) => {
151
+ itWithTransaction("should execute seed functions", async ({ trx }) => {
151
152
  const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
152
153
  name: "John Doe",
153
154
  email: `user${Date.now()}@example.com`,
154
155
  createdAt: /* @__PURE__ */ new Date()
155
156
  }));
156
157
  const builders = { user: userBuilder };
157
- const seeds = { createAdminUser: require_KyselyFactory.KyselyFactory.createSeed(async (attrs, factory$1, db$2) => {
158
+ const seeds = { createAdminUser: require_KyselyFactory.KyselyFactory.createSeed(async (attrs, factory$1, db$1) => {
158
159
  return await factory$1.insert("user", {
159
160
  name: attrs.name || "Admin User",
160
161
  email: "admin@example.com"
161
162
  });
162
163
  }) };
163
- const factory = new require_KyselyFactory.KyselyFactory(builders, seeds, trx$1);
164
+ const factory = new require_KyselyFactory.KyselyFactory(builders, seeds, trx);
164
165
  const adminUser = await factory.seed("createAdminUser");
165
166
  (0, vitest.expect)(adminUser).toBeDefined();
166
167
  (0, vitest.expect)(adminUser.name).toBe("Admin User");
167
168
  (0, vitest.expect)(adminUser.email).toBe("admin@example.com");
168
169
  });
169
- itWithTransaction("should pass attributes to seed functions", async ({ trx: trx$1 }) => {
170
+ itWithTransaction("should pass attributes to seed functions", async ({ trx }) => {
170
171
  const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
171
172
  name: "John Doe",
172
173
  email: `user${Date.now()}@example.com`,
173
174
  createdAt: /* @__PURE__ */ new Date()
174
175
  }));
175
176
  const builders = { user: userBuilder };
176
- const seeds = { createCustomUser: require_KyselyFactory.KyselyFactory.createSeed(async (attrs, factory$1, db$2) => {
177
+ const seeds = { createCustomUser: require_KyselyFactory.KyselyFactory.createSeed(async (attrs, factory$1, db$1) => {
177
178
  return await factory$1.insert("user", attrs);
178
179
  }) };
179
- const factory = new require_KyselyFactory.KyselyFactory(builders, seeds, trx$1);
180
+ const factory = new require_KyselyFactory.KyselyFactory(builders, seeds, trx);
180
181
  const customUser = await factory.seed("createCustomUser", {
181
182
  name: "Custom User",
182
183
  email: "custom@test.com"
@@ -184,26 +185,26 @@ pg.default.types.setTypeParser(int8TypeId, (val) => {
184
185
  (0, vitest.expect)(customUser.name).toBe("Custom User");
185
186
  (0, vitest.expect)(customUser.email).toBe("custom@test.com");
186
187
  });
187
- itWithTransaction("should throw error for non-existent seed", async ({ trx: trx$1 }) => {
188
- const factory = new require_KyselyFactory.KyselyFactory({}, {}, trx$1);
188
+ itWithTransaction("should throw error for non-existent seed", async ({ trx }) => {
189
+ const factory = new require_KyselyFactory.KyselyFactory({}, {}, trx);
189
190
  (0, vitest.expect)(() => factory.seed("nonExistent")).toThrow("Seed \"nonExistent\" is not registered");
190
191
  });
191
192
  });
192
193
  (0, vitest.describe)("Factory integration", () => {
193
- itWithTransaction("should work with controlled transactions", async ({ trx: trx$1 }) => {
194
+ itWithTransaction("should work with controlled transactions", async ({ trx }) => {
194
195
  const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
195
196
  name: "John Doe",
196
197
  email: `user${Date.now()}@example.com`,
197
198
  createdAt: /* @__PURE__ */ new Date()
198
199
  }));
199
200
  const builders = { user: userBuilder };
200
- const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx$1);
201
+ const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
201
202
  const user = await factory.insert("user");
202
- const foundUser = await trx$1.selectFrom("users").selectAll().where("id", "=", user.id).executeTakeFirst();
203
+ const foundUser = await trx.selectFrom("users").selectAll().where("id", "=", user.id).executeTakeFirst();
203
204
  (0, vitest.expect)(foundUser).toBeDefined();
204
205
  (0, vitest.expect)(foundUser?.id).toBe(user.id);
205
206
  });
206
- itWithTransaction("should work with factory passed to defaults", async ({ trx: trx$1 }) => {
207
+ itWithTransaction("should work with factory passed to defaults", async ({ trx }) => {
207
208
  const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
208
209
  name: "John Doe",
209
210
  email: `user${Date.now()}@example.com`,
@@ -222,10 +223,10 @@ pg.default.types.setTypeParser(int8TypeId, (val) => {
222
223
  user: userBuilder,
223
224
  post: postBuilder
224
225
  };
225
- const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx$1);
226
+ const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
226
227
  const post = await factory.insert("post");
227
228
  (0, vitest.expect)(post.userId).toBeDefined();
228
- const relatedUser = await trx$1.selectFrom("users").selectAll().where("id", "=", post.userId).executeTakeFirst();
229
+ const relatedUser = await trx.selectFrom("users").selectAll().where("id", "=", post.userId).executeTakeFirst();
229
230
  (0, vitest.expect)(relatedUser).toBeDefined();
230
231
  });
231
232
  });
@@ -1,32 +1,33 @@
1
1
  import "../Factory-DlzMkMzb.mjs";
2
2
  import "../faker-BwaXA_RF.mjs";
3
3
  import { KyselyFactory } from "../KyselyFactory-pOMOFQWE.mjs";
4
- import "../VitestTransactionIsolator-BjVXqFs6.mjs";
5
- import "../VitestKyselyTransactionIsolator-BS3R-V0I.mjs";
6
- import { createKyselyDb, wrapVitestKyselyTransaction } from "../helpers-DOiGIkaU.mjs";
7
- import { TEST_DATABASE_CONFIG, createTestTables } from "../helpers-BfuX-cjN.mjs";
4
+ import "../PostgresMigrator-CEoRKTdq.mjs";
5
+ import "../PostgresKyselyMigrator-D8fm35-s.mjs";
6
+ import "../VitestTransactionIsolator-e-R3p_X8.mjs";
7
+ import "../VitestKyselyTransactionIsolator-D-qpeVKO.mjs";
8
+ import { createKyselyDb } from "../helpers-DN4sJO4i.mjs";
9
+ import { wrapVitestKyselyTransaction } from "../kysely-C1-aHdnU.mjs";
10
+ import { TEST_DATABASE_CONFIG, createTestTables } from "../helpers-Rf5F71r9.mjs";
8
11
  import pg from "pg";
9
- import { describe, expect } from "vitest";
12
+ import { describe, expect, it } from "vitest";
10
13
 
11
14
  //#region src/__tests__/KyselyFactory.spec.ts
12
15
  const db = createKyselyDb(TEST_DATABASE_CONFIG);
13
- const itWithTransaction = wrapVitestKyselyTransaction(db, createTestTables);
16
+ const itWithTransaction = wrapVitestKyselyTransaction(it, db, createTestTables);
14
17
  const int8TypeId = 20;
15
18
  pg.types.setTypeParser(int8TypeId, (val) => {
16
19
  return parseInt(val, 10);
17
20
  });
18
21
  describe("KyselyFactory", () => {
19
- let db$1;
20
- let trx;
21
22
  describe("KyselyFactory.insert", () => {
22
- itWithTransaction("should insert a record with defaults", async ({ trx: trx$1 }) => {
23
+ itWithTransaction("should insert a record with defaults", async ({ trx }) => {
23
24
  const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
24
25
  name: "John Doe",
25
26
  email: `user${Date.now()}@example.com`,
26
27
  createdAt: /* @__PURE__ */ new Date()
27
28
  }));
28
29
  const builders = { user: userBuilder };
29
- const factory = new KyselyFactory(builders, {}, trx$1);
30
+ const factory = new KyselyFactory(builders, {}, trx);
30
31
  const user = await factory.insert("user");
31
32
  expect(user).toBeDefined();
32
33
  expect(user.id).toBeDefined();
@@ -35,14 +36,14 @@ describe("KyselyFactory", () => {
35
36
  expect(user.email).toContain("@example.com");
36
37
  expect(user.createdAt).toBeInstanceOf(Date);
37
38
  });
38
- itWithTransaction("should override defaults with provided attributes", async ({ trx: trx$1 }) => {
39
+ itWithTransaction("should override defaults with provided attributes", async ({ trx }) => {
39
40
  const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
40
41
  name: "John Doe",
41
42
  email: `user${Date.now()}@example.com`,
42
43
  createdAt: /* @__PURE__ */ new Date()
43
44
  }));
44
45
  const builders = { user: userBuilder };
45
- const factory = new KyselyFactory(builders, {}, trx$1);
46
+ const factory = new KyselyFactory(builders, {}, trx);
46
47
  const customEmail = "custom@test.com";
47
48
  const customName = "Jane Smith";
48
49
  const user = await factory.insert("user", {
@@ -52,7 +53,7 @@ describe("KyselyFactory", () => {
52
53
  expect(user.name).toBe(customName);
53
54
  expect(user.email).toBe(customEmail);
54
55
  });
55
- itWithTransaction("should handle relations", async ({ trx: trx$1 }) => {
56
+ itWithTransaction("should handle relations", async ({ trx }) => {
56
57
  const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
57
58
  name: "John Doe",
58
59
  email: `user${Date.now()}@example.com`,
@@ -78,27 +79,27 @@ describe("KyselyFactory", () => {
78
79
  user: userBuilder,
79
80
  post: postBuilder
80
81
  };
81
- const factory = new KyselyFactory(builders, {}, trx$1);
82
+ const factory = new KyselyFactory(builders, {}, trx);
82
83
  const post = await factory.insert("post", { title: "Test Post" });
83
84
  expect(post).toBeDefined();
84
85
  expect(post.title).toBe("Test Post");
85
86
  expect(post.userId).toBeDefined();
86
87
  expect(typeof post.userId).toBe("number");
87
88
  });
88
- itWithTransaction("should throw error for non-existent builder", async ({ trx: trx$1 }) => {
89
- const factory = new KyselyFactory({}, {}, trx$1);
89
+ itWithTransaction("should throw error for non-existent builder", async ({ trx }) => {
90
+ const factory = new KyselyFactory({}, {}, trx);
90
91
  await expect(factory.insert("nonExistent")).rejects.toThrow("Factory \"nonExistent\" does not exist");
91
92
  });
92
93
  });
93
94
  describe("KyselyFactory.insertMany", () => {
94
- itWithTransaction("should insert multiple records with same attributes", async ({ trx: trx$1 }) => {
95
+ itWithTransaction("should insert multiple records with same attributes", async ({ trx }) => {
95
96
  const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
96
97
  name: "John Doe",
97
98
  email: `user${Date.now()}-${Math.random()}@example.com`,
98
99
  createdAt: /* @__PURE__ */ new Date()
99
100
  }));
100
101
  const builders = { user: userBuilder };
101
- const factory = new KyselyFactory(builders, {}, trx$1);
102
+ const factory = new KyselyFactory(builders, {}, trx);
102
103
  const users = await factory.insertMany(3, "user");
103
104
  expect(users).toHaveLength(3);
104
105
  users.forEach((user, index) => {
@@ -107,26 +108,26 @@ describe("KyselyFactory", () => {
107
108
  expect(user.email).toContain("@example.com");
108
109
  });
109
110
  });
110
- itWithTransaction("should insert multiple records with dynamic attributes", async ({ trx: trx$1 }) => {
111
+ itWithTransaction("should insert multiple records with dynamic attributes", async ({ trx }) => {
111
112
  const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
112
113
  email: `user${Date.now()}-${Math.random()}@example.com`,
113
114
  createdAt: /* @__PURE__ */ new Date()
114
115
  }));
115
116
  const builders = { user: userBuilder };
116
- const factory = new KyselyFactory(builders, {}, trx$1);
117
+ const factory = new KyselyFactory(builders, {}, trx);
117
118
  const users = await factory.insertMany(3, "user", (idx) => ({ name: `User ${idx}` }));
118
119
  expect(users).toHaveLength(3);
119
120
  users.forEach((user, index) => {
120
121
  expect(user.name).toBe(`User ${index}`);
121
122
  });
122
123
  });
123
- itWithTransaction("should throw error for non-existent builder", async ({ trx: trx$1 }) => {
124
- const factory = new KyselyFactory({}, {}, trx$1);
124
+ itWithTransaction("should throw error for non-existent builder", async ({ trx }) => {
125
+ const factory = new KyselyFactory({}, {}, trx);
125
126
  await expect(factory.insertMany(2, "nonExistent")).rejects.toThrow("Builder \"nonExistent\" is not registered");
126
127
  });
127
128
  });
128
129
  describe("KyselyFactory.createBuilder", () => {
129
- itWithTransaction("should work with async defaults", async ({ trx: trx$1 }) => {
130
+ itWithTransaction("should work with async defaults", async ({ trx }) => {
130
131
  let counter = 0;
131
132
  const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => {
132
133
  await new Promise((resolve) => setTimeout(resolve, 10));
@@ -138,7 +139,7 @@ describe("KyselyFactory", () => {
138
139
  };
139
140
  });
140
141
  const builders = { user: userBuilder };
141
- const factory = new KyselyFactory(builders, {}, trx$1);
142
+ const factory = new KyselyFactory(builders, {}, trx);
142
143
  const user1 = await factory.insert("user");
143
144
  const user2 = await factory.insert("user");
144
145
  expect(user1.name).toBe("Async User 1");
@@ -146,36 +147,36 @@ describe("KyselyFactory", () => {
146
147
  });
147
148
  });
148
149
  describe("KyselyFactory.seed", () => {
149
- itWithTransaction("should execute seed functions", async ({ trx: trx$1 }) => {
150
+ itWithTransaction("should execute seed functions", async ({ trx }) => {
150
151
  const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
151
152
  name: "John Doe",
152
153
  email: `user${Date.now()}@example.com`,
153
154
  createdAt: /* @__PURE__ */ new Date()
154
155
  }));
155
156
  const builders = { user: userBuilder };
156
- const seeds = { createAdminUser: KyselyFactory.createSeed(async (attrs, factory$1, db$2) => {
157
+ const seeds = { createAdminUser: KyselyFactory.createSeed(async (attrs, factory$1, db$1) => {
157
158
  return await factory$1.insert("user", {
158
159
  name: attrs.name || "Admin User",
159
160
  email: "admin@example.com"
160
161
  });
161
162
  }) };
162
- const factory = new KyselyFactory(builders, seeds, trx$1);
163
+ const factory = new KyselyFactory(builders, seeds, trx);
163
164
  const adminUser = await factory.seed("createAdminUser");
164
165
  expect(adminUser).toBeDefined();
165
166
  expect(adminUser.name).toBe("Admin User");
166
167
  expect(adminUser.email).toBe("admin@example.com");
167
168
  });
168
- itWithTransaction("should pass attributes to seed functions", async ({ trx: trx$1 }) => {
169
+ itWithTransaction("should pass attributes to seed functions", async ({ trx }) => {
169
170
  const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
170
171
  name: "John Doe",
171
172
  email: `user${Date.now()}@example.com`,
172
173
  createdAt: /* @__PURE__ */ new Date()
173
174
  }));
174
175
  const builders = { user: userBuilder };
175
- const seeds = { createCustomUser: KyselyFactory.createSeed(async (attrs, factory$1, db$2) => {
176
+ const seeds = { createCustomUser: KyselyFactory.createSeed(async (attrs, factory$1, db$1) => {
176
177
  return await factory$1.insert("user", attrs);
177
178
  }) };
178
- const factory = new KyselyFactory(builders, seeds, trx$1);
179
+ const factory = new KyselyFactory(builders, seeds, trx);
179
180
  const customUser = await factory.seed("createCustomUser", {
180
181
  name: "Custom User",
181
182
  email: "custom@test.com"
@@ -183,26 +184,26 @@ describe("KyselyFactory", () => {
183
184
  expect(customUser.name).toBe("Custom User");
184
185
  expect(customUser.email).toBe("custom@test.com");
185
186
  });
186
- itWithTransaction("should throw error for non-existent seed", async ({ trx: trx$1 }) => {
187
- const factory = new KyselyFactory({}, {}, trx$1);
187
+ itWithTransaction("should throw error for non-existent seed", async ({ trx }) => {
188
+ const factory = new KyselyFactory({}, {}, trx);
188
189
  expect(() => factory.seed("nonExistent")).toThrow("Seed \"nonExistent\" is not registered");
189
190
  });
190
191
  });
191
192
  describe("Factory integration", () => {
192
- itWithTransaction("should work with controlled transactions", async ({ trx: trx$1 }) => {
193
+ itWithTransaction("should work with controlled transactions", async ({ trx }) => {
193
194
  const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
194
195
  name: "John Doe",
195
196
  email: `user${Date.now()}@example.com`,
196
197
  createdAt: /* @__PURE__ */ new Date()
197
198
  }));
198
199
  const builders = { user: userBuilder };
199
- const factory = new KyselyFactory(builders, {}, trx$1);
200
+ const factory = new KyselyFactory(builders, {}, trx);
200
201
  const user = await factory.insert("user");
201
- const foundUser = await trx$1.selectFrom("users").selectAll().where("id", "=", user.id).executeTakeFirst();
202
+ const foundUser = await trx.selectFrom("users").selectAll().where("id", "=", user.id).executeTakeFirst();
202
203
  expect(foundUser).toBeDefined();
203
204
  expect(foundUser?.id).toBe(user.id);
204
205
  });
205
- itWithTransaction("should work with factory passed to defaults", async ({ trx: trx$1 }) => {
206
+ itWithTransaction("should work with factory passed to defaults", async ({ trx }) => {
206
207
  const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
207
208
  name: "John Doe",
208
209
  email: `user${Date.now()}@example.com`,
@@ -221,10 +222,10 @@ describe("KyselyFactory", () => {
221
222
  user: userBuilder,
222
223
  post: postBuilder
223
224
  };
224
- const factory = new KyselyFactory(builders, {}, trx$1);
225
+ const factory = new KyselyFactory(builders, {}, trx);
225
226
  const post = await factory.insert("post");
226
227
  expect(post.userId).toBeDefined();
227
- const relatedUser = await trx$1.selectFrom("users").selectAll().where("id", "=", post.userId).executeTakeFirst();
228
+ const relatedUser = await trx.selectFrom("users").selectAll().where("id", "=", post.userId).executeTakeFirst();
228
229
  expect(relatedUser).toBeDefined();
229
230
  });
230
231
  });
@@ -1,7 +1,7 @@
1
1
  const require_chunk = require('../chunk-CUT6urMc.cjs');
2
2
  require('../Factory-DREHoms3.cjs');
3
3
  const require_ObjectionFactory = require('../ObjectionFactory-BlkzSEqo.cjs');
4
- const require_helpers = require('../helpers-DKEBHABj.cjs');
4
+ const require_helpers = require('../helpers-B2CfbaTC.cjs');
5
5
  const vitest = require_chunk.__toESM(require("vitest"));
6
6
  const objection = require_chunk.__toESM(require("objection"));
7
7
 
@@ -1,6 +1,6 @@
1
1
  import "../Factory-DlzMkMzb.mjs";
2
2
  import { ObjectionFactory } from "../ObjectionFactory-ChuX8sZN.mjs";
3
- import { setupKnexTest } from "../helpers-BfuX-cjN.mjs";
3
+ import { setupKnexTest } from "../helpers-Rf5F71r9.mjs";
4
4
  import { afterAll, beforeAll, describe, expect, it } from "vitest";
5
5
  import { Model } from "objection";
6
6
 
@@ -1,6 +1,6 @@
1
1
  const require_chunk = require('../chunk-CUT6urMc.cjs');
2
2
  const require_PostgresMigrator = require('../PostgresMigrator-Bz-tnjB6.cjs');
3
- const require_helpers = require('../helpers-DKEBHABj.cjs');
3
+ const require_helpers = require('../helpers-B2CfbaTC.cjs');
4
4
  const pg = require_chunk.__toESM(require("pg"));
5
5
  const vitest = require_chunk.__toESM(require("vitest"));
6
6
 
@@ -1,5 +1,5 @@
1
1
  import { PostgresMigrator } from "../PostgresMigrator-CEoRKTdq.mjs";
2
- import { createTestDatabase } from "../helpers-BfuX-cjN.mjs";
2
+ import { createTestDatabase } from "../helpers-Rf5F71r9.mjs";
3
3
  import { Client } from "pg";
4
4
  import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
5
5
 
@@ -2,15 +2,18 @@ const require_chunk = require('../chunk-CUT6urMc.cjs');
2
2
  require('../Factory-DREHoms3.cjs');
3
3
  require('../faker-caz-8zt8.cjs');
4
4
  const require_KyselyFactory = require('../KyselyFactory-BX7Kv2uP.cjs');
5
- require('../VitestTransactionIsolator-Bx2c4OzK.cjs');
6
- require('../VitestKyselyTransactionIsolator-DWSTKIe3.cjs');
7
- const require_helpers = require('../helpers-B9Jdk_C7.cjs');
8
- const require_helpers$1 = require('../helpers-DKEBHABj.cjs');
5
+ require('../PostgresMigrator-Bz-tnjB6.cjs');
6
+ require('../PostgresKyselyMigrator-JTY2LfwD.cjs');
7
+ require('../VitestTransactionIsolator-BK9UsrKt.cjs');
8
+ require('../VitestKyselyTransactionIsolator-jF6Ohyu_.cjs');
9
+ const require_helpers = require('../helpers-DOtYCEvZ.cjs');
10
+ const require_kysely = require('../kysely-DL3C2eM4.cjs');
11
+ const require_helpers$1 = require('../helpers-B2CfbaTC.cjs');
9
12
  const vitest = require_chunk.__toESM(require("vitest"));
10
13
 
11
14
  //#region src/__tests__/integration.spec.ts
12
15
  const db = require_helpers.createKyselyDb(require_helpers$1.TEST_DATABASE_CONFIG);
13
- const it = require_helpers.wrapVitestKyselyTransaction(db, require_helpers$1.createTestTables);
16
+ const it = require_kysely.wrapVitestKyselyTransaction(vitest.it, db, require_helpers$1.createTestTables);
14
17
  (0, vitest.describe)("Testkit Integration Tests", () => {
15
18
  (0, vitest.beforeAll)(async () => {});
16
19
  (0, vitest.describe)("Complex Factory Scenarios", () => {
@@ -1,15 +1,18 @@
1
1
  import "../Factory-DlzMkMzb.mjs";
2
2
  import "../faker-BwaXA_RF.mjs";
3
3
  import { KyselyFactory } from "../KyselyFactory-pOMOFQWE.mjs";
4
- import "../VitestTransactionIsolator-BjVXqFs6.mjs";
5
- import "../VitestKyselyTransactionIsolator-BS3R-V0I.mjs";
6
- import { createKyselyDb, wrapVitestKyselyTransaction } from "../helpers-DOiGIkaU.mjs";
7
- import { TEST_DATABASE_CONFIG, createTestTables } from "../helpers-BfuX-cjN.mjs";
8
- import { beforeAll, describe, expect } from "vitest";
4
+ import "../PostgresMigrator-CEoRKTdq.mjs";
5
+ import "../PostgresKyselyMigrator-D8fm35-s.mjs";
6
+ import "../VitestTransactionIsolator-e-R3p_X8.mjs";
7
+ import "../VitestKyselyTransactionIsolator-D-qpeVKO.mjs";
8
+ import { createKyselyDb } from "../helpers-DN4sJO4i.mjs";
9
+ import { wrapVitestKyselyTransaction } from "../kysely-C1-aHdnU.mjs";
10
+ import { TEST_DATABASE_CONFIG, createTestTables } from "../helpers-Rf5F71r9.mjs";
11
+ import { beforeAll, describe, expect, it } from "vitest";
9
12
 
10
13
  //#region src/__tests__/integration.spec.ts
11
14
  const db = createKyselyDb(TEST_DATABASE_CONFIG);
12
- const it$1 = wrapVitestKyselyTransaction(db, createTestTables);
15
+ const it$1 = wrapVitestKyselyTransaction(it, db, createTestTables);
13
16
  describe("Testkit Integration Tests", () => {
14
17
  beforeAll(async () => {});
15
18
  describe("Complex Factory Scenarios", () => {
@@ -0,0 +1,13 @@
1
+ import { CamelCasePlugin, Kysely, PostgresDialect } from "kysely";
2
+ import pg from "pg";
3
+
4
+ //#region src/helpers.ts
5
+ function createKyselyDb(config) {
6
+ return new Kysely({
7
+ dialect: new PostgresDialect({ pool: new pg.Pool(config) }),
8
+ plugins: [new CamelCasePlugin()]
9
+ });
10
+ }
11
+
12
+ //#endregion
13
+ export { createKyselyDb };
@@ -0,0 +1,19 @@
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const kysely = require_chunk.__toESM(require("kysely"));
3
+ const pg = require_chunk.__toESM(require("pg"));
4
+
5
+ //#region src/helpers.ts
6
+ function createKyselyDb(config) {
7
+ return new kysely.Kysely({
8
+ dialect: new kysely.PostgresDialect({ pool: new pg.default.Pool(config) }),
9
+ plugins: [new kysely.CamelCasePlugin()]
10
+ });
11
+ }
12
+
13
+ //#endregion
14
+ Object.defineProperty(exports, 'createKyselyDb', {
15
+ enumerable: true,
16
+ get: function () {
17
+ return createKyselyDb;
18
+ }
19
+ });
package/dist/helpers.cjs CHANGED
@@ -1,6 +1,3 @@
1
- require('./VitestTransactionIsolator-Bx2c4OzK.cjs');
2
- require('./VitestKyselyTransactionIsolator-DWSTKIe3.cjs');
3
- const require_helpers = require('./helpers-B9Jdk_C7.cjs');
1
+ const require_helpers = require('./helpers-DOtYCEvZ.cjs');
4
2
 
5
- exports.createKyselyDb = require_helpers.createKyselyDb;
6
- exports.wrapVitestKyselyTransaction = require_helpers.wrapVitestKyselyTransaction;
3
+ exports.createKyselyDb = require_helpers.createKyselyDb;
package/dist/helpers.mjs CHANGED
@@ -1,5 +1,3 @@
1
- import "./VitestTransactionIsolator-BjVXqFs6.mjs";
2
- import "./VitestKyselyTransactionIsolator-BS3R-V0I.mjs";
3
- import { createKyselyDb, wrapVitestKyselyTransaction } from "./helpers-DOiGIkaU.mjs";
1
+ import { createKyselyDb } from "./helpers-DN4sJO4i.mjs";
4
2
 
5
- export { createKyselyDb, wrapVitestKyselyTransaction };
3
+ export { createKyselyDb };
@@ -0,0 +1,11 @@
1
+ import { IsolationLevel } from "./VitestTransactionIsolator-e-R3p_X8.mjs";
2
+ import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-D-qpeVKO.mjs";
3
+
4
+ //#region src/kysely.ts
5
+ function wrapVitestKyselyTransaction(api, db, setup, level = IsolationLevel.REPEATABLE_READ) {
6
+ const wrapper = new VitestKyselyTransactionIsolator(api);
7
+ return wrapper.wrapVitestWithTransaction(db, setup, level);
8
+ }
9
+
10
+ //#endregion
11
+ export { wrapVitestKyselyTransaction };
@@ -0,0 +1,16 @@
1
+ const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BK9UsrKt.cjs');
2
+ const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-jF6Ohyu_.cjs');
3
+
4
+ //#region src/kysely.ts
5
+ function wrapVitestKyselyTransaction(api, db, setup, level = require_VitestTransactionIsolator.IsolationLevel.REPEATABLE_READ) {
6
+ const wrapper = new require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator(api);
7
+ return wrapper.wrapVitestWithTransaction(db, setup, level);
8
+ }
9
+
10
+ //#endregion
11
+ Object.defineProperty(exports, 'wrapVitestKyselyTransaction', {
12
+ enumerable: true,
13
+ get: function () {
14
+ return wrapVitestKyselyTransaction;
15
+ }
16
+ });
package/dist/kysely.cjs CHANGED
@@ -3,16 +3,10 @@ require('./faker-caz-8zt8.cjs');
3
3
  const require_KyselyFactory = require('./KyselyFactory-BX7Kv2uP.cjs');
4
4
  require('./PostgresMigrator-Bz-tnjB6.cjs');
5
5
  const require_PostgresKyselyMigrator = require('./PostgresKyselyMigrator-JTY2LfwD.cjs');
6
- const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-Bx2c4OzK.cjs');
7
- const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-DWSTKIe3.cjs');
6
+ require('./VitestTransactionIsolator-BK9UsrKt.cjs');
7
+ require('./VitestKyselyTransactionIsolator-jF6Ohyu_.cjs');
8
+ const require_kysely = require('./kysely-DL3C2eM4.cjs');
8
9
 
9
- //#region src/kysely.ts
10
- function wrapVitestKyselyTransaction(db, setup, level = require_VitestTransactionIsolator.IsolationLevel.REPEATABLE_READ) {
11
- const wrapper = new require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator();
12
- return wrapper.wrapVitestWithTransaction(db, setup, level);
13
- }
14
-
15
- //#endregion
16
10
  exports.KyselyFactory = require_KyselyFactory.KyselyFactory;
17
11
  exports.PostgresKyselyMigrator = require_PostgresKyselyMigrator.PostgresKyselyMigrator;
18
- exports.wrapVitestKyselyTransaction = wrapVitestKyselyTransaction;
12
+ exports.wrapVitestKyselyTransaction = require_kysely.wrapVitestKyselyTransaction;
package/dist/kysely.mjs CHANGED
@@ -3,14 +3,8 @@ import "./faker-BwaXA_RF.mjs";
3
3
  import { KyselyFactory } from "./KyselyFactory-pOMOFQWE.mjs";
4
4
  import "./PostgresMigrator-CEoRKTdq.mjs";
5
5
  import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-D8fm35-s.mjs";
6
- import { IsolationLevel } from "./VitestTransactionIsolator-BjVXqFs6.mjs";
7
- import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-BS3R-V0I.mjs";
6
+ import "./VitestTransactionIsolator-e-R3p_X8.mjs";
7
+ import "./VitestKyselyTransactionIsolator-D-qpeVKO.mjs";
8
+ import { wrapVitestKyselyTransaction } from "./kysely-C1-aHdnU.mjs";
8
9
 
9
- //#region src/kysely.ts
10
- function wrapVitestKyselyTransaction(db, setup, level = IsolationLevel.REPEATABLE_READ) {
11
- const wrapper = new VitestKyselyTransactionIsolator();
12
- return wrapper.wrapVitestWithTransaction(db, setup, level);
13
- }
14
-
15
- //#endregion
16
10
  export { KyselyFactory, PostgresKyselyMigrator, wrapVitestKyselyTransaction };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/testkit",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,4 +1,4 @@
1
- import { test as base } from 'vitest';
1
+ import type { TestAPI } from 'vitest';
2
2
 
3
3
  export interface DatabaseFixtures<Transaction> {
4
4
  trx: Transaction;
@@ -21,12 +21,14 @@ export abstract class VitestPostgresTransactionIsolator<
21
21
  fn: (trx: Transaction) => Promise<void>,
22
22
  ): Promise<void>;
23
23
 
24
+ constructor(private readonly api: TestAPI) {}
25
+
24
26
  wrapVitestWithTransaction(
25
27
  conn: Connection,
26
28
  setup?: (trx: Transaction) => Promise<void>,
27
29
  level: IsolationLevel = IsolationLevel.REPEATABLE_READ,
28
30
  ) {
29
- return base.extend<DatabaseFixtures<Transaction>>({
31
+ return this.api.extend<DatabaseFixtures<Transaction>>({
30
32
  // This fixture automatically provides a transaction to each test
31
33
  trx: async ({}, use) => {
32
34
  // Create a custom error class for rollback
@@ -1,13 +1,14 @@
1
- import type { ControlledTransaction, Kysely } from 'kysely';
2
1
  import pg from 'pg';
3
- import { describe, expect } from 'vitest';
2
+ import { describe, expect, it } from 'vitest';
4
3
  import { TEST_DATABASE_CONFIG } from '../../test/globalSetup';
5
4
  import { type TestDatabase, createTestTables } from '../../test/helpers';
6
5
  import { KyselyFactory } from '../KyselyFactory';
7
- import { createKyselyDb, wrapVitestKyselyTransaction } from '../helpers';
6
+ import { createKyselyDb } from '../helpers';
7
+ import { wrapVitestKyselyTransaction } from '../kysely';
8
8
 
9
9
  const db = createKyselyDb<TestDatabase>(TEST_DATABASE_CONFIG);
10
10
  const itWithTransaction = wrapVitestKyselyTransaction<TestDatabase>(
11
+ it,
11
12
  db,
12
13
  createTestTables,
13
14
  );
@@ -17,9 +18,6 @@ pg.types.setTypeParser(int8TypeId, (val) => {
17
18
  return parseInt(val, 10);
18
19
  });
19
20
  describe('KyselyFactory', () => {
20
- let db: Kysely<TestDatabase>;
21
- let trx: ControlledTransaction<TestDatabase, []>;
22
-
23
21
  describe('KyselyFactory.insert', () => {
24
22
  itWithTransaction(
25
23
  'should insert a record with defaults',
@@ -1,11 +1,16 @@
1
- import { beforeAll, describe, expect } from 'vitest';
1
+ import { it as base, beforeAll, describe, expect } from 'vitest';
2
2
  import { TEST_DATABASE_CONFIG } from '../../test/globalSetup';
3
3
  import { type TestDatabase, createTestTables } from '../../test/helpers';
4
4
  import { KyselyFactory } from '../KyselyFactory';
5
- import { createKyselyDb, wrapVitestKyselyTransaction } from '../helpers';
5
+ import { createKyselyDb } from '../helpers';
6
+ import { wrapVitestKyselyTransaction } from '../kysely';
6
7
 
7
8
  const db = createKyselyDb<TestDatabase>(TEST_DATABASE_CONFIG);
8
- const it = wrapVitestKyselyTransaction<TestDatabase>(db, createTestTables);
9
+ const it = wrapVitestKyselyTransaction<TestDatabase>(
10
+ base,
11
+ db,
12
+ createTestTables,
13
+ );
9
14
  describe('Testkit Integration Tests', () => {
10
15
  beforeAll(async () => {});
11
16
  describe('Complex Factory Scenarios', () => {
package/src/helpers.ts CHANGED
@@ -1,22 +1,5 @@
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
 
21
4
  export function createKyselyDb<Database>(config: any): Kysely<Database> {
22
5
  return new Kysely({
package/src/kysely.ts CHANGED
@@ -1,4 +1,5 @@
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,11 +7,12 @@ export { KyselyFactory } from './KyselyFactory';
6
7
  export { PostgresKyselyMigrator } from './PostgresKyselyMigrator';
7
8
 
8
9
  export function wrapVitestKyselyTransaction<Database>(
10
+ api: TestAPI,
9
11
  db: Kysely<Database>,
10
12
  setup?: (trx: Transaction<Database>) => Promise<void>,
11
13
  level: IsolationLevel = IsolationLevel.REPEATABLE_READ,
12
14
  ) {
13
- const wrapper = new VitestKyselyTransactionIsolator<Database>();
15
+ const wrapper = new VitestKyselyTransactionIsolator<Database>(api);
14
16
 
15
17
  return wrapper.wrapVitestWithTransaction(db, setup, level);
16
18
  }
@@ -1,31 +0,0 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-Bx2c4OzK.cjs');
3
- const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-DWSTKIe3.cjs');
4
- const kysely = require_chunk.__toESM(require("kysely"));
5
- const pg = require_chunk.__toESM(require("pg"));
6
-
7
- //#region src/helpers.ts
8
- function wrapVitestKyselyTransaction(db, setup, level = require_VitestTransactionIsolator.IsolationLevel.REPEATABLE_READ) {
9
- const wrapper = new require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator();
10
- return wrapper.wrapVitestWithTransaction(db, setup, level);
11
- }
12
- function createKyselyDb(config) {
13
- return new kysely.Kysely({
14
- dialect: new kysely.PostgresDialect({ pool: new pg.default.Pool(config) }),
15
- plugins: [new kysely.CamelCasePlugin()]
16
- });
17
- }
18
-
19
- //#endregion
20
- Object.defineProperty(exports, 'createKyselyDb', {
21
- enumerable: true,
22
- get: function () {
23
- return createKyselyDb;
24
- }
25
- });
26
- Object.defineProperty(exports, 'wrapVitestKyselyTransaction', {
27
- enumerable: true,
28
- get: function () {
29
- return wrapVitestKyselyTransaction;
30
- }
31
- });
@@ -1,19 +0,0 @@
1
- import { IsolationLevel } from "./VitestTransactionIsolator-BjVXqFs6.mjs";
2
- import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-BS3R-V0I.mjs";
3
- import { CamelCasePlugin, Kysely, PostgresDialect } from "kysely";
4
- import pg from "pg";
5
-
6
- //#region src/helpers.ts
7
- function wrapVitestKyselyTransaction(db, setup, level = IsolationLevel.REPEATABLE_READ) {
8
- const wrapper = new VitestKyselyTransactionIsolator();
9
- return wrapper.wrapVitestWithTransaction(db, setup, level);
10
- }
11
- function createKyselyDb(config) {
12
- return new Kysely({
13
- dialect: new PostgresDialect({ pool: new pg.Pool(config) }),
14
- plugins: [new CamelCasePlugin()]
15
- });
16
- }
17
-
18
- //#endregion
19
- export { createKyselyDb, wrapVitestKyselyTransaction };