UNPKG

@vecrea/oid4vc-prex

Version:

A TypeScript library for handling OpenID for Verifiable Credentials (OID4VC) Presentation Exchange operations

39 lines (38 loc) 1.5 kB
import { z } from 'zod'; /** * Create Zod schema for non-empty set * This function returns schema ensures a value is a non-empty array. * * It applies the following validations: * - The value must be a array. * - The array must have 1 or more items. * * @template T typeof schema * @param {z.ZodType<T, any>} schema Zod schema * @returns {z.ZodNonEmptyArray<T>} non-empty set schema * * @example * // Valid usage * const itemSchema = z.string(); * const nonEmptySetSchema = createNonEmptySetSchema(itemSchema); * nonEmptySetSchema.parse(['abc123', "def456"]); // Returns ['abc123', "def456"] * nonEmptySetSchema.parse(['a']); // Returns ['a'] * * // Invalid usage (will throw ZodError) * const itemSchema = z.string(); * const nonEmptySetSchema = createNonEmptySetSchema(itemSchema); * nonEmptySetSchema.parse(''); // Throws error: String must contain at least 1 character(s) * nonEmptySetSchema.parse(123); // Throws error: Expected string, received number */ export declare const createNonEmptySetSchema: <T>(schema: z.ZodType<T, any>) => z.ZodArray<z.ZodType<T, any, T>, "atleastone">; /** * Type of the non-empty set. * @template T typeof schema * * * @example * const itemSchema = z.string(); * const nonEmptySetSchema = createNonEmptySetSchema(itemSchema); * const nonEmptySet: NonEmptySet<z.infer<typeof itemSchema>> = nonEmptySetSchema.parse(['abc123', 'def456']); */ export type NonEmptySet<T> = z.infer<z.ZodArray<z.ZodType<T, any, T>, 'atleastone'>>;