@trapi/metadata 0.1.2 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/cache/driver.js +1 -2
  2. package/dist/cache/driver.js.map +1 -1
  3. package/dist/cache/utils.d.ts.map +1 -1
  4. package/dist/cache/utils.js +12 -12
  5. package/dist/cache/utils.js.map +1 -1
  6. package/dist/decorator/index.d.ts +1 -1
  7. package/dist/decorator/index.d.ts.map +1 -1
  8. package/dist/decorator/index.js +1 -3
  9. package/dist/decorator/index.js.map +1 -1
  10. package/dist/decorator/mapper/index.js +1 -2
  11. package/dist/decorator/mapper/index.js.map +1 -1
  12. package/dist/decorator/representation/index.js +2 -4
  13. package/dist/decorator/representation/index.js.map +1 -1
  14. package/dist/decorator/representation/property/utils.js +4 -3
  15. package/dist/decorator/representation/property/utils.js.map +1 -1
  16. package/dist/generator/controller.js +1 -1
  17. package/dist/generator/controller.js.map +1 -1
  18. package/dist/generator/endpoint.js +0 -3
  19. package/dist/generator/endpoint.js.map +1 -1
  20. package/dist/generator/index.d.ts +5 -33
  21. package/dist/generator/index.d.ts.map +1 -1
  22. package/dist/generator/index.js +15 -151
  23. package/dist/generator/index.js.map +1 -1
  24. package/dist/generator/method.js +0 -2
  25. package/dist/generator/method.js.map +1 -1
  26. package/dist/generator/module.d.ts +41 -0
  27. package/dist/generator/module.d.ts.map +1 -0
  28. package/dist/generator/module.js +166 -0
  29. package/dist/generator/module.js.map +1 -0
  30. package/dist/generator/parameter.js +1 -9
  31. package/dist/generator/parameter.js.map +1 -1
  32. package/dist/resolver/type-node.js +28 -61
  33. package/dist/resolver/type-node.js.map +1 -1
  34. package/dist/resolver/utils/initializer.d.ts.map +1 -1
  35. package/dist/resolver/utils/initializer.js +2 -1
  36. package/dist/resolver/utils/initializer.js.map +1 -1
  37. package/dist/resolver/utils/validator.js +2 -1
  38. package/dist/resolver/utils/validator.js.map +1 -1
  39. package/dist/type.d.ts +5 -0
  40. package/dist/type.d.ts.map +1 -1
  41. package/dist/utils/generator.js +1 -1
  42. package/dist/utils/generator.js.map +1 -1
  43. package/dist/utils/js-doc.js +1 -1
  44. package/dist/utils/js-doc.js.map +1 -1
  45. package/package.json +18 -12
  46. package/src/cache/driver.ts +0 -97
  47. package/src/cache/index.ts +0 -10
  48. package/src/cache/type.ts +0 -43
  49. package/src/cache/utils.ts +0 -49
  50. package/src/config/index.ts +0 -8
  51. package/src/config/path.ts +0 -29
  52. package/src/decorator/functions.ts +0 -142
  53. package/src/decorator/index.ts +0 -13
  54. package/src/decorator/mapper/index.ts +0 -153
  55. package/src/decorator/mapper/maps/decorators-express.ts +0 -117
  56. package/src/decorator/mapper/maps/internal.ts +0 -95
  57. package/src/decorator/mapper/maps/typescript-rest.ts +0 -150
  58. package/src/decorator/mapper/utils.ts +0 -88
  59. package/src/decorator/representation/index.ts +0 -82
  60. package/src/decorator/representation/property/utils.ts +0 -146
  61. package/src/decorator/type.ts +0 -235
  62. package/src/decorator/utils/index.ts +0 -9
  63. package/src/decorator/utils/node.ts +0 -59
  64. package/src/decorator/utils/validator.ts +0 -104
  65. package/src/generator/controller.ts +0 -65
  66. package/src/generator/endpoint.ts +0 -212
  67. package/src/generator/index.ts +0 -219
  68. package/src/generator/method.ts +0 -198
  69. package/src/generator/parameter.ts +0 -392
  70. package/src/index.ts +0 -13
  71. package/src/resolver/error.ts +0 -38
  72. package/src/resolver/index.ts +0 -11
  73. package/src/resolver/type-node.ts +0 -1287
  74. package/src/resolver/type.ts +0 -257
  75. package/src/resolver/utils/index.ts +0 -9
  76. package/src/resolver/utils/initializer.ts +0 -81
  77. package/src/resolver/utils/validator.ts +0 -144
  78. package/src/type.ts +0 -185
  79. package/src/utils/generator.ts +0 -42
  80. package/src/utils/index.ts +0 -10
  81. package/src/utils/js-doc.ts +0 -125
  82. package/src/utils/validator.ts +0 -43
  83. package/test/data/library/@decorators-express/decorators.ts +0 -7
  84. package/test/data/library/self/api.ts +0 -37
  85. package/test/data/library/type.ts +0 -138
  86. package/test/data/library/typescript-rest/api.ts +0 -366
  87. package/test/data/library/typescript-rest/decorators/index.ts +0 -10
  88. package/test/data/library/typescript-rest/decorators/methods.ts +0 -34
  89. package/test/data/library/typescript-rest/decorators/parameters.ts +0 -62
  90. package/test/data/library/typescript-rest/decorators/services.ts +0 -47
  91. package/test/data/library/typescript-rest/return-types.ts +0 -94
  92. package/test/data/library/utils.ts +0 -7
  93. package/test/jest.config.js +0 -49
  94. package/test/unit/cache.spec.ts +0 -48
  95. package/test/unit/decorator/mapper/index.spec.ts +0 -83
  96. package/test/unit/decorator/representation/index.spec.ts +0 -102
  97. package/test/unit/decorator/utils/node.spec.ts +0 -47
  98. package/test/unit/library/typescript-rest.spec.ts +0 -342
  99. package/test/unit/resolver/type.spec.ts +0 -134
  100. package/test/unit/utils/generator.spec.ts +0 -41
  101. package/test/unit/utils/js-doc.spec.ts +0 -95
  102. package/tsconfig.build.json +0 -11
  103. package/tsconfig.json +0 -9
  104. package/writable/.gitignore +0 -3
@@ -1,153 +0,0 @@
1
- /*
2
- * Copyright (c) 2021.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import {Node} from "typescript";
9
- import {hasOwnProperty} from "@trapi/metadata-utils";
10
- import {RepresentationManager} from "../representation";
11
- import {Decorator} from "../type";
12
- import {getDecoratorMap, isMappingTypeIncluded, reduceTypeRepresentationMapping} from "./utils";
13
- import {getNodeDecorators} from "../utils";
14
-
15
- export class DecoratorMapper {
16
- protected mapping : Partial<Decorator.TypeRepresentationMap> = {};
17
-
18
- constructor(
19
- protected config?: Decorator.Config
20
- ) {
21
- this.aggregate();
22
- }
23
-
24
- public setConfig(config?: Decorator.Config) {
25
- this.config = config;
26
- this.aggregate();
27
- }
28
-
29
- /**
30
- * Try to find a matching representation for a given decorator type and decorators or node.
31
- *
32
- * @param type
33
- * @param data
34
- */
35
- public match<T extends Decorator.Type>(
36
- type: T,
37
- data: Decorator.Data[] | Node
38
- ) {
39
- if(!hasOwnProperty(this.mapping, type)) {
40
- return undefined;
41
- }
42
-
43
- const decorators : Decorator.Data[] = Array.isArray(data) ? data : getNodeDecorators(data);
44
-
45
- const representations : Array<Decorator.Representation<T>> = (Array.isArray(this.mapping[type]) ? this.mapping[type] : [this.mapping[type]]) as Array<Decorator.Representation<T>>;
46
- for(let i=0; i<representations.length; i++) {
47
- const items = decorators.filter(decorator => decorator.text === representations[i].id);
48
- if(items.length > 0) {
49
- return new RepresentationManager<T>(
50
- representations[i],
51
- items
52
- );
53
- }
54
- }
55
-
56
- return undefined;
57
- }
58
-
59
- // -------------------------------------------
60
-
61
- private aggregate() : void {
62
- if(typeof this.config === 'undefined') {
63
- this.mapping = {};
64
- return;
65
- }
66
-
67
- const items : Array<Partial<Decorator.TypeRepresentationMap>> = [];
68
-
69
- // mapping - internal
70
- const internalMap = getDecoratorMap('internal');
71
- items.push(
72
- typeof this.config.internal === 'undefined' ?
73
- internalMap :
74
- reduceTypeRepresentationMapping(internalMap, (type) => {
75
- return isMappingTypeIncluded(type, this.config.internal);
76
- })
77
- );
78
-
79
- // mapping - extension
80
- if(typeof this.config.map !== 'undefined') {
81
- items.push(this.config.map);
82
- }
83
-
84
- // mapping - library
85
- if(typeof this.config.library !== 'undefined') {
86
- // check if string or string[]
87
-
88
- if(
89
- typeof this.config.library === 'string' ||
90
- Array.isArray(this.config.library)
91
- ) {
92
- const libraries : string[] = Array.isArray(this.config.library) ?
93
- this.config.library :
94
- [this.config.library];
95
-
96
- items.push(...libraries.map(library => getDecoratorMap(library)));
97
- } else {
98
- // tslint:disable-next-line:forin
99
- for(const key in this.config.library) {
100
- items.push(
101
- reduceTypeRepresentationMapping(getDecoratorMap(key), (type) => {
102
- return isMappingTypeIncluded(type, this.config.library[key]);
103
- })
104
- );
105
- }
106
- }
107
- }
108
-
109
- this.mapping = this.merge(...items);
110
- }
111
-
112
- /**
113
- * Merge decorator type-representation mappings of different libraries together.
114
- *
115
- * @param mappings
116
- * @private
117
- */
118
- private merge(...mappings: Array<Partial<Decorator.TypeRepresentationMap>>) : Partial<Decorator.TypeRepresentationMap> {
119
- const result : Partial<Decorator.TypeRepresentationMap> = {};
120
-
121
- // we need all available mapping keys :)
122
- let keys : Decorator.Type[] = mappings
123
- .map(mapping => Object.keys(mapping))
124
- .reduce(((previousValue, currentValue) => [...previousValue, ...currentValue])) as Decorator.Type[];
125
-
126
- keys = Array.from(new Set(keys));
127
-
128
- for(let i=0; i<keys.length; i++) {
129
- const representations : Array<Decorator.Representation<any>> = [];
130
-
131
- for(let j=0; j<mappings.length; j++) {
132
- if(hasOwnProperty(mappings[j], keys[i])) {
133
- const value : Decorator.Representation<any> | Array<Decorator.Representation<any>> = mappings[j][keys[i]];
134
-
135
- if(typeof value === 'undefined') {
136
- continue;
137
- }
138
-
139
- if(Array.isArray(value)) {
140
- representations.push(...value);
141
- } else {
142
- representations.push(value);
143
- }
144
- }
145
- }
146
-
147
- // @ts-ignore
148
- result[keys[i]] = representations;
149
- }
150
-
151
- return result;
152
- }
153
- }
@@ -1,117 +0,0 @@
1
- /*
2
- * Copyright (c) 2021.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import {Decorator} from "../../type";
9
-
10
- export default {
11
- // Class
12
- CLASS_PATH: {
13
- id: 'Controller',
14
- properties: {
15
- DEFAULT: {}
16
- }
17
- },
18
-
19
- // Method
20
- METHOD_PATH: [
21
- {
22
- id: 'All',
23
- properties: {
24
- DEFAULT: {}
25
- }
26
- },
27
- {
28
- id: 'Get',
29
- properties: {
30
- DEFAULT: {}
31
- }
32
- },
33
- {
34
- id: 'Post',
35
- properties: {
36
- DEFAULT: {}
37
- }
38
- },
39
- {
40
- id: 'Put',
41
- properties: {
42
- DEFAULT: {}
43
- }
44
- },
45
- {
46
- id: 'Delete',
47
- properties: {
48
- DEFAULT: {}
49
- }
50
- },
51
- {
52
- id: 'Patch',
53
- properties: {
54
- DEFAULT: {}
55
- }
56
- },
57
- {
58
- id: 'Options',
59
- properties: {
60
- DEFAULT: {}
61
- }
62
- },
63
- {
64
- id: 'Head',
65
- properties: {
66
- DEFAULT: {}
67
- }
68
- }
69
- ],
70
-
71
- // Parameter
72
- SERVER_CONTEXT: [
73
- {
74
- id: 'Request',
75
- properties: {}
76
- },
77
- {
78
- id: 'Response',
79
- properties: {}
80
- },
81
- {
82
- id: 'Next',
83
- properties: {}
84
- },
85
- ],
86
- SERVER_QUERY: {
87
- id: 'Query',
88
- properties: {
89
- DEFAULT: {}
90
- }
91
- },
92
- SERVER_FORM: undefined,
93
- SERVER_BODY: {
94
- id: 'Body',
95
- properties: {
96
- DEFAULT: {}
97
- }
98
- },
99
- SERVER_HEADERS: {
100
- id: 'Headers',
101
- properties: {
102
- DEFAULT: {}
103
- }
104
- },
105
- SERVER_COOKIES: {
106
- id: 'Cookies',
107
- properties: {
108
- DEFAULT: {}
109
- }
110
- },
111
- SERVER_PATH_PARAMS: {
112
- id: 'Params',
113
- properties: {
114
- DEFAULT: {}
115
- }
116
- }
117
- } as Partial<Decorator.TypeRepresentationMap>;
@@ -1,95 +0,0 @@
1
- /*
2
- * Copyright (c) 2021.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import {Decorator} from "../../type";
9
-
10
- export default {
11
- EXTENSION: {
12
- id: 'Extension',
13
- properties: {
14
- KEY: {type: "element", srcArgumentType: "argument", srcPosition: 0},
15
- VALUE: {type: "element", srcArgumentType: "argument", srcPosition: 1}
16
- }
17
- },
18
-
19
- // Class
20
- SWAGGER_TAGS: {
21
- id: 'SwaggerTags',
22
- properties: {
23
- DEFAULT: {type: 'array', srcArgumentType: "argument"}
24
- }
25
- },
26
-
27
- // Class + Method
28
- RESPONSE_EXAMPLE: {
29
- id: 'ResponseExample',
30
- properties: {
31
- TYPE: {isType: true, srcArgumentType: "typeArgument"},
32
- PAYLOAD: {type: "element", srcArgumentType: "argument", srcPosition: 0}
33
- }
34
- },
35
- RESPONSE_DESCRIPTION: {
36
- id: 'ResponseDescription',
37
- properties: {
38
- TYPE: {isType: true, srcArgumentType: "typeArgument"},
39
- STATUS_CODE: {type: "element", srcArgumentType: "argument", srcPosition: 0},
40
- DESCRIPTION: {type: "element", srcArgumentType: "argument", srcPosition: 1},
41
- PAYLOAD: {type: "element", srcArgumentType: "argument", srcPosition: 2}
42
- }
43
- },
44
- REQUEST_CONSUMES: {
45
- id: 'RequestConsumes',
46
- properties: {
47
- DEFAULT: {type: 'array', srcArgumentType: "argument", srcAmount: -1, srcStrategy: "merge"}
48
- }
49
- },
50
- RESPONSE_PRODUCES: {
51
- id: 'ResponseProduces',
52
- properties: {
53
- DEFAULT: {type: 'array', srcArgumentType: "argument", srcAmount: -1, srcStrategy: "merge"}
54
- }
55
- },
56
-
57
- HIDDEN: {
58
- id: 'SwaggerHidden',
59
- properties: []
60
- },
61
- DEPRECATED: {
62
- id: 'SwaggerDeprecated',
63
- properties: undefined
64
- },
65
-
66
- IS_INT: {
67
- id: 'IsInt',
68
- properties: undefined
69
- },
70
- IS_LONG: {
71
- id: 'IsLong',
72
- properties: undefined
73
- },
74
- IS_FlOAT: {
75
- id: 'IsFloat',
76
- properties: undefined
77
- },
78
- IS_DOUBLE: {
79
- id: 'IsDouble',
80
- properties: undefined
81
- },
82
-
83
- SERVER_FILES_PARAM: {
84
- id: 'RequestFileParam',
85
- properties: {
86
- DEFAULT: {}
87
- }
88
- },
89
- SERVER_FILE_PARAM: {
90
- id: 'RequestFileParam',
91
- properties: {
92
- DEFAULT: {}
93
- }
94
- },
95
- } as Partial<Decorator.TypeRepresentationMap>;
@@ -1,150 +0,0 @@
1
- /*
2
- * Copyright (c) 2021.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import {Decorator} from "../../type";
9
-
10
- export default {
11
- // Class
12
- CLASS_PATH: {
13
- id: 'Path',
14
- properties: {
15
- DEFAULT: {type: 'element', srcArgumentType: "argument"}
16
- }
17
- },
18
-
19
- // Class + Method
20
- REQUEST_ACCEPT: undefined,
21
- RESPONSE_EXAMPLE: {
22
- id: 'Example',
23
- properties: {
24
- TYPE: {isType: true, srcArgumentType: "typeArgument"},
25
- PAYLOAD: {type: "element", srcArgumentType: "argument"}
26
- }
27
- },
28
- RESPONSE_DESCRIPTION: {
29
- id: 'Response',
30
- properties: {
31
- TYPE: {type: "element", srcArgumentType: "typeArgument"},
32
- STATUS_CODE: {type: "element", srcArgumentType: "argument", srcPosition: 0},
33
- DESCRIPTION: {type: "element", srcArgumentType: "argument", srcPosition: 1},
34
- PAYLOAD: {type: "element", srcArgumentType: "argument", srcPosition: 2}
35
- }
36
- },
37
-
38
- // Method
39
- ALL: {
40
- id: 'ALL',
41
- properties: {}
42
- },
43
- GET: {
44
- id: 'GET',
45
- properties: {}
46
- },
47
- POST: {
48
- id: 'POST',
49
- properties: {}
50
- },
51
- PUT: {
52
- id: 'PUT',
53
- properties: {}
54
- },
55
- DELETE: {
56
- id: 'DELETE',
57
- properties: {}
58
- },
59
- PATCH: {
60
- id: 'PATCH',
61
- properties: {}
62
- },
63
- OPTIONS: {
64
- id: 'OPTIONS',
65
- properties: {}
66
- },
67
- HEAD: {
68
- id: 'HEAD',
69
- properties: {}
70
- },
71
-
72
- METHOD_PATH: {
73
- id: 'Path',
74
- properties: {
75
- DEFAULT: {type: 'element', srcArgumentType: "argument"}
76
- }
77
- },
78
-
79
- // Parameter
80
- SERVER_CONTEXT: [
81
- {
82
- id: 'Context',
83
- },
84
- {
85
- id: 'ContextRequest',
86
- },
87
- {
88
- id: 'ContextResponse',
89
- },
90
- {
91
- id: 'ContextNext',
92
- },
93
- {
94
- id: 'ContextLanguage',
95
- },
96
- {
97
- id: 'ContextAccept',
98
- }
99
- ],
100
- SERVER_PARAMS: {
101
- id: 'Param',
102
- properties: {
103
- DEFAULT: {}
104
- }
105
- },
106
- SERVER_QUERY: {
107
- id: 'QueryParam',
108
- properties: {
109
- DEFAULT: {}
110
- }
111
- },
112
- SERVER_FORM: {
113
- id: 'FormParam',
114
- properties: {
115
- DEFAULT: {}
116
- }
117
- },
118
- SERVER_BODY: undefined,
119
- SERVER_HEADERS: {
120
- id: 'HeaderParam',
121
- properties: {
122
- DEFAULT: {}
123
- }
124
- },
125
- SERVER_COOKIES: {
126
- id: 'CookieParam',
127
- properties: {
128
- DEFAULT: {}
129
- }
130
- },
131
- SERVER_PATH_PARAMS: {
132
- id: 'PathParam',
133
- properties: {
134
- DEFAULT: {}
135
- }
136
- },
137
- SERVER_FILES_PARAM: {
138
- id: 'FilesParam',
139
- properties: {
140
- DEFAULT: {}
141
- }
142
- },
143
- SERVER_FILE_PARAM: {
144
- id: 'FileParam',
145
- properties: {
146
- DEFAULT: {}
147
- }
148
- }
149
- } as Partial<Decorator.TypeRepresentationMap>;
150
-
@@ -1,88 +0,0 @@
1
- /*
2
- * Copyright (c) 2021.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import {hasOwnProperty} from "@trapi/metadata-utils";
9
- import {Decorator} from "../type";
10
-
11
- /**
12
- *
13
- *
14
- * @param mapping
15
- * @param reducer
16
- */
17
- export function reduceTypeRepresentationMapping(
18
- mapping: Partial<Decorator.TypeRepresentationMap>,
19
- reducer: (type: Decorator.Type) => boolean
20
- ): Partial<Decorator.TypeRepresentationMap> {
21
- const mappingKeys: Decorator.Type[] = (Object.keys(mapping) as Decorator.Type[]);
22
- const allowedTypes: Decorator.Type[] = mappingKeys
23
- .filter(reducer);
24
-
25
- if (mappingKeys.length === allowedTypes.length) {
26
- return mapping;
27
- }
28
-
29
- const result: Partial<Decorator.TypeRepresentationMap> = {};
30
- for (let i = 0; i < allowedTypes.length; i++) {
31
- // @ts-ignore
32
- result[allowedTypes[i]] = mapping[allowedTypes[i]];
33
- }
34
-
35
- return result;
36
- }
37
-
38
- /**
39
- *
40
- *
41
- * @param type
42
- * @param config
43
- */
44
- export function isMappingTypeIncluded(
45
- type: Decorator.Type,
46
- config: Decorator.TypeRepresentationConfig
47
- ): boolean {
48
- const allowedType = Object.prototype.toString.call(config);
49
- switch (allowedType) {
50
- case '[object Boolean]':
51
- return !!config;
52
- case '[object String]':
53
- return (config as string) === type;
54
- case '[object Array]':
55
- return (config as unknown as Decorator.Type[]).indexOf(type) !== -1;
56
- case '[object Object]':
57
- return hasOwnProperty((config as Record<Decorator.Type, boolean>), type) && (config as Record<Decorator.Type, boolean>)[type];
58
- }
59
-
60
- /* istanbul ignore next */
61
- return false;
62
- }
63
-
64
- let decoratorMap : Record<string, Partial<Decorator.TypeRepresentationMap>> = {};
65
-
66
- export function getDecoratorMap(name: string) : Partial<Decorator.TypeRepresentationMap> {
67
- if(hasOwnProperty(decoratorMap, name)) {
68
- return decoratorMap[name];
69
- }
70
-
71
- const content = loadDecoratorMap(name);
72
-
73
- (decoratorMap as Record<string, Partial<Decorator.TypeRepresentationMap>>)[name] = content;
74
-
75
- return content;
76
- }
77
-
78
- /* istanbul ignore next */
79
- function loadDecoratorMap(library: string) : Partial<Decorator.TypeRepresentationMap> {
80
- const exp = require(`./maps/${library}`);
81
-
82
- if(hasOwnProperty(exp, 'default')) {
83
- return exp.default;
84
- }
85
-
86
- /* istanbul ignore next */
87
- return exp;
88
- }
@@ -1,82 +0,0 @@
1
- /*
2
- * Copyright (c) 2021.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import {hasOwnProperty} from "@trapi/metadata-utils";
9
- import {Decorator} from "../type";
10
- import {extendRepresentationPropertyConfig, extractRepresentationPropertyValue} from "./property/utils";
11
- import TypePropertyMaps = Decorator.TypePropertyMap;
12
-
13
- export class RepresentationManager<T extends Decorator.Type> {
14
- protected extendedProperties : Partial<Decorator.RepresentationProperties<Decorator.TypePropertyMap[T]>> = {};
15
-
16
- constructor(
17
- protected representation: Decorator.Representation<T>,
18
- public decorators: Decorator.Data[]
19
- ) {
20
-
21
- }
22
-
23
- // -------------------------------------------
24
-
25
- /**
26
- * Get one or more specific value(s) of the decorator arguments or typeArguments.
27
- * @param type
28
- * @param decoratorOrIndex
29
- */
30
- public getPropertyValue<P extends keyof Decorator.TypePropertyMap[T]>(
31
- type: P,
32
- decoratorOrIndex?: number | Decorator.Data
33
- ) : TypePropertyMaps[T][P] | undefined {
34
- const config : Decorator.Property = this.getPropertyConfiguration(type);
35
- if(typeof config === 'undefined') {
36
- return undefined;
37
- }
38
-
39
- let decorator : Decorator.Data;
40
-
41
- if(
42
- typeof decoratorOrIndex === 'number' ||
43
- typeof decoratorOrIndex === 'undefined'
44
- ) {
45
- decoratorOrIndex = decoratorOrIndex ?? 0;
46
- if (decoratorOrIndex < 0 || decoratorOrIndex >= this.decorators.length) {
47
- return undefined;
48
- }
49
-
50
- decorator = this.decorators[decoratorOrIndex];
51
- } else {
52
- decorator = decoratorOrIndex;
53
- }
54
-
55
- return extractRepresentationPropertyValue<T, P>(decorator, config);
56
- }
57
-
58
- // -------------------------------------------
59
-
60
- public getPropertyConfiguration(type: keyof Decorator.TypePropertyMap[T]) : Decorator.Property | undefined {
61
- if(!hasOwnProperty(this.representation.properties, type)) {
62
- return undefined;
63
- }
64
-
65
- return this.extendProperty(type);
66
- }
67
-
68
- // -------------------------------------------
69
-
70
- protected extendProperty<P extends keyof Decorator.TypePropertyMap[T]>(type: P) : Decorator.Property {
71
- if(hasOwnProperty(this.extendedProperties, type)) {
72
- return this.extendedProperties[type];
73
- }
74
-
75
- const property = this.representation.properties[type];
76
- this.extendedProperties[type] = extendRepresentationPropertyConfig(property);
77
-
78
- return this.extendedProperties[type];
79
-
80
- }
81
- }
82
-