1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.clonePluginMetadataFactory = void 0;
|
4 | const lodash_1 = require("lodash");
|
5 | const plugin_constants_1 = require("../plugin/plugin-constants");
|
6 | function clonePluginMetadataFactory(target, parent, transformFn = lodash_1.identity) {
|
7 | let targetMetadata = {};
|
8 | do {
|
9 | if (!parent.constructor) {
|
10 | return;
|
11 | }
|
12 | if (!parent.constructor[plugin_constants_1.METADATA_FACTORY_NAME]) {
|
13 | continue;
|
14 | }
|
15 | const parentMetadata = parent.constructor[plugin_constants_1.METADATA_FACTORY_NAME]();
|
16 | targetMetadata = Object.assign(Object.assign({}, parentMetadata), targetMetadata);
|
17 | } while ((parent = Reflect.getPrototypeOf(parent)) &&
|
18 | parent !== Object.prototype &&
|
19 | parent);
|
20 | targetMetadata = transformFn(targetMetadata);
|
21 | if (target[plugin_constants_1.METADATA_FACTORY_NAME]) {
|
22 | const originalFactory = target[plugin_constants_1.METADATA_FACTORY_NAME];
|
23 | target[plugin_constants_1.METADATA_FACTORY_NAME] = () => {
|
24 | const originalMetadata = originalFactory();
|
25 | return Object.assign(Object.assign({}, originalMetadata), targetMetadata);
|
26 | };
|
27 | }
|
28 | else {
|
29 | target[plugin_constants_1.METADATA_FACTORY_NAME] = () => targetMetadata;
|
30 | }
|
31 | }
|
32 | exports.clonePluginMetadataFactory = clonePluginMetadataFactory;
|