Skip to content

Commit 33db763

Browse files
committed
fix: update schema-schema types
1 parent 668da58 commit 33db763

File tree

2 files changed

+76
-59
lines changed

2 files changed

+76
-59
lines changed

bin/collect-input.js

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ async function read (filename) {
2929
return fs.promises.readFile(filename, 'utf8')
3030
}
3131

32+
/**
33+
* @param {string[]} files
34+
* @returns {{ filename: string, contents }[]}
35+
*/
3236
export async function collectInput (files) {
3337
let input = []
3438

schema-schema.ts

+72-59
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,44 @@ export type KindLink = {}
1010
export type KindUnion = {}
1111
export type KindStruct = {}
1212
export type KindEnum = {}
13-
export type TypeBool = { kind: "bool" }
14-
export type TypeString = { kind: "string" }
15-
export type TypeBytes = {
16-
kind: "bytes"
17-
representation?: BytesRepresentation
13+
14+
export type TypeDefn =
15+
{ bool: TypeDefnBool }
16+
| { string: TypeDefnString }
17+
| { bytes: TypeDefnBytes }
18+
| { int: TypeDefnInt }
19+
| { float: TypeDefnFloat }
20+
| { map: TypeDefnMap }
21+
| { list: TypeDefnList }
22+
| { link: TypeDefnLink }
23+
| { union: TypeDefnUnion }
24+
| { struct: TypeDefnStruct }
25+
| { enum: TypeDefnEnum }
26+
| { unit: TypeDefnUnit }
27+
| { any: TypeDefnAny }
28+
| { copy: TypeDefnCopy }
29+
| { null: TypeDefnNull } // TODO: not in schema-schema, what do?
30+
31+
export type TypeDefnBool = {}
32+
export type TypeDefnString = {}
33+
export type TypeDefnBytes = {
34+
representation?: BytesRepresentation // TODO: not optional in schema-schema
1835
}
1936
export type BytesRepresentation =
2037
{ bytes: BytesRepresentation_Bytes }
2138
| { advanced: AdvancedDataLayoutName }
2239
export type BytesRepresentation_Bytes = {}
23-
export type TypeInt = { kind: "int" }
24-
export type TypeFloat = { kind: "float" }
25-
export type TypeNull = { kind: "null" }
26-
export type TypeMap = {
27-
kind: "map"
40+
export type TypeDefnInt = {}
41+
export type TypeDefnFloat = {}
42+
export type TypeDefnNull = {} // TODO: not in schema-schema, what do?
43+
export type TypeDefnMap = {
2844
keyType: TypeName
29-
valueType: TypeTerm
45+
valueType: TypeNameOrInlineDefn
3046
valueNullable?: KindBool
3147
representation?: MapRepresentation
3248
}
3349
export type MapRepresentation =
34-
{ map: MapRepresentation_Map }
50+
{ map: MapRepresentation_Map } // TODO: not in schema-schema - put it there
3551
| { stringpairs: MapRepresentation_StringPairs }
3652
| { listpairs: MapRepresentation_ListPairs }
3753
| { advanced: AdvancedDataLayoutName }
@@ -41,63 +57,65 @@ export type MapRepresentation_StringPairs = {
4157
entryDelim: KindString
4258
}
4359
export type MapRepresentation_ListPairs = {}
44-
export type TypeList = {
45-
kind: "list"
46-
valueType: TypeTerm
60+
export type TypeDefnList = {
61+
valueType: TypeNameOrInlineDefn
4762
valueNullable?: KindBool
4863
representation?: ListRepresentation
4964
}
5065
export type ListRepresentation =
51-
{ list: ListRepresentation_List }
66+
{ list: ListRepresentation_List } // TODO: not in schema-schema - put it there?
5267
| { advanced: AdvancedDataLayoutName }
5368
export type ListRepresentation_List = {}
54-
export type TypeLink = {
55-
kind: "link"
69+
export type TypeDefnLink = {
5670
expectedType?: KindString
5771
}
58-
export type TypeUnion = {
59-
kind: "union"
72+
export type TypeDefnUnion = {
73+
members: UnionMember[]
6074
representation: UnionRepresentation
6175
}
76+
export type UnionMember =
77+
TypeName
78+
| UnionMemberInlineDefn
79+
export type UnionMemberInlineDefn =
80+
{ link: TypeDefnLink }
6281
export type UnionRepresentation =
6382
{ kinded: UnionRepresentation_Kinded }
6483
| { keyed: UnionRepresentation_Keyed }
6584
| { envelope: UnionRepresentation_Envelope }
6685
| { inline: UnionRepresentation_Inline }
6786
| { stringprefix: UnionRepresentation_StringPrefix }
6887
| { bytesprefix: UnionRepresentation_BytesPrefix }
69-
export type UnionRepresentation_Kinded = { [k in RepresentationKind]?: KindedType }
70-
export type KindedType = TypeName | TypeLink
71-
export type UnionRepresentation_Keyed = { [k in KindString]: TypeName }
88+
export type UnionRepresentation_Kinded = { [k in RepresentationKind]?: UnionMember }
89+
export type UnionRepresentation_Keyed = { [k in KindString]: UnionMember }
7290
export type UnionRepresentation_Envelope = {
7391
discriminantKey: KindString
7492
contentKey: KindString
75-
discriminantTable: { [ k in KindString]: TypeName }
93+
discriminantTable: { [ k in KindString]: UnionMember }
7694
}
7795
export type UnionRepresentation_Inline = {
7896
discriminantKey: KindString
79-
discriminantTable: { [ k in KindString]: TypeName }
97+
discriminantTable: { [ k in HexString]: TypeName }
8098
}
99+
export type HexString = string
81100
export type UnionRepresentation_StringPrefix = { [ k in KindString]: TypeName }
82101
export type UnionRepresentation_BytesPrefix = { [ k in KindString]: TypeName }
83-
export type TypeStruct = {
84-
kind: "struct"
102+
export type TypeDefnStruct = {
85103
fields: { [ k in FieldName]: StructField }
86104
representation?: StructRepresentation
87105
}
88106
export type FieldName = string
89107
export type StructField = {
90-
type: TypeTerm
108+
type: TypeNameOrInlineDefn
91109
optional?: KindBool
92110
nullable?: KindBool
93111
}
94-
export type TypeTerm =
112+
export type TypeNameOrInlineDefn =
95113
TypeName
96114
| InlineDefn
97115
export type InlineDefn =
98-
TypeMap
99-
| TypeList
100-
| TypeLink
116+
{ map: TypeDefnMap }
117+
| { list: TypeDefnList }
118+
| { link: TypeDefnLink }
101119
export type StructRepresentation =
102120
{ map: StructRepresentation_Map }
103121
| { tuple: StructRepresentation_Tuple }
@@ -123,41 +141,36 @@ export type StructRepresentation_StringJoin = {
123141
fieldOrder?: FieldName[]
124142
}
125143
export type StructRepresentation_ListPairs = {}
126-
export type TypeEnum = {
127-
kind: "enum"
128-
members: { [ k in EnumValue]: KindNull }
144+
export type TypeDefnEnum = {
145+
members: EnumMember[]
129146
representation: EnumRepresentation
130147
}
131-
export type EnumValue = string
148+
export type EnumMember = string
132149
export type EnumRepresentation =
133150
{ string: EnumRepresentation_String }
134151
| { int: EnumRepresentation_Int }
135-
export type EnumRepresentation_String = { [ k in EnumValue]: KindString }
136-
export type EnumRepresentation_Int = { [ k in EnumValue]: KindInt }
137-
export type TypeCopy = {
138-
kind: "copy"
152+
export type EnumRepresentation_String = { [ k in EnumMember]: KindString }
153+
export type EnumRepresentation_Int = { [ k in EnumMember]: KindInt }
154+
export type TypeDefnCopy = {
139155
fromType: TypeName
140156
}
157+
export type TypeDefnUnit = {
158+
representation: UnitRepresentation
159+
}
160+
export type UnitRepresentation =
161+
"null"
162+
| "true"
163+
| "false"
164+
| "emptymap"
165+
export type TypeDefnAny = {}
141166
export type TypeName = string
142-
export type SchemaMap = { [ k in TypeName]: Type }
143-
export type AdvancedDataLayoutName = string
144167
export type Schema = {
145-
types: SchemaMap
146-
}
147-
export type Type =
148-
TypeBool
149-
| TypeString
150-
| TypeBytes
151-
| TypeInt
152-
| TypeFloat
153-
| TypeNull
154-
| TypeMap
155-
| TypeList
156-
| TypeLink
157-
| TypeUnion
158-
| TypeStruct
159-
| TypeEnum
160-
| TypeCopy
168+
types: { [ k in TypeName]: TypeDefn }
169+
advanced?: AdvancedDataLayoutMap
170+
}
171+
export type AdvancedDataLayoutName = string
172+
export type AdvancedDataLayoutMap = { [ k in AdvancedDataLayoutName ]: AdvancedDataLayout }
173+
export type AdvancedDataLayout = {}
161174
export type TypeKind =
162175
KindBool
163176
| KindString
@@ -176,7 +189,7 @@ export type RepresentationKind =
176189
| "bytes"
177190
| "int"
178191
| "float"
179-
| "null"
192+
| "null" // TODO: not in schema-schema, wot do?
180193
| "map"
181194
| "list"
182195
| "link"

0 commit comments

Comments
 (0)