Skip to content

dhi v1.7.0

Latest

Choose a tag to compare

@justrach justrach released this 31 Aug 00:19
· 2 commits to main since this release
abd1926

Codecs, real async parsing, and the remaining Zod 4 API surface.

Published to npm with SLSA provenance via an OIDC trusted publisher.

Added

  • Codecs — z.codec(input, output, { decode, encode }) plus z.encode/decode/
    safeEncode/safeDecode (and *Async) and matching methods on every schema. Encoding runs
    the schema backwards through codecs, pipes and z.stringbool(), and refuses one-way
    .transform()s with a ZodEncodeError.
  • Real async parsing — .parseAsync() / .safeParseAsync() / .spa() await async
    refinements, superRefinements, transforms and .check() callbacks, including when nested in
    objects, arrays, tuples, records, sets, maps, unions and wrappers. A synchronous .parse()
    that meets one throws ZodAsyncError instead of leaking a Promise.
  • Error helpers — z.treeifyError(), z.flattenError(), z.formatError(), all with the
    optional issue mapper. ZodError is now an Error with a lazily built .stack and gains
    .isEmpty, .addIssue(), .addIssues().
  • Top-level functional API — z.parse/safeParse/parseAsync/safeParseAsync,
    z.transform, z.catch, z.default, z.prefault, z.nullish, z.nonoptional,
    z.readonly, z.exactOptional, z.keyof, z.clone, z.xor, z.stringFormat,
    z.slugify, z.describe, z.meta, z.fromJSONSchema.
  • Constants and namespaces — z.NEVER, z.TimePrecision, z.ZodIssueCode, z.$brand,
    z.regexes, z.util, z.core, z.locales, z.config(), z.getErrorMap(),
    z.setErrorMap(), and runtime z.ZodString / z.ZodObject / … class aliases.
  • Schema introspection — .type, .apply(), .with(), .toJSONSchema(), .spa() on
    every schema, plus .format/.minValue/.maxValue/.isInt on numbers, .minDate/
    .maxDate on dates, .element on arrays, .keyType/.valueType on records and maps.
  • z.object().safeExtend(), z.tuple(items, rest), z.map().min/max/size/nonempty(),
    z.function().implementAsync(), z.string().slugify().
  • z.toJSONSchema() accepts target, metadata, unrepresentable, override and io, and
    emits Zod's document shape. .meta() registers in z.globalRegistry.

Changed

  • Issues carry Zod 4 codes natively (invalid_format, invalid_value, invalid_union); Zod 3
    spellings passed to ctx.addIssue() are still accepted and normalised.
  • .prefault(v) runs the fallback through the schema; .default(v) still short-circuits.
  • .transform() receives Zod's ctx; .catch() receives { value, issues, error, input };
    .refine() accepts { when, abort, path, message, error }.
  • z.prettifyError() uses Zod's layout; error.flatten() keys fieldErrors like Zod.
  • .extend(), .pick(), .omit(), .partial(), .required() keep the object's unknown-key
    policy.
  • z.discriminatedUnion() resolves discriminators through optional, nullable, enum and
    nested-union options.

Performance

Zig core JSON parse/validate paths use a stack-owned arena instead of a heap-allocated
Parsed wrapper, and json_batch_validator is now part of zig build test. (#80)

The differential parity suite is now 283 schemas / 4,961 checks against zod@4.3.6 with zero
mismatches, and dhi remains faster than Zod on every benchmark row.