Skip to content

add fromModel helper#11

Merged
stevendborrelli merged 4 commits intocrossplane:mainfrom
stevendborrelli:fromModel
Mar 2, 2026
Merged

add fromModel helper#11
stevendborrelli merged 4 commits intocrossplane:mainfrom
stevendborrelli:fromModel

Conversation

@stevendborrelli
Copy link
Member

@stevendborrelli stevendborrelli commented Mar 2, 2026

Description of your changes

Add a fromModel helper to clean up the fromJson/toJson pattern that emerges from using models:

Before:

dcds["my-pod"] = Resource.fromJSON({
     resource: pod.toJSON()
});

after:

dcds["my-pod"] = fromModel(pod);

Fixes #

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 2, 2026 18:29
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

Adds a fromModel helper to reduce boilerplate when converting Kubernetes model objects (e.g., kubernetes-models) into Resource protobuf wrappers.

Changes:

  • Introduces fromModel() helper that accepts either a model with toJSON() or a plain object and returns a Resource.
  • Adds Vitest coverage for fromModel, plus existing fromObject / toObject behaviors.
  • Updates public exports and README usage example to recommend fromModel.

Reviewed changes

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

File Description
src/resource/resource.ts Adds fromModel helper and reformats a few existing utilities
src/resource/resource.test.ts Adds unit tests for fromModel, fromObject, and toObject
src/index.ts Re-exports fromModel from the package entrypoint
README.md Documents the simplified usage via fromModel

💡 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 6f6d9f9 into crossplane:main Mar 2, 2026
7 checks passed
@stevendborrelli stevendborrelli deleted the fromModel branch March 2, 2026 19:40
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