Repository navigation
fix(sdk): accept a contains pin in the ranked query type - #5402
Conversation
A ranked or having-range query already answers a `contains` pin on a typed array: the wasm-sdk parses it with the shared where parser and keys it as an equality before the ranked grammar, as the server does. `DocumentsIndexPin` only listed `==` and `in`, so TypeScript callers had to cast such a pin. Widen it to `contains` (not `containsAny`, which the ranked and having grammars refuse), update the JSDoc and the stale "pins must be `==`" error text, guard the union with a unit test, add a typed evo-sdk spec, and document the pin in the evo-sdk README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Waiting for bot review — coderabbitai ✓ · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
🕓 Review not started yet because the new head is waiting for the 30-minute push debounce.
Commit 874be58. Normal review starts when eligible; priority review starts as soon as a slot is available. |
Basic explanation
A ranked query (the "top n" document query) can be pinned to one tag of a list, for example "the most liked posts tagged
dash", by writing['tags', 'contains', 'dash']inwhere. The SDK and the node already answer that query, but the SDK's TypeScript type for a pin only listed==andin, so TypeScript code had to force the pin through with a cast. This lets the type acceptcontains, keepscontainsAnyout (a ranked query refuses it), and fixes the docs and an error message that still said every pin must be==.Issue being fixed or feature implemented
Since #5370 and #5372, an index can name a typed array and a query reads one element with
contains. A ranked or having-range query takes such a pin at runtime:parse_where_clauseacceptscontains, andassert_ranked_shape/assert_having_shapekey it as an equality before the ranked grammar, as the server's ranked and having dispatchers do (key_array_element_clauses).containsAnyis refused there, since a ranking over several elements would count a document once per element it holds.The
DocumentsIndexPinTypeScript type was not updated, so callers such as Yappr'stagPininlib/services/ranked-likes.tsneededas unknown as DocumentsIndexPin.Before:
After:
What was done?
packages/wasm-sdk/src/queries/document_ranked.rsDocumentsIndexPingains[string, 'contains' | 'Contains', unknown](both spellings, as the parser andDocumentWhereOperatortake them).containsAnystays out. The type is shared byDocumentsRankedQuery.whereandDocumentsHavingQuery.where, and both surfaces accept the pin.wherefields says what acontainspin names and whycontainsAnyis rejected.whereentries must be==pins" (it was also stale forin). It now reads: "whereentries pin the covering compound index's leading properties with==(containson a typed array), or one boundedin."index_pin_union_takes_contains_but_not_contains_anyreads the declared union, next to the existingaxis_kind_strings_match_the_typescript_union. It fails ifcontainsis dropped orcontainsAnyis added. This is the guard CI enforces: the mocha runs of the TS specs do not type-check.packages/js-evo-sdk/tests/unit/facades/documents.spec.ts: aranked()case with acontainspin, with the query typed asDocumentsRankedQuery.packages/js-evo-sdk/README.md: "Pinning a compound index" shows acontainspin and sayscontainsAnycannot pin; the typed array section points to it.How Has This Been Tested?
cargo fmt -p wasm-sdk --checkpasses, and eslint passes on the touched spec.tsc --strict, the old union rejectswhere: [['tags', 'contains', 'dash']]with the TS2322 error quoted above.yarn build) and the evo-sdk build were still running when this PR was opened. This section will be updated with thetsccheck of the new spec against the generatedsdk.d.ts, the run ofdocuments.spec.ts, andcargo test -p wasm-sdk --lib index_pin_union.tsc.Breaking Changes
None. The type only widens, and the runtime is unchanged apart from the wording of one error message.
Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
874be58/skip-botsproceeds without the ones not yet reported/self-reviewedjs-wasm-sdk(packages/js-evo-sdk/README.md,packages/js-evo-sdk/tests/unit/facades/documents.spec.ts,packages/wasm-sdk/src/queries/document_ranked.rs) — shumkovWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.Summary by CodeRabbit
New Features
containsto pin a typed-array property to a specific element.contains, with at most one branchingincondition. Range operators andcontainsAnyare not supported as prefix pins.Documentation