feat: a datasource filters on the fields of the objects it lists - #105
Merged
Conversation
A companion datasource declared filter_type and filter_value, and only ever acted on one value of them: filter_type "id" fetched one object, and everything else returned the collection whole. filter_value narrowed nothing. A caller who wanted one object had to know its position in the list and index to it, which no API promises to keep stable. Every scalar field at the root of a listed object is now an optional argument of that field's own type, and items carries the objects that matched every argument the configuration set. Nested fields and collections are not offered: HCL would have to describe a whole object to match one leaf of it, and a collection has no single value to compare. Matching is exact and runs over the objects the list already answered with, so a filter carries no wire value and binds to no SDK field. Setting id is still answered by the by-id read where the API has one, rather than listing a collection to discard all but one of it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
What was wrong
A companion datasource declared
filter_typeandfilter_value, and theOneOfvalidator allowed exactly two values:allandid. Onlyiddidanything — it fetched one object through the item
GET. Every other casereturned the collection whole, and
filter_valuenarrowed nothing at all.So a caller who wanted one object had to know its position in the list and
index to it —
items[2]— which no API promises to keep stable. The filterwas the part that was never built.
What changes
Every scalar field at the root of a listed object becomes an optional argument
of that field's own type, and
itemscarries the objects that matched everyargument the configuration set.
Nested objects and collections are not offered: HCL would have to describe a
whole object to match one leaf of it, and a collection has no single value to
compare. They are read off the items the filters selected.
the field's own type, so
managed = true, not"true". The generated matchcompares terraform values with
.Equal, which needs no conversion and cannotdisagree with the item model.
nothing, which is what lets several combine and none be mandatory.
idstill short-circuits. Where the API has a by-id read, settingidcalls it rather than listing a collection to discard all but one of it.
objects the list already answered with — so
sdkbindleaves them alone, asit already did for
filter_type.Carried on the intermediate representation as
Attribute.Filter, which is whattells addressing attributes and filters apart at the root of a companion; that
distinction used to be a hardcoded name check.
Generated output
Two imports stop being emitted for datasources —
stringvalidatorandvalidatorwere there only forfilter_type's hardcodedOneOf, andfmtonly for the
filter_valueerror. The schema builder still adds them where afilter actually needs one.
Verification
make checkpasses: fmt, build, vet, coverage gate at 91.3% total, hygiene.The generated-tree tests are the load-bearing ones here —
RenderServices_TheRenderedTreeCompilesbuilds the emitted provider for both backends, and
CuratedTreeCompilesdoesthe same for the curated tree, so the new
matchesfunction and the reshapedmodel are compiled, not just string-matched. Added a test asserting each root
scalar is offered at its own type, that the model carries a field for it, that
the match consults every filter, and that
idreaches the by-id read.Test fixtures in
internal/emitandinternal/sdkbindthat hand-built the oldfilter_type/filter_valueroot were updated to the new shape.🤖 Generated with Claude Code