@lark-apaas/nestjs-capability 0.1.11 → 0.1.13-alpha.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/index.cjs +79 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -1
- package/dist/index.d.ts +26 -1
- package/dist/index.js +78 -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,64 @@ 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
|
+
* Debug 调用(isDebug=true)跳过校验:开发者可能在 paramSchema 里声明了字段但表单
|
|
976
|
+
* 里并未通过 {{input.xxx}} 实际引用,此时 required 校验会误报;debug 阶段交由
|
|
977
|
+
* 插件自身的 zod schema 兜底即可。
|
|
978
|
+
*
|
|
979
|
+
* 诊断原因:
|
|
980
|
+
* not_provided — input 中完全没有该字段(key 不存在 / undefined / null),调用方未传
|
|
981
|
+
* empty_value — 调用方传了值但为空(空串/空数组),需要检查数据来源
|
|
982
|
+
*/
|
|
983
|
+
validateRequiredParams(input, paramsSchema, capabilityName, isDebug) {
|
|
984
|
+
if (isDebug) return;
|
|
985
|
+
if (!paramsSchema?.required?.length || !paramsSchema.properties) {
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
if (typeof input !== "object" || input === null) {
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
const params = input;
|
|
992
|
+
const diagnostics = [];
|
|
993
|
+
for (const fieldName of paramsSchema.required) {
|
|
994
|
+
const fieldSchema = paramsSchema.properties[fieldName];
|
|
995
|
+
if (!fieldSchema) continue;
|
|
996
|
+
const value = params[fieldName];
|
|
997
|
+
const schemaType = fieldSchema.type;
|
|
998
|
+
const desc = fieldSchema.description || fieldName;
|
|
999
|
+
if (value === void 0 || value === null) {
|
|
1000
|
+
diagnostics.push({
|
|
1001
|
+
field: fieldName,
|
|
1002
|
+
reason: "not_provided",
|
|
1003
|
+
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`
|
|
1004
|
+
});
|
|
1005
|
+
continue;
|
|
1006
|
+
}
|
|
1007
|
+
if (schemaType === "array") {
|
|
1008
|
+
if (Array.isArray(value) && value.length === 0) {
|
|
1009
|
+
diagnostics.push({
|
|
1010
|
+
field: fieldName,
|
|
1011
|
+
reason: "empty_value",
|
|
1012
|
+
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`
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
} else if (typeof value === "string" && value === "") {
|
|
1016
|
+
diagnostics.push({
|
|
1017
|
+
field: fieldName,
|
|
1018
|
+
reason: "empty_value",
|
|
1019
|
+
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`
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
if (diagnostics.length > 0) {
|
|
1024
|
+
throw new RequiredParamMissingError(capabilityName, diagnostics);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
953
1028
|
* 检查 action 是否为流式
|
|
954
1029
|
*/
|
|
955
1030
|
async checkIsStream(config, actionName) {
|
|
@@ -973,6 +1048,7 @@ var CapabilityService = class _CapabilityService {
|
|
|
973
1048
|
};
|
|
974
1049
|
let isStream = false;
|
|
975
1050
|
try {
|
|
1051
|
+
this.validateRequiredParams(input, config.paramsSchema, config.name, contextOverride?.isDebug ?? false);
|
|
976
1052
|
const { pluginInstance, resolvedParams } = await this.loadPluginAndResolveParams(config, input);
|
|
977
1053
|
if (!pluginInstance.hasAction(actionName)) {
|
|
978
1054
|
throw new ActionNotFoundError(config.pluginKey, actionName);
|
|
@@ -1033,6 +1109,7 @@ var CapabilityService = class _CapabilityService {
|
|
|
1033
1109
|
};
|
|
1034
1110
|
const chunks = [];
|
|
1035
1111
|
try {
|
|
1112
|
+
this.validateRequiredParams(input, config.paramsSchema, config.name, contextOverride?.isDebug ?? false);
|
|
1036
1113
|
const { pluginInstance, resolvedParams } = await this.loadPluginAndResolveParams(config, input);
|
|
1037
1114
|
if (!pluginInstance.hasAction(actionName)) {
|
|
1038
1115
|
throw new ActionNotFoundError(config.pluginKey, actionName);
|
|
@@ -1093,6 +1170,7 @@ var CapabilityService = class _CapabilityService {
|
|
|
1093
1170
|
};
|
|
1094
1171
|
const chunks = [];
|
|
1095
1172
|
try {
|
|
1173
|
+
this.validateRequiredParams(input, config.paramsSchema, config.name, contextOverride?.isDebug ?? false);
|
|
1096
1174
|
const { pluginInstance, resolvedParams } = await this.loadPluginAndResolveParams(config, input);
|
|
1097
1175
|
if (!pluginInstance.hasAction(actionName)) {
|
|
1098
1176
|
throw new ActionNotFoundError(config.pluginKey, actionName);
|
|
@@ -1955,6 +2033,7 @@ CapabilityModule = _ts_decorate7([
|
|
|
1955
2033
|
PluginLoadError,
|
|
1956
2034
|
PluginLoaderService,
|
|
1957
2035
|
PluginNotFoundError,
|
|
2036
|
+
RequiredParamMissingError,
|
|
1958
2037
|
TelemetryService,
|
|
1959
2038
|
TemplateEngineService,
|
|
1960
2039
|
WebhookController,
|