UNPKG

@proofkit/fmodata

Version:
45 lines (44 loc) 1.97 kB
import { ODataRecordMetadata } from './types.js'; import { StandardSchemaV1 } from '@standard-schema/spec'; import { TableOccurrence } from './client/table-occurrence.js'; import { ValidationError, ResponseStructureError, RecordCountMismatchError } from './errors.js'; export type ExpandValidationConfig = { relation: string; targetSchema?: Record<string, StandardSchemaV1>; targetOccurrence?: TableOccurrence<any, any, any, any>; targetBaseTable?: any; occurrence?: TableOccurrence<any, any, any, any>; selectedFields?: string[]; nestedExpands?: ExpandValidationConfig[]; }; /** * Validates a single record against a schema, only validating selected fields. * Also validates expanded relations if expandConfigs are provided. */ export declare function validateRecord<T extends Record<string, any>>(record: any, schema: Record<string, StandardSchemaV1> | undefined, selectedFields?: (keyof T)[], expandConfigs?: ExpandValidationConfig[]): Promise<{ valid: true; data: T & ODataRecordMetadata; } | { valid: false; error: ValidationError; }>; /** * Validates a list response against a schema. */ export declare function validateListResponse<T extends Record<string, any>>(response: any, schema: Record<string, StandardSchemaV1> | undefined, selectedFields?: (keyof T)[], expandConfigs?: ExpandValidationConfig[]): Promise<{ valid: true; data: (T & ODataRecordMetadata)[]; } | { valid: false; error: ResponseStructureError | ValidationError; }>; /** * Validates a single record response against a schema. */ export declare function validateSingleResponse<T extends Record<string, any>>(response: any, schema: Record<string, StandardSchemaV1> | undefined, selectedFields?: (keyof T)[], expandConfigs?: ExpandValidationConfig[], mode?: "exact" | "maybe"): Promise<{ valid: true; data: (T & ODataRecordMetadata) | null; } | { valid: false; error: RecordCountMismatchError | ValidationError; }>;