@geekmidas/testkit 0.4.0 → 0.6.0

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 (209) hide show
  1. package/dist/Factory-BFVnMMCC.mjs.map +1 -1
  2. package/dist/Factory-BhjUOBWN.cjs.map +1 -1
  3. package/dist/{Factory-c16c27Y6.d.cts → Factory-Bx0AJXZB.d.cts} +3 -2
  4. package/dist/Factory-Bx0AJXZB.d.cts.map +1 -0
  5. package/dist/{Factory-BcGJjLc8.d.mts → Factory-SFupxRC2.d.mts} +2 -1
  6. package/dist/Factory-SFupxRC2.d.mts.map +1 -0
  7. package/dist/Factory.d.cts +2 -2
  8. package/dist/Factory.d.mts +1 -1
  9. package/dist/KyselyFactory-BFqVIn_0.cjs.map +1 -1
  10. package/dist/KyselyFactory-DMswpwji.mjs.map +1 -1
  11. package/dist/{KyselyFactory-uZ45h7YU.d.cts → KyselyFactory-KLeKH43i.d.cts} +4 -3
  12. package/dist/KyselyFactory-KLeKH43i.d.cts.map +1 -0
  13. package/dist/{KyselyFactory-Cj-EultY.d.mts → KyselyFactory-vAxYodck.d.mts} +3 -2
  14. package/dist/KyselyFactory-vAxYodck.d.mts.map +1 -0
  15. package/dist/KyselyFactory.d.cts +3 -3
  16. package/dist/KyselyFactory.d.mts +2 -2
  17. package/dist/{ObjectionFactory-DL4qkuF1.d.mts → ObjectionFactory-BWjB49-i.d.mts} +3 -2
  18. package/dist/ObjectionFactory-BWjB49-i.d.mts.map +1 -0
  19. package/dist/ObjectionFactory-BeFBYcan.cjs.map +1 -1
  20. package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +1 -1
  21. package/dist/{ObjectionFactory-CdhzKs4f.d.cts → ObjectionFactory-aMGvAKt9.d.cts} +4 -3
  22. package/dist/ObjectionFactory-aMGvAKt9.d.cts.map +1 -0
  23. package/dist/ObjectionFactory.d.cts +3 -3
  24. package/dist/ObjectionFactory.d.mts +2 -2
  25. package/dist/{PostgresKyselyMigrator-upT-hmrz.mjs → PostgresKyselyMigrator-6sE1KOni.mjs} +2 -2
  26. package/dist/PostgresKyselyMigrator-6sE1KOni.mjs.map +1 -0
  27. package/dist/{PostgresKyselyMigrator-CIx3AFSR.d.mts → PostgresKyselyMigrator-CBltSOq5.d.cts} +3 -2
  28. package/dist/PostgresKyselyMigrator-CBltSOq5.d.cts.map +1 -0
  29. package/dist/{PostgresKyselyMigrator-CfytARcA.cjs → PostgresKyselyMigrator-D6IbPq8t.cjs} +2 -2
  30. package/dist/PostgresKyselyMigrator-D6IbPq8t.cjs.map +1 -0
  31. package/dist/{PostgresKyselyMigrator-CQ3aUoy_.d.cts → PostgresKyselyMigrator-DrVWncqd.d.mts} +3 -2
  32. package/dist/PostgresKyselyMigrator-DrVWncqd.d.mts.map +1 -0
  33. package/dist/PostgresKyselyMigrator.cjs +2 -2
  34. package/dist/PostgresKyselyMigrator.d.cts +2 -2
  35. package/dist/PostgresKyselyMigrator.d.mts +2 -2
  36. package/dist/PostgresKyselyMigrator.mjs +2 -2
  37. package/dist/{PostgresMigrator-DbuJGAVy.mjs → PostgresMigrator-BjjenqSd.mjs} +2 -2
  38. package/dist/PostgresMigrator-BjjenqSd.mjs.map +1 -0
  39. package/dist/{PostgresMigrator-D5UkK1_K.d.cts → PostgresMigrator-Bres0U6E.d.cts} +2 -1
  40. package/dist/PostgresMigrator-Bres0U6E.d.cts.map +1 -0
  41. package/dist/{PostgresMigrator-DFcNdCvD.cjs → PostgresMigrator-D6dQn0x2.cjs} +2 -2
  42. package/dist/PostgresMigrator-D6dQn0x2.cjs.map +1 -0
  43. package/dist/{PostgresMigrator-DQaRxoaY.d.mts → PostgresMigrator-S-YYosAC.d.mts} +2 -1
  44. package/dist/PostgresMigrator-S-YYosAC.d.mts.map +1 -0
  45. package/dist/PostgresMigrator.cjs +1 -1
  46. package/dist/PostgresMigrator.d.cts +1 -1
  47. package/dist/PostgresMigrator.d.mts +1 -1
  48. package/dist/PostgresMigrator.mjs +1 -1
  49. package/dist/{PostgresObjectionMigrator-CZHHcCOv.d.cts → PostgresObjectionMigrator-CPfBAP7r.d.cts} +3 -2
  50. package/dist/PostgresObjectionMigrator-CPfBAP7r.d.cts.map +1 -0
  51. package/dist/{PostgresObjectionMigrator-BG6ymgnt.cjs → PostgresObjectionMigrator-DK8ODIHQ.cjs} +2 -2
  52. package/dist/PostgresObjectionMigrator-DK8ODIHQ.cjs.map +1 -0
  53. package/dist/{PostgresObjectionMigrator-D_hCcrQu.d.mts → PostgresObjectionMigrator-DVEqB5tp.d.mts} +3 -2
  54. package/dist/PostgresObjectionMigrator-DVEqB5tp.d.mts.map +1 -0
  55. package/dist/{PostgresObjectionMigrator-DPj2pOpX.mjs → PostgresObjectionMigrator-D_QxXbIN.mjs} +2 -2
  56. package/dist/PostgresObjectionMigrator-D_QxXbIN.mjs.map +1 -0
  57. package/dist/PostgresObjectionMigrator.cjs +2 -2
  58. package/dist/PostgresObjectionMigrator.d.cts +2 -2
  59. package/dist/PostgresObjectionMigrator.d.mts +2 -2
  60. package/dist/PostgresObjectionMigrator.mjs +2 -2
  61. package/dist/{VitestKyselyTransactionIsolator-D3EZZhjZ.d.cts → VitestKyselyTransactionIsolator-CduJlHoT.d.cts} +4 -3
  62. package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts.map +1 -0
  63. package/dist/{VitestKyselyTransactionIsolator-Dxlp1u0f.d.mts → VitestKyselyTransactionIsolator-Cswnnj0k.d.mts} +4 -3
  64. package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts.map +1 -0
  65. package/dist/{VitestKyselyTransactionIsolator-EvDLk5zg.cjs → VitestKyselyTransactionIsolator-D7RRXOBa.cjs} +2 -2
  66. package/dist/VitestKyselyTransactionIsolator-D7RRXOBa.cjs.map +1 -0
  67. package/dist/{VitestKyselyTransactionIsolator-CNURW8y6.mjs → VitestKyselyTransactionIsolator-DceyIqr4.mjs} +2 -2
  68. package/dist/VitestKyselyTransactionIsolator-DceyIqr4.mjs.map +1 -0
  69. package/dist/VitestKyselyTransactionIsolator.cjs +1 -1
  70. package/dist/VitestKyselyTransactionIsolator.d.cts +2 -2
  71. package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
  72. package/dist/VitestKyselyTransactionIsolator.mjs +1 -1
  73. package/dist/{VitestObjectionTransactionIsolator-1TpsPqfG.d.cts → VitestObjectionTransactionIsolator-BXoR6xdG.d.cts} +4 -3
  74. package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts.map +1 -0
  75. package/dist/{VitestObjectionTransactionIsolator-CM5KTAFA.cjs → VitestObjectionTransactionIsolator-CdLRrzNf.cjs} +2 -2
  76. package/dist/VitestObjectionTransactionIsolator-CdLRrzNf.cjs.map +1 -0
  77. package/dist/{VitestObjectionTransactionIsolator-jQFaCz0u.mjs → VitestObjectionTransactionIsolator-OF2osYY5.mjs} +2 -2
  78. package/dist/VitestObjectionTransactionIsolator-OF2osYY5.mjs.map +1 -0
  79. package/dist/{VitestObjectionTransactionIsolator-i9jIgU8Q.d.mts → VitestObjectionTransactionIsolator-x6hY5j4u.d.mts} +4 -3
  80. package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts.map +1 -0
  81. package/dist/VitestObjectionTransactionIsolator.cjs +1 -1
  82. package/dist/VitestObjectionTransactionIsolator.d.cts +2 -2
  83. package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
  84. package/dist/VitestObjectionTransactionIsolator.mjs +1 -1
  85. package/dist/{VitestTransactionIsolator-BvR19bYn.d.mts → VitestTransactionIsolator-BNWJqh9f.d.mts} +3 -2
  86. package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts.map +1 -0
  87. package/dist/VitestTransactionIsolator-CMfJXZP8.cjs.map +1 -1
  88. package/dist/{VitestTransactionIsolator-CwQaxZLP.d.cts → VitestTransactionIsolator-CSroc7Df.d.cts} +3 -2
  89. package/dist/VitestTransactionIsolator-CSroc7Df.d.cts.map +1 -0
  90. package/dist/VitestTransactionIsolator-DQ7tLqgV.mjs.map +1 -1
  91. package/dist/VitestTransactionIsolator.d.cts +1 -1
  92. package/dist/VitestTransactionIsolator.d.mts +1 -1
  93. package/dist/aws.cjs.map +1 -1
  94. package/dist/aws.d.cts +2 -0
  95. package/dist/aws.d.cts.map +1 -0
  96. package/dist/aws.d.mts +2 -0
  97. package/dist/aws.d.mts.map +1 -0
  98. package/dist/aws.mjs.map +1 -1
  99. package/dist/benchmark.cjs.map +1 -1
  100. package/dist/benchmark.d.cts +1 -0
  101. package/dist/benchmark.d.cts.map +1 -0
  102. package/dist/benchmark.d.mts +1 -0
  103. package/dist/benchmark.d.mts.map +1 -0
  104. package/dist/benchmark.mjs.map +1 -1
  105. package/dist/better-auth.cjs +29 -30
  106. package/dist/better-auth.cjs.map +1 -1
  107. package/dist/better-auth.d.cts +2 -2
  108. package/dist/better-auth.d.cts.map +1 -0
  109. package/dist/better-auth.d.mts.map +1 -0
  110. package/dist/better-auth.mjs +29 -30
  111. package/dist/better-auth.mjs.map +1 -1
  112. package/dist/directory-B-Ozljzk.mjs.map +1 -1
  113. package/dist/directory-BVC8g7cX.cjs.map +1 -1
  114. package/dist/{directory-BXavAeJZ.d.mts → directory-CVrfTq1I.d.mts} +2 -1
  115. package/dist/directory-CVrfTq1I.d.mts.map +1 -0
  116. package/dist/directory-Cys9g76X.d.cts +13 -0
  117. package/dist/directory-Cys9g76X.d.cts.map +1 -0
  118. package/dist/faker-B14IEMIN.cjs.map +1 -1
  119. package/dist/faker-BGKYFoCT.mjs.map +1 -1
  120. package/dist/{faker-DvxiCtxc.d.cts → faker-BSH1EMtg.d.cts} +3 -3
  121. package/dist/faker-BSH1EMtg.d.cts.map +1 -0
  122. package/dist/faker-DHh7xs4u.d.mts.map +1 -0
  123. package/dist/faker.d.cts +1 -1
  124. package/dist/helpers.cjs.map +1 -1
  125. package/dist/helpers.d.cts +1 -0
  126. package/dist/helpers.d.cts.map +1 -0
  127. package/dist/helpers.d.mts +1 -0
  128. package/dist/helpers.d.mts.map +1 -0
  129. package/dist/helpers.mjs.map +1 -1
  130. package/dist/kysely.cjs +3 -3
  131. package/dist/kysely.cjs.map +1 -1
  132. package/dist/kysely.d.cts +8 -7
  133. package/dist/kysely.d.cts.map +1 -0
  134. package/dist/kysely.d.mts +7 -6
  135. package/dist/kysely.d.mts.map +1 -0
  136. package/dist/kysely.mjs +3 -3
  137. package/dist/kysely.mjs.map +1 -1
  138. package/dist/logger.cjs.map +1 -1
  139. package/dist/logger.d.cts +1 -0
  140. package/dist/logger.d.cts.map +1 -0
  141. package/dist/logger.d.mts +1 -0
  142. package/dist/logger.d.mts.map +1 -0
  143. package/dist/logger.mjs.map +1 -1
  144. package/dist/objection.cjs +3 -3
  145. package/dist/objection.cjs.map +1 -1
  146. package/dist/objection.d.cts +8 -7
  147. package/dist/objection.d.cts.map +1 -0
  148. package/dist/objection.d.mts +7 -6
  149. package/dist/objection.d.mts.map +1 -0
  150. package/dist/objection.mjs +3 -3
  151. package/dist/objection.mjs.map +1 -1
  152. package/dist/os/directory.d.cts +1 -1
  153. package/dist/os/directory.d.mts +1 -1
  154. package/dist/os/index.d.cts +1 -1
  155. package/dist/os/index.d.mts +1 -1
  156. package/dist/timer.cjs.map +1 -1
  157. package/dist/timer.d.cts +2 -0
  158. package/dist/timer.d.cts.map +1 -0
  159. package/dist/timer.d.mts +2 -0
  160. package/dist/timer.d.mts.map +1 -0
  161. package/dist/timer.mjs.map +1 -1
  162. package/package.json +5 -5
  163. package/src/Factory.ts +72 -72
  164. package/src/KyselyFactory.ts +330 -330
  165. package/src/ObjectionFactory.ts +354 -355
  166. package/src/PostgresKyselyMigrator.ts +37 -37
  167. package/src/PostgresMigrator.ts +107 -107
  168. package/src/PostgresObjectionMigrator.ts +91 -91
  169. package/src/VitestKyselyTransactionIsolator.ts +27 -27
  170. package/src/VitestObjectionTransactionIsolator.ts +39 -39
  171. package/src/VitestTransactionIsolator.ts +196 -195
  172. package/src/__tests__/Factory.spec.ts +163 -155
  173. package/src/__tests__/KyselyFactory.spec.ts +443 -439
  174. package/src/__tests__/ObjectionFactory.spec.ts +563 -557
  175. package/src/__tests__/PostgresKyselyMigrator.spec.ts +641 -641
  176. package/src/__tests__/PostgresMigrator.spec.ts +341 -341
  177. package/src/__tests__/PostgresObjectionMigrator.spec.ts +578 -578
  178. package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +114 -114
  179. package/src/__tests__/benchmark.spec.ts +140 -0
  180. package/src/__tests__/better-auth.spec.ts +15 -15
  181. package/src/__tests__/faker.spec.ts +226 -137
  182. package/src/__tests__/integration.spec.ts +597 -597
  183. package/src/__tests__/utilities.spec.ts +211 -0
  184. package/src/aws.ts +104 -104
  185. package/src/benchmark.ts +12 -12
  186. package/src/better-auth.ts +286 -301
  187. package/src/faker.ts +153 -153
  188. package/src/helpers.ts +6 -6
  189. package/src/kysely.ts +33 -33
  190. package/src/logger.ts +10 -10
  191. package/src/objection.ts +31 -31
  192. package/src/os/directory.ts +11 -10
  193. package/src/timer.ts +1 -1
  194. package/test/globalSetup.ts +45 -45
  195. package/test/helpers.ts +189 -189
  196. package/test/migrations/1749664623372_user.ts +13 -13
  197. package/tsconfig.json +9 -0
  198. package/vitest.config.ts +4 -4
  199. package/dist/PostgresKyselyMigrator-CfytARcA.cjs.map +0 -1
  200. package/dist/PostgresKyselyMigrator-upT-hmrz.mjs.map +0 -1
  201. package/dist/PostgresMigrator-DFcNdCvD.cjs.map +0 -1
  202. package/dist/PostgresMigrator-DbuJGAVy.mjs.map +0 -1
  203. package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs.map +0 -1
  204. package/dist/PostgresObjectionMigrator-DPj2pOpX.mjs.map +0 -1
  205. package/dist/VitestKyselyTransactionIsolator-CNURW8y6.mjs.map +0 -1
  206. package/dist/VitestKyselyTransactionIsolator-EvDLk5zg.cjs.map +0 -1
  207. package/dist/VitestObjectionTransactionIsolator-CM5KTAFA.cjs.map +0 -1
  208. package/dist/VitestObjectionTransactionIsolator-jQFaCz0u.mjs.map +0 -1
  209. package/dist/directory-Mi7tdOuD.d.cts +0 -12
