Skip to content

Conversation

@colbyfayock
Copy link
Collaborator

Description

This PR migrates the repo off of Zod schemas toward pure TS with JSDoc annotations that can eventually be used to extract metadata for display in docs.

Generally the external behavior should be identical, with obvious exceptions where schema entry points are no longer available etc., so this would constitute a breaking change for consumers relying on those entrypoints or whose inputs may no longer be valid with new type safety around video/image options.

I've also updated all the tests to .ts so we can be sure the types for the API are working as we expect going forward.

Although all the tests are passing, the doc generation issue remains unsolved, causing the repo-wide build to fail, so that will need to be updated to use a JSDoc parsing tool. However, it should be quite straightforward to wire that up in place of the previous Zod-embedded metadata.

For now, I'm opening this against the beta branch so the required JSDoc parsing logic can be added and other changes can be experimented with before broader consumption.

Issue Ticket Number

N/A

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Fix or improve the documentation
  • This change requires a documentation update

Checklist

(Still a draft, need to figure out how to work around missing schemas in build)

  • I have followed the contributing guidelines of this project as mentioned in CONTRIBUTING.md
  • I have created an issue ticket for this PR
  • I have checked to ensure there aren't other open Pull Requests for the same update/change?
  • I have performed a self-review of my own code
  • I have run tests locally to ensure they all pass
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes needed to the documentation

BREAKING CHANGES: removes zod schemas, refactors type system

Description

Issue Ticket Number

Fixes #<ISSUE_NUMBER>

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Fix or improve the documentation
  • This change requires a documentation update

Checklist

  • I have followed the contributing guidelines of this project as mentioned in CONTRIBUTING.md
  • I have created an issue ticket for this PR
  • I have checked to ensure there aren't other open Pull Requests for the same update/change?
  • I have performed a self-review of my own code
  • I have run tests locally to ensure they all pass
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes needed to the documentation

ssalbdivad and others added 5 commits October 18, 2024 14:11
…fy parsing (#217)

# Description

<!-- Include a summary of the change made and also list the dependencies
that are required if any -->

This PR migrates the repo off of Zod schemas toward pure TS with JSDoc
annotations that can eventually be used to extract metadata for display
in docs.

Generally the external behavior should be identical, with obvious
exceptions where schema entry points are no longer available etc., so
this would constitute a breaking change for consumers relying on those
entrypoints or whose inputs may no longer be valid with new type safety
around video/image options.

I've also updated all the tests to `.ts` so we can be sure the types for
the API are working as we expect going forward.

Although all the tests are passing, the doc generation issue remains
unsolved, causing the repo-wide build to fail, so that will need to be
updated to use a JSDoc parsing tool. However, it should be quite
straightforward to wire that up in place of the previous Zod-embedded
metadata.

For now, I'm opening this against the `beta` branch so the required
JSDoc parsing logic can be added and other changes can be experimented
with before broader consumption.

## Issue Ticket Number

N/A

<!-- Specify above which issue this fixes by referencing the issue
number (`#<ISSUE_NUMBER>`) or issue URL. -->
<!-- Example: Fixes
https://github.com/colbyfayock/cloudinary-util/issues/<ISSUE_NUMBER> -->

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [X] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Fix or improve the documentation
- [X] This change requires a documentation update

# Checklist

(Still a draft, need to figure out how to work around missing schemas in
build)

<!-- These must all be followed and checked. -->

- [ ] I have followed the contributing guidelines of this project as
mentioned in [CONTRIBUTING.md](/CONTRIBUTING.md)
- [ ] I have created an
[issue](https://github.com/colbyfayock/cloudinary-util/issues) ticket
for this PR
- [ ] I have checked to ensure there aren't other open [Pull
Requests](https://github.com/colbyfayock/cloudinary-util/pulls) for the
same update/change?
- [ ] I have performed a self-review of my own code
- [ ] I have run tests locally to ensure they all pass
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes needed to the documentation

BREAKING CHANGES: removes zod schemas, refactors type system
# [@cloudinary-util/util-v5.0.0-beta.1](https://github.com/cloudinary-community/cloudinary-util/compare/@cloudinary-util/util-v4.0.0...@cloudinary-util/util-v5.0.0-beta.1) (2024-10-18)

### Features

* migrate Zod to pure TS w/ JSDoc, improve type safety and simplify parsing ([#217](#217)) ([f605f26](f605f26))
# [@cloudinary-util/url-loader-v6.0.0-beta.1](https://github.com/cloudinary-community/cloudinary-util/compare/@cloudinary-util/url-loader-v5.10.5...@cloudinary-util/url-loader-v6.0.0-beta.1) (2024-10-18)

### Features

* migrate Zod to pure TS w/ JSDoc, improve type safety and simplify parsing ([#217](#217)) ([f605f26](f605f26))
# [@cloudinary-util/types-v2.0.0-beta.1](https://github.com/cloudinary-community/cloudinary-util/compare/@cloudinary-util/types-v1.5.11...@cloudinary-util/types-v2.0.0-beta.1) (2024-10-18)

### Features

* migrate Zod to pure TS w/ JSDoc, improve type safety and simplify parsing ([#217](#217)) ([f605f26](f605f26))
@colbyfayock
Copy link
Collaborator Author

image

packages released for testing, may need to install all the beta dependencies for it to work properly

Mrinank-Bhowmick and others added 8 commits October 22, 2024 08:31
# Description

This pull request introduces TypeScript types for the Cloudinary Product
Gallery Widget. It defines a comprehensive interface for the widget,
following the reference documentation for better type safety and
improved developer experience. No additional dependencies are required
for this change.

## Issue Ticket Number
199 

Fixes #199 


## Type of change

<!-- Please select all options that are applicable. -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Fix or improve the documentation
- [ ] This change requires a documentation update

# Checklist

<!-- These must all be followed and checked. -->

- [x] I have followed the contributing guidelines of this project as
mentioned in [CONTRIBUTING.md](/CONTRIBUTING.md)
- [x] I have created an
[issue](https://github.com/colbyfayock/cloudinary-util/issues) ticket
for this PR
- [x] I have checked to ensure there aren't other open [Pull
Requests](https://github.com/colbyfayock/cloudinary-util/pulls) for the
same update/change?
- [x] I have performed a self-review of my own code
- [x] I have run tests locally to ensure they all pass
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes needed to the documentation
# [@cloudinary-util/types-v2.0.0-beta.2](https://github.com/cloudinary-community/cloudinary-util/compare/@cloudinary-util/types-v2.0.0-beta.1...@cloudinary-util/types-v2.0.0-beta.2) (2024-10-22)

### Bug Fixes

* Add TypeScript Types for Cloudinary Product Gallery Widget ([#218](#218)) ([05cd33e](05cd33e)), closes [#199](#199)
# Description

Based on a conversation with @colbyfayock, this adds back enumerated
props for each plugin.

They're collected via two top-level exports, `cloudinaryPluginProps` and
`cloudinaryPluginKeys`, so we can expose which props are handled by
cloudinary without all the implementation details of each plugin.
@colbyfayock
Copy link
Collaborator Author

@ssalbdivad - @ghostdevv noticed an issue where when using only CldImage, because all of the plugins run, she noticed ABR plugin warnings

CldImage would not directly set any assetType but assetType should default to image (or at least it did)

any ideas what might be causing that?

image

@ssalbdivad
Copy link

@colbyfayock What API do you mean specifically by "only CldImage"?

I don't think the logic around defaulting assetType changed at all in constructCloudinaryUrl (see below).

image

@colbyfayock
Copy link
Collaborator Author

the example given was a page that simply only loaded CldImage, so it appears by using CldImage (asset type image), we get warnings about trying to use video plugins

@ssalbdivad
Copy link

ssalbdivad commented Oct 25, 2024

@colbyfayock Ahh okay I see the issue here. You can fix it by migrating AbrPlugin to use the new applyWhen logic to make it clearer when the plugin should do anything. It also handles the typeof check for you implicitly!

In abr.ts:

  applyWhen: "streamingProfile",
  apply: (asset, opts) => {
    asset.addTransformation(`sp_${opts.streamingProfile}`);

    return {};
  },

applyWhen accepts either a single key representing a key that must have a value for the plugin to apply (streamingProfile, in this case). This covers most of the cases pretty easily and narrows what you get for opts in apply so that you know that key is defined. However, there's a fallback for more complex logic where you can just provide a function that can access all the options and return a boolean for whether the plugin should apply. It was an oversight on my part not to add that as a note to the plugin function so maybe you want to copy some of it over :P

Would potentially be worth migrating more of these over in the future as the inverse problem could occur for a video asset where you get a bunch of warnings about image types. I think it should result in the logic for actually handling what the plugin does at that point much clearer though!

@ssalbdivad
Copy link

@colbyfayock Also looking back on why exactly this change was made, some of the motivation was that we didn't have the explicit props object we just added back in that listed the relevant keys.

Potentially you could remove applyWhen in favor of just checking if any of those props are present? I wanted to leave it more open ended because some of the plugin logic seemed complex and I wasn't sure there was a 1:1 between one of the owned props being present and that plugin applying.

I think in either case, it would be super helpful for separation of concerns if the logic of "should this plugin do anything based on these options" lived outside each individual plugin, so if we can do that by adding some centralized logic that checks for props overlap similarly to before and then only run apply in those cases, that may be ideal.

colbyfayock and others added 9 commits October 25, 2024 14:33
# [@cloudinary-util/url-loader-v6.0.0-beta.4](https://github.com/cloudinary-community/cloudinary-util/compare/@cloudinary-util/url-loader-v6.0.0-beta.3...@cloudinary-util/url-loader-v6.0.0-beta.4) (2024-10-25)

### Bug Fixes

* adding applyWhen to streaming profile to prevent abr plugin from running ([ef7e57a](ef7e57a))
* adding string and number back to replaceBackground ([672009a](672009a))
…lwaysApply exception (#228)

# Description

<!-- Include a summary of the change made and also list the dependencies
that are required if any -->

Simplify applyWhen to just check for presence of props from the new
props key as discussed with @colbyfayock, add an alwaysApply key that
can be used for exceptions like SanitizePlugin that should always run
regardless of the presence of associated keys.

This is a rebased version of
#226.

## Issue Ticket Number

Fixes #<ISSUE_NUMBER>

<!-- Specify above which issue this fixes by referencing the issue
number (`#<ISSUE_NUMBER>`) or issue URL. -->
<!-- Example: Fixes
https://github.com/colbyfayock/cloudinary-util/issues/<ISSUE_NUMBER> -->

## Type of change

<!-- Please select all options that are applicable. -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Fix or improve the documentation
- [ ] This change requires a documentation update

# Checklist

<!-- These must all be followed and checked. -->

- [ ] I have followed the contributing guidelines of this project as
mentioned in [CONTRIBUTING.md](/CONTRIBUTING.md)
- [ ] I have created an
[issue](https://github.com/colbyfayock/cloudinary-util/issues) ticket
for this PR
- [ ] I have checked to ensure there aren't other open [Pull
Requests](https://github.com/colbyfayock/cloudinary-util/pulls) for the
same update/change?
- [ ] I have performed a self-review of my own code
- [ ] I have run tests locally to ensure they all pass
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes needed to the documentation
# [@cloudinary-util/url-loader-v6.0.0-beta.6](https://github.com/cloudinary-community/cloudinary-util/compare/@cloudinary-util/url-loader-v6.0.0-beta.5...@cloudinary-util/url-loader-v6.0.0-beta.6) (2024-10-31)

### Bug Fixes

* remove applyWhen in favor of explicit props overlap check with alwaysApply exception ([#228](#228)) ([90d07c2](90d07c2))
# [@cloudinary-util/types-v2.0.0-beta.3](https://github.com/cloudinary-community/cloudinary-util/compare/@cloudinary-util/types-v2.0.0-beta.2...@cloudinary-util/types-v2.0.0-beta.3) (2024-10-31)

### Bug Fixes

* remove applyWhen in favor of explicit props overlap check with alwaysApply exception ([#228](#228)) ([90d07c2](90d07c2))
# [@cloudinary-util/util-v5.0.0-beta.2](https://github.com/cloudinary-community/cloudinary-util/compare/@cloudinary-util/util-v5.0.0-beta.1...@cloudinary-util/util-v5.0.0-beta.2) (2024-10-31)

### Bug Fixes

* remove applyWhen in favor of explicit props overlap check with alwaysApply exception ([#228](#228)) ([90d07c2](90d07c2))
@colbyfayock colbyfayock merged commit 6740562 into main Nov 1, 2024
1 of 2 checks passed
@colbyfayock colbyfayock deleted the beta branch November 1, 2024 18:32
@github-actions
Copy link

github-actions bot commented Nov 1, 2024

🎉 This PR is included in version @cloudinary-util/util-v4.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

github-actions bot commented Nov 1, 2024

🎉 This PR is included in version @cloudinary-util/url-loader-v5.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

github-actions bot commented Nov 1, 2024

🎉 This PR is included in version @cloudinary-util/types-v1.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants