@vecrea/oid4vc-prex
Version:
A TypeScript library for handling OpenID for Verifiable Credentials (OID4VC) Presentation Exchange operations
107 lines (106 loc) • 4.55 kB
TypeScript
import { z } from 'zod';
import { Id } from './Id';
import { Name } from './Name';
import { Purpose } from './Purpose';
import { Filter } from './Filter';
import { JSONSchema } from '.';
/**
* Zod schema for a path in a FieldConstraint.
* This schema ensures that a value is a non-empty set of JSON paths.
* It applies the following validations:
* - The value must be a non-empty set of JSON paths.
* @type {z.ZodNonEmptyArray<string>}
* @example
* // Valid usage
* pathSchema.parse(['$.a', '$.b']); // Returns ['$.a', '$.b']
* // Invalid usage (will throw ZodError)
* pathSchema.parse(['', '$.a', 123]); // Throws error: Invalid JSON path
* @throws {z.ZodError} Throws a ZodError if the input fails validation
*/
export declare const pathSchema: z.ZodOptional<z.ZodArray<z.ZodType<string, any, string>, "atleastone">>;
/**
* Zod schema for a FieldConstraint.
* This schema ensures that a value is a valid FieldConstraint.
* It applies the following validations:
* - The value must be an object.
* - The object may have a path property.
* - The path property must be a non-empty set of JSON paths.
* - The object may have an id property.
* - The id property must be a string.
* - The object may have a name property.
* - The name property must be a string.
* - The object may have a purpose property.
* - The purpose property must be a string.
* - The object may have a filter property.
* - The filter property must be a valid JSON Schema.
* - The object may have an optional property.
* - The optional property must be a boolean.
* - The object may have an intent_to_retain property.
* - The intent_to_retain property must be a boolean.
* @type {z.ZodObject}
* @example
* // Valid usage
* fieldConstraintSchema.parse({ path: ['$.a'], id: '123', name: 'name', purpose: 'purpose', filter: { type: 'string' }, optional: true, intent_to_retain: true }); // Returns { path: ['$.a'], id: '123', name: 'name', purpose: 'purpose', filter: { type: 'string' }, optional: true, intent_to_retain: true }
* // Invalid usage (will throw ZodError)
* fieldConstraintSchema.parse({ path: ['.a'], id: '123', name: 'name', purpose: 'purpose', filter: { type: 'string' }, optional: true, intent_to_retain: true }); // Throws error: Invalid JSON path
* @throws {z.ZodError} Throws a ZodError if the input fails validation
*/
export declare const fieldConstraintSchema: z.ZodType<FieldConstraintJSON>;
/**
* Type of a Path.
*/
export type Path = z.infer<typeof pathSchema>;
/**
* Type of a FieldConstraint JSON object.
*/
export type FieldConstraintJSON = {
path?: Path;
id?: string;
name?: string;
purpose?: string;
filter?: JSONSchema;
optional?: boolean;
intent_to_retain?: boolean;
};
/**
* Represents a item of constraints property of Input Descriptor.
*
* @class
* @example
* // Create a valid Id instance
* const fieldConstraint = new FieldConstraint(['$.a'], new Id('123'), new Name('name'), new Purpose('purpose'), new Filter({ type: 'string' }), true, true);
*
*/
export declare class FieldConstraint {
paths?: Path;
id?: Id | undefined;
name?: Name | undefined;
purpose?: Purpose | undefined;
filter?: Filter | undefined;
optional?: boolean | undefined;
intentToRetain?: boolean | undefined;
/**
* Creates an instance of FieldConstraint.
* @param {Path} paths - The path of the FieldConstraint.
* @param {Id} id - The id of the FieldConstraint.
* @param {Name} name - The name of the FieldConstraint.
* @param {Purpose} purpose - The purpose of the FieldConstraint.
* @param {Filter} filter - The filter of the FieldConstraint.
* @param {boolean} optional - The optional of the FieldConstraint.
* @param {boolean} intentToRetain - The intent_to_retain of the FieldConstraint.
*/
constructor(paths?: Path, id?: Id | undefined, name?: Name | undefined, purpose?: Purpose | undefined, filter?: Filter | undefined, optional?: boolean | undefined, intentToRetain?: boolean | undefined);
/**
* Creates a FieldConstraint instance from a JSON object.
*
* @param {FieldConstraintJSON} json - JSON object representation of the FieldConstraint.
* @returns {FieldConstraint} A FieldConstraint instance.
*/
static fromJSON(json: FieldConstraintJSON): FieldConstraint;
/**
* Returns the JSON representation of the FieldConstraint.
*
* @returns {FieldConstraintJSON} JSON object representation of the FieldConstraint.
*/
toJSON(): FieldConstraintJSON;
}