UNPKG

8.65 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var MetadataUtils_1 = require("../metadata-builder/MetadataUtils");
4/**
5 * Storage all metadatas args of all available types: tables, columns, subscribers, relations, etc.
6 * Each metadata args represents some specifications of what it represents.
7 * MetadataArgs used to create a real Metadata objects.
8 */
9var MetadataArgsStorage = /** @class */ (function () {
10 function MetadataArgsStorage() {
11 // -------------------------------------------------------------------------
12 // Properties
13 // -------------------------------------------------------------------------
14 this.tables = [];
15 this.trees = [];
16 this.entityRepositories = [];
17 this.transactionEntityManagers = [];
18 this.transactionRepositories = [];
19 this.namingStrategies = [];
20 this.entitySubscribers = [];
21 this.indices = [];
22 this.uniques = [];
23 this.checks = [];
24 this.exclusions = [];
25 this.columns = [];
26 this.generations = [];
27 this.relations = [];
28 this.joinColumns = [];
29 this.joinTables = [];
30 this.entityListeners = [];
31 this.relationCounts = [];
32 this.relationIds = [];
33 this.embeddeds = [];
34 this.inheritances = [];
35 this.discriminatorValues = [];
36 }
37 MetadataArgsStorage.prototype.filterTables = function (target) {
38 return this.filterByTarget(this.tables, target);
39 };
40 MetadataArgsStorage.prototype.filterColumns = function (target) {
41 return this.filterByTargetAndWithoutDuplicateProperties(this.columns, target);
42 };
43 MetadataArgsStorage.prototype.findGenerated = function (target, propertyName) {
44 return this.generations.find(function (generated) {
45 return (target instanceof Array ? target.indexOf(generated.target) !== -1 : generated.target === target) && generated.propertyName === propertyName;
46 });
47 };
48 MetadataArgsStorage.prototype.findTree = function (target) {
49 return this.trees.find(function (tree) {
50 return (target instanceof Array ? target.indexOf(tree.target) !== -1 : tree.target === target);
51 });
52 };
53 MetadataArgsStorage.prototype.filterRelations = function (target) {
54 return this.filterByTargetAndWithoutDuplicateProperties(this.relations, target);
55 };
56 MetadataArgsStorage.prototype.filterRelationIds = function (target) {
57 return this.filterByTargetAndWithoutDuplicateProperties(this.relationIds, target);
58 };
59 MetadataArgsStorage.prototype.filterRelationCounts = function (target) {
60 return this.filterByTargetAndWithoutDuplicateProperties(this.relationCounts, target);
61 };
62 MetadataArgsStorage.prototype.filterIndices = function (target) {
63 // todo: implement parent-entity overrides?
64 return this.indices.filter(function (index) {
65 return target instanceof Array ? target.indexOf(index.target) !== -1 : index.target === target;
66 });
67 };
68 MetadataArgsStorage.prototype.filterUniques = function (target) {
69 return this.uniques.filter(function (unique) {
70 return target instanceof Array ? target.indexOf(unique.target) !== -1 : unique.target === target;
71 });
72 };
73 MetadataArgsStorage.prototype.filterChecks = function (target) {
74 return this.checks.filter(function (check) {
75 return target instanceof Array ? target.indexOf(check.target) !== -1 : check.target === target;
76 });
77 };
78 MetadataArgsStorage.prototype.filterExclusions = function (target) {
79 return this.exclusions.filter(function (exclusion) {
80 return target instanceof Array ? target.indexOf(exclusion.target) !== -1 : exclusion.target === target;
81 });
82 };
83 MetadataArgsStorage.prototype.filterListeners = function (target) {
84 return this.filterByTarget(this.entityListeners, target);
85 };
86 MetadataArgsStorage.prototype.filterEmbeddeds = function (target) {
87 return this.filterByTargetAndWithoutDuplicateEmbeddedProperties(this.embeddeds, target);
88 };
89 MetadataArgsStorage.prototype.findJoinTable = function (target, propertyName) {
90 return this.joinTables.find(function (joinTable) {
91 return joinTable.target === target && joinTable.propertyName === propertyName;
92 });
93 };
94 MetadataArgsStorage.prototype.filterJoinColumns = function (target, propertyName) {
95 // todo: implement parent-entity overrides?
96 return this.joinColumns.filter(function (joinColumn) {
97 return joinColumn.target === target && joinColumn.propertyName === propertyName;
98 });
99 };
100 MetadataArgsStorage.prototype.filterSubscribers = function (target) {
101 return this.filterByTarget(this.entitySubscribers, target);
102 };
103 MetadataArgsStorage.prototype.filterNamingStrategies = function (target) {
104 return this.filterByTarget(this.namingStrategies, target);
105 };
106 MetadataArgsStorage.prototype.filterTransactionEntityManagers = function (target, propertyName) {
107 return this.transactionEntityManagers.filter(function (transactionEm) {
108 return (target instanceof Array ? target.indexOf(transactionEm.target) !== -1 : transactionEm.target === target) && transactionEm.methodName === propertyName;
109 });
110 };
111 MetadataArgsStorage.prototype.filterTransactionRepository = function (target, propertyName) {
112 return this.transactionRepositories.filter(function (transactionEm) {
113 return (target instanceof Array ? target.indexOf(transactionEm.target) !== -1 : transactionEm.target === target) && transactionEm.methodName === propertyName;
114 });
115 };
116 MetadataArgsStorage.prototype.filterSingleTableChildren = function (target) {
117 return this.tables.filter(function (table) {
118 return table.target instanceof Function
119 && target instanceof Function
120 && MetadataUtils_1.MetadataUtils.isInherited(table.target, target)
121 && table.type === "entity-child";
122 });
123 };
124 MetadataArgsStorage.prototype.findInheritanceType = function (target) {
125 return this.inheritances.find(function (inheritance) { return inheritance.target === target; });
126 };
127 MetadataArgsStorage.prototype.findDiscriminatorValue = function (target) {
128 return this.discriminatorValues.find(function (discriminatorValue) { return discriminatorValue.target === target; });
129 };
130 // -------------------------------------------------------------------------
131 // Protected Methods
132 // -------------------------------------------------------------------------
133 /**
134 * Filters given array by a given target or targets.
135 */
136 MetadataArgsStorage.prototype.filterByTarget = function (array, target) {
137 return array.filter(function (table) {
138 return target instanceof Array ? target.indexOf(table.target) !== -1 : table.target === target;
139 });
140 };
141 /**
142 * Filters given array by a given target or targets and prevents duplicate property names.
143 */
144 MetadataArgsStorage.prototype.filterByTargetAndWithoutDuplicateProperties = function (array, target) {
145 var newArray = [];
146 array.forEach(function (item) {
147 var sameTarget = target instanceof Array ? target.indexOf(item.target) !== -1 : item.target === target;
148 if (sameTarget) {
149 if (!newArray.find(function (newItem) { return newItem.propertyName === item.propertyName; }))
150 newArray.push(item);
151 }
152 });
153 return newArray;
154 };
155 /**
156 * Filters given array by a given target or targets and prevents duplicate embedded property names.
157 */
158 MetadataArgsStorage.prototype.filterByTargetAndWithoutDuplicateEmbeddedProperties = function (array, target) {
159 var newArray = [];
160 array.forEach(function (item) {
161 var sameTarget = target instanceof Array ? target.indexOf(item.target) !== -1 : item.target === target;
162 if (sameTarget) {
163 var isDuplicateEmbeddedProperty = newArray.find(function (newItem) {
164 return newItem.prefix === item.prefix && newItem.propertyName === item.propertyName;
165 });
166 if (!isDuplicateEmbeddedProperty)
167 newArray.push(item);
168 }
169 });
170 return newArray;
171 };
172 return MetadataArgsStorage;
173}());
174exports.MetadataArgsStorage = MetadataArgsStorage;
175
176//# sourceMappingURL=MetadataArgsStorage.js.map