@ptolemy2002/zod-utils 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,6 @@
1
- import z, { ZodArray, ZodType, ZodUnknown } from "zod";
1
+ import z, { ZodArray, ZodUnknown } from "zod";
2
2
  import { $ZodFunctionArgs, $ZodFunctionOut } from "zod/v4/core";
3
- import { ZodPath } from "./types";
4
- export type TrialErrorMode = "allow" | "forbid" | "require" | ((e: unknown) => boolean) | {
5
- require: (e: unknown) => boolean;
6
- };
7
- export type FunctionTrial<Input extends unknown[]> = {
8
- id?: string;
9
- input: Input;
10
- outputSchema?: ZodType;
11
- error?: TrialErrorMode;
12
- errorStringify?: (e: unknown) => string;
13
- };
14
- export type ZodFunctionParseOptions<In extends $ZodFunctionArgs, Out extends $ZodFunctionOut> = {
15
- input?: In;
16
- output?: Out;
17
- inputPath?: ZodPath;
18
- outputPath?: ZodPath;
19
- };
3
+ import { ZodFunctionParseOptions, FunctionTrial } from "./types";
20
4
  export type ZodFunctionSchemaOptions<In extends $ZodFunctionArgs, Out extends $ZodFunctionOut> = {
21
5
  trials?: FunctionTrial<z.infer<In>>[];
22
6
  } & ZodFunctionParseOptions<In, Out>;
@@ -1,8 +1,3 @@
1
- import { InterpretableZodError, InterpretableZodIssue, ZodPath } from './types';
2
- export type InterpretZodErrorOptions = {
3
- prefix?: ZodPath;
4
- multiline?: boolean;
5
- includeCode?: boolean;
6
- };
1
+ import { InterpretableZodError, InterpretableZodIssue, ZodPath, InterpretZodErrorOptions } from './types';
7
2
  export declare function interpretZodError(err: InterpretableZodError, options?: ZodPath | InterpretZodErrorOptions): string;
8
3
  export declare function interpretZodIssue(issue: InterpretableZodIssue, options?: ZodPath | InterpretZodErrorOptions): string;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ZodOptional, ZodSafeParseResult, ZodType } from 'zod';
2
+ import { $ZodFunctionArgs, $ZodFunctionOut } from 'zod/v4/core';
2
3
  export type ZodSafeParseable<O> = {
3
4
  safeParse: (data: unknown) => ZodSafeParseResult<O>;
4
5
  };
@@ -13,10 +14,14 @@ export type ZodValidationResult<O> = {
13
14
  error: string;
14
15
  };
15
16
  export type ZodValidatorWithErrors<O> = (v: unknown) => ZodValidationResult<O>;
17
+ export type InterpretZodErrorOptions = {
18
+ prefix?: ZodPath;
19
+ multiline?: boolean;
20
+ includeCode?: boolean;
21
+ };
16
22
  export type ZodValidateWithErrorsOptions = {
17
23
  _throw?: boolean;
18
- prefix?: string | string[];
19
- };
24
+ } & InterpretZodErrorOptions;
20
25
  export type MaybeZodOptional<ZT extends ZodType> = ZT | ZodOptional<ZT>;
21
26
  export type ZodPath = PropertyKey | PropertyKey[];
22
27
  export type InterpretableZodIssue = Readonly<{
@@ -27,3 +32,19 @@ export type InterpretableZodIssue = Readonly<{
27
32
  export type InterpretableZodError = Readonly<{
28
33
  issues: InterpretableZodIssue[];
29
34
  }>;
35
+ export type ZodFunctionParseOptions<In extends $ZodFunctionArgs, Out extends $ZodFunctionOut> = {
36
+ input?: In;
37
+ output?: Out;
38
+ inputPath?: ZodPath;
39
+ outputPath?: ZodPath;
40
+ };
41
+ export type TrialErrorMode = "allow" | "forbid" | "require" | ((e: unknown) => boolean) | {
42
+ require: (e: unknown) => boolean;
43
+ };
44
+ export type FunctionTrial<Input extends unknown[]> = {
45
+ id?: string;
46
+ input: Input;
47
+ outputSchema?: ZodType;
48
+ error?: TrialErrorMode;
49
+ errorStringify?: (e: unknown) => string;
50
+ };
@@ -1,3 +1,3 @@
1
1
  import * as t from './types';
2
2
  export declare function zodValidate<O>(p: t.ZodSafeParseable<O>): t.ZodValidator<O>;
3
- export declare function zodValidateWithErrors<O>(p: t.ZodSafeParseable<O>, { _throw, prefix, }?: t.ZodValidateWithErrorsOptions): t.ZodValidatorWithErrors<O>;
3
+ export declare function zodValidateWithErrors<O>(p: t.ZodSafeParseable<O>, { _throw, ...options }?: t.ZodValidateWithErrorsOptions): t.ZodValidatorWithErrors<O>;
package/dist/validate.js CHANGED
@@ -9,13 +9,13 @@ function zodValidate(p) {
9
9
  return result.success;
10
10
  };
11
11
  }
12
- function zodValidateWithErrors(p, { _throw = false, prefix = "", } = {}) {
12
+ function zodValidateWithErrors(p, { _throw = false, ...options } = {}) {
13
13
  return (_v) => {
14
14
  const { success, error, data: v } = p.safeParse(_v);
15
15
  if (success)
16
16
  return { success, value: v };
17
17
  if (_throw)
18
18
  throw error;
19
- return { success, error: (0, interpret_1.interpretZodError)(error, prefix) };
19
+ return { success, error: (0, interpret_1.interpretZodError)(error, options) };
20
20
  };
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptolemy2002/zod-utils",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",