package/src/faker.ts CHANGED
@@ -18,46 +18,46 @@ import { faker as baseFaker } from '@faker-js/faker';
18
18
  * ```
19
19
  */
20
20
  class AtomicCounter {
21
- /**
22
- * The current counter value.
23
- * @private
24
- */
25
- private value: number;
26
-
27
- /**
28
- * Creates a new atomic counter.
29
- * @param initialValue - The starting value (default: 0)
30
- */
31
- constructor(initialValue = 0) {
32
- this.value = initialValue;
33
- }
34
-
35
- /**
36
- * Increments the counter and returns the new value.
37
- * @returns The incremented value
38
- */
39
- increment(): number {
40
- // In Node.js, JavaScript is single-threaded within the event loop,
41
- // so this operation is already atomic. However, this class provides
42
- // a cleaner abstraction and makes the intent explicit.
43
- return ++this.value;
44
- }
45
-
46
- /**
47
- * Gets the current counter value without incrementing.
48
- * @returns The current value
49
- */
50
- get(): number {
51
- return this.value;
52
- }
53
-
54
- /**
55
- * Resets the counter to a specific value.
56
- * @param value - The new value (default: 0)
57
- */
58
- reset(value = 0): void {
59
- this.value = value;
60
- }
21
+ /**
22
+ * The current counter value.
23
+ * @private
24
+ */
25
+ private value: number;
26
+
27
+ /**
28
+ * Creates a new atomic counter.
29
+ * @param initialValue - The starting value (default: 0)
30
+ */
31
+ constructor(initialValue = 0) {
32
+ this.value = initialValue;
33
+ }
34
+
35
+ /**
36
+ * Increments the counter and returns the new value.
37
+ * @returns The incremented value
38
+ */
39
+ increment(): number {
40
+ // In Node.js, JavaScript is single-threaded within the event loop,
41
+ // so this operation is already atomic. However, this class provides
42
+ // a cleaner abstraction and makes the intent explicit.
43
+ return ++this.value;
44
+ }
45
+
46
+ /**
47
+ * Gets the current counter value without incrementing.
48
+ * @returns The current value
49
+ */
50
+ get(): number {
51
+ return this.value;
52
+ }
53
+
54
+ /**
55
+ * Resets the counter to a specific value.
56
+ * @param value - The new value (default: 0)
57
+ */
58
+ reset(value = 0): void {
59
+ this.value = value;
60
+ }
61
61
  }
62
62
 
63
63
  /**
@@ -81,16 +81,16 @@ class AtomicCounter {
81
81
  * ```
