Replace dotrain order dummy constructor with class constructor#1907
Replace dotrain order dummy constructor with class constructor#1907
Conversation
## Walkthrough
This change refactors all usages of the `DotrainOrder` struct to consolidate its creation and initialization into a single asynchronous `create` method, replacing the previous two-step pattern of calling `new()` followed by `initialize()`. Related tests and API surfaces are updated accordingly, and the `wasm-bindgen-utils` dependency is bumped from version 0.0.8 to 0.0.9.
## Changes
| File(s) | Change Summary |
|-------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
| crates/common/src/dotrain_order/mod.rs | Removes `new`, `initialize`, and `ensure_initialized`; updates `create` to return initialized instance directly. |
| crates/cli/src/commands/order/calldata.rs<br>crates/cli/src/commands/order/compose.rs<br>crates/cli/src/commands/order/listorderfrontmatterkeys.rs<br>crates/cli/src/commands/order/orderbook_address.rs<br>crates/cli/src/commands/words/mod.rs | Refactors to use `DotrainOrder::create` instead of `new` + `initialize`. |
| crates/common/src/add_order.rs<br>crates/common/src/replays.rs | Updates test code to use `DotrainOrder::create` for initialization. |
| crates/integration_tests/src/lib.rs | Refactors test initialization to use `DotrainOrder::create`. |
| crates/js_api/src/gui/mod.rs<br>crates/js_api/src/gui/state_management.rs | Refactors all creation to use `DotrainOrder::create`; removes separate initialization step. |
| crates/quote/src/order_quotes.rs<br>crates/quote/src/quote_debug.rs | Updates test helpers and tests to use single-step `DotrainOrder::create`. |
| packages/orderbook/test/common/test.test.ts | Refactors tests to handle result from `DotrainOrder.create` as a result object, with explicit error checks. |
| tauri-app/src-tauri/Cargo.toml<br>Cargo.toml | Bumps `wasm-bindgen-utils` dependency from 0.0.8 to 0.0.9. |
| tauri-app/src-tauri/src/commands/authoring_meta.rs<br>tauri-app/src-tauri/src/commands/order.rs<br>tauri-app/src-tauri/src/commands/order_quote.rs<br>tauri-app/src-tauri/src/commands/trade_debug.rs | Refactors all usages to single-step `DotrainOrder::create` initialization. |
## Sequence Diagram(s)
```mermaid
sequenceDiagram
participant Caller
participant DotrainOrder
Caller->>DotrainOrder: create(dotrain, settings) (async)
activate DotrainOrder
DotrainOrder-->>Caller: Initialized DotrainOrder instanceAssessment against linked issues
Assessment against linked issues: Out-of-scope changes
Possibly related PRs
Suggested labels
Suggested reviewers
Learnt from: findolor |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (2)
Cargo.lockis excluded by!**/*.locktauri-app/src-tauri/Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (20)
Cargo.toml(1 hunks)crates/cli/src/commands/order/calldata.rs(1 hunks)crates/cli/src/commands/order/compose.rs(1 hunks)crates/cli/src/commands/order/listorderfrontmatterkeys.rs(1 hunks)crates/cli/src/commands/order/orderbook_address.rs(1 hunks)crates/cli/src/commands/words/mod.rs(1 hunks)crates/common/src/add_order.rs(2 hunks)crates/common/src/dotrain_order/mod.rs(15 hunks)crates/common/src/replays.rs(1 hunks)crates/integration_tests/src/lib.rs(2 hunks)crates/js_api/src/gui/mod.rs(5 hunks)crates/js_api/src/gui/state_management.rs(1 hunks)crates/quote/src/order_quotes.rs(1 hunks)crates/quote/src/quote_debug.rs(3 hunks)packages/orderbook/test/common/test.test.ts(2 hunks)tauri-app/src-tauri/Cargo.toml(1 hunks)tauri-app/src-tauri/src/commands/authoring_meta.rs(1 hunks)tauri-app/src-tauri/src/commands/order.rs(2 hunks)tauri-app/src-tauri/src/commands/order_quote.rs(1 hunks)tauri-app/src-tauri/src/commands/trade_debug.rs(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
Cargo.toml (1)
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1710
File: crates/quote/Cargo.toml:30-30
Timestamp: 2025-05-14T04:49:14.621Z
Learning: In the rain.orderbook repository, wasm-bindgen-utils is intentionally used as an unconditional dependency because non-wasm targets (like tests) sometimes need to use it.
🧬 Code Graph Analysis (13)
crates/cli/src/commands/order/compose.rs (1)
crates/common/src/dotrain_order/mod.rs (2)
create(226-263)dotrain(267-269)
tauri-app/src-tauri/src/commands/trade_debug.rs (1)
crates/common/src/dotrain_order/mod.rs (2)
create(226-263)dotrain(267-269)
crates/cli/src/commands/order/calldata.rs (1)
crates/common/src/dotrain_order/mod.rs (2)
create(226-263)dotrain(267-269)
crates/cli/src/commands/order/orderbook_address.rs (1)
crates/common/src/dotrain_order/mod.rs (2)
create(226-263)dotrain(267-269)
tauri-app/src-tauri/src/commands/authoring_meta.rs (1)
crates/common/src/dotrain_order/mod.rs (2)
create(226-263)dotrain(267-269)
crates/js_api/src/gui/state_management.rs (1)
crates/common/src/dotrain_order/mod.rs (2)
create(226-263)dotrain(267-269)
crates/cli/src/commands/words/mod.rs (1)
crates/common/src/dotrain_order/mod.rs (2)
create(226-263)dotrain(267-269)
crates/quote/src/quote_debug.rs (1)
crates/common/src/dotrain_order/mod.rs (2)
create(226-263)dotrain(267-269)
crates/integration_tests/src/lib.rs (1)
crates/common/src/dotrain_order/mod.rs (2)
create(226-263)dotrain(267-269)
tauri-app/src-tauri/src/commands/order_quote.rs (1)
crates/common/src/dotrain_order/mod.rs (2)
create(226-263)dotrain(267-269)
crates/js_api/src/gui/mod.rs (1)
crates/common/src/dotrain_order/mod.rs (2)
create(226-263)dotrain(267-269)
packages/orderbook/test/common/test.test.ts (2)
crates/common/src/dotrain_order/mod.rs (1)
dotrain(267-269)tauri-app/src/__tests__/pickConfig.test.ts (1)
config(11-182)
crates/quote/src/order_quotes.rs (1)
crates/common/src/dotrain_order/mod.rs (2)
create(226-263)dotrain(267-269)
🔇 Additional comments (25)
Cargo.toml (1)
55-55:Details
✅ Verification successful
Verify the wasm-bindgen-utils version upgrade.
The version bump from 0.0.8 to 0.0.9 aligns with the PR objectives to leverage enhanced class constructor support. Please ensure this version is available and check for any breaking changes.
🏁 Script executed:
#!/bin/bash # Check if wasm-bindgen-utils 0.0.9 exists on crates.io and look for any security advisories curl -s https://crates.io/api/v1/crates/wasm-bindgen-utils | jq '.versions[] | select(.num == "0.0.9") | {num: .num, created_at: .created_at}' # Check for any security advisories gh api graphql -f query=' { securityVulnerabilities(first: 5, ecosystem: RUST, package: "wasm-bindgen-utils") { nodes { advisory { summary severity publishedAt } vulnerableVersionRange firstPatchedVersion { identifier } } } }'Length of output: 565
Confirmed wasm-bindgen-utils 0.0.9 is available and secure.
The crate version 0.0.9 was published on 2025-06-04 and no security advisories were found for this package. You can proceed with the upgrade.
tauri-app/src-tauri/Cargo.toml (1)
53-53: LGTM! Consistent dependency update.The wasm-bindgen-utils version update is properly scoped to the wasm target and aligns with the workspace-level dependency bump.
crates/quote/src/quote_debug.rs (3)
157-157: LGTM! Proper implementation of the new DotrainOrder creation pattern.The refactor correctly replaces the two-step initialization pattern with the new asynchronous
createmethod, simplifying the code and enforcing initialization at creation time.
283-283: LGTM! Consistent usage of the new creation pattern.The change follows the same pattern as other tests, maintaining consistency across the codebase.
407-407: LGTM! Final test updated consistently.All three test functions now use the unified
DotrainOrder::createmethod, completing the refactor for this file.crates/common/src/replays.rs (1)
145-145: LGTM! Consistent implementation of the new DotrainOrder pattern.The change correctly adopts the new
DotrainOrder::createmethod, maintaining consistency with the broader refactor across the codebase.tauri-app/src-tauri/src/commands/trade_debug.rs (1)
120-120: LGTM! Clean refactoring to consolidated async constructor.The change from the two-step
DotrainOrder::new()+initialize()pattern to the singleDotrainOrder::create()call simplifies the API and eliminates the need for mutable variables while maintaining the same functionality.tauri-app/src-tauri/src/commands/order_quote.rs (1)
124-124: LGTM! Consistent with the broader DotrainOrder API refactor.The consolidation of creation and initialization into the single async
create()method is applied consistently here, improving code clarity and eliminating mutable variable requirements.crates/integration_tests/src/lib.rs (1)
84-84: LGTM! Consistent DotrainOrder API modernization in both test functions.Both changes properly replace the old two-step initialization pattern with the new consolidated
create()method, maintaining identical functionality while simplifying the code structure.Also applies to: 189-189
crates/common/src/add_order.rs (1)
893-893: LGTM! Final consistent application of DotrainOrder API refactor.Both test functions correctly adopt the new
DotrainOrder::create()pattern, completing the systematic refactor to consolidate creation and initialization into a single async method call.Also applies to: 981-981
crates/js_api/src/gui/state_management.rs (1)
181-181: LGTM! Clean consolidation of DotrainOrder creation and initialization.This change successfully replaces the previous two-step pattern (new + initialize) with a single async factory method call, eliminating the need for mutable variables and separate initialization steps.
crates/cli/src/commands/words/mod.rs (1)
95-95: LGTM! Consistent refactor with proper settings handling.The change correctly consolidates DotrainOrder creation and initialization while properly transforming the optional settings string into the expected vector format.
crates/cli/src/commands/order/compose.rs (1)
45-45: LGTM! Follows the established refactor pattern correctly.The consolidation of DotrainOrder creation and initialization is implemented consistently with proper settings transformation and error handling.
crates/cli/src/commands/order/listorderfrontmatterkeys.rs (1)
44-44: LGTM! Completes the consistent DotrainOrder refactor across CLI commands.This final change maintains consistency with the broader refactor, successfully consolidating creation and initialization while preserving all existing functionality and error handling.
crates/cli/src/commands/order/calldata.rs (1)
39-39: LGTM! Clean refactoring to the new DotrainOrder initialization pattern.The change correctly replaces the previous two-step initialization (new + initialize) with the consolidated
createmethod. The settings parameter mapping fromOption<String>toOption<Vec<String>>is handled appropriately, and error handling is preserved.crates/quote/src/order_quotes.rs (1)
277-277: LGTM! Test helper function correctly updated for new DotrainOrder API.The change appropriately uses the new
createmethod withNonefor settings, which is suitable for test scenarios. Theunwrap()usage is acceptable in test context.crates/cli/src/commands/order/orderbook_address.rs (1)
37-37: LGTM! Consistent implementation of the DotrainOrder refactoring.The change follows the same pattern as other CLI commands, correctly using the new
createmethod with proper settings parameter mapping and error handling.tauri-app/src-tauri/src/commands/order.rs (3)
144-144: LGTM! Correct usage of the new create method.The settings parameter is already
Option<Vec<String>>so it can be passed directly tocreate().
152-152: LGTM! Proper parameter wrapping for the create method.Correctly wraps the
Vec<String>inSome()sincecreate()expectsOption<Vec<String>>.
437-437: LGTM! Test code appropriately updated.The test correctly uses the new
createmethod withNonefor settings, andunwrap()is acceptable in test context.crates/js_api/src/gui/mod.rs (1)
75-75: LGTM! Clean refactor to consolidate initialization.The changes correctly replace the two-step pattern with the single
DotrainOrder::create()call across all methods. This simplifies the API and removes the need for mutable intermediate states.Also applies to: 88-88, 207-207, 220-220, 272-272
tauri-app/src-tauri/src/commands/authoring_meta.rs (1)
9-9: LGTM!The refactor correctly replaces the two-step initialization with the single
createcall, maintaining the same error propagation pattern.crates/common/src/dotrain_order/mod.rs (3)
215-221: Good update to the dummy() method.The
dummy()method now properly initializesdotrain_yamlwith an empty vector, ensuring the instance is valid even without going through the fullcreate()flow. This is important for test scenarios.
223-263: Excellent refactor of the initialization pattern.The new
create()method successfully consolidates all initialization logic that was previously split betweennew()andinitialize(). This ensures thatDotrainOrderinstances are always fully initialized, eliminating potential bugs from forgetting to callinitialize().The implementation correctly:
- Extracts frontmatter
- Merges settings if provided
- Fetches remote networks and tokens asynchronously
- Updates caches appropriately
507-509: Test updates are consistent and correct.All test cases have been properly updated to use the new
create()pattern. The async/await usage is correct and error handling remains intact.Also applies to: 550-552, 600-602, 647-651, 692-694, 736-738, 784-786, 837-839, 891-893, 967-969, 1151-1153, 1178-1180, 1236-1238
Caution
Chained PR - do not merge before #1906
Motivation
See issue: #1855
Now that we've bumped the wasm-bindgen-utils version and have the ability to use class constructors with wasm bindings, this PR implements the first pass for dotrain order class
Solution
Checks
By submitting this for review, I'm confirming I've done the following:
fix #1855
Summary by CodeRabbit