@anatine/zod-mock
Advanced tools
Comparing version 3.5.9 to 3.5.10
@@ -5,2 +5,4 @@ # Changelog | ||
### [3.5.10](https://github.com/anatine/zod-plugins/compare/zod-mock-3.5.9...zod-mock-3.5.10) (2022-09-12) | ||
### [3.5.9](https://github.com/anatine/zod-plugins/compare/zod-mock-3.5.8...zod-mock-3.5.9) (2022-09-05) | ||
@@ -7,0 +9,0 @@ |
{ | ||
"name": "@anatine/zod-mock", | ||
"version": "3.5.9", | ||
"version": "3.5.10", | ||
"description": "Zod auto-mock object generator using Faker at @faker-js/faker", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -25,3 +25,11 @@ import { z, ZodTypeAny } from 'zod'; | ||
mapEntriesLength?: number; | ||
/** | ||
* Set to true to throw an exception instead of returning undefined when encountering an unknown `ZodType` | ||
*/ | ||
throwOnUnknownType?: boolean; | ||
} | ||
export declare function generateMock<T extends ZodTypeAny>(zodRef: T, options?: GenerateMockOptions): z.infer<typeof zodRef>; | ||
export declare class ZodMockError extends Error { | ||
typeName: string; | ||
constructor(typeName: string); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateMock = void 0; | ||
exports.ZodMockError = exports.generateMock = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
@@ -290,3 +290,2 @@ const faker_1 = require("@faker-js/faker"); | ||
function generateMock(zodRef, options) { | ||
var _a; | ||
try { | ||
@@ -297,6 +296,6 @@ const typeName = zodRef._def.typeName; | ||
} | ||
else { | ||
else if ((options === null || options === void 0 ? void 0 : options.backupMocks) && typeName in options.backupMocks) { | ||
// check for a generator match in the options. | ||
// workaround for unimplemented Zod types | ||
const generator = (_a = options === null || options === void 0 ? void 0 : options.backupMocks) === null || _a === void 0 ? void 0 : _a[typeName]; | ||
const generator = options.backupMocks[typeName]; | ||
if (generator) { | ||
@@ -306,5 +305,11 @@ return generator(); | ||
} | ||
else if (options === null || options === void 0 ? void 0 : options.throwOnUnknownType) { | ||
throw new ZodMockError(typeName); | ||
} | ||
return undefined; | ||
} | ||
catch (err) { | ||
if (err instanceof ZodMockError) { | ||
throw err; | ||
} | ||
console.error(err); | ||
@@ -315,2 +320,9 @@ return undefined; | ||
exports.generateMock = generateMock; | ||
class ZodMockError extends Error { | ||
constructor(typeName) { | ||
super(`Unable to generate a mock value for ZodType ${typeName}.`); | ||
this.typeName = typeName; | ||
} | ||
} | ||
exports.ZodMockError = ZodMockError; | ||
//# sourceMappingURL=zod-mock.js.map |
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
36617
375