pulse-ai-utils
Version:
Utility functions and helpers for AI-powered applications
75 lines • 3.39 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSchemaByCategory = getSchemaByCategory;
exports.getSchemaByCategoryLegacy = getSchemaByCategoryLegacy;
const pulseTypeRegistry = __importStar(require("pulse-type-registry"));
const zodToJsonSchema_1 = require("./zodToJsonSchema");
const content_types_config_1 = require("../config/content-types-config");
function getSchemaByCategory(category) {
const typeConfig = content_types_config_1.contentTypesConfig.getContentTypeConfig(category.toLowerCase());
if (!typeConfig) {
throw new Error(`Unsupported category: ${category}`);
}
if (!typeConfig.enabled) {
throw new Error(`Category ${category} is not enabled`);
}
const schemaName = typeConfig.schemaName;
const schema = pulseTypeRegistry[schemaName];
if (!schema) {
throw new Error(`Schema ${schemaName} not found in pulse-type-registry for category ${category}`);
}
return { zod: schema, json: (0, zodToJsonSchema_1.zodToJsonSchema)(schema) };
}
// Legacy function for backward compatibility
function getSchemaByCategoryLegacy(category) {
const categoryLower = category.toLowerCase();
// Build schema mapping dynamically from content types config
const config = content_types_config_1.contentTypesConfig.getConfig();
const allContentTypes = { ...config.contentTypes, ...config.futureTypes };
// Find the content type configuration
const typeConfig = allContentTypes[categoryLower];
if (!typeConfig) {
throw new Error(`Unsupported category: ${category}`);
}
// Get schema from pulse-type-registry using the configured schema name
const schemaName = typeConfig.schemaName;
const schema = pulseTypeRegistry[schemaName];
if (!schema) {
throw new Error(`Schema ${schemaName} not found in pulse-type-registry for category ${category}`);
}
return { zod: schema, json: (0, zodToJsonSchema_1.zodToJsonSchema)(schema) };
}
//# sourceMappingURL=pulseSchemas.js.map