@gati-framework/runtime
Version:
Gati runtime execution engine for running handler-based applications
167 lines • 4.67 kB
TypeScript
/**
* @module runtime/gtype/schema
* @description GType schema definitions for runtime type validation
*/
/**
* Primitive type kinds
*/
export type PrimitiveKind = 'string' | 'number' | 'boolean' | 'null' | 'undefined';
/**
* GType kind discriminator
*/
export type GTypeKind = 'primitive' | 'object' | 'array' | 'union' | 'intersection' | 'literal' | 'tuple' | 'enum';
/**
* Base GType interface
*/
export interface GTypeBase {
kind: GTypeKind;
description?: string;
optional?: boolean;
nullable?: boolean;
validators?: Validator[];
}
/**
* Primitive GType
*/
export interface GTypePrimitive extends GTypeBase {
kind: 'primitive';
primitiveType: PrimitiveKind;
}
/**
* Literal GType (specific value)
*/
export interface GTypeLiteral extends GTypeBase {
kind: 'literal';
value: string | number | boolean | null;
}
/**
* Object GType
*/
export interface GTypeObject extends GTypeBase {
kind: 'object';
properties: Record<string, GType>;
required?: string[];
additionalProperties?: boolean | GType;
}
/**
* Array GType
*/
export interface GTypeArray extends GTypeBase {
kind: 'array';
items: GType;
minItems?: number;
maxItems?: number;
}
/**
* Tuple GType (fixed-length array with specific types)
*/
export interface GTypeTuple extends GTypeBase {
kind: 'tuple';
items: GType[];
}
/**
* Union GType (one of several types)
*/
export interface GTypeUnion extends GTypeBase {
kind: 'union';
types: GType[];
}
/**
* Intersection GType (all of several types)
*/
export interface GTypeIntersection extends GTypeBase {
kind: 'intersection';
types: GType[];
}
/**
* Enum GType (one of specific values)
*/
export interface GTypeEnum extends GTypeBase {
kind: 'enum';
values: (string | number)[];
}
/**
* Union of all GType variants
*/
export type GType = GTypePrimitive | GTypeLiteral | GTypeObject | GTypeArray | GTypeTuple | GTypeUnion | GTypeIntersection | GTypeEnum;
/**
* Validator types
*/
export type ValidatorType = 'min' | 'max' | 'minLength' | 'maxLength' | 'pattern' | 'email' | 'url' | 'uuid' | 'enum' | 'custom';
/**
* Validator definition
*/
export interface Validator {
type: ValidatorType;
value?: unknown;
message?: string;
fn?: (value: unknown) => boolean;
}
/**
* GType reference (for recursive types)
*/
export interface GTypeRef {
$ref: string;
}
/**
* GType schema with definitions
*/
export interface GTypeSchema {
$id?: string;
$schema?: string;
type: GType;
definitions?: Record<string, GType>;
}
/**
* Create a primitive GType
*/
export declare function primitive(primitiveType: PrimitiveKind, options?: Partial<Omit<GTypePrimitive, 'kind' | 'primitiveType'>>): GTypePrimitive;
/**
* Create a literal GType
*/
export declare function literal(value: string | number | boolean | null, options?: Partial<Omit<GTypeLiteral, 'kind' | 'value'>>): GTypeLiteral;
/**
* Create an object GType
*/
export declare function object(properties: Record<string, GType>, options?: Partial<Omit<GTypeObject, 'kind' | 'properties'>>): GTypeObject;
/**
* Create an array GType
*/
export declare function array(items: GType, options?: Partial<Omit<GTypeArray, 'kind' | 'items'>>): GTypeArray;
/**
* Create a tuple GType
*/
export declare function tuple(items: GType[], options?: Partial<Omit<GTypeTuple, 'kind' | 'items'>>): GTypeTuple;
/**
* Create a union GType
*/
export declare function union(types: GType[], options?: Partial<Omit<GTypeUnion, 'kind' | 'types'>>): GTypeUnion;
/**
* Create an intersection GType
*/
export declare function intersection(types: GType[], options?: Partial<Omit<GTypeIntersection, 'kind' | 'types'>>): GTypeIntersection;
/**
* Create an enum GType
*/
export declare function enumType(values: (string | number)[], options?: Partial<Omit<GTypeEnum, 'kind' | 'values'>>): GTypeEnum;
/**
* Common GType helpers
*/
export declare const GTypes: {
string: () => GTypePrimitive;
number: () => GTypePrimitive;
boolean: () => GTypePrimitive;
null: () => GTypePrimitive;
undefined: () => GTypePrimitive;
optional: (type: GType) => GType;
nullable: (type: GType) => GType;
stringWithPattern: (pattern: string, message?: string) => GTypePrimitive;
email: () => GTypePrimitive;
url: () => GTypePrimitive;
uuid: () => GTypePrimitive;
minLength: (min: number, message?: string) => GTypePrimitive;
maxLength: (max: number, message?: string) => GTypePrimitive;
min: (min: number, message?: string) => GTypePrimitive;
max: (max: number, message?: string) => GTypePrimitive;
};
//# sourceMappingURL=schema.d.ts.map