Skip to content

feat: add typed required resources and resource accessors - #39

Merged
jonasz-lasut merged 2 commits into
mainfrom
feat/typed-resources-and-accessors
Oct 11, 2026
Merged

jonasz-lasut merged 2 commits into
mainfrom
feat/typed-resources-and-accessors

Conversation

@jonasz-lasut

Copy link
Copy Markdown
Collaborator

Implements the typed get_required_resources_as/get_required_resource_as getters from #33 and the four observed/desired resource accessors from #34, and switches the example and README to the accessors.

Fixes #33
Fixes #34

get_required_resources returns JSON values, so every caller
deserialized each item by hand. get_required_resources_as and
get_required_resource_as deserialize into any DeserializeOwned type,
like get_input and resource::get, restoring integral numbers first so
integer fields deserialize.

They return Result<Option<_>>: `?` handles an item that does not
deserialize, and None still means the requirement is unresolved. The
untyped getters stay.

Fixes #33

Signed-off-by: Jonasz Małecki <jonasz@upbound.io>
Functions reached into requests and responses through Option chains,
and the example and README repeated the same two. Add the accessors
function-sdk-go has as GetObservedCompositeResource,
GetObservedComposedResources, SetDesiredCompositeResource and
SetDesiredComposedResources:

- request::observed_composite and request::observed_composed borrow
  the observed XR and a composed resource by name.
- response::desired_composite and response::desired_composed return
  the desired XR and a composed resource by name, inserting an empty
  one when the response has none, so state copied forward by
  response::to is modified in place.

The example function, the README and the resource::get docs use them.

Fixes #34

Signed-off-by: Jonasz Małecki <jonasz@upbound.io>
@jonasz-lasut
jonasz-lasut marked this pull request as ready for review October 11, 2026 15:38
@jonasz-lasut
jonasz-lasut merged commit 947b6bb into main Oct 11, 2026
5 checks passed
@jonasz-lasut
jonasz-lasut deleted the feat/typed-resources-and-accessors branch October 11, 2026 15:38
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.

Add accessors for the observed and desired XR and composed resources Add typed variants of get_required_resources

1 participant