@trapi/metadata 0.1.3 → 0.1.7

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 (165) hide show
  1. package/dist/cache/driver.d.ts +1 -1
  2. package/dist/cache/driver.d.ts.map +1 -1
  3. package/dist/cache/driver.js +3 -6
  4. package/dist/cache/driver.js.map +1 -1
  5. package/dist/cache/type.d.ts +1 -1
  6. package/dist/cache/type.d.ts.map +1 -1
  7. package/dist/cache/utils.d.ts +1 -1
  8. package/dist/cache/utils.d.ts.map +1 -1
  9. package/dist/cache/utils.js +14 -14
  10. package/dist/cache/utils.js.map +1 -1
  11. package/dist/config/path.js.map +1 -1
  12. package/dist/decorator/functions.d.ts.map +1 -1
  13. package/dist/decorator/functions.js +9 -13
  14. package/dist/decorator/functions.js.map +1 -1
  15. package/dist/decorator/index.d.ts +1 -1
  16. package/dist/decorator/index.d.ts.map +1 -1
  17. package/dist/decorator/index.js +1 -3
  18. package/dist/decorator/index.js.map +1 -1
  19. package/dist/decorator/mapper/index.d.ts +3 -3
  20. package/dist/decorator/mapper/index.d.ts.map +1 -1
  21. package/dist/decorator/mapper/index.js +6 -11
  22. package/dist/decorator/mapper/index.js.map +1 -1
  23. package/dist/decorator/mapper/maps/decorators-express.d.ts +1 -1
  24. package/dist/decorator/mapper/maps/decorators-express.d.ts.map +1 -1
  25. package/dist/decorator/mapper/maps/decorators-express.js +33 -33
  26. package/dist/decorator/mapper/maps/internal.d.ts +1 -1
  27. package/dist/decorator/mapper/maps/internal.d.ts.map +1 -1
  28. package/dist/decorator/mapper/maps/internal.js +31 -27
  29. package/dist/decorator/mapper/maps/internal.js.map +1 -1
  30. package/dist/decorator/mapper/maps/typescript-rest.d.ts +1 -1
  31. package/dist/decorator/mapper/maps/typescript-rest.d.ts.map +1 -1
  32. package/dist/decorator/mapper/maps/typescript-rest.js +38 -38
  33. package/dist/decorator/mapper/maps/typescript-rest.js.map +1 -1
  34. package/dist/decorator/mapper/utils.d.ts +1 -1
  35. package/dist/decorator/mapper/utils.d.ts.map +1 -1
  36. package/dist/decorator/mapper/utils.js +1 -1
  37. package/dist/decorator/mapper/utils.js.map +1 -1
  38. package/dist/decorator/representation/index.d.ts +1 -1
  39. package/dist/decorator/representation/index.d.ts.map +1 -1
  40. package/dist/decorator/representation/index.js +2 -4
  41. package/dist/decorator/representation/index.js.map +1 -1
  42. package/dist/decorator/representation/property/utils.d.ts +1 -1
  43. package/dist/decorator/representation/property/utils.d.ts.map +1 -1
  44. package/dist/decorator/representation/property/utils.js +7 -6
  45. package/dist/decorator/representation/property/utils.js.map +1 -1
  46. package/dist/decorator/type.d.ts.map +1 -1
  47. package/dist/decorator/utils/node.d.ts +1 -1
  48. package/dist/decorator/utils/node.d.ts.map +1 -1
  49. package/dist/decorator/utils/node.js +4 -6
  50. package/dist/decorator/utils/node.js.map +1 -1
  51. package/dist/decorator/utils/validator.d.ts +2 -2
  52. package/dist/decorator/utils/validator.d.ts.map +1 -1
  53. package/dist/decorator/utils/validator.js +8 -8
  54. package/dist/decorator/utils/validator.js.map +1 -1
  55. package/dist/generator/controller.d.ts +1 -1
  56. package/dist/generator/controller.d.ts.map +1 -1
  57. package/dist/generator/controller.js +1 -1
  58. package/dist/generator/controller.js.map +1 -1
  59. package/dist/generator/endpoint.d.ts +2 -2
  60. package/dist/generator/endpoint.d.ts.map +1 -1
  61. package/dist/generator/endpoint.js +14 -19
  62. package/dist/generator/endpoint.js.map +1 -1
  63. package/dist/generator/index.d.ts +5 -33
  64. package/dist/generator/index.d.ts.map +1 -1
  65. package/dist/generator/index.js +15 -151
  66. package/dist/generator/index.js.map +1 -1
  67. package/dist/generator/method.d.ts +1 -1
  68. package/dist/generator/method.d.ts.map +1 -1
  69. package/dist/generator/method.js +10 -12
  70. package/dist/generator/method.js.map +1 -1
  71. package/dist/generator/module.d.ts +41 -0
  72. package/dist/generator/module.d.ts.map +1 -0
  73. package/dist/generator/module.js +166 -0
  74. package/dist/generator/module.js.map +1 -0
  75. package/dist/generator/parameter.d.ts +1 -1
  76. package/dist/generator/parameter.d.ts.map +1 -1
  77. package/dist/generator/parameter.js +26 -35
  78. package/dist/generator/parameter.js.map +1 -1
  79. package/dist/resolver/type-node.d.ts +1 -1
  80. package/dist/resolver/type-node.d.ts.map +1 -1
  81. package/dist/resolver/type-node.js +124 -189
  82. package/dist/resolver/type-node.js.map +1 -1
  83. package/dist/resolver/type.d.ts +1 -1
  84. package/dist/resolver/type.d.ts.map +1 -1
  85. package/dist/resolver/utils/initializer.d.ts +1 -1
  86. package/dist/resolver/utils/initializer.d.ts.map +1 -1
  87. package/dist/resolver/utils/initializer.js +11 -12
  88. package/dist/resolver/utils/initializer.js.map +1 -1
  89. package/dist/resolver/utils/validator.d.ts +1 -1
  90. package/dist/resolver/utils/validator.d.ts.map +1 -1
  91. package/dist/resolver/utils/validator.js +8 -11
  92. package/dist/resolver/utils/validator.js.map +1 -1
  93. package/dist/type.d.ts +8 -3
  94. package/dist/type.d.ts.map +1 -1
  95. package/dist/utils/generator.d.ts +2 -2
  96. package/dist/utils/generator.d.ts.map +1 -1
  97. package/dist/utils/generator.js +2 -2
  98. package/dist/utils/generator.js.map +1 -1
  99. package/dist/utils/js-doc.d.ts.map +1 -1
  100. package/dist/utils/js-doc.js +7 -11
  101. package/dist/utils/js-doc.js.map +1 -1
  102. package/dist/utils/validator.d.ts +2 -2
  103. package/dist/utils/validator.d.ts.map +1 -1
  104. package/dist/utils/validator.js +2 -2
  105. package/dist/utils/validator.js.map +1 -1
  106. package/package.json +19 -13
  107. package/src/cache/driver.ts +0 -97
  108. package/src/cache/index.ts +0 -10
  109. package/src/cache/type.ts +0 -43
  110. package/src/cache/utils.ts +0 -49
  111. package/src/config/index.ts +0 -8
  112. package/src/config/path.ts +0 -29
  113. package/src/decorator/functions.ts +0 -142
  114. package/src/decorator/index.ts +0 -13
  115. package/src/decorator/mapper/index.ts +0 -153
  116. package/src/decorator/mapper/maps/decorators-express.ts +0 -117
  117. package/src/decorator/mapper/maps/internal.ts +0 -95
  118. package/src/decorator/mapper/maps/typescript-rest.ts +0 -150
  119. package/src/decorator/mapper/utils.ts +0 -88
  120. package/src/decorator/representation/index.ts +0 -82
  121. package/src/decorator/representation/property/utils.ts +0 -146
  122. package/src/decorator/type.ts +0 -235
  123. package/src/decorator/utils/index.ts +0 -9
  124. package/src/decorator/utils/node.ts +0 -59
  125. package/src/decorator/utils/validator.ts +0 -104
  126. package/src/generator/controller.ts +0 -65
  127. package/src/generator/endpoint.ts +0 -212
  128. package/src/generator/index.ts +0 -219
  129. package/src/generator/method.ts +0 -198
  130. package/src/generator/parameter.ts +0 -392
  131. package/src/index.ts +0 -13
  132. package/src/resolver/error.ts +0 -38
  133. package/src/resolver/index.ts +0 -11
  134. package/src/resolver/type-node.ts +0 -1287
  135. package/src/resolver/type.ts +0 -257
  136. package/src/resolver/utils/index.ts +0 -9
  137. package/src/resolver/utils/initializer.ts +0 -81
  138. package/src/resolver/utils/validator.ts +0 -144
  139. package/src/type.ts +0 -185
  140. package/src/utils/generator.ts +0 -42
  141. package/src/utils/index.ts +0 -10
  142. package/src/utils/js-doc.ts +0 -125
  143. package/src/utils/validator.ts +0 -43
  144. package/test/data/library/@decorators-express/decorators.ts +0 -7
  145. package/test/data/library/self/api.ts +0 -37
  146. package/test/data/library/type.ts +0 -138
  147. package/test/data/library/typescript-rest/api.ts +0 -366
  148. package/test/data/library/typescript-rest/decorators/index.ts +0 -10
  149. package/test/data/library/typescript-rest/decorators/methods.ts +0 -34
  150. package/test/data/library/typescript-rest/decorators/parameters.ts +0 -62
  151. package/test/data/library/typescript-rest/decorators/services.ts +0 -47
  152. package/test/data/library/typescript-rest/return-types.ts +0 -94
  153. package/test/data/library/utils.ts +0 -7
  154. package/test/jest.config.js +0 -49
  155. package/test/unit/cache.spec.ts +0 -48
  156. package/test/unit/decorator/mapper/index.spec.ts +0 -83
  157. package/test/unit/decorator/representation/index.spec.ts +0 -102
  158. package/test/unit/decorator/utils/node.spec.ts +0 -47
  159. package/test/unit/library/typescript-rest.spec.ts +0 -342
  160. package/test/unit/resolver/type.spec.ts +0 -134
  161. package/test/unit/utils/generator.spec.ts +0 -41
  162. package/test/unit/utils/js-doc.spec.ts +0 -104
  163. package/tsconfig.build.json +0 -11
  164. package/tsconfig.json +0 -9
  165. package/writable/.gitignore +0 -3
@@ -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
-
@@ -1,146 +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 {
9
- Expression
10
- } from "typescript";
11
- import {hasOwnProperty} from "@trapi/metadata-utils";
12
- import {Decorator} from "../../type";
13
- import {getInitializerValue} from "../../../resolver";
14
-
15
- export function extendRepresentationPropertyConfig(property: Decorator.Property): Decorator.Property {
16
- if(typeof property.isType === 'undefined') {
17
- property.isType = false;
18
- }
19
-
20
- if (typeof property.type === 'undefined') {
21
- property.type = 'element';
22
- }
23
-
24
- if (typeof property.srcArgumentType === 'undefined') {
25
- property.srcArgumentType = 'argument';
26
- }
27
-
28
- if (
29
- property.type === 'element' &&
30
- typeof property.srcPosition === 'undefined'
31
- ) {
32
- property.srcPosition = 0;
33
- }
34
-
35
- return property;
36
- }
37
-
38
- export function extractRepresentationPropertyValue<
39
- T extends Decorator.Type,
40
- P extends keyof Decorator.TypePropertyMap[T]
41
- >(
42
- decorator: Decorator.Data,
43
- config: Decorator.Property
44
- ): Decorator.TypePropertyMap[T][P] | undefined {
45
- let items : unknown[] = [];
46
-
47
- switch (config.srcArgumentType) {
48
- case 'typeArgument':
49
- items = decorator.typeArguments;
50
- break;
51
- case "argument":
52
- items = decorator.arguments;
53
- break;
54
- }
55
-
56
- if(!config.isType) {
57
- items = extractValueFromArgumentType(items);
58
- }
59
-
60
- const srcPosition : number = config.srcPosition ?? 0;
61
- const srcAmount : number = config.srcAmount ?? 1;
62
-
63
- if (items.length <= srcPosition) {
64
- switch (config.type) {
65
- case 'element':
66
- return undefined;
67
- case 'array':
68
- return [] as unknown as Decorator.TypePropertyMap[T][P];
69
- }
70
- }
71
-
72
- const data : unknown[] | unknown[][] = srcAmount >= 1 ? items.slice(srcPosition, srcPosition + srcAmount) : items.slice(srcPosition);
73
-
74
- if(data.length === 0) {
75
- return (config.type === 'array' ? [] : undefined) as unknown as Decorator.TypePropertyMap[T][P];
76
- }
77
-
78
- const srcStrategy : Decorator.PropertyStrategy = config.srcStrategy ?? 'none';
79
-
80
- switch (srcStrategy) {
81
- case "merge":
82
- switch (config.type) {
83
- case 'array':
84
- return mergeArrayArguments(data) as unknown as Decorator.TypePropertyMap[T][P];
85
- case 'element':
86
- default:
87
- return mergeObjectArguments(data) as Decorator.TypePropertyMap[T][P];
88
- }
89
- case "none":
90
- // if we dont have any merge strategy, we just return the first argument.
91
- switch (config.type) {
92
- case 'array':
93
- const arr = Array.isArray(data[0]) ? data[0] : [data[0]];
94
- return arr as unknown as Decorator.TypePropertyMap[T][P];
95
- case 'element':
96
- default:
97
- return data[0] as Decorator.TypePropertyMap[T][P];
98
- }
99
- default:
100
- if(typeof config.srcStrategy === 'function') {
101
- return config.srcStrategy(data) as Decorator.TypePropertyMap[T][P];
102
- }
103
-
104
- return (config.type === 'array' ? [] : undefined) as unknown as Decorator.TypePropertyMap[T][P];
105
- }
106
- }
107
-
108
- export function mergeObjectArguments(data: unknown[]) {
109
- let output : Record<string, any> = {};
110
- for(let i=0; i<data.length; i++) {
111
- const prototype = Object.prototype.toString.call(data[i]);
112
- if(prototype === '[object Object]') {
113
- output = Object.assign(output, data[i]);
114
- }
115
- }
116
-
117
- return output;
118
- }
119
-
120
- export function mergeArrayArguments(data: unknown[]) {
121
- let merged : unknown[] = [];
122
- for(let i=0; i<data.length; i++) {
123
- if(Array.isArray(data[i])) {
124
- merged = [...merged, ...data[i] as unknown[]];
125
- } else {
126
- merged.push(data[i]);
127
- }
128
- }
129
-
130
- return merged;
131
- }
132
-
133
- function extractValueFromArgumentType(argument: unknown[]) {
134
- const values : unknown[] = [];
135
-
136
- for(let i=0; i<argument.length; i++) {
137
- if(!hasOwnProperty(argument[i], 'kind')) {
138
- values.push(argument[i]);
139
- continue;
140
- }
141
-
142
- values.push(getInitializerValue(argument[i] as Expression));
143
- }
144
-
145
- return values;
146
- }