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
Fallbacks within Union #194
Comments
less risky and complex than |
I'm broadly on board with this. The main bit that needs some resolving here is how we want this to end up represented at the type level. To set it up and review current behaviors: For example, currently, when we have something like the (The higher-level logic in force there is: "the type level representation should be purely a function of the type definition clause, and not regard the representation strategy".) Now: if we roll with this concept of adding a That would be defined, but we lost something. It's not clear how to access the |
Maybe I'm misunderstanding but why couldn't it be |
What's the expected behaviour if we try to match
...? That data would actually match the default, and so the type would be |
@aschmahmann do you want to try and pursue this further or shall we close this for now? |
We've used this DSL description in the Reframe specification ipfs/specs#272. However, I do not currently have the bandwidth to pursue integrating this into the schema-schema. |
I was just thinking through alternatives here and I ended up in two places without realising I was retreading existing territory until late in the thought process:
Sooo, that leads me to a possible in-between. Perhaps what It gets a bit verbose when you compare typed to data model forms of the same data, but maybe that's OK because at least it's not lossy:
I think the same thing might work for inline and envelope unions - you just treat the container as a map and give a Kinded unions are different, an actual
|
Feature request: it should be possible to describe unions with fallback cases.
Using IPLD Schema syntax to describe it, for example, all of the following should be valid:
Motivation
Sometimes it is useful to describe an abstract format for data, such as a list of data that all has the form
{ "sometype" : some-nested-object}
but with different type names. While we could write out every single type name into a keyed union we'd end up with errors if we missed one. Instead it'd be nice if we could allow passing through the data that fits the general format and let the next layer of the application figure out how to deal with it.Here we have an example where we want some consumers of this data to be dumb processers of the data and not have to understand every type that could possibly be in the union even if that means they'll accept some data that's not 100% compliant with a global schema they're unaware of.
When this has been brought up in the past it's been noted that we could just try decoding that fragment of the schema and if it errors then just interpret the data with a different schema that looks like the "Any" schema. This both makes the schemas harder to use (and less descriptive in things like specs) and also this formula is so defined we could just support it.
Alternatives
If there was support for the
probe
union representation #177 this would be easy enough to support instead as (keyed union example below):The text was updated successfully, but these errors were encountered: