@geekmidas/testkit 0.0.10 → 0.0.12

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 (97) hide show
  1. package/dist/Factory-Bm44VKa-.d.cts +131 -0
  2. package/dist/Factory-tjCDNgUK.d.mts +131 -0
  3. package/dist/Factory.d.cts +3 -0
  4. package/dist/Factory.d.mts +3 -0
  5. package/dist/KyselyFactory-BoPDDitt.d.cts +200 -0
  6. package/dist/{KyselyFactory-ELiHgHVv.mjs → KyselyFactory-C3Bc3p4L.mjs} +1 -1
  7. package/dist/{KyselyFactory-Bdq1s1Go.cjs → KyselyFactory-CXtfmMfK.cjs} +1 -1
  8. package/dist/KyselyFactory-D82j74t9.d.mts +200 -0
  9. package/dist/KyselyFactory.cjs +2 -2
  10. package/dist/KyselyFactory.d.cts +4 -0
  11. package/dist/KyselyFactory.d.mts +4 -0
  12. package/dist/KyselyFactory.mjs +2 -2
  13. package/dist/ObjectionFactory-BWMTXsxH.d.cts +213 -0
  14. package/dist/ObjectionFactory-CEG5qUrm.d.mts +213 -0
  15. package/dist/{ObjectionFactory-C47B03Ot.cjs → ObjectionFactory-DxIxJagq.cjs} +82 -40
  16. package/dist/{ObjectionFactory-89p-FFEw.mjs → ObjectionFactory-qIICOph3.mjs} +82 -40
  17. package/dist/ObjectionFactory.cjs +2 -1
  18. package/dist/ObjectionFactory.d.cts +4 -0
  19. package/dist/ObjectionFactory.d.mts +4 -0
  20. package/dist/ObjectionFactory.mjs +2 -1
  21. package/dist/PostgresKyselyMigrator-CQ3aUoy_.d.cts +67 -0
  22. package/dist/PostgresKyselyMigrator-_6yHZigp.d.mts +67 -0
  23. package/dist/PostgresKyselyMigrator.d.cts +3 -0
  24. package/dist/PostgresKyselyMigrator.d.mts +3 -0
  25. package/dist/PostgresMigrator-BlvuQl7d.d.mts +84 -0
  26. package/dist/PostgresMigrator-D5UkK1_K.d.cts +84 -0
  27. package/dist/PostgresMigrator.d.cts +2 -0
  28. package/dist/PostgresMigrator.d.mts +2 -0
  29. package/dist/PostgresObjectionMigrator-C69n7vzr.d.mts +77 -0
  30. package/dist/PostgresObjectionMigrator-CZHHcCOv.d.cts +77 -0
  31. package/dist/PostgresObjectionMigrator.d.cts +3 -0
  32. package/dist/PostgresObjectionMigrator.d.mts +3 -0
  33. package/dist/VitestKyselyTransactionIsolator-ClCazkBO.d.mts +56 -0
  34. package/dist/VitestKyselyTransactionIsolator-UE1J-UoP.d.cts +56 -0
  35. package/dist/VitestKyselyTransactionIsolator.d.cts +3 -0
  36. package/dist/VitestKyselyTransactionIsolator.d.mts +3 -0
  37. package/dist/VitestObjectionTransactionIsolator-CO2nTi9r.d.cts +57 -0
  38. package/dist/VitestObjectionTransactionIsolator-D264iuPy.d.mts +57 -0
  39. package/dist/VitestObjectionTransactionIsolator.d.cts +3 -0
  40. package/dist/VitestObjectionTransactionIsolator.d.mts +3 -0
  41. package/dist/VitestTransactionIsolator-DHf2MxmC.d.cts +118 -0
  42. package/dist/VitestTransactionIsolator-Xqyjlmw6.d.mts +118 -0
  43. package/dist/VitestTransactionIsolator.d.cts +2 -0
  44. package/dist/VitestTransactionIsolator.d.mts +2 -0
  45. package/dist/__tests__/Factory.spec.d.cts +1 -0
  46. package/dist/__tests__/Factory.spec.d.mts +1 -0
  47. package/dist/__tests__/KyselyFactory.spec.cjs +2 -2
  48. package/dist/__tests__/KyselyFactory.spec.d.cts +1 -0
  49. package/dist/__tests__/KyselyFactory.spec.d.mts +1 -0
  50. package/dist/__tests__/KyselyFactory.spec.mjs +2 -2
  51. package/dist/__tests__/ObjectionFactory.spec.cjs +117 -1
  52. package/dist/__tests__/ObjectionFactory.spec.d.cts +1 -0
  53. package/dist/__tests__/ObjectionFactory.spec.d.mts +1 -0
  54. package/dist/__tests__/ObjectionFactory.spec.mjs +117 -1
  55. package/dist/__tests__/PostgresMigrator.spec.d.cts +1 -0
  56. package/dist/__tests__/PostgresMigrator.spec.d.mts +1 -0
  57. package/dist/__tests__/PostgresObjectionMigrator.spec.d.cts +1 -0
  58. package/dist/__tests__/PostgresObjectionMigrator.spec.d.mts +1 -0
  59. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.cjs +2 -1
  60. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.cts +1 -0
  61. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.mts +1 -0
  62. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.mjs +2 -1
  63. package/dist/__tests__/faker.spec.cjs +1 -1
  64. package/dist/__tests__/faker.spec.d.cts +1 -0
  65. package/dist/__tests__/faker.spec.d.mts +1 -0
  66. package/dist/__tests__/faker.spec.mjs +1 -1
  67. package/dist/__tests__/integration.spec.cjs +2 -2
  68. package/dist/__tests__/integration.spec.d.cts +1 -0
  69. package/dist/__tests__/integration.spec.d.mts +1 -0
  70. package/dist/__tests__/integration.spec.mjs +2 -2
  71. package/dist/example.cjs +2 -2
  72. package/dist/example.d.cts +26 -0
  73. package/dist/example.d.mts +26 -0
  74. package/dist/example.mjs +2 -2
  75. package/dist/{faker-SMN4ira4.cjs → faker-B14IEMIN.cjs} +41 -1
  76. package/dist/{faker-CxKkEeYi.mjs → faker-BGKYFoCT.mjs} +36 -2
  77. package/dist/faker-ChuHaYMR.d.mts +165 -0
  78. package/dist/faker-km9UhOS6.d.cts +165 -0
  79. package/dist/faker.cjs +2 -1
  80. package/dist/faker.d.cts +2 -0
  81. package/dist/faker.d.mts +2 -0
  82. package/dist/faker.mjs +2 -2
  83. package/dist/helpers.d.cts +41 -0
  84. package/dist/helpers.d.mts +41 -0
  85. package/dist/kysely.cjs +2 -2
  86. package/dist/kysely.d.cts +73 -0
  87. package/dist/kysely.d.mts +73 -0
  88. package/dist/kysely.mjs +2 -2
  89. package/dist/objection.cjs +2 -1
  90. package/dist/objection.d.cts +88 -0
  91. package/dist/objection.d.mts +88 -0
  92. package/dist/objection.mjs +2 -1
  93. package/package.json +5 -5
  94. package/src/ObjectionFactory.ts +156 -13
  95. package/src/__tests__/ObjectionFactory.spec.ts +162 -0
  96. package/src/faker.ts +86 -0
  97. package/PostgresKyselyMigrator.spec +0 -471
