@k8ts/metadata
Version:
K8ts tools for working with k8ts metadata.
52 lines • 1.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseMetaInput = parseMetaInput;
const immutable_1 = require("immutable");
const what_are_you_1 = require("what-are-you");
const parse_key_1 = require("../key/parse-key");
const repr_1 = require("../key/repr");
const meta_1 = require("../meta");
function parseMetaInput(input) {
if (input == null) {
return (0, immutable_1.Map)();
}
if (immutable_1.Map.isMap(input)) {
return input;
}
if (input instanceof meta_1.Meta.Meta) {
return input["_dict"];
}
if (input instanceof meta_1.Meta.MutableMeta) {
return input["_meta"]["_dict"];
}
let map = (0, immutable_1.Map)();
for (const [key, value] of Object.entries(input)) {
const outer = (0, parse_key_1.parseOuterKey)(key);
if ((0, what_are_you_1.isNullish)(value)) {
continue;
}
if (outer instanceof repr_1.SectionKey) {
if (typeof value !== "object") {
throw new Error(`Expected object for section key ${key}`);
}
for (const [kk, vv] of Object.entries(value)) {
if ((0, what_are_you_1.isNullish)(vv)) {
continue;
}
const inner = (0, parse_key_1.parseInnerKey)(kk);
if (typeof vv !== "string") {
throw new Error(`Expected string value for inner key ${kk}`);
}
map = map.set(inner.section(outer), vv);
}
}
else {
if (typeof value !== "string") {
throw new Error(`Expected string value for key ${key}`);
}
map = map.set(outer, value);
}
}
return map;
}
//# sourceMappingURL=parse-dict.js.map