Skip to content

fix!: use arrays for collections instead of sets #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

achingbrain
Copy link
Member

@achingbrain achingbrain commented Oct 5, 2024

Because we have uniqueItems: true in our service definition yaml, fields with type: array are generated as Sets by the typescript generator.

Serialization/deserialization of these types is broken so where we use these APIs we pass arrays with @ts-expect-error anyway.

It also makes pagination harder to use, since we need to set the .after field to get the next page of pins - sets have no guarantee of order so you have to first convert the current set of results into an array and sort it by creation date which is inefficient.

It doesn't look possible to override the use of Set by the generator in a way that works (type-mappings=set=array produces uncompilable code) so manually change the generated code in the same way we have to change the import settings (due, I think, to another option that doesn't work).

Also adds a note to the readme reminding people to do it.

BREAKING CHANGE: fields that were Sets such as PinResults.results and PinsGetRequest.cid are now Arrays

@achingbrain achingbrain requested a review from a team as a code owner October 5, 2024 15:41
Because we have `uniqueItems: true` in our service definition yaml, fields with `type: array` are generated as `Set`s by the typescript generator.

Serialization/deserialization of these types is [broken](OpenAPITools/openapi-generator#11746) so where we use these APIs [we pass arrays with `@ts-expect-error` anyway](https://github.com/ipfs/helia-remote-pinning/blob/main/src/heliaRemotePinner.ts#L155).

It doesn't look possible to override the use of Set by the generator in a way that works (`type-mappings=set=array` produces uncompilable code) so manually change the generated code.

Also adds a note to the readme reminding people to do it.

BREAKING CHANGE: fields that were Sets such as `PinResults.results` and `PinsGetRequest.cid` are now Arrays
@achingbrain achingbrain force-pushed the fix/use-arrays-for-collections branch from 7a25aa1 to ca888c4 Compare October 5, 2024 15:44
@achingbrain
Copy link
Member Author

@lidel, @SgtPooki any comments or objections to merging this?

Copy link
Member

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of having to manually modify more of the generated code here, but I'm okay with this change if you're recommending it.

@achingbrain
Copy link
Member Author

Me neither TBH, I've opened ipfs/pinning-services-api-spec#112 but who knows if we're making changes here any more.

@achingbrain achingbrain merged commit 75736f5 into main Oct 8, 2024
13 checks passed
@achingbrain achingbrain deleted the fix/use-arrays-for-collections branch October 8, 2024 06:00
github-actions bot pushed a commit that referenced this pull request Oct 8, 2024
## [3.0.0](v2.0.0...v3.0.0) (2024-10-08)

### ⚠ BREAKING CHANGES

* fields that were Sets such as `PinResults.results` and `PinsGetRequest.cid` are now Arrays

### Bug Fixes

* use arrays for collections instead of sets ([#70](#70)) ([75736f5](75736f5)), closes [/github.com/ipfs/helia-remote-pinning/blob/main/src/heliaRemotePinner.ts#L155](https://github.com/ipfs-shipyard//github.com/ipfs/helia-remote-pinning/blob/main/src/heliaRemotePinner.ts/issues/L155)
Copy link

github-actions bot commented Oct 8, 2024

🎉 This PR is included in version 3.0.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.

2 participants