82
82
  */
83
83
  export function timestamps(): Timestamps {
84
- const createdAt = faker.date.past();
85
- const updatedAt = faker.date.between({
86
- from: createdAt,
87
- to: new Date(),
88
- });
84
+ const createdAt = faker.date.past();
85
+ const updatedAt = faker.date.between({
86
+ from: createdAt,
87
+ to: new Date(),
88
+ });
89
89
 
90
- createdAt.setMilliseconds(0);
91
- updatedAt.setMilliseconds(0);
90
+ createdAt.setMilliseconds(0);
91
+ updatedAt.setMilliseconds(0);
92
92
 
93
- return { createdAt, updatedAt };
93
+ return { createdAt, updatedAt };
94
94
  }
95
95
 
96
96
  /**
@@ -108,11 +108,11 @@ export function timestamps(): Timestamps {
108
108
  * ```
109
109
  */
110
110
  export function identifier(suffix?: string): string {
111
- return [
112
- faker.internet.domainSuffix(),
113
- faker.internet.domainWord(),
114
- suffix ? suffix : faker.internet.domainWord() + sequence('identifier'),
115
- ].join('.');
111
+ return [
112
+ faker.internet.domainSuffix(),
113
+ faker.internet.domainWord(),
114
+ suffix ? suffix : faker.internet.domainWord() + sequence('identifier'),
115
+ ].join('.');
116
116
  }
117
117
 
118
118
  /**
@@ -143,12 +143,12 @@ const sequences = new Map<string, AtomicCounter>();
143
143
  * ```
144
144
  */
145
145
  export function sequence(name = 'default'): number {
146
- if (!sequences.has(name)) {
147
- sequences.set(name, new AtomicCounter());
148
- }
146
+ if (!sequences.has(name)) {
147
+ sequences.set(name, new AtomicCounter());
148
+ }
149
149
 
150
- const counter = sequences.get(name) as AtomicCounter;
151
- return counter.increment();
150
+ const counter = sequences.get(name) as AtomicCounter;
151
+ return counter.increment();
152
152
  }
153
153
 
154
154
  /**
@@ -170,12 +170,12 @@ export function sequence(name = 'default'): number {
170
170
  * ```
171
171
  */
172
172
  export function resetSequence(name = 'default', value = 0): void {
173
- if (sequences.has(name)) {
174
- const counter = sequences.get(name) as AtomicCounter;
175
- counter.reset(value);
176
- } else {
177
- sequences.set(name, new AtomicCounter(value));
178
- }
173
+ if (sequences.has(name)) {
174
+ const counter = sequences.get(name) as AtomicCounter;
175
+ counter.reset(value);
176
+ } else {
177
+ sequences.set(name, new AtomicCounter(value));
178
+ }
179
179
  }
180
180
 
181
181
  /**
@@ -196,7 +196,7 @@ export function resetSequence(name = 'default', value = 0): void {
196
196
  * ```
197
197
  */
198
198
  export function resetAllSequences(): void {
199
- sequences.clear();
199
+ sequences.clear();
200
200
  }
201
201
 
202
202
  /**
@@ -212,89 +212,89 @@ export function resetAllSequences(): void {
212
212
  * ```
213
213
  */
214
214
  function price(): number {
215
- return +faker.commerce.price();
215
+ return +faker.commerce.price();
216
216
  }
217
217
 
218
218
  type Coordinate = {
219
- lat: number;
220
- lng: number;
219
+ lat: number;
220
+ lng: number;
221
221
  };
222
222
 
223
223
  export function coordinateInRadius(
224
- center: Coordinate,
225
- radius: number,
224
+ center: Coordinate,
225
+ radius: number,
226
226
  ): Coordinate {
227
- // Earth's radius in meters
228
- const earth = 6378137;
229
- // Convert radius from meters to degrees
230
- const d = radius / earth;
231
-
232
- // Random bearing and distance
233
- const theta = 2 * Math.PI * Math.random();
234
- const r = d * Math.sqrt(Math.random());
235
-
236
- const lat1 = (center.lat * Math.PI) / 180;
237
- const lng1 = (center.lng * Math.PI) / 180;
238
-
239
- const lat2 = Math.asin(
240
- Math.sin(lat1) * Math.cos(r) +
241
- Math.cos(lat1) * Math.sin(r) * Math.cos(theta),
242
- );
243
- const lng2 =
244
- lng1 +
245
- Math.atan2(
246
- Math.sin(theta) * Math.sin(r) * Math.cos(lat1),
247
- Math.cos(r) - Math.sin(lat1) * Math.sin(lat2),
248
- );
249
-
250
- return {
251
- lat: (lat2 * 180) / Math.PI,
252
- lng: (lng2 * 180) / Math.PI,
253
- };
227
+ // Earth's radius in meters
228
+ const earth = 6378137;
229
+ // Convert radius from meters to degrees
230
+ const d = radius / earth;
231
+
232
+ // Random bearing and distance
233
+ const theta = 2 * Math.PI * Math.random();
234
+ const r = d * Math.sqrt(Math.random());
235
+
236
+ const lat1 = (center.lat * Math.PI) / 180;
237
+ const lng1 = (center.lng * Math.PI) / 180;
238
+
239
+ const lat2 = Math.asin(
240
+ Math.sin(lat1) * Math.cos(r) +
241
+ Math.cos(lat1) * Math.sin(r) * Math.cos(theta),
242
+ );
243
+ const lng2 =
244
+ lng1 +
245
+ Math.atan2(
246
+ Math.sin(theta) * Math.sin(r) * Math.cos(lat1),
247
+ Math.cos(r) - Math.sin(lat1) * Math.sin(lat2),
248
+ );
249
+
250
+ return {
251
+ lat: (lat2 * 180) / Math.PI,
252
+ lng: (lng2 * 180) / Math.PI,
253
+ };
254
254
  }
255
255
 
256
256
  function coordinateOutsideRadius(
257
- center: Coordinate,
258
- minRadiusMeters: number,
259
- maxRadiusMeters: number,
257
+ center: Coordinate,
258
+ minRadiusMeters: number,
259
+ maxRadiusMeters: number,
260
260
  ): Coordinate {
261
- // Earth's radius in meters
262
- const earth = 6378137;
263
-
264
- // Convert radii from meters to radians
265
- const minD = minRadiusMeters / earth;
266
- const maxD = maxRadiusMeters / earth;
267
-
268
- // Random bearing
269
- const theta = 2 * Math.PI * Math.random();
270
-
271
- // Random distance in annular ring (uniform distribution by area)
272
- // For uniform distribution in annulus: r = sqrt(r_min² + (r_max² - r_min²) * random)
273
- const r = Math.sqrt(
274
- minD * minD + (maxD * maxD - minD * minD) * Math.random(),
275
- );
276
-
277
- const lat1 = (center.lat * Math.PI) / 180;
278
- const lng1 = (center.lng * Math.PI) / 180;
279
-
280
- const lat2 = Math.asin(
281
- Math.sin(lat1) * Math.cos(r) +
282
- Math.cos(lat1) * Math.sin(r) * Math.cos(theta),
283
- );
284
- const lng2 =
285
- lng1 +
286
- Math.atan2(
287
- Math.sin(theta) * Math.sin(r) * Math.cos(lat1),
288
- Math.cos(r) - Math.sin(lat1) * Math.sin(lat2),
289
- );
290
-
291
- // Normalize longitude to [-180, 180]
292
- const normalizedLng = (((lng2 * 180) / Math.PI + 540) % 360) - 180;
293
-
294
- return {
295
- lat: (lat2 * 180) / Math.PI,
296
- lng: normalizedLng,
297
- };
261
+ // Earth's radius in meters
262
+ const earth = 6378137;
263
+
264
+ // Convert radii from meters to radians
265
+ const minD = minRadiusMeters / earth;
266
+ const maxD = maxRadiusMeters / earth;
267
+
268
+ // Random bearing
269
+ const theta = 2 * Math.PI * Math.random();
270
+
271
+ // Random distance in annular ring (uniform distribution by area)
272
+ // For uniform distribution in annulus: r = sqrt(r_min² + (r_max² - r_min²) * random)
273
+ const r = Math.sqrt(
274
+ minD * minD + (maxD * maxD - minD * minD) * Math.random(),
275
+ );
276
+
277
+ const lat1 = (center.lat * Math.PI) / 180;
278
+ const lng1 = (center.lng * Math.PI) / 180;
279
+
280
+ const lat2 = Math.asin(
281
+ Math.sin(lat1) * Math.cos(r) +
282
+ Math.cos(lat1) * Math.sin(r) * Math.cos(theta),
283
+ );
284
+ const lng2 =
285
+ lng1 +
286
+ Math.atan2(
287
+ Math.sin(theta) * Math.sin(r) * Math.cos(lat1),
288
+ Math.cos(r) - Math.sin(lat1) * Math.sin(lat2),
289
+ );
290
+
291
+ // Normalize longitude to [-180, 180]
292
+ const normalizedLng = (((lng2 * 180) / Math.PI + 540) % 360) - 180;
293
+
294
+ return {
295
+ lat: (lat2 * 180) / Math.PI,
296
+ lng: normalizedLng,
297
+ };
298
298
  }
299
299
 
300
300
  /**
@@ -317,18 +317,18 @@ function coordinateOutsideRadius(
317
317
  * ```
318
318
  */
319
319
  export const faker = Object.freeze(
320
- Object.assign({}, baseFaker, {
321
- timestamps,
322
- identifier,
323
- sequence,
324
- resetSequence,
325
- resetAllSequences,
326
- price,
327
- coordinates: {
328
- within: coordinateInRadius,
329
- outside: coordinateOutsideRadius,
330
- },
331
- }),
320
+ Object.assign({}, baseFaker, {
321
+ timestamps,
322
+ identifier,
323
+ sequence,
324
+ resetSequence,
325
+ resetAllSequences,
326
+ price,
327
+ coordinates: {
328
+ within: coordinateInRadius,
329
+ outside: coordinateOutsideRadius,
330
+ },
331
+ }),
332
332
  );
333
333
 
334
334
  /**
@@ -336,10 +336,10 @@ export const faker = Object.freeze(
336
336
  * Used by the timestamps() function to generate date fields.
337
337
  */
338
338
  export type Timestamps = {
339
- /** The creation date */
340
- createdAt: Date;
341
- /** The last update date */
342
- updatedAt: Date;
339
+ /** The creation date */
340
+ createdAt: Date;
341
+ /** The last update date */
342
+ updatedAt: Date;
343
343
  };
344
344
 
345
345
  /**
package/src/helpers.ts CHANGED
@@ -36,10 +36,10 @@ import pg from 'pg';
36
36
  * ```
37
37
  */
38
38
  export function createKyselyDb<Database>(config: any): Kysely<Database> {
39
- return new Kysely({
40
- dialect: new PostgresDialect({
41
- pool: new pg.Pool(config),
42
- }),
43
- plugins: [new CamelCasePlugin()],
44
- });
39
+ return new Kysely({
40
+ dialect: new PostgresDialect({
41
+ pool: new pg.Pool(config),
42
+ }),
43
+ plugins: [new CamelCasePlugin()],
44
+ });
45
45
  }
package/src/kysely.ts CHANGED
@@ -2,10 +2,10 @@ import type { Kysely, Transaction } from 'kysely';
2
2
  import type { TestAPI } from 'vitest';
