Skip to content

Commit 108af7d

Browse files
committed
schemas: specify Any and AnyScalar
1 parent 5ced4dc commit 108af7d

4 files changed

Lines changed: 49 additions & 6 deletions

File tree

schemas/examples.ipldsch

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11

2-
type ExampleWithNullable {String : nullable String}
2+
type ExampleWithNullable {String : nullable &Any}
33

44
type ExampleWithAnonDefns struct {
55
fooField optional {String:String} (rename "foo_field")
66
barField nullable {String:String}
77
bazField {String : nullable String}
88
wozField {String:[nullable String]}
9+
boomField &ExampleWithNullable
910
} representation map

schemas/examples.ipldsch.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"ExampleWithNullable": {
44
"kind": "map",
55
"keyType": "String",
6-
"valueType": "String",
6+
"valueType": {
7+
"kind": "link"
8+
},
79
"valueNullable": true
810
},
911
"ExampleWithAnonDefns": {
@@ -43,6 +45,12 @@
4345
"valueNullable": true
4446
}
4547
}
48+
},
49+
"boomField": {
50+
"type": {
51+
"kind": "link",
52+
"expectedType": "ExampleWithNullable"
53+
}
4654
}
4755
},
4856
"representation": {

schemas/schema-schema.ipldsch

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ type RepresentationKind enum {
135135
| "link"
136136
}
137137

138+
## AnyScalar defines a union of the basic non-complex kinds.
139+
##
140+
## Useful defining usage of IPLD nodes that do compose from other nodes.
141+
##
142+
type AnyScalar union {
143+
| Bool bool
144+
| String string
145+
| Bytes bytes
146+
| Int int
147+
| Float float
148+
} representation kinded
149+
138150
## TypeBool describes a simple boolean type.
139151
## It has no details.
140152
##
@@ -178,15 +190,25 @@ type TypeList struct {
178190
} representation map
179191

180192
## TypeLink describes a hash linking to another object (a CID).
193+
##
181194
## A link also has an "expectedType" that provides a hinting mechanism
182195
## suggesting what we should find if we were to follow the link. This
183196
## cannot be strictly enforced by a node or block-level schema
184197
## validation but may be enforced elsewhere in an application relying on
185198
## a schema.
199+
##
186200
## The expectedType is specified with the `&Any` link shorthand, where
187201
## `Any` may be replaced with a specific type.
202+
##
203+
## Unlike other kinds, we use `&Type` to denote a link Type rather than
204+
## `Link`. In this usage, we replace `Type` the expected Type, with `&Any`
205+
## being shorthand for "a link which may resolve to a type of any kind".
206+
##
207+
## `expectedType` is a String, but it should validate as "Any" or a TypeName
208+
## found somewhere in the schema.
209+
##
188210
type TypeLink struct {
189-
expectedType TypeTerm (implicit "Any")
211+
expectedType String (implicit "Any")
190212
}
191213

192214
## TypeUnion describes a union (sometimes called a "sum type", or
@@ -406,7 +428,7 @@ type StructRepresentation_Map struct {
406428
##
407429
type StructRepresentation_Map_FieldDetails struct {
408430
rename optional String
409-
implicit optional Any # Review: may be better to introduce a small kinded union here which has the essential scalars as members.
431+
implicit optional AnyScalar
410432
}
411433

412434
## StructRepresentation_Tuple describes a way to map a struct type into a list

schemas/schema-schema.ipldsch.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@
6666
"link": null
6767
}
6868
},
69+
"AnyScalar": {
70+
"kind": "union",
71+
"representation": {
72+
"kinded": {
73+
"bool": "Bool",
74+
"string": "String",
75+
"bytes": "Bytes",
76+
"int": "Int",
77+
"float": "Float"
78+
}
79+
}
80+
},
6981
"TypeBool": {
7082
"kind": "struct",
7183
"fields": {},
@@ -148,7 +160,7 @@
148160
"kind": "struct",
149161
"fields": {
150162
"expectedType": {
151-
"type": "TypeTerm"
163+
"type": "String"
152164
}
153165
},
154166
"representation": {
@@ -330,7 +342,7 @@
330342
"optional": true
331343
},
332344
"implicit": {
333-
"type": "Any",
345+
"type": "AnyScalar",
334346
"optional": true
335347
}
336348
},

0 commit comments

Comments
 (0)