feat(selection): accept ValueProxy keys in Table.get and Table.getAll - #9
Merged
Conversation
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()).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
N/A
❓ Type of change
📚 Description
Widens the typing of
Table.getandTable.getAllselection keys to acceptValueProxyvalues, 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 ValueProxy→Expression.decode), andstage_get/stage_getAllhave a dedicatedneedsExprbranch emitting$match: {$expr: {$eq: [...]}}for non-literal keys. Consumers currently have to cast (e.g.table.getAll(id as string, index)orrow.key("_id") as unknown as stringfor correlated subqueries) — this change removes those casts. Verified working against@antelopejs/mongodb1.2.1.Type-only change: the methods still pass arguments through to
this.stage(...)unchanged. The array case remains valid sincestage_getAlldecodes each element individually. Build, lint and the 161 tests pass.📝 Checklist
Greptile Summary
This PR is a type-only change that widens the
key/keysparameters ofTable.getandTable.getAllto acceptValueProxy-wrapped values in addition to plain scalars, removing the need for manual casts in correlated-subquery patterns.Table.getchanges fromkey: stringtokey: ValueProxyOrValue<string>, matching the runtime's existingDecodeValuepath.Table.getAllreplaces the inline unionstring | number | boolean | (...)[]withValueProxyOrValue<SelectionKey> | ValueProxyOrValue<SelectionKey>[], whereSelectionKeyis a new local alias forstring | 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
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>"Reviews (1): Last reviewed commit: "feat(selection): accept ValueProxy keys ..." | Re-trigger Greptile