@axarai/axar
Version:
TypeScript-based agent framework for building agentic applications powered by LLMs
35 lines (34 loc) • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasSchemaDef = hasSchemaDef;
exports.getSchemaDef = getSchemaDef;
const meta_keys_1 = require("./meta-keys");
/**
* Checks if a class has an associated Zod schema.
*
* This function determines whether the specified class constructor
* has been decorated with a Zod schema, by checking for the presence
* of metadata associated with the schema.
*
* @internal
* @param target - The class constructor to check for schema metadata.
* @returns A boolean indicating if the Zod schema metadata is present.
*/
function hasSchemaDef(target) {
return Reflect.hasMetadata(meta_keys_1.META_KEYS.SCHEMA_DEF, target);
}
/**
* Retrieves the Zod schema associated with the specified class constructor.
*
* @internal
* @param target - The class constructor to retrieve the schema for.
* @returns The Zod schema associated with the class constructor
* @throws Error if no schema is present.
*/
function getSchemaDef(target) {
const schema = Reflect.getMetadata(meta_keys_1.META_KEYS.SCHEMA_DEF, target);
if (!schema) {
throw new Error(`No schema found for ${target.name}. Did you apply @schema decorator?`);
}
return schema;
}