Skip to content

Add Required resources and schemas#14

Merged
stevendborrelli merged 5 commits intocrossplane:mainfrom
stevendborrelli:required-resources
Mar 4, 2026
Merged

Add Required resources and schemas#14
stevendborrelli merged 5 commits intocrossplane:mainfrom
stevendborrelli:required-resources

Conversation

@stevendborrelli
Copy link
Member

@stevendborrelli stevendborrelli commented Mar 4, 2026

Description of your changes

This PR adds support for required resources and schemas to the TypeScript SDK, implementing the requireResource(), requireSchema(), getRequiredResource(), getRequiredSchema(), and getRequiredSchemas() functions to match the Go and Python SDK implementations.

These functions enable composition functions to request that Crossplane fetch specific Kubernetes resources or OpenAPI schemas and include them in subsequent function invocations, allowing functions to make decisions based on cluster state or validate resources against schemas.

This feature requires Crossplane v1.15+ for required resources (CAPABILITY_REQUIRED_RESOURCES) and v2.2+ for required schemas (CAPABILITY_REQUIRED_SCHEMAS).

I have:

Signed-off-by: Steven Borrelli <steve@borrelli.org>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
@stevendborrelli stevendborrelli requested a review from Copilot March 4, 2026 06:53
@stevendborrelli stevendborrelli changed the title Add Required resources Add Required resources and schemas Mar 4, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds “required resources” and “required schemas” support to the TypeScript SDK so composition functions can ask Crossplane to fetch specific Kubernetes resources or OpenAPI schemas and return them in subsequent function invocations (aligning behavior with the Go/Python SDKs).

Changes:

  • Added response helpers to request required resources and schemas (requireResource, requireSchema).
  • Added request helpers to read resolved required resources and schemas (getRequiredResource, getRequiredSchema, getRequiredSchemas).
  • Extended the protobuf API/types to include required schemas and capability advertisement, and updated SDK exports/tests accordingly.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/response/response.ts Adds response helpers to declare required resources/schemas.
src/response/response.test.ts Adds unit tests for the new response helpers.
src/request/request.ts Adds request helpers to retrieve resolved required resources/schemas.
src/request/request.test.ts Adds unit tests and updates fixtures for the new request fields/helpers.
src/proto/run_function.proto Extends the protocol definition with required schemas and capabilities.
src/proto/run_function.ts Updates generated TypeScript bindings for new proto fields/types.
src/index.ts Re-exports the new helper functions and additional proto types.
src/resource/resource.ts Formatting/typing cleanup in resource utilities.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +572 to +581
if (!rsp.requirements) {
rsp.requirements = {
extraResources: {},
resources: {},
schemas: {},
};
}
if (!rsp.requirements.resources) {
rsp.requirements.resources = {};
}
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requireResource only ensures requirements.resources exists. If rsp.requirements is set but missing extraResources or schemas, protobuf encoding can throw (it iterates Object.entries over these maps). Consider initializing all Requirements maps (extraResources, resources, schemas) defensively when any are missing.

Copilot uses AI. Check for mistakes.
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Steven Borrelli <steve@borrelli.org>
@stevendborrelli stevendborrelli merged commit 257b405 into crossplane:main Mar 4, 2026
7 checks passed
@stevendborrelli stevendborrelli deleted the required-resources branch March 4, 2026 09: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.

2 participants