Skip to content

Commit

Permalink
fix: schema-schema fixes from actual use
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jun 23, 2021
1 parent 0d255c6 commit 7cf823c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
49 changes: 30 additions & 19 deletions schema-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ export type KindUnion = {}
export type KindStruct = {}
export type KindEnum = {}

export type TypeBool = {}
export type TypeString = {}
export type TypeBool = { kind: "bool" }
export type TypeString = { kind: "string" }
export type TypeBytes = {
kind: "bytes"
representation?: BytesRepresentation
}
export type BytesRepresentation =
{ bytes: BytesRepresentation_Bytes }
| { advanced: AdvancedDataLayoutName }
export type BytesRepresentation_Bytes = {}
export type TypeInt = {}
export type TypeFloat = {}
export type TypeInt = { kind: "int" }
export type TypeFloat = { kind: "float" }
export type TypeNull = { kind: "null" }
export type TypeMap = {
kind: "map"
keyType: TypeName
valueType?: TypeTerm
valueType: TypeTerm
valueNullable?: KindBool
representation?: MapRepresentation
}
Expand All @@ -41,6 +44,7 @@ export type MapRepresentation_StringPairs = {
}
export type MapRepresentation_ListPairs = {}
export type TypeList = {
kind: "list"
valueType: TypeTerm
valueNullable?: KindBool
representation?: ListRepresentation
Expand All @@ -50,34 +54,37 @@ export type ListRepresentation =
| { advanced: AdvancedDataLayoutName }
export type ListRepresentation_List = {}
export type TypeLink = {
kind: "link"
expectedType?: KindString
}
export type TypeUnion = {
representation?: UnionRepresentation
kind: "union"
representation: UnionRepresentation
}
export type UnionRepresentation =
{ kinded: UnionRepresentation_Kinded }
| { keyed: UnionRepresentation_Keyed }
| { envelope: UnionRepresentation_Envelope }
| { inline: UnionRepresentation_Inline }
| { byteprefix: UnionRepresentation_BytePrefix }
export type UnionRepresentation_Kinded = Record<RepresentationKind, TypeName>
export type UnionRepresentation_Keyed = Record<KindString, TypeName>
export type UnionRepresentation_Kinded = { [k in RepresentationKind]?: TypeName }
export type UnionRepresentation_Keyed = { [k in KindString]: TypeName }
export type UnionRepresentation_Envelope = {
discriminantKey: KindString
contentKey: KindString
discriminantTable: Record<KindString, TypeName>
discriminantTable: { [ k in KindString]: TypeName }
}
export type UnionRepresentation_Inline = {
discriminantKey: KindString
discriminantTable: Record<KindString, TypeName>
discriminantTable: { [ k in KindString]: TypeName }
}
export type UnionRepresentation_BytePrefix = {
discriminantTable: Record<TypeName, KindInt>
discriminantTable: { [ k in TypeName]: KindInt }
}

export type TypeStruct = {
fields: Record<FieldName, StructField>
kind: "struct"
fields: { [ k in FieldName]: StructField }
representation?: StructRepresentation
}
export type FieldName = string
Expand All @@ -90,16 +97,16 @@ export type TypeTerm =
TypeName
| InlineDefn
export type InlineDefn =
{ map: TypeMap }
| { list: TypeList }
TypeMap
| TypeList
export type StructRepresentation =
{ map: StructRepresentation_Map }
| { tuple: StructRepresentation_Tuple }
| { stringpairs: StructRepresentation_StringPairs }
| { stringjoin: StructRepresentation_StringJoin }
| { listpairs: StructRepresentation_ListPairs }
export type StructRepresentation_Map = {
fields?: Record<FieldName, StructRepresentation_Map_FieldDetails>
fields?: { [ k in FieldName]: StructRepresentation_Map_FieldDetails }
}
export type StructRepresentation_Map_FieldDetails = {
rename?: KindString
Expand All @@ -120,21 +127,23 @@ export type StructRepresentation_ListPairs = {}


export type TypeEnum = {
members: Record<EnumValue, KindNull>
kind: "enum"
members: { [ k in EnumValue]: KindNull }
representation: EnumRepresentation
}
export type EnumValue = string
export type EnumRepresentation =
{ string: EnumRepresentation_String }
| { int: EnumRepresentation_Int }
export type EnumRepresentation_String = Record<EnumValue, KindString>
export type EnumRepresentation_Int = Record<EnumValue, KindInt>
export type EnumRepresentation_String = { [ k in EnumValue]: KindString }
export type EnumRepresentation_Int = { [ k in EnumValue]: KindInt }
export type TypeCopy = {
kind: "copy"
fromType: TypeName
}

export type TypeName = string
export type SchemaMap = { TypeName: Type }
export type SchemaMap = { [ k in TypeName]: Type }
export type AdvancedDataLayoutName = string
export type Schema = {
types: SchemaMap
Expand All @@ -145,6 +154,7 @@ export type Type =
| TypeBytes
| TypeInt
| TypeFloat
| TypeNull
| TypeMap
| TypeList
| TypeLink
Expand Down Expand Up @@ -172,6 +182,7 @@ export type RepresentationKind =
| "bytes"
| "int"
| "float"
| "null"
| "map"
| "list"
| "link"
Expand Down
3 changes: 2 additions & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Schema } from './schema-schema'

export function parse(schemaText: string): Schema
function parse(schemaText: string): Schema
export { Schema, parse }

0 comments on commit 7cf823c

Please sign in to comment.