astro-ghostcms/.pnpm-store/v3/files/1e/93ce4d0182e9f614902389e04f3...

87 lines
2.6 KiB
Plaintext
Raw Normal View History

2024-02-14 14:10:47 +00:00
'use strict';
var map = require('./common/map.js');
var _null = require('./common/null.js');
var seq = require('./common/seq.js');
var string = require('./common/string.js');
var bool = require('./core/bool.js');
var float = require('./core/float.js');
var int = require('./core/int.js');
var schema = require('./core/schema.js');
var schema$1 = require('./json/schema.js');
var binary = require('./yaml-1.1/binary.js');
var omap = require('./yaml-1.1/omap.js');
var pairs = require('./yaml-1.1/pairs.js');
var schema$2 = require('./yaml-1.1/schema.js');
var set = require('./yaml-1.1/set.js');
var timestamp = require('./yaml-1.1/timestamp.js');
const schemas = new Map([
['core', schema.schema],
['failsafe', [map.map, seq.seq, string.string]],
['json', schema$1.schema],
['yaml11', schema$2.schema],
['yaml-1.1', schema$2.schema]
]);
const tagsByName = {
binary: binary.binary,
bool: bool.boolTag,
float: float.float,
floatExp: float.floatExp,
floatNaN: float.floatNaN,
floatTime: timestamp.floatTime,
int: int.int,
intHex: int.intHex,
intOct: int.intOct,
intTime: timestamp.intTime,
map: map.map,
null: _null.nullTag,
omap: omap.omap,
pairs: pairs.pairs,
seq: seq.seq,
set: set.set,
timestamp: timestamp.timestamp
};
const coreKnownTags = {
'tag:yaml.org,2002:binary': binary.binary,
'tag:yaml.org,2002:omap': omap.omap,
'tag:yaml.org,2002:pairs': pairs.pairs,
'tag:yaml.org,2002:set': set.set,
'tag:yaml.org,2002:timestamp': timestamp.timestamp
};
function getTags(customTags, schemaName) {
let tags = schemas.get(schemaName);
if (!tags) {
if (Array.isArray(customTags))
tags = [];
else {
const keys = Array.from(schemas.keys())
.filter(key => key !== 'yaml11')
.map(key => JSON.stringify(key))
.join(', ');
throw new Error(`Unknown schema "${schemaName}"; use one of ${keys} or define customTags array`);
}
}
if (Array.isArray(customTags)) {
for (const tag of customTags)
tags = tags.concat(tag);
}
else if (typeof customTags === 'function') {
tags = customTags(tags.slice());
}
return tags.map(tag => {
if (typeof tag !== 'string')
return tag;
const tagObj = tagsByName[tag];
if (tagObj)
return tagObj;
const keys = Object.keys(tagsByName)
.map(key => JSON.stringify(key))
.join(', ');
throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
});
}
exports.coreKnownTags = coreKnownTags;
exports.getTags = getTags;