@graphprotocol/graph-cli 0.37.3 → 0.37.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/package.json +5 -1
- package/babel.config.js +0 -3
- package/jest.config.js +0 -175
- package/src/bin.ts +0 -6
- package/src/cli.ts +0 -30
- package/src/codegen/schema.test.ts +0 -460
- package/src/codegen/schema.ts +0 -299
- package/src/codegen/template.ts +0 -45
- package/src/codegen/types/conversions.ts +0 -358
- package/src/codegen/types/index.test.ts +0 -715
- package/src/codegen/types/index.ts +0 -111
- package/src/codegen/typescript.ts +0 -224
- package/src/codegen/util.test.ts +0 -112
- package/src/codegen/util.ts +0 -54
- package/src/command-helpers/abi.ts +0 -99
- package/src/command-helpers/auth.ts +0 -46
- package/src/command-helpers/compiler.ts +0 -60
- package/src/command-helpers/data-sources.ts +0 -36
- package/src/command-helpers/fs.ts +0 -5
- package/src/command-helpers/gluegun.ts +0 -52
- package/src/command-helpers/ipfs-http-client.d.ts +0 -1
- package/src/command-helpers/ipfs.ts +0 -3
- package/src/command-helpers/jsonrpc.ts +0 -22
- package/src/command-helpers/network.test.ts +0 -85
- package/src/command-helpers/network.ts +0 -133
- package/src/command-helpers/node.ts +0 -46
- package/src/command-helpers/scaffold.ts +0 -174
- package/src/command-helpers/spinner.ts +0 -60
- package/src/command-helpers/studio.test.ts +0 -84
- package/src/command-helpers/studio.ts +0 -25
- package/src/command-helpers/subgraph.ts +0 -21
- package/src/command-helpers/version.test.ts +0 -241
- package/src/command-helpers/version.ts +0 -53
- package/src/commands/add.ts +0 -220
- package/src/commands/auth.ts +0 -138
- package/src/commands/binary-install-raw.d.ts +0 -1
- package/src/commands/build.ts +0 -147
- package/src/commands/codegen.ts +0 -123
- package/src/commands/create.ts +0 -109
- package/src/commands/deploy.ts +0 -388
- package/src/commands/init.ts +0 -1060
- package/src/commands/local.ts +0 -539
- package/src/commands/remove.ts +0 -110
- package/src/commands/test.ts +0 -369
- package/src/compiler/asc.ts +0 -77
- package/src/compiler/index.ts +0 -677
- package/src/debug.ts +0 -15
- package/src/migrations/mapping_api_version_0_0_1.ts +0 -75
- package/src/migrations/mapping_api_version_0_0_2.ts +0 -75
- package/src/migrations/mapping_api_version_0_0_3.ts +0 -75
- package/src/migrations/mapping_api_version_0_0_4.ts +0 -77
- package/src/migrations/mapping_api_version_0_0_5.ts +0 -77
- package/src/migrations/spec_version_0_0_2.ts +0 -24
- package/src/migrations/spec_version_0_0_3.ts +0 -29
- package/src/migrations/util/load-manifest.ts +0 -10
- package/src/migrations/util/versions.ts +0 -27
- package/src/migrations.ts +0 -33
- package/src/protocols/arweave/manifest.graphql +0 -57
- package/src/protocols/arweave/scaffold/manifest.ts +0 -14
- package/src/protocols/arweave/scaffold/mapping.ts +0 -49
- package/src/protocols/arweave/subgraph.ts +0 -22
- package/src/protocols/contract.ts +0 -9
- package/src/protocols/cosmos/manifest.graphql +0 -76
- package/src/protocols/cosmos/scaffold/manifest.ts +0 -11
- package/src/protocols/cosmos/scaffold/mapping.ts +0 -35
- package/src/protocols/cosmos/subgraph.ts +0 -27
- package/src/protocols/ethereum/abi.ts +0 -153
- package/src/protocols/ethereum/codegen/abi.test.ts +0 -330
- package/src/protocols/ethereum/codegen/abi.ts +0 -719
- package/src/protocols/ethereum/codegen/template.ts +0 -41
- package/src/protocols/ethereum/contract.ts +0 -24
- package/src/protocols/ethereum/manifest.graphql +0 -94
- package/src/protocols/ethereum/scaffold/manifest.ts +0 -28
- package/src/protocols/ethereum/scaffold/mapping.ts +0 -76
- package/src/protocols/ethereum/subgraph.ts +0 -189
- package/src/protocols/ethereum/type-generator.ts +0 -191
- package/src/protocols/index.ts +0 -287
- package/src/protocols/ipfs/codegen/file_template.ts +0 -43
- package/src/protocols/near/contract.ts +0 -47
- package/src/protocols/near/manifest.graphql +0 -64
- package/src/protocols/near/scaffold/manifest.ts +0 -13
- package/src/protocols/near/scaffold/mapping.ts +0 -35
- package/src/protocols/near/subgraph.ts +0 -22
- package/src/protocols/subgraph.ts +0 -12
- package/src/protocols/substreams/manifest.graphql +0 -45
- package/src/protocols/substreams/scaffold/manifest.ts +0 -8
- package/src/protocols/substreams/subgraph.ts +0 -22
- package/src/scaffold/cosmos.test.ts +0 -83
- package/src/scaffold/ethereum.test.ts +0 -512
- package/src/scaffold/index.ts +0 -172
- package/src/scaffold/mapping.ts +0 -44
- package/src/scaffold/near.test.ts +0 -86
- package/src/scaffold/schema.ts +0 -89
- package/src/scaffold/tests.ts +0 -217
- package/src/schema.ts +0 -26
- package/src/subgraph.ts +0 -302
- package/src/type-generator.ts +0 -266
- package/src/validation/contract.ts +0 -51
- package/src/validation/index.ts +0 -5
- package/src/validation/manifest.ts +0 -360
- package/src/validation/schema.test.ts +0 -38
- package/src/validation/schema.ts +0 -957
- package/src/watcher.ts +0 -96
- package/tests/cli/globalSetup.ts +0 -8
- package/tests/cli/globalTeardown.ts +0 -8
- package/tests/cli/init/ethereum/abis/Marketplace.json +0 -408
- package/tests/cli/init/ethereum/abis/OverloadedElements.json +0 -91
- package/tests/cli/init/ethereum/abis/SoloMargin.json +0 -2729
- package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stderr +0 -14
- package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stdout +0 -12
- package/tests/cli/init/ethereum/from-contract-with-abi.stderr +0 -14
- package/tests/cli/init/ethereum/from-contract-with-abi.stdout +0 -12
- package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stderr +0 -14
- package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stdout +0 -12
- package/tests/cli/init/ethereum/from-contract.stderr +0 -16
- package/tests/cli/init/ethereum/from-contract.stdout +0 -12
- package/tests/cli/init/ethereum/from-example.stderr +0 -12
- package/tests/cli/init/ethereum/from-example.stdout +0 -12
- package/tests/cli/init/near/from-contract.stderr +0 -14
- package/tests/cli/init/near/from-contract.stdout +0 -12
- package/tests/cli/init.test.ts +0 -157
- package/tests/cli/spawn-command.d.ts +0 -7
- package/tests/cli/util.ts +0 -132
- package/tests/cli/validation/abi-not-found/Abi.json +0 -7
- package/tests/cli/validation/abi-not-found/mapping.ts +0 -0
- package/tests/cli/validation/abi-not-found/schema.graphql +0 -3
- package/tests/cli/validation/abi-not-found/subgraph.yaml +0 -42
- package/tests/cli/validation/abi-not-found copy.stderr +0 -13
- package/tests/cli/validation/big-decimal-is-valid/Abi.json +0 -7
- package/tests/cli/validation/big-decimal-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/big-decimal-is-valid/schema.graphql +0 -4
- package/tests/cli/validation/big-decimal-is-valid/subgraph.yaml +0 -23
- package/tests/cli/validation/call-function-not-found/Abi.json +0 -57
- package/tests/cli/validation/call-function-not-found/mapping.ts +0 -0
- package/tests/cli/validation/call-function-not-found/schema.graphql +0 -3
- package/tests/cli/validation/call-function-not-found/subgraph.yaml +0 -22
- package/tests/cli/validation/call-function-not-found.stderr +0 -10
- package/tests/cli/validation/call-handler-with-tuple/Abi.json +0 -24
- package/tests/cli/validation/call-handler-with-tuple/generated/schema.ts +0 -44
- package/tests/cli/validation/call-handler-with-tuple/mapping.ts +0 -0
- package/tests/cli/validation/call-handler-with-tuple/schema.graphql +0 -3
- package/tests/cli/validation/call-handler-with-tuple/subgraph.yaml +0 -22
- package/tests/cli/validation/call-handler-with-tuple.stderr +0 -24
- package/tests/cli/validation/conflicting-network-names/Abi.json +0 -7
- package/tests/cli/validation/conflicting-network-names/mapping.ts +0 -0
- package/tests/cli/validation/conflicting-network-names/schema.graphql +0 -3
- package/tests/cli/validation/conflicting-network-names/subgraph.yaml +0 -41
- package/tests/cli/validation/conflicting-network-names.stderr +0 -10
- package/tests/cli/validation/conflicting-protocol-names/Abi.json +0 -7
- package/tests/cli/validation/conflicting-protocol-names/mapping.ts +0 -0
- package/tests/cli/validation/conflicting-protocol-names/schema.graphql +0 -3
- package/tests/cli/validation/conflicting-protocol-names/subgraph.yaml +0 -41
- package/tests/cli/validation/conflicting-protocol-names.stderr +0 -10
- package/tests/cli/validation/derived-from-target-type-missing/Abi.json +0 -6
- package/tests/cli/validation/derived-from-target-type-missing/mapping.ts +0 -0
- package/tests/cli/validation/derived-from-target-type-missing/schema.graphql +0 -4
- package/tests/cli/validation/derived-from-target-type-missing/subgraph.yaml +0 -22
- package/tests/cli/validation/derived-from-target-type-missing.stderr +0 -5
- package/tests/cli/validation/derived-from-with-interface/Gravity.json +0 -1
- package/tests/cli/validation/derived-from-with-interface/mapping.ts +0 -22
- package/tests/cli/validation/derived-from-with-interface/schema.graphql +0 -19
- package/tests/cli/validation/derived-from-with-interface/subgraph.yaml +0 -25
- package/tests/cli/validation/duplicate-data-source-name/Abi.json +0 -7
- package/tests/cli/validation/duplicate-data-source-name/mapping.ts +0 -0
- package/tests/cli/validation/duplicate-data-source-name/schema.graphql +0 -4
- package/tests/cli/validation/duplicate-data-source-name/subgraph.yaml +0 -40
- package/tests/cli/validation/duplicate-data-source-name.stderr +0 -5
- package/tests/cli/validation/duplicate-template-name/Abi.json +0 -7
- package/tests/cli/validation/duplicate-template-name/mapping.ts +0 -0
- package/tests/cli/validation/duplicate-template-name/schema.graphql +0 -4
- package/tests/cli/validation/duplicate-template-name/subgraph.yaml +0 -59
- package/tests/cli/validation/duplicate-template-name.stderr +0 -5
- package/tests/cli/validation/entity-field-args/Abi.json +0 -7
- package/tests/cli/validation/entity-field-args/mapping.ts +0 -0
- package/tests/cli/validation/entity-field-args/schema.graphql +0 -4
- package/tests/cli/validation/entity-field-args/subgraph.yaml +0 -22
- package/tests/cli/validation/entity-field-args.stderr +0 -5
- package/tests/cli/validation/ethereum-contract-without-handlers/Abi.json +0 -7
- package/tests/cli/validation/ethereum-contract-without-handlers/mapping.ts +0 -0
- package/tests/cli/validation/ethereum-contract-without-handlers/schema.graphql +0 -3
- package/tests/cli/validation/ethereum-contract-without-handlers/subgraph.yaml +0 -19
- package/tests/cli/validation/ethereum-contract-without-handlers.stderr +0 -6
- package/tests/cli/validation/event-not-found/Abi.json +0 -7
- package/tests/cli/validation/event-not-found/mapping.ts +0 -0
- package/tests/cli/validation/event-not-found/schema.graphql +0 -3
- package/tests/cli/validation/event-not-found/subgraph.yaml +0 -40
- package/tests/cli/validation/event-not-found.stderr +0 -12
- package/tests/cli/validation/example-values-found/Abi.json +0 -7
- package/tests/cli/validation/example-values-found/generated/ExampleSubgraph/ExampleContract.ts +0 -35
- package/tests/cli/validation/example-values-found/generated/schema.ts +0 -44
- package/tests/cli/validation/example-values-found/mapping.ts +0 -0
- package/tests/cli/validation/example-values-found/schema.graphql +0 -3
- package/tests/cli/validation/example-values-found/subgraph.yaml +0 -24
- package/tests/cli/validation/example-values-found.stderr +0 -34
- package/tests/cli/validation/invalid-abis/InvalidAbi.json +0 -1
- package/tests/cli/validation/invalid-abis/mapping.ts +0 -0
- package/tests/cli/validation/invalid-abis/schema.graphql +0 -3
- package/tests/cli/validation/invalid-abis/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-abis.stderr +0 -5
- package/tests/cli/validation/invalid-contract-addresses/Abi.json +0 -7
- package/tests/cli/validation/invalid-contract-addresses/mapping.ts +0 -0
- package/tests/cli/validation/invalid-contract-addresses/schema.graphql +0 -3
- package/tests/cli/validation/invalid-contract-addresses/subgraph.yaml +0 -58
- package/tests/cli/validation/invalid-contract-addresses.stderr +0 -14
- package/tests/cli/validation/invalid-data-source-template/mapping.ts +0 -0
- package/tests/cli/validation/invalid-data-source-template/schema.graphql +0 -3
- package/tests/cli/validation/invalid-data-source-template/subgraph.yaml +0 -32
- package/tests/cli/validation/invalid-data-source-template.stderr +0 -30
- package/tests/cli/validation/invalid-entity-field-types/Abi.json +0 -7
- package/tests/cli/validation/invalid-entity-field-types/mapping.ts +0 -0
- package/tests/cli/validation/invalid-entity-field-types/schema.graphql +0 -157
- package/tests/cli/validation/invalid-entity-field-types/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-entity-field-types.stderr +0 -148
- package/tests/cli/validation/invalid-fulltext-directive/Abi.json +0 -7
- package/tests/cli/validation/invalid-fulltext-directive/mapping.ts +0 -0
- package/tests/cli/validation/invalid-fulltext-directive/schema.graphql +0 -140
- package/tests/cli/validation/invalid-fulltext-directive/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-fulltext-directive.stderr +0 -32
- package/tests/cli/validation/invalid-graphql-schema/Abi.json +0 -7
- package/tests/cli/validation/invalid-graphql-schema/mapping.ts +0 -0
- package/tests/cli/validation/invalid-graphql-schema/schema.graphql +0 -8
- package/tests/cli/validation/invalid-graphql-schema/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-graphql-schema.stderr +0 -25
- package/tests/cli/validation/invalid-manifest/subgraph.yaml +0 -13
- package/tests/cli/validation/invalid-manifest-cannot-infer-protocol/subgraph.yaml +0 -12
- package/tests/cli/validation/invalid-manifest-cannot-infer-protocol.stderr +0 -5
- package/tests/cli/validation/invalid-manifest.stderr +0 -28
- package/tests/cli/validation/missing-entity-id/Abi.json +0 -7
- package/tests/cli/validation/missing-entity-id/mapping.ts +0 -0
- package/tests/cli/validation/missing-entity-id/schema.graphql +0 -3
- package/tests/cli/validation/missing-entity-id/subgraph.yaml +0 -22
- package/tests/cli/validation/missing-entity-id/types/ExampleSubgraph/ExampleContract.ts +0 -35
- package/tests/cli/validation/missing-entity-id/types/schema.ts +0 -27
- package/tests/cli/validation/missing-entity-id.stderr +0 -5
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/Abi.json +0 -7
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/mapping.ts +0 -0
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/schema.graphql +0 -40
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/subgraph.yaml +0 -22
- package/tests/cli/validation/missing-or-invalid-derived-from-fields.stderr +0 -10
- package/tests/cli/validation/missing-or-invalid-derived-from-fields.stdout +0 -0
- package/tests/cli/validation/near-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/near-is-valid/schema.graphql +0 -8
- package/tests/cli/validation/near-is-valid/subgraph.yaml +0 -30
- package/tests/cli/validation/nested-template-nice-error/Abi.json +0 -7
- package/tests/cli/validation/nested-template-nice-error/mapping.ts +0 -0
- package/tests/cli/validation/nested-template-nice-error/schema.graphql +0 -3
- package/tests/cli/validation/nested-template-nice-error/subgraph.yaml +0 -35
- package/tests/cli/validation/nested-template-nice-error.stderr +0 -5
- package/tests/cli/validation/no-network-names/Abi.json +0 -7
- package/tests/cli/validation/no-network-names/mapping.ts +0 -0
- package/tests/cli/validation/no-network-names/schema.graphql +0 -3
- package/tests/cli/validation/no-network-names/subgraph.yaml +0 -40
- package/tests/cli/validation/no-network-names.stderr +0 -34
- package/tests/cli/validation/source-without-address-is-valid/Abi.json +0 -7
- package/tests/cli/validation/source-without-address-is-valid/generated/ExampleSubgraph/ExampleContract.ts +0 -35
- package/tests/cli/validation/source-without-address-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/source-without-address-is-valid/schema.graphql +0 -3
- package/tests/cli/validation/source-without-address-is-valid/subgraph.yaml +0 -23
- package/tests/cli/validation/source-without-address-is-valid.stderr +0 -24
- package/tests/cli/validation/topic0-is-valid/Abi.json +0 -7
- package/tests/cli/validation/topic0-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/topic0-is-valid/schema.graphql +0 -4
- package/tests/cli/validation/topic0-is-valid/subgraph.yaml +0 -24
- package/tests/cli/validation.test.ts +0 -226
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -19
package/src/codegen/schema.ts
DELETED
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
import immutable from 'immutable';
|
|
2
|
-
import Schema from '../schema';
|
|
3
|
-
import * as typesCodegen from './types';
|
|
4
|
-
import * as tsCodegen from './typescript';
|
|
5
|
-
|
|
6
|
-
class IdField {
|
|
7
|
-
static BYTES = Symbol('Bytes');
|
|
8
|
-
static STRING = Symbol('String');
|
|
9
|
-
|
|
10
|
-
private kind: typeof IdField.BYTES | typeof IdField.STRING;
|
|
11
|
-
|
|
12
|
-
constructor(idField: immutable.Map<any, any>) {
|
|
13
|
-
const typeName = idField.getIn(['type', 'type', 'name', 'value']);
|
|
14
|
-
this.kind = typeName === 'Bytes' ? IdField.BYTES : IdField.STRING;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
typeName() {
|
|
18
|
-
return this.kind === IdField.BYTES ? 'Bytes' : 'string';
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
gqlTypeName() {
|
|
22
|
-
return this.kind === IdField.BYTES ? 'Bytes' : 'String';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
tsNamedType() {
|
|
26
|
-
return tsCodegen.namedType(this.typeName());
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
tsValueFrom() {
|
|
30
|
-
return this.kind === IdField.BYTES ? 'Value.fromBytes(id)' : 'Value.fromString(id)';
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
tsValueKind() {
|
|
34
|
-
return this.kind === IdField.BYTES ? 'ValueKind.BYTES' : 'ValueKind.STRING';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
tsValueToString() {
|
|
38
|
-
return this.kind == IdField.BYTES ? 'id.toBytes().toHexString()' : 'id.toString()';
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
tsToString() {
|
|
42
|
-
return this.kind == IdField.BYTES ? 'id.toHexString()' : 'id';
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static fromFields(fields: immutable.List<any>) {
|
|
46
|
-
const idField = fields.find(field => field.getIn(['name', 'value']) === 'id');
|
|
47
|
-
return new IdField(idField);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
static fromTypeDef(def: immutable.Map<any, any>) {
|
|
51
|
-
return IdField.fromFields(def.get('fields'));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export default class SchemaCodeGenerator {
|
|
56
|
-
constructor(private schema: Schema) {
|
|
57
|
-
this.schema = schema;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
generateModuleImports() {
|
|
61
|
-
return [
|
|
62
|
-
tsCodegen.moduleImports(
|
|
63
|
-
[
|
|
64
|
-
// Base classes
|
|
65
|
-
'TypedMap',
|
|
66
|
-
'Entity',
|
|
67
|
-
'Value',
|
|
68
|
-
'ValueKind',
|
|
69
|
-
|
|
70
|
-
// APIs
|
|
71
|
-
'store',
|
|
72
|
-
|
|
73
|
-
// Basic Scalar types
|
|
74
|
-
'Bytes',
|
|
75
|
-
'BigInt',
|
|
76
|
-
'BigDecimal',
|
|
77
|
-
],
|
|
78
|
-
'@graphprotocol/graph-ts',
|
|
79
|
-
),
|
|
80
|
-
];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
generateTypes() {
|
|
84
|
-
return this.schema.ast
|
|
85
|
-
.get('definitions')
|
|
86
|
-
.filter((def: any) => this._isEntityTypeDefinition(def))
|
|
87
|
-
.map((def: any) => this._generateEntityType(def));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
_isEntityTypeDefinition(def: immutable.Map<any, any>) {
|
|
91
|
-
return (
|
|
92
|
-
def.get('kind') === 'ObjectTypeDefinition' &&
|
|
93
|
-
def
|
|
94
|
-
.get('directives')
|
|
95
|
-
.find((directive: any) => directive.getIn(['name', 'value']) === 'entity') !== undefined
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
_isInterfaceDefinition(def: immutable.Map<any, any>) {
|
|
100
|
-
return def.get('kind') === 'InterfaceTypeDefinition';
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
_generateEntityType(def: immutable.Map<any, any>) {
|
|
104
|
-
const name = def.getIn(['name', 'value']) as string;
|
|
105
|
-
const klass = tsCodegen.klass(name, { export: true, extends: 'Entity' });
|
|
106
|
-
const fields = def.get('fields');
|
|
107
|
-
const idField = IdField.fromFields(fields);
|
|
108
|
-
|
|
109
|
-
// Generate and add a constructor
|
|
110
|
-
klass.addMethod(this._generateConstructor(name, fields));
|
|
111
|
-
|
|
112
|
-
// Generate and add save() and getById() methods
|
|
113
|
-
this._generateStoreMethods(name, idField).forEach(method => klass.addMethod(method));
|
|
114
|
-
|
|
115
|
-
// Generate and add entity field getters and setters
|
|
116
|
-
def
|
|
117
|
-
.get('fields')
|
|
118
|
-
.reduce(
|
|
119
|
-
(methods: any, field: any) => methods.concat(this._generateEntityFieldMethods(def, field)),
|
|
120
|
-
immutable.List(),
|
|
121
|
-
)
|
|
122
|
-
.forEach((method: any) => klass.addMethod(method));
|
|
123
|
-
|
|
124
|
-
return klass;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
_generateConstructor(_entityName: string, fields: immutable.List<any>) {
|
|
128
|
-
const idField = IdField.fromFields(fields);
|
|
129
|
-
return tsCodegen.method(
|
|
130
|
-
'constructor',
|
|
131
|
-
[tsCodegen.param('id', idField.tsNamedType())],
|
|
132
|
-
undefined,
|
|
133
|
-
`
|
|
134
|
-
super()
|
|
135
|
-
this.set('id', ${idField.tsValueFrom()})
|
|
136
|
-
`,
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
_generateStoreMethods(entityName: any, idField: any) {
|
|
141
|
-
return immutable.List.of<tsCodegen.Method | tsCodegen.StaticMethod>(
|
|
142
|
-
tsCodegen.method(
|
|
143
|
-
'save',
|
|
144
|
-
[],
|
|
145
|
-
tsCodegen.namedType('void'),
|
|
146
|
-
`
|
|
147
|
-
let id = this.get('id')
|
|
148
|
-
assert(id != null,
|
|
149
|
-
'Cannot save ${entityName} entity without an ID')
|
|
150
|
-
if (id) {
|
|
151
|
-
assert(id.kind == ${idField.tsValueKind()},
|
|
152
|
-
\`Entities of type ${entityName} must have an ID of type ${idField.gqlTypeName()} but the id '\${id.displayData()}' is of type \${id.displayKind()}\`)
|
|
153
|
-
store.set('${entityName}', ${idField.tsValueToString()}, this)
|
|
154
|
-
}`,
|
|
155
|
-
),
|
|
156
|
-
|
|
157
|
-
tsCodegen.staticMethod(
|
|
158
|
-
'load',
|
|
159
|
-
[tsCodegen.param('id', tsCodegen.namedType(idField.typeName()))],
|
|
160
|
-
tsCodegen.nullableType(tsCodegen.namedType(entityName)),
|
|
161
|
-
`
|
|
162
|
-
return changetype<${entityName} | null>(store.get('${entityName}', ${idField.tsToString()}))
|
|
163
|
-
`,
|
|
164
|
-
),
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
_generateEntityFieldMethods(entityDef: any, fieldDef: immutable.Map<any, any>) {
|
|
169
|
-
return immutable.List([
|
|
170
|
-
this._generateEntityFieldGetter(entityDef, fieldDef),
|
|
171
|
-
this._generateEntityFieldSetter(entityDef, fieldDef),
|
|
172
|
-
]);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
_generateEntityFieldGetter(_entityDef: any, fieldDef: immutable.Map<any, any>) {
|
|
176
|
-
const name = fieldDef.getIn(['name', 'value']);
|
|
177
|
-
const gqlType = fieldDef.get('type');
|
|
178
|
-
const fieldValueType = this._valueTypeFromGraphQl(gqlType);
|
|
179
|
-
const returnType = this._typeFromGraphQl(gqlType);
|
|
180
|
-
const isNullable = returnType instanceof tsCodegen.NullableType;
|
|
181
|
-
|
|
182
|
-
const getNonNullable = `return ${typesCodegen.valueToAsc('value!', fieldValueType)}`;
|
|
183
|
-
const getNullable = `if (!value || value.kind == ValueKind.NULL) {
|
|
184
|
-
return null
|
|
185
|
-
} else {
|
|
186
|
-
return ${typesCodegen.valueToAsc('value', fieldValueType)}
|
|
187
|
-
}`;
|
|
188
|
-
|
|
189
|
-
return tsCodegen.method(
|
|
190
|
-
`get ${name}`,
|
|
191
|
-
[],
|
|
192
|
-
returnType,
|
|
193
|
-
`
|
|
194
|
-
let value = this.get('${name}')
|
|
195
|
-
${isNullable ? getNullable : getNonNullable}
|
|
196
|
-
`,
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
_generateEntityFieldSetter(_entityDef: any, fieldDef: immutable.Map<any, any>) {
|
|
201
|
-
const name = fieldDef.getIn(['name', 'value']);
|
|
202
|
-
const gqlType = fieldDef.get('type');
|
|
203
|
-
const fieldValueType = this._valueTypeFromGraphQl(gqlType);
|
|
204
|
-
const paramType = this._typeFromGraphQl(gqlType);
|
|
205
|
-
const isNullable = paramType instanceof tsCodegen.NullableType;
|
|
206
|
-
const paramTypeString = isNullable ? paramType.inner.toString() : paramType.toString();
|
|
207
|
-
const isArray = paramType instanceof tsCodegen.ArrayType;
|
|
208
|
-
|
|
209
|
-
if (isArray && paramType.inner instanceof tsCodegen.NullableType) {
|
|
210
|
-
const baseType = this._baseType(gqlType);
|
|
211
|
-
|
|
212
|
-
throw new Error(`
|
|
213
|
-
GraphQL schema can't have List's with Nullable members.
|
|
214
|
-
Error in '${name}' field of type '[${baseType}]'.
|
|
215
|
-
Suggestion: add an '!' to the member type of the List, change from '[${baseType}]' to '[${baseType}!]'`);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const setNonNullable = `
|
|
219
|
-
this.set('${name}', ${typesCodegen.valueFromAsc(`value`, fieldValueType)})
|
|
220
|
-
`;
|
|
221
|
-
const setNullable = `
|
|
222
|
-
if (!value) {
|
|
223
|
-
this.unset('${name}')
|
|
224
|
-
} else {
|
|
225
|
-
this.set('${name}', ${typesCodegen.valueFromAsc(
|
|
226
|
-
`<${paramTypeString}>value`,
|
|
227
|
-
fieldValueType,
|
|
228
|
-
)})
|
|
229
|
-
}
|
|
230
|
-
`;
|
|
231
|
-
|
|
232
|
-
return tsCodegen.method(
|
|
233
|
-
`set ${name}`,
|
|
234
|
-
[tsCodegen.param('value', paramType)],
|
|
235
|
-
undefined,
|
|
236
|
-
isNullable ? setNullable : setNonNullable,
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
_resolveFieldType(gqlType: immutable.Map<any, any>) {
|
|
241
|
-
const typeName = gqlType.getIn(['name', 'value']);
|
|
242
|
-
|
|
243
|
-
// If this is a reference to another type, the field has the type of
|
|
244
|
-
// the referred type's id field
|
|
245
|
-
const typeDef = this.schema.ast
|
|
246
|
-
.get('definitions')
|
|
247
|
-
.find(
|
|
248
|
-
(def: any) =>
|
|
249
|
-
(this._isEntityTypeDefinition(def) || this._isInterfaceDefinition(def)) &&
|
|
250
|
-
def.getIn(['name', 'value']) === typeName,
|
|
251
|
-
);
|
|
252
|
-
if (typeDef) {
|
|
253
|
-
return IdField.fromTypeDef(typeDef).typeName();
|
|
254
|
-
}
|
|
255
|
-
return typeName as string;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/** Return the type that values for this field must have. For scalar
|
|
259
|
-
* types, that's the type from the subgraph schema. For references to
|
|
260
|
-
* other entity types, this is the same as the type of the id of the
|
|
261
|
-
* referred type, i.e., `string` or `Bytes`*/
|
|
262
|
-
_valueTypeFromGraphQl(gqlType: immutable.Map<any, any>): any {
|
|
263
|
-
if (gqlType.get('kind') === 'NonNullType') {
|
|
264
|
-
return this._valueTypeFromGraphQl(gqlType.get('type'));
|
|
265
|
-
}
|
|
266
|
-
if (gqlType.get('kind') === 'ListType') {
|
|
267
|
-
return '[' + this._valueTypeFromGraphQl(gqlType.get('type')) + ']';
|
|
268
|
-
}
|
|
269
|
-
return this._resolveFieldType(gqlType);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/** Determine the base type of `gqlType` by removing any non-null
|
|
273
|
-
* constraints and using the type of elements of lists */
|
|
274
|
-
_baseType(gqlType: immutable.Map<any, any>): any {
|
|
275
|
-
if (gqlType.get('kind') === 'NonNullType') {
|
|
276
|
-
return this._baseType(gqlType.get('type'));
|
|
277
|
-
}
|
|
278
|
-
if (gqlType.get('kind') === 'ListType') {
|
|
279
|
-
return this._baseType(gqlType.get('type'));
|
|
280
|
-
}
|
|
281
|
-
return gqlType.getIn(['name', 'value']);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
_typeFromGraphQl(gqlType: immutable.Map<any, any>, nullable = true): any {
|
|
285
|
-
if (gqlType.get('kind') === 'NonNullType') {
|
|
286
|
-
return this._typeFromGraphQl(gqlType.get('type'), false);
|
|
287
|
-
}
|
|
288
|
-
if (gqlType.get('kind') === 'ListType') {
|
|
289
|
-
const type = tsCodegen.arrayType(this._typeFromGraphQl(gqlType.get('type')));
|
|
290
|
-
return nullable ? tsCodegen.nullableType(type) : type;
|
|
291
|
-
}
|
|
292
|
-
// NamedType
|
|
293
|
-
const type = tsCodegen.namedType(
|
|
294
|
-
typesCodegen.ascTypeForValue(this._resolveFieldType(gqlType)) as any,
|
|
295
|
-
);
|
|
296
|
-
// In AssemblyScript, primitives cannot be nullable.
|
|
297
|
-
return nullable && !type.isPrimitive() ? tsCodegen.nullableType(type) : type;
|
|
298
|
-
}
|
|
299
|
-
}
|
package/src/codegen/template.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import immutable from 'immutable';
|
|
2
|
-
import Protocol from '../protocols';
|
|
3
|
-
import IpfsFileTemplateCodeGen from '../protocols/ipfs/codegen/file_template';
|
|
4
|
-
import * as tsCodegen from './typescript';
|
|
5
|
-
|
|
6
|
-
export default class DataSourceTemplateCodeGenerator {
|
|
7
|
-
protocolTemplateCodeGen: any;
|
|
8
|
-
|
|
9
|
-
constructor(public template: immutable.Map<any, any>, protocol: Protocol) {
|
|
10
|
-
this.template = template;
|
|
11
|
-
const kind = template.get('kind');
|
|
12
|
-
|
|
13
|
-
if (kind.split('/')[0] == protocol.name) {
|
|
14
|
-
this.protocolTemplateCodeGen = protocol.getTemplateCodeGen(template);
|
|
15
|
-
} else if (kind == 'file/ipfs') {
|
|
16
|
-
this.protocolTemplateCodeGen = new IpfsFileTemplateCodeGen(template);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
generateModuleImports() {
|
|
21
|
-
return [
|
|
22
|
-
tsCodegen.moduleImports(
|
|
23
|
-
[
|
|
24
|
-
...this.protocolTemplateCodeGen.generateModuleImports(),
|
|
25
|
-
'DataSourceTemplate',
|
|
26
|
-
'DataSourceContext',
|
|
27
|
-
],
|
|
28
|
-
'@graphprotocol/graph-ts',
|
|
29
|
-
),
|
|
30
|
-
];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
generateTypes() {
|
|
34
|
-
return immutable.List([this._generateTemplateType()]);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
_generateTemplateType() {
|
|
38
|
-
const name = this.template.get('name');
|
|
39
|
-
|
|
40
|
-
const klass = tsCodegen.klass(name, { export: true, extends: 'DataSourceTemplate' });
|
|
41
|
-
klass.addMethod(this.protocolTemplateCodeGen.generateCreateMethod());
|
|
42
|
-
klass.addMethod(this.protocolTemplateCodeGen.generateCreateWithContextMethod());
|
|
43
|
-
return klass;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
import immutable from 'immutable';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ethereum.Value -> AssemblyScript conversions
|
|
5
|
-
*/
|
|
6
|
-
const ETHEREUM_VALUE_TO_ASSEMBLYSCRIPT = [
|
|
7
|
-
// Scalar values
|
|
8
|
-
|
|
9
|
-
['address', 'Address', (code: any) => `${code}.toAddress()`],
|
|
10
|
-
['bool', 'boolean', (code: any) => `${code}.toBoolean()`],
|
|
11
|
-
['byte', 'Bytes', (code: any) => `${code}.toBytes()`],
|
|
12
|
-
[
|
|
13
|
-
/^bytes(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32)?$/,
|
|
14
|
-
'Bytes',
|
|
15
|
-
(code: any) => `${code}.toBytes()`,
|
|
16
|
-
],
|
|
17
|
-
[/^int(8|16|24|32)$/, 'i32', (code: any) => `${code}.toI32()`],
|
|
18
|
-
[/^uint(8|16|24)$/, 'i32', (code: any) => `${code}.toI32()`],
|
|
19
|
-
['uint32', 'BigInt', (code: any) => `${code}.toBigInt()`],
|
|
20
|
-
[
|
|
21
|
-
/^u?int(40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)$/,
|
|
22
|
-
'BigInt',
|
|
23
|
-
(code: any) => `${code}.toBigInt()`,
|
|
24
|
-
],
|
|
25
|
-
['string', 'string', (code: any) => `${code}.toString()`],
|
|
26
|
-
|
|
27
|
-
// Arrays
|
|
28
|
-
|
|
29
|
-
[/^address\[([0-9]+)?\]$/, 'Array<Address>', (code: any) => `${code}.toAddressArray()`],
|
|
30
|
-
[/^bool\[([0-9]+)?\]$/, 'Array<boolean>', (code: any) => `${code}.toBooleanArray()`],
|
|
31
|
-
[/^byte\[([0-9]+)?\]$/, 'Array<Bytes>', (code: any) => `${code}.toBytesArray()`],
|
|
32
|
-
[
|
|
33
|
-
/^bytes(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32)?\[([0-9]+)?\]$/,
|
|
34
|
-
'Array<Bytes>',
|
|
35
|
-
(code: any) => `${code}.toBytesArray()`,
|
|
36
|
-
],
|
|
37
|
-
[/^int(8|16|24|32)\[([0-9]+)?\]$/, 'Array<i32>', (code: any) => `${code}.toI32Array()`],
|
|
38
|
-
[/^uint(8|16|24)\[([0-9]+)?\]$/, 'Array<i32>', (code: any) => `${code}.toI32Array()`],
|
|
39
|
-
[/^uint32\[([0-9]+)?\]$/, 'Array<BigInt>', (code: any) => `${code}.toBigIntArray()`],
|
|
40
|
-
[
|
|
41
|
-
/^u?int(40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)\[([0-9]+)?\]$/,
|
|
42
|
-
'Array<BigInt>',
|
|
43
|
-
(code: any) => `${code}.toBigIntArray()`,
|
|
44
|
-
],
|
|
45
|
-
[/^string\[([0-9]+)?\]$/, 'Array<string>', (code: any) => `${code}.toStringArray()`],
|
|
46
|
-
|
|
47
|
-
// Tuples
|
|
48
|
-
|
|
49
|
-
['tuple', 'ethereum.Tuple', (code: any) => `${code}.toTuple()`],
|
|
50
|
-
[
|
|
51
|
-
/^tuple\[([0-9]+)?\]$/,
|
|
52
|
-
'Array<ethereum.Tuple>',
|
|
53
|
-
(code: any, type: any) => `${code}.toTupleArray<${type}>()`,
|
|
54
|
-
],
|
|
55
|
-
|
|
56
|
-
// Multi dimensional arrays
|
|
57
|
-
|
|
58
|
-
[
|
|
59
|
-
/^address\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
60
|
-
'Array<Array<Address>>',
|
|
61
|
-
(code: any) => `${code}.toAddressMatrix()`,
|
|
62
|
-
],
|
|
63
|
-
[
|
|
64
|
-
/^bool\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
65
|
-
'Array<Array<boolean>>',
|
|
66
|
-
(code: any) => `${code}.toBooleanMatrix()`,
|
|
67
|
-
],
|
|
68
|
-
[
|
|
69
|
-
/^byte\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
70
|
-
'Array<Array<Bytes>>',
|
|
71
|
-
(code: any) => `${code}.toBytesMatrix()`,
|
|
72
|
-
],
|
|
73
|
-
[
|
|
74
|
-
/^bytes(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32)?\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
75
|
-
'Array<Array<Bytes>>',
|
|
76
|
-
(code: any) => `${code}.toBytesMatrix()`,
|
|
77
|
-
],
|
|
78
|
-
[
|
|
79
|
-
/^int(8|16|24|32)\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
80
|
-
'Array<Array<i32>>',
|
|
81
|
-
(code: any) => `${code}.toI32Matrix()`,
|
|
82
|
-
],
|
|
83
|
-
[
|
|
84
|
-
/^uint(8|16|24)\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
85
|
-
'Array<Array<i32>>',
|
|
86
|
-
(code: any) => `${code}.toI32Matrix()`,
|
|
87
|
-
],
|
|
88
|
-
[
|
|
89
|
-
/^uint32\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
90
|
-
'Array<Array<BigInt>>',
|
|
91
|
-
(code: any) => `${code}.toBigIntMatrix()`,
|
|
92
|
-
],
|
|
93
|
-
[
|
|
94
|
-
/^u?int(40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
95
|
-
'Array<Array<BigInt>>',
|
|
96
|
-
(code: any) => `${code}.toBigIntMatrix()`,
|
|
97
|
-
],
|
|
98
|
-
[
|
|
99
|
-
/^string\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
100
|
-
'Array<Array<string>>',
|
|
101
|
-
(code: any) => `${code}.toStringMatrix()`,
|
|
102
|
-
],
|
|
103
|
-
[
|
|
104
|
-
/^tuple\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
105
|
-
'Array<Array<ethereum.Tuple>>',
|
|
106
|
-
(code: any, type: any) => `${code}.toTupleMatrix<${type}>()`,
|
|
107
|
-
],
|
|
108
|
-
];
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* AssemblyScript -> ethereum.Value conversions
|
|
112
|
-
*
|
|
113
|
-
* Note: The order and patterns for conversions in this direction differ slightly
|
|
114
|
-
* from ethereum.Value -> AssemblyScript, which is why there is a separate table
|
|
115
|
-
* for them.
|
|
116
|
-
*/
|
|
117
|
-
const ASSEMBLYSCRIPT_TO_ETHEREUM_VALUE = [
|
|
118
|
-
// Scalar values
|
|
119
|
-
|
|
120
|
-
['Address', 'address', (code: any) => `ethereum.Value.fromAddress(${code})`],
|
|
121
|
-
['boolean', 'bool', (code: any) => `ethereum.Value.fromBoolean(${code})`],
|
|
122
|
-
['Bytes', 'byte', (code: any) => `ethereum.Value.fromFixedBytes(${code})`],
|
|
123
|
-
['Bytes', 'bytes', (code: any) => `ethereum.Value.fromBytes(${code})`],
|
|
124
|
-
[
|
|
125
|
-
'Bytes',
|
|
126
|
-
/^bytes(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32)$/,
|
|
127
|
-
(code: any) => `ethereum.Value.fromFixedBytes(${code})`,
|
|
128
|
-
],
|
|
129
|
-
['i32', /^int(8|16|24|32)$/, (code: any) => `ethereum.Value.fromI32(${code})`],
|
|
130
|
-
[
|
|
131
|
-
'i32',
|
|
132
|
-
/^uint(8|16|24)$/,
|
|
133
|
-
(code: any) => `ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(${code}))`,
|
|
134
|
-
],
|
|
135
|
-
[
|
|
136
|
-
'BigInt',
|
|
137
|
-
/^int(40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)$/,
|
|
138
|
-
(code: any) => `ethereum.Value.fromSignedBigInt(${code})`,
|
|
139
|
-
],
|
|
140
|
-
[
|
|
141
|
-
'BigInt',
|
|
142
|
-
/^uint(32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)$/,
|
|
143
|
-
(code: any) => `ethereum.Value.fromUnsignedBigInt(${code})`,
|
|
144
|
-
],
|
|
145
|
-
['string', 'string', (code: any) => `ethereum.Value.fromString(${code})`],
|
|
146
|
-
|
|
147
|
-
// Arrays
|
|
148
|
-
|
|
149
|
-
[
|
|
150
|
-
'Array<Address>',
|
|
151
|
-
/^address\[([0-9]+)?\]$/,
|
|
152
|
-
(code: any) => `ethereum.Value.fromAddressArray(${code})`,
|
|
153
|
-
],
|
|
154
|
-
[
|
|
155
|
-
'Array<boolean>',
|
|
156
|
-
/^bool\[([0-9]+)?\]$/,
|
|
157
|
-
(code: any) => `ethereum.Value.fromBooleanArray(${code})`,
|
|
158
|
-
],
|
|
159
|
-
[
|
|
160
|
-
'Array<Bytes>',
|
|
161
|
-
/^byte\[([0-9]+)?\]$/,
|
|
162
|
-
(code: any) => `ethereum.Value.fromFixedBytesArray(${code})`,
|
|
163
|
-
],
|
|
164
|
-
['Array<Bytes>', /bytes\[([0-9]+)?\]$/, (code: any) => `ethereum.Value.fromBytesArray(${code})`],
|
|
165
|
-
[
|
|
166
|
-
'Array<Bytes>',
|
|
167
|
-
/^bytes(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32)\[([0-9]+)?\]$/,
|
|
168
|
-
(code: any) => `ethereum.Value.fromFixedBytesArray(${code})`,
|
|
169
|
-
],
|
|
170
|
-
[
|
|
171
|
-
'Array<i32>',
|
|
172
|
-
/^int(8|16|24|32)\[([0-9]+)?\]$/,
|
|
173
|
-
(code: any) => `ethereum.Value.fromI32Array(${code})`,
|
|
174
|
-
],
|
|
175
|
-
[
|
|
176
|
-
'Array<i32>',
|
|
177
|
-
/^uint(8|16|24)\[([0-9]+)?\]$/,
|
|
178
|
-
(code: any) => `ethereum.Value.fromI32Array(${code})`,
|
|
179
|
-
],
|
|
180
|
-
[
|
|
181
|
-
'Array<BigInt>',
|
|
182
|
-
/^int(40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)\[([0-9]+)?\]$/,
|
|
183
|
-
(code: any) => `ethereum.Value.fromSignedBigIntArray(${code})`,
|
|
184
|
-
],
|
|
185
|
-
[
|
|
186
|
-
'Array<BigInt>',
|
|
187
|
-
/^uint(32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)\[([0-9]+)?\]$/,
|
|
188
|
-
(code: any) => `ethereum.Value.fromUnsignedBigIntArray(${code})`,
|
|
189
|
-
],
|
|
190
|
-
[
|
|
191
|
-
'Array<string>',
|
|
192
|
-
/^string\[([0-9]+)?\]$/,
|
|
193
|
-
(code: any) => `ethereum.Value.fromStringArray(${code})`,
|
|
194
|
-
],
|
|
195
|
-
|
|
196
|
-
// Tuples
|
|
197
|
-
|
|
198
|
-
['ethereum.Tuple', 'tuple', (code: any) => `ethereum.Value.fromTuple(${code})`],
|
|
199
|
-
[
|
|
200
|
-
'Array<ethereum.Tuple>',
|
|
201
|
-
/^tuple\[([0-9]+)?\]$/,
|
|
202
|
-
(code: any) => `ethereum.Value.fromTupleArray(${code})`,
|
|
203
|
-
],
|
|
204
|
-
|
|
205
|
-
// Multi dimentional arrays
|
|
206
|
-
|
|
207
|
-
[
|
|
208
|
-
'Array<Array<Address>>',
|
|
209
|
-
/^address\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
210
|
-
(code: any) => `ethereum.Value.fromAddressMatrix(${code})`,
|
|
211
|
-
],
|
|
212
|
-
[
|
|
213
|
-
'Array<Array<boolean>>',
|
|
214
|
-
/^bool\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
215
|
-
(code: any) => `ethereum.Value.fromBooleanMatrix(${code})`,
|
|
216
|
-
],
|
|
217
|
-
[
|
|
218
|
-
'Array<Array<Bytes>>',
|
|
219
|
-
/^byte\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
220
|
-
(code: any) => `ethereum.Value.fromFixedBytesMatrix(${code})`,
|
|
221
|
-
],
|
|
222
|
-
[
|
|
223
|
-
'Array<Array<Bytes>>',
|
|
224
|
-
/bytes\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
225
|
-
(code: any) => `ethereum.Value.fromBytesMatrix(${code})`,
|
|
226
|
-
],
|
|
227
|
-
[
|
|
228
|
-
'Array<Array<Bytes>>',
|
|
229
|
-
/^bytes(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32)\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
230
|
-
(code: any) => `ethereum.Value.fromFixedBytesMatrix(${code})`,
|
|
231
|
-
],
|
|
232
|
-
[
|
|
233
|
-
'Array<Array<i32>>',
|
|
234
|
-
/^int(8|16|24|32)\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
235
|
-
(code: any) => `ethereum.Value.fromI32Matrix(${code})`,
|
|
236
|
-
],
|
|
237
|
-
[
|
|
238
|
-
'Array<Array<i32>>',
|
|
239
|
-
/^uint(8|16|24)\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
240
|
-
(code: any) => `ethereum.Value.fromI32Matrix(${code})`,
|
|
241
|
-
],
|
|
242
|
-
[
|
|
243
|
-
'Array<Array<BigInt>>',
|
|
244
|
-
/^int(40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
245
|
-
(code: any) => `ethereum.Value.fromSignedBigIntMatrix(${code})`,
|
|
246
|
-
],
|
|
247
|
-
[
|
|
248
|
-
'Array<Array<BigInt>>',
|
|
249
|
-
/^uint(32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
250
|
-
(code: any) => `ethereum.Value.fromUnsignedBigIntMatrix(${code})`,
|
|
251
|
-
],
|
|
252
|
-
[
|
|
253
|
-
'Array<Array<string>>',
|
|
254
|
-
/^string\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
255
|
-
(code: any) => `ethereum.Value.fromStringMatrix(${code})`,
|
|
256
|
-
],
|
|
257
|
-
[
|
|
258
|
-
'Array<Array<ethereum.Tuple>>',
|
|
259
|
-
/^tuple\[([0-9]+)?\]\[([0-9]+)?\]$/,
|
|
260
|
-
(code: any) => `ethereum.Value.fromTupleMatrix(${code})`,
|
|
261
|
-
],
|
|
262
|
-
];
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Value -> AssemblyScript conversions
|
|
266
|
-
*/
|
|
267
|
-
const VALUE_TO_ASSEMBLYSCRIPT = [
|
|
268
|
-
// Arrays
|
|
269
|
-
|
|
270
|
-
['[Bytes]', 'Array<Bytes>', (code: any) => `${code}.toBytesArray()`],
|
|
271
|
-
['[Boolean]', 'Array<boolean>', (code: any) => `${code}.toBooleanArray()`],
|
|
272
|
-
['[Int]', 'Array<i32>', (code: any) => `${code}.toI32Array()`],
|
|
273
|
-
['[BigInt]', 'Array<BigInt>', (code: any) => `${code}.toBigIntArray()`],
|
|
274
|
-
['[ID]', 'Array<string>', (code: any) => `${code}.toStringArray()`],
|
|
275
|
-
['[String]', 'Array<string>', (code: any) => `${code}.toStringArray()`],
|
|
276
|
-
['[BigDecimal]', 'Array<BigDecimal>', (code: any) => `${code}.toBigDecimalArray()`],
|
|
277
|
-
[/\[.*\]/, 'Array<string>', (code: any) => `${code}.toStringArray()`],
|
|
278
|
-
|
|
279
|
-
// Scalar values
|
|
280
|
-
|
|
281
|
-
['Bytes', 'Bytes', (code: any) => `${code}.toBytes()`],
|
|
282
|
-
['Boolean', 'boolean', (code: any) => `${code}.toBoolean()`],
|
|
283
|
-
['Int', 'i32', (code: any) => `${code}.toI32()`],
|
|
284
|
-
['BigInt', 'BigInt', (code: any) => `${code}.toBigInt()`],
|
|
285
|
-
['ID', 'string', (code: any) => `${code}.toString()`],
|
|
286
|
-
['String', 'string', (code: any) => `${code}.toString()`],
|
|
287
|
-
['BigDecimal', 'BigDecimal', (code: any) => `${code}.toBigDecimal()`],
|
|
288
|
-
[/.*/, 'string', (code: any) => `${code}.toString()`],
|
|
289
|
-
];
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* AssemblyScript -> Value conversions
|
|
293
|
-
*
|
|
294
|
-
* Note: The order and patterns for conversions in this direction differ slightly
|
|
295
|
-
* from Value -> AssemblyScript, which is why there is a separate table
|
|
296
|
-
* for them.
|
|
297
|
-
*/
|
|
298
|
-
const ASSEMBLYSCRIPT_TO_VALUE = [
|
|
299
|
-
// Matrices
|
|
300
|
-
|
|
301
|
-
['Array<Array<Address>>', '[[Bytes]]', (code: any) => `Value.fromBytesMatrix(${code})`],
|
|
302
|
-
['Array<Array<Bytes>>', '[[Bytes]]', (code: any) => `Value.fromBytesMatrix(${code})`],
|
|
303
|
-
['Array<Array<boolean>>', '[[Boolean]]', (code: any) => `Value.fromBooleanMatrix(${code})`],
|
|
304
|
-
['Array<Array<i32>>', '[[Int]]', (code: any) => `Value.fromI32Matrix(${code})`],
|
|
305
|
-
['Array<Array<BigInt>>', '[[BigInt]]', (code: any) => `Value.fromBigIntMatrix(${code})`],
|
|
306
|
-
['Array<Array<string>>', '[[String]]', (code: any) => `Value.fromStringMatrix(${code})`],
|
|
307
|
-
['Array<Array<string>>', '[[ID]]', (code: any) => `Value.fromStringMatrix(${code})`],
|
|
308
|
-
[
|
|
309
|
-
'Array<Array<BigDecimal>>',
|
|
310
|
-
'[[BigDecimal]]',
|
|
311
|
-
(code: any) => `Value.fromBigDecimalMatrix(${code})`,
|
|
312
|
-
],
|
|
313
|
-
['Array<Array<string>>', /\[\[.*\]\]/, (code: any) => `Value.fromStringMatrix(${code})`],
|
|
314
|
-
['Array<Array<string | null>>', null, (code: any) => `Value.fromStringMatrix(${code})`], // is this overwriting the Array null below?
|
|
315
|
-
|
|
316
|
-
// Arrays
|
|
317
|
-
|
|
318
|
-
['Array<Address>', '[Bytes]', (code: any) => `Value.fromBytesArray(${code})`],
|
|
319
|
-
['Array<Bytes>', '[Bytes]', (code: any) => `Value.fromBytesArray(${code})`],
|
|
320
|
-
['Array<boolean>', '[Boolean]', (code: any) => `Value.fromBooleanArray(${code})`],
|
|
321
|
-
['Array<i32>', '[Int]', (code: any) => `Value.fromI32Array(${code})`],
|
|
322
|
-
['Array<BigInt>', '[BigInt]', (code: any) => `Value.fromBigIntArray(${code})`],
|
|
323
|
-
['Array<string>', '[String]', (code: any) => `Value.fromStringArray(${code})`],
|
|
324
|
-
['Array<string>', '[ID]', (code: any) => `Value.fromStringArray(${code})`],
|
|
325
|
-
['Array<BigDecimal>', '[BigDecimal]', (code: any) => `Value.fromBigDecimalArray(${code})`],
|
|
326
|
-
['Array<string>', /\[.*\]/, (code: any) => `Value.fromStringArray(${code})`],
|
|
327
|
-
['Array<string | null>', null, (code: any) => `Value.fromStringArray(${code})`],
|
|
328
|
-
|
|
329
|
-
// Scalar values
|
|
330
|
-
|
|
331
|
-
['Address', 'Bytes', (code: any) => `Value.fromBytes(${code})`],
|
|
332
|
-
['Bytes', 'Bytes', (code: any) => `Value.fromBytes(${code})`],
|
|
333
|
-
['boolean', 'Boolean', (code: any) => `Value.fromBoolean(${code})`],
|
|
334
|
-
['i32', 'Int', (code: any) => `Value.fromI32(${code})`],
|
|
335
|
-
['BigInt', 'BigInt', (code: any) => `Value.fromBigInt(${code})`],
|
|
336
|
-
['string', 'String', (code: any) => `Value.fromString(${code})`],
|
|
337
|
-
['string', 'ID', (code: any) => `Value.fromString(${code})`],
|
|
338
|
-
['BigDecimal', 'BigDecimal', (code: any) => `Value.fromBigDecimal(${code})`],
|
|
339
|
-
['string', /.*/, (code: any) => `Value.fromString(${code})`],
|
|
340
|
-
];
|
|
341
|
-
|
|
342
|
-
const CONVERSIONS = {
|
|
343
|
-
ethereum: {
|
|
344
|
-
AssemblyScript: ETHEREUM_VALUE_TO_ASSEMBLYSCRIPT,
|
|
345
|
-
},
|
|
346
|
-
AssemblyScript: {
|
|
347
|
-
ethereum: ASSEMBLYSCRIPT_TO_ETHEREUM_VALUE,
|
|
348
|
-
Value: ASSEMBLYSCRIPT_TO_VALUE,
|
|
349
|
-
},
|
|
350
|
-
Value: {
|
|
351
|
-
AssemblyScript: VALUE_TO_ASSEMBLYSCRIPT,
|
|
352
|
-
},
|
|
353
|
-
} as const;
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Type conversions
|
|
357
|
-
*/
|
|
358
|
-
export default immutable.fromJS(CONVERSIONS);
|