@lark-apaas/nestjs-capability 0.1.11 → 0.1.12
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/index.cjs +74 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -40,6 +40,7 @@ __export(index_exports, {
|
|
|
40
40
|
PluginLoadError: () => PluginLoadError,
|
|
41
41
|
PluginLoaderService: () => PluginLoaderService,
|
|
42
42
|
PluginNotFoundError: () => PluginNotFoundError,
|
|
43
|
+
RequiredParamMissingError: () => RequiredParamMissingError,
|
|
43
44
|
TelemetryService: () => TelemetryService,
|
|
44
45
|
TemplateEngineService: () => TemplateEngineService,
|
|
45
46
|
WebhookController: () => WebhookController,
|
|
@@ -718,6 +719,22 @@ var ActionNotFoundError = class extends Error {
|
|
|
718
719
|
this.actionName = actionName;
|
|
719
720
|
}
|
|
720
721
|
};
|
|
722
|
+
var RequiredParamMissingError = class extends Error {
|
|
723
|
+
static {
|
|
724
|
+
__name(this, "RequiredParamMissingError");
|
|
725
|
+
}
|
|
726
|
+
capabilityName;
|
|
727
|
+
diagnostics;
|
|
728
|
+
constructor(capabilityName, diagnostics) {
|
|
729
|
+
const lines = diagnostics.map((d) => ` - ${d.field}: ${d.detail}`).join("\n");
|
|
730
|
+
super(`\u300C${capabilityName}\u300D\u63D2\u4EF6\u8C03\u7528\u5931\u8D25\uFF0C\u4EE5\u4E0B\u5FC5\u586B\u53C2\u6570\u65E0\u6548:
|
|
731
|
+
${lines}
|
|
732
|
+
\u8BF7\u68C0\u67E5\u8C03\u7528\u4EE3\u7801\u4E2D capabilityClient.load(id).call(action, input) \u7684 input \u5BF9\u8C61\uFF0C\u786E\u8BA4\u4E0A\u8FF0\u53C2\u6570\u5DF2\u6B63\u786E\u4F20\u503C\u4E14\u672A\u5728\u4F20\u9012\u94FE\u8DEF\u4E2D\u4E22\u5931\u3002`);
|
|
733
|
+
this.name = "RequiredParamMissingError";
|
|
734
|
+
this.capabilityName = capabilityName;
|
|
735
|
+
this.diagnostics = diagnostics;
|
|
736
|
+
}
|
|
737
|
+
};
|
|
721
738
|
var CapabilityService = class _CapabilityService {
|
|
722
739
|
static {
|
|
723
740
|
__name(this, "CapabilityService");
|
|
@@ -950,6 +967,59 @@ var CapabilityService = class _CapabilityService {
|
|
|
950
967
|
};
|
|
951
968
|
}
|
|
952
969
|
/**
|
|
970
|
+
* 校验调用方传入的 input 是否满足 paramsSchema.required 约束。
|
|
971
|
+
*
|
|
972
|
+
* 注意:校验发生在模板替换之前。paramsSchema.required 声明的是调用方需要传哪些变量
|
|
973
|
+
* (它们会被 formValue 中的 {{input.xxx}} 引用),不是 resolve 后的 formValue key。
|
|
974
|
+
*
|
|
975
|
+
* 诊断原因:
|
|
976
|
+
* not_provided — input 中完全没有该字段(key 不存在 / undefined / null),调用方未传
|
|
977
|
+
* empty_value — 调用方传了值但为空(空串/空数组),需要检查数据来源
|
|
978
|
+
*/
|
|
979
|
+
validateRequiredParams(input, paramsSchema, capabilityName) {
|
|
980
|
+
if (!paramsSchema?.required?.length || !paramsSchema.properties) {
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
if (typeof input !== "object" || input === null) {
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
const params = input;
|
|
987
|
+
const diagnostics = [];
|
|
988
|
+
for (const fieldName of paramsSchema.required) {
|
|
989
|
+
const fieldSchema = paramsSchema.properties[fieldName];
|
|
990
|
+
if (!fieldSchema) continue;
|
|
991
|
+
const value = params[fieldName];
|
|
992
|
+
const schemaType = fieldSchema.type;
|
|
993
|
+
const desc = fieldSchema.description || fieldName;
|
|
994
|
+
if (value === void 0 || value === null) {
|
|
995
|
+
diagnostics.push({
|
|
996
|
+
field: fieldName,
|
|
997
|
+
reason: "not_provided",
|
|
998
|
+
detail: `\u300C${desc}\u300D\u672A\u4F20\u503C\uFF0C\u8C03\u7528\u65B9\u7684 input \u4E2D\u7F3A\u5C11\u300C${fieldName}\u300D\u5B57\u6BB5\u3002\u8BF7\u68C0\u67E5 capabilityClient.load(id).call(action, { ... }) \u4E2D\u662F\u5426\u4F20\u5165\u4E86\u8BE5\u53C2\u6570\uFF0C\u4EE5\u53CA\u6570\u636E\u5728\u7EC4\u4EF6\u4F20\u9012\u94FE\u8DEF\u4E2D\u662F\u5426\u4E22\u5931\uFF08\u5982 state \u672A\u66F4\u65B0\u3001props \u672A\u900F\u4F20\u7B49\uFF09\u3002`
|
|
999
|
+
});
|
|
1000
|
+
continue;
|
|
1001
|
+
}
|
|
1002
|
+
if (schemaType === "array") {
|
|
1003
|
+
if (Array.isArray(value) && value.length === 0) {
|
|
1004
|
+
diagnostics.push({
|
|
1005
|
+
field: fieldName,
|
|
1006
|
+
reason: "empty_value",
|
|
1007
|
+
detail: `\u300C${desc}\u300D\u4F20\u5165\u4E86\u7A7A\u6570\u7EC4 []\uFF0C\u8BE5\u5B57\u6BB5\u4E3A\u5FC5\u586B\u3002\u8BF7\u786E\u8BA4\u6570\u636E\u6765\u6E90\u662F\u5426\u6B63\u786E\uFF0C\u4F8B\u5982\uFF1A\u5217\u8868\u63A5\u53E3\u662F\u5426\u8FD4\u56DE\u4E86\u6570\u636E\u3001\u6587\u4EF6/\u56FE\u7247\u662F\u5426\u5DF2\u6210\u529F\u4E0A\u4F20\u3002`
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
} else if (typeof value === "string" && value === "") {
|
|
1011
|
+
diagnostics.push({
|
|
1012
|
+
field: fieldName,
|
|
1013
|
+
reason: "empty_value",
|
|
1014
|
+
detail: `\u300C${desc}\u300D\u4F20\u5165\u4E86\u7A7A\u5B57\u7B26\u4E32\uFF0C\u8BE5\u5B57\u6BB5\u4E3A\u5FC5\u586B\u3002\u8BF7\u786E\u8BA4\u6570\u636E\u6765\u6E90\u662F\u5426\u6B63\u786E\uFF0C\u4F8B\u5982\uFF1A\u8868\u5355\u5B57\u6BB5\u662F\u5426\u5DF2\u586B\u5199\u3001\u53D8\u91CF\u662F\u5426\u5DF2\u8D4B\u503C\u3002`
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
if (diagnostics.length > 0) {
|
|
1019
|
+
throw new RequiredParamMissingError(capabilityName, diagnostics);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
953
1023
|
* 检查 action 是否为流式
|
|
954
1024
|
*/
|
|
955
1025
|
async checkIsStream(config, actionName) {
|
|
@@ -973,6 +1043,7 @@ var CapabilityService = class _CapabilityService {
|
|
|
973
1043
|
};
|
|
974
1044
|
let isStream = false;
|
|
975
1045
|
try {
|
|
1046
|
+
this.validateRequiredParams(input, config.paramsSchema, config.name);
|
|
976
1047
|
const { pluginInstance, resolvedParams } = await this.loadPluginAndResolveParams(config, input);
|
|
977
1048
|
if (!pluginInstance.hasAction(actionName)) {
|
|
978
1049
|
throw new ActionNotFoundError(config.pluginKey, actionName);
|
|
@@ -1033,6 +1104,7 @@ var CapabilityService = class _CapabilityService {
|
|
|
1033
1104
|
};
|
|
1034
1105
|
const chunks = [];
|
|
1035
1106
|
try {
|
|
1107
|
+
this.validateRequiredParams(input, config.paramsSchema, config.name);
|
|
1036
1108
|
const { pluginInstance, resolvedParams } = await this.loadPluginAndResolveParams(config, input);
|
|
1037
1109
|
if (!pluginInstance.hasAction(actionName)) {
|
|
1038
1110
|
throw new ActionNotFoundError(config.pluginKey, actionName);
|
|
@@ -1093,6 +1165,7 @@ var CapabilityService = class _CapabilityService {
|
|
|
1093
1165
|
};
|
|
1094
1166
|
const chunks = [];
|
|
1095
1167
|
try {
|
|
1168
|
+
this.validateRequiredParams(input, config.paramsSchema, config.name);
|
|
1096
1169
|
const { pluginInstance, resolvedParams } = await this.loadPluginAndResolveParams(config, input);
|
|
1097
1170
|
if (!pluginInstance.hasAction(actionName)) {
|
|
1098
1171
|
throw new ActionNotFoundError(config.pluginKey, actionName);
|
|
@@ -1955,6 +2028,7 @@ CapabilityModule = _ts_decorate7([
|
|
|
1955
2028
|
PluginLoadError,
|
|
1956
2029
|
PluginLoaderService,
|
|
1957
2030
|
PluginNotFoundError,
|
|
2031
|
+
RequiredParamMissingError,
|
|
1958
2032
|
TelemetryService,
|
|
1959
2033
|
TemplateEngineService,
|
|
1960
2034
|
WebhookController,
|