-
Notifications
You must be signed in to change notification settings - Fork 52
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
fix: Dojo store add entity #349
Conversation
WalkthroughThe pull request includes modifications to the Changes
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
💤 Files with no reviewable changes (2)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 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 (
|
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
🧹 Outside diff range and nitpick comments (2)
packages/sdk/src/state/zustand.ts (1)
97-103
: Consider using Object.assign with multiple sources.The nested Object.assign calls can be simplified for better readability.
- ] = Object.assign( - {}, - mergedModels[ - typedNamespace as keyof typeof mergedModels - ], - namespaceModels - ); + ] = Object.assign({}, + mergedModels[typedNamespace as keyof typeof mergedModels], + namespaceModels);packages/sdk/src/__tests__/state.test.ts (1)
107-107
: Consider adding edge case tests.While the basic functionality is well tested, consider adding tests for:
- Adding an entity with missing required fields
- Adding an entity with invalid model structure
- Concurrent updates to the same entity
Also applies to: 128-128, 148-148
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
packages/sdk/package.json
(0 hunks)packages/sdk/src/__tests__/state.test.ts
(3 hunks)packages/sdk/src/state/zustand.ts
(1 hunks)
💤 Files with no reviewable changes (1)
- packages/sdk/package.json
🔇 Additional comments (2)
packages/sdk/src/state/zustand.ts (1)
75-116
: Verify type safety and required fields validation.
While the implementation correctly handles both updating and adding entities, consider adding validation to ensure:
- New entities conform to the expected schema type
- Required fields are present when adding new entities
✅ Verification successful
Based on the code analysis, I can now provide a final response:
Type safety is handled through TypeScript's static type system
The implementation is already type-safe through TypeScript's static typing:
ParsedEntity<T>
type ensures entities conform to the schema typeWritableDraft<ParsedEntity<T>>
type is used for new entities- Type validation for models and namespaces is enforced through TypeScript's generics
Required fields validation is implicitly handled:
- Entity ID is required through the type system (
entity.entityId
) - Models object is required through the type system (
entity.models
) - Additional validation is not necessary as the store is an internal implementation detail, with data already validated at the SDK level
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check for type validation patterns in the codebase
rg -A 3 "type.*validation|schema.*validation|required.*fields"
# Look for similar entity validation patterns
ast-grep --pattern 'if ($entity && $entity.models) {
$$$
}'
Length of output: 128
Script:
#!/bin/bash
# Let's check for type validation patterns more broadly
rg -A 3 "typeof|instanceof|type.*check"
# Look for entity validation or type checking in the same file
fd "zustand.ts" --exec cat {}
# Check for type definitions related to entities
ast-grep --pattern 'type ParsedEntity'
Length of output: 58614
Script:
#!/bin/bash
# Let's check the ParsedEntity type definition and related type validations
fd "types.ts" --exec cat {}
# Look for schema validation patterns in the codebase
rg -A 3 "schema.*validation|validateSchema|checkSchema"
# Check for any type guards or validation functions
ast-grep --pattern 'function is$_($entity) {
$$$
}'
Length of output: 10974
packages/sdk/src/__tests__/state.test.ts (1)
Line range hint 134-151
: LGTM! Test coverage properly validates the new functionality.
The test case effectively verifies that:
- New entities can be added via updateEntity
- The entity count increases correctly
- The added entity has the expected structure and data
a2dde2d
to
8d93559
Compare
Introduced changes
zustand Dojo store
updateEntity()
can add new entities.Checklist
Summary by CodeRabbit
entityId
does not exist.getEntities()
andgetEntitiesByModel
.