Merged
Conversation
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Contributor
There was a problem hiding this comment.
Pull request overview
Synchronizes the TypeScript Crossplane Function SDK with the Python SDK by adding missing utility helpers for resource updates, condition extraction, and Crossplane capability detection, and exposing them via the public SDK entrypoint.
Changes:
- Added
update()resource deep-merge helper andgetCondition()plus aConditioninterface for Kubernetes status conditions. - Added request helpers
advertiseCapabilities(),hasCapability(), andgetWatchedResource()for Crossplane capability/version-aware behavior. - Updated
src/index.tsexports and expanded resource utility unit tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/resource/resource.ts |
Adds Condition, update() deep-merge utility, and getCondition() helper. |
src/resource/resource.test.ts |
Adds/expands unit tests for new resource utilities, including update() and getCondition(). |
src/request/request.ts |
Adds capability detection helpers and watched-resource extraction helper. |
src/index.ts |
Exports the newly added helpers/types (with aliases to avoid naming collisions). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
src/resource/resource.ts:403
getCondition()comparesc.type !== typebefore coercingc.typeto a string, but later it explicitly stringifies non-string fields. As written, a condition with a non-stringtype(e.g., numeric) will never match even though the function otherwise tries to be tolerant of non-string fields. Consider comparing usingString(c.type)(or ensuringtypeof c.type === 'string'up front) so the matching logic aligns with the conversion behavior.
for (const c of conditions) {
if (c.type !== type) {
continue;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
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.
Description of your changes
Summary
Synchronize TypeScript SDK with the Python SDK by adding missing utility functions and improving protobuf resource handling. This update brings feature parity between the TypeScript and Python SDKs for Crossplane function development.
Changes
New Resource Management Functions
update(r: Resource, source): Deep merge functionality to update Resources by merging plain objects, Structs, or Resource objects. Similar to dictionary update semantics - adds new fields and overwrites existing ones.getCondition(resource, type): Extract Kubernetes status conditions from resources by type (e.g., "Ready", "Synced"). Returns aConditionobject with status, reason, message, and lastTransitionTime.Conditioninterface : New TypeScript interface representing Kubernetes status conditions with type, status, reason, message, and lastTransitionTime fields.Capability Detection Functions
advertiseCapabilities(req): Check if Crossplane advertises its capabilities (Crossplane v2.2+). Returns false for older versions that predate capability advertisement.hasCapability(req, cap): Check if Crossplane advertises a specific capability (e.g.,CAPABILITY_REQUIRED_SCHEMAS,CAPABILITY_CONDITIONS). Enables version-aware function behavior.getWatchedResource(req): Get the resource that triggered a WatchOperation by extracting the specialops.crossplane.io/watched-resourcerequirement.Protobuf Type Detection Improvements
update()function with better protobuf Resource vs. plain object detectionconnectionDetails,ready) to distinguish genuine protobuf Resource instancesAPI Exports
Updated index.ts to export new functions:
advertiseCapabilitieshasCapabilitygetWatchedResourcegetConditionupdateResource(aliased fromupdate)Conditiontype (asResourceCondition)Dependencies
ts-deepmergefor reliable deep object mergingI have: