@graphprotocol/graph-cli 0.37.4 → 0.37.5

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.
Files changed (100) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/bin.js +6 -0
  3. package/dist/cli.js +26 -0
  4. package/dist/codegen/schema.js +244 -0
  5. package/dist/codegen/schema.test.js +455 -0
  6. package/dist/codegen/template.js +66 -0
  7. package/dist/codegen/types/conversions.js +335 -0
  8. package/dist/codegen/types/index.js +71 -0
  9. package/dist/codegen/types/index.test.js +563 -0
  10. package/dist/codegen/typescript.js +200 -0
  11. package/dist/codegen/util.js +40 -0
  12. package/dist/codegen/util.test.js +93 -0
  13. package/dist/command-helpers/abi.js +76 -0
  14. package/dist/command-helpers/auth.js +76 -0
  15. package/dist/command-helpers/compiler.js +66 -0
  16. package/dist/command-helpers/data-sources.js +29 -0
  17. package/dist/command-helpers/fs.js +9 -0
  18. package/dist/command-helpers/gluegun.js +48 -0
  19. package/dist/command-helpers/ipfs.js +5 -0
  20. package/dist/command-helpers/jsonrpc.js +27 -0
  21. package/dist/command-helpers/network.js +90 -0
  22. package/dist/command-helpers/network.test.js +86 -0
  23. package/dist/command-helpers/node.js +40 -0
  24. package/dist/command-helpers/scaffold.js +110 -0
  25. package/dist/command-helpers/spinner.js +80 -0
  26. package/dist/command-helpers/studio.js +14 -0
  27. package/dist/command-helpers/studio.test.js +41 -0
  28. package/dist/command-helpers/subgraph.js +22 -0
  29. package/dist/command-helpers/version.js +66 -0
  30. package/dist/command-helpers/version.test.js +186 -0
  31. package/dist/commands/add.js +187 -0
  32. package/dist/commands/auth.js +122 -0
  33. package/dist/commands/build.js +136 -0
  34. package/dist/commands/codegen.js +128 -0
  35. package/dist/commands/create.js +94 -0
  36. package/dist/commands/deploy.js +335 -0
  37. package/dist/commands/init.js +800 -0
  38. package/dist/commands/local.js +380 -0
  39. package/dist/commands/remove.js +95 -0
  40. package/dist/commands/test.js +293 -0
  41. package/dist/compiler/asc.js +83 -0
  42. package/dist/compiler/index.js +466 -0
  43. package/dist/debug.js +16 -0
  44. package/dist/migrations/mapping_api_version_0_0_1.js +83 -0
  45. package/dist/migrations/mapping_api_version_0_0_2.js +83 -0
  46. package/dist/migrations/mapping_api_version_0_0_3.js +83 -0
  47. package/dist/migrations/mapping_api_version_0_0_4.js +85 -0
  48. package/dist/migrations/mapping_api_version_0_0_5.js +85 -0
  49. package/dist/migrations/spec_version_0_0_2.js +45 -0
  50. package/dist/migrations/spec_version_0_0_3.js +50 -0
  51. package/dist/migrations/util/load-manifest.js +16 -0
  52. package/dist/migrations/util/versions.js +28 -0
  53. package/dist/migrations.js +54 -0
  54. package/dist/protocols/arweave/manifest.graphql +57 -0
  55. package/dist/protocols/arweave/scaffold/manifest.js +18 -0
  56. package/dist/protocols/arweave/scaffold/mapping.js +52 -0
  57. package/dist/protocols/arweave/subgraph.js +23 -0
  58. package/dist/protocols/contract.js +2 -0
  59. package/dist/protocols/cosmos/manifest.graphql +76 -0
  60. package/dist/protocols/cosmos/scaffold/manifest.js +15 -0
  61. package/dist/protocols/cosmos/scaffold/mapping.js +38 -0
  62. package/dist/protocols/cosmos/subgraph.js +28 -0
  63. package/dist/protocols/ethereum/abi.js +138 -0
  64. package/dist/protocols/ethereum/codegen/abi.js +474 -0
  65. package/dist/protocols/ethereum/codegen/abi.test.js +325 -0
  66. package/dist/protocols/ethereum/codegen/template.js +52 -0
  67. package/dist/protocols/ethereum/contract.js +22 -0
  68. package/dist/protocols/ethereum/manifest.graphql +94 -0
  69. package/dist/protocols/ethereum/scaffold/manifest.js +32 -0
  70. package/dist/protocols/ethereum/scaffold/mapping.js +65 -0
  71. package/dist/protocols/ethereum/subgraph.js +172 -0
  72. package/dist/protocols/ethereum/type-generator.js +123 -0
  73. package/dist/protocols/index.js +266 -0
  74. package/dist/protocols/ipfs/codegen/file_template.js +53 -0
  75. package/dist/protocols/near/contract.js +41 -0
  76. package/dist/protocols/near/manifest.graphql +64 -0
  77. package/dist/protocols/near/scaffold/manifest.js +16 -0
  78. package/dist/protocols/near/scaffold/mapping.js +38 -0
  79. package/dist/protocols/near/subgraph.js +23 -0
  80. package/dist/protocols/subgraph.js +2 -0
  81. package/dist/protocols/substreams/manifest.graphql +45 -0
  82. package/dist/protocols/substreams/scaffold/manifest.js +12 -0
  83. package/dist/protocols/substreams/subgraph.js +23 -0
  84. package/dist/scaffold/cosmos.test.js +82 -0
  85. package/dist/scaffold/ethereum.test.js +496 -0
  86. package/dist/scaffold/index.js +133 -0
  87. package/dist/scaffold/mapping.js +57 -0
  88. package/dist/scaffold/near.test.js +85 -0
  89. package/dist/scaffold/schema.js +86 -0
  90. package/dist/scaffold/tests.js +179 -0
  91. package/dist/schema.js +54 -0
  92. package/dist/subgraph.js +243 -0
  93. package/dist/type-generator.js +225 -0
  94. package/dist/validation/contract.js +44 -0
  95. package/dist/validation/index.js +10 -0
  96. package/dist/validation/manifest.js +266 -0
  97. package/dist/validation/schema.js +768 -0
  98. package/dist/validation/schema.test.js +35 -0
  99. package/dist/watcher.js +79 -0
  100. package/package.json +1 -1
@@ -0,0 +1,76 @@
1
+ # Each referenced type's in any of the types below must be listed
2
+ # here either as `scalar` or `type` for the validation code to work
3
+ # properly.
4
+ #
5
+ # That's why `String` is listed as a scalar even though it's built-in
6
+ # GraphQL basic types.
7
+ scalar String
8
+ scalar File
9
+ scalar BigInt
10
+
11
+ type SubgraphManifest {
12
+ specVersion: String!
13
+ features: [String!]
14
+ schema: Schema!
15
+ description: String
16
+ repository: String
17
+ graft: Graft
18
+ dataSources: [DataSource!]!
19
+ }
20
+
21
+ type Schema {
22
+ file: File!
23
+ }
24
+
25
+ type DataSource {
26
+ kind: String!
27
+ name: String!
28
+ network: String
29
+ source: ContractSource!
30
+ mapping: ContractMapping!
31
+ }
32
+
33
+ type ContractSource {
34
+ startBlock: BigInt
35
+ }
36
+
37
+ type ContractMapping {
38
+ apiVersion: String!
39
+ language: String!
40
+ file: File!
41
+ entities: [String!]!
42
+ blockHandlers: [BlockHandler!]
43
+ eventHandlers: [EventHandler!]
44
+ transactionHandlers: [TransactionHandler!]
45
+ messageHandlers: [MessageHandler!]
46
+ }
47
+
48
+ type BlockHandler {
49
+ handler: String!
50
+ }
51
+
52
+ enum EventOrigin {
53
+ BeginBlock
54
+ DeliverTx
55
+ EndBlock
56
+ }
57
+
58
+ type EventHandler {
59
+ event: String!
60
+ origin: EventOrigin
61
+ handler: String!
62
+ }
63
+
64
+ type TransactionHandler {
65
+ handler: String!
66
+ }
67
+
68
+ type MessageHandler {
69
+ message: String!
70
+ handler: String!
71
+ }
72
+
73
+ type Graft {
74
+ base: String!
75
+ block: BigInt!
76
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapping = exports.source = void 0;
4
+ const source = () => `
5
+ startBlock: 0`;
6
+ exports.source = source;
7
+ const mapping = () => `
8
+ apiVersion: 0.0.5
9
+ language: wasm/assemblyscript
10
+ entities:
11
+ - ExampleEntity
12
+ blockHandlers:
13
+ - handler: handleBlock
14
+ file: ./src/contract.ts`;
15
+ exports.mapping = mapping;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generatePlaceholderHandlers = void 0;
4
+ const generatePlaceholderHandlers = () => `
5
+ import { cosmos, BigInt } from '@graphprotocol/graph-ts'
6
+ import { ExampleEntity } from '../generated/schema'
7
+
8
+ export function handleBlock(block: cosmos.Block): void {
9
+ // Entities can be loaded from the store using a string ID; this ID
10
+ // needs to be unique across all entities of the same type
11
+ let entity = ExampleEntity.load(block.header.hash.toHex())
12
+
13
+ // Entities only exist after they have been saved to the store;
14
+ // \`null\` checks allow to create entities on demand
15
+ if (!entity) {
16
+ entity = new ExampleEntity(block.header.hash.toHex())
17
+
18
+ // Entity fields can be set using simple assignments
19
+ entity.count = BigInt.fromI32(0)
20
+ }
21
+
22
+ // BigInt and BigDecimal math are supported
23
+ entity.count = entity.count + BigInt.fromI32(1)
24
+
25
+ // Entity fields can be set based on receipt information
26
+ entity.height = block.header.height
27
+
28
+ // Entities can be written to the store with \`.save()\`
29
+ entity.save()
30
+
31
+ // Note: If a handler doesn't require existing field values, it is faster
32
+ // _not_ to load the entity from the store. Instead, create it fresh with
33
+ // \`new Entity(...)\`, set the fields that should be updated and save the
34
+ // entity back to the store. Fields that were not set or unset remain
35
+ // unchanged, allowing for partial updates to be applied.
36
+ }
37
+ `;
38
+ exports.generatePlaceholderHandlers = generatePlaceholderHandlers;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const immutable_1 = __importDefault(require("immutable"));
7
+ class CosmosSubgraph {
8
+ manifest;
9
+ resolveFile;
10
+ protocol;
11
+ constructor(options) {
12
+ this.manifest = options.manifest;
13
+ this.resolveFile = options.resolveFile;
14
+ this.protocol = options.protocol;
15
+ }
16
+ validateManifest() {
17
+ return immutable_1.default.List();
18
+ }
19
+ handlerTypes() {
20
+ return immutable_1.default.List([
21
+ 'blockHandlers',
22
+ 'eventHandlers',
23
+ 'transactionHandlers',
24
+ 'messageHandlers',
25
+ ]);
26
+ }
27
+ }
28
+ exports.default = CosmosSubgraph;
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const immutable_1 = __importDefault(require("immutable"));
9
+ const abi_1 = __importDefault(require("./codegen/abi"));
10
+ const TUPLE_ARRAY_PATTERN = /^tuple\[([0-9]*)\]$/;
11
+ const TUPLE_MATRIX_PATTERN = /^tuple\[([0-9]*)\]\[([0-9]*)\]$/;
12
+ const buildOldSignatureParameter = (input) => {
13
+ return input.get('type') === 'tuple'
14
+ ? `(${input
15
+ .get('components')
16
+ .map((component) => buildSignatureParameter(component))
17
+ .join(',')})`
18
+ : String(input.get('type'));
19
+ };
20
+ const buildSignatureParameter = (input) => {
21
+ if (input.get('type') === 'tuple') {
22
+ return `(${input.get('indexed') ? 'indexed ' : ''}${input
23
+ .get('components')
24
+ .map((component) => buildSignatureParameter(component))
25
+ .join(',')})`;
26
+ }
27
+ if (input.get('type').match(TUPLE_ARRAY_PATTERN)) {
28
+ const length = input.get('type').match(TUPLE_ARRAY_PATTERN)[1];
29
+ return `(${input.get('indexed') ? 'indexed ' : ''}${input
30
+ .get('components')
31
+ .map((component) => buildSignatureParameter(component))
32
+ .join(',')})[${length ? length : ''}]`;
33
+ }
34
+ if (input.get('type').match(TUPLE_MATRIX_PATTERN)) {
35
+ const length1 = input.get('type').match(TUPLE_MATRIX_PATTERN)[1];
36
+ const length2 = input.get('type').match(TUPLE_MATRIX_PATTERN)[2];
37
+ return `(${input.get('indexed') ? 'indexed ' : ''}${input
38
+ .get('components')
39
+ .map((component) => buildSignatureParameter(component))
40
+ .join(',')})[${length1 ? length1 : ''}][${length2 ? length2 : ''}]`;
41
+ }
42
+ return `${input.get('indexed') ? 'indexed ' : ''}${input.get('type')}`;
43
+ };
44
+ class ABI {
45
+ name;
46
+ file;
47
+ data;
48
+ constructor(name, file, data) {
49
+ this.name = name;
50
+ this.file = file;
51
+ this.data = data;
52
+ this.name = name;
53
+ this.file = file;
54
+ this.data = data;
55
+ }
56
+ codeGenerator() {
57
+ return new abi_1.default(this);
58
+ }
59
+ static oldEventSignature(event) {
60
+ return `${event.get('name')}(${event
61
+ .get('inputs', [])
62
+ .map(buildOldSignatureParameter)
63
+ .join(',')})`;
64
+ }
65
+ static eventSignature(event) {
66
+ return `${event.get('name')}(${event
67
+ .get('inputs', [])
68
+ .map(buildSignatureParameter)
69
+ .join(',')})`;
70
+ }
71
+ /**
72
+ * For the ABI of a function, returns a string function signature compatible
73
+ * with the Rust `ethabi` library. It is of the form
74
+ *
75
+ * <function>([<input-type-1>, ...])[:(<output-type-1,...)]
76
+ *
77
+ * A few examples for a function called `example`:
78
+ *
79
+ * - No inputs or outputs: `example()`
80
+ * - One input and output: `example(uint256):(bool)`
81
+ * - Multiple inputs and outputs: `example(uint256,(string,bytes32)):(bool,uint256)`
82
+ */
83
+ functionSignature(fn) {
84
+ const inputs = fn.get('inputs', []).map(buildSignatureParameter).join(',');
85
+ const outputs = fn.get('outputs', []).map(buildSignatureParameter).join(',');
86
+ return `${fn.get('name')}(${inputs})${outputs.length > 0 ? `:(${outputs})` : ''}`;
87
+ }
88
+ oldEventSignatures() {
89
+ return this.data
90
+ .filter((entry) => entry.get('type') === 'event')
91
+ .map(ABI.oldEventSignature);
92
+ }
93
+ eventSignatures() {
94
+ return this.data.filter((entry) => entry.get('type') === 'event').map(ABI.eventSignature);
95
+ }
96
+ callFunctions() {
97
+ // An entry is a function if its type is not set or if it is one of
98
+ // 'constructor', 'function' or 'fallback'
99
+ const functionTypes = immutable_1.default.Set(['constructor', 'function', 'fallback']);
100
+ const functions = this.data.filter((entry) => !entry.has('type') || functionTypes.includes(entry.get('type')));
101
+ // A function is a call function if it is nonpayable, payable or
102
+ // not constant
103
+ const mutabilityTypes = immutable_1.default.Set(['nonpayable', 'payable']);
104
+ return functions.filter((entry) => mutabilityTypes.includes(entry.get('stateMutability')) || entry.get('constant') === false);
105
+ }
106
+ callFunctionSignatures() {
107
+ return this.callFunctions()
108
+ .filter((entry) => entry.get('type') !== 'constructor')
109
+ .map((entry) => {
110
+ const name = entry.get('name', '<default>');
111
+ const inputs = entry
112
+ .get('inputs', immutable_1.default.List())
113
+ .map((input) => buildSignatureParameter(input));
114
+ return `${name}(${inputs.join(',')})`;
115
+ });
116
+ }
117
+ static normalized(json) {
118
+ if (Array.isArray(json)) {
119
+ return json;
120
+ }
121
+ if (json.abi !== undefined) {
122
+ return json.abi;
123
+ }
124
+ if (json.compilerOutput?.abi) {
125
+ return json.compilerOutput.abi;
126
+ }
127
+ return undefined;
128
+ }
129
+ static load(name, file) {
130
+ const data = JSON.parse(fs_extra_1.default.readFileSync(file).toString());
131
+ const abi = ABI.normalized(data);
132
+ if (abi === null || abi === undefined) {
133
+ throw Error(`No valid ABI in file: ${path_1.default.relative(process.cwd(), file)}`);
134
+ }
135
+ return new ABI(name, file, immutable_1.default.fromJS(abi));
136
+ }
137
+ }
138
+ exports.default = ABI;