@tsed/platform-params 6.88.1 → 6.89.0

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 (174) hide show
  1. package/lib/{builder → cjs/builder}/PlatformParams.d.ts +0 -0
  2. package/lib/cjs/builder/PlatformParams.js +79 -0
  3. package/lib/cjs/builder/PlatformParams.js.map +1 -0
  4. package/lib/{decorators → cjs/decorators}/bodyParams.d.ts +0 -0
  5. package/lib/cjs/decorators/bodyParams.js +53 -0
  6. package/lib/cjs/decorators/bodyParams.js.map +1 -0
  7. package/lib/{decorators → cjs/decorators}/context.d.ts +0 -0
  8. package/lib/cjs/decorators/context.js +19 -0
  9. package/lib/cjs/decorators/context.js.map +1 -0
  10. package/lib/{decorators → cjs/decorators}/cookies.d.ts +0 -0
  11. package/lib/cjs/decorators/cookies.js +24 -0
  12. package/lib/cjs/decorators/cookies.js.map +1 -0
  13. package/lib/{decorators → cjs/decorators}/headerParams.d.ts +0 -0
  14. package/lib/cjs/decorators/headerParams.js +19 -0
  15. package/lib/cjs/decorators/headerParams.js.map +1 -0
  16. package/lib/{decorators → cjs/decorators}/locals.d.ts +0 -0
  17. package/lib/cjs/decorators/locals.js +19 -0
  18. package/lib/cjs/decorators/locals.js.map +1 -0
  19. package/lib/{decorators → cjs/decorators}/paramFn.d.ts +0 -0
  20. package/lib/cjs/decorators/paramFn.js +22 -0
  21. package/lib/cjs/decorators/paramFn.js.map +1 -0
  22. package/lib/{decorators → cjs/decorators}/pathParams.d.ts +0 -0
  23. package/lib/cjs/decorators/pathParams.js +55 -0
  24. package/lib/cjs/decorators/pathParams.js.map +1 -0
  25. package/lib/{decorators → cjs/decorators}/queryParams.d.ts +0 -0
  26. package/lib/cjs/decorators/queryParams.js +55 -0
  27. package/lib/cjs/decorators/queryParams.js.map +1 -0
  28. package/lib/{decorators → cjs/decorators}/session.d.ts +0 -0
  29. package/lib/cjs/decorators/session.js +19 -0
  30. package/lib/cjs/decorators/session.js.map +1 -0
  31. package/lib/{decorators → cjs/decorators}/useDeserialization.d.ts +0 -0
  32. package/lib/cjs/decorators/useDeserialization.js +18 -0
  33. package/lib/cjs/decorators/useDeserialization.js.map +1 -0
  34. package/lib/{decorators → cjs/decorators}/useParam.d.ts +0 -0
  35. package/lib/cjs/decorators/useParam.js +38 -0
  36. package/lib/cjs/decorators/useParam.js.map +1 -0
  37. package/lib/{decorators → cjs/decorators}/useParamExpression.d.ts +0 -0
  38. package/lib/cjs/decorators/useParamExpression.js +20 -0
  39. package/lib/cjs/decorators/useParamExpression.js.map +1 -0
  40. package/lib/{decorators → cjs/decorators}/useParamType.d.ts +0 -0
  41. package/lib/cjs/decorators/useParamType.js +26 -0
  42. package/lib/cjs/decorators/useParamType.js.map +1 -0
  43. package/lib/{decorators → cjs/decorators}/usePipe.d.ts +0 -0
  44. package/lib/cjs/decorators/usePipe.js +22 -0
  45. package/lib/cjs/decorators/usePipe.js.map +1 -0
  46. package/lib/{decorators → cjs/decorators}/useType.d.ts +0 -0
  47. package/lib/cjs/decorators/useType.js +20 -0
  48. package/lib/cjs/decorators/useType.js.map +1 -0
  49. package/lib/{decorators → cjs/decorators}/useValidation.d.ts +0 -0
  50. package/lib/cjs/decorators/useValidation.js +22 -0
  51. package/lib/cjs/decorators/useValidation.js.map +1 -0
  52. package/lib/{domain → cjs/domain}/ParamMetadata.d.ts +0 -0
  53. package/lib/cjs/domain/ParamMetadata.js +34 -0
  54. package/lib/cjs/domain/ParamMetadata.js.map +1 -0
  55. package/lib/{domain → cjs/domain}/ParamOptions.d.ts +0 -0
  56. package/lib/cjs/domain/ParamOptions.js +3 -0
  57. package/lib/cjs/domain/ParamOptions.js.map +1 -0
  58. package/lib/{domain → cjs/domain}/ParamTypes.d.ts +0 -0
  59. package/lib/cjs/domain/ParamTypes.js +30 -0
  60. package/lib/cjs/domain/ParamTypes.js.map +1 -0
  61. package/lib/{errors → cjs/errors}/ParamValidationError.d.ts +0 -0
  62. package/lib/cjs/errors/ParamValidationError.js +29 -0
  63. package/lib/cjs/errors/ParamValidationError.js.map +1 -0
  64. package/lib/{errors → cjs/errors}/RequiredValidationError.d.ts +0 -1
  65. package/lib/cjs/errors/RequiredValidationError.js +32 -0
  66. package/lib/cjs/errors/RequiredValidationError.js.map +1 -0
  67. package/lib/{errors → cjs/errors}/ValidationError.d.ts +0 -0
  68. package/lib/cjs/errors/ValidationError.js +13 -0
  69. package/lib/cjs/errors/ValidationError.js.map +1 -0
  70. package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
  71. package/lib/cjs/index.js +37 -0
  72. package/lib/cjs/index.js.map +1 -0
  73. package/lib/{pipes → cjs/pipes}/DeserializerPipe.d.ts +0 -0
  74. package/lib/cjs/pipes/DeserializerPipe.js +30 -0
  75. package/lib/cjs/pipes/DeserializerPipe.js.map +1 -0
  76. package/lib/{pipes → cjs/pipes}/ParseExpressionPipe.d.ts +0 -0
  77. package/lib/cjs/pipes/ParseExpressionPipe.js +24 -0
  78. package/lib/cjs/pipes/ParseExpressionPipe.js.map +1 -0
  79. package/lib/{pipes → cjs/pipes}/ValidationPipe.d.ts +0 -0
  80. package/lib/cjs/pipes/ValidationPipe.js +80 -0
  81. package/lib/cjs/pipes/ValidationPipe.js.map +1 -0
  82. package/lib/{utils → cjs/utils}/mapParamsOptions.d.ts +0 -0
  83. package/lib/cjs/utils/mapParamsOptions.js +30 -0
  84. package/lib/cjs/utils/mapParamsOptions.js.map +1 -0
  85. package/lib/esm/builder/PlatformParams.js +76 -0
  86. package/lib/esm/builder/PlatformParams.js.map +1 -0
  87. package/lib/esm/decorators/bodyParams.js +48 -0
  88. package/lib/esm/decorators/bodyParams.js.map +1 -0
  89. package/lib/esm/decorators/context.js +15 -0
  90. package/lib/esm/decorators/context.js.map +1 -0
  91. package/lib/esm/decorators/cookies.js +19 -0
  92. package/lib/esm/decorators/cookies.js.map +1 -0
  93. package/lib/esm/decorators/headerParams.js +15 -0
  94. package/lib/esm/decorators/headerParams.js.map +1 -0
  95. package/lib/esm/decorators/locals.js +15 -0
  96. package/lib/esm/decorators/locals.js.map +1 -0
  97. package/lib/esm/decorators/paramFn.js +18 -0
  98. package/lib/esm/decorators/paramFn.js.map +1 -0
  99. package/lib/esm/decorators/pathParams.js +50 -0
  100. package/lib/esm/decorators/pathParams.js.map +1 -0
  101. package/lib/esm/decorators/queryParams.js +50 -0
  102. package/lib/esm/decorators/queryParams.js.map +1 -0
  103. package/lib/esm/decorators/session.js +15 -0
  104. package/lib/esm/decorators/session.js.map +1 -0
  105. package/lib/esm/decorators/useDeserialization.js +14 -0
  106. package/lib/esm/decorators/useDeserialization.js.map +1 -0
  107. package/lib/esm/decorators/useParam.js +34 -0
  108. package/lib/esm/decorators/useParam.js.map +1 -0
  109. package/lib/esm/decorators/useParamExpression.js +16 -0
  110. package/lib/esm/decorators/useParamExpression.js.map +1 -0
  111. package/lib/esm/decorators/useParamType.js +22 -0
  112. package/lib/esm/decorators/useParamType.js.map +1 -0
  113. package/lib/esm/decorators/usePipe.js +18 -0
  114. package/lib/esm/decorators/usePipe.js.map +1 -0
  115. package/lib/esm/decorators/useType.js +16 -0
  116. package/lib/esm/decorators/useType.js.map +1 -0
  117. package/lib/esm/decorators/useValidation.js +18 -0
  118. package/lib/esm/decorators/useValidation.js.map +1 -0
  119. package/lib/esm/domain/ParamMetadata.js +31 -0
  120. package/lib/esm/domain/ParamMetadata.js.map +1 -0
  121. package/lib/esm/domain/ParamOptions.js +2 -0
  122. package/lib/esm/domain/ParamOptions.js.map +1 -0
  123. package/lib/esm/domain/ParamTypes.js +27 -0
  124. package/lib/esm/domain/ParamTypes.js.map +1 -0
  125. package/lib/esm/errors/ParamValidationError.js +25 -0
  126. package/lib/esm/errors/ParamValidationError.js.map +1 -0
  127. package/lib/esm/errors/RequiredValidationError.js +28 -0
  128. package/lib/esm/errors/RequiredValidationError.js.map +1 -0
  129. package/lib/esm/errors/ValidationError.js +9 -0
  130. package/lib/esm/errors/ValidationError.js.map +1 -0
  131. package/lib/esm/index.js +34 -0
  132. package/lib/esm/index.js.map +1 -0
  133. package/lib/esm/pipes/DeserializerPipe.js +27 -0
  134. package/lib/esm/pipes/DeserializerPipe.js.map +1 -0
  135. package/lib/esm/pipes/ParseExpressionPipe.js +21 -0
  136. package/lib/esm/pipes/ParseExpressionPipe.js.map +1 -0
  137. package/lib/esm/pipes/ValidationPipe.js +77 -0
  138. package/lib/esm/pipes/ValidationPipe.js.map +1 -0
  139. package/lib/esm/utils/mapParamsOptions.js +26 -0
  140. package/lib/esm/utils/mapParamsOptions.js.map +1 -0
  141. package/lib/types/builder/PlatformParams.d.ts +23 -0
  142. package/lib/types/decorators/bodyParams.d.ts +64 -0
  143. package/lib/types/decorators/context.d.ts +59 -0
  144. package/lib/types/decorators/cookies.d.ts +81 -0
  145. package/lib/types/decorators/headerParams.d.ts +33 -0
  146. package/lib/types/decorators/locals.d.ts +42 -0
  147. package/lib/types/decorators/paramFn.d.ts +11 -0
  148. package/lib/types/decorators/pathParams.d.ts +68 -0
  149. package/lib/types/decorators/queryParams.d.ts +73 -0
  150. package/lib/types/decorators/session.d.ts +36 -0
  151. package/lib/types/decorators/useDeserialization.d.ts +9 -0
  152. package/lib/types/decorators/useParam.d.ts +22 -0
  153. package/lib/types/decorators/useParamExpression.d.ts +10 -0
  154. package/lib/types/decorators/useParamType.d.ts +10 -0
  155. package/lib/types/decorators/usePipe.d.ts +13 -0
  156. package/lib/types/decorators/useType.d.ts +13 -0
  157. package/lib/types/decorators/useValidation.d.ts +9 -0
  158. package/lib/types/domain/ParamMetadata.d.ts +16 -0
  159. package/lib/types/domain/ParamOptions.d.ts +10 -0
  160. package/lib/types/domain/ParamTypes.d.ts +24 -0
  161. package/lib/types/errors/ParamValidationError.d.ts +8 -0
  162. package/lib/types/errors/RequiredValidationError.d.ts +6 -0
  163. package/lib/types/errors/ValidationError.d.ts +6 -0
  164. package/lib/types/index.d.ts +28 -0
  165. package/lib/types/pipes/DeserializerPipe.d.ts +5 -0
  166. package/lib/types/pipes/ParseExpressionPipe.d.ts +5 -0
  167. package/lib/types/pipes/ValidationPipe.d.ts +10 -0
  168. package/lib/types/utils/mapParamsOptions.d.ts +5 -0
  169. package/package.json +20 -16
  170. package/tsconfig.compile.esm.json +23 -0
  171. package/lib/index.js +0 -807
  172. package/lib/index.js.map +0 -1
  173. package/lib/index.modern.js +0 -788
  174. package/lib/index.modern.js.map +0 -1
@@ -1,788 +0,0 @@
1
- import { isObject, prototypeOf, DecoratorTypes, getValue, nameOf, decoratorTypeOf, useDecorators, isString } from '@tsed/core';
2
- import { __decorate, __metadata } from 'tslib';
3
- import { JsonParameterStore, JsonEntityStore, JsonEntityComponent, getJsonSchema, isParameterType, Name, CollectionOf, Any, JsonEntityFn } from '@tsed/schema';
4
- import { Injectable, Constant, InjectorService, ProviderScope, Inject } from '@tsed/di';
5
- import { deserialize } from '@tsed/json-mapper';
6
- import { BadRequest } from '@tsed/exceptions';
7
-
8
- function _extends() {
9
- _extends = Object.assign || function (target) {
10
- for (var i = 1; i < arguments.length; i++) {
11
- var source = arguments[i];
12
-
13
- for (var key in source) {
14
- if (Object.prototype.hasOwnProperty.call(source, key)) {
15
- target[key] = source[key];
16
- }
17
- }
18
- }
19
-
20
- return target;
21
- };
22
-
23
- return _extends.apply(this, arguments);
24
- }
25
-
26
- function _objectWithoutPropertiesLoose(source, excluded) {
27
- if (source == null) return {};
28
- var target = {};
29
- var sourceKeys = Object.keys(source);
30
- var key, i;
31
-
32
- for (i = 0; i < sourceKeys.length; i++) {
33
- key = sourceKeys[i];
34
- if (excluded.indexOf(key) >= 0) continue;
35
- target[key] = source[key];
36
- }
37
-
38
- return target;
39
- }
40
-
41
- /**
42
- * @ignore
43
- */
44
-
45
- function mapParamsOptions(args) {
46
- if (args.length === 1) {
47
- if (typeof args[0] === "string") {
48
- return {
49
- expression: args[0]
50
- };
51
- }
52
-
53
- if (!isObject(args[0])) {
54
- return {
55
- useType: args[0]
56
- };
57
- }
58
-
59
- return _extends({}, args[0]);
60
- }
61
-
62
- return {
63
- expression: args[0],
64
- useType: args[1]
65
- };
66
- }
67
-
68
- var ParamTypes;
69
-
70
- (function (ParamTypes) {
71
- ParamTypes["$CTX"] = "$CTX";
72
- ParamTypes["BODY"] = "BODY";
73
- ParamTypes["PATH"] = "PATH";
74
- ParamTypes["QUERY"] = "QUERY";
75
- ParamTypes["HEADER"] = "HEADER";
76
- ParamTypes["RAW_BODY"] = "RAW_BODY";
77
- ParamTypes["COOKIES"] = "COOKIES";
78
- ParamTypes["LOCALS"] = "LOCALS";
79
- ParamTypes["SESSION"] = "SESSION";
80
- ParamTypes["FILES"] = "FILES"; /// NOT STD
81
-
82
- ParamTypes["NEXT_FN"] = "NEXT_FN";
83
- ParamTypes["ERR"] = "ERR";
84
- ParamTypes["REQUEST"] = "REQUEST";
85
- ParamTypes["PLATFORM_REQUEST"] = "PLATFORM_REQUEST";
86
- ParamTypes["NODE_REQUEST"] = "NODE_REQUEST";
87
- ParamTypes["RESPONSE"] = "RESPONSE";
88
- ParamTypes["PLATFORM_RESPONSE"] = "PLATFORM_RESPONSE";
89
- ParamTypes["NODE_RESPONSE"] = "NODE_RESPONSE";
90
- ParamTypes["RESPONSE_DATA"] = "RESPONSE_DATA";
91
- ParamTypes["ENDPOINT_INFO"] = "ENDPOINT_INFO";
92
- ParamTypes["RES"] = "RES";
93
- ParamTypes["REQ"] = "REQ";
94
- })(ParamTypes || (ParamTypes = {}));
95
-
96
- let ParamMetadata = class ParamMetadata extends JsonParameterStore {
97
- constructor(options) {
98
- super(options);
99
- this.paramType = "$ctx";
100
- this.pipes = [];
101
- this.paramType = options.paramType || this.paramType;
102
- this.expression = options.expression || this.expression;
103
- this.dataPath = options.dataPath || this.dataPath;
104
- this.pipes = options.pipes || [];
105
- }
106
-
107
- get key() {
108
- let {
109
- expression,
110
- paramType,
111
- dataPath
112
- } = this;
113
-
114
- if (expression && paramType === ParamTypes.HEADER) {
115
- expression = String(expression).toLowerCase();
116
- }
117
-
118
- return [dataPath, expression].filter(Boolean).join(".");
119
- }
120
-
121
- static get(target, propertyKey, index) {
122
- return JsonEntityStore.from(prototypeOf(target), propertyKey, index);
123
- }
124
-
125
- };
126
- ParamMetadata = __decorate([JsonEntityComponent(DecoratorTypes.PARAM), __metadata("design:paramtypes", [Object])], ParamMetadata);
127
-
128
- let ParseExpressionPipe = class ParseExpressionPipe {
129
- transform(scope, param) {
130
- const {
131
- paramType,
132
- type
133
- } = param;
134
- const value = getValue(scope, param.key);
135
-
136
- if ([ParamTypes.QUERY, ParamTypes.PATH].includes(paramType) && value === "" && type !== String) {
137
- return undefined;
138
- }
139
-
140
- return value;
141
- }
142
-
143
- };
144
- ParseExpressionPipe = __decorate([Injectable({
145
- priority: -1000
146
- })], ParseExpressionPipe);
147
-
148
- var DeserializerPipe_1;
149
- let DeserializerPipe = DeserializerPipe_1 = class DeserializerPipe {
150
- transform(value, param) {
151
- return deserialize(value, _extends({
152
- useAlias: true,
153
- additionalProperties: this.settings.additionalProperties === "accept",
154
- type: param.type,
155
- collectionType: param.collectionType,
156
- groups: param.parameter.groups,
157
- genericTypes: param.nestedGenerics[0],
158
- nestedGenerics: param.nestedGenerics
159
- }, param.store.get(DeserializerPipe_1) || {}));
160
- }
161
-
162
- };
163
-
164
- __decorate([Constant("converter", {}), __metadata("design:type", Object)], DeserializerPipe.prototype, "settings", void 0);
165
-
166
- DeserializerPipe = DeserializerPipe_1 = __decorate([Injectable()], DeserializerPipe);
167
-
168
- class ValidationError extends BadRequest {
169
- constructor(message, errors = []) {
170
- super(message);
171
- this.name = "VALIDATION_ERROR";
172
- this.errors = errors;
173
- }
174
-
175
- }
176
-
177
- class RequiredValidationError extends ValidationError {
178
- constructor() {
179
- super(...arguments);
180
- this.name = "REQUIRED_VALIDATION_ERROR";
181
- }
182
-
183
- static from(metadata) {
184
- const name = nameOf(metadata.paramType);
185
- const expression = metadata.expression;
186
- const type = name.toLowerCase().replace(/parse|params|filter/gi, "");
187
- const message = `It should have required parameter '${expression}'`;
188
- const errors = [{
189
- dataPath: "",
190
- keyword: "required",
191
- message,
192
- modelName: type,
193
- params: {
194
- missingProperty: expression
195
- },
196
- schemaPath: "#/required"
197
- }];
198
- return new RequiredValidationError(message, errors);
199
- }
200
-
201
- }
202
-
203
- let ValidationPipe = class ValidationPipe {
204
- constructor(injector) {
205
- const provider = injector.getProviders().find(provider => nameOf(provider.token) === "AjvService");
206
-
207
- if (provider) {
208
- this.validator = injector.invoke(provider.token);
209
- }
210
- }
211
-
212
- coerceTypes(value, metadata) {
213
- if (value === undefined) {
214
- return value;
215
- }
216
-
217
- if (value === "null") {
218
- return null;
219
- }
220
-
221
- if (metadata.isPrimitive) {
222
- try {
223
- return deserialize(value, {
224
- type: metadata.type
225
- });
226
- } catch (er) {
227
- return value;
228
- }
229
- }
230
-
231
- if (metadata.isArray) {
232
- return [].concat(value);
233
- }
234
-
235
- return value;
236
- }
237
-
238
- skip(value, metadata) {
239
- return metadata.paramType === ParamTypes.PATH && !metadata.isPrimitive;
240
- }
241
-
242
- async transform(value, metadata) {
243
- if (!this.validator) {
244
- this.checkIsRequired(value, metadata);
245
- return value;
246
- }
247
-
248
- if (this.skip(value, metadata)) {
249
- return value;
250
- }
251
-
252
- value = this.coerceTypes(value, metadata);
253
- this.checkIsRequired(value, metadata);
254
-
255
- if (value === undefined) {
256
- return value;
257
- }
258
-
259
- const schema = getJsonSchema(metadata, {
260
- customKeys: true
261
- });
262
- await this.validator.validate(value, {
263
- schema,
264
- type: metadata.isClass ? metadata.type : undefined,
265
- collectionType: metadata.collectionType
266
- });
267
- return value;
268
- }
269
-
270
- checkIsRequired(value, metadata) {
271
- if (metadata.isRequired(value)) {
272
- throw RequiredValidationError.from(metadata);
273
- }
274
-
275
- return true;
276
- }
277
-
278
- };
279
- ValidationPipe = __decorate([Injectable({
280
- type: "validator"
281
- }), __metadata("design:paramtypes", [InjectorService])], ValidationPipe);
282
-
283
- class ParamValidationError extends BadRequest {
284
- constructor() {
285
- super(...arguments);
286
- this.name = "PARAM_VALIDATION_ERROR";
287
- }
288
-
289
- static from(metadata, origin = {}) {
290
- if (origin instanceof ValidationError || origin instanceof BadRequest) {
291
- const name = nameOf(metadata.paramType).toLowerCase().replace(/parse|params|filter/gi, "");
292
- const expression = metadata.expression;
293
- const message = `Bad request on parameter "request.${name}${expression ? "." + expression : ""}".\n${origin.message}`.trim();
294
- const error = new ParamValidationError(message);
295
- error.dataPath = String(metadata.expression) || "";
296
- error.requestType = nameOf(metadata.paramType);
297
- error.origin = origin.origin || origin;
298
- return error;
299
- }
300
-
301
- return origin;
302
- }
303
-
304
- }
305
-
306
- /**
307
- * Platform Params abstraction layer.
308
- * @platform
309
- */
310
-
311
- let PlatformParams = class PlatformParams {
312
- async getPipes(param) {
313
- const get = pipe => {
314
- return this.injector.getProvider(pipe).priority || 0;
315
- };
316
-
317
- const sort = (p1, p2) => get(p1) < get(p2) ? -1 : get(p1) > get(p2) ? 1 : 0;
318
-
319
- const map = token => this.injector.invoke(token);
320
-
321
- const promises = await Promise.all([ParseExpressionPipe, ...param.pipes.sort(sort)].map(map));
322
- return promises.filter(Boolean);
323
- }
324
-
325
- async compile(entity) {
326
- var _this = this;
327
-
328
- const params = JsonParameterStore.getParams(entity.target, entity.propertyKey);
329
- const argsPipes = await Promise.all(params.map(async function (param) {
330
- return {
331
- param,
332
- pipes: await _this.getPipes(param)
333
- };
334
- }));
335
- return scope => {
336
- const promises = argsPipes.map(({
337
- param,
338
- pipes
339
- }) => {
340
- return this.getArg(scope, pipes, param);
341
- });
342
- return Promise.all(promises);
343
- };
344
- }
345
-
346
- async getArg(scope, pipes, param) {
347
- return pipes.reduce(async function (value, pipe) {
348
- value = await value;
349
-
350
- try {
351
- return await pipe.transform(value, param);
352
- } catch (er) {
353
- throw ParamValidationError.from(param, er);
354
- }
355
- }, scope);
356
- }
357
-
358
- async compileHandler(metadata) {
359
- var _this2 = this;
360
-
361
- const {
362
- token,
363
- propertyKey,
364
- getCustomArgs
365
- } = metadata;
366
- const provider = this.injector.getProvider(token);
367
- const getArguments = getCustomArgs || (await this.compile(JsonEntityStore.fromMethod(token, propertyKey)));
368
-
369
- if (!provider || !provider.scope || provider.scope === ProviderScope.SINGLETON) {
370
- const instance = await this.injector.invoke(token);
371
- const handler = instance[propertyKey].bind(instance);
372
- return async function (scope) {
373
- const args = await getArguments(scope);
374
- return handler(...args, scope.$ctx);
375
- };
376
- }
377
-
378
- return async function (scope) {
379
- const [instance, args] = await Promise.all([_this2.injector.invoke(token, scope.$ctx.container), getArguments(scope)]);
380
- const handler = instance[propertyKey].bind(instance);
381
- return handler(...args, scope.$ctx);
382
- };
383
- }
384
-
385
- };
386
-
387
- __decorate([Inject(), __metadata("design:type", InjectorService)], PlatformParams.prototype, "injector", void 0);
388
-
389
- PlatformParams = __decorate([Injectable({
390
- scope: ProviderScope.SINGLETON,
391
- imports: []
392
- })], PlatformParams);
393
-
394
- /**
395
- * Get the Param metadata. Use this decorator to compose your own decorator.
396
- *
397
- * @param fn
398
- * @decorator
399
- * @operation
400
- * @input
401
- */
402
-
403
- function ParamFn(fn) {
404
- return (target, propertyKey, index) => {
405
- if (decoratorTypeOf([target, propertyKey, index]) === DecoratorTypes.PARAM) {
406
- fn(ParamMetadata.get(target, propertyKey, index), [target, propertyKey, index]);
407
- }
408
- };
409
- }
410
-
411
- /**
412
- * Register a Pipe to be used with the current decorated param.
413
- *
414
- * @param token
415
- * @param options
416
- * @decorator
417
- * @operation
418
- * @input
419
- * @pipe
420
- */
421
-
422
- function UsePipe(token, options = {}) {
423
- return ParamFn(param => {
424
- param.store.set(token, options);
425
- param.pipes.push(token);
426
- });
427
- }
428
-
429
- /**
430
- * Use JsonMapper to deserialize the data.
431
- *
432
- * @decorator
433
- * @operation
434
- * @input
435
- * @pipe
436
- */
437
-
438
- function UseDeserialization(options = {}) {
439
- return UsePipe(DeserializerPipe, options);
440
- }
441
-
442
- /**
443
- * Get data from a path inside the given object
444
- *
445
- * @param expression
446
- * @decorator
447
- * @operation
448
- * @input
449
- * @pipe
450
- */
451
-
452
- function UseParamExpression(expression) {
453
- return ParamFn(param => {
454
- param.expression = expression || "";
455
- });
456
- }
457
-
458
- /**
459
- * Get the object from request (like body, params, query, etc...).
460
- *
461
- * @decorator
462
- * @operation
463
- * @input
464
- * @pipe
465
- */
466
-
467
- function UseParamType(options) {
468
- return useDecorators(ParamFn(param => {
469
- if (isParameterType(options.paramType)) {
470
- param.parameter.in(options.paramType);
471
- }
472
-
473
- param.paramType = options.paramType;
474
- param.dataPath = options.dataPath;
475
- }), UseParamExpression(options.expression), options.expression && Name(options.expression));
476
- }
477
-
478
- /**
479
- * Set the type of the item colllection.
480
- *
481
- * Prefer @@CollectionOf@@ usage.
482
- *
483
- * @param type
484
- * @decorator
485
- * @operation
486
- * @input
487
- * @alias CollectionOf
488
- */
489
-
490
- function UseType(type) {
491
- return CollectionOf(type);
492
- }
493
-
494
- /**
495
- * Enable validation on the decoratored parameter.
496
- *
497
- * @decorator
498
- * @operation
499
- * @input
500
- * @pipe
501
- */
502
-
503
- function UseValidation() {
504
- return ParamFn(param => {
505
- if (param.type || param.collectionType) {
506
- param.pipes.push(ValidationPipe);
507
- }
508
- });
509
- }
510
-
511
- const _excluded = ["paramType", "useType", "expression", "useValidation", "useConverter"];
512
- /**
513
- * @ignore
514
- * @param options
515
- */
516
-
517
- function mapPipes(options) {
518
- const {
519
- useType,
520
- useValidation,
521
- useConverter
522
- } = options,
523
- props = _objectWithoutPropertiesLoose(options, _excluded);
524
-
525
- return [useType ? UseType(useType) : ParamFn((entity, parameters) => {
526
- if (entity.isCollection && entity.type === Object) {
527
- Any()(...parameters);
528
- }
529
- }), useValidation && UseValidation(), useConverter && UseDeserialization(props)];
530
- }
531
-
532
- function UseParam(...args) {
533
- const options = _extends({
534
- dataPath: "$ctx"
535
- }, (isString(args[0]) ? args[1] : args[0]) || {}, {
536
- paramType: isString(args[0]) ? args[0] : args[0].paramType
537
- });
538
-
539
- return useDecorators(UseParamType(options), ...mapPipes(options));
540
- }
541
-
542
- function Context(...args) {
543
- const {
544
- expression,
545
- useType,
546
- useConverter = false,
547
- useValidation = false
548
- } = mapParamsOptions(args);
549
- return UseParam({
550
- paramType: ParamTypes.$CTX,
551
- dataPath: "$ctx",
552
- expression,
553
- useType,
554
- useConverter,
555
- useValidation
556
- });
557
- }
558
-
559
- function BodyParams(...args) {
560
- const {
561
- expression,
562
- useType,
563
- useConverter = true,
564
- useValidation = true
565
- } = mapParamsOptions(args);
566
- return UseParam({
567
- paramType: ParamTypes.BODY,
568
- dataPath: "$ctx.request.body",
569
- expression,
570
- useType,
571
- useConverter,
572
- useValidation
573
- });
574
- }
575
- /**
576
- * RawBodyParams return the value from [request.body](http://expressjs.com/en/4x/api.html#req.body) as a Buffer.
577
- *
578
- * #### Example
579
- *
580
- * ```typescript
581
- * @Controller('/')
582
- * class MyCtrl {
583
- * @Post('/')
584
- * create(@RawBodyParams() body: Buffer) {
585
- * console.log('Entire body', body.toString("utf8"));
586
- * }
587
- * }
588
- * ```
589
- *
590
- * @decorator
591
- * @operation
592
- * @input
593
- */
594
-
595
- function RawBodyParams() {
596
- return useDecorators(UseParam({
597
- paramType: ParamTypes.RAW_BODY,
598
- dataPath: "$ctx.request.rawBody",
599
- useType: String,
600
- useConverter: false,
601
- useValidation: false
602
- }), JsonEntityFn(entity => {
603
- var _entity$parent$operat;
604
-
605
- (_entity$parent$operat = entity.parent.operation) == null ? void 0 : _entity$parent$operat.consumes(["*/*"]);
606
- }));
607
- }
608
-
609
- function HeaderParams(...args) {
610
- const {
611
- expression,
612
- useType,
613
- useConverter = false,
614
- useValidation = false
615
- } = mapParamsOptions(args);
616
- return UseParam({
617
- paramType: ParamTypes.HEADER,
618
- dataPath: "$ctx.request.headers",
619
- expression,
620
- useType,
621
- useConverter,
622
- useValidation
623
- });
624
- }
625
-
626
- function CookiesParams(...args) {
627
- const {
628
- expression,
629
- useType,
630
- useConverter = false,
631
- useValidation = false
632
- } = mapParamsOptions(args);
633
- return UseParam({
634
- paramType: ParamTypes.COOKIES,
635
- dataPath: "$ctx.request.cookies",
636
- expression,
637
- useType,
638
- useConverter,
639
- useValidation
640
- });
641
- }
642
- function Cookies(...args) {
643
- // @ts-ignore
644
- return CookiesParams(...args);
645
- }
646
-
647
- function Locals(...args) {
648
- const {
649
- expression,
650
- useType,
651
- useConverter = false,
652
- useValidation = false
653
- } = mapParamsOptions(args);
654
- return UseParam({
655
- paramType: ParamTypes.LOCALS,
656
- dataPath: "$ctx.response.locals",
657
- expression,
658
- useType,
659
- useConverter,
660
- useValidation
661
- });
662
- }
663
-
664
- function PathParams(...args) {
665
- const {
666
- expression,
667
- useType,
668
- useConverter = true,
669
- useValidation = true
670
- } = mapParamsOptions(args);
671
- return UseParam({
672
- paramType: ParamTypes.PATH,
673
- dataPath: "$ctx.request.params",
674
- expression,
675
- useType,
676
- useConverter,
677
- useValidation
678
- });
679
- }
680
- /**
681
- * RawPathParams return the raw value from [request.params](http://expressjs.com/en/4x/api.html#req.params) object.
682
- *
683
- * Any validation and transformation are performed on the value. Use [pipes](/docs/pipes.html) to validate and/or transform the value.
684
- *
685
- * #### Example
686
- *
687
- * ```typescript
688
- * @Controller('/')
689
- * class MyCtrl {
690
- * @Get('/')
691
- * get(@RawPathParams() params: string) {
692
- * console.log('Entire params', params);
693
- * }
694
- *
695
- * @Get('/')
696
- * get(@RawPathParams('id') id: string) {
697
- * console.log('ID', id);
698
- * }
699
- * }
700
- * ```
701
- * > For more information on deserialization see [converters](/docs/converters.md) page.
702
- *
703
- * @param expression The path of the property to get.
704
- * @decorator
705
- * @operation
706
- * @input
707
- */
708
-
709
- function RawPathParams(expression) {
710
- return UseParam({
711
- paramType: ParamTypes.PATH,
712
- dataPath: "$ctx.request.params",
713
- expression
714
- });
715
- }
716
-
717
- function QueryParams(...args) {
718
- const {
719
- expression,
720
- useType,
721
- useConverter = true,
722
- useValidation = true
723
- } = mapParamsOptions(args);
724
- return UseParam({
725
- paramType: ParamTypes.QUERY,
726
- dataPath: "$ctx.request.query",
727
- expression,
728
- useType,
729
- useConverter,
730
- useValidation
731
- });
732
- }
733
- /**
734
- * RawQueryParams return the value from [request.query](http://expressjs.com/en/4x/api.html#req.query) object.
735
- *
736
- * Any validation and transformation are performed on the value. Use [pipes](/docs/pipes.html) to validate and/or transform the value.
737
- *
738
- * #### Example
739
- *
740
- * ```typescript
741
- * @Controller('/')
742
- * class MyCtrl {
743
- * @Get('/')
744
- * get(@RawPathParams() params: any) {
745
- * console.log('Entire params', params);
746
- * }
747
- *
748
- * @Get('/')
749
- * get(@RawPathParams('id') id: string) {
750
- * console.log('ID', id);
751
- * }
752
- * }
753
- * ```
754
- * > For more information on deserialization see [converters](/docs/converters.md) page.
755
- *
756
- * @param expression The path of the property to get.
757
- * @decorator
758
- * @operation
759
- * @input
760
- */
761
-
762
- function RawQueryParams(expression) {
763
- return UseParam({
764
- paramType: ParamTypes.QUERY,
765
- dataPath: "$ctx.request.query",
766
- expression
767
- });
768
- }
769
-
770
- function Session(...args) {
771
- const {
772
- expression,
773
- useType,
774
- useConverter = false,
775
- useValidation = false
776
- } = mapParamsOptions(args);
777
- return UseParam({
778
- paramType: ParamTypes.SESSION,
779
- dataPath: "$ctx.request.session",
780
- expression,
781
- useType,
782
- useConverter,
783
- useValidation
784
- });
785
- }
786
-
787
- export { BodyParams, Context, Cookies, CookiesParams, DeserializerPipe, HeaderParams, Locals, ParamFn, ParamMetadata, ParamTypes, ParamValidationError, ParseExpressionPipe, PathParams, PlatformParams, QueryParams, RawBodyParams, RawPathParams, RawQueryParams, RequiredValidationError, Session, UseDeserialization, UseParam, UseParamExpression, UseParamType, UsePipe, UseType, UseValidation, ValidationError, ValidationPipe, mapParamsOptions };
788
- //# sourceMappingURL=index.modern.js.map