UNPKG

@k8ts/metadata

Version:

K8ts tools for working with k8ts metadata.

53 lines 2.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pNameValue = exports.normalChar = void 0; exports.parseSectionKey = parseSectionKey; exports.checkValue = checkValue; exports.parseInnerKey = parseInnerKey; exports.parseOuterKey = parseOuterKey; const parjs_1 = require("parjs"); const combinators_1 = require("parjs/combinators"); const error_1 = require("../error"); const repr_1 = require("./repr"); const cPrefix = (0, parjs_1.anyCharOf)("%^#"); const cSection = (0, parjs_1.string)("/"); const cExtra = (0, parjs_1.anyCharOf)("-_.").expects("'-', '_', or '.'"); exports.normalChar = (0, parjs_1.upper)().pipe((0, combinators_1.or)((0, parjs_1.lower)(), (0, parjs_1.digit)())).expects("alphanumeric"); const cNameChar = (0, parjs_1.lower)().pipe((0, combinators_1.or)((0, parjs_1.digit)())).pipe((0, combinators_1.or)("-")); const cInterior = exports.normalChar.pipe((0, combinators_1.or)(cExtra)).expects("alphanumeric, '-', '_', or '.'"); exports.pNameValue = cNameChar.pipe((0, combinators_1.many1)(), (0, combinators_1.stringify)()); const pSpecialKey = (0, parjs_1.anyStringOf)("namespace", "name").pipe((0, combinators_1.map)(key => { return new repr_1.ValueKey("", "", key); })); const pCleanKey = cInterior.pipe((0, combinators_1.many1)(), (0, combinators_1.stringify)()); const pSectionKey = pCleanKey.pipe((0, combinators_1.thenq)(cSection), (0, combinators_1.map)(x => new repr_1.SectionKey(x))); const pInnerKey = cPrefix.pipe((0, combinators_1.then)(pCleanKey), (0, combinators_1.map)(([prefix, name]) => { return new repr_1.ValueKey(prefix, "", name); })); const pKey = cPrefix.pipe((0, combinators_1.then)(pCleanKey, cSection.pipe((0, combinators_1.qthen)(pCleanKey), (0, combinators_1.stringify)(), (0, combinators_1.maybe)())), (0, combinators_1.map)(([prefix, nameOrSection, name]) => { if (name) { return new repr_1.ValueKey(prefix, nameOrSection, name); } return new repr_1.ValueKey(prefix, "", nameOrSection); }), (0, combinators_1.or)(pSpecialKey)); const pOuterKey = pKey.pipe((0, combinators_1.or)(pSectionKey)); function parseSectionKey(key) { return pSectionKey.parse(key).value; } function checkValue(value) { return value === "" ? "" : pCleanKey.parse(value).value; } function parseInnerKey(key) { return pInnerKey.parse(key).value; } function parseOuterKey(key) { const result = pOuterKey.parse(key); if (result.kind === "OK") { return result.value; } throw new error_1.MetadataError(`Failed to parse key ${key}: ${result.toString()}`, { key, error: result.toString() }); } //# sourceMappingURL=parse-key.js.map