@anatine/zod-mock
Advanced tools
Comparing version 3.5.8 to 3.5.9
@@ -5,2 +5,4 @@ # Changelog | ||
### [3.5.9](https://github.com/anatine/zod-plugins/compare/zod-mock-3.5.8...zod-mock-3.5.9) (2022-09-05) | ||
### [3.5.8](https://github.com/anatine/zod-plugins/compare/zod-mock-3.5.7...zod-mock-3.5.8) (2022-09-05) | ||
@@ -7,0 +9,0 @@ |
{ | ||
"name": "@anatine/zod-mock", | ||
"version": "3.5.8", | ||
"version": "3.5.9", | ||
"description": "Zod auto-mock object generator using Faker at @faker-js/faker", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -17,4 +17,11 @@ import { z, ZodTypeAny } from 'zod'; | ||
backupMocks?: Record<string, () => any | undefined>; | ||
/** | ||
* How many entries to create for records | ||
*/ | ||
recordKeysLength?: number; | ||
/** | ||
* How many entries to create for Maps | ||
*/ | ||
mapEntriesLength?: number; | ||
} | ||
export declare function generateMock<T extends ZodTypeAny>(zodRef: T, options?: GenerateMockOptions): z.infer<typeof zodRef>; |
@@ -211,2 +211,26 @@ "use strict"; | ||
} | ||
function parseSet(zodRef, options) { | ||
var _a, _b; | ||
let min = ((_a = zodRef._def.minSize) === null || _a === void 0 ? void 0 : _a.value) != null ? zodRef._def.minSize.value : 1; | ||
const max = ((_b = zodRef._def.maxSize) === null || _b === void 0 ? void 0 : _b.value) != null ? zodRef._def.maxSize.value : 5; | ||
// prevents arrays from exceeding the max regardless of the min. | ||
if (min > max) { | ||
min = max; | ||
} | ||
const targetLength = faker_1.faker.datatype.number({ min, max }); | ||
const results = new Set(); | ||
while (results.size < targetLength) { | ||
results.add(generateMock(zodRef._def.valueType, options)); | ||
} | ||
return results; | ||
} | ||
function parseMap(zodRef, options) { | ||
var _a; | ||
const targetLength = (_a = options === null || options === void 0 ? void 0 : options.mapEntriesLength) !== null && _a !== void 0 ? _a : 1; | ||
const results = new Map(); | ||
while (results.size < targetLength) { | ||
results.set(generateMock(zodRef._def.keyType, options), generateMock(zodRef._def.valueType, options)); | ||
} | ||
return results; | ||
} | ||
function parseEnum(zodRef) { | ||
@@ -262,2 +286,4 @@ const values = zodRef._def.values; | ||
ZodUnion: parseUnion, | ||
ZodSet: parseSet, | ||
ZodMap: parseMap, | ||
ZodDiscriminatedUnion: parseDiscriminatedUnion, | ||
@@ -264,0 +290,0 @@ }; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35417
355