From 777e990f2e900b4d8df8b4c4d91c1d4e9bab6f72 Mon Sep 17 00:00:00 2001 From: Denis Davidyuk Date: Tue, 22 Jun 2021 23:21:00 +0300 Subject: [PATCH] feat!: generate compiler api in TypeScript using autorest BREAKING CHANGE: `filesystem` option renamed to `fileSystem` BREAKING CHANGE: methods of `compilerApi` requires `options` object according to their specification BREAKING CHANGE: methods of `compilerApi` returns and accepts keys named in camelCase instead of snake_case --- .eslintrc.js | 2 +- .gitignore | 1 + docs/guides/contracts.md | 6 +- package-lock.json | 414 ++++++++++++++++++++++++++++++- package.json | 5 +- src/contract/aci.js | 22 +- src/contract/compiler.js | 82 +++--- test/integration/contract-aci.js | 26 +- test/integration/contract.js | 32 ++- tooling/autorest/compiler.yaml | 30 +++ 10 files changed, 531 insertions(+), 89 deletions(-) create mode 100644 tooling/autorest/compiler.yaml diff --git a/.eslintrc.js b/.eslintrc.js index 5520dd617a..6cb4b162c3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -46,7 +46,7 @@ module.exports = { plugins: [ '@typescript-eslint' ], - ignorePatterns: ['dist', 'es'], + ignorePatterns: ['dist', 'es', 'src/apis'], rules: { 'max-len': ['error', 100, 2, { ignoreUrls: true, diff --git a/.gitignore b/.gitignore index c8f7bbc318..8e448c47a7 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ coverage.* .history .site site +/src/apis/ diff --git a/docs/guides/contracts.md b/docs/guides/contracts.md index 9abc5f067c..37b23525ce 100644 --- a/docs/guides/contracts.md +++ b/docs/guides/contracts.md @@ -63,8 +63,8 @@ Note: - If your contract includes external dependencies which are not part of the [standard library](https://aeternity.com/aesophia/latest/sophia_stdlib) you should initialize the contract using: ```js - const filesystem = ... // key-value map with name of the include as key and source code of the include as value - const contractInstance = await aeSdk.getContractInstance({ source: CONTRACT_SOURCE, filesystem }) + const fileSystem = ... // key-value map with name of the include as key and source code of the include as value + const contractInstance = await aeSdk.getContractInstance({ source: CONTRACT_SOURCE, fileSystem }) ``` ### By ACI and bytecode @@ -93,7 +93,7 @@ const contractInstance = await aeSdk.getContractInstance({ aci, contractAddress - `contractAddress` - The address where the contract is located at. - To be used if a contract is already deployed. - - `filesystem` (default: {}) + - `fileSystem` (default: {}) - Key-value map with name of the include as key and source code of the include as value. - `validateBytecode` (default: false) - Compare source code with on-chain version. diff --git a/package-lock.json b/package-lock.json index 375ebf48b5..9573cf10f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,8 @@ "@aeternity/argon2-browser": "^0.1.2", "@aeternity/json-bigint": "^0.3.1", "@aeternity/uuid": "^0.0.1", + "@azure/core-client": "^1.5.0", + "@azure/core-rest-pipeline": "^1.7.0", "@babel/runtime-corejs3": "^7.17.2", "@stamp/it": "^1.1.0", "@stamp/required": "^1.0.1", @@ -122,6 +124,126 @@ "node": ">=6.0.0" } }, + "node_modules/@azure/abort-controller": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-1.0.4.tgz", + "integrity": "sha512-lNUmDRVGpanCsiUN3NWxFTdwmdFI53xwhkTFfHDGTYk46ca7Ind3nanJc+U6Zj9Tv+9nTCWRBscWEW1DyKOpTw==", + "dependencies": { + "tslib": "^2.0.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@azure/abort-controller/node_modules/tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + }, + "node_modules/@azure/core-asynciterator-polyfill": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@azure/core-asynciterator-polyfill/-/core-asynciterator-polyfill-1.0.2.tgz", + "integrity": "sha512-3rkP4LnnlWawl0LZptJOdXNrT/fHp2eQMadoasa6afspXdpGrtPZuAQc2PD0cpgyuoXtUWyC3tv7xfntjGS5Dw==", + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/@azure/core-auth": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@azure/core-auth/-/core-auth-1.3.2.tgz", + "integrity": "sha512-7CU6DmCHIZp5ZPiZ9r3J17lTKMmYsm/zGvNkjArQwPkrLlZ1TZ+EUYfGgh2X31OLMVAQCTJZW4cXHJi02EbJnA==", + "dependencies": { + "@azure/abort-controller": "^1.0.0", + "tslib": "^2.2.0" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/@azure/core-auth/node_modules/tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + }, + "node_modules/@azure/core-client": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@azure/core-client/-/core-client-1.5.0.tgz", + "integrity": "sha512-YNk8i9LT6YcFdFO+RRU0E4Ef+A8Y5lhXo6lz61rwbG8Uo7kSqh0YqK04OexiilM43xd6n3Y9yBhLnb1NFNI9dA==", + "dependencies": { + "@azure/abort-controller": "^1.0.0", + "@azure/core-asynciterator-polyfill": "^1.0.0", + "@azure/core-auth": "^1.3.0", + "@azure/core-rest-pipeline": "^1.5.0", + "@azure/core-tracing": "1.0.0-preview.13", + "@azure/logger": "^1.0.0", + "tslib": "^2.2.0" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/@azure/core-client/node_modules/tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + }, + "node_modules/@azure/core-rest-pipeline": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@azure/core-rest-pipeline/-/core-rest-pipeline-1.7.0.tgz", + "integrity": "sha512-e2awPzwMKHrmvYgZ0qIKNkqnCM1QoDs7A0rOiS3OSAlOQOz/kL7PPKHXwFMuBeaRvS8i7fgobJn79q2Cji5f+Q==", + "dependencies": { + "@azure/abort-controller": "^1.0.0", + "@azure/core-auth": "^1.3.0", + "@azure/core-tracing": "1.0.0-preview.13", + "@azure/logger": "^1.0.0", + "form-data": "^4.0.0", + "http-proxy-agent": "^4.0.1", + "https-proxy-agent": "^5.0.0", + "tslib": "^2.2.0", + "uuid": "^8.3.0" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/@azure/core-rest-pipeline/node_modules/tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + }, + "node_modules/@azure/core-tracing": { + "version": "1.0.0-preview.13", + "resolved": "https://registry.npmjs.org/@azure/core-tracing/-/core-tracing-1.0.0-preview.13.tgz", + "integrity": "sha512-KxDlhXyMlh2Jhj2ykX6vNEU0Vou4nHr025KoSEiz7cS3BNiHNaZcdECk/DmLkEB0as5T7b/TpRcehJ5yV6NeXQ==", + "dependencies": { + "@opentelemetry/api": "^1.0.1", + "tslib": "^2.2.0" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/@azure/core-tracing/node_modules/tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + }, + "node_modules/@azure/logger": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@azure/logger/-/logger-1.0.3.tgz", + "integrity": "sha512-aK4s3Xxjrx3daZr3VylxejK3vG5ExXck5WOHDJ8in/k9AqlfIyFMMT1uG7u8mNjX+QRILTIn0/Xgschfh/dQ9g==", + "dependencies": { + "tslib": "^2.2.0" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/@azure/logger/node_modules/tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + }, "node_modules/@babel/cli": { "version": "7.17.0", "resolved": "https://registry.npmjs.org/@babel/cli/-/cli-7.17.0.tgz", @@ -2586,6 +2708,14 @@ "node": ">= 8" } }, + "node_modules/@opentelemetry/api": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.0.4.tgz", + "integrity": "sha512-BuJuXRSJNQ3QoKA6GWWDyuLpOUck+9hAXNMCnrloc1aWVoy6Xq6t9PUV08aBZ4Lutqq2LEHM486bpZqoViScog==", + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/@polka/url": { "version": "1.0.0-next.21", "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.21.tgz", @@ -2678,6 +2808,14 @@ "@stamp/compose": "^1.0.2" } }, + "node_modules/@tootallnate/once": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz", + "integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==", + "engines": { + "node": ">= 6" + } + }, "node_modules/@tsconfig/node10": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.8.tgz", @@ -3281,6 +3419,17 @@ "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.1.2.tgz", "integrity": "sha512-e5pEa2kBnBOgR4Y/p20pskXI74UEz7de8ZGVo58asOtvSVG5YAbJeELPZxOmt+Bnz3rX753YKhfIn4X4l1PPRQ==" }, + "node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/aggregate-error": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", @@ -3496,6 +3645,11 @@ "node": "*" } }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + }, "node_modules/babel-loader": { "version": "8.2.3", "resolved": "https://registry.npmjs.org/babel-loader/-/babel-loader-8.2.3.tgz", @@ -4159,6 +4313,17 @@ "integrity": "sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g==", "dev": true }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/command-line-args": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-5.2.0.tgz", @@ -4881,7 +5046,6 @@ "version": "4.3.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz", "integrity": "sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==", - "dev": true, "dependencies": { "ms": "2.1.2" }, @@ -4984,6 +5148,14 @@ "node": ">= 0.4" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/detect-indent": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.1.0.tgz", @@ -6210,6 +6382,19 @@ "node": ">=8.0.0" } }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/form-data-encoder": { "version": "1.7.1", "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.1.tgz", @@ -6820,6 +7005,31 @@ "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", "dev": true }, + "node_modules/http-proxy-agent": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz", + "integrity": "sha512-k0zdNgqWTGA6aeIRVpvfVob4fL52dTfaehylg0Y4UvSySvOq/Y+BOyPrgpUrA7HylqvU8vIZGsRuXmspskV0Tg==", + "dependencies": { + "@tootallnate/once": "1", + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/https-proxy-agent": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz", + "integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==", + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -8228,7 +8438,6 @@ "version": "1.51.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.51.0.tgz", "integrity": "sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g==", - "dev": true, "engines": { "node": ">= 0.6" } @@ -8237,7 +8446,6 @@ "version": "2.1.34", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.34.tgz", "integrity": "sha512-6cP692WwGIs9XXdOO4++N+7qjqv0rqxxVvJ3VHPh/Sc9mVZcQP+ZGhkKiTvWMQRr2tbHkJP/Yn7Y0npb3ZBs4A==", - "dev": true, "dependencies": { "mime-db": "1.51.0" }, @@ -8464,8 +8672,7 @@ "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "node_modules/nanoid": { "version": "3.2.0", @@ -11129,6 +11336,14 @@ "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", "dev": true }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/v8-compile-cache": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", @@ -11868,6 +12083,117 @@ "@jridgewell/trace-mapping": "^0.3.0" } }, + "@azure/abort-controller": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-1.0.4.tgz", + "integrity": "sha512-lNUmDRVGpanCsiUN3NWxFTdwmdFI53xwhkTFfHDGTYk46ca7Ind3nanJc+U6Zj9Tv+9nTCWRBscWEW1DyKOpTw==", + "requires": { + "tslib": "^2.0.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + } + } + }, + "@azure/core-asynciterator-polyfill": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@azure/core-asynciterator-polyfill/-/core-asynciterator-polyfill-1.0.2.tgz", + "integrity": "sha512-3rkP4LnnlWawl0LZptJOdXNrT/fHp2eQMadoasa6afspXdpGrtPZuAQc2PD0cpgyuoXtUWyC3tv7xfntjGS5Dw==" + }, + "@azure/core-auth": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@azure/core-auth/-/core-auth-1.3.2.tgz", + "integrity": "sha512-7CU6DmCHIZp5ZPiZ9r3J17lTKMmYsm/zGvNkjArQwPkrLlZ1TZ+EUYfGgh2X31OLMVAQCTJZW4cXHJi02EbJnA==", + "requires": { + "@azure/abort-controller": "^1.0.0", + "tslib": "^2.2.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + } + } + }, + "@azure/core-client": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@azure/core-client/-/core-client-1.5.0.tgz", + "integrity": "sha512-YNk8i9LT6YcFdFO+RRU0E4Ef+A8Y5lhXo6lz61rwbG8Uo7kSqh0YqK04OexiilM43xd6n3Y9yBhLnb1NFNI9dA==", + "requires": { + "@azure/abort-controller": "^1.0.0", + "@azure/core-asynciterator-polyfill": "^1.0.0", + "@azure/core-auth": "^1.3.0", + "@azure/core-rest-pipeline": "^1.5.0", + "@azure/core-tracing": "1.0.0-preview.13", + "@azure/logger": "^1.0.0", + "tslib": "^2.2.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + } + } + }, + "@azure/core-rest-pipeline": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@azure/core-rest-pipeline/-/core-rest-pipeline-1.7.0.tgz", + "integrity": "sha512-e2awPzwMKHrmvYgZ0qIKNkqnCM1QoDs7A0rOiS3OSAlOQOz/kL7PPKHXwFMuBeaRvS8i7fgobJn79q2Cji5f+Q==", + "requires": { + "@azure/abort-controller": "^1.0.0", + "@azure/core-auth": "^1.3.0", + "@azure/core-tracing": "1.0.0-preview.13", + "@azure/logger": "^1.0.0", + "form-data": "^4.0.0", + "http-proxy-agent": "^4.0.1", + "https-proxy-agent": "^5.0.0", + "tslib": "^2.2.0", + "uuid": "^8.3.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + } + } + }, + "@azure/core-tracing": { + "version": "1.0.0-preview.13", + "resolved": "https://registry.npmjs.org/@azure/core-tracing/-/core-tracing-1.0.0-preview.13.tgz", + "integrity": "sha512-KxDlhXyMlh2Jhj2ykX6vNEU0Vou4nHr025KoSEiz7cS3BNiHNaZcdECk/DmLkEB0as5T7b/TpRcehJ5yV6NeXQ==", + "requires": { + "@opentelemetry/api": "^1.0.1", + "tslib": "^2.2.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + } + } + }, + "@azure/logger": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@azure/logger/-/logger-1.0.3.tgz", + "integrity": "sha512-aK4s3Xxjrx3daZr3VylxejK3vG5ExXck5WOHDJ8in/k9AqlfIyFMMT1uG7u8mNjX+QRILTIn0/Xgschfh/dQ9g==", + "requires": { + "tslib": "^2.2.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + } + } + }, "@babel/cli": { "version": "7.17.0", "resolved": "https://registry.npmjs.org/@babel/cli/-/cli-7.17.0.tgz", @@ -13621,6 +13947,11 @@ "fastq": "^1.6.0" } }, + "@opentelemetry/api": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.0.4.tgz", + "integrity": "sha512-BuJuXRSJNQ3QoKA6GWWDyuLpOUck+9hAXNMCnrloc1aWVoy6Xq6t9PUV08aBZ4Lutqq2LEHM486bpZqoViScog==" + }, "@polka/url": { "version": "1.0.0-next.21", "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.21.tgz", @@ -13713,6 +14044,11 @@ "@stamp/compose": "^1.0.2" } }, + "@tootallnate/once": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz", + "integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==" + }, "@tsconfig/node10": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.8.tgz", @@ -14195,6 +14531,14 @@ "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.1.2.tgz", "integrity": "sha512-e5pEa2kBnBOgR4Y/p20pskXI74UEz7de8ZGVo58asOtvSVG5YAbJeELPZxOmt+Bnz3rX753YKhfIn4X4l1PPRQ==" }, + "agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "requires": { + "debug": "4" + } + }, "aggregate-error": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", @@ -14358,6 +14702,11 @@ "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", "dev": true }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + }, "babel-loader": { "version": "8.2.3", "resolved": "https://registry.npmjs.org/babel-loader/-/babel-loader-8.2.3.tgz", @@ -14843,6 +15192,14 @@ "integrity": "sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g==", "dev": true }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "requires": { + "delayed-stream": "~1.0.0" + } + }, "command-line-args": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-5.2.0.tgz", @@ -15417,7 +15774,6 @@ "version": "4.3.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz", "integrity": "sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==", - "dev": true, "requires": { "ms": "2.1.2" } @@ -15490,6 +15846,11 @@ "object-keys": "^1.0.12" } }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" + }, "detect-indent": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.1.0.tgz", @@ -16424,6 +16785,16 @@ "signal-exit": "^3.0.2" } }, + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, "form-data-encoder": { "version": "1.7.1", "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.1.tgz", @@ -16871,6 +17242,25 @@ "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", "dev": true }, + "http-proxy-agent": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz", + "integrity": "sha512-k0zdNgqWTGA6aeIRVpvfVob4fL52dTfaehylg0Y4UvSySvOq/Y+BOyPrgpUrA7HylqvU8vIZGsRuXmspskV0Tg==", + "requires": { + "@tootallnate/once": "1", + "agent-base": "6", + "debug": "4" + } + }, + "https-proxy-agent": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz", + "integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==", + "requires": { + "agent-base": "6", + "debug": "4" + } + }, "human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -17922,14 +18312,12 @@ "mime-db": { "version": "1.51.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.51.0.tgz", - "integrity": "sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g==", - "dev": true + "integrity": "sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g==" }, "mime-types": { "version": "2.1.34", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.34.tgz", "integrity": "sha512-6cP692WwGIs9XXdOO4++N+7qjqv0rqxxVvJ3VHPh/Sc9mVZcQP+ZGhkKiTvWMQRr2tbHkJP/Yn7Y0npb3ZBs4A==", - "dev": true, "requires": { "mime-db": "1.51.0" } @@ -18096,8 +18484,7 @@ "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "nanoid": { "version": "3.2.0", @@ -20081,6 +20468,11 @@ "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", "dev": true }, + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" + }, "v8-compile-cache": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", diff --git a/package.json b/package.json index ba6a246670..54fdd80477 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "sideEffects": false, "scripts": { "build:es": "tsc && babel src --config-file ./babel.esm.config.js --out-dir es --extensions .js,.ts --out-file-extension .mjs --source-maps true", - "build": "webpack --mode=production && npm run build:es", + "build:api": "npx autorest tooling/autorest/compiler.yaml --output-artifact:code-model-v4", + "build": "npm run build:api && webpack --mode=production && npm run build:es", "build:dev": "webpack --mode=development && npm run build:es", "docs:examples": "node tooling/docs/examples-to-md.js examples/node/*.js", "docs:api": "node apidoc.js", @@ -36,6 +37,8 @@ "@aeternity/argon2-browser": "^0.1.2", "@aeternity/json-bigint": "^0.3.1", "@aeternity/uuid": "^0.0.1", + "@azure/core-client": "^1.5.0", + "@azure/core-rest-pipeline": "^1.7.0", "@babel/runtime-corejs3": "^7.17.2", "@stamp/it": "^1.1.0", "@stamp/required": "^1.0.1", diff --git a/src/contract/aci.js b/src/contract/aci.js index f0bc72973a..ddc5418f3b 100644 --- a/src/contract/aci.js +++ b/src/contract/aci.js @@ -54,7 +54,7 @@ import { hash } from '../utils/crypto-ts' * @param {String} [options.bytecode] Contract bytecode * @param {Object} [options.aci] Contract ACI * @param {String} [options.contractAddress] Contract address - * @param {Object} [options.filesystem] Contact source external namespaces map + * @param {Object} [options.fileSystem] Contact source external namespaces map * @param {Boolean} [options.validateBytecode] Compare source code with on-chain version * @return {ContractInstance} JS Contract API * @example @@ -73,12 +73,12 @@ export default async function getContractInstance ({ bytecode, aci: _aci, contractAddress, - filesystem = {}, + fileSystem = {}, validateBytecode, ...otherOptions } = {}) { if (!_aci && source) { - _aci = await this.compilerApi.generateACI({ code: source, options: { filesystem } }) + _aci = await this.compilerApi.generateACI({ code: source, options: { fileSystem } }) } if (!_aci) throw new MissingContractDefError() contractAddress = contractAddress && await this.resolveName( @@ -95,15 +95,15 @@ export default async function getContractInstance ({ const instance = { _aci, - _name: _aci.encoded_aci.contract.name, - calldata: new Calldata([_aci.encoded_aci, ..._aci.external_encoded_aci]), + _name: _aci.encodedAci.contract.name, + calldata: new Calldata([_aci.encodedAci, ..._aci.externalEncodedAci]), source, bytecode, deployInfo: { address: contractAddress }, options: { ...this.Ae.defaults, callStatic: false, - filesystem, + fileSystem, ...otherOptions }, compilerVersion: this.compilerVersion @@ -115,7 +115,7 @@ export default async function getContractInstance ({ const isValid = source ? await this.compilerApi.validateByteCode( { bytecode: onChanBytecode, source, options: instance.options } - ).then((res) => Object.entries(res).length === 0, () => false) + ).then(() => true, () => false) : bytecode === onChanBytecode if (!isValid) throw new BytecodeMismatchError(source ? 'source' : 'bytecode') } @@ -210,7 +210,7 @@ export default async function getContractInstance ({ * @return {Object} function ACI */ function getFunctionACI (name) { - const fn = instance._aci.encoded_aci.contract.functions.find(f => f.name === name) + const fn = instance._aci.encodedAci.contract.functions.find(f => f.name === name) if (fn) return fn if (name === 'init') return { payable: false } throw new NoSuchContractFunctionError(`Function ${name} doesn't exist in contract`) @@ -293,8 +293,8 @@ export default async function getContractInstance ({ if (addressToName[address]) return addressToName[address] const matchedEvents = [ - instance._aci.encoded_aci, - ...instance._aci.external_encoded_aci + instance._aci.encodedAci, + ...instance._aci.externalEncodedAci ] .filter(({ contract }) => contract?.event) .map(({ contract }) => [contract.name, contract.event.variant]) @@ -350,7 +350,7 @@ export default async function getContractInstance ({ * `await contract.methods.testFunction.get()` -> use call-static(dry-run) * `await contract.methods.testFunction.send()` -> send tx on-chain */ - instance.methods = Object.fromEntries(instance._aci.encoded_aci.contract.functions + instance.methods = Object.fromEntries(instance._aci.encodedAci.contract.functions .map(({ name, arguments: aciArgs, stateful }) => { const genHandler = callStatic => (...args) => { const options = args.length === aciArgs.length + 1 ? args.pop() : {} diff --git a/src/contract/compiler.js b/src/contract/compiler.js index 3de688fedf..7e55d7791f 100644 --- a/src/contract/compiler.js +++ b/src/contract/compiler.js @@ -23,11 +23,11 @@ * @example import { ContractCompilerHttp } from '@aeternity/aepp-sdk' */ +import { RestError } from '@azure/core-rest-pipeline' import semverSatisfies from '../utils/semver-satisfies' import AsyncInit from '../utils/async-init' -import genSwaggerClient from '../utils/swagger' +import { Compiler as CompilerApi } from '../apis/compiler/' import { MissingParamError, UnsupportedVersionError } from '../utils/errors' -import { mapObject } from '../utils/other' /** * Contract Compiler Stamp @@ -49,46 +49,54 @@ export default AsyncInit.compose({ methods: { async setCompilerUrl (compilerUrl, { ignoreVersion = false } = {}) { if (!compilerUrl) throw new MissingParamError('compilerUrl required') - compilerUrl = compilerUrl.replace(/\/$/, '') - const client = await genSwaggerClient(`${compilerUrl}/api`, { - disableBigNumbers: true, - disableCaseConversion: true, - responseInterceptor: response => { - if (response.ok) return - let message = `${new URL(response.url).pathname.slice(1)} error` - if (response.body.reason) { - message += ': ' + response.body.reason + - (response.body.parameter ? ` in ${response.body.parameter}` : '') + - // TODO: revising after improving documentation https://github.com/aeternity/aesophia_http/issues/78 - (response.body.info ? ` (${JSON.stringify(response.body.info)})` : '') - } - if (Array.isArray(response.body)) { - message += ':\n' + response.body - .map(e => `${e.type}:${e.pos.line}:${e.pos.col}: ${e.message}${e.context ? `(${e.context})` : ''}`) - .map(e => e.trim()) // TODO: remove after fixing https://github.com/aeternity/aesophia_http/issues/80 - .join('\n') - } - response.statusText = message - return response - } + const compilerApi = new CompilerApi(compilerUrl, { + allowInsecureConnection: true, + additionalPolicies: [{ + policy: { + name: 'error-formatter', + async sendRequest (request, next) { + try { + return await next(request) + } catch (error) { + if (!(error instanceof RestError)) throw error + let body + try { + body = JSON.parse(error.response.bodyAsText) + } catch (e) { + throw error + } + error.message = `${new URL(error.request.url).pathname.slice(1)} error` + if (body.reason) { + error.message += ': ' + body.reason + + (body.parameter ? ` in ${body.parameter}` : '') + + // TODO: revising after improving documentation https://github.com/aeternity/aesophia_http/issues/78 + (body.info ? ` (${JSON.stringify(body.info)})` : '') + } + if (Array.isArray(body)) { + error.message += ':\n' + body + .map(e => `${e.type}:${e.pos.line}:${e.pos.col}: ${e.message}${e.context ? `(${e.context})` : ''}`) + .map(e => e.trim()) // TODO: remove after fixing https://github.com/aeternity/aesophia_http/issues/80 + .join('\n') + } + throw error + } + } + }, + position: 'perCall' + }] }) - this.compilerVersion = client.spec.info.version - this.compilerApi = mapObject( - client.api, - ([key, fn]) => [ - key, - ({ options: { filesystem, ...options } = {}, ...args } = {}) => fn({ - ...args, options: { ...options, file_system: filesystem } - }) - ] - ) + const compilerVersion = (await compilerApi.aPIVersion()).apiVersion - if (ignoreVersion) return - if (!semverSatisfies(this.compilerVersion, COMPILER_GE_VERSION, COMPILER_LT_VERSION)) { + if ( + !ignoreVersion && + !semverSatisfies(compilerVersion, COMPILER_GE_VERSION, COMPILER_LT_VERSION) + ) { throw new UnsupportedVersionError( - 'compiler', this.compilerVersion, COMPILER_GE_VERSION, COMPILER_LT_VERSION + 'compiler', compilerVersion, COMPILER_GE_VERSION, COMPILER_LT_VERSION ) } + + Object.assign(this, { compilerApi, compilerVersion }) } }, props: { diff --git a/test/integration/contract-aci.js b/test/integration/contract-aci.js index 745cc78c22..88a4219459 100644 --- a/test/integration/contract-aci.js +++ b/test/integration/contract-aci.js @@ -131,7 +131,7 @@ contract StateContract = put(state{value = t}) recursion(t) ` -const filesystem = { +const fileSystem = { testLib: libContractSource } const notExistingContractAddress = 'ct_ptREMvyDbSh1d38t4WgYgac5oLsa2v9xwYFnG7eUWR8Er5cmT' @@ -146,16 +146,16 @@ describe('Contract instance', function () { before(async function () { aeSdk = await getSdk() testContractAci = await aeSdk.compilerApi - .generateACI({ code: testContractSource, options: { filesystem } }) + .generateACI({ code: testContractSource, options: { fileSystem } }) testContractBytecode = (await aeSdk.compilerApi.compileContract({ - code: testContractSource, options: { filesystem } + code: testContractSource, options: { fileSystem } })).bytecode }) it('generates by source code', async () => { aeSdk.Ae.defaults.testProperty = 'test' testContract = await aeSdk.getContractInstance({ - source: testContractSource, filesystem, ttl: 0, gasLimit: 15000 + source: testContractSource, fileSystem, ttl: 0, gasLimit: 15000 }) delete aeSdk.Ae.defaults.testProperty expect(testContract.options.testProperty).to.be.equal('test') @@ -166,10 +166,10 @@ describe('Contract instance', function () { testContract.should.have.property('call') testContract.should.have.property('deploy') testContract.options.ttl.should.be.equal(0) - testContract.options.should.have.property('filesystem') - testContract.options.filesystem.should.have.property('testLib') + testContract.options.should.have.property('fileSystem') + testContract.options.fileSystem.should.have.property('testLib') expect(Object.keys(testContract.methods)).to.be.eql( - testContract._aci.encoded_aci.contract.functions.map(({ name }) => name) + testContract._aci.encodedAci.contract.functions.map(({ name }) => name) ) }) @@ -245,7 +245,7 @@ describe('Contract instance', function () { it('accepts matching source code with enabled validation', () => aeSdk.getContractInstance({ source: testContractSource, - filesystem, + fileSystem, contractAddress: testContractAddress, validateBytecode: true })) @@ -264,9 +264,11 @@ describe('Contract instance', function () { })) it('rejects not matching bytecode with enabled validation', async () => expect(aeSdk.getContractInstance({ - bytecode: (await aeSdk.compilerApi.compileContract({ code: identityContractSource })).bytecode, + bytecode: (await aeSdk.compilerApi.compileContract({ + code: identityContractSource, options: {} + })).bytecode, aci: await aeSdk.compilerApi - .generateACI({ code: identityContractSource, options: { filesystem } }), + .generateACI({ code: identityContractSource, options: { fileSystem } }), contractAddress: testContractAddress, validateBytecode: true })).to.be.rejectedWith(BytecodeMismatchError, 'Contract bytecode do not correspond to the bytecode deployed on the chain')) @@ -318,7 +320,7 @@ describe('Contract instance', function () { let contract before(async () => { - contract = await aeSdk.getContractInstance({ source: testContractSource, filesystem }) + contract = await aeSdk.getContractInstance({ source: testContractSource, fileSystem }) }) it('estimates gas by default for contract deployments', async () => { @@ -329,7 +331,7 @@ describe('Contract instance', function () { it('overrides gas through getContractInstance options for contract deployments', async () => { const ct = await aeSdk.getContractInstance({ - source: testContractSource, filesystem, gasLimit: 300 + source: testContractSource, fileSystem, gasLimit: 300 }) const { tx: { gas }, gasUsed } = (await ct.deploy(['test', 42])).txData expect(gasUsed).to.be.equal(160) diff --git a/test/integration/contract.js b/test/integration/contract.js index 8bc090d541..5aea203437 100644 --- a/test/integration/contract.js +++ b/test/integration/contract.js @@ -128,7 +128,9 @@ describe('Contract', function () { }) it('compiles Sophia code', async () => { - bytecode = (await aeSdk.compilerApi.compileContract({ code: identityContract })).bytecode + bytecode = (await aeSdk.compilerApi.compileContract({ + code: identityContract, options: {} + })).bytecode expect(bytecode).to.satisfy(b => b.startsWith('cb_')) }) @@ -243,13 +245,13 @@ describe('Contract', function () { it('Can compiler contract with external deps', async () => { contract = await aeSdk.getContractInstance({ - source: contractWithLib, filesystem: { testLib: libContract } + source: contractWithLib, fileSystem: { testLib: libContract } }) expect(await contract.compile()).to.satisfy(b => b.startsWith('cb_')) }) it('Throw error when try to compile contract without providing external deps', async () => { - await expect(aeSdk.getContractInstance({ source: contractWithLib })) + await expect(aeSdk.getContractInstance({ source: contractWithLib, options: {} })) .to.be.rejectedWith('Couldn\'t find include file') }) @@ -274,7 +276,9 @@ describe('Contract', function () { let bytecode it('compile', async () => { - bytecode = (await aeSdk.compilerApi.compileContract({ code: identityContract })).bytecode + bytecode = (await aeSdk.compilerApi.compileContract({ + code: identityContract, options: {} + })).bytecode expect(bytecode).to.be.a('string') expect(bytecode.split('_')[0]).to.be.equal('cb') }) @@ -285,7 +289,8 @@ describe('Contract', function () { 'contract Foo =\n' + ' entrypoint getArg(x : bar) = x\n' + ' entrypoint getArg(x : int) = baz\n' + - ' entrypoint getArg1(x : int) = baz\n' + ' entrypoint getArg1(x : int) = baz\n', + options: {} })).to.be.rejectedWith( 'compile error:\n' + 'type_error:3:3: Duplicate definitions of getArg at\n' + @@ -297,25 +302,26 @@ describe('Contract', function () { }) it('generate contract ACI', async () => { - const aci = await aeSdk.compilerApi.generateACI({ code: identityContract }) - expect(aci).to.have.property('encoded_aci') - expect(aci).to.have.property('external_encoded_aci') + const aci = await aeSdk.compilerApi.generateACI({ code: identityContract, options: {} }) + expect(aci).to.have.property('encodedAci') + expect(aci).to.have.property('externalEncodedAci') expect(aci).to.have.property('interface') }) it('throws clear exception if generating ACI with no arguments', async () => { - await expect(aeSdk.compilerApi.generateACI()) - .to.be.rejectedWith('validation_error in body ({"error":"missing_required_property","data":"code","path":[]})') + await expect(aeSdk.compilerApi.generateACI({ options: {} })) + .to.be.rejectedWith('Error "body.code cannot be null or undefined." occurred in serializing the payload - undefined') }) it('validate bytecode', async () => { - expect(await aeSdk.compilerApi.validateByteCode({ bytecode, source: identityContract })) - .to.be.eql({}) + expect(await aeSdk.compilerApi.validateByteCode({ + bytecode, source: identityContract, options: {} + })).to.be.eql({ body: {} }) }) it('Use invalid compiler url', async () => { await expect(aeSdk.setCompilerUrl('https://compiler.aepps.comas')) - .to.be.rejectedWith('request to https://compiler.aepps.comas/api failed, reason: getaddrinfo ENOTFOUND compiler.aepps.comas') + .to.be.rejectedWith('getaddrinfo ENOTFOUND compiler.aepps.comas') }) }) diff --git a/tooling/autorest/compiler.yaml b/tooling/autorest/compiler.yaml new file mode 100644 index 0000000000..517559b767 --- /dev/null +++ b/tooling/autorest/compiler.yaml @@ -0,0 +1,30 @@ +--- +directive: + - from: swagger-document + where: $.info.title + set: compiler + reason: the whole SDK already about aeternity + + - from: swagger-document + where: $.paths.*.*.responses + transform: > + Object.entries($) + .filter(([key]) => key !== '200') + .forEach(([, value]) => value['x-ms-error-response'] = true) + reason: > + throw errors even for explained response with not 200 code + https://github.com/Azure/autorest.typescript/issues/463#issuecomment-524203041 + +version: ^3.6.1 +use-extension: + '@autorest/typescript': ^6.0.0-beta.18 + '@autorest/modelerfour': ^4.23.1 +# replace with a link to https://github.com/aeternity/aesophia_http/blob/master/config/swagger.yaml +# at specific version after fixing https://github.com/aeternity/aesophia_http/issues/87 +input-file: https://compiler.aeternity.io/api +output-folder: ../../src/apis/compiler +source-code-folder-path: . +client-side-validation: true +generator: typescript +generate-metadata: false +add-credentials: false