@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/compiler/index.ts
DELETED
|
@@ -1,677 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import fs from 'fs-extra';
|
|
5
|
-
import * as toolbox from 'gluegun';
|
|
6
|
-
import immutable from 'immutable';
|
|
7
|
-
import yaml from 'js-yaml';
|
|
8
|
-
import { Spinner, step, withSpinner } from '../command-helpers/spinner';
|
|
9
|
-
import debug from '../debug';
|
|
10
|
-
import { applyMigrations } from '../migrations';
|
|
11
|
-
import Protocol from '../protocols';
|
|
12
|
-
import Subgraph from '../subgraph';
|
|
13
|
-
import Watcher from '../watcher';
|
|
14
|
-
import * as asc from './asc';
|
|
15
|
-
|
|
16
|
-
const compilerDebug = debug('graph-cli:compiler');
|
|
17
|
-
|
|
18
|
-
interface CompilerOptions {
|
|
19
|
-
ipfs: any;
|
|
20
|
-
subgraphManifest: string;
|
|
21
|
-
outputDir: string;
|
|
22
|
-
outputFormat: string;
|
|
23
|
-
skipMigrations: boolean;
|
|
24
|
-
blockIpfsMethods?: boolean;
|
|
25
|
-
protocol: Protocol;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default class Compiler {
|
|
29
|
-
private ipfs: any;
|
|
30
|
-
private sourceDir: string;
|
|
31
|
-
private blockIpfsMethods?: boolean;
|
|
32
|
-
private libsDirs: string[];
|
|
33
|
-
private globalsFile: string;
|
|
34
|
-
private protocol: Protocol;
|
|
35
|
-
private ABI: any;
|
|
36
|
-
|
|
37
|
-
constructor(private options: CompilerOptions) {
|
|
38
|
-
this.options = options;
|
|
39
|
-
this.ipfs = options.ipfs;
|
|
40
|
-
this.sourceDir = path.dirname(options.subgraphManifest);
|
|
41
|
-
this.blockIpfsMethods = options.blockIpfsMethods;
|
|
42
|
-
this.libsDirs = [];
|
|
43
|
-
|
|
44
|
-
if (options.protocol.name !== 'substreams') {
|
|
45
|
-
for (
|
|
46
|
-
let dir: string | undefined = path.resolve(this.sourceDir);
|
|
47
|
-
// Terminate after the root dir or when we have found node_modules
|
|
48
|
-
dir !== undefined;
|
|
49
|
-
// Continue with the parent directory, terminate after the root dir
|
|
50
|
-
dir = path.dirname(dir) === dir ? undefined : path.dirname(dir)
|
|
51
|
-
) {
|
|
52
|
-
if (fs.existsSync(path.join(dir, 'node_modules'))) {
|
|
53
|
-
this.libsDirs.push(path.join(dir, 'node_modules'));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (this.libsDirs.length === 0) {
|
|
58
|
-
throw Error(`could not locate \`node_modules\` in parent directories of subgraph manifest`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const globalsFile = path.join('@graphprotocol', 'graph-ts', 'global', 'global.ts');
|
|
62
|
-
const globalsLib = this.libsDirs.find(item => {
|
|
63
|
-
return fs.existsSync(path.join(item, globalsFile));
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
if (!globalsLib) {
|
|
67
|
-
throw Error(
|
|
68
|
-
'Could not locate `@graphprotocol/graph-ts` package in parent directories of subgraph manifest.',
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
this.globalsFile = path.join(globalsLib, globalsFile);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// @ts-expect-error assigned or not, we dont care
|
|
76
|
-
if (!this.globalsFile) {
|
|
77
|
-
throw new Error('Globals file is missing.');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
this.protocol = this.options.protocol;
|
|
81
|
-
this.ABI = this.protocol.getABI();
|
|
82
|
-
|
|
83
|
-
process.on('uncaughtException', e => {
|
|
84
|
-
toolbox.print.error(`UNCAUGHT EXCEPTION: ${e}`);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
subgraphDir(parent: string, subgraph: immutable.Map<any, any>) {
|
|
89
|
-
return path.join(parent, subgraph.get('name'));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
displayPath(p: string) {
|
|
93
|
-
return path.relative(process.cwd(), p);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
cacheKeyForFile(filename: string) {
|
|
97
|
-
const hash = crypto.createHash('sha1');
|
|
98
|
-
hash.update(fs.readFileSync(filename));
|
|
99
|
-
return hash.digest('hex');
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async compile() {
|
|
103
|
-
try {
|
|
104
|
-
if (!this.options.skipMigrations) {
|
|
105
|
-
await applyMigrations({
|
|
106
|
-
sourceDir: this.sourceDir,
|
|
107
|
-
manifestFile: this.options.subgraphManifest,
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
const subgraph = await this.loadSubgraph();
|
|
111
|
-
const compiledSubgraph = await this.compileSubgraph(subgraph);
|
|
112
|
-
const localSubgraph = await this.writeSubgraphToOutputDirectory(
|
|
113
|
-
this.options.protocol,
|
|
114
|
-
compiledSubgraph,
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
if (this.ipfs !== undefined) {
|
|
118
|
-
const ipfsHash = await this.uploadSubgraphToIPFS(localSubgraph);
|
|
119
|
-
this.completed(ipfsHash);
|
|
120
|
-
return ipfsHash;
|
|
121
|
-
}
|
|
122
|
-
this.completed(path.join(this.options.outputDir, 'subgraph.yaml'));
|
|
123
|
-
return true;
|
|
124
|
-
} catch (e) {
|
|
125
|
-
toolbox.print.error(e);
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
completed(ipfsHashOrPath: string) {
|
|
131
|
-
toolbox.print.info('');
|
|
132
|
-
toolbox.print.success(`Build completed: ${chalk.blue(ipfsHashOrPath)}`);
|
|
133
|
-
toolbox.print.info('');
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
async loadSubgraph({ quiet } = { quiet: false }) {
|
|
137
|
-
const subgraphLoadOptions = { protocol: this.protocol, skipValidation: false };
|
|
138
|
-
|
|
139
|
-
if (quiet) {
|
|
140
|
-
return (await Subgraph.load(this.options.subgraphManifest, subgraphLoadOptions)).result;
|
|
141
|
-
}
|
|
142
|
-
const manifestPath = this.displayPath(this.options.subgraphManifest);
|
|
143
|
-
|
|
144
|
-
return await withSpinner(
|
|
145
|
-
`Load subgraph from ${manifestPath}`,
|
|
146
|
-
`Failed to load subgraph from ${manifestPath}`,
|
|
147
|
-
`Warnings loading subgraph from ${manifestPath}`,
|
|
148
|
-
async () => {
|
|
149
|
-
return Subgraph.load(this.options.subgraphManifest, subgraphLoadOptions);
|
|
150
|
-
},
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
async getFilesToWatch() {
|
|
155
|
-
try {
|
|
156
|
-
const files = [];
|
|
157
|
-
const subgraph = await this.loadSubgraph({ quiet: true });
|
|
158
|
-
|
|
159
|
-
// Add the subgraph manifest file
|
|
160
|
-
files.push(this.options.subgraphManifest);
|
|
161
|
-
|
|
162
|
-
// Add all file paths specified in manifest
|
|
163
|
-
files.push(path.resolve(subgraph.getIn(['schema', 'file'])));
|
|
164
|
-
subgraph.get('dataSources').map((dataSource: any) => {
|
|
165
|
-
files.push(dataSource.getIn(['mapping', 'file']));
|
|
166
|
-
// Only watch ABI related files if the target protocol has support/need for them.
|
|
167
|
-
if (this.protocol.hasABIs()) {
|
|
168
|
-
dataSource.getIn(['mapping', 'abis']).map((abi: any) => {
|
|
169
|
-
files.push(abi.get('file'));
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
// Make paths absolute
|
|
175
|
-
return files.map(file => path.resolve(file));
|
|
176
|
-
} catch (e) {
|
|
177
|
-
throw Error(`Failed to load subgraph: ${e.message}`);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
async watchAndCompile(onCompiled?: (ipfsHash: string) => void) {
|
|
182
|
-
const compiler = this;
|
|
183
|
-
let spinner: Spinner;
|
|
184
|
-
|
|
185
|
-
// Create watcher and recompile once and then on every change to a watched file
|
|
186
|
-
const watcher = new Watcher({
|
|
187
|
-
onReady: () => (spinner = toolbox.print.spin('Watching subgraph files')),
|
|
188
|
-
onTrigger: async changedFile => {
|
|
189
|
-
if (changedFile !== undefined) {
|
|
190
|
-
spinner.info(`File change detected: ${this.displayPath(changedFile)}\n`);
|
|
191
|
-
}
|
|
192
|
-
const ipfsHash = await compiler.compile();
|
|
193
|
-
onCompiled?.(ipfsHash);
|
|
194
|
-
spinner.start();
|
|
195
|
-
},
|
|
196
|
-
onCollectFiles: async () => await compiler.getFilesToWatch(),
|
|
197
|
-
onError: error => {
|
|
198
|
-
spinner.stop();
|
|
199
|
-
toolbox.print.error(`${error.message}\n`);
|
|
200
|
-
spinner.start();
|
|
201
|
-
},
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
// Catch keyboard interrupt: close watcher and exit process
|
|
205
|
-
process.on('SIGINT', () => {
|
|
206
|
-
watcher.close();
|
|
207
|
-
process.exit();
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
try {
|
|
211
|
-
await watcher.watch();
|
|
212
|
-
} catch (e) {
|
|
213
|
-
toolbox.print.error(String(e.message));
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
_writeSubgraphFile(
|
|
218
|
-
maybeRelativeFile: string,
|
|
219
|
-
data: string | Buffer,
|
|
220
|
-
sourceDir: string,
|
|
221
|
-
targetDir: string,
|
|
222
|
-
spinner: Spinner,
|
|
223
|
-
) {
|
|
224
|
-
const absoluteSourceFile = path.resolve(sourceDir, maybeRelativeFile);
|
|
225
|
-
const relativeSourceFile = path.relative(sourceDir, absoluteSourceFile);
|
|
226
|
-
const targetFile = path.join(targetDir, relativeSourceFile);
|
|
227
|
-
step(spinner, 'Write subgraph file', this.displayPath(targetFile));
|
|
228
|
-
fs.mkdirsSync(path.dirname(targetFile));
|
|
229
|
-
fs.writeFileSync(targetFile, data);
|
|
230
|
-
return targetFile;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
async compileSubgraph(subgraph: any) {
|
|
234
|
-
return await withSpinner(
|
|
235
|
-
`Compile subgraph`,
|
|
236
|
-
`Failed to compile subgraph`,
|
|
237
|
-
`Warnings while compiling subgraph`,
|
|
238
|
-
async spinner => {
|
|
239
|
-
// Cache compiled files so identical input files are only compiled once
|
|
240
|
-
const compiledFiles = new Map();
|
|
241
|
-
|
|
242
|
-
await asc.ready();
|
|
243
|
-
|
|
244
|
-
subgraph = subgraph.update('dataSources', (dataSources: any[]) =>
|
|
245
|
-
dataSources.map((dataSource: any) =>
|
|
246
|
-
dataSource.updateIn(['mapping', 'file'], (mappingPath: string) =>
|
|
247
|
-
this._compileDataSourceMapping(
|
|
248
|
-
this.protocol,
|
|
249
|
-
dataSource,
|
|
250
|
-
mappingPath,
|
|
251
|
-
compiledFiles,
|
|
252
|
-
spinner,
|
|
253
|
-
),
|
|
254
|
-
),
|
|
255
|
-
),
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
subgraph = subgraph.update('templates', (templates: any) =>
|
|
259
|
-
templates === undefined
|
|
260
|
-
? templates
|
|
261
|
-
: templates.map((template: any) =>
|
|
262
|
-
template.updateIn(['mapping', 'file'], (mappingPath: string) =>
|
|
263
|
-
this._compileTemplateMapping(template, mappingPath, compiledFiles, spinner),
|
|
264
|
-
),
|
|
265
|
-
),
|
|
266
|
-
);
|
|
267
|
-
|
|
268
|
-
return subgraph;
|
|
269
|
-
},
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
_compileDataSourceMapping(
|
|
274
|
-
protocol: Protocol,
|
|
275
|
-
dataSource: immutable.Map<any, any>,
|
|
276
|
-
mappingPath: string,
|
|
277
|
-
compiledFiles: Map<any, any>,
|
|
278
|
-
spinner: Spinner,
|
|
279
|
-
) {
|
|
280
|
-
if (protocol.name == 'substreams') {
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
try {
|
|
285
|
-
const dataSourceName = dataSource.getIn(['name']);
|
|
286
|
-
|
|
287
|
-
const baseDir = this.sourceDir;
|
|
288
|
-
const absoluteMappingPath = path.resolve(baseDir, mappingPath);
|
|
289
|
-
const inputFile = path.relative(baseDir, absoluteMappingPath);
|
|
290
|
-
this._validateMappingContent(absoluteMappingPath);
|
|
291
|
-
|
|
292
|
-
// If the file has already been compiled elsewhere, just use that output
|
|
293
|
-
// file and return early
|
|
294
|
-
const inputCacheKey = this.cacheKeyForFile(absoluteMappingPath);
|
|
295
|
-
const alreadyCompiled = compiledFiles.has(inputCacheKey);
|
|
296
|
-
if (alreadyCompiled) {
|
|
297
|
-
const outFile = compiledFiles.get(inputCacheKey);
|
|
298
|
-
step(
|
|
299
|
-
spinner,
|
|
300
|
-
'Compile data source:',
|
|
301
|
-
`${dataSourceName} => ${this.displayPath(outFile)} (already compiled)`,
|
|
302
|
-
);
|
|
303
|
-
return outFile;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
const outFile = path.resolve(
|
|
307
|
-
this.subgraphDir(this.options.outputDir, dataSource),
|
|
308
|
-
this.options.outputFormat == 'wasm' ? `${dataSourceName}.wasm` : `${dataSourceName}.wast`,
|
|
309
|
-
);
|
|
310
|
-
|
|
311
|
-
step(spinner, 'Compile data source:', `${dataSourceName} => ${this.displayPath(outFile)}`);
|
|
312
|
-
|
|
313
|
-
const outputFile = path.relative(baseDir, outFile);
|
|
314
|
-
|
|
315
|
-
// Create output directory
|
|
316
|
-
fs.mkdirsSync(path.dirname(outFile));
|
|
317
|
-
|
|
318
|
-
const libs = this.libsDirs.join(',');
|
|
319
|
-
const global = path.relative(baseDir, this.globalsFile);
|
|
320
|
-
|
|
321
|
-
asc.compile({
|
|
322
|
-
inputFile,
|
|
323
|
-
global,
|
|
324
|
-
baseDir,
|
|
325
|
-
libs,
|
|
326
|
-
outputFile,
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
// Remember the output file to avoid compiling the same file again
|
|
330
|
-
compiledFiles.set(inputCacheKey, outFile);
|
|
331
|
-
|
|
332
|
-
return outFile;
|
|
333
|
-
} catch (e) {
|
|
334
|
-
throw Error(`Failed to compile data source mapping: ${e.message}`);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
_compileTemplateMapping(
|
|
339
|
-
template: immutable.Collection<any, any>,
|
|
340
|
-
mappingPath: string,
|
|
341
|
-
compiledFiles: Map<any, any>,
|
|
342
|
-
spinner: Spinner,
|
|
343
|
-
) {
|
|
344
|
-
try {
|
|
345
|
-
const templateName = template.get('name');
|
|
346
|
-
|
|
347
|
-
const baseDir = this.sourceDir;
|
|
348
|
-
const absoluteMappingPath = path.resolve(baseDir, mappingPath);
|
|
349
|
-
const inputFile = path.relative(baseDir, absoluteMappingPath);
|
|
350
|
-
this._validateMappingContent(absoluteMappingPath);
|
|
351
|
-
|
|
352
|
-
// If the file has already been compiled elsewhere, just use that output
|
|
353
|
-
// file and return early
|
|
354
|
-
const inputCacheKey = this.cacheKeyForFile(absoluteMappingPath);
|
|
355
|
-
const alreadyCompiled = compiledFiles.has(inputCacheKey);
|
|
356
|
-
if (alreadyCompiled) {
|
|
357
|
-
const outFile = compiledFiles.get(inputCacheKey);
|
|
358
|
-
step(
|
|
359
|
-
spinner,
|
|
360
|
-
'Compile data source template:',
|
|
361
|
-
`${templateName} => ${this.displayPath(outFile)} (already compiled)`,
|
|
362
|
-
);
|
|
363
|
-
return outFile;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
const outFile = path.resolve(
|
|
367
|
-
this.options.outputDir,
|
|
368
|
-
'templates',
|
|
369
|
-
templateName,
|
|
370
|
-
this.options.outputFormat == 'wasm' ? `${templateName}.wasm` : `${templateName}.wast`,
|
|
371
|
-
);
|
|
372
|
-
|
|
373
|
-
step(
|
|
374
|
-
spinner,
|
|
375
|
-
'Compile data source template:',
|
|
376
|
-
`${templateName} => ${this.displayPath(outFile)}`,
|
|
377
|
-
);
|
|
378
|
-
|
|
379
|
-
const outputFile = path.relative(baseDir, outFile);
|
|
380
|
-
|
|
381
|
-
// Create output directory
|
|
382
|
-
fs.mkdirsSync(path.dirname(outFile));
|
|
383
|
-
|
|
384
|
-
const libs = this.libsDirs.join(',');
|
|
385
|
-
const global = path.relative(baseDir, this.globalsFile);
|
|
386
|
-
|
|
387
|
-
asc.compile({
|
|
388
|
-
inputFile,
|
|
389
|
-
global,
|
|
390
|
-
baseDir,
|
|
391
|
-
libs,
|
|
392
|
-
outputFile,
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
// Remember the output file to avoid compiling the same file again
|
|
396
|
-
compiledFiles.set(inputCacheKey, outFile);
|
|
397
|
-
|
|
398
|
-
return outFile;
|
|
399
|
-
} catch (e) {
|
|
400
|
-
throw Error(`Failed to compile data source template: ${e.message}`);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
_validateMappingContent(filePath: string) {
|
|
405
|
-
const data = fs.readFileSync(filePath);
|
|
406
|
-
if (this.blockIpfsMethods && (data.includes('ipfs.cat') || data.includes('ipfs.map'))) {
|
|
407
|
-
throw Error(`
|
|
408
|
-
Subgraph Studio does not support mappings with ipfs methods.
|
|
409
|
-
Please remove all instances of ipfs.cat and ipfs.map from
|
|
410
|
-
${filePath}
|
|
411
|
-
`);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
async writeSubgraphToOutputDirectory(protocol: Protocol, subgraph: immutable.Map<any, any>) {
|
|
416
|
-
const displayDir = `${this.displayPath(this.options.outputDir)}${toolbox.filesystem.separator}`;
|
|
417
|
-
|
|
418
|
-
return await withSpinner(
|
|
419
|
-
`Write compiled subgraph to ${displayDir}`,
|
|
420
|
-
`Failed to write compiled subgraph to ${displayDir}`,
|
|
421
|
-
`Warnings while writing compiled subgraph to ${displayDir}`,
|
|
422
|
-
async spinner => {
|
|
423
|
-
// Copy schema and update its path
|
|
424
|
-
subgraph = subgraph.updateIn(['schema', 'file'], schemaFile => {
|
|
425
|
-
const schemaFilePath = path.resolve(this.sourceDir, schemaFile as string);
|
|
426
|
-
const schemaFileName = path.basename(schemaFile as string);
|
|
427
|
-
const targetFile = path.resolve(this.options.outputDir, schemaFileName);
|
|
428
|
-
step(spinner, 'Copy schema file', this.displayPath(targetFile));
|
|
429
|
-
fs.copyFileSync(schemaFilePath, targetFile);
|
|
430
|
-
return path.relative(this.options.outputDir, targetFile);
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
// Copy data source files and update their paths
|
|
434
|
-
subgraph = subgraph.update('dataSources', (dataSources: any[]) =>
|
|
435
|
-
dataSources.map(dataSource => {
|
|
436
|
-
let updatedDataSource = dataSource;
|
|
437
|
-
|
|
438
|
-
if (this.protocol.hasABIs()) {
|
|
439
|
-
updatedDataSource = updatedDataSource
|
|
440
|
-
// Write data source ABIs to the output directory
|
|
441
|
-
.updateIn(['mapping', 'abis'], (abis: any[]) =>
|
|
442
|
-
abis.map((abi: any) =>
|
|
443
|
-
abi.update('file', (abiFile: string) => {
|
|
444
|
-
abiFile = path.resolve(this.sourceDir, abiFile);
|
|
445
|
-
const abiData = this.ABI.load(abi.get('name'), abiFile);
|
|
446
|
-
return path.relative(
|
|
447
|
-
this.options.outputDir,
|
|
448
|
-
this._writeSubgraphFile(
|
|
449
|
-
abiFile,
|
|
450
|
-
JSON.stringify(abiData.data.toJS(), null, 2),
|
|
451
|
-
this.sourceDir,
|
|
452
|
-
this.subgraphDir(this.options.outputDir, dataSource),
|
|
453
|
-
spinner,
|
|
454
|
-
),
|
|
455
|
-
);
|
|
456
|
-
}),
|
|
457
|
-
),
|
|
458
|
-
);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
if (protocol.name == 'substreams') {
|
|
462
|
-
updatedDataSource = updatedDataSource
|
|
463
|
-
// Write data source ABIs to the output directory
|
|
464
|
-
.updateIn(['source', 'package'], (substreamsPackage: any) =>
|
|
465
|
-
substreamsPackage.update('file', (packageFile: string) => {
|
|
466
|
-
packageFile = path.resolve(this.sourceDir, packageFile);
|
|
467
|
-
const packageContent = fs.readFileSync(packageFile);
|
|
468
|
-
|
|
469
|
-
return path.relative(
|
|
470
|
-
this.options.outputDir,
|
|
471
|
-
this._writeSubgraphFile(
|
|
472
|
-
packageFile,
|
|
473
|
-
packageContent,
|
|
474
|
-
this.sourceDir,
|
|
475
|
-
this.subgraphDir(this.options.outputDir, dataSource),
|
|
476
|
-
spinner,
|
|
477
|
-
),
|
|
478
|
-
);
|
|
479
|
-
}),
|
|
480
|
-
);
|
|
481
|
-
|
|
482
|
-
return updatedDataSource;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
// The mapping file is already being written to the output
|
|
486
|
-
// directory by the AssemblyScript compiler
|
|
487
|
-
return updatedDataSource.updateIn(['mapping', 'file'], (mappingFile: string) =>
|
|
488
|
-
path.relative(this.options.outputDir, path.resolve(this.sourceDir, mappingFile)),
|
|
489
|
-
);
|
|
490
|
-
}),
|
|
491
|
-
);
|
|
492
|
-
|
|
493
|
-
// Copy template files and update their paths
|
|
494
|
-
subgraph = subgraph.update('templates', templates =>
|
|
495
|
-
templates === undefined
|
|
496
|
-
? templates
|
|
497
|
-
: templates.map((template: any) => {
|
|
498
|
-
let updatedTemplate = template;
|
|
499
|
-
|
|
500
|
-
if (this.protocol.hasABIs()) {
|
|
501
|
-
updatedTemplate = updatedTemplate
|
|
502
|
-
// Write template ABIs to the output directory
|
|
503
|
-
.updateIn(['mapping', 'abis'], (abis: any[]) =>
|
|
504
|
-
abis.map(abi =>
|
|
505
|
-
abi.update('file', (abiFile: string) => {
|
|
506
|
-
abiFile = path.resolve(this.sourceDir, abiFile);
|
|
507
|
-
const abiData = this.ABI.load(abi.get('name'), abiFile);
|
|
508
|
-
return path.relative(
|
|
509
|
-
this.options.outputDir,
|
|
510
|
-
this._writeSubgraphFile(
|
|
511
|
-
abiFile,
|
|
512
|
-
JSON.stringify(abiData.data.toJS(), null, 2),
|
|
513
|
-
this.sourceDir,
|
|
514
|
-
this.subgraphDir(this.options.outputDir, template),
|
|
515
|
-
spinner,
|
|
516
|
-
),
|
|
517
|
-
);
|
|
518
|
-
}),
|
|
519
|
-
),
|
|
520
|
-
);
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
// The mapping file is already being written to the output
|
|
524
|
-
// directory by the AssemblyScript compiler
|
|
525
|
-
return updatedTemplate.updateIn(['mapping', 'file'], (mappingFile: string) =>
|
|
526
|
-
path.relative(this.options.outputDir, path.resolve(this.sourceDir, mappingFile)),
|
|
527
|
-
);
|
|
528
|
-
}),
|
|
529
|
-
);
|
|
530
|
-
|
|
531
|
-
// Write the subgraph manifest itself
|
|
532
|
-
const outputFilename = path.join(this.options.outputDir, 'subgraph.yaml');
|
|
533
|
-
step(spinner, 'Write subgraph manifest', this.displayPath(outputFilename));
|
|
534
|
-
await Subgraph.write(subgraph, outputFilename);
|
|
535
|
-
|
|
536
|
-
return subgraph;
|
|
537
|
-
},
|
|
538
|
-
);
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
async uploadSubgraphToIPFS(subgraph: immutable.Map<any, any>) {
|
|
542
|
-
return withSpinner(
|
|
543
|
-
`Upload subgraph to IPFS`,
|
|
544
|
-
`Failed to upload subgraph to IPFS`,
|
|
545
|
-
`Warnings while uploading subgraph to IPFS`,
|
|
546
|
-
async spinner => {
|
|
547
|
-
// Cache uploaded IPFS files so identical files are only uploaded once
|
|
548
|
-
const uploadedFiles = new Map();
|
|
549
|
-
|
|
550
|
-
// Collect all source (path -> hash) updates to apply them later
|
|
551
|
-
const updates = [];
|
|
552
|
-
|
|
553
|
-
// Upload the schema to IPFS
|
|
554
|
-
updates.push({
|
|
555
|
-
keyPath: ['schema', 'file'],
|
|
556
|
-
value: await this._uploadFileToIPFS(
|
|
557
|
-
subgraph.getIn(['schema', 'file']) as string,
|
|
558
|
-
uploadedFiles,
|
|
559
|
-
spinner,
|
|
560
|
-
),
|
|
561
|
-
});
|
|
562
|
-
|
|
563
|
-
if (this.protocol.hasABIs()) {
|
|
564
|
-
for (const [i, dataSource] of subgraph.get('dataSources').entries()) {
|
|
565
|
-
for (const [j, abi] of dataSource.getIn(['mapping', 'abis']).entries()) {
|
|
566
|
-
updates.push({
|
|
567
|
-
keyPath: ['dataSources', i, 'mapping', 'abis', j, 'file'],
|
|
568
|
-
value: await this._uploadFileToIPFS(abi.get('file'), uploadedFiles, spinner),
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
// Upload all mappings
|
|
575
|
-
if (this.protocol.name !== 'substreams') {
|
|
576
|
-
for (const [i, dataSource] of subgraph.get('dataSources').entries()) {
|
|
577
|
-
updates.push({
|
|
578
|
-
keyPath: ['dataSources', i, 'mapping', 'file'],
|
|
579
|
-
value: await this._uploadFileToIPFS(
|
|
580
|
-
dataSource.getIn(['mapping', 'file']),
|
|
581
|
-
uploadedFiles,
|
|
582
|
-
spinner,
|
|
583
|
-
),
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
} else {
|
|
587
|
-
for (const [i, dataSource] of subgraph.get('dataSources').entries()) {
|
|
588
|
-
updates.push({
|
|
589
|
-
keyPath: ['dataSources', i, 'source', 'package', 'file'],
|
|
590
|
-
value: await this._uploadFileToIPFS(
|
|
591
|
-
dataSource.getIn(['source', 'package', 'file']),
|
|
592
|
-
uploadedFiles,
|
|
593
|
-
spinner,
|
|
594
|
-
),
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
for (const [i, template] of subgraph.get('templates', immutable.List()).entries()) {
|
|
600
|
-
if (this.protocol.hasABIs()) {
|
|
601
|
-
for (const [j, abi] of template.getIn(['mapping', 'abis']).entries()) {
|
|
602
|
-
updates.push({
|
|
603
|
-
keyPath: ['templates', i, 'mapping', 'abis', j, 'file'],
|
|
604
|
-
value: await this._uploadFileToIPFS(abi.get('file'), uploadedFiles, spinner),
|
|
605
|
-
});
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
updates.push({
|
|
610
|
-
keyPath: ['templates', i, 'mapping', 'file'],
|
|
611
|
-
value: await this._uploadFileToIPFS(
|
|
612
|
-
template.getIn(['mapping', 'file']),
|
|
613
|
-
uploadedFiles,
|
|
614
|
-
spinner,
|
|
615
|
-
),
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
// Apply all updates to the subgraph
|
|
620
|
-
for (const update of updates) {
|
|
621
|
-
subgraph = subgraph.setIn(update.keyPath, update.value);
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
// Upload the subgraph itself
|
|
625
|
-
return await this._uploadSubgraphDefinitionToIPFS(subgraph);
|
|
626
|
-
},
|
|
627
|
-
);
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
async _uploadFileToIPFS(
|
|
631
|
-
maybeRelativeFile: string,
|
|
632
|
-
uploadedFiles: Map<any, any>,
|
|
633
|
-
spinner: Spinner,
|
|
634
|
-
) {
|
|
635
|
-
compilerDebug(
|
|
636
|
-
'Resolving IPFS file "%s" from output dir "%s"',
|
|
637
|
-
maybeRelativeFile,
|
|
638
|
-
this.options.outputDir,
|
|
639
|
-
);
|
|
640
|
-
const absoluteFile = path.resolve(this.options.outputDir, maybeRelativeFile);
|
|
641
|
-
step(spinner, 'Add file to IPFS', this.displayPath(absoluteFile));
|
|
642
|
-
|
|
643
|
-
const uploadCacheKey = this.cacheKeyForFile(absoluteFile);
|
|
644
|
-
const alreadyUploaded = uploadedFiles.has(uploadCacheKey);
|
|
645
|
-
|
|
646
|
-
if (!alreadyUploaded) {
|
|
647
|
-
// @ts-expect-error Buffer.from with Buffer data can indeed accept utf-8
|
|
648
|
-
const content = Buffer.from(await fs.readFile(absoluteFile), 'utf-8');
|
|
649
|
-
const hash = await this._uploadToIPFS({
|
|
650
|
-
path: path.relative(this.options.outputDir, absoluteFile),
|
|
651
|
-
content,
|
|
652
|
-
});
|
|
653
|
-
|
|
654
|
-
uploadedFiles.set(uploadCacheKey, hash);
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
const hash = uploadedFiles.get(uploadCacheKey);
|
|
658
|
-
step(spinner, ' ..', `${hash}${alreadyUploaded ? ' (already uploaded)' : ''}`);
|
|
659
|
-
return immutable.fromJS({ '/': `/ipfs/${hash}` });
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
async _uploadSubgraphDefinitionToIPFS(subgraph: immutable.Map<any, any>) {
|
|
663
|
-
const str = yaml.safeDump(subgraph.toJS(), { noRefs: true, sortKeys: true });
|
|
664
|
-
const file = { path: 'subgraph.yaml', content: Buffer.from(str, 'utf-8') };
|
|
665
|
-
return await this._uploadToIPFS(file);
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
async _uploadToIPFS(file: { path: string; content: Buffer }) {
|
|
669
|
-
try {
|
|
670
|
-
const hash = (await this.ipfs.add([file]))[0].hash;
|
|
671
|
-
await this.ipfs.pin.add(hash);
|
|
672
|
-
return hash;
|
|
673
|
-
} catch (e) {
|
|
674
|
-
throw Error(`Failed to upload file to IPFS: ${e.message}`);
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
}
|
package/src/debug.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import debugFactory from 'debug';
|
|
2
|
-
|
|
3
|
-
debugFactory.formatters.L = immutableList => {
|
|
4
|
-
return JSON.stringify(immutableList);
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
debugFactory.formatters.M = immutableMap => {
|
|
8
|
-
if (immutableMap.toMap != null) {
|
|
9
|
-
return JSON.stringify(immutableMap.toMap());
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return immutableMap;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export default debugFactory;
|