-
Notifications
You must be signed in to change notification settings - Fork 11
feat(): support use contract params when using useProvider with contract #4746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Walkthrough本次变更扩展了 Flow API 的参数处理能力,支持以对象(UseProviderContractConf)形式传递参数,而不仅限于数组形式。相关类型声明、参数签名、参数解析与测试均已适配。参数提取与校验逻辑得到统一和增强,支持更丰富的参数结构及扩展字段处理。 Changes
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
packages/easyops-runtime/src/flowApi/FlowApi.spec.tsOops! Something went wrong! :( ESLint: 9.29.0 Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs packages/easyops-runtime/src/flowApi/FlowApi.tsOops! Something went wrong! :( ESLint: 9.29.0 Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs packages/easyops-runtime/src/flowApi/FlowApiProvider.tsOops! Something went wrong! :( ESLint: 9.29.0 Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (9)
🚧 Files skipped from review as they are similar to previous changes (5)
🧰 Additional context used🧬 Code Graph Analysis (1)packages/runtime/src/internal/bindListeners.ts (2)
🪛 Biome (1.9.4)packages/runtime/src/internal/data/resolveData.ts[error] 74-74: Don't use 'Function' as a type. Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs. (lint/complexity/noBannedTypes) packages/easyops-runtime/src/flowApi/FlowApi.ts[error] 9-9: Do not shadow the global "hasOwnProperty" property. Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global. (lint/suspicious/noShadowRestrictedNames) ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (9)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v3 #4746 +/- ##
==========================================
+ Coverage 95.21% 95.23% +0.01%
==========================================
Files 209 209
Lines 9082 9120 +38
Branches 1743 1756 +13
==========================================
+ Hits 8647 8685 +38
+ Misses 323 322 -1
- Partials 112 113 +1
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (2)
packages/runtime/src/internal/data/resolveData.ts (1)
65-70: 优化建议:简化条件判断逻辑当前的条件判断可以更清晰地表达:
- const contractConf = - !Array.isArray(args) && - params && - hooks?.flowApi?.isFlowApiProvider(useProvider) - ? ({ params, options, filename } as UserProviderContractConf) - : null; + const isContractMode = !Array.isArray(args) && params && hooks?.flowApi?.isFlowApiProvider(useProvider); + const contractConf = isContractMode + ? ({ params, options, filename } as UserProviderContractConf) + : null;packages/easyops-runtime/src/flowApi/FlowApi.ts (1)
136-145: 验证错误消息的完整性当缺少必需参数时,错误消息可以更详细,帮助开发者定位问题:
- throw new Error(`Missing required param: "${key}"`); + throw new Error(`Missing required param: "${key}" for API "${api.namespace}.${api.name}"`);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (7)
etc/runtime.api.md(2 hunks)packages/easyops-runtime/src/flowApi/FlowApi.spec.ts(5 hunks)packages/easyops-runtime/src/flowApi/FlowApi.ts(5 hunks)packages/easyops-runtime/src/flowApi/FlowApiProvider.ts(3 hunks)packages/runtime/src/internal/Runtime.ts(2 hunks)packages/runtime/src/internal/data/resolveData.ts(5 hunks)packages/types/src/manifest.ts(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
packages/types/src/manifest.ts (1)
packages/react-runtime/src/useProvider/useProviderTypes.ts (1)
RequestInit(49-51)
packages/runtime/src/internal/Runtime.ts (1)
packages/types/src/manifest.ts (1)
UserProviderContractConf(698-707)
packages/easyops-runtime/src/flowApi/FlowApi.spec.ts (1)
packages/easyops-runtime/src/flowApi/FlowApi.ts (1)
getArgsOfFlowApi(39-60)
packages/easyops-runtime/src/flowApi/FlowApiProvider.ts (2)
packages/types/src/manifest.ts (1)
ExtField(1304-1307)packages/http/src/http.ts (1)
HttpOptions(62-62)
🪛 Biome (1.9.4)
packages/runtime/src/internal/data/resolveData.ts
[error] 74-74: Don't use 'Function' as a type.
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
(lint/complexity/noBannedTypes)
packages/easyops-runtime/src/flowApi/FlowApi.ts
[error] 9-9: Do not shadow the global "hasOwnProperty" property.
Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.
(lint/suspicious/noShadowRestrictedNames)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build (20.x)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (17)
packages/types/src/manifest.ts (3)
673-674: LGTM!接口扩展设计合理通过
extends Partial<UserProviderContractConf>的设计很好地支持了可选的契约配置,允许用户根据需要使用新的参数结构。
682-682: 优先级说明清晰注释明确说明了
args比params具有更高的优先级,这对开发者理解参数处理顺序很有帮助。
698-707: 新接口定义完整且文档清晰
UserProviderContractConf接口设计合理:
params作为必需的契约参数对象options和filename作为可选的扩展配置- JSDoc 注释清楚地说明了每个属性的用途和优先级
接口设计符合预期的契约参数支持需求。
packages/runtime/src/internal/Runtime.ts (2)
12-12: 导入语句正确正确导入了新定义的
UserProviderContractConf类型,为后续的接口更新提供了类型支持。
87-87: 方法签名更新恰当将
originalArgs参数类型从unknown[]扩展为unknown[] | UserProviderContractConf联合类型,很好地支持了向后兼容性,同时启用了新的契约参数功能。etc/runtime.api.md (2)
47-47: API 导入声明一致在 API 报告中正确添加了
UserProviderContractConf类型导入,与运行时实现保持一致。
496-496: API 签名更新一致
getArgsOfFlowApi方法的参数类型更新与packages/runtime/src/internal/Runtime.ts中的实现完全一致,确保了 API 报告的准确性。packages/easyops-runtime/src/flowApi/FlowApi.spec.ts (4)
54-54: 测试契约模拟数据设计合理新增的三个契约模拟数据很好地覆盖了不同的测试场景:
TestPost:基本的 POST 请求契约TestPostWithExtFieldsQuery:包含查询参数扩展字段的契约TestPostWithExtFieldsBody:包含请求体扩展字段的契约契约结构完整,包含了必要的 endpoint、request 和 namespace 配置。
Also applies to: 110-190
219-237: 对象参数支持测试完整测试用例验证了使用对象形式的参数(
{ params: {} })调用getArgsOfFlowApi的功能,确保新的契约参数结构能够正确处理。期望的返回值包含了正确的 request 配置和空的参数对象。
266-291: 文件下载场景测试充分测试用例验证了在
saveAs方法中使用契约参数对象的功能,包含filename属性的传递。这确保了文件下载场景下新参数结构的正确性。
354-450: 扩展字段处理测试全面三个新的测试用例很好地验证了扩展字段的不同处理方式:
- 基本 POST 请求的参数提取和 URL 构建
- 查询参数扩展字段的处理(
source: "query")- 请求体扩展字段的处理(
source: "body")测试覆盖了 URI 参数替换、扩展字段提取和最终参数构造的完整流程。
packages/easyops-runtime/src/flowApi/FlowApiProvider.ts (5)
24-26: 可选参数处理改进使用可选链操作符
ext_fields?.some()正确处理了可选的ext_fields参数,避免了在参数为undefined时的运行时错误,提高了代码的健壮性。
29-29: 函数签名更新恰当将
ext_fields参数类型从ExtField[]更新为ExtField[] | undefined,与实际使用场景更加匹配,支持了不包含扩展字段的契约。
35-35: 一致的可选链使用在
hasBodyParams的计算中也使用了可选链,与hasQueryParams的处理方式保持一致,确保了代码风格的统一性。
37-39: 重要的兼容性说明添加的注释清楚地说明了参数顺序与生成的 SDK 不同的情况,这对维护向后兼容性很重要。注释有助于开发者理解为什么保持当前的参数顺序。
126-126: 逻辑简化合理移除了
ext_fields的默认值,并简化了noParams的计算逻辑。这些改进使代码更加简洁,同时保持了原有的功能逻辑。使用可选链和空值合并操作符提高了代码的可读性。Also applies to: 143-146
packages/easyops-runtime/src/flowApi/FlowApi.ts (1)
78-87: 正确处理了 saveAs 方法的特殊逻辑代码很好地处理了数组和对象两种参数形式下的文件名提取,保持了向后兼容性。
next-core
|
||||||||||||||||||||||||||||
| Project |
next-core
|
| Branch Review |
steve/v3-use-provider-params
|
| Run status |
|
| Run duration | 00m 27s |
| Commit |
|
| Committer | Shenwei Wang |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
17
|
| View all changes introduced in this branch ↗︎ | |
f29d4ba to
e396b04
Compare
|
|
||
| export interface UseProviderContractConf { | ||
| /** 根据契约定义的参数对象。优先级低于 `args`。*/ | ||
| params: Record<string, unknown>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
由于 AI 生成编排时不容易理解前台的参数构造规则,现支持直接按契约定义的 request 结构传递 params
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enables passing contract-based parameters (params, options, filename) when using useProvider and integrates them into the runtime resolution and event binding flows.
- Introduces
UseProviderContractConfand extendsUseProviderResolveConf/UseProviderEventHandlerin types to allow object-based contract params. - Updates
resolveDataandbindListenersto detect and compute contract configs and route them through the flow API. - Enhances Flow API modules (
FlowApiProvider.ts,FlowApi.ts) to acceptUseProviderContractConfand adjust URI/args transformation.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/types/src/manifest.ts | Added UseProviderContractConf and extended resolve/event interfaces. |
| packages/runtime/src/internal/data/resolveData.ts | Enhanced resolveData to detect and apply contract params. |
| packages/runtime/src/internal/bindListeners.ts | Updated listener binding to support contract params via getArgsOfFlowApi. |
| packages/easyops-runtime/src/flowApi/FlowApiProvider.ts | Made ext_fields handling null-safe. |
| packages/easyops-runtime/src/flowApi/FlowApi.ts | Refactored getArgsOfFlowApi and URI/args transformations. |
| packages/easyops-runtime/src/flowApi/FlowApi.spec.ts | Added tests for contract-based params, filename, and missing parameter error. |
| etc/runtime.api.md | Updated API docs to reflect new UseProviderContractConf overload. |
Comments suppressed due to low confidence (2)
packages/runtime/src/internal/data/resolveData.ts:34
- [nitpick] Consider renaming the parameter
resolveOptions(e.g., toruntimeOptions) to avoid confusion with theoptionsfield inUseProviderContractConf.
) {
packages/runtime/src/internal/data/resolveData.ts:34
- There are no unit tests covering the new
UseProviderContractConfpath inresolveData. Add tests to validate that contract-based parameters (params,options,filename) are passed correctly through this method.
) {
依赖检查
组件之间的依赖声明,是微服务组件架构下的重要信息,请确保其正确性。
请勾选以下两组选项其中之一:
或者:
提交信息检查
Git 提交信息将决定包的版本发布及自动生成的 CHANGELOG,请检查工作内容与提交信息是否相符,并在以下每组选项中都依次确认。
破坏性变更:
feat作为提交类型。BREAKING CHANGE: 你的变更说明。新特性:
feat作为提交类型。问题修复:
fix作为提交类型。杂项工作:
即所有对下游使用者无任何影响、且没有必要显示在 CHANGELOG 中的改动,例如修改注释、测试用例、开发文档等:
chore,docs,test等作为提交类型。Summary by CodeRabbit
新功能
修复与优化
测试
文档