@tsed/platform-params 7.0.0-beta.13 → 7.0.0-beta.14
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.
- package/lib/cjs/builder/PlatformParams.js +21 -28
- package/lib/cjs/builder/PlatformParams.js.map +1 -1
- package/lib/cjs/pipes/ParseExpressionPipe.js.map +1 -1
- package/lib/esm/builder/PlatformParams.js +22 -29
- package/lib/esm/builder/PlatformParams.js.map +1 -1
- package/lib/esm/pipes/ParseExpressionPipe.js.map +1 -1
- package/lib/types/builder/PlatformParams.d.ts +15 -13
- package/lib/types/pipes/ParseExpressionPipe.d.ts +2 -2
- package/package.json +11 -11
|
@@ -12,27 +12,36 @@ const ParseExpressionPipe_1 = require("../pipes/ParseExpressionPipe");
|
|
|
12
12
|
*/
|
|
13
13
|
let PlatformParams = class PlatformParams {
|
|
14
14
|
injector;
|
|
15
|
-
|
|
15
|
+
getPipes(param) {
|
|
16
16
|
const get = (pipe) => {
|
|
17
17
|
return this.injector.getProvider(pipe).priority || 0;
|
|
18
18
|
};
|
|
19
19
|
const sort = (p1, p2) => (get(p1) < get(p2) ? -1 : get(p1) > get(p2) ? 1 : 0);
|
|
20
|
-
const map = (token) => this.injector.
|
|
21
|
-
|
|
22
|
-
return promises.filter(Boolean);
|
|
20
|
+
const map = (token) => this.injector.get(token);
|
|
21
|
+
return [ParseExpressionPipe_1.ParseExpressionPipe, ...param.pipes.sort(sort)].map(map).filter(Boolean);
|
|
23
22
|
}
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Return a handler with injectable parameters
|
|
25
|
+
* @param handlerMetadata
|
|
26
|
+
*/
|
|
27
|
+
compileHandler({ propertyKey, token }) {
|
|
28
|
+
const store = schema_1.JsonMethodStore.fromMethod(token, propertyKey);
|
|
29
|
+
const getArguments = this.compile(store);
|
|
30
|
+
return async (scope) => {
|
|
31
|
+
const [instance, args] = await Promise.all([this.injector.invoke(token, scope.$ctx.container), getArguments(scope)]);
|
|
32
|
+
return instance[propertyKey].call(instance, ...args, scope.$ctx);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
compile(entity) {
|
|
25
36
|
const params = schema_1.JsonParameterStore.getParams(entity.target, entity.propertyKey);
|
|
26
|
-
const argsPipes =
|
|
37
|
+
const argsPipes = params.map((param) => {
|
|
27
38
|
return {
|
|
28
39
|
param,
|
|
29
|
-
pipes:
|
|
40
|
+
pipes: this.getPipes(param)
|
|
30
41
|
};
|
|
31
|
-
})
|
|
42
|
+
});
|
|
32
43
|
return (scope) => {
|
|
33
|
-
const promises = argsPipes.map(({ param, pipes }) =>
|
|
34
|
-
return this.getArg(scope, pipes, param);
|
|
35
|
-
});
|
|
44
|
+
const promises = argsPipes.map(({ param, pipes }) => this.getArg(scope, pipes, param));
|
|
36
45
|
return Promise.all(promises);
|
|
37
46
|
};
|
|
38
47
|
}
|
|
@@ -47,22 +56,6 @@ let PlatformParams = class PlatformParams {
|
|
|
47
56
|
}
|
|
48
57
|
}, scope);
|
|
49
58
|
}
|
|
50
|
-
async compileHandler(metadata) {
|
|
51
|
-
const { token, propertyKey, getCustomArgs } = metadata;
|
|
52
|
-
const provider = this.injector.getProvider(token);
|
|
53
|
-
const getArguments = getCustomArgs || (await this.compile(schema_1.JsonEntityStore.fromMethod(token, propertyKey)));
|
|
54
|
-
if (!provider || !provider.scope || provider.scope === di_1.ProviderScope.SINGLETON) {
|
|
55
|
-
const instance = await this.injector.invoke(token);
|
|
56
|
-
return async (scope) => {
|
|
57
|
-
const args = await getArguments(scope);
|
|
58
|
-
return instance[propertyKey].call(instance, ...args, scope.$ctx);
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
return async (scope) => {
|
|
62
|
-
const [instance, args] = await Promise.all([this.injector.invoke(token, scope.$ctx.container), getArguments(scope)]);
|
|
63
|
-
return instance[propertyKey].call(instance, ...args, scope.$ctx);
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
59
|
};
|
|
67
60
|
tslib_1.__decorate([
|
|
68
61
|
(0, di_1.Inject)(),
|
|
@@ -71,7 +64,7 @@ tslib_1.__decorate([
|
|
|
71
64
|
PlatformParams = tslib_1.__decorate([
|
|
72
65
|
(0, di_1.Injectable)({
|
|
73
66
|
scope: di_1.ProviderScope.SINGLETON,
|
|
74
|
-
imports: []
|
|
67
|
+
imports: [ParseExpressionPipe_1.ParseExpressionPipe]
|
|
75
68
|
})
|
|
76
69
|
], PlatformParams);
|
|
77
70
|
exports.PlatformParams = PlatformParams;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformParams.js","sourceRoot":"","sources":["../../../src/builder/PlatformParams.ts"],"names":[],"mappings":";;;;AAAA,iCAAsG;AACtG,yCAA8E;AAC9E,yEAAoE;AACpE,sEAAiE;
|
|
1
|
+
{"version":3,"file":"PlatformParams.js","sourceRoot":"","sources":["../../../src/builder/PlatformParams.ts"],"names":[],"mappings":";;;;AAAA,iCAAsG;AACtG,yCAA8E;AAC9E,yEAAoE;AACpE,sEAAiE;AAKjE;;;GAGG;AAKH,IAAa,cAAc,GAA3B,MAAa,cAAc;IAEf,QAAQ,CAAkB;IAEpC,QAAQ,CAAC,KAAyB;QAChC,MAAM,GAAG,GAAG,CAAC,IAAmB,EAAE,EAAE;YAClC,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAE,CAAC,QAAQ,IAAI,CAAC,CAAC;QACxD,CAAC,CAAC;QAEF,MAAM,IAAI,GAAG,CAAC,EAAiB,EAAE,EAAiB,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5G,MAAM,GAAG,GAAG,CAAC,KAAoB,E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Q,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,EAAC,KAAK,EAAE,KAAK,EAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;YACrF,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC/B,CAAC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAwC,KAA0B,EAAE,KAAoB,EAAE,KAAyB;QAC7H,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,KAAyB,EAAE,IAAI,EAAE,EAAE;YAC5D,KAAK,GAAG,MAAM,KAAK,CAAC;YAEpB,IAAI;gBACF,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;aAC3C;YAAC,OAAO,EAAE,EAAE;gBACX,MAAM,2CAAoB,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;aAC5C;QACH,CAAC,EAAE,KAAK,CAAC,CAAC;IACZ,CAAC;CACF,CAAA;AA5DC;IADC,IAAA,WAAM,GAAE;sCACW,oBAAe;gDAAC;AAFzB,cAAc;IAJ1B,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,CAAC,yCAAmB,CAAC;KAC/B,CAAC;GACW,cAAc,CA8D1B;AA9DY,wCAAc","sourcesContent":["import {DIContext, Inject, Injectable, InjectorService, ProviderScope, TokenProvider} from \"@tsed/di\";\nimport {JsonMethodStore, JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {ParamValidationError} from \"../errors/ParamValidationError\";\nimport {ParseExpressionPipe} from \"../pipes/ParseExpressionPipe\";\n\nexport type PlatformParamsScope<Context extends DIContext = DIContext> = {$ctx: Context} & Record<string, any>;\nexport type PlatformParamsCallback<Context extends DIContext = DIContext> = (scope: PlatformParamsScope) => Promise<any>;\n\n/**\n * Platform Params abstraction layer.\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: [ParseExpressionPipe]\n})\nexport class PlatformParams {\n @Inject()\n protected injector: InjectorService;\n\n getPipes(param: JsonParameterStore) {\n const get = (pipe: TokenProvider) => {\n return this.injector.getProvider(pipe)!.priority || 0;\n };\n\n const sort = (p1: TokenProvider, p2: TokenProvider) => (get(p1) < get(p2) ? -1 : get(p1) > get(p2) ? 1 : 0);\n const map = (token: TokenProvider) => this.injector.get<PipeMethods>(token)!;\n\n return [ParseExpressionPipe, ...param.pipes.sort(sort)].map(map).filter(Boolean);\n }\n\n /**\n * Return a handler with injectable parameters\n * @param handlerMetadata\n */\n compileHandler<Context extends DIContext = DIContext>({\n propertyKey,\n token\n }: {\n propertyKey: string | symbol;\n token: any;\n }): PlatformParamsCallback<Context> {\n const store = JsonMethodStore.fromMethod(token, propertyKey);\n const getArguments = this.compile<Context>(store);\n\n return async (scope: PlatformParamsScope) => {\n const [instance, args] = await Promise.all([this.injector.invoke<any>(token, scope.$ctx.container), getArguments(scope)]);\n\n return instance[propertyKey].call(instance, ...args, scope.$ctx);\n };\n }\n\n compile<Context extends DIContext = DIContext>(entity: JsonMethodStore): PlatformParamsCallback<Context> {\n const params = JsonParameterStore.getParams(entity.target, entity.propertyKey);\n const argsPipes = params.map((param) => {\n return {\n param,\n pipes: this.getPipes(param)\n };\n });\n\n return (scope) => {\n const promises = argsPipes.map(({param, pipes}) => this.getArg(scope, pipes, param));\n return Promise.all(promises);\n };\n }\n\n async getArg<Context extends DIContext = DIContext>(scope: PlatformParamsScope, pipes: PipeMethods[], param: JsonParameterStore) {\n return pipes.reduce(async (value: any | Promise<any>, pipe) => {\n value = await value;\n\n try {\n return await pipe.transform(value, param);\n } catch (er) {\n throw ParamValidationError.from(param, er);\n }\n }, scope);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParseExpressionPipe.js","sourceRoot":"","sources":["../../../src/pipes/ParseExpressionPip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B,CAuB/B;AAvBY,kDAAmB","sourcesContent":["import {getValue} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {PlatformParamsScope} from \"../builder/PlatformParams\";\nimport {ParamTypes} from \"../domain/ParamTypes\";\n\n@Injectable({\n priority: -1000\n})\nexport class ParseExpressionPipe implements PipeMethods {\n transform(scope: PlatformParamsScope, param: JsonParameterStore) {\n const {paramType, type} = param;\n\n const value = getValue(scope, this.getKey(param));\n\n if ([ParamTypes.QUERY, ParamTypes.PATH].includes(paramType as ParamTypes) && value === \"\" && type !== String) {\n return undefined;\n }\n\n return value;\n }\n\n protected getKey(param: JsonParameterStore) {\n let {expression, paramType, dataPath} = param;\n paramType = paramType || param.parameter.get(\"in\").toUpperCase();\n\n if (expression && paramType === ParamTypes.HEADER) {\n expression = String(expression).toLowerCase();\n }\n\n return [dataPath, expression].filter(Boolean).join(\".\");\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Inject, Injectable, InjectorService, ProviderScope } from "@tsed/di";
|
|
3
|
-
import {
|
|
3
|
+
import { JsonMethodStore, JsonParameterStore } from "@tsed/schema";
|
|
4
4
|
import { ParamValidationError } from "../errors/ParamValidationError.js";
|
|
5
5
|
import { ParseExpressionPipe } from "../pipes/ParseExpressionPipe.js";
|
|
6
6
|
/**
|
|
@@ -9,27 +9,36 @@ import { ParseExpressionPipe } from "../pipes/ParseExpressionPipe.js";
|
|
|
9
9
|
*/
|
|
10
10
|
let PlatformParams = class PlatformParams {
|
|
11
11
|
injector;
|
|
12
|
-
|
|
12
|
+
getPipes(param) {
|
|
13
13
|
const get = (pipe) => {
|
|
14
14
|
return this.injector.getProvider(pipe).priority || 0;
|
|
15
15
|
};
|
|
16
16
|
const sort = (p1, p2) => (get(p1) < get(p2) ? -1 : get(p1) > get(p2) ? 1 : 0);
|
|
17
|
-
const map = (token) => this.injector.
|
|
18
|
-
|
|
19
|
-
return promises.filter(Boolean);
|
|
17
|
+
const map = (token) => this.injector.get(token);
|
|
18
|
+
return [ParseExpressionPipe, ...param.pipes.sort(sort)].map(map).filter(Boolean);
|
|
20
19
|
}
|
|
21
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Return a handler with injectable parameters
|
|
22
|
+
* @param handlerMetadata
|
|
23
|
+
*/
|
|
24
|
+
compileHandler({ propertyKey, token }) {
|
|
25
|
+
const store = JsonMethodStore.fromMethod(token, propertyKey);
|
|
26
|
+
const getArguments = this.compile(store);
|
|
27
|
+
return async (scope) => {
|
|
28
|
+
const [instance, args] = await Promise.all([this.injector.invoke(token, scope.$ctx.container), getArguments(scope)]);
|
|
29
|
+
return instance[propertyKey].call(instance, ...args, scope.$ctx);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
compile(entity) {
|
|
22
33
|
const params = JsonParameterStore.getParams(entity.target, entity.propertyKey);
|
|
23
|
-
const argsPipes =
|
|
34
|
+
const argsPipes = params.map((param) => {
|
|
24
35
|
return {
|
|
25
36
|
param,
|
|
26
|
-
pipes:
|
|
37
|
+
pipes: this.getPipes(param)
|
|
27
38
|
};
|
|
28
|
-
})
|
|
39
|
+
});
|
|
29
40
|
return (scope) => {
|
|
30
|
-
const promises = argsPipes.map(({ param, pipes }) =>
|
|
31
|
-
return this.getArg(scope, pipes, param);
|
|
32
|
-
});
|
|
41
|
+
const promises = argsPipes.map(({ param, pipes }) => this.getArg(scope, pipes, param));
|
|
33
42
|
return Promise.all(promises);
|
|
34
43
|
};
|
|
35
44
|
}
|
|
@@ -44,22 +53,6 @@ let PlatformParams = class PlatformParams {
|
|
|
44
53
|
}
|
|
45
54
|
}, scope);
|
|
46
55
|
}
|
|
47
|
-
async compileHandler(metadata) {
|
|
48
|
-
const { token, propertyKey, getCustomArgs } = metadata;
|
|
49
|
-
const provider = this.injector.getProvider(token);
|
|
50
|
-
const getArguments = getCustomArgs || (await this.compile(JsonEntityStore.fromMethod(token, propertyKey)));
|
|
51
|
-
if (!provider || !provider.scope || provider.scope === ProviderScope.SINGLETON) {
|
|
52
|
-
const instance = await this.injector.invoke(token);
|
|
53
|
-
return async (scope) => {
|
|
54
|
-
const args = await getArguments(scope);
|
|
55
|
-
return instance[propertyKey].call(instance, ...args, scope.$ctx);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
return async (scope) => {
|
|
59
|
-
const [instance, args] = await Promise.all([this.injector.invoke(token, scope.$ctx.container), getArguments(scope)]);
|
|
60
|
-
return instance[propertyKey].call(instance, ...args, scope.$ctx);
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
56
|
};
|
|
64
57
|
__decorate([
|
|
65
58
|
Inject(),
|
|
@@ -68,7 +61,7 @@ __decorate([
|
|
|
68
61
|
PlatformParams = __decorate([
|
|
69
62
|
Injectable({
|
|
70
63
|
scope: ProviderScope.SINGLETON,
|
|
71
|
-
imports: []
|
|
64
|
+
imports: [ParseExpressionPipe]
|
|
72
65
|
})
|
|
73
66
|
], PlatformParams);
|
|
74
67
|
export { PlatformParams };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformParams.js","sourceRoot":"","sources":["../../../src/builder/PlatformParams.ts"],"names":[],"mappings":";AAAA,OAAO,EAAY,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,aAAa,EAAgB,MAAM,UAAU,CAAC;AACtG,OAAO,EAAC,eAAe,EAAE,kBAAkB,EAAc,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAC,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"PlatformParams.js","sourceRoot":"","sources":["../../../src/builder/PlatformParams.ts"],"names":[],"mappings":";AAAA,OAAO,EAAY,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,aAAa,EAAgB,MAAM,UAAU,CAAC;AACtG,OAAO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,KAAK,EAAE,KAAK,CAAC,CAAC;aAC3C;YAAC,OAAO,EAAE,EAAE;gBACX,MAAM,oBAAoB,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;aAC5C;QACH,CAAC,EAAE,KAAK,CAAC,CAAC;IACZ,CAAC;CACF,CAAA;AA5DC;IADC,MAAM,EAAE;8BACW,eAAe;gDAAC;AAFzB,cAAc;IAJ1B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,CAAC,mBAAmB,CAAC;KAC/B,CAAC;GACW,cAAc,CA8D1B;SA9DY,cAAc","sourcesContent":["import {DIContext, Inject, Injectable, InjectorService, ProviderScope, TokenProvider} from \"@tsed/di\";\nimport {JsonMethodStore, JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {ParamValidationError} from \"../errors/ParamValidationError\";\nimport {ParseExpressionPipe} from \"../pipes/ParseExpressionPipe\";\n\nexport type PlatformParamsScope<Context extends DIContext = DIContext> = {$ctx: Context} & Record<string, any>;\nexport type PlatformParamsCallback<Context extends DIContext = DIContext> = (scope: PlatformParamsScope) => Promise<any>;\n\n/**\n * Platform Params abstraction layer.\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: [ParseExpressionPipe]\n})\nexport class PlatformParams {\n @Inject()\n protected injector: InjectorService;\n\n getPipes(param: JsonParameterStore) {\n const get = (pipe: TokenProvider) => {\n return this.injector.getProvider(pipe)!.priority || 0;\n };\n\n const sort = (p1: TokenProvider, p2: TokenProvider) => (get(p1) < get(p2) ? -1 : get(p1) > get(p2) ? 1 : 0);\n const map = (token: TokenProvider) => this.injector.get<PipeMethods>(token)!;\n\n return [ParseExpressionPipe, ...param.pipes.sort(sort)].map(map).filter(Boolean);\n }\n\n /**\n * Return a handler with injectable parameters\n * @param handlerMetadata\n */\n compileHandler<Context extends DIContext = DIContext>({\n propertyKey,\n token\n }: {\n propertyKey: string | symbol;\n token: any;\n }): PlatformParamsCallback<Context> {\n const store = JsonMethodStore.fromMethod(token, propertyKey);\n const getArguments = this.compile<Context>(store);\n\n return async (scope: PlatformParamsScope) => {\n const [instance, args] = await Promise.all([this.injector.invoke<any>(token, scope.$ctx.container), getArguments(scope)]);\n\n return instance[propertyKey].call(instance, ...args, scope.$ctx);\n };\n }\n\n compile<Context extends DIContext = DIContext>(entity: JsonMethodStore): PlatformParamsCallback<Context> {\n const params = JsonParameterStore.getParams(entity.target, entity.propertyKey);\n const argsPipes = params.map((param) => {\n return {\n param,\n pipes: this.getPipes(param)\n };\n });\n\n return (scope) => {\n const promises = argsPipes.map(({param, pipes}) => this.getArg(scope, pipes, param));\n return Promise.all(promises);\n };\n }\n\n async getArg<Context extends DIContext = DIContext>(scope: PlatformParamsScope, pipes: PipeMethods[], param: JsonParameterStore) {\n return pipes.reduce(async (value: any | Promise<any>, pipe) => {\n value = await value;\n\n try {\n return await pipe.transform(value, param);\n } catch (er) {\n throw ParamValidationError.from(param, er);\n }\n }, scope);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParseExpressionPipe.js","sourceRoot":"","sources":["../../../src/pipes/ParseExpressionPipe.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"ParseExpressionPipe.js","sourceRoot":"","sources":["../../../src/pipes/ParseExpressionPipe.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAGpC,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAKhD,IAAa,mBAAmB,GAAhC,MAAa,mBAAmB;IAC9B,SAAS,CAAC,KAA0B,EAAE,KAAyB;QAC7D,MAAM,EAAC,SAAS,EAAE,IAAI,EAAC,GAAG,KAAK,CAAC;QAEhC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAElD,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAuB,CAAC,IAAI,KAAK,KAAK,EAAE,IAAI,IAAI,KAAK,MAAM,EAAE;YAC5G,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAES,MAAM,CAAC,KAAyB;QACxC,IAAI,EAAC,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAC,GAAG,KAAK,CAAC;QAC9C,SAAS,GAAG,SAAS,IAAI,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QAEjE,IAAI,UAAU,IAAI,SAAS,KAAK,UAAU,CAAC,MAAM,EAAE;YACjD,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;SAC/C;QAED,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1D,CAAC;CACF,CAAA;AAvBY,mBAAmB;IAH/B,UAAU,CAAC;QACV,QAAQ,EAAE,CAAC,IAAI;KAChB,CAAC;GACW,mBAAmB,CAuB/B;SAvBY,mBAAmB","sourcesContent":["import {getValue} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {PlatformParamsScope} from \"../builder/PlatformParams\";\nimport {ParamTypes} from \"../domain/ParamTypes\";\n\n@Injectable({\n priority: -1000\n})\nexport class ParseExpressionPipe implements PipeMethods {\n transform(scope: PlatformParamsScope, param: JsonParameterStore) {\n const {paramType, type} = param;\n\n const value = getValue(scope, this.getKey(param));\n\n if ([ParamTypes.QUERY, ParamTypes.PATH].includes(paramType as ParamTypes) && value === \"\" && type !== String) {\n return undefined;\n }\n\n return value;\n }\n\n protected getKey(param: JsonParameterStore) {\n let {expression, paramType, dataPath} = param;\n paramType = paramType || param.parameter.get(\"in\").toUpperCase();\n\n if (expression && paramType === ParamTypes.HEADER) {\n expression = String(expression).toLowerCase();\n }\n\n return [dataPath, expression].filter(Boolean).join(\".\");\n }\n}\n"]}
|
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import { DIContext, InjectorService
|
|
2
|
-
import {
|
|
3
|
-
export declare type
|
|
1
|
+
import { DIContext, InjectorService } from "@tsed/di";
|
|
2
|
+
import { JsonMethodStore, JsonParameterStore, PipeMethods } from "@tsed/schema";
|
|
3
|
+
export declare type PlatformParamsScope<Context extends DIContext = DIContext> = {
|
|
4
4
|
$ctx: Context;
|
|
5
5
|
} & Record<string, any>;
|
|
6
|
-
export declare type
|
|
7
|
-
export interface CompileHandlerOptions<Context extends DIContext = DIContext> extends Record<any, unknown> {
|
|
8
|
-
token: TokenProvider;
|
|
9
|
-
propertyKey: string | symbol;
|
|
10
|
-
getCustomArgs?: (scope: ArgScope<Context>) => Promise<any[]>;
|
|
11
|
-
}
|
|
6
|
+
export declare type PlatformParamsCallback<Context extends DIContext = DIContext> = (scope: PlatformParamsScope) => Promise<any>;
|
|
12
7
|
/**
|
|
13
8
|
* Platform Params abstraction layer.
|
|
14
9
|
* @platform
|
|
15
10
|
*/
|
|
16
11
|
export declare class PlatformParams {
|
|
17
12
|
protected injector: InjectorService;
|
|
18
|
-
getPipes(param: JsonParameterStore):
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
getPipes(param: JsonParameterStore): PipeMethods<any, any>[];
|
|
14
|
+
/**
|
|
15
|
+
* Return a handler with injectable parameters
|
|
16
|
+
* @param handlerMetadata
|
|
17
|
+
*/
|
|
18
|
+
compileHandler<Context extends DIContext = DIContext>({ propertyKey, token }: {
|
|
19
|
+
propertyKey: string | symbol;
|
|
20
|
+
token: any;
|
|
21
|
+
}): PlatformParamsCallback<Context>;
|
|
22
|
+
compile<Context extends DIContext = DIContext>(entity: JsonMethodStore): PlatformParamsCallback<Context>;
|
|
23
|
+
getArg<Context extends DIContext = DIContext>(scope: PlatformParamsScope, pipes: PipeMethods[], param: JsonParameterStore): Promise<any>;
|
|
22
24
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JsonParameterStore, PipeMethods } from "@tsed/schema";
|
|
2
|
-
import
|
|
2
|
+
import { PlatformParamsScope } from "../builder/PlatformParams";
|
|
3
3
|
export declare class ParseExpressionPipe implements PipeMethods {
|
|
4
|
-
transform(scope:
|
|
4
|
+
transform(scope: PlatformParamsScope, param: JsonParameterStore): any;
|
|
5
5
|
protected getKey(param: JsonParameterStore): string;
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-params",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.14",
|
|
4
4
|
"description": "Params module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -24,18 +24,18 @@
|
|
|
24
24
|
"tslib": "2.4.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@tsed/core": "7.0.0-beta.
|
|
28
|
-
"@tsed/di": "7.0.0-beta.
|
|
29
|
-
"@tsed/exceptions": "7.0.0-beta.
|
|
30
|
-
"@tsed/json-mapper": "7.0.0-beta.
|
|
31
|
-
"@tsed/schema": "7.0.0-beta.
|
|
27
|
+
"@tsed/core": "7.0.0-beta.14",
|
|
28
|
+
"@tsed/di": "7.0.0-beta.14",
|
|
29
|
+
"@tsed/exceptions": "7.0.0-beta.14",
|
|
30
|
+
"@tsed/json-mapper": "7.0.0-beta.14",
|
|
31
|
+
"@tsed/schema": "7.0.0-beta.14"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@tsed/core": "^7.0.0-beta.
|
|
35
|
-
"@tsed/di": "^7.0.0-beta.
|
|
36
|
-
"@tsed/exceptions": "^7.0.0-beta.
|
|
37
|
-
"@tsed/json-mapper": "^7.0.0-beta.
|
|
38
|
-
"@tsed/schema": "^7.0.0-beta.
|
|
34
|
+
"@tsed/core": "^7.0.0-beta.14",
|
|
35
|
+
"@tsed/di": "^7.0.0-beta.14",
|
|
36
|
+
"@tsed/exceptions": "^7.0.0-beta.14",
|
|
37
|
+
"@tsed/json-mapper": "^7.0.0-beta.14",
|
|
38
|
+
"@tsed/schema": "^7.0.0-beta.14"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
41
41
|
"@tsed/core": {
|