Latest Supply Chain Attack:Mini Shai-Hulud Hits @antv npm Packages, 639 Versions Compromised.Learn More
Socket
Book a DemoSign in
Socket

@adaptate/core

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adaptate/core

Dynamic and Adaptable Model Validator Using Zod, Interoperable with OpenAPI

latest
Source
npmnpm
Version
2.2.2
Version published
Weekly downloads
185
224.56%
Maintainers
1
Weekly downloads
 
Created
Source

@adaptate/core

Schema transformation engine — make Zod schema fields required based on configuration objects.

Installation

pnpm add @adaptate/core
# or
npm install @adaptate/core

Peer dependency: zod@^3.23.8 || ^4.0.0

Monorepo development: If you clone the adaptate repo to work on source, use pnpm at the repo root only — required for the repo’s supply-chain protections (Development in the root README). The install commands above remain correct when installing published packages from npm.

API

transformSchema(schema, config)

Transforms a Zod schema by making specified fields required based on a config object.

Config values:

  • true — make the field required (strip optionality)
  • false — keep the field optional
  • Nested object — recurse into sub-schema
  • { '*': config } — apply config to all array elements
import { z } from 'zod';
import { transformSchema, type Config } from '@adaptate/core';

const schema = z.object({
  name: z.string().optional(),
  age: z.number().optional(),
  address: z.object({
    street: z.string().optional(),
    city: z.string().optional(),
  }).optional(),
});

const config = {
  name: true,
  age: true,
  address: { city: true },
} satisfies Config<z.infer<typeof schema>>;

const updatedSchema = transformSchema(schema, config);

updatedSchema.parse({ name: 'Davin', age: 30, address: { city: 'Pettit' } }); // passes
updatedSchema.parse({ name: 'Davin', age: 30, address: { street: 'Main St' } } ); // throws

Config<T> (Type Helper)

Fully typed config for autocomplete and compile-time safety.

const config = {
  name: true,
  address: { city: true },
  tags: { '*': true },
} satisfies Config<z.infer<typeof userSchema>>;

makeConditionalSchemaTransformer(data)

Creates a transformer that can apply conditional requirements based on runtime data.

Config values (in addition to above):

  • (data) => boolean — function that determines if field is required
  • { requiredIf: (data) => boolean } — explicit conditional syntax
import { z } from 'zod';
import { makeConditionalSchemaTransformer } from '@adaptate/core';

const schema = z.object({
  parentContactNumber: z.number().optional(),
  age: z.number().optional(),
});

const config = {
  parentContactNumber: { requiredIf: (data: any) => data.age < 18 },
  age: true,
};

const data = { age: 17 };
const transformer = makeConditionalSchemaTransformer(data)(schema, config);

transformer.run(); // throws — parentContactNumber required because age < 18

Transformer properties:

  • transformer.schema — the transformed Zod schema
  • transformer.run() — shorthand for transformer.schema.parse(data)
  • transformer.staticConfig — config with conditionals removed (for use with transformSchema)

How It Works

The engine recursively traverses the Zod schema tree:

  • Checks if a field is optional → uses .unwrap() to strip optionality
  • For nested objects → recurses with the nested config
  • For arrays with '*' config → applies config to element schema
  • Merges the transformed shape back with the original using ZodObject.merge()

This preserves all fields not mentioned in the config while making specified fields required.

Keywords

Zod

FAQs

Package last updated on 14 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts