Skip to content

feat(selection): accept ValueProxy keys in Table.get and Table.getAll - #9

Merged
Upd4ting merged 1 commit into
mainfrom
feat/valueproxy-selection-keys
Jun 12, 2026
Merged

feat(selection): accept ValueProxy keys in Table.get and Table.getAll#9
Upd4ting merged 1 commit into
mainfrom
feat/valueproxy-selection-keys

Conversation

@Upd4ting

@Upd4ting Upd4ting commented Jun 12, 2026

Copy link
Copy Markdown
Member

🔗 Linked issue

N/A

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Widens the typing of Table.get and Table.getAll selection keys to accept ValueProxy values, matching the existing runtime contract.

  • get(key: string)get(key: ValueProxyOrValue<string>)
  • getAll(keys: string | number | boolean | (...)[])getAll(keys: ValueProxyOrValue<SelectionKey> | ValueProxyOrValue<SelectionKey>[], index?: string)

The mongodb driver already decodes each stage argument via DecodeValue (value instanceof ValueProxyExpression.decode), and stage_get/stage_getAll have a dedicated needsExpr branch emitting $match: {$expr: {$eq: [...]}} for non-literal keys. Consumers currently have to cast (e.g. table.getAll(id as string, index) or row.key("_id") as unknown as string for correlated subqueries) — this change removes those casts. Verified working against @antelopejs/mongodb 1.2.1.

Type-only change: the methods still pass arguments through to this.stage(...) unchanged. The array case remains valid since stage_getAll decodes each element individually. Build, lint and the 161 tests pass.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Greptile Summary

This PR is a type-only change that widens the key / keys parameters of Table.get and Table.getAll to accept ValueProxy-wrapped values in addition to plain scalars, removing the need for manual casts in correlated-subquery patterns.

  • Table.get changes from key: string to key: ValueProxyOrValue<string>, matching the runtime's existing DecodeValue path.
  • Table.getAll replaces the inline union string | number | boolean | (...)[] with ValueProxyOrValue<SelectionKey> | ValueProxyOrValue<SelectionKey>[], where SelectionKey is a new local alias for string | number | boolean. Both the single-value and array cases remain structurally identical to the old type at the literal-value level.

Confidence Score: 5/5

Safe to merge — the change touches only TypeScript type signatures with no runtime logic altered.

Both method bodies are unchanged; the new types are strict supersets of the old ones, so all existing call sites remain valid. The introduced SelectionKey alias is a local type with no export surface. The widened signatures correctly reflect what the underlying driver already handles at runtime.

No files require special attention.

Important Files Changed

Filename Overview
src/selection.ts Type-only widening of Table.get and Table.getAll to accept ValueProxy-wrapped keys alongside plain scalar values; a new SelectionKey type alias is introduced for readability.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant Table
    participant stage
    participant Driver

    Note over Caller,Driver: get() with ValueProxy key
    Caller->>Table: "get(valueProxy: ValueProxy<string>)"
    Table->>stage: stage(SingleSelection, "get", undefined, valueProxy)
    stage->>Driver: DecodeValue(valueProxy) → Expression.decode
    Driver-->>Caller: "SingleSelection<T> via $match $expr $eq"

    Note over Caller,Driver: get() with plain string key (unchanged)
    Caller->>Table: get(key: string)
    Table->>stage: stage(SingleSelection, "get", undefined, key)
    stage->>Driver: DecodeValue(key) → literal
    Driver-->>Caller: "SingleSelection<T> via $match _id"

    Note over Caller,Driver: getAll() with mixed proxy/value array
    Caller->>Table: getAll([proxy, "literal"], index?)
    Table->>stage: "stage(Selection, "getAll", {index}, keys)"
    stage->>Driver: DecodeValue per element
    Driver-->>Caller: "Selection<T>"
Loading

Reviews (1): Last reviewed commit: "feat(selection): accept ValueProxy keys ..." | Re-trigger Greptile

The runtime contract already accepts ValueProxy keys: the mongodb
driver decodes each stage argument via DecodeValue and stage_get/
stage_getAll emit $match: {$expr: {$eq: [...]}} for non-literal
keys. Widening the signatures to ValueProxyOrValue removes the need
for consumers to cast (e.g. correlated subqueries using row.key()).
@Upd4ting
Upd4ting merged commit 6931cfd into main Jun 12, 2026
3 checks passed
@Upd4ting
Upd4ting deleted the feat/valueproxy-selection-keys branch June 12, 2026 16:57
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.

1 participant