Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
feat: allow inline link definitions for kinded unions
Browse files Browse the repository at this point in the history
e.g.

```
type Foo union {
  | &Blip link
  | Blop string
} representation kinded
```

rather than having to `type BlipLink &Blip` before using it in a
kinded union.
  • Loading branch information
rvagg committed Jun 14, 2021
1 parent 9bab36f commit bf71b7b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 9 additions & 1 deletion schemas/schema-schema.ipldsch
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,15 @@ type UnionRepresentation union {
##
## The referenced type must of course produce the RepresentationKind it's
## matched with!
type UnionRepresentation_Kinded {RepresentationKind:TypeName}
type UnionRepresentation_Kinded {RepresentationKind:KindedType}

## "KindedType" is used to allow inline link definitions within a kinded union
## as a shorthand rather than requiring all links be defined as a separate type
## before used within a kinded union.
type KindedType union {
| TypeName "string"
| TypeLink "link"
} representation kinded

## "Keyed" union representations will encode as a map, where the map has
## exactly one entry, the key string of which will be used to look up the name
Expand Down
11 changes: 10 additions & 1 deletion schemas/schema-schema.ipldsch.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,16 @@
"UnionRepresentation_Kinded": {
"kind": "map",
"keyType": "RepresentationKind",
"valueType": "TypeName"
"valueType": "KindedType"
},
"KindedType": {
"kind": "union",
"representation": {
"kinded": {
"string": "TypeName",
"link": "TypeLink"
}
}
},
"UnionRepresentation_Keyed": {
"kind": "map",
Expand Down

0 comments on commit bf71b7b

Please sign in to comment.