UNPKG

weavebot-core

Version:

Generic content processing framework for web scraping and AI extraction

99 lines (98 loc) 2.77 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/schemas/index.ts var schemas_exports = {}; __export(schemas_exports, { SchemaRegistry: () => SchemaRegistry, createSchemaRegistry: () => createSchemaRegistry, defaultSchemaRegistry: () => defaultSchemaRegistry }); module.exports = __toCommonJS(schemas_exports); var SchemaRegistry = class { schemas = /* @__PURE__ */ new Map(); fieldMappings = /* @__PURE__ */ new Map(); /** * Register a schema with optional field mapping */ register(name, schema, fieldMapping) { this.schemas.set(name, schema); if (fieldMapping) { this.fieldMappings.set(name, fieldMapping); } } /** * Validate data against a registered schema */ validate(schemaName, data) { const schema = this.schemas.get(schemaName); if (!schema) { throw new Error(`Schema '${schemaName}' not found`); } return schema.parse(data); } /** * Get a registered schema */ getSchema(name) { return this.schemas.get(name); } /** * Get field mapping for a schema */ getFieldMapping(name) { return this.fieldMappings.get(name); } /** * List all registered schema names */ listSchemas() { return Array.from(this.schemas.keys()); } /** * Check if a schema is registered */ hasSchema(name) { return this.schemas.has(name); } /** * Clear all registered schemas */ clear() { this.schemas.clear(); this.fieldMappings.clear(); } }; var defaultSchemaRegistry = new SchemaRegistry(); function createSchemaRegistry(schemas, mappings) { const registry = new SchemaRegistry(); if (schemas) { Object.entries(schemas).forEach(([name, schema]) => { const mapping = mappings?.[name]; registry.register(name, schema, mapping); }); } return registry; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { SchemaRegistry, createSchemaRegistry, defaultSchemaRegistry }); //# sourceMappingURL=schemas.js.map