UNPKG

@k8ts/instruments

Version:

A collection of utilities and core components for k8ts.

161 lines 7.28 kB
"use strict"; var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); var _, done = false; for (var i = decorators.length - 1; i >= 0; i--) { var context = {}; for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; for (var p in contextIn.access) context.access[p] = contextIn.access[p]; context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); if (kind === "accessor") { if (result === void 0) continue; if (result === null || typeof result !== "object") throw new TypeError("Object expected"); if (_ = accept(result.get)) descriptor.get = _; if (_ = accept(result.set)) descriptor.set = _; if (_ = accept(result.init)) initializers.unshift(_); } else if (_ = accept(result)) { if (kind === "field") initializers.unshift(_); else descriptor[key] = _; } } if (target) Object.defineProperty(target, contextIn.name, descriptor); done = true; }; var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { var useValue = arguments.length > 2; for (var i = 0; i < initializers.length; i++) { value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); } return useValue ? value : void 0; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.auto_register = exports.Origin = void 0; const chalk_1 = __importDefault(require("chalk")); const doddle_1 = require("doddle"); const stacktracey_1 = __importDefault(require("stacktracey")); const _string_1 = require("../_string"); const displayers_1 = require("../displayers"); const kind_map_1 = require("../kind-map"); const tracing_1 = require("../tracing"); const trace_1 = require("../tracing/trace"); const base_node_1 = require("./base-node"); const resource_node_1 = require("./resource-node"); let Origin = (() => { let _classDecorators = [(0, displayers_1.displayers)({ simple: s => `[${s.shortFqn}]`, prefix: s => { if (s.name === "EXTERNAL") { return (0, _string_1.getMarkerForExternal)(); } return (0, _string_1.getMarkerForIndex)(s.index); }, pretty(origin, format) { const kindName = chalk_1.default.greenBright.bold(origin.kind.name); const resourceName = chalk_1.default.cyan(origin.name); const pref = this.prefix(); return chalk_1.default.underline(`${pref}${kindName}:${resourceName}`); } })]; let _classDescriptor; let _classExtraInitializers = []; let _classThis; let _classSuper = base_node_1.BaseNode; var Origin = class extends _classSuper { static { _classThis = this; } static { const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0; __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers); Origin = _classThis = _classDescriptor.value; if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); __runInitializers(_classThis, _classExtraInitializers); } parent; key; _kids = []; get kids() { return (0, doddle_1.seq)(this._kids); } get meta() { return this._entity.meta; } index; _getIndex = (0, doddle_1.doddle)(() => { let index = 1; return () => index++; }).pull(); constructor(parent, entity, key) { super(entity); this.parent = parent; this.key = key; this.index = parent?._getIndex() ?? 0; this._kindMap = new kind_map_1.KindMap(undefined, parent?._kindMap); } get resourceKinds() { return this._kindMap; } _kindMap; _attached = []; get relations() { return doddle_1.seq.empty(); } [Symbol.iterator]() { return this.resources[Symbol.iterator](); } attachedTree = (0, doddle_1.seq)(() => { const self = this; const desc = self.descendants.concatFirst([this]).concatMap(function* (x) { yield* self.resources; for (const kid of self.kids) { yield* kid.resources; } }); return desc; }).cache(); get resources() { return this._attached; } static registerWithOrigin(ctor) { const prototype = ctor.prototype; for (const key of Object.getOwnPropertyNames(prototype)) { const value = prototype[key]; if (!key.match(/^[A-Z]/) || typeof value !== "function") { continue; } const orig = prototype[key]; prototype[key] = { [key](...args) { const result = orig.apply(this, args); if (typeof result === "object" && "node" in result && result.node instanceof resource_node_1.ResourceNode) { result.node.origin.__attach_resource__([result.node]); tracing_1.TraceEmbedder.set(result.node, new trace_1.Trace(new stacktracey_1.default().slice(1))); } return result; } }[key]; } } __attach_child__(child) { this._kids.push(child); } __attach_resource__(resources) { resources = Symbol.iterator in resources ? resources : [resources]; for (const resource of resources) { this._attached.push(resource); } } }; return Origin = _classThis; })(); exports.Origin = Origin; exports.auto_register = Origin.registerWithOrigin; //# sourceMappingURL=origin-node.js.map