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
Support for generics in schema #248
Comments
I think there’s some overlap with #194 where you don’t want to fully specify details and keep type somewhat open |
Generics would be great to have. 👍 It seems like it'd require some major effort to update all the codebases to support this though, so we might want to find specific projects that needs this and find resources to implement it. Is this something related to your UCAN work at web3.storage? |
Not necessarily UCANs related work but indeed while working on web3.storage. We've been specifying our protocols using IPLD schema, but found this limitation very painful. We end up resorting to using TS interfaces to disambiguate. |
Would folks from the web3.storage team have time to work on this and add changes to existing schema implementations? (go + js) |
There's two ways forward with this, both with downsides:
Additional thoughts: Can you do multiple parameters? I can see generics being possible on maps ( Do all of these recursive templates need to work?
|
@Gozala if you want to start experimenting, you could poke around with https://github.com/ipld/js-ipld-schema/blob/master/ipld-schema.pegjs which I think you should be able to follow. If you've not looked at the schema-schema before then that may be an introduction. This might be even more helpful for you in grokking what the schema-schema is trying to do, my TypeScript version of it: https://github.com/ipld/js-ipld-schema/blob/master/schema-schema.ts - this validates the DMT, which is output from the |
Talking to @expede, this is something she and Fission folks would also like to use. (In Rust in particular!) |
2023-01-03 IPLD triage notes: @Gozala are you able to respond here and do the followup work? |
I often find myself resorting to use of
Any
type accompanied with a comment saying it’s actually a generic over ….List, Map, Link are already generic through a special syntax support, but structs and unions aren’t :(
I don’t really know how hard it would be to actually add support for generics, yet I think having syntax for them even if they just desugar to
Any
would be useful way to communicate intent.Could desugar to something like
While improving schemas when used as a documentation tool
The text was updated successfully, but these errors were encountered: