Add Required resources and schemas#14
Conversation
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
There was a problem hiding this comment.
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.
| if (!rsp.requirements) { | ||
| rsp.requirements = { | ||
| extraResources: {}, | ||
| resources: {}, | ||
| schemas: {}, | ||
| }; | ||
| } | ||
| if (!rsp.requirements.resources) { | ||
| rsp.requirements.resources = {}; | ||
| } |
There was a problem hiding this comment.
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.
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
There was a problem hiding this comment.
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>
Description of your changes
This PR adds support for required resources and schemas to the TypeScript SDK, implementing the
requireResource(),requireSchema(),getRequiredResource(),getRequiredSchema(), andgetRequiredSchemas()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: