Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WRAP ABI 0.2 Refactor #1474

Draft
wants to merge 91 commits into
base: origin-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
e89be37
(wip): import resolution re-do
namesty Dec 16, 2022
73863d6
(feat): new definitions
namesty Dec 20, 2022
f2d08c3
(wip): new definitions and object extractor
namesty Dec 22, 2022
0b6b94e
(wip): updated 0.2 defintions and map parsing
namesty Jan 4, 2023
111a76b
(fix): object type extractors
namesty Jan 5, 2023
8af84a7
(wip): new extractors structure
namesty Jan 5, 2023
1c1ab95
(chore): new module and directives extractors
namesty Jan 6, 2023
3973f08
(chore): simplified property extraction in object extractor
namesty Jan 6, 2023
8f6befe
(chore): moved legacy extractors into legacy dir. Working with new ones
namesty Jan 6, 2023
6f68845
(chore): removed old extractors. Minor fixes
namesty Jan 9, 2023
40db593
(feat): added main transform visitor funcs. Added pre-pass visit
namesty Jan 9, 2023
8fa38b0
(feat): added Definition transformer, fixed transforms, added toMapStr
namesty Jan 9, 2023
8bf9320
(chore): toGraphQLType function updated
namesty Jan 9, 2023
a29eea0
(chore): removed unused code
namesty Jan 9, 2023
dfb642a
(feat): updated ABI definitions. Removed Env from parse
namesty Feb 8, 2023
d085bfa
(feat): removed env from compose
namesty Feb 8, 2023
8518ff9
(feat): remove env from bind
namesty Feb 8, 2023
772bade
(chore): removed interfaces and capabilities from parse
namesty Feb 8, 2023
f13f3c4
(chore): removed env transforms
namesty Feb 8, 2023
936fb2b
(chore): updated extractors and transformes to new definitions
namesty Feb 8, 2023
ebb21e9
(chore): re-did GraphQL string parsers
namesty Feb 8, 2023
4518fd3
(chore): trimming GraphQL strings
namesty Feb 9, 2023
bcb58d4
(feat): added extractors and utils unit tests
namesty Feb 9, 2023
8d926d2
(chore): added multiple test cases for object defs
namesty Feb 9, 2023
ec2b5de
(chore): started migrating parsing logic from compose
namesty Feb 10, 2023
e9fa8c8
(feat): discover imports in parse
namesty Feb 10, 2023
7057f96
(feat): uniqueDefinitions pre-pass
namesty Feb 11, 2023
35a06e1
(chore): started migrating GraphQL specific impl outside
namesty Feb 11, 2023
28bdf43
(chore): migrated extractors outside
namesty Feb 11, 2023
72a8e8c
(chore): migrated GraphQL AST validation and tests outside
namesty Feb 11, 2023
fec106d
(chore): completely removed GraphQL dependency from schema package
namesty Feb 11, 2023
9f16d62
(chore): renamed compose -> linking
namesty Feb 13, 2023
2b56d22
(feat): started linking implementation
namesty Feb 13, 2023
14c8ea2
(chore): implemented new ABI visitor
namesty Feb 13, 2023
90994b6
(chore): first full implementation of linking
namesty Feb 13, 2023
fbccf17
(chore): removed unused legacy code
namesty Feb 13, 2023
5151f53
(chore): made visitor support enter and leave
namesty Feb 13, 2023
01450f3
(feat): imports parser
namesty Feb 14, 2023
4943c6a
(feat): unlinked defs
namesty Feb 15, 2023
236199f
(feat): test for imports resolution
namesty Feb 15, 2023
a4c7f6e
(chore): wip unlinked defs parsing
namesty Feb 15, 2023
6718a21
(chore): imports resolution algorithm working
namesty Feb 16, 2023
8256987
(chore): added circular deps detection and visual repr for dep tree
namesty Feb 16, 2023
588962d
(chore): imports extraction test working
namesty Feb 16, 2023
1767b86
(chore): started local import parsing
namesty Feb 16, 2023
4da5788
(feat): local imports: merging + flattening + linking
namesty Feb 17, 2023
c2b1e9f
(fix): fixed faulty tree shaking of ext imports
namesty Feb 17, 2023
92bb4f5
(chore): rmeoved concept of UnlinkedDefs as separate from the Abi defs
namesty Feb 20, 2023
d6e4c99
(feat): abi visitor
namesty Feb 20, 2023
1750b4d
(feat): ABI tree shaker
namesty Feb 20, 2023
796d736
Merge branch 'exp-schema-refactor' into namesty/schema-refactor
namesty Feb 20, 2023
586635c
(feat): recursive imports shaking
namesty Feb 20, 2023
4ef1be6
(chore): remove duplicated local shake logic. Finish first impl
namesty Feb 21, 2023
f7b3603
(feat): depend on interfaces, not implementations
namesty Feb 21, 2023
d264575
(chore): removed unnecessary method from interface. Removed dep tree
namesty Feb 21, 2023
d476856
(chore): added main entrypoint function + fetcher types
namesty Feb 21, 2023
5eee0d9
(chore): eliminated linking package
namesty Feb 21, 2023
760bb8e
(feat): renamed package to schema-abi. Removed transforms
namesty Feb 21, 2023
97e5d1b
(feat): extracted ABI types into separate packages
namesty Feb 22, 2023
5d9de93
(chore): moved createABI to the core types package
namesty Feb 23, 2023
da274e5
(feat): implemented circular dependency detection
namesty Feb 23, 2023
f2b13af
(feat): made ABI visitor mutable with GraphQL's AST visitor devexp
namesty Feb 24, 2023
fa1db49
(chore): changed currentIDPath algorithm
namesty Feb 24, 2023
598f5a5
(chore): linking references
namesty Feb 24, 2023
20d914e
(feat): implemented Linker Visitor to mutate and link UnlinkedRefs
namesty Feb 25, 2023
5c8e8a1
(chore): linking unlinked refs using visitor
namesty Feb 25, 2023
680e0e3
(wip): ABI Imports Linker tests added
namesty Feb 25, 2023
a9d750f
(chore): added local imports merging tests and mocks
namesty Feb 25, 2023
45376ae
(chore): added external imports embedding tests
namesty Feb 25, 2023
89c7b17
(feat): reference linking tests
namesty Feb 26, 2023
01eb66a
(fix): Linker visitor mutation fix
namesty Feb 26, 2023
bac928a
(fix): fixed link imports test
namesty Feb 27, 2023
b4d1663
(feat): ABI shaker unit tests
namesty Feb 27, 2023
e86a6a0
(feat): ABI sanitizer added
namesty Feb 27, 2023
47c90a8
(chore): fixed mutating ABI visitor
namesty Feb 27, 2023
c1ec525
(fix): all tests passing
namesty Feb 27, 2023
4bc5318
(fix): more tests to shaker. Tested deep transitive imports
namesty Feb 27, 2023
b11fc79
(chore): added visitor tests
namesty Feb 28, 2023
851f96d
(chore): removed old tests
namesty Feb 28, 2023
c360dcc
(chore): explicitly stating UnlinkedImportRefs have namespaced names
namesty Feb 28, 2023
943e7d6
(feat): Linker visitor tests
namesty Feb 28, 2023
714f73d
(feat): add first last transform
namesty Mar 1, 2023
c6b219c
(chore): moved transforms to bind package
namesty Mar 2, 2023
e49c34e
(chore): updated top level AS schema bindings
namesty Apr 5, 2023
a19e838
(feat): changed Mustache templates for Handlebars
namesty Apr 6, 2023
1bb49d7
(feat): bindings WasmRenderer
namesty Apr 6, 2023
ddc610e
(feat): Wasm initial values renderer added
namesty Apr 7, 2023
47cdca6
(chore): removed unnecessary transforms
namesty Apr 7, 2023
cde565d
(feat): better assemblyscript helpers and renderers
namesty Apr 7, 2023
d035703
(chore): removed legacy templating code
namesty Apr 7, 2023
3b6bb00
(chore): updated object type templates
namesty Apr 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@polywrap/schema-compose",
"description": "Polywrap Schema Composition",
"name": "@polywrap/abi-types",
"description": "Polywrap ABI Core Types",
"version": "0.10.0-pre.5",
"license": "MIT",
"repository": {
Expand All @@ -13,24 +13,17 @@
],
"scripts": {
"build": "rimraf ./build && tsc --project tsconfig.build.json",
"lint": "eslint --color -c ../../../.eslintrc.js src/",
"lint": "eslint --color src/",
"test": "jest --passWithNoTests --runInBand --verbose",
"test:ci": "jest --passWithNoTests --runInBand --verbose",
"test:watch": "jest --watch --passWithNoTests --verbose"
},
"dependencies": {
"@polywrap/schema-parse": "0.10.0-pre.5",
"@polywrap/wrap-manifest-types-js": "0.10.0-pre.5",
"graphql": "15.5.0",
"mustache": "4.0.1"
},
"devDependencies": {
"@polywrap/test-cases": "0.10.0-pre.5",
"@types/deep-equal": "1.0.1",
"@types/jest": "26.0.8",
"@types/mustache": "4.0.1",
"@types/prettier": "2.6.0",
"jest": "26.6.3",
"jest-diff": "28.1.3",
"rimraf": "3.0.2",
"ts-jest": "26.5.4",
"ts-node": "8.10.2",
Expand Down
182 changes: 182 additions & 0 deletions packages/schema/abi-types/src/definitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/// ABIs

export interface AbiDefs {
functions?: FunctionDef[];
objects?: ObjectDef[];
enums?: EnumDef[];
}

export interface Abi extends AbiDefs {
version: "0.2";
imports?: ImportedAbi[];
}

export type ImportAbiType =
| "wasm"
| "interface";

export interface ImportedAbi extends AbiDefs {
id: string;
uri: string;
type: ImportAbiType;
namespace: string;
imports?: ImportedAbi[];
}

/// Definitions (user-defined)

export type AnyDef = FunctionDef | ObjectDef | EnumDef | PropertyDef | ArgumentDef | ResultDef;

export type UniqueDefKind =
| "Function"
| "Object"
| "Enum"

export type DefKind =
| UniqueDefKind
| "Argument"
| "Result"
| "Property";

export interface Def {
kind: DefKind;
}

export interface NamedDef extends Def {
name: string;
}

export interface InlinedTypeDef extends Def, OptionalType { }

export interface NamedTypeDef extends NamedDef, InlinedTypeDef { }

export interface FunctionDef extends NamedDef {
kind: "Function";
args: ArgumentDef[];
result: ResultDef;
}

export interface ArgumentDef extends NamedTypeDef {
kind: "Argument";
}

export interface ResultDef extends InlinedTypeDef {
kind: "Result";
}

export interface ObjectDef extends NamedDef {
kind: "Object";
props: PropertyDef[];
}

export interface PropertyDef extends NamedTypeDef {
kind: "Property";
}

export interface EnumDef extends NamedDef {
kind: "Enum";
constants: string[];
}

/// Types (built-ins)

export type AnyType =
| ScalarType
| ArrayType
| MapType
| RefType
| ImportRefType
| UnlinkedImportRefType;

export type TypeKind =
| "Scalar"
| "Array"
| "Map"
| "Ref"
| "ImportRef"
| "UnlinkedImportRef"

export interface Type {
kind: TypeKind;
}

export interface ScalarType<
TScalarTypeName extends ScalarTypeName = ScalarTypeName
> extends Type {
kind: "Scalar";
scalar: TScalarTypeName;
}

export interface ArrayType extends Type {
kind: "Array";
item: OptionalType;
}

export interface MapType extends Type {
kind: "Map";
key: ScalarType<MapKeyTypeName>;
value: OptionalType;
}

export interface RefType extends Type {
kind: "Ref";
ref_kind: UniqueDefKind;
ref_name: string;
}

export interface ImportRefType extends Type {
kind: "ImportRef";
import_id: string;
ref_kind: UniqueDefKind;
ref_name: string;
}

export interface UnlinkedImportRefType extends Type {
kind: "UnlinkedImportRef";
namespaced_ref_name: string;
}

export interface OptionalType {
required: boolean;
type: AnyType;
}

/// Constants

export 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",
};
export type ScalarTypeSet = typeof scalarTypeSet;

