75 lines
2.1 KiB
Plaintext
75 lines
2.1 KiB
Plaintext
/**
|
|
* @fileoverview Types for object-schema package.
|
|
*/
|
|
/**
|
|
* Built-in validation strategies.
|
|
*/
|
|
export type BuiltInValidationStrategy = "array" | "boolean" | "number" | "object" | "object?" | "string" | "string!";
|
|
/**
|
|
* Built-in merge strategies.
|
|
*/
|
|
export type BuiltInMergeStrategy = "assign" | "overwrite" | "replace";
|
|
/**
|
|
* Custom merge strategy.
|
|
*/
|
|
export type CustomMergeStrategy = (target: any, source: any) => any;
|
|
/**
|
|
* Custom validation strategy.
|
|
*/
|
|
export type CustomValidationStrategy = (value: any) => void;
|
|
interface BasePropertyDefinition {
|
|
/**
|
|
* Indicates if the property is required.
|
|
*/
|
|
required?: boolean;
|
|
/**
|
|
* The other properties that must be present when this property is used.
|
|
*/
|
|
requires?: string[];
|
|
}
|
|
/**
|
|
* Property definition that specifies explicit merge and validation strategies.
|
|
* This form cannot include a `schema`.
|
|
*/
|
|
export interface PropertyDefinitionWithStrategies extends BasePropertyDefinition {
|
|
/**
|
|
* The schema for the object value of this property.
|
|
*/
|
|
schema?: never;
|
|
/**
|
|
* The strategy to merge the property.
|
|
*/
|
|
merge: BuiltInMergeStrategy | CustomMergeStrategy;
|
|
/**
|
|
* The strategy to validate the property.
|
|
*/
|
|
validate: BuiltInValidationStrategy | CustomValidationStrategy;
|
|
}
|
|
/**
|
|
* Property definition that uses a nested `schema`.
|
|
* When `schema` is present, merge and validation strategies are optional.
|
|
*/
|
|
export interface PropertyDefinitionWithSchema extends BasePropertyDefinition {
|
|
/**
|
|
* The schema for the object value of this property.
|
|
*/
|
|
schema: ObjectDefinition;
|
|
/**
|
|
* The strategy to merge the property.
|
|
*/
|
|
merge?: BuiltInMergeStrategy | CustomMergeStrategy;
|
|
/**
|
|
* The strategy to validate the property.
|
|
*/
|
|
validate?: BuiltInValidationStrategy | CustomValidationStrategy;
|
|
}
|
|
/**
|
|
* Property definition.
|
|
*/
|
|
export type PropertyDefinition = PropertyDefinitionWithStrategies | PropertyDefinitionWithSchema;
|
|
/**
|
|
* Object definition.
|
|
*/
|
|
export type ObjectDefinition = Record<string, PropertyDefinition>;
|
|
export {};
|