Spaces:
Paused
Paused
Include updated package-lock.json (part 15)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- node_modules/zod-to-json-schema/.github/CR_logotype-full-color.png +0 -0
- node_modules/zod-to-json-schema/.github/FUNDING.yml +1 -0
- node_modules/zod-to-json-schema/.prettierrc.json +1 -0
- node_modules/zod-to-json-schema/LICENSE +15 -0
- node_modules/zod-to-json-schema/README.md +390 -0
- node_modules/zod-to-json-schema/changelog.md +83 -0
- node_modules/zod-to-json-schema/contributing.md +9 -0
- node_modules/zod-to-json-schema/createIndex.ts +32 -0
- node_modules/zod-to-json-schema/package.json +85 -0
- node_modules/zod-to-json-schema/postcjs.ts +3 -0
- node_modules/zod-to-json-schema/postesm.ts +3 -0
- node_modules/zod-validation-error/LICENSE +9 -0
- node_modules/zod-validation-error/README.md +504 -0
- node_modules/zod-validation-error/README.v3.md +558 -0
- node_modules/zod-validation-error/package.json +108 -0
- node_modules/zod-validation-error/v3/index.d.mts +50 -0
- node_modules/zod-validation-error/v3/index.d.ts +50 -0
- node_modules/zod-validation-error/v3/index.js +309 -0
- node_modules/zod-validation-error/v3/index.js.map +1 -0
- node_modules/zod-validation-error/v3/index.mjs +263 -0
- node_modules/zod-validation-error/v3/index.mjs.map +1 -0
- node_modules/zod-validation-error/v4/index.d.mts +66 -0
- node_modules/zod-validation-error/v4/index.d.ts +66 -0
- node_modules/zod-validation-error/v4/index.js +725 -0
- node_modules/zod-validation-error/v4/index.js.map +1 -0
- node_modules/zod-validation-error/v4/index.mjs +679 -0
- node_modules/zod-validation-error/v4/index.mjs.map +1 -0
- node_modules/zod/mini/index.cjs +32 -0
- node_modules/zod/mini/index.d.cts +3 -0
- node_modules/zod/mini/index.d.ts +3 -0
- node_modules/zod/mini/index.js +3 -0
- node_modules/zod/mini/package.json +7 -0
- node_modules/zod/package.json +135 -0
- node_modules/zod/src/index.ts +4 -0
- node_modules/zod/src/locales/index.ts +1 -0
- node_modules/zod/src/mini/index.ts +3 -0
- node_modules/zod/src/v3/ZodError.ts +330 -0
- node_modules/zod/src/v3/benchmarks/datetime.ts +58 -0
- node_modules/zod/src/v3/benchmarks/discriminatedUnion.ts +80 -0
- node_modules/zod/src/v3/benchmarks/index.ts +59 -0
- node_modules/zod/src/v3/benchmarks/ipv4.ts +57 -0
- node_modules/zod/src/v3/benchmarks/object.ts +69 -0
- node_modules/zod/src/v3/benchmarks/primitives.ts +162 -0
- node_modules/zod/src/v3/benchmarks/realworld.ts +63 -0
- node_modules/zod/src/v3/benchmarks/string.ts +55 -0
- node_modules/zod/src/v3/benchmarks/union.ts +80 -0
- node_modules/zod/src/v3/errors.ts +13 -0
- node_modules/zod/src/v3/external.ts +6 -0
- node_modules/zod/src/v3/helpers/enumUtil.ts +17 -0
- node_modules/zod/src/v3/helpers/errorUtil.ts +8 -0
node_modules/zod-to-json-schema/.github/CR_logotype-full-color.png
ADDED
|
node_modules/zod-to-json-schema/.github/FUNDING.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
github: [StefanTerdell]
|
node_modules/zod-to-json-schema/.prettierrc.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{}
|
node_modules/zod-to-json-schema/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ISC License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2020, Stefan Terdell
|
| 4 |
+
|
| 5 |
+
Permission to use, copy, modify, and/or distribute this software for any
|
| 6 |
+
purpose with or without fee is hereby granted, provided that the above
|
| 7 |
+
copyright notice and this permission notice appear in all copies.
|
| 8 |
+
|
| 9 |
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
| 10 |
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
| 11 |
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
| 12 |
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 13 |
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 14 |
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
| 15 |
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
node_modules/zod-to-json-schema/README.md
ADDED
|
@@ -0,0 +1,390 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Zod to Json Schema
|
| 2 |
+
|
| 3 |
+
[](https://npmjs.org/package/zod-to-json-schema)
|
| 4 |
+
[](https://npmjs.org/package/zod-to-json-schema)
|
| 5 |
+
|
| 6 |
+
## Notice of deprecation
|
| 7 |
+
|
| 8 |
+
As of November 2025, this project will no longer be actively maintained. [Zod v4 natively supports generating JSON schemas](https://zod.dev/json-schema#ztojsonschema), so I recommend you switch to the new major.
|
| 9 |
+
|
| 10 |
+
Thank you to all the contributors and sponsors throughout the years! So long, and thanks for all the fish.
|
| 11 |
+
|
| 12 |
+
## Summary
|
| 13 |
+
|
| 14 |
+
Does what it says on the tin; converts [Zod schemas](https://github.com/colinhacks/zod) into [JSON schemas](https://json-schema.org/)!
|
| 15 |
+
|
| 16 |
+
- Supports all relevant schema types, basic string, number and array length validations and string patterns.
|
| 17 |
+
- Resolves recursive and recurring schemas with internal `$ref`s.
|
| 18 |
+
- Supports targeting legacy Open API 3.0 specification (3.1 supports regular Json Schema).
|
| 19 |
+
- Supports Open AI strict mode schemas (Optional object properties are replaced with required but nullable ones).
|
| 20 |
+
- As of v3.25 you can use Zod v4 as a peer-dependency, so long as you still provide v3-schemas.
|
| 21 |
+
|
| 22 |
+
_Looking for the exact opposite? Check out [json-schema-to-zod](https://npmjs.org/package/json-schema-to-zod)_
|
| 23 |
+
|
| 24 |
+
## Sponsors
|
| 25 |
+
|
| 26 |
+
As this project will no longer be receiving updates I am no longer accepting new partnerships. Huge shout-out to CodeRabbit for keeping it real to the end <3
|
| 27 |
+
|
| 28 |
+
<table align="center" style="justify-content: center;align-items: center;display: flex;">
|
| 29 |
+
<tr>
|
| 30 |
+
<td align="center">
|
| 31 |
+
<p></p>
|
| 32 |
+
<p>
|
| 33 |
+
<div style="background-color: white; padding: 4px; padding-bottom: 8px;" alt="stainless">
|
| 34 |
+
<a href="https://www.coderabbit.ai/">
|
| 35 |
+
<picture height="45px">
|
| 36 |
+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/user-attachments/assets/eea24edb-ff20-4532-b57c-e8719f455d6d">
|
| 37 |
+
<img alt="CodeRabbit logo" height="45px" src="https://github.com/user-attachments/assets/d791bc7d-dc60-4d55-9c31-97779839cb74">
|
| 38 |
+
</picture>
|
| 39 |
+
</a>
|
| 40 |
+
</div>
|
| 41 |
+
<br />
|
| 42 |
+
Cut code review time & bugs in half
|
| 43 |
+
<br/>
|
| 44 |
+
<a href="https://www.coderabbit.ai/" style="text-decoration:none;">coderabbit.ai</a>
|
| 45 |
+
</p>
|
| 46 |
+
<p></p>
|
| 47 |
+
</td>
|
| 48 |
+
</tr>
|
| 49 |
+
</table>
|
| 50 |
+
|
| 51 |
+
## Usage
|
| 52 |
+
|
| 53 |
+
### Basic example
|
| 54 |
+
|
| 55 |
+
```typescript
|
| 56 |
+
import { z } from "zod"; // Or, using v3.25 or v4, "zod/v3"
|
| 57 |
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
| 58 |
+
|
| 59 |
+
const mySchema = z
|
| 60 |
+
.object({
|
| 61 |
+
myString: z.string().min(5),
|
| 62 |
+
myUnion: z.union([z.number(), z.boolean()]),
|
| 63 |
+
})
|
| 64 |
+
.describe("My neat object schema");
|
| 65 |
+
|
| 66 |
+
const jsonSchema = zodToJsonSchema(mySchema, "mySchema");
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
#### Expected output
|
| 70 |
+
|
| 71 |
+
```json
|
| 72 |
+
{
|
| 73 |
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
| 74 |
+
"$ref": "#/definitions/mySchema",
|
| 75 |
+
"definitions": {
|
| 76 |
+
"mySchema": {
|
| 77 |
+
"description": "My neat object schema",
|
| 78 |
+
"type": "object",
|
| 79 |
+
"properties": {
|
| 80 |
+
"myString": {
|
| 81 |
+
"type": "string",
|
| 82 |
+
"minLength": 5
|
| 83 |
+
},
|
| 84 |
+
"myUnion": {
|
| 85 |
+
"type": ["number", "boolean"]
|
| 86 |
+
}
|
| 87 |
+
},
|
| 88 |
+
"additionalProperties": false,
|
| 89 |
+
"required": ["myString", "myUnion"]
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
## Options
|
| 96 |
+
|
| 97 |
+
### Schema name
|
| 98 |
+
|
| 99 |
+
You can pass a string as the second parameter of the main zodToJsonSchema function. If you do, your schema will end up inside a definitions object property on the root and referenced from there. Alternatively, you can pass the name as the `name` property of the options object (see below).
|
| 100 |
+
|
| 101 |
+
### Options object
|
| 102 |
+
|
| 103 |
+
Instead of the schema name (or nothing), you can pass an options object as the second parameter. The following options are available:
|
| 104 |
+
|
| 105 |
+
| Option | Effect |
|
| 106 |
+
| ---------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 107 |
+
| **name**?: _string_ | As described above. |
|
| 108 |
+
| **nameStrategy**?: "ref" \| "title" | Adds name as "title" meta instead of as a ref as described above |
|
| 109 |
+
| **basePath**?: string[] | The base path of the root reference builder. Defaults to ["#"]. |
|
| 110 |
+
| **$refStrategy**?: "root" \| "relative" \| "seen" \| "none" | The reference builder strategy; <ul><li>**"root"** resolves $refs from the root up, ie: "#/definitions/mySchema".</li><li>**"relative"** uses [relative JSON pointers](https://tools.ietf.org/id/draft-handrews-relative-json-pointer-00.html). _See known issues!_</li><li>**"seen"** reuses the output of any "seen" Zod schema. In theory it's a more performant version of "none", but in practice this behaviour can cause issues with nested schemas and has now gotten its own option.</li> <li>**"none"** ignores referencing all together, creating a new schema branch even on "seen" schemas. Recursive references defaults to "any", ie `{}`.</li></ul> Defaults to "root". |
|
| 111 |
+
| **effectStrategy**?: "input" \| "any" | The effects output strategy. Defaults to "input". _See known issues!_ |
|
| 112 |
+
| **dateStrategy**?: "format:date" \| "format:date-time" \| "string" \| "integer" | Date strategy, integer allow to specify in unix-time min and max values. "format:date" creates a string schema with format: "date". "format:date-time" creates a string schema with format: "date-time". "string" is intepreted as "format:date-time". "integer" creates an integer schema with format "unix-time" (unless target "openApi3" is used min max checks are also respected) |
|
| 113 |
+
| |
|
| 114 |
+
| **emailStrategy**?: "format:email" \| "format:idn-email" \| "pattern:zod" | Choose how to handle the email string check. Defaults to "format:email". |
|
| 115 |
+
| **base64Strategy**?: "format:binary" \| "contentEnconding:base64" \| "pattern:zod" | Choose how to handle the base64 string check. Defaults to "contentEncoding:base64" as described [here](https://json-schema.org/understanding-json-schema/reference/non_json_data#contentencoding). Note that "format:binary" is not represented in the output type as it's not part of the JSON Schema spec and only intended to be used when targeting OpenAPI 3.0. Later versions of OpenAPI support contentEncoding. |
|
| 116 |
+
| **definitionPath**?: "definitions" \| "$defs" | The name of the definitions property when name is passed. Defaults to "definitions". |
|
| 117 |
+
| **target**?: "jsonSchema7" \| "jsonSchema2019-09" \| "openApi3" \| "openAi" | Which spec to target. Defaults to "jsonSchema7" |
|
| 118 |
+
| **strictUnions**?: boolean | Scrubs unions of any-like json schemas, like `{}` or `true`. Multiple zod types may result in these out of necessity, such as z.instanceof() |
|
| 119 |
+
| **definitions**?: Record<string, ZodSchema> | See separate section below |
|
| 120 |
+
| **errorMessages**?: boolean | Include custom error messages created via chained function checks for supported zod types. See section below |
|
| 121 |
+
| **markdownDescription**?: boolean | Copies the `description` meta to `markdownDescription` |
|
| 122 |
+
| **patternStrategy**?: "escape" \| "preserve" | The Zod string validations `.includes()`, `.startsWith()`, and `.endsWith()` must be converted to regex to be compatible with JSON Schema's `pattern`. For safety, all non-alphanumeric characters are `escape`d by default (consider `z.string().includes(".")`), but this can occasionally cause problems with Unicode-flagged regex parsers. Use `preserve` to prevent this escaping behaviour and preserve the exact string written, even if it results in an inaccurate regex. |
|
| 123 |
+
| **applyRegexFlags**?: boolean | JSON Schema's `pattern` doesn't support RegExp flags, but Zod's `z.string().regex()` does. When this option is true (default false), a best-effort is made to transform regexes into a flag-independent form (e.g. `/x/i => /[xX]/` ). Supported flags: `i` (basic Latin only), `m`, `s`. |
|
| 124 |
+
| **pipeStrategy**?: "all" \| "input" \| "output" | Decide which types should be included when using `z.pipe`, for example `z.string().pipe(z.number())` would return both `string` and `number` by default, only `string` for "input" and only `number` for "output". |
|
| 125 |
+
| **removeAdditionalStrategy**?: "passthrough" \| "strict" | Decide when `additionalProperties` should be allowed. See the section on additional properties for details. |
|
| 126 |
+
| **allowedAdditionalProperties**?: `true` \| `undefined` | What value to give `additionalProperties` when allowed. See the section on additional properties for details. |
|
| 127 |
+
| **rejectedAdditionalProperties**?: `false` \| `undefined` | What value to give `additionalProperties` when rejected. See the section on additional properties for details. |
|
| 128 |
+
| **override**?: callback | See section |
|
| 129 |
+
| **postProcess**?: callback | See section |
|
| 130 |
+
| **openAiAnyTypeName**?: string | Decides the name of a Json schema used to allow semi-arbitrary values in Open AI structured output. If any value in the Zod-schema resolves to any "any"-type schema it will reference a definition of this name. If no such definition is provided a default Json schema will be used. Defaults to "OpenAiAnyType" |
|
| 131 |
+
|
| 132 |
+
### Definitions
|
| 133 |
+
|
| 134 |
+
The definitions option lets you manually add recurring schemas into definitions for cleaner outputs. It's fully compatible with named schemas, changed definitions path and base path. Here's a simple example:
|
| 135 |
+
|
| 136 |
+
```typescript
|
| 137 |
+
const myRecurringSchema = z.string();
|
| 138 |
+
const myObjectSchema = z.object({ a: myRecurringSchema, b: myRecurringSchema });
|
| 139 |
+
|
| 140 |
+
const myJsonSchema = zodToJsonSchema(myObjectSchema, {
|
| 141 |
+
definitions: { myRecurringSchema },
|
| 142 |
+
});
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
#### Result
|
| 146 |
+
|
| 147 |
+
```json
|
| 148 |
+
{
|
| 149 |
+
"type": "object",
|
| 150 |
+
"properties": {
|
| 151 |
+
"a": {
|
| 152 |
+
"$ref": "#/definitions/myRecurringSchema"
|
| 153 |
+
},
|
| 154 |
+
"b": {
|
| 155 |
+
"$ref": "#/definitions/myRecurringSchema"
|
| 156 |
+
}
|
| 157 |
+
},
|
| 158 |
+
"definitions": {
|
| 159 |
+
"myRecurringSchema": {
|
| 160 |
+
"type": "string"
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
### Error Messages
|
| 167 |
+
|
| 168 |
+
This feature allows optionally including error messages created via chained function calls for supported zod types:
|
| 169 |
+
|
| 170 |
+
```ts
|
| 171 |
+
// string schema with additional chained function call checks
|
| 172 |
+
const EmailSchema = z.string().email("Invalid email").min(5, "Too short");
|
| 173 |
+
|
| 174 |
+
const jsonSchema = zodToJsonSchema(EmailSchema, { errorMessages: true });
|
| 175 |
+
```
|
| 176 |
+
|
| 177 |
+
#### Result
|
| 178 |
+
|
| 179 |
+
```json
|
| 180 |
+
{
|
| 181 |
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
| 182 |
+
"type": "string",
|
| 183 |
+
"format": "email",
|
| 184 |
+
"minLength": 5,
|
| 185 |
+
"errorMessage": {
|
| 186 |
+
"format": "Invalid email",
|
| 187 |
+
"minLength": "Too short"
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
```
|
| 191 |
+
|
| 192 |
+
This allows for field specific, validation step specific error messages which can be useful for building forms and such. This format is accepted by `react-hook-form`'s ajv resolver (and therefor `ajv-errors` which it uses under the hood). Note that if using AJV with this format will require [enabling `ajv-errors`](https://ajv.js.org/packages/ajv-errors.html#usage) as vanilla AJV does not accept this format by default.
|
| 193 |
+
|
| 194 |
+
#### Custom Error Message Support
|
| 195 |
+
|
| 196 |
+
- ZodString
|
| 197 |
+
- regex
|
| 198 |
+
- min, max
|
| 199 |
+
- email, cuid, uuid, url
|
| 200 |
+
- endsWith, startsWith
|
| 201 |
+
- ZodNumber
|
| 202 |
+
- min, max, lt, lte, gt, gte,
|
| 203 |
+
- int
|
| 204 |
+
- multipleOf
|
| 205 |
+
- ZodSet
|
| 206 |
+
- min, max
|
| 207 |
+
- ZodArray
|
| 208 |
+
- min, max
|
| 209 |
+
|
| 210 |
+
### Additional properties
|
| 211 |
+
|
| 212 |
+
By default, Zod removes undeclared properties when parsing object schemas. In order to replicate the expected output of this behaviour, the default for behaviour of zodToJsonSchema is to set `"additionalProperties"` to `false` (although the correctness of this can be debated). If you wish to allow undeclared properties you can either:
|
| 213 |
+
|
| 214 |
+
- Set `removeAdditionalStrategy` to `"strict"`. This will allow additional properties for any object schema that is not declared with `.strict()`.
|
| 215 |
+
- Leave `removeAdditionalStrategy` set to its default value of `"passthrough"`, and add `.passtrough()` to your object schema.
|
| 216 |
+
|
| 217 |
+
#### Removing the `additionalProperties` keyword using the `allowedAdditionalProperties` and/or `rejectedAdditionalProperties` options.
|
| 218 |
+
|
| 219 |
+
Some schema definitions (like Googles Gen AI API for instance) does not allow the `additionalProperties` keyword at all. Luckily the JSON Schema spec allows for this: leaving the keyword undefined _should_ have the same effect as setting it to true (as per usual YMMV). To enable this behaviour, set the option `allowedAdditionalProperties` to `undefined`.
|
| 220 |
+
|
| 221 |
+
To exclude the keyword even when additional properties are _not_ allowed, set the `rejectedAdditionalProperties` to `undefined` as well.
|
| 222 |
+
|
| 223 |
+
_Heads up ⚠️: Both of these options will be ignored if your schema is declared with `.catchall(...)` as the provided schema will be used instead (if valid)._
|
| 224 |
+
|
| 225 |
+
#### Expected outputs
|
| 226 |
+
|
| 227 |
+
| `z.object({})` + option | `"additionalProperties"` value |
|
| 228 |
+
| ------------------------- | ----------------------------------------------------------- |
|
| 229 |
+
| `.strip()` (default) | `false` if strategy is `"passtrough"`, `true` if `"strict"` |
|
| 230 |
+
| `.passtrough()` | `true` |
|
| 231 |
+
| `.strict()` | `false` |
|
| 232 |
+
| `.catchall(z.string())` | `{ "type": "string" }` |
|
| 233 |
+
| `.catchall(z.function())` | `undefined` (function schemas are not currently parseable) |
|
| 234 |
+
|
| 235 |
+
Substitute `true` and `false` for `undefined` according to `allowedAdditionalProperties` and/or `rejectedAdditionalProperties` respectively.
|
| 236 |
+
|
| 237 |
+
### `override`
|
| 238 |
+
|
| 239 |
+
This options takes a callback receiving a Zod schema definition, the current reference object (containing the current ref path and other options), an argument containing inforation about wether or not the schema has been encountered before, and a forceResolution argument.
|
| 240 |
+
|
| 241 |
+
Important: if you don't want to override the current item you have to return the `ignoreOverride` symbol exported from the index. This is because `undefined` is a valid option to return when you want the property to be excluded from the resulting JSON schema.
|
| 242 |
+
|
| 243 |
+
```typescript
|
| 244 |
+
import zodToJsonSchema, { ignoreOverride } from "zod-to-json-schema";
|
| 245 |
+
|
| 246 |
+
zodToJsonSchema(
|
| 247 |
+
z.object({
|
| 248 |
+
ignoreThis: z.string(),
|
| 249 |
+
overrideThis: z.string(),
|
| 250 |
+
removeThis: z.string(),
|
| 251 |
+
}),
|
| 252 |
+
{
|
| 253 |
+
override: (def, refs) => {
|
| 254 |
+
const path = refs.currentPath.join("/");
|
| 255 |
+
|
| 256 |
+
if (path === "#/properties/overrideThis") {
|
| 257 |
+
return {
|
| 258 |
+
type: "integer",
|
| 259 |
+
};
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
if (path === "#/properties/removeThis") {
|
| 263 |
+
return undefined;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
// Important! Do not return `undefined` or void unless you want to remove the property from the resulting schema completely.
|
| 267 |
+
return ignoreOverride;
|
| 268 |
+
},
|
| 269 |
+
},
|
| 270 |
+
);
|
| 271 |
+
```
|
| 272 |
+
|
| 273 |
+
Expected output:
|
| 274 |
+
|
| 275 |
+
```json
|
| 276 |
+
{
|
| 277 |
+
"type": "object",
|
| 278 |
+
"required": ["ignoreThis", "overrideThis"],
|
| 279 |
+
"properties": {
|
| 280 |
+
"ignoreThis": {
|
| 281 |
+
"type": "string"
|
| 282 |
+
},
|
| 283 |
+
"overrideThis": {
|
| 284 |
+
"type": "integer"
|
| 285 |
+
}
|
| 286 |
+
},
|
| 287 |
+
"additionalProperties": false
|
| 288 |
+
}
|
| 289 |
+
```
|
| 290 |
+
|
| 291 |
+
### `postProcess`
|
| 292 |
+
|
| 293 |
+
Besided receiving all arguments of the `override` callback, the `postProcess` callback also receives the generated schema. It should always return a JSON Schema, or `undefined` if you wish to filter it out. Unlike the `override` callback you do not have to return `ignoreOverride` if you are happy with the produced schema; simply return it unchanged.
|
| 294 |
+
|
| 295 |
+
```typescript
|
| 296 |
+
import zodToJsonSchema, { PostProcessCallback } from "zod-to-json-schema";
|
| 297 |
+
|
| 298 |
+
// Define the callback to be used to process the output using the PostProcessCallback type:
|
| 299 |
+
const postProcess: PostProcessCallback = (
|
| 300 |
+
// The original output produced by the package itself:
|
| 301 |
+
jsonSchema,
|
| 302 |
+
// The ZodSchema def used to produce the original schema:
|
| 303 |
+
def,
|
| 304 |
+
// The refs object containing the current path, passed options, etc.
|
| 305 |
+
refs,
|
| 306 |
+
) => {
|
| 307 |
+
if (!jsonSchema) {
|
| 308 |
+
return jsonSchema;
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
// Try to expand description as JSON meta:
|
| 312 |
+
if (jsonSchema.description) {
|
| 313 |
+
try {
|
| 314 |
+
jsonSchema = {
|
| 315 |
+
...jsonSchema,
|
| 316 |
+
...JSON.parse(jsonSchema.description),
|
| 317 |
+
};
|
| 318 |
+
} catch {}
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
// Make all numbers nullable:
|
| 322 |
+
if ("type" in jsonSchema! && jsonSchema.type === "number") {
|
| 323 |
+
jsonSchema.type = ["number", "null"];
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
// Add the refs path, just because
|
| 327 |
+
(jsonSchema as any).path = refs.currentPath;
|
| 328 |
+
|
| 329 |
+
return jsonSchema;
|
| 330 |
+
};
|
| 331 |
+
|
| 332 |
+
const jsonSchema = zodToJsonSchema(zodSchema, { postProcess });
|
| 333 |
+
```
|
| 334 |
+
|
| 335 |
+
#### Using `postProcess` for including examples and other meta
|
| 336 |
+
|
| 337 |
+
Adding support for examples and other JSON Schema meta keys are among the most commonly requested features for this project. Unfortunately the current Zod major (3) has pretty anemic support for this, so some userland hacking is required. Since this is such a common usecase I've included a helper function that simply tries to parse any description as JSON and expand it into the resulting schema.
|
| 338 |
+
|
| 339 |
+
Simply stringify whatever you want added to the output schema as the description, then import and use `jsonDescription` as the postProcess option:
|
| 340 |
+
|
| 341 |
+
```typescript
|
| 342 |
+
import zodToJsonSchema, { jsonDescription } from "zod-to-json-schema";
|
| 343 |
+
|
| 344 |
+
const zodSchema = z.string().describe(
|
| 345 |
+
JSON.stringify({
|
| 346 |
+
title: "My string",
|
| 347 |
+
description: "My description",
|
| 348 |
+
examples: ["Foo", "Bar"],
|
| 349 |
+
whatever: 123,
|
| 350 |
+
}),
|
| 351 |
+
);
|
| 352 |
+
|
| 353 |
+
const jsonSchema = zodToJsonSchema(zodSchema, {
|
| 354 |
+
postProcess: jsonDescription,
|
| 355 |
+
});
|
| 356 |
+
```
|
| 357 |
+
|
| 358 |
+
Expected output:
|
| 359 |
+
|
| 360 |
+
```json
|
| 361 |
+
{
|
| 362 |
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
| 363 |
+
"type": "string",
|
| 364 |
+
"title": "My string",
|
| 365 |
+
"description": "My description",
|
| 366 |
+
"examples": ["Foo", "Bar"],
|
| 367 |
+
"whatever": 123
|
| 368 |
+
}
|
| 369 |
+
```
|
| 370 |
+
|
| 371 |
+
## Known issues
|
| 372 |
+
|
| 373 |
+
- The OpenAI target should be considered experimental for now, as some combination of options may break the compatibility.
|
| 374 |
+
- When using `.transform`, the return type is inferred from the supplied function. In other words, there is no schema for the return type, and there is no way to convert it in runtime. Currently the JSON schema will therefore reflect the input side of the Zod schema and not necessarily the output (the latter aka. `z.infer`). If this causes problems with your schema, consider using the effectStrategy "any", which will allow any type of output.
|
| 375 |
+
- JSON Schemas does not support any other key type than strings for objects. When using `z.record` with any other key type, this will be ignored. An exception to this rule is `z.enum` as is supported since 3.11.3
|
| 376 |
+
- Relative JSON pointers, while published alongside [JSON schema draft 2020-12](https://json-schema.org/specification.html), is not technically a part of it. Currently, most resolvers do not handle them at all.
|
| 377 |
+
- Since v3, the Object parser uses `.isOptional()` to check if a property should be included in `required` or not. This has the potentially dangerous behavior of calling `.safeParse` with `undefined`. To work around this, make sure your `preprocess` and other effects callbacks are pure and not liable to throw errors. An issue has been logged in the Zod repo and can be [tracked here](https://github.com/colinhacks/zod/issues/1460).
|
| 378 |
+
- JSON Schema version 2020-12 is not yet officially supported. However, you should be able to use this library to obtain a compatible schema for the 2020-12 format just by changing the returned schema's `$schema` field to: "https://json-schema.org/draft/2020-12/schema#"
|
| 379 |
+
|
| 380 |
+
## Versioning
|
| 381 |
+
|
| 382 |
+
This package _does not_ follow semantic versioning. The major and minor versions of this package instead reflects feature parity with the [Zod package](http://npmjs.com/package/zod).
|
| 383 |
+
|
| 384 |
+
I will do my best to keep API-breaking changes to an absolute minimum, but new features may appear as "patches", such as introducing the options pattern in 3.9.1.
|
| 385 |
+
|
| 386 |
+
While v3.25 supports Zod v4 as a peer-dependency, it does _not_ mean it supports v4 schemas. Use `import { z } from "zod/v3"` and refer to the Zod documentation.
|
| 387 |
+
|
| 388 |
+
## Changelog
|
| 389 |
+
|
| 390 |
+
https://github.com/StefanTerdell/zod-to-json-schema/blob/master/changelog.md
|
node_modules/zod-to-json-schema/changelog.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Changelog
|
| 2 |
+
|
| 3 |
+
| Version | Change |
|
| 4 |
+
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 5 |
+
| 3.25.2 | Bumps the peer dependency of Zod 3 to 3.25.28 - Versions before patch 13 caused [OOM issues](https://github.com/StefanTerdell/zod-to-json-schema/issues/185) and versions between that and 28 removed the /v3 import alias. |
|
| 6 |
+
| 3.25.1 | Fixes large install size due to accidental inclusion of test files. Thanks, [Felix Mosheev](https://github.com/felixmosh)! |
|
| 7 |
+
| 3.25.0 | Adds support for v3.25 and v3 through v4 (`import { z } from "zod/v3"`). Big thank you to both [Andrey Gubanovs](https://github.com/finom) and especially to [Faïz Hernawan Abdillah](https://github.com/Abdillah), whose more minimal implementation was merged. This will likely be the final release of `zod-to-json-schema`, as v4 now supports JSON schema natively. |
|
| 8 |
+
| 3.24.6 | Removed use of instanceOf to check for optional properties as differing package versions could produce intermittent bugs. Added OpenAiAnyType to work around their schema restrictions. |
|
| 9 |
+
| 3.24.5 | Update .npmignore to drop 2 mb of test files. Thanks [Misha Kaletsky](https://github.com/mmkal)! |
|
| 10 |
+
| 3.24.4 | Added options to set the value of additionalProperties in objects and record |
|
| 11 |
+
| 3.24.3 | Adds postProcess callback option |
|
| 12 |
+
| 3.24.2 | Restructured internals to remove circular dependencies which apparently might cause some build systems to whine a bit. Big thanks to [Víctor Hernández](https://github.com/NanezX) for the fix. |
|
| 13 |
+
| 3.24.1 | Adds OpenAI target |
|
| 14 |
+
| 3.24.0 | Implements new string checks (jwt, base64url, cidr ipv4/v6), matching the new Zod version |
|
| 15 |
+
| 3.23.5 | Module import hotfix by [Enzo Monjardín](https://github.com/enzomonjardin). Thanks! |
|
| 16 |
+
| 3.23.4 | Fixes branded regex property names and a weird edgecase in arrays. Thanks to [Isaiah Marc Sanchez](https://github.com/imsanchez) and [Mitchell Merry](https://github.com/mitchell-merry)! |
|
| 17 |
+
| 3.23.3 | More tests (Thanks [Brett Zamir!](https://github.com/brettz9)), removed dead code |
|
| 18 |
+
| 3.23.2 | Lazily loads Emoji regex to avoid incompatibility with some environments. Thanks [Jacob Lee](https://github.com/jacoblee93)! |
|
| 19 |
+
| 3.23.1 | Best-effort RegEx flag support by [Spappz](https://github.com/Spappz)! Some minor fixes and additions, such as the title option. |
|
| 20 |
+
| 3.23.0 | Adds support for base64, date, time, duration and nanoid string validations. A warm welcome and a big thanks to [Colin](https://www.github.com/colinhacks), the creator of Zod, joining in as a contributor :) |
|
| 21 |
+
| 3.22.5 | Adds new z.date() parsing options and override callback |
|
| 22 |
+
| 3.22.4 | Adds fix for nullable references in OpenAPI mode |
|
| 23 |
+
| 3.22.3 | Adjust root path from "#/" to "#" according to RFC 6901 |
|
| 24 |
+
| 3.22.2 | Adds "output" pipe strategy |
|
| 25 |
+
| 3.22.1 | Fixes broken imports when using some bundlers |
|
| 26 |
+
| 3.22.0 | Support readonly. Export both CJS and ESM. Export everything from index. Alternative map parser. Improved pattern handling and updated sources. |
|
| 27 |
+
| 3.21.4 | Fixes missing support for exact array length |
|
| 28 |
+
| 3.21.3 | Fixes issue #77 (Reference path to nullable schemas in Open-API mode) |
|
| 29 |
+
| 3.21.2 | Adds "integer" type Date output to support min/max checks, markdownDescription option, fixes "none" refStrategy by adding "seen" and adds an option to use "pattern" with Zods' email enum instead of "format". |
|
| 30 |
+
| 3.21.1 | New target (2019-09) along with improved intersection schemas, improved mutual recursion references in definitions, descriptions respected in union parser and not removed in collapsed |
|
| 31 |
+
| 3.21.0 | Added new string validations (ip, emoji, etc) and BigInt checks to support Zod 3.21 |
|
| 32 |
+
| 3.20.5 | Added uniqueItems to Set and an option to disregard pipe schemas |
|
| 33 |
+
| 3.20.4 | Bugfixes and improved record parsing for openApi3 |
|
| 34 |
+
| 3.20.3 | Added Cuid2 support introduced in Zod 3.20.3 |
|
| 35 |
+
| 3.20.2 | Reintroduced conditional simplified return-type for when target is OpenAPI 3 |
|
| 36 |
+
| 3.20.1 | Fixed inconsistent casing in imports |
|
| 37 |
+
| 3.20.0 | Adds support for Zod 3.20 with catch and pipe parser as well as new string validations. Refactored Ref handling; adding definitions no longer considered experimental. Main API function refactored and simplified; output type less defined but a lot easier to maintain. Doubt anyone will miss it. <br/><quote><i>Narrator: Someone did in fact miss it</i></quote> |
|
| 38 |
+
| 3.19.4 | Adds custom error message support |
|
| 39 |
+
| 3.19.3 | Mark `definitions` as experimental in the readme |
|
| 40 |
+
| 3.19.2 | Added `definitions` option |
|
| 41 |
+
| 3.19.1 | Strict unions fix |
|
| 42 |
+
| 3.19.0 | No new features added in Zod, parity bump |
|
| 43 |
+
| 3.18.2 | Fixes support for native enums |
|
| 44 |
+
| 3.18.1 | Add strictUnions options |
|
| 45 |
+
| 3.18.0 | Added support for branded types |
|
| 46 |
+
| 3.17.2 | Fix for reference paths when supplying name option string. |
|
| 47 |
+
| 3.17.1 | Added startsWith and endsWith string checks. Merge multiple pattern checks into allOf array. |
|
| 48 |
+
| 3.17.0 | Added switch case handler for new trim "check". No changes to functionality. |
|
| 49 |
+
| 3.15.x - 3.16.x | Skipped: Did not change the Zod API in any way relevant for this package. |
|
| 50 |
+
| 3.14.1 | Dependabot security updates |
|
| 51 |
+
| 3.14.0 | Moves Zod into peerDependencies. Supports checks for sets, NaN-type (sort of), discriminated union type and standalone optional properties (as unions with undefined) |
|
| 52 |
+
| 3.12.x - 3.13.x | Skipped |
|
| 53 |
+
| 3.11.3 | Joins unions of enums into single enum and allows enums as keys of records |
|
| 54 |
+
| 3.11.2 | Adds option to target Open API 3 spec (paths) instead of Json Schema 7. |
|
| 55 |
+
| 3.11.1 | Performance boost when using $refStrategy `none` and internal improvements. |
|
| 56 |
+
| 3.11.0 | Added description support introduced in Zod 3.11.5 |
|
| 57 |
+
| 3.10.x | Skipped: Minor 10 did not change the Zod API |
|
| 58 |
+
| 3.9.5 | Type bug fix: used dev dependency types in package |
|
| 59 |
+
| 3.9.4 | Path bug fix and test case when using optional definitions path |
|
| 60 |
+
| 3.9.3 | Added option to change definition property name to $defs |
|
| 61 |
+
| 3.9.2 | Added option to handle transform results as any instead of relying on their input schema. |
|
| 62 |
+
| 3.9.1 | Refactored the way reference pointers are passed around and added options pattern to main function without braking backwards compatibility! You can now add a base path, change the reference strategy (or opt out), and still set the schema name inside the options object or outside as before. |
|
| 63 |
+
| 3.9.0 | Added support for multipleOf number validaion, .rest() schemas for tuples and key validation for records (only compatible with string keys due to JSON Schema limitation). |
|
| 64 |
+
| 3.7.x - 3.8.x | Skipped to reach functional parity with Zod versioning. |
|
| 65 |
+
| 3.6.1 | Realised intersection had another potential ref pathing bug. Fixed. |
|
| 66 |
+
| 3.6.0 | Added support for default & effects (refine). Broke out changelog.md |
|
| 67 |
+
| 3.5.0 | Added support for CUID string validation |
|
| 68 |
+
| 3.4.3 | Fixed $ref pathing for catchall and intersection. Additional tests and code structure fixes. |
|
| 69 |
+
| 3.4.2 | Fixed broken intersection parser (Thanks [Noah2610](https://github.com/Noah2610)!) |
|
| 70 |
+
| 3.4.1 | Fixed pathing bug for nullable items. |
|
| 71 |
+
| 3.4.0 | Added support for z.lazy() |
|
| 72 |
+
| 3.3.0 | Added support for catchall (additionalProperties schema on objects). Rebuilt object parser. |
|
| 73 |
+
| 3.2.0 | Added support for Map and Set as seen by their most common JSON definitions. Beware no standardized definition seem to exist and JSON.parse doesn't handle either natively. Their implementations here are based on the spread approach. Also further simplified intersection definition to just allOf. |
|
| 74 |
+
| 3.1.0 | String patterns finally supported! Fixed bugs include broken external type, unsafe nullable parsing, bad intersection implementation, and missing support for passthrough keys in objects. |
|
| 75 |
+
| 3.0.3 | Fixed array deep pathing bug (path contained `array` instead of `items`) |
|
| 76 |
+
| 3.0.2 | Fixed broken type usage (NonEmptyArrayDefinition was removed from Zod) |
|
| 77 |
+
| 3.0.1 | Fixed a typo in the readme |
|
| 78 |
+
| 3.0.0 | Compatible with Zod 3.2.0. Huge props to [Mr Hammad Asif](https://github.com/mrhammadasif) for his work on this. |
|
| 79 |
+
| 0.6.2 | Hotfix for undefined object properties. Could crash the parser when using Pick |
|
| 80 |
+
| 0.6.1 | Fixed bug in union pathing. `$Ref` was missing `/anyOf` |
|
| 81 |
+
| 0.6.0 | Moved `@types/json-schema` and `typescript` to dev dependencies. `@types/json-schema` is now only used for the test suites. Using `strict: true` in ts config. |
|
| 82 |
+
| 0.5.1 | First working release with all relevant Zod types present with most validations (except for string patterns due to Zod not exposing the source regexp pattern for those). |
|
| 83 |
+
| < 0.5.1 | Deprecated due to broken package structure. Please be patient, I eat crayons. |
|
node_modules/zod-to-json-schema/contributing.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Contributing
|
| 2 |
+
|
| 3 |
+
Hey, thanks for wanting to contribute.
|
| 4 |
+
|
| 5 |
+
Before you open a PR, make sure to open an issue and discuss the problem you want to solve. I will not consider PRs without issues.
|
| 6 |
+
|
| 7 |
+
I use [gitmoji](https://gitmoji.dev/) for my commit messages because I think it's fun. I encourage you to do the same, but won't enforce it.
|
| 8 |
+
|
| 9 |
+
I check PRs and issues very rarely so please be patient.
|
node_modules/zod-to-json-schema/createIndex.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { readdirSync, writeFileSync, statSync } from "fs";
|
| 2 |
+
|
| 3 |
+
const ignore = ["src/index.ts"];
|
| 4 |
+
|
| 5 |
+
function checkSrcDir(path: string): string[] {
|
| 6 |
+
const lines: string[] = [];
|
| 7 |
+
|
| 8 |
+
for (const item of readdirSync(path)) {
|
| 9 |
+
const itemPath = path + "/" + item;
|
| 10 |
+
|
| 11 |
+
if (ignore.includes(itemPath)) {
|
| 12 |
+
continue;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
if (statSync(itemPath).isDirectory()) {
|
| 16 |
+
lines.push(...checkSrcDir(itemPath));
|
| 17 |
+
} else if (item.endsWith(".ts")) {
|
| 18 |
+
lines.push('export * from "./' + itemPath.slice(4, -2) + 'js"');
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
return lines;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
const lines = checkSrcDir("src");
|
| 26 |
+
|
| 27 |
+
lines.push(
|
| 28 |
+
'import { zodToJsonSchema } from "./zodToJsonSchema.js"',
|
| 29 |
+
"export default zodToJsonSchema;",
|
| 30 |
+
);
|
| 31 |
+
|
| 32 |
+
writeFileSync("./src/index.ts", lines.join(";\n"));
|
node_modules/zod-to-json-schema/package.json
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "zod-to-json-schema",
|
| 3 |
+
"version": "3.25.2",
|
| 4 |
+
"description": "Converts Zod schemas to Json Schemas",
|
| 5 |
+
"types": "./dist/types/index.d.ts",
|
| 6 |
+
"main": "./dist/cjs/index.js",
|
| 7 |
+
"module": "./dist/esm/index.js",
|
| 8 |
+
"exports": {
|
| 9 |
+
"import": {
|
| 10 |
+
"types": "./dist/types/index.d.ts",
|
| 11 |
+
"default": "./dist/esm/index.js"
|
| 12 |
+
},
|
| 13 |
+
"require": {
|
| 14 |
+
"types": "./dist/types/index.d.ts",
|
| 15 |
+
"default": "./dist/cjs/index.js"
|
| 16 |
+
}
|
| 17 |
+
},
|
| 18 |
+
"scripts": {
|
| 19 |
+
"build:test": "npm --prefix ./dist-test-v3 test && npm --prefix ./dist-test-v4 test",
|
| 20 |
+
"build:types": "tsc -p tsconfig.types.json",
|
| 21 |
+
"build:cjs": "tsc -p tsconfig.cjs.json && tsx postcjs.ts",
|
| 22 |
+
"build:esm": "tsc -p tsconfig.esm.json && tsx postesm.ts",
|
| 23 |
+
"build": "npm i && npm run gen && npm test && rimraf ./dist && npm run build:types && npm run build:cjs && npm run build:esm && npm run build:test",
|
| 24 |
+
"dry": "npm run build && npm pub --dry-run",
|
| 25 |
+
"test:watch": "tsx watch test/index.ts",
|
| 26 |
+
"test:gen": "tsx test/createIndex.ts",
|
| 27 |
+
"test": "tsx test/index.ts",
|
| 28 |
+
"gen": "tsx createIndex.ts"
|
| 29 |
+
},
|
| 30 |
+
"keywords": [
|
| 31 |
+
"zod",
|
| 32 |
+
"json",
|
| 33 |
+
"schema",
|
| 34 |
+
"open",
|
| 35 |
+
"api",
|
| 36 |
+
"conversion"
|
| 37 |
+
],
|
| 38 |
+
"author": "Stefan Terdell",
|
| 39 |
+
"contributors": [
|
| 40 |
+
"Hammad Asif (https://github.com/mrhammadasif)",
|
| 41 |
+
"Noah Rosenzweig (https://github.com/Noah2610)",
|
| 42 |
+
"John Wright (https://github.com/johngeorgewright)",
|
| 43 |
+
"Krzysztof Ciombor (https://github.com/krzysztofciombor)",
|
| 44 |
+
"Yuta Mombetsu (https://github.com/mokocm)",
|
| 45 |
+
"Tom Arad (https://github.com/tomarad)",
|
| 46 |
+
"Isaac Way (https://github.com/iway1)",
|
| 47 |
+
"Andreas Berger (https://github.com/Andy2003)",
|
| 48 |
+
"Jan Potoms (https://github.com/Janpot)",
|
| 49 |
+
"Santiago Cammi (https://github.com/scammi)",
|
| 50 |
+
"Philipp Burckhardt (https://github.com/Planeshifter)",
|
| 51 |
+
"Bram del Canho (https://github.com/Bram-dc)",
|
| 52 |
+
"Gilad Hecht (https://github.com/gthecht)",
|
| 53 |
+
"Colin McDonnell (https://github.com/colinhacks)",
|
| 54 |
+
"Spappz (https://github.com/Spappz)",
|
| 55 |
+
"Jacob Lee (https://github.com/jacoblee93)",
|
| 56 |
+
"Brett Zamir (https://github.com/brettz9)",
|
| 57 |
+
"Isaiah Marc Sanchez (https://github.com/imsanchez)",
|
| 58 |
+
"Mitchell Merry (https://github.com/mitchell-merry)",
|
| 59 |
+
"Enzo Monjardín (https://github.com/enzomonjardin)",
|
| 60 |
+
"Víctor Hernández (https://github.com/NanezX)",
|
| 61 |
+
"Faïz Hernawan Abdillah (https://github.com/Abdillah)",
|
| 62 |
+
"Felix Mosheev (https://github.com/felixmosh)"
|
| 63 |
+
],
|
| 64 |
+
"repository": {
|
| 65 |
+
"type": "git",
|
| 66 |
+
"url": "https://github.com/StefanTerdell/zod-to-json-schema"
|
| 67 |
+
},
|
| 68 |
+
"license": "ISC",
|
| 69 |
+
"peerDependencies": {
|
| 70 |
+
"zod": "^3.25.28 || ^4"
|
| 71 |
+
},
|
| 72 |
+
"devDependencies": {
|
| 73 |
+
"@types/json-schema": "^7.0.9",
|
| 74 |
+
"@types/node": "^20.9.0",
|
| 75 |
+
"ajv": "^8.6.3",
|
| 76 |
+
"ajv-errors": "^3.0.0",
|
| 77 |
+
"ajv-formats": "^2.1.1",
|
| 78 |
+
"fast-diff": "^1.3.0",
|
| 79 |
+
"local-ref-resolver": "^0.2.0",
|
| 80 |
+
"rimraf": "^6.1.3",
|
| 81 |
+
"tsx": "^4.19.0",
|
| 82 |
+
"typescript": "^5.1.3",
|
| 83 |
+
"zod": "^3.25.28 || ^4"
|
| 84 |
+
}
|
| 85 |
+
}
|
node_modules/zod-to-json-schema/postcjs.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { writeFileSync } from "fs";
|
| 2 |
+
|
| 3 |
+
writeFileSync("./dist/cjs/package.json", '{"type":"commonjs"}', "utf-8");
|
node_modules/zod-to-json-schema/postesm.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { writeFileSync } from "fs";
|
| 2 |
+
|
| 3 |
+
writeFileSync("./dist/esm/package.json", '{"type":"module","main":"index.js"}', "utf-8");
|
node_modules/zod-validation-error/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(The MIT License)
|
| 2 |
+
|
| 3 |
+
Copyright 2022 Causaly, Inc <front-end@causaly.com>
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 6 |
+
|
| 7 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 8 |
+
|
| 9 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEAL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|
|
|
|
|
|
|
|
|
| 1 |
+
# zod-validation-error
|
| 2 |
+
|
| 3 |
+
Wrap zod validation errors in user-friendly readable messages.
|
| 4 |
+
|
| 5 |
+
[](https://github.com/causaly/zod-validation-error/actions/workflows/ci.yml) [](https://www.npmjs.com/package/zod-validation-error)
|
| 6 |
+
|
| 7 |
+
#### Features
|
| 8 |
+
|
| 9 |
+
- User-friendly readable error messages with extensive configuration options;
|
| 10 |
+
- Preserves original error details accessible via `error.details`;
|
| 11 |
+
- Provides a custom error map for better user-friendly messages;
|
| 12 |
+
- Supports both Zod v3 and v4.
|
| 13 |
+
|
| 14 |
+
**_Note:_** This version of `zod-validation-error` works with zod v4. If you are looking for zod v3 support, please refer to the [v3 documentation](./README.v3.md)
|
| 15 |
+
|
| 16 |
+
## Installation
|
| 17 |
+
|
| 18 |
+
```bash
|
| 19 |
+
npm install zod-validation-error
|
| 20 |
+
```
|
| 21 |
+
|
| 22 |
+
#### Requirements
|
| 23 |
+
|
| 24 |
+
- Node.js v.18+
|
| 25 |
+
- TypeScript v.4.5+
|
| 26 |
+
|
| 27 |
+
## Quick start
|
| 28 |
+
|
| 29 |
+
```typescript
|
| 30 |
+
import { z as zod } from 'zod';
|
| 31 |
+
import { fromError, createErrorMap } from 'zod-validation-error';
|
| 32 |
+
|
| 33 |
+
// configure zod to use zod-validation-error's error map
|
| 34 |
+
// this is optional, you may also use your own custom error map or zod's native error map
|
| 35 |
+
// we recommend using zod-validation-error's error map for better user-friendly messages
|
| 36 |
+
// see https://zod.dev/error-customization for further details
|
| 37 |
+
zod.config({
|
| 38 |
+
customError: createErrorMap(),
|
| 39 |
+
});
|
| 40 |
+
|
| 41 |
+
// create zod schema
|
| 42 |
+
const zodSchema = zod.object({
|
| 43 |
+
id: zod.int().positive(),
|
| 44 |
+
email: zod.email(),
|
| 45 |
+
});
|
| 46 |
+
|
| 47 |
+
// parse some invalid value
|
| 48 |
+
try {
|
| 49 |
+
zodSchema.parse({
|
| 50 |
+
id: 1,
|
| 51 |
+
email: 'coyote@acme', // note: invalid email
|
| 52 |
+
});
|
| 53 |
+
} catch (err) {
|
| 54 |
+
const validationError = fromError(err);
|
| 55 |
+
// the error is now readable by the user
|
| 56 |
+
// you may print it to console
|
| 57 |
+
console.log(validationError.toString());
|
| 58 |
+
// or return it as an actual error
|
| 59 |
+
return validationError;
|
| 60 |
+
}
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
## Motivation
|
| 64 |
+
|
| 65 |
+
Zod errors are difficult to consume for the end-user. This library wraps Zod validation errors in user-friendly readable messages that can be exposed to the outer world, while maintaining the original errors in an array for _dev_ use.
|
| 66 |
+
|
| 67 |
+
### Example
|
| 68 |
+
|
| 69 |
+
#### Input (from Zod)
|
| 70 |
+
|
| 71 |
+
```json
|
| 72 |
+
[
|
| 73 |
+
{
|
| 74 |
+
"origin": "number",
|
| 75 |
+
"code": "too_small",
|
| 76 |
+
"minimum": 0,
|
| 77 |
+
"inclusive": false,
|
| 78 |
+
"path": ["id"],
|
| 79 |
+
"message": "Number must be greater than 0 at \"id\""
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"origin": "string",
|
| 83 |
+
"code": "invalid_format",
|
| 84 |
+
"format": "email",
|
| 85 |
+
"pattern": "/^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$/",
|
| 86 |
+
"path": ["email"],
|
| 87 |
+
"message": "Invalid email at \"email\""
|
| 88 |
+
}
|
| 89 |
+
]
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
#### Output
|
| 93 |
+
|
| 94 |
+
```
|
| 95 |
+
Validation error: Number must be greater than 0 at "id"; Invalid email at "email"
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
## API
|
| 99 |
+
|
| 100 |
+
- [ValidationError(message[, options])](#validationerror)
|
| 101 |
+
- [createErrorMap(options)](#createErrorMap)
|
| 102 |
+
- [createMessageBuilder(options)](#createMessageBuilder)
|
| 103 |
+
- [isValidationError(error)](#isvalidationerror)
|
| 104 |
+
- [isValidationErrorLike(error)](#isvalidationerrorlike)
|
| 105 |
+
- [isZodErrorLike(error)](#iszoderrorlike)
|
| 106 |
+
- [fromError(error[, options])](#fromerror)
|
| 107 |
+
- [fromZodIssue(zodIssue[, options])](#fromzodissue)
|
| 108 |
+
- [fromZodError(zodError[, options])](#fromzoderror)
|
| 109 |
+
- [toValidationError([options]) => (error) => ValidationError](#tovalidationerror)
|
| 110 |
+
|
| 111 |
+
### ValidationError
|
| 112 |
+
|
| 113 |
+
Main `ValidationError` class, extending JavaScript's native `Error`.
|
| 114 |
+
|
| 115 |
+
#### Arguments
|
| 116 |
+
|
| 117 |
+
- `message` - _string_; error message (required)
|
| 118 |
+
- `options` - _ErrorOptions_; error options as per [JavaScript definition](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error#options) (optional)
|
| 119 |
+
- `options.cause` - _any_; can be used to hold the original zod error (optional)
|
| 120 |
+
|
| 121 |
+
#### Example 1: construct new ValidationError with `message`
|
| 122 |
+
|
| 123 |
+
```typescript
|
| 124 |
+
import { ValidationError } from 'zod-validation-error';
|
| 125 |
+
|
| 126 |
+
const error = new ValidationError('foobar');
|
| 127 |
+
console.log(error instanceof Error); // prints true
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
#### Example 2: construct new ValidationError with `message` and `options.cause`
|
| 131 |
+
|
| 132 |
+
```typescript
|
| 133 |
+
import { z as zod } from 'zod';
|
| 134 |
+
import { ValidationError } from 'zod-validation-error';
|
| 135 |
+
|
| 136 |
+
const error = new ValidationError('foobar', {
|
| 137 |
+
cause: new zod.ZodError([
|
| 138 |
+
{
|
| 139 |
+
origin: 'number',
|
| 140 |
+
code: 'too_small',
|
| 141 |
+
minimum: 0,
|
| 142 |
+
inclusive: false,
|
| 143 |
+
path: ['id'],
|
| 144 |
+
message: 'Number must be greater than 0 at "id"',
|
| 145 |
+
input: -1,
|
| 146 |
+
},
|
| 147 |
+
]),
|
| 148 |
+
});
|
| 149 |
+
|
| 150 |
+
console.log(error.details); // prints issues from zod error
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
### createErrorMap
|
| 154 |
+
|
| 155 |
+
Creates zod-validation-error's `errorMap`, which is used to format issues into user-friendly error messages.
|
| 156 |
+
|
| 157 |
+
We think that zod's native error map is not user-friendly enough, so we provide our own implementation that formats issues into human-readable messages.
|
| 158 |
+
|
| 159 |
+
Note: zod-validation-error's `errorMap` is an errorMap like all others and thus can also be used directly with `zod` (see https://zod.dev/error-customization for further details), e.g.
|
| 160 |
+
|
| 161 |
+
#### Arguments
|
| 162 |
+
|
| 163 |
+
- `options` - _Object_; formatting options (optional)
|
| 164 |
+
|
| 165 |
+
##### createErrorMap Options
|
| 166 |
+
|
| 167 |
+
| Name | Type | Description |
|
| 168 |
+
| ------------------------------- | :-------------------------------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 169 |
+
| `displayInvalidFormatDetails` | `boolean` | Indicates whether to display invalid format details (e.g. regexp pattern) in the error message (optional, defaults to `false`) |
|
| 170 |
+
| `maxAllowedValuesToDisplay` | `number` | Max number of allowed values to display (optional, defaults to `10`). Allowed values beyond this limit will be hidden. |
|
| 171 |
+
| `allowedValuesSeparator` | `string` | Used to concatenate allowed values in the message (optional, defaults to `", "`) |
|
| 172 |
+
| `allowedValuesLastSeparator` | `string \| undefined` | Used to concatenate last allowed value in the message (optional, defaults to `" or "`). Set to `undefined` to disable. |
|
| 173 |
+
| `wrapAllowedValuesInQuote` | `boolean` | Indicates whether to wrap allowed values in quotes (optional, defaults to `true`). Note that this only applies to string values. |
|
| 174 |
+
| `maxUnrecognizedKeysToDisplay` | `number` | Max number of unrecognized keys to display in the error message (optional, defaults to `5`) |
|
| 175 |
+
| `unrecognizedKeysSeparator` | `string` | Used to concatenate unrecognized keys in the message (optional, defaults to `", "`) |
|
| 176 |
+
| `unrecognizedKeysLastSeparator` | `string \| undefined` | Used to concatenate the last unrecognized key in message (optional, defaults to `" and "`). Set to `undefined` to disable. |
|
| 177 |
+
| `wrapUnrecognizedKeysInQuote` | `boolean` | Indicates whether to wrap unrecognized keys in quotes (optional, defaults to `true`). Note that this only applies to string keys. |
|
| 178 |
+
| `dateLocalization` | `boolean \| Intl.LocalesArgument` | Indicates whether to localize date values (optional, defaults to `true`). If set to `true`, it will use the default locale of the environment. You can also pass `Intl.LocalesArgument` to specify a custom locale. |
|
| 179 |
+
| `numberLocalization` | `boolean \| Intl.LocalesArgument` | Indicates whether to localize numeric values (optional, defaults to `true`). If set to `true`, it will use the default locale of the environment. You can also pass `Intl.LocalesArgument` to specify a custom locale. |
|
| 180 |
+
|
| 181 |
+
#### Example
|
| 182 |
+
|
| 183 |
+
```typescript
|
| 184 |
+
import { z as zod } from 'zod';
|
| 185 |
+
import { createErrorMap } from 'zod-validation-error';
|
| 186 |
+
|
| 187 |
+
zod.config({
|
| 188 |
+
customError: createErrorMap({
|
| 189 |
+
// default values are used when not specified
|
| 190 |
+
displayInvalidFormatDetails: true,
|
| 191 |
+
}),
|
| 192 |
+
});
|
| 193 |
+
```
|
| 194 |
+
|
| 195 |
+
### createMessageBuilder
|
| 196 |
+
|
| 197 |
+
Creates zod-validation-error's default `MessageBuilder`, which is used to produce user-friendly error messages.
|
| 198 |
+
|
| 199 |
+
Meant to be passed as an option to [fromError](#fromerror), [fromZodIssue](#fromzodissue), [fromZodError](#fromzoderror) or [toValidationError](#tovalidationerror).
|
| 200 |
+
|
| 201 |
+
#### Arguments
|
| 202 |
+
|
| 203 |
+
- `options` - _Object_; formatting options (optional)
|
| 204 |
+
|
| 205 |
+
##### createMessageBuilder Options
|
| 206 |
+
|
| 207 |
+
| Name | Type | Description |
|
| 208 |
+
| -------------------- | :-------------------: | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
| 209 |
+
| `maxIssuesInMessage` | `number` | Max issues to include in user-friendly message (optional, defaults to `99`) |
|
| 210 |
+
| `issueSeparator` | `string` | Used to concatenate issues in user-friendly message (optional, defaults to `";"`) |
|
| 211 |
+
| `unionSeparator` | `string` | Used to concatenate union-issues in user-friendly message (optional, defaults to `" or "`) |
|
| 212 |
+
| `prefix` | `string \| undefined` | Prefix to use in user-friendly message (optional, defaults to `"Validation error"`). Pass `undefined` to disable prefix completely. |
|
| 213 |
+
| `prefixSeparator` | `string` | Used to concatenate prefix with rest of the user-friendly message (optional, defaults to `": "`). Not used when `prefix` is `undefined`. |
|
| 214 |
+
| `includePath` | `boolean` | Indicates whether to include the erroneous property key in the error message (optional, defaults to `true`) |
|
| 215 |
+
| `forceTitleCase` | `boolean` | Indicates whether to convert individual issue messages to title case (optional, defaults to `true`). |
|
| 216 |
+
|
| 217 |
+
#### Example
|
| 218 |
+
|
| 219 |
+
```typescript
|
| 220 |
+
import { createMessageBuilder } from 'zod-validation-error';
|
| 221 |
+
|
| 222 |
+
const messageBuilder = createMessageBuilder({
|
| 223 |
+
maxIssuesInMessage: 3,
|
| 224 |
+
includePath: false,
|
| 225 |
+
});
|
| 226 |
+
```
|
| 227 |
+
|
| 228 |
+
### isValidationError
|
| 229 |
+
|
| 230 |
+
A [type guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates) utility function, based on `instanceof` comparison.
|
| 231 |
+
|
| 232 |
+
#### Arguments
|
| 233 |
+
|
| 234 |
+
- `error` - error instance (required)
|
| 235 |
+
|
| 236 |
+
#### Example
|
| 237 |
+
|
| 238 |
+
```typescript
|
| 239 |
+
import { z as zod } from 'zod';
|
| 240 |
+
import { ValidationError, isValidationError } from 'zod-validation-error';
|
| 241 |
+
|
| 242 |
+
const err = new ValidationError('foobar');
|
| 243 |
+
isValidationError(err); // returns true
|
| 244 |
+
|
| 245 |
+
const invalidErr = new Error('foobar');
|
| 246 |
+
isValidationError(err); // returns false
|
| 247 |
+
```
|
| 248 |
+
|
| 249 |
+
### isValidationErrorLike
|
| 250 |
+
|
| 251 |
+
A [type guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates) utility function, based on _heuristics_ comparison.
|
| 252 |
+
|
| 253 |
+
_Why do we need heuristics since we can use a simple `instanceof` comparison?_ Because of multi-version inconsistencies. For instance, it's possible that a dependency is using an older `zod-validation-error` version internally. In such case, the `instanceof` comparison will yield invalid results because module deduplication does not apply at npm/yarn level and the prototype is different.
|
| 254 |
+
|
| 255 |
+
tl;dr if you are uncertain then it is preferable to use `isValidationErrorLike` instead of `isValidationError`.
|
| 256 |
+
|
| 257 |
+
#### Arguments
|
| 258 |
+
|
| 259 |
+
- `error` - error instance (required)
|
| 260 |
+
|
| 261 |
+
#### Example
|
| 262 |
+
|
| 263 |
+
```typescript
|
| 264 |
+
import { ValidationError, isValidationErrorLike } from 'zod-validation-error';
|
| 265 |
+
|
| 266 |
+
const err = new ValidationError('foobar');
|
| 267 |
+
isValidationErrorLike(err); // returns true
|
| 268 |
+
|
| 269 |
+
const invalidErr = new Error('foobar');
|
| 270 |
+
isValidationErrorLike(err); // returns false
|
| 271 |
+
```
|
| 272 |
+
|
| 273 |
+
### isZodErrorLike
|
| 274 |
+
|
| 275 |
+
A [type guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates) utility function, based on _heuristics_ comparison.
|
| 276 |
+
|
| 277 |
+
_Why do we need heuristics since we can use a simple `instanceof` comparison?_ Because of multi-version inconsistencies. For instance, it's possible that a dependency is using an older `zod` version internally. In such case, the `instanceof` comparison will yield invalid results because module deduplication does not apply at npm/yarn level and the prototype is different.
|
| 278 |
+
|
| 279 |
+
#### Arguments
|
| 280 |
+
|
| 281 |
+
- `error` - error instance (required)
|
| 282 |
+
|
| 283 |
+
#### Example
|
| 284 |
+
|
| 285 |
+
```typescript
|
| 286 |
+
import { z as zod } from 'zod';
|
| 287 |
+
import { ValidationError, isZodErrorLike } from 'zod-validation-error';
|
| 288 |
+
|
| 289 |
+
const zodValidationErr = new ValidationError('foobar');
|
| 290 |
+
isZodErrorLike(zodValidationErr); // returns false
|
| 291 |
+
|
| 292 |
+
const genericErr = new Error('foobar');
|
| 293 |
+
isZodErrorLike(genericErr); // returns false
|
| 294 |
+
|
| 295 |
+
const zodErr = new zod.ZodError([
|
| 296 |
+
{
|
| 297 |
+
origin: 'number',
|
| 298 |
+
code: 'too_small',
|
| 299 |
+
minimum: 0,
|
| 300 |
+
inclusive: false,
|
| 301 |
+
path: ['id'],
|
| 302 |
+
message: 'Number must be greater than 0 at "id"',
|
| 303 |
+
input: -1,
|
| 304 |
+
},
|
| 305 |
+
]);
|
| 306 |
+
isZodErrorLike(zodErr); // returns true
|
| 307 |
+
```
|
| 308 |
+
|
| 309 |
+
### fromError
|
| 310 |
+
|
| 311 |
+
Converts an error to `ValidationError`.
|
| 312 |
+
|
| 313 |
+
_What is the difference between `fromError` and `fromZodError`?_ The `fromError` function is a less strict version of `fromZodError`. It can accept an unknown error and attempt to convert it to a `ValidationError`.
|
| 314 |
+
|
| 315 |
+
#### Arguments
|
| 316 |
+
|
| 317 |
+
- `error` - _unknown_; an error (required)
|
| 318 |
+
- `options` - _Object_; formatting options (optional)
|
| 319 |
+
- `messageBuilder` - _MessageBuilder_; a function that accepts an array of `zod.ZodIssue` objects and returns a user-friendly error message in the form of a `string` (optional).
|
| 320 |
+
|
| 321 |
+
#### Notes
|
| 322 |
+
|
| 323 |
+
Alternatively, you may pass [createMessageBuilder options](#createmessagebuilder-options) directly as `options`. These will be used as arguments to create the `MessageBuilder` instance internally.
|
| 324 |
+
|
| 325 |
+
### fromZodIssue
|
| 326 |
+
|
| 327 |
+
Converts a single zod issue to `ValidationError`.
|
| 328 |
+
|
| 329 |
+
#### Arguments
|
| 330 |
+
|
| 331 |
+
- `zodIssue` - _zod.ZodIssue_; a ZodIssue instance (required)
|
| 332 |
+
- `options` - _Object_; formatting options (optional)
|
| 333 |
+
- `messageBuilder` - _MessageBuilder_; a function that accepts an array of `zod.ZodIssue` objects and returns a user-friendly error message in the form of a `string` (optional).
|
| 334 |
+
|
| 335 |
+
#### Notes
|
| 336 |
+
|
| 337 |
+
Alternatively, you may pass [createMessageBuilder options](#createmessagebuilder-options) directly as `options`. These will be used as arguments to create the `MessageBuilder` instance internally.
|
| 338 |
+
|
| 339 |
+
### fromZodError
|
| 340 |
+
|
| 341 |
+
Converts zod error to `ValidationError`.
|
| 342 |
+
|
| 343 |
+
_Why is the difference between `ZodError` and `ZodIssue`?_ A `ZodError` is a collection of 1 or more `ZodIssue` instances. It's what you get when you call `zodSchema.parse()`.
|
| 344 |
+
|
| 345 |
+
#### Arguments
|
| 346 |
+
|
| 347 |
+
- `zodError` - _zod.ZodError_; a ZodError instance (required)
|
| 348 |
+
- `options` - _Object_; formatting options (optional)
|
| 349 |
+
- `messageBuilder` - _MessageBuilder_; a function that accepts an array of `zod.ZodIssue` objects and returns a user-friendly error message in the form of a `string` (optional).
|
| 350 |
+
|
| 351 |
+
#### Notes
|
| 352 |
+
|
| 353 |
+
Alternatively, you may pass [createMessageBuilder options](#createmessagebuilder-optionscreateMessageBuilder) directly as `options`. These will be used as arguments to create the `MessageBuilder` instance internally.
|
| 354 |
+
|
| 355 |
+
### toValidationError
|
| 356 |
+
|
| 357 |
+
A curried version of `fromZodError` meant to be used for FP (Functional Programming). Note it first takes the options object if needed and returns a function that converts the `zodError` to a `ValidationError` object
|
| 358 |
+
|
| 359 |
+
```js
|
| 360 |
+
toValidationError(options) => (zodError) => ValidationError
|
| 361 |
+
```
|
| 362 |
+
|
| 363 |
+
#### Example using fp-ts
|
| 364 |
+
|
| 365 |
+
```typescript
|
| 366 |
+
import * as Either from 'fp-ts/Either';
|
| 367 |
+
import { z as zod } from 'zod';
|
| 368 |
+
import { toValidationError, ValidationError } from 'zod-validation-error';
|
| 369 |
+
|
| 370 |
+
// create zod schema
|
| 371 |
+
const zodSchema = zod
|
| 372 |
+
.object({
|
| 373 |
+
id: zod.int().positive(),
|
| 374 |
+
email: zod.email(),
|
| 375 |
+
})
|
| 376 |
+
.brand<'User'>();
|
| 377 |
+
|
| 378 |
+
export type User = zod.infer<typeof zodSchema>;
|
| 379 |
+
|
| 380 |
+
export function parse(
|
| 381 |
+
value: zod.input<typeof zodSchema>
|
| 382 |
+
): Either.Either<ValidationError, User> {
|
| 383 |
+
return Either.tryCatch(() => schema.parse(value), toValidationError());
|
| 384 |
+
}
|
| 385 |
+
```
|
| 386 |
+
|
| 387 |
+
## FAQ
|
| 388 |
+
|
| 389 |
+
### What is the difference between zod-validation-error and zod's own [prettifyError](https://zod.dev/error-formatting#zprettifyerror)?
|
| 390 |
+
|
| 391 |
+
While both libraries aim to provide a human-readable string representation of a zod error, they differ in several ways...
|
| 392 |
+
|
| 393 |
+
1. **End-user focus**: zod-validation-error provides opinionated, user-friendly error messages designed to be displayed directly to end-users in forms or API responses.
|
| 394 |
+
1. **Customization options**: zod-validation-error offers extensive configuration for message formatting, such as controlling path inclusion, allowed values display, localization, and more.
|
| 395 |
+
1. **Error handling**: zod-validation-error maintains the original error details while providing a clean, consistent interface through the ValidationError class.
|
| 396 |
+
1. **Integration flexibility**: Beyond just formatting, zod-validation-error provides utility functions for error detection and conversion that work well in various architectural patterns, e.g. functional programming.
|
| 397 |
+
|
| 398 |
+
Disclaimer: as per this [comment](https://github.com/causaly/zod-validation-error/issues/455#issuecomment-2811895152), we have no intention to antagonize zod. In fact, we are happy to decommission this module assuming it's in the best interest of the community. As of now, it seems that there's room for both `zod-validation-error` and `prettifyError`, also based on Colin McDonnell's [response](https://github.com/causaly/zod-validation-error/issues/455#issuecomment-2814466019).
|
| 399 |
+
|
| 400 |
+
### Do I need to use `zod-validation-error`'s error map?
|
| 401 |
+
|
| 402 |
+
No, you can use zod's native error map if you prefer. However, we recommend using `zod-validation-error`'s error map for better user-friendly messages.
|
| 403 |
+
|
| 404 |
+
You may also use your own custom error map if you have specific requirements, e.g. internationalization.
|
| 405 |
+
|
| 406 |
+
### Where can I see how `zod-validation-error`'s error map formatting works?
|
| 407 |
+
|
| 408 |
+
The easiest way to understand how `zod-validation-error`'s error map works is to look at the [tests](./lib/v4/errorMap/errorMap.test.ts). They cover various scenarios and demonstrate how the error map formats issues into user-friendly messages.
|
| 409 |
+
|
| 410 |
+
### How to distinguish between errors
|
| 411 |
+
|
| 412 |
+
Use the `isValidationErrorLike` type guard.
|
| 413 |
+
|
| 414 |
+
#### Example
|
| 415 |
+
|
| 416 |
+
Scenario: Distinguish between `ValidationError` VS generic `Error` in order to respond with 400 VS 500 HTTP status code respectively.
|
| 417 |
+
|
| 418 |
+
```typescript
|
| 419 |
+
import { isValidationErrorLike } from 'zod-validation-error';
|
| 420 |
+
|
| 421 |
+
try {
|
| 422 |
+
func(); // throws Error - or - ValidationError
|
| 423 |
+
} catch (err) {
|
| 424 |
+
if (isValidationErrorLike(err)) {
|
| 425 |
+
return 400; // Bad Data (this is a client error)
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
return 500; // Server Error
|
| 429 |
+
}
|
| 430 |
+
```
|
| 431 |
+
|
| 432 |
+
### How to use `ValidationError` outside `zod`
|
| 433 |
+
|
| 434 |
+
It's possible to implement custom validation logic outside `zod` and throw a `ValidationError`.
|
| 435 |
+
|
| 436 |
+
#### Example 1: passing custom message
|
| 437 |
+
|
| 438 |
+
```typescript
|
| 439 |
+
import { ValidationError } from 'zod-validation-error';
|
| 440 |
+
import { Buffer } from 'node:buffer';
|
| 441 |
+
|
| 442 |
+
function parseBuffer(buf: unknown): Buffer {
|
| 443 |
+
if (!Buffer.isBuffer(buf)) {
|
| 444 |
+
throw new ValidationError('Invalid argument; expected buffer');
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
return buf;
|
| 448 |
+
}
|
| 449 |
+
```
|
| 450 |
+
|
| 451 |
+
#### Example 2: passing custom message and original error as cause
|
| 452 |
+
|
| 453 |
+
```typescript
|
| 454 |
+
import { ValidationError } from 'zod-validation-error';
|
| 455 |
+
|
| 456 |
+
try {
|
| 457 |
+
// do something that throws an error
|
| 458 |
+
} catch (err) {
|
| 459 |
+
throw new ValidationError('Something went deeply wrong', { cause: err });
|
| 460 |
+
}
|
| 461 |
+
```
|
| 462 |
+
|
| 463 |
+
### How to use `ValidationError` with custom "error map"
|
| 464 |
+
|
| 465 |
+
Zod supports customizing error messages by providing a custom "error map". You may combine this with `zod-validation-error` to produce user-friendly messages.
|
| 466 |
+
|
| 467 |
+
#### Example: produce user-friendly error messages using the `customError` property
|
| 468 |
+
|
| 469 |
+
If all you need is to produce user-friendly error messages you may use the `customError` property.
|
| 470 |
+
|
| 471 |
+
```typescript
|
| 472 |
+
import { z as zod } from 'zod';
|
| 473 |
+
import { createErrorMap } from 'zod-validation-error';
|
| 474 |
+
|
| 475 |
+
zod.config({
|
| 476 |
+
customError: createErrorMap({
|
| 477 |
+
includePath: true,
|
| 478 |
+
}),
|
| 479 |
+
});
|
| 480 |
+
```
|
| 481 |
+
|
| 482 |
+
`zod-validation-error` will respect the `customError` property when it is set, no further configuration is needed.
|
| 483 |
+
|
| 484 |
+
### Does `zod-validation-error` support CommonJS
|
| 485 |
+
|
| 486 |
+
Yes, `zod-validation-error` supports CommonJS out-of-the-box. All you need to do is import it using `require`.
|
| 487 |
+
|
| 488 |
+
#### Example
|
| 489 |
+
|
| 490 |
+
```typescript
|
| 491 |
+
const { ValidationError } = require('zod-validation-error');
|
| 492 |
+
```
|
| 493 |
+
|
| 494 |
+
## Contribute
|
| 495 |
+
|
| 496 |
+
Source code contributions are most welcome. Please open a PR, ensure the linter is satisfied and all tests pass.
|
| 497 |
+
|
| 498 |
+
#### We are hiring
|
| 499 |
+
|
| 500 |
+
Causaly is building the world's largest biomedical knowledge platform, using technologies such as TypeScript, React and Node.js. Find out more about our openings at https://jobs.ashbyhq.com/causaly.
|
| 501 |
+
|
| 502 |
+
## License
|
| 503 |
+
|
| 504 |
+
MIT
|
node_modules/zod-validation-error/README.v3.md
ADDED
|
@@ -0,0 +1,558 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# zod-validation-error
|
| 2 |
+
|
| 3 |
+
Wrap zod validation errors in user-friendly readable messages.
|
| 4 |
+
|
| 5 |
+
[](https://github.com/causaly/zod-validation-error/actions/workflows/ci.yml) [](https://www.npmjs.com/package/zod-validation-error)
|
| 6 |
+
|
| 7 |
+
#### Features
|
| 8 |
+
|
| 9 |
+
- User-friendly readable messages, configurable via options;
|
| 10 |
+
- Maintain original issues under `error.details`;
|
| 11 |
+
- Supports both `zod` v3 and v4.
|
| 12 |
+
|
| 13 |
+
**_Note:_** This is the v3 version of `zod-validation-error`. If you are looking for zod v4 support, please click [here](/README.md).
|
| 14 |
+
|
| 15 |
+
## Installation
|
| 16 |
+
|
| 17 |
+
```bash
|
| 18 |
+
npm install zod-validation-error
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
#### Requirements
|
| 22 |
+
|
| 23 |
+
- Node.js v.18+
|
| 24 |
+
- TypeScript v.4.5+
|
| 25 |
+
|
| 26 |
+
## Quick start
|
| 27 |
+
|
| 28 |
+
```typescript
|
| 29 |
+
import { z as zod } from 'zod/v3';
|
| 30 |
+
import { fromError } from 'zod-validation-error/v3';
|
| 31 |
+
|
| 32 |
+
// create zod schema
|
| 33 |
+
const zodSchema = zod.object({
|
| 34 |
+
id: zod.number().int().positive(),
|
| 35 |
+
email: zod.string().email(),
|
| 36 |
+
});
|
| 37 |
+
|
| 38 |
+
// parse some invalid value
|
| 39 |
+
try {
|
| 40 |
+
zodSchema.parse({
|
| 41 |
+
id: 1,
|
| 42 |
+
email: 'foobar', // note: invalid email
|
| 43 |
+
});
|
| 44 |
+
} catch (err) {
|
| 45 |
+
const validationError = fromError(err);
|
| 46 |
+
// the error is now readable by the user
|
| 47 |
+
// you may print it to console
|
| 48 |
+
console.log(validationError.toString());
|
| 49 |
+
// or return it as an actual error
|
| 50 |
+
return validationError;
|
| 51 |
+
}
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
## Motivation
|
| 55 |
+
|
| 56 |
+
Zod errors are difficult to consume for the end-user. This library wraps Zod validation errors in user-friendly readable messages that can be exposed to the outer world, while maintaining the original errors in an array for _dev_ use.
|
| 57 |
+
|
| 58 |
+
### Example
|
| 59 |
+
|
| 60 |
+
#### Input (from Zod)
|
| 61 |
+
|
| 62 |
+
```json
|
| 63 |
+
[
|
| 64 |
+
{
|
| 65 |
+
"code": "too_small",
|
| 66 |
+
"inclusive": false,
|
| 67 |
+
"message": "Number must be greater than 0",
|
| 68 |
+
"minimum": 0,
|
| 69 |
+
"path": ["id"],
|
| 70 |
+
"type": "number"
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"code": "invalid_string",
|
| 74 |
+
"message": "Invalid email",
|
| 75 |
+
"path": ["email"],
|
| 76 |
+
"validation": "email"
|
| 77 |
+
}
|
| 78 |
+
]
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
#### Output
|
| 82 |
+
|
| 83 |
+
```
|
| 84 |
+
Validation error: Number must be greater than 0 at "id"; Invalid email at "email"
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
## API
|
| 88 |
+
|
| 89 |
+
- [ValidationError(message[, options])](#validationerror)
|
| 90 |
+
- [createMessageBuilder(props)](#createMessageBuilder)
|
| 91 |
+
- [errorMap](#errormap)
|
| 92 |
+
- [isValidationError(error)](#isvalidationerror)
|
| 93 |
+
- [isValidationErrorLike(error)](#isvalidationerrorlike)
|
| 94 |
+
- [isZodErrorLike(error)](#iszoderrorlike)
|
| 95 |
+
- [fromError(error[, options])](#fromerror)
|
| 96 |
+
- [fromZodIssue(zodIssue[, options])](#fromzodissue)
|
| 97 |
+
- [fromZodError(zodError[, options])](#fromzoderror)
|
| 98 |
+
- [toValidationError([options]) => (error) => ValidationError](#tovalidationerror)
|
| 99 |
+
|
| 100 |
+
### ValidationError
|
| 101 |
+
|
| 102 |
+
Main `ValidationError` class, extending native JavaScript `Error`.
|
| 103 |
+
|
| 104 |
+
#### Arguments
|
| 105 |
+
|
| 106 |
+
- `message` - _string_; error message (required)
|
| 107 |
+
- `options` - _ErrorOptions_; error options as per [JavaScript definition](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error#options) (optional)
|
| 108 |
+
- `options.cause` - _any_; can be used to hold the original zod error (optional)
|
| 109 |
+
|
| 110 |
+
#### Example 1: construct new ValidationError with `message`
|
| 111 |
+
|
| 112 |
+
```typescript
|
| 113 |
+
const { ValidationError } = require('zod-validation-error');
|
| 114 |
+
|
| 115 |
+
const error = new ValidationError('foobar');
|
| 116 |
+
console.log(error instanceof Error); // prints true
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
#### Example 2: construct new ValidationError with `message` and `options.cause`
|
| 120 |
+
|
| 121 |
+
```typescript
|
| 122 |
+
import { z as zod } from 'zod/v3';
|
| 123 |
+
const { ValidationError } = require('zod-validation-error');
|
| 124 |
+
|
| 125 |
+
const error = new ValidationError('foobar', {
|
| 126 |
+
cause: new zod.ZodError([
|
| 127 |
+
{
|
| 128 |
+
code: 'invalid_string',
|
| 129 |
+
message: 'Invalid email',
|
| 130 |
+
path: ['email'],
|
| 131 |
+
validation: 'email',
|
| 132 |
+
},
|
| 133 |
+
]),
|
| 134 |
+
});
|
| 135 |
+
|
| 136 |
+
console.log(error.details); // prints issues from zod error
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
### createMessageBuilder
|
| 140 |
+
|
| 141 |
+
Creates zod-validation-error's default `MessageBuilder`, which is used to produce user-friendly error messages.
|
| 142 |
+
|
| 143 |
+
Meant to be passed as an option to [fromError](#fromerror), [fromZodIssue](#fromzodissue), [fromZodError](#fromzoderror) or [toValidationError](#tovalidationerror).
|
| 144 |
+
|
| 145 |
+
You may read more on the concept of the `MessageBuilder` further [below](#MessageBuilder).
|
| 146 |
+
|
| 147 |
+
#### Arguments
|
| 148 |
+
|
| 149 |
+
- `props` - _Object_; formatting options (optional)
|
| 150 |
+
- `maxIssuesInMessage` - _number_; max issues to include in user-friendly message (optional, defaults to 99)
|
| 151 |
+
- `issueSeparator` - _string_; used to concatenate issues in user-friendly message (optional, defaults to ";")
|
| 152 |
+
- `unionSeparator` - _string_; used to concatenate union-issues in user-friendly message (optional, defaults to ", or")
|
| 153 |
+
- `prefix` - _string_ or _null_; prefix to use in user-friendly message (optional, defaults to "Validation error"). Pass `null` to disable prefix completely.
|
| 154 |
+
- `prefixSeparator` - _string_; used to concatenate prefix with rest of the user-friendly message (optional, defaults to ": "). Not used when `prefix` is `null`.
|
| 155 |
+
- `includePath` - _boolean_; used to provide control on whether to include the erroneous property name suffix or not (optional, defaults to `true`).
|
| 156 |
+
|
| 157 |
+
#### Example
|
| 158 |
+
|
| 159 |
+
```typescript
|
| 160 |
+
import { createMessageBuilder } from 'zod-validation-error/v3';
|
| 161 |
+
|
| 162 |
+
const messageBuilder = createMessageBuilder({
|
| 163 |
+
includePath: false,
|
| 164 |
+
maxIssuesInMessage: 3,
|
| 165 |
+
});
|
| 166 |
+
```
|
| 167 |
+
|
| 168 |
+
### errorMap
|
| 169 |
+
|
| 170 |
+
A custom error map to use with zod's `setErrorMap` method and get user-friendly messages automatically.
|
| 171 |
+
|
| 172 |
+
#### Example
|
| 173 |
+
|
| 174 |
+
```typescript
|
| 175 |
+
import { z as zod } from 'zod/v3';
|
| 176 |
+
import { errorMap } from 'zod-validation-error/v3';
|
| 177 |
+
|
| 178 |
+
zod.setErrorMap(errorMap);
|
| 179 |
+
```
|
| 180 |
+
|
| 181 |
+
### isValidationError
|
| 182 |
+
|
| 183 |
+
A [type guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates) utility function, based on `instanceof` comparison.
|
| 184 |
+
|
| 185 |
+
#### Arguments
|
| 186 |
+
|
| 187 |
+
- `error` - error instance (required)
|
| 188 |
+
|
| 189 |
+
#### Example
|
| 190 |
+
|
| 191 |
+
```typescript
|
| 192 |
+
import { z as zod } from 'zod/v3';
|
| 193 |
+
import { ValidationError, isValidationError } from 'zod-validation-error/v3';
|
| 194 |
+
|
| 195 |
+
const err = new ValidationError('foobar');
|
| 196 |
+
isValidationError(err); // returns true
|
| 197 |
+
|
| 198 |
+
const invalidErr = new Error('foobar');
|
| 199 |
+
isValidationError(err); // returns false
|
| 200 |
+
```
|
| 201 |
+
|
| 202 |
+
### isValidationErrorLike
|
| 203 |
+
|
| 204 |
+
A [type guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates) utility function, based on _heuristics_ comparison.
|
| 205 |
+
|
| 206 |
+
_Why do we need heuristics since we can use a simple `instanceof` comparison?_ Because of multi-version inconsistencies. For instance, it's possible that a dependency is using an older `zod-validation-error` version internally. In such case, the `instanceof` comparison will yield invalid results because module deduplication does not apply at npm/yarn level and the prototype is different.
|
| 207 |
+
|
| 208 |
+
tl;dr if you are uncertain then it is preferable to use `isValidationErrorLike` instead of `isValidationError`.
|
| 209 |
+
|
| 210 |
+
#### Arguments
|
| 211 |
+
|
| 212 |
+
- `error` - error instance (required)
|
| 213 |
+
|
| 214 |
+
#### Example
|
| 215 |
+
|
| 216 |
+
```typescript
|
| 217 |
+
import {
|
| 218 |
+
ValidationError,
|
| 219 |
+
isValidationErrorLike,
|
| 220 |
+
} from 'zod-validation-error/v3';
|
| 221 |
+
|
| 222 |
+
const err = new ValidationError('foobar');
|
| 223 |
+
isValidationErrorLike(err); // returns true
|
| 224 |
+
|
| 225 |
+
const invalidErr = new Error('foobar');
|
| 226 |
+
isValidationErrorLike(err); // returns false
|
| 227 |
+
```
|
| 228 |
+
|
| 229 |
+
### isZodErrorLike
|
| 230 |
+
|
| 231 |
+
A [type guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates) utility function, based on _heuristics_ comparison.
|
| 232 |
+
|
| 233 |
+
_Why do we need heuristics since we can use a simple `instanceof` comparison?_ Because of multi-version inconsistencies. For instance, it's possible that a dependency is using an older `zod` version internally. In such case, the `instanceof` comparison will yield invalid results because module deduplication does not apply at npm/yarn level and the prototype is different.
|
| 234 |
+
|
| 235 |
+
#### Arguments
|
| 236 |
+
|
| 237 |
+
- `error` - error instance (required)
|
| 238 |
+
|
| 239 |
+
#### Example
|
| 240 |
+
|
| 241 |
+
```typescript
|
| 242 |
+
import { z as zod } from 'zod/v3';
|
| 243 |
+
import { ValidationError, isZodErrorLike } from 'zod-validation-error/v3';
|
| 244 |
+
|
| 245 |
+
const zodValidationErr = new ValidationError('foobar');
|
| 246 |
+
isZodErrorLike(zodValidationErr); // returns false
|
| 247 |
+
|
| 248 |
+
const genericErr = new Error('foobar');
|
| 249 |
+
isZodErrorLike(genericErr); // returns false
|
| 250 |
+
|
| 251 |
+
const zodErr = new zod.ZodError([
|
| 252 |
+
{
|
| 253 |
+
code: zod.ZodIssueCode.custom,
|
| 254 |
+
path: [],
|
| 255 |
+
message: 'foobar',
|
| 256 |
+
fatal: true,
|
| 257 |
+
},
|
| 258 |
+
]);
|
| 259 |
+
isZodErrorLike(zodErr); // returns true
|
| 260 |
+
```
|
| 261 |
+
|
| 262 |
+
### fromError
|
| 263 |
+
|
| 264 |
+
Converts an error to `ValidationError`.
|
| 265 |
+
|
| 266 |
+
_What is the difference between `fromError` and `fromZodError`?_ The `fromError` function is a less strict version of `fromZodError`. It can accept an unknown error and attempt to convert it to a `ValidationError`.
|
| 267 |
+
|
| 268 |
+
#### Arguments
|
| 269 |
+
|
| 270 |
+
- `error` - _unknown_; an error (required)
|
| 271 |
+
- `options` - _Object_; formatting options (optional)
|
| 272 |
+
- `messageBuilder` - _MessageBuilder_; a function that accepts an array of `zod.ZodIssue` objects and returns a user-friendly error message in the form of a `string` (optional).
|
| 273 |
+
|
| 274 |
+
#### Notes
|
| 275 |
+
|
| 276 |
+
Alternatively, you may pass the following `options` instead of a `messageBuilder`.
|
| 277 |
+
|
| 278 |
+
- `options` - _Object_; formatting options (optional)
|
| 279 |
+
- `maxIssuesInMessage` - _number_; max issues to include in user-friendly message (optional, defaults to 99)
|
| 280 |
+
- `issueSeparator` - _string_; used to concatenate issues in user-friendly message (optional, defaults to ";")
|
| 281 |
+
- `unionSeparator` - _string_; used to concatenate union-issues in user-friendly message (optional, defaults to ", or")
|
| 282 |
+
- `prefix` - _string_ or _null_; prefix to use in user-friendly message (optional, defaults to "Validation error"). Pass `null` to disable prefix completely.
|
| 283 |
+
- `prefixSeparator` - _string_; used to concatenate prefix with rest of the user-friendly message (optional, defaults to ": "). Not used when `prefix` is `null`.
|
| 284 |
+
- `includePath` - _boolean_; used to provide control on whether to include the erroneous property name suffix or not (optional, defaults to `true`).
|
| 285 |
+
|
| 286 |
+
They will be passed as arguments to the [createMessageBuilder](#createMessageBuilder) function. The only reason they exist is to provide backwards-compatibility with older versions of `zod-validation-error`. They should however be considered deprecated and may be removed in the future.
|
| 287 |
+
|
| 288 |
+
### fromZodIssue
|
| 289 |
+
|
| 290 |
+
Converts a single zod issue to `ValidationError`.
|
| 291 |
+
|
| 292 |
+
#### Arguments
|
| 293 |
+
|
| 294 |
+
- `zodIssue` - _zod.ZodIssue_; a ZodIssue instance (required)
|
| 295 |
+
- `options` - _Object_; formatting options (optional)
|
| 296 |
+
- `messageBuilder` - _MessageBuilder_; a function that accepts an array of `zod.ZodIssue` objects and returns a user-friendly error message in the form of a `string` (optional).
|
| 297 |
+
|
| 298 |
+
#### Notes
|
| 299 |
+
|
| 300 |
+
Alternatively, you may pass the following `options` instead of a `messageBuilder`.
|
| 301 |
+
|
| 302 |
+
- `options` - _Object_; formatting options (optional)
|
| 303 |
+
- `issueSeparator` - _string_; used to concatenate issues in user-friendly message (optional, defaults to ";")
|
| 304 |
+
- `unionSeparator` - _string_; used to concatenate union-issues in user-friendly message (optional, defaults to ", or")
|
| 305 |
+
- `prefix` - _string_ or _null_; prefix to use in user-friendly message (optional, defaults to "Validation error"). Pass `null` to disable prefix completely.
|
| 306 |
+
- `prefixSeparator` - _string_; used to concatenate prefix with rest of the user-friendly message (optional, defaults to ": "). Not used when `prefix` is `null`.
|
| 307 |
+
- `includePath` - _boolean_; used to provide control on whether to include the erroneous property name suffix or not (optional, defaults to `true`).
|
| 308 |
+
|
| 309 |
+
They will be passed as arguments to the [createMessageBuilder](#createMessageBuilder) function. The only reason they exist is to provide backwards-compatibility with older versions of `zod-validation-error`. They should however be considered deprecated and may be removed in the future.
|
| 310 |
+
|
| 311 |
+
### fromZodError
|
| 312 |
+
|
| 313 |
+
Converts zod error to `ValidationError`.
|
| 314 |
+
|
| 315 |
+
_Why is the difference between `ZodError` and `ZodIssue`?_ A `ZodError` is a collection of 1 or more `ZodIssue` instances. It's what you get when you call `zodSchema.parse()`.
|
| 316 |
+
|
| 317 |
+
#### Arguments
|
| 318 |
+
|
| 319 |
+
- `zodError` - _zod.ZodError_; a ZodError instance (required)
|
| 320 |
+
- `options` - _Object_; formatting options (optional)
|
| 321 |
+
- `messageBuilder` - _MessageBuilder_; a function that accepts an array of `zod.ZodIssue` objects and returns a user-friendly error message in the form of a `string` (optional).
|
| 322 |
+
|
| 323 |
+
#### Notes
|
| 324 |
+
|
| 325 |
+
Alternatively, you may pass the following `options` instead of a `messageBuilder`.
|
| 326 |
+
|
| 327 |
+
- `options` - _Object_; formatting options (optional)
|
| 328 |
+
- `maxIssuesInMessage` - _number_; max issues to include in user-friendly message (optional, defaults to 99)
|
| 329 |
+
- `issueSeparator` - _string_; used to concatenate issues in user-friendly message (optional, defaults to ";")
|
| 330 |
+
- `unionSeparator` - _string_; used to concatenate union-issues in user-friendly message (optional, defaults to ", or")
|
| 331 |
+
- `prefix` - _string_ or _null_; prefix to use in user-friendly message (optional, defaults to "Validation error"). Pass `null` to disable prefix completely.
|
| 332 |
+
- `prefixSeparator` - _string_; used to concatenate prefix with rest of the user-friendly message (optional, defaults to ": "). Not used when `prefix` is `null`.
|
| 333 |
+
- `includePath` - _boolean_; used to provide control on whether to include the erroneous property name suffix or not (optional, defaults to `true`).
|
| 334 |
+
|
| 335 |
+
They will be passed as arguments to the [createMessageBuilder](#createMessageBuilder) function. The only reason they exist is to provide backwards-compatibility with older versions of `zod-validation-error`. They should however be considered deprecated and may be removed in the future.
|
| 336 |
+
|
| 337 |
+
### toValidationError
|
| 338 |
+
|
| 339 |
+
A curried version of `fromZodError` meant to be used for FP (Functional Programming). Note it first takes the options object if needed and returns a function that converts the `zodError` to a `ValidationError` object
|
| 340 |
+
|
| 341 |
+
```js
|
| 342 |
+
toValidationError(options) => (zodError) => ValidationError
|
| 343 |
+
```
|
| 344 |
+
|
| 345 |
+
#### Example using fp-ts
|
| 346 |
+
|
| 347 |
+
```typescript
|
| 348 |
+
import * as Either from 'fp-ts/Either';
|
| 349 |
+
import { z as zod } from 'zod/v3';
|
| 350 |
+
import { toValidationError, ValidationError } from 'zod-validation-error/v3';
|
| 351 |
+
|
| 352 |
+
// create zod schema
|
| 353 |
+
const zodSchema = zod
|
| 354 |
+
.object({
|
| 355 |
+
id: zod.number().int().positive(),
|
| 356 |
+
email: zod.string().email(),
|
| 357 |
+
})
|
| 358 |
+
.brand<'User'>();
|
| 359 |
+
|
| 360 |
+
export type User = zod.infer<typeof zodSchema>;
|
| 361 |
+
|
| 362 |
+
export function parse(
|
| 363 |
+
value: zod.input<typeof zodSchema>
|
| 364 |
+
): Either.Either<ValidationError, User> {
|
| 365 |
+
return Either.tryCatch(() => schema.parse(value), toValidationError());
|
| 366 |
+
}
|
| 367 |
+
```
|
| 368 |
+
|
| 369 |
+
## MessageBuilder
|
| 370 |
+
|
| 371 |
+
`zod-validation-error` can be configured with a custom `MessageBuilder` function in order to produce case-specific error messages.
|
| 372 |
+
|
| 373 |
+
#### Example
|
| 374 |
+
|
| 375 |
+
For instance, one may want to print `invalid_string` errors to the console in red color.
|
| 376 |
+
|
| 377 |
+
```typescript
|
| 378 |
+
import { z as zod } from 'zod/v3';
|
| 379 |
+
import { type MessageBuilder, fromError } from 'zod-validation-error/v3';
|
| 380 |
+
import chalk from 'chalk';
|
| 381 |
+
|
| 382 |
+
// create custom MessageBuilder
|
| 383 |
+
const myMessageBuilder: MessageBuilder = (issues) => {
|
| 384 |
+
return (
|
| 385 |
+
issues
|
| 386 |
+
// format error message
|
| 387 |
+
.map((issue) => {
|
| 388 |
+
if (issue.code === zod.ZodIssueCode.invalid_string) {
|
| 389 |
+
return chalk.red(issue.message);
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
return issue.message;
|
| 393 |
+
})
|
| 394 |
+
// join as string with new-line character
|
| 395 |
+
.join('\n')
|
| 396 |
+
);
|
| 397 |
+
};
|
| 398 |
+
|
| 399 |
+
// create zod schema
|
| 400 |
+
const zodSchema = zod.object({
|
| 401 |
+
id: zod.number().int().positive(),
|
| 402 |
+
email: zod.string().email(),
|
| 403 |
+
});
|
| 404 |
+
|
| 405 |
+
// parse some invalid value
|
| 406 |
+
try {
|
| 407 |
+
zodSchema.parse({
|
| 408 |
+
id: 1,
|
| 409 |
+
email: 'foobar', // note: invalid email value
|
| 410 |
+
});
|
| 411 |
+
} catch (err) {
|
| 412 |
+
const validationError = fromError(err, {
|
| 413 |
+
messageBuilder: myMessageBuilder,
|
| 414 |
+
});
|
| 415 |
+
// the error is now displayed with red letters
|
| 416 |
+
console.log(validationError.toString());
|
| 417 |
+
}
|
| 418 |
+
```
|
| 419 |
+
|
| 420 |
+
## FAQ
|
| 421 |
+
|
| 422 |
+
### How to distinguish between errors
|
| 423 |
+
|
| 424 |
+
Use the `isValidationErrorLike` type guard.
|
| 425 |
+
|
| 426 |
+
#### Example
|
| 427 |
+
|
| 428 |
+
Scenario: Distinguish between `ValidationError` VS generic `Error` in order to respond with 400 VS 500 HTTP status code respectively.
|
| 429 |
+
|
| 430 |
+
```typescript
|
| 431 |
+
import * as Either from 'fp-ts/Either';
|
| 432 |
+
import { z as zod } from 'zod/v3';
|
| 433 |
+
import { isValidationErrorLike } from 'zod-validation-error/v3';
|
| 434 |
+
|
| 435 |
+
try {
|
| 436 |
+
func(); // throws Error - or - ValidationError
|
| 437 |
+
} catch (err) {
|
| 438 |
+
if (isValidationErrorLike(err)) {
|
| 439 |
+
return 400; // Bad Data (this is a client error)
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
return 500; // Server Error
|
| 443 |
+
}
|
| 444 |
+
```
|
| 445 |
+
|
| 446 |
+
### How to use `ValidationError` outside `zod`
|
| 447 |
+
|
| 448 |
+
It's possible to implement custom validation logic outside `zod` and throw a `ValidationError`.
|
| 449 |
+
|
| 450 |
+
#### Example 1: passing custom message
|
| 451 |
+
|
| 452 |
+
```typescript
|
| 453 |
+
import { ValidationError } from 'zod-validation-error/v3';
|
| 454 |
+
import { Buffer } from 'node:buffer';
|
| 455 |
+
|
| 456 |
+
function parseBuffer(buf: unknown): Buffer {
|
| 457 |
+
if (!Buffer.isBuffer(buf)) {
|
| 458 |
+
throw new ValidationError('Invalid argument; expected buffer');
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
return buf;
|
| 462 |
+
}
|
| 463 |
+
```
|
| 464 |
+
|
| 465 |
+
#### Example 2: passing custom message and original error as cause
|
| 466 |
+
|
| 467 |
+
```typescript
|
| 468 |
+
import { ValidationError } from 'zod-validation-error/v3';
|
| 469 |
+
|
| 470 |
+
try {
|
| 471 |
+
// do something that throws an error
|
| 472 |
+
} catch (err) {
|
| 473 |
+
throw new ValidationError('Something went deeply wrong', { cause: err });
|
| 474 |
+
}
|
| 475 |
+
```
|
| 476 |
+
|
| 477 |
+
### How to use `ValidationError` with custom "error map"
|
| 478 |
+
|
| 479 |
+
Zod supports customizing error messages by providing a custom "error map". You may combine this with `zod-validation-error` to produce user-friendly messages.
|
| 480 |
+
|
| 481 |
+
#### Example 1: produce user-friendly error messages using the `errorMap` property
|
| 482 |
+
|
| 483 |
+
If all you need is to produce user-friendly error messages you may use the `errorMap` property.
|
| 484 |
+
|
| 485 |
+
```typescript
|
| 486 |
+
import { z as zod } from 'zod/v3';
|
| 487 |
+
import { errorMap } from 'zod-validation-error/v3';
|
| 488 |
+
|
| 489 |
+
zod.setErrorMap(errorMap);
|
| 490 |
+
```
|
| 491 |
+
|
| 492 |
+
#### Example 2: extra customization using `fromZodIssue`
|
| 493 |
+
|
| 494 |
+
If you need to customize some error code, you may use the `fromZodIssue` function.
|
| 495 |
+
|
| 496 |
+
```typescript
|
| 497 |
+
import { z as zod } from 'zod/v3';
|
| 498 |
+
import { fromZodIssue } from 'zod-validation-error/v3';
|
| 499 |
+
|
| 500 |
+
const customErrorMap: zod.ZodErrorMap = (issue, ctx) => {
|
| 501 |
+
switch (issue.code) {
|
| 502 |
+
case ZodIssueCode.invalid_type: {
|
| 503 |
+
return {
|
| 504 |
+
message:
|
| 505 |
+
'Custom error message of your preference for invalid_type errors',
|
| 506 |
+
};
|
| 507 |
+
}
|
| 508 |
+
default: {
|
| 509 |
+
const validationError = fromZodIssue({
|
| 510 |
+
...issue,
|
| 511 |
+
// fallback to the default error message
|
| 512 |
+
// when issue does not have a message
|
| 513 |
+
message: issue.message ?? ctx.defaultError,
|
| 514 |
+
});
|
| 515 |
+
|
| 516 |
+
return {
|
| 517 |
+
message: validationError.message,
|
| 518 |
+
};
|
| 519 |
+
}
|
| 520 |
+
}
|
| 521 |
+
};
|
| 522 |
+
|
| 523 |
+
zod.setErrorMap(customErrorMap);
|
| 524 |
+
```
|
| 525 |
+
|
| 526 |
+
### How to use `zod-validation-error` with `react-hook-form`?
|
| 527 |
+
|
| 528 |
+
```typescript
|
| 529 |
+
import { useForm } from 'react-hook-form';
|
| 530 |
+
import { zodResolver } from '@hookform/resolvers/zod';
|
| 531 |
+
import { errorMap } from 'zod-validation-error/v3';
|
| 532 |
+
|
| 533 |
+
useForm({
|
| 534 |
+
resolver: zodResolver(schema, { errorMap }),
|
| 535 |
+
});
|
| 536 |
+
```
|
| 537 |
+
|
| 538 |
+
### Does `zod-validation-error` support CommonJS
|
| 539 |
+
|
| 540 |
+
Yes, `zod-validation-error` supports CommonJS out-of-the-box. All you need to do is import it using `require`.
|
| 541 |
+
|
| 542 |
+
#### Example
|
| 543 |
+
|
| 544 |
+
```typescript
|
| 545 |
+
const { ValidationError } = require('zod-validation-error');
|
| 546 |
+
```
|
| 547 |
+
|
| 548 |
+
## Contribute
|
| 549 |
+
|
| 550 |
+
Source code contributions are most welcome. Please open a PR, ensure the linter is satisfied and all tests pass.
|
| 551 |
+
|
| 552 |
+
#### We are hiring
|
| 553 |
+
|
| 554 |
+
Causaly is building the world's largest biomedical knowledge platform, using technologies such as TypeScript, React and Node.js. Find out more about our openings at https://jobs.ashbyhq.com/causaly.
|
| 555 |
+
|
| 556 |
+
## License
|
| 557 |
+
|
| 558 |
+
MIT
|
node_modules/zod-validation-error/package.json
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "zod-validation-error",
|
| 3 |
+
"version": "4.0.2",
|
| 4 |
+
"description": "Wrap zod validation errors in user-friendly readable messages",
|
| 5 |
+
"keywords": [
|
| 6 |
+
"zod",
|
| 7 |
+
"error",
|
| 8 |
+
"validation"
|
| 9 |
+
],
|
| 10 |
+
"license": "MIT",
|
| 11 |
+
"repository": {
|
| 12 |
+
"type": "git",
|
| 13 |
+
"url": "git://github.com/causaly/zod-validation-error.git"
|
| 14 |
+
},
|
| 15 |
+
"author": {
|
| 16 |
+
"name": "Dimitrios C. Michalakos",
|
| 17 |
+
"email": "dimitris@jmike.gr",
|
| 18 |
+
"url": "https://github.com/jmike"
|
| 19 |
+
},
|
| 20 |
+
"contributors": [
|
| 21 |
+
{
|
| 22 |
+
"name": "Thanos Karagiannis",
|
| 23 |
+
"email": "hey@maestros.io",
|
| 24 |
+
"url": "https://github.com/thanoskrg"
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"name": "Nikos Tsompanides",
|
| 28 |
+
"email": "nikostsompanides@gmail.com",
|
| 29 |
+
"url": "https://github.com/NikosTsompanides"
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"name": "Nikos Kalogridis",
|
| 33 |
+
"url": "https://github.com/nikoskalogridis"
|
| 34 |
+
}
|
| 35 |
+
],
|
| 36 |
+
"main": "./v4/index.js",
|
| 37 |
+
"module": "./v4/index.mjs",
|
| 38 |
+
"types": "./v4/index.d.ts",
|
| 39 |
+
"exports": {
|
| 40 |
+
".": {
|
| 41 |
+
"types": "./v4/index.d.ts",
|
| 42 |
+
"require": "./v4/index.js",
|
| 43 |
+
"import": "./v4/index.mjs"
|
| 44 |
+
},
|
| 45 |
+
"./v3": {
|
| 46 |
+
"types": "./v3/index.d.ts",
|
| 47 |
+
"require": "./v3/index.js",
|
| 48 |
+
"import": "./v3/index.mjs"
|
| 49 |
+
},
|
| 50 |
+
"./v4": {
|
| 51 |
+
"types": "./v4/index.d.ts",
|
| 52 |
+
"require": "./v4/index.js",
|
| 53 |
+
"import": "./v4/index.mjs"
|
| 54 |
+
}
|
| 55 |
+
},
|
| 56 |
+
"files": [
|
| 57 |
+
"v3",
|
| 58 |
+
"v4"
|
| 59 |
+
],
|
| 60 |
+
"publishConfig": {
|
| 61 |
+
"access": "public"
|
| 62 |
+
},
|
| 63 |
+
"sideEffects": false,
|
| 64 |
+
"engines": {
|
| 65 |
+
"node": ">=18.0.0"
|
| 66 |
+
},
|
| 67 |
+
"scripts": {
|
| 68 |
+
"typecheck": "tsc --noEmit",
|
| 69 |
+
"build": "tsup --config ./tsup.config.ts",
|
| 70 |
+
"lint": "eslint lib --ext .ts",
|
| 71 |
+
"format": "prettier --config ./.prettierrc --ignore-path .gitignore -w .",
|
| 72 |
+
"test": "vitest run",
|
| 73 |
+
"changeset": "changeset",
|
| 74 |
+
"prerelease": "npm run build && npm run test",
|
| 75 |
+
"release": "changeset publish",
|
| 76 |
+
"prepare": "husky"
|
| 77 |
+
},
|
| 78 |
+
"lint-staged": {
|
| 79 |
+
"*.{js,jsx,ts,tsx}": [
|
| 80 |
+
"eslint --fix",
|
| 81 |
+
"prettier --config ./.prettierrc.json --write"
|
| 82 |
+
]
|
| 83 |
+
},
|
| 84 |
+
"devDependencies": {
|
| 85 |
+
"@changesets/changelog-github": "^0.5.0",
|
| 86 |
+
"@changesets/cli": "^2.27.7",
|
| 87 |
+
"@commitlint/cli": "^18.0.0",
|
| 88 |
+
"@commitlint/config-conventional": "^18.0.0",
|
| 89 |
+
"@types/node": "^20.5.0",
|
| 90 |
+
"@typescript-eslint/eslint-plugin": "^6.4.1",
|
| 91 |
+
"@typescript-eslint/parser": "^6.4.1",
|
| 92 |
+
"concurrently": "^8.2.0",
|
| 93 |
+
"eslint": "^8.4.1",
|
| 94 |
+
"eslint-config-prettier": "^9.0.0",
|
| 95 |
+
"eslint-plugin-import": "^2.29.1",
|
| 96 |
+
"eslint-plugin-prettier": "^4.2.1",
|
| 97 |
+
"husky": "^9.1.7",
|
| 98 |
+
"lint-staged": "^15.0.1",
|
| 99 |
+
"prettier": "^2.8.8",
|
| 100 |
+
"tsup": "^8.0.2",
|
| 101 |
+
"typescript": "^5.1.6",
|
| 102 |
+
"vitest": "^3.1.2",
|
| 103 |
+
"zod": "^4.0.2"
|
| 104 |
+
},
|
| 105 |
+
"peerDependencies": {
|
| 106 |
+
"zod": "^3.25.0 || ^4.0.0"
|
| 107 |
+
}
|
| 108 |
+
}
|
node_modules/zod-validation-error/v3/index.d.mts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as zod from 'zod/v3';
|
| 2 |
+
|
| 3 |
+
interface ErrorOptions {
|
| 4 |
+
cause?: unknown;
|
| 5 |
+
}
|
| 6 |
+
declare class ValidationError extends Error {
|
| 7 |
+
name: 'ZodValidationError';
|
| 8 |
+
details: Array<zod.ZodIssue>;
|
| 9 |
+
constructor(message?: string, options?: ErrorOptions);
|
| 10 |
+
toString(): string;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
declare function isValidationError(err: unknown): err is ValidationError;
|
| 14 |
+
|
| 15 |
+
declare function isValidationErrorLike(err: unknown): err is ValidationError;
|
| 16 |
+
|
| 17 |
+
declare function isZodErrorLike(err: unknown): err is zod.ZodError;
|
| 18 |
+
|
| 19 |
+
declare const errorMap: zod.ZodErrorMap;
|
| 20 |
+
|
| 21 |
+
type NonEmptyArray<T> = [T, ...T[]];
|
| 22 |
+
|
| 23 |
+
type ZodIssue = zod.ZodIssue;
|
| 24 |
+
type MessageBuilder = (issues: NonEmptyArray<ZodIssue>) => string;
|
| 25 |
+
type CreateMessageBuilderProps = {
|
| 26 |
+
issueSeparator?: string;
|
| 27 |
+
unionSeparator?: string;
|
| 28 |
+
prefix?: string | null;
|
| 29 |
+
prefixSeparator?: string;
|
| 30 |
+
includePath?: boolean;
|
| 31 |
+
maxIssuesInMessage?: number;
|
| 32 |
+
};
|
| 33 |
+
declare function createMessageBuilder(props?: CreateMessageBuilderProps): MessageBuilder;
|
| 34 |
+
|
| 35 |
+
type ZodError = zod.ZodError;
|
| 36 |
+
type FromZodErrorOptions = {
|
| 37 |
+
messageBuilder: MessageBuilder;
|
| 38 |
+
} | CreateMessageBuilderProps;
|
| 39 |
+
declare function fromZodError(zodError: ZodError, options?: FromZodErrorOptions): ValidationError;
|
| 40 |
+
|
| 41 |
+
declare function fromError(err: unknown, options?: FromZodErrorOptions): ValidationError;
|
| 42 |
+
|
| 43 |
+
type FromZodIssueOptions = {
|
| 44 |
+
messageBuilder: MessageBuilder;
|
| 45 |
+
} | Omit<CreateMessageBuilderProps, 'maxIssuesInMessage'>;
|
| 46 |
+
declare function fromZodIssue(issue: ZodIssue, options?: FromZodIssueOptions): ValidationError;
|
| 47 |
+
|
| 48 |
+
declare const toValidationError: (options?: FromZodErrorOptions) => (err: unknown) => ValidationError;
|
| 49 |
+
|
| 50 |
+
export { type ErrorOptions, type FromZodErrorOptions, type FromZodIssueOptions, type MessageBuilder, type NonEmptyArray, ValidationError, type ZodError, type ZodIssue, createMessageBuilder, errorMap, fromError, fromZodError, fromZodIssue, isValidationError, isValidationErrorLike, isZodErrorLike, toValidationError };
|
node_modules/zod-validation-error/v3/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as zod from 'zod/v3';
|
| 2 |
+
|
| 3 |
+
interface ErrorOptions {
|
| 4 |
+
cause?: unknown;
|
| 5 |
+
}
|
| 6 |
+
declare class ValidationError extends Error {
|
| 7 |
+
name: 'ZodValidationError';
|
| 8 |
+
details: Array<zod.ZodIssue>;
|
| 9 |
+
constructor(message?: string, options?: ErrorOptions);
|
| 10 |
+
toString(): string;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
declare function isValidationError(err: unknown): err is ValidationError;
|
| 14 |
+
|
| 15 |
+
declare function isValidationErrorLike(err: unknown): err is ValidationError;
|
| 16 |
+
|
| 17 |
+
declare function isZodErrorLike(err: unknown): err is zod.ZodError;
|
| 18 |
+
|
| 19 |
+
declare const errorMap: zod.ZodErrorMap;
|
| 20 |
+
|
| 21 |
+
type NonEmptyArray<T> = [T, ...T[]];
|
| 22 |
+
|
| 23 |
+
type ZodIssue = zod.ZodIssue;
|
| 24 |
+
type MessageBuilder = (issues: NonEmptyArray<ZodIssue>) => string;
|
| 25 |
+
type CreateMessageBuilderProps = {
|
| 26 |
+
issueSeparator?: string;
|
| 27 |
+
unionSeparator?: string;
|
| 28 |
+
prefix?: string | null;
|
| 29 |
+
prefixSeparator?: string;
|
| 30 |
+
includePath?: boolean;
|
| 31 |
+
maxIssuesInMessage?: number;
|
| 32 |
+
};
|
| 33 |
+
declare function createMessageBuilder(props?: CreateMessageBuilderProps): MessageBuilder;
|
| 34 |
+
|
| 35 |
+
type ZodError = zod.ZodError;
|
| 36 |
+
type FromZodErrorOptions = {
|
| 37 |
+
messageBuilder: MessageBuilder;
|
| 38 |
+
} | CreateMessageBuilderProps;
|
| 39 |
+
declare function fromZodError(zodError: ZodError, options?: FromZodErrorOptions): ValidationError;
|
| 40 |
+
|
| 41 |
+
declare function fromError(err: unknown, options?: FromZodErrorOptions): ValidationError;
|
| 42 |
+
|
| 43 |
+
type FromZodIssueOptions = {
|
| 44 |
+
messageBuilder: MessageBuilder;
|
| 45 |
+
} | Omit<CreateMessageBuilderProps, 'maxIssuesInMessage'>;
|
| 46 |
+
declare function fromZodIssue(issue: ZodIssue, options?: FromZodIssueOptions): ValidationError;
|
| 47 |
+
|
| 48 |
+
declare const toValidationError: (options?: FromZodErrorOptions) => (err: unknown) => ValidationError;
|
| 49 |
+
|
| 50 |
+
export { type ErrorOptions, type FromZodErrorOptions, type FromZodIssueOptions, type MessageBuilder, type NonEmptyArray, ValidationError, type ZodError, type ZodIssue, createMessageBuilder, errorMap, fromError, fromZodError, fromZodIssue, isValidationError, isValidationErrorLike, isZodErrorLike, toValidationError };
|
node_modules/zod-validation-error/v3/index.js
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
var __create = Object.create;
|
| 3 |
+
var __defProp = Object.defineProperty;
|
| 4 |
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
| 5 |
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
| 6 |
+
var __getProtoOf = Object.getPrototypeOf;
|
| 7 |
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
| 8 |
+
var __export = (target, all) => {
|
| 9 |
+
for (var name in all)
|
| 10 |
+
__defProp(target, name, { get: all[name], enumerable: true });
|
| 11 |
+
};
|
| 12 |
+
var __copyProps = (to, from, except, desc) => {
|
| 13 |
+
if (from && typeof from === "object" || typeof from === "function") {
|
| 14 |
+
for (let key of __getOwnPropNames(from))
|
| 15 |
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
| 16 |
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
| 17 |
+
}
|
| 18 |
+
return to;
|
| 19 |
+
};
|
| 20 |
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
| 21 |
+
// If the importer is in node compatibility mode or this is not an ESM
|
| 22 |
+
// file that has been converted to a CommonJS file using a Babel-
|
| 23 |
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
| 24 |
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
| 25 |
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
| 26 |
+
mod
|
| 27 |
+
));
|
| 28 |
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
| 29 |
+
|
| 30 |
+
// lib/v3/index.ts
|
| 31 |
+
var index_exports = {};
|
| 32 |
+
__export(index_exports, {
|
| 33 |
+
ValidationError: () => ValidationError,
|
| 34 |
+
createMessageBuilder: () => createMessageBuilder,
|
| 35 |
+
errorMap: () => errorMap,
|
| 36 |
+
fromError: () => fromError,
|
| 37 |
+
fromZodError: () => fromZodError,
|
| 38 |
+
fromZodIssue: () => fromZodIssue,
|
| 39 |
+
isValidationError: () => isValidationError,
|
| 40 |
+
isValidationErrorLike: () => isValidationErrorLike,
|
| 41 |
+
isZodErrorLike: () => isZodErrorLike,
|
| 42 |
+
toValidationError: () => toValidationError
|
| 43 |
+
});
|
| 44 |
+
module.exports = __toCommonJS(index_exports);
|
| 45 |
+
|
| 46 |
+
// lib/v3/isZodErrorLike.ts
|
| 47 |
+
function isZodErrorLike(err) {
|
| 48 |
+
return err instanceof Error && err.name === "ZodError" && "issues" in err && Array.isArray(err.issues);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
// lib/v3/ValidationError.ts
|
| 52 |
+
var ValidationError = class extends Error {
|
| 53 |
+
name;
|
| 54 |
+
details;
|
| 55 |
+
constructor(message, options) {
|
| 56 |
+
super(message, options);
|
| 57 |
+
this.name = "ZodValidationError";
|
| 58 |
+
this.details = getIssuesFromErrorOptions(options);
|
| 59 |
+
}
|
| 60 |
+
toString() {
|
| 61 |
+
return this.message;
|
| 62 |
+
}
|
| 63 |
+
};
|
| 64 |
+
function getIssuesFromErrorOptions(options) {
|
| 65 |
+
if (options) {
|
| 66 |
+
const cause = options.cause;
|
| 67 |
+
if (isZodErrorLike(cause)) {
|
| 68 |
+
return cause.issues;
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
return [];
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
// lib/v3/isValidationError.ts
|
| 75 |
+
function isValidationError(err) {
|
| 76 |
+
return err instanceof ValidationError;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// lib/v3/isValidationErrorLike.ts
|
| 80 |
+
function isValidationErrorLike(err) {
|
| 81 |
+
return err instanceof Error && err.name === "ZodValidationError";
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
// lib/v3/fromZodIssue.ts
|
| 85 |
+
var zod2 = __toESM(require("zod/v3"));
|
| 86 |
+
|
| 87 |
+
// lib/v3/MessageBuilder.ts
|
| 88 |
+
var zod = __toESM(require("zod/v3"));
|
| 89 |
+
|
| 90 |
+
// lib/utils/NonEmptyArray.ts
|
| 91 |
+
function isNonEmptyArray(value) {
|
| 92 |
+
return value.length !== 0;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
// lib/utils/stringify.ts
|
| 96 |
+
function stringifySymbol(symbol) {
|
| 97 |
+
return symbol.description ?? "";
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
// lib/utils/joinPath.ts
|
| 101 |
+
var identifierRegex = /[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u;
|
| 102 |
+
function joinPath(path) {
|
| 103 |
+
if (path.length === 1) {
|
| 104 |
+
let propertyKey = path[0];
|
| 105 |
+
if (typeof propertyKey === "symbol") {
|
| 106 |
+
propertyKey = stringifySymbol(propertyKey);
|
| 107 |
+
}
|
| 108 |
+
return propertyKey.toString() || '""';
|
| 109 |
+
}
|
| 110 |
+
return path.reduce((acc, propertyKey) => {
|
| 111 |
+
if (typeof propertyKey === "number") {
|
| 112 |
+
return acc + "[" + propertyKey.toString() + "]";
|
| 113 |
+
}
|
| 114 |
+
if (typeof propertyKey === "symbol") {
|
| 115 |
+
propertyKey = stringifySymbol(propertyKey);
|
| 116 |
+
}
|
| 117 |
+
if (propertyKey.includes('"')) {
|
| 118 |
+
return acc + '["' + escapeQuotes(propertyKey) + '"]';
|
| 119 |
+
}
|
| 120 |
+
if (!identifierRegex.test(propertyKey)) {
|
| 121 |
+
return acc + '["' + propertyKey + '"]';
|
| 122 |
+
}
|
| 123 |
+
const separator = acc.length === 0 ? "" : ".";
|
| 124 |
+
return acc + separator + propertyKey;
|
| 125 |
+
}, "");
|
| 126 |
+
}
|
| 127 |
+
function escapeQuotes(str) {
|
| 128 |
+
return str.replace(/"/g, '\\"');
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
// lib/v3/config.ts
|
| 132 |
+
var ISSUE_SEPARATOR = "; ";
|
| 133 |
+
var MAX_ISSUES_IN_MESSAGE = 99;
|
| 134 |
+
var PREFIX = "Validation error";
|
| 135 |
+
var PREFIX_SEPARATOR = ": ";
|
| 136 |
+
var UNION_SEPARATOR = ", or ";
|
| 137 |
+
|
| 138 |
+
// lib/v3/MessageBuilder.ts
|
| 139 |
+
function createMessageBuilder(props = {}) {
|
| 140 |
+
const {
|
| 141 |
+
issueSeparator = ISSUE_SEPARATOR,
|
| 142 |
+
unionSeparator = UNION_SEPARATOR,
|
| 143 |
+
prefixSeparator = PREFIX_SEPARATOR,
|
| 144 |
+
prefix = PREFIX,
|
| 145 |
+
includePath = true,
|
| 146 |
+
maxIssuesInMessage = MAX_ISSUES_IN_MESSAGE
|
| 147 |
+
} = props;
|
| 148 |
+
return (issues) => {
|
| 149 |
+
const message = issues.slice(0, maxIssuesInMessage).map(
|
| 150 |
+
(issue) => getMessageFromZodIssue({
|
| 151 |
+
issue,
|
| 152 |
+
issueSeparator,
|
| 153 |
+
unionSeparator,
|
| 154 |
+
includePath
|
| 155 |
+
})
|
| 156 |
+
).join(issueSeparator);
|
| 157 |
+
return prefixMessage(message, prefix, prefixSeparator);
|
| 158 |
+
};
|
| 159 |
+
}
|
| 160 |
+
function getMessageFromZodIssue(props) {
|
| 161 |
+
const { issue, issueSeparator, unionSeparator, includePath } = props;
|
| 162 |
+
if (issue.code === zod.ZodIssueCode.invalid_union) {
|
| 163 |
+
return issue.unionErrors.reduce((acc, zodError) => {
|
| 164 |
+
const newIssues = zodError.issues.map(
|
| 165 |
+
(issue2) => getMessageFromZodIssue({
|
| 166 |
+
issue: issue2,
|
| 167 |
+
issueSeparator,
|
| 168 |
+
unionSeparator,
|
| 169 |
+
includePath
|
| 170 |
+
})
|
| 171 |
+
).join(issueSeparator);
|
| 172 |
+
if (!acc.includes(newIssues)) {
|
| 173 |
+
acc.push(newIssues);
|
| 174 |
+
}
|
| 175 |
+
return acc;
|
| 176 |
+
}, []).join(unionSeparator);
|
| 177 |
+
}
|
| 178 |
+
if (issue.code === zod.ZodIssueCode.invalid_arguments) {
|
| 179 |
+
return [
|
| 180 |
+
issue.message,
|
| 181 |
+
...issue.argumentsError.issues.map(
|
| 182 |
+
(issue2) => getMessageFromZodIssue({
|
| 183 |
+
issue: issue2,
|
| 184 |
+
issueSeparator,
|
| 185 |
+
unionSeparator,
|
| 186 |
+
includePath
|
| 187 |
+
})
|
| 188 |
+
)
|
| 189 |
+
].join(issueSeparator);
|
| 190 |
+
}
|
| 191 |
+
if (issue.code === zod.ZodIssueCode.invalid_return_type) {
|
| 192 |
+
return [
|
| 193 |
+
issue.message,
|
| 194 |
+
...issue.returnTypeError.issues.map(
|
| 195 |
+
(issue2) => getMessageFromZodIssue({
|
| 196 |
+
issue: issue2,
|
| 197 |
+
issueSeparator,
|
| 198 |
+
unionSeparator,
|
| 199 |
+
includePath
|
| 200 |
+
})
|
| 201 |
+
)
|
| 202 |
+
].join(issueSeparator);
|
| 203 |
+
}
|
| 204 |
+
if (includePath && isNonEmptyArray(issue.path)) {
|
| 205 |
+
if (issue.path.length === 1) {
|
| 206 |
+
const identifier = issue.path[0];
|
| 207 |
+
if (typeof identifier === "number") {
|
| 208 |
+
return `${issue.message} at index ${identifier}`;
|
| 209 |
+
}
|
| 210 |
+
}
|
| 211 |
+
return `${issue.message} at "${joinPath(issue.path)}"`;
|
| 212 |
+
}
|
| 213 |
+
return issue.message;
|
| 214 |
+
}
|
| 215 |
+
function prefixMessage(message, prefix, prefixSeparator) {
|
| 216 |
+
if (prefix !== null) {
|
| 217 |
+
if (message.length > 0) {
|
| 218 |
+
return [prefix, message].join(prefixSeparator);
|
| 219 |
+
}
|
| 220 |
+
return prefix;
|
| 221 |
+
}
|
| 222 |
+
if (message.length > 0) {
|
| 223 |
+
return message;
|
| 224 |
+
}
|
| 225 |
+
return PREFIX;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
// lib/v3/fromZodIssue.ts
|
| 229 |
+
function fromZodIssue(issue, options = {}) {
|
| 230 |
+
const messageBuilder = createMessageBuilderFromOptions(options);
|
| 231 |
+
const message = messageBuilder([issue]);
|
| 232 |
+
return new ValidationError(message, { cause: new zod2.ZodError([issue]) });
|
| 233 |
+
}
|
| 234 |
+
function createMessageBuilderFromOptions(options) {
|
| 235 |
+
if ("messageBuilder" in options) {
|
| 236 |
+
return options.messageBuilder;
|
| 237 |
+
}
|
| 238 |
+
return createMessageBuilder(options);
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
// lib/v3/errorMap.ts
|
| 242 |
+
var errorMap = (issue, ctx) => {
|
| 243 |
+
const error = fromZodIssue({
|
| 244 |
+
...issue,
|
| 245 |
+
// fallback to the default error message
|
| 246 |
+
// when issue does not have a message
|
| 247 |
+
message: issue.message ?? ctx.defaultError
|
| 248 |
+
});
|
| 249 |
+
return {
|
| 250 |
+
message: error.message
|
| 251 |
+
};
|
| 252 |
+
};
|
| 253 |
+
|
| 254 |
+
// lib/v3/fromZodError.ts
|
| 255 |
+
function fromZodError(zodError, options = {}) {
|
| 256 |
+
if (!isZodErrorLike(zodError)) {
|
| 257 |
+
throw new TypeError(
|
| 258 |
+
`Invalid zodError param; expected instance of ZodError. Did you mean to use the "${fromError.name}" method instead?`
|
| 259 |
+
);
|
| 260 |
+
}
|
| 261 |
+
return fromZodErrorWithoutRuntimeCheck(zodError, options);
|
| 262 |
+
}
|
| 263 |
+
function fromZodErrorWithoutRuntimeCheck(zodError, options = {}) {
|
| 264 |
+
const zodIssues = zodError.errors;
|
| 265 |
+
let message;
|
| 266 |
+
if (isNonEmptyArray(zodIssues)) {
|
| 267 |
+
const messageBuilder = createMessageBuilderFromOptions2(options);
|
| 268 |
+
message = messageBuilder(zodIssues);
|
| 269 |
+
} else {
|
| 270 |
+
message = zodError.message;
|
| 271 |
+
}
|
| 272 |
+
return new ValidationError(message, { cause: zodError });
|
| 273 |
+
}
|
| 274 |
+
function createMessageBuilderFromOptions2(options) {
|
| 275 |
+
if ("messageBuilder" in options) {
|
| 276 |
+
return options.messageBuilder;
|
| 277 |
+
}
|
| 278 |
+
return createMessageBuilder(options);
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
// lib/v3/toValidationError.ts
|
| 282 |
+
var toValidationError = (options = {}) => (err) => {
|
| 283 |
+
if (isZodErrorLike(err)) {
|
| 284 |
+
return fromZodErrorWithoutRuntimeCheck(err, options);
|
| 285 |
+
}
|
| 286 |
+
if (err instanceof Error) {
|
| 287 |
+
return new ValidationError(err.message, { cause: err });
|
| 288 |
+
}
|
| 289 |
+
return new ValidationError("Unknown error");
|
| 290 |
+
};
|
| 291 |
+
|
| 292 |
+
// lib/v3/fromError.ts
|
| 293 |
+
function fromError(err, options = {}) {
|
| 294 |
+
return toValidationError(options)(err);
|
| 295 |
+
}
|
| 296 |
+
// Annotate the CommonJS export names for ESM import in node:
|
| 297 |
+
0 && (module.exports = {
|
| 298 |
+
ValidationError,
|
| 299 |
+
createMessageBuilder,
|
| 300 |
+
errorMap,
|
| 301 |
+
fromError,
|
| 302 |
+
fromZodError,
|
| 303 |
+
fromZodIssue,
|
| 304 |
+
isValidationError,
|
| 305 |
+
isValidationErrorLike,
|
| 306 |
+
isZodErrorLike,
|
| 307 |
+
toValidationError
|
| 308 |
+
});
|
| 309 |
+
//# sourceMappingURL=index.js.map
|
node_modules/zod-validation-error/v3/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"sources":["../lib/v3/index.ts","../lib/v3/isZodErrorLike.ts","../lib/v3/ValidationError.ts","../lib/v3/isValidationError.ts","../lib/v3/isValidationErrorLike.ts","../lib/v3/fromZodIssue.ts","../lib/v3/MessageBuilder.ts","../lib/utils/NonEmptyArray.ts","../lib/utils/stringify.ts","../lib/utils/joinPath.ts","../lib/v3/config.ts","../lib/v3/errorMap.ts","../lib/v3/fromZodError.ts","../lib/v3/toValidationError.ts","../lib/v3/fromError.ts"],"sourcesContent":["export { ValidationError, type ErrorOptions } from './ValidationError.ts';\nexport { isValidationError } from './isValidationError.ts';\nexport { isValidationErrorLike } from './isValidationErrorLike.ts';\nexport { isZodErrorLike } from './isZodErrorLike.ts';\nexport { errorMap } from './errorMap.ts';\nexport { fromError } from './fromError.ts';\nexport { fromZodIssue, type FromZodIssueOptions } from './fromZodIssue.ts';\nexport {\n fromZodError,\n type FromZodErrorOptions,\n type ZodError,\n} from './fromZodError.ts';\nexport { toValidationError } from './toValidationError.ts';\nexport {\n type MessageBuilder,\n type ZodIssue,\n createMessageBuilder,\n} from './MessageBuilder.ts';\nexport { type NonEmptyArray } from '../utils/NonEmptyArray.ts';\n","import type * as zod from 'zod/v3';\n\nexport function isZodErrorLike(err: unknown): err is zod.ZodError {\n return (\n err instanceof Error &&\n err.name === 'ZodError' &&\n 'issues' in err &&\n Array.isArray(err.issues)\n );\n}\n","import { isZodErrorLike } from './isZodErrorLike.ts';\nimport type * as zod from 'zod/v3';\n\n// make zod-validation-error compatible with\n// earlier to es2022 typescript configurations\n// @see https://github.com/causaly/zod-validation-error/issues/226\nexport interface ErrorOptions {\n cause?: unknown;\n}\n\nexport class ValidationError extends Error {\n name: 'ZodValidationError';\n details: Array<zod.ZodIssue>;\n\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'ZodValidationError';\n this.details = getIssuesFromErrorOptions(options);\n }\n\n toString(): string {\n return this.message;\n }\n}\n\nfunction getIssuesFromErrorOptions(\n options?: ErrorOptions\n): Array<zod.ZodIssue> {\n if (options) {\n const cause = options.cause;\n\n if (isZodErrorLike(cause)) {\n return cause.issues;\n }\n }\n\n return [];\n}\n","import { ValidationError } from './ValidationError.ts';\n\nexport function isValidationError(err: unknown): err is ValidationError {\n return err instanceof ValidationError;\n}\n","import type { ValidationError } from './ValidationError.ts';\n\nexport function isValidationErrorLike(err: unknown): err is ValidationError {\n return err instanceof Error && err.name === 'ZodValidationError';\n}\n","import * as zod from 'zod/v3';\n\nimport {\n type MessageBuilder,\n type CreateMessageBuilderProps,\n type ZodIssue,\n createMessageBuilder,\n} from './MessageBuilder.ts';\nimport { ValidationError } from './ValidationError.ts';\n\nexport type FromZodIssueOptions =\n | {\n messageBuilder: MessageBuilder;\n }\n // maintain backwards compatibility\n | Omit<CreateMessageBuilderProps, 'maxIssuesInMessage'>;\n\nexport function fromZodIssue(\n issue: ZodIssue,\n options: FromZodIssueOptions = {}\n): ValidationError {\n const messageBuilder = createMessageBuilderFromOptions(options);\n const message = messageBuilder([issue]);\n\n return new ValidationError(message, { cause: new zod.ZodError([issue]) });\n}\n\nfunction createMessageBuilderFromOptions(\n options: FromZodIssueOptions\n): MessageBuilder {\n if ('messageBuilder' in options) {\n return options.messageBuilder;\n }\n\n return createMessageBuilder(options);\n}\n","import * as zod from 'zod/v3';\nimport { type NonEmptyArray, isNonEmptyArray } from '../utils/NonEmptyArray.ts';\nimport { joinPath } from '../utils/joinPath.ts';\nimport {\n ISSUE_SEPARATOR,\n MAX_ISSUES_IN_MESSAGE,\n PREFIX,\n PREFIX_SEPARATOR,\n UNION_SEPARATOR,\n} from './config.ts';\n\nexport type ZodIssue = zod.ZodIssue;\n\nexport type MessageBuilder = (issues: NonEmptyArray<ZodIssue>) => string;\n\nexport type CreateMessageBuilderProps = {\n issueSeparator?: string;\n unionSeparator?: string;\n prefix?: string | null;\n prefixSeparator?: string;\n includePath?: boolean;\n maxIssuesInMessage?: number;\n};\n\nexport function createMessageBuilder(\n props: CreateMessageBuilderProps = {}\n): MessageBuilder {\n const {\n issueSeparator = ISSUE_SEPARATOR,\n unionSeparator = UNION_SEPARATOR,\n prefixSeparator = PREFIX_SEPARATOR,\n prefix = PREFIX,\n includePath = true,\n maxIssuesInMessage = MAX_ISSUES_IN_MESSAGE,\n } = props;\n return (issues) => {\n const message = issues\n // limit max number of issues printed in the reason section\n .slice(0, maxIssuesInMessage)\n // format error message\n .map((issue) =>\n getMessageFromZodIssue({\n issue,\n issueSeparator,\n unionSeparator,\n includePath,\n })\n )\n // concat as string\n .join(issueSeparator);\n\n return prefixMessage(message, prefix, prefixSeparator);\n };\n}\n\nfunction getMessageFromZodIssue(props: {\n issue: ZodIssue;\n issueSeparator: string;\n unionSeparator: string;\n includePath: boolean;\n}): string {\n const { issue, issueSeparator, unionSeparator, includePath } = props;\n\n if (issue.code === zod.ZodIssueCode.invalid_union) {\n return issue.unionErrors\n .reduce<string[]>((acc, zodError) => {\n const newIssues = zodError.issues\n .map((issue) =>\n getMessageFromZodIssue({\n issue,\n issueSeparator,\n unionSeparator,\n includePath,\n })\n )\n .join(issueSeparator);\n\n if (!acc.includes(newIssues)) {\n acc.push(newIssues);\n }\n\n return acc;\n }, [])\n .join(unionSeparator);\n }\n\n if (issue.code === zod.ZodIssueCode.invalid_arguments) {\n return [\n issue.message,\n ...issue.argumentsError.issues.map((issue) =>\n getMessageFromZodIssue({\n issue,\n issueSeparator,\n unionSeparator,\n includePath,\n })\n ),\n ].join(issueSeparator);\n }\n\n if (issue.code === zod.ZodIssueCode.invalid_return_type) {\n return [\n issue.message,\n ...issue.returnTypeError.issues.map((issue) =>\n getMessageFromZodIssue({\n issue,\n issueSeparator,\n unionSeparator,\n includePath,\n })\n ),\n ].join(issueSeparator);\n }\n\n if (includePath && isNonEmptyArray(issue.path)) {\n // handle array indices\n if (issue.path.length === 1) {\n const identifier = issue.path[0];\n\n if (typeof identifier === 'number') {\n return `${issue.message} at index ${identifier}`;\n }\n }\n\n return `${issue.message} at \"${joinPath(issue.path)}\"`;\n }\n\n return issue.message;\n}\n\nfunction prefixMessage(\n message: string,\n prefix: string | null,\n prefixSeparator: string\n): string {\n if (prefix !== null) {\n if (message.length > 0) {\n return [prefix, message].join(prefixSeparator);\n }\n\n return prefix;\n }\n\n if (message.length > 0) {\n return message;\n }\n\n // if both reason and prefix are empty, return default prefix\n // to avoid having an empty error message\n return PREFIX;\n}\n","export type NonEmptyArray<T> = [T, ...T[]];\n\nexport function isNonEmptyArray<T>(value: T[]): value is NonEmptyArray<T> {\n return value.length !== 0;\n}\n","import type { util } from 'zod/v4/core';\n\nexport function stringifySymbol(symbol: symbol): string {\n return symbol.description ?? '';\n}\n\nexport type StringifyValueOptions = {\n wrapStringValueInQuote?: boolean;\n localization?: boolean | Intl.LocalesArgument;\n};\n\nexport function stringify(\n value: util.Primitive | Date,\n options: StringifyValueOptions = {}\n): string {\n switch (typeof value) {\n case 'symbol':\n return stringifySymbol(value);\n case 'bigint':\n case 'number': {\n switch (options.localization) {\n case true:\n return value.toLocaleString();\n case false:\n return value.toString();\n default:\n return value.toLocaleString(options.localization);\n }\n }\n case 'string': {\n if (options.wrapStringValueInQuote) {\n return `\"${value}\"`;\n }\n return value;\n }\n default: {\n if (value instanceof Date) {\n switch (options.localization) {\n case true:\n return value.toLocaleString();\n case false:\n return value.toISOString();\n default:\n return value.toLocaleString(options.localization);\n }\n }\n return String(value);\n }\n }\n}\n","import { stringifySymbol } from './stringify.ts';\nimport type { NonEmptyArray } from './NonEmptyArray.ts';\n\n/**\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#identifiers\n */\nconst identifierRegex = /[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*/u;\n\nexport function joinPath(path: NonEmptyArray<PropertyKey>): string {\n if (path.length === 1) {\n let propertyKey = path[0];\n\n if (typeof propertyKey === 'symbol') {\n propertyKey = stringifySymbol(propertyKey);\n }\n\n return propertyKey.toString() || '\"\"';\n }\n\n return path.reduce<string>((acc, propertyKey) => {\n // handle numeric indices\n if (typeof propertyKey === 'number') {\n return acc + '[' + propertyKey.toString() + ']';\n }\n\n // handle symbols\n if (typeof propertyKey === 'symbol') {\n propertyKey = stringifySymbol(propertyKey);\n }\n\n // handle quoted values\n if (propertyKey.includes('\"')) {\n return acc + '[\"' + escapeQuotes(propertyKey) + '\"]';\n }\n\n // handle special characters\n if (!identifierRegex.test(propertyKey)) {\n return acc + '[\"' + propertyKey + '\"]';\n }\n\n // handle normal values\n const separator = acc.length === 0 ? '' : '.';\n return acc + separator + propertyKey;\n }, '');\n}\n\nfunction escapeQuotes(str: string): string {\n return str.replace(/\"/g, '\\\\\"');\n}\n","export const ISSUE_SEPARATOR = '; ';\nexport const MAX_ISSUES_IN_MESSAGE = 99; // I've got 99 problems but the b$tch ain't one\nexport const PREFIX = 'Validation error';\nexport const PREFIX_SEPARATOR = ': ';\nexport const UNION_SEPARATOR = ', or ';\n","import { fromZodIssue } from './fromZodIssue.ts';\nimport type * as zod from 'zod/v3';\n\nexport const errorMap: zod.ZodErrorMap = (issue, ctx) => {\n const error = fromZodIssue({\n ...issue,\n // fallback to the default error message\n // when issue does not have a message\n message: issue.message ?? ctx.defaultError,\n });\n\n return {\n message: error.message,\n };\n};\n","import { isNonEmptyArray } from '../utils/NonEmptyArray.ts';\nimport { fromError } from './fromError.ts';\nimport { isZodErrorLike } from './isZodErrorLike.ts';\nimport {\n createMessageBuilder,\n type CreateMessageBuilderProps,\n type MessageBuilder,\n} from './MessageBuilder.ts';\nimport { ValidationError } from './ValidationError.ts';\nimport type * as zod from 'zod/v3';\n\nexport type ZodError = zod.ZodError;\n\nexport type FromZodErrorOptions =\n | {\n messageBuilder: MessageBuilder;\n }\n // maintain backwards compatibility\n | CreateMessageBuilderProps;\n\nexport function fromZodError(\n zodError: ZodError,\n options: FromZodErrorOptions = {}\n): ValidationError {\n // perform runtime check to ensure the input is a ZodError\n // why? because people have been historically using this function incorrectly\n if (!isZodErrorLike(zodError)) {\n throw new TypeError(\n `Invalid zodError param; expected instance of ZodError. Did you mean to use the \"${fromError.name}\" method instead?`\n );\n }\n\n return fromZodErrorWithoutRuntimeCheck(zodError, options);\n}\n\nexport function fromZodErrorWithoutRuntimeCheck(\n zodError: ZodError,\n options: FromZodErrorOptions = {}\n): ValidationError {\n const zodIssues = zodError.errors;\n\n let message: string;\n if (isNonEmptyArray(zodIssues)) {\n const messageBuilder = createMessageBuilderFromOptions(options);\n message = messageBuilder(zodIssues);\n } else {\n message = zodError.message;\n }\n\n return new ValidationError(message, { cause: zodError });\n}\n\nfunction createMessageBuilderFromOptions(\n options: FromZodErrorOptions\n): MessageBuilder {\n if ('messageBuilder' in options) {\n return options.messageBuilder;\n }\n\n return createMessageBuilder(options);\n}\n","import { ValidationError } from './ValidationError.ts';\nimport { isZodErrorLike } from './isZodErrorLike.ts';\nimport {\n fromZodErrorWithoutRuntimeCheck,\n type FromZodErrorOptions,\n} from './fromZodError.ts';\n\nexport const toValidationError =\n (options: FromZodErrorOptions = {}) =>\n (err: unknown): ValidationError => {\n if (isZodErrorLike(err)) {\n return fromZodErrorWithoutRuntimeCheck(err, options);\n }\n\n if (err instanceof Error) {\n return new ValidationError(err.message, { cause: err });\n }\n\n return new ValidationError('Unknown error');\n };\n","import { toValidationError } from './toValidationError.ts';\nimport type { FromZodErrorOptions } from './fromZodError.ts';\nimport type { ValidationError } from './ValidationError.ts';\n\n/**\n * This function is a non-curried version of `toValidationError`\n */\nexport function fromError(\n err: unknown,\n options: FromZodErrorOptions = {}\n): ValidationError {\n return toValidationError(options)(err);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,SAAS,eAAe,KAAmC;AAChE,SACE,eAAe,SACf,IAAI,SAAS,cACb,YAAY,OACZ,MAAM,QAAQ,IAAI,MAAM;AAE5B;;;ACCO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC;AAAA,EACA;AAAA,EAEA,YAAY,SAAkB,SAAwB;AACpD,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AACZ,SAAK,UAAU,0BAA0B,OAAO;AAAA,EAClD;AAAA,EAEA,WAAmB;AACjB,WAAO,KAAK;AAAA,EACd;AACF;AAEA,SAAS,0BACP,SACqB;AACrB,MAAI,SAAS;AACX,UAAM,QAAQ,QAAQ;AAEtB,QAAI,eAAe,KAAK,GAAG;AACzB,aAAO,MAAM;AAAA,IACf;AAAA,EACF;AAEA,SAAO,CAAC;AACV;;;ACnCO,SAAS,kBAAkB,KAAsC;AACtE,SAAO,eAAe;AACxB;;;ACFO,SAAS,sBAAsB,KAAsC;AAC1E,SAAO,eAAe,SAAS,IAAI,SAAS;AAC9C;;;ACJA,IAAAA,OAAqB;;;ACArB,UAAqB;;;ACEd,SAAS,gBAAmB,OAAuC;AACxE,SAAO,MAAM,WAAW;AAC1B;;;ACFO,SAAS,gBAAgB,QAAwB;AACtD,SAAO,OAAO,eAAe;AAC/B;;;ACEA,IAAM,kBAAkB;AAEjB,SAAS,SAAS,MAA0C;AACjE,MAAI,KAAK,WAAW,GAAG;AACrB,QAAI,cAAc,KAAK,CAAC;AAExB,QAAI,OAAO,gBAAgB,UAAU;AACnC,oBAAc,gBAAgB,WAAW;AAAA,IAC3C;AAEA,WAAO,YAAY,SAAS,KAAK;AAAA,EACnC;AAEA,SA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+
function isZodErrorLike(err) {
|
| 3 |
+
return err instanceof Error && err.name === "ZodError" && "issues" in err && Array.isArray(err.issues);
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
// lib/v3/ValidationError.ts
|
| 7 |
+
var ValidationError = class extends Error {
|
| 8 |
+
name;
|
| 9 |
+
details;
|
| 10 |
+
constructor(message, options) {
|
| 11 |
+
super(message, options);
|
| 12 |
+
this.name = "ZodValidationError";
|
| 13 |
+
this.details = getIssuesFromErrorOptions(options);
|
| 14 |
+
}
|
| 15 |
+
toString() {
|
| 16 |
+
return this.message;
|
| 17 |
+
}
|
| 18 |
+
};
|
| 19 |
+
function getIssuesFromErrorOptions(options) {
|
| 20 |
+
if (options) {
|
| 21 |
+
const cause = options.cause;
|
| 22 |
+
if (isZodErrorLike(cause)) {
|
| 23 |
+
return cause.issues;
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
return [];
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
// lib/v3/isValidationError.ts
|
| 30 |
+
function isValidationError(err) {
|
| 31 |
+
return err instanceof ValidationError;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
// lib/v3/isValidationErrorLike.ts
|
| 35 |
+
function isValidationErrorLike(err) {
|
| 36 |
+
return err instanceof Error && err.name === "ZodValidationError";
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
// lib/v3/fromZodIssue.ts
|
| 40 |
+
import * as zod2 from "zod/v3";
|
| 41 |
+
|
| 42 |
+
// lib/v3/MessageBuilder.ts
|
| 43 |
+
import * as zod from "zod/v3";
|
| 44 |
+
|
| 45 |
+
// lib/utils/NonEmptyArray.ts
|
| 46 |
+
function isNonEmptyArray(value) {
|
| 47 |
+
return value.length !== 0;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
// lib/utils/stringify.ts
|
| 51 |
+
function stringifySymbol(symbol) {
|
| 52 |
+
return symbol.description ?? "";
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
// lib/utils/joinPath.ts
|
| 56 |
+
var identifierRegex = /[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u;
|
| 57 |
+
function joinPath(path) {
|
| 58 |
+
if (path.length === 1) {
|
| 59 |
+
let propertyKey = path[0];
|
| 60 |
+
if (typeof propertyKey === "symbol") {
|
| 61 |
+
propertyKey = stringifySymbol(propertyKey);
|
| 62 |
+
}
|
| 63 |
+
return propertyKey.toString() || '""';
|
| 64 |
+
}
|
| 65 |
+
return path.reduce((acc, propertyKey) => {
|
| 66 |
+
if (typeof propertyKey === "number") {
|
| 67 |
+
return acc + "[" + propertyKey.toString() + "]";
|
| 68 |
+
}
|
| 69 |
+
if (typeof propertyKey === "symbol") {
|
| 70 |
+
propertyKey = stringifySymbol(propertyKey);
|
| 71 |
+
}
|
| 72 |
+
if (propertyKey.includes('"')) {
|
| 73 |
+
return acc + '["' + escapeQuotes(propertyKey) + '"]';
|
| 74 |
+
}
|
| 75 |
+
if (!identifierRegex.test(propertyKey)) {
|
| 76 |
+
return acc + '["' + propertyKey + '"]';
|
| 77 |
+
}
|
| 78 |
+
const separator = acc.length === 0 ? "" : ".";
|
| 79 |
+
return acc + separator + propertyKey;
|
| 80 |
+
}, "");
|
| 81 |
+
}
|
| 82 |
+
function escapeQuotes(str) {
|
| 83 |
+
return str.replace(/"/g, '\\"');
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
// lib/v3/config.ts
|
| 87 |
+
var ISSUE_SEPARATOR = "; ";
|
| 88 |
+
var MAX_ISSUES_IN_MESSAGE = 99;
|
| 89 |
+
var PREFIX = "Validation error";
|
| 90 |
+
var PREFIX_SEPARATOR = ": ";
|
| 91 |
+
var UNION_SEPARATOR = ", or ";
|
| 92 |
+
|
| 93 |
+
// lib/v3/MessageBuilder.ts
|
| 94 |
+
function createMessageBuilder(props = {}) {
|
| 95 |
+
const {
|
| 96 |
+
issueSeparator = ISSUE_SEPARATOR,
|
| 97 |
+
unionSeparator = UNION_SEPARATOR,
|
| 98 |
+
prefixSeparator = PREFIX_SEPARATOR,
|
| 99 |
+
prefix = PREFIX,
|
| 100 |
+
includePath = true,
|
| 101 |
+
maxIssuesInMessage = MAX_ISSUES_IN_MESSAGE
|
| 102 |
+
} = props;
|
| 103 |
+
return (issues) => {
|
| 104 |
+
const message = issues.slice(0, maxIssuesInMessage).map(
|
| 105 |
+
(issue) => getMessageFromZodIssue({
|
| 106 |
+
issue,
|
| 107 |
+
issueSeparator,
|
| 108 |
+
unionSeparator,
|
| 109 |
+
includePath
|
| 110 |
+
})
|
| 111 |
+
).join(issueSeparator);
|
| 112 |
+
return prefixMessage(message, prefix, prefixSeparator);
|
| 113 |
+
};
|
| 114 |
+
}
|
| 115 |
+
function getMessageFromZodIssue(props) {
|
| 116 |
+
const { issue, issueSeparator, unionSeparator, includePath } = props;
|
| 117 |
+
if (issue.code === zod.ZodIssueCode.invalid_union) {
|
| 118 |
+
return issue.unionErrors.reduce((acc, zodError) => {
|
| 119 |
+
const newIssues = zodError.issues.map(
|
| 120 |
+
(issue2) => getMessageFromZodIssue({
|
| 121 |
+
issue: issue2,
|
| 122 |
+
issueSeparator,
|
| 123 |
+
unionSeparator,
|
| 124 |
+
includePath
|
| 125 |
+
})
|
| 126 |
+
).join(issueSeparator);
|
| 127 |
+
if (!acc.includes(newIssues)) {
|
| 128 |
+
acc.push(newIssues);
|
| 129 |
+
}
|
| 130 |
+
return acc;
|
| 131 |
+
}, []).join(unionSeparator);
|
| 132 |
+
}
|
| 133 |
+
if (issue.code === zod.ZodIssueCode.invalid_arguments) {
|
| 134 |
+
return [
|
| 135 |
+
issue.message,
|
| 136 |
+
...issue.argumentsError.issues.map(
|
| 137 |
+
(issue2) => getMessageFromZodIssue({
|
| 138 |
+
issue: issue2,
|
| 139 |
+
issueSeparator,
|
| 140 |
+
unionSeparator,
|
| 141 |
+
includePath
|
| 142 |
+
})
|
| 143 |
+
)
|
| 144 |
+
].join(issueSeparator);
|
| 145 |
+
}
|
| 146 |
+
if (issue.code === zod.ZodIssueCode.invalid_return_type) {
|
| 147 |
+
return [
|
| 148 |
+
issue.message,
|
| 149 |
+
...issue.returnTypeError.issues.map(
|
| 150 |
+
(issue2) => getMessageFromZodIssue({
|
| 151 |
+
issue: issue2,
|
| 152 |
+
issueSeparator,
|
| 153 |
+
unionSeparator,
|
| 154 |
+
includePath
|
| 155 |
+
})
|
| 156 |
+
)
|
| 157 |
+
].join(issueSeparator);
|
| 158 |
+
}
|
| 159 |
+
if (includePath && isNonEmptyArray(issue.path)) {
|
| 160 |
+
if (issue.path.length === 1) {
|
| 161 |
+
const identifier = issue.path[0];
|
| 162 |
+
if (typeof identifier === "number") {
|
| 163 |
+
return `${issue.message} at index ${identifier}`;
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
return `${issue.message} at "${joinPath(issue.path)}"`;
|
| 167 |
+
}
|
| 168 |
+
return issue.message;
|
| 169 |
+
}
|
| 170 |
+
function prefixMessage(message, prefix, prefixSeparator) {
|
| 171 |
+
if (prefix !== null) {
|
| 172 |
+
if (message.length > 0) {
|
| 173 |
+
return [prefix, message].join(prefixSeparator);
|
| 174 |
+
}
|
| 175 |
+
return prefix;
|
| 176 |
+
}
|
| 177 |
+
if (message.length > 0) {
|
| 178 |
+
return message;
|
| 179 |
+
}
|
| 180 |
+
return PREFIX;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
// lib/v3/fromZodIssue.ts
|
| 184 |
+
function fromZodIssue(issue, options = {}) {
|
| 185 |
+
const messageBuilder = createMessageBuilderFromOptions(options);
|
| 186 |
+
const message = messageBuilder([issue]);
|
| 187 |
+
return new ValidationError(message, { cause: new zod2.ZodError([issue]) });
|
| 188 |
+
}
|
| 189 |
+
function createMessageBuilderFromOptions(options) {
|
| 190 |
+
if ("messageBuilder" in options) {
|
| 191 |
+
return options.messageBuilder;
|
| 192 |
+
}
|
| 193 |
+
return createMessageBuilder(options);
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
// lib/v3/errorMap.ts
|
| 197 |
+
var errorMap = (issue, ctx) => {
|
| 198 |
+
const error = fromZodIssue({
|
| 199 |
+
...issue,
|
| 200 |
+
// fallback to the default error message
|
| 201 |
+
// when issue does not have a message
|
| 202 |
+
message: issue.message ?? ctx.defaultError
|
| 203 |
+
});
|
| 204 |
+
return {
|
| 205 |
+
message: error.message
|
| 206 |
+
};
|
| 207 |
+
};
|
| 208 |
+
|
| 209 |
+
// lib/v3/fromZodError.ts
|
| 210 |
+
function fromZodError(zodError, options = {}) {
|
| 211 |
+
if (!isZodErrorLike(zodError)) {
|
| 212 |
+
throw new TypeError(
|
| 213 |
+
`Invalid zodError param; expected instance of ZodError. Did you mean to use the "${fromError.name}" method instead?`
|
| 214 |
+
);
|
| 215 |
+
}
|
| 216 |
+
return fromZodErrorWithoutRuntimeCheck(zodError, options);
|
| 217 |
+
}
|
| 218 |
+
function fromZodErrorWithoutRuntimeCheck(zodError, options = {}) {
|
| 219 |
+
const zodIssues = zodError.errors;
|
| 220 |
+
let message;
|
| 221 |
+
if (isNonEmptyArray(zodIssues)) {
|
| 222 |
+
const messageBuilder = createMessageBuilderFromOptions2(options);
|
| 223 |
+
message = messageBuilder(zodIssues);
|
| 224 |
+
} else {
|
| 225 |
+
message = zodError.message;
|
| 226 |
+
}
|
| 227 |
+
return new ValidationError(message, { cause: zodError });
|
| 228 |
+
}
|
| 229 |
+
function createMessageBuilderFromOptions2(options) {
|
| 230 |
+
if ("messageBuilder" in options) {
|
| 231 |
+
return options.messageBuilder;
|
| 232 |
+
}
|
| 233 |
+
return createMessageBuilder(options);
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
// lib/v3/toValidationError.ts
|
| 237 |
+
var toValidationError = (options = {}) => (err) => {
|
| 238 |
+
if (isZodErrorLike(err)) {
|
| 239 |
+
return fromZodErrorWithoutRuntimeCheck(err, options);
|
| 240 |
+
}
|
| 241 |
+
if (err instanceof Error) {
|
| 242 |
+
return new ValidationError(err.message, { cause: err });
|
| 243 |
+
}
|
| 244 |
+
return new ValidationError("Unknown error");
|
| 245 |
+
};
|
| 246 |
+
|
| 247 |
+
// lib/v3/fromError.ts
|
| 248 |
+
function fromError(err, options = {}) {
|
| 249 |
+
return toValidationError(options)(err);
|
| 250 |
+
}
|
| 251 |
+
export {
|
| 252 |
+
ValidationError,
|
| 253 |
+
createMessageBuilder,
|
| 254 |
+
errorMap,
|
| 255 |
+
fromError,
|
| 256 |
+
fromZodError,
|
| 257 |
+
fromZodIssue,
|
| 258 |
+
isValidationError,
|
| 259 |
+
isValidationErrorLike,
|
| 260 |
+
isZodErrorLike,
|
| 261 |
+
toValidationError
|
| 262 |
+
};
|
| 263 |
+
//# sourceMappingURL=index.mjs.map
|
node_modules/zod-validation-error/v3/index.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"sources":["../lib/v3/isZodErrorLike.ts","../lib/v3/ValidationError.ts","../lib/v3/isValidationError.ts","../lib/v3/isValidationErrorLike.ts","../lib/v3/fromZodIssue.ts","../lib/v3/MessageBuilder.ts","../lib/utils/NonEmptyArray.ts","../lib/utils/stringify.ts","../lib/utils/joinPath.ts","../lib/v3/config.ts","../lib/v3/errorMap.ts","../lib/v3/fromZodError.ts","../lib/v3/toValidationError.ts","../lib/v3/fromError.ts"],"sourcesContent":["import type * as zod from 'zod/v3';\n\nexport function isZodErrorLike(err: unknown): err is zod.ZodError {\n return (\n err instanceof Error &&\n err.name === 'ZodError' &&\n 'issues' in err &&\n Array.isArray(err.issues)\n );\n}\n","import { isZodErrorLike } from './isZodErrorLike.ts';\nimport type * as zod from 'zod/v3';\n\n// make zod-validation-error compatible with\n// earlier to es2022 typescript configurations\n// @see https://github.com/causaly/zod-validation-error/issues/226\nexport interface ErrorOptions {\n cause?: unknown;\n}\n\nexport class ValidationError extends Error {\n name: 'ZodValidationError';\n details: Array<zod.ZodIssue>;\n\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'ZodValidationError';\n this.details = getIssuesFromErrorOptions(options);\n }\n\n toString(): string {\n return this.message;\n }\n}\n\nfunction getIssuesFromErrorOptions(\n options?: ErrorOptions\n): Array<zod.ZodIssue> {\n if (options) {\n const cause = options.cause;\n\n if (isZodErrorLike(cause)) {\n return cause.issues;\n }\n }\n\n return [];\n}\n","import { ValidationError } from './ValidationError.ts';\n\nexport function isValidationError(err: unknown): err is ValidationError {\n return err instanceof ValidationError;\n}\n","import type { ValidationError } from './ValidationError.ts';\n\nexport function isValidationErrorLike(err: unknown): err is ValidationError {\n return err instanceof Error && err.name === 'ZodValidationError';\n}\n","import * as zod from 'zod/v3';\n\nimport {\n type MessageBuilder,\n type CreateMessageBuilderProps,\n type ZodIssue,\n createMessageBuilder,\n} from './MessageBuilder.ts';\nimport { ValidationError } from './ValidationError.ts';\n\nexport type FromZodIssueOptions =\n | {\n messageBuilder: MessageBuilder;\n }\n // maintain backwards compatibility\n | Omit<CreateMessageBuilderProps, 'maxIssuesInMessage'>;\n\nexport function fromZodIssue(\n issue: ZodIssue,\n options: FromZodIssueOptions = {}\n): ValidationError {\n const messageBuilder = createMessageBuilderFromOptions(options);\n const message = messageBuilder([issue]);\n\n return new ValidationError(message, { cause: new zod.ZodError([issue]) });\n}\n\nfunction createMessageBuilderFromOptions(\n options: FromZodIssueOptions\n): MessageBuilder {\n if ('messageBuilder' in options) {\n return options.messageBuilder;\n }\n\n return createMessageBuilder(options);\n}\n","import * as zod from 'zod/v3';\nimport { type NonEmptyArray, isNonEmptyArray } from '../utils/NonEmptyArray.ts';\nimport { joinPath } from '../utils/joinPath.ts';\nimport {\n ISSUE_SEPARATOR,\n MAX_ISSUES_IN_MESSAGE,\n PREFIX,\n PREFIX_SEPARATOR,\n UNION_SEPARATOR,\n} from './config.ts';\n\nexport type ZodIssue = zod.ZodIssue;\n\nexport type MessageBuilder = (issues: NonEmptyArray<ZodIssue>) => string;\n\nexport type CreateMessageBuilderProps = {\n issueSeparator?: string;\n unionSeparator?: string;\n prefix?: string | null;\n prefixSeparator?: string;\n includePath?: boolean;\n maxIssuesInMessage?: number;\n};\n\nexport function createMessageBuilder(\n props: CreateMessageBuilderProps = {}\n): MessageBuilder {\n const {\n issueSeparator = ISSUE_SEPARATOR,\n unionSeparator = UNION_SEPARATOR,\n prefixSeparator = PREFIX_SEPARATOR,\n prefix = PREFIX,\n includePath = true,\n maxIssuesInMessage = MAX_ISSUES_IN_MESSAGE,\n } = props;\n return (issues) => {\n const message = issues\n // limit max number of issues printed in the reason section\n .slice(0, maxIssuesInMessage)\n // format error message\n .map((issue) =>\n getMessageFromZodIssue({\n issue,\n issueSeparator,\n unionSeparator,\n includePath,\n })\n )\n // concat as string\n .join(issueSeparator);\n\n return prefixMessage(message, prefix, prefixSeparator);\n };\n}\n\nfunction getMessageFromZodIssue(props: {\n issue: ZodIssue;\n issueSeparator: string;\n unionSeparator: string;\n includePath: boolean;\n}): string {\n const { issue, issueSeparator, unionSeparator, includePath } = props;\n\n if (issue.code === zod.ZodIssueCode.invalid_union) {\n return issue.unionErrors\n .reduce<string[]>((acc, zodError) => {\n const newIssues = zodError.issues\n .map((issue) =>\n getMessageFromZodIssue({\n issue,\n issueSeparator,\n unionSeparator,\n includePath,\n })\n )\n .join(issueSeparator);\n\n if (!acc.includes(newIssues)) {\n acc.push(newIssues);\n }\n\n return acc;\n }, [])\n .join(unionSeparator);\n }\n\n if (issue.code === zod.ZodIssueCode.invalid_arguments) {\n return [\n issue.message,\n ...issue.argumentsError.issues.map((issue) =>\n getMessageFromZodIssue({\n issue,\n issueSeparator,\n unionSeparator,\n includePath,\n })\n ),\n ].join(issueSeparator);\n }\n\n if (issue.code === zod.ZodIssueCode.invalid_return_type) {\n return [\n issue.message,\n ...issue.returnTypeError.issues.map((issue) =>\n getMessageFromZodIssue({\n issue,\n issueSeparator,\n unionSeparator,\n includePath,\n })\n ),\n ].join(issueSeparator);\n }\n\n if (includePath && isNonEmptyArray(issue.path)) {\n // handle array indices\n if (issue.path.length === 1) {\n const identifier = issue.path[0];\n\n if (typeof identifier === 'number') {\n return `${issue.message} at index ${identifier}`;\n }\n }\n\n return `${issue.message} at \"${joinPath(issue.path)}\"`;\n }\n\n return issue.message;\n}\n\nfunction prefixMessage(\n message: string,\n prefix: string | null,\n prefixSeparator: string\n): string {\n if (prefix !== null) {\n if (message.length > 0) {\n return [prefix, message].join(prefixSeparator);\n }\n\n return prefix;\n }\n\n if (message.length > 0) {\n return message;\n }\n\n // if both reason and prefix are empty, return default prefix\n // to avoid having an empty error message\n return PREFIX;\n}\n","export type NonEmptyArray<T> = [T, ...T[]];\n\nexport function isNonEmptyArray<T>(value: T[]): value is NonEmptyArray<T> {\n return value.length !== 0;\n}\n","import type { util } from 'zod/v4/core';\n\nexport function stringifySymbol(symbol: symbol): string {\n return symbol.description ?? '';\n}\n\nexport type StringifyValueOptions = {\n wrapStringValueInQuote?: boolean;\n localization?: boolean | Intl.LocalesArgument;\n};\n\nexport function stringify(\n value: util.Primitive | Date,\n options: StringifyValueOptions = {}\n): string {\n switch (typeof value) {\n case 'symbol':\n return stringifySymbol(value);\n case 'bigint':\n case 'number': {\n switch (options.localization) {\n case true:\n return value.toLocaleString();\n case false:\n return value.toString();\n default:\n return value.toLocaleString(options.localization);\n }\n }\n case 'string': {\n if (options.wrapStringValueInQuote) {\n return `\"${value}\"`;\n }\n return value;\n }\n default: {\n if (value instanceof Date) {\n switch (options.localization) {\n case true:\n return value.toLocaleString();\n case false:\n return value.toISOString();\n default:\n return value.toLocaleString(options.localization);\n }\n }\n return String(value);\n }\n }\n}\n","import { stringifySymbol } from './stringify.ts';\nimport type { NonEmptyArray } from './NonEmptyArray.ts';\n\n/**\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#identifiers\n */\nconst identifierRegex = /[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*/u;\n\nexport function joinPath(path: NonEmptyArray<PropertyKey>): string {\n if (path.length === 1) {\n let propertyKey = path[0];\n\n if (typeof propertyKey === 'symbol') {\n propertyKey = stringifySymbol(propertyKey);\n }\n\n return propertyKey.toString() || '\"\"';\n }\n\n return path.reduce<string>((acc, propertyKey) => {\n // handle numeric indices\n if (typeof propertyKey === 'number') {\n return acc + '[' + propertyKey.toString() + ']';\n }\n\n // handle symbols\n if (typeof propertyKey === 'symbol') {\n propertyKey = stringifySymbol(propertyKey);\n }\n\n // handle quoted values\n if (propertyKey.includes('\"')) {\n return acc + '[\"' + escapeQuotes(propertyKey) + '\"]';\n }\n\n // handle special characters\n if (!identifierRegex.test(propertyKey)) {\n return acc + '[\"' + propertyKey + '\"]';\n }\n\n // handle normal values\n const separator = acc.length === 0 ? '' : '.';\n return acc + separator + propertyKey;\n }, '');\n}\n\nfunction escapeQuotes(str: string): string {\n return str.replace(/\"/g, '\\\\\"');\n}\n","export const ISSUE_SEPARATOR = '; ';\nexport const MAX_ISSUES_IN_MESSAGE = 99; // I've got 99 problems but the b$tch ain't one\nexport const PREFIX = 'Validation error';\nexport const PREFIX_SEPARATOR = ': ';\nexport const UNION_SEPARATOR = ', or ';\n","import { fromZodIssue } from './fromZodIssue.ts';\nimport type * as zod from 'zod/v3';\n\nexport const errorMap: zod.ZodErrorMap = (issue, ctx) => {\n const error = fromZodIssue({\n ...issue,\n // fallback to the default error message\n // when issue does not have a message\n message: issue.message ?? ctx.defaultError,\n });\n\n return {\n message: error.message,\n };\n};\n","import { isNonEmptyArray } from '../utils/NonEmptyArray.ts';\nimport { fromError } from './fromError.ts';\nimport { isZodErrorLike } from './isZodErrorLike.ts';\nimport {\n createMessageBuilder,\n type CreateMessageBuilderProps,\n type MessageBuilder,\n} from './MessageBuilder.ts';\nimport { ValidationError } from './ValidationError.ts';\nimport type * as zod from 'zod/v3';\n\nexport type ZodError = zod.ZodError;\n\nexport type FromZodErrorOptions =\n | {\n messageBuilder: MessageBuilder;\n }\n // maintain backwards compatibility\n | CreateMessageBuilderProps;\n\nexport function fromZodError(\n zodError: ZodError,\n options: FromZodErrorOptions = {}\n): ValidationError {\n // perform runtime check to ensure the input is a ZodError\n // why? because people have been historically using this function incorrectly\n if (!isZodErrorLike(zodError)) {\n throw new TypeError(\n `Invalid zodError param; expected instance of ZodError. Did you mean to use the \"${fromError.name}\" method instead?`\n );\n }\n\n return fromZodErrorWithoutRuntimeCheck(zodError, options);\n}\n\nexport function fromZodErrorWithoutRuntimeCheck(\n zodError: ZodError,\n options: FromZodErrorOptions = {}\n): ValidationError {\n const zodIssues = zodError.errors;\n\n let message: string;\n if (isNonEmptyArray(zodIssues)) {\n const messageBuilder = createMessageBuilderFromOptions(options);\n message = messageBuilder(zodIssues);\n } else {\n message = zodError.message;\n }\n\n return new ValidationError(message, { cause: zodError });\n}\n\nfunction createMessageBuilderFromOptions(\n options: FromZodErrorOptions\n): MessageBuilder {\n if ('messageBuilder' in options) {\n return options.messageBuilder;\n }\n\n return createMessageBuilder(options);\n}\n","import { ValidationError } from './ValidationError.ts';\nimport { isZodErrorLike } from './isZodErrorLike.ts';\nimport {\n fromZodErrorWithoutRuntimeCheck,\n type FromZodErrorOptions,\n} from './fromZodError.ts';\n\nexport const toValidationError =\n (options: FromZodErrorOptions = {}) =>\n (err: unknown): ValidationError => {\n if (isZodErrorLike(err)) {\n return fromZodErrorWithoutRuntimeCheck(err, options);\n }\n\n if (err instanceof Error) {\n return new ValidationError(err.message, { cause: err });\n }\n\n return new ValidationError('Unknown error');\n };\n","import { toValidationError } from './toValidationError.ts';\nimport type { FromZodErrorOptions } from './fromZodError.ts';\nimport type { ValidationError } from './ValidationError.ts';\n\n/**\n * This function is a non-curried version of `toValidationError`\n */\nexport function fromError(\n err: unknown,\n options: FromZodErrorOptions = {}\n): ValidationError {\n return toValidationError(options)(err);\n}\n"],"mappings":";AAEO,SAAS,eAAe,KAAmC;AAChE,SACE,eAAe,SACf,IAAI,SAAS,cACb,YAAY,OACZ,MAAM,QAAQ,IAAI,MAAM;AAE5B;;;ACCO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC;AAAA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A+B,CAAC,GACf;AACjB,SAAO,kBAAkB,OAAO,EAAE,GAAG;AACvC;","names":["zod","issue","createMessageBuilderFromOptions"]}
|
node_modules/zod-validation-error/v4/index.d.mts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as zod from 'zod/v4/core';
|
| 2 |
+
|
| 3 |
+
declare const ZOD_VALIDATION_ERROR_NAME = "ZodValidationError";
|
| 4 |
+
interface ErrorOptions {
|
| 5 |
+
cause?: unknown;
|
| 6 |
+
}
|
| 7 |
+
declare class ValidationError extends Error {
|
| 8 |
+
name: typeof ZOD_VALIDATION_ERROR_NAME;
|
| 9 |
+
details: Array<zod.$ZodIssue>;
|
| 10 |
+
constructor(message?: string, options?: ErrorOptions);
|
| 11 |
+
toString(): string;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
declare function isValidationError(err: unknown): err is ValidationError;
|
| 15 |
+
|
| 16 |
+
declare function isValidationErrorLike(err: unknown): err is ValidationError;
|
| 17 |
+
|
| 18 |
+
declare function isZodErrorLike(err: unknown): err is zod.$ZodError;
|
| 19 |
+
|
| 20 |
+
type ErrorMapOptions = {
|
| 21 |
+
dateLocalization: boolean | Intl.LocalesArgument;
|
| 22 |
+
numberLocalization: boolean | Intl.LocalesArgument;
|
| 23 |
+
displayInvalidFormatDetails: boolean;
|
| 24 |
+
allowedValuesSeparator: string;
|
| 25 |
+
allowedValuesLastSeparator: string | undefined;
|
| 26 |
+
wrapAllowedValuesInQuote: boolean;
|
| 27 |
+
maxAllowedValuesToDisplay: number;
|
| 28 |
+
unrecognizedKeysSeparator: string;
|
| 29 |
+
unrecognizedKeysLastSeparator: string | undefined;
|
| 30 |
+
wrapUnrecognizedKeysInQuote: boolean;
|
| 31 |
+
maxUnrecognizedKeysToDisplay: number;
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
declare function createErrorMap(partialOptions?: Partial<ErrorMapOptions>): zod.$ZodErrorMap<zod.$ZodIssue>;
|
| 35 |
+
|
| 36 |
+
type NonEmptyArray<T> = [T, ...T[]];
|
| 37 |
+
|
| 38 |
+
type ZodIssue = zod.$ZodIssue;
|
| 39 |
+
type MessageBuilder = (issues: NonEmptyArray<ZodIssue>) => string;
|
| 40 |
+
type MessageBuilderOptions = {
|
| 41 |
+
prefix: string | null | undefined;
|
| 42 |
+
prefixSeparator: string;
|
| 43 |
+
maxIssuesInMessage: number;
|
| 44 |
+
issueSeparator: string;
|
| 45 |
+
unionSeparator: string;
|
| 46 |
+
includePath: boolean;
|
| 47 |
+
forceTitleCase: boolean;
|
| 48 |
+
};
|
| 49 |
+
declare function createMessageBuilder(partialOptions?: Partial<MessageBuilderOptions>): MessageBuilder;
|
| 50 |
+
|
| 51 |
+
type ZodError = zod.$ZodError;
|
| 52 |
+
type FromZodErrorOptions = {
|
| 53 |
+
messageBuilder: MessageBuilder;
|
| 54 |
+
} | Partial<MessageBuilderOptions>;
|
| 55 |
+
declare function fromZodError(zodError: ZodError, options?: FromZodErrorOptions): ValidationError;
|
| 56 |
+
|
| 57 |
+
declare function fromError(err: unknown, options?: FromZodErrorOptions): ValidationError;
|
| 58 |
+
|
| 59 |
+
type FromZodIssueOptions = {
|
| 60 |
+
messageBuilder: MessageBuilder;
|
| 61 |
+
} | Partial<Omit<MessageBuilderOptions, 'maxIssuesInMessage'>>;
|
| 62 |
+
declare function fromZodIssue(issue: ZodIssue, options?: FromZodIssueOptions): ValidationError;
|
| 63 |
+
|
| 64 |
+
declare const toValidationError: (options?: FromZodErrorOptions) => (err: unknown) => ValidationError;
|
| 65 |
+
|
| 66 |
+
export { type ErrorMapOptions, type ErrorOptions, type FromZodErrorOptions, type FromZodIssueOptions, type MessageBuilder, type MessageBuilderOptions, type NonEmptyArray, ValidationError, type ZodError, type ZodIssue, createErrorMap, createMessageBuilder, fromError, fromZodError, fromZodIssue, isValidationError, isValidationErrorLike, isZodErrorLike, toValidationError };
|
node_modules/zod-validation-error/v4/index.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as zod from 'zod/v4/core';
|
| 2 |
+
|
| 3 |
+
declare const ZOD_VALIDATION_ERROR_NAME = "ZodValidationError";
|
| 4 |
+
interface ErrorOptions {
|
| 5 |
+
cause?: unknown;
|
| 6 |
+
}
|
| 7 |
+
declare class ValidationError extends Error {
|
| 8 |
+
name: typeof ZOD_VALIDATION_ERROR_NAME;
|
| 9 |
+
details: Array<zod.$ZodIssue>;
|
| 10 |
+
constructor(message?: string, options?: ErrorOptions);
|
| 11 |
+
toString(): string;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
declare function isValidationError(err: unknown): err is ValidationError;
|
| 15 |
+
|
| 16 |
+
declare function isValidationErrorLike(err: unknown): err is ValidationError;
|
| 17 |
+
|
| 18 |
+
declare function isZodErrorLike(err: unknown): err is zod.$ZodError;
|
| 19 |
+
|
| 20 |
+
type ErrorMapOptions = {
|
| 21 |
+
dateLocalization: boolean | Intl.LocalesArgument;
|
| 22 |
+
numberLocalization: boolean | Intl.LocalesArgument;
|
| 23 |
+
displayInvalidFormatDetails: boolean;
|
| 24 |
+
allowedValuesSeparator: string;
|
| 25 |
+
allowedValuesLastSeparator: string | undefined;
|
| 26 |
+
wrapAllowedValuesInQuote: boolean;
|
| 27 |
+
maxAllowedValuesToDisplay: number;
|
| 28 |
+
unrecognizedKeysSeparator: string;
|
| 29 |
+
unrecognizedKeysLastSeparator: string | undefined;
|
| 30 |
+
wrapUnrecognizedKeysInQuote: boolean;
|
| 31 |
+
maxUnrecognizedKeysToDisplay: number;
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
declare function createErrorMap(partialOptions?: Partial<ErrorMapOptions>): zod.$ZodErrorMap<zod.$ZodIssue>;
|
| 35 |
+
|
| 36 |
+
type NonEmptyArray<T> = [T, ...T[]];
|
| 37 |
+
|
| 38 |
+
type ZodIssue = zod.$ZodIssue;
|
| 39 |
+
type MessageBuilder = (issues: NonEmptyArray<ZodIssue>) => string;
|
| 40 |
+
type MessageBuilderOptions = {
|
| 41 |
+
prefix: string | null | undefined;
|
| 42 |
+
prefixSeparator: string;
|
| 43 |
+
maxIssuesInMessage: number;
|
| 44 |
+
issueSeparator: string;
|
| 45 |
+
unionSeparator: string;
|
| 46 |
+
includePath: boolean;
|
| 47 |
+
forceTitleCase: boolean;
|
| 48 |
+
};
|
| 49 |
+
declare function createMessageBuilder(partialOptions?: Partial<MessageBuilderOptions>): MessageBuilder;
|
| 50 |
+
|
| 51 |
+
type ZodError = zod.$ZodError;
|
| 52 |
+
type FromZodErrorOptions = {
|
| 53 |
+
messageBuilder: MessageBuilder;
|
| 54 |
+
} | Partial<MessageBuilderOptions>;
|
| 55 |
+
declare function fromZodError(zodError: ZodError, options?: FromZodErrorOptions): ValidationError;
|
| 56 |
+
|
| 57 |
+
declare function fromError(err: unknown, options?: FromZodErrorOptions): ValidationError;
|
| 58 |
+
|
| 59 |
+
type FromZodIssueOptions = {
|
| 60 |
+
messageBuilder: MessageBuilder;
|
| 61 |
+
} | Partial<Omit<MessageBuilderOptions, 'maxIssuesInMessage'>>;
|
| 62 |
+
declare function fromZodIssue(issue: ZodIssue, options?: FromZodIssueOptions): ValidationError;
|
| 63 |
+
|
| 64 |
+
declare const toValidationError: (options?: FromZodErrorOptions) => (err: unknown) => ValidationError;
|
| 65 |
+
|
| 66 |
+
export { type ErrorMapOptions, type ErrorOptions, type FromZodErrorOptions, type FromZodIssueOptions, type MessageBuilder, type MessageBuilderOptions, type NonEmptyArray, ValidationError, type ZodError, type ZodIssue, createErrorMap, createMessageBuilder, fromError, fromZodError, fromZodIssue, isValidationError, isValidationErrorLike, isZodErrorLike, toValidationError };
|
node_modules/zod-validation-error/v4/index.js
ADDED
|
@@ -0,0 +1,725 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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| 5 |
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
| 6 |
+
var __getProtoOf = Object.getPrototypeOf;
|
| 7 |
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
| 8 |
+
var __export = (target, all) => {
|
| 9 |
+
for (var name in all)
|
| 10 |
+
__defProp(target, name, { get: all[name], enumerable: true });
|
| 11 |
+
};
|
| 12 |
+
var __copyProps = (to, from, except, desc) => {
|
| 13 |
+
if (from && typeof from === "object" || typeof from === "function") {
|
| 14 |
+
for (let key of __getOwnPropNames(from))
|
| 15 |
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
| 16 |
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
| 17 |
+
}
|
| 18 |
+
return to;
|
| 19 |
+
};
|
| 20 |
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
| 21 |
+
// If the importer is in node compatibility mode or this is not an ESM
|
| 22 |
+
// file that has been converted to a CommonJS file using a Babel-
|
| 23 |
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
| 24 |
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
| 25 |
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
| 26 |
+
mod
|
| 27 |
+
));
|
| 28 |
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
| 29 |
+
|
| 30 |
+
// lib/v4/index.ts
|
| 31 |
+
var index_exports = {};
|
| 32 |
+
__export(index_exports, {
|
| 33 |
+
ValidationError: () => ValidationError,
|
| 34 |
+
createErrorMap: () => createErrorMap,
|
| 35 |
+
createMessageBuilder: () => createMessageBuilder,
|
| 36 |
+
fromError: () => fromError,
|
| 37 |
+
fromZodError: () => fromZodError,
|
| 38 |
+
fromZodIssue: () => fromZodIssue,
|
| 39 |
+
isValidationError: () => isValidationError,
|
| 40 |
+
isValidationErrorLike: () => isValidationErrorLike,
|
| 41 |
+
isZodErrorLike: () => isZodErrorLike,
|
| 42 |
+
toValidationError: () => toValidationError
|
| 43 |
+
});
|
| 44 |
+
module.exports = __toCommonJS(index_exports);
|
| 45 |
+
|
| 46 |
+
// lib/v4/isZodErrorLike.ts
|
| 47 |
+
function isZodErrorLike(err) {
|
| 48 |
+
return err instanceof Object && "name" in err && (err.name === "ZodError" || err.name === "$ZodError") && "issues" in err && Array.isArray(err.issues);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
// lib/v4/ValidationError.ts
|
| 52 |
+
var ZOD_VALIDATION_ERROR_NAME = "ZodValidationError";
|
| 53 |
+
var ValidationError = class extends Error {
|
| 54 |
+
name;
|
| 55 |
+
details;
|
| 56 |
+
constructor(message, options) {
|
| 57 |
+
super(message, options);
|
| 58 |
+
this.name = ZOD_VALIDATION_ERROR_NAME;
|
| 59 |
+
this.details = getIssuesFromErrorOptions(options);
|
| 60 |
+
}
|
| 61 |
+
toString() {
|
| 62 |
+
return this.message;
|
| 63 |
+
}
|
| 64 |
+
};
|
| 65 |
+
function getIssuesFromErrorOptions(options) {
|
| 66 |
+
if (options) {
|
| 67 |
+
const cause = options.cause;
|
| 68 |
+
if (isZodErrorLike(cause)) {
|
| 69 |
+
return cause.issues;
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
return [];
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
// lib/v4/isValidationError.ts
|
| 76 |
+
function isValidationError(err) {
|
| 77 |
+
return err instanceof ValidationError;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
// lib/v4/isValidationErrorLike.ts
|
| 81 |
+
function isValidationErrorLike(err) {
|
| 82 |
+
return err instanceof Error && err.name === ZOD_VALIDATION_ERROR_NAME;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
// lib/v4/errorMap/custom.ts
|
| 86 |
+
function parseCustomIssue(issue) {
|
| 87 |
+
return {
|
| 88 |
+
type: issue.code,
|
| 89 |
+
path: issue.path,
|
| 90 |
+
message: issue.message ?? "Invalid input"
|
| 91 |
+
};
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
// lib/v4/errorMap/invalidElement.ts
|
| 95 |
+
function parseInvalidElementIssue(issue) {
|
| 96 |
+
return {
|
| 97 |
+
type: issue.code,
|
| 98 |
+
path: issue.path,
|
| 99 |
+
message: `unexpected element in ${issue.origin}`
|
| 100 |
+
};
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
// lib/v4/errorMap/invalidKey.ts
|
| 104 |
+
function parseInvalidKeyIssue(issue) {
|
| 105 |
+
return {
|
| 106 |
+
type: issue.code,
|
| 107 |
+
path: issue.path,
|
| 108 |
+
message: `unexpected key in ${issue.origin}`
|
| 109 |
+
};
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// lib/v4/errorMap/invalidStringFormat.ts
|
| 113 |
+
function parseInvalidStringFormatIssue(issue, options = {
|
| 114 |
+
displayInvalidFormatDetails: false
|
| 115 |
+
}) {
|
| 116 |
+
switch (issue.format) {
|
| 117 |
+
case "lowercase":
|
| 118 |
+
case "uppercase":
|
| 119 |
+
return {
|
| 120 |
+
type: issue.code,
|
| 121 |
+
path: issue.path,
|
| 122 |
+
message: `value must be in ${issue.format} format`
|
| 123 |
+
};
|
| 124 |
+
default: {
|
| 125 |
+
if (isZodIssueStringStartsWith(issue)) {
|
| 126 |
+
return parseStringStartsWith(issue);
|
| 127 |
+
}
|
| 128 |
+
if (isZodIssueStringEndsWith(issue)) {
|
| 129 |
+
return parseStringEndsWith(issue);
|
| 130 |
+
}
|
| 131 |
+
if (isZodIssueStringIncludes(issue)) {
|
| 132 |
+
return parseStringIncludes(issue);
|
| 133 |
+
}
|
| 134 |
+
if (isZodIssueStringInvalidRegex(issue)) {
|
| 135 |
+
return parseStringInvalidRegex(issue, options);
|
| 136 |
+
}
|
| 137 |
+
if (isZodIssueStringInvalidJWT(issue)) {
|
| 138 |
+
return parseStringInvalidJWT(issue, options);
|
| 139 |
+
}
|
| 140 |
+
return {
|
| 141 |
+
type: issue.code,
|
| 142 |
+
path: issue.path,
|
| 143 |
+
message: `invalid ${issue.format}`
|
| 144 |
+
};
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
function isZodIssueStringStartsWith(issue) {
|
| 149 |
+
return issue.format === "starts_with";
|
| 150 |
+
}
|
| 151 |
+
function parseStringStartsWith(issue) {
|
| 152 |
+
return {
|
| 153 |
+
type: issue.code,
|
| 154 |
+
path: issue.path,
|
| 155 |
+
message: `value must start with "${issue.prefix}"`
|
| 156 |
+
};
|
| 157 |
+
}
|
| 158 |
+
function isZodIssueStringEndsWith(issue) {
|
| 159 |
+
return issue.format === "ends_with";
|
| 160 |
+
}
|
| 161 |
+
function parseStringEndsWith(issue) {
|
| 162 |
+
return {
|
| 163 |
+
type: issue.code,
|
| 164 |
+
path: issue.path,
|
| 165 |
+
message: `value must end with "${issue.suffix}"`
|
| 166 |
+
};
|
| 167 |
+
}
|
| 168 |
+
function isZodIssueStringIncludes(issue) {
|
| 169 |
+
return issue.format === "includes";
|
| 170 |
+
}
|
| 171 |
+
function parseStringIncludes(issue) {
|
| 172 |
+
return {
|
| 173 |
+
type: issue.code,
|
| 174 |
+
path: issue.path,
|
| 175 |
+
message: `value must include "${issue.includes}"`
|
| 176 |
+
};
|
| 177 |
+
}
|
| 178 |
+
function isZodIssueStringInvalidRegex(issue) {
|
| 179 |
+
return issue.format === "regex";
|
| 180 |
+
}
|
| 181 |
+
function parseStringInvalidRegex(issue, options = {
|
| 182 |
+
displayInvalidFormatDetails: false
|
| 183 |
+
}) {
|
| 184 |
+
let message = "value must match pattern";
|
| 185 |
+
if (options.displayInvalidFormatDetails) {
|
| 186 |
+
message += ` "${issue.pattern}"`;
|
| 187 |
+
}
|
| 188 |
+
return {
|
| 189 |
+
type: issue.code,
|
| 190 |
+
path: issue.path,
|
| 191 |
+
message
|
| 192 |
+
};
|
| 193 |
+
}
|
| 194 |
+
function isZodIssueStringInvalidJWT(issue) {
|
| 195 |
+
return issue.format === "jwt";
|
| 196 |
+
}
|
| 197 |
+
function parseStringInvalidJWT(issue, options = {
|
| 198 |
+
displayInvalidFormatDetails: false
|
| 199 |
+
}) {
|
| 200 |
+
return {
|
| 201 |
+
type: issue.code,
|
| 202 |
+
path: issue.path,
|
| 203 |
+
message: options.displayInvalidFormatDetails && issue.algorithm ? `invalid jwt/${issue.algorithm}` : `invalid jwt`
|
| 204 |
+
};
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
// lib/v4/errorMap/invalidType.ts
|
| 208 |
+
function parseInvalidTypeIssue(issue) {
|
| 209 |
+
let message = `expected ${issue.expected}`;
|
| 210 |
+
if ("input" in issue) {
|
| 211 |
+
message += `, received ${getTypeName(issue.input)}`;
|
| 212 |
+
}
|
| 213 |
+
return {
|
| 214 |
+
type: issue.code,
|
| 215 |
+
path: issue.path,
|
| 216 |
+
message
|
| 217 |
+
};
|
| 218 |
+
}
|
| 219 |
+
function getTypeName(value) {
|
| 220 |
+
if (typeof value === "object") {
|
| 221 |
+
if (value === null) {
|
| 222 |
+
return "null";
|
| 223 |
+
}
|
| 224 |
+
if (value === void 0) {
|
| 225 |
+
return "undefined";
|
| 226 |
+
}
|
| 227 |
+
if (Array.isArray(value)) {
|
| 228 |
+
return "array";
|
| 229 |
+
}
|
| 230 |
+
if (value instanceof Date) {
|
| 231 |
+
return "date";
|
| 232 |
+
}
|
| 233 |
+
if (value instanceof RegExp) {
|
| 234 |
+
return "regexp";
|
| 235 |
+
}
|
| 236 |
+
if (value instanceof Map) {
|
| 237 |
+
return "map";
|
| 238 |
+
}
|
| 239 |
+
if (value instanceof Set) {
|
| 240 |
+
return "set";
|
| 241 |
+
}
|
| 242 |
+
if (value instanceof Error) {
|
| 243 |
+
return "error";
|
| 244 |
+
}
|
| 245 |
+
if (value instanceof Function) {
|
| 246 |
+
return "function";
|
| 247 |
+
}
|
| 248 |
+
return "object";
|
| 249 |
+
}
|
| 250 |
+
return typeof value;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
// lib/v4/errorMap/invalidUnion.ts
|
| 254 |
+
function parseInvalidUnionIssue(issue) {
|
| 255 |
+
return {
|
| 256 |
+
type: issue.code,
|
| 257 |
+
path: issue.path,
|
| 258 |
+
message: issue.message ?? "Invalid input"
|
| 259 |
+
};
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
// lib/utils/stringify.ts
|
| 263 |
+
function stringifySymbol(symbol) {
|
| 264 |
+
return symbol.description ?? "";
|
| 265 |
+
}
|
| 266 |
+
function stringify(value, options = {}) {
|
| 267 |
+
switch (typeof value) {
|
| 268 |
+
case "symbol":
|
| 269 |
+
return stringifySymbol(value);
|
| 270 |
+
case "bigint":
|
| 271 |
+
case "number": {
|
| 272 |
+
switch (options.localization) {
|
| 273 |
+
case true:
|
| 274 |
+
return value.toLocaleString();
|
| 275 |
+
case false:
|
| 276 |
+
return value.toString();
|
| 277 |
+
default:
|
| 278 |
+
return value.toLocaleString(options.localization);
|
| 279 |
+
}
|
| 280 |
+
}
|
| 281 |
+
case "string": {
|
| 282 |
+
if (options.wrapStringValueInQuote) {
|
| 283 |
+
return `"${value}"`;
|
| 284 |
+
}
|
| 285 |
+
return value;
|
| 286 |
+
}
|
| 287 |
+
default: {
|
| 288 |
+
if (value instanceof Date) {
|
| 289 |
+
switch (options.localization) {
|
| 290 |
+
case true:
|
| 291 |
+
return value.toLocaleString();
|
| 292 |
+
case false:
|
| 293 |
+
return value.toISOString();
|
| 294 |
+
default:
|
| 295 |
+
return value.toLocaleString(options.localization);
|
| 296 |
+
}
|
| 297 |
+
}
|
| 298 |
+
return String(value);
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
// lib/utils/joinValues.ts
|
| 304 |
+
function joinValues(values, options) {
|
| 305 |
+
const valuesToDisplay = (options.maxValuesToDisplay ? values.slice(0, options.maxValuesToDisplay) : values).map((value) => {
|
| 306 |
+
return stringify(value, {
|
| 307 |
+
wrapStringValueInQuote: options.wrapStringValuesInQuote
|
| 308 |
+
});
|
| 309 |
+
});
|
| 310 |
+
if (valuesToDisplay.length < values.length) {
|
| 311 |
+
valuesToDisplay.push(
|
| 312 |
+
`${values.length - valuesToDisplay.length} more value(s)`
|
| 313 |
+
);
|
| 314 |
+
}
|
| 315 |
+
return valuesToDisplay.reduce((acc, value, index) => {
|
| 316 |
+
if (index > 0) {
|
| 317 |
+
if (index === valuesToDisplay.length - 1 && options.lastSeparator) {
|
| 318 |
+
acc += options.lastSeparator;
|
| 319 |
+
} else {
|
| 320 |
+
acc += options.separator;
|
| 321 |
+
}
|
| 322 |
+
}
|
| 323 |
+
acc += value;
|
| 324 |
+
return acc;
|
| 325 |
+
}, "");
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
// lib/v4/errorMap/invalidValue.ts
|
| 329 |
+
function parseInvalidValueIssue(issue, options) {
|
| 330 |
+
let message;
|
| 331 |
+
if (issue.values.length === 0) {
|
| 332 |
+
message = "invalid value";
|
| 333 |
+
} else if (issue.values.length === 1) {
|
| 334 |
+
const valueStr = stringify(issue.values[0], {
|
| 335 |
+
wrapStringValueInQuote: true
|
| 336 |
+
});
|
| 337 |
+
message = `expected value to be ${valueStr}`;
|
| 338 |
+
} else {
|
| 339 |
+
const valuesStr = joinValues(issue.values, {
|
| 340 |
+
separator: options.allowedValuesSeparator,
|
| 341 |
+
lastSeparator: options.allowedValuesLastSeparator,
|
| 342 |
+
wrapStringValuesInQuote: options.wrapAllowedValuesInQuote,
|
| 343 |
+
maxValuesToDisplay: options.maxAllowedValuesToDisplay
|
| 344 |
+
});
|
| 345 |
+
message = `expected value to be one of ${valuesStr}`;
|
| 346 |
+
}
|
| 347 |
+
return {
|
| 348 |
+
type: issue.code,
|
| 349 |
+
path: issue.path,
|
| 350 |
+
message
|
| 351 |
+
};
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
// lib/v4/errorMap/notMultipleOf.ts
|
| 355 |
+
function parseNotMultipleOfIssue(issue) {
|
| 356 |
+
return {
|
| 357 |
+
type: issue.code,
|
| 358 |
+
path: issue.path,
|
| 359 |
+
message: `expected multiple of ${issue.divisor}`
|
| 360 |
+
};
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
// lib/v4/errorMap/tooBig.ts
|
| 364 |
+
function parseTooBigIssue(issue, options) {
|
| 365 |
+
const maxValueStr = issue.origin === "date" ? stringify(new Date(issue.maximum), {
|
| 366 |
+
localization: options.dateLocalization
|
| 367 |
+
}) : stringify(issue.maximum, {
|
| 368 |
+
localization: options.numberLocalization
|
| 369 |
+
});
|
| 370 |
+
switch (issue.origin) {
|
| 371 |
+
case "number":
|
| 372 |
+
case "int":
|
| 373 |
+
case "bigint": {
|
| 374 |
+
return {
|
| 375 |
+
type: issue.code,
|
| 376 |
+
path: issue.path,
|
| 377 |
+
message: `number must be less than${issue.inclusive ? " or equal to" : ""} ${maxValueStr}`
|
| 378 |
+
};
|
| 379 |
+
}
|
| 380 |
+
case "string": {
|
| 381 |
+
return {
|
| 382 |
+
type: issue.code,
|
| 383 |
+
path: issue.path,
|
| 384 |
+
message: `string must contain at most ${maxValueStr} character(s)`
|
| 385 |
+
};
|
| 386 |
+
}
|
| 387 |
+
case "date": {
|
| 388 |
+
return {
|
| 389 |
+
type: issue.code,
|
| 390 |
+
path: issue.path,
|
| 391 |
+
message: `date must be ${issue.inclusive ? "prior or equal to" : "prior to"} "${maxValueStr}"`
|
| 392 |
+
};
|
| 393 |
+
}
|
| 394 |
+
case "array": {
|
| 395 |
+
return {
|
| 396 |
+
type: issue.code,
|
| 397 |
+
path: issue.path,
|
| 398 |
+
message: `array must contain at most ${maxValueStr} item(s)`
|
| 399 |
+
};
|
| 400 |
+
}
|
| 401 |
+
case "set": {
|
| 402 |
+
return {
|
| 403 |
+
type: issue.code,
|
| 404 |
+
path: issue.path,
|
| 405 |
+
message: `set must contain at most ${maxValueStr} item(s)`
|
| 406 |
+
};
|
| 407 |
+
}
|
| 408 |
+
case "file": {
|
| 409 |
+
return {
|
| 410 |
+
type: issue.code,
|
| 411 |
+
path: issue.path,
|
| 412 |
+
message: `file must not exceed ${maxValueStr} byte(s) in size`
|
| 413 |
+
};
|
| 414 |
+
}
|
| 415 |
+
default:
|
| 416 |
+
return {
|
| 417 |
+
type: issue.code,
|
| 418 |
+
path: issue.path,
|
| 419 |
+
message: `value must be less than${issue.inclusive ? " or equal to" : ""} ${maxValueStr}`
|
| 420 |
+
};
|
| 421 |
+
}
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
// lib/v4/errorMap/tooSmall.ts
|
| 425 |
+
function parseTooSmallIssue(issue, options) {
|
| 426 |
+
const minValueStr = issue.origin === "date" ? stringify(new Date(issue.minimum), {
|
| 427 |
+
localization: options.dateLocalization
|
| 428 |
+
}) : stringify(issue.minimum, {
|
| 429 |
+
localization: options.numberLocalization
|
| 430 |
+
});
|
| 431 |
+
switch (issue.origin) {
|
| 432 |
+
case "number":
|
| 433 |
+
case "int":
|
| 434 |
+
case "bigint": {
|
| 435 |
+
return {
|
| 436 |
+
type: issue.code,
|
| 437 |
+
path: issue.path,
|
| 438 |
+
message: `number must be greater than${issue.inclusive ? " or equal to" : ""} ${minValueStr}`
|
| 439 |
+
};
|
| 440 |
+
}
|
| 441 |
+
case "date": {
|
| 442 |
+
return {
|
| 443 |
+
type: issue.code,
|
| 444 |
+
path: issue.path,
|
| 445 |
+
message: `date must be ${issue.inclusive ? "later or equal to" : "later to"} "${minValueStr}"`
|
| 446 |
+
};
|
| 447 |
+
}
|
| 448 |
+
case "string": {
|
| 449 |
+
return {
|
| 450 |
+
type: issue.code,
|
| 451 |
+
path: issue.path,
|
| 452 |
+
message: `string must contain at least ${minValueStr} character(s)`
|
| 453 |
+
};
|
| 454 |
+
}
|
| 455 |
+
case "array": {
|
| 456 |
+
return {
|
| 457 |
+
type: issue.code,
|
| 458 |
+
path: issue.path,
|
| 459 |
+
message: `array must contain at least ${minValueStr} item(s)`
|
| 460 |
+
};
|
| 461 |
+
}
|
| 462 |
+
case "set": {
|
| 463 |
+
return {
|
| 464 |
+
type: issue.code,
|
| 465 |
+
path: issue.path,
|
| 466 |
+
message: `set must contain at least ${minValueStr} item(s)`
|
| 467 |
+
};
|
| 468 |
+
}
|
| 469 |
+
case "file": {
|
| 470 |
+
return {
|
| 471 |
+
type: issue.code,
|
| 472 |
+
path: issue.path,
|
| 473 |
+
message: `file must be at least ${minValueStr} byte(s) in size`
|
| 474 |
+
};
|
| 475 |
+
}
|
| 476 |
+
default:
|
| 477 |
+
return {
|
| 478 |
+
type: issue.code,
|
| 479 |
+
path: issue.path,
|
| 480 |
+
message: `value must be greater than${issue.inclusive ? " or equal to" : ""} ${minValueStr}`
|
| 481 |
+
};
|
| 482 |
+
}
|
| 483 |
+
}
|
| 484 |
+
|
| 485 |
+
// lib/v4/errorMap/unrecognizedKeys.ts
|
| 486 |
+
function parseUnrecognizedKeysIssue(issue, options) {
|
| 487 |
+
const keysStr = joinValues(issue.keys, {
|
| 488 |
+
separator: options.unrecognizedKeysSeparator,
|
| 489 |
+
lastSeparator: options.unrecognizedKeysLastSeparator,
|
| 490 |
+
wrapStringValuesInQuote: options.wrapUnrecognizedKeysInQuote,
|
| 491 |
+
maxValuesToDisplay: options.maxUnrecognizedKeysToDisplay
|
| 492 |
+
});
|
| 493 |
+
return {
|
| 494 |
+
type: issue.code,
|
| 495 |
+
path: issue.path,
|
| 496 |
+
message: `unrecognized key(s) ${keysStr} in object`
|
| 497 |
+
};
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
// lib/v4/errorMap/errorMap.ts
|
| 501 |
+
var issueParsers = {
|
| 502 |
+
invalid_type: parseInvalidTypeIssue,
|
| 503 |
+
too_big: parseTooBigIssue,
|
| 504 |
+
too_small: parseTooSmallIssue,
|
| 505 |
+
invalid_format: parseInvalidStringFormatIssue,
|
| 506 |
+
invalid_value: parseInvalidValueIssue,
|
| 507 |
+
invalid_element: parseInvalidElementIssue,
|
| 508 |
+
not_multiple_of: parseNotMultipleOfIssue,
|
| 509 |
+
unrecognized_keys: parseUnrecognizedKeysIssue,
|
| 510 |
+
invalid_key: parseInvalidKeyIssue,
|
| 511 |
+
custom: parseCustomIssue,
|
| 512 |
+
invalid_union: parseInvalidUnionIssue
|
| 513 |
+
};
|
| 514 |
+
var defaultErrorMapOptions = {
|
| 515 |
+
displayInvalidFormatDetails: false,
|
| 516 |
+
allowedValuesSeparator: ", ",
|
| 517 |
+
allowedValuesLastSeparator: " or ",
|
| 518 |
+
wrapAllowedValuesInQuote: true,
|
| 519 |
+
maxAllowedValuesToDisplay: 10,
|
| 520 |
+
unrecognizedKeysSeparator: ", ",
|
| 521 |
+
unrecognizedKeysLastSeparator: " and ",
|
| 522 |
+
wrapUnrecognizedKeysInQuote: true,
|
| 523 |
+
maxUnrecognizedKeysToDisplay: 5,
|
| 524 |
+
dateLocalization: true,
|
| 525 |
+
numberLocalization: true
|
| 526 |
+
};
|
| 527 |
+
function createErrorMap(partialOptions = {}) {
|
| 528 |
+
const options = {
|
| 529 |
+
...defaultErrorMapOptions,
|
| 530 |
+
...partialOptions
|
| 531 |
+
};
|
| 532 |
+
const errorMap = (issue) => {
|
| 533 |
+
if (issue.code === void 0) {
|
| 534 |
+
return "Not supported issue type";
|
| 535 |
+
}
|
| 536 |
+
const parseFunc = issueParsers[issue.code];
|
| 537 |
+
const ast = parseFunc(issue, options);
|
| 538 |
+
return ast.message;
|
| 539 |
+
};
|
| 540 |
+
return errorMap;
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
// lib/utils/NonEmptyArray.ts
|
| 544 |
+
function isNonEmptyArray(value) {
|
| 545 |
+
return value.length !== 0;
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
// lib/utils/joinPath.ts
|
| 549 |
+
var identifierRegex = /[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u;
|
| 550 |
+
function joinPath(path) {
|
| 551 |
+
if (path.length === 1) {
|
| 552 |
+
let propertyKey = path[0];
|
| 553 |
+
if (typeof propertyKey === "symbol") {
|
| 554 |
+
propertyKey = stringifySymbol(propertyKey);
|
| 555 |
+
}
|
| 556 |
+
return propertyKey.toString() || '""';
|
| 557 |
+
}
|
| 558 |
+
return path.reduce((acc, propertyKey) => {
|
| 559 |
+
if (typeof propertyKey === "number") {
|
| 560 |
+
return acc + "[" + propertyKey.toString() + "]";
|
| 561 |
+
}
|
| 562 |
+
if (typeof propertyKey === "symbol") {
|
| 563 |
+
propertyKey = stringifySymbol(propertyKey);
|
| 564 |
+
}
|
| 565 |
+
if (propertyKey.includes('"')) {
|
| 566 |
+
return acc + '["' + escapeQuotes(propertyKey) + '"]';
|
| 567 |
+
}
|
| 568 |
+
if (!identifierRegex.test(propertyKey)) {
|
| 569 |
+
return acc + '["' + propertyKey + '"]';
|
| 570 |
+
}
|
| 571 |
+
const separator = acc.length === 0 ? "" : ".";
|
| 572 |
+
return acc + separator + propertyKey;
|
| 573 |
+
}, "");
|
| 574 |
+
}
|
| 575 |
+
function escapeQuotes(str) {
|
| 576 |
+
return str.replace(/"/g, '\\"');
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
// lib/utils/titleCase.ts
|
| 580 |
+
function titleCase(value) {
|
| 581 |
+
if (value.length === 0) {
|
| 582 |
+
return value;
|
| 583 |
+
}
|
| 584 |
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
// lib/v4/MessageBuilder.ts
|
| 588 |
+
var defaultMessageBuilderOptions = {
|
| 589 |
+
prefix: "Validation error",
|
| 590 |
+
prefixSeparator: ": ",
|
| 591 |
+
maxIssuesInMessage: 99,
|
| 592 |
+
// I've got 99 problems but the b$tch ain't one
|
| 593 |
+
unionSeparator: " or ",
|
| 594 |
+
issueSeparator: "; ",
|
| 595 |
+
includePath: true,
|
| 596 |
+
forceTitleCase: true
|
| 597 |
+
};
|
| 598 |
+
function createMessageBuilder(partialOptions = {}) {
|
| 599 |
+
const options = {
|
| 600 |
+
...defaultMessageBuilderOptions,
|
| 601 |
+
...partialOptions
|
| 602 |
+
};
|
| 603 |
+
return function messageBuilder(issues) {
|
| 604 |
+
const message = issues.slice(0, options.maxIssuesInMessage).map((issue) => mapIssue(issue, options)).join(options.issueSeparator);
|
| 605 |
+
return conditionallyPrefixMessage(message, options);
|
| 606 |
+
};
|
| 607 |
+
}
|
| 608 |
+
function mapIssue(issue, options) {
|
| 609 |
+
if (issue.code === "invalid_union" && isNonEmptyArray(issue.errors)) {
|
| 610 |
+
const individualMessages = issue.errors.map(
|
| 611 |
+
(issues) => issues.map(
|
| 612 |
+
(subIssue) => mapIssue(
|
| 613 |
+
{
|
| 614 |
+
...subIssue,
|
| 615 |
+
path: issue.path.concat(subIssue.path)
|
| 616 |
+
},
|
| 617 |
+
options
|
| 618 |
+
)
|
| 619 |
+
).join(options.issueSeparator)
|
| 620 |
+
);
|
| 621 |
+
return Array.from(new Set(individualMessages)).join(options.unionSeparator);
|
| 622 |
+
}
|
| 623 |
+
const buf = [];
|
| 624 |
+
if (options.forceTitleCase) {
|
| 625 |
+
buf.push(titleCase(issue.message));
|
| 626 |
+
} else {
|
| 627 |
+
buf.push(issue.message);
|
| 628 |
+
}
|
| 629 |
+
pathCondition: if (options.includePath && issue.path !== void 0 && isNonEmptyArray(issue.path)) {
|
| 630 |
+
if (issue.path.length === 1) {
|
| 631 |
+
const identifier = issue.path[0];
|
| 632 |
+
if (typeof identifier === "number") {
|
| 633 |
+
buf.push(` at index ${identifier}`);
|
| 634 |
+
break pathCondition;
|
| 635 |
+
}
|
| 636 |
+
}
|
| 637 |
+
buf.push(` at "${joinPath(issue.path)}"`);
|
| 638 |
+
}
|
| 639 |
+
return buf.join("");
|
| 640 |
+
}
|
| 641 |
+
function conditionallyPrefixMessage(message, options) {
|
| 642 |
+
if (options.prefix != null) {
|
| 643 |
+
if (message.length > 0) {
|
| 644 |
+
return [options.prefix, message].join(options.prefixSeparator);
|
| 645 |
+
}
|
| 646 |
+
return options.prefix;
|
| 647 |
+
}
|
| 648 |
+
if (message.length > 0) {
|
| 649 |
+
return message;
|
| 650 |
+
}
|
| 651 |
+
return defaultMessageBuilderOptions.prefix;
|
| 652 |
+
}
|
| 653 |
+
|
| 654 |
+
// lib/v4/fromZodError.ts
|
| 655 |
+
function fromZodError(zodError, options = {}) {
|
| 656 |
+
if (!isZodErrorLike(zodError)) {
|
| 657 |
+
throw new TypeError(
|
| 658 |
+
`Invalid zodError param; expected instance of ZodError. Did you mean to use the "${fromError.name}" method instead?`
|
| 659 |
+
);
|
| 660 |
+
}
|
| 661 |
+
return fromZodErrorWithoutRuntimeCheck(zodError, options);
|
| 662 |
+
}
|
| 663 |
+
function fromZodErrorWithoutRuntimeCheck(zodError, options = {}) {
|
| 664 |
+
const zodIssues = zodError.issues;
|
| 665 |
+
let message;
|
| 666 |
+
if (isNonEmptyArray(zodIssues)) {
|
| 667 |
+
const messageBuilder = createMessageBuilderFromOptions(options);
|
| 668 |
+
message = messageBuilder(zodIssues);
|
| 669 |
+
} else {
|
| 670 |
+
message = zodError.message;
|
| 671 |
+
}
|
| 672 |
+
return new ValidationError(message, { cause: zodError });
|
| 673 |
+
}
|
| 674 |
+
function createMessageBuilderFromOptions(options) {
|
| 675 |
+
if ("messageBuilder" in options) {
|
| 676 |
+
return options.messageBuilder;
|
| 677 |
+
}
|
| 678 |
+
return createMessageBuilder(options);
|
| 679 |
+
}
|
| 680 |
+
|
| 681 |
+
// lib/v4/toValidationError.ts
|
| 682 |
+
var toValidationError = (options = {}) => (err) => {
|
| 683 |
+
if (isZodErrorLike(err)) {
|
| 684 |
+
return fromZodErrorWithoutRuntimeCheck(err, options);
|
| 685 |
+
}
|
| 686 |
+
if (err instanceof Error) {
|
| 687 |
+
return new ValidationError(err.message, { cause: err });
|
| 688 |
+
}
|
| 689 |
+
return new ValidationError("Unknown error");
|
| 690 |
+
};
|
| 691 |
+
|
| 692 |
+
// lib/v4/fromError.ts
|
| 693 |
+
function fromError(err, options = {}) {
|
| 694 |
+
return toValidationError(options)(err);
|
| 695 |
+
}
|
| 696 |
+
|
| 697 |
+
// lib/v4/fromZodIssue.ts
|
| 698 |
+
var zod = __toESM(require("zod/v4/core"));
|
| 699 |
+
function fromZodIssue(issue, options = {}) {
|
| 700 |
+
const messageBuilder = createMessageBuilderFromOptions2(options);
|
| 701 |
+
const message = messageBuilder([issue]);
|
| 702 |
+
return new ValidationError(message, {
|
| 703 |
+
cause: new zod.$ZodRealError([issue])
|
| 704 |
+
});
|
| 705 |
+
}
|
| 706 |
+
function createMessageBuilderFromOptions2(options) {
|
| 707 |
+
if ("messageBuilder" in options) {
|
| 708 |
+
return options.messageBuilder;
|
| 709 |
+
}
|
| 710 |
+
return createMessageBuilder(options);
|
| 711 |
+
}
|
| 712 |
+
// Annotate the CommonJS export names for ESM import in node:
|
| 713 |
+
0 && (module.exports = {
|
| 714 |
+
ValidationError,
|
| 715 |
+
createErrorMap,
|
| 716 |
+
createMessageBuilder,
|
| 717 |
+
fromError,
|
| 718 |
+
fromZodError,
|
| 719 |
+
fromZodIssue,
|
| 720 |
+
isValidationError,
|
| 721 |
+
isValidationErrorLike,
|
| 722 |
+
isZodErrorLike,
|
| 723 |
+
toValidationError
|
| 724 |
+
});
|
| 725 |
+
//# sourceMappingURL=index.js.map
|
node_modules/zod-validation-error/v4/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"sources":["../lib/v4/index.ts","../lib/v4/isZodErrorLike.ts","../lib/v4/ValidationError.ts","../lib/v4/isValidationError.ts","../lib/v4/isValidationErrorLike.ts","../lib/v4/errorMap/custom.ts","../lib/v4/errorMap/invalidElement.ts","../lib/v4/errorMap/invalidKey.ts","../lib/v4/errorMap/invalidStringFormat.ts","../lib/v4/errorMap/invalidType.ts","../lib/v4/errorMap/invalidUnion.ts","../lib/utils/stringify.ts","../lib/utils/joinValues.ts","../lib/v4/errorMap/invalidValue.ts","../lib/v4/errorMap/notMultipleOf.ts","../lib/v4/errorMap/tooBig.ts","../lib/v4/errorMap/tooSmall.ts","../lib/v4/errorMap/unrecognizedKeys.ts","../lib/v4/errorMap/errorMap.ts","../lib/utils/NonEmptyArray.ts","../lib/utils/joinPath.ts","../lib/utils/titleCase.ts","../lib/v4/MessageBuilder.ts","../lib/v4/fromZodError.ts","../lib/v4/toValidationError.ts","../lib/v4/fromError.ts","../lib/v4/fromZodIssue.ts"],"sourcesContent":["export { ValidationError, type ErrorOptions } from './ValidationError.ts';\nexport { isValidationError } from './isValidationError.ts';\nexport { isValidationErrorLike } from './isValidationErrorLike.ts';\nexport { isZodErrorLike } from './isZodErrorLike.ts';\nexport { createErrorMap, type ErrorMapOptions } from './errorMap/index.ts';\nexport { fromError } from './fromError.ts';\nexport { fromZodIssue, type FromZodIssueOptions } from './fromZodIssue.ts';\nexport {\n fromZodError,\n type FromZodErrorOptions,\n type ZodError,\n} from './fromZodError.ts';\nexport { toValidationError } from './toValidationError.ts';\nexport {\n type MessageBuilder,\n type ZodIssue,\n createMessageBuilder,\n type MessageBuilderOptions,\n} from './MessageBuilder.ts';\nexport { type NonEmptyArray } from '../utils/NonEmptyArray.ts';\n","import type * as zod from 'zod/v4/core';\n\nexport function isZodErrorLike(err: unknown): err is zod.$ZodError {\n return (\n err instanceof Object &&\n 'name' in err &&\n (err.name === 'ZodError' || err.name === '$ZodError') &&\n 'issues' in err &&\n Array.isArray(err.issues)\n );\n}\n","import { isZodErrorLike } from './isZodErrorLike.ts';\nimport type * as zod from 'zod/v4/core';\n\nexport const ZOD_VALIDATION_ERROR_NAME = 'ZodValidationError';\n\n// make zod-validation-error compatible with\n// earlier to es2022 typescript configurations\n// @see https://github.com/causaly/zod-validation-error/issues/226\nexport interface ErrorOptions {\n cause?: unknown;\n}\n\nexport class ValidationError extends Error {\n name: typeof ZOD_VALIDATION_ERROR_NAME;\n details: Array<zod.$ZodIssue>;\n\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options);\n this.name = ZOD_VALIDATION_ERROR_NAME;\n this.details = getIssuesFromErrorOptions(options);\n }\n\n toString(): string {\n return this.message;\n }\n}\n\nfunction getIssuesFromErrorOptions(\n options?: ErrorOptions\n): Array<zod.$ZodIssue> {\n if (options) {\n const cause = options.cause;\n if (isZodErrorLike(cause)) {\n return cause.issues;\n }\n }\n\n return [];\n}\n","import { ValidationError } from './ValidationError.ts';\n\nexport function isValidationError(err: unknown): err is ValidationError {\n return err instanceof ValidationError;\n}\n","import {\n ZOD_VALIDATION_ERROR_NAME,\n type ValidationError,\n} from './ValidationError.ts';\n\nexport function isValidationErrorLike(err: unknown): err is ValidationError {\n return err instanceof Error && err.name === ZOD_VALIDATION_ERROR_NAME;\n}\n","import type * as zod from 'zod/v4/core';\nimport type { AbstractSyntaxTree } from './types.ts';\n\nexport function parseCustomIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueCustom>\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message: issue.message ?? 'Invalid input',\n };\n}\n","import type * as zod from 'zod/v4/core';\nimport type { AbstractSyntaxTree } from './types.ts';\n\nexport function parseInvalidElementIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidElement>\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message: `unexpected element in ${issue.origin}`,\n };\n}\n","import type * as zod from 'zod/v4/core';\nimport type { AbstractSyntaxTree } from './types.ts';\n\nexport function parseInvalidKeyIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidKey>\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message: `unexpected key in ${issue.origin}`,\n };\n}\n","import type { AbstractSyntaxTree, ErrorMapOptions } from './types.ts';\nimport type * as zod from 'zod/v4/core';\n\nexport function parseInvalidStringFormatIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidStringFormat>,\n options: Pick<ErrorMapOptions, 'displayInvalidFormatDetails'> = {\n displayInvalidFormatDetails: false,\n }\n): AbstractSyntaxTree {\n switch (issue.format) {\n case 'lowercase':\n case 'uppercase':\n return {\n type: issue.code,\n path: issue.path,\n message: `value must be in ${issue.format} format`,\n };\n default: {\n if (isZodIssueStringStartsWith(issue)) {\n return parseStringStartsWith(issue);\n }\n if (isZodIssueStringEndsWith(issue)) {\n return parseStringEndsWith(issue);\n }\n if (isZodIssueStringIncludes(issue)) {\n return parseStringIncludes(issue);\n }\n if (isZodIssueStringInvalidRegex(issue)) {\n return parseStringInvalidRegex(issue, options);\n }\n if (isZodIssueStringInvalidJWT(issue)) {\n return parseStringInvalidJWT(issue, options);\n }\n\n return {\n type: issue.code,\n path: issue.path,\n message: `invalid ${issue.format}`,\n };\n }\n }\n}\nfunction isZodIssueStringStartsWith(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidStringFormat>\n): issue is zod.$ZodRawIssue<zod.$ZodIssueStringStartsWith> {\n return issue.format === 'starts_with';\n}\n\nfunction parseStringStartsWith(\n issue: zod.$ZodRawIssue<zod.$ZodIssueStringStartsWith>\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message: `value must start with \"${issue.prefix}\"`,\n };\n}\n\nfunction isZodIssueStringEndsWith(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidStringFormat>\n): issue is zod.$ZodRawIssue<zod.$ZodIssueStringEndsWith> {\n return issue.format === 'ends_with';\n}\nfunction parseStringEndsWith(\n issue: zod.$ZodRawIssue<zod.$ZodIssueStringEndsWith>\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message: `value must end with \"${issue.suffix}\"`,\n };\n}\n\nfunction isZodIssueStringIncludes(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidStringFormat>\n): issue is zod.$ZodRawIssue<zod.$ZodIssueStringIncludes> {\n return issue.format === 'includes';\n}\nfunction parseStringIncludes(\n issue: zod.$ZodRawIssue<zod.$ZodIssueStringIncludes>\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message: `value must include \"${issue.includes}\"`,\n };\n}\n\nfunction isZodIssueStringInvalidRegex(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidStringFormat>\n): issue is zod.$ZodRawIssue<zod.$ZodIssueStringInvalidRegex> {\n return issue.format === 'regex';\n}\nfunction parseStringInvalidRegex(\n issue: zod.$ZodRawIssue<zod.$ZodIssueStringInvalidRegex>,\n options: Pick<ErrorMapOptions, 'displayInvalidFormatDetails'> = {\n displayInvalidFormatDetails: false,\n }\n): AbstractSyntaxTree {\n let message = 'value must match pattern';\n if (options.displayInvalidFormatDetails) {\n message += ` \"${issue.pattern}\"`;\n }\n\n return {\n type: issue.code,\n path: issue.path,\n message,\n };\n}\n\nfunction isZodIssueStringInvalidJWT(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidStringFormat>\n): issue is zod.$ZodRawIssue<zod.$ZodIssueStringInvalidJWT> {\n return issue.format === 'jwt';\n}\nfunction parseStringInvalidJWT(\n issue: zod.$ZodRawIssue<zod.$ZodIssueStringInvalidJWT>,\n options: Pick<ErrorMapOptions, 'displayInvalidFormatDetails'> = {\n displayInvalidFormatDetails: false,\n }\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message:\n options.displayInvalidFormatDetails && issue.algorithm\n ? `invalid jwt/${issue.algorithm}`\n : `invalid jwt`,\n };\n}\n","import type { AbstractSyntaxTree } from './types.ts';\nimport type * as zod from 'zod/v4/core';\n\nexport function parseInvalidTypeIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidType>\n): AbstractSyntaxTree {\n let message = `expected ${issue.expected}`;\n\n // note: it's possible that issue.input is not defined\n if ('input' in issue) {\n message += `, received ${getTypeName(issue.input)}`;\n }\n\n return {\n type: issue.code,\n path: issue.path,\n message,\n };\n}\n\nexport function getTypeName(value: unknown): string {\n if (typeof value === 'object') {\n if (value === null) {\n return 'null';\n }\n if (value === undefined) {\n return 'undefined';\n }\n if (Array.isArray(value)) {\n return 'array';\n }\n if (value instanceof Date) {\n return 'date';\n }\n if (value instanceof RegExp) {\n return 'regexp';\n }\n if (value instanceof Map) {\n return 'map';\n }\n if (value instanceof Set) {\n return 'set';\n }\n if (value instanceof Error) {\n return 'error';\n }\n if (value instanceof Function) {\n return 'function';\n }\n return 'object';\n }\n\n return typeof value;\n}\n","import type * as zod from 'zod/v4/core';\nimport type { AbstractSyntaxTree } from './types.ts';\n\nexport function parseInvalidUnionIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidUnion>\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message: issue.message ?? 'Invalid input',\n };\n}\n","import type { util } from 'zod/v4/core';\n\nexport function stringifySymbol(symbol: symbol): string {\n return symbol.description ?? '';\n}\n\nexport type StringifyValueOptions = {\n wrapStringValueInQuote?: boolean;\n localization?: boolean | Intl.LocalesArgument;\n};\n\nexport function stringify(\n value: util.Primitive | Date,\n options: StringifyValueOptions = {}\n): string {\n switch (typeof value) {\n case 'symbol':\n return stringifySymbol(value);\n case 'bigint':\n case 'number': {\n switch (options.localization) {\n case true:\n return value.toLocaleString();\n case false:\n return value.toString();\n default:\n return value.toLocaleString(options.localization);\n }\n }\n case 'string': {\n if (options.wrapStringValueInQuote) {\n return `\"${value}\"`;\n }\n return value;\n }\n default: {\n if (value instanceof Date) {\n switch (options.localization) {\n case true:\n return value.toLocaleString();\n case false:\n return value.toISOString();\n default:\n return value.toLocaleString(options.localization);\n }\n }\n return String(value);\n }\n }\n}\n","import { stringify } from './stringify.ts';\nimport type { util } from 'zod/v4/core';\n\nexport type JoinValuesOptions = {\n separator: string;\n lastSeparator?: string;\n wrapStringValuesInQuote?: boolean;\n maxValuesToDisplay?: number;\n};\n\nexport function joinValues(\n values: Array<util.Primitive>,\n options: JoinValuesOptions\n): string {\n const valuesToDisplay = (\n options.maxValuesToDisplay\n ? values.slice(0, options.maxValuesToDisplay)\n : values\n ).map((value) => {\n return stringify(value, {\n wrapStringValueInQuote: options.wrapStringValuesInQuote,\n });\n });\n\n // add remaining values count (if any)\n // this is to avoid displaying too many values in the error message\n // and to keep the message concise\n // e.g. `\"foo\", \"bar\", \"baz\" or 3 more value(s)`\n if (valuesToDisplay.length < values.length) {\n valuesToDisplay.push(\n `${values.length - valuesToDisplay.length} more value(s)`\n );\n }\n\n return valuesToDisplay.reduce<string>((acc, value, index) => {\n if (index > 0) {\n if (index === valuesToDisplay.length - 1 && options.lastSeparator) {\n acc += options.lastSeparator;\n } else {\n acc += options.separator;\n }\n }\n\n acc += value;\n\n return acc;\n }, '');\n}\n","import { joinValues } from '../../utils/joinValues.ts';\nimport { stringify } from '../../utils/stringify.ts';\nimport type { AbstractSyntaxTree, ErrorMapOptions } from './types.ts';\nimport type * as zod from 'zod/v4/core';\n\nexport function parseInvalidValueIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidValue>,\n options: Pick<\n ErrorMapOptions,\n | 'allowedValuesSeparator'\n | 'maxAllowedValuesToDisplay'\n | 'wrapAllowedValuesInQuote'\n | 'allowedValuesLastSeparator'\n >\n): AbstractSyntaxTree {\n let message: string;\n\n if (issue.values.length === 0) {\n message = 'invalid value';\n } else if (issue.values.length === 1) {\n const valueStr = stringify(issue.values[0], {\n wrapStringValueInQuote: true,\n });\n message = `expected value to be ${valueStr}`;\n } else {\n const valuesStr = joinValues(issue.values, {\n separator: options.allowedValuesSeparator,\n lastSeparator: options.allowedValuesLastSeparator,\n wrapStringValuesInQuote: options.wrapAllowedValuesInQuote,\n maxValuesToDisplay: options.maxAllowedValuesToDisplay,\n });\n message = `expected value to be one of ${valuesStr}`;\n }\n\n return {\n type: issue.code,\n path: issue.path,\n message,\n };\n}\n","import type * as zod from 'zod/v4/core';\nimport type { AbstractSyntaxTree } from './types.ts';\n\nexport function parseNotMultipleOfIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueNotMultipleOf>\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message: `expected multiple of ${issue.divisor}`,\n };\n}\n","import { stringify } from '../../utils/stringify.ts';\nimport type { AbstractSyntaxTree, ErrorMapOptions } from './types.ts';\nimport type * as zod from 'zod/v4/core';\n\nexport function parseTooBigIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueTooBig>,\n options: Pick<ErrorMapOptions, 'dateLocalization' | 'numberLocalization'>\n): AbstractSyntaxTree {\n const maxValueStr =\n issue.origin === 'date'\n ? stringify(new Date(issue.maximum as number), {\n localization: options.dateLocalization,\n })\n : stringify(issue.maximum, {\n localization: options.numberLocalization,\n });\n\n switch (issue.origin) {\n case 'number':\n case 'int':\n case 'bigint': {\n return {\n type: issue.code,\n path: issue.path,\n message: `number must be less than${\n issue.inclusive ? ' or equal to' : ''\n } ${maxValueStr}`,\n };\n }\n case 'string': {\n return {\n type: issue.code,\n path: issue.path,\n message: `string must contain at most ${maxValueStr} character(s)`,\n };\n }\n case 'date': {\n return {\n type: issue.code,\n path: issue.path,\n message: `date must be ${\n issue.inclusive ? 'prior or equal to' : 'prior to'\n } \"${maxValueStr}\"`,\n };\n }\n case 'array': {\n return {\n type: issue.code,\n path: issue.path,\n message: `array must contain at most ${maxValueStr} item(s)`,\n };\n }\n case 'set': {\n return {\n type: issue.code,\n path: issue.path,\n message: `set must contain at most ${maxValueStr} item(s)`,\n };\n }\n case 'file': {\n return {\n type: issue.code,\n path: issue.path,\n message: `file must not exceed ${maxValueStr} byte(s) in size`,\n };\n }\n default:\n return {\n type: issue.code,\n path: issue.path,\n message: `value must be less than${\n issue.inclusive ? ' or equal to' : ''\n } ${maxValueStr}`,\n };\n }\n}\n","import { stringify } from '../../utils/stringify.ts';\nimport type * as zod from 'zod/v4/core';\nimport type { AbstractSyntaxTree, ErrorMapOptions } from './types.ts';\n\nexport function parseTooSmallIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueTooSmall>,\n options: Pick<ErrorMapOptions, 'dateLocalization' | 'numberLocalization'>\n): AbstractSyntaxTree {\n const minValueStr =\n issue.origin === 'date'\n ? stringify(new Date(issue.minimum as number), {\n localization: options.dateLocalization,\n })\n : stringify(issue.minimum, {\n localization: options.numberLocalization,\n });\n\n switch (issue.origin) {\n case 'number':\n case 'int':\n case 'bigint': {\n return {\n type: issue.code,\n path: issue.path,\n message: `number must be greater than${\n issue.inclusive ? ' or equal to' : ''\n } ${minValueStr}`,\n };\n }\n case 'date': {\n return {\n type: issue.code,\n path: issue.path,\n message: `date must be ${\n issue.inclusive ? 'later or equal to' : 'later to'\n } \"${minValueStr}\"`,\n };\n }\n case 'string': {\n return {\n type: issue.code,\n path: issue.path,\n message: `string must contain at least ${minValueStr} character(s)`,\n };\n }\n case 'array': {\n return {\n type: issue.code,\n path: issue.path,\n message: `array must contain at least ${minValueStr} item(s)`,\n };\n }\n case 'set': {\n return {\n type: issue.code,\n path: issue.path,\n message: `set must contain at least ${minValueStr} item(s)`,\n };\n }\n case 'file': {\n return {\n type: issue.code,\n path: issue.path,\n message: `file must be at least ${minValueStr} byte(s) in size`,\n };\n }\n default:\n return {\n type: issue.code,\n path: issue.path,\n message: `value must be greater than${\n issue.inclusive ? ' or equal to' : ''\n } ${minValueStr}`,\n };\n }\n}\n","import { joinValues } from '../../utils/joinValues.ts';\nimport type * as zod from 'zod/v4/core';\nimport type { AbstractSyntaxTree, ErrorMapOptions } from './types.ts';\n\nexport function parseUnrecognizedKeysIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueUnrecognizedKeys>,\n options: Pick<\n ErrorMapOptions,\n | 'unrecognizedKeysSeparator'\n | 'unrecognizedKeysLastSeparator'\n | 'wrapUnrecognizedKeysInQuote'\n | 'maxUnrecognizedKeysToDisplay'\n >\n): AbstractSyntaxTree {\n const keysStr = joinValues(issue.keys, {\n separator: options.unrecognizedKeysSeparator,\n lastSeparator: options.unrecognizedKeysLastSeparator,\n wrapStringValuesInQuote: options.wrapUnrecognizedKeysInQuote,\n maxValuesToDisplay: options.maxUnrecognizedKeysToDisplay,\n });\n\n return {\n type: issue.code,\n path: issue.path,\n message: `unrecognized key(s) ${keysStr} in object`,\n };\n}\n","import { parseCustomIssue } from './custom.ts';\nimport { parseInvalidElementIssue } from './invalidElement.ts';\nimport { parseInvalidKeyIssue } from './invalidKey.ts';\nimport { parseInvalidStringFormatIssue } from './invalidStringFormat.ts';\nimport { parseInvalidTypeIssue } from './invalidType.ts';\nimport { parseInvalidUnionIssue } from './invalidUnion.ts';\nimport { parseInvalidValueIssue } from './invalidValue.ts';\nimport { parseNotMultipleOfIssue } from './notMultipleOf.ts';\nimport { parseTooBigIssue } from './tooBig.ts';\nimport { parseTooSmallIssue } from './tooSmall.ts';\nimport { parseUnrecognizedKeysIssue } from './unrecognizedKeys.ts';\nimport type {\n AbstractSyntaxTree,\n ErrorMapOptions,\n IssueType,\n} from './types.ts';\nimport type * as zod from 'zod/v4/core';\n\ntype IssueParsers = {\n [IssueCode in IssueType]: (\n issue: zod.$ZodRawIssue<Extract<zod.$ZodIssue, { code: IssueCode }>>,\n options: ErrorMapOptions\n ) => AbstractSyntaxTree;\n};\n\nconst issueParsers: IssueParsers = {\n invalid_type: parseInvalidTypeIssue,\n too_big: parseTooBigIssue,\n too_small: parseTooSmallIssue,\n invalid_format: parseInvalidStringFormatIssue,\n invalid_value: parseInvalidValueIssue,\n invalid_element: parseInvalidElementIssue,\n not_multiple_of: parseNotMultipleOfIssue,\n unrecognized_keys: parseUnrecognizedKeysIssue,\n invalid_key: parseInvalidKeyIssue,\n custom: parseCustomIssue,\n invalid_union: parseInvalidUnionIssue,\n};\n\nexport const defaultErrorMapOptions = {\n displayInvalidFormatDetails: false,\n allowedValuesSeparator: ', ',\n allowedValuesLastSeparator: ' or ',\n wrapAllowedValuesInQuote: true,\n maxAllowedValuesToDisplay: 10,\n unrecognizedKeysSeparator: ', ',\n unrecognizedKeysLastSeparator: ' and ',\n wrapUnrecognizedKeysInQuote: true,\n maxUnrecognizedKeysToDisplay: 5,\n dateLocalization: true,\n numberLocalization: true,\n} as const satisfies ErrorMapOptions;\n\nexport function createErrorMap(\n partialOptions: Partial<ErrorMapOptions> = {}\n): zod.$ZodErrorMap<zod.$ZodIssue> {\n // fill-in default options\n const options = {\n ...defaultErrorMapOptions,\n ...partialOptions,\n };\n\n const errorMap: zod.$ZodErrorMap<zod.$ZodIssue> = (issue) => {\n if (issue.code === undefined) {\n // TODO: handle this case\n return 'Not supported issue type';\n }\n\n const parseFunc = issueParsers[issue.code] as (\n iss: typeof issue,\n opts: ErrorMapOptions\n ) => AbstractSyntaxTree;\n const ast = parseFunc(issue, options);\n return ast.message;\n };\n\n return errorMap;\n}\n","export type NonEmptyArray<T> = [T, ...T[]];\n\nexport function isNonEmptyArray<T>(value: T[]): value is NonEmptyArray<T> {\n return value.length !== 0;\n}\n","import { stringifySymbol } from './stringify.ts';\nimport type { NonEmptyArray } from './NonEmptyArray.ts';\n\n/**\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#identifiers\n */\nconst identifierRegex = /[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*/u;\n\nexport function joinPath(path: NonEmptyArray<PropertyKey>): string {\n if (path.length === 1) {\n let propertyKey = path[0];\n\n if (typeof propertyKey === 'symbol') {\n propertyKey = stringifySymbol(propertyKey);\n }\n\n return propertyKey.toString() || '\"\"';\n }\n\n return path.reduce<string>((acc, propertyKey) => {\n // handle numeric indices\n if (typeof propertyKey === 'number') {\n return acc + '[' + propertyKey.toString() + ']';\n }\n\n // handle symbols\n if (typeof propertyKey === 'symbol') {\n propertyKey = stringifySymbol(propertyKey);\n }\n\n // handle quoted values\n if (propertyKey.includes('\"')) {\n return acc + '[\"' + escapeQuotes(propertyKey) + '\"]';\n }\n\n // handle special characters\n if (!identifierRegex.test(propertyKey)) {\n return acc + '[\"' + propertyKey + '\"]';\n }\n\n // handle normal values\n const separator = acc.length === 0 ? '' : '.';\n return acc + separator + propertyKey;\n }, '');\n}\n\nfunction escapeQuotes(str: string): string {\n return str.replace(/\"/g, '\\\\\"');\n}\n","export function titleCase(value: string): string {\n if (value.length === 0) {\n return value;\n }\n return value.charAt(0).toUpperCase() + value.slice(1);\n}\n","import { joinPath } from '../utils/joinPath.ts';\nimport { isNonEmptyArray, type NonEmptyArray } from '../utils/NonEmptyArray.ts';\nimport { titleCase } from '../utils/titleCase.ts';\nimport type * as zod from 'zod/v4/core';\n\nexport type ZodIssue = zod.$ZodIssue;\n\nexport type MessageBuilder = (issues: NonEmptyArray<ZodIssue>) => string;\n\nexport type MessageBuilderOptions = {\n prefix: string | null | undefined;\n prefixSeparator: string;\n maxIssuesInMessage: number;\n issueSeparator: string;\n unionSeparator: string;\n includePath: boolean;\n forceTitleCase: boolean;\n};\n\nexport const defaultMessageBuilderOptions: MessageBuilderOptions & {\n prefix: string;\n} = {\n prefix: 'Validation error',\n prefixSeparator: ': ',\n maxIssuesInMessage: 99, // I've got 99 problems but the b$tch ain't one\n unionSeparator: ' or ',\n issueSeparator: '; ',\n includePath: true,\n forceTitleCase: true,\n};\n\nexport function createMessageBuilder(\n partialOptions: Partial<MessageBuilderOptions> = {}\n): MessageBuilder {\n const options = {\n ...defaultMessageBuilderOptions,\n ...partialOptions,\n };\n\n return function messageBuilder(issues) {\n const message = issues\n // limit max number of issues printed in the reason section\n .slice(0, options.maxIssuesInMessage)\n // format error message\n .map((issue) => mapIssue(issue, options))\n // concat as string\n .join(options.issueSeparator);\n\n return conditionallyPrefixMessage(message, options);\n };\n}\n\nfunction mapIssue(\n issue: zod.$ZodIssue,\n options: MessageBuilderOptions\n): string {\n if (issue.code === 'invalid_union' && isNonEmptyArray(issue.errors)) {\n const individualMessages = issue.errors.map((issues) =>\n issues\n .map((subIssue) =>\n mapIssue(\n {\n ...subIssue,\n path: issue.path.concat(subIssue.path),\n },\n options\n )\n )\n .join(options.issueSeparator)\n );\n\n // deduplicate messages\n // and join them with the union separator\n // to create a single message for the invalid union issue\n return Array.from(new Set(individualMessages)).join(options.unionSeparator);\n }\n\n const buf = [];\n\n if (options.forceTitleCase) {\n buf.push(titleCase(issue.message));\n } else {\n buf.push(issue.message);\n }\n\n pathCondition: if (\n options.includePath &&\n issue.path !== undefined &&\n isNonEmptyArray(issue.path)\n ) {\n // handle array indices\n if (issue.path.length === 1) {\n const identifier = issue.path[0];\n\n if (typeof identifier === 'number') {\n buf.push(` at index ${identifier}`);\n break pathCondition;\n }\n }\n\n buf.push(` at \"${joinPath(issue.path)}\"`);\n }\n\n return buf.join('');\n}\n\nfunction conditionallyPrefixMessage(\n message: string,\n options: Pick<MessageBuilderOptions, 'prefix' | 'prefixSeparator'>\n): string {\n if (options.prefix != null) {\n if (message.length > 0) {\n return [options.prefix, message].join(options.prefixSeparator);\n }\n\n return options.prefix;\n }\n\n if (message.length > 0) {\n return message;\n }\n\n // if both reason and prefix are empty, return default prefix\n // to avoid having an empty error message\n return defaultMessageBuilderOptions.prefix;\n}\n","import { isNonEmptyArray } from '../utils/NonEmptyArray.ts';\nimport { fromError } from './fromError.ts';\nimport { isZodErrorLike } from './isZodErrorLike.ts';\nimport {\n createMessageBuilder,\n type MessageBuilderOptions,\n type MessageBuilder,\n} from './MessageBuilder.ts';\nimport { ValidationError } from './ValidationError.ts';\nimport type * as zod from 'zod/v4/core';\n\nexport type ZodError = zod.$ZodError;\n\nexport type FromZodErrorOptions =\n | {\n messageBuilder: MessageBuilder;\n }\n // maintain backwards compatibility\n | Partial<MessageBuilderOptions>;\n\nexport function fromZodError(\n zodError: ZodError,\n options: FromZodErrorOptions = {}\n): ValidationError {\n // perform runtime check to ensure the input is a ZodError\n // why? because people have been historically using this function incorrectly\n if (!isZodErrorLike(zodError)) {\n throw new TypeError(\n `Invalid zodError param; expected instance of ZodError. Did you mean to use the \"${fromError.name}\" method instead?`\n );\n }\n\n return fromZodErrorWithoutRuntimeCheck(zodError, options);\n}\n\nexport function fromZodErrorWithoutRuntimeCheck(\n zodError: ZodError,\n options: FromZodErrorOptions = {}\n): ValidationError {\n const zodIssues = zodError.issues;\n\n let message: string;\n if (isNonEmptyArray(zodIssues)) {\n const messageBuilder = createMessageBuilderFromOptions(options);\n message = messageBuilder(zodIssues);\n } else {\n message = zodError.message;\n }\n\n return new ValidationError(message, { cause: zodError });\n}\n\nfunction createMessageBuilderFromOptions(\n options: FromZodErrorOptions\n): MessageBuilder {\n if ('messageBuilder' in options) {\n return options.messageBuilder;\n }\n\n return createMessageBuilder(options);\n}\n","import { ValidationError } from './ValidationError.ts';\nimport { isZodErrorLike } from './isZodErrorLike.ts';\nimport {\n fromZodErrorWithoutRuntimeCheck,\n type FromZodErrorOptions,\n} from './fromZodError.ts';\n\nexport const toValidationError =\n (options: FromZodErrorOptions = {}) =>\n (err: unknown): ValidationError => {\n if (isZodErrorLike(err)) {\n return fromZodErrorWithoutRuntimeCheck(err, options);\n }\n\n if (err instanceof Error) {\n return new ValidationError(err.message, { cause: err });\n }\n\n return new ValidationError('Unknown error');\n };\n","import { toValidationError } from './toValidationError.ts';\nimport type { FromZodErrorOptions } from './fromZodError.ts';\nimport type { ValidationError } from './ValidationError.ts';\n\n/**\n * This function is a non-curried version of `toValidationError`\n */\nexport function fromError(\n err: unknown,\n options: FromZodErrorOptions = {}\n): ValidationError {\n return toValidationError(options)(err);\n}\n","import * as zod from 'zod/v4/core';\n\nimport {\n type MessageBuilder,\n type MessageBuilderOptions,\n type ZodIssue,\n createMessageBuilder,\n} from './MessageBuilder.ts';\nimport { ValidationError } from './ValidationError.ts';\n\nexport type FromZodIssueOptions =\n | {\n messageBuilder: MessageBuilder;\n }\n // maintain backwards compatibility\n | Partial<Omit<MessageBuilderOptions, 'maxIssuesInMessage'>>;\n\nexport function fromZodIssue(\n issue: ZodIssue,\n options: FromZodIssueOptions = {}\n): ValidationError {\n const messageBuilder = createMessageBuilderFromOptions(options);\n const message = messageBuilder([issue]);\n\n return new ValidationError(message, {\n cause: new zod.$ZodRealError([issue]),\n });\n}\n\nfunction createMessageBuilderFromOptions(\n options: FromZodIssueOptions\n): MessageBuilder {\n if ('messageBuilder' in options) {\n return options.messageBuilder;\n }\n\n return createMessageBuilder(options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,SAAS,eAAe,KAAoC;AACjE,SACE,eAAe,UACf,UAAU,QACT,IAAI,SAAS,cAAc,IAAI,SAAS,gBACzC,YAAY,OACZ,MAAM,QAAQ,IAAI,MAAM;AAE5B;;;ACPO,IAAM,4BAA4B;AASlC,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC;AAAA,EACA;AAAA,EAEA,YAAY,SAAkB,SAAwB;AACpD,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AACZ,SAAK,UAAU,0BAA0B,OAAO;AAAA,EAClD;AAAA,EAEA,WAAmB;AACjB,WAAO,KAAK;AAAA,EACd;AACF;AAEA,SAAS,0BACP,SACsB;AACtB,MAAI,SAAS;AACX,UAAM,QAAQ,QAAQ;AACtB,QAAI,eAAe,KAAK,GAAG;AACzB,aAAO,MAAM;AAAA,IACf;AAAA,EACF;AAEA,SAAO,CAAC;AACV;;;ACpCO,SAAS,kBAAkB,KAAsC;AACtE,SAAO,eAAe;AACxB;;;ACCO,SAAS,sBAAsB,KAAsC;AAC1E,SAAO,eAAe,SAAS,IAAI,SAAS;AAC9C;;;ACJO,SAAS,iBACd,OACoB;AACpB,SAAO;AAAA,IACL,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ,SAAS,MAAM,WAAW;AAAA,EAC5B;AACF;;;ACRO,SAAS,yBACd,OACoB;AACpB,SAAO;AAAA,IACL,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ,SAAS,yBAAyB,MAAM,MAAM;AAAA,EAChD;AACF;;;ACRO,SAAS,qBACd,OACoB;AACpB,SAAO;AAAA,IACL,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// lib/v4/isZodErrorLike.ts
|
| 2 |
+
function isZodErrorLike(err) {
|
| 3 |
+
return err instanceof Object && "name" in err && (err.name === "ZodError" || err.name === "$ZodError") && "issues" in err && Array.isArray(err.issues);
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
// lib/v4/ValidationError.ts
|
| 7 |
+
var ZOD_VALIDATION_ERROR_NAME = "ZodValidationError";
|
| 8 |
+
var ValidationError = class extends Error {
|
| 9 |
+
name;
|
| 10 |
+
details;
|
| 11 |
+
constructor(message, options) {
|
| 12 |
+
super(message, options);
|
| 13 |
+
this.name = ZOD_VALIDATION_ERROR_NAME;
|
| 14 |
+
this.details = getIssuesFromErrorOptions(options);
|
| 15 |
+
}
|
| 16 |
+
toString() {
|
| 17 |
+
return this.message;
|
| 18 |
+
}
|
| 19 |
+
};
|
| 20 |
+
function getIssuesFromErrorOptions(options) {
|
| 21 |
+
if (options) {
|
| 22 |
+
const cause = options.cause;
|
| 23 |
+
if (isZodErrorLike(cause)) {
|
| 24 |
+
return cause.issues;
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
return [];
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
// lib/v4/isValidationError.ts
|
| 31 |
+
function isValidationError(err) {
|
| 32 |
+
return err instanceof ValidationError;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
// lib/v4/isValidationErrorLike.ts
|
| 36 |
+
function isValidationErrorLike(err) {
|
| 37 |
+
return err instanceof Error && err.name === ZOD_VALIDATION_ERROR_NAME;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
// lib/v4/errorMap/custom.ts
|
| 41 |
+
function parseCustomIssue(issue) {
|
| 42 |
+
return {
|
| 43 |
+
type: issue.code,
|
| 44 |
+
path: issue.path,
|
| 45 |
+
message: issue.message ?? "Invalid input"
|
| 46 |
+
};
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
// lib/v4/errorMap/invalidElement.ts
|
| 50 |
+
function parseInvalidElementIssue(issue) {
|
| 51 |
+
return {
|
| 52 |
+
type: issue.code,
|
| 53 |
+
path: issue.path,
|
| 54 |
+
message: `unexpected element in ${issue.origin}`
|
| 55 |
+
};
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
// lib/v4/errorMap/invalidKey.ts
|
| 59 |
+
function parseInvalidKeyIssue(issue) {
|
| 60 |
+
return {
|
| 61 |
+
type: issue.code,
|
| 62 |
+
path: issue.path,
|
| 63 |
+
message: `unexpected key in ${issue.origin}`
|
| 64 |
+
};
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
// lib/v4/errorMap/invalidStringFormat.ts
|
| 68 |
+
function parseInvalidStringFormatIssue(issue, options = {
|
| 69 |
+
displayInvalidFormatDetails: false
|
| 70 |
+
}) {
|
| 71 |
+
switch (issue.format) {
|
| 72 |
+
case "lowercase":
|
| 73 |
+
case "uppercase":
|
| 74 |
+
return {
|
| 75 |
+
type: issue.code,
|
| 76 |
+
path: issue.path,
|
| 77 |
+
message: `value must be in ${issue.format} format`
|
| 78 |
+
};
|
| 79 |
+
default: {
|
| 80 |
+
if (isZodIssueStringStartsWith(issue)) {
|
| 81 |
+
return parseStringStartsWith(issue);
|
| 82 |
+
}
|
| 83 |
+
if (isZodIssueStringEndsWith(issue)) {
|
| 84 |
+
return parseStringEndsWith(issue);
|
| 85 |
+
}
|
| 86 |
+
if (isZodIssueStringIncludes(issue)) {
|
| 87 |
+
return parseStringIncludes(issue);
|
| 88 |
+
}
|
| 89 |
+
if (isZodIssueStringInvalidRegex(issue)) {
|
| 90 |
+
return parseStringInvalidRegex(issue, options);
|
| 91 |
+
}
|
| 92 |
+
if (isZodIssueStringInvalidJWT(issue)) {
|
| 93 |
+
return parseStringInvalidJWT(issue, options);
|
| 94 |
+
}
|
| 95 |
+
return {
|
| 96 |
+
type: issue.code,
|
| 97 |
+
path: issue.path,
|
| 98 |
+
message: `invalid ${issue.format}`
|
| 99 |
+
};
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
function isZodIssueStringStartsWith(issue) {
|
| 104 |
+
return issue.format === "starts_with";
|
| 105 |
+
}
|
| 106 |
+
function parseStringStartsWith(issue) {
|
| 107 |
+
return {
|
| 108 |
+
type: issue.code,
|
| 109 |
+
path: issue.path,
|
| 110 |
+
message: `value must start with "${issue.prefix}"`
|
| 111 |
+
};
|
| 112 |
+
}
|
| 113 |
+
function isZodIssueStringEndsWith(issue) {
|
| 114 |
+
return issue.format === "ends_with";
|
| 115 |
+
}
|
| 116 |
+
function parseStringEndsWith(issue) {
|
| 117 |
+
return {
|
| 118 |
+
type: issue.code,
|
| 119 |
+
path: issue.path,
|
| 120 |
+
message: `value must end with "${issue.suffix}"`
|
| 121 |
+
};
|
| 122 |
+
}
|
| 123 |
+
function isZodIssueStringIncludes(issue) {
|
| 124 |
+
return issue.format === "includes";
|
| 125 |
+
}
|
| 126 |
+
function parseStringIncludes(issue) {
|
| 127 |
+
return {
|
| 128 |
+
type: issue.code,
|
| 129 |
+
path: issue.path,
|
| 130 |
+
message: `value must include "${issue.includes}"`
|
| 131 |
+
};
|
| 132 |
+
}
|
| 133 |
+
function isZodIssueStringInvalidRegex(issue) {
|
| 134 |
+
return issue.format === "regex";
|
| 135 |
+
}
|
| 136 |
+
function parseStringInvalidRegex(issue, options = {
|
| 137 |
+
displayInvalidFormatDetails: false
|
| 138 |
+
}) {
|
| 139 |
+
let message = "value must match pattern";
|
| 140 |
+
if (options.displayInvalidFormatDetails) {
|
| 141 |
+
message += ` "${issue.pattern}"`;
|
| 142 |
+
}
|
| 143 |
+
return {
|
| 144 |
+
type: issue.code,
|
| 145 |
+
path: issue.path,
|
| 146 |
+
message
|
| 147 |
+
};
|
| 148 |
+
}
|
| 149 |
+
function isZodIssueStringInvalidJWT(issue) {
|
| 150 |
+
return issue.format === "jwt";
|
| 151 |
+
}
|
| 152 |
+
function parseStringInvalidJWT(issue, options = {
|
| 153 |
+
displayInvalidFormatDetails: false
|
| 154 |
+
}) {
|
| 155 |
+
return {
|
| 156 |
+
type: issue.code,
|
| 157 |
+
path: issue.path,
|
| 158 |
+
message: options.displayInvalidFormatDetails && issue.algorithm ? `invalid jwt/${issue.algorithm}` : `invalid jwt`
|
| 159 |
+
};
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
// lib/v4/errorMap/invalidType.ts
|
| 163 |
+
function parseInvalidTypeIssue(issue) {
|
| 164 |
+
let message = `expected ${issue.expected}`;
|
| 165 |
+
if ("input" in issue) {
|
| 166 |
+
message += `, received ${getTypeName(issue.input)}`;
|
| 167 |
+
}
|
| 168 |
+
return {
|
| 169 |
+
type: issue.code,
|
| 170 |
+
path: issue.path,
|
| 171 |
+
message
|
| 172 |
+
};
|
| 173 |
+
}
|
| 174 |
+
function getTypeName(value) {
|
| 175 |
+
if (typeof value === "object") {
|
| 176 |
+
if (value === null) {
|
| 177 |
+
return "null";
|
| 178 |
+
}
|
| 179 |
+
if (value === void 0) {
|
| 180 |
+
return "undefined";
|
| 181 |
+
}
|
| 182 |
+
if (Array.isArray(value)) {
|
| 183 |
+
return "array";
|
| 184 |
+
}
|
| 185 |
+
if (value instanceof Date) {
|
| 186 |
+
return "date";
|
| 187 |
+
}
|
| 188 |
+
if (value instanceof RegExp) {
|
| 189 |
+
return "regexp";
|
| 190 |
+
}
|
| 191 |
+
if (value instanceof Map) {
|
| 192 |
+
return "map";
|
| 193 |
+
}
|
| 194 |
+
if (value instanceof Set) {
|
| 195 |
+
return "set";
|
| 196 |
+
}
|
| 197 |
+
if (value instanceof Error) {
|
| 198 |
+
return "error";
|
| 199 |
+
}
|
| 200 |
+
if (value instanceof Function) {
|
| 201 |
+
return "function";
|
| 202 |
+
}
|
| 203 |
+
return "object";
|
| 204 |
+
}
|
| 205 |
+
return typeof value;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
// lib/v4/errorMap/invalidUnion.ts
|
| 209 |
+
function parseInvalidUnionIssue(issue) {
|
| 210 |
+
return {
|
| 211 |
+
type: issue.code,
|
| 212 |
+
path: issue.path,
|
| 213 |
+
message: issue.message ?? "Invalid input"
|
| 214 |
+
};
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
// lib/utils/stringify.ts
|
| 218 |
+
function stringifySymbol(symbol) {
|
| 219 |
+
return symbol.description ?? "";
|
| 220 |
+
}
|
| 221 |
+
function stringify(value, options = {}) {
|
| 222 |
+
switch (typeof value) {
|
| 223 |
+
case "symbol":
|
| 224 |
+
return stringifySymbol(value);
|
| 225 |
+
case "bigint":
|
| 226 |
+
case "number": {
|
| 227 |
+
switch (options.localization) {
|
| 228 |
+
case true:
|
| 229 |
+
return value.toLocaleString();
|
| 230 |
+
case false:
|
| 231 |
+
return value.toString();
|
| 232 |
+
default:
|
| 233 |
+
return value.toLocaleString(options.localization);
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
case "string": {
|
| 237 |
+
if (options.wrapStringValueInQuote) {
|
| 238 |
+
return `"${value}"`;
|
| 239 |
+
}
|
| 240 |
+
return value;
|
| 241 |
+
}
|
| 242 |
+
default: {
|
| 243 |
+
if (value instanceof Date) {
|
| 244 |
+
switch (options.localization) {
|
| 245 |
+
case true:
|
| 246 |
+
return value.toLocaleString();
|
| 247 |
+
case false:
|
| 248 |
+
return value.toISOString();
|
| 249 |
+
default:
|
| 250 |
+
return value.toLocaleString(options.localization);
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
return String(value);
|
| 254 |
+
}
|
| 255 |
+
}
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
// lib/utils/joinValues.ts
|
| 259 |
+
function joinValues(values, options) {
|
| 260 |
+
const valuesToDisplay = (options.maxValuesToDisplay ? values.slice(0, options.maxValuesToDisplay) : values).map((value) => {
|
| 261 |
+
return stringify(value, {
|
| 262 |
+
wrapStringValueInQuote: options.wrapStringValuesInQuote
|
| 263 |
+
});
|
| 264 |
+
});
|
| 265 |
+
if (valuesToDisplay.length < values.length) {
|
| 266 |
+
valuesToDisplay.push(
|
| 267 |
+
`${values.length - valuesToDisplay.length} more value(s)`
|
| 268 |
+
);
|
| 269 |
+
}
|
| 270 |
+
return valuesToDisplay.reduce((acc, value, index) => {
|
| 271 |
+
if (index > 0) {
|
| 272 |
+
if (index === valuesToDisplay.length - 1 && options.lastSeparator) {
|
| 273 |
+
acc += options.lastSeparator;
|
| 274 |
+
} else {
|
| 275 |
+
acc += options.separator;
|
| 276 |
+
}
|
| 277 |
+
}
|
| 278 |
+
acc += value;
|
| 279 |
+
return acc;
|
| 280 |
+
}, "");
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
// lib/v4/errorMap/invalidValue.ts
|
| 284 |
+
function parseInvalidValueIssue(issue, options) {
|
| 285 |
+
let message;
|
| 286 |
+
if (issue.values.length === 0) {
|
| 287 |
+
message = "invalid value";
|
| 288 |
+
} else if (issue.values.length === 1) {
|
| 289 |
+
const valueStr = stringify(issue.values[0], {
|
| 290 |
+
wrapStringValueInQuote: true
|
| 291 |
+
});
|
| 292 |
+
message = `expected value to be ${valueStr}`;
|
| 293 |
+
} else {
|
| 294 |
+
const valuesStr = joinValues(issue.values, {
|
| 295 |
+
separator: options.allowedValuesSeparator,
|
| 296 |
+
lastSeparator: options.allowedValuesLastSeparator,
|
| 297 |
+
wrapStringValuesInQuote: options.wrapAllowedValuesInQuote,
|
| 298 |
+
maxValuesToDisplay: options.maxAllowedValuesToDisplay
|
| 299 |
+
});
|
| 300 |
+
message = `expected value to be one of ${valuesStr}`;
|
| 301 |
+
}
|
| 302 |
+
return {
|
| 303 |
+
type: issue.code,
|
| 304 |
+
path: issue.path,
|
| 305 |
+
message
|
| 306 |
+
};
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
// lib/v4/errorMap/notMultipleOf.ts
|
| 310 |
+
function parseNotMultipleOfIssue(issue) {
|
| 311 |
+
return {
|
| 312 |
+
type: issue.code,
|
| 313 |
+
path: issue.path,
|
| 314 |
+
message: `expected multiple of ${issue.divisor}`
|
| 315 |
+
};
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
// lib/v4/errorMap/tooBig.ts
|
| 319 |
+
function parseTooBigIssue(issue, options) {
|
| 320 |
+
const maxValueStr = issue.origin === "date" ? stringify(new Date(issue.maximum), {
|
| 321 |
+
localization: options.dateLocalization
|
| 322 |
+
}) : stringify(issue.maximum, {
|
| 323 |
+
localization: options.numberLocalization
|
| 324 |
+
});
|
| 325 |
+
switch (issue.origin) {
|
| 326 |
+
case "number":
|
| 327 |
+
case "int":
|
| 328 |
+
case "bigint": {
|
| 329 |
+
return {
|
| 330 |
+
type: issue.code,
|
| 331 |
+
path: issue.path,
|
| 332 |
+
message: `number must be less than${issue.inclusive ? " or equal to" : ""} ${maxValueStr}`
|
| 333 |
+
};
|
| 334 |
+
}
|
| 335 |
+
case "string": {
|
| 336 |
+
return {
|
| 337 |
+
type: issue.code,
|
| 338 |
+
path: issue.path,
|
| 339 |
+
message: `string must contain at most ${maxValueStr} character(s)`
|
| 340 |
+
};
|
| 341 |
+
}
|
| 342 |
+
case "date": {
|
| 343 |
+
return {
|
| 344 |
+
type: issue.code,
|
| 345 |
+
path: issue.path,
|
| 346 |
+
message: `date must be ${issue.inclusive ? "prior or equal to" : "prior to"} "${maxValueStr}"`
|
| 347 |
+
};
|
| 348 |
+
}
|
| 349 |
+
case "array": {
|
| 350 |
+
return {
|
| 351 |
+
type: issue.code,
|
| 352 |
+
path: issue.path,
|
| 353 |
+
message: `array must contain at most ${maxValueStr} item(s)`
|
| 354 |
+
};
|
| 355 |
+
}
|
| 356 |
+
case "set": {
|
| 357 |
+
return {
|
| 358 |
+
type: issue.code,
|
| 359 |
+
path: issue.path,
|
| 360 |
+
message: `set must contain at most ${maxValueStr} item(s)`
|
| 361 |
+
};
|
| 362 |
+
}
|
| 363 |
+
case "file": {
|
| 364 |
+
return {
|
| 365 |
+
type: issue.code,
|
| 366 |
+
path: issue.path,
|
| 367 |
+
message: `file must not exceed ${maxValueStr} byte(s) in size`
|
| 368 |
+
};
|
| 369 |
+
}
|
| 370 |
+
default:
|
| 371 |
+
return {
|
| 372 |
+
type: issue.code,
|
| 373 |
+
path: issue.path,
|
| 374 |
+
message: `value must be less than${issue.inclusive ? " or equal to" : ""} ${maxValueStr}`
|
| 375 |
+
};
|
| 376 |
+
}
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
// lib/v4/errorMap/tooSmall.ts
|
| 380 |
+
function parseTooSmallIssue(issue, options) {
|
| 381 |
+
const minValueStr = issue.origin === "date" ? stringify(new Date(issue.minimum), {
|
| 382 |
+
localization: options.dateLocalization
|
| 383 |
+
}) : stringify(issue.minimum, {
|
| 384 |
+
localization: options.numberLocalization
|
| 385 |
+
});
|
| 386 |
+
switch (issue.origin) {
|
| 387 |
+
case "number":
|
| 388 |
+
case "int":
|
| 389 |
+
case "bigint": {
|
| 390 |
+
return {
|
| 391 |
+
type: issue.code,
|
| 392 |
+
path: issue.path,
|
| 393 |
+
message: `number must be greater than${issue.inclusive ? " or equal to" : ""} ${minValueStr}`
|
| 394 |
+
};
|
| 395 |
+
}
|
| 396 |
+
case "date": {
|
| 397 |
+
return {
|
| 398 |
+
type: issue.code,
|
| 399 |
+
path: issue.path,
|
| 400 |
+
message: `date must be ${issue.inclusive ? "later or equal to" : "later to"} "${minValueStr}"`
|
| 401 |
+
};
|
| 402 |
+
}
|
| 403 |
+
case "string": {
|
| 404 |
+
return {
|
| 405 |
+
type: issue.code,
|
| 406 |
+
path: issue.path,
|
| 407 |
+
message: `string must contain at least ${minValueStr} character(s)`
|
| 408 |
+
};
|
| 409 |
+
}
|
| 410 |
+
case "array": {
|
| 411 |
+
return {
|
| 412 |
+
type: issue.code,
|
| 413 |
+
path: issue.path,
|
| 414 |
+
message: `array must contain at least ${minValueStr} item(s)`
|
| 415 |
+
};
|
| 416 |
+
}
|
| 417 |
+
case "set": {
|
| 418 |
+
return {
|
| 419 |
+
type: issue.code,
|
| 420 |
+
path: issue.path,
|
| 421 |
+
message: `set must contain at least ${minValueStr} item(s)`
|
| 422 |
+
};
|
| 423 |
+
}
|
| 424 |
+
case "file": {
|
| 425 |
+
return {
|
| 426 |
+
type: issue.code,
|
| 427 |
+
path: issue.path,
|
| 428 |
+
message: `file must be at least ${minValueStr} byte(s) in size`
|
| 429 |
+
};
|
| 430 |
+
}
|
| 431 |
+
default:
|
| 432 |
+
return {
|
| 433 |
+
type: issue.code,
|
| 434 |
+
path: issue.path,
|
| 435 |
+
message: `value must be greater than${issue.inclusive ? " or equal to" : ""} ${minValueStr}`
|
| 436 |
+
};
|
| 437 |
+
}
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
// lib/v4/errorMap/unrecognizedKeys.ts
|
| 441 |
+
function parseUnrecognizedKeysIssue(issue, options) {
|
| 442 |
+
const keysStr = joinValues(issue.keys, {
|
| 443 |
+
separator: options.unrecognizedKeysSeparator,
|
| 444 |
+
lastSeparator: options.unrecognizedKeysLastSeparator,
|
| 445 |
+
wrapStringValuesInQuote: options.wrapUnrecognizedKeysInQuote,
|
| 446 |
+
maxValuesToDisplay: options.maxUnrecognizedKeysToDisplay
|
| 447 |
+
});
|
| 448 |
+
return {
|
| 449 |
+
type: issue.code,
|
| 450 |
+
path: issue.path,
|
| 451 |
+
message: `unrecognized key(s) ${keysStr} in object`
|
| 452 |
+
};
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
// lib/v4/errorMap/errorMap.ts
|
| 456 |
+
var issueParsers = {
|
| 457 |
+
invalid_type: parseInvalidTypeIssue,
|
| 458 |
+
too_big: parseTooBigIssue,
|
| 459 |
+
too_small: parseTooSmallIssue,
|
| 460 |
+
invalid_format: parseInvalidStringFormatIssue,
|
| 461 |
+
invalid_value: parseInvalidValueIssue,
|
| 462 |
+
invalid_element: parseInvalidElementIssue,
|
| 463 |
+
not_multiple_of: parseNotMultipleOfIssue,
|
| 464 |
+
unrecognized_keys: parseUnrecognizedKeysIssue,
|
| 465 |
+
invalid_key: parseInvalidKeyIssue,
|
| 466 |
+
custom: parseCustomIssue,
|
| 467 |
+
invalid_union: parseInvalidUnionIssue
|
| 468 |
+
};
|
| 469 |
+
var defaultErrorMapOptions = {
|
| 470 |
+
displayInvalidFormatDetails: false,
|
| 471 |
+
allowedValuesSeparator: ", ",
|
| 472 |
+
allowedValuesLastSeparator: " or ",
|
| 473 |
+
wrapAllowedValuesInQuote: true,
|
| 474 |
+
maxAllowedValuesToDisplay: 10,
|
| 475 |
+
unrecognizedKeysSeparator: ", ",
|
| 476 |
+
unrecognizedKeysLastSeparator: " and ",
|
| 477 |
+
wrapUnrecognizedKeysInQuote: true,
|
| 478 |
+
maxUnrecognizedKeysToDisplay: 5,
|
| 479 |
+
dateLocalization: true,
|
| 480 |
+
numberLocalization: true
|
| 481 |
+
};
|
| 482 |
+
function createErrorMap(partialOptions = {}) {
|
| 483 |
+
const options = {
|
| 484 |
+
...defaultErrorMapOptions,
|
| 485 |
+
...partialOptions
|
| 486 |
+
};
|
| 487 |
+
const errorMap = (issue) => {
|
| 488 |
+
if (issue.code === void 0) {
|
| 489 |
+
return "Not supported issue type";
|
| 490 |
+
}
|
| 491 |
+
const parseFunc = issueParsers[issue.code];
|
| 492 |
+
const ast = parseFunc(issue, options);
|
| 493 |
+
return ast.message;
|
| 494 |
+
};
|
| 495 |
+
return errorMap;
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
// lib/utils/NonEmptyArray.ts
|
| 499 |
+
function isNonEmptyArray(value) {
|
| 500 |
+
return value.length !== 0;
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
// lib/utils/joinPath.ts
|
| 504 |
+
var identifierRegex = /[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u;
|
| 505 |
+
function joinPath(path) {
|
| 506 |
+
if (path.length === 1) {
|
| 507 |
+
let propertyKey = path[0];
|
| 508 |
+
if (typeof propertyKey === "symbol") {
|
| 509 |
+
propertyKey = stringifySymbol(propertyKey);
|
| 510 |
+
}
|
| 511 |
+
return propertyKey.toString() || '""';
|
| 512 |
+
}
|
| 513 |
+
return path.reduce((acc, propertyKey) => {
|
| 514 |
+
if (typeof propertyKey === "number") {
|
| 515 |
+
return acc + "[" + propertyKey.toString() + "]";
|
| 516 |
+
}
|
| 517 |
+
if (typeof propertyKey === "symbol") {
|
| 518 |
+
propertyKey = stringifySymbol(propertyKey);
|
| 519 |
+
}
|
| 520 |
+
if (propertyKey.includes('"')) {
|
| 521 |
+
return acc + '["' + escapeQuotes(propertyKey) + '"]';
|
| 522 |
+
}
|
| 523 |
+
if (!identifierRegex.test(propertyKey)) {
|
| 524 |
+
return acc + '["' + propertyKey + '"]';
|
| 525 |
+
}
|
| 526 |
+
const separator = acc.length === 0 ? "" : ".";
|
| 527 |
+
return acc + separator + propertyKey;
|
| 528 |
+
}, "");
|
| 529 |
+
}
|
| 530 |
+
function escapeQuotes(str) {
|
| 531 |
+
return str.replace(/"/g, '\\"');
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
// lib/utils/titleCase.ts
|
| 535 |
+
function titleCase(value) {
|
| 536 |
+
if (value.length === 0) {
|
| 537 |
+
return value;
|
| 538 |
+
}
|
| 539 |
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
| 540 |
+
}
|
| 541 |
+
|
| 542 |
+
// lib/v4/MessageBuilder.ts
|
| 543 |
+
var defaultMessageBuilderOptions = {
|
| 544 |
+
prefix: "Validation error",
|
| 545 |
+
prefixSeparator: ": ",
|
| 546 |
+
maxIssuesInMessage: 99,
|
| 547 |
+
// I've got 99 problems but the b$tch ain't one
|
| 548 |
+
unionSeparator: " or ",
|
| 549 |
+
issueSeparator: "; ",
|
| 550 |
+
includePath: true,
|
| 551 |
+
forceTitleCase: true
|
| 552 |
+
};
|
| 553 |
+
function createMessageBuilder(partialOptions = {}) {
|
| 554 |
+
const options = {
|
| 555 |
+
...defaultMessageBuilderOptions,
|
| 556 |
+
...partialOptions
|
| 557 |
+
};
|
| 558 |
+
return function messageBuilder(issues) {
|
| 559 |
+
const message = issues.slice(0, options.maxIssuesInMessage).map((issue) => mapIssue(issue, options)).join(options.issueSeparator);
|
| 560 |
+
return conditionallyPrefixMessage(message, options);
|
| 561 |
+
};
|
| 562 |
+
}
|
| 563 |
+
function mapIssue(issue, options) {
|
| 564 |
+
if (issue.code === "invalid_union" && isNonEmptyArray(issue.errors)) {
|
| 565 |
+
const individualMessages = issue.errors.map(
|
| 566 |
+
(issues) => issues.map(
|
| 567 |
+
(subIssue) => mapIssue(
|
| 568 |
+
{
|
| 569 |
+
...subIssue,
|
| 570 |
+
path: issue.path.concat(subIssue.path)
|
| 571 |
+
},
|
| 572 |
+
options
|
| 573 |
+
)
|
| 574 |
+
).join(options.issueSeparator)
|
| 575 |
+
);
|
| 576 |
+
return Array.from(new Set(individualMessages)).join(options.unionSeparator);
|
| 577 |
+
}
|
| 578 |
+
const buf = [];
|
| 579 |
+
if (options.forceTitleCase) {
|
| 580 |
+
buf.push(titleCase(issue.message));
|
| 581 |
+
} else {
|
| 582 |
+
buf.push(issue.message);
|
| 583 |
+
}
|
| 584 |
+
pathCondition: if (options.includePath && issue.path !== void 0 && isNonEmptyArray(issue.path)) {
|
| 585 |
+
if (issue.path.length === 1) {
|
| 586 |
+
const identifier = issue.path[0];
|
| 587 |
+
if (typeof identifier === "number") {
|
| 588 |
+
buf.push(` at index ${identifier}`);
|
| 589 |
+
break pathCondition;
|
| 590 |
+
}
|
| 591 |
+
}
|
| 592 |
+
buf.push(` at "${joinPath(issue.path)}"`);
|
| 593 |
+
}
|
| 594 |
+
return buf.join("");
|
| 595 |
+
}
|
| 596 |
+
function conditionallyPrefixMessage(message, options) {
|
| 597 |
+
if (options.prefix != null) {
|
| 598 |
+
if (message.length > 0) {
|
| 599 |
+
return [options.prefix, message].join(options.prefixSeparator);
|
| 600 |
+
}
|
| 601 |
+
return options.prefix;
|
| 602 |
+
}
|
| 603 |
+
if (message.length > 0) {
|
| 604 |
+
return message;
|
| 605 |
+
}
|
| 606 |
+
return defaultMessageBuilderOptions.prefix;
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
// lib/v4/fromZodError.ts
|
| 610 |
+
function fromZodError(zodError, options = {}) {
|
| 611 |
+
if (!isZodErrorLike(zodError)) {
|
| 612 |
+
throw new TypeError(
|
| 613 |
+
`Invalid zodError param; expected instance of ZodError. Did you mean to use the "${fromError.name}" method instead?`
|
| 614 |
+
);
|
| 615 |
+
}
|
| 616 |
+
return fromZodErrorWithoutRuntimeCheck(zodError, options);
|
| 617 |
+
}
|
| 618 |
+
function fromZodErrorWithoutRuntimeCheck(zodError, options = {}) {
|
| 619 |
+
const zodIssues = zodError.issues;
|
| 620 |
+
let message;
|
| 621 |
+
if (isNonEmptyArray(zodIssues)) {
|
| 622 |
+
const messageBuilder = createMessageBuilderFromOptions(options);
|
| 623 |
+
message = messageBuilder(zodIssues);
|
| 624 |
+
} else {
|
| 625 |
+
message = zodError.message;
|
| 626 |
+
}
|
| 627 |
+
return new ValidationError(message, { cause: zodError });
|
| 628 |
+
}
|
| 629 |
+
function createMessageBuilderFromOptions(options) {
|
| 630 |
+
if ("messageBuilder" in options) {
|
| 631 |
+
return options.messageBuilder;
|
| 632 |
+
}
|
| 633 |
+
return createMessageBuilder(options);
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
// lib/v4/toValidationError.ts
|
| 637 |
+
var toValidationError = (options = {}) => (err) => {
|
| 638 |
+
if (isZodErrorLike(err)) {
|
| 639 |
+
return fromZodErrorWithoutRuntimeCheck(err, options);
|
| 640 |
+
}
|
| 641 |
+
if (err instanceof Error) {
|
| 642 |
+
return new ValidationError(err.message, { cause: err });
|
| 643 |
+
}
|
| 644 |
+
return new ValidationError("Unknown error");
|
| 645 |
+
};
|
| 646 |
+
|
| 647 |
+
// lib/v4/fromError.ts
|
| 648 |
+
function fromError(err, options = {}) {
|
| 649 |
+
return toValidationError(options)(err);
|
| 650 |
+
}
|
| 651 |
+
|
| 652 |
+
// lib/v4/fromZodIssue.ts
|
| 653 |
+
import * as zod from "zod/v4/core";
|
| 654 |
+
function fromZodIssue(issue, options = {}) {
|
| 655 |
+
const messageBuilder = createMessageBuilderFromOptions2(options);
|
| 656 |
+
const message = messageBuilder([issue]);
|
| 657 |
+
return new ValidationError(message, {
|
| 658 |
+
cause: new zod.$ZodRealError([issue])
|
| 659 |
+
});
|
| 660 |
+
}
|
| 661 |
+
function createMessageBuilderFromOptions2(options) {
|
| 662 |
+
if ("messageBuilder" in options) {
|
| 663 |
+
return options.messageBuilder;
|
| 664 |
+
}
|
| 665 |
+
return createMessageBuilder(options);
|
| 666 |
+
}
|
| 667 |
+
export {
|
| 668 |
+
ValidationError,
|
| 669 |
+
createErrorMap,
|
| 670 |
+
createMessageBuilder,
|
| 671 |
+
fromError,
|
| 672 |
+
fromZodError,
|
| 673 |
+
fromZodIssue,
|
| 674 |
+
isValidationError,
|
| 675 |
+
isValidationErrorLike,
|
| 676 |
+
isZodErrorLike,
|
| 677 |
+
toValidationError
|
| 678 |
+
};
|
| 679 |
+
//# sourceMappingURL=index.mjs.map
|
node_modules/zod-validation-error/v4/index.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"sources":["../lib/v4/isZodErrorLike.ts","../lib/v4/ValidationError.ts","../lib/v4/isValidationError.ts","../lib/v4/isValidationErrorLike.ts","../lib/v4/errorMap/custom.ts","../lib/v4/errorMap/invalidElement.ts","../lib/v4/errorMap/invalidKey.ts","../lib/v4/errorMap/invalidStringFormat.ts","../lib/v4/errorMap/invalidType.ts","../lib/v4/errorMap/invalidUnion.ts","../lib/utils/stringify.ts","../lib/utils/joinValues.ts","../lib/v4/errorMap/invalidValue.ts","../lib/v4/errorMap/notMultipleOf.ts","../lib/v4/errorMap/tooBig.ts","../lib/v4/errorMap/tooSmall.ts","../lib/v4/errorMap/unrecognizedKeys.ts","../lib/v4/errorMap/errorMap.ts","../lib/utils/NonEmptyArray.ts","../lib/utils/joinPath.ts","../lib/utils/titleCase.ts","../lib/v4/MessageBuilder.ts","../lib/v4/fromZodError.ts","../lib/v4/toValidationError.ts","../lib/v4/fromError.ts","../lib/v4/fromZodIssue.ts"],"sourcesContent":["import type * as zod from 'zod/v4/core';\n\nexport function isZodErrorLike(err: unknown): err is zod.$ZodError {\n return (\n err instanceof Object &&\n 'name' in err &&\n (err.name === 'ZodError' || err.name === '$ZodError') &&\n 'issues' in err &&\n Array.isArray(err.issues)\n );\n}\n","import { isZodErrorLike } from './isZodErrorLike.ts';\nimport type * as zod from 'zod/v4/core';\n\nexport const ZOD_VALIDATION_ERROR_NAME = 'ZodValidationError';\n\n// make zod-validation-error compatible with\n// earlier to es2022 typescript configurations\n// @see https://github.com/causaly/zod-validation-error/issues/226\nexport interface ErrorOptions {\n cause?: unknown;\n}\n\nexport class ValidationError extends Error {\n name: typeof ZOD_VALIDATION_ERROR_NAME;\n details: Array<zod.$ZodIssue>;\n\n constructor(message?: string, options?: ErrorOptions) {\n super(message, options);\n this.name = ZOD_VALIDATION_ERROR_NAME;\n this.details = getIssuesFromErrorOptions(options);\n }\n\n toString(): string {\n return this.message;\n }\n}\n\nfunction getIssuesFromErrorOptions(\n options?: ErrorOptions\n): Array<zod.$ZodIssue> {\n if (options) {\n const cause = options.cause;\n if (isZodErrorLike(cause)) {\n return cause.issues;\n }\n }\n\n return [];\n}\n","import { ValidationError } from './ValidationError.ts';\n\nexport function isValidationError(err: unknown): err is ValidationError {\n return err instanceof ValidationError;\n}\n","import {\n ZOD_VALIDATION_ERROR_NAME,\n type ValidationError,\n} from './ValidationError.ts';\n\nexport function isValidationErrorLike(err: unknown): err is ValidationError {\n return err instanceof Error && err.name === ZOD_VALIDATION_ERROR_NAME;\n}\n","import type * as zod from 'zod/v4/core';\nimport type { AbstractSyntaxTree } from './types.ts';\n\nexport function parseCustomIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueCustom>\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message: issue.message ?? 'Invalid input',\n };\n}\n","import type * as zod from 'zod/v4/core';\nimport type { AbstractSyntaxTree } from './types.ts';\n\nexport function parseInvalidElementIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidElement>\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message: `unexpected element in ${issue.origin}`,\n };\n}\n","import type * as zod from 'zod/v4/core';\nimport type { AbstractSyntaxTree } from './types.ts';\n\nexport function parseInvalidKeyIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidKey>\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message: `unexpected key in ${issue.origin}`,\n };\n}\n","import type { AbstractSyntaxTree, ErrorMapOptions } from './types.ts';\nimport type * as zod from 'zod/v4/core';\n\nexport function parseInvalidStringFormatIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidStringFormat>,\n options: Pick<ErrorMapOptions, 'displayInvalidFormatDetails'> = {\n displayInvalidFormatDetails: false,\n }\n): AbstractSyntaxTree {\n switch (issue.format) {\n case 'lowercase':\n case 'uppercase':\n return {\n type: issue.code,\n path: issue.path,\n message: `value must be in ${issue.format} format`,\n };\n default: {\n if (isZodIssueStringStartsWith(issue)) {\n return parseStringStartsWith(issue);\n }\n if (isZodIssueStringEndsWith(issue)) {\n return parseStringEndsWith(issue);\n }\n if (isZodIssueStringIncludes(issue)) {\n return parseStringIncludes(issue);\n }\n if (isZodIssueStringInvalidRegex(issue)) {\n return parseStringInvalidRegex(issue, options);\n }\n if (isZodIssueStringInvalidJWT(issue)) {\n return parseStringInvalidJWT(issue, options);\n }\n\n return {\n type: issue.code,\n path: issue.path,\n message: `invalid ${issue.format}`,\n };\n }\n }\n}\nfunction isZodIssueStringStartsWith(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidStringFormat>\n): issue is zod.$ZodRawIssue<zod.$ZodIssueStringStartsWith> {\n return issue.format === 'starts_with';\n}\n\nfunction parseStringStartsWith(\n issue: zod.$ZodRawIssue<zod.$ZodIssueStringStartsWith>\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message: `value must start with \"${issue.prefix}\"`,\n };\n}\n\nfunction isZodIssueStringEndsWith(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidStringFormat>\n): issue is zod.$ZodRawIssue<zod.$ZodIssueStringEndsWith> {\n return issue.format === 'ends_with';\n}\nfunction parseStringEndsWith(\n issue: zod.$ZodRawIssue<zod.$ZodIssueStringEndsWith>\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message: `value must end with \"${issue.suffix}\"`,\n };\n}\n\nfunction isZodIssueStringIncludes(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidStringFormat>\n): issue is zod.$ZodRawIssue<zod.$ZodIssueStringIncludes> {\n return issue.format === 'includes';\n}\nfunction parseStringIncludes(\n issue: zod.$ZodRawIssue<zod.$ZodIssueStringIncludes>\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message: `value must include \"${issue.includes}\"`,\n };\n}\n\nfunction isZodIssueStringInvalidRegex(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidStringFormat>\n): issue is zod.$ZodRawIssue<zod.$ZodIssueStringInvalidRegex> {\n return issue.format === 'regex';\n}\nfunction parseStringInvalidRegex(\n issue: zod.$ZodRawIssue<zod.$ZodIssueStringInvalidRegex>,\n options: Pick<ErrorMapOptions, 'displayInvalidFormatDetails'> = {\n displayInvalidFormatDetails: false,\n }\n): AbstractSyntaxTree {\n let message = 'value must match pattern';\n if (options.displayInvalidFormatDetails) {\n message += ` \"${issue.pattern}\"`;\n }\n\n return {\n type: issue.code,\n path: issue.path,\n message,\n };\n}\n\nfunction isZodIssueStringInvalidJWT(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidStringFormat>\n): issue is zod.$ZodRawIssue<zod.$ZodIssueStringInvalidJWT> {\n return issue.format === 'jwt';\n}\nfunction parseStringInvalidJWT(\n issue: zod.$ZodRawIssue<zod.$ZodIssueStringInvalidJWT>,\n options: Pick<ErrorMapOptions, 'displayInvalidFormatDetails'> = {\n displayInvalidFormatDetails: false,\n }\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message:\n options.displayInvalidFormatDetails && issue.algorithm\n ? `invalid jwt/${issue.algorithm}`\n : `invalid jwt`,\n };\n}\n","import type { AbstractSyntaxTree } from './types.ts';\nimport type * as zod from 'zod/v4/core';\n\nexport function parseInvalidTypeIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidType>\n): AbstractSyntaxTree {\n let message = `expected ${issue.expected}`;\n\n // note: it's possible that issue.input is not defined\n if ('input' in issue) {\n message += `, received ${getTypeName(issue.input)}`;\n }\n\n return {\n type: issue.code,\n path: issue.path,\n message,\n };\n}\n\nexport function getTypeName(value: unknown): string {\n if (typeof value === 'object') {\n if (value === null) {\n return 'null';\n }\n if (value === undefined) {\n return 'undefined';\n }\n if (Array.isArray(value)) {\n return 'array';\n }\n if (value instanceof Date) {\n return 'date';\n }\n if (value instanceof RegExp) {\n return 'regexp';\n }\n if (value instanceof Map) {\n return 'map';\n }\n if (value instanceof Set) {\n return 'set';\n }\n if (value instanceof Error) {\n return 'error';\n }\n if (value instanceof Function) {\n return 'function';\n }\n return 'object';\n }\n\n return typeof value;\n}\n","import type * as zod from 'zod/v4/core';\nimport type { AbstractSyntaxTree } from './types.ts';\n\nexport function parseInvalidUnionIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidUnion>\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message: issue.message ?? 'Invalid input',\n };\n}\n","import type { util } from 'zod/v4/core';\n\nexport function stringifySymbol(symbol: symbol): string {\n return symbol.description ?? '';\n}\n\nexport type StringifyValueOptions = {\n wrapStringValueInQuote?: boolean;\n localization?: boolean | Intl.LocalesArgument;\n};\n\nexport function stringify(\n value: util.Primitive | Date,\n options: StringifyValueOptions = {}\n): string {\n switch (typeof value) {\n case 'symbol':\n return stringifySymbol(value);\n case 'bigint':\n case 'number': {\n switch (options.localization) {\n case true:\n return value.toLocaleString();\n case false:\n return value.toString();\n default:\n return value.toLocaleString(options.localization);\n }\n }\n case 'string': {\n if (options.wrapStringValueInQuote) {\n return `\"${value}\"`;\n }\n return value;\n }\n default: {\n if (value instanceof Date) {\n switch (options.localization) {\n case true:\n return value.toLocaleString();\n case false:\n return value.toISOString();\n default:\n return value.toLocaleString(options.localization);\n }\n }\n return String(value);\n }\n }\n}\n","import { stringify } from './stringify.ts';\nimport type { util } from 'zod/v4/core';\n\nexport type JoinValuesOptions = {\n separator: string;\n lastSeparator?: string;\n wrapStringValuesInQuote?: boolean;\n maxValuesToDisplay?: number;\n};\n\nexport function joinValues(\n values: Array<util.Primitive>,\n options: JoinValuesOptions\n): string {\n const valuesToDisplay = (\n options.maxValuesToDisplay\n ? values.slice(0, options.maxValuesToDisplay)\n : values\n ).map((value) => {\n return stringify(value, {\n wrapStringValueInQuote: options.wrapStringValuesInQuote,\n });\n });\n\n // add remaining values count (if any)\n // this is to avoid displaying too many values in the error message\n // and to keep the message concise\n // e.g. `\"foo\", \"bar\", \"baz\" or 3 more value(s)`\n if (valuesToDisplay.length < values.length) {\n valuesToDisplay.push(\n `${values.length - valuesToDisplay.length} more value(s)`\n );\n }\n\n return valuesToDisplay.reduce<string>((acc, value, index) => {\n if (index > 0) {\n if (index === valuesToDisplay.length - 1 && options.lastSeparator) {\n acc += options.lastSeparator;\n } else {\n acc += options.separator;\n }\n }\n\n acc += value;\n\n return acc;\n }, '');\n}\n","import { joinValues } from '../../utils/joinValues.ts';\nimport { stringify } from '../../utils/stringify.ts';\nimport type { AbstractSyntaxTree, ErrorMapOptions } from './types.ts';\nimport type * as zod from 'zod/v4/core';\n\nexport function parseInvalidValueIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidValue>,\n options: Pick<\n ErrorMapOptions,\n | 'allowedValuesSeparator'\n | 'maxAllowedValuesToDisplay'\n | 'wrapAllowedValuesInQuote'\n | 'allowedValuesLastSeparator'\n >\n): AbstractSyntaxTree {\n let message: string;\n\n if (issue.values.length === 0) {\n message = 'invalid value';\n } else if (issue.values.length === 1) {\n const valueStr = stringify(issue.values[0], {\n wrapStringValueInQuote: true,\n });\n message = `expected value to be ${valueStr}`;\n } else {\n const valuesStr = joinValues(issue.values, {\n separator: options.allowedValuesSeparator,\n lastSeparator: options.allowedValuesLastSeparator,\n wrapStringValuesInQuote: options.wrapAllowedValuesInQuote,\n maxValuesToDisplay: options.maxAllowedValuesToDisplay,\n });\n message = `expected value to be one of ${valuesStr}`;\n }\n\n return {\n type: issue.code,\n path: issue.path,\n message,\n };\n}\n","import type * as zod from 'zod/v4/core';\nimport type { AbstractSyntaxTree } from './types.ts';\n\nexport function parseNotMultipleOfIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueNotMultipleOf>\n): AbstractSyntaxTree {\n return {\n type: issue.code,\n path: issue.path,\n message: `expected multiple of ${issue.divisor}`,\n };\n}\n","import { stringify } from '../../utils/stringify.ts';\nimport type { AbstractSyntaxTree, ErrorMapOptions } from './types.ts';\nimport type * as zod from 'zod/v4/core';\n\nexport function parseTooBigIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueTooBig>,\n options: Pick<ErrorMapOptions, 'dateLocalization' | 'numberLocalization'>\n): AbstractSyntaxTree {\n const maxValueStr =\n issue.origin === 'date'\n ? stringify(new Date(issue.maximum as number), {\n localization: options.dateLocalization,\n })\n : stringify(issue.maximum, {\n localization: options.numberLocalization,\n });\n\n switch (issue.origin) {\n case 'number':\n case 'int':\n case 'bigint': {\n return {\n type: issue.code,\n path: issue.path,\n message: `number must be less than${\n issue.inclusive ? ' or equal to' : ''\n } ${maxValueStr}`,\n };\n }\n case 'string': {\n return {\n type: issue.code,\n path: issue.path,\n message: `string must contain at most ${maxValueStr} character(s)`,\n };\n }\n case 'date': {\n return {\n type: issue.code,\n path: issue.path,\n message: `date must be ${\n issue.inclusive ? 'prior or equal to' : 'prior to'\n } \"${maxValueStr}\"`,\n };\n }\n case 'array': {\n return {\n type: issue.code,\n path: issue.path,\n message: `array must contain at most ${maxValueStr} item(s)`,\n };\n }\n case 'set': {\n return {\n type: issue.code,\n path: issue.path,\n message: `set must contain at most ${maxValueStr} item(s)`,\n };\n }\n case 'file': {\n return {\n type: issue.code,\n path: issue.path,\n message: `file must not exceed ${maxValueStr} byte(s) in size`,\n };\n }\n default:\n return {\n type: issue.code,\n path: issue.path,\n message: `value must be less than${\n issue.inclusive ? ' or equal to' : ''\n } ${maxValueStr}`,\n };\n }\n}\n","import { stringify } from '../../utils/stringify.ts';\nimport type * as zod from 'zod/v4/core';\nimport type { AbstractSyntaxTree, ErrorMapOptions } from './types.ts';\n\nexport function parseTooSmallIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueTooSmall>,\n options: Pick<ErrorMapOptions, 'dateLocalization' | 'numberLocalization'>\n): AbstractSyntaxTree {\n const minValueStr =\n issue.origin === 'date'\n ? stringify(new Date(issue.minimum as number), {\n localization: options.dateLocalization,\n })\n : stringify(issue.minimum, {\n localization: options.numberLocalization,\n });\n\n switch (issue.origin) {\n case 'number':\n case 'int':\n case 'bigint': {\n return {\n type: issue.code,\n path: issue.path,\n message: `number must be greater than${\n issue.inclusive ? ' or equal to' : ''\n } ${minValueStr}`,\n };\n }\n case 'date': {\n return {\n type: issue.code,\n path: issue.path,\n message: `date must be ${\n issue.inclusive ? 'later or equal to' : 'later to'\n } \"${minValueStr}\"`,\n };\n }\n case 'string': {\n return {\n type: issue.code,\n path: issue.path,\n message: `string must contain at least ${minValueStr} character(s)`,\n };\n }\n case 'array': {\n return {\n type: issue.code,\n path: issue.path,\n message: `array must contain at least ${minValueStr} item(s)`,\n };\n }\n case 'set': {\n return {\n type: issue.code,\n path: issue.path,\n message: `set must contain at least ${minValueStr} item(s)`,\n };\n }\n case 'file': {\n return {\n type: issue.code,\n path: issue.path,\n message: `file must be at least ${minValueStr} byte(s) in size`,\n };\n }\n default:\n return {\n type: issue.code,\n path: issue.path,\n message: `value must be greater than${\n issue.inclusive ? ' or equal to' : ''\n } ${minValueStr}`,\n };\n }\n}\n","import { joinValues } from '../../utils/joinValues.ts';\nimport type * as zod from 'zod/v4/core';\nimport type { AbstractSyntaxTree, ErrorMapOptions } from './types.ts';\n\nexport function parseUnrecognizedKeysIssue(\n issue: zod.$ZodRawIssue<zod.$ZodIssueUnrecognizedKeys>,\n options: Pick<\n ErrorMapOptions,\n | 'unrecognizedKeysSeparator'\n | 'unrecognizedKeysLastSeparator'\n | 'wrapUnrecognizedKeysInQuote'\n | 'maxUnrecognizedKeysToDisplay'\n >\n): AbstractSyntaxTree {\n const keysStr = joinValues(issue.keys, {\n separator: options.unrecognizedKeysSeparator,\n lastSeparator: options.unrecognizedKeysLastSeparator,\n wrapStringValuesInQuote: options.wrapUnrecognizedKeysInQuote,\n maxValuesToDisplay: options.maxUnrecognizedKeysToDisplay,\n });\n\n return {\n type: issue.code,\n path: issue.path,\n message: `unrecognized key(s) ${keysStr} in object`,\n };\n}\n","import { parseCustomIssue } from './custom.ts';\nimport { parseInvalidElementIssue } from './invalidElement.ts';\nimport { parseInvalidKeyIssue } from './invalidKey.ts';\nimport { parseInvalidStringFormatIssue } from './invalidStringFormat.ts';\nimport { parseInvalidTypeIssue } from './invalidType.ts';\nimport { parseInvalidUnionIssue } from './invalidUnion.ts';\nimport { parseInvalidValueIssue } from './invalidValue.ts';\nimport { parseNotMultipleOfIssue } from './notMultipleOf.ts';\nimport { parseTooBigIssue } from './tooBig.ts';\nimport { parseTooSmallIssue } from './tooSmall.ts';\nimport { parseUnrecognizedKeysIssue } from './unrecognizedKeys.ts';\nimport type {\n AbstractSyntaxTree,\n ErrorMapOptions,\n IssueType,\n} from './types.ts';\nimport type * as zod from 'zod/v4/core';\n\ntype IssueParsers = {\n [IssueCode in IssueType]: (\n issue: zod.$ZodRawIssue<Extract<zod.$ZodIssue, { code: IssueCode }>>,\n options: ErrorMapOptions\n ) => AbstractSyntaxTree;\n};\n\nconst issueParsers: IssueParsers = {\n invalid_type: parseInvalidTypeIssue,\n too_big: parseTooBigIssue,\n too_small: parseTooSmallIssue,\n invalid_format: parseInvalidStringFormatIssue,\n invalid_value: parseInvalidValueIssue,\n invalid_element: parseInvalidElementIssue,\n not_multiple_of: parseNotMultipleOfIssue,\n unrecognized_keys: parseUnrecognizedKeysIssue,\n invalid_key: parseInvalidKeyIssue,\n custom: parseCustomIssue,\n invalid_union: parseInvalidUnionIssue,\n};\n\nexport const defaultErrorMapOptions = {\n displayInvalidFormatDetails: false,\n allowedValuesSeparator: ', ',\n allowedValuesLastSeparator: ' or ',\n wrapAllowedValuesInQuote: true,\n maxAllowedValuesToDisplay: 10,\n unrecognizedKeysSeparator: ', ',\n unrecognizedKeysLastSeparator: ' and ',\n wrapUnrecognizedKeysInQuote: true,\n maxUnrecognizedKeysToDisplay: 5,\n dateLocalization: true,\n numberLocalization: true,\n} as const satisfies ErrorMapOptions;\n\nexport function createErrorMap(\n partialOptions: Partial<ErrorMapOptions> = {}\n): zod.$ZodErrorMap<zod.$ZodIssue> {\n // fill-in default options\n const options = {\n ...defaultErrorMapOptions,\n ...partialOptions,\n };\n\n const errorMap: zod.$ZodErrorMap<zod.$ZodIssue> = (issue) => {\n if (issue.code === undefined) {\n // TODO: handle this case\n return 'Not supported issue type';\n }\n\n const parseFunc = issueParsers[issue.code] as (\n iss: typeof issue,\n opts: ErrorMapOptions\n ) => AbstractSyntaxTree;\n const ast = parseFunc(issue, options);\n return ast.message;\n };\n\n return errorMap;\n}\n","export type NonEmptyArray<T> = [T, ...T[]];\n\nexport function isNonEmptyArray<T>(value: T[]): value is NonEmptyArray<T> {\n return value.length !== 0;\n}\n","import { stringifySymbol } from './stringify.ts';\nimport type { NonEmptyArray } from './NonEmptyArray.ts';\n\n/**\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#identifiers\n */\nconst identifierRegex = /[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*/u;\n\nexport function joinPath(path: NonEmptyArray<PropertyKey>): string {\n if (path.length === 1) {\n let propertyKey = path[0];\n\n if (typeof propertyKey === 'symbol') {\n propertyKey = stringifySymbol(propertyKey);\n }\n\n return propertyKey.toString() || '\"\"';\n }\n\n return path.reduce<string>((acc, propertyKey) => {\n // handle numeric indices\n if (typeof propertyKey === 'number') {\n return acc + '[' + propertyKey.toString() + ']';\n }\n\n // handle symbols\n if (typeof propertyKey === 'symbol') {\n propertyKey = stringifySymbol(propertyKey);\n }\n\n // handle quoted values\n if (propertyKey.includes('\"')) {\n return acc + '[\"' + escapeQuotes(propertyKey) + '\"]';\n }\n\n // handle special characters\n if (!identifierRegex.test(propertyKey)) {\n return acc + '[\"' + propertyKey + '\"]';\n }\n\n // handle normal values\n const separator = acc.length === 0 ? '' : '.';\n return acc + separator + propertyKey;\n }, '');\n}\n\nfunction escapeQuotes(str: string): string {\n return str.replace(/\"/g, '\\\\\"');\n}\n","export function titleCase(value: string): string {\n if (value.length === 0) {\n return value;\n }\n return value.charAt(0).toUpperCase() + value.slice(1);\n}\n","import { joinPath } from '../utils/joinPath.ts';\nimport { isNonEmptyArray, type NonEmptyArray } from '../utils/NonEmptyArray.ts';\nimport { titleCase } from '../utils/titleCase.ts';\nimport type * as zod from 'zod/v4/core';\n\nexport type ZodIssue = zod.$ZodIssue;\n\nexport type MessageBuilder = (issues: NonEmptyArray<ZodIssue>) => string;\n\nexport type MessageBuilderOptions = {\n prefix: string | null | undefined;\n prefixSeparator: string;\n maxIssuesInMessage: number;\n issueSeparator: string;\n unionSeparator: string;\n includePath: boolean;\n forceTitleCase: boolean;\n};\n\nexport const defaultMessageBuilderOptions: MessageBuilderOptions & {\n prefix: string;\n} = {\n prefix: 'Validation error',\n prefixSeparator: ': ',\n maxIssuesInMessage: 99, // I've got 99 problems but the b$tch ain't one\n unionSeparator: ' or ',\n issueSeparator: '; ',\n includePath: true,\n forceTitleCase: true,\n};\n\nexport function createMessageBuilder(\n partialOptions: Partial<MessageBuilderOptions> = {}\n): MessageBuilder {\n const options = {\n ...defaultMessageBuilderOptions,\n ...partialOptions,\n };\n\n return function messageBuilder(issues) {\n const message = issues\n // limit max number of issues printed in the reason section\n .slice(0, options.maxIssuesInMessage)\n // format error message\n .map((issue) => mapIssue(issue, options))\n // concat as string\n .join(options.issueSeparator);\n\n return conditionallyPrefixMessage(message, options);\n };\n}\n\nfunction mapIssue(\n issue: zod.$ZodIssue,\n options: MessageBuilderOptions\n): string {\n if (issue.code === 'invalid_union' && isNonEmptyArray(issue.errors)) {\n const individualMessages = issue.errors.map((issues) =>\n issues\n .map((subIssue) =>\n mapIssue(\n {\n ...subIssue,\n path: issue.path.concat(subIssue.path),\n },\n options\n )\n )\n .join(options.issueSeparator)\n );\n\n // deduplicate messages\n // and join them with the union separator\n // to create a single message for the invalid union issue\n return Array.from(new Set(individualMessages)).join(options.unionSeparator);\n }\n\n const buf = [];\n\n if (options.forceTitleCase) {\n buf.push(titleCase(issue.message));\n } else {\n buf.push(issue.message);\n }\n\n pathCondition: if (\n options.includePath &&\n issue.path !== undefined &&\n isNonEmptyArray(issue.path)\n ) {\n // handle array indices\n if (issue.path.length === 1) {\n const identifier = issue.path[0];\n\n if (typeof identifier === 'number') {\n buf.push(` at index ${identifier}`);\n break pathCondition;\n }\n }\n\n buf.push(` at \"${joinPath(issue.path)}\"`);\n }\n\n return buf.join('');\n}\n\nfunction conditionallyPrefixMessage(\n message: string,\n options: Pick<MessageBuilderOptions, 'prefix' | 'prefixSeparator'>\n): string {\n if (options.prefix != null) {\n if (message.length > 0) {\n return [options.prefix, message].join(options.prefixSeparator);\n }\n\n return options.prefix;\n }\n\n if (message.length > 0) {\n return message;\n }\n\n // if both reason and prefix are empty, return default prefix\n // to avoid having an empty error message\n return defaultMessageBuilderOptions.prefix;\n}\n","import { isNonEmptyArray } from '../utils/NonEmptyArray.ts';\nimport { fromError } from './fromError.ts';\nimport { isZodErrorLike } from './isZodErrorLike.ts';\nimport {\n createMessageBuilder,\n type MessageBuilderOptions,\n type MessageBuilder,\n} from './MessageBuilder.ts';\nimport { ValidationError } from './ValidationError.ts';\nimport type * as zod from 'zod/v4/core';\n\nexport type ZodError = zod.$ZodError;\n\nexport type FromZodErrorOptions =\n | {\n messageBuilder: MessageBuilder;\n }\n // maintain backwards compatibility\n | Partial<MessageBuilderOptions>;\n\nexport function fromZodError(\n zodError: ZodError,\n options: FromZodErrorOptions = {}\n): ValidationError {\n // perform runtime check to ensure the input is a ZodError\n // why? because people have been historically using this function incorrectly\n if (!isZodErrorLike(zodError)) {\n throw new TypeError(\n `Invalid zodError param; expected instance of ZodError. Did you mean to use the \"${fromError.name}\" method instead?`\n );\n }\n\n return fromZodErrorWithoutRuntimeCheck(zodError, options);\n}\n\nexport function fromZodErrorWithoutRuntimeCheck(\n zodError: ZodError,\n options: FromZodErrorOptions = {}\n): ValidationError {\n const zodIssues = zodError.issues;\n\n let message: string;\n if (isNonEmptyArray(zodIssues)) {\n const messageBuilder = createMessageBuilderFromOptions(options);\n message = messageBuilder(zodIssues);\n } else {\n message = zodError.message;\n }\n\n return new ValidationError(message, { cause: zodError });\n}\n\nfunction createMessageBuilderFromOptions(\n options: FromZodErrorOptions\n): MessageBuilder {\n if ('messageBuilder' in options) {\n return options.messageBuilder;\n }\n\n return createMessageBuilder(options);\n}\n","import { ValidationError } from './ValidationError.ts';\nimport { isZodErrorLike } from './isZodErrorLike.ts';\nimport {\n fromZodErrorWithoutRuntimeCheck,\n type FromZodErrorOptions,\n} from './fromZodError.ts';\n\nexport const toValidationError =\n (options: FromZodErrorOptions = {}) =>\n (err: unknown): ValidationError => {\n if (isZodErrorLike(err)) {\n return fromZodErrorWithoutRuntimeCheck(err, options);\n }\n\n if (err instanceof Error) {\n return new ValidationError(err.message, { cause: err });\n }\n\n return new ValidationError('Unknown error');\n };\n","import { toValidationError } from './toValidationError.ts';\nimport type { FromZodErrorOptions } from './fromZodError.ts';\nimport type { ValidationError } from './ValidationError.ts';\n\n/**\n * This function is a non-curried version of `toValidationError`\n */\nexport function fromError(\n err: unknown,\n options: FromZodErrorOptions = {}\n): ValidationError {\n return toValidationError(options)(err);\n}\n","import * as zod from 'zod/v4/core';\n\nimport {\n type MessageBuilder,\n type MessageBuilderOptions,\n type ZodIssue,\n createMessageBuilder,\n} from './MessageBuilder.ts';\nimport { ValidationError } from './ValidationError.ts';\n\nexport type FromZodIssueOptions =\n | {\n messageBuilder: MessageBuilder;\n }\n // maintain backwards compatibility\n | Partial<Omit<MessageBuilderOptions, 'maxIssuesInMessage'>>;\n\nexport function fromZodIssue(\n issue: ZodIssue,\n options: FromZodIssueOptions = {}\n): ValidationError {\n const messageBuilder = createMessageBuilderFromOptions(options);\n const message = messageBuilder([issue]);\n\n return new ValidationError(message, {\n cause: new zod.$ZodRealError([issue]),\n });\n}\n\nfunction createMessageBuilderFromOptions(\n options: FromZodIssueOptions\n): MessageBuilder {\n if ('messageBuilder' in options) {\n return options.messageBuilder;\n }\n\n return createMessageBuilder(options);\n}\n"],"mappings":";AAEO,SAAS,eAAe,KAAoC;AACjE,SACE,eAAe,UACf,UAAU,QACT,IAAI,SAAS,cAAc,IAAI,SAAS,gBACzC,YAAY,OACZ,MAAM,QAAQ,IAAI,MAAM;AAE5B;;;ACPO,IAAM,4BAA4B;AASlC,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC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DED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
| 3 |
+
if (k2 === undefined) k2 = k;
|
| 4 |
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
| 5 |
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
| 6 |
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
| 7 |
+
}
|
| 8 |
+
Object.defineProperty(o, k2, desc);
|
| 9 |
+
}) : (function(o, m, k, k2) {
|
| 10 |
+
if (k2 === undefined) k2 = k;
|
| 11 |
+
o[k2] = m[k];
|
| 12 |
+
}));
|
| 13 |
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
| 14 |
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
| 15 |
+
}) : function(o, v) {
|
| 16 |
+
o["default"] = v;
|
| 17 |
+
});
|
| 18 |
+
var __importStar = (this && this.__importStar) || function (mod) {
|
| 19 |
+
if (mod && mod.__esModule) return mod;
|
| 20 |
+
var result = {};
|
| 21 |
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
| 22 |
+
__setModuleDefault(result, mod);
|
| 23 |
+
return result;
|
| 24 |
+
};
|
| 25 |
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
| 26 |
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
| 27 |
+
};
|
| 28 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 29 |
+
exports.z = void 0;
|
| 30 |
+
const z = __importStar(require("../v4/mini/external.cjs"));
|
| 31 |
+
exports.z = z;
|
| 32 |
+
__exportStar(require("../v4/mini/external.cjs"), exports);
|
node_modules/zod/mini/index.d.cts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as z from "../v4/mini/external.cjs";
|
| 2 |
+
export * from "../v4/mini/external.cjs";
|
| 3 |
+
export { z };
|
node_modules/zod/mini/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as z from "../v4/mini/external.js";
|
| 2 |
+
export * from "../v4/mini/external.js";
|
| 3 |
+
export { z };
|
node_modules/zod/mini/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as z from "../v4/mini/external.js";
|
| 2 |
+
export * from "../v4/mini/external.js";
|
| 3 |
+
export { z };
|
node_modules/zod/mini/package.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"type": "module",
|
| 3 |
+
"main": "./index.cjs",
|
| 4 |
+
"module": "./index.js",
|
| 5 |
+
"types": "./index.d.cts",
|
| 6 |
+
"sideEffects": false
|
| 7 |
+
}
|
node_modules/zod/package.json
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "zod",
|
| 3 |
+
"version": "4.4.3",
|
| 4 |
+
"type": "module",
|
| 5 |
+
"license": "MIT",
|
| 6 |
+
"author": "Colin McDonnell <zod@colinhacks.com>",
|
| 7 |
+
"description": "TypeScript-first schema declaration and validation library with static type inference",
|
| 8 |
+
"homepage": "https://zod.dev",
|
| 9 |
+
"llms": "https://zod.dev/llms.txt",
|
| 10 |
+
"llmsFull": "https://zod.dev/llms-full.txt",
|
| 11 |
+
"mcpServer": "https://mcp.inkeep.com/zod/mcp",
|
| 12 |
+
"funding": "https://github.com/sponsors/colinhacks",
|
| 13 |
+
"sideEffects": false,
|
| 14 |
+
"files": [
|
| 15 |
+
"src",
|
| 16 |
+
"**/*.js",
|
| 17 |
+
"**/*.mjs",
|
| 18 |
+
"**/*.cjs",
|
| 19 |
+
"**/*.d.ts",
|
| 20 |
+
"**/*.d.mts",
|
| 21 |
+
"**/*.d.cts",
|
| 22 |
+
"**/package.json"
|
| 23 |
+
],
|
| 24 |
+
"keywords": [
|
| 25 |
+
"typescript",
|
| 26 |
+
"schema",
|
| 27 |
+
"validation",
|
| 28 |
+
"type",
|
| 29 |
+
"inference"
|
| 30 |
+
],
|
| 31 |
+
"main": "./index.cjs",
|
| 32 |
+
"types": "./index.d.cts",
|
| 33 |
+
"module": "./index.js",
|
| 34 |
+
"zshy": {
|
| 35 |
+
"exports": {
|
| 36 |
+
"./package.json": "./package.json",
|
| 37 |
+
".": "./src/index.ts",
|
| 38 |
+
"./mini": "./src/mini/index.ts",
|
| 39 |
+
"./locales": "./src/locales/index.ts",
|
| 40 |
+
"./v3": "./src/v3/index.ts",
|
| 41 |
+
"./v4": "./src/v4/index.ts",
|
| 42 |
+
"./v4-mini": "./src/v4-mini/index.ts",
|
| 43 |
+
"./v4/mini": "./src/v4/mini/index.ts",
|
| 44 |
+
"./v4/core": "./src/v4/core/index.ts",
|
| 45 |
+
"./v4/locales": "./src/v4/locales/index.ts",
|
| 46 |
+
"./v4/locales/*": "./src/v4/locales/*"
|
| 47 |
+
},
|
| 48 |
+
"conditions": {
|
| 49 |
+
"@zod/source": "src"
|
| 50 |
+
}
|
| 51 |
+
},
|
| 52 |
+
"exports": {
|
| 53 |
+
"./package.json": "./package.json",
|
| 54 |
+
".": {
|
| 55 |
+
"@zod/source": "./src/index.ts",
|
| 56 |
+
"types": "./index.d.cts",
|
| 57 |
+
"import": "./index.js",
|
| 58 |
+
"require": "./index.cjs"
|
| 59 |
+
},
|
| 60 |
+
"./mini": {
|
| 61 |
+
"@zod/source": "./src/mini/index.ts",
|
| 62 |
+
"types": "./mini/index.d.cts",
|
| 63 |
+
"import": "./mini/index.js",
|
| 64 |
+
"require": "./mini/index.cjs"
|
| 65 |
+
},
|
| 66 |
+
"./locales": {
|
| 67 |
+
"@zod/source": "./src/locales/index.ts",
|
| 68 |
+
"types": "./locales/index.d.cts",
|
| 69 |
+
"import": "./locales/index.js",
|
| 70 |
+
"require": "./locales/index.cjs"
|
| 71 |
+
},
|
| 72 |
+
"./v3": {
|
| 73 |
+
"@zod/source": "./src/v3/index.ts",
|
| 74 |
+
"types": "./v3/index.d.cts",
|
| 75 |
+
"import": "./v3/index.js",
|
| 76 |
+
"require": "./v3/index.cjs"
|
| 77 |
+
},
|
| 78 |
+
"./v4": {
|
| 79 |
+
"@zod/source": "./src/v4/index.ts",
|
| 80 |
+
"types": "./v4/index.d.cts",
|
| 81 |
+
"import": "./v4/index.js",
|
| 82 |
+
"require": "./v4/index.cjs"
|
| 83 |
+
},
|
| 84 |
+
"./v4-mini": {
|
| 85 |
+
"@zod/source": "./src/v4-mini/index.ts",
|
| 86 |
+
"types": "./v4-mini/index.d.cts",
|
| 87 |
+
"import": "./v4-mini/index.js",
|
| 88 |
+
"require": "./v4-mini/index.cjs"
|
| 89 |
+
},
|
| 90 |
+
"./v4/mini": {
|
| 91 |
+
"@zod/source": "./src/v4/mini/index.ts",
|
| 92 |
+
"types": "./v4/mini/index.d.cts",
|
| 93 |
+
"import": "./v4/mini/index.js",
|
| 94 |
+
"require": "./v4/mini/index.cjs"
|
| 95 |
+
},
|
| 96 |
+
"./v4/core": {
|
| 97 |
+
"@zod/source": "./src/v4/core/index.ts",
|
| 98 |
+
"types": "./v4/core/index.d.cts",
|
| 99 |
+
"import": "./v4/core/index.js",
|
| 100 |
+
"require": "./v4/core/index.cjs"
|
| 101 |
+
},
|
| 102 |
+
"./v4/locales": {
|
| 103 |
+
"@zod/source": "./src/v4/locales/index.ts",
|
| 104 |
+
"types": "./v4/locales/index.d.cts",
|
| 105 |
+
"import": "./v4/locales/index.js",
|
| 106 |
+
"require": "./v4/locales/index.cjs"
|
| 107 |
+
},
|
| 108 |
+
"./v4/locales/*": {
|
| 109 |
+
"@zod/source": "./src/v4/locales/*",
|
| 110 |
+
"types": "./v4/locales/*",
|
| 111 |
+
"import": "./v4/locales/*",
|
| 112 |
+
"require": "./v4/locales/*"
|
| 113 |
+
}
|
| 114 |
+
},
|
| 115 |
+
"repository": {
|
| 116 |
+
"type": "git",
|
| 117 |
+
"url": "git+https://github.com/colinhacks/zod.git"
|
| 118 |
+
},
|
| 119 |
+
"bugs": {
|
| 120 |
+
"url": "https://github.com/colinhacks/zod/issues"
|
| 121 |
+
},
|
| 122 |
+
"support": {
|
| 123 |
+
"backing": {
|
| 124 |
+
"npm-funding": true
|
| 125 |
+
}
|
| 126 |
+
},
|
| 127 |
+
"scripts": {
|
| 128 |
+
"clean": "git clean -xdf . -e node_modules",
|
| 129 |
+
"build": "zshy --project tsconfig.build.json",
|
| 130 |
+
"postbuild": "tsx ../../scripts/write-stub-package-jsons.ts && pnpm biome check --write .",
|
| 131 |
+
"test:watch": "pnpm vitest",
|
| 132 |
+
"test": "pnpm vitest run",
|
| 133 |
+
"prepublishOnly": "tsx ../../scripts/check-versions.ts"
|
| 134 |
+
}
|
| 135 |
+
}
|
node_modules/zod/src/index.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as z from "./v4/classic/external.js";
|
| 2 |
+
export * from "./v4/classic/external.js";
|
| 3 |
+
export { z };
|
| 4 |
+
export default z;
|
node_modules/zod/src/locales/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export * from "../v4/locales/index.js";
|
node_modules/zod/src/mini/index.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as z from "../v4/mini/external.js";
|
| 2 |
+
export * from "../v4/mini/external.js";
|
| 3 |
+
export { z };
|
node_modules/zod/src/v3/ZodError.ts
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Primitive } from "./helpers/typeAliases.js";
|
| 2 |
+
import { util, type ZodParsedType } from "./helpers/util.js";
|
| 3 |
+
import type { TypeOf, ZodType } from "./index.js";
|
| 4 |
+
|
| 5 |
+
type allKeys<T> = T extends any ? keyof T : never;
|
| 6 |
+
|
| 7 |
+
export type inferFlattenedErrors<T extends ZodType<any, any, any>, U = string> = typeToFlattenedError<TypeOf<T>, U>;
|
| 8 |
+
export type typeToFlattenedError<T, U = string> = {
|
| 9 |
+
formErrors: U[];
|
| 10 |
+
fieldErrors: {
|
| 11 |
+
[P in allKeys<T>]?: U[];
|
| 12 |
+
};
|
| 13 |
+
};
|
| 14 |
+
|
| 15 |
+
export const ZodIssueCode = util.arrayToEnum([
|
| 16 |
+
"invalid_type",
|
| 17 |
+
"invalid_literal",
|
| 18 |
+
"custom",
|
| 19 |
+
"invalid_union",
|
| 20 |
+
"invalid_union_discriminator",
|
| 21 |
+
"invalid_enum_value",
|
| 22 |
+
"unrecognized_keys",
|
| 23 |
+
"invalid_arguments",
|
| 24 |
+
"invalid_return_type",
|
| 25 |
+
"invalid_date",
|
| 26 |
+
"invalid_string",
|
| 27 |
+
"too_small",
|
| 28 |
+
"too_big",
|
| 29 |
+
"invalid_intersection_types",
|
| 30 |
+
"not_multiple_of",
|
| 31 |
+
"not_finite",
|
| 32 |
+
]);
|
| 33 |
+
|
| 34 |
+
export type ZodIssueCode = keyof typeof ZodIssueCode;
|
| 35 |
+
|
| 36 |
+
export type ZodIssueBase = {
|
| 37 |
+
path: (string | number)[];
|
| 38 |
+
message?: string | undefined;
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
export interface ZodInvalidTypeIssue extends ZodIssueBase {
|
| 42 |
+
code: typeof ZodIssueCode.invalid_type;
|
| 43 |
+
expected: ZodParsedType;
|
| 44 |
+
received: ZodParsedType;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
export interface ZodInvalidLiteralIssue extends ZodIssueBase {
|
| 48 |
+
code: typeof ZodIssueCode.invalid_literal;
|
| 49 |
+
expected: unknown;
|
| 50 |
+
received: unknown;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
export interface ZodUnrecognizedKeysIssue extends ZodIssueBase {
|
| 54 |
+
code: typeof ZodIssueCode.unrecognized_keys;
|
| 55 |
+
keys: string[];
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
export interface ZodInvalidUnionIssue extends ZodIssueBase {
|
| 59 |
+
code: typeof ZodIssueCode.invalid_union;
|
| 60 |
+
unionErrors: ZodError[];
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
export interface ZodInvalidUnionDiscriminatorIssue extends ZodIssueBase {
|
| 64 |
+
code: typeof ZodIssueCode.invalid_union_discriminator;
|
| 65 |
+
options: Primitive[];
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
export interface ZodInvalidEnumValueIssue extends ZodIssueBase {
|
| 69 |
+
received: string | number;
|
| 70 |
+
code: typeof ZodIssueCode.invalid_enum_value;
|
| 71 |
+
options: (string | number)[];
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
export interface ZodInvalidArgumentsIssue extends ZodIssueBase {
|
| 75 |
+
code: typeof ZodIssueCode.invalid_arguments;
|
| 76 |
+
argumentsError: ZodError;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
export interface ZodInvalidReturnTypeIssue extends ZodIssueBase {
|
| 80 |
+
code: typeof ZodIssueCode.invalid_return_type;
|
| 81 |
+
returnTypeError: ZodError;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
export interface ZodInvalidDateIssue extends ZodIssueBase {
|
| 85 |
+
code: typeof ZodIssueCode.invalid_date;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
export type StringValidation =
|
| 89 |
+
| "email"
|
| 90 |
+
| "url"
|
| 91 |
+
| "emoji"
|
| 92 |
+
| "uuid"
|
| 93 |
+
| "nanoid"
|
| 94 |
+
| "regex"
|
| 95 |
+
| "cuid"
|
| 96 |
+
| "cuid2"
|
| 97 |
+
| "ulid"
|
| 98 |
+
| "datetime"
|
| 99 |
+
| "date"
|
| 100 |
+
| "time"
|
| 101 |
+
| "duration"
|
| 102 |
+
| "ip"
|
| 103 |
+
| "cidr"
|
| 104 |
+
| "base64"
|
| 105 |
+
| "jwt"
|
| 106 |
+
| "base64url"
|
| 107 |
+
| { includes: string; position?: number | undefined }
|
| 108 |
+
| { startsWith: string }
|
| 109 |
+
| { endsWith: string };
|
| 110 |
+
|
| 111 |
+
export interface ZodInvalidStringIssue extends ZodIssueBase {
|
| 112 |
+
code: typeof ZodIssueCode.invalid_string;
|
| 113 |
+
validation: StringValidation;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
export interface ZodTooSmallIssue extends ZodIssueBase {
|
| 117 |
+
code: typeof ZodIssueCode.too_small;
|
| 118 |
+
minimum: number | bigint;
|
| 119 |
+
inclusive: boolean;
|
| 120 |
+
exact?: boolean;
|
| 121 |
+
type: "array" | "string" | "number" | "set" | "date" | "bigint";
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
export interface ZodTooBigIssue extends ZodIssueBase {
|
| 125 |
+
code: typeof ZodIssueCode.too_big;
|
| 126 |
+
maximum: number | bigint;
|
| 127 |
+
inclusive: boolean;
|
| 128 |
+
exact?: boolean;
|
| 129 |
+
type: "array" | "string" | "number" | "set" | "date" | "bigint";
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
export interface ZodInvalidIntersectionTypesIssue extends ZodIssueBase {
|
| 133 |
+
code: typeof ZodIssueCode.invalid_intersection_types;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
export interface ZodNotMultipleOfIssue extends ZodIssueBase {
|
| 137 |
+
code: typeof ZodIssueCode.not_multiple_of;
|
| 138 |
+
multipleOf: number | bigint;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
export interface ZodNotFiniteIssue extends ZodIssueBase {
|
| 142 |
+
code: typeof ZodIssueCode.not_finite;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
export interface ZodCustomIssue extends ZodIssueBase {
|
| 146 |
+
code: typeof ZodIssueCode.custom;
|
| 147 |
+
params?: { [k: string]: any };
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
export type DenormalizedError = { [k: string]: DenormalizedError | string[] };
|
| 151 |
+
|
| 152 |
+
export type ZodIssueOptionalMessage =
|
| 153 |
+
| ZodInvalidTypeIssue
|
| 154 |
+
| ZodInvalidLiteralIssue
|
| 155 |
+
| ZodUnrecognizedKeysIssue
|
| 156 |
+
| ZodInvalidUnionIssue
|
| 157 |
+
| ZodInvalidUnionDiscriminatorIssue
|
| 158 |
+
| ZodInvalidEnumValueIssue
|
| 159 |
+
| ZodInvalidArgumentsIssue
|
| 160 |
+
| ZodInvalidReturnTypeIssue
|
| 161 |
+
| ZodInvalidDateIssue
|
| 162 |
+
| ZodInvalidStringIssue
|
| 163 |
+
| ZodTooSmallIssue
|
| 164 |
+
| ZodTooBigIssue
|
| 165 |
+
| ZodInvalidIntersectionTypesIssue
|
| 166 |
+
| ZodNotMultipleOfIssue
|
| 167 |
+
| ZodNotFiniteIssue
|
| 168 |
+
| ZodCustomIssue;
|
| 169 |
+
|
| 170 |
+
export type ZodIssue = ZodIssueOptionalMessage & {
|
| 171 |
+
fatal?: boolean | undefined;
|
| 172 |
+
message: string;
|
| 173 |
+
};
|
| 174 |
+
|
| 175 |
+
export const quotelessJson = (obj: any) => {
|
| 176 |
+
const json = JSON.stringify(obj, null, 2);
|
| 177 |
+
return json.replace(/"([^"]+)":/g, "$1:");
|
| 178 |
+
};
|
| 179 |
+
|
| 180 |
+
type recursiveZodFormattedError<T> = T extends [any, ...any[]]
|
| 181 |
+
? { [K in keyof T]?: ZodFormattedError<T[K]> }
|
| 182 |
+
: T extends any[]
|
| 183 |
+
? { [k: number]: ZodFormattedError<T[number]> }
|
| 184 |
+
: T extends object
|
| 185 |
+
? { [K in keyof T]?: ZodFormattedError<T[K]> }
|
| 186 |
+
: unknown;
|
| 187 |
+
|
| 188 |
+
export type ZodFormattedError<T, U = string> = {
|
| 189 |
+
_errors: U[];
|
| 190 |
+
} & recursiveZodFormattedError<NonNullable<T>>;
|
| 191 |
+
|
| 192 |
+
export type inferFormattedError<T extends ZodType<any, any, any>, U = string> = ZodFormattedError<TypeOf<T>, U>;
|
| 193 |
+
|
| 194 |
+
export class ZodError<T = any> extends Error {
|
| 195 |
+
issues: ZodIssue[] = [];
|
| 196 |
+
|
| 197 |
+
get errors() {
|
| 198 |
+
return this.issues;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
constructor(issues: ZodIssue[]) {
|
| 202 |
+
super();
|
| 203 |
+
|
| 204 |
+
const actualProto = new.target.prototype;
|
| 205 |
+
if (Object.setPrototypeOf) {
|
| 206 |
+
// eslint-disable-next-line ban/ban
|
| 207 |
+
Object.setPrototypeOf(this, actualProto);
|
| 208 |
+
} else {
|
| 209 |
+
(this as any).__proto__ = actualProto;
|
| 210 |
+
}
|
| 211 |
+
this.name = "ZodError";
|
| 212 |
+
this.issues = issues;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
format(): ZodFormattedError<T>;
|
| 216 |
+
format<U>(mapper: (issue: ZodIssue) => U): ZodFormattedError<T, U>;
|
| 217 |
+
format(_mapper?: any) {
|
| 218 |
+
const mapper: (issue: ZodIssue) => any =
|
| 219 |
+
_mapper ||
|
| 220 |
+
function (issue: ZodIssue) {
|
| 221 |
+
return issue.message;
|
| 222 |
+
};
|
| 223 |
+
const fieldErrors: ZodFormattedError<T> = { _errors: [] } as any;
|
| 224 |
+
const processError = (error: ZodError) => {
|
| 225 |
+
for (const issue of error.issues) {
|
| 226 |
+
if (issue.code === "invalid_union") {
|
| 227 |
+
issue.unionErrors.map(processError);
|
| 228 |
+
} else if (issue.code === "invalid_return_type") {
|
| 229 |
+
processError(issue.returnTypeError);
|
| 230 |
+
} else if (issue.code === "invalid_arguments") {
|
| 231 |
+
processError(issue.argumentsError);
|
| 232 |
+
} else if (issue.path.length === 0) {
|
| 233 |
+
(fieldErrors as any)._errors.push(mapper(issue));
|
| 234 |
+
} else {
|
| 235 |
+
let curr: any = fieldErrors;
|
| 236 |
+
let i = 0;
|
| 237 |
+
while (i < issue.path.length) {
|
| 238 |
+
const el = issue.path[i]!;
|
| 239 |
+
const terminal = i === issue.path.length - 1;
|
| 240 |
+
|
| 241 |
+
if (!terminal) {
|
| 242 |
+
curr[el] = curr[el] || { _errors: [] };
|
| 243 |
+
// if (typeof el === "string") {
|
| 244 |
+
// curr[el] = curr[el] || { _errors: [] };
|
| 245 |
+
// } else if (typeof el === "number") {
|
| 246 |
+
// const errorArray: any = [];
|
| 247 |
+
// errorArray._errors = [];
|
| 248 |
+
// curr[el] = curr[el] || errorArray;
|
| 249 |
+
// }
|
| 250 |
+
} else {
|
| 251 |
+
curr[el] = curr[el] || { _errors: [] };
|
| 252 |
+
curr[el]._errors.push(mapper(issue));
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
curr = curr[el];
|
| 256 |
+
i++;
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
};
|
| 261 |
+
|
| 262 |
+
processError(this);
|
| 263 |
+
return fieldErrors;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
static create = (issues: ZodIssue[]) => {
|
| 267 |
+
const error = new ZodError(issues);
|
| 268 |
+
return error;
|
| 269 |
+
};
|
| 270 |
+
|
| 271 |
+
static assert(value: unknown): asserts value is ZodError {
|
| 272 |
+
if (!(value instanceof ZodError)) {
|
| 273 |
+
throw new Error(`Not a ZodError: ${value}`);
|
| 274 |
+
}
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
override toString() {
|
| 278 |
+
return this.message;
|
| 279 |
+
}
|
| 280 |
+
override get message() {
|
| 281 |
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
get isEmpty(): boolean {
|
| 285 |
+
return this.issues.length === 0;
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
addIssue = (sub: ZodIssue) => {
|
| 289 |
+
this.issues = [...this.issues, sub];
|
| 290 |
+
};
|
| 291 |
+
|
| 292 |
+
addIssues = (subs: ZodIssue[] = []) => {
|
| 293 |
+
this.issues = [...this.issues, ...subs];
|
| 294 |
+
};
|
| 295 |
+
|
| 296 |
+
flatten(): typeToFlattenedError<T>;
|
| 297 |
+
flatten<U>(mapper?: (issue: ZodIssue) => U): typeToFlattenedError<T, U>;
|
| 298 |
+
flatten<U = string>(mapper: (issue: ZodIssue) => U = (issue: ZodIssue) => issue.message as any): any {
|
| 299 |
+
const fieldErrors: any = Object.create(null);
|
| 300 |
+
const formErrors: U[] = [];
|
| 301 |
+
for (const sub of this.issues) {
|
| 302 |
+
if (sub.path.length > 0) {
|
| 303 |
+
const firstEl = sub.path[0]!;
|
| 304 |
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
| 305 |
+
fieldErrors[firstEl].push(mapper(sub));
|
| 306 |
+
} else {
|
| 307 |
+
formErrors.push(mapper(sub));
|
| 308 |
+
}
|
| 309 |
+
}
|
| 310 |
+
return { formErrors, fieldErrors };
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
get formErrors() {
|
| 314 |
+
return this.flatten();
|
| 315 |
+
}
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
type stripPath<T extends object> = T extends any ? util.OmitKeys<T, "path"> : never;
|
| 319 |
+
|
| 320 |
+
export type IssueData = stripPath<ZodIssueOptionalMessage> & {
|
| 321 |
+
path?: (string | number)[];
|
| 322 |
+
fatal?: boolean | undefined;
|
| 323 |
+
};
|
| 324 |
+
|
| 325 |
+
export type ErrorMapCtx = {
|
| 326 |
+
defaultError: string;
|
| 327 |
+
data: any;
|
| 328 |
+
};
|
| 329 |
+
|
| 330 |
+
export type ZodErrorMap = (issue: ZodIssueOptionalMessage, _ctx: ErrorMapCtx) => { message: string };
|
node_modules/zod/src/v3/benchmarks/datetime.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Benchmark from "benchmark";
|
| 2 |
+
|
| 3 |
+
const datetimeValidationSuite = new Benchmark.Suite("datetime");
|
| 4 |
+
|
| 5 |
+
const DATA = "2021-01-01";
|
| 6 |
+
const MONTHS_31 = new Set([1, 3, 5, 7, 8, 10, 12]);
|
| 7 |
+
const MONTHS_30 = new Set([4, 6, 9, 11]);
|
| 8 |
+
|
| 9 |
+
const simpleDatetimeRegex = /^(\d{4})-(\d{2})-(\d{2})$/;
|
| 10 |
+
const datetimeRegexNoLeapYearValidation =
|
| 11 |
+
/^\d{4}-((0[13578]|10|12)-31|(0[13-9]|1[0-2])-30|(0[1-9]|1[0-2])-(0[1-9]|1\d|2\d))$/;
|
| 12 |
+
const datetimeRegexWithLeapYearValidation =
|
| 13 |
+
/^((\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\d|3[01])|(0[469]|11)-(0[1-9]|[12]\d|30)|(02)-(0[1-9]|1\d|2[0-8])))$/;
|
| 14 |
+
|
| 15 |
+
datetimeValidationSuite
|
| 16 |
+
.add("new Date()", () => {
|
| 17 |
+
return !Number.isNaN(new Date(DATA).getTime());
|
| 18 |
+
})
|
| 19 |
+
.add("regex (no validation)", () => {
|
| 20 |
+
return simpleDatetimeRegex.test(DATA);
|
| 21 |
+
})
|
| 22 |
+
.add("regex (no leap year)", () => {
|
| 23 |
+
return datetimeRegexNoLeapYearValidation.test(DATA);
|
| 24 |
+
})
|
| 25 |
+
.add("regex (w/ leap year)", () => {
|
| 26 |
+
return datetimeRegexWithLeapYearValidation.test(DATA);
|
| 27 |
+
})
|
| 28 |
+
.add("capture groups + code", () => {
|
| 29 |
+
const match = DATA.match(simpleDatetimeRegex);
|
| 30 |
+
if (!match) return false;
|
| 31 |
+
|
| 32 |
+
// Extract year, month, and day from the capture groups
|
| 33 |
+
const year = Number.parseInt(match[1], 10);
|
| 34 |
+
const month = Number.parseInt(match[2], 10); // month is 0-indexed in JavaScript Date, so subtract 1
|
| 35 |
+
const day = Number.parseInt(match[3], 10);
|
| 36 |
+
|
| 37 |
+
if (month === 2) {
|
| 38 |
+
if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
|
| 39 |
+
return day <= 29;
|
| 40 |
+
}
|
| 41 |
+
return day <= 28;
|
| 42 |
+
}
|
| 43 |
+
if (MONTHS_30.has(month)) {
|
| 44 |
+
return day <= 30;
|
| 45 |
+
}
|
| 46 |
+
if (MONTHS_31.has(month)) {
|
| 47 |
+
return day <= 31;
|
| 48 |
+
}
|
| 49 |
+
return false;
|
| 50 |
+
})
|
| 51 |
+
|
| 52 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 53 |
+
console.log(`${datetimeValidationSuite.name!}: ${e.target}`);
|
| 54 |
+
});
|
| 55 |
+
|
| 56 |
+
export default {
|
| 57 |
+
suites: [datetimeValidationSuite],
|
| 58 |
+
};
|
node_modules/zod/src/v3/benchmarks/discriminatedUnion.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Benchmark from "benchmark";
|
| 2 |
+
|
| 3 |
+
import { z } from "zod/v3";
|
| 4 |
+
|
| 5 |
+
const doubleSuite = new Benchmark.Suite("z.discriminatedUnion: double");
|
| 6 |
+
const manySuite = new Benchmark.Suite("z.discriminatedUnion: many");
|
| 7 |
+
|
| 8 |
+
const aSchema = z.object({
|
| 9 |
+
type: z.literal("a"),
|
| 10 |
+
});
|
| 11 |
+
const objA = {
|
| 12 |
+
type: "a",
|
| 13 |
+
};
|
| 14 |
+
|
| 15 |
+
const bSchema = z.object({
|
| 16 |
+
type: z.literal("b"),
|
| 17 |
+
});
|
| 18 |
+
const objB = {
|
| 19 |
+
type: "b",
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
const cSchema = z.object({
|
| 23 |
+
type: z.literal("c"),
|
| 24 |
+
});
|
| 25 |
+
const objC = {
|
| 26 |
+
type: "c",
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
const dSchema = z.object({
|
| 30 |
+
type: z.literal("d"),
|
| 31 |
+
});
|
| 32 |
+
|
| 33 |
+
const double = z.discriminatedUnion("type", [aSchema, bSchema]);
|
| 34 |
+
const many = z.discriminatedUnion("type", [aSchema, bSchema, cSchema, dSchema]);
|
| 35 |
+
|
| 36 |
+
doubleSuite
|
| 37 |
+
.add("valid: a", () => {
|
| 38 |
+
double.parse(objA);
|
| 39 |
+
})
|
| 40 |
+
.add("valid: b", () => {
|
| 41 |
+
double.parse(objB);
|
| 42 |
+
})
|
| 43 |
+
.add("invalid: null", () => {
|
| 44 |
+
try {
|
| 45 |
+
double.parse(null);
|
| 46 |
+
} catch (_err) {}
|
| 47 |
+
})
|
| 48 |
+
.add("invalid: wrong shape", () => {
|
| 49 |
+
try {
|
| 50 |
+
double.parse(objC);
|
| 51 |
+
} catch (_err) {}
|
| 52 |
+
})
|
| 53 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 54 |
+
console.log(`${(doubleSuite as any).name}: ${e.target}`);
|
| 55 |
+
});
|
| 56 |
+
|
| 57 |
+
manySuite
|
| 58 |
+
.add("valid: a", () => {
|
| 59 |
+
many.parse(objA);
|
| 60 |
+
})
|
| 61 |
+
.add("valid: c", () => {
|
| 62 |
+
many.parse(objC);
|
| 63 |
+
})
|
| 64 |
+
.add("invalid: null", () => {
|
| 65 |
+
try {
|
| 66 |
+
many.parse(null);
|
| 67 |
+
} catch (_err) {}
|
| 68 |
+
})
|
| 69 |
+
.add("invalid: wrong shape", () => {
|
| 70 |
+
try {
|
| 71 |
+
many.parse({ type: "unknown" });
|
| 72 |
+
} catch (_err) {}
|
| 73 |
+
})
|
| 74 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 75 |
+
console.log(`${(manySuite as any).name}: ${e.target}`);
|
| 76 |
+
});
|
| 77 |
+
|
| 78 |
+
export default {
|
| 79 |
+
suites: [doubleSuite, manySuite],
|
| 80 |
+
};
|
node_modules/zod/src/v3/benchmarks/index.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type Benchmark from "benchmark";
|
| 2 |
+
|
| 3 |
+
import datetimeBenchmarks from "./datetime.js";
|
| 4 |
+
import discriminatedUnionBenchmarks from "./discriminatedUnion.js";
|
| 5 |
+
import ipv4Benchmarks from "./ipv4.js";
|
| 6 |
+
import objectBenchmarks from "./object.js";
|
| 7 |
+
import primitiveBenchmarks from "./primitives.js";
|
| 8 |
+
import realworld from "./realworld.js";
|
| 9 |
+
import stringBenchmarks from "./string.js";
|
| 10 |
+
import unionBenchmarks from "./union.js";
|
| 11 |
+
|
| 12 |
+
const argv = process.argv.slice(2);
|
| 13 |
+
let suites: Benchmark.Suite[] = [];
|
| 14 |
+
|
| 15 |
+
if (!argv.length) {
|
| 16 |
+
suites = [
|
| 17 |
+
...realworld.suites,
|
| 18 |
+
...primitiveBenchmarks.suites,
|
| 19 |
+
...stringBenchmarks.suites,
|
| 20 |
+
...objectBenchmarks.suites,
|
| 21 |
+
...unionBenchmarks.suites,
|
| 22 |
+
...discriminatedUnionBenchmarks.suites,
|
| 23 |
+
];
|
| 24 |
+
} else {
|
| 25 |
+
if (argv.includes("--realworld")) {
|
| 26 |
+
suites.push(...realworld.suites);
|
| 27 |
+
}
|
| 28 |
+
if (argv.includes("--primitives")) {
|
| 29 |
+
suites.push(...primitiveBenchmarks.suites);
|
| 30 |
+
}
|
| 31 |
+
if (argv.includes("--string")) {
|
| 32 |
+
suites.push(...stringBenchmarks.suites);
|
| 33 |
+
}
|
| 34 |
+
if (argv.includes("--object")) {
|
| 35 |
+
suites.push(...objectBenchmarks.suites);
|
| 36 |
+
}
|
| 37 |
+
if (argv.includes("--union")) {
|
| 38 |
+
suites.push(...unionBenchmarks.suites);
|
| 39 |
+
}
|
| 40 |
+
if (argv.includes("--discriminatedUnion")) {
|
| 41 |
+
suites.push(...datetimeBenchmarks.suites);
|
| 42 |
+
}
|
| 43 |
+
if (argv.includes("--datetime")) {
|
| 44 |
+
suites.push(...datetimeBenchmarks.suites);
|
| 45 |
+
}
|
| 46 |
+
if (argv.includes("--ipv4")) {
|
| 47 |
+
suites.push(...ipv4Benchmarks.suites);
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
for (const suite of suites) {
|
| 52 |
+
suite.run({});
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
// exit on Ctrl-C
|
| 56 |
+
process.on("SIGINT", function () {
|
| 57 |
+
console.log("Exiting...");
|
| 58 |
+
process.exit();
|
| 59 |
+
});
|
node_modules/zod/src/v3/benchmarks/ipv4.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Benchmark from "benchmark";
|
| 2 |
+
|
| 3 |
+
const suite = new Benchmark.Suite("ipv4");
|
| 4 |
+
|
| 5 |
+
const DATA = "127.0.0.1";
|
| 6 |
+
const ipv4RegexA =
|
| 7 |
+
/^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
|
| 8 |
+
const ipv4RegexB =
|
| 9 |
+
/^(?:(?:(?=(25[0-5]))\1|(?=(2[0-4][0-9]))\2|(?=(1[0-9]{2}))\3|(?=([0-9]{1,2}))\4)\.){3}(?:(?=(25[0-5]))\5|(?=(2[0-4][0-9]))\6|(?=(1[0-9]{2}))\7|(?=([0-9]{1,2}))\8)$/;
|
| 10 |
+
const ipv4RegexC = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
|
| 11 |
+
const ipv4RegexD = /^(\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/;
|
| 12 |
+
const ipv4RegexE = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.){3}(25[0-5]|(2[0-4]|1\d|[1-9]|)\d)$/;
|
| 13 |
+
const ipv4RegexF = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/;
|
| 14 |
+
const ipv4RegexG = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$/;
|
| 15 |
+
const ipv4RegexH = /^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\.(?!$)|$)){4}$/;
|
| 16 |
+
const ipv4RegexI =
|
| 17 |
+
/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
| 18 |
+
|
| 19 |
+
suite
|
| 20 |
+
.add("A", () => {
|
| 21 |
+
return ipv4RegexA.test(DATA);
|
| 22 |
+
})
|
| 23 |
+
.add("B", () => {
|
| 24 |
+
return ipv4RegexB.test(DATA);
|
| 25 |
+
})
|
| 26 |
+
.add("C", () => {
|
| 27 |
+
return ipv4RegexC.test(DATA);
|
| 28 |
+
})
|
| 29 |
+
.add("D", () => {
|
| 30 |
+
return ipv4RegexD.test(DATA);
|
| 31 |
+
})
|
| 32 |
+
.add("E", () => {
|
| 33 |
+
return ipv4RegexE.test(DATA);
|
| 34 |
+
})
|
| 35 |
+
.add("F", () => {
|
| 36 |
+
return ipv4RegexF.test(DATA);
|
| 37 |
+
})
|
| 38 |
+
.add("G", () => {
|
| 39 |
+
return ipv4RegexG.test(DATA);
|
| 40 |
+
})
|
| 41 |
+
.add("H", () => {
|
| 42 |
+
return ipv4RegexH.test(DATA);
|
| 43 |
+
})
|
| 44 |
+
.add("I", () => {
|
| 45 |
+
return ipv4RegexI.test(DATA);
|
| 46 |
+
})
|
| 47 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 48 |
+
console.log(`${suite.name!}: ${e.target}`);
|
| 49 |
+
});
|
| 50 |
+
|
| 51 |
+
export default {
|
| 52 |
+
suites: [suite],
|
| 53 |
+
};
|
| 54 |
+
|
| 55 |
+
if (require.main === module) {
|
| 56 |
+
suite.run();
|
| 57 |
+
}
|
node_modules/zod/src/v3/benchmarks/object.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Benchmark from "benchmark";
|
| 2 |
+
|
| 3 |
+
import { z } from "zod/v3";
|
| 4 |
+
|
| 5 |
+
const emptySuite = new Benchmark.Suite("z.object: empty");
|
| 6 |
+
const shortSuite = new Benchmark.Suite("z.object: short");
|
| 7 |
+
const longSuite = new Benchmark.Suite("z.object: long");
|
| 8 |
+
|
| 9 |
+
const empty = z.object({});
|
| 10 |
+
const short = z.object({
|
| 11 |
+
string: z.string(),
|
| 12 |
+
});
|
| 13 |
+
const long = z.object({
|
| 14 |
+
string: z.string(),
|
| 15 |
+
number: z.number(),
|
| 16 |
+
boolean: z.boolean(),
|
| 17 |
+
});
|
| 18 |
+
|
| 19 |
+
emptySuite
|
| 20 |
+
.add("valid", () => {
|
| 21 |
+
empty.parse({});
|
| 22 |
+
})
|
| 23 |
+
.add("valid: extra keys", () => {
|
| 24 |
+
empty.parse({ string: "string" });
|
| 25 |
+
})
|
| 26 |
+
.add("invalid: null", () => {
|
| 27 |
+
try {
|
| 28 |
+
empty.parse(null);
|
| 29 |
+
} catch (_err) {}
|
| 30 |
+
})
|
| 31 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 32 |
+
console.log(`${(emptySuite as any).name}: ${e.target}`);
|
| 33 |
+
});
|
| 34 |
+
|
| 35 |
+
shortSuite
|
| 36 |
+
.add("valid", () => {
|
| 37 |
+
short.parse({ string: "string" });
|
| 38 |
+
})
|
| 39 |
+
.add("valid: extra keys", () => {
|
| 40 |
+
short.parse({ string: "string", number: 42 });
|
| 41 |
+
})
|
| 42 |
+
.add("invalid: null", () => {
|
| 43 |
+
try {
|
| 44 |
+
short.parse(null);
|
| 45 |
+
} catch (_err) {}
|
| 46 |
+
})
|
| 47 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 48 |
+
console.log(`${(shortSuite as any).name}: ${e.target}`);
|
| 49 |
+
});
|
| 50 |
+
|
| 51 |
+
longSuite
|
| 52 |
+
.add("valid", () => {
|
| 53 |
+
long.parse({ string: "string", number: 42, boolean: true });
|
| 54 |
+
})
|
| 55 |
+
.add("valid: extra keys", () => {
|
| 56 |
+
long.parse({ string: "string", number: 42, boolean: true, list: [] });
|
| 57 |
+
})
|
| 58 |
+
.add("invalid: null", () => {
|
| 59 |
+
try {
|
| 60 |
+
long.parse(null);
|
| 61 |
+
} catch (_err) {}
|
| 62 |
+
})
|
| 63 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 64 |
+
console.log(`${(longSuite as any).name}: ${e.target}`);
|
| 65 |
+
});
|
| 66 |
+
|
| 67 |
+
export default {
|
| 68 |
+
suites: [emptySuite, shortSuite, longSuite],
|
| 69 |
+
};
|
node_modules/zod/src/v3/benchmarks/primitives.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Benchmark from "benchmark";
|
| 2 |
+
|
| 3 |
+
import { z } from "zod/v3";
|
| 4 |
+
import { Mocker } from "../tests/Mocker.js";
|
| 5 |
+
|
| 6 |
+
const val = new Mocker();
|
| 7 |
+
|
| 8 |
+
const enumSuite = new Benchmark.Suite("z.enum");
|
| 9 |
+
const enumSchema = z.enum(["a", "b", "c"]);
|
| 10 |
+
|
| 11 |
+
enumSuite
|
| 12 |
+
.add("valid", () => {
|
| 13 |
+
enumSchema.parse("a");
|
| 14 |
+
})
|
| 15 |
+
.add("invalid", () => {
|
| 16 |
+
try {
|
| 17 |
+
enumSchema.parse("x");
|
| 18 |
+
} catch (_e: any) {}
|
| 19 |
+
})
|
| 20 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 21 |
+
console.log(`z.enum: ${e.target}`);
|
| 22 |
+
});
|
| 23 |
+
|
| 24 |
+
const longEnumSuite = new Benchmark.Suite("long z.enum");
|
| 25 |
+
const longEnumSchema = z.enum([
|
| 26 |
+
"one",
|
| 27 |
+
"two",
|
| 28 |
+
"three",
|
| 29 |
+
"four",
|
| 30 |
+
"five",
|
| 31 |
+
"six",
|
| 32 |
+
"seven",
|
| 33 |
+
"eight",
|
| 34 |
+
"nine",
|
| 35 |
+
"ten",
|
| 36 |
+
"eleven",
|
| 37 |
+
"twelve",
|
| 38 |
+
"thirteen",
|
| 39 |
+
"fourteen",
|
| 40 |
+
"fifteen",
|
| 41 |
+
"sixteen",
|
| 42 |
+
"seventeen",
|
| 43 |
+
]);
|
| 44 |
+
|
| 45 |
+
longEnumSuite
|
| 46 |
+
.add("valid", () => {
|
| 47 |
+
longEnumSchema.parse("five");
|
| 48 |
+
})
|
| 49 |
+
.add("invalid", () => {
|
| 50 |
+
try {
|
| 51 |
+
longEnumSchema.parse("invalid");
|
| 52 |
+
} catch (_e: any) {}
|
| 53 |
+
})
|
| 54 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 55 |
+
console.log(`long z.enum: ${e.target}`);
|
| 56 |
+
});
|
| 57 |
+
|
| 58 |
+
const undefinedSuite = new Benchmark.Suite("z.undefined");
|
| 59 |
+
const undefinedSchema = z.undefined();
|
| 60 |
+
|
| 61 |
+
undefinedSuite
|
| 62 |
+
.add("valid", () => {
|
| 63 |
+
undefinedSchema.parse(undefined);
|
| 64 |
+
})
|
| 65 |
+
.add("invalid", () => {
|
| 66 |
+
try {
|
| 67 |
+
undefinedSchema.parse(1);
|
| 68 |
+
} catch (_e: any) {}
|
| 69 |
+
})
|
| 70 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 71 |
+
console.log(`z.undefined: ${e.target}`);
|
| 72 |
+
});
|
| 73 |
+
|
| 74 |
+
const literalSuite = new Benchmark.Suite("z.literal");
|
| 75 |
+
const short = "short";
|
| 76 |
+
const bad = "bad";
|
| 77 |
+
const literalSchema = z.literal("short");
|
| 78 |
+
|
| 79 |
+
literalSuite
|
| 80 |
+
.add("valid", () => {
|
| 81 |
+
literalSchema.parse(short);
|
| 82 |
+
})
|
| 83 |
+
.add("invalid", () => {
|
| 84 |
+
try {
|
| 85 |
+
literalSchema.parse(bad);
|
| 86 |
+
} catch (_e: any) {}
|
| 87 |
+
})
|
| 88 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 89 |
+
console.log(`z.literal: ${e.target}`);
|
| 90 |
+
});
|
| 91 |
+
|
| 92 |
+
const numberSuite = new Benchmark.Suite("z.number");
|
| 93 |
+
const numberSchema = z.number().int();
|
| 94 |
+
|
| 95 |
+
numberSuite
|
| 96 |
+
.add("valid", () => {
|
| 97 |
+
numberSchema.parse(1);
|
| 98 |
+
})
|
| 99 |
+
.add("invalid type", () => {
|
| 100 |
+
try {
|
| 101 |
+
numberSchema.parse("bad");
|
| 102 |
+
} catch (_e: any) {}
|
| 103 |
+
})
|
| 104 |
+
.add("invalid number", () => {
|
| 105 |
+
try {
|
| 106 |
+
numberSchema.parse(0.5);
|
| 107 |
+
} catch (_e: any) {}
|
| 108 |
+
})
|
| 109 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 110 |
+
console.log(`z.number: ${e.target}`);
|
| 111 |
+
});
|
| 112 |
+
|
| 113 |
+
const dateSuite = new Benchmark.Suite("z.date");
|
| 114 |
+
|
| 115 |
+
const plainDate = z.date();
|
| 116 |
+
const minMaxDate = z.date().min(new Date("2021-01-01")).max(new Date("2030-01-01"));
|
| 117 |
+
|
| 118 |
+
dateSuite
|
| 119 |
+
.add("valid", () => {
|
| 120 |
+
plainDate.parse(new Date());
|
| 121 |
+
})
|
| 122 |
+
.add("invalid", () => {
|
| 123 |
+
try {
|
| 124 |
+
plainDate.parse(1);
|
| 125 |
+
} catch (_e: any) {}
|
| 126 |
+
})
|
| 127 |
+
.add("valid min and max", () => {
|
| 128 |
+
minMaxDate.parse(new Date("2023-01-01"));
|
| 129 |
+
})
|
| 130 |
+
.add("invalid min", () => {
|
| 131 |
+
try {
|
| 132 |
+
minMaxDate.parse(new Date("2019-01-01"));
|
| 133 |
+
} catch (_e: any) {}
|
| 134 |
+
})
|
| 135 |
+
.add("invalid max", () => {
|
| 136 |
+
try {
|
| 137 |
+
minMaxDate.parse(new Date("2031-01-01"));
|
| 138 |
+
} catch (_e: any) {}
|
| 139 |
+
})
|
| 140 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 141 |
+
console.log(`z.date: ${e.target}`);
|
| 142 |
+
});
|
| 143 |
+
|
| 144 |
+
const symbolSuite = new Benchmark.Suite("z.symbol");
|
| 145 |
+
const symbolSchema = z.symbol();
|
| 146 |
+
|
| 147 |
+
symbolSuite
|
| 148 |
+
.add("valid", () => {
|
| 149 |
+
symbolSchema.parse(val.symbol);
|
| 150 |
+
})
|
| 151 |
+
.add("invalid", () => {
|
| 152 |
+
try {
|
| 153 |
+
symbolSchema.parse(1);
|
| 154 |
+
} catch (_e: any) {}
|
| 155 |
+
})
|
| 156 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 157 |
+
console.log(`z.symbol: ${e.target}`);
|
| 158 |
+
});
|
| 159 |
+
|
| 160 |
+
export default {
|
| 161 |
+
suites: [enumSuite, longEnumSuite, undefinedSuite, literalSuite, numberSuite, dateSuite, symbolSuite],
|
| 162 |
+
};
|
node_modules/zod/src/v3/benchmarks/realworld.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Benchmark from "benchmark";
|
| 2 |
+
|
| 3 |
+
import { z } from "zod/v3";
|
| 4 |
+
|
| 5 |
+
const shortSuite = new Benchmark.Suite("realworld");
|
| 6 |
+
|
| 7 |
+
const People = z.array(
|
| 8 |
+
z.object({
|
| 9 |
+
type: z.literal("person"),
|
| 10 |
+
hair: z.enum(["blue", "brown"]),
|
| 11 |
+
active: z.boolean(),
|
| 12 |
+
name: z.string(),
|
| 13 |
+
age: z.number().int(),
|
| 14 |
+
hobbies: z.array(z.string()),
|
| 15 |
+
address: z.object({
|
| 16 |
+
street: z.string(),
|
| 17 |
+
zip: z.string(),
|
| 18 |
+
country: z.string(),
|
| 19 |
+
}),
|
| 20 |
+
})
|
| 21 |
+
);
|
| 22 |
+
|
| 23 |
+
let i = 0;
|
| 24 |
+
|
| 25 |
+
function num() {
|
| 26 |
+
return ++i;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
function str() {
|
| 30 |
+
return (++i % 100).toString(16);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
function array<T>(fn: () => T): T[] {
|
| 34 |
+
return Array.from({ length: ++i % 10 }, () => fn());
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
const people = Array.from({ length: 100 }, () => {
|
| 38 |
+
return {
|
| 39 |
+
type: "person",
|
| 40 |
+
hair: i % 2 ? "blue" : "brown",
|
| 41 |
+
active: !!(i % 2),
|
| 42 |
+
name: str(),
|
| 43 |
+
age: num(),
|
| 44 |
+
hobbies: array(str),
|
| 45 |
+
address: {
|
| 46 |
+
street: str(),
|
| 47 |
+
zip: str(),
|
| 48 |
+
country: str(),
|
| 49 |
+
},
|
| 50 |
+
};
|
| 51 |
+
});
|
| 52 |
+
|
| 53 |
+
shortSuite
|
| 54 |
+
.add("valid", () => {
|
| 55 |
+
People.parse(people);
|
| 56 |
+
})
|
| 57 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 58 |
+
console.log(`${(shortSuite as any).name}: ${e.target}`);
|
| 59 |
+
});
|
| 60 |
+
|
| 61 |
+
export default {
|
| 62 |
+
suites: [shortSuite],
|
| 63 |
+
};
|
node_modules/zod/src/v3/benchmarks/string.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Benchmark from "benchmark";
|
| 2 |
+
|
| 3 |
+
import { z } from "zod/v3";
|
| 4 |
+
|
| 5 |
+
const SUITE_NAME = "z.string";
|
| 6 |
+
const suite = new Benchmark.Suite(SUITE_NAME);
|
| 7 |
+
|
| 8 |
+
const empty = "";
|
| 9 |
+
const short = "short";
|
| 10 |
+
const long = "long".repeat(256);
|
| 11 |
+
const manual = (str: unknown) => {
|
| 12 |
+
if (typeof str !== "string") {
|
| 13 |
+
throw new Error("Not a string");
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
return str;
|
| 17 |
+
};
|
| 18 |
+
const stringSchema = z.string();
|
| 19 |
+
const optionalStringSchema = z.string().optional();
|
| 20 |
+
const optionalNullableStringSchema = z.string().optional().nullable();
|
| 21 |
+
|
| 22 |
+
suite
|
| 23 |
+
.add("empty string", () => {
|
| 24 |
+
stringSchema.parse(empty);
|
| 25 |
+
})
|
| 26 |
+
.add("short string", () => {
|
| 27 |
+
stringSchema.parse(short);
|
| 28 |
+
})
|
| 29 |
+
.add("long string", () => {
|
| 30 |
+
stringSchema.parse(long);
|
| 31 |
+
})
|
| 32 |
+
.add("optional string", () => {
|
| 33 |
+
optionalStringSchema.parse(long);
|
| 34 |
+
})
|
| 35 |
+
.add("nullable string", () => {
|
| 36 |
+
optionalNullableStringSchema.parse(long);
|
| 37 |
+
})
|
| 38 |
+
.add("nullable (null) string", () => {
|
| 39 |
+
optionalNullableStringSchema.parse(null);
|
| 40 |
+
})
|
| 41 |
+
.add("invalid: null", () => {
|
| 42 |
+
try {
|
| 43 |
+
stringSchema.parse(null);
|
| 44 |
+
} catch (_err) {}
|
| 45 |
+
})
|
| 46 |
+
.add("manual parser: long", () => {
|
| 47 |
+
manual(long);
|
| 48 |
+
})
|
| 49 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 50 |
+
console.log(`${SUITE_NAME}: ${e.target}`);
|
| 51 |
+
});
|
| 52 |
+
|
| 53 |
+
export default {
|
| 54 |
+
suites: [suite],
|
| 55 |
+
};
|
node_modules/zod/src/v3/benchmarks/union.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Benchmark from "benchmark";
|
| 2 |
+
|
| 3 |
+
import { z } from "zod/v3";
|
| 4 |
+
|
| 5 |
+
const doubleSuite = new Benchmark.Suite("z.union: double");
|
| 6 |
+
const manySuite = new Benchmark.Suite("z.union: many");
|
| 7 |
+
|
| 8 |
+
const aSchema = z.object({
|
| 9 |
+
type: z.literal("a"),
|
| 10 |
+
});
|
| 11 |
+
const objA = {
|
| 12 |
+
type: "a",
|
| 13 |
+
};
|
| 14 |
+
|
| 15 |
+
const bSchema = z.object({
|
| 16 |
+
type: z.literal("b"),
|
| 17 |
+
});
|
| 18 |
+
const objB = {
|
| 19 |
+
type: "b",
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
const cSchema = z.object({
|
| 23 |
+
type: z.literal("c"),
|
| 24 |
+
});
|
| 25 |
+
const objC = {
|
| 26 |
+
type: "c",
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
const dSchema = z.object({
|
| 30 |
+
type: z.literal("d"),
|
| 31 |
+
});
|
| 32 |
+
|
| 33 |
+
const double = z.union([aSchema, bSchema]);
|
| 34 |
+
const many = z.union([aSchema, bSchema, cSchema, dSchema]);
|
| 35 |
+
|
| 36 |
+
doubleSuite
|
| 37 |
+
.add("valid: a", () => {
|
| 38 |
+
double.parse(objA);
|
| 39 |
+
})
|
| 40 |
+
.add("valid: b", () => {
|
| 41 |
+
double.parse(objB);
|
| 42 |
+
})
|
| 43 |
+
.add("invalid: null", () => {
|
| 44 |
+
try {
|
| 45 |
+
double.parse(null);
|
| 46 |
+
} catch (_err) {}
|
| 47 |
+
})
|
| 48 |
+
.add("invalid: wrong shape", () => {
|
| 49 |
+
try {
|
| 50 |
+
double.parse(objC);
|
| 51 |
+
} catch (_err) {}
|
| 52 |
+
})
|
| 53 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 54 |
+
console.log(`${(doubleSuite as any).name}: ${e.target}`);
|
| 55 |
+
});
|
| 56 |
+
|
| 57 |
+
manySuite
|
| 58 |
+
.add("valid: a", () => {
|
| 59 |
+
many.parse(objA);
|
| 60 |
+
})
|
| 61 |
+
.add("valid: c", () => {
|
| 62 |
+
many.parse(objC);
|
| 63 |
+
})
|
| 64 |
+
.add("invalid: null", () => {
|
| 65 |
+
try {
|
| 66 |
+
many.parse(null);
|
| 67 |
+
} catch (_err) {}
|
| 68 |
+
})
|
| 69 |
+
.add("invalid: wrong shape", () => {
|
| 70 |
+
try {
|
| 71 |
+
many.parse({ type: "unknown" });
|
| 72 |
+
} catch (_err) {}
|
| 73 |
+
})
|
| 74 |
+
.on("cycle", (e: Benchmark.Event) => {
|
| 75 |
+
console.log(`${(manySuite as any).name}: ${e.target}`);
|
| 76 |
+
});
|
| 77 |
+
|
| 78 |
+
export default {
|
| 79 |
+
suites: [doubleSuite, manySuite],
|
| 80 |
+
};
|
node_modules/zod/src/v3/errors.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ZodErrorMap } from "./ZodError.js";
|
| 2 |
+
import defaultErrorMap from "./locales/en.js";
|
| 3 |
+
|
| 4 |
+
let overrideErrorMap = defaultErrorMap;
|
| 5 |
+
export { defaultErrorMap };
|
| 6 |
+
|
| 7 |
+
export function setErrorMap(map: ZodErrorMap) {
|
| 8 |
+
overrideErrorMap = map;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
export function getErrorMap() {
|
| 12 |
+
return overrideErrorMap;
|
| 13 |
+
}
|
node_modules/zod/src/v3/external.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export * from "./errors.js";
|
| 2 |
+
export * from "./helpers/parseUtil.js";
|
| 3 |
+
export * from "./helpers/typeAliases.js";
|
| 4 |
+
export * from "./helpers/util.js";
|
| 5 |
+
export * from "./types.js";
|
| 6 |
+
export * from "./ZodError.js";
|
node_modules/zod/src/v3/helpers/enumUtil.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export namespace enumUtil {
|
| 2 |
+
type UnionToIntersectionFn<T> = (T extends unknown ? (k: () => T) => void : never) extends (
|
| 3 |
+
k: infer Intersection
|
| 4 |
+
) => void
|
| 5 |
+
? Intersection
|
| 6 |
+
: never;
|
| 7 |
+
|
| 8 |
+
type GetUnionLast<T> = UnionToIntersectionFn<T> extends () => infer Last ? Last : never;
|
| 9 |
+
|
| 10 |
+
type UnionToTuple<T, Tuple extends unknown[] = []> = [T] extends [never]
|
| 11 |
+
? Tuple
|
| 12 |
+
: UnionToTuple<Exclude<T, GetUnionLast<T>>, [GetUnionLast<T>, ...Tuple]>;
|
| 13 |
+
|
| 14 |
+
type CastToStringTuple<T> = T extends [string, ...string[]] ? T : never;
|
| 15 |
+
|
| 16 |
+
export type UnionToTupleString<T> = CastToStringTuple<UnionToTuple<T>>;
|
| 17 |
+
}
|
node_modules/zod/src/v3/helpers/errorUtil.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export namespace errorUtil {
|
| 2 |
+
export type ErrMessage = string | { message?: string | undefined };
|
| 3 |
+
export const errToObj = (message?: ErrMessage): { message?: string | undefined } =>
|
| 4 |
+
typeof message === "string" ? { message } : message || {};
|
| 5 |
+
// biome-ignore lint:
|
| 6 |
+
export const toString = (message?: ErrMessage): string | undefined =>
|
| 7 |
+
typeof message === "string" ? message : message?.message;
|
| 8 |
+
}
|