Libraries
    Preparing search index...
    • Wraps an external Standard Schema v1 compatible schema into a @cleverbrush/schema builder.

      This enables cross-library schema composition — use schemas from Zod, Valibot, ArkType, or any Standard Schema v1 compliant library as properties inside @cleverbrush/schema object schemas with full type inference.

      Type Parameters

      Parameters

      • standardSchema: T

        A Standard Schema v1 compliant schema instance (any object that exposes a ['~standard'] property with version: 1 and a validate function).

      Returns ExternSchemaBuilder<
          T,
          true,
          false,
          undefined,
          false,
          {},
          StandardSchemaV1.InferOutput<T>,
      >

      import { z } from 'zod';
      import { object, date, extern, InferType } from '@cleverbrush/schema';

      const zodUser = z.object({ first: z.string(), last: z.string() });

      const order = object({
      user: extern(zodUser),
      date: date(),
      });

      type Order = InferType<typeof order>;
      // { user: { first: string; last: string }; date: Date }

      order.validate({
      user: { first: 'Alice', last: 'Smith' },
      date: new Date(),
      }); // { valid: true, object: { user: …, date: … } }
      // Optional external schema
      const schema = extern(zodUser).optional();
      schema.validate(undefined); // valid
      // Inside an array
      import { array, extern } from '@cleverbrush/schema';
      const users = array(extern(zodUser));