27 lines
943 B
TypeScript
27 lines
943 B
TypeScript
import type { Command, CommandSchema } from './types.js';
|
|
import { parseCommand } from './command-parse.js';
|
|
import { parseCommandSchema } from './schema-parse.js';
|
|
import { applyCommandSchema as applyCommandSchemaCore } from './command-apply.js';
|
|
|
|
export { applyCommandSchemaCore as applyCommandSchema };
|
|
|
|
export function validateCommand(
|
|
command: Command,
|
|
schema: CommandSchema
|
|
): { valid: true } | { valid: false; errors: string[] } {
|
|
const result = applyCommandSchemaCore(command, schema);
|
|
if (result.valid) {
|
|
return { valid: true };
|
|
}
|
|
return { valid: false, errors: result.errors };
|
|
}
|
|
|
|
export function parseCommandWithSchema(
|
|
input: string,
|
|
schemaStr: string
|
|
): { command: Command; valid: true } | { command: Command; valid: false; errors: string[] } {
|
|
const schema = parseCommandSchema(schemaStr);
|
|
const command = parseCommand(input);
|
|
return applyCommandSchemaCore(command, schema);
|
|
}
|