@schmock/faker 1.8.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -1,83 +1,16 @@
1
1
  /// <reference path="../../core/schmock.d.ts" />
2
2
 
3
- import { en, Faker } from "@faker-js/faker";
4
3
  import {
5
4
  ResourceLimitError,
6
5
  SchemaGenerationError,
7
6
  SchemaValidationError,
8
7
  } from "@schmock/core";
9
8
  import type { JSONSchema7 } from "json-schema";
10
- import jsf from "json-schema-faker";
11
-
12
- function isJSONSchema7(value: unknown): value is JSONSchema7 {
13
- return typeof value === "object" && value !== null && !Array.isArray(value);
14
- }
15
-
16
- /** JSONSchema7 extended with json-schema-faker's `faker` property */
17
- interface FakerSchema extends JSONSchema7 {
18
- faker?: string;
19
- }
20
-
21
- /**
22
- * Create isolated faker instance to avoid race conditions
23
- * Each generation gets its own faker instance to ensure thread-safety
24
- * @returns Fresh Faker instance with English locale
25
- */
26
- function createFakerInstance(seed?: number) {
27
- const faker = new Faker({ locale: [en] });
28
- if (seed !== undefined) {
29
- faker.seed(seed);
30
- }
31
- return faker;
32
- }
33
-
34
- let jsfConfigured = false;
35
- let currentSeed: number | undefined;
36
-
37
- /**
38
- * Create a seeded PRNG using the mulberry32 algorithm.
39
- * Returns a function that produces deterministic values in [0, 1).
40
- */
41
- function createSeededRandom(seed: number): () => number {
42
- let state = seed | 0;
43
- return () => {
44
- state = (state + 0x6d2b79f5) | 0;
45
- let t = state;
46
- t = Math.imul(t ^ (t >>> 15), t | 1);
47
- t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
48
- return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
49
- };
50
- }
51
-
52
- function getJsf(seed?: number) {
53
- const seedChanged = seed !== currentSeed;
54
- if (!jsfConfigured || seedChanged) {
55
- currentSeed = seed;
56
- jsf.extend("faker", () => createFakerInstance(seed));
57
- jsf.option({
58
- requiredOnly: false,
59
- alwaysFakeOptionals: true,
60
- useDefaultValue: true,
61
- ignoreMissingRefs: true,
62
- failOnInvalidTypes: false,
63
- failOnInvalidFormat: false,
64
- });
65
- jsfConfigured = true;
66
- }
67
- // Always reset PRNG for deterministic output per call
68
- if (seed !== undefined) {
69
- jsf.option({ random: createSeededRandom(seed) });
70
- jsf.extend("faker", () => createFakerInstance(seed));
71
- }
72
- return jsf;
73
- }
74
-
75
- // Resource limits for safety
76
- const MAX_ARRAY_SIZE = 10000;
77
- const MAX_NESTING_DEPTH = 10; // Reasonable limit for schema nesting
78
- const DEFAULT_ARRAY_COUNT = 3; // Default items to generate when not specified
79
- const DEEP_NESTING_THRESHOLD = 3; // Depth at which to check for memory risks
80
- const LARGE_ARRAY_THRESHOLD = 100; // Array size considered "large"
9
+ import { MAX_ARRAY_SIZE } from "./constants.js";
10
+ import { getJsf } from "./jsf-config.js";
11
+ import { applyOverrides, determineArrayCount } from "./overrides.js";
12
+ import { enhanceSchemaWithSmartMapping } from "./schema-enhancement.js";
13
+ import { validateSchema } from "./validation.js";
81
14
 
82
15
  export interface SchemaGenerationContext {
83
16
  schema: JSONSchema7;
@@ -192,678 +125,3 @@ export function generateFromSchema(options: SchemaGenerationContext): any {
192
125
 
193
126
  return generated;
194
127
  }
195
-
196
- /**
197
- * Validate JSON Schema structure and enforce resource limits
198
- * Checks for malformed schemas, circular references, excessive nesting,
199
- * and dangerous patterns that could cause memory issues
200
- * @param schema - JSON Schema to validate
201
- * @param path - Current path in schema tree (for error messages)
202
- * @throws {SchemaValidationError} When schema structure is invalid
203
- * @throws {ResourceLimitError} When schema exceeds safety limits
204
- */
205
- function validateSchema(schema: JSONSchema7, path = "$"): void {
206
- if (!schema || typeof schema !== "object") {
207
- throw new SchemaValidationError(
208
- path,
209
- "Schema must be a valid JSON Schema object",
210
- );
211
- }
212
-
213
- if (Object.keys(schema).length === 0) {
214
- throw new SchemaValidationError(path, "Schema cannot be empty");
215
- }
216
-
217
- // Check for invalid schema types
218
- const validTypes = [
219
- "object",
220
- "array",
221
- "string",
222
- "number",
223
- "integer",
224
- "boolean",
225
- "null",
226
- ];
227
- if (
228
- schema.type &&
229
- typeof schema.type === "string" &&
230
- !validTypes.includes(schema.type)
231
- ) {
232
- throw new SchemaValidationError(
233
- path,
234
- `Invalid schema type: "${schema.type}"`,
235
- "Supported types are: object, array, string, number, integer, boolean, null",
236
- );
237
- }
238
-
239
- // Check for malformed properties (must be object, not string)
240
- if (schema.type === "object" && schema.properties) {
241
- if (
242
- typeof schema.properties !== "object" ||
243
- Array.isArray(schema.properties)
244
- ) {
245
- throw new SchemaValidationError(
246
- `${path}.properties`,
247
- "Properties must be an object mapping property names to schemas",
248
- 'Use { "propertyName": { "type": "string" } } format',
249
- );
250
- }
251
-
252
- // Validate each property recursively
253
- for (const [propName, propSchema] of Object.entries(schema.properties)) {
254
- if (typeof propSchema === "object" && propSchema !== null) {
255
- // Check for invalid faker methods in property schemas
256
- const fakerProp =
257
- "faker" in propSchema ? String(propSchema.faker) : undefined;
258
- if (fakerProp) {
259
- try {
260
- validateFakerMethod(fakerProp);
261
- } catch (error: unknown) {
262
- // Re-throw with proper path context
263
- if (error instanceof SchemaValidationError) {
264
- const ctx = error.context;
265
- let issue = "Invalid faker method";
266
- let suggestion: string | undefined;
267
- if (ctx && typeof ctx === "object") {
268
- if ("issue" in ctx && typeof ctx.issue === "string")
269
- issue = ctx.issue;
270
- if ("suggestion" in ctx && typeof ctx.suggestion === "string")
271
- suggestion = ctx.suggestion;
272
- }
273
- throw new SchemaValidationError(
274
- `${path}.properties.${propName}.faker`,
275
- issue,
276
- suggestion,
277
- );
278
- }
279
- if (error instanceof Error) throw error;
280
- throw new Error(String(error));
281
- }
282
- }
283
- validateSchema(propSchema, `${path}.properties.${propName}`);
284
- }
285
- }
286
- }
287
-
288
- // Check for invalid array items
289
- if (schema.type === "array") {
290
- // Array must have items defined and non-null
291
- if (schema.items === null || schema.items === undefined) {
292
- throw new SchemaValidationError(
293
- `${path}.items`,
294
- "Array schema must have valid items definition",
295
- "Define items as a schema object or array of schemas",
296
- );
297
- }
298
-
299
- if (Array.isArray(schema.items)) {
300
- if (schema.items.length === 0) {
301
- throw new SchemaValidationError(
302
- `${path}.items`,
303
- "Array items cannot be empty array",
304
- "Provide at least one item schema",
305
- );
306
- }
307
- schema.items.forEach((item, index) => {
308
- if (typeof item === "object" && item !== null) {
309
- validateSchema(item, `${path}.items[${index}]`);
310
- }
311
- });
312
- } else if (typeof schema.items === "object" && schema.items !== null) {
313
- validateSchema(schema.items, `${path}.items`);
314
- }
315
- }
316
-
317
- // Check for circular references
318
- if (hasCircularReference(schema)) {
319
- throw new SchemaValidationError(
320
- path,
321
- "Schema contains circular references which are not supported",
322
- );
323
- }
324
-
325
- // Check nesting depth
326
- const depth = calculateNestingDepth(schema);
327
- if (depth > MAX_NESTING_DEPTH) {
328
- throw new ResourceLimitError(
329
- "schema_nesting_depth",
330
- MAX_NESTING_DEPTH,
331
- depth,
332
- );
333
- }
334
-
335
- // Check for dangerous combination of deep nesting + large arrays
336
- if (depth >= 4) {
337
- checkForDeepNestingWithArrays(schema, path);
338
- }
339
-
340
- // Check for potentially dangerous array sizes in schema definition
341
- checkArraySizeLimits(schema, path);
342
-
343
- // Check for forbidden features
344
- if (schema.$ref === "#") {
345
- throw new SchemaValidationError(
346
- path,
347
- "Self-referencing schemas are not supported",
348
- );
349
- }
350
- }
351
-
352
- /**
353
- * Detect circular references in JSON Schema using path-based traversal
354
- * Uses backtracking to distinguish between cycles and legitimate schema reuse
355
- * @param schema - Schema to check for cycles
356
- * @param currentPath - Set of schemas currently in traversal path
357
- * @returns true if circular reference detected, false otherwise
358
- * @example
359
- * // Detects: schema A -> B -> A (cycle)
360
- * // Allows: schema A -> B, A -> C (reuse of A)
361
- */
362
- function hasCircularReference(
363
- schema: JSONSchema7,
364
- currentPath = new Set(),
365
- ): boolean {
366
- // Check if this schema is currently being traversed (cycle detected)
367
- if (currentPath.has(schema)) {
368
- return true;
369
- }
370
-
371
- if (schema.$ref === "#") {
372
- return true;
373
- }
374
-
375
- // Add to current path for this traversal branch
376
- currentPath.add(schema);
377
-
378
- if (schema.type === "object" && schema.properties) {
379
- for (const prop of Object.values(schema.properties)) {
380
- if (isJSONSchema7(prop)) {
381
- if (hasCircularReference(prop, currentPath)) {
382
- return true;
383
- }
384
- }
385
- }
386
- }
387
-
388
- if (schema.type === "array" && schema.items) {
389
- const items = Array.isArray(schema.items) ? schema.items : [schema.items];
390
- for (const item of items) {
391
- if (isJSONSchema7(item)) {
392
- if (hasCircularReference(item, currentPath)) {
393
- return true;
394
- }
395
- }
396
- }
397
- }
398
-
399
- // Remove from current path after checking all children (backtrack)
400
- currentPath.delete(schema);
401
-
402
- return false;
403
- }
404
-
405
- /**
406
- * Calculate maximum nesting depth of a JSON Schema
407
- * Recursively traverses object properties and array items
408
- * @param schema - Schema to measure
409
- * @param depth - Current depth (internal recursion parameter)
410
- * @returns Maximum nesting depth found
411
- */
412
- function calculateNestingDepth(schema: JSONSchema7, depth = 0): number {
413
- if (depth > MAX_NESTING_DEPTH) {
414
- return depth;
415
- }
416
-
417
- let maxDepth = depth;
418
-
419
- if (schema.type === "object" && schema.properties) {
420
- for (const prop of Object.values(schema.properties)) {
421
- if (isJSONSchema7(prop)) {
422
- maxDepth = Math.max(maxDepth, calculateNestingDepth(prop, depth + 1));
423
- }
424
- }
425
- }
426
-
427
- if (schema.type === "array" && schema.items) {
428
- const items = Array.isArray(schema.items) ? schema.items : [schema.items];
429
- for (const item of items) {
430
- if (isJSONSchema7(item)) {
431
- maxDepth = Math.max(maxDepth, calculateNestingDepth(item, depth + 1));
432
- }
433
- }
434
- }
435
-
436
- return maxDepth;
437
- }
438
-
439
- /**
440
- * Check for dangerous patterns of deep nesting combined with large arrays
441
- * Prevents memory issues from schemas like: depth 3+ with 100+ item arrays
442
- * @param schema - Schema to check
443
- * @param _path - Path in schema (unused but kept for signature consistency)
444
- * @throws {ResourceLimitError} When dangerous nesting pattern detected
445
- */
446
- function checkForDeepNestingWithArrays(
447
- schema: JSONSchema7,
448
- _path: string,
449
- ): void {
450
- // Look for arrays in deeply nested structures that could cause memory issues
451
- function findArraysInDeepNesting(
452
- node: JSONSchema7,
453
- currentDepth: number,
454
- ): boolean {
455
- const schemaType = node.type;
456
- const isArray = Array.isArray(schemaType)
457
- ? schemaType.includes("array")
458
- : schemaType === "array";
459
-
460
- if (isArray) {
461
- const maxItems = node.maxItems || DEFAULT_ARRAY_COUNT;
462
- // Be more aggressive about deep nesting detection
463
- if (
464
- currentDepth >= DEEP_NESTING_THRESHOLD &&
465
- maxItems >= LARGE_ARRAY_THRESHOLD
466
- ) {
467
- throw new ResourceLimitError(
468
- "deep_nesting_memory_risk",
469
- DEEP_NESTING_THRESHOLD * LARGE_ARRAY_THRESHOLD,
470
- currentDepth * maxItems,
471
- );
472
- }
473
-
474
- // Check items if they exist
475
- if (node.items) {
476
- const items = Array.isArray(node.items) ? node.items : [node.items];
477
- for (const item of items) {
478
- if (isJSONSchema7(item)) {
479
- if (findArraysInDeepNesting(item, currentDepth + 1)) {
480
- return true;
481
- }
482
- }
483
- }
484
- }
485
-
486
- return true;
487
- }
488
-
489
- if (schemaType === "object" && node.properties) {
490
- for (const prop of Object.values(node.properties)) {
491
- if (isJSONSchema7(prop)) {
492
- if (findArraysInDeepNesting(prop, currentDepth + 1)) {
493
- return true;
494
- }
495
- }
496
- }
497
- }
498
-
499
- return false;
500
- }
501
-
502
- findArraysInDeepNesting(schema, 0);
503
- }
504
-
505
- function checkArraySizeLimits(schema: JSONSchema7, path: string): void {
506
- // Recursively check all array constraints in the schema
507
- if (schema.type === "array") {
508
- // Check for dangerously large maxItems
509
- if (schema.maxItems && schema.maxItems > MAX_ARRAY_SIZE) {
510
- throw new ResourceLimitError(
511
- "array_max_items",
512
- MAX_ARRAY_SIZE,
513
- schema.maxItems,
514
- );
515
- }
516
-
517
- // Check for combination of deep nesting and large arrays
518
- const depth = calculateNestingDepth(schema);
519
- const estimatedSize =
520
- schema.maxItems || schema.minItems || DEFAULT_ARRAY_COUNT;
521
-
522
- // If we have deep nesting and large arrays, it could cause memory issues
523
- if (
524
- depth > DEEP_NESTING_THRESHOLD &&
525
- estimatedSize > LARGE_ARRAY_THRESHOLD
526
- ) {
527
- throw new ResourceLimitError(
528
- "memory_estimation",
529
- DEEP_NESTING_THRESHOLD * LARGE_ARRAY_THRESHOLD,
530
- depth * estimatedSize,
531
- );
532
- }
533
- }
534
-
535
- // Recursively check nested schemas
536
- if (schema.type === "object" && schema.properties) {
537
- for (const [propName, propSchema] of Object.entries(schema.properties)) {
538
- if (isJSONSchema7(propSchema)) {
539
- checkArraySizeLimits(propSchema, `${path}.properties.${propName}`);
540
- }
541
- }
542
- }
543
-
544
- if (schema.type === "array" && schema.items) {
545
- if (Array.isArray(schema.items)) {
546
- schema.items.forEach((item, index) => {
547
- if (isJSONSchema7(item)) {
548
- checkArraySizeLimits(item, `${path}.items[${index}]`);
549
- }
550
- });
551
- } else if (isJSONSchema7(schema.items)) {
552
- checkArraySizeLimits(schema.items, `${path}.items`);
553
- }
554
- }
555
- }
556
-
557
- /**
558
- * Determine number of items to generate for array schema
559
- * Prefers explicit count, then schema minItems/maxItems, with sane defaults
560
- * @param schema - Array schema with optional minItems/maxItems
561
- * @param explicitCount - Explicit count override from plugin options
562
- * @returns Number of array items to generate
563
- */
564
- function determineArrayCount(
565
- schema: JSONSchema7,
566
- explicitCount?: number,
567
- ): number {
568
- if (explicitCount !== undefined) {
569
- // Handle negative or invalid counts
570
- if (explicitCount < 0) {
571
- return 0;
572
- }
573
- return explicitCount;
574
- }
575
-
576
- if (schema.minItems !== undefined && schema.maxItems !== undefined) {
577
- return (
578
- Math.floor(Math.random() * (schema.maxItems - schema.minItems + 1)) +
579
- schema.minItems
580
- );
581
- }
582
-
583
- if (schema.minItems !== undefined) {
584
- return Math.max(schema.minItems, DEFAULT_ARRAY_COUNT);
585
- }
586
-
587
- if (schema.maxItems !== undefined) {
588
- return Math.min(schema.maxItems, DEFAULT_ARRAY_COUNT);
589
- }
590
-
591
- return DEFAULT_ARRAY_COUNT;
592
- }
593
-
594
- /**
595
- * Apply overrides to generated data with support for templates
596
- * Supports nested paths (dot notation), templates with {{params.id}}, and state access
597
- * @param data - Generated data to apply overrides to
598
- * @param overrides - Override values (can use templates)
599
- * @param params - Route parameters for template expansion
600
- * @param state - Plugin state for template expansion
601
- * @param query - Query parameters for template expansion
602
- * @returns Data with overrides applied
603
- */
604
- function applyOverrides(
605
- data: any,
606
- overrides?: Record<string, any>,
607
- params?: Record<string, string>,
608
- state?: any,
609
- query?: Record<string, string>,
610
- ): any {
611
- if (!overrides) return data;
612
-
613
- const result = structuredClone(data);
614
-
615
- for (const [key, value] of Object.entries(overrides)) {
616
- // Handle nested paths like "data.id" or "pagination.page"
617
- if (key.includes(".")) {
618
- setNestedProperty(result, key, value, { params, state, query });
619
- } else {
620
- // Handle flat keys and nested objects
621
- if (
622
- typeof value === "object" &&
623
- value !== null &&
624
- !Array.isArray(value)
625
- ) {
626
- // Recursively apply nested overrides
627
- if (result[key] && typeof result[key] === "object") {
628
- result[key] = applyOverrides(
629
- result[key],
630
- value,
631
- params,
632
- state,
633
- query,
634
- );
635
- } else {
636
- result[key] = applyOverrides({}, value, params, state, query);
637
- }
638
- } else if (typeof value === "string" && value.includes("{{")) {
639
- // Template processing
640
- result[key] = processTemplate(value, { params, state, query });
641
- } else {
642
- result[key] = value;
643
- }
644
- }
645
- }
646
-
647
- return result;
648
- }
649
-
650
- function setNestedProperty(
651
- obj: any,
652
- path: string,
653
- value: any,
654
- context: {
655
- params?: Record<string, string>;
656
- state?: any;
657
- query?: Record<string, string>;
658
- },
659
- ): void {
660
- const parts = path.split(".");
661
- let current = obj;
662
-
663
- // Navigate to the parent of the target property
664
- for (let i = 0; i < parts.length - 1; i++) {
665
- const part = parts[i];
666
- if (
667
- !(part in current) ||
668
- typeof current[part] !== "object" ||
669
- current[part] === null
670
- ) {
671
- current[part] = {};
672
- }
673
- current = current[part];
674
- }
675
-
676
- // Set the final property
677
- const finalKey = parts[parts.length - 1];
678
- if (typeof value === "string" && value.includes("{{")) {
679
- current[finalKey] = processTemplate(value, context);
680
- } else {
681
- current[finalKey] = value;
682
- }
683
- }
684
-
685
- function processTemplate(
686
- template: string,
687
- context: {
688
- params?: Record<string, string>;
689
- state?: any;
690
- query?: Record<string, string>;
691
- },
692
- ): any {
693
- // Check if the template is just a single template expression
694
- const singleTemplateMatch = template.match(/^\{\{\s*([^}]+)\s*\}\}$/);
695
- if (singleTemplateMatch) {
696
- // For single templates, return the actual value without string conversion
697
- const expression = singleTemplateMatch[1];
698
- const parts = expression.trim().split(".");
699
- let result: any = context;
700
-
701
- for (const part of parts) {
702
- if (result && typeof result === "object") {
703
- result = result[part];
704
- } else {
705
- return template; // Return original if can't resolve
706
- }
707
- }
708
-
709
- return result !== undefined ? result : template;
710
- }
711
-
712
- // For templates mixed with other text, do string replacement
713
- const processed = template.replace(
714
- /\{\{\s*([^}]+)\s*\}\}/g,
715
- (match, expression) => {
716
- const parts = expression.trim().split(".");
717
- let result: any = context;
718
-
719
- for (const part of parts) {
720
- if (result && typeof result === "object") {
721
- result = result[part];
722
- } else {
723
- return match; // Return original if can't resolve
724
- }
725
- }
726
-
727
- return result !== undefined ? String(result) : match;
728
- },
729
- );
730
-
731
- return processed;
732
- }
733
-
734
- /**
735
- * Validate that faker method string references a valid Faker.js API
736
- * Checks format (namespace.method) and validates against known namespaces
737
- * @param fakerMethod - Faker method string (e.g., "person.fullName")
738
- * @throws {SchemaValidationError} When faker method format or namespace is invalid
739
- */
740
- function validateFakerMethod(fakerMethod: string): void {
741
- // Check if faker method follows valid format (namespace.method)
742
- const parts = fakerMethod.split(".");
743
- if (parts.length < 2) {
744
- throw new SchemaValidationError(
745
- "$.faker",
746
- `Invalid faker method format: "${fakerMethod}"`,
747
- "Use format like 'person.firstName' or 'internet.email'",
748
- );
749
- }
750
-
751
- // Validate by resolving the method path on a real faker instance
752
- const faker = createFakerInstance();
753
- let current: any = faker;
754
- for (const part of parts) {
755
- if (current && typeof current === "object" && part in current) {
756
- current = current[part];
757
- } else {
758
- throw new SchemaValidationError(
759
- "$.faker",
760
- `Invalid faker method: "${fakerMethod}"`,
761
- "Check faker.js documentation for valid methods",
762
- );
763
- }
764
- }
765
- if (typeof current !== "function") {
766
- throw new SchemaValidationError(
767
- "$.faker",
768
- `Invalid faker method: "${fakerMethod}" is not a function`,
769
- "Check faker.js documentation for valid methods",
770
- );
771
- }
772
- }
773
-
774
- function enhanceSchemaWithSmartMapping(schema: JSONSchema7): JSONSchema7 {
775
- if (!schema || typeof schema !== "object") {
776
- return schema;
777
- }
778
-
779
- const enhanced = { ...schema };
780
-
781
- // Handle object properties
782
- if (enhanced.type === "object" && enhanced.properties) {
783
- enhanced.properties = { ...enhanced.properties };
784
-
785
- for (const [fieldName, fieldSchema] of Object.entries(
786
- enhanced.properties,
787
- )) {
788
- if (isJSONSchema7(fieldSchema)) {
789
- enhanced.properties[fieldName] = enhanceFieldSchema(
790
- fieldName,
791
- fieldSchema,
792
- );
793
- }
794
- }
795
- }
796
-
797
- return enhanced;
798
- }
799
-
800
- function enhanceFieldSchema(
801
- fieldName: string,
802
- fieldSchema: JSONSchema7,
803
- ): FakerSchema {
804
- const enhanced: FakerSchema = { ...fieldSchema };
805
-
806
- // If already has faker extension, validate it and don't override
807
- if (enhanced.faker) {
808
- validateFakerMethod(enhanced.faker);
809
- return enhanced;
810
- }
811
-
812
- // Apply smart field name mapping
813
- const lowerFieldName = fieldName.toLowerCase();
814
-
815
- // Email fields
816
- if (lowerFieldName.includes("email")) {
817
- enhanced.format = "email";
818
- enhanced.faker = "internet.email";
819
- }
820
- // Name fields
821
- else if (lowerFieldName === "firstname" || lowerFieldName === "first_name") {
822
- enhanced.faker = "person.firstName";
823
- } else if (lowerFieldName === "lastname" || lowerFieldName === "last_name") {
824
- enhanced.faker = "person.lastName";
825
- } else if (lowerFieldName === "name" || lowerFieldName === "fullname") {
826
- enhanced.faker = "person.fullName";
827
- }
828
- // Phone fields
829
- else if (lowerFieldName.includes("phone") || lowerFieldName === "mobile") {
830
- enhanced.faker = "phone.number";
831
- }
832
- // Address fields
833
- else if (lowerFieldName === "street" || lowerFieldName === "address") {
834
- enhanced.faker = "location.streetAddress";
835
- } else if (lowerFieldName === "city") {
836
- enhanced.faker = "location.city";
837
- } else if (lowerFieldName === "zipcode" || lowerFieldName === "zip") {
838
- enhanced.faker = "location.zipCode";
839
- }
840
- // UUID fields
841
- else if (
842
- lowerFieldName === "uuid" ||
843
- (lowerFieldName === "id" && enhanced.format === "uuid")
844
- ) {
845
- enhanced.faker = "string.uuid";
846
- }
847
- // Date fields
848
- else if (
849
- lowerFieldName.includes("createdat") ||
850
- lowerFieldName.includes("created_at") ||
851
- lowerFieldName.includes("updatedat") ||
852
- lowerFieldName.includes("updated_at")
853
- ) {
854
- enhanced.format = "date-time";
855
- enhanced.faker = "date.recent";
856
- }
857
- // Company fields
858
- else if (lowerFieldName.includes("company")) {
859
- enhanced.faker = "company.name";
860
- } else if (lowerFieldName === "position" || lowerFieldName === "jobtitle") {
861
- enhanced.faker = "person.jobTitle";
862
- }
863
- // Price/money fields
864
- else if (lowerFieldName === "price" || lowerFieldName === "amount") {
865
- enhanced.faker = "commerce.price";
866
- }
867
-
868
- return enhanced;
869
- }