3
3
  import { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';
4
4
  import {
5
- type DatabaseConnection,
6
- type FixtureCreators,
7
- type IsolationLevel,
8
- extendWithFixtures as baseExtendWithFixtures,
5
+ extendWithFixtures as baseExtendWithFixtures,
6
+ type DatabaseConnection,
7
+ type FixtureCreators,
8
+ type IsolationLevel,
9
9
  } from './VitestTransactionIsolator';
10
10
 
11
11
  /**
@@ -13,38 +13,38 @@ import {
13
13
  * Provides factories, migrators, and transaction isolators for Kysely ORM.
14
14
  */
15
15
 
16
- export { KyselyFactory } from './KyselyFactory';
17
16
  export type { ExtractSeedAttrs, FactorySeed } from './Factory';
17
+ export { KyselyFactory } from './KyselyFactory';
18
18
  export { PostgresKyselyMigrator } from './PostgresKyselyMigrator';
19
19
  export { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';
20
- export { IsolationLevel } from './VitestTransactionIsolator';
21
20
  export type {
22
- DatabaseFixtures,
23
- ExtendedDatabaseFixtures,
24
- FixtureCreators,
25
- TestWithExtendedFixtures,
26
- TransactionWrapperOptions,
21
+ DatabaseFixtures,
22
+ ExtendedDatabaseFixtures,
23
+ FixtureCreators,
24
+ TestWithExtendedFixtures,
25
+ TransactionWrapperOptions,
27
26
  } from './VitestTransactionIsolator';
27
+ export { IsolationLevel } from './VitestTransactionIsolator';
28
28
 
29
29
  /**
30
30
  * Kysely-specific options for transaction wrapping.
31
31
  */
32
32
  export interface KyselyTransactionOptions<
33
- Database,
34
- Extended extends Record<string, unknown> = {},
33
+ Database,
34
+ Extended extends Record<string, unknown> = {},
35
35
  > {
36
- /** Function that creates or returns a Kysely database instance */
37
- connection: DatabaseConnection<Kysely<Database>>;
38
- /** Optional setup function to run within the transaction before each test */
39
- setup?: (trx: Transaction<Database>) => Promise<void>;
40
- /** Transaction isolation level (defaults to REPEATABLE_READ) */
41
- isolationLevel?: IsolationLevel;
42
- /** Additional fixtures that depend on the transaction */
43
- fixtures?: FixtureCreators<Transaction<Database>, Extended>;
36
+ /** Function that creates or returns a Kysely database instance */
37
+ connection: DatabaseConnection<Kysely<Database>>;
38
+ /** Optional setup function to run within the transaction before each test */
39
+ setup?: (trx: Transaction<Database>) => Promise<void>;
40
+ /** Transaction isolation level (defaults to REPEATABLE_READ) */
41
+ isolationLevel?: IsolationLevel;
42
+ /** Additional fixtures that depend on the transaction */
43
+ fixtures?: FixtureCreators<Transaction<Database>, Extended>;
44
44
  }
45
45
 
46
46
  // Re-export faker and FakerFactory for type portability in declaration files
47
- export { faker, type FakerFactory } from './faker';
47
+ export { type FakerFactory, faker } from './faker';
48
48
 
49
49
  /**
50
50
  * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.
@@ -94,12 +94,12 @@ export { faker, type FakerFactory } from './faker';
94
94
  * ```
95
95
  */
96
96
  export function wrapVitestKyselyTransaction<
97
- Database,
98
- Extended extends Record<string, unknown> = {},
97
+ Database,
98
+ Extended extends Record<string, unknown> = {},
99
99
  >(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>) {
100
- const wrapper = new VitestKyselyTransactionIsolator<Database>(api);
100
+ const wrapper = new VitestKyselyTransactionIsolator<Database>(api);
101
101
 
102
- return wrapper.wrapVitestWithTransaction(options);
102
+ return wrapper.wrapVitestWithTransaction(options);
103
103
  }
104
104
 
105
105
  /**
@@ -155,12 +155,12 @@ export function wrapVitestKyselyTransaction<
155
155
  * ```
156
156
  */
157
157
  export function extendWithFixtures<
158
- Database,
159
- Extended extends Record<string, unknown>,
160
- T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,
158
+ Database,
159
+ Extended extends Record<string, unknown>,
160
+ T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,
161
161
  >(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>) {
162
- return baseExtendWithFixtures<Transaction<Database>, Extended, T>(
163
- wrappedTest,
164
- fixtures,
165
- );
162
+ return baseExtendWithFixtures<Transaction<Database>, Extended, T>(
163
+ wrappedTest,
164
+ fixtures,
165
+ );
166
166
  }
package/src/logger.ts CHANGED
@@ -5,14 +5,14 @@ import { vi } from 'vitest';
5
5
  * Creates a mock Logger for testing
6
6
  */
7
7
  export function createMockLogger(): Logger {
8
- const logger: Logger = {
9
- debug: vi.fn(),
10
- info: vi.fn(),
11
- warn: vi.fn(),
12
- error: vi.fn(),
13
- fatal: vi.fn(),
14
- trace: vi.fn(),
15
- child: vi.fn(() => logger),
16
- };
17
- return logger;
8
+ const logger: Logger = {
9
+ debug: vi.fn(),
10
+ info: vi.fn(),
11
+ warn: vi.fn(),
12
+ error: vi.fn(),
13
+ fatal: vi.fn(),
14
+ trace: vi.fn(),
15
+ child: vi.fn(() => logger),
16
+ };
17
+ return logger;
18
18
  }
package/src/objection.ts CHANGED
@@ -2,10 +2,10 @@ import type { Knex } from 'knex';
2
2
  import type { TestAPI } from 'vitest';
3
3
  import { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';
4
4
  import {
5
- type DatabaseConnection,
6
- type FixtureCreators,
7
- type IsolationLevel,
8
- extendWithFixtures as baseExtendWithFixtures,
5
+ extendWithFixtures as baseExtendWithFixtures,
6
+ type DatabaseConnection,
7
+ type FixtureCreators,
8
+ type IsolationLevel,
9
9
  } from './VitestTransactionIsolator';
10
10
 
11
11
  /**
@@ -14,37 +14,37 @@ import {
14
14
  * and transaction isolation for test suites.
15
15
  */
16
16
 
17
- export { ObjectionFactory } from './ObjectionFactory';
18
17
  export type { ExtractSeedAttrs, FactorySeed } from './Factory';
19
- export { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';
20
- export { IsolationLevel } from './VitestTransactionIsolator';
18
+ export { ObjectionFactory } from './ObjectionFactory';
21
19
  export { PostgresObjectionMigrator } from './PostgresObjectionMigrator';
20
+ export { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';
22
21
  export type {
23
- DatabaseFixtures,
24
- ExtendedDatabaseFixtures,
25
- FixtureCreators,
26
- TestWithExtendedFixtures,
27
- TransactionWrapperOptions,
22
+ DatabaseFixtures,
23
+ ExtendedDatabaseFixtures,
24
+ FixtureCreators,
25
+ TestWithExtendedFixtures,
26
+ TransactionWrapperOptions,
28
27
  } from './VitestTransactionIsolator';
28
+ export { IsolationLevel } from './VitestTransactionIsolator';
29
29
 
30
30
  /**
31
31
  * Objection.js-specific options for transaction wrapping.
32
32
  */
33
33
  export interface ObjectionTransactionOptions<
34
- Extended extends Record<string, unknown> = {},
34
+ Extended extends Record<string, unknown> = {},
35
35
  > {
36
- /** Function that creates or returns a Knex database connection */
37
- connection: DatabaseConnection<Knex>;
38
- /** Optional setup function to run within the transaction before each test */
39
- setup?: (trx: Knex.Transaction) => Promise<void>;
40
- /** Transaction isolation level (defaults to REPEATABLE_READ) */
41
- isolationLevel?: IsolationLevel;
42
- /** Additional fixtures that depend on the transaction */
43
- fixtures?: FixtureCreators<Knex.Transaction, Extended>;
36
+ /** Function that creates or returns a Knex database connection */
37
+ connection: DatabaseConnection<Knex>;
38
+ /** Optional setup function to run within the transaction before each test */
39
+ setup?: (trx: Knex.Transaction) => Promise<void>;
40
+ /** Transaction isolation level (defaults to REPEATABLE_READ) */
41
+ isolationLevel?: IsolationLevel;
42
+ /** Additional fixtures that depend on the transaction */
43
+ fixtures?: FixtureCreators<Knex.Transaction, Extended>;
44
44
  }
45
45
 
46
46
  // Re-export faker and FakerFactory for type portability in declaration files
47
- export { faker, type FakerFactory } from './faker';
47
+ export { type FakerFactory, faker } from './faker';
48
48
 
49
49
  /**
50
50
  * Creates a wrapped Vitest test API with automatic transaction rollback for Objection.js.
@@ -91,11 +91,11 @@ export { faker, type FakerFactory } from './faker';
91
91
  * ```
92
92
  */
93
93
  export function wrapVitestObjectionTransaction<
94
- Extended extends Record<string, unknown> = {},
94
+ Extended extends Record<string, unknown> = {},
95
95
  >(api: TestAPI, options: ObjectionTransactionOptions<Extended>) {
96
- const wrapper = new VitestObjectionTransactionIsolator(api);
96
+ const wrapper = new VitestObjectionTransactionIsolator(api);
97
97
 
98
- return wrapper.wrapVitestWithTransaction(options);
98
+ return wrapper.wrapVitestWithTransaction(options);
99
99
  }
100
100
 
101
101
  /**
@@ -147,11 +147,11 @@ export function wrapVitestObjectionTransaction<
147
147
  * ```
148
148
  */
149
149
  export function extendWithFixtures<
150
- Extended extends Record<string, unknown>,
151
- T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,
150
+ Extended extends Record<string, unknown>,
151
+ T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,
152
152
  >(wrappedTest: T, fixtures: FixtureCreators<Knex.Transaction, Extended>) {
153
- return baseExtendWithFixtures<Knex.Transaction, Extended, T>(
154
- wrappedTest,
155
- fixtures,
156
- );
153
+ return baseExtendWithFixtures<Knex.Transaction, Extended, T>(
154
+ wrappedTest,
155
+ fixtures,
156
+ );
157
157
  }
@@ -5,17 +5,18 @@ import path from 'node:path';
5
5
  import { it } from 'vitest';
6
6
 
7
7
  export const itWithDir = it.extend<DirectoryFixtures>({
8
- // This fixture automatically provides a transaction to each test
9
- dir: async ({}, use) => {
10
- const tempDir = os.tmpdir();
11
- const directoryName = crypto.randomUUID().replace(/-/g, '').toUpperCase();
12
- const dir = path.join(tempDir, directoryName);
13
- await fs.mkdir(dir, { recursive: true });
14
- await use(dir);
15
- await fs.rm(dir, { recursive: true, force: true });
16
- },
8
+ // This fixture automatically provides a transaction to each test
9
+ // biome-ignore lint/correctness/noEmptyPattern: this has to be like this to satisfy Biome
10
+ dir: async ({}, use) => {
11
+ const tempDir = os.tmpdir();
12
+ const directoryName = crypto.randomUUID().replace(/-/g, '').toUpperCase();
13
+ const dir = path.join(tempDir, directoryName);
14
+ await fs.mkdir(dir, { recursive: true });
15
+ await use(dir);
16
+ await fs.rm(dir, { recursive: true, force: true });
17
+ },
17
18
  });
18
19
 
19
20
  export interface DirectoryFixtures {
20
- dir: string;
21
+ dir: string;
21
22
  }
package/src/timer.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export function waitFor(ms: number) {
2
- return new Promise((resolve) => setTimeout(resolve, ms));
2
+ return new Promise((resolve) => setTimeout(resolve, ms));
3
3
  }