2026-03-31 14:55:46 +08:00
|
|
|
type SchemaType = 'string' | 'number' | 'boolean';
|
|
|
|
|
interface PrimitiveSchema {
|
|
|
|
|
type: SchemaType;
|
|
|
|
|
}
|
2026-03-31 16:37:14 +08:00
|
|
|
interface NamedSchema {
|
|
|
|
|
name?: string;
|
|
|
|
|
schema: Schema;
|
|
|
|
|
}
|
2026-03-31 14:55:46 +08:00
|
|
|
interface TupleSchema {
|
|
|
|
|
type: 'tuple';
|
2026-03-31 16:37:14 +08:00
|
|
|
elements: NamedSchema[];
|
2026-03-31 14:55:46 +08:00
|
|
|
}
|
|
|
|
|
interface ArraySchema {
|
|
|
|
|
type: 'array';
|
|
|
|
|
element: Schema;
|
|
|
|
|
}
|
|
|
|
|
type Schema = PrimitiveSchema | TupleSchema | ArraySchema;
|
|
|
|
|
interface ParsedSchema {
|
|
|
|
|
schema: Schema;
|
|
|
|
|
validator: (value: unknown) => boolean;
|
|
|
|
|
parse: (valueString: string) => unknown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
declare class ParseError extends Error {
|
|
|
|
|
position?: number | undefined;
|
|
|
|
|
constructor(message: string, position?: number | undefined);
|
|
|
|
|
}
|
|
|
|
|
declare function parseSchema(schemaString: string): Schema;
|
|
|
|
|
|
|
|
|
|
declare function parseValue(schema: Schema, valueString: string): unknown;
|
|
|
|
|
declare function createValidator(schema: Schema): (value: unknown) => boolean;
|
|
|
|
|
|
|
|
|
|
declare function defineSchema(schemaString: string): ParsedSchema;
|
|
|
|
|
|
|
|
|
|
export { type ArraySchema, ParseError, type ParsedSchema, type PrimitiveSchema, type Schema, type TupleSchema, createValidator, defineSchema, parseSchema, parseValue };
|