import { IBonbonsContext, IPipeBundle, IPipe } from "@bonbons/contracts/dist/src/private-api"; import { Reflection } from "../di"; import { clone } from "../utils"; export function createPipeInstance(type: IPipeBundle, depts: any[], $$ctx?: IBonbonsContext) { const { target, params } = type; const { keyMatch } = Reflection.GetPipeMetadata(target.prototype); const initFn = (target.prototype).pipeOnInit; const instance = new target(...depts); instance.context = $$ctx; const paramsCopy = clone(params); Object.defineProperty(instance, "params", { enumerable: true, configurable: false, get: () => paramsCopy }); (<[(string | number), string][]>keyMatch).forEach(([old, newKey]) => instance[newKey] = (params)[old]); initFn && (initFn.bind(instance))(); return instance; }