@k8ts/instruments
Version:
A collection of utilities and core components for k8ts.
36 lines • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.relations = exports.Relations = void 0;
const base_1 = require("../_embedder/base");
const dependencies_1 = require("./dependencies");
class RelationsService {
_system = new base_1.Embedder("relations");
implement(ctor, input) {
const existing = this._system.tryGet(ctor.prototype);
if (existing) {
input = Object.assign({}, existing, input);
}
this._system.set(ctor.prototype, input);
}
get(target) {
const input = this._system.get(target);
const o = {
kids: () => input.kids?.call(o, target).map(x => x.node) ?? [],
parent: () => input.parent?.call(o, target)?.node ?? null,
needs: () => (0, dependencies_1.dependencies)(input.needs?.call(o, target) ?? {})
};
return o;
}
get decorator() {
return (input) => {
return (ctor) => {
this.implement(ctor, input === "none" ? {} : input);
return ctor;
};
};
}
}
exports.Relations = new RelationsService();
exports.relations = exports.Relations.decorator;
// writing the decorator itself
//# sourceMappingURL=relations.js.map