export type ScalarTypeName = keyof ScalarTypeSet;

export const mapKeyTypeSet = {
UInt: "UInt",
UInt8: "UInt8",
UInt16: "UInt16",
UInt32: "UInt32",
Int: "Int",
Int8: "Int8",
Int16: "Int16",
Int32: "Int32",
String: "String",
};
export type MapKeyTypeSet = typeof mapKeyTypeSet;

export type MapKeyTypeName = keyof MapKeyTypeSet;

export type AnyTypeOrDef = AnyType | AnyDef;
46 changes: 46 additions & 0 deletions packages/schema/abi-types/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Abi } from "./definitions";

export * from "./definitions";

export interface ImportStatement {
kind: "local" | "external";
importedTypes: string[];
uriOrPath: string;
}

export interface ExternalImportStatement extends ImportStatement {
kind: "external";
namespace: string;
}

export interface LocalImportStatement extends ImportStatement {
kind: "local";
}

export interface SchemaParser {
parseExternalImportStatements: (schema: string) => Promise<ExternalImportStatement[]>
parseLocalImportStatements: (schema: string) => Promise<LocalImportStatement[]>
parse: (schema: string) => Promise<Abi>
}

export interface SchemaRenderer {
render: (abi: Abi) => Promise<string>
}

export interface ParserOptions {
noValidate?: boolean;
}

