Skip to content

Match python sdk#15

Merged
stevendborrelli merged 5 commits intocrossplane:mainfrom
stevendborrelli:match-python-sdk
Mar 5, 2026
Merged

Match python sdk#15
stevendborrelli merged 5 commits intocrossplane:mainfrom
stevendborrelli:match-python-sdk

Conversation

@stevendborrelli
Copy link
Member

@stevendborrelli stevendborrelli commented Mar 4, 2026

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 a Condition object with status, reason, message, and lastTransitionTime.

  • Condition interface : 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 special ops.crossplane.io/watched-resource requirement.

Protobuf Type Detection Improvements

  • Enhanced update() function with better protobuf Resource vs. plain object detection
  • Check for protobuf-specific fields (connectionDetails, ready) to distinguish genuine protobuf Resource instances
  • Proper handling of both wrapped Resource objects and plain JavaScript objects

API Exports

Updated index.ts to export new functions:

  • advertiseCapabilities
  • hasCapability
  • getWatchedResource
  • getCondition
  • updateResource (aliased from update)
  • Condition type (as ResourceCondition)

Dependencies

  • Added ts-deepmerge for reliable deep object merging

I have:

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

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 and getCondition() plus a Condition interface for Kubernetes status conditions.
  • Added request helpers advertiseCapabilities(), hasCapability(), and getWatchedResource() for Crossplane capability/version-aware behavior.
  • Updated src/index.ts exports 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>
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 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() compares c.type !== type before coercing c.type to a string, but later it explicitly stringifies non-string fields. As written, a condition with a non-string type (e.g., numeric) will never match even though the function otherwise tries to be tolerant of non-string fields. Consider comparing using String(c.type) (or ensuring typeof 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>
@stevendborrelli stevendborrelli merged commit e5816ba into crossplane:main Mar 5, 2026
7 checks passed
@stevendborrelli stevendborrelli deleted the match-python-sdk branch March 5, 2026 14:02
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