@proofkit/fmodata
Version:
FileMaker OData API client
55 lines (54 loc) • 2.68 kB
TypeScript
import { StandardSchemaV1 } from '@standard-schema/spec';
import { RecordCountMismatchError, ResponseStructureError, ValidationError } from './errors.js';
import { FMTable } from './orm/table.js';
import { ODataRecordMetadata } from './types.js';
/**
* Validates and transforms input data for insert/update operations.
* Applies input validators (writeValidators) to transform user input to database format.
* Fields without input validators are passed through unchanged.
*
* @param data - The input data to validate and transform
* @param inputSchema - Optional schema containing input validators for each field
* @returns Transformed data ready to send to the server
* @throws ValidationError if any field fails validation
*/
export declare function validateAndTransformInput<T extends Record<string, any>>(data: Partial<T>, inputSchema?: Partial<Record<string, StandardSchemaV1>>): Promise<Partial<T>>;
export interface ExpandValidationConfig {
relation: string;
targetSchema?: Partial<Record<string, StandardSchemaV1>>;
targetTable?: FMTable<any, any>;
table?: FMTable<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: Partial<Record<string, StandardSchemaV1>> | undefined, selectedFields?: (keyof T)[], expandConfigs?: ExpandValidationConfig[], includeSpecialColumns?: boolean): 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: Partial<Record<string, StandardSchemaV1>> | undefined, selectedFields?: (keyof T)[], expandConfigs?: ExpandValidationConfig[], includeSpecialColumns?: boolean): 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: Partial<Record<string, StandardSchemaV1>> | undefined, selectedFields?: (keyof T)[], expandConfigs?: ExpandValidationConfig[], mode?: "exact" | "maybe", includeSpecialColumns?: boolean): Promise<{
valid: true;
data: (T & ODataRecordMetadata) | null;
} | {
valid: false;
error: RecordCountMismatchError | ValidationError;
}>;