Uh oh!
There was an error while loading. Please reload this page.
feat(swift-example-app): GroveDB path elements diagnostic view (SYS-06) - #3931
Conversation
Surface the raw GroveDB path-elements query (SYS-06) in SwiftExampleApp
via a thin SDK wrapper + a diagnostic read view over the already-exported
FFI `dash_sdk_system_get_path_elements`.
- SwiftDashSDK: `systemPathElements(path:keys:) -> [PathElement]` wrapper
in PlatformQueryExtensions (call -> marshal -> parse -> return; parses
the {key,element,type} JSON array; NoData -> []). Pure bridge.
- SwiftExampleApp: GroveDBPathElementsView, reached via Platform Queries
-> System & Utility -> "Get GroveDB Path Elements". Path + keys JSON
fields, Run, results list (type/key/element), error section, and a
"DPNS contract example" preset (path=["40"], keys=[DPNS contract id])
that fills the fields directly (no typed JSON -> avoids the simulator's
smart-punctuation mangling).
- The preset uses a *bounded* path on purpose: root-level queries
(path=[]) fail GroveDB proof verification ("Cannot verify lower bound");
bounded path queries verify cleanly.
- TEST_PLAN: flip SYS-06 from no-UI to drivable, update Appendix A +
completeness lists.
No Rust/xcframework change: dash_sdk_system_get_path_elements was already
exported.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>📝 WalkthroughWalkthroughAdds a ChangesGroveDB Path Elements Feature
Sequence DiagramsequenceDiagram
actor User
participant GroveDBPathElementsView
participant SDK
participant FFI as dash_sdk_system_get_path_elements
User->>GroveDBPathElementsView: tap "Run Query"
GroveDBPathElementsView->>GroveDBPathElementsView: decodeStringArray(pathText, keysText)
GroveDBPathElementsView->>SDK: sdk.systemPathElements(path:keys:)
SDK->>SDK: JSONEncoder serialize path/keys
SDK->>FFI: dash_sdk_system_get_path_elements(path_json, keys_json)
FFI-->>SDK: SdkResult
alt FFI error
SDK-->>GroveDBPathElementsView: throws SDKError
GroveDBPathElementsView->>User: display red error message
else success
SDK->>SDK: parse JSON → [PathElement]
SDK-->>GroveDBPathElementsView: [PathElement]
GroveDBPathElementsView->>User: render element list (type, key, element)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
✅ Review complete (commit a5ce2b4) |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/swift-sdk/Sources/SwiftDashSDK/FFI/PlatformQueryExtensions.swift`:
- Around line 1715-1725: The PathElement initialization in the map closure is
silently defaulting missing or incorrectly-typed fields to empty strings using
the nil-coalescing operator. Instead, validate that the key, element, and type
fields are present and properly typed, and throw an SDKError.serializationError
with a descriptive message if any of these required fields are missing or
invalid, rather than defaulting them to empty strings.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ca701a64-e2cf-4621-98e2-23b6e09a90ea
📒 Files selected for processing (4)
packages/swift-sdk/Sources/SwiftDashSDK/FFI/PlatformQueryExtensions.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/GroveDBPathElementsView.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/PlatformQueriesView.swiftpackages/swift-sdk/SwiftExampleApp/TEST_PLAN.md
| guard let data = jsonString.data(using: .utf8), | ||
| let array = try? JSONSerialization.jsonObject(with: data) as? [[String: Any]] else { | ||
| throw SDKError.serializationError("Failed to parse path elements JSON array") | ||
| } | ||
| return array.map { entry in | ||
| PathElement( | ||
| key: entry["key"] as? String ?? "", | ||
| element: entry["element"] as? String ?? "", | ||
| type: entry["type"] as? String ?? "" | ||
| ) |
There was a problem hiding this comment.
Fail fast on malformed path-element payloads instead of silently zero-filling fields.
Line 1722, Line 1723, and Line 1724 currently coerce missing/invalid fields to "". That hides FFI contract breaks and can produce misleading diagnostic output. This bridge should throw serialization errors when key/element/type are absent or wrong-typed.
Suggested fix
- guard let data = jsonString.data(using: .utf8),- let array = try? JSONSerialization.jsonObject(with: data) as? [[String: Any]] else {- throw SDKError.serializationError("Failed to parse path elements JSON array")- }-- return array.map { entry in- PathElement(- key: entry["key"] as? String ?? "",- element: entry["element"] as? String ?? "",- type: entry["type"] as? String ?? ""- )- }+ struct RawPathElement: Decodable {+ let key: String+ let element: String+ let type: String+ }++ guard let data = jsonString.data(using: .utf8) else {+ throw SDKError.serializationError("Failed to parse path elements JSON array")+ }++ do {+ let decoded = try JSONDecoder().decode([RawPathElement].self, from: data)+ return decoded.map { PathElement(key: $0.key, element: $0.element, type: $0.type) }+ } catch {+ throw SDKError.serializationError("Invalid path elements payload: \(error.localizedDescription)")+ }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/swift-sdk/Sources/SwiftDashSDK/FFI/PlatformQueryExtensions.swift`
around lines 1715 - 1725, The PathElement initialization in the map closure is
silently defaulting missing or incorrectly-typed fields to empty strings using
the nil-coalescing operator. Instead, validate that the key, element, and type
fields are present and properly typed, and throw an SDKError.serializationError
with a descriptive message if any of these required fields are missing or
invalid, rather than defaulting them to empty strings.
Uh oh!
There was an error while loading. Please reload this page.
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
Thin Swift wrapper around the already-shipped dash_sdk_system_get_path_elements FFI plus a read-only SwiftUI diagnostic view, with TEST_PLAN flips for SYS-06. All six agents converged on no in-scope findings; FFI memory ownership, string lifetimes via withCString, error/data free pairing, and NoData→[] mapping match existing precedent in the file. No correctness, security, FFI, or architectural issues introduced by this PR.
Issue being fixed or feature implemented
SYS-06(raw GroveDB path elements) was marked 🔌 SDK-only, no UI — the FFIdash_sdk_system_get_path_elementsis fully implemented and proof-verified, but nothing in SwiftExampleApp surfaced it, so it could only ever be skipped in app QA. This adds the missing diagnostic surface.What was done?
PlatformQueryExtensions.swift): added a thin read-only bridgesystemPathElements(path:keys:) -> [PathElement]over the already-exported FFIdash_sdk_system_get_path_elements(call → marshal → parse the{key, element, type}JSON array → return;NoData→[]). Mirrors the existingdocumentCountwrapper — no business logic.GroveDBPathElementsView.swift, new;PlatformQueriesView.swift): a "Get GroveDB Path Elements" read view reachable via Platform Queries → System & Utility → Get GroveDB Path Elements.path+keysJSON fields, a Run button, a results list (type / key / element), an error section, and a "DPNS contract example" preset that fills the fields directly (no typed JSON → avoids the simulator's smart-punctuation mangling of quotes).path=[]) fail GroveDB proof verification ("Cannot verify lower bound"); bounded path queries verify cleanly. The footer documents this.SYS-06from 🔌 to 🧪, updated the Appendix A read-query row and the SDK-only completeness list.No Rust / xcframework change —
dash_sdk_system_get_path_elementswas already implemented and exported; this is Swift-only.How Has This Been Tested?
Driven end-to-end on testnet (iPhone 16 Pro sim) via the new view:
path=["40"](theDataContractDocumentsroot, byte0x40),keys=[DPNS system contract id]→ 1 element returned, typetree(the DPNS contract's GroveDB subtree), proof-verified. Recordedpassfor SYS-06 to the QA contract; it renders on the live QA dashboard. Also confirmed the empty-path preset path errors with a proof-verification failure, which is why the shipped preset is bounded.Breaking Changes
None.
Checklist:
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Documentation