UNPKG

@vecrea/oid4vc-prex

Version:

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

170 lines (169 loc) 4.79 kB
import { z } from 'zod'; /** * Zod schema for validating all values. * * This schema ensures that the rule is 'all'. * * @type {z.ZodString} * * @example * // Valid usage * allSchema.parse({ rule: 'all' }); // Returns { rule: 'all' } * * // Invalid usage (will throw ZodError) * allSchema.parse({ rule: 'pick' }); // Throws error: Invalid input * * @throws {z.ZodError} Throws a ZodError if the input fails validation */ export declare const allSchema: z.ZodObject<{ rule: z.ZodLiteral<"all">; }, "strip", z.ZodTypeAny, { rule: "all"; }, { rule: "all"; }>; /** * Zod schema for validating pick values. * * This schema ensures that the rule is 'pick' and that the count, min, and max properties are numbers. * * @type {z.ZodObject} * * @example * // Valid usage * pickSchema.parse({ rule: 'pick', count: 1, min: 0, max: 1 }); // Returns { rule: 'pick', count: 1, min: 0, max: 1 } * * // Invalid usage (will throw ZodError) * pickSchema.parse({ rule: 'pick', count: '1', min: 0, max: 1 }); // Throws error: Invalid input * * @throws {z.ZodError} Throws a ZodError if the input fails validation */ export declare const pickSchema: z.ZodObject<{ rule: z.ZodLiteral<"pick">; count: z.ZodOptional<z.ZodNumber>; min: z.ZodOptional<z.ZodNumber>; max: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { rule: "pick"; count?: number | undefined; min?: number | undefined; max?: number | undefined; }, { rule: "pick"; count?: number | undefined; min?: number | undefined; max?: number | undefined; }>; /** * Zod discriminated union for validating rule values. * This schema ensures that the rule is either 'all' or 'pick'. * * @type {z.ZodUnion} * * @example * // Valid usage * ruleSchema.parse({ rule: 'all' }); // Returns { rule: 'all' } * ruleSchema.parse({ rule: 'pick', count: 1, min: 0, max: 1 }); // Returns { rule: 'pick', count: 1, min: 0, max: 1 } * * // Invalid usage (will throw ZodError) * ruleSchema.parse({ rule: 'invalid' }); // Throws error: Invalid input * ruleSchema.parse({ rule: 'pick', count: '1', min: 0, max: 1 }); // Throws error: Invalid input * * @throws {z.ZodError} Throws a ZodError if the input fails validation */ export declare const ruleSchema: z.ZodDiscriminatedUnion<"rule", [z.ZodObject<{ rule: z.ZodLiteral<"all">; }, "strip", z.ZodTypeAny, { rule: "all"; }, { rule: "all"; }>, z.ZodObject<{ rule: z.ZodLiteral<"pick">; count: z.ZodOptional<z.ZodNumber>; min: z.ZodOptional<z.ZodNumber>; max: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { rule: "pick"; count?: number | undefined; min?: number | undefined; max?: number | undefined; }, { rule: "pick"; count?: number | undefined; min?: number | undefined; max?: number | undefined; }>]>; /** * Type of a rule. */ export type RuleJSON = z.infer<typeof ruleSchema>; /** * Interface for Rule. * This interface represents the rule property of Submission Requirements * @interface */ export interface Rule { readonly __type: 'All' | 'Pick'; /** * Returns the JSON representation of Rule. * @returns {RuleJSON} */ toJSON(): RuleJSON; } /** * Namespace for Rule. * @namespace */ export declare namespace Rule { /** * Returns a Rule instance from a JSON object. * @param {RuleJSON} json - The JSON object. * * @returns {Rule} The Rule instance. */ const fromJSON: (json: RuleJSON) => Rule; /** * Represents the 'all' rule. * @class */ class All implements Rule { readonly __type: "All"; private static instance; /** * Private constructor for All. */ private constructor(); /** * Returns the instance of All. * @returns {All} */ static readResolve(): All; /** * Returns the JSON representation of All. * @returns {RuleJSON} */ toJSON(): RuleJSON; } /** * Represents the 'pick' rule. * @class */ class Pick implements Rule { count?: number | undefined; min?: number | undefined; max?: number | undefined; readonly __type: "Pick"; /** * Constructor for Pick. * @param {number} count - The number of requirements to pick. * @param {number} min - The minimum number of requirements to pick. * @param {number} max - The maximum number of requirements to pick. */ constructor(count?: number | undefined, min?: number | undefined, max?: number | undefined); /** * Returns the JSON representation of Pick. * @returns {RuleJSON} */ toJSON(): RuleJSON; } }