@lark-apaas/nestjs-capability 0.1.10 → 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.d.cts CHANGED
@@ -403,6 +403,16 @@ declare class ActionNotFoundError extends Error {
403
403
  readonly actionName: string;
404
404
  constructor(pluginKey: string, actionName: string);
405
405
  }
406
+ interface ParamDiagnostic {
407
+ field: string;
408
+ reason: 'not_provided' | 'empty_value';
409
+ detail: string;
410
+ }
411
+ declare class RequiredParamMissingError extends Error {
412
+ readonly capabilityName: string;
413
+ readonly diagnostics: ParamDiagnostic[];
414
+ constructor(capabilityName: string, diagnostics: ParamDiagnostic[]);
415
+ }
406
416
  interface CapabilityExecutor {
407
417
  /**
408
418
  * 调用 capability(始终返回 Promise)
@@ -499,6 +509,17 @@ declare class CapabilityService implements OnModuleInit, OnModuleDestroy {
499
509
  * 根据 manifest 的 form.refType 决定 formValue 的消费方式
500
510
  */
501
511
  private loadPluginAndResolveParams;
512
+ /**
513
+ * 校验调用方传入的 input 是否满足 paramsSchema.required 约束。
514
+ *
515
+ * 注意:校验发生在模板替换之前。paramsSchema.required 声明的是调用方需要传哪些变量
516
+ * (它们会被 formValue 中的 {{input.xxx}} 引用),不是 resolve 后的 formValue key。
517
+ *
518
+ * 诊断原因:
519
+ * not_provided — input 中完全没有该字段(key 不存在 / undefined / null),调用方未传
520
+ * empty_value — 调用方传了值但为空(空串/空数组),需要检查数据来源
521
+ */
522
+ private validateRequiredParams;
502
523
  /**
503
524
  * 检查 action 是否为流式
504
525
  */
@@ -661,4 +682,4 @@ interface MigrationResponse {
661
682
  */
662
683
  declare function migrationAdaptor(promise: Promise<unknown>): Promise<MigrationResponse>;
663
684
 
664
- export { ActionNotFoundError, type ActionSchema, type CallEventDetails, type CallerType, type CapabilityConfig, type CapabilityExecutor, type CapabilityListItem, CapabilityModule, type CapabilityModuleOptions, CapabilityNotFoundError, CapabilityService, DebugController, type DebugExecuteResponseData, type DebugInfo, type ErrorCode, ErrorCodes, type ErrorResponse, type EventType, type ExecuteResponseData, type FailureOutput, type JSONSchema, type ListResponseData, type MigrationResponse, type PluginActionContext, type PluginInstance, PluginLoadError, PluginLoaderService, type PluginManifest, PluginNotFoundError, type PluginPackage, type ResourceEvent, type StreamContentResponse, type StreamDoneMetadata, type StreamError, type StreamErrorResponse, type StreamEvent, type StreamResponse, type SuccessResponse, TelemetryService, TemplateEngineService, type UserContext, WebhookController, migrationAdaptor };
685
+ export { ActionNotFoundError, type ActionSchema, type CallEventDetails, type CallerType, type CapabilityConfig, type CapabilityExecutor, type CapabilityListItem, CapabilityModule, type CapabilityModuleOptions, CapabilityNotFoundError, CapabilityService, DebugController, type DebugExecuteResponseData, type DebugInfo, type ErrorCode, ErrorCodes, type ErrorResponse, type EventType, type ExecuteResponseData, type FailureOutput, type JSONSchema, type ListResponseData, type MigrationResponse, type ParamDiagnostic, type PluginActionContext, type PluginInstance, PluginLoadError, PluginLoaderService, type PluginManifest, PluginNotFoundError, type PluginPackage, RequiredParamMissingError, type ResourceEvent, type StreamContentResponse, type StreamDoneMetadata, type StreamError, type StreamErrorResponse, type StreamEvent, type StreamResponse, type SuccessResponse, TelemetryService, TemplateEngineService, type UserContext, WebhookController, migrationAdaptor };
package/dist/index.d.ts CHANGED
@@ -403,6 +403,16 @@ declare class ActionNotFoundError extends Error {
403
403
  readonly actionName: string;
404
404
  constructor(pluginKey: string, actionName: string);
405
405
  }
406
+ interface ParamDiagnostic {
407
+ field: string;
408
+ reason: 'not_provided' | 'empty_value';
409
+ detail: string;
410
+ }
411
+ declare class RequiredParamMissingError extends Error {
412
+ readonly capabilityName: string;
413
+ readonly diagnostics: ParamDiagnostic[];
414
+ constructor(capabilityName: string, diagnostics: ParamDiagnostic[]);
415
+ }
406
416
  interface CapabilityExecutor {
407
417
  /**
408
418
  * 调用 capability(始终返回 Promise)
@@ -499,6 +509,17 @@ declare class CapabilityService implements OnModuleInit, OnModuleDestroy {
499
509
  * 根据 manifest 的 form.refType 决定 formValue 的消费方式
500
510
  */
501
511
  private loadPluginAndResolveParams;
512
+ /**
513
+ * 校验调用方传入的 input 是否满足 paramsSchema.required 约束。
514
+ *
515
+ * 注意:校验发生在模板替换之前。paramsSchema.required 声明的是调用方需要传哪些变量
516
+ * (它们会被 formValue 中的 {{input.xxx}} 引用),不是 resolve 后的 formValue key。
517
+ *
518
+ * 诊断原因:
519
+ * not_provided — input 中完全没有该字段(key 不存在 / undefined / null),调用方未传
520
+ * empty_value — 调用方传了值但为空(空串/空数组),需要检查数据来源
521
+ */
522
+ private validateRequiredParams;
502
523
  /**
503
524
  * 检查 action 是否为流式
504
525
  */
@@ -661,4 +682,4 @@ interface MigrationResponse {
661
682
  */
662
683
  declare function migrationAdaptor(promise: Promise<unknown>): Promise<MigrationResponse>;
663
684
 
664
- export { ActionNotFoundError, type ActionSchema, type CallEventDetails, type CallerType, type CapabilityConfig, type CapabilityExecutor, type CapabilityListItem, CapabilityModule, type CapabilityModuleOptions, CapabilityNotFoundError, CapabilityService, DebugController, type DebugExecuteResponseData, type DebugInfo, type ErrorCode, ErrorCodes, type ErrorResponse, type EventType, type ExecuteResponseData, type FailureOutput, type JSONSchema, type ListResponseData, type MigrationResponse, type PluginActionContext, type PluginInstance, PluginLoadError, PluginLoaderService, type PluginManifest, PluginNotFoundError, type PluginPackage, type ResourceEvent, type StreamContentResponse, type StreamDoneMetadata, type StreamError, type StreamErrorResponse, type StreamEvent, type StreamResponse, type SuccessResponse, TelemetryService, TemplateEngineService, type UserContext, WebhookController, migrationAdaptor };
685
+ export { ActionNotFoundError, type ActionSchema, type CallEventDetails, type CallerType, type CapabilityConfig, type CapabilityExecutor, type CapabilityListItem, CapabilityModule, type CapabilityModuleOptions, CapabilityNotFoundError, CapabilityService, DebugController, type DebugExecuteResponseData, type DebugInfo, type ErrorCode, ErrorCodes, type ErrorResponse, type EventType, type ExecuteResponseData, type FailureOutput, type JSONSchema, type ListResponseData, type MigrationResponse, type ParamDiagnostic, type PluginActionContext, type PluginInstance, PluginLoadError, PluginLoaderService, type PluginManifest, PluginNotFoundError, type PluginPackage, RequiredParamMissingError, type ResourceEvent, type StreamContentResponse, type StreamDoneMetadata, type StreamError, type StreamErrorResponse, type StreamEvent, type StreamResponse, type SuccessResponse, TelemetryService, TemplateEngineService, type UserContext, WebhookController, migrationAdaptor };
package/dist/index.js CHANGED
@@ -668,6 +668,22 @@ var ActionNotFoundError = class extends Error {
668
668
  this.actionName = actionName;
669
669
  }
670
670
  };
671
+ var RequiredParamMissingError = class extends Error {
672
+ static {
673
+ __name(this, "RequiredParamMissingError");
674
+ }
675
+ capabilityName;
676
+ diagnostics;
677
+ constructor(capabilityName, diagnostics) {
678
+ const lines = diagnostics.map((d) => ` - ${d.field}: ${d.detail}`).join("\n");
679
+ super(`\u300C${capabilityName}\u300D\u63D2\u4EF6\u8C03\u7528\u5931\u8D25\uFF0C\u4EE5\u4E0B\u5FC5\u586B\u53C2\u6570\u65E0\u6548:
680
+ ${lines}
681
+ \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`);
682
+ this.name = "RequiredParamMissingError";
683
+ this.capabilityName = capabilityName;
684
+ this.diagnostics = diagnostics;
685
+ }
686
+ };
671
687
  var CapabilityService = class _CapabilityService {
672
688
  static {
673
689
  __name(this, "CapabilityService");
@@ -900,6 +916,59 @@ var CapabilityService = class _CapabilityService {
900
916
  };
901
917
  }
902
918
  /**
919
+ * 校验调用方传入的 input 是否满足 paramsSchema.required 约束。
920
+ *
921
+ * 注意:校验发生在模板替换之前。paramsSchema.required 声明的是调用方需要传哪些变量
922
+ * (它们会被 formValue 中的 {{input.xxx}} 引用),不是 resolve 后的 formValue key。
923
+ *
924
+ * 诊断原因:
925
+ * not_provided — input 中完全没有该字段(key 不存在 / undefined / null),调用方未传
926
+ * empty_value — 调用方传了值但为空(空串/空数组),需要检查数据来源
927
+ */
928
+ validateRequiredParams(input, paramsSchema, capabilityName) {
929
+ if (!paramsSchema?.required?.length || !paramsSchema.properties) {
930
+ return;
931
+ }
932
+ if (typeof input !== "object" || input === null) {
933
+ return;
934
+ }
935
+ const params = input;
936
+ const diagnostics = [];
937
+ for (const fieldName of paramsSchema.required) {
938
+ const fieldSchema = paramsSchema.properties[fieldName];
939
+ if (!fieldSchema) continue;
940
+ const value = params[fieldName];
941
+ const schemaType = fieldSchema.type;
942
+ const desc = fieldSchema.description || fieldName;
943
+ if (value === void 0 || value === null) {
944
+ diagnostics.push({
945
+ field: fieldName,
946
+ reason: "not_provided",
947
+ 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`
948
+ });
949
+ continue;
950
+ }
951
+ if (schemaType === "array") {
952
+ if (Array.isArray(value) && value.length === 0) {
953
+ diagnostics.push({
954
+ field: fieldName,
955
+ reason: "empty_value",
956
+ 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`
957
+ });
958
+ }
959
+ } else if (typeof value === "string" && value === "") {
960
+ diagnostics.push({
961
+ field: fieldName,
962
+ reason: "empty_value",
963
+ 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`
964
+ });
965
+ }
966
+ }
967
+ if (diagnostics.length > 0) {
968
+ throw new RequiredParamMissingError(capabilityName, diagnostics);
969
+ }
970
+ }
971
+ /**
903
972
  * 检查 action 是否为流式
904
973
  */
905
974
  async checkIsStream(config, actionName) {
@@ -923,6 +992,7 @@ var CapabilityService = class _CapabilityService {
923
992
  };
924
993
  let isStream = false;
925
994
  try {
995
+ this.validateRequiredParams(input, config.paramsSchema, config.name);
926
996
  const { pluginInstance, resolvedParams } = await this.loadPluginAndResolveParams(config, input);
927
997
  if (!pluginInstance.hasAction(actionName)) {
928
998
  throw new ActionNotFoundError(config.pluginKey, actionName);
@@ -983,6 +1053,7 @@ var CapabilityService = class _CapabilityService {
983
1053
  };
984
1054
  const chunks = [];
985
1055
  try {
1056
+ this.validateRequiredParams(input, config.paramsSchema, config.name);
986
1057
  const { pluginInstance, resolvedParams } = await this.loadPluginAndResolveParams(config, input);
987
1058
  if (!pluginInstance.hasAction(actionName)) {
988
1059
  throw new ActionNotFoundError(config.pluginKey, actionName);
@@ -1043,6 +1114,7 @@ var CapabilityService = class _CapabilityService {
1043
1114
  };
1044
1115
  const chunks = [];
1045
1116
  try {
1117
+ this.validateRequiredParams(input, config.paramsSchema, config.name);
1046
1118
  const { pluginInstance, resolvedParams } = await this.loadPluginAndResolveParams(config, input);
1047
1119
  if (!pluginInstance.hasAction(actionName)) {
1048
1120
  throw new ActionNotFoundError(config.pluginKey, actionName);
@@ -1904,6 +1976,7 @@ export {
1904
1976
  PluginLoadError,
1905
1977
  PluginLoaderService,
1906
1978
  PluginNotFoundError,
1979
+ RequiredParamMissingError,
1907
1980
  TelemetryService,
1908
1981
  TemplateEngineService,
1909
1982
  WebhookController,