@schmock/faker 2.2.2 → 2.3.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.
- package/dist/field-mappings.d.ts.map +1 -1
- package/dist/field-mappings.js +8 -1
- package/dist/field-name-matcher.d.ts.map +1 -1
- package/dist/field-name-matcher.js +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/jsf-config.d.ts +11 -1
- package/dist/jsf-config.d.ts.map +1 -1
- package/dist/jsf-config.js +93 -11
- package/dist/overrides.d.ts.map +1 -1
- package/dist/overrides.js +20 -14
- package/dist/schema-enhancement.d.ts.map +1 -1
- package/dist/schema-enhancement.js +18 -3
- package/dist/test-utils.d.ts +9 -9
- package/dist/test-utils.d.ts.map +1 -1
- package/dist/test-utils.js +25 -12
- package/dist/validation.js +1 -1
- package/package.json +4 -4
- package/src/field-mappings.ts +8 -1
- package/src/field-name-matcher.ts +4 -5
- package/src/index.test.ts +102 -0
- package/src/index.ts +59 -42
- package/src/jsf-config.test.ts +65 -0
- package/src/jsf-config.ts +129 -21
- package/src/overrides.ts +23 -20
- package/src/performance.test.ts +274 -327
- package/src/post-process.test.ts +87 -61
- package/src/schema-enhancement.test.ts +8 -2
- package/src/schema-enhancement.ts +24 -8
- package/src/steps/deterministic-seeds.steps.ts +77 -0
- package/src/steps/faker-plugin.steps.ts +198 -6
- package/src/test-utils.ts +48 -28
- package/src/validation.ts +1 -1
package/src/overrides.ts
CHANGED
|
@@ -3,6 +3,10 @@ import { DEFAULT_ARRAY_COUNT } from "./constants.js";
|
|
|
3
3
|
|
|
4
4
|
const DANGEROUS_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
5
5
|
|
|
6
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
7
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
/**
|
|
7
11
|
* Determine number of items to generate for array schema
|
|
8
12
|
* Prefers explicit count, then schema minItems/maxItems, with sane defaults
|
|
@@ -37,6 +41,10 @@ export function determineArrayCount(
|
|
|
37
41
|
return Math.min(schema.maxItems, DEFAULT_ARRAY_COUNT);
|
|
38
42
|
}
|
|
39
43
|
|
|
44
|
+
if (Array.isArray(schema.items)) {
|
|
45
|
+
return schema.items.length;
|
|
46
|
+
}
|
|
47
|
+
|
|
40
48
|
return DEFAULT_ARRAY_COUNT;
|
|
41
49
|
}
|
|
42
50
|
|
|
@@ -58,9 +66,9 @@ export function applyOverrides(
|
|
|
58
66
|
query?: Record<string, string>,
|
|
59
67
|
): unknown {
|
|
60
68
|
if (!overrides) return data;
|
|
61
|
-
if (
|
|
69
|
+
if (!isRecord(data)) return data;
|
|
62
70
|
|
|
63
|
-
const result = structuredClone(data)
|
|
71
|
+
const result = structuredClone(data);
|
|
64
72
|
|
|
65
73
|
for (const [key, value] of Object.entries(overrides)) {
|
|
66
74
|
if (DANGEROUS_KEYS.has(key)) continue;
|
|
@@ -69,23 +77,18 @@ export function applyOverrides(
|
|
|
69
77
|
setNestedProperty(result, key, value, { params, state, query });
|
|
70
78
|
} else {
|
|
71
79
|
// Handle flat keys and nested objects
|
|
72
|
-
if (
|
|
73
|
-
typeof value === "object" &&
|
|
74
|
-
value !== null &&
|
|
75
|
-
!Array.isArray(value)
|
|
76
|
-
) {
|
|
77
|
-
const nested = value as Record<string, unknown>;
|
|
80
|
+
if (isRecord(value)) {
|
|
78
81
|
// Recursively apply nested overrides
|
|
79
|
-
if (result[key]
|
|
82
|
+
if (isRecord(result[key])) {
|
|
80
83
|
result[key] = applyOverrides(
|
|
81
84
|
result[key],
|
|
82
|
-
|
|
85
|
+
value,
|
|
83
86
|
params,
|
|
84
87
|
state,
|
|
85
88
|
query,
|
|
86
89
|
);
|
|
87
90
|
} else {
|
|
88
|
-
result[key] = applyOverrides({},
|
|
91
|
+
result[key] = applyOverrides({}, value, params, state, query);
|
|
89
92
|
}
|
|
90
93
|
} else if (typeof value === "string" && value.includes("{{")) {
|
|
91
94
|
// Template processing
|
|
@@ -112,14 +115,14 @@ function setNestedProperty(
|
|
|
112
115
|
for (let i = 0; i < parts.length - 1; i++) {
|
|
113
116
|
const part = parts[i];
|
|
114
117
|
if (DANGEROUS_KEYS.has(part)) return;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
current[part] =
|
|
118
|
+
const next = current[part];
|
|
119
|
+
if (isRecord(next)) {
|
|
120
|
+
current = next;
|
|
121
|
+
} else {
|
|
122
|
+
const nested: Record<string, unknown> = {};
|
|
123
|
+
current[part] = nested;
|
|
124
|
+
current = nested;
|
|
121
125
|
}
|
|
122
|
-
current = current[part] as Record<string, unknown>;
|
|
123
126
|
}
|
|
124
127
|
|
|
125
128
|
// Set the final property
|
|
@@ -146,8 +149,8 @@ function resolveTemplatePath(
|
|
|
146
149
|
let result: unknown = context;
|
|
147
150
|
|
|
148
151
|
for (const part of parts) {
|
|
149
|
-
if (result
|
|
150
|
-
result =
|
|
152
|
+
if (isRecord(result)) {
|
|
153
|
+
result = result[part];
|
|
151
154
|
} else {
|
|
152
155
|
return undefined;
|
|
153
156
|
}
|