UNPKG

@sentzunhat/zacatl

Version:

A modular, high-performance TypeScript microservice framework for Node.js, featuring layered architecture, dependency injection, and robust validation for building scalable APIs and distributed systems.

50 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.loadYAML = exports.loadYML = void 0; const fs_1 = require("fs"); const js_yaml_1 = require("js-yaml"); const error_1 = require("../error/index.js"); const utils_1 = require("../utils/index.js"); const loadYML = (filePath, schema) => { try { const content = (0, fs_1.readFileSync)(filePath, 'utf-8'); const data = (0, js_yaml_1.load)(content); if (schema) { return schema.parse(data); } return data; } catch (error) { if ((0, utils_1.isNodeError)(error) && error.code === 'ENOENT') { throw new error_1.NotFoundError({ message: `YAML file not found: ${filePath}`, component: 'YAMLLoader', operation: 'loadYML', }); } if (error instanceof Error && error.name === 'YAMLException') { throw new error_1.BadRequestError({ message: `Invalid YAML in file: ${filePath}`, reason: error.message, component: 'YAMLLoader', operation: 'loadYML', }); } if ((0, utils_1.isZodError)(error)) { throw new error_1.ValidationError({ message: `YAML validation failed for file: ${filePath}`, reason: "Data doesn't match the expected schema", component: 'YAMLLoader', operation: 'loadYML', metadata: { filePath, issues: error.issues, }, }); } throw error; } }; exports.loadYML = loadYML; exports.loadYAML = exports.loadYML; //# sourceMappingURL=yml.js.map