@@ -1,5 +1,6 @@
1
1
  import "../Factory-z2m01hMj.mjs";
2
- import { ObjectionFactory } from "../ObjectionFactory-89p-FFEw.mjs";
2
+ import { faker } from "../faker-BGKYFoCT.mjs";
3
+ import { ObjectionFactory } from "../ObjectionFactory-qIICOph3.mjs";
3
4
  import { setupKnexTest } from "../helpers-BEmjyUVE.mjs";
4
5
  import { afterAll, beforeAll, describe, expect, it } from "vitest";
5
6
  import { Model } from "objection";
@@ -285,6 +286,121 @@ describe.skip("ObjectionFactory", () => {
285
286
  expect(result).toBe(seedFn);
286
287
  });
287
288
  });
289
+ describe("createBuilder static method", () => {
290
+ it("should create a builder function with auto-insert", async () => {
291
+ const userBuilder = ObjectionFactory.createBuilder(User, (attrs, factory$1, db$1, faker$1) => ({
292
+ name: faker$1.person.fullName(),
293
+ email: faker$1.internet.email(),
294
+ role: "user",
295
+ createdAt: /* @__PURE__ */ new Date(),
296
+ updatedAt: /* @__PURE__ */ new Date(),
297
+ ...attrs
298
+ }));
299
+ const builders = { user: userBuilder };
300
+ factory = new ObjectionFactory(builders, {}, trx);
301
+ const result = await factory.insert("user", { name: "Test User" });
302
+ expect(result).toBeInstanceOf(User);
303
+ expect(result.name).toBe("Test User");
304
+ expect(result.email).toMatch(/@/);
305
+ expect(result.id).toBeDefined();
306
+ });
307
+ it("should create a builder function without auto-insert", async () => {
308
+ const userBuilder = ObjectionFactory.createBuilder(User, (attrs) => ({
309
+ name: "No Insert User",
310
+ email: "noinsert@example.com",
311
+ role: "user",
312
+ createdAt: /* @__PURE__ */ new Date(),
313
+ updatedAt: /* @__PURE__ */ new Date(),
314
+ ...attrs
315
+ }), false);
316
+ const builders = { user: userBuilder };
317
+ factory = new ObjectionFactory(builders, {}, trx);
318
+ const result = await factory.insert("user");
319
+ expect(result).toBeInstanceOf(User);
320
+ expect(result.name).toBe("No Insert User");
321
+ expect(result.id).toBeDefined();
322
+ });
323
+ it("should pass all parameters to the item function", async () => {
324
+ let capturedFactory;
325
+ let capturedDb;
326
+ let capturedFaker;
327
+ const userBuilder = ObjectionFactory.createBuilder(User, (attrs, factory$1, db$1, fakerInstance) => {
328
+ capturedFactory = factory$1;
329
+ capturedDb = db$1;
330
+ capturedFaker = fakerInstance;
331
+ return {
332
+ name: "Test User",
333
+ email: "test@example.com",
334
+ role: "user",
335
+ createdAt: /* @__PURE__ */ new Date(),
336
+ updatedAt: /* @__PURE__ */ new Date(),
337
+ ...attrs
338
+ };
339
+ });
340
+ const builders = { user: userBuilder };
341
+ factory = new ObjectionFactory(builders, {}, trx);
342
+ await factory.insert("user");
343
+ expect(capturedFactory).toBe(factory);
344
+ expect(capturedDb).toBe(trx);
345
+ expect(capturedFaker).toBe(faker);
346
+ });
347
+ it("should handle async item functions", async () => {
348
+ const userBuilder = ObjectionFactory.createBuilder(User, async (attrs, factory$1, db$1, faker$1) => {
349
+ await new Promise((resolve) => setTimeout(resolve, 10));
350
+ return {
351
+ name: "Async User",
352
+ email: faker$1.internet.email(),
353
+ role: "user",
354
+ createdAt: /* @__PURE__ */ new Date(),
355
+ updatedAt: /* @__PURE__ */ new Date(),
356
+ ...attrs
357
+ };
358
+ });
359
+ const builders = { user: userBuilder };
360
+ factory = new ObjectionFactory(builders, {}, trx);
361
+ const result = await factory.insert("user");
362
+ expect(result).toBeInstanceOf(User);
363
+ expect(result.name).toBe("Async User");
364
+ expect(result.id).toBeDefined();
365
+ });
366
+ it("should work without item function", async () => {
367
+ const userBuilder = ObjectionFactory.createBuilder(User);
368
+ const builders = { user: userBuilder };
369
+ factory = new ObjectionFactory(builders, {}, trx);
370
+ const attrs = {
371
+ name: "Manual User",
372
+ email: "manual@example.com",
373
+ role: "user",
374
+ createdAt: /* @__PURE__ */ new Date(),
375
+ updatedAt: /* @__PURE__ */ new Date()
376
+ };
377
+ const result = await factory.insert("user", attrs);
378
+ expect(result).toBeInstanceOf(User);
379
+ expect(result.name).toBe("Manual User");
380
+ expect(result.email).toBe("manual@example.com");
381
+ expect(result.id).toBeDefined();
382
+ });
383
+ it("should allow overriding default values", async () => {
384
+ const userBuilder = ObjectionFactory.createBuilder(User, (attrs, factory$1, db$1, faker$1) => ({
385
+ name: "Default Name",
386
+ email: "default@example.com",
387
+ role: "user",
388
+ createdAt: /* @__PURE__ */ new Date(),
389
+ updatedAt: /* @__PURE__ */ new Date(),
390
+ ...attrs
391
+ }));
392
+ const builders = { user: userBuilder };
393
+ factory = new ObjectionFactory(builders, {}, trx);
394
+ const result = await factory.insert("user", {
395
+ name: "Override Name",
396
+ email: "override@example.com"
397
+ });
398
+ expect(result).toBeInstanceOf(User);
399
+ expect(result.name).toBe("Override Name");
400
+ expect(result.email).toBe("override@example.com");
401
+ expect(result.role).toBe("user");
402
+ });
403
+ });
288
404
  describe("error handling", () => {
289
405
  it("should handle builder errors gracefully", async () => {
290
406
  const userBuilder = async (attrs, factory$1, db$1) => {
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -1,6 +1,7 @@
1
1
  const require_chunk = require('../chunk-CUT6urMc.cjs');
2
2
  require('../Factory-WMhTNZ9S.cjs');
3
- require('../ObjectionFactory-C47B03Ot.cjs');
3
+ require('../faker-B14IEMIN.cjs');
4
+ require('../ObjectionFactory-DxIxJagq.cjs');
4
5
  require('../PostgresMigrator-DFcNdCvD.cjs');
5
6
  require('../PostgresObjectionMigrator-BG6ymgnt.cjs');
6
7
  require('../VitestTransactionIsolator-CruLTRRi.cjs');
@@ -1,5 +1,6 @@
1
1
  import "../Factory-z2m01hMj.mjs";
2
- import "../ObjectionFactory-89p-FFEw.mjs";
2
+ import "../faker-BGKYFoCT.mjs";
3
+ import "../ObjectionFactory-qIICOph3.mjs";
3
4
  import "../PostgresMigrator-DxPC_gGu.mjs";
4
5
  import "../PostgresObjectionMigrator-G4h5FLvU.mjs";
5
6
  import "../VitestTransactionIsolator-BWwK-ca6.mjs";
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('../chunk-CUT6urMc.cjs');
2
- const require_faker = require('../faker-SMN4ira4.cjs');
2
+ const require_faker = require('../faker-B14IEMIN.cjs');
3
3
  const vitest = require_chunk.__toESM(require("vitest"));
4
4
 
5
5
  //#region src/__tests__/faker.spec.ts
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -1,4 +1,4 @@
1
- import { faker } from "../faker-CxKkEeYi.mjs";
1
+ import { faker } from "../faker-BGKYFoCT.mjs";
2
2
  import { beforeEach, describe, expect, it } from "vitest";
3
3
 
4
4
  //#region src/__tests__/faker.spec.ts
@@ -1,7 +1,7 @@
1
1
  const require_chunk = require('../chunk-CUT6urMc.cjs');
2
2
  require('../Factory-WMhTNZ9S.cjs');
3
- require('../faker-SMN4ira4.cjs');
4
- const require_KyselyFactory = require('../KyselyFactory-Bdq1s1Go.cjs');
3
+ require('../faker-B14IEMIN.cjs');
4
+ const require_KyselyFactory = require('../KyselyFactory-CXtfmMfK.cjs');
5
5
  require('../PostgresMigrator-DFcNdCvD.cjs');
6
6
  require('../PostgresKyselyMigrator-CfytARcA.cjs');
7
7
  require('../VitestTransactionIsolator-CruLTRRi.cjs');
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -1,6 +1,6 @@
1
1
  import "../Factory-z2m01hMj.mjs";
2
- import "../faker-CxKkEeYi.mjs";
3
- import { KyselyFactory } from "../KyselyFactory-ELiHgHVv.mjs";
2
+ import "../faker-BGKYFoCT.mjs";
3
+ import { KyselyFactory } from "../KyselyFactory-C3Bc3p4L.mjs";
4
4
  import "../PostgresMigrator-DxPC_gGu.mjs";
5
5
  import "../PostgresKyselyMigrator-Bdhl251C.mjs";
6
6
  import "../VitestTransactionIsolator-BWwK-ca6.mjs";
package/dist/example.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  require('./Factory-WMhTNZ9S.cjs');
2
- require('./faker-SMN4ira4.cjs');
3
- const require_KyselyFactory = require('./KyselyFactory-Bdq1s1Go.cjs');
2
+ require('./faker-B14IEMIN.cjs');
3
+ const require_KyselyFactory = require('./KyselyFactory-CXtfmMfK.cjs');
4
4
 
5
5
  //#region src/example.ts
6
6
  const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder({
@@ -0,0 +1,26 @@
1
+ import { FakerFactory } from "./faker-km9UhOS6.cjs";
2
+ import * as kysely0 from "kysely";
3
+
4
+ //#region src/example.d.ts
5
+ interface Database {
6
+ users: {
7
+ id: number;
8
+ name: string;
9
+ email: string;
10
+ createdAt: Date;
11
+ };
12
+ posts: {
13
+ id: number;
14
+ title: string;
15
+ content: string;
16
+ userId: number;
17
+ createdAt: Date;
18
+ };
19
+ }
20
+ declare const builders: {
21
+ user: (attrs: Partial<kysely0.Insertable<DB[TableName]>>, factory: any, db: kysely0.Kysely<Database>, faker: FakerFactory) => Promise<kysely0.Selectable<DB[TableName]>>;
22
+ };
23
+ type Builders = typeof builders;
24
+ type Seeds = Record<string, any>;
25
+ //#endregion
26
+ export { Builders, Seeds };
@@ -0,0 +1,26 @@
1
+ import { FakerFactory } from "./faker-ChuHaYMR.mjs";
2
+ import * as kysely0 from "kysely";
3
+
4
+ //#region src/example.d.ts
5
+ interface Database {
6
+ users: {
7
+ id: number;
8
+ name: string;
9
+ email: string;
10
+ createdAt: Date;
11
+ };
12
+ posts: {
13
+ id: number;
14
+ title: string;
15
+ content: string;
16
+ userId: number;
17
+ createdAt: Date;
18
+ };
19
+ }
20
+ declare const builders: {
21
+ user: (attrs: Partial<kysely0.Insertable<DB[TableName]>>, factory: any, db: kysely0.Kysely<Database>, faker: FakerFactory) => Promise<kysely0.Selectable<DB[TableName]>>;
22
+ };
23
+ type Builders = typeof builders;
24
+ type Seeds = Record<string, any>;
25
+ //#endregion
26
+ export { Builders, Seeds };
package/dist/example.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import "./Factory-z2m01hMj.mjs";
2
- import "./faker-CxKkEeYi.mjs";
3
- import { KyselyFactory } from "./KyselyFactory-ELiHgHVv.mjs";
2
+ import "./faker-BGKYFoCT.mjs";
3
+ import { KyselyFactory } from "./KyselyFactory-C3Bc3p4L.mjs";
4
4
 
5
5
  //#region src/example.ts
6
6
  const userBuilder = KyselyFactory.createBuilder({
@@ -196,6 +196,36 @@ function resetAllSequences() {
196
196
  function price() {
197
197
  return +faker.commerce.price();
198
198
  }
199
+ function coordinateInRadius(center, radius) {
200
+ const earth = 6378137;
201
+ const d = radius / earth;
202
+ const theta = 2 * Math.PI * Math.random();
203
+ const r = d * Math.sqrt(Math.random());
204
+ const lat1 = center.lat * Math.PI / 180;
205
+ const lng1 = center.lng * Math.PI / 180;
206
+ const lat2 = Math.asin(Math.sin(lat1) * Math.cos(r) + Math.cos(lat1) * Math.sin(r) * Math.cos(theta));
207
+ const lng2 = lng1 + Math.atan2(Math.sin(theta) * Math.sin(r) * Math.cos(lat1), Math.cos(r) - Math.sin(lat1) * Math.sin(lat2));
208
+ return {
209
+ lat: lat2 * 180 / Math.PI,
210
+ lng: lng2 * 180 / Math.PI
211
+ };
212
+ }
213
+ function coordinateOutsideRadius(center, minRadiusMeters, maxRadiusMeters) {
214
+ const earth = 6378137;
215
+ const minD = minRadiusMeters / earth;
216
+ const maxD = maxRadiusMeters / earth;
217
+ const theta = 2 * Math.PI * Math.random();
218
+ const r = Math.sqrt(minD * minD + (maxD * maxD - minD * minD) * Math.random());
219
+ const lat1 = center.lat * Math.PI / 180;
220
+ const lng1 = center.lng * Math.PI / 180;
221
+ const lat2 = Math.asin(Math.sin(lat1) * Math.cos(r) + Math.cos(lat1) * Math.sin(r) * Math.cos(theta));
222
+ const lng2 = lng1 + Math.atan2(Math.sin(theta) * Math.sin(r) * Math.cos(lat1), Math.cos(r) - Math.sin(lat1) * Math.sin(lat2));
223
+ const normalizedLng = (lng2 * 180 / Math.PI + 540) % 360 - 180;
224
+ return {
225
+ lat: lat2 * 180 / Math.PI,
226
+ lng: normalizedLng
227
+ };
228
+ }
199
229
  /**
200
230
  * Enhanced faker instance with additional utility methods for testing.
201
231
  * Extends @faker-js/faker with custom methods for common test data generation patterns.
@@ -221,10 +251,20 @@ const faker = Object.freeze(Object.assign({}, __faker_js_faker.faker, {
221
251
  sequence,
222
252
  resetSequence,
223
253
  resetAllSequences,
224
- price
254
+ price,
255
+ coordinates: {
256
+ within: coordinateInRadius,
257
+ outside: coordinateOutsideRadius
258
+ }
225
259
  }));
226
260
 
227
261
  //#endregion
262
+ Object.defineProperty(exports, 'coordinateInRadius', {
263
+ enumerable: true,
264
+ get: function () {
265
+ return coordinateInRadius;
266
+ }
267
+ });
228
268
  Object.defineProperty(exports, 'faker', {
229
269
  enumerable: true,
230
270
  get: function () {
@@ -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 };
@@ -0,0 +1,165 @@
1
+ import * as _faker_js_faker4 from "@faker-js/faker";
2
+
3
+ //#region src/faker.d.ts
4
+
5
+ /**
6
+ * Generates random timestamp fields for database records.
7
+ * Creates a createdAt date in the past and an updatedAt date between creation and now.
8
+ * Milliseconds are set to 0 for cleaner database storage.
9
+ *
10
+ * @returns Object with createdAt and updatedAt Date fields
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const { createdAt, updatedAt } = timestamps();
15
+ * console.log(createdAt); // 2023-05-15T10:30:00.000Z
16
+ * console.log(updatedAt); // 2023-11-20T14:45:00.000Z
17
+ *
18
+ * // Use in factory
19
+ * const user = {
20
+ * name: 'John Doe',
21
+ * ...timestamps()
22
+ * };
23
+ * ```
24
+ */
25
+ declare function timestamps(): Timestamps;
26
+ /**
27
+ * Generates a reverse domain name identifier.
28
+ * Useful for creating unique identifiers that follow domain naming conventions.
29
+ *
30
+ * @param suffix - Optional suffix to append to the identifier
31
+ * @returns A reverse domain name string (e.g., "com.example.feature123")
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * console.log(identifier()); // "com.example.widget1"
36
+ * console.log(identifier('user')); // "org.acme.user"
37
+ * console.log(identifier('api')); // "net.demo.api"
38
+ * ```
39
+ */
40
+ declare function identifier(suffix?: string): string;
41
+ /**
42
+ * Generates sequential numbers for a named sequence.
43
+ * Useful for creating unique IDs or numbered test data.
44
+ * Each named sequence maintains its own counter.
45
+ *
46
+ * @param name - The sequence name (default: 'default')
47
+ * @returns The next number in the sequence
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * console.log(sequence()); // 1
52
+ * console.log(sequence()); // 2
53
+ * console.log(sequence('user')); // 1
54
+ * console.log(sequence('user')); // 2
55
+ * console.log(sequence()); // 3
56
+ *
57
+ * // Use in factories
58
+ * const email = `user${sequence('email')}@example.com`;
59
+ * ```
60
+ */
61
+ declare function sequence(name?: string): number;
62
+ /**
63
+ * Resets a named sequence counter to a specific value.
64
+ * Useful for resetting sequences between test suites.
65
+ *
66
+ * @param name - The sequence name to reset (default: 'default')
67
+ * @param value - The new starting value (default: 0)
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * sequence('user'); // 1
72
+ * sequence('user'); // 2
73
+ * resetSequence('user');
74
+ * sequence('user'); // 1
75
+ *
76
+ * resetSequence('order', 1000);
77
+ * sequence('order'); // 1001
78
+ * ```
79
+ */
80
+ declare function resetSequence(name?: string, value?: number): void;
81
+ /**
82
+ * Resets all sequence counters.
83
+ * Useful for cleaning up between test suites to ensure predictable sequences.
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * // In test setup
88
+ * beforeEach(() => {
89
+ * resetAllSequences();
90
+ * });
91
+ *
92
+ * it('starts sequences from 1', () => {
93
+ * expect(sequence()).toBe(1);
94
+ * expect(sequence('user')).toBe(1);
95
+ * });
96
+ * ```
97
+ */
98
+ declare function resetAllSequences(): void;
99
+ /**
100
+ * Generates a random price as a number.
101
+ * Converts faker's string price to a numeric value.
102
+ *
103
+ * @returns A random price number
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * const productPrice = price(); // 29.99
108
+ * const total = price() * quantity; // Numeric calculation
109
+ * ```
110
+ */
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;
118
+ /**
119
+ * Enhanced faker instance with additional utility methods for testing.
120
+ * Extends @faker-js/faker with custom methods for common test data generation patterns.
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * import { faker } from '@geekmidas/testkit';
125
+ *
126
+ * // Use standard faker methods
127
+ * const name = faker.person.fullName();
128
+ * const email = faker.internet.email();
129
+ *
130
+ * // Use custom extensions
131
+ * const { createdAt, updatedAt } = faker.timestamps();
132
+ * const id = faker.identifier('user');
133
+ * const orderNumber = faker.sequence('order');
134
+ * const productPrice = faker.price();
135
+ * ```
136
+ */
137
+ declare const faker$1: Readonly<_faker_js_faker4.Faker & {
138
+ timestamps: typeof timestamps;
139
+ identifier: typeof identifier;
140
+ sequence: typeof sequence;
141
+ resetSequence: typeof resetSequence;
142
+ resetAllSequences: typeof resetAllSequences;
143
+ price: typeof price;
144
+ coordinates: {
145
+ within: typeof coordinateInRadius;
146
+ outside: typeof coordinateOutsideRadius;
147
+ };
148
+ }>;
149
+ /**
150
+ * Type definition for timestamp fields.
151
+ * Used by the timestamps() function to generate date fields.
152
+ */
153
+ type Timestamps = {
154
+ /** The creation date */
155
+ createdAt: Date;
156
+ /** The last update date */
157
+ updatedAt: Date;
158
+ };
159
+ /**
160
+ * Type definition for the enhanced faker factory.
161
+ * Includes all standard faker methods plus custom extensions.
162
+ */
163
+ type FakerFactory = typeof faker$1;
164
+ //#endregion
165
+ export { FakerFactory, Timestamps, coordinateInRadius, faker$1 as faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };