1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import { ɵstringify as stringify } from '@angular/core';
|
---|
9 | let _nextReferenceId = 0;
|
---|
10 | export class MetadataOverrider {
|
---|
11 | constructor() {
|
---|
12 | this._references = new Map();
|
---|
13 | }
|
---|
14 | /**
|
---|
15 | * Creates a new instance for the given metadata class
|
---|
16 | * based on an old instance and overrides.
|
---|
17 | */
|
---|
18 | overrideMetadata(metadataClass, oldMetadata, override) {
|
---|
19 | const props = {};
|
---|
20 | if (oldMetadata) {
|
---|
21 | _valueProps(oldMetadata).forEach((prop) => props[prop] = oldMetadata[prop]);
|
---|
22 | }
|
---|
23 | if (override.set) {
|
---|
24 | if (override.remove || override.add) {
|
---|
25 | throw new Error(`Cannot set and add/remove ${stringify(metadataClass)} at the same time!`);
|
---|
26 | }
|
---|
27 | setMetadata(props, override.set);
|
---|
28 | }
|
---|
29 | if (override.remove) {
|
---|
30 | removeMetadata(props, override.remove, this._references);
|
---|
31 | }
|
---|
32 | if (override.add) {
|
---|
33 | addMetadata(props, override.add);
|
---|
34 | }
|
---|
35 | return new metadataClass(props);
|
---|
36 | }
|
---|
37 | }
|
---|
38 | function removeMetadata(metadata, remove, references) {
|
---|
39 | const removeObjects = new Set();
|
---|
40 | for (const prop in remove) {
|
---|
41 | const removeValue = remove[prop];
|
---|
42 | if (Array.isArray(removeValue)) {
|
---|
43 | removeValue.forEach((value) => {
|
---|
44 | removeObjects.add(_propHashKey(prop, value, references));
|
---|
45 | });
|
---|
46 | }
|
---|
47 | else {
|
---|
48 | removeObjects.add(_propHashKey(prop, removeValue, references));
|
---|
49 | }
|
---|
50 | }
|
---|
51 | for (const prop in metadata) {
|
---|
52 | const propValue = metadata[prop];
|
---|
53 | if (Array.isArray(propValue)) {
|
---|
54 | metadata[prop] = propValue.filter((value) => !removeObjects.has(_propHashKey(prop, value, references)));
|
---|
55 | }
|
---|
56 | else {
|
---|
57 | if (removeObjects.has(_propHashKey(prop, propValue, references))) {
|
---|
58 | metadata[prop] = undefined;
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 | function addMetadata(metadata, add) {
|
---|
64 | for (const prop in add) {
|
---|
65 | const addValue = add[prop];
|
---|
66 | const propValue = metadata[prop];
|
---|
67 | if (propValue != null && Array.isArray(propValue)) {
|
---|
68 | metadata[prop] = propValue.concat(addValue);
|
---|
69 | }
|
---|
70 | else {
|
---|
71 | metadata[prop] = addValue;
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|
75 | function setMetadata(metadata, set) {
|
---|
76 | for (const prop in set) {
|
---|
77 | metadata[prop] = set[prop];
|
---|
78 | }
|
---|
79 | }
|
---|
80 | function _propHashKey(propName, propValue, references) {
|
---|
81 | const replacer = (key, value) => {
|
---|
82 | if (typeof value === 'function') {
|
---|
83 | value = _serializeReference(value, references);
|
---|
84 | }
|
---|
85 | return value;
|
---|
86 | };
|
---|
87 | return `${propName}:${JSON.stringify(propValue, replacer)}`;
|
---|
88 | }
|
---|
89 | function _serializeReference(ref, references) {
|
---|
90 | let id = references.get(ref);
|
---|
91 | if (!id) {
|
---|
92 | id = `${stringify(ref)}${_nextReferenceId++}`;
|
---|
93 | references.set(ref, id);
|
---|
94 | }
|
---|
95 | return id;
|
---|
96 | }
|
---|
97 | function _valueProps(obj) {
|
---|
98 | const props = [];
|
---|
99 | // regular public props
|
---|
100 | Object.keys(obj).forEach((prop) => {
|
---|
101 | if (!prop.startsWith('_')) {
|
---|
102 | props.push(prop);
|
---|
103 | }
|
---|
104 | });
|
---|
105 | // getters
|
---|
106 | let proto = obj;
|
---|
107 | while (proto = Object.getPrototypeOf(proto)) {
|
---|
108 | Object.keys(proto).forEach((protoProp) => {
|
---|
109 | const desc = Object.getOwnPropertyDescriptor(proto, protoProp);
|
---|
110 | if (!protoProp.startsWith('_') && desc && 'get' in desc) {
|
---|
111 | props.push(protoProp);
|
---|
112 | }
|
---|
113 | });
|
---|
114 | }
|
---|
115 | return props;
|
---|
116 | }
|
---|
117 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWV0YWRhdGFfb3ZlcnJpZGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvY29yZS90ZXN0aW5nL3NyYy9tZXRhZGF0YV9vdmVycmlkZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUFDLFVBQVUsSUFBSSxTQUFTLEVBQUMsTUFBTSxlQUFlLENBQUM7QUFPdEQsSUFBSSxnQkFBZ0IsR0FBRyxDQUFDLENBQUM7QUFFekIsTUFBTSxPQUFPLGlCQUFpQjtJQUE5QjtRQUNVLGdCQUFXLEdBQUcsSUFBSSxHQUFHLEVBQWUsQ0FBQztJQTBCL0MsQ0FBQztJQXpCQzs7O09BR0c7SUFDSCxnQkFBZ0IsQ0FDWixhQUFvQyxFQUFFLFdBQWMsRUFBRSxRQUE2QjtRQUNyRixNQUFNLEtBQUssR0FBYyxFQUFFLENBQUM7UUFDNUIsSUFBSSxXQUFXLEVBQUU7WUFDZixXQUFXLENBQUMsV0FBVyxDQUFDLENBQUMsT0FBTyxDQUFDLENBQUMsSUFBSSxFQUFFLEVBQUUsQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLEdBQVMsV0FBWSxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUM7U0FDcEY7UUFFRCxJQUFJLFFBQVEsQ0FBQyxHQUFHLEVBQUU7WUFDaEIsSUFBSSxRQUFRLENBQUMsTUFBTSxJQUFJLFFBQVEsQ0FBQyxHQUFHLEVBQUU7Z0JBQ25DLE1BQU0sSUFBSSxLQUFLLENBQUMsNkJB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