-
Notifications
You must be signed in to change notification settings - Fork 11
feat(): support some legacy transform functions #4679
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
此次更改主要围绕“legacy”属性转换逻辑的实现与重构。新增了 `legacy_transform.ts` 文件,集中实现了向后兼容的属性转换相关函数,包括 `legacyDoTransform`、`legacyTransformProperties` 和 `legacyTransformIntermediateData`,并提供了详细的类型定义。同时,相关接口及类型在 `getV2RuntimeFromDll.ts` 中进行了声明扩展。原本在 `secret_internals.ts` 内部实现的 `legacyDoTransform` 被移除,改为从新模块导出。新增了完整的单元测试文件 `legacy_transform.spec.ts`,覆盖各类转换场景。除此之外,还对 `evaluate` 函数增加了对全局 `CTX.DS` 的访问支持,并在 `DataStore` 类中新增了 `has` 方法用于检测数据项是否存在。
## Changes
| 文件/分组 | 变更摘要 |
|-------------------------------------------------------------------|--------------------------------------------------------------------------------------------------|
| packages/runtime/src/getV2RuntimeFromDll.ts | `Kit` 接口新增 `transformProperties` 方法,新增并导出 `LegacyGeneralTransform`、`LegacyTransformMap`、`LegacyTransformItem` 类型定义。|
| packages/runtime/src/internal/legacy_transform.ts | 新增文件,实现 `legacyDoTransform`、`legacyTransformProperties`、`legacyTransformIntermediateData`,集中 legacy 属性转换逻辑。|
| packages/runtime/src/internal/legacy_transform.spec.ts | 新增测试文件,针对 legacy 属性转换函数进行全面单元测试,涵盖多种输入、映射与错误场景。 |
| packages/runtime/src/internal/secret_internals.ts | 移除本地 `legacyDoTransform` 实现,改为从 `legacy_transform.ts` 重新导出 `legacyDoTransform`、`legacyTransformProperties` 和 `legacyTransformIntermediateData`。|
| packages/runtime/src/internal/compute/evaluate.ts | 修改 `lowLevelEvaluate` 中对全局变量 `CTX` 的代理,支持从运行时上下文访问全局 `DS`,并调整代理的 `ownKeys` 处理逻辑。|
| packages/runtime/src/internal/compute/evaluate.spec.ts | 新增针对访问全局 `CTX.DS` 的测试,验证访问不存在的属性抛错及模拟返回值的正确性。 |
| packages/runtime/src/internal/data/DataStore.ts | 新增 `DataStore` 类的 `has(name: string): boolean` 方法,用于判断指定名称的数据是否存在。 |
| etc/runtime.api.md | 移除并重新添加 `legacyDoTransform`,新增导出 `legacyTransformProperties` 和 `legacyTransformIntermediateData`,新增相关类型声明。|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/runtime/src/internal/compute/evaluate.spec.tsOops! Something went wrong! :( ESLint: 9.22.0 Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs packages/runtime/src/getV2RuntimeFromDll.tsOops! Something went wrong! :( ESLint: 9.22.0 Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs packages/runtime/src/internal/compute/evaluate.tsOops! Something went wrong! :( ESLint: 9.22.0 Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (8)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (5)
🧰 Additional context used🧬 Code Graph Analysis (2)packages/runtime/src/internal/compute/evaluate.spec.ts (2)
packages/runtime/src/internal/compute/evaluate.ts (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
🔇 Additional comments (6)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 (
|
88542f8 to
6f0c2ef
Compare
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: 0
🧹 Nitpick comments (1)
packages/runtime/src/internal/legacy_transform.ts (1)
120-127: 需要明确处理 "auto" 映射模式当前代码仅对
true/false做了明确的布尔判断,"auto"值走默认路径,相当于"不改动"。为了增强代码的可读性和明确性,建议显式处理"auto"情况。请考虑添加明确的
"auto"处理逻辑:if (!isArray && mapArray === true) { isArray = true; fromData = [fromData]; } else if (isArray && mapArray === false) { isArray = false; +} else if (!isArray && mapArray === "auto") { + // 保持不变 +} else if (isArray && mapArray === "auto") { + // 保持映射 }请确认
"auto"的预期行为是否为"数组时才映射"。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
etc/runtime.api.md(2 hunks)packages/runtime/src/getV2RuntimeFromDll.ts(2 hunks)packages/runtime/src/internal/legacy_transform.spec.ts(1 hunks)packages/runtime/src/internal/legacy_transform.ts(1 hunks)packages/runtime/src/internal/secret_internals.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/runtime/src/internal/secret_internals.ts
- packages/runtime/src/internal/legacy_transform.spec.ts
- packages/runtime/src/getV2RuntimeFromDll.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: build (20.x)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (9)
packages/runtime/src/internal/legacy_transform.ts (6)
1-9: 导入依赖项和类型定义清晰明确导入依赖和类型定义结构良好,与功能需求一致。特别是
getV2RuntimeFromDll的导入显示了与 v2 运行时的兼容性设计。
10-33: 函数实现符合向后兼容设计要求
legacyDoTransform函数实现了良好的向后兼容设计,优先尝试使用 v2 运行时,在不可用时回退到 v3 的实现。错误处理也很清晰。
35-59: transformProperties 实现方式符合预期
legacyTransformProperties函数逻辑合理,优先使用 v2 运行时实现,回退逻辑处理清晰。使用preprocessTransformProperties预处理数据并设置属性是一个良好的设计决策。
61-79: 中间数据转换功能实现简洁有效
legacyTransformIntermediateData实现简洁明了,正确处理了from路径的数据提取,并在必要时应用转换。
81-104: 预处理函数实现结构清晰
preprocessTransformProperties函数实现得当,能正确处理数组和非数组转换项。
106-141: 管道转换函数设计良好
pipeableTransform函数处理了不同类型转换的情况,包括字符串直接映射和对象映射。代码逻辑清晰,正确处理了数组和非数组数据的转换。etc/runtime.api.md (3)
76-78: 在内部 API 中正确导出了新函数在
__secret_internals命名空间中正确导出了legacyDoTransform和legacyTransformProperties函数,使其可在内部使用。
264-280: 新增类型定义结构清晰
LegacyGeneralTransform、LegacyTransformItem和LegacyTransformMap类型定义清晰明确,为转换功能提供了良好的类型支持。
282-283: 函数签名定义完整
legacyTransformProperties函数签名完整,包含所有必要的参数和返回类型。
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v3 #4679 +/- ##
==========================================
+ Coverage 95.25% 95.27% +0.01%
==========================================
Files 208 209 +1
Lines 8982 9028 +46
Branches 1719 1734 +15
==========================================
+ Hits 8556 8601 +45
Misses 319 319
- Partials 107 108 +1
🚀 New features to boost your workflow:
|
next-core
|
||||||||||||||||||||||||||||
| Project |
next-core
|
| Branch Review |
steve/v3-legayc-transform
|
| Run status |
|
| Run duration | 00m 26s |
| Commit |
|
| Committer | Shenwei Wang |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
16
|
| View all changes introduced in this branch ↗︎ | |
6f0c2ef to
0f2148a
Compare
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.
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
依赖检查
组件之间的依赖声明,是微服务组件架构下的重要信息,请确保其正确性。
请勾选以下两组选项其中之一:
或者:
提交信息检查
Git 提交信息将决定包的版本发布及自动生成的 CHANGELOG,请检查工作内容与提交信息是否相符,并在以下每组选项中都依次确认。
破坏性变更:
feat作为提交类型。BREAKING CHANGE: 你的变更说明。新特性:
feat作为提交类型。问题修复:
fix作为提交类型。杂项工作:
即所有对下游使用者无任何影响、且没有必要显示在 CHANGELOG 中的改动,例如修改注释、测试用例、开发文档等:
chore,docs,test等作为提交类型。Summary by CodeRabbit
has方法,用于检测指定数据项是否存在。