From e8167fa0cf2d7edc3dd7bd29e1e382921c5e7992 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Fri, 30 Dec 2022 16:11:35 -0500 Subject: [PATCH 01/20] initial abi 0.2 draft --- abi/abi-0.2.ts | 167 ++++++++++++++++++++++++++++++++++++ abi/examples/method.graphql | 5 ++ abi/examples/method.ts | 26 ++++++ abi/examples/sanity.graphql | 19 ++++ abi/examples/sanity.ts | 95 ++++++++++++++++++++ abi/examples/todo | 5 ++ abi/principles.md | 7 ++ 7 files changed, 324 insertions(+) create mode 100644 abi/abi-0.2.ts create mode 100644 abi/examples/method.graphql create mode 100644 abi/examples/method.ts create mode 100644 abi/examples/sanity.graphql create mode 100644 abi/examples/sanity.ts create mode 100644 abi/examples/todo create mode 100644 abi/principles.md diff --git a/abi/abi-0.2.ts b/abi/abi-0.2.ts new file mode 100644 index 0000000..c5e2409 --- /dev/null +++ b/abi/abi-0.2.ts @@ -0,0 +1,167 @@ +/// ABIs + +export interface Abi extends AbiDefs { + version: "0.2"; + imports?: ImportedAbi[]; +} + +interface ImportedAbi extends AbiDefs { + namespace: string; + uri: string; +} + +interface AbiDefs { + methods?: MethodDef[]; + objects?: ObjectDef[]; + enums?: EnumDef[]; + env?: EnvDef; +} + +/// Definitions (user-defined) + +type AnyDef = + | MethodDef + | ArgumentDef + | ResultDef + | ObjectDef + | PropertyDef + | EnumDef + | EnvDef; + +type DefKind = + | "Method" + | "Argument" + | "Result" + | "Object" + | "Property" + | "Enum" + | "Env"; + +interface Def { + kind: DefKind; +} + +interface NamedDef extends Def { + name: string; + comment?: string; +} + +interface TypeDef extends Def { + required: boolean; + type: AnyType; +} + +interface NamedTypeDef extends NamedDef, TypeDef { } + +interface MethodDef extends NamedDef { + kind: "Method"; + args: ArgumentDef[]; + result: ResultDef; +} + +interface ArgumentDef extends NamedTypeDef { + kind: "Argument"; +} + +interface ResultDef extends TypeDef { + kind: "Result"; +} + +interface ObjectDef extends NamedDef { + kind: "Object"; + props: PropertyDef[]; +} + +interface PropertyDef extends NamedTypeDef { + kind: "Property"; +} + +interface EnumDef extends NamedDef { + kind: "Enum"; + constants: string[]; +} + +interface EnvDef extends NamedDef { + kind: "Env"; + name: "Env"; + props: PropertyDef[]; +} + +/// Types (built-ins) + +type AnyType = + | ScalarType + | ArrayType + | MapType + | RefType; + +type TypeKind = + | "Scalar" + | "Array" + | "Map" + | "Ref"; + +interface Type { + kind: TypeKind; +} + +interface ScalarType< + TScalarTypeName extends ScalarTypeName = ScalarTypeName +> extends Type { + kind: "Scalar"; + scalar: TScalarTypeName; +} + +interface ArrayType extends Type { + kind: "Array"; + item: AnyType; +} + +interface MapType extends Type { + kind: "Map"; + key: ScalarType; + value: AnyType; +} + +interface RefType extends Type { + kind: "Ref"; + ref: string; +} + +/// Constants + +const scalarTypeSet = { + UInt: "UInt", + UInt8: "UInt8", + UInt16: "UInt16", + UInt32: "UInt32", + Int: "Int", + Int8: "Int8", + Int16: "Int16", + Int32: "Int32", + String: "String", + Boolean: "Boolean", + Bytes: "Bytes", + // TODO: remove complex types + BigInt: "BigInt", + BigNumber: "BigNumber", + JSON: "JSON", +}; +type ScalarTypeSet = typeof scalarTypeSet; + +type ScalarTypeName = keyof ScalarTypeSet; + +const mapKeyTypeSet = { + UInt: "UInt", + UInt8: "UInt8", + UInt16: "UInt16", + UInt32: "UInt32", + Int: "Int", + Int8: "Int8", + Int16: "Int16", + Int32: "Int32", + String: "String", +}; +type MapKeyTypeSet = typeof mapKeyTypeSet; + +type MapKeyTypeName = keyof MapKeyTypeSet; diff --git a/abi/examples/method.graphql b/abi/examples/method.graphql new file mode 100644 index 0000000..325e224 --- /dev/null +++ b/abi/examples/method.graphql @@ -0,0 +1,5 @@ +type Module { + method( + arg: String! + ): String! +} diff --git a/abi/examples/method.ts b/abi/examples/method.ts new file mode 100644 index 0000000..cc507d8 --- /dev/null +++ b/abi/examples/method.ts @@ -0,0 +1,26 @@ +import { Abi } from "../abi-0.2"; + +const abi: Abi = { + version: "0.2", + methods: [ + { + kind: "Method", + name: "method", + args: [ + { + kind: "Argument", + name: "arg", + type: { + kind: "Scalar", + scalar: "String" + }, + required: true, + } + ], + result: { + kind: "Scalar", + scalar: "String" + } + } + ] +}; diff --git a/abi/examples/sanity.graphql b/abi/examples/sanity.graphql new file mode 100644 index 0000000..4bdf4de --- /dev/null +++ b/abi/examples/sanity.graphql @@ -0,0 +1,19 @@ +type Module { + # some comment + method1( + arg: Bytes! + ): UInt32! + + method2( + custom: Custom! + ): Int32 +} + +type Custom { + prop1: String! + nested: Nested +} + +type Nested { + prop: UInt8 +} diff --git a/abi/examples/sanity.ts b/abi/examples/sanity.ts new file mode 100644 index 0000000..0756c82 --- /dev/null +++ b/abi/examples/sanity.ts @@ -0,0 +1,95 @@ +import { Abi } from "../abi-0.2"; + +const abi: Abi = { + version: "0.2", + methods: [ + { + kind: "Method", + name: "method1", + comment: "some comment", + args: [ + { + kind: "Argument", + name: "arg", + type: { + kind: "Scalar", + scalar: "Bytes" + }, + required: true + } + ], + result: { + kind: "Result", + type: { + kind: "Scalar", + scalar: "UInt32", + }, + required: true + } + }, + { + kind: "Method", + name: "method2", + args: [ + { + kind: "Argument", + name: "custom", + type: { + kind: "Ref", + ref: "Custom" + }, + required: true + } + ], + result: { + kind: "Result", + type: { + kind: "Scalar", + scalar: "Int32" + }, + required: false + } + } + ], + objects: [ + { + kind: "Object", + name: "Custom", + props: [ + { + kind: "Property", + name: "prop1", + type: { + kind: "Scalar", + scalar: "String" + }, + required: true + }, + { + kind: "Property", + name: "nested", + type: { + kind: "Ref", + ref: "Nested" + }, + required: false + } + ] + }, + { + kind: "Object", + name: "Nested", + props: [ + { + kind: "Property", + name: "prop", + type: { + kind: "Scalar", + scalar: "UInt8" + }, + required: false + } + ] + } + ] +}; diff --git a/abi/examples/todo b/abi/examples/todo new file mode 100644 index 0000000..ffa98a0 --- /dev/null +++ b/abi/examples/todo @@ -0,0 +1,5 @@ +- env +- arrays +- maps +- enums +- comments (all locations) diff --git a/abi/principles.md b/abi/principles.md new file mode 100644 index 0000000..bed0aa8 --- /dev/null +++ b/abi/principles.md @@ -0,0 +1,7 @@ +# goals / motiviation / priciples: +- reduce redundant nesting +- remove needless properties +- "definition" = user-specified type definitions +- "type" = built-in types +- do not combine the concept of "definition" & "type", keep the separate + - ex: see how ArgumentDef has a "type" property From ae3c2caf08b202fbd2db64f90811fde74f961108 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Fri, 30 Dec 2022 16:36:14 -0500 Subject: [PATCH 02/20] update method example --- abi/examples/method.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/abi/examples/method.ts b/abi/examples/method.ts index cc507d8..c2a99ed 100644 --- a/abi/examples/method.ts +++ b/abi/examples/method.ts @@ -18,8 +18,12 @@ const abi: Abi = { } ], result: { - kind: "Scalar", - scalar: "String" + kind: "Result", + type: { + kind: "Scalar", + scalar: "String" + }, + required: true } } ] From 02bc9141ce13eed9ef324b3cc851823800c79e3e Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Mon, 2 Jan 2023 12:01:05 -0500 Subject: [PATCH 03/20] updates based on Nestor's feedback --- abi/abi-0.2.ts | 24 ++++++++++++++---------- abi/examples/method.graphql | 2 +- abi/examples/method.ts | 6 +++--- abi/examples/sanity.graphql | 4 ++-- abi/examples/sanity.ts | 16 +++++++++------- abi/principles.md | 15 ++++++++------- 6 files changed, 37 insertions(+), 30 deletions(-) diff --git a/abi/abi-0.2.ts b/abi/abi-0.2.ts index c5e2409..c4dff00 100644 --- a/abi/abi-0.2.ts +++ b/abi/abi-0.2.ts @@ -11,7 +11,7 @@ interface ImportedAbi extends AbiDefs { } interface AbiDefs { - methods?: MethodDef[]; + functions?: FunctionDef[]; objects?: ObjectDef[]; enums?: EnumDef[]; env?: EnvDef; @@ -20,7 +20,7 @@ interface AbiDefs { /// Definitions (user-defined) type AnyDef = - | MethodDef + | FunctionDef | ArgumentDef | ResultDef | ObjectDef @@ -28,15 +28,18 @@ type AnyDef = | EnumDef | EnvDef; -type DefKind = - | "Method" - | "Argument" - | "Result" +type UniqueDefKind = + | "Function" | "Object" - | "Property" | "Enum" | "Env"; +type DefKind = + | UniqueDefKind + | "Argument" + | "Result" + | "Property"; + interface Def { kind: DefKind; } @@ -53,8 +56,8 @@ interface TypeDef extends Def { interface NamedTypeDef extends NamedDef, TypeDef { } -interface MethodDef extends NamedDef { - kind: "Method"; +interface FunctionDef extends NamedDef { + kind: "Function"; args: ArgumentDef[]; result: ResultDef; } @@ -125,7 +128,8 @@ interface MapType extends Type { interface RefType extends Type { kind: "Ref"; - ref: string; + ref_kind: UniqueDefKind; + ref_name: string; } /// Constants diff --git a/abi/examples/method.graphql b/abi/examples/method.graphql index 325e224..81505e5 100644 --- a/abi/examples/method.graphql +++ b/abi/examples/method.graphql @@ -1,5 +1,5 @@ type Module { - method( + fooFunc( arg: String! ): String! } diff --git a/abi/examples/method.ts b/abi/examples/method.ts index c2a99ed..e5df6ef 100644 --- a/abi/examples/method.ts +++ b/abi/examples/method.ts @@ -2,10 +2,10 @@ import { Abi } from "../abi-0.2"; const abi: Abi = { version: "0.2", - methods: [ + functions: [ { - kind: "Method", - name: "method", + kind: "Function", + name: "fooFunc", args: [ { kind: "Argument", diff --git a/abi/examples/sanity.graphql b/abi/examples/sanity.graphql index 4bdf4de..aa50798 100644 --- a/abi/examples/sanity.graphql +++ b/abi/examples/sanity.graphql @@ -1,10 +1,10 @@ type Module { # some comment - method1( + func1( arg: Bytes! ): UInt32! - method2( + func2( custom: Custom! ): Int32 } diff --git a/abi/examples/sanity.ts b/abi/examples/sanity.ts index 0756c82..662d01f 100644 --- a/abi/examples/sanity.ts +++ b/abi/examples/sanity.ts @@ -2,10 +2,10 @@ import { Abi } from "../abi-0.2"; const abi: Abi = { version: "0.2", - methods: [ + functions: [ { - kind: "Method", - name: "method1", + kind: "Function", + name: "func1", comment: "some comment", args: [ { @@ -28,15 +28,16 @@ const abi: Abi = { } }, { - kind: "Method", - name: "method2", + kind: "Function", + name: "func2", args: [ { kind: "Argument", name: "custom", type: { kind: "Ref", - ref: "Custom" + ref_name: "Custom", + ref_kind: "Object" }, required: true } @@ -70,7 +71,8 @@ const abi: Abi = { name: "nested", type: { kind: "Ref", - ref: "Nested" + ref_name: "Nested", + ref_kind: "Object" }, required: false } diff --git a/abi/principles.md b/abi/principles.md index bed0aa8..23694b0 100644 --- a/abi/principles.md +++ b/abi/principles.md @@ -1,7 +1,8 @@ -# goals / motiviation / priciples: -- reduce redundant nesting -- remove needless properties -- "definition" = user-specified type definitions -- "type" = built-in types -- do not combine the concept of "definition" & "type", keep the separate - - ex: see how ArgumentDef has a "type" property +# WRAP ABI 0.2 Principles +- **Optimized:** In 0.1 we have redundant information that can be removed, helping optimize the size of the ABI. +- **Functional:** The composition & usage of this ABI should be highly functional. It should not require expensive parsing / transformation. +- **Clear Semantics:** In 0.2 we're proposing clearer symantic naming conventions. + - **"Type"** = built-in type (`UInt#`, `Int#`, `String`, etc) + - **"Definition"** = user-defined type (`MyObject`, `MyEnum`, etc) + - **"Reference"** = reference to a "definition" +- **Functions Not Methods:** In 0.1 we called the static functions exported by the module "methods", but since we have plans to introduce stateful objects w/ callable methods, we should rename this in 0.2. So, in 0.2 we will call them "module functions", and later will introduce "object methods". From bda95876e8d86ea042a6ccfed44135290ca58d23 Mon Sep 17 00:00:00 2001 From: Nestor Amesty Date: Wed, 4 Jan 2023 13:33:37 +0100 Subject: [PATCH 04/20] (feat): added required properties to inner types in Arrays and Maps --- abi/abi-0.2.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/abi/abi-0.2.ts b/abi/abi-0.2.ts index c4dff00..fadb377 100644 --- a/abi/abi-0.2.ts +++ b/abi/abi-0.2.ts @@ -117,13 +117,19 @@ interface ScalarType< interface ArrayType extends Type { kind: "Array"; - item: AnyType; + item: { + required: boolean; + type: AnyType; + } } interface MapType extends Type { kind: "Map"; key: ScalarType; - value: AnyType; + value: { + required: boolean; + type: AnyType + }; } interface RefType extends Type { From 1281fdc440d4ca45ff55617d2376a82c3a796a65 Mon Sep 17 00:00:00 2001 From: Nestor Amesty Date: Wed, 4 Jan 2023 13:34:00 +0100 Subject: [PATCH 05/20] (chore): Array and Map show cases --- abi/examples/array.graphql | 7 ++ abi/examples/array.ts | 139 +++++++++++++++++++++++++++++++ abi/examples/map.graphql | 16 ++++ abi/examples/map.ts | 165 +++++++++++++++++++++++++++++++++++++ 4 files changed, 327 insertions(+) create mode 100644 abi/examples/array.graphql create mode 100644 abi/examples/array.ts create mode 100644 abi/examples/map.graphql create mode 100644 abi/examples/map.ts diff --git a/abi/examples/array.graphql b/abi/examples/array.graphql new file mode 100644 index 0000000..463cf72 --- /dev/null +++ b/abi/examples/array.graphql @@ -0,0 +1,7 @@ +type CustomType { + uArray: [UInt!]! + uOptArray: [UInt!] + uOptArrayOptArray: [[UInt32]]! + uArrayOptArrayArray: [[[UInt32!]!]]! + crazyArray: [[[[UInt32!]]!]] +} diff --git a/abi/examples/array.ts b/abi/examples/array.ts new file mode 100644 index 0000000..9236afd --- /dev/null +++ b/abi/examples/array.ts @@ -0,0 +1,139 @@ +import { Abi } from "../abi-0.2"; + +const abi: Abi = { + version: "0.2", + objects: [ + { + kind: "Object", + name: "CustomType", + props: [ + { + kind: "Property", + required: true, + name: "uArray", + type: { + kind: "Array", + item: { + required: true, + type: { + kind: "Scalar", + scalar: "UInt" + } + } + } + }, + { + kind: "Property", + required: false, + name: "uOptArray", + type: { + kind: "Array", + item: { + required: true, + type: { + kind: "Scalar", + scalar: "UInt" + } + } + } + }, + { + kind: "Property", + required: true, + name: "uArray", + type: { + kind: "Array", + item: { + required: true, + type: { + kind: "Scalar", + scalar: "UInt" + } + } + } + }, + { + kind: "Property", + required: true, + name: "uOptArrayOptArray", + type: { + kind: "Array", + item: { + required: false, + type: { + kind: "Array", + item: { + type: { + kind: "Scalar", + scalar: "UInt32" + }, + required: false + } + } + } + } + }, + { + kind: "Property", + required: true, + name: "uArrayOptArrayArray", + type: { + kind: "Array", + item: { + required: false, + type: { + kind: "Array", + item: { + required: true, + type: { + kind: "Array", + item: { + required: true, + type: { + kind: "Scalar", + scalar: "UInt32" + } + } + }, + } + } + } + } + }, + { + kind: "Property", + required: false, + name: "crazyArray", + type: { + kind: "Array", + item: { + required: false, + type: { + kind: "Array", + item: { + required: true, + type: { + kind: "Array", + item: { + required: false, + type: { + kind: "Array", + item: { + required: true, + type: { + kind: "Scalar", + scalar: "UInt32" + } + } + } + } + }, + } + } + } + } + } + ] + } + ] +}; diff --git a/abi/examples/map.graphql b/abi/examples/map.graphql new file mode 100644 index 0000000..e1c0fca --- /dev/null +++ b/abi/examples/map.graphql @@ -0,0 +1,16 @@ +type Module implements Interface_Module { + mapMethod( + map: Map @annotate(type: "Map") + ): Map @annotate(type: "Map") +} + +type CustomType { + map: Map! @annotate(type: "Map!") + mapOfArr: Map! @annotate(type: "Map!") + mapOfObj: Map! @annotate(type: "Map!") + mapOfArrOfObj: Map! @annotate(type: "Map!") +} + +type AnotherType { + prop: String +} \ No newline at end of file diff --git a/abi/examples/map.ts b/abi/examples/map.ts new file mode 100644 index 0000000..b06a0da --- /dev/null +++ b/abi/examples/map.ts @@ -0,0 +1,165 @@ +import { Abi } from "../abi-0.2"; + +// Map values are always required + +const abi: Abi = { + version: "0.2", + functions: [ + { + kind: "Function", + name: "mapMethod", + args: [ + { + kind: "Argument", + name: "map", + type: { + kind: "Map", + key: { + kind: "Scalar", + scalar: "String" + }, + value: { + required: true, + type: { + kind: "Scalar", + scalar: "Int", + } + } + }, + required: false, + } + ], + result: { + kind: "Result", + type: { + kind: "Map", + key: { + kind: "Scalar", + scalar: "String" + }, + value: { + required: true, + type: { + kind: "Scalar", + scalar: "Int", + } + } + }, + required: false, + } + } + ], + objects: [ + { + kind: "Object", + name: "CustomType", + props: [ + { + kind: "Property", + required: true, + name: "map", + type: { + kind: "Map", + key: { + kind: "Scalar", + scalar: "String", + }, + value: { + required: false, + type: { + kind: "Scalar", + scalar: "Int", + } + } + } + }, + { + kind: "Property", + required: true, + name: "mapOfArr", + type: { + kind: "Map", + key: { + kind: "Scalar", + scalar: "String", + }, + value: { + required: true, + type: { + kind: "Array", + item: { + required: true, + type: { + kind: "Scalar", + scalar: "Int" + } + }, + } + } + } + }, + { + kind: "Property", + required: true, + name: "mapOfObj", + type: { + kind: "Map", + key: { + kind: "Scalar", + scalar: "String", + }, + value: { + required: true, + type: { + kind: "Ref", + ref_kind: "Object", + ref_name: "AnotherType" + } + } + } + }, + { + kind: "Property", + required: true, + name: "mapOfArrOfObj", + type: { + kind: "Map", + key: { + kind: "Scalar", + scalar: "String", + }, + value: { + required: true, + type: { + kind: "Array", + item: { + required: true, + type: { + kind: "Ref", + ref_kind: "Object", + ref_name: "AnotherType" + } + } + } + } + } + } + ] + }, + { + kind: "Object", + name: "AnotherType", + props: [ + { + kind: "Property", + name: "prop", + required: false, + type: { + kind: "Scalar", + scalar: "String" + } + } + ] + } + ] +}; From cfcd3ce7d15e9edcb48c59aa21115e7512312262 Mon Sep 17 00:00:00 2001 From: Nestor Amesty Date: Wed, 4 Jan 2023 14:12:22 +0100 Subject: [PATCH 06/20] (chore): removed unnecessary nesting --- abi/abi-0.2.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/abi/abi-0.2.ts b/abi/abi-0.2.ts index fadb377..cc54576 100644 --- a/abi/abi-0.2.ts +++ b/abi/abi-0.2.ts @@ -117,19 +117,15 @@ interface ScalarType< interface ArrayType extends Type { kind: "Array"; - item: { - required: boolean; - type: AnyType; - } + required: boolean; + item: AnyType; } interface MapType extends Type { kind: "Map"; key: ScalarType; - value: { - required: boolean; - type: AnyType - }; + required: boolean; + value: AnyType; } interface RefType extends Type { From b89458207818c82c6daf42764e5a707a0316b422 Mon Sep 17 00:00:00 2001 From: Nestor Amesty Date: Wed, 4 Jan 2023 14:12:45 +0100 Subject: [PATCH 07/20] removed unnecessary nesting --- abi/examples/array.ts | 86 ++++++++++++++++--------------------------- abi/examples/map.ts | 68 +++++++++++++--------------------- 2 files changed, 57 insertions(+), 97 deletions(-) diff --git a/abi/examples/array.ts b/abi/examples/array.ts index 9236afd..c5f7a50 100644 --- a/abi/examples/array.ts +++ b/abi/examples/array.ts @@ -13,12 +13,10 @@ const abi: Abi = { name: "uArray", type: { kind: "Array", + required: true, item: { - required: true, - type: { - kind: "Scalar", - scalar: "UInt" - } + kind: "Scalar", + scalar: "UInt" } } }, @@ -28,12 +26,10 @@ const abi: Abi = { name: "uOptArray", type: { kind: "Array", + required: true, item: { - required: true, - type: { - kind: "Scalar", - scalar: "UInt" - } + kind: "Scalar", + scalar: "UInt" } } }, @@ -43,12 +39,10 @@ const abi: Abi = { name: "uArray", type: { kind: "Array", + required: true, item: { - required: true, - type: { - kind: "Scalar", - scalar: "UInt" - } + kind: "Scalar", + scalar: "UInt" } } }, @@ -58,17 +52,13 @@ const abi: Abi = { name: "uOptArrayOptArray", type: { kind: "Array", + required: false, item: { + kind: "Array", required: false, - type: { - kind: "Array", - item: { - type: { - kind: "Scalar", - scalar: "UInt32" - }, - required: false - } + item: { + kind: "Scalar", + scalar: "UInt32" } } } @@ -79,22 +69,16 @@ const abi: Abi = { name: "uArrayOptArrayArray", type: { kind: "Array", + required: false, item: { - required: false, - type: { + kind: "Array", + required: true, + item: { kind: "Array", + required: true, item: { - required: true, - type: { - kind: "Array", - item: { - required: true, - type: { - kind: "Scalar", - scalar: "UInt32" - } - } - }, + kind: "Scalar", + scalar: "UInt32" } } } @@ -106,28 +90,20 @@ const abi: Abi = { name: "crazyArray", type: { kind: "Array", + required: false, item: { - required: false, - type: { + kind: "Array", + required: true, + item: { kind: "Array", + required: false, item: { + kind: "Array", required: true, - type: { - kind: "Array", - item: { - required: false, - type: { - kind: "Array", - item: { - required: true, - type: { - kind: "Scalar", - scalar: "UInt32" - } - } - } - } - }, + item: { + kind: "Scalar", + scalar: "UInt32" + } } } } diff --git a/abi/examples/map.ts b/abi/examples/map.ts index b06a0da..794c5d9 100644 --- a/abi/examples/map.ts +++ b/abi/examples/map.ts @@ -18,12 +18,10 @@ const abi: Abi = { kind: "Scalar", scalar: "String" }, + required: true, value: { - required: true, - type: { - kind: "Scalar", - scalar: "Int", - } + kind: "Scalar", + scalar: "Int", } }, required: false, @@ -37,12 +35,10 @@ const abi: Abi = { kind: "Scalar", scalar: "String" }, + required: true, value: { - required: true, - type: { - kind: "Scalar", - scalar: "Int", - } + kind: "Scalar", + scalar: "Int", } }, required: false, @@ -64,12 +60,10 @@ const abi: Abi = { kind: "Scalar", scalar: "String", }, - value: { - required: false, - type: { - kind: "Scalar", - scalar: "Int", - } + required: false, + value: { + kind: "Scalar", + scalar: "Int", } } }, @@ -83,18 +77,14 @@ const abi: Abi = { kind: "Scalar", scalar: "String", }, + required: true, value: { + kind: "Array", required: true, - type: { - kind: "Array", - item: { - required: true, - type: { - kind: "Scalar", - scalar: "Int" - } - }, - } + item: { + kind: "Scalar", + scalar: "Int" + }, } } }, @@ -108,13 +98,11 @@ const abi: Abi = { kind: "Scalar", scalar: "String", }, + required: true, value: { - required: true, - type: { - kind: "Ref", - ref_kind: "Object", - ref_name: "AnotherType" - } + kind: "Ref", + ref_kind: "Object", + ref_name: "AnotherType" } } }, @@ -128,18 +116,14 @@ const abi: Abi = { kind: "Scalar", scalar: "String", }, + required: true, value: { + kind: "Array", required: true, - type: { - kind: "Array", - item: { - required: true, - type: { - kind: "Ref", - ref_kind: "Object", - ref_name: "AnotherType" - } - } + item: { + kind: "Ref", + ref_kind: "Object", + ref_name: "AnotherType" } } } From 6d877166b290be8032ac7c4f9bfda7f1a7ab8818 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Tue, 10 Jan 2023 23:44:53 -0500 Subject: [PATCH 08/20] updates --- abi/README.md | 20 ++++ abi/abi-0.2.ts | 82 ++++++++-------- abi/examples/array.ts | 84 ++++++++++------ abi/examples/enum.graphql | 1 + abi/examples/env.graphql | 3 + .../{method.graphql => function.graphql} | 0 abi/examples/{method.ts => function.ts} | 0 abi/examples/import.graphql | 0 abi/examples/interface.graphql | 0 abi/examples/map.graphql | 1 + abi/examples/map.ts | 98 ++++++++++++++----- abi/examples/sanity.ts | 1 - abi/examples/todo | 13 ++- abi/principles.md | 8 -- 14 files changed, 199 insertions(+), 112 deletions(-) create mode 100644 abi/README.md create mode 100644 abi/examples/enum.graphql create mode 100644 abi/examples/env.graphql rename abi/examples/{method.graphql => function.graphql} (100%) rename abi/examples/{method.ts => function.ts} (100%) create mode 100644 abi/examples/import.graphql create mode 100644 abi/examples/interface.graphql delete mode 100644 abi/principles.md diff --git a/abi/README.md b/abi/README.md new file mode 100644 index 0000000..f85f24f --- /dev/null +++ b/abi/README.md @@ -0,0 +1,20 @@ +# WRAP ABI (v0.2) +## Goals +- **Optimized:** The size and performance of the ABI should be optimized. +- **Functional:** The composition & usage of this ABI should be highly functional. It should not require expensive parsing / transformation. +- **Stable:** The ABI should be resistent to potential future changes, helping it remain stable and easily upgradeable. + +## Improvements Upon 0.1 +- **Smaller:** 0.2 is much smaller than 0.1, as we have removed a significant amount of redundant information from the ABI. +- **Easier To Parse:** 0.2's structured layout is easier to parse than 0.1, as well as it includes a few properties that help solve ambiguity, which required reparsing to solve. +- **Clearer Semantics:** In 0.2 we're proposing clearer semantic naming conventions, to help bring more structure to the ABI's ontology. + +## Decisions Made +1. **ABI Sub-Types:** The different sub-types contained within an ABI have been better defined: + * **"Definition"** = user-defined type (`MyObject`, `MyEnum`, etc). + * **"Type"** = built-in type (`UInt#`, `Int#`, `String`, etc). + * **"Reference"** = reference to a "Definition" +2. **Functions Not Methods:** In 0.1 we called the static functions exported by the module "methods", but since we have plans to introduce stateful objects w/ callable methods, we should rename this in 0.2. So, in 0.2 we will call them "module functions", and later will introduce "object methods". +3. **Imports Are Namespaced ABIs:** Instead of creating multiple properties on the `Abi` interface for each import type (ex: `importedObjects: ObjectDefinition[]`), we instead treat all imports as namespaced ABIs. This allows us to add a single property to the root ABI which contains all imports, `imports: ImportedAbi[]`, where `ImportedAbi` is a derived interface from `Abi` which adds `namespace` and `uri` properties. +4. **Heterogeneous < Homogenous Collections:** Currently the `Abi` interface stores each definition kind within a homogenous array (ex: `objects: ObjectDef[]`). It has been discussed that it may be better to make the `Abi` a heterogeneous collection of all possible definitions (ex: `type Abi = AnyDef[]`). This is also know as a "polymorphic array". After some consideration of 0.2's primary goals, we have decided that we prefer the homogenous collections approach because it is easier to parse, because you know ahead of time what the type of each element in the array is. +5. **Remove Comments:** In order to help optimize the ABI, we've removed all `comment` properties. Comments can instead be found on the original source file written by the user that was used to produce the ABI. diff --git a/abi/abi-0.2.ts b/abi/abi-0.2.ts index cc54576..218a87c 100644 --- a/abi/abi-0.2.ts +++ b/abi/abi-0.2.ts @@ -5,21 +5,21 @@ export interface Abi extends AbiDefs { imports?: ImportedAbi[]; } -interface ImportedAbi extends AbiDefs { - namespace: string; - uri: string; -} - -interface AbiDefs { +export interface AbiDefs { functions?: FunctionDef[]; objects?: ObjectDef[]; enums?: EnumDef[]; env?: EnvDef; } +export interface ImportedAbi extends AbiDefs { + namespace: string; + uri: string; +} + /// Definitions (user-defined) -type AnyDef = +export type AnyDef = | FunctionDef | ArgumentDef | ResultDef @@ -28,115 +28,113 @@ type AnyDef = | EnumDef | EnvDef; -type UniqueDefKind = +export type UniqueDefKind = | "Function" | "Object" | "Enum" | "Env"; -type DefKind = +export type DefKind = | UniqueDefKind | "Argument" | "Result" | "Property"; -interface Def { +export interface Def { kind: DefKind; } -interface NamedDef extends Def { +export interface NamedDef extends Def { name: string; - comment?: string; } -interface TypeDef extends Def { - required: boolean; - type: AnyType; -} +export interface InlinedTypeDef extends Def, OptionalType { } -interface NamedTypeDef extends NamedDef, TypeDef { } +export interface NamedTypeDef extends NamedDef, InlinedTypeDef { } -interface FunctionDef extends NamedDef { +export interface FunctionDef extends NamedDef { kind: "Function"; args: ArgumentDef[]; result: ResultDef; } -interface ArgumentDef extends NamedTypeDef { +export interface ArgumentDef extends NamedTypeDef { kind: "Argument"; } -interface ResultDef extends TypeDef { +export interface ResultDef extends InlinedTypeDef { kind: "Result"; } -interface ObjectDef extends NamedDef { +export interface ObjectDef extends NamedDef { kind: "Object"; props: PropertyDef[]; } -interface PropertyDef extends NamedTypeDef { +export interface PropertyDef extends NamedTypeDef { kind: "Property"; } -interface EnumDef extends NamedDef { +export interface EnumDef extends NamedDef { kind: "Enum"; constants: string[]; } -interface EnvDef extends NamedDef { +export interface EnvDef extends Def { kind: "Env"; - name: "Env"; props: PropertyDef[]; } /// Types (built-ins) -type AnyType = +export type AnyType = | ScalarType | ArrayType | MapType | RefType; -type TypeKind = +export type TypeKind = | "Scalar" | "Array" | "Map" | "Ref"; -interface Type { +export interface Type { kind: TypeKind; } -interface ScalarType< +export interface ScalarType< TScalarTypeName extends ScalarTypeName = ScalarTypeName > extends Type { kind: "Scalar"; scalar: TScalarTypeName; } -interface ArrayType extends Type { +export interface ArrayType extends Type { kind: "Array"; - required: boolean; - item: AnyType; + item: OptionalType; } -interface MapType extends Type { +export interface MapType extends Type { kind: "Map"; key: ScalarType; - required: boolean; - value: AnyType; + value: OptionalType; } -interface RefType extends Type { +export interface RefType extends Type { kind: "Ref"; ref_kind: UniqueDefKind; ref_name: string; } +export interface OptionalType { + required: boolean; + type: AnyType; +} + /// Constants -const scalarTypeSet = { +export const scalarTypeSet = { UInt: "UInt", UInt8: "UInt8", UInt16: "UInt16", @@ -153,11 +151,11 @@ const scalarTypeSet = { BigNumber: "BigNumber", JSON: "JSON", }; -type ScalarTypeSet = typeof scalarTypeSet; +export type ScalarTypeSet = typeof scalarTypeSet; -type ScalarTypeName = keyof ScalarTypeSet; +export type ScalarTypeName = keyof ScalarTypeSet; -const mapKeyTypeSet = { +export const mapKeyTypeSet = { UInt: "UInt", UInt8: "UInt8", UInt16: "UInt16", @@ -168,6 +166,6 @@ const mapKeyTypeSet = { Int32: "Int32", String: "String", }; -type MapKeyTypeSet = typeof mapKeyTypeSet; +export type MapKeyTypeSet = typeof mapKeyTypeSet; -type MapKeyTypeName = keyof MapKeyTypeSet; +export type MapKeyTypeName = keyof MapKeyTypeSet; diff --git a/abi/examples/array.ts b/abi/examples/array.ts index c5f7a50..2f70cf5 100644 --- a/abi/examples/array.ts +++ b/abi/examples/array.ts @@ -13,10 +13,12 @@ const abi: Abi = { name: "uArray", type: { kind: "Array", - required: true, item: { - kind: "Scalar", - scalar: "UInt" + required: true, + type: { + kind: "Scalar", + scalar: "UInt" + } } } }, @@ -26,10 +28,12 @@ const abi: Abi = { name: "uOptArray", type: { kind: "Array", - required: true, item: { - kind: "Scalar", - scalar: "UInt" + required: true, + type: { + kind: "Scalar", + scalar: "UInt" + } } } }, @@ -39,10 +43,12 @@ const abi: Abi = { name: "uArray", type: { kind: "Array", - required: true, item: { - kind: "Scalar", - scalar: "UInt" + required: true, + type: { + kind: "Scalar", + scalar: "UInt" + } } } }, @@ -52,13 +58,17 @@ const abi: Abi = { name: "uOptArrayOptArray", type: { kind: "Array", - required: false, item: { - kind: "Array", required: false, - item: { - kind: "Scalar", - scalar: "UInt32" + type: { + kind: "Array", + item: { + required: false, + type: { + kind: "Scalar", + scalar: "UInt32" + } + } } } } @@ -69,16 +79,22 @@ const abi: Abi = { name: "uArrayOptArrayArray", type: { kind: "Array", - required: false, item: { - kind: "Array", - required: true, - item: { + required: false, + type: { kind: "Array", - required: true, item: { - kind: "Scalar", - scalar: "UInt32" + required: true, + type: { + kind: "Array", + item: { + required: true, + type: { + kind: "Scalar", + scalar: "UInt32" + } + } + } } } } @@ -90,19 +106,27 @@ const abi: Abi = { name: "crazyArray", type: { kind: "Array", - required: false, item: { - kind: "Array", - required: true, - item: { + required: false, + type: { kind: "Array", - required: false, item: { - kind: "Array", required: true, - item: { - kind: "Scalar", - scalar: "UInt32" + type: { + kind: "Array", + item: { + required: false, + type: { + kind: "Array", + item: { + required: true, + type: { + kind: "Scalar", + scalar: "UInt32" + } + } + } + } } } } diff --git a/abi/examples/enum.graphql b/abi/examples/enum.graphql new file mode 100644 index 0000000..f87f5c1 --- /dev/null +++ b/abi/examples/enum.graphql @@ -0,0 +1 @@ +# TODO \ No newline at end of file diff --git a/abi/examples/env.graphql b/abi/examples/env.graphql new file mode 100644 index 0000000..d2dfa12 --- /dev/null +++ b/abi/examples/env.graphql @@ -0,0 +1,3 @@ +type Env { + prop: String! +} diff --git a/abi/examples/method.graphql b/abi/examples/function.graphql similarity index 100% rename from abi/examples/method.graphql rename to abi/examples/function.graphql diff --git a/abi/examples/method.ts b/abi/examples/function.ts similarity index 100% rename from abi/examples/method.ts rename to abi/examples/function.ts diff --git a/abi/examples/import.graphql b/abi/examples/import.graphql new file mode 100644 index 0000000..e69de29 diff --git a/abi/examples/interface.graphql b/abi/examples/interface.graphql new file mode 100644 index 0000000..e69de29 diff --git a/abi/examples/map.graphql b/abi/examples/map.graphql index e1c0fca..a868f00 100644 --- a/abi/examples/map.graphql +++ b/abi/examples/map.graphql @@ -9,6 +9,7 @@ type CustomType { mapOfArr: Map! @annotate(type: "Map!") mapOfObj: Map! @annotate(type: "Map!") mapOfArrOfObj: Map! @annotate(type: "Map!") + mapOfMapOfObj: Map! @annotate(type: "Map!>!") } type AnotherType { diff --git a/abi/examples/map.ts b/abi/examples/map.ts index 794c5d9..d0f921f 100644 --- a/abi/examples/map.ts +++ b/abi/examples/map.ts @@ -18,10 +18,12 @@ const abi: Abi = { kind: "Scalar", scalar: "String" }, - required: true, value: { - kind: "Scalar", - scalar: "Int", + required: true, + type: { + kind: "Scalar", + scalar: "Int", + } } }, required: false, @@ -35,10 +37,12 @@ const abi: Abi = { kind: "Scalar", scalar: "String" }, - required: true, value: { - kind: "Scalar", - scalar: "Int", + required: true, + type: { + kind: "Scalar", + scalar: "Int", + } } }, required: false, @@ -60,10 +64,12 @@ const abi: Abi = { kind: "Scalar", scalar: "String", }, - required: false, - value: { - kind: "Scalar", - scalar: "Int", + value: { + required: false, + type: { + kind: "Scalar", + scalar: "Int", + } } } }, @@ -77,14 +83,18 @@ const abi: Abi = { kind: "Scalar", scalar: "String", }, - required: true, value: { - kind: "Array", required: true, - item: { - kind: "Scalar", - scalar: "Int" - }, + type: { + kind: "Array", + item: { + required: true, + type: { + kind: "Scalar", + scalar: "Int" + } + }, + } } } }, @@ -98,11 +108,13 @@ const abi: Abi = { kind: "Scalar", scalar: "String", }, - required: true, value: { - kind: "Ref", - ref_kind: "Object", - ref_name: "AnotherType" + required: true, + type: { + kind: "Ref", + ref_kind: "Object", + ref_name: "AnotherType" + } } } }, @@ -116,14 +128,48 @@ const abi: Abi = { kind: "Scalar", scalar: "String", }, - required: true, value: { - kind: "Array", required: true, - item: { - kind: "Ref", - ref_kind: "Object", - ref_name: "AnotherType" + type: { + kind: "Array", + item: { + required: true, + type: { + kind: "Ref", + ref_kind: "Object", + ref_name: "AnotherType" + } + } + } + } + } + }, + { + kind: "Property", + required: true, + name: "mapOfMapOfObj", + type: { + kind: "Map", + key: { + kind: "Scalar", + scalar: "String", + }, + value: { + required: true, + type: { + kind: "Map", + key: { + kind: "Scalar", + scalar: "String" + }, + value: { + required: true, + type: { + kind: "Ref", + ref_kind: "Object", + ref_name: "AnotherType" + } + } } } } diff --git a/abi/examples/sanity.ts b/abi/examples/sanity.ts index 662d01f..19661cb 100644 --- a/abi/examples/sanity.ts +++ b/abi/examples/sanity.ts @@ -6,7 +6,6 @@ const abi: Abi = { { kind: "Function", name: "func1", - comment: "some comment", args: [ { kind: "Argument", diff --git a/abi/examples/todo b/abi/examples/todo index ffa98a0..f5c0553 100644 --- a/abi/examples/todo +++ b/abi/examples/todo @@ -1,5 +1,8 @@ -- env -- arrays -- maps -- enums -- comments (all locations) +TODO: +- referencing imports +- implemented interfaces +- parity with old ABI +- notes on things removed from old ABI (capabilities) +- JSON-schema +- Transpile to TS +- compile the ts example files to make sure they implement the ABI well \ No newline at end of file diff --git a/abi/principles.md b/abi/principles.md deleted file mode 100644 index 23694b0..0000000 --- a/abi/principles.md +++ /dev/null @@ -1,8 +0,0 @@ -# WRAP ABI 0.2 Principles -- **Optimized:** In 0.1 we have redundant information that can be removed, helping optimize the size of the ABI. -- **Functional:** The composition & usage of this ABI should be highly functional. It should not require expensive parsing / transformation. -- **Clear Semantics:** In 0.2 we're proposing clearer symantic naming conventions. - - **"Type"** = built-in type (`UInt#`, `Int#`, `String`, etc) - - **"Definition"** = user-defined type (`MyObject`, `MyEnum`, etc) - - **"Reference"** = reference to a "definition" -- **Functions Not Methods:** In 0.1 we called the static functions exported by the module "methods", but since we have plans to introduce stateful objects w/ callable methods, we should rename this in 0.2. So, in 0.2 we will call them "module functions", and later will introduce "object methods". From ac784238c1e03a997ec324f03ca43dbaab0800cb Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Wed, 11 Jan 2023 14:03:56 -0500 Subject: [PATCH 09/20] Nestor & Jordan updates --- abi/abi-0.2.ts | 27 +++-- abi/examples/import.ts | 185 +++++++++++++++++++++++++++++++++ abi/examples/interface.graphql | 11 ++ abi/examples/sanity.graphql | 3 + abi/examples/sanity.ts | 17 +++ abi/examples/todo | 7 +- 6 files changed, 241 insertions(+), 9 deletions(-) create mode 100644 abi/examples/import.ts diff --git a/abi/abi-0.2.ts b/abi/abi-0.2.ts index 218a87c..fe04c34 100644 --- a/abi/abi-0.2.ts +++ b/abi/abi-0.2.ts @@ -1,10 +1,5 @@ /// ABIs -export interface Abi extends AbiDefs { - version: "0.2"; - imports?: ImportedAbi[]; -} - export interface AbiDefs { functions?: FunctionDef[]; objects?: ObjectDef[]; @@ -12,9 +7,16 @@ export interface AbiDefs { env?: EnvDef; } +export interface Abi extends AbiDefs { + version: "0.2"; + imports?: ImportedAbi[]; +} + export interface ImportedAbi extends AbiDefs { - namespace: string; + id: string; uri: string; + namespace: string; + imports?: ImportedAbi[]; } /// Definitions (user-defined) @@ -91,13 +93,15 @@ export type AnyType = | ScalarType | ArrayType | MapType - | RefType; + | RefType + | ImportRefType; export type TypeKind = | "Scalar" | "Array" | "Map" - | "Ref"; + | "Ref" + | "ImportRef"; export interface Type { kind: TypeKind; @@ -127,6 +131,13 @@ export interface RefType extends Type { ref_name: string; } +export interface ImportRefType extends Type { + kind: "ImportRef"; + import_id: string; + ref_kind: UniqueDefKind; + ref_name: string; +} + export interface OptionalType { required: boolean; type: AnyType; diff --git a/abi/examples/import.ts b/abi/examples/import.ts new file mode 100644 index 0000000..9b81a79 --- /dev/null +++ b/abi/examples/import.ts @@ -0,0 +1,185 @@ +/* +Interface + -> WrapperA + -> WrapperB +*/ + + +import { Abi } from "../abi-0.2"; + +/* +type Foo { + prop: UInt8! +} +*/ +const layer_0: Abi = { + version: "0.2", + objects: [ + { + kind: "Object", + name: "Foo", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "UInt8" + } + } + ] + } + ] +} + +/* +#import { Foo } into Interface from "uri" + +type Bar { + foo: Interface_Foo! +} +*/ +const layer_1: Abi = { + version: "0.2", + imports: [ + { + id: "0", + uri: "interface", + namespace: "Interface", + objects: [ + { + kind: "Object", + name: "Foo", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "UInt8" + } + } + ] + } + ] + } + ], + objects: [ + { + kind: "Object", + name: "Bar", + props: [ + { + kind: "Property", + name: "foo", + required: true, + type: { + kind: "ImportRef", + import_id: "0", + ref_kind: "Object", + ref_name: "Foo" + } + } + ] + } + ] +}; + +/* +#import { Bar, Interface_Foo } into Wrapper from "wrapper" + +type MyObject { + bar: Wrapper_Bar! + foo: Wrapper_Interface_Foo! +} +*/ +/* +0. import an external ABI +1. extract all imports of that ABI, append a namespace to them +2. extract all abi defs, set as namespace +*/ +const final: Abi = { + version: "0.2", + imports: [ + { + id: "0", + uri: "uri", + namespace: "Wrapper", + objects: [ + { + kind: "Object", + name: "Bar", + props: [ + { + kind: "Property", + name: "foo", + required: true, + type: { + kind: "ImportRef", + import_id: "0", + ref_kind: "Object", + ref_name: "Foo" + } + } + ] + } + ], + imports: [ + { + id: "0", + uri: "interface", + namespace: "Interface", + objects: [ + { + kind: "Object", + name: "Foo", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "UInt8" + } + } + ] + } + ] + } + ], + } + ], + objects: [ + { + kind: "Object", + name: "MyObject", + props: [ + { + kind: "Property", + name: "bar", + required: true, + type: { + kind: "ImportRef", + import_id: "0", + ref_kind: "Object", + ref_name: "Bar" + } + }, + { + kind: "Property", + name: "foo", + required: true, + type: { + kind: "ImportRef", + import_id: "0.0", + ref_kind: "Object", + ref_name: "Foo" + } + } + ] + } + ] +} diff --git a/abi/examples/interface.graphql b/abi/examples/interface.graphql index e69de29..7cc9655 100644 --- a/abi/examples/interface.graphql +++ b/abi/examples/interface.graphql @@ -0,0 +1,11 @@ +#import { Module, SwapParams } into Uniswap from "..." + +type Module implements Uniswap_Module { + execSwap( + swap: Uniswap_SwapParams! + ): ... +} + +type Uniswap_Module { + ... +} diff --git a/abi/examples/sanity.graphql b/abi/examples/sanity.graphql index aa50798..2003efc 100644 --- a/abi/examples/sanity.graphql +++ b/abi/examples/sanity.graphql @@ -1,3 +1,5 @@ +#import { Object } into Namespace from "uri" + type Module { # some comment func1( @@ -16,4 +18,5 @@ type Custom { type Nested { prop: UInt8 + importedObj: Namespace_Object! } diff --git a/abi/examples/sanity.ts b/abi/examples/sanity.ts index 19661cb..9de9626 100644 --- a/abi/examples/sanity.ts +++ b/abi/examples/sanity.ts @@ -89,6 +89,23 @@ const abi: Abi = { scalar: "UInt8" }, required: false + }, + { + kind: "Property", + name: "importedObj", + type: { + kind: "Ref", + ref_kind: "Object", + ref_name: "Namespace_Object" + + /* + kind: "ImpotRef", + ref_abi: 0, + ref_kind: "Object", + ref_name: "Object" + */ + }, + required: true } ] } diff --git a/abi/examples/todo b/abi/examples/todo index f5c0553..66ab1ee 100644 --- a/abi/examples/todo +++ b/abi/examples/todo @@ -5,4 +5,9 @@ TODO: - notes on things removed from old ABI (capabilities) - JSON-schema - Transpile to TS -- compile the ts example files to make sure they implement the ABI well \ No newline at end of file +- compile the ts example files to make sure they implement the ABI well +- research merkle-root hashes for root-definitions (function, object, enum, etc?) to help with validation execution time + - "does interface A implement interface B?" +- document the choices around imports & how import "routing" works for importing the imports of your import. (ex: "1.2.3") + +- document future plan: "runtime abi" is a compressed hyper optimized ABI for small storage & download, and fast runtime traversal & introspection (hashes, etc) From 19f76d857db71187361bcbb865d2f1cb8ddf23e5 Mon Sep 17 00:00:00 2001 From: Nestor Amesty Date: Wed, 11 Jan 2023 23:32:59 +0100 Subject: [PATCH 10/20] (wip): added further decisions to readme --- abi/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/abi/README.md b/abi/README.md index f85f24f..dc1f06b 100644 --- a/abi/README.md +++ b/abi/README.md @@ -18,3 +18,6 @@ 3. **Imports Are Namespaced ABIs:** Instead of creating multiple properties on the `Abi` interface for each import type (ex: `importedObjects: ObjectDefinition[]`), we instead treat all imports as namespaced ABIs. This allows us to add a single property to the root ABI which contains all imports, `imports: ImportedAbi[]`, where `ImportedAbi` is a derived interface from `Abi` which adds `namespace` and `uri` properties. 4. **Heterogeneous < Homogenous Collections:** Currently the `Abi` interface stores each definition kind within a homogenous array (ex: `objects: ObjectDef[]`). It has been discussed that it may be better to make the `Abi` a heterogeneous collection of all possible definitions (ex: `type Abi = AnyDef[]`). This is also know as a "polymorphic array". After some consideration of 0.2's primary goals, we have decided that we prefer the homogenous collections approach because it is easier to parse, because you know ahead of time what the type of each element in the array is. 5. **Remove Comments:** In order to help optimize the ABI, we've removed all `comment` properties. Comments can instead be found on the original source file written by the user that was used to produce the ABI. +6. **Keyword `implements` no longer implies inheritance**: Currently, users use `implements` as `extends`. If they implement an interface, the interface's properties get automatically copied over to the implementation type. While this allows users to type less, it incorrectly behaves as inheritance; so we're removing that behavior. Now if `A implements B`, we will just validate that `A` contains the properties of `B`. +7. **Remove Interfaces and Capabilities:** All wrappers have implicit interface definitions (by having a schema) but only some have implementations. Therefore, there's no reason to restrict implementation wrappers types to be used as interfaces (with the `implements` keyword); or to only enable `getImplementations` capabilities in interface wrappers. So we're removing the concept of `interfaces` in favor of just using types, and enabling `getImplementation` capabilities for all modules. +8. **Import an imported ABI's imports**: Currently, it isn't possible to use a type that was imported in an import without manually re-exporting it, as referenced here: https://github.com/polywrap/toolchain/issues/1448. This will now be possible. \ No newline at end of file From 09eacbd037244383d594f91b83fbe3ffa1d86cc0 Mon Sep 17 00:00:00 2001 From: Nestor Amesty Date: Thu, 12 Jan 2023 21:25:53 +0100 Subject: [PATCH 11/20] (chore): added imports example --- abi/examples/import.graphql | 0 abi/examples/import.ts | 185 ------------------------- abi/examples/imports/externalA.graphql | 6 + abi/examples/imports/externalA.ts | 63 +++++++++ abi/examples/imports/externalB.graphql | 5 + abi/examples/imports/externalB.ts | 38 +++++ abi/examples/imports/schema.graphql | 8 ++ abi/examples/imports/schema.ts | 108 +++++++++++++++ 8 files changed, 228 insertions(+), 185 deletions(-) delete mode 100644 abi/examples/import.graphql delete mode 100644 abi/examples/import.ts create mode 100644 abi/examples/imports/externalA.graphql create mode 100644 abi/examples/imports/externalA.ts create mode 100644 abi/examples/imports/externalB.graphql create mode 100644 abi/examples/imports/externalB.ts create mode 100644 abi/examples/imports/schema.graphql create mode 100644 abi/examples/imports/schema.ts diff --git a/abi/examples/import.graphql b/abi/examples/import.graphql deleted file mode 100644 index e69de29..0000000 diff --git a/abi/examples/import.ts b/abi/examples/import.ts deleted file mode 100644 index 9b81a79..0000000 --- a/abi/examples/import.ts +++ /dev/null @@ -1,185 +0,0 @@ -/* -Interface - -> WrapperA - -> WrapperB -*/ - - -import { Abi } from "../abi-0.2"; - -/* -type Foo { - prop: UInt8! -} -*/ -const layer_0: Abi = { - version: "0.2", - objects: [ - { - kind: "Object", - name: "Foo", - props: [ - { - kind: "Property", - name: "prop", - required: true, - type: { - kind: "Scalar", - scalar: "UInt8" - } - } - ] - } - ] -} - -/* -#import { Foo } into Interface from "uri" - -type Bar { - foo: Interface_Foo! -} -*/ -const layer_1: Abi = { - version: "0.2", - imports: [ - { - id: "0", - uri: "interface", - namespace: "Interface", - objects: [ - { - kind: "Object", - name: "Foo", - props: [ - { - kind: "Property", - name: "prop", - required: true, - type: { - kind: "Scalar", - scalar: "UInt8" - } - } - ] - } - ] - } - ], - objects: [ - { - kind: "Object", - name: "Bar", - props: [ - { - kind: "Property", - name: "foo", - required: true, - type: { - kind: "ImportRef", - import_id: "0", - ref_kind: "Object", - ref_name: "Foo" - } - } - ] - } - ] -}; - -/* -#import { Bar, Interface_Foo } into Wrapper from "wrapper" - -type MyObject { - bar: Wrapper_Bar! - foo: Wrapper_Interface_Foo! -} -*/ -/* -0. import an external ABI -1. extract all imports of that ABI, append a namespace to them -2. extract all abi defs, set as namespace -*/ -const final: Abi = { - version: "0.2", - imports: [ - { - id: "0", - uri: "uri", - namespace: "Wrapper", - objects: [ - { - kind: "Object", - name: "Bar", - props: [ - { - kind: "Property", - name: "foo", - required: true, - type: { - kind: "ImportRef", - import_id: "0", - ref_kind: "Object", - ref_name: "Foo" - } - } - ] - } - ], - imports: [ - { - id: "0", - uri: "interface", - namespace: "Interface", - objects: [ - { - kind: "Object", - name: "Foo", - props: [ - { - kind: "Property", - name: "prop", - required: true, - type: { - kind: "Scalar", - scalar: "UInt8" - } - } - ] - } - ] - } - ], - } - ], - objects: [ - { - kind: "Object", - name: "MyObject", - props: [ - { - kind: "Property", - name: "bar", - required: true, - type: { - kind: "ImportRef", - import_id: "0", - ref_kind: "Object", - ref_name: "Bar" - } - }, - { - kind: "Property", - name: "foo", - required: true, - type: { - kind: "ImportRef", - import_id: "0.0", - ref_kind: "Object", - ref_name: "Foo" - } - } - ] - } - ] -} diff --git a/abi/examples/imports/externalA.graphql b/abi/examples/imports/externalA.graphql new file mode 100644 index 0000000..4e86b1f --- /dev/null +++ b/abi/examples/imports/externalA.graphql @@ -0,0 +1,6 @@ +#import { AnotherFoo } into Lorem from "wrap://ens/lorem.eth" +#import { YetFoo } from "wrap://ens/lorem.eth" + +type SomeFoo { + prop: Lorem_AnotherFoo! +} diff --git a/abi/examples/imports/externalA.ts b/abi/examples/imports/externalA.ts new file mode 100644 index 0000000..2db47a9 --- /dev/null +++ b/abi/examples/imports/externalA.ts @@ -0,0 +1,63 @@ +import { Abi } from "../../abi-0.2"; + +const abi: Abi = { + version: "0.2", + imports: [ + { + namespace: "Lorem", + uri: "wrap://ens/lorem.eth", + id: "7", + objects: [ + { + kind: "Object", + name: "AnotherFoo", + props: [ + { + kind: "Property", + name: "prop", + required: false, + type: { + kind: "Scalar", + scalar: "Int" + } + } + ] + } + ] + } + ], + objects: [ + { + kind: "Object", + name: "SomeFoo", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "ImportRef", + import_id: "7", + ref_kind: "Object", + ref_name: "AnotherFoo" + } + } + ] + }, + { + kind: "Object", + name: "YetFoo", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "String" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/abi/examples/imports/externalB.graphql b/abi/examples/imports/externalB.graphql new file mode 100644 index 0000000..e0862fb --- /dev/null +++ b/abi/examples/imports/externalB.graphql @@ -0,0 +1,5 @@ +#import { TypeBar } from "wrap://ens/lorem.eth" + +type SomeBar { + prop: TypeBar! +} diff --git a/abi/examples/imports/externalB.ts b/abi/examples/imports/externalB.ts new file mode 100644 index 0000000..29adcca --- /dev/null +++ b/abi/examples/imports/externalB.ts @@ -0,0 +1,38 @@ +import { Abi } from "../../abi-0.2"; + +const abi: Abi = { + version: "0.2", + objects: [ + { + kind: "Object", + name: "TypeBar", + props: [ + { + kind: "Property", + name: "prop", + required: false, + type: { + kind: "Scalar", + scalar: "Int" + } + } + ] + }, + { + kind: "Object", + name: "SomeBar", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Ref", + ref_kind: "Object", + ref_name: "TypeBar" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/abi/examples/imports/schema.graphql b/abi/examples/imports/schema.graphql new file mode 100644 index 0000000..55633a8 --- /dev/null +++ b/abi/examples/imports/schema.graphql @@ -0,0 +1,8 @@ +#import { Lorem_AnotherFoo, YetFoo } into ExternalA from "wrap://ens/externalA.eth" +#import { TypeBar } from "wrap://ens/externalB.eth" + +type Baz { + propA: ExternalA_Lorem_AnotherFoo! + propB: ExternalA_YetFoo! + propC: TypeBar! +} \ No newline at end of file diff --git a/abi/examples/imports/schema.ts b/abi/examples/imports/schema.ts new file mode 100644 index 0000000..2ab68a5 --- /dev/null +++ b/abi/examples/imports/schema.ts @@ -0,0 +1,108 @@ +import { Abi } from "../../abi-0.2"; + +const abi: Abi = { + version: "0.2", + imports: [ + { + namespace: "ExternalA", + uri: "wrap://ens/externalA.eth", + id: "1", + imports: [ + { + namespace: "Lorem", + uri: "wrap://ens/lorem.eth", + id: "7", + objects: [ + { + kind: "Object", + name: "AnotherFoo", + props: [ + { + kind: "Property", + name: "prop", + required: false, + type: { + kind: "Scalar", + scalar: "Int" + } + } + ] + } + ] + } + ], + objects: [ + { + kind: "Object", + name: "YetFoo", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "String" + } + } + ] + } + ] + }, + ], + objects: [ + { + kind: "Object", + name: "TypeBar", + props: [ + { + kind: "Property", + name: "prop", + required: false, + type: { + kind: "Scalar", + scalar: "Int" + } + } + ] + }, + { + kind: "Object", + name: "Baz", + props: [ + { + kind: "Property", + name: "propA", + required: true, + type: { + kind: "ImportRef", + ref_kind: "Object", + ref_name: "AnotherFoo", + import_id: "1.7" + } + }, + { + kind: "Property", + name: "propB", + required: true, + type: { + kind: "ImportRef", + ref_kind: "Object", + ref_name: "YetFoo", + import_id: "1" + } + }, + { + kind: "Property", + name: "propC", + required: true, + type: { + kind: "Ref", + ref_kind: "Object", + ref_name: "TypeBar", + } + } + ] + } + ] +} \ No newline at end of file From 6f9e9604d9e0557ce9afd564a54dbc96f163dac1 Mon Sep 17 00:00:00 2001 From: Nestor Amesty Date: Thu, 12 Jan 2023 22:20:38 +0100 Subject: [PATCH 12/20] (chore): added enum and implement cases --- abi/examples/enum.graphql | 9 +- abi/examples/enum.ts | 30 ++++++ abi/examples/implements.graphql | 17 ++++ abi/examples/implements.ts | 161 ++++++++++++++++++++++++++++++++ abi/examples/interface.graphql | 11 --- 5 files changed, 216 insertions(+), 12 deletions(-) create mode 100644 abi/examples/enum.ts create mode 100644 abi/examples/implements.graphql create mode 100644 abi/examples/implements.ts delete mode 100644 abi/examples/interface.graphql diff --git a/abi/examples/enum.graphql b/abi/examples/enum.graphql index f87f5c1..dd0f9ca 100644 --- a/abi/examples/enum.graphql +++ b/abi/examples/enum.graphql @@ -1 +1,8 @@ -# TODO \ No newline at end of file +enum Foo { + BAR, + BAZ +} + +type SomeObject { + prop: Foo! +} \ No newline at end of file diff --git a/abi/examples/enum.ts b/abi/examples/enum.ts new file mode 100644 index 0000000..3947d92 --- /dev/null +++ b/abi/examples/enum.ts @@ -0,0 +1,30 @@ +import { Abi } from "../abi-0.2"; + +const abi: Abi = { + version: "0.2", + enums: [ + { + kind: "Enum", + name: "Foo", + constants: ["BAR", "BAZ"] + } + ], + objects: [ + { + kind: "Object", + name: "SomeObject", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Ref", + ref_kind: "Enum", + ref_name: "Foo" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/abi/examples/implements.graphql b/abi/examples/implements.graphql new file mode 100644 index 0000000..c610e90 --- /dev/null +++ b/abi/examples/implements.graphql @@ -0,0 +1,17 @@ +#import { Module, Foo } into External from "wrap://ens/external.eth" + +type Module implements External_Module { + func(arg: Int!): Int! + exec(arg: String!): String! +} + +type Bar implements External_Foo { + propA: Int! + propB: String! +} + +type Baz implements Bar { + propA: Int! + propB: String! + propC: String! +} diff --git a/abi/examples/implements.ts b/abi/examples/implements.ts new file mode 100644 index 0000000..c26c522 --- /dev/null +++ b/abi/examples/implements.ts @@ -0,0 +1,161 @@ +import { Abi } from "../abi-0.2"; + +const abi: Abi = { + version: "0.2", + imports: [ + { + namespace: "External", + uri: "wrap://ens/external.eth", + id: "1", + functions: [ + { + kind: "Function", + name: "func", + args: [ + { + kind: "Argument", + name: "arg", + required: true, + type: { + kind: "Scalar", + scalar: "Int" + } + } + ], + result: { + kind: "Result", + required: true, + type: { + kind: "Scalar", + scalar: "Int" + } + } + } + ], + objects: [ + { + kind: "Object", + name: "Foo", + props: [ + { + kind: "Property", + name: "propA", + required: true, + type: { + kind: "Scalar", + scalar: "Int" + } + } + ] + } + ] + } + ], + functions: [ + { + kind: "Function", + name: "func", + args: [ + { + kind: "Argument", + name: "arg", + required: true, + type: { + kind: "Scalar", + scalar: "Int" + } + } + ], + result: { + kind: "Result", + required: true, + type: { + kind: "Scalar", + scalar: "Int" + } + } + }, + { + kind: "Function", + name: "exec", + args: [ + { + kind: "Argument", + name: "arg", + required: true, + type: { + kind: "Scalar", + scalar: "String" + } + } + ], + result: { + kind: "Result", + required: true, + type: { + kind: "Scalar", + scalar: "String" + } + } + } + ], + objects: [ + { + kind: "Object", + name: "Bar", + props: [ + { + kind: "Property", + name: "propA", + required: true, + type: { + kind: "Scalar", + scalar: "Int" + } + }, + { + kind: "Property", + name: "propB", + required: true, + type: { + kind: "Scalar", + scalar: "String" + } + } + ] + }, + { + kind: "Object", + name: "Baz", + props: [ + { + kind: "Property", + name: "propA", + required: true, + type: { + kind: "Scalar", + scalar: "Int" + } + }, + { + kind: "Property", + name: "propB", + required: true, + type: { + kind: "Scalar", + scalar: "String" + } + }, + { + kind: "Property", + name: "propC", + required: true, + type: { + kind: "Scalar", + scalar: "String" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/abi/examples/interface.graphql b/abi/examples/interface.graphql deleted file mode 100644 index 7cc9655..0000000 --- a/abi/examples/interface.graphql +++ /dev/null @@ -1,11 +0,0 @@ -#import { Module, SwapParams } into Uniswap from "..." - -type Module implements Uniswap_Module { - execSwap( - swap: Uniswap_SwapParams! - ): ... -} - -type Uniswap_Module { - ... -} From 43550c3ad500825b5e3aafb8ad0f9f688486eca0 Mon Sep 17 00:00:00 2001 From: Nestor Amesty Date: Sat, 14 Jan 2023 19:07:38 +0100 Subject: [PATCH 13/20] (feat): added experiments for embedding and namespacing --- abi/examples/imports-embedding/bar.graphql | 5 + abi/examples/imports-embedding/bar.ts | 38 ++++++ abi/examples/imports-embedding/foo.graphql | 5 + abi/examples/imports-embedding/foo.ts | 38 ++++++ abi/examples/imports-embedding/lib1.graphql | 3 + abi/examples/imports-embedding/lib1.ts | 22 +++ abi/examples/imports-embedding/lib2.graphql | 3 + abi/examples/imports-embedding/lib2.ts | 22 +++ abi/examples/imports-embedding/user.graphql | 7 + abi/examples/imports-embedding/user.ts | 91 +++++++++++++ abi/examples/imports-namespacing/bar.graphql | 5 + abi/examples/imports-namespacing/bar.ts | 46 +++++++ abi/examples/imports-namespacing/foo.graphql | 5 + abi/examples/imports-namespacing/foo.ts | 46 +++++++ abi/examples/imports-namespacing/lib1.graphql | 3 + abi/examples/imports-namespacing/lib1.ts | 22 +++ abi/examples/imports-namespacing/lib2.graphql | 3 + abi/examples/imports-namespacing/lib2.ts | 22 +++ abi/examples/imports-namespacing/user.graphql | 7 + abi/examples/imports-namespacing/user.ts | 125 ++++++++++++++++++ 20 files changed, 518 insertions(+) create mode 100644 abi/examples/imports-embedding/bar.graphql create mode 100644 abi/examples/imports-embedding/bar.ts create mode 100644 abi/examples/imports-embedding/foo.graphql create mode 100644 abi/examples/imports-embedding/foo.ts create mode 100644 abi/examples/imports-embedding/lib1.graphql create mode 100644 abi/examples/imports-embedding/lib1.ts create mode 100644 abi/examples/imports-embedding/lib2.graphql create mode 100644 abi/examples/imports-embedding/lib2.ts create mode 100644 abi/examples/imports-embedding/user.graphql create mode 100644 abi/examples/imports-embedding/user.ts create mode 100644 abi/examples/imports-namespacing/bar.graphql create mode 100644 abi/examples/imports-namespacing/bar.ts create mode 100644 abi/examples/imports-namespacing/foo.graphql create mode 100644 abi/examples/imports-namespacing/foo.ts create mode 100644 abi/examples/imports-namespacing/lib1.graphql create mode 100644 abi/examples/imports-namespacing/lib1.ts create mode 100644 abi/examples/imports-namespacing/lib2.graphql create mode 100644 abi/examples/imports-namespacing/lib2.ts create mode 100644 abi/examples/imports-namespacing/user.graphql create mode 100644 abi/examples/imports-namespacing/user.ts diff --git a/abi/examples/imports-embedding/bar.graphql b/abi/examples/imports-embedding/bar.graphql new file mode 100644 index 0000000..a0657a2 --- /dev/null +++ b/abi/examples/imports-embedding/bar.graphql @@ -0,0 +1,5 @@ +#import { DataType } from "lib1" + +type Obj1 { + data: DataType! +} \ No newline at end of file diff --git a/abi/examples/imports-embedding/bar.ts b/abi/examples/imports-embedding/bar.ts new file mode 100644 index 0000000..c35a57f --- /dev/null +++ b/abi/examples/imports-embedding/bar.ts @@ -0,0 +1,38 @@ +import { Abi } from "../../abi-0.2"; + +const abi: Abi = { + version: "0.2", + objects: [ + { + kind: "Object", + name: "DataType", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "UInt32" + } + } + ] + }, + { + kind: "Object", + name: "Obj1", + props: [ + { + kind: "Property", + name: "data", + required: true, + type: { + kind: "Ref", + ref_kind: "Object", + ref_name: "DataType" + } + } + ] + }, + ] +} \ No newline at end of file diff --git a/abi/examples/imports-embedding/foo.graphql b/abi/examples/imports-embedding/foo.graphql new file mode 100644 index 0000000..d820bda --- /dev/null +++ b/abi/examples/imports-embedding/foo.graphql @@ -0,0 +1,5 @@ +#import { DataType } from "lib2" + +type Obj2 { + data: DataType! +} \ No newline at end of file diff --git a/abi/examples/imports-embedding/foo.ts b/abi/examples/imports-embedding/foo.ts new file mode 100644 index 0000000..f7f3671 --- /dev/null +++ b/abi/examples/imports-embedding/foo.ts @@ -0,0 +1,38 @@ +import { Abi } from "../../abi-0.2"; + +const abi: Abi = { + version: "0.2", + objects: [ + { + kind: "Object", + name: "DataType", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "Bytes" + } + } + ] + }, + { + kind: "Object", + name: "Obj2", + props: [ + { + kind: "Property", + name: "data", + required: true, + type: { + kind: "Ref", + ref_kind: "Object", + ref_name: "DataType" + } + } + ] + }, + ] +} \ No newline at end of file diff --git a/abi/examples/imports-embedding/lib1.graphql b/abi/examples/imports-embedding/lib1.graphql new file mode 100644 index 0000000..847dd39 --- /dev/null +++ b/abi/examples/imports-embedding/lib1.graphql @@ -0,0 +1,3 @@ +type DataType { + prop: UInt32! +} \ No newline at end of file diff --git a/abi/examples/imports-embedding/lib1.ts b/abi/examples/imports-embedding/lib1.ts new file mode 100644 index 0000000..a05f6a1 --- /dev/null +++ b/abi/examples/imports-embedding/lib1.ts @@ -0,0 +1,22 @@ +import { Abi } from "../../abi-0.2"; + +const abi: Abi = { + version: "0.2", + objects: [ + { + kind: "Object", + name: "DataType", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "UInt32" + } + } + ] + }, + ] +} \ No newline at end of file diff --git a/abi/examples/imports-embedding/lib2.graphql b/abi/examples/imports-embedding/lib2.graphql new file mode 100644 index 0000000..1b6863f --- /dev/null +++ b/abi/examples/imports-embedding/lib2.graphql @@ -0,0 +1,3 @@ +type DataType { + prop: Bytes! +} \ No newline at end of file diff --git a/abi/examples/imports-embedding/lib2.ts b/abi/examples/imports-embedding/lib2.ts new file mode 100644 index 0000000..5ac338a --- /dev/null +++ b/abi/examples/imports-embedding/lib2.ts @@ -0,0 +1,22 @@ +import { Abi } from "../../abi-0.2"; + +const abi: Abi = { + version: "0.2", + objects: [ + { + kind: "Object", + name: "DataType", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "Bytes" + } + } + ] + }, + ] +} \ No newline at end of file diff --git a/abi/examples/imports-embedding/user.graphql b/abi/examples/imports-embedding/user.graphql new file mode 100644 index 0000000..e9e7845 --- /dev/null +++ b/abi/examples/imports-embedding/user.graphql @@ -0,0 +1,7 @@ +#import { Obj1 } from "bar" +#import { Obj2 } from "foo" + +type UserObj { + obj1: Obj1! + obj2: Obj2! +} \ No newline at end of file diff --git a/abi/examples/imports-embedding/user.ts b/abi/examples/imports-embedding/user.ts new file mode 100644 index 0000000..32b6a56 --- /dev/null +++ b/abi/examples/imports-embedding/user.ts @@ -0,0 +1,91 @@ +import { Abi } from "../../abi-0.2"; + +const abi: Abi = { + version: "0.2", + imports: [ + { + id: "foo", + namespace: "foo", + uri: "foo", + objects: [{ + kind: "Object", + name: "DataType", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "UInt32" + } + } + ] + }] + }, + { + id: "bar", + namespace: "bar", + uri: "bar", + objects: [{ + kind: "Object", + name: "DataType", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "UInt32" + } + } + ] + }] + } + ], + objects: [ + { + kind: "Object", + name: "Obj1", + props: [ + { + kind: "Property", + name: "data", + required: true, + type: { + kind: "Ref", + ref_kind: "Object", + ref_name: "DataType" + } + } + ] + }, + { + kind: "Object", + name: "UserObj", + props: [ + { + kind: "Property", + name: "obj1", + required: true, + type: { + kind: "Ref", + ref_kind: "Object", + ref_name: "Obj1" + } + }, + { + kind: "Property", + name: "obj2", + required: true, + type: { + kind: "Ref", + ref_kind: "Object", + ref_name: "Obj2" + } + } + ] + }, + ] +} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/bar.graphql b/abi/examples/imports-namespacing/bar.graphql new file mode 100644 index 0000000..197160b --- /dev/null +++ b/abi/examples/imports-namespacing/bar.graphql @@ -0,0 +1,5 @@ +#import { DataType } into Lib1 from "lib1" + +type Obj1 { + data: Lib1_DataType! +} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/bar.ts b/abi/examples/imports-namespacing/bar.ts new file mode 100644 index 0000000..16863e5 --- /dev/null +++ b/abi/examples/imports-namespacing/bar.ts @@ -0,0 +1,46 @@ +import { Abi } from "../../abi-0.2"; + +const abi: Abi = { + version: "0.2", + imports: [ + { + uri: "lib1", + id: "0", + namespace: "Lib1", + objects: [{ + kind: "Object", + name: "DataType", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "UInt32" + } + } + ] + }] + } + ], + objects: [ + { + kind: "Object", + name: "Obj1", + props: [ + { + kind: "Property", + name: "data", + required: true, + type: { + kind: "ImportRef", + import_id: "0", + ref_kind: "Object", + ref_name: "DataType" + } + } + ] + }, + ] +} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/foo.graphql b/abi/examples/imports-namespacing/foo.graphql new file mode 100644 index 0000000..8aae8b3 --- /dev/null +++ b/abi/examples/imports-namespacing/foo.graphql @@ -0,0 +1,5 @@ +#import { DataType } into Lib2 from "lib2" + +type Obj2 { + data: Lib2_DataType! +} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/foo.ts b/abi/examples/imports-namespacing/foo.ts new file mode 100644 index 0000000..20cf872 --- /dev/null +++ b/abi/examples/imports-namespacing/foo.ts @@ -0,0 +1,46 @@ +import { Abi } from "../../abi-0.2"; + +const abi: Abi = { + version: "0.2", + imports: [ + { + uri: "lib2", + id: "0", + namespace: "Lib2", + objects: [{ + kind: "Object", + name: "DataType", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "Bytes" + } + } + ] + }] + } + ], + objects: [ + { + kind: "Object", + name: "Obj2", + props: [ + { + kind: "Property", + name: "data", + required: true, + type: { + kind: "ImportRef", + import_id: "0", + ref_kind: "Object", + ref_name: "DataType" + } + } + ] + }, + ] +} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/lib1.graphql b/abi/examples/imports-namespacing/lib1.graphql new file mode 100644 index 0000000..847dd39 --- /dev/null +++ b/abi/examples/imports-namespacing/lib1.graphql @@ -0,0 +1,3 @@ +type DataType { + prop: UInt32! +} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/lib1.ts b/abi/examples/imports-namespacing/lib1.ts new file mode 100644 index 0000000..a05f6a1 --- /dev/null +++ b/abi/examples/imports-namespacing/lib1.ts @@ -0,0 +1,22 @@ +import { Abi } from "../../abi-0.2"; + +const abi: Abi = { + version: "0.2", + objects: [ + { + kind: "Object", + name: "DataType", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "UInt32" + } + } + ] + }, + ] +} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/lib2.graphql b/abi/examples/imports-namespacing/lib2.graphql new file mode 100644 index 0000000..1b6863f --- /dev/null +++ b/abi/examples/imports-namespacing/lib2.graphql @@ -0,0 +1,3 @@ +type DataType { + prop: Bytes! +} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/lib2.ts b/abi/examples/imports-namespacing/lib2.ts new file mode 100644 index 0000000..5ac338a --- /dev/null +++ b/abi/examples/imports-namespacing/lib2.ts @@ -0,0 +1,22 @@ +import { Abi } from "../../abi-0.2"; + +const abi: Abi = { + version: "0.2", + objects: [ + { + kind: "Object", + name: "DataType", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "Bytes" + } + } + ] + }, + ] +} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/user.graphql b/abi/examples/imports-namespacing/user.graphql new file mode 100644 index 0000000..bc19b20 --- /dev/null +++ b/abi/examples/imports-namespacing/user.graphql @@ -0,0 +1,7 @@ +#import { Obj1 } into Bar from "bar" +#import { Obj2 } into Foo from "foo" + +type UserObj { + obj1: Bar_Obj1! + obj2: Foo_Obj2! +} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/user.ts b/abi/examples/imports-namespacing/user.ts new file mode 100644 index 0000000..34870da --- /dev/null +++ b/abi/examples/imports-namespacing/user.ts @@ -0,0 +1,125 @@ +import { Abi } from "../../abi-0.2"; + +const abi: Abi = { + version: "0.2", + imports: [ + { + id: "0", + namespace: "Bar", + uri: "bar", + imports: [ + { + uri: "lib1", + id: "0", + namespace: "Lib1", + objects: [{ + kind: "Object", + name: "DataType", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "UInt32" + } + } + ] + }] + } + ], + objects: [{ + kind: "Object", + name: "Obj1", + props: [ + { + kind: "Property", + name: "data", + required: true, + type: { + kind: "ImportRef", + import_id: "0", + ref_kind: "Object", + ref_name: "DataType" + } + } + ] + }] + }, + { + id: "1", + namespace: "Foo", + uri: "foo", + imports: [ + { + uri: "lib2", + id: "0", + namespace: "Lib2", + objects: [{ + kind: "Object", + name: "DataType", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "Bytes" + } + } + ] + }] + } + ], + objects: [{ + kind: "Object", + name: "Obj2", + props: [ + { + kind: "Property", + name: "data", + required: true, + type: { + kind: "ImportRef", + import_id: "0", + ref_kind: "Object", + ref_name: "DataType" + } + } + ] + }] + }, + ], + objects: [ + { + kind: "Object", + name: "UserObj", + props: [ + { + kind: "Property", + name: "obj1", + required: true, + type: { + import_id: "0", + kind: "ImportRef", + ref_kind: "Object", + ref_name: "Obj1" + } + }, + { + kind: "Property", + name: "obj2", + required: true, + type: { + import_id: "1", + kind: "ImportRef", + ref_kind: "Object", + ref_name: "Obj2" + } + } + ] + }, + ] +} \ No newline at end of file From 0db0512d4661ee8e3a40879c24e9475ac2ebb0e4 Mon Sep 17 00:00:00 2001 From: Nestor Amesty Date: Sat, 14 Jan 2023 19:18:34 +0100 Subject: [PATCH 14/20] (chore): added local peer dep case --- abi/examples/imports-namespacing/bar.graphql | 5 ++ abi/examples/imports-namespacing/bar.ts | 15 ++++++ abi/examples/imports-namespacing/user.ts | 48 +++++++++++++------- 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/abi/examples/imports-namespacing/bar.graphql b/abi/examples/imports-namespacing/bar.graphql index 197160b..fb88b9d 100644 --- a/abi/examples/imports-namespacing/bar.graphql +++ b/abi/examples/imports-namespacing/bar.graphql @@ -1,5 +1,10 @@ #import { DataType } into Lib1 from "lib1" +type Baz { + prop: String! +} + type Obj1 { data: Lib1_DataType! + data2: Baz! } \ No newline at end of file diff --git a/abi/examples/imports-namespacing/bar.ts b/abi/examples/imports-namespacing/bar.ts index 16863e5..5a3f349 100644 --- a/abi/examples/imports-namespacing/bar.ts +++ b/abi/examples/imports-namespacing/bar.ts @@ -42,5 +42,20 @@ const abi: Abi = { } ] }, + { + kind: "Object", + name: "Baz", + props: [ + { + kind: "Property", + name: "data2", + required: true, + type: { + kind: "Scalar", + scalar: "String" + } + } + ] + } ] } \ No newline at end of file diff --git a/abi/examples/imports-namespacing/user.ts b/abi/examples/imports-namespacing/user.ts index 34870da..059a020 100644 --- a/abi/examples/imports-namespacing/user.ts +++ b/abi/examples/imports-namespacing/user.ts @@ -29,23 +29,39 @@ const abi: Abi = { }] } ], - objects: [{ - kind: "Object", - name: "Obj1", - props: [ - { - kind: "Property", - name: "data", - required: true, - type: { - kind: "ImportRef", - import_id: "0", - ref_kind: "Object", - ref_name: "DataType" + objects: [ + { + kind: "Object", + name: "Baz", + props: [ + { + kind: "Property", + name: "data2", + required: true, + type: { + kind: "Scalar", + scalar: "String" + } } - } - ] - }] + ] + }, + { + kind: "Object", + name: "Obj1", + props: [ + { + kind: "Property", + name: "data", + required: true, + type: { + kind: "ImportRef", + import_id: "0", + ref_kind: "Object", + ref_name: "DataType" + } + } + ] + }] }, { id: "1", From dd1b48c396af12d0c6fcfce3b4b6d2620da83d1b Mon Sep 17 00:00:00 2001 From: Nestor Amesty Date: Sun, 15 Jan 2023 20:01:55 +0100 Subject: [PATCH 15/20] (chore): settled for namespacing everything. Import an import --- abi/README.md | 3 +- abi/examples/imports-embedding/bar.graphql | 5 - abi/examples/imports-embedding/foo.graphql | 5 - abi/examples/imports-embedding/foo.ts | 38 ------ abi/examples/imports-embedding/lib1.graphql | 3 - abi/examples/imports-embedding/lib1.ts | 22 ---- abi/examples/imports-embedding/user.graphql | 7 -- abi/examples/imports-embedding/user.ts | 91 --------------- abi/examples/imports-namespacing/lib1.graphql | 3 - abi/examples/imports-namespacing/lib1.ts | 22 ---- abi/examples/imports-namespacing/lib2.graphql | 3 - abi/examples/imports-namespacing/lib2.ts | 22 ---- .../bar.graphql | 2 +- .../{imports-namespacing => imports}/bar.ts | 15 +++ abi/examples/imports/externalA.graphql | 6 - abi/examples/imports/externalA.ts | 63 ---------- abi/examples/imports/externalB.graphql | 5 - abi/examples/imports/externalB.ts | 38 ------ .../foo.graphql | 0 .../{imports-namespacing => imports}/foo.ts | 0 abi/examples/imports/lib1.graphql | 7 ++ .../bar.ts => imports/lib1.ts} | 9 +- .../lib2.graphql | 0 .../{imports-embedding => imports}/lib2.ts | 0 abi/examples/imports/schema.graphql | 8 -- abi/examples/imports/schema.ts | 108 ------------------ .../user.graphql | 2 +- .../{imports-namespacing => imports}/user.ts | 17 ++- 28 files changed, 46 insertions(+), 458 deletions(-) delete mode 100644 abi/examples/imports-embedding/bar.graphql delete mode 100644 abi/examples/imports-embedding/foo.graphql delete mode 100644 abi/examples/imports-embedding/foo.ts delete mode 100644 abi/examples/imports-embedding/lib1.graphql delete mode 100644 abi/examples/imports-embedding/lib1.ts delete mode 100644 abi/examples/imports-embedding/user.graphql delete mode 100644 abi/examples/imports-embedding/user.ts delete mode 100644 abi/examples/imports-namespacing/lib1.graphql delete mode 100644 abi/examples/imports-namespacing/lib1.ts delete mode 100644 abi/examples/imports-namespacing/lib2.graphql delete mode 100644 abi/examples/imports-namespacing/lib2.ts rename abi/examples/{imports-namespacing => imports}/bar.graphql (59%) rename abi/examples/{imports-namespacing => imports}/bar.ts (78%) delete mode 100644 abi/examples/imports/externalA.graphql delete mode 100644 abi/examples/imports/externalA.ts delete mode 100644 abi/examples/imports/externalB.graphql delete mode 100644 abi/examples/imports/externalB.ts rename abi/examples/{imports-namespacing => imports}/foo.graphql (100%) rename abi/examples/{imports-namespacing => imports}/foo.ts (100%) create mode 100644 abi/examples/imports/lib1.graphql rename abi/examples/{imports-embedding/bar.ts => imports/lib1.ts} (79%) rename abi/examples/{imports-embedding => imports}/lib2.graphql (100%) rename abi/examples/{imports-embedding => imports}/lib2.ts (100%) delete mode 100644 abi/examples/imports/schema.graphql delete mode 100644 abi/examples/imports/schema.ts rename abi/examples/{imports-namespacing => imports}/user.graphql (62%) rename abi/examples/{imports-namespacing => imports}/user.ts (88%) diff --git a/abi/README.md b/abi/README.md index dc1f06b..44c525d 100644 --- a/abi/README.md +++ b/abi/README.md @@ -20,4 +20,5 @@ 5. **Remove Comments:** In order to help optimize the ABI, we've removed all `comment` properties. Comments can instead be found on the original source file written by the user that was used to produce the ABI. 6. **Keyword `implements` no longer implies inheritance**: Currently, users use `implements` as `extends`. If they implement an interface, the interface's properties get automatically copied over to the implementation type. While this allows users to type less, it incorrectly behaves as inheritance; so we're removing that behavior. Now if `A implements B`, we will just validate that `A` contains the properties of `B`. 7. **Remove Interfaces and Capabilities:** All wrappers have implicit interface definitions (by having a schema) but only some have implementations. Therefore, there's no reason to restrict implementation wrappers types to be used as interfaces (with the `implements` keyword); or to only enable `getImplementations` capabilities in interface wrappers. So we're removing the concept of `interfaces` in favor of just using types, and enabling `getImplementation` capabilities for all modules. -8. **Import an imported ABI's imports**: Currently, it isn't possible to use a type that was imported in an import without manually re-exporting it, as referenced here: https://github.com/polywrap/toolchain/issues/1448. This will now be possible. \ No newline at end of file +8. **Import an imported ABI's imports**: Currently, it isn't possible to use a type that was imported in an import without manually re-exporting it, as referenced here: https://github.com/polywrap/toolchain/issues/1448. This will now be possible by importing it in its namespaced form. See the [example](abi/examples/imports/schema.ts) +9. **Non-namespaced imports are now embedded into local ABI**: Ex \ No newline at end of file diff --git a/abi/examples/imports-embedding/bar.graphql b/abi/examples/imports-embedding/bar.graphql deleted file mode 100644 index a0657a2..0000000 --- a/abi/examples/imports-embedding/bar.graphql +++ /dev/null @@ -1,5 +0,0 @@ -#import { DataType } from "lib1" - -type Obj1 { - data: DataType! -} \ No newline at end of file diff --git a/abi/examples/imports-embedding/foo.graphql b/abi/examples/imports-embedding/foo.graphql deleted file mode 100644 index d820bda..0000000 --- a/abi/examples/imports-embedding/foo.graphql +++ /dev/null @@ -1,5 +0,0 @@ -#import { DataType } from "lib2" - -type Obj2 { - data: DataType! -} \ No newline at end of file diff --git a/abi/examples/imports-embedding/foo.ts b/abi/examples/imports-embedding/foo.ts deleted file mode 100644 index f7f3671..0000000 --- a/abi/examples/imports-embedding/foo.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Abi } from "../../abi-0.2"; - -const abi: Abi = { - version: "0.2", - objects: [ - { - kind: "Object", - name: "DataType", - props: [ - { - kind: "Property", - name: "prop", - required: true, - type: { - kind: "Scalar", - scalar: "Bytes" - } - } - ] - }, - { - kind: "Object", - name: "Obj2", - props: [ - { - kind: "Property", - name: "data", - required: true, - type: { - kind: "Ref", - ref_kind: "Object", - ref_name: "DataType" - } - } - ] - }, - ] -} \ No newline at end of file diff --git a/abi/examples/imports-embedding/lib1.graphql b/abi/examples/imports-embedding/lib1.graphql deleted file mode 100644 index 847dd39..0000000 --- a/abi/examples/imports-embedding/lib1.graphql +++ /dev/null @@ -1,3 +0,0 @@ -type DataType { - prop: UInt32! -} \ No newline at end of file diff --git a/abi/examples/imports-embedding/lib1.ts b/abi/examples/imports-embedding/lib1.ts deleted file mode 100644 index a05f6a1..0000000 --- a/abi/examples/imports-embedding/lib1.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Abi } from "../../abi-0.2"; - -const abi: Abi = { - version: "0.2", - objects: [ - { - kind: "Object", - name: "DataType", - props: [ - { - kind: "Property", - name: "prop", - required: true, - type: { - kind: "Scalar", - scalar: "UInt32" - } - } - ] - }, - ] -} \ No newline at end of file diff --git a/abi/examples/imports-embedding/user.graphql b/abi/examples/imports-embedding/user.graphql deleted file mode 100644 index e9e7845..0000000 --- a/abi/examples/imports-embedding/user.graphql +++ /dev/null @@ -1,7 +0,0 @@ -#import { Obj1 } from "bar" -#import { Obj2 } from "foo" - -type UserObj { - obj1: Obj1! - obj2: Obj2! -} \ No newline at end of file diff --git a/abi/examples/imports-embedding/user.ts b/abi/examples/imports-embedding/user.ts deleted file mode 100644 index 32b6a56..0000000 --- a/abi/examples/imports-embedding/user.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { Abi } from "../../abi-0.2"; - -const abi: Abi = { - version: "0.2", - imports: [ - { - id: "foo", - namespace: "foo", - uri: "foo", - objects: [{ - kind: "Object", - name: "DataType", - props: [ - { - kind: "Property", - name: "prop", - required: true, - type: { - kind: "Scalar", - scalar: "UInt32" - } - } - ] - }] - }, - { - id: "bar", - namespace: "bar", - uri: "bar", - objects: [{ - kind: "Object", - name: "DataType", - props: [ - { - kind: "Property", - name: "prop", - required: true, - type: { - kind: "Scalar", - scalar: "UInt32" - } - } - ] - }] - } - ], - objects: [ - { - kind: "Object", - name: "Obj1", - props: [ - { - kind: "Property", - name: "data", - required: true, - type: { - kind: "Ref", - ref_kind: "Object", - ref_name: "DataType" - } - } - ] - }, - { - kind: "Object", - name: "UserObj", - props: [ - { - kind: "Property", - name: "obj1", - required: true, - type: { - kind: "Ref", - ref_kind: "Object", - ref_name: "Obj1" - } - }, - { - kind: "Property", - name: "obj2", - required: true, - type: { - kind: "Ref", - ref_kind: "Object", - ref_name: "Obj2" - } - } - ] - }, - ] -} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/lib1.graphql b/abi/examples/imports-namespacing/lib1.graphql deleted file mode 100644 index 847dd39..0000000 --- a/abi/examples/imports-namespacing/lib1.graphql +++ /dev/null @@ -1,3 +0,0 @@ -type DataType { - prop: UInt32! -} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/lib1.ts b/abi/examples/imports-namespacing/lib1.ts deleted file mode 100644 index a05f6a1..0000000 --- a/abi/examples/imports-namespacing/lib1.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Abi } from "../../abi-0.2"; - -const abi: Abi = { - version: "0.2", - objects: [ - { - kind: "Object", - name: "DataType", - props: [ - { - kind: "Property", - name: "prop", - required: true, - type: { - kind: "Scalar", - scalar: "UInt32" - } - } - ] - }, - ] -} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/lib2.graphql b/abi/examples/imports-namespacing/lib2.graphql deleted file mode 100644 index 1b6863f..0000000 --- a/abi/examples/imports-namespacing/lib2.graphql +++ /dev/null @@ -1,3 +0,0 @@ -type DataType { - prop: Bytes! -} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/lib2.ts b/abi/examples/imports-namespacing/lib2.ts deleted file mode 100644 index 5ac338a..0000000 --- a/abi/examples/imports-namespacing/lib2.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Abi } from "../../abi-0.2"; - -const abi: Abi = { - version: "0.2", - objects: [ - { - kind: "Object", - name: "DataType", - props: [ - { - kind: "Property", - name: "prop", - required: true, - type: { - kind: "Scalar", - scalar: "Bytes" - } - } - ] - }, - ] -} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/bar.graphql b/abi/examples/imports/bar.graphql similarity index 59% rename from abi/examples/imports-namespacing/bar.graphql rename to abi/examples/imports/bar.graphql index fb88b9d..fbbbdd6 100644 --- a/abi/examples/imports-namespacing/bar.graphql +++ b/abi/examples/imports/bar.graphql @@ -1,4 +1,4 @@ -#import { DataType } into Lib1 from "lib1" +#import { DataType, SecondType } into Lib1 from "lib1" type Baz { prop: String! diff --git a/abi/examples/imports-namespacing/bar.ts b/abi/examples/imports/bar.ts similarity index 78% rename from abi/examples/imports-namespacing/bar.ts rename to abi/examples/imports/bar.ts index 5a3f349..bce030d 100644 --- a/abi/examples/imports-namespacing/bar.ts +++ b/abi/examples/imports/bar.ts @@ -21,6 +21,21 @@ const abi: Abi = { } } ] + }, + { + kind: "Object", + name: "SecondType", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "String" + } + } + ] }] } ], diff --git a/abi/examples/imports/externalA.graphql b/abi/examples/imports/externalA.graphql deleted file mode 100644 index 4e86b1f..0000000 --- a/abi/examples/imports/externalA.graphql +++ /dev/null @@ -1,6 +0,0 @@ -#import { AnotherFoo } into Lorem from "wrap://ens/lorem.eth" -#import { YetFoo } from "wrap://ens/lorem.eth" - -type SomeFoo { - prop: Lorem_AnotherFoo! -} diff --git a/abi/examples/imports/externalA.ts b/abi/examples/imports/externalA.ts deleted file mode 100644 index 2db47a9..0000000 --- a/abi/examples/imports/externalA.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { Abi } from "../../abi-0.2"; - -const abi: Abi = { - version: "0.2", - imports: [ - { - namespace: "Lorem", - uri: "wrap://ens/lorem.eth", - id: "7", - objects: [ - { - kind: "Object", - name: "AnotherFoo", - props: [ - { - kind: "Property", - name: "prop", - required: false, - type: { - kind: "Scalar", - scalar: "Int" - } - } - ] - } - ] - } - ], - objects: [ - { - kind: "Object", - name: "SomeFoo", - props: [ - { - kind: "Property", - name: "prop", - required: true, - type: { - kind: "ImportRef", - import_id: "7", - ref_kind: "Object", - ref_name: "AnotherFoo" - } - } - ] - }, - { - kind: "Object", - name: "YetFoo", - props: [ - { - kind: "Property", - name: "prop", - required: true, - type: { - kind: "Scalar", - scalar: "String" - } - } - ] - } - ] -} \ No newline at end of file diff --git a/abi/examples/imports/externalB.graphql b/abi/examples/imports/externalB.graphql deleted file mode 100644 index e0862fb..0000000 --- a/abi/examples/imports/externalB.graphql +++ /dev/null @@ -1,5 +0,0 @@ -#import { TypeBar } from "wrap://ens/lorem.eth" - -type SomeBar { - prop: TypeBar! -} diff --git a/abi/examples/imports/externalB.ts b/abi/examples/imports/externalB.ts deleted file mode 100644 index 29adcca..0000000 --- a/abi/examples/imports/externalB.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Abi } from "../../abi-0.2"; - -const abi: Abi = { - version: "0.2", - objects: [ - { - kind: "Object", - name: "TypeBar", - props: [ - { - kind: "Property", - name: "prop", - required: false, - type: { - kind: "Scalar", - scalar: "Int" - } - } - ] - }, - { - kind: "Object", - name: "SomeBar", - props: [ - { - kind: "Property", - name: "prop", - required: true, - type: { - kind: "Ref", - ref_kind: "Object", - ref_name: "TypeBar" - } - } - ] - } - ] -} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/foo.graphql b/abi/examples/imports/foo.graphql similarity index 100% rename from abi/examples/imports-namespacing/foo.graphql rename to abi/examples/imports/foo.graphql diff --git a/abi/examples/imports-namespacing/foo.ts b/abi/examples/imports/foo.ts similarity index 100% rename from abi/examples/imports-namespacing/foo.ts rename to abi/examples/imports/foo.ts diff --git a/abi/examples/imports/lib1.graphql b/abi/examples/imports/lib1.graphql new file mode 100644 index 0000000..0d36b91 --- /dev/null +++ b/abi/examples/imports/lib1.graphql @@ -0,0 +1,7 @@ +type DataType { + prop: UInt32! +} + +type SecondType { + prop: String! +} \ No newline at end of file diff --git a/abi/examples/imports-embedding/bar.ts b/abi/examples/imports/lib1.ts similarity index 79% rename from abi/examples/imports-embedding/bar.ts rename to abi/examples/imports/lib1.ts index c35a57f..a92345b 100644 --- a/abi/examples/imports-embedding/bar.ts +++ b/abi/examples/imports/lib1.ts @@ -20,16 +20,15 @@ const abi: Abi = { }, { kind: "Object", - name: "Obj1", + name: "SecondType", props: [ { kind: "Property", - name: "data", + name: "prop", required: true, type: { - kind: "Ref", - ref_kind: "Object", - ref_name: "DataType" + kind: "Scalar", + scalar: "String" } } ] diff --git a/abi/examples/imports-embedding/lib2.graphql b/abi/examples/imports/lib2.graphql similarity index 100% rename from abi/examples/imports-embedding/lib2.graphql rename to abi/examples/imports/lib2.graphql diff --git a/abi/examples/imports-embedding/lib2.ts b/abi/examples/imports/lib2.ts similarity index 100% rename from abi/examples/imports-embedding/lib2.ts rename to abi/examples/imports/lib2.ts diff --git a/abi/examples/imports/schema.graphql b/abi/examples/imports/schema.graphql deleted file mode 100644 index 55633a8..0000000 --- a/abi/examples/imports/schema.graphql +++ /dev/null @@ -1,8 +0,0 @@ -#import { Lorem_AnotherFoo, YetFoo } into ExternalA from "wrap://ens/externalA.eth" -#import { TypeBar } from "wrap://ens/externalB.eth" - -type Baz { - propA: ExternalA_Lorem_AnotherFoo! - propB: ExternalA_YetFoo! - propC: TypeBar! -} \ No newline at end of file diff --git a/abi/examples/imports/schema.ts b/abi/examples/imports/schema.ts deleted file mode 100644 index 2ab68a5..0000000 --- a/abi/examples/imports/schema.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { Abi } from "../../abi-0.2"; - -const abi: Abi = { - version: "0.2", - imports: [ - { - namespace: "ExternalA", - uri: "wrap://ens/externalA.eth", - id: "1", - imports: [ - { - namespace: "Lorem", - uri: "wrap://ens/lorem.eth", - id: "7", - objects: [ - { - kind: "Object", - name: "AnotherFoo", - props: [ - { - kind: "Property", - name: "prop", - required: false, - type: { - kind: "Scalar", - scalar: "Int" - } - } - ] - } - ] - } - ], - objects: [ - { - kind: "Object", - name: "YetFoo", - props: [ - { - kind: "Property", - name: "prop", - required: true, - type: { - kind: "Scalar", - scalar: "String" - } - } - ] - } - ] - }, - ], - objects: [ - { - kind: "Object", - name: "TypeBar", - props: [ - { - kind: "Property", - name: "prop", - required: false, - type: { - kind: "Scalar", - scalar: "Int" - } - } - ] - }, - { - kind: "Object", - name: "Baz", - props: [ - { - kind: "Property", - name: "propA", - required: true, - type: { - kind: "ImportRef", - ref_kind: "Object", - ref_name: "AnotherFoo", - import_id: "1.7" - } - }, - { - kind: "Property", - name: "propB", - required: true, - type: { - kind: "ImportRef", - ref_kind: "Object", - ref_name: "YetFoo", - import_id: "1" - } - }, - { - kind: "Property", - name: "propC", - required: true, - type: { - kind: "Ref", - ref_kind: "Object", - ref_name: "TypeBar", - } - } - ] - } - ] -} \ No newline at end of file diff --git a/abi/examples/imports-namespacing/user.graphql b/abi/examples/imports/user.graphql similarity index 62% rename from abi/examples/imports-namespacing/user.graphql rename to abi/examples/imports/user.graphql index bc19b20..729c6bc 100644 --- a/abi/examples/imports-namespacing/user.graphql +++ b/abi/examples/imports/user.graphql @@ -1,4 +1,4 @@ -#import { Obj1 } into Bar from "bar" +#import { Obj1, Lib1_SecondType } into Bar from "bar" #import { Obj2 } into Foo from "foo" type UserObj { diff --git a/abi/examples/imports-namespacing/user.ts b/abi/examples/imports/user.ts similarity index 88% rename from abi/examples/imports-namespacing/user.ts rename to abi/examples/imports/user.ts index 059a020..a74da3b 100644 --- a/abi/examples/imports-namespacing/user.ts +++ b/abi/examples/imports/user.ts @@ -26,8 +26,23 @@ const abi: Abi = { } } ] + }, + { + kind: "Object", + name: "SecondType", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "String" + } + } + ] }] - } + }, ], objects: [ { From 998f0c2a9fa676fe897c934e997fe967d22ccfdf Mon Sep 17 00:00:00 2001 From: Nestor Amesty Date: Mon, 16 Jan 2023 13:04:47 +0100 Subject: [PATCH 16/20] (chore): added future plans and ABI routing --- abi/README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/abi/README.md b/abi/README.md index 44c525d..1ab75f4 100644 --- a/abi/README.md +++ b/abi/README.md @@ -20,5 +20,10 @@ 5. **Remove Comments:** In order to help optimize the ABI, we've removed all `comment` properties. Comments can instead be found on the original source file written by the user that was used to produce the ABI. 6. **Keyword `implements` no longer implies inheritance**: Currently, users use `implements` as `extends`. If they implement an interface, the interface's properties get automatically copied over to the implementation type. While this allows users to type less, it incorrectly behaves as inheritance; so we're removing that behavior. Now if `A implements B`, we will just validate that `A` contains the properties of `B`. 7. **Remove Interfaces and Capabilities:** All wrappers have implicit interface definitions (by having a schema) but only some have implementations. Therefore, there's no reason to restrict implementation wrappers types to be used as interfaces (with the `implements` keyword); or to only enable `getImplementations` capabilities in interface wrappers. So we're removing the concept of `interfaces` in favor of just using types, and enabling `getImplementation` capabilities for all modules. -8. **Import an imported ABI's imports**: Currently, it isn't possible to use a type that was imported in an import without manually re-exporting it, as referenced here: https://github.com/polywrap/toolchain/issues/1448. This will now be possible by importing it in its namespaced form. See the [example](abi/examples/imports/schema.ts) -9. **Non-namespaced imports are now embedded into local ABI**: Ex \ No newline at end of file +8. **Import an imported ABI's imports**: Currently, it isn't possible to use a type that was imported in an import without manually re-exporting it, as referenced here: https://github.com/polywrap/toolchain/issues/1448. This will now be possible by importing it in its namespaced form. See the [example](abi/examples/imports/user.ts) +9. **Introduced `ImportRef` (references to an import)**: references to an imported definition are now defined as `ImportRef`s. All imported ABIs contain an `id` propertyand imported ABIs can also have nested imported ABIs inside of them. Therefore, types defined in nested imports can be referenced through a "route" of their IDs. For example, route `1.2.3` would point to an imported ABI with ID `3`, nested inside an imported ABI with ID `2`, nested inside an imported ABI with ID `1`. `ImportRef`s contain an `import_id` property that point to the referenced types's import route. + +## Future Plans + +- Research merkle-root hashes for root-definitions (function, object, enum, etc?) to help with validation execution time. +- Introduce the concept of "Runtime ABI", which would be a compressed hyper optimized ABI for small storage & download, and fast runtime traversal & introspection (hashes, etc). This ABI would be separate from the ABI that the CLI uses to generate code. This differentiation would help to avoid constraining ourselves too much with optimizations, in the ABI that we manipulate in the CLI and focus on "ease of work"; while also not holding back on optimizations for the "Runtime ABI" because it'd be harder to work with From 664d2f75dae5c41aa043c413d0428c0e31a6b250 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Mon, 16 Jan 2023 20:51:54 -0500 Subject: [PATCH 17/20] add importType + start json schema --- abi/0.2.json | 69 ++++++++++++++++++++++++++++++++++++ abi/abi-0.2.ts | 5 +++ abi/examples/implements.ts | 1 + abi/examples/imports/bar.ts | 1 + abi/examples/imports/foo.ts | 1 + abi/examples/imports/user.ts | 4 +++ abi/examples/todo | 24 +++++++++---- 7 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 abi/0.2.json diff --git a/abi/0.2.json b/abi/0.2.json new file mode 100644 index 0000000..5c79442 --- /dev/null +++ b/abi/0.2.json @@ -0,0 +1,69 @@ +{ + "id": "Abi", + "type": "object", + "definitions": { + "uniqueDefKind": { + "type": "string", + "enum": [ + "Function", + "Object", + "Enum", + "Env" + ] + }, + "typeKind": { + "type": "string", + "enum": [ + "Scalar", + "Array", + "Map", + "Ref", + "ImportRef" + ] + }, + "scalarType": { + "type": "string", + "enum": [ + "UInt", + "UInt8", + "UInt16", + "UInt32", + "Int", + "Int8", + "Int16", + "Int32", + "String", + "Boolean", + "Bytes", + "BigInt", + "BigNumber", + "JSON" + ] + }, + "mapKeyType": { + "type": "string", + "enum": [ + "UInt", + "UInt8", + "UInt16", + "UInt32", + "Int", + "Int8", + "Int16", + "Int32", + "String" + ] + }, + "optionalType": { + "type": "object", + "properties": { + "required": { + "type": "boolean" + }, + "type": { + "$ref": "#/definitions/anyType" + } + } + }, + } +} diff --git a/abi/abi-0.2.ts b/abi/abi-0.2.ts index fe04c34..45270d0 100644 --- a/abi/abi-0.2.ts +++ b/abi/abi-0.2.ts @@ -12,9 +12,14 @@ export interface Abi extends AbiDefs { imports?: ImportedAbi[]; } +export type ImportAbiType = + | "wasm" + | "interface"; + export interface ImportedAbi extends AbiDefs { id: string; uri: string; + type: ImportAbiType; namespace: string; imports?: ImportedAbi[]; } diff --git a/abi/examples/implements.ts b/abi/examples/implements.ts index c26c522..6728551 100644 --- a/abi/examples/implements.ts +++ b/abi/examples/implements.ts @@ -6,6 +6,7 @@ const abi: Abi = { { namespace: "External", uri: "wrap://ens/external.eth", + type: "wasm", id: "1", functions: [ { diff --git a/abi/examples/imports/bar.ts b/abi/examples/imports/bar.ts index bce030d..f484939 100644 --- a/abi/examples/imports/bar.ts +++ b/abi/examples/imports/bar.ts @@ -5,6 +5,7 @@ const abi: Abi = { imports: [ { uri: "lib1", + type: "wasm", id: "0", namespace: "Lib1", objects: [{ diff --git a/abi/examples/imports/foo.ts b/abi/examples/imports/foo.ts index 20cf872..b728dce 100644 --- a/abi/examples/imports/foo.ts +++ b/abi/examples/imports/foo.ts @@ -5,6 +5,7 @@ const abi: Abi = { imports: [ { uri: "lib2", + type: "wasm", id: "0", namespace: "Lib2", objects: [{ diff --git a/abi/examples/imports/user.ts b/abi/examples/imports/user.ts index a74da3b..b81e06b 100644 --- a/abi/examples/imports/user.ts +++ b/abi/examples/imports/user.ts @@ -7,9 +7,11 @@ const abi: Abi = { id: "0", namespace: "Bar", uri: "bar", + type: "wasm", imports: [ { uri: "lib1", + type: "wasm", id: "0", namespace: "Lib1", objects: [{ @@ -82,9 +84,11 @@ const abi: Abi = { id: "1", namespace: "Foo", uri: "foo", + type: "wasm", imports: [ { uri: "lib2", + type: "wasm", id: "0", namespace: "Lib2", objects: [{ diff --git a/abi/examples/todo b/abi/examples/todo index 66ab1ee..c52bc08 100644 --- a/abi/examples/todo +++ b/abi/examples/todo @@ -1,13 +1,23 @@ TODO: -- referencing imports -- implemented interfaces -- parity with old ABI -- notes on things removed from old ABI (capabilities) +x add wrapper type to imports +x parity with old ABI +- use maps for unique def kinds +- use enums instead of strings - JSON-schema - Transpile to TS +- notes on things removed from old ABI (capabilities) - compile the ts example files to make sure they implement the ABI well -- research merkle-root hashes for root-definitions (function, object, enum, etc?) to help with validation execution time - - "does interface A implement interface B?" - document the choices around imports & how import "routing" works for importing the imports of your import. (ex: "1.2.3") +- migration script from 0.1 to 0.2? -- document future plan: "runtime abi" is a compressed hyper optimized ABI for small storage & download, and fast runtime traversal & introspection (hashes, etc) +Test-Cases: +- referencing imports +- implemented interfaces + +After Init PR: +- fix complex types + +Future: +- "runtime abi" is a compressed hyper optimized ABI for small storage & download, and fast runtime traversal & introspection (hashes, etc) +- research merkle-root hashes for root-definitions (function, object, enum, etc?) to help with validation execution time + - "does interface A implement interface B?" From 0465ebdf656e413e6cedcb09b98811777abbe0a5 Mon Sep 17 00:00:00 2001 From: Nestor Amesty Date: Wed, 18 Jan 2023 02:16:09 +0100 Subject: [PATCH 18/20] (chore): updated examples and todos --- abi/0.2.json | 2 +- abi/examples/env.ts | 19 +++++++++++++++++++ abi/examples/imports/user.ts | 2 +- abi/examples/sanity.graphql | 4 ---- abi/examples/sanity.ts | 17 ----------------- abi/examples/todo | 16 ++++++++-------- 6 files changed, 29 insertions(+), 31 deletions(-) create mode 100644 abi/examples/env.ts diff --git a/abi/0.2.json b/abi/0.2.json index 5c79442..ac7cb33 100644 --- a/abi/0.2.json +++ b/abi/0.2.json @@ -64,6 +64,6 @@ "$ref": "#/definitions/anyType" } } - }, + } } } diff --git a/abi/examples/env.ts b/abi/examples/env.ts new file mode 100644 index 0000000..1131eab --- /dev/null +++ b/abi/examples/env.ts @@ -0,0 +1,19 @@ +import { Abi } from "../abi-0.2"; + +const abi: Abi = { + version: "0.2", + env: { + kind: "Env", + props: [ + { + kind: "Property", + name: "prop", + required: true, + type: { + kind: "Scalar", + scalar: "String" + } + } + ] + } +} \ No newline at end of file diff --git a/abi/examples/imports/user.ts b/abi/examples/imports/user.ts index b81e06b..c3ed551 100644 --- a/abi/examples/imports/user.ts +++ b/abi/examples/imports/user.ts @@ -148,7 +148,7 @@ const abi: Abi = { name: "obj2", required: true, type: { - import_id: "1", + import_id: "0.0", kind: "ImportRef", ref_kind: "Object", ref_name: "Obj2" diff --git a/abi/examples/sanity.graphql b/abi/examples/sanity.graphql index 2003efc..1bb01d1 100644 --- a/abi/examples/sanity.graphql +++ b/abi/examples/sanity.graphql @@ -1,7 +1,4 @@ -#import { Object } into Namespace from "uri" - type Module { - # some comment func1( arg: Bytes! ): UInt32! @@ -18,5 +15,4 @@ type Custom { type Nested { prop: UInt8 - importedObj: Namespace_Object! } diff --git a/abi/examples/sanity.ts b/abi/examples/sanity.ts index 9de9626..3c5d3c5 100644 --- a/abi/examples/sanity.ts +++ b/abi/examples/sanity.ts @@ -90,23 +90,6 @@ const abi: Abi = { }, required: false }, - { - kind: "Property", - name: "importedObj", - type: { - kind: "Ref", - ref_kind: "Object", - ref_name: "Namespace_Object" - - /* - kind: "ImpotRef", - ref_abi: 0, - ref_kind: "Object", - ref_name: "Object" - */ - }, - required: true - } ] } ] diff --git a/abi/examples/todo b/abi/examples/todo index c52bc08..c4368e0 100644 --- a/abi/examples/todo +++ b/abi/examples/todo @@ -1,23 +1,23 @@ TODO: x add wrapper type to imports x parity with old ABI -- use maps for unique def kinds +x use maps for unique def kinds - use enums instead of strings - JSON-schema - Transpile to TS -- notes on things removed from old ABI (capabilities) -- compile the ts example files to make sure they implement the ABI well -- document the choices around imports & how import "routing" works for importing the imports of your import. (ex: "1.2.3") +x notes on things removed from old ABI (capabilities) +x compile the ts example files to make sure they implement the ABI well +x document the choices around imports & how import "routing" works for importing the imports of your import. (ex: "1.2.3") - migration script from 0.1 to 0.2? Test-Cases: -- referencing imports -- implemented interfaces +x referencing imports +x implemented interfaces After Init PR: - fix complex types Future: -- "runtime abi" is a compressed hyper optimized ABI for small storage & download, and fast runtime traversal & introspection (hashes, etc) -- research merkle-root hashes for root-definitions (function, object, enum, etc?) to help with validation execution time +x "runtime abi" is a compressed hyper optimized ABI for small storage & download, and fast runtime traversal & introspection (hashes, etc) +x research merkle-root hashes for root-definitions (function, object, enum, etc?) to help with validation execution time - "does interface A implement interface B?" From 86cc2733e125dbe6216346bcb13dc14533e21493 Mon Sep 17 00:00:00 2001 From: Nestor Amesty Date: Wed, 18 Jan 2023 02:34:37 +0100 Subject: [PATCH 19/20] (feat): added jsonschema --- abi/0.2.json | 361 ++++++++++++++++++++++++++++++++++++++++------ abi/abi-0.2.ts | 9 -- abi/examples/todo | 2 +- 3 files changed, 314 insertions(+), 58 deletions(-) diff --git a/abi/0.2.json b/abi/0.2.json index ac7cb33..fec1599 100644 --- a/abi/0.2.json +++ b/abi/0.2.json @@ -1,69 +1,334 @@ { - "id": "Abi", - "type": "object", + "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { - "uniqueDefKind": { - "type": "string", - "enum": [ - "Function", - "Object", - "Enum", - "Env" + "AnyType": { + "anyOf": [ + { + "$ref": "#/definitions/ScalarType" + }, + { + "$ref": "#/definitions/ArrayType" + }, + { + "$ref": "#/definitions/MapType" + }, + { + "$ref": "#/definitions/RefType" + }, + { + "$ref": "#/definitions/ImportRefType" + } ] }, - "typeKind": { - "type": "string", - "enum": [ - "Scalar", - "Array", - "Map", - "Ref", - "ImportRef" - ] + "ArgumentDef": { + "properties": { + "kind": { + "enum": [ + "Argument" + ], + "type": "string" + }, + "name": { + "type": "string" + }, + "required": { + "type": "boolean" + }, + "type": { + "$ref": "#/definitions/AnyType" + } + }, + "type": "object" + }, + "ArrayType": { + "properties": { + "item": { + "$ref": "#/definitions/OptionalType" + }, + "kind": { + "enum": [ + "Array" + ], + "type": "string" + } + }, + "type": "object" + }, + "EnumDef": { + "properties": { + "constants": { + "items": { + "type": "string" + }, + "type": "array" + }, + "kind": { + "enum": [ + "Enum" + ], + "type": "string" + }, + "name": { + "type": "string" + } + }, + "type": "object" + }, + "EnvDef": { + "properties": { + "kind": { + "enum": [ + "Env" + ], + "type": "string" + }, + "props": { + "items": { + "$ref": "#/definitions/PropertyDef" + }, + "type": "array" + } + }, + "type": "object" + }, + "FunctionDef": { + "properties": { + "args": { + "items": { + "$ref": "#/definitions/ArgumentDef" + }, + "type": "array" + }, + "kind": { + "enum": [ + "Function" + ], + "type": "string" + }, + "name": { + "type": "string" + }, + "result": { + "$ref": "#/definitions/ResultDef" + } + }, + "type": "object" + }, + "ImportRefType": { + "properties": { + "import_id": { + "type": "string" + }, + "kind": { + "enum": [ + "ImportRef" + ], + "type": "string" + }, + "ref_kind": { + "$ref": "#/definitions/UniqueDefKind" + }, + "ref_name": { + "type": "string" + } + }, + "type": "object" + }, + "MapType": { + "properties": { + "key": { + "$ref": "#/definitions/MapKeyScalarType" + }, + "kind": { + "enum": [ + "Map" + ], + "type": "string" + }, + "value": { + "$ref": "#/definitions/OptionalType" + } + }, + "type": "object" + }, + "ObjectDef": { + "properties": { + "kind": { + "enum": [ + "Object" + ], + "type": "string" + }, + "name": { + "type": "string" + }, + "props": { + "items": { + "$ref": "#/definitions/PropertyDef" + }, + "type": "array" + } + }, + "type": "object" + }, + "OptionalType": { + "properties": { + "required": { + "type": "boolean" + }, + "type": { + "$ref": "#/definitions/AnyType" + } + }, + "type": "object" + }, + "PropertyDef": { + "properties": { + "kind": { + "enum": [ + "Property" + ], + "type": "string" + }, + "name": { + "type": "string" + }, + "required": { + "type": "boolean" + }, + "type": { + "$ref": "#/definitions/AnyType" + } + }, + "type": "object" }, - "scalarType": { - "type": "string", + "RefType": { + "properties": { + "kind": { + "enum": [ + "Ref" + ], + "type": "string" + }, + "ref_kind": { + "$ref": "#/definitions/UniqueDefKind" + }, + "ref_name": { + "type": "string" + } + }, + "type": "object" + }, + "ResultDef": { + "properties": { + "kind": { + "enum": [ + "Result" + ], + "type": "string" + }, + "required": { + "type": "boolean" + }, + "type": { + "$ref": "#/definitions/AnyType" + } + }, + "type": "object" + }, + "ScalarTypeEnum": { "enum": [ - "UInt", - "UInt8", - "UInt16", - "UInt32", + "BigInt", + "BigNumber", + "Boolean", + "Bytes", "Int", - "Int8", "Int16", "Int32", + "Int8", + "JSON", "String", - "Boolean", - "Bytes", - "BigInt", - "BigNumber", - "JSON" - ] - }, - "mapKeyType": { - "type": "string", - "enum": [ "UInt", - "UInt8", "UInt16", "UInt32", + "UInt8" + ], + "type": "string" + }, + "ScalarTypeMapKeyEnum": { + "enum": [ "Int", - "Int8", "Int16", "Int32", - "String" - ] + "Int8", + "String", + "UInt", + "UInt16", + "UInt32", + "UInt8" + ], + "type": "string" }, - "optionalType": { - "type": "object", + "MapKeyScalarType": { "properties": { - "required": { - "type": "boolean" + "kind": { + "enum": [ + "Scalar" + ], + "type": "string" }, - "type": { - "$ref": "#/definitions/anyType" + "scalar": { + "$ref": "#/definitions/ScalarTypeMapKeyEnum" + } + }, + "type": "object" + }, + "ScalarType": { + "properties": { + "kind": { + "enum": [ + "Scalar" + ], + "type": "string" + }, + "scalar": { + "$ref": "#/definitions/ScalarTypeEnum" } - } + }, + "type": "object" + }, + "UniqueDefKind": { + "enum": [ + "Enum", + "Env", + "Function", + "Object" + ], + "type": "string" + } + }, + "properties": { + "enums": { + "items": { + "$ref": "#/definitions/EnumDef" + }, + "type": "array" + }, + "env": { + "$ref": "#/definitions/EnvDef" + }, + "functions": { + "items": { + "$ref": "#/definitions/FunctionDef" + }, + "type": "array" + }, + "objects": { + "items": { + "$ref": "#/definitions/ObjectDef" + }, + "type": "array" } - } -} + }, + "type": "object" +} \ No newline at end of file diff --git a/abi/abi-0.2.ts b/abi/abi-0.2.ts index 45270d0..f3c6fe5 100644 --- a/abi/abi-0.2.ts +++ b/abi/abi-0.2.ts @@ -26,15 +26,6 @@ export interface ImportedAbi extends AbiDefs { /// Definitions (user-defined) -export type AnyDef = - | FunctionDef - | ArgumentDef - | ResultDef - | ObjectDef - | PropertyDef - | EnumDef - | EnvDef; - export type UniqueDefKind = | "Function" | "Object" diff --git a/abi/examples/todo b/abi/examples/todo index c4368e0..0cfca68 100644 --- a/abi/examples/todo +++ b/abi/examples/todo @@ -3,7 +3,7 @@ x add wrapper type to imports x parity with old ABI x use maps for unique def kinds - use enums instead of strings -- JSON-schema +x JSON-schema - Transpile to TS x notes on things removed from old ABI (capabilities) x compile the ts example files to make sure they implement the ABI well From 4643528111a9abaf9ddd0041bce53211b80a549f Mon Sep 17 00:00:00 2001 From: Nestor Amesty Date: Fri, 20 Jan 2023 18:37:53 +0100 Subject: [PATCH 20/20] removed env from definitions --- abi/0.2.json | 21 --------------------- abi/abi-0.2.ts | 7 ------- abi/examples/env.graphql | 3 --- abi/examples/env.ts | 19 ------------------- 4 files changed, 50 deletions(-) delete mode 100644 abi/examples/env.graphql delete mode 100644 abi/examples/env.ts diff --git a/abi/0.2.json b/abi/0.2.json index fec1599..be43df4 100644 --- a/abi/0.2.json +++ b/abi/0.2.json @@ -74,23 +74,6 @@ }, "type": "object" }, - "EnvDef": { - "properties": { - "kind": { - "enum": [ - "Env" - ], - "type": "string" - }, - "props": { - "items": { - "$ref": "#/definitions/PropertyDef" - }, - "type": "array" - } - }, - "type": "object" - }, "FunctionDef": { "properties": { "args": { @@ -300,7 +283,6 @@ "UniqueDefKind": { "enum": [ "Enum", - "Env", "Function", "Object" ], @@ -314,9 +296,6 @@ }, "type": "array" }, - "env": { - "$ref": "#/definitions/EnvDef" - }, "functions": { "items": { "$ref": "#/definitions/FunctionDef" diff --git a/abi/abi-0.2.ts b/abi/abi-0.2.ts index f3c6fe5..a8570cd 100644 --- a/abi/abi-0.2.ts +++ b/abi/abi-0.2.ts @@ -4,7 +4,6 @@ export interface AbiDefs { functions?: FunctionDef[]; objects?: ObjectDef[]; enums?: EnumDef[]; - env?: EnvDef; } export interface Abi extends AbiDefs { @@ -30,7 +29,6 @@ export type UniqueDefKind = | "Function" | "Object" | "Enum" - | "Env"; export type DefKind = | UniqueDefKind @@ -78,11 +76,6 @@ export interface EnumDef extends NamedDef { constants: string[]; } -export interface EnvDef extends Def { - kind: "Env"; - props: PropertyDef[]; -} - /// Types (built-ins) export type AnyType = diff --git a/abi/examples/env.graphql b/abi/examples/env.graphql deleted file mode 100644 index d2dfa12..0000000 --- a/abi/examples/env.graphql +++ /dev/null @@ -1,3 +0,0 @@ -type Env { - prop: String! -} diff --git a/abi/examples/env.ts b/abi/examples/env.ts deleted file mode 100644 index 1131eab..0000000 --- a/abi/examples/env.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Abi } from "../abi-0.2"; - -const abi: Abi = { - version: "0.2", - env: { - kind: "Env", - props: [ - { - kind: "Property", - name: "prop", - required: true, - type: { - kind: "Scalar", - scalar: "String" - } - } - ] - } -} \ No newline at end of file