UNPKG

@vecrea/oid4vc-prex

Version:

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

151 lines (150 loc) 5.58 kB
import { z } from 'zod'; import { SubmissionRequirement, SubmissionRequirementJSON } from './SubmissionRequirement'; import { Group } from './Group'; /** * Zod schema for the from property of Submission Requirements * * This schema ensures that a value is a non-empty string. * It applies the following validations: * - The value must be a string. * - The string must have a minimum length of 1. * * @type {z.ZodString} * * @example * // Valid usage * fromGroupSchema.parse('issuer'); // Returns 'issuer' * * // Invalid usage (will throw ZodError) * fromGroupSchema.parse(''); // Throws error: Expected string to have a minimum length of 1, received empty string * fromGroupSchema.parse(123); // Throws error: Expected string, received number * * @throws {z.ZodError} Throws a ZodError if the input fails validation */ export declare const fromGroupSchema: z.ZodString; /** * Zod schema for the from_nested property of Submission Requirements * * This schema ensures that a value is an array of SubmissionRequirementJSON objects. * It applies the following validations: * - The value must be an array. * - The array must contain SubmissionRequirementJSON objects. * * @type {z.ZodArray<z.ZodType<SubmissionRequirementJSON>>} * * @example * // Valid usage * fromNestedSchema.parse([{ "from": "issuer" }]); // Returns [{ "from": "issuer" }] * * // Invalid usage (will throw ZodError) * fromNestedSchema.parse([{ "from": "issuer" }, { "from": "subject" }]); // Throws error: Invalid SubmissionRequirement * fromNestedSchema.parse([{ "from": "issuer" }, { "from_nested": [{ "from": "subject" }] }]); // Throws error: Invalid SubmissionRequirement * * @throws {z.ZodError} Throws a ZodError if the input fails validation */ export declare const fromNestedSchema: z.ZodType<SubmissionRequirementJSON[]>; /** * Zod schema for validating FromJSON values. * This schema ensures that a value is an object with optional 'from' and 'from_nested' properties. * - 'from' must be a non-empty string or undefined. * - 'from_nested' must be an array of SubmissionRequirementJSON objects or undefined. * * @type {z.ZodObject<{ from: z.ZodString; from_nested: z.ZodArray<z.ZodType<SubmissionRequirementJSON>> }>} * * @example * // Valid usage * fromSchema.parse({ from: 'issuer' }); // Returns { from: 'issuer' } * fromSchema.parse({ from_nested: [{ "from": "issuer" }] }); // Returns { from_nested: [{ "from": "issuer" }] } * * // Invalid usage (will throw ZodError) * fromSchema.parse({ from: 'issuer', from_nested: [{ "from": "issuer" }] }); // Throws error: From and FromNested cannot be defined at the same time * fromSchema.parse({}); // Throws error: From or FromNested must be defined * * @throws {z.ZodError} Throws a ZodError if the input fails validation */ export declare const fromSchema: z.ZodEffects<z.ZodObject<{ from: z.ZodOptional<z.ZodString>; from_nested: z.ZodOptional<z.ZodType<SubmissionRequirementJSON[], z.ZodTypeDef, SubmissionRequirementJSON[]>>; }, "strip", z.ZodTypeAny, { from?: string | undefined; from_nested?: SubmissionRequirementJSON[] | undefined; }, { from?: string | undefined; from_nested?: SubmissionRequirementJSON[] | undefined; }>, { from?: string | undefined; from_nested?: SubmissionRequirementJSON[] | undefined; }, { from?: string | undefined; from_nested?: SubmissionRequirementJSON[] | undefined; }>; /** * Type of from / from_nested JSON object. */ export type FromJSON = z.infer<typeof fromSchema>; /** * Interface for From. * This interface represents the from or from_nested property of Submission Requirements * @interface */ export interface From { readonly __type: 'FromGroup' | 'FromNested'; /** * Returns the JSON representation of the From object. * @returns {FromJSON} JSON representation of the From object. */ toJSON(): FromJSON; } /** * Namespace for From * @namespace */ export declare namespace From { /** * Creates a new From object from a JSON object. * @param {FromJSON} * @returns {From} From object created from the JSON object. * @throws {Error} Throws an error if the JSON object is invalid. */ const fromJSON: (json: FromJSON) => From; /** * Represents the from property of Submission Requirements * @class * @implements {From} * @param {Group} group - The group instance. */ class FromGroup implements From { group: Group; readonly __type: "FromGroup"; /** * Creates a new FromGroup object. * @param group - The group instance. */ constructor(group: Group); /** * Returns the JSON representation of the From object. * @returns {FromJSON} JSON representation of the From object. */ toJSON(): FromJSON; } /** * Represents the from_nested property of Submission Requirements * @class * @implements {From} * @param {SubmissionRequirement[]} nested - The nested value of the From object. */ class FromNested implements From { nested: SubmissionRequirement[]; readonly __type: "FromNested"; /** * Creates a new FromNested object. * @param nested - The array of SubmissionRequirement instance. */ constructor(nested: SubmissionRequirement[]); /** * Returns the JSON representation of the From object. * @returns {FromJSON} JSON representation of the From object. */ toJSON(): FromJSON; } }