UNPKG

@k8ts/instruments

Version:

A collection of utilities and core components for k8ts.

69 lines 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RefKey = void 0; const immutable_1 = require("immutable"); const error_1 = require("../error"); var RefKey; (function (RefKey_1) { function make(kind, name) { return new RefKey(kind, name); } RefKey_1.make = make; const separator = "/"; function parse(ref) { const result = tryParse(ref); if (!result) { throw new error_1.InstrumentsError(`Could not parse reference key: ${ref}`); } return result; } RefKey_1.parse = parse; function tryParse(ref) { if (typeof ref !== "string") { return undefined; } if (ref == null) { return undefined; } if (typeof ref === "object") { return undefined; } const [kind, name] = ref.split(separator).map(s => s.trim()); if (!kind || !name) { return undefined; } return { kind, name }; } RefKey_1.tryParse = tryParse; class RefKey { kind; name; constructor(kind, name) { this.kind = kind; this.name = name; } get string() { return [this.kind.name, this.name].join(separator); } equals(other) { if (other == null) { return false; } if (typeof other !== "object") { return false; } return this.kind.equals(other.kind) && this.name === other.name; } hashCode() { return (0, immutable_1.hash)(this.string); } toString() { return this.string; } } RefKey_1.RefKey = RefKey; })(RefKey || (exports.RefKey = RefKey = {})); //# sourceMappingURL=ref-key.js.map