/** * @file yaml.js * @description js-yaml 5 with js-yaml 4's loading rules, for the YAML files * AgentHub reads from a user (a repo's docker-compose file, omp's * `models.yml`/`config.yml`). js-yaml 5's `load` uses the bare YAML 1.2 core * schema — no `<<` merge keys, no timestamps, `!!binary`/`!!set` refused — and * throws on an empty document; 4's default schema was core plus exactly those * tags, and an empty document loaded as `undefined`. A member's file that * loaded before must load the same now (and `mergedModels` rewrites it). * @author Nguyễn Ngọc Trí Vĩ */ const yaml = require("js-yaml"); /** js-yaml 4's DEFAULT_SCHEMA. */ const V4_SCHEMA = yaml.CORE_SCHEMA.withTags([ yaml.mergeTag, yaml.timestampTag, yaml.binaryTag, yaml.omapTag, yaml.pairsTag, yaml.setTag, ]); /** `yaml.load` as js-yaml 4 did it: undefined for a document-less text. */ function load(text) { try { return yaml.load(text, { schema: V4_SCHEMA }); } catch (err) { if (err && /input is empty/.test(err.reason || "")) return undefined; throw err; } } module.exports = { load, dump: yaml.dump, V4_SCHEMA };