@faapi/faapi 6.18.1 → 6.19.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.
- package/dist/cli/index.js +29 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +29 -2
- package/dist/index.js.map +1 -1
- package/dist/{routeTypes-BAhPIzcG.d.ts → routeTypes-DTqdo28V.d.ts} +8 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +29 -2
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
|
@@ -930,7 +930,14 @@ interface FaapiContext {
|
|
|
930
930
|
*/
|
|
931
931
|
log: Logger;
|
|
932
932
|
request: Request;
|
|
933
|
-
|
|
933
|
+
/**
|
|
934
|
+
* 动态路由参数
|
|
935
|
+
*
|
|
936
|
+
* handler 声明了 `params: XxxParams` 类型时,管线按声明类型校验并回写
|
|
937
|
+
* 转换后的值(number/boolean 字段不再是字符串);未声明时保持 URL 原始
|
|
938
|
+
* 字符串。以 handler 形参上的接口声明为准读取(注入即本对象)。
|
|
939
|
+
*/
|
|
940
|
+
params: Record<string, string | number | boolean>;
|
|
934
941
|
query: URLSearchParams;
|
|
935
942
|
headers: Headers;
|
|
936
943
|
method: string;
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as FaapiContext, F as FaapiMiddleware, I as InjectorMap, R as RouteManifest, W as WsRouteManifest, C as CorsOptions, H as HelmetOptions } from './routeTypes-
|
|
1
|
+
import { a as FaapiContext, F as FaapiMiddleware, I as InjectorMap, R as RouteManifest, W as WsRouteManifest, C as CorsOptions, H as HelmetOptions } from './routeTypes-DTqdo28V.js';
|
|
2
2
|
import { Server } from 'node:http';
|
|
3
3
|
import { WebSocket } from 'ws';
|
|
4
4
|
|
package/dist/testing.js
CHANGED
|
@@ -1108,8 +1108,10 @@ function getAgentHandle(ctx) {
|
|
|
1108
1108
|
// src/injection/injectParams.ts
|
|
1109
1109
|
function getBuiltinInjectionValue(type, ctx, body) {
|
|
1110
1110
|
switch (type) {
|
|
1111
|
-
case "query":
|
|
1112
|
-
|
|
1111
|
+
case "query": {
|
|
1112
|
+
const validated = ctx.__validatedQuery;
|
|
1113
|
+
return validated ?? queryToObject(ctx.query);
|
|
1114
|
+
}
|
|
1113
1115
|
case "params":
|
|
1114
1116
|
return ctx.params;
|
|
1115
1117
|
case "headers":
|
|
@@ -2663,6 +2665,15 @@ function collectRouteSchemaSources(routes, rootDir) {
|
|
|
2663
2665
|
typeInfo,
|
|
2664
2666
|
coerce: isForm || void 0
|
|
2665
2667
|
});
|
|
2668
|
+
const paramsArg = meta.params.find((p) => p.type === "params");
|
|
2669
|
+
if (paramsArg?.typeName) {
|
|
2670
|
+
sources.push({
|
|
2671
|
+
urlPath: entry.urlPath,
|
|
2672
|
+
filePath,
|
|
2673
|
+
schemaName: getSchemaName(method, "params"),
|
|
2674
|
+
typeInfo: resolver.resolve(paramsArg.typeName) ?? null
|
|
2675
|
+
});
|
|
2676
|
+
}
|
|
2666
2677
|
}
|
|
2667
2678
|
}
|
|
2668
2679
|
return { sources, resolversByFile };
|
|
@@ -4962,6 +4973,22 @@ function createRoutePipeline(opts) {
|
|
|
4962
4973
|
if (!result.valid) {
|
|
4963
4974
|
throw new ValidationError("\u53C2\u6570\u6821\u9A8C\u5931\u8D25", result.issues);
|
|
4964
4975
|
}
|
|
4976
|
+
if (inputType === "query" && result.data !== input && typeof result.data === "object" && result.data !== null) {
|
|
4977
|
+
ctx.__validatedQuery = {
|
|
4978
|
+
...input,
|
|
4979
|
+
...result.data
|
|
4980
|
+
};
|
|
4981
|
+
}
|
|
4982
|
+
const paramsResult = await validateInput(schemaPath, route.method, "params", match.params);
|
|
4983
|
+
if (!paramsResult.valid) {
|
|
4984
|
+
throw new ValidationError("\u53C2\u6570\u6821\u9A8C\u5931\u8D25", paramsResult.issues);
|
|
4985
|
+
}
|
|
4986
|
+
if (paramsResult.data !== match.params) {
|
|
4987
|
+
ctx.params = typeof paramsResult.data === "object" && paramsResult.data !== null ? {
|
|
4988
|
+
...match.params,
|
|
4989
|
+
...paramsResult.data
|
|
4990
|
+
} : match.params;
|
|
4991
|
+
}
|
|
4965
4992
|
const body = inputType === "query" && hasBody(route.method) ? await resolveBodyForQueryMethod(request) : hasBody(route.method) ? result.data : void 0;
|
|
4966
4993
|
if (route.middlewares === void 0 && route.injectors === void 0 && route.middlewarePaths) {
|
|
4967
4994
|
await ensureMiddlewaresCompiled(route.middlewarePaths, rootDir);
|