UNPKG

@voiceflow/common

Version:

Junk drawer of utility functions

16 lines (15 loc) 734 B
"use strict"; /** * Copied from the implementation found in `@nest-zod/z` since it recommended to migrate to bare `zod` * https://github.com/BenLorantfy/nestjs-zod/blob/main/packages/z/src/z/generic-types/json.ts */ Object.defineProperty(exports, "__esModule", { value: true }); exports.zJSON = void 0; const zod_1 = require("zod"); const literal = zod_1.z.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.boolean()]); const DEFAULT_MESSAGE = 'Expected value to be a JSON-serializable'; const zJSON = (message = DEFAULT_MESSAGE) => { const schema = zod_1.z.lazy(() => zod_1.z.union([literal, zod_1.z.array(schema), zod_1.z.record(zod_1.z.string(), schema)], { error: message })); return schema; }; exports.zJSON = zJSON;