export interface ExternalSchemaFetcher {
fetch: (uri: string) => Promise<Abi>;
}

export interface LocalSchemaFetcher {
fetch: (path: string) => Promise<string>;
}

export function createAbi(): Abi {
return {
version: "0.2"
};
}
95 changes: 95 additions & 0 deletions packages/schema/abi/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@

module.exports = {
extends: "../../../.eslintrc.js",
overrides: [
{
files: ["*.ts"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["tsconfig.json"],
},
plugins: [
"eslint-plugin-import",
"@typescript-eslint",
"prettier"
],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
rules: {
"prettier/prettier": ["error"],
"@typescript-eslint/naming-convention": [
"error",
{selector: "default", format: ["camelCase"]},
{
selector: [
"classProperty", "parameterProperty",
"classMethod", "parameter"
],
format: ["camelCase"],
leadingUnderscore: "allow"
},
//wrapper host methods doesn"t satisfy neither camel or snake
{selector: ["objectLiteralMethod", "typeMethod"], filter: {regex: "^_wrap_.*", match: true}, format: null},
//variable must be in camel or upper case
{selector: "variable", format: ["camelCase", "PascalCase", "UPPER_CASE"], leadingUnderscore: "allow"},
//classes and types must be in PascalCase
{selector: ["typeLike", "enum"], format: ["PascalCase"]},
{selector: "enumMember", format: null},
//ignore rule for quoted stuff
{
selector: [
"classProperty",
"objectLiteralProperty",
"typeProperty",
"classMethod",
"objectLiteralMethod",
"typeMethod",
"accessor",
"enumMember"
],
format: null,
modifiers: ["requiresQuotes"]
},
//ignore rules on destructured params
{
selector: "variable",
modifiers: ["destructured"],
format: null
},
{
selector: [
"objectLiteralProperty",
"objectLiteralMethod",
],
format: ["PascalCase", "camelCase"]
},
],
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/member-ordering": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-unused-vars": ["error", {
"varsIgnorePattern": "^_",
"argsIgnorePattern": "^_",
}],
"@typescript-eslint/no-floating-promises": "error",
"import/no-extraneous-dependencies": ["error", {
"devDependencies": false,
"optionalDependencies": true,
"peerDependencies": false
}],
"import/order": [
"error",
{
"groups": [["index", "sibling", "parent", "internal"], ["external", "builtin"], "object"],
"newlines-between": "always"
}
],
},
},
],
};
Loading