| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149 |
1×
9×
9×
9×
9×
1×
1×
1×
10×
10×
10×
1×
120×
1×
1×
10×
1×
30×
1×
23×
1×
8×
1×
10×
10×
1×
10×
10×
1×
10×
10×
3×
10×
1×
10×
1×
10×
1×
10×
10×
10×
10×
10×
1×
7×
1×
6×
10×
3×
10×
3×
10×
1×
10×
1×
10×
10×
1×
10×
10×
1×
10×
10×
10×
10×
10×
10×
1×
40×
40×
60×
60×
1×
20×
20×
16×
4×
4×
6×
2×
6×
4×
4×
1×
20×
20×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
| "use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
Iif (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) Eif (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var utils_1 = require("./../utils");
var StructureWrapper = (function () {
function StructureWrapper(wrapperFactory, transformOptions, structure) {
this.wrapperFactory = wrapperFactory;
this.transformOptions = transformOptions;
this.structure = structure;
}
StructureWrapper.prototype.getName = function () {
return this.structure.name;
};
StructureWrapper.prototype.getDefinition = function () {
return this.structure;
};
StructureWrapper.prototype.getTestStructureName = function () {
return this.transformOptions.getNameToTestStructureName(this.structure.name);
};
StructureWrapper.prototype.getProperties = function () {
return this.getValidProperties();
};
StructureWrapper.prototype.hasTypeParameters = function () {
return this.structure.typeParameters.length > 0;
};
StructureWrapper.prototype.getTypeParametersCount = function () {
return this.structure.typeParameters.length;
};
StructureWrapper.prototype.getTypeParameters = function () {
var _this = this;
return this.structure.typeParameters.map(function (t) { return _this.wrapperFactory.getStructureTypeParameter(_this, t); });
};
StructureWrapper.prototype.getValidExtendsTypes = function () {
var extendsTypes = this.getExtendsTypes();
return extendsTypes.filter(function (t) { return !t.shouldIgnoreType() && t.getImmediateValidDefinitions().length > 0; });
};
StructureWrapper.prototype.getValidExtendsStructures = function () {
var validExtendsDefinitions = [];
this.getExtendsTypes().forEach(function (extendsType) {
validExtendsDefinitions.push.apply(validExtendsDefinitions, extendsType.getImmediateValidDefinitions());
});
return validExtendsDefinitions;
};
StructureWrapper.prototype.getNameWithTypeParameters = function () {
return this.getNameWithTypeParametersInternal(this.getName(), function (t) { return t.getName(); });
};
StructureWrapper.prototype.getTestStructureNameWithTypeParameters = function () {
return this.getNameWithTypeParametersInternal(this.getTestStructureName(), function (t) { return t.getTestStructureName(); });
};
StructureWrapper.prototype.getInitializeDependencies = function () {
var typeParams = this.getTypeParameters();
var extendsTypes = this.getValidExtendsTypes();
var propDependencies = this.getPropertyDependencies();
var dependencies = [];
var structureName = this.getName();
function addToDependency(name, dep) {
if (name === structureName || dependencies.some(function (d) { return d.name === name; }))
return;
dependencies.push({ name: name, dep: dep });
}
typeParams.forEach(function (typeParam) {
addToDependency(typeParam.getName(), typeParam);
});
extendsTypes.forEach(function (extendsType) {
addToDependency(extendsType.getImmediateValidDefinitions()[0].getName(), extendsType);
});
propDependencies.forEach(function (dep) {
addToDependency(dep.getName(), dep);
});
return dependencies.map(function (d) { return d.dep; });
};
StructureWrapper.prototype.getCustomTestTransforms = function () {
var _this = this;
return this.transformOptions.getCustomTestTransforms().filter(function (t) { return t.condition(_this.structure); });
};
StructureWrapper.prototype.getTestStructureTransforms = function () {
var _this = this;
return this.transformOptions.getTestStructureTransforms().filter(function (t) { return t.condition(_this.structure); });
};
StructureWrapper.prototype.getPropertyDependencies = function () {
var props = this.getValidProperties();
var dependencies = [];
props.forEach(function (prop) {
var definitions = prop.getType().getAllValidDefinitions();
dependencies.push.apply(dependencies, definitions);
});
return dependencies;
};
StructureWrapper.prototype.getValidProperties = function () {
var _this = this;
// todo: memoize
var tsProps = this.structure.properties;
var props = tsProps.map(function (p) { return _this.wrapperFactory.getStructureProperty(_this.structure, p); });
return props.filter(function (p) { return !p.shouldIgnoreProperty(); });
};
StructureWrapper.prototype.getNameWithTypeParametersInternal = function (name, getTypeParamName) {
var typeParams = this.getTypeParameters();
if (typeParams.length === 0)
return name;
name += "<";
typeParams.forEach(function (typeParam, i) {
if (i > 0)
name += ", ";
name += getTypeParamName(typeParam);
});
name += ">";
return name;
};
StructureWrapper.prototype.getExtendsTypes = function () {
var _this = this;
return this.structure.extendsTypes.map(function (t) { return _this.wrapperFactory.getStructureType(_this, t); });
};
return StructureWrapper;
}());
__decorate([
utils_1.Memoize
], StructureWrapper.prototype, "getTestStructureName", null);
__decorate([
utils_1.Memoize
], StructureWrapper.prototype, "getTypeParameters", null);
__decorate([
utils_1.Memoize
], StructureWrapper.prototype, "getValidExtendsTypes", null);
__decorate([
utils_1.Memoize
], StructureWrapper.prototype, "getValidExtendsStructures", null);
__decorate([
utils_1.Memoize
], StructureWrapper.prototype, "getNameWithTypeParameters", null);
__decorate([
utils_1.Memoize
], StructureWrapper.prototype, "getTestStructureNameWithTypeParameters", null);
__decorate([
utils_1.Memoize
], StructureWrapper.prototype, "getInitializeDependencies", null);
__decorate([
utils_1.Memoize
], StructureWrapper.prototype, "getCustomTestTransforms", null);
__decorate([
utils_1.Memoize
], StructureWrapper.prototype, "getTestStructureTransforms", null);
exports.StructureWrapper = StructureWrapper;
//# sourceMappingURL=StructureWrapper.js.map
|