-
-
Notifications
You must be signed in to change notification settings - Fork 4
fix: fix headers parse #42
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
base: main
Are you sure you want to change the base?
Conversation
- Add `serializeObject` to create a clean object from a source. - Export and thoroughly test the `forEach` utility.
WalkthroughA new interface, Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Utils
participant AxiosHeaders
Caller->>Utils: resolveUniAppRequestOptions(options)
Utils->>Utils: serializeObject(headers, options)
Utils->>AxiosHeaders: AxiosHeaders.from(serializedHeaders)
AxiosHeaders-->>Utils: normalizedHeaders
Utils-->>Caller: processedOptions
Poem
✨ 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 (
|
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/types.ts(1 hunks)src/utils.ts(3 hunks)test/utils.test.ts(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/utils.ts (1)
src/types.ts (1)
SerializeOptions(32-38)
🪛 Biome (1.9.4)
src/utils.ts
[error] 189-189: 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)
🔇 Additional comments (8)
src/types.ts (1)
29-38: Well-designed interface with clear documentation.The
SerializeOptionsinterface is properly defined with clear documentation. The Chinese comments are consistent with the codebase style, and theasStringsoption provides clear control over array serialization behavior.test/utils.test.ts (3)
1-2: Good import additions for testing new utilities.The imports correctly include the new utility functions and the
vimock helper from vitest for proper testing setup.
68-129: Comprehensive test coverage for serializeObject.The test suite thoroughly covers all critical scenarios:
- Filtering of null, undefined, and false values
- Handling of nullish inputs
- Array serialization with asStrings option
- Prototype verification ensuring clean objects
The test cases are well-structured and verify the function's behavior accurately.
131-195: Thorough testing of forEach utility function.The tests comprehensively cover:
- Array iteration with correct callback arguments
- Object property enumeration (enumerable vs non-enumerable)
- Non-object value wrapping behavior
- Null/undefined input handling
The test implementation properly uses vitest mocks to verify callback invocations and ensures edge cases are handled correctly.
src/utils.ts (4)
15-15: Good addition of SerializeOptions import.The import correctly includes the new interface needed for the serializeObject function.
47-47: Headers parsing fix addresses the core issue.The modification to serialize headers before passing to
AxiosHeaders.from()properly addresses the headers parsing issue mentioned in the PR. This ensures that headers are normalized and cleaned before processing.
119-148: Well-implemented serializeObject function.The implementation correctly:
- Creates a prototype-free object for cleaner output
- Filters out null, undefined, and false values
- Supports optional array-to-string conversion
- Uses the forEach utility for consistent iteration
The JSDoc documentation with axios source reference is helpful for understanding the implementation origin.
150-212: Well-structured forEach implementation with room for type improvements.The function implementation correctly handles:
- Null/undefined safety checks
- Non-object wrapping into arrays
- Array iteration with proper callback arguments
- Object iteration with configurable property enumeration
The overloaded signatures provide good type safety for specific use cases. However, the main implementation could benefit from better typing beyond the Function type issue already mentioned.
Description 描述
请查阅 #41
Linked Issues 关联的 Issues
#41
Additional context 额外上下文
新增实现了
serializeObject、forEach工具方法(axios 内部的相关实现的优化版本),并完善相关单元测试。Summary by CodeRabbit
New Features
Tests