@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
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import immutable from 'immutable';
|
|
2
|
-
import { loadManifest } from '../migrations/util/load-manifest';
|
|
3
|
-
import Protocol from '../protocols';
|
|
4
|
-
|
|
5
|
-
// Loads manifest from file path and returns all:
|
|
6
|
-
// - data sources
|
|
7
|
-
// - templates
|
|
8
|
-
// In a single list.
|
|
9
|
-
export const fromFilePath = async (manifestPath: string) => {
|
|
10
|
-
const { dataSources = [], templates = [] } = await loadManifest(manifestPath);
|
|
11
|
-
|
|
12
|
-
return dataSources.concat(templates);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const extractDataSourceByType = (
|
|
16
|
-
manifest: immutable.Map<any, any>,
|
|
17
|
-
dataSourceType: string,
|
|
18
|
-
protocol: Protocol,
|
|
19
|
-
) =>
|
|
20
|
-
manifest
|
|
21
|
-
.get(dataSourceType, immutable.List())
|
|
22
|
-
.reduce(
|
|
23
|
-
(dataSources: any[], dataSource: any, dataSourceIndex: number) =>
|
|
24
|
-
protocol.isValidKindName(dataSource.get('kind'))
|
|
25
|
-
? dataSources.push(immutable.Map({ path: [dataSourceType, dataSourceIndex], dataSource }))
|
|
26
|
-
: dataSources,
|
|
27
|
-
immutable.List(),
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
// Extracts data sources and templates from a immutable manifest data structure
|
|
31
|
-
export const fromManifest = (manifest: immutable.Map<any, any>, protocol: Protocol) => {
|
|
32
|
-
const dataSources = extractDataSourceByType(manifest, 'dataSources', protocol);
|
|
33
|
-
const templates = extractDataSourceByType(manifest, 'templates', protocol);
|
|
34
|
-
|
|
35
|
-
return dataSources.concat(templates);
|
|
36
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
// Workaround for https://github.com/infinitered/gluegun/pull/464.
|
|
2
|
-
//
|
|
3
|
-
// There is currently no way in Gluegun to define command-line options
|
|
4
|
-
// that take no arguments (like `--watch`). As a consequence, boolean
|
|
5
|
-
// options like `--watch` will consume the immediately following argument,
|
|
6
|
-
// leading to confusing behavior.
|
|
7
|
-
//
|
|
8
|
-
// E.g. `graph deploy --watch subgraph/name
|
|
9
|
-
//
|
|
10
|
-
// Will result in
|
|
11
|
-
// ```
|
|
12
|
-
// toolbox.parameters.options === { watch: 'subgraph/name' }
|
|
13
|
-
// toolbox.parameters.first === undefined
|
|
14
|
-
// toolbox.parameters.array === []
|
|
15
|
-
// ```
|
|
16
|
-
// where what we really want is
|
|
17
|
-
// ```
|
|
18
|
-
// toolbox.parameters.options === { watch: true }
|
|
19
|
-
// toolbox.parameters.first = 'subgraph/name'
|
|
20
|
-
// toolbox.parameters.array = ['subgraph/name']
|
|
21
|
-
// ```
|
|
22
|
-
//
|
|
23
|
-
// The `fixParameters` function checks if any of the provided boolean
|
|
24
|
-
// options has a string value; if so, it pushes it to the front of the
|
|
25
|
-
// parameters array and returns the result of that.
|
|
26
|
-
|
|
27
|
-
import { GluegunParameters } from 'gluegun';
|
|
28
|
-
|
|
29
|
-
export const fixParameters = (
|
|
30
|
-
parameters: GluegunParameters,
|
|
31
|
-
booleanOptions: Record<string, string>,
|
|
32
|
-
) => {
|
|
33
|
-
const unexpectedStringOptions = Object.keys(booleanOptions)
|
|
34
|
-
.filter(key => typeof booleanOptions[key] === 'string')
|
|
35
|
-
.map(key => ({ key, value: booleanOptions[key] }));
|
|
36
|
-
|
|
37
|
-
const optionNames = unexpectedStringOptions
|
|
38
|
-
.map(({ key }) => `--` + key.replace(/([A-Z])/, '-$1').toLowerCase())
|
|
39
|
-
.join(', ');
|
|
40
|
-
|
|
41
|
-
if (unexpectedStringOptions.length > 1) {
|
|
42
|
-
throw new Error(
|
|
43
|
-
`Unexpected value provided for one or more of ${optionNames}. See --help for more information.`,
|
|
44
|
-
);
|
|
45
|
-
} else if (unexpectedStringOptions.length == 1) {
|
|
46
|
-
const params = parameters.array;
|
|
47
|
-
params!.unshift(unexpectedStringOptions[0].value);
|
|
48
|
-
return params!;
|
|
49
|
-
} else {
|
|
50
|
-
return parameters.array!;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
declare module 'ipfs-http-client';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { print } from 'gluegun';
|
|
2
|
-
import jayson from 'jayson';
|
|
3
|
-
|
|
4
|
-
export function createJsonRpcClient(url: URL): jayson.Client | null {
|
|
5
|
-
const params = {
|
|
6
|
-
host: url.hostname,
|
|
7
|
-
port: url.port,
|
|
8
|
-
path: url.pathname,
|
|
9
|
-
// username may be empty
|
|
10
|
-
auth: url.password ? `${url.username}:${url.password}` : undefined,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
if (url.protocol === 'https:') {
|
|
14
|
-
return jayson.Client.https(params);
|
|
15
|
-
}
|
|
16
|
-
if (url.protocol === 'http:') {
|
|
17
|
-
return jayson.Client.http(params);
|
|
18
|
-
}
|
|
19
|
-
print.error(`Unsupported protocol: ${url.protocol.substring(0, url.protocol.length - 1)}`);
|
|
20
|
-
print.error('The Graph Node URL must be of the following format: http(s)://host[:port]/[path]');
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import * as toolbox from 'gluegun';
|
|
3
|
-
import yaml from 'yaml';
|
|
4
|
-
import { initNetworksConfig, updateSubgraphNetwork } from './network';
|
|
5
|
-
|
|
6
|
-
const SUBGRAPH_PATH_BASE = path.join(
|
|
7
|
-
__dirname,
|
|
8
|
-
'..',
|
|
9
|
-
'..',
|
|
10
|
-
'..',
|
|
11
|
-
'..',
|
|
12
|
-
'examples',
|
|
13
|
-
'example-subgraph',
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
describe('initNetworksConfig', () => {
|
|
17
|
-
beforeAll(async () => {
|
|
18
|
-
await initNetworksConfig(toolbox, SUBGRAPH_PATH_BASE, 'address');
|
|
19
|
-
});
|
|
20
|
-
afterAll(async () => {
|
|
21
|
-
toolbox.filesystem.remove(`${SUBGRAPH_PATH_BASE}/networks.json`);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('generates networks.json from subgraph.yaml', () => {
|
|
25
|
-
expect(toolbox.filesystem.exists(`${SUBGRAPH_PATH_BASE}/networks.json`)).toBe('file');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('Populates the networks.json file with the data from subgraph.yaml', async () => {
|
|
29
|
-
const networksStr = toolbox.filesystem.read(`${SUBGRAPH_PATH_BASE}/networks.json`);
|
|
30
|
-
const networks = JSON.parse(networksStr!);
|
|
31
|
-
|
|
32
|
-
const expected = {
|
|
33
|
-
mainnet: {
|
|
34
|
-
ExampleSubgraph: { address: '0x22843e74c59580b3eaf6c233fa67d8b7c561a835' },
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
expect(networks).toStrictEqual(expected);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('updateSubgraphNetwork', () => {
|
|
43
|
-
beforeAll(async () => {
|
|
44
|
-
const content = {
|
|
45
|
-
optimism: {
|
|
46
|
-
ExampleSubgraph: { address: '0x12345...' },
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
toolbox.filesystem.write(`${SUBGRAPH_PATH_BASE}/networks.json`, content);
|
|
51
|
-
toolbox.filesystem.copy(
|
|
52
|
-
`${SUBGRAPH_PATH_BASE}/subgraph.yaml`,
|
|
53
|
-
`${SUBGRAPH_PATH_BASE}/subgraph_copy.yaml`,
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
afterAll(async () => {
|
|
58
|
-
toolbox.filesystem.remove(`${SUBGRAPH_PATH_BASE}/networks.json`);
|
|
59
|
-
toolbox.filesystem.remove(`${SUBGRAPH_PATH_BASE}/subgraph_copy.yaml`);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('Updates subgraph.yaml', async () => {
|
|
63
|
-
const manifest = `${SUBGRAPH_PATH_BASE}/subgraph_copy.yaml`;
|
|
64
|
-
const networksFie = `${SUBGRAPH_PATH_BASE}/networks.json`;
|
|
65
|
-
let subgraph = toolbox.filesystem.read(manifest);
|
|
66
|
-
let subgraphObj = yaml.parse(subgraph!);
|
|
67
|
-
|
|
68
|
-
let network = subgraphObj.dataSources[0].network;
|
|
69
|
-
let address = subgraphObj.dataSources[0].source.address;
|
|
70
|
-
|
|
71
|
-
expect(network).toBe('mainnet');
|
|
72
|
-
expect(address).toBe('0x22843e74c59580b3eaf6c233fa67d8b7c561a835');
|
|
73
|
-
|
|
74
|
-
await updateSubgraphNetwork(toolbox, manifest, 'optimism', networksFie, 'address');
|
|
75
|
-
|
|
76
|
-
subgraph = toolbox.filesystem.read(manifest);
|
|
77
|
-
subgraphObj = yaml.parse(subgraph!);
|
|
78
|
-
|
|
79
|
-
network = subgraphObj.dataSources[0].network;
|
|
80
|
-
address = subgraphObj.dataSources[0].source.address;
|
|
81
|
-
|
|
82
|
-
expect(network).toBe('optimism');
|
|
83
|
-
expect(address).toBe('0x12345...');
|
|
84
|
-
});
|
|
85
|
-
});
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { GluegunFilesystem, GluegunPatching } from 'gluegun';
|
|
3
|
-
import yaml from 'yaml';
|
|
4
|
-
import { step, withSpinner } from './spinner';
|
|
5
|
-
|
|
6
|
-
export const updateSubgraphNetwork = async (
|
|
7
|
-
toolbox: { filesystem: GluegunFilesystem; patching: GluegunPatching },
|
|
8
|
-
manifest: any,
|
|
9
|
-
network: string,
|
|
10
|
-
networksFile: string,
|
|
11
|
-
identifierName: string,
|
|
12
|
-
) =>
|
|
13
|
-
await withSpinner(
|
|
14
|
-
`Update sources network`,
|
|
15
|
-
`Failed to update sources network`,
|
|
16
|
-
`Warnings while updating sources network`,
|
|
17
|
-
async spinner => {
|
|
18
|
-
step(spinner, `Reading networks config`);
|
|
19
|
-
const allNetworks = await toolbox.filesystem.read(networksFile, 'json');
|
|
20
|
-
const networkConfig = allNetworks[network];
|
|
21
|
-
|
|
22
|
-
// Exit if the network passed with --network does not exits in networks.json
|
|
23
|
-
if (!networkConfig) {
|
|
24
|
-
throw new Error(`Network '${network}' was not found in '${networksFile}'`);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
await toolbox.patching.update(manifest, content => {
|
|
28
|
-
const subgraph = yaml.parse(content);
|
|
29
|
-
const networkSources = Object.keys(networkConfig);
|
|
30
|
-
const subgraphSources = subgraph.dataSources.map((value: any) => value.name);
|
|
31
|
-
|
|
32
|
-
// Update the dataSources network config
|
|
33
|
-
subgraph.dataSources = subgraph.dataSources.map((source: any) => {
|
|
34
|
-
if (!networkSources.includes(source.name)) {
|
|
35
|
-
throw new Error(
|
|
36
|
-
`'${source.name}' was not found in the '${network}' configuration, please update!`,
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (hasChanges(identifierName, network, networkConfig[source.name], source)) {
|
|
41
|
-
step(spinner, `Update '${source.name}' network configuration`);
|
|
42
|
-
source.network = network;
|
|
43
|
-
source.source = source.source.abi ? { abi: source.source.abi } : {};
|
|
44
|
-
Object.assign(source.source, networkConfig[source.name]);
|
|
45
|
-
} else {
|
|
46
|
-
step(spinner, `Skip '${source.name}': No changes to network configuration`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return source;
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// All data sources shoud be on the same network,
|
|
53
|
-
// so we have to update the network of all templates too.
|
|
54
|
-
subgraph.templates &&= subgraph.templates.map((template: any) => ({
|
|
55
|
-
...template,
|
|
56
|
-
network,
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
|
-
const unsusedSources = networkSources.filter(x => !subgraphSources.includes(x));
|
|
60
|
-
|
|
61
|
-
unsusedSources.forEach(source => {
|
|
62
|
-
step(spinner, `dataSource '${source}' from '${networksFile}' not found in ${manifest}`);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const yaml_doc = new yaml.Document();
|
|
66
|
-
yaml_doc.contents = subgraph;
|
|
67
|
-
return yaml_doc.toString();
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
export const initNetworksConfig = async (
|
|
73
|
-
toolbox: { filesystem: GluegunFilesystem },
|
|
74
|
-
directory: string,
|
|
75
|
-
identifierName: string,
|
|
76
|
-
) =>
|
|
77
|
-
await withSpinner(
|
|
78
|
-
`Initialize networks config`,
|
|
79
|
-
`Failed to initialize networks config`,
|
|
80
|
-
`Warnings while initializing networks config`,
|
|
81
|
-
async () => {
|
|
82
|
-
const subgraphStr = toolbox.filesystem.read(path.join(directory, 'subgraph.yaml'));
|
|
83
|
-
const subgraph = yaml.parse(subgraphStr!);
|
|
84
|
-
|
|
85
|
-
const networks = subgraph.dataSources.reduce(
|
|
86
|
-
(acc: any, source: any) =>
|
|
87
|
-
Object.assign(acc, {
|
|
88
|
-
[source.network]: {
|
|
89
|
-
[source.name]: {
|
|
90
|
-
[identifierName]: source.source.address,
|
|
91
|
-
startBlock: source.source.startBlock,
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
}),
|
|
95
|
-
{},
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
toolbox.filesystem.write(`${directory}/networks.json`, networks);
|
|
99
|
-
|
|
100
|
-
return true;
|
|
101
|
-
},
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
// Checks if any network attribute has been changed
|
|
105
|
-
function hasChanges(identifierName: string, network: string, networkConfig: any, dataSource: any) {
|
|
106
|
-
const networkChanged = dataSource.network !== network;
|
|
107
|
-
|
|
108
|
-
// Return directly if the network is different
|
|
109
|
-
if (networkChanged) return networkChanged;
|
|
110
|
-
|
|
111
|
-
const addressChanged = networkConfig[identifierName] !== dataSource.source[identifierName];
|
|
112
|
-
|
|
113
|
-
const startBlockChanged = networkConfig.startBlock !== dataSource.source.startBlock;
|
|
114
|
-
|
|
115
|
-
return networkChanged || addressChanged || startBlockChanged;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export const updateNetworksFile = async (
|
|
119
|
-
toolbox: { patching: GluegunPatching },
|
|
120
|
-
network: string,
|
|
121
|
-
dataSource: any,
|
|
122
|
-
address: string,
|
|
123
|
-
networksFile: string,
|
|
124
|
-
) => {
|
|
125
|
-
await toolbox.patching.update(networksFile, config => {
|
|
126
|
-
if (Object.keys(config).includes(network)) {
|
|
127
|
-
Object.assign(config[network], { [dataSource]: { address } });
|
|
128
|
-
} else {
|
|
129
|
-
Object.assign(config, { [network]: { [dataSource]: { address } } });
|
|
130
|
-
}
|
|
131
|
-
return config;
|
|
132
|
-
});
|
|
133
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { URL } from 'url';
|
|
2
|
-
import { print } from 'gluegun';
|
|
3
|
-
|
|
4
|
-
const SUBGRAPH_STUDIO_URL = 'https://api.studio.thegraph.com/deploy/';
|
|
5
|
-
const HOSTED_SERVICE_URL = 'https://api.thegraph.com/deploy/';
|
|
6
|
-
|
|
7
|
-
export const validateNodeUrl = (node: string) => new URL(node);
|
|
8
|
-
|
|
9
|
-
export const normalizeNodeUrl = (node: string) => new URL(node).toString();
|
|
10
|
-
|
|
11
|
-
export function chooseNodeUrl({
|
|
12
|
-
product,
|
|
13
|
-
studio,
|
|
14
|
-
node,
|
|
15
|
-
allowSimpleName,
|
|
16
|
-
}: {
|
|
17
|
-
product: string;
|
|
18
|
-
studio: string;
|
|
19
|
-
node?: string;
|
|
20
|
-
allowSimpleName?: boolean;
|
|
21
|
-
}) {
|
|
22
|
-
if (node) {
|
|
23
|
-
try {
|
|
24
|
-
validateNodeUrl(node);
|
|
25
|
-
} catch (e) {
|
|
26
|
-
print.error(`Graph node "${node}" is invalid: ${e.message}`);
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
} else {
|
|
30
|
-
if (studio) {
|
|
31
|
-
product = 'subgraph-studio';
|
|
32
|
-
}
|
|
33
|
-
switch (product) {
|
|
34
|
-
case 'subgraph-studio':
|
|
35
|
-
node = SUBGRAPH_STUDIO_URL;
|
|
36
|
-
break;
|
|
37
|
-
case 'hosted-service':
|
|
38
|
-
node = HOSTED_SERVICE_URL;
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (node?.match(/studio/) || product === 'subgraph-studio') {
|
|
43
|
-
allowSimpleName = true;
|
|
44
|
-
}
|
|
45
|
-
return { node, allowSimpleName };
|
|
46
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import { strings } from 'gluegun';
|
|
4
|
-
import { Map } from 'immutable';
|
|
5
|
-
import prettier from 'prettier';
|
|
6
|
-
import yaml from 'yaml';
|
|
7
|
-
import Protocol from '../protocols';
|
|
8
|
-
import ABI from '../protocols/ethereum/abi';
|
|
9
|
-
import Scaffold from '../scaffold';
|
|
10
|
-
import { generateEventIndexingHandlers } from '../scaffold/mapping';
|
|
11
|
-
import { abiEvents, generateEventType } from '../scaffold/schema';
|
|
12
|
-
import { generateTestsFiles } from '../scaffold/tests';
|
|
13
|
-
import { Spinner, step } from './spinner';
|
|
14
|
-
|
|
15
|
-
export const generateDataSource = async (
|
|
16
|
-
protocol: Protocol,
|
|
17
|
-
contractName: string,
|
|
18
|
-
network: string,
|
|
19
|
-
contractAddress: string,
|
|
20
|
-
abi: ABI,
|
|
21
|
-
) => {
|
|
22
|
-
const protocolManifest = protocol.getManifestScaffold();
|
|
23
|
-
|
|
24
|
-
return Map.of(
|
|
25
|
-
'kind',
|
|
26
|
-
protocol.name,
|
|
27
|
-
'name',
|
|
28
|
-
contractName,
|
|
29
|
-
'network',
|
|
30
|
-
network,
|
|
31
|
-
'source',
|
|
32
|
-
yaml.parse(
|
|
33
|
-
prettier.format(protocolManifest.source({ contract: contractAddress, contractName }), {
|
|
34
|
-
parser: 'yaml',
|
|
35
|
-
}),
|
|
36
|
-
),
|
|
37
|
-
'mapping',
|
|
38
|
-
yaml.parse(
|
|
39
|
-
prettier.format(protocolManifest.mapping({ abi, contractName }), {
|
|
40
|
-
parser: 'yaml',
|
|
41
|
-
}),
|
|
42
|
-
),
|
|
43
|
-
).asMutable();
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const generateScaffold = async (
|
|
47
|
-
{
|
|
48
|
-
protocolInstance,
|
|
49
|
-
abi,
|
|
50
|
-
contract,
|
|
51
|
-
network,
|
|
52
|
-
subgraphName,
|
|
53
|
-
indexEvents,
|
|
54
|
-
contractName = 'Contract',
|
|
55
|
-
node,
|
|
56
|
-
}: {
|
|
57
|
-
protocolInstance: Protocol;
|
|
58
|
-
abi: ABI;
|
|
59
|
-
contract: string;
|
|
60
|
-
network: string;
|
|
61
|
-
subgraphName: string;
|
|
62
|
-
indexEvents: boolean;
|
|
63
|
-
contractName?: string;
|
|
64
|
-
node: string;
|
|
65
|
-
},
|
|
66
|
-
spinner: Spinner,
|
|
67
|
-
) => {
|
|
68
|
-
step(spinner, 'Generate subgraph');
|
|
69
|
-
|
|
70
|
-
const scaffold = new Scaffold({
|
|
71
|
-
protocol: protocolInstance,
|
|
72
|
-
abi,
|
|
73
|
-
indexEvents,
|
|
74
|
-
contract,
|
|
75
|
-
network,
|
|
76
|
-
contractName,
|
|
77
|
-
subgraphName,
|
|
78
|
-
node,
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
return scaffold.generate();
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const writeScaffoldDirectory = async (scaffold: any, directory: string, spinner: Spinner) => {
|
|
85
|
-
// Create directory itself
|
|
86
|
-
await fs.mkdirs(directory);
|
|
87
|
-
|
|
88
|
-
const promises = Object.keys(scaffold).map(async basename => {
|
|
89
|
-
const content = scaffold[basename];
|
|
90
|
-
const filename = path.join(directory, basename);
|
|
91
|
-
|
|
92
|
-
// Write file or recurse into subdirectory
|
|
93
|
-
if (typeof content === 'string') {
|
|
94
|
-
await fs.writeFile(filename, content, 'utf-8');
|
|
95
|
-
} else if (content == null) {
|
|
96
|
-
return; // continue loop
|
|
97
|
-
} else {
|
|
98
|
-
writeScaffoldDirectory(content, path.join(directory, basename), spinner);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
await Promise.all(promises);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export const writeScaffold = async (scaffold: any, directory: string, spinner: Spinner) => {
|
|
106
|
-
step(spinner, `Write subgraph to directory`);
|
|
107
|
-
await writeScaffoldDirectory(scaffold, directory, spinner);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export const writeABI = async (abi: ABI, contractName: string) => {
|
|
111
|
-
const data = prettier.format(JSON.stringify(abi.data), {
|
|
112
|
-
parser: 'json',
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
await fs.writeFile(`./abis/${contractName}.json`, data, 'utf-8');
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
export const writeSchema = async (
|
|
119
|
-
abi: ABI,
|
|
120
|
-
protocol: Protocol,
|
|
121
|
-
schemaPath: string,
|
|
122
|
-
entities: any,
|
|
123
|
-
) => {
|
|
124
|
-
const events = protocol.hasEvents()
|
|
125
|
-
? abiEvents(abi)
|
|
126
|
-
.filter(event => !entities.includes(event.get('name')))
|
|
127
|
-
.toJS()
|
|
128
|
-
: [];
|
|
129
|
-
|
|
130
|
-
const data = prettier.format(
|
|
131
|
-
events.map(event => generateEventType(event, protocol.name)).join('\n\n'),
|
|
132
|
-
{
|
|
133
|
-
parser: 'graphql',
|
|
134
|
-
},
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
await fs.appendFile(schemaPath, data, { encoding: 'utf-8' });
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
export const writeMapping = async (
|
|
141
|
-
abi: ABI,
|
|
142
|
-
protocol: Protocol,
|
|
143
|
-
contractName: string,
|
|
144
|
-
entities: any,
|
|
145
|
-
) => {
|
|
146
|
-
const events = protocol.hasEvents()
|
|
147
|
-
? abiEvents(abi)
|
|
148
|
-
.filter(event => !entities.includes(event.get('name')))
|
|
149
|
-
.toJS()
|
|
150
|
-
: [];
|
|
151
|
-
|
|
152
|
-
const mapping = prettier.format(generateEventIndexingHandlers(events, contractName), {
|
|
153
|
-
parser: 'typescript',
|
|
154
|
-
semi: false,
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
await fs.writeFile(`./src/${strings.kebabCase(contractName)}.ts`, mapping, 'utf-8');
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
export const writeTestsFiles = async (abi: ABI, protocol: Protocol, contractName: string) => {
|
|
161
|
-
const hasEvents = protocol.hasEvents();
|
|
162
|
-
const events = hasEvents ? abiEvents(abi).toJS() : [];
|
|
163
|
-
|
|
164
|
-
if (events.length > 0) {
|
|
165
|
-
// If a contract is added to a subgraph that has no tests folder
|
|
166
|
-
await fs.ensureDir('./tests/');
|
|
167
|
-
|
|
168
|
-
const testsFiles = generateTestsFiles(contractName, events, true);
|
|
169
|
-
|
|
170
|
-
for (const [fileName, content] of Object.entries(testsFiles)) {
|
|
171
|
-
await fs.writeFile(`./tests/${fileName}`, content, 'utf-8');
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import * as toolbox from 'gluegun';
|
|
2
|
-
|
|
3
|
-
export type Spinner = ReturnType<toolbox.GluegunPrint['spin']>;
|
|
4
|
-
|
|
5
|
-
export const step = (spinner: Spinner, subject: string, text?: string) => {
|
|
6
|
-
if (text) {
|
|
7
|
-
spinner.stopAndPersist({
|
|
8
|
-
text: toolbox.print.colors.muted(`${subject} ${text}`),
|
|
9
|
-
});
|
|
10
|
-
} else {
|
|
11
|
-
spinner.stopAndPersist({ text: toolbox.print.colors.muted(subject) });
|
|
12
|
-
}
|
|
13
|
-
spinner.start();
|
|
14
|
-
return spinner;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// Executes the function `f` in a command-line spinner, using the
|
|
18
|
-
// provided captions for in-progress, error and failed messages.
|
|
19
|
-
//
|
|
20
|
-
// If `f` throws an error, the spinner stops with the failure message
|
|
21
|
-
// and rethrows the error.
|
|
22
|
-
// If `f` returns an object with a `warning` and a `result` key, the
|
|
23
|
-
// spinner stops with the warning message and returns the `result` value.
|
|
24
|
-
// Otherwise the spinner prints the in-progress message with a check mark
|
|
25
|
-
// and simply returns the value returned by `f`.
|
|
26
|
-
export const withSpinner = async (
|
|
27
|
-
text: string,
|
|
28
|
-
errorText: string,
|
|
29
|
-
warningText: string,
|
|
30
|
-
f: (spinner: Spinner) => Promise<any> | any, // TODO: type result
|
|
31
|
-
) => {
|
|
32
|
-
const spinner = toolbox.print.spin(text);
|
|
33
|
-
try {
|
|
34
|
-
const result = await f(spinner);
|
|
35
|
-
if (typeof result === 'object') {
|
|
36
|
-
const hasError = Object.keys(result).includes('error');
|
|
37
|
-
const hasWarning = Object.keys(result).includes('warning');
|
|
38
|
-
const hasResult = Object.keys(result).includes('result');
|
|
39
|
-
|
|
40
|
-
if (hasError) {
|
|
41
|
-
spinner.fail(`${errorText}: ${result.error}`);
|
|
42
|
-
return hasResult ? result.result : result;
|
|
43
|
-
}
|
|
44
|
-
if (hasWarning && hasResult) {
|
|
45
|
-
if (result.warning !== null) {
|
|
46
|
-
spinner.warn(`${warningText}: ${result.warning}`);
|
|
47
|
-
}
|
|
48
|
-
spinner.succeed(text);
|
|
49
|
-
return result.result;
|
|
50
|
-
}
|
|
51
|
-
spinner.succeed(text);
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
spinner.succeed(text);
|
|
55
|
-
return result;
|
|
56
|
-
} catch (e) {
|
|
57
|
-
spinner.fail(`${errorText}: ${e.message}`);
|
|
58
|
-
throw e;
|
|
59
|
-
}
|
|
60
|
-
};
|