UNPKG

@k8ts/instruments

Version:

A collection of utilities and core components for k8ts.

64 lines 1.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.manifest = exports.Builder = void 0; const _1 = require("."); const base_1 = require("../_embedder/base"); class BuilderDecorator { _system = new base_1.Embedder("builder"); implement(ctor, input) { this._system.set(ctor.prototype, { ...input }); } _metadata(self) { return { name: self.meta.get("name"), namespace: self.meta.tryGet("namespace"), labels: self.meta.labels, annotations: self.meta.annotations }; } _idents(self) { return { apiVersion: self.kind.parent.text, kind: self.kind.name }; } async manifest(trait, self) { const mani = { ...trait.ident(), metadata: trait.metadata(), ...(await trait.body()) }; _1.ManifestSourceEmbedder.set(mani, self); return mani; } idents(self) { return { kind: self.kind.name, apiVersion: self.kind.parent.text }; } get(target) { const input = this._system.get(target); const o = { ident: () => input.ident?.call(o, target) ?? this._idents(target), metadata: () => input.metadata?.call(o, target) ?? this._metadata(target), body: () => input.body.call(o, target), manifest: () => this.manifest(o, target) }; return o; } get decorator() { return (input) => { return (ctor) => { this.implement(ctor, input); return ctor; }; }; } } exports.Builder = new BuilderDecorator(); exports.manifest = exports.Builder.decorator; // writing the decorator itself //# sourceMappingURL=manifest-builder.js.map