UNPKG

@gati-framework/runtime

Version:

Gati runtime execution engine for running handler-based applications

121 lines 2.79 kB
/** * @module runtime/gtype/schema * @description GType schema definitions for runtime type validation */ /** * Create a primitive GType */ export function primitive(primitiveType, options) { return { kind: 'primitive', primitiveType, ...options, }; } /** * Create a literal GType */ export function literal(value, options) { return { kind: 'literal', value, ...options, }; } /** * Create an object GType */ export function object(properties, options) { return { kind: 'object', properties, ...options, }; } /** * Create an array GType */ export function array(items, options) { return { kind: 'array', items, ...options, }; } /** * Create a tuple GType */ export function tuple(items, options) { return { kind: 'tuple', items, ...options, }; } /** * Create a union GType */ export function union(types, options) { return { kind: 'union', types, ...options, }; } /** * Create an intersection GType */ export function intersection(types, options) { return { kind: 'intersection', types, ...options, }; } /** * Create an enum GType */ export function enumType(values, options) { return { kind: 'enum', values, ...options, }; } /** * Common GType helpers */ export const GTypes = { string: () => primitive('string'), number: () => primitive('number'), boolean: () => primitive('boolean'), null: () => primitive('null'), undefined: () => primitive('undefined'), optional: (type) => ({ ...type, optional: true }), nullable: (type) => ({ ...type, nullable: true }), stringWithPattern: (pattern, message) => primitive('string', { validators: [{ type: 'pattern', value: pattern, message }], }), email: () => primitive('string', { validators: [{ type: 'email', message: 'Must be a valid email' }], }), url: () => primitive('string', { validators: [{ type: 'url', message: 'Must be a valid URL' }], }), uuid: () => primitive('string', { validators: [{ type: 'uuid', message: 'Must be a valid UUID' }], }), minLength: (min, message) => primitive('string', { validators: [{ type: 'minLength', value: min, message }], }), maxLength: (max, message) => primitive('string', { validators: [{ type: 'maxLength', value: max, message }], }), min: (min, message) => primitive('number', { validators: [{ type: 'min', value: min, message }], }), max: (max, message) => primitive('number', { validators: [{ type: 'max', value: max, message }], }), }; //# sourceMappingURL=schema.js.map