Skip to content

feat(swift-example-app): document count aggregation view (DOC-10/11/12)#3926

Merged
QuantumExplorer merged 1 commit into
v3.1-devfrom
claude/doc-count-aggregation
Jun 17, 2026
Merged

feat(swift-example-app): document count aggregation view (DOC-10/11/12)#3926
QuantumExplorer merged 1 commit into
v3.1-devfrom
claude/doc-count-aggregation

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Jun 17, 2026

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

DOC-08 in the iOS test plan lumped document count / sum / average aggregation into one row marked 🔌 SDK-only, no UI — nothing in SwiftExampleApp drove it, so it could never be QA'd through the app. Document COUNT is in fact fully implemented at the FFI layer (dash_sdk_document_count, proof-verified); only SUM/AVERAGE are still upstream-blocked. This adds the missing app surface for COUNT and splits the catalog row so each capability is tracked independently.

What was done?

  • SwiftDashSDK (PlatformQueryExtensions.swift): added a thin read-only bridge documentCount(dataContractId:documentType:whereJSON:orderByJSON:groupByJSON:limit:) -> DocumentCountResult over the already-exported FFI dash_sdk_document_count (call → marshal → return; parses the {"counts":{hexKey:u64}} result; total is the empty-string key, grouped results are per-hex-key). Follows the existing documentList/documentGet pattern — no business logic.
  • SwiftExampleApp (CountDocumentsView.swift, new; TransitionCategoryView.swift): a "Count Documents" read view reachable via Settings → State Transitions → Document → Count Documents. Accessible (navigationLink) contract + document-type pickers, optional where / group_by JSON fields, a Run button, and total / per-group / error result sections.
  • TEST_PLAN.md: split the former DOC-08 (now an ➖ umbrella pointer) into:
    • DOC-10 count — total, DOC-11 count — filtered (where), DOC-12 count — grouped (group_by) → all 🧪, now drivable.
    • DOC-13 sum, DOC-14 average → 🚫, because the FFI dash_sdk_document_sum / _average entry points return NotImplemented (blocked upstream on grovedb PR 670). Updated the §6 Document index, Appendix A read-query row, and the completeness lists accordingly.

No Rust / xcframework change — dash_sdk_document_count was already implemented and exported in the header; this is Swift-only.

How Has This Been Tested?

Built for the iOS Simulator (iPhone 16, iphonesimulator) — ** BUILD SUCCEEDED ** — and driven end-to-end on testnet against a purpose-built countable contract (G72GKU5X…, doc type item with documentsCountable: true + a byCategory countable index, seeded with category a×3 / b×2 / c×1):

  • DOC-10 (total): result 6
  • DOC-11 (where category == "a"): result 3
  • DOC-12 (where category in ["a","b","c"] + group_by ["category"]): per-group {a:3, b:2, c:1} ✅ (group_by requires an In/range where per the platform; the FFI operator token is lowercase in)

All three recorded pass, and DOC-13/DOC-14 recorded blocked (grovedb PR 670), to the QA contract; they render on the live QA dashboard.

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Introduced document count query functionality with optional filtering, sorting, and grouping capabilities.
    • Added Count Documents interface in the example app to query and display document aggregation statistics.
  • Documentation

    • Updated test plan documentation to reflect document aggregation features and corresponding test coverage.

Add a read-only "Count Documents" view that exercises document COUNT
aggregation (total / where-filtered / group_by) over the already-exported
FFI `dash_sdk_document_count`.

- SwiftDashSDK: thin `documentCount(...) -> DocumentCountResult` wrapper
  in PlatformQueryExtensions (call -> marshal -> return; parses the
  {"counts":{hexKey:u64}} result, total under the empty-string key).
- SwiftExampleApp: CountDocumentsView reached via Settings -> State
  Transitions -> Document -> Count Documents; accessible navigationLink
  contract/type pickers + where/group_by JSON fields + result display.
- TEST_PLAN: split the former DOC-08 (count/sum/avg, was no-UI) into
  DOC-10 (count total), DOC-11 (count filtered), DOC-12 (count grouped),
  now drivable, plus DOC-13 (sum) / DOC-14 (average) which stay blocked
  because the FFI sum/average entry points return NotImplemented (blocked
  upstream on grovedb PR 670).

No Rust/xcframework change: dash_sdk_document_count was already exported.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@thepastaclaw

thepastaclaw commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

✅ Review complete (commit f133c2a)

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Adds document count aggregation to the Swift SDK: a new DocumentCountResult type and SDK.documentCount async FFI wrapper in PlatformQueryExtensions.swift, a new CountDocumentsView SwiftUI screen with contract/type pickers and optional JSON filter inputs, navigation wiring in TransitionCategoryView, and updated TEST_PLAN.md aggregation entries.

Changes

Document Count Aggregation

Layer / File(s) Summary
DocumentCountResult type and SDK.documentCount FFI wrapper
packages/swift-sdk/Sources/SwiftDashSDK/FFI/PlatformQueryExtensions.swift
Adds DocumentCountResult struct (counts: [String: UInt64], computed total and isGrouped). Adds SDK.documentCount(...) async method that validates limit != 0, fetches the data contract handle, marshals optional whereJSON/orderByJSON/groupByJSON via withOptionalCString, calls dash_sdk_document_count, parses the {"counts": {...}} JSON response, and returns DocumentCountResult. Adds withOptionalCString private helper for null-safe FFI bridging.
CountDocumentsView SwiftUI screen
packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/CountDocumentsView.swift
Introduces CountDocumentsView with state for selected contract/type, optional whereJSON/groupByJSON text fields, and run/result/error holders. Renders a contract picker (filtered by active network), document type picker, JSON filter inputs disabled during execution, and a run button with spinner. Results section shows total count and per-group rows from DocumentCountResult. Implements runCount(), groupedRows(_:), resetResult(), and trimmedOrNil(_:) helpers.
Navigation wiring and test plan
packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/TransitionCategoryView.swift, packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md
Adds a conditional "Count Documents" NavigationLink to TransitionCategoryView for the .document category, routing to CountDocumentsView. Updates TEST_PLAN.md with aggregation rows DOC-08 through DOC-14, expands the Document category index to DOC-01..14, revises Appendix A's getDocuments RPC row for COUNT visibility, and updates Appendix B's not-runnable lists for DOC-13/DOC-14.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • shumkov
  • lklimek
  • llbartekll
  • ZocoLini

Poem

🐇 Hop hop, the counts come in,
A DocumentCountResult born within!
The FFI speaks in hex and JSON sprite,
SwiftUI renders totals just right.
Groups are sorted, blanks trimmed to nil
The rabbit counts docs with consummate skill! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(swift-example-app): document count aggregation view (DOC-10/11/12)' directly and clearly summarizes the main change: adding a document count aggregation UI to the Swift Example App.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/doc-count-aggregation

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@QuantumExplorer QuantumExplorer merged commit 8bd9a77 into v3.1-dev Jun 17, 2026
17 of 18 checks passed
@QuantumExplorer QuantumExplorer deleted the claude/doc-count-aggregation branch June 17, 2026 11:33

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Swift-only PR that adds a thin documentCount FFI wrapper and a read-only CountDocumentsView. Marshaling, ownership, and the limit==0 guard match the existing documentList/documentGet precedent and the FFI contract. No consensus, Rust, signing, or cryptography touched. Two minor nitpicks verified: a UX wart in the grouped-result rendering and a theoretical u64 precision gap through JSONSerialization.

💬 2 nitpick(s)

Comment on lines +139 to +148
Section("Total") {
HStack {
Text("Count")
Spacer()
Text(result.total.map(String.init) ?? "—")
.fontWeight(.bold)
.foregroundColor(.primary)
.accessibilityIdentifier("countDocuments.totalCount")
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Nitpick: "Total" section shows "—" when results are grouped

When group_by is set, the FFI omits the empty-string aggregate entry, so result.total is nil and the Section("Total") row renders Count — above the per-group rows. The dash above grouped data reads as a failed-to-compute total. Hide the Total section when result.isGrouped, or surface a derived sum across groups. total: UInt64? is correctly typed — purely a presentation issue.

source: ['claude']

Comment on lines +667 to +672
var counts: [String: UInt64] = [:]
for (key, value) in countsObject {
if let num = value as? NSNumber {
counts[key] = num.uint64Value
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Nitpick: u64 counts above Int64.max lose precision through JSONSerialization → uint64Value

The Rust side serializes counts as raw JSON integers from BTreeMap<String, u64>. Foundation's JSONSerialization only guarantees fidelity for integers in the Int64 range — values in (Int64.max, UInt64.max] are typically returned as a Double-backed NSNumber, and num.uint64Value then silently truncates/rounds. Document counts will not realistically reach 2^63, so this is theoretical rather than a real bug. If you want full round-trip fidelity, decode with JSONDecoder into a Codable struct keyed [String: UInt64], which preserves UInt64 precision.

source: ['claude', 'codex']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants