UNPKG

@sprucelabs/schema

Version:

Static and dynamic binding plus runtime validation and transformation to ensure your app is sound. 🤓

31 lines (30 loc) • 1.36 kB
import { FieldDefinitions } from './../.spruce/schemas/fields/fields.types'; import { FieldError } from '../errors/options.types'; import { FieldTemplateDetails, FieldTemplateDetailOptions } from '../types/template.types'; import { ValidateOptions, Field } from './field.static.types'; export default abstract class AbstractField<F extends FieldDefinitions> implements Field<F> { /** The definition for this field */ definition: F; /** Shortcut to this field */ readonly type: F['type']; /** The name of this field (camel case) */ name: string; constructor(name: string, definition: F); static description: string; /** For mapping schemas to types dynamically in schema values */ static generateTypeDetails(): { valueTypeMapper: string | undefined; }; /** Details needed for generating templates */ static generateTemplateDetails(_options: FieldTemplateDetailOptions<any>): FieldTemplateDetails; get options(): F["options"]; get isRequired(): boolean; get isPrivate(): boolean; get isArray(): boolean; get label(): string | undefined; get hint(): string | undefined; get minArrayLength(): number; validate(value: any, _?: ValidateOptions<F>): FieldError[]; /** Transform any value to the value type of this field */ toValueType(value: any, _: any): any; }