@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/subgraph.ts
DELETED
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import * as graphql from 'graphql/language';
|
|
4
|
-
import immutable from 'immutable';
|
|
5
|
-
import yaml from 'yaml';
|
|
6
|
-
import { strOptions } from 'yaml/types';
|
|
7
|
-
import debug from './debug';
|
|
8
|
-
import { Subgraph as ISubgraph } from './protocols/subgraph';
|
|
9
|
-
import * as validation from './validation';
|
|
10
|
-
|
|
11
|
-
const subgraphDebug = debug('graph-cli:subgraph');
|
|
12
|
-
|
|
13
|
-
const throwCombinedError = (filename: string, errors: immutable.List<any>) => {
|
|
14
|
-
throw new Error(
|
|
15
|
-
errors.reduce(
|
|
16
|
-
(msg, e) =>
|
|
17
|
-
`${msg}
|
|
18
|
-
|
|
19
|
-
Path: ${e.get('path').size === 0 ? '/' : e.get('path').join(' > ')}
|
|
20
|
-
${e.get('message').split('\n').join('\n ')}`,
|
|
21
|
-
`Error in ${path.relative(process.cwd(), filename)}:`,
|
|
22
|
-
),
|
|
23
|
-
);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const buildCombinedWarning = (filename: string, warnings: immutable.List<any>) =>
|
|
27
|
-
warnings.size > 0
|
|
28
|
-
? warnings.reduce(
|
|
29
|
-
(msg, w) =>
|
|
30
|
-
`${msg}
|
|
31
|
-
|
|
32
|
-
Path: ${w.get('path').size === 0 ? '/' : w.get('path').join(' > ')}
|
|
33
|
-
${w.get('message').split('\n').join('\n ')}`,
|
|
34
|
-
`Warnings in ${path.relative(process.cwd(), filename)}:`,
|
|
35
|
-
) + '\n'
|
|
36
|
-
: null;
|
|
37
|
-
|
|
38
|
-
type ResolveFile = (path: string) => string;
|
|
39
|
-
|
|
40
|
-
export default class Subgraph {
|
|
41
|
-
static async validate(data: any, protocol: any, { resolveFile }: { resolveFile: ResolveFile }) {
|
|
42
|
-
subgraphDebug(`Validating Subgraph with protocol "%s"`, protocol);
|
|
43
|
-
if (protocol.name == null) {
|
|
44
|
-
return immutable.fromJS([
|
|
45
|
-
{
|
|
46
|
-
path: [],
|
|
47
|
-
message: `Unable to determine for which protocol manifest file is built for. Ensure you have at least one 'dataSources' and/or 'templates' elements defined in your subgraph.`,
|
|
48
|
-
},
|
|
49
|
-
]);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Parse the default subgraph schema
|
|
53
|
-
const schema = graphql.parse(
|
|
54
|
-
await fs.readFile(
|
|
55
|
-
path.join(__dirname, 'protocols', protocol.name, `manifest.graphql`),
|
|
56
|
-
'utf-8',
|
|
57
|
-
),
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
// Obtain the root `SubgraphManifest` type from the schema
|
|
61
|
-
const rootType = schema.definitions.find(definition => {
|
|
62
|
-
// @ts-expect-error TODO: name field does not exist on definition, really?
|
|
63
|
-
return definition.name.value === 'SubgraphManifest';
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// Validate the subgraph manifest using this schema
|
|
67
|
-
return validation.validateManifest(data, rootType, schema, protocol, { resolveFile });
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
static validateSchema(manifest: any, { resolveFile }: { resolveFile: ResolveFile }) {
|
|
71
|
-
const filename = resolveFile(manifest.getIn(['schema', 'file']));
|
|
72
|
-
const validationErrors = validation.validateSchema(filename);
|
|
73
|
-
let errors: immutable.Collection<any, any>;
|
|
74
|
-
|
|
75
|
-
if (validationErrors.size > 0) {
|
|
76
|
-
errors = validationErrors.groupBy(error => error.get('entity')).sort();
|
|
77
|
-
const msg = errors.reduce((msg, errors, entity) => {
|
|
78
|
-
errors = errors.groupBy((error: any) => error.get('directive'));
|
|
79
|
-
const inner_msgs = errors.reduce((msg: string, errors: any[], directive: string) => {
|
|
80
|
-
return `${msg}${
|
|
81
|
-
directive
|
|
82
|
-
? `
|
|
83
|
-
${directive}:`
|
|
84
|
-
: ''
|
|
85
|
-
}
|
|
86
|
-
${errors
|
|
87
|
-
.map(error => error.get('message').split('\n').join('\n '))
|
|
88
|
-
.map(msg => `${directive ? ' ' : ''}- ${msg}`)
|
|
89
|
-
.join('\n ')}`;
|
|
90
|
-
}, ``);
|
|
91
|
-
return `${msg}
|
|
92
|
-
|
|
93
|
-
${entity}:${inner_msgs}`;
|
|
94
|
-
}, `Error in ${path.relative(process.cwd(), filename)}:`);
|
|
95
|
-
|
|
96
|
-
throw new Error(msg);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
static validateRepository(manifest: immutable.Collection<any, any>) {
|
|
101
|
-
const repository = manifest.get('repository');
|
|
102
|
-
|
|
103
|
-
return /^https:\/\/github\.com\/graphprotocol\/example-subgraphs?$/.test(repository)
|
|
104
|
-
? immutable.List().push(
|
|
105
|
-
immutable.fromJS({
|
|
106
|
-
path: ['repository'],
|
|
107
|
-
message: `\
|
|
108
|
-
The repository is still set to ${repository}.
|
|
109
|
-
Please replace it with a link to your subgraph source code.`,
|
|
110
|
-
}),
|
|
111
|
-
)
|
|
112
|
-
: immutable.List();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
static validateDescription(manifest: immutable.Collection<any, any>) {
|
|
116
|
-
// TODO: Maybe implement this in the future for each protocol example description
|
|
117
|
-
return manifest.get('description', '').startsWith('Gravatar for ')
|
|
118
|
-
? immutable.List().push(
|
|
119
|
-
immutable.fromJS({
|
|
120
|
-
path: ['description'],
|
|
121
|
-
message: `\
|
|
122
|
-
The description is still the one from the example subgraph.
|
|
123
|
-
Please update it to tell users more about your subgraph.`,
|
|
124
|
-
}),
|
|
125
|
-
)
|
|
126
|
-
: immutable.List();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
static validateHandlers(
|
|
130
|
-
manifest: immutable.Collection<any, any>,
|
|
131
|
-
protocol: any,
|
|
132
|
-
protocolSubgraph: ISubgraph,
|
|
133
|
-
) {
|
|
134
|
-
return manifest
|
|
135
|
-
.get('dataSources')
|
|
136
|
-
.filter((dataSource: any) => protocol.isValidKindName(dataSource.get('kind')))
|
|
137
|
-
.reduce((errors: any, dataSource: any, dataSourceIndex: any) => {
|
|
138
|
-
const path = ['dataSources', dataSourceIndex, 'mapping'];
|
|
139
|
-
const mapping = dataSource.get('mapping');
|
|
140
|
-
const handlerTypes = protocolSubgraph.handlerTypes();
|
|
141
|
-
|
|
142
|
-
subgraphDebug(
|
|
143
|
-
'Validating dataSource "%s" handlers with %d handlers types defined for protocol',
|
|
144
|
-
dataSource.get('name'),
|
|
145
|
-
handlerTypes.size,
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
if (handlerTypes.size == 0) {
|
|
149
|
-
return errors;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const areAllHandlersEmpty = handlerTypes
|
|
153
|
-
.map((handlerType: any) => mapping.get(handlerType, immutable.List()))
|
|
154
|
-
.every((handlers: immutable.List<any>) => handlers.isEmpty());
|
|
155
|
-
|
|
156
|
-
const handlerNamesWithoutLast = handlerTypes.pop().join(', ');
|
|
157
|
-
|
|
158
|
-
return areAllHandlersEmpty
|
|
159
|
-
? errors.push(
|
|
160
|
-
immutable.fromJS({
|
|
161
|
-
path,
|
|
162
|
-
message: `\
|
|
163
|
-
Mapping has no ${handlerNamesWithoutLast} or ${handlerTypes.get(-1)}.
|
|
164
|
-
At least one such handler must be defined.`,
|
|
165
|
-
}),
|
|
166
|
-
)
|
|
167
|
-
: errors;
|
|
168
|
-
}, immutable.List());
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
static validateContractValues(manifest: any, protocol: any) {
|
|
172
|
-
if (!protocol.hasContract()) {
|
|
173
|
-
return immutable.List();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return validation.validateContractValues(manifest, protocol);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Validate that data source names are unique, so they don't overwrite each other.
|
|
180
|
-
static validateUniqueDataSourceNames(manifest: any) {
|
|
181
|
-
const names: any[] = [];
|
|
182
|
-
return manifest
|
|
183
|
-
.get('dataSources')
|
|
184
|
-
.reduce((errors: immutable.List<any>, dataSource: any, dataSourceIndex: number) => {
|
|
185
|
-
const path = ['dataSources', dataSourceIndex, 'name'];
|
|
186
|
-
const name = dataSource.get('name');
|
|
187
|
-
if (names.includes(name)) {
|
|
188
|
-
errors = errors.push(
|
|
189
|
-
immutable.fromJS({
|
|
190
|
-
path,
|
|
191
|
-
message: `\
|
|
192
|
-
More than one data source named '${name}', data source names must be unique.`,
|
|
193
|
-
}),
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
names.push(name);
|
|
197
|
-
return errors;
|
|
198
|
-
}, immutable.List());
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
static validateUniqueTemplateNames(manifest: any) {
|
|
202
|
-
const names: any[] = [];
|
|
203
|
-
return manifest
|
|
204
|
-
.get('templates', immutable.List())
|
|
205
|
-
.reduce((errors: immutable.List<any>, template: any, templateIndex: number) => {
|
|
206
|
-
const path = ['templates', templateIndex, 'name'];
|
|
207
|
-
const name = template.get('name');
|
|
208
|
-
if (names.includes(name)) {
|
|
209
|
-
errors = errors.push(
|
|
210
|
-
immutable.fromJS({
|
|
211
|
-
path,
|
|
212
|
-
message: `\
|
|
213
|
-
More than one template named '${name}', template names must be unique.`,
|
|
214
|
-
}),
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
names.push(name);
|
|
218
|
-
return errors;
|
|
219
|
-
}, immutable.List());
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
static dump(manifest: any) {
|
|
223
|
-
strOptions.fold.lineWidth = 90;
|
|
224
|
-
// @ts-expect-error TODO: plain is the value behind the TS constant
|
|
225
|
-
strOptions.defaultType = 'PLAIN';
|
|
226
|
-
|
|
227
|
-
return yaml.stringify(manifest.toJS());
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
static async load(
|
|
231
|
-
filename: string,
|
|
232
|
-
{ protocol, skipValidation }: { protocol?: any; skipValidation?: boolean } = {
|
|
233
|
-
skipValidation: false,
|
|
234
|
-
},
|
|
235
|
-
) {
|
|
236
|
-
// Load and validate the manifest
|
|
237
|
-
let data = null;
|
|
238
|
-
let has_file_data_sources = false;
|
|
239
|
-
|
|
240
|
-
if (filename.match(/.js$/)) {
|
|
241
|
-
data = require(path.resolve(filename));
|
|
242
|
-
} else {
|
|
243
|
-
const raw_data = await fs.readFile(filename, 'utf-8');
|
|
244
|
-
has_file_data_sources = raw_data.includes('kind: file');
|
|
245
|
-
data = yaml.parse(raw_data);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// Helper to resolve files relative to the subgraph manifest
|
|
249
|
-
const resolveFile: ResolveFile = maybeRelativeFile =>
|
|
250
|
-
path.resolve(path.dirname(filename), maybeRelativeFile);
|
|
251
|
-
|
|
252
|
-
// TODO: Validation for file data sources
|
|
253
|
-
if (!has_file_data_sources) {
|
|
254
|
-
const manifestErrors = await Subgraph.validate(data, protocol, { resolveFile });
|
|
255
|
-
if (manifestErrors.size > 0) {
|
|
256
|
-
throwCombinedError(filename, manifestErrors);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const manifest = immutable.fromJS(data) as immutable.Map<any, any>;
|
|
261
|
-
|
|
262
|
-
// Validate the schema
|
|
263
|
-
Subgraph.validateSchema(manifest, { resolveFile });
|
|
264
|
-
|
|
265
|
-
// Perform other validations
|
|
266
|
-
const protocolSubgraph = protocol.getSubgraph({
|
|
267
|
-
manifest,
|
|
268
|
-
resolveFile,
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
const errors = skipValidation
|
|
272
|
-
? immutable.List()
|
|
273
|
-
: immutable.List.of(
|
|
274
|
-
...protocolSubgraph.validateManifest(),
|
|
275
|
-
...Subgraph.validateContractValues(manifest, protocol),
|
|
276
|
-
...Subgraph.validateUniqueDataSourceNames(manifest),
|
|
277
|
-
...Subgraph.validateUniqueTemplateNames(manifest),
|
|
278
|
-
...Subgraph.validateHandlers(manifest, protocol, protocolSubgraph),
|
|
279
|
-
);
|
|
280
|
-
|
|
281
|
-
if (errors.size > 0) {
|
|
282
|
-
throwCombinedError(filename, errors);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// Perform warning validations
|
|
286
|
-
const warnings = skipValidation
|
|
287
|
-
? immutable.List()
|
|
288
|
-
: immutable.List.of(
|
|
289
|
-
...Subgraph.validateRepository(manifest),
|
|
290
|
-
...Subgraph.validateDescription(manifest),
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
return {
|
|
294
|
-
result: manifest,
|
|
295
|
-
warning: warnings.size > 0 ? buildCombinedWarning(filename, warnings) : null,
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
static async write(manifest: any, filename: string) {
|
|
300
|
-
await fs.writeFile(filename, Subgraph.dump(manifest));
|
|
301
|
-
}
|
|
302
|
-
}
|
package/src/type-generator.ts
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
// @ts-expect-error TODO: type out if necessary
|
|
3
|
-
import uncrashable from '@float-capital/float-subgraph-uncrashable/src/Index.bs.js';
|
|
4
|
-
import fs from 'fs-extra';
|
|
5
|
-
import * as toolbox from 'gluegun';
|
|
6
|
-
import * as graphql from 'graphql/language';
|
|
7
|
-
import immutable from 'immutable';
|
|
8
|
-
import prettier from 'prettier';
|
|
9
|
-
import DataSourceTemplateCodeGenerator from './codegen/template';
|
|
10
|
-
import { GENERATED_FILE_NOTE } from './codegen/typescript';
|
|
11
|
-
import { displayPath } from './command-helpers/fs';
|
|
12
|
-
import { Spinner, step, withSpinner } from './command-helpers/spinner';
|
|
13
|
-
import { applyMigrations } from './migrations';
|
|
14
|
-
import Protocol from './protocols';
|
|
15
|
-
import Schema from './schema';
|
|
16
|
-
import Subgraph from './subgraph';
|
|
17
|
-
import Watcher from './watcher';
|
|
18
|
-
|
|
19
|
-
export interface TypeGeneratorOptions {
|
|
20
|
-
sourceDir?: string;
|
|
21
|
-
subgraphManifest: string;
|
|
22
|
-
subgraph?: string;
|
|
23
|
-
protocol: Protocol;
|
|
24
|
-
outputDir: string;
|
|
25
|
-
skipMigrations?: boolean;
|
|
26
|
-
uncrashable: any;
|
|
27
|
-
uncrashableConfig: boolean;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default class TypeGenerator {
|
|
31
|
-
private sourceDir: string;
|
|
32
|
-
private options: TypeGeneratorOptions;
|
|
33
|
-
private protocol: Protocol;
|
|
34
|
-
private protocolTypeGenerator: any;
|
|
35
|
-
|
|
36
|
-
constructor(options: TypeGeneratorOptions) {
|
|
37
|
-
this.options = options;
|
|
38
|
-
this.sourceDir =
|
|
39
|
-
this.options.sourceDir ||
|
|
40
|
-
(this.options.subgraphManifest && path.dirname(this.options.subgraphManifest));
|
|
41
|
-
|
|
42
|
-
this.protocol = this.options.protocol;
|
|
43
|
-
this.protocolTypeGenerator = this.protocol?.getTypeGenerator?.({
|
|
44
|
-
sourceDir: this.sourceDir,
|
|
45
|
-
outputDir: this.options.outputDir,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
process.on('uncaughtException', e => {
|
|
49
|
-
toolbox.print.error(`UNCAUGHT EXCEPTION: ${e}`);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async generateTypes() {
|
|
54
|
-
try {
|
|
55
|
-
if (!this.options.skipMigrations && this.options.subgraphManifest) {
|
|
56
|
-
await applyMigrations({
|
|
57
|
-
sourceDir: this.sourceDir,
|
|
58
|
-
manifestFile: this.options.subgraphManifest,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
const subgraph = await this.loadSubgraph();
|
|
62
|
-
|
|
63
|
-
// Not all protocols support/have ABIs.
|
|
64
|
-
if (this.protocol.hasABIs()) {
|
|
65
|
-
const abis = await this.protocolTypeGenerator.loadABIs(subgraph);
|
|
66
|
-
await this.protocolTypeGenerator.generateTypesForABIs(abis);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
await this.generateTypesForDataSourceTemplates(subgraph);
|
|
70
|
-
|
|
71
|
-
// Not all protocols support/have ABIs.
|
|
72
|
-
if (this.protocol.hasABIs()) {
|
|
73
|
-
const templateAbis = await this.protocolTypeGenerator.loadDataSourceTemplateABIs(subgraph);
|
|
74
|
-
await this.protocolTypeGenerator.generateTypesForDataSourceTemplateABIs(templateAbis);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const schema = await this.loadSchema(subgraph);
|
|
78
|
-
await this.generateTypesForSchema(schema);
|
|
79
|
-
|
|
80
|
-
toolbox.print.success('\nTypes generated successfully\n');
|
|
81
|
-
|
|
82
|
-
if (this.options.uncrashable && this.options.uncrashableConfig) {
|
|
83
|
-
await this.generateUncrashableEntities(schema);
|
|
84
|
-
toolbox.print.success('\nUncrashable Helpers generated successfully\n');
|
|
85
|
-
}
|
|
86
|
-
return true;
|
|
87
|
-
} catch (e) {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async generateUncrashableEntities(graphSchema: any) {
|
|
93
|
-
const ast = graphql.parse(graphSchema.document);
|
|
94
|
-
const entityDefinitions = ast['definitions'];
|
|
95
|
-
return await withSpinner(
|
|
96
|
-
`Generate Uncrashable Entity Helpers`,
|
|
97
|
-
`Failed to generate Uncrashable Entity Helpers`,
|
|
98
|
-
`Warnings while generating Uncrashable Entity Helpers`,
|
|
99
|
-
async spinner => {
|
|
100
|
-
uncrashable.run(entityDefinitions, this.options.uncrashableConfig, this.options.outputDir);
|
|
101
|
-
const outputFile = path.join(this.options.outputDir, 'UncrashableEntityHelpers.ts');
|
|
102
|
-
step(spinner, 'Save uncrashable entities to', displayPath(outputFile));
|
|
103
|
-
},
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async loadSubgraph({ quiet } = { quiet: false }) {
|
|
108
|
-
const subgraphLoadOptions = { protocol: this.protocol, skipValidation: false };
|
|
109
|
-
|
|
110
|
-
if (quiet) {
|
|
111
|
-
return this.options.subgraph
|
|
112
|
-
? this.options.subgraph
|
|
113
|
-
: (await Subgraph.load(this.options.subgraphManifest, subgraphLoadOptions)).result;
|
|
114
|
-
}
|
|
115
|
-
const manifestPath = displayPath(this.options.subgraphManifest);
|
|
116
|
-
|
|
117
|
-
return await withSpinner(
|
|
118
|
-
`Load subgraph from ${manifestPath}`,
|
|
119
|
-
`Failed to load subgraph from ${manifestPath}`,
|
|
120
|
-
`Warnings while loading subgraph from ${manifestPath}`,
|
|
121
|
-
async _spinner => {
|
|
122
|
-
return this.options.subgraph
|
|
123
|
-
? this.options.subgraph
|
|
124
|
-
: Subgraph.load(this.options.subgraphManifest, subgraphLoadOptions);
|
|
125
|
-
},
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async loadSchema(subgraph: immutable.Map<any, any>) {
|
|
130
|
-
const maybeRelativePath = subgraph.getIn(['schema', 'file']) as string;
|
|
131
|
-
const absolutePath = path.resolve(this.sourceDir, maybeRelativePath);
|
|
132
|
-
return await withSpinner(
|
|
133
|
-
`Load GraphQL schema from ${displayPath(absolutePath)}`,
|
|
134
|
-
`Failed to load GraphQL schema from ${displayPath(absolutePath)}`,
|
|
135
|
-
`Warnings while loading GraphQL schema from ${displayPath(absolutePath)}`,
|
|
136
|
-
async _spinner => {
|
|
137
|
-
const absolutePath = path.resolve(this.sourceDir, maybeRelativePath);
|
|
138
|
-
return Schema.load(absolutePath);
|
|
139
|
-
},
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
async generateTypesForSchema(schema: any) {
|
|
144
|
-
return await withSpinner(
|
|
145
|
-
`Generate types for GraphQL schema`,
|
|
146
|
-
`Failed to generate types for GraphQL schema`,
|
|
147
|
-
`Warnings while generating types for GraphQL schema`,
|
|
148
|
-
async spinner => {
|
|
149
|
-
// Generate TypeScript module from schema
|
|
150
|
-
const codeGenerator = schema.codeGenerator();
|
|
151
|
-
const code = prettier.format(
|
|
152
|
-
[
|
|
153
|
-
GENERATED_FILE_NOTE,
|
|
154
|
-
...codeGenerator.generateModuleImports(),
|
|
155
|
-
...codeGenerator.generateTypes(),
|
|
156
|
-
].join('\n'),
|
|
157
|
-
{
|
|
158
|
-
parser: 'typescript',
|
|
159
|
-
},
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
const outputFile = path.join(this.options.outputDir, 'schema.ts');
|
|
163
|
-
step(spinner, 'Write types to', displayPath(outputFile));
|
|
164
|
-
await fs.mkdirs(path.dirname(outputFile));
|
|
165
|
-
await fs.writeFile(outputFile, code);
|
|
166
|
-
},
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async generateTypesForDataSourceTemplates(subgraph: immutable.Map<any, any>) {
|
|
171
|
-
return await withSpinner(
|
|
172
|
-
`Generate types for data source templates`,
|
|
173
|
-
`Failed to generate types for data source templates`,
|
|
174
|
-
`Warnings while generating types for data source templates`,
|
|
175
|
-
async spinner => {
|
|
176
|
-
// Combine the generated code for all templates
|
|
177
|
-
const codeSegments = subgraph
|
|
178
|
-
.get('templates', immutable.List())
|
|
179
|
-
.reduce((codeSegments: any, template: any) => {
|
|
180
|
-
step(spinner, 'Generate types for data source template', String(template.get('name')));
|
|
181
|
-
|
|
182
|
-
const codeGenerator = new DataSourceTemplateCodeGenerator(template, this.protocol);
|
|
183
|
-
|
|
184
|
-
// Only generate module imports once, because they are identical for
|
|
185
|
-
// all types generated for data source templates.
|
|
186
|
-
if (codeSegments.isEmpty()) {
|
|
187
|
-
codeSegments = codeSegments.concat(codeGenerator.generateModuleImports());
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return codeSegments.concat(codeGenerator.generateTypes());
|
|
191
|
-
}, immutable.List());
|
|
192
|
-
|
|
193
|
-
if (!codeSegments.isEmpty()) {
|
|
194
|
-
const code = prettier.format([GENERATED_FILE_NOTE, ...codeSegments].join('\n'), {
|
|
195
|
-
parser: 'typescript',
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
const outputFile = path.join(this.options.outputDir, 'templates.ts');
|
|
199
|
-
step(spinner, `Write types for templates to`, displayPath(outputFile));
|
|
200
|
-
await fs.mkdirs(path.dirname(outputFile));
|
|
201
|
-
await fs.writeFile(outputFile, code);
|
|
202
|
-
}
|
|
203
|
-
},
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
async getFilesToWatch() {
|
|
208
|
-
try {
|
|
209
|
-
const files = [];
|
|
210
|
-
const subgraph = await this.loadSubgraph({ quiet: true });
|
|
211
|
-
|
|
212
|
-
// Add the subgraph manifest file
|
|
213
|
-
files.push(this.options.subgraphManifest);
|
|
214
|
-
|
|
215
|
-
// Add the GraphQL schema to the watched files
|
|
216
|
-
files.push(subgraph.getIn(['schema', 'file']));
|
|
217
|
-
|
|
218
|
-
// Add all file paths specified in manifest
|
|
219
|
-
subgraph.get('dataSources').map((dataSource: any) => {
|
|
220
|
-
dataSource.getIn(['mapping', 'abis']).map((abi: any) => {
|
|
221
|
-
files.push(abi.get('file'));
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
// Make paths absolute
|
|
226
|
-
return files.map(file => path.resolve(file));
|
|
227
|
-
} catch (e) {
|
|
228
|
-
throw Error(`Failed to load subgraph: ${e.message}`);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
async watchAndGenerateTypes() {
|
|
233
|
-
const generator = this;
|
|
234
|
-
let spinner: Spinner;
|
|
235
|
-
|
|
236
|
-
// Create watcher and generate types once and then on every change to a watched file
|
|
237
|
-
const watcher = new Watcher({
|
|
238
|
-
onReady: () => (spinner = toolbox.print.spin('Watching subgraph files')),
|
|
239
|
-
onTrigger: async changedFile => {
|
|
240
|
-
if (changedFile !== undefined) {
|
|
241
|
-
spinner.info(`File change detected: ${displayPath(changedFile)}\n`);
|
|
242
|
-
}
|
|
243
|
-
await generator.generateTypes();
|
|
244
|
-
spinner.start();
|
|
245
|
-
},
|
|
246
|
-
onCollectFiles: async () => await generator.getFilesToWatch(),
|
|
247
|
-
onError: error => {
|
|
248
|
-
spinner.stop();
|
|
249
|
-
toolbox.print.error(`${error}\n`);
|
|
250
|
-
spinner.start();
|
|
251
|
-
},
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
// Catch keyboard interrupt: close watcher and exit process
|
|
255
|
-
process.on('SIGINT', () => {
|
|
256
|
-
watcher.close();
|
|
257
|
-
process.exit();
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
try {
|
|
261
|
-
await watcher.watch();
|
|
262
|
-
} catch (e) {
|
|
263
|
-
toolbox.print.error(String(e.message));
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import immutable from 'immutable';
|
|
2
|
-
import Protocol from '../protocols';
|
|
3
|
-
import { ContractCtor } from '../protocols/contract';
|
|
4
|
-
|
|
5
|
-
export const validateContract = (value: string, ProtocolContract: ContractCtor) => {
|
|
6
|
-
const contract = new ProtocolContract(value);
|
|
7
|
-
|
|
8
|
-
const { valid, error } = contract.validate();
|
|
9
|
-
|
|
10
|
-
if (!valid) {
|
|
11
|
-
return {
|
|
12
|
-
valid,
|
|
13
|
-
error: `Contract ${ProtocolContract.identifierName()} is invalid: ${value}\n${error}`,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return { valid, error };
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const validateContractValues = (manifest: immutable.Map<any, any>, protocol: Protocol) => {
|
|
21
|
-
const ProtocolContract = protocol.getContract()!;
|
|
22
|
-
|
|
23
|
-
const fieldName = ProtocolContract.identifierName();
|
|
24
|
-
|
|
25
|
-
return manifest
|
|
26
|
-
.get('dataSources')
|
|
27
|
-
.filter((dataSource: any) => protocol.isValidKindName(dataSource.get('kind')))
|
|
28
|
-
.reduce((errors: any[], dataSource: any, dataSourceIndex: number) => {
|
|
29
|
-
const path = ['dataSources', dataSourceIndex, 'source', fieldName];
|
|
30
|
-
|
|
31
|
-
// No need to validate if the source has no contract field
|
|
32
|
-
if (!dataSource.get('source').has(fieldName)) {
|
|
33
|
-
return errors;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const contractValue = dataSource.getIn(['source', fieldName]);
|
|
37
|
-
|
|
38
|
-
const { valid, error } = validateContract(contractValue, ProtocolContract);
|
|
39
|
-
|
|
40
|
-
// Validate whether the contract is valid for the protocol
|
|
41
|
-
if (valid) {
|
|
42
|
-
return errors;
|
|
43
|
-
}
|
|
44
|
-
return errors.push(
|
|
45
|
-
immutable.fromJS({
|
|
46
|
-
path,
|
|
47
|
-
message: error,
|
|
48
|
-
}),
|
|
49
|
-
);
|
|
50
|
-
}, immutable.List());
|
|
51
|
-
};
|
package/src/validation/index.ts
DELETED