diff --git a/.github/workflows/js-ci.yaml b/.github/workflows/js-ci.yaml index ae9497024c..b303be57f2 100644 --- a/.github/workflows/js-ci.yaml +++ b/.github/workflows/js-ci.yaml @@ -169,6 +169,16 @@ jobs: with: node-version: '${{ steps.nvm.outputs.NVMRC }}' + - uses: actions/setup-go@v3 + with: + go-version: '^1.13.1' + + - name: Install cue lang + run: go install cuelang.org/go/cmd/cue@latest + + - name: Check if cue is installed + run: cue version + - name: Get yarn cache directory path id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" diff --git a/CHANGELOG.md b/CHANGELOG.md index 24d440a7c7..1b6e0e3548 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ +# Polywrap 0.0.1-prealpha.89 +## Features +* [PR-903](https://github.com/polywrap/monorepo/pull/903) `polywrap` CLI: Recipes have been re-worked into composable workflows, and they can be run using CLI commands. +* [PR-951](https://github.com/polywrap/monorepo/pull/951) `polywrap` CLI: Docker Buildx output option has been removed. +* [PR-944](https://github.com/polywrap/monorepo/pull/944) `@polywrap/schema-bind`, `@polywrap/wasm-as`: `Nullable` type has been replaced with `Option` in the Assemblyscript schema bindings. +* [PR-938](https://github.com/polywrap/monorepo/pull/938) `@polywrap/schema-bind`, `@polywrap/wasm-as`: Rollback of JSON serialization in the Assemblyscript schema bindings. + +## Bugs +* [PR-946](https://github.com/polywrap/monorepo/pull/946) `@polywrap/test-env-js`: Path fix for `npmCLI` test utility. + +## Breaking Changes +* [PR-903](https://github.com/polywrap/monorepo/pull/903) `polywrap` CLI: Running recipes via the `polywrap query ...` command has been deprecated in favor of a new workflows system, accessible via the `polywrap run ...` command. +* [PR-944](https://github.com/polywrap/monorepo/pull/944) `wasm/assemblyscript` Wrappers: `Nullable` type has been removed in favor of `Option` which also has a different interface. +* [PR-938](https://github.com/polywrap/monorepo/pull/938) `wasm/assemblyscript` Wrappers: `JSON` serializer and deserializer, and related methods `fromJson` and `toJson` have been removed in favor of `parse` and `stringify`. + # Polywrap 0.0.1-prealpha.88 ## Bugs * Various CI/CD fixes. diff --git a/VERSION b/VERSION index 8f9a849c50..5bf85935b0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.1-prealpha.88 +0.0.1-prealpha.89 diff --git a/package.json b/package.json index e7fd41f4ae..4bbed698a1 100644 --- a/package.json +++ b/package.json @@ -46,20 +46,21 @@ }, "devDependencies": { "@types/prettier": "2.6.0", - "lerna": "4.0.0", - "rimraf": "3.0.2", "@typescript-eslint/eslint-plugin": "4.11.1", "@typescript-eslint/parser": "4.11.1", "eslint": "7.16.0", "eslint-config-prettier": "7.1.0", "eslint-plugin-import": "2.22.1", + "eslint-plugin-json": "3.0.0", "eslint-plugin-prettier": "3.4.0", - "prettier": "2.2.1", "graphql": "15.5.0", - "eslint-plugin-json": "3.0.0" + "lerna": "4.0.0", + "prettier": "2.2.1", + "rimraf": "3.0.2" }, "resolutions": { "@types/react": "16.9.0", "@types/react-dom": "16.9.0" - } + }, + "version": "0.0.1-prealpha.87" } diff --git a/packages/cli/lang/en.json b/packages/cli/lang/en.json index bddbea1492..5d436c0d88 100644 --- a/packages/cli/lang/en.json +++ b/packages/cli/lang/en.json @@ -102,7 +102,6 @@ "commands_create_options_o": "Output directory for the new project", "commands_create_options_o_path": "path", "commands_create_options_projectName": "project-name", - "commands_query_options_recipeScript": "Path to recipe script", "commands_create_overwritePrompt": "Do you want to overwrite this directory?", "commands_create_overwriting": "Overwriting {dir}...", "commands_create_readyApp": "You are ready to build an app using Polywrap", @@ -140,43 +139,51 @@ "commands_plugin_options_path": "path", "commands_plugin_options_publish": "Output path for the built schema and manifest (default: {default})", "commands_plugin_options_codegen": "Output directory for the generated types (default: {default})", - "commands_query_options_configPath": "config-path", - "commands_query_options_outputFilePath": "output-file-path", - "commands_query_options_config": "Add custom configuration to the PolywrapClient", - "commands_query_options_outputFile": "Output file path for the query result", - "commands_query_options_quiet": "Suppress output", - "commands_query_error_outputFileMissing": "{option} option missing {argument} argument", - "commands_query_error_clientConfigMissingPath": "{option} option missing {argument} argument", - "commands_query_error_clientConfigModuleMissingExport": "Custom client config module missing named export 'getClientConfig' at {module}", - "commands_query_error_clientConfigInvalidFileExt": "Custom client config file: {module} must be a JS/TS file", - "commands_query_error_clientConfigNotObject": "Custom client config must be an object", - "commands_query_error_redirectsExportNotArray": "Exported redirects must be an array", - "commands_query_error_redirectsItemNotValid": "Redirect at index {index} must be an object with properties 'from' and 'to'", - "commands_query_error_redirectsItemFromNotString": "Redirect property 'from' at index {index} must be a valid wrap:// URI string", - "commands_query_error_redirectsItemToNotStringOrObject": "Redirect property 'to' at index {index} must be a valid wrap:// URI string, or a plugin", - "commands_query_error_redirectsItemToNotValidPlugin": "Redirect property 'to' at index {index} must be a valid plugin instance", - "commands_query_error_pluginsExportNotArray": "Exported plugins must be an array", - "commands_query_error_pluginsItemNotObject": "Plugin at index {index} must be an object with properties 'uri' and 'plugin'", - "commands_query_error_pluginsItemUriNotString": "Plugin property 'uri' at index {index} must be a valid wrap:// URI string", - "commands_query_error_pluginsItemPluginNotObject": "Plugin property 'plugin' at index {index} must be an object with properties 'factory' and 'manifest'", - "commands_query_error_pluginsItemPluginFactoryNotFunction": "Plugin property 'plugin.factory' at index {index} must be a function", - "commands_query_error_pluginsItemPluginManifestNotObject": "Plugin property 'plugin.manifest' at index {index} must be an object", - "commands_query_error_interfacesExportNotArray": "Exported interfaces must be an array", - "commands_query_error_interfacesItemNotObject": "Interface at index {index} must be an object with properties 'interface' and 'implementations'", - "commands_query_error_interfacesItemInterfaceNotString": "Interface property 'interface' at index {index} must be a valid wrap:// URI string", - "commands_query_error_interfacesItemImplementationsNotArray": "Interface property 'implementations' at index {index} must be an array", - "commands_query_error_interfacesItemImplementationsEmpty": "Interface property 'implementations' at index {index} must not be an empty array", - "commands_query_error_interfacesItemImplementationsItemNotString": "Implementation at index ({index}, {implementationIndex}) must be a valid wrap:// URI string", - "commands_query_error_envsExportNotArray": "Exported envs must be an array", - "commands_query_error_envsItemNotObject": "Env at index {index} must be an object with properties 'uri' and optional properties 'common', 'query', and 'mutation'", - "commands_query_error_envsItemUriNotString": "Env property 'uri' at index {index} must be a valid wrap:// URI string", - "commands_query_error_envsItemModuleNotObject": "Env property 'module' at index {index} must be an object", - "commands_query_description": "Query wrappers using recipe scripts", - "commands_query_error_missingScript": "Required argument {script} is missing", - "commands_query_error_noWrapper": "Wrapper needs to be initialized", - "commands_query_error_readFail": "Failed to read query {query}", - "commands_query_error_noRecipeScriptFound": "Recipe script not found at path: {path}", - "commands_query_error_noTestEnvFound": "polywrap test-env not found, please run 'polywrap infra up --modules=eth-ens-ipfs'", + "commands_run_options_workflow": "workflow", + "commands_run_options_workflowScript": "Path to workflow script", + "commands_run_options_configPath": "config-path", + "commands_run_options_outputFilePath": "output-file-path", + "commands_run_options_config": "Add custom configuration to the PolywrapClient", + "commands_run_options_validateScript": "Validate the output of the workflow jobs", + "commands_run_options_validate": "cue-file", + "commands_run_options_outputFile": "Output file path for the workflow result", + "commands_run_options_quiet": "Suppress output", + "commands_run_options_jobIds": "jobs", + "commands_run_options_jobs": "Specify ids of jobs that you want to run", + "commands_run_error_validatorNotFound": "validate script not found at: {path}", + "commands_run_error_outputFileMissing": "{option} option missing {argument} argument", + "commands_run_error_clientConfigMissingPath": "{option} option missing {argument} argument", + "commands_run_error_clientConfigModuleMissingExport": "Custom client config module missing named export 'getClientConfig' at {module}", + "commands_run_error_clientConfigInvalidFileExt": "Custom client config file: {module} must be a JS/TS file", + "commands_run_error_clientConfigNotObject": "Custom client config must be an object", + "commands_run_error_redirectsExportNotArray": "Exported redirects must be an array", + "commands_run_error_redirectsItemNotValid": "Redirect at index {index} must be an object with properties 'from' and 'to'", + "commands_run_error_redirectsItemFromNotString": "Redirect property 'from' at index {index} must be a valid wrap:// URI string", + "commands_run_error_redirectsItemToNotStringOrObject": "Redirect property 'to' at index {index} must be a valid wrap:// URI string, or a plugin", + "commands_run_error_redirectsItemToNotValidPlugin": "Redirect property 'to' at index {index} must be a valid plugin instance", + "commands_run_error_pluginsExportNotArray": "Exported plugins must be an array", + "commands_run_error_pluginsItemNotObject": "Plugin at index {index} must be an object with properties 'uri' and 'plugin'", + "commands_run_error_pluginsItemUriNotString": "Plugin property 'uri' at index {index} must be a valid wrap:// URI string", + "commands_run_error_pluginsItemPluginNotObject": "Plugin property 'plugin' at index {index} must be an object with properties 'factory' and 'manifest'", + "commands_run_error_pluginsItemPluginFactoryNotFunction": "Plugin property 'plugin.factory' at index {index} must be a function", + "commands_run_error_pluginsItemPluginManifestNotObject": "Plugin property 'plugin.manifest' at index {index} must be an object", + "commands_run_error_interfacesExportNotArray": "Exported interfaces must be an array", + "commands_run_error_interfacesItemNotObject": "Interface at index {index} must be an object with properties 'interface' and 'implementations'", + "commands_run_error_interfacesItemInterfaceNotString": "Interface property 'interface' at index {index} must be a valid wrap:// URI string", + "commands_run_error_interfacesItemImplementationsNotArray": "Interface property 'implementations' at index {index} must be an array", + "commands_run_error_interfacesItemImplementationsEmpty": "Interface property 'implementations' at index {index} must not be an empty array", + "commands_run_error_interfacesItemImplementationsItemNotString": "Implementation at index ({index}, {implementationIndex}) must be a valid wrap:// URI string", + "commands_run_error_envsExportNotArray": "Exported envs must be an array", + "commands_run_error_envsItemNotObject": "Env at index {index} must be an object with properties 'uri'", + "commands_run_error_envsItemUriNotString": "Env property 'uri' at index {index} must be a valid wrap:// URI string", + "commands_run_error_envsItemModuleNotObject": "Env property 'env' at index {index} must be an object", + "commands_run_description": "Runs workflow script", + "commands_run_error_missingScript": "Required argument {script} is missing", + "commands_run_error_noApi": "API needs to be initialized", + "commands_run_error_readFail": "Failed to read query {query}", + "commands_run_error_unsupportedOutputFileExt": "Unsupported outputFile extention: ${outputFileExt}", + "commands_run_error_noWorkflowScriptFound": "Workflow script not found at path: {path}", + "commands_run_error_noTestEnvFound": "polywrap test-env not found, please run 'polywrap infra up --modules=eth-ens-ipfs'", "commands_testEnv_description": "Manage a test environment for Polywrap", "commands_testEnv_error_never": "This should never happen...", "commands_testEnv_error_noCommand": "No command given", diff --git a/packages/cli/lang/es.json b/packages/cli/lang/es.json index 0d994590e6..3c8bdbe892 100644 --- a/packages/cli/lang/es.json +++ b/packages/cli/lang/es.json @@ -1,4 +1,3 @@ - { "commands_build_description": "Builds a wrapper", "commands_build_error_manifestPathMissing": "{option} option missing {argument} argument", @@ -103,7 +102,6 @@ "commands_create_options_o": "Output directory for the new project", "commands_create_options_o_path": "path", "commands_create_options_projectName": "project-name", - "commands_query_options_recipeScript": "Path to recipe script", "commands_create_overwritePrompt": "Do you want to overwrite this directory?", "commands_create_overwriting": "Overwriting {dir}...", "commands_create_readyApp": "You are ready to build an app using Polywrap", @@ -141,43 +139,51 @@ "commands_plugin_options_path": "path", "commands_plugin_options_publish": "Output path for the built schema and manifest (default: {default})", "commands_plugin_options_codegen": "Output directory for the generated types (default: {default})", - "commands_query_options_configPath": "config-path", - "commands_query_options_outputFilePath": "output-file-path", - "commands_query_options_config": "Add custom configuration to the PolywrapClient", - "commands_query_options_outputFile": "Output file path for the query result", - "commands_query_options_quiet": "Suppress output", - "commands_query_error_outputFileMissing": "{option} option missing {argument} argument", - "commands_query_error_clientConfigMissingPath": "{option} option missing {argument} argument", - "commands_query_error_clientConfigModuleMissingExport": "Custom client config module missing named export 'getClientConfig' at {module}", - "commands_query_error_clientConfigInvalidFileExt": "Custom client config file: {module} must be a JS/TS file", - "commands_query_error_clientConfigNotObject": "Custom client config must be an object", - "commands_query_error_redirectsExportNotArray": "Exported redirects must be an array", - "commands_query_error_redirectsItemNotValid": "Redirect at index {index} must be an object with properties 'from' and 'to'", - "commands_query_error_redirectsItemFromNotString": "Redirect property 'from' at index {index} must be a valid wrap:// URI string", - "commands_query_error_redirectsItemToNotStringOrObject": "Redirect property 'to' at index {index} must be a valid wrap:// URI string, or a plugin", - "commands_query_error_redirectsItemToNotValidPlugin": "Redirect property 'to' at index {index} must be a valid plugin instance", - "commands_query_error_pluginsExportNotArray": "Exported plugins must be an array", - "commands_query_error_pluginsItemNotObject": "Plugin at index {index} must be an object with properties 'uri' and 'plugin'", - "commands_query_error_pluginsItemUriNotString": "Plugin property 'uri' at index {index} must be a valid wrap:// URI string", - "commands_query_error_pluginsItemPluginNotObject": "Plugin property 'plugin' at index {index} must be an object with properties 'factory' and 'manifest'", - "commands_query_error_pluginsItemPluginFactoryNotFunction": "Plugin property 'plugin.factory' at index {index} must be a function", - "commands_query_error_pluginsItemPluginManifestNotObject": "Plugin property 'plugin.manifest' at index {index} must be an object", - "commands_query_error_interfacesExportNotArray": "Exported interfaces must be an array", - "commands_query_error_interfacesItemNotObject": "Interface at index {index} must be an object with properties 'interface' and 'implementations'", - "commands_query_error_interfacesItemInterfaceNotString": "Interface property 'interface' at index {index} must be a valid wrap:// URI string", - "commands_query_error_interfacesItemImplementationsNotArray": "Interface property 'implementations' at index {index} must be an array", - "commands_query_error_interfacesItemImplementationsEmpty": "Interface property 'implementations' at index {index} must not be an empty array", - "commands_query_error_interfacesItemImplementationsItemNotString": "Implementation at index ({index}, {implementationIndex}) must be a valid wrap:// URI string", - "commands_query_error_envsExportNotArray": "Exported envs must be an array", - "commands_query_error_envsItemNotObject": "Env at index {index} must be an object with properties 'uri'", - "commands_query_error_envsItemUriNotString": "Env property 'uri' at index {index} must be a valid wrap:// URI string", - "commands_query_error_envsItemModuleNotObject": "Env property 'common' at index {index} must be an object", - "commands_query_description": "Query wrappers using recipe scripts", - "commands_query_error_missingScript": "Required argument {script} is missing", - "commands_query_error_noWrapper": "Wrapper needs to be initialized", - "commands_query_error_readFail": "Failed to read query {query}", - "commands_query_error_noRecipeScriptFound": "Recipe script not found at path: {path}", - "commands_query_error_noTestEnvFound": "polywrap test-env not found, please run 'polywrap infra up --modules=eth-ens-ipfs'", + "commands_run_options_workflow": "workflow", + "commands_run_options_workflowScript": "Path to workflow script", + "commands_run_options_configPath": "config-path", + "commands_run_options_outputFilePath": "output-file-path", + "commands_run_options_config": "Add custom configuration to the PolywrapClient", + "commands_run_options_validateScript": "Validate the output of the workflow jobs", + "commands_run_options_validate": "cue-file", + "commands_run_options_outputFile": "Output file path for the workflow result", + "commands_run_options_quiet": "Suppress output", + "commands_run_options_jobIds": "jobs", + "commands_run_options_jobs": "Specify ids of jobs that you want to run", + "commands_run_error_validatorNotFound": "validate script not found at: {path}", + "commands_run_error_outputFileMissing": "{option} option missing {argument} argument", + "commands_run_error_clientConfigMissingPath": "{option} option missing {argument} argument", + "commands_run_error_clientConfigModuleMissingExport": "Custom client config module missing named export 'getClientConfig' at {module}", + "commands_run_error_clientConfigInvalidFileExt": "Custom client config file: {module} must be a JS/TS file", + "commands_run_error_clientConfigNotObject": "Custom client config must be an object", + "commands_run_error_redirectsExportNotArray": "Exported redirects must be an array", + "commands_run_error_redirectsItemNotValid": "Redirect at index {index} must be an object with properties 'from' and 'to'", + "commands_run_error_redirectsItemFromNotString": "Redirect property 'from' at index {index} must be a valid wrap:// URI string", + "commands_run_error_redirectsItemToNotStringOrObject": "Redirect property 'to' at index {index} must be a valid wrap:// URI string, or a plugin", + "commands_run_error_redirectsItemToNotValidPlugin": "Redirect property 'to' at index {index} must be a valid plugin instance", + "commands_run_error_pluginsExportNotArray": "Exported plugins must be an array", + "commands_run_error_pluginsItemNotObject": "Plugin at index {index} must be an object with properties 'uri' and 'plugin'", + "commands_run_error_pluginsItemUriNotString": "Plugin property 'uri' at index {index} must be a valid wrap:// URI string", + "commands_run_error_pluginsItemPluginNotObject": "Plugin property 'plugin' at index {index} must be an object with properties 'factory' and 'manifest'", + "commands_run_error_pluginsItemPluginFactoryNotFunction": "Plugin property 'plugin.factory' at index {index} must be a function", + "commands_run_error_pluginsItemPluginManifestNotObject": "Plugin property 'plugin.manifest' at index {index} must be an object", + "commands_run_error_interfacesExportNotArray": "Exported interfaces must be an array", + "commands_run_error_interfacesItemNotObject": "Interface at index {index} must be an object with properties 'interface' and 'implementations'", + "commands_run_error_interfacesItemInterfaceNotString": "Interface property 'interface' at index {index} must be a valid wrap:// URI string", + "commands_run_error_interfacesItemImplementationsNotArray": "Interface property 'implementations' at index {index} must be an array", + "commands_run_error_interfacesItemImplementationsEmpty": "Interface property 'implementations' at index {index} must not be an empty array", + "commands_run_error_interfacesItemImplementationsItemNotString": "Implementation at index ({index}, {implementationIndex}) must be a valid wrap:// URI string", + "commands_run_error_envsExportNotArray": "Exported envs must be an array", + "commands_run_error_envsItemNotObject": "Env at index {index} must be an object with properties 'uri'", + "commands_run_error_envsItemUriNotString": "Env property 'uri' at index {index} must be a valid wrap:// URI string", + "commands_run_error_envsItemModuleNotObject": "Env property 'env' at index {index} must be an object", + "commands_run_description": "Runs workflow script", + "commands_run_error_missingScript": "Required argument {script} is missing", + "commands_run_error_noApi": "API needs to be initialized", + "commands_run_error_readFail": "Failed to read query {query}", + "commands_run_error_unsupportedOutputFileExt": "Unsupported outputFile extention: ${outputFileExt}", + "commands_run_error_noWorkflowScriptFound": "Workflow script not found at path: {path}", + "commands_run_error_noTestEnvFound": "polywrap test-env not found, please run 'polywrap infra up --modules=eth-ens-ipfs'", "commands_testEnv_description": "Manage a test environment for Polywrap", "commands_testEnv_error_never": "This should never happen...", "commands_testEnv_error_noCommand": "No command given", diff --git a/packages/cli/src/__tests__/e2e/create.spec.ts b/packages/cli/src/__tests__/e2e/create.spec.ts index c8a0c3317f..eefc1f442a 100644 --- a/packages/cli/src/__tests__/e2e/create.spec.ts +++ b/packages/cli/src/__tests__/e2e/create.spec.ts @@ -98,8 +98,7 @@ describe("e2e tests for create command", () => { expect(output).toBe(""); }); - // TODO: re-enable this post-polywrap init release - test.skip("Should successfully generate project", async () => { + test("Should successfully generate project", async () => { rimraf.sync(`${__dirname}/test`); const { exitCode: code, stdout: output } = await runCLI({ diff --git a/packages/cli/src/__tests__/e2e/help.spec.ts b/packages/cli/src/__tests__/e2e/help.spec.ts index b4ee397923..8c9f3797ef 100644 --- a/packages/cli/src/__tests__/e2e/help.spec.ts +++ b/packages/cli/src/__tests__/e2e/help.spec.ts @@ -15,8 +15,8 @@ Commands: create|c Create a new project with polywrap CLI deploy|d [options] Deploys/Publishes a Polywrap plugin|p Build/generate types for the plugin - query|q [options] Query wrappers using recipe scripts infra|i [options] Manage infrastructure for your wrapper + run|r [options] Runs workflow script help [command] display help for command `; diff --git a/packages/cli/src/__tests__/e2e/no-command.spec.ts b/packages/cli/src/__tests__/e2e/no-command.spec.ts index 057f42a800..87976e9502 100644 --- a/packages/cli/src/__tests__/e2e/no-command.spec.ts +++ b/packages/cli/src/__tests__/e2e/no-command.spec.ts @@ -15,8 +15,8 @@ Commands: create|c Create a new project with polywrap CLI deploy|d [options] Deploys/Publishes a Polywrap plugin|p Build/generate types for the plugin - query|q [options] Query wrappers using recipe scripts infra|i [options] Manage infrastructure for your wrapper + run|r [options] Runs workflow script help [command] display help for command `; diff --git a/packages/cli/src/__tests__/e2e/query.spec.helper.ts b/packages/cli/src/__tests__/e2e/query.spec.helper.ts deleted file mode 100644 index dfc2a869f6..0000000000 --- a/packages/cli/src/__tests__/e2e/query.spec.helper.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { normalizeLineEndings } from "@polywrap/os-js"; -import { clearStyle } from "./utils"; - -export interface ISampleOutputOptions { - SimpleStorageAddr: string; -} - -export function checkSampleQueryOutput( - output: string, - { SimpleStorageAddr }: ISampleOutputOptions -) { - expect(clearStyle(normalizeLineEndings(output, "\n"))).toContain( - getSampleOutput({ SimpleStorageAddr }) - ); - - expect(clearStyle(output)).toContain(getSampleOutputSetDataValue()); -} - -export function getSampleOutputWithClientConfig( - options: ISampleOutputOptions -): string { - return `----------------------------------- -mutation { - setData( - options: { - address: $address - value: $value - } - connection: { - networkNameOrChainId: $network - } - ) { - value - txReceipt - } -} - -{ - "address": "${options.SimpleStorageAddr}", - "value": 569, - "network": "testnet" -} ------------------------------------ ------------------------------------ -{ - "setData": { - "value": 569, - "txReceipt": "0xdone" - } -} ------------------------------------ -`; -} - -export function getSampleOutput(options: ISampleOutputOptions): string { - return `----------------------------------- -mutation { - setData( - options: { - address: $address - value: $value - } - connection: { - networkNameOrChainId: $network - } - ) { - value - txReceipt - } -} - -{ - "address": "${options.SimpleStorageAddr}", - "value": 569, - "network": "testnet" -} ------------------------------------ ------------------------------------ -{ - "setData": { - "txReceipt": "0x`; -} - -export function getSampleOutputSetDataValue(): string { - return `", - "value": 569 - } -} ------------------------------------ -`; -} - -export function getSampleObjectOutput(): any { - return { - query: "./set.graphql", - variables: { - address: "$SimpleStorageAddr", - value: 569, - network: "testnet", - }, - output: { - data: { - setData: { - value: 569, - }, - }, - }, - }; -} diff --git a/packages/cli/src/__tests__/e2e/query.spec.ts b/packages/cli/src/__tests__/e2e/query.spec.ts deleted file mode 100644 index d3104013ae..0000000000 --- a/packages/cli/src/__tests__/e2e/query.spec.ts +++ /dev/null @@ -1,278 +0,0 @@ -import fs from "fs"; -import path from "path"; -import yaml from "js-yaml"; - -import { clearStyle, polywrapCli } from "./utils"; - -import { buildAndDeployWrapper, providers, initTestEnvironment, runCLI, stopTestEnvironment } from "@polywrap/test-env-js"; -import { GetPathToCliTestFiles } from "@polywrap/test-cases"; -import { normalizeLineEndings } from "@polywrap/os-js"; -import { - checkSampleQueryOutput, - getSampleObjectOutput, - getSampleOutputWithClientConfig, - ISampleOutputOptions, -} from "./query.spec.helper"; - -jest.setTimeout(200000); - -const HELP = `Usage: polywrap query|q [options] - -Query wrappers using recipe scripts - -Arguments: - recipe Path to recipe script - -Options: - -c, --client-config Add custom configuration to the - PolywrapClient - -o, --output-file Output file path for the query result - -q, --quiet Suppress output - -h, --help display help for command -`; - -describe("sanity tests for query command", () => { - const testCaseRoot = path.join(GetPathToCliTestFiles(), "wasm/query"); - - test("Should show help text", async () => { - const { exitCode: code, stdout: output, stderr: error } = await runCLI({ - args: ["query", "--help"], - cwd: testCaseRoot, - }); - - expect(code).toEqual(0); - expect(error).toBe(""); - expect(clearStyle(output)).toEqual(HELP); - }); - - test("Should throw error for missing recipe-string", async () => { - const { exitCode, stdout, stderr } = await runCLI({ - args: ["query"], - cwd: testCaseRoot, - cli: polywrapCli, - }); - - expect(exitCode).toEqual(1); - expect(stderr).toContain("error: missing required argument 'recipe"); - expect(stdout).toEqual(``); - }); - - test("Should throw error is --client-config doesn't contain arguments", async () => { - const { exitCode, stdout, stderr } = await runCLI({ - args: ["query", "./recipes/e2e.json", "--client-config"], - cwd: testCaseRoot, - cli: polywrapCli, - }); - - expect(exitCode).toEqual(1); - expect(stderr).toBe( - "error: option '-c, --client-config ' argument missing\n" - ); - expect(stdout).toEqual(``); - }); -}); - -describe("e2e tests for query command", () => { - const testCaseRoot = path.join(GetPathToCliTestFiles(), "wasm/query"); - - beforeAll(async () => { - await initTestEnvironment(); - - const { stderr: deployErr } = await runCLI({ - args: ["./deploy-contracts.js"], - cwd: testCaseRoot, - cli: " ", - }); - - expect(deployErr).toBe(""); - - await buildAndDeployWrapper({ - wrapperAbsPath: testCaseRoot, - ipfsProvider: providers.ipfs, - ethereumProvider: providers.ethereum, - ensName: "simplestorage.eth", - }) - }); - - afterAll(async () => { - await stopTestEnvironment(); - }); - - test("Should successfully return response: using json recipes", async () => { - const { exitCode: code, stdout: output, stderr: queryErr } = await runCLI({ - args: ["query", "./recipes/e2e.json"], - cwd: testCaseRoot, - cli: polywrapCli, - }); - - expect(queryErr).toBe(""); - expect(code).toEqual(0); - - const constants = require(`${testCaseRoot}/recipes/constants.json`); - checkSampleQueryOutput(output, { - SimpleStorageAddr: constants.SimpleStorageAddr, - }); - }, 480000); - - test("Should successfully return response: using yaml recipes", async () => { - const { exitCode: code, stdout: output, stderr: queryErr } = await runCLI({ - args: ["query", "./recipes/e2e.yaml"], - cwd: testCaseRoot, - cli: polywrapCli, - }); - - expect(code).toEqual(0); - expect(queryErr).toBe(""); - - const constants = yaml.load( - await fs.promises.readFile( - `${testCaseRoot}/recipes/constants.yaml`, - "utf8" - ) - ) as ISampleOutputOptions; - - checkSampleQueryOutput(output, { - SimpleStorageAddr: constants.SimpleStorageAddr, - }); - }, 480000); - - test("Should successfully return response: using mix of yaml & json recipes", async () => { - const { exitCode: code, stdout: output, stderr: queryErr } = await runCLI({ - args: ["query", "./recipes/e2e.json"], - cwd: testCaseRoot, - cli: polywrapCli, - }); - - expect(code).toEqual(0); - expect(queryErr).toBe(""); - - const constants = yaml.load( - await fs.promises.readFile( - `${testCaseRoot}/recipes/constants.yaml`, - "utf8" - ) - ) as ISampleOutputOptions; - - checkSampleQueryOutput(output, { - SimpleStorageAddr: constants.SimpleStorageAddr, - }); - }, 480000); - - test("Should successfully create json output file if specified", async () => { - const { exitCode: code, stdout: output, stderr: queryErr } = await runCLI({ - args: [ - "query", - "./recipes/e2e.json", - "--output-file", - "./recipes/output.json", - ], - cwd: testCaseRoot, - cli: polywrapCli, - }); - - expect(code).toEqual(0); - expect(queryErr).toBe(""); - - const constants = require(`${testCaseRoot}/recipes/constants.json`); - checkSampleQueryOutput(output, { - SimpleStorageAddr: constants.SimpleStorageAddr, - }); - - expect(fs.existsSync(`${testCaseRoot}/recipes/output.json`)).toBeTruthy(); - const arr: Array = JSON.parse( - fs.readFileSync(`${testCaseRoot}/recipes/output.json`, "utf8") - ); - expect(Array.isArray(arr)).toBeTruthy(); - - expect(arr[2]).toMatchObject(getSampleObjectOutput()); - - fs.unlinkSync(`${testCaseRoot}/recipes/output.json`); - }, 48000); - - test("Should successfully create yaml output file if specified", async () => { - const { exitCode: code, stdout: output, stderr: queryErr } = await runCLI({ - args: [ - "query", - "./recipes/e2e.yaml", - "--output-file", - "./recipes/output.yaml", - ], - cwd: testCaseRoot, - cli: polywrapCli, - }); - - expect(code).toEqual(0); - expect(queryErr).toBe(""); - - const constants = yaml.load( - await fs.promises.readFile( - `${testCaseRoot}/recipes/constants.yaml`, - "utf8" - ) - ) as ISampleOutputOptions; - - checkSampleQueryOutput(output, { - SimpleStorageAddr: constants.SimpleStorageAddr, - }); - - expect(fs.existsSync(`${testCaseRoot}/recipes/output.yaml`)).toBeTruthy(); - const arr: Array = (yaml.load( - fs.readFileSync(`${testCaseRoot}/recipes/output.yaml`, "utf8") - ) as unknown) as Array; - expect(Array.isArray(arr)).toBeTruthy(); - expect(arr[2]).toMatchObject(getSampleObjectOutput()); - - fs.unlinkSync(`${testCaseRoot}/recipes/output.yaml`); - }, 48000); - - test("Should suppress the ouput if --quiet option is specified", async () => { - const { exitCode: code, stdout: output, stderr: queryErr } = await runCLI({ - args: [ - "query", - "./recipes/e2e.json", - "--quiet", - ], - cwd: testCaseRoot, - cli: polywrapCli, - }); - - expect(code).toEqual(0); - expect(queryErr).toBe(""); - expect(output).toBeFalsy(); - }, 48000); - - test("Should use custom config for client if specified", async () => { - const configs = [ - "./client-config.ts", - "./client-config.js", - "./client-async-config.ts", - "./client-async-config.js", - ]; - - for (const config of configs) { - const { exitCode, stdout, stderr } = await runCLI({ - args: [ - "query", - "./recipes/e2e.json", - "--client-config", - config, - ], - cwd: testCaseRoot, - cli: polywrapCli, - }); - - expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); - - expect(exitCode).toEqual(0); - expect(stderr).toBe(""); - - const constants = require(`${testCaseRoot}/recipes/constants.json`); - expect(clearStyle(normalizeLineEndings(stdout, "\n"))).toContain( - getSampleOutputWithClientConfig({ - SimpleStorageAddr: constants.SimpleStorageAddr, - }) - ); - } - }, 48000); -}); diff --git a/packages/cli/src/__tests__/e2e/run.spec.ts b/packages/cli/src/__tests__/e2e/run.spec.ts new file mode 100644 index 0000000000..2be7b972f6 --- /dev/null +++ b/packages/cli/src/__tests__/e2e/run.spec.ts @@ -0,0 +1,250 @@ +import fs from "fs"; +import path from "path"; +import yaml from "js-yaml"; + +import { clearStyle, parseOutput, polywrapCli } from "./utils"; + +import { + buildAndDeployWrapper, + initTestEnvironment, + runCLI, +} from "@polywrap/test-env-js"; +import { GetPathToCliTestFiles } from "@polywrap/test-cases"; + +jest.setTimeout(200000); + +const HELP = `Usage: polywrap run|r [options] + +Runs workflow script + +Arguments: + workflow Path to workflow script + +Options: + -c, --client-config Add custom configuration to the + PolywrapClient + -v, --validate-script Validate the output of the workflow + jobs + -o, --output-file Output file path for the workflow + result + -j, --jobs Specify ids of jobs that you want to + run + -q, --quiet Suppress output + -h, --help display help for command +`; + +describe("sanity tests for workflow command", () => { + const testCaseRoot = path.join(GetPathToCliTestFiles(), "wasm/run"); + + it("Should show help text", async () => { + const { exitCode: code, stdout: output, stderr: error } = await runCLI({ + args: ["run", "--help"], + cwd: testCaseRoot, + }); + + expect(code).toEqual(0); + expect(error).toBe(""); + expect(clearStyle(output)).toEqual(HELP); + }); + + it("Should throw error for missing workflow-string", async () => { + const { exitCode, stdout, stderr } = await runCLI({ + args: ["run"], + cwd: testCaseRoot, + cli: polywrapCli, + }); + + expect(exitCode).toEqual(1); + expect(stderr).toContain("error: missing required argument 'workflow'"); + expect(stdout).toEqual(``); + }); + + it("Should throw error is --client-config doesn't contain arguments", async () => { + const { exitCode, stdout, stderr } = await runCLI({ + args: ["run", "./recipes/e2e.json", "--client-config"], + cwd: testCaseRoot, + cli: polywrapCli, + }); + + expect(exitCode).toEqual(1); + expect(stderr).toBe( + "error: option '-c, --client-config ' argument missing\n" + ); + expect(stdout).toEqual(``); + }); +}); + +describe("e2e tests for run command", () => { + const testCaseRoot = path.join(GetPathToCliTestFiles(), "wasm/run"); + + beforeAll(async () => { + await initTestEnvironment(); + + await buildAndDeployWrapper({ + wrapperAbsPath: testCaseRoot, + ipfsProvider: "http://localhost:5001", + ethereumProvider: "http://localhost:8545", + ensName: "simple-storage.eth", + }); + }); + + afterAll(async () => { + await runCLI({ + args: ["test-env", "down"], + cwd: testCaseRoot, + cli: polywrapCli, + }); + }); + + it("Should successfully return response: using json workflow", async () => { + const { exitCode: code, stdout, stderr } = await runCLI({ + args: ["run", "./workflows/e2e.json", "-c", "./workflows/config.ts"], + cwd: testCaseRoot, + cli: polywrapCli, + }); + + expect(code).toEqual(0); + expect(stderr).toBe(""); + + const output = parseOutput(stdout); + output.forEach((item) => { + expect(item.error).toBeUndefined(); + expect(item.data).toBeDefined(); + }); + expect(output).toHaveLength(3); + }, 480000); + + it("Should successfully return response: using yaml workflow", async () => { + const { exitCode: code, stdout, stderr } = await runCLI({ + args: ["run", "./workflows/e2e.yaml", "-c", "./workflows/config.ts"], + cwd: testCaseRoot, + cli: polywrapCli, + }); + + expect(code).toEqual(0); + expect(stderr).toBe(""); + + const output = parseOutput(stdout); + output.forEach((item) => { + expect(item.error).toBeUndefined(); + expect(item.data).toBeDefined(); + }); + expect(output).toHaveLength(3); + }, 480000); + + it("Should successfully create json output file if specified", async () => { + const { exitCode: code, stdout, stderr } = await runCLI({ + args: [ + "run", + "./workflows/e2e.json", + "-c", + "./workflows/config.ts", + "--output-file", + "./workflows/output.json", + ], + cwd: testCaseRoot, + cli: polywrapCli, + }); + + expect(code).toEqual(0); + expect(stderr).toBe(""); + expect(parseOutput(stdout)).toMatchObject( + JSON.parse( + fs.readFileSync( + path.join(testCaseRoot, "workflows/output.json"), + "utf8" + ) + ) + ); + + fs.unlinkSync(`${testCaseRoot}/workflows/output.json`); + }, 48000); + + it("Should successfully create yaml output file if specified", async () => { + const { exitCode: code, stdout, stderr } = await runCLI({ + args: [ + "run", + "./workflows/e2e.json", + "-c", + "./workflows/config.ts", + "--output-file", + "./workflows/output.yaml", + ], + cwd: testCaseRoot, + cli: polywrapCli, + }); + + expect(code).toEqual(0); + expect(stderr).toBe(""); + expect(parseOutput(stdout)).toMatchObject( + JSON.parse( + JSON.stringify( + (yaml.load( + fs.readFileSync( + path.join(testCaseRoot, "workflows/output.yaml"), + "utf8" + ) + ) as unknown) as Array + ) + ) + ); + + fs.unlinkSync(`${testCaseRoot}/workflows/output.yaml`); + }, 48000); + + it("Should suppress the ouput if --quiet option is specified", async () => { + const { exitCode: code, stdout, stderr } = await runCLI({ + args: [ + "run", + "./workflows/e2e.json", + "-c", + "./workflows/config.ts", + "--quiet", + ], + cwd: testCaseRoot, + cli: polywrapCli, + }); + + expect(code).toEqual(0); + expect(stderr).toBe(""); + expect(stdout).toBeFalsy(); + }, 48000); + + it("Should validate output if validate script given", async () => { + const { exitCode: code, stdout, stderr } = await runCLI({ + args: [ + "run", + "./workflows/e2e.json", + "-c", + "./workflows/config.ts", + "-v", + "./workflows/validator.cue", + "-q", + ], + cwd: testCaseRoot, + cli: polywrapCli, + }); + + expect(code).toEqual(0); + expect(stderr).toBe(""); + expect(stdout).toBe(""); + + }, 48000); + + it("Should print error on stderr if validation fails", async () => { + const { exitCode: code, stderr } = await runCLI({ + args: [ + "run", + "./workflows/e2e.json", + "-v", + "./workflows/validator.cue", + "-q", + ], + cwd: testCaseRoot, + cli: polywrapCli, + }); + + expect(code).toEqual(1); + expect(stderr).toBeDefined(); + }, 48000); +}); diff --git a/packages/cli/src/__tests__/e2e/test/test/package.json b/packages/cli/src/__tests__/e2e/test/test/package.json deleted file mode 100644 index 47cd757a44..0000000000 --- a/packages/cli/src/__tests__/e2e/test/test/package.json +++ /dev/null @@ -1,5 +0,0 @@ - -{ - "name": "template" -} - \ No newline at end of file diff --git a/packages/cli/src/__tests__/e2e/utils.ts b/packages/cli/src/__tests__/e2e/utils.ts index fe561fbdde..7a2251085c 100644 --- a/packages/cli/src/__tests__/e2e/utils.ts +++ b/packages/cli/src/__tests__/e2e/utils.ts @@ -5,4 +5,24 @@ export const clearStyle = (styled: string) => { ); }; +export const parseOutput = ( + outputs: string +): Array<{ id: string; data?: unknown, error?: unknown }> => { + const outputsArr = outputs.split(/-{35}[\t \n]+-{35}/); + return outputsArr.map((output) => { + output = output.replace(/-{35}/, ""); + const idIdx = output.indexOf("ID: "); + const dataIdx = output.indexOf("Data: "); + if (dataIdx !== -1) { + const id = output.substring(idIdx + 3, dataIdx - 1); + const data = output.substring(dataIdx + 6); + return { id: id.replace(/\s/g, ""), data: JSON.parse(data) }; + } else { + const errIdx = output.indexOf("Error: "); + const id = output.substring(idIdx + 3); + return { id: id.replace(/\s/g, ""), error: output.substring(errIdx + 7) }; + } + }); +}; + export const polywrapCli = `${__dirname}/../../../bin/polywrap`; diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index a01645efe0..1ac5735cf2 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -4,5 +4,5 @@ export * from "./codegen"; export * from "./create"; export * from "./deploy"; export * from "./plugin"; -export * from "./query"; export * from "./infra"; +export * from "./run"; diff --git a/packages/cli/src/commands/query.ts b/packages/cli/src/commands/query.ts deleted file mode 100644 index ec970f5822..0000000000 --- a/packages/cli/src/commands/query.ts +++ /dev/null @@ -1,188 +0,0 @@ -import { Command, Program } from "./types"; -import { - intlMsg, - parseClientConfigOption, - parseRecipeOutputFilePathOption, -} from "../lib"; - -import { PolywrapClient, PolywrapClientConfig } from "@polywrap/client-js"; -import gql from "graphql-tag"; -import path from "path"; -import yaml from "js-yaml"; -import fs from "fs"; - -type QueryCommandOptions = { - clientConfig: Partial; - outputFile?: string; - quiet?: boolean; -}; - -export const query: Command = { - setup: (program: Program) => { - program - .command("query") - .alias("q") - .description(intlMsg.commands_query_description()) - .argument("", intlMsg.commands_query_options_recipeScript()) - .option( - `-c, --client-config <${intlMsg.commands_query_options_configPath()}> `, - `${intlMsg.commands_query_options_config()}` - ) - .option( - `-o, --output-file <${intlMsg.commands_query_options_outputFilePath()}>`, - `${intlMsg.commands_query_options_outputFile()}` - ) - .option(`-q, --quiet`, `${intlMsg.commands_query_options_quiet()}`) - .action(async (recipe: string, options) => { - await run(recipe, { - ...options, - clientConfig: await parseClientConfigOption( - options.clientConfig, - undefined - ), - outputFile: options.outputFile - ? parseRecipeOutputFilePathOption(options.outputFile, undefined) - : undefined, - }); - }); - }, -}; - -async function run(recipePath: string, options: QueryCommandOptions) { - const { clientConfig, outputFile, quiet } = options; - const client = new PolywrapClient(clientConfig); - - function getParser(path: string) { - return path.endsWith(".yaml") || path.endsWith(".yml") - ? yaml.load - : JSON.parse; - } - - const recipe = getParser(recipePath)(fs.readFileSync(recipePath).toString()); - const dir = path.dirname(recipePath); - let uri = ""; - const recipeOutput = []; - - let constants: Record = {}; - for (const task of recipe) { - if (task.wrapper) { - uri = task.wrapper; - recipeOutput.push({ wrapper: task.wrapper }); - } - - if (task.constants) { - constants = getParser(task.constants)( - fs.readFileSync(path.join(dir, task.constants)).toString() - ); - recipeOutput.push({ constants: task.constants }); - } - - if (task.query) { - const query = fs.readFileSync(path.join(dir, task.query)).toString(); - - if (!query) { - const readFailMessage = intlMsg.commands_query_error_readFail({ - query: query ?? "undefined", - }); - console.error(readFailMessage); - process.exit(1); - } - - let variables: Record = {}; - - if (task.variables) { - const resolveObjectConstants = ( - constants: Record - ): Record => { - const output: Record = {}; - - Object.keys(constants).forEach((key: string) => { - output[key] = resolveConstant(constants[key]); - }); - - return output; - }; - - const resolveArrayConstants = (arr: unknown[]): unknown[] => { - return arr.map((item) => { - return resolveConstant(item); - }); - }; - - const resolveConstant = (constant: unknown): unknown => { - if (typeof constant === "string" && constant[0] === "$") { - return constants[constant.replace("$", "")]; - } else if (Array.isArray(constant)) { - return resolveArrayConstants(constant); - } else if (typeof constant === "object") { - return resolveObjectConstants(constant as Record); - } else { - return constant; - } - }; - - variables = resolveObjectConstants(task.variables); - } - - if (!uri) { - throw Error(intlMsg.commands_query_error_noWrapper()); - } - - if (!quiet) { - console.log("-----------------------------------"); - console.log(query); - console.log(JSON.stringify(variables, null, 2)); - console.log("-----------------------------------"); - } - - const { data, errors } = await client.query({ - uri, - query: gql(query), - variables, - }); - - if (outputFile) { - recipeOutput.push({ - query: task.query, - variables: task.variables, - output: { - data, - errors, - }, - }); - } - - if (!quiet && data && data !== {}) { - console.log("-----------------------------------"); - console.log(JSON.stringify(data, null, 2)); - console.log("-----------------------------------"); - } - - if (!quiet && errors) { - for (const error of errors) { - console.log("-----------------------------------"); - console.log(error.message); - console.log(error.stack || ""); - console.log("-----------------------------------"); - } - process.exitCode = 1; - } - } - - if (outputFile) { - const outputFileExt = path.extname(outputFile).substring(1); - if (!outputFileExt) throw new Error("Require output file extention"); - switch (outputFileExt) { - case "yaml": - case "yml": - fs.writeFileSync(outputFile, yaml.dump(recipeOutput)); - break; - case "json": - fs.writeFileSync(outputFile, JSON.stringify(recipeOutput)); - break; - default: - throw new Error(`Unsupported outputFile extention: ${outputFileExt}`); - } - } - } -} diff --git a/packages/cli/src/commands/run.ts b/packages/cli/src/commands/run.ts new file mode 100644 index 0000000000..66ba2f72a4 --- /dev/null +++ b/packages/cli/src/commands/run.ts @@ -0,0 +1,131 @@ +import { Command, Program } from "./types"; +import { + intlMsg, + parseClientConfigOption, + parseValidateScriptOption, + parseWorkflowOutputFilePathOption, + validateOutput, +} from "../lib"; + +import { InvokeResult, Workflow } from "@polywrap/core-js"; +import { PolywrapClient, PolywrapClientConfig } from "@polywrap/client-js"; +import path from "path"; +import yaml from "js-yaml"; +import fs from "fs"; + +type WorkflowCommandOptions = { + clientConfig: Partial; + jobs?: string[]; + validateScript?: string; + outputFile?: string; + quiet?: boolean; +}; + +export const run: Command = { + setup: (program: Program) => { + program + .command("run") + .alias("r") + .description(intlMsg.commands_run_description()) + .argument( + `<${intlMsg.commands_run_options_workflow()}>`, + intlMsg.commands_run_options_workflowScript() + ) + .option( + `-c, --client-config <${intlMsg.commands_run_options_configPath()}> `, + `${intlMsg.commands_run_options_config()}` + ) + .option( + `-v, --validate-script <${intlMsg.commands_run_options_validate()}>`, + `${intlMsg.commands_run_options_validateScript()}` + ) + .option( + `-o, --output-file <${intlMsg.commands_run_options_outputFilePath()}>`, + `${intlMsg.commands_run_options_outputFile()}` + ) + .option( + `-j, --jobs <${intlMsg.commands_run_options_jobIds()}...>`, + intlMsg.commands_run_options_jobs() + ) + .option(`-q, --quiet`, `${intlMsg.commands_run_options_quiet()}`) + .action(async (workflow: string, options) => { + await _run(workflow, { + ...options, + clientConfig: await parseClientConfigOption( + options.clientConfig, + undefined + ), + outputFile: options.outputFile + ? parseWorkflowOutputFilePathOption(options.outputFile, undefined) + : undefined, + validateScript: options.validateScript + ? parseValidateScriptOption(options.validateScript, undefined) + : undefined, + }); + }); + }, +}; + +const _run = async (workflowPath: string, options: WorkflowCommandOptions) => { + const { clientConfig, outputFile, validateScript, quiet, jobs } = options; + const client = new PolywrapClient(clientConfig); + + function getParser(path: string) { + return path.endsWith(".yaml") || path.endsWith(".yml") + ? yaml.load + : JSON.parse; + } + + const workflow: Workflow = getParser(workflowPath)( + fs.readFileSync(workflowPath).toString() + ); + const workflowOutput: (InvokeResult & { id: string })[] = []; + + await client.run({ + workflow, + config: clientConfig, + ids: jobs, + onExecution: async (id: string, data: unknown, error: Error) => { + if (!quiet) { + console.log("-----------------------------------"); + console.log(`ID: ${id}`); + } + + if (!quiet && data && data !== {}) { + console.log(`Data: ${JSON.stringify(data, null, 2)}`); + console.log("-----------------------------------"); + } + + if (!quiet && error) { + console.log(`Error: ${error.message}`); + console.log(error.stack || ""); + console.log("-----------------------------------"); + process.exitCode = 1; + } + + if (validateScript) { + await validateOutput(id, { data, error }, validateScript); + } + + workflowOutput.push({ id, data, error }); + }, + }); + + if (outputFile) { + const outputFileExt = path.extname(outputFile).substring(1); + if (!outputFileExt) throw new Error("Require output file extention"); + switch (outputFileExt) { + case "yaml": + case "yml": + fs.writeFileSync(outputFile, yaml.dump(workflowOutput)); + break; + case "json": + fs.writeFileSync(outputFile, JSON.stringify(workflowOutput, null, 2)); + break; + default: + throw new Error( + intlMsg.commands_run_error_unsupportedOutputFileExt({ outputFileExt }) + ); + } + } +}; diff --git a/packages/cli/src/lib/Compiler.ts b/packages/cli/src/lib/Compiler.ts index e519ee6206..1fefd3427d 100644 --- a/packages/cli/src/lib/Compiler.ts +++ b/packages/cli/src/lib/Compiler.ts @@ -292,7 +292,6 @@ export class Compiler { const useBuildx = !!dockerBuildxConfig; let cacheDir: string | undefined; - let buildxOutput: string | undefined; let removeBuilder = false; if (dockerBuildxConfig && typeof dockerBuildxConfig !== "boolean") { @@ -310,14 +309,6 @@ export class Compiler { } } - const output = dockerBuildxConfig.output; - - if (output === true) { - buildxOutput = "docker"; - } else if (typeof output === "string") { - buildxOutput = output; - } - removeBuilder = !!dockerBuildxConfig.removeBuilder; } @@ -334,7 +325,6 @@ export class Compiler { imageName, dockerfile, cacheDir, - buildxOutput, useBuildx, project.quiet ); diff --git a/packages/cli/src/lib/defaults/build-images/wasm/assemblyscript/Dockerfile.mustache b/packages/cli/src/lib/defaults/build-images/wasm/assemblyscript/Dockerfile.mustache index e7519b153c..e233c527ec 100644 --- a/packages/cli/src/lib/defaults/build-images/wasm/assemblyscript/Dockerfile.mustache +++ b/packages/cli/src/lib/defaults/build-images/wasm/assemblyscript/Dockerfile.mustache @@ -39,6 +39,5 @@ RUN ./node_modules/.bin/asc {{dir}}/wrap/entry.ts \ --use abort={{dir}}/wrap/entry/wrapAbort \ --optimize --importMemory \ --runtime stub \ - --runPasses asyncify \ - --transform @serial-as/transform + --runPasses asyncify {{/polywrap_module}} diff --git a/packages/cli/src/lib/helpers/index.ts b/packages/cli/src/lib/helpers/index.ts index a3485cc82d..6b07ba8337 100644 --- a/packages/cli/src/lib/helpers/index.ts +++ b/packages/cli/src/lib/helpers/index.ts @@ -4,3 +4,4 @@ export * from "./parameters"; export * from "./spinner"; export * from "./uuid"; export * from "./validate-client-config"; +export * from "./workflow-validator"; diff --git a/packages/cli/src/lib/helpers/validate-client-config.ts b/packages/cli/src/lib/helpers/validate-client-config.ts index 767007cfcd..06c47a6419 100644 --- a/packages/cli/src/lib/helpers/validate-client-config.ts +++ b/packages/cli/src/lib/helpers/validate-client-config.ts @@ -14,7 +14,7 @@ export function validateRedirects( redirects: UriRedirect[] ): void { if (!Array.isArray(redirects)) { - throw new Error(intlMsg.commands_query_error_redirectsExportNotArray()); + throw new Error(intlMsg.commands_run_error_redirectsExportNotArray()); } // Ensure each redirect in the array is valid @@ -23,19 +23,19 @@ export function validateRedirects( if (typeof redirect !== "object" || !redirect.from || !redirect.to) { throw new Error( - intlMsg.commands_query_error_redirectsItemNotValid({ + intlMsg.commands_run_error_redirectsItemNotValid({ index: i.toString(), }) ); } else if (typeof redirect.from !== "string") { throw new Error( - intlMsg.commands_query_error_redirectsItemFromNotString({ + intlMsg.commands_run_error_redirectsItemFromNotString({ index: i.toString(), }) ); } else if (typeof redirect.to !== "string") { throw new Error( - intlMsg.commands_query_error_redirectsItemToNotStringOrObject({ + intlMsg.commands_run_error_redirectsItemToNotStringOrObject({ index: i.toString(), }) ); @@ -47,7 +47,7 @@ export function validatePlugins( plugins: PluginRegistration[] ): void { if (!Array.isArray(plugins)) { - throw new Error(intlMsg.commands_query_error_pluginsExportNotArray()); + throw new Error(intlMsg.commands_run_error_pluginsExportNotArray()); } // Ensure each plugin in the array is valid @@ -55,31 +55,31 @@ export function validatePlugins( const plugin = plugins[i]; if (typeof plugin !== "object") { throw new Error( - intlMsg.commands_query_error_pluginsItemNotObject({ + intlMsg.commands_run_error_pluginsItemNotObject({ index: i.toString(), }) ); } else if (typeof plugin.uri !== "string") { throw new Error( - intlMsg.commands_query_error_pluginsItemUriNotString({ + intlMsg.commands_run_error_pluginsItemUriNotString({ index: i.toString(), }) ); } else if (typeof plugin.plugin !== "object") { throw new Error( - intlMsg.commands_query_error_pluginsItemPluginNotObject({ + intlMsg.commands_run_error_pluginsItemPluginNotObject({ index: i.toString(), }) ); } else if (typeof plugin.plugin.factory !== "function") { throw new Error( - intlMsg.commands_query_error_pluginsItemPluginFactoryNotFunction({ + intlMsg.commands_run_error_pluginsItemPluginFactoryNotFunction({ index: i.toString(), }) ); } else if (typeof plugin.plugin.manifest !== "object") { throw new Error( - intlMsg.commands_query_error_pluginsItemPluginManifestNotObject({ + intlMsg.commands_run_error_pluginsItemPluginManifestNotObject({ index: i.toString(), }) ); @@ -91,32 +91,32 @@ export function validateInterfaces( interfaces: InterfaceImplementations[] ): void { if (!Array.isArray(interfaces)) { - throw new Error(intlMsg.commands_query_error_interfacesExportNotArray()); + throw new Error(intlMsg.commands_run_error_interfacesExportNotArray()); } // Ensure each interface in the array is valid for (let i = 0; i < interfaces.length; ++i) { const interfaceImplementations = interfaces[i]; if (typeof interfaceImplementations !== "object") { throw new Error( - intlMsg.commands_query_error_interfacesItemNotObject({ + intlMsg.commands_run_error_interfacesItemNotObject({ index: i.toString(), }) ); } else if (typeof interfaceImplementations.interface !== "string") { throw new Error( - intlMsg.commands_query_error_interfacesItemInterfaceNotString({ + intlMsg.commands_run_error_interfacesItemInterfaceNotString({ index: i.toString(), }) ); } else if (!Array.isArray(interfaceImplementations.implementations)) { throw new Error( - intlMsg.commands_query_error_interfacesItemImplementationsNotArray({ + intlMsg.commands_run_error_interfacesItemImplementationsNotArray({ index: i.toString(), }) ); } else if (interfaceImplementations.implementations.length === 0) { throw new Error( - intlMsg.commands_query_error_interfacesItemImplementationsEmpty({ + intlMsg.commands_run_error_interfacesItemImplementationsEmpty({ index: i.toString(), }) ); @@ -125,7 +125,7 @@ export function validateInterfaces( const implementation = interfaceImplementations.implementations[j]; if (typeof implementation !== "string") { throw new Error( - intlMsg.commands_query_error_interfacesItemImplementationsItemNotString( + intlMsg.commands_run_error_interfacesItemImplementationsItemNotString( { index: i.toString(), implementationIndex: j.toString(), @@ -141,25 +141,25 @@ export function validateEnvs( envs: Env[] ): void { if (!Array.isArray(envs)) { - throw new Error(intlMsg.commands_query_error_envsExportNotArray()); + throw new Error(intlMsg.commands_run_error_envsExportNotArray()); } for (let i = 0; i < envs.length; ++i) { const env = envs[i]; if (typeof env !== "object") { throw new Error( - intlMsg.commands_query_error_envsItemNotObject({ + intlMsg.commands_run_error_envsItemNotObject({ index: i.toString(), }) ); } else if (typeof env.uri !== "string") { throw new Error( - intlMsg.commands_query_error_envsItemUriNotString({ + intlMsg.commands_run_error_envsItemUriNotString({ index: i.toString(), }) ); } else if (!env.env && typeof env.env !== "object") { throw new Error( - intlMsg.commands_query_error_envsItemModuleNotObject({ + intlMsg.commands_run_error_envsItemModuleNotObject({ index: i.toString(), }) ); @@ -171,7 +171,7 @@ export function validateClientConfig( config: Partial ): void { if (!config || typeof config !== "object") { - throw new Error(intlMsg.commands_query_error_clientConfigNotObject()); + throw new Error(intlMsg.commands_run_error_clientConfigNotObject()); } if (config.plugins) validatePlugins(config.plugins); if (config.envs) validateEnvs(config.envs); diff --git a/packages/cli/src/lib/helpers/workflow-validator.ts b/packages/cli/src/lib/helpers/workflow-validator.ts new file mode 100644 index 0000000000..c28b3cdcef --- /dev/null +++ b/packages/cli/src/lib/helpers/workflow-validator.ts @@ -0,0 +1,44 @@ +import { runCommand } from "../system"; + +import fs from "fs"; +import { InvokeResult } from "@polywrap/core-js"; + +const TMPDIR = process.env.TMPDIR || "/tmp"; + +export async function cueExists(): Promise { + try { + const { stdout } = await runCommand("cue version"); + return stdout.startsWith("cue version "); + } catch (e) { + return false; + } +} + +export async function validateOutput( + id: string, + result: InvokeResult, + validateScriptPath: string +): Promise { + const index = id.lastIndexOf("."); + const jobId = id.substring(0, index); + const stepId = id.substring(index + 1); + + const selector = `${jobId}.\\$${stepId}`; + const jsonOutput = `${TMPDIR}/${id}.json`; + + await fs.promises.writeFile(jsonOutput, JSON.stringify(result, null, 2)); + + try { + await runCommand( + `cue vet -d ${selector} ${validateScriptPath} ${jsonOutput}` + ); + } catch (e) { + console.error(e.message); + console.log("-----------------------------------"); + process.exitCode = 1; + } + + if (fs.existsSync(jsonOutput)) { + await fs.promises.unlink(jsonOutput); + } +} diff --git a/packages/cli/src/lib/option-parsers/index.ts b/packages/cli/src/lib/option-parsers/index.ts index f1b70a6297..f954637a56 100644 --- a/packages/cli/src/lib/option-parsers/index.ts +++ b/packages/cli/src/lib/option-parsers/index.ts @@ -3,4 +3,4 @@ export * from "./build"; export * from "./codegen"; export * from "./wasm"; export * from "./plugin"; -export * from "./query"; +export * from "./run"; diff --git a/packages/cli/src/lib/option-parsers/query.ts b/packages/cli/src/lib/option-parsers/run.ts similarity index 77% rename from packages/cli/src/lib/option-parsers/query.ts rename to packages/cli/src/lib/option-parsers/run.ts index cfe529364d..873e8e5c92 100644 --- a/packages/cli/src/lib/option-parsers/query.ts +++ b/packages/cli/src/lib/option-parsers/run.ts @@ -8,14 +8,14 @@ import fs from "fs"; import { PolywrapClientConfig } from "@polywrap/client-js"; import { executeMaybeAsyncFunction } from "@polywrap/core-js"; -export function parseRecipeScriptPathOption( +export function parseWorkflowScriptPathOption( script: string, _: unknown ): string { const absPath = path.resolve(script); if (!fs.existsSync(absPath)) { throw new Error( - intlMsg.commands_query_error_noRecipeScriptFound({ path: absPath }) + intlMsg.commands_run_error_noWorkflowScriptFound({ path: absPath }) ); } return absPath; @@ -30,7 +30,7 @@ export async function parseClientConfigOption( try { finalClientConfig = await getTestEnvClientConfig(); } catch (e) { - console.error(intlMsg.commands_query_error_noTestEnvFound()); + console.error(intlMsg.commands_run_error_noTestEnvFound()); process.exit(1); } @@ -43,7 +43,7 @@ export async function parseClientConfigOption( } else if (configPath.endsWith(".ts")) { configModule = await importTypescriptModule(path.resolve(configPath)); } else { - const configsModuleMissingExportMessage = intlMsg.commands_query_error_clientConfigInvalidFileExt( + const configsModuleMissingExportMessage = intlMsg.commands_run_error_clientConfigInvalidFileExt( { module: configPath } ); console.error(configsModuleMissingExportMessage); @@ -51,7 +51,7 @@ export async function parseClientConfigOption( } if (!configModule || !configModule.getClientConfig) { - const configsModuleMissingExportMessage = intlMsg.commands_query_error_clientConfigModuleMissingExport( + const configsModuleMissingExportMessage = intlMsg.commands_run_error_clientConfigModuleMissingExport( { module: configModule } ); console.error(configsModuleMissingExportMessage); @@ -80,9 +80,24 @@ export async function defaultClientConfigOption(): Promise< return await parseClientConfigOption(undefined, undefined); } -export function parseRecipeOutputFilePathOption( +export function parseWorkflowOutputFilePathOption( outputFile: string, _: unknown ): string { return path.resolve(outputFile); } + +export function parseValidateScriptOption(cueFile: string, _: unknown): string { + const cueFilepath = path.resolve(cueFile); + + if (!fs.existsSync(cueFilepath)) { + console.error( + intlMsg.commands_run_error_validatorNotFound({ + path: cueFilepath, + }) + ); + process.exit(1); + } + + return cueFilepath; +} diff --git a/packages/cli/src/lib/system/docker.ts b/packages/cli/src/lib/system/docker.ts index 89630acd07..b41dc05218 100644 --- a/packages/cli/src/lib/system/docker.ts +++ b/packages/cli/src/lib/system/docker.ts @@ -118,7 +118,6 @@ export async function createBuildImage( imageName: string, dockerfile: string, cacheDir?: string, - buildxOutput?: string, useBuildx = false, quiet = true ): Promise { @@ -131,9 +130,6 @@ export async function createBuildImage( ? `--cache-from type=local,src=${cacheDir}` : ""; const cacheTo = cacheDir ? `--cache-to type=local,dest=${cacheDir}` : ""; - const output = buildxOutput - ? `--output=type=${buildxOutput}` - : `--output=type=docker`; // Build the docker image let buildxUseFailed: boolean; @@ -151,7 +147,7 @@ export async function createBuildImage( ); } await runCommand( - `docker buildx build -f ${dockerfile} -t ${imageName} ${rootDir} ${cacheFrom} ${cacheTo} ${output}`, + `docker buildx build -f ${dockerfile} -t ${imageName} ${rootDir} ${cacheFrom} ${cacheTo} --output=type=docker`, quiet ); } else { diff --git a/packages/js/client/src/__tests__/e2e/test-cases.ts b/packages/js/client/src/__tests__/e2e/test-cases.ts index 52d8c0de63..39493c523a 100644 --- a/packages/js/client/src/__tests__/e2e/test-cases.ts +++ b/packages/js/client/src/__tests__/e2e/test-cases.ts @@ -632,40 +632,68 @@ export const runJsonTypeTest = async ( client: PolywrapClient, uri: string ) => { - const fromJson = await client.invoke<{ x: number; y: number }>({ + type Json = string; + const value = JSON.stringify({ foo: "bar", bar: "bar" }) + const parseResponse = await client.invoke<{ parse: Json }>({ uri, - method: "fromJson", + method: "parse", input: { - json: JSON.stringify({ x: 1, y: 2 }), - }, - }); + value + } + }) - expect(fromJson.error).toBeFalsy(); - expect(fromJson.data).toBeTruthy(); - expect(fromJson.data).toMatchObject({ - x: 1, - y: 2, - }); + expect(parseResponse.data).toEqual(value); + + const values = [ + JSON.stringify({ bar: "foo" }), + JSON.stringify({ baz: "fuz" }), + ]; - const toJson = await client.invoke<{ str: string }>({ + const stringifyResponse = await client.invoke<{ stringify: Json}>({ uri, - method: "toJson", + method: "stringify", input: { - pair: { - x: 1, - y: 2, - }, + values + } + }) + + expect(stringifyResponse.data).toEqual(values.join("")); + + const object = { + jsonA: JSON.stringify({ foo: "bar" }), + jsonB: JSON.stringify({ fuz: "baz" }), + }; + + const stringifyObjectResponse = await client.invoke<{ + stringifyObject: string; + }>({ + uri, + method: "stringifyObject", + input: { + object, }, }); - expect(toJson.error).toBeFalsy(); - expect(toJson.data).toBeTruthy(); - expect(toJson.data).toBe( - JSON.stringify({ - x: 1, - y: 2, - }) + expect(stringifyObjectResponse.data).toEqual( + object.jsonA + object.jsonB ); + + const json = { + valueA: 5, + valueB: "foo", + valueC: true + } + + const methodJSONResponse = await client.invoke<{ + methodJSON: Json; + }>({ + uri, + method: "methodJSON", + input: json + }); + + const methodJSONResult = JSON.stringify(json); + expect(methodJSONResponse.data).toEqual(methodJSONResult); }; export const runLargeTypesTest = async ( diff --git a/packages/js/core/src/manifest/formats/polywrap.build/0.0.1-prealpha.3.ts b/packages/js/core/src/manifest/formats/polywrap.build/0.0.1-prealpha.3.ts index 4f4655d5aa..640fa904bd 100644 --- a/packages/js/core/src/manifest/formats/polywrap.build/0.0.1-prealpha.3.ts +++ b/packages/js/core/src/manifest/formats/polywrap.build/0.0.1-prealpha.3.ts @@ -33,10 +33,6 @@ export interface BuildManifest { * Path to cache directory, set to true for default value, set to false to disable caching. */ cache?: string | boolean; - /** - * Path to cache directory, set to true or false for default value. - */ - output?: string | boolean; /** * Remove the builder instance. */ diff --git a/packages/js/core/src/manifest/formats/polywrap.build/validate.ts b/packages/js/core/src/manifest/formats/polywrap.build/validate.ts index ffa751200f..ca7d90c93c 100644 --- a/packages/js/core/src/manifest/formats/polywrap.build/validate.ts +++ b/packages/js/core/src/manifest/formats/polywrap.build/validate.ts @@ -38,7 +38,6 @@ Validator.prototype.customFormats.dockerfileName = Validators.dockerfileName; Validator.prototype.customFormats.dockerImageId = Validators.dockerImageId; Validator.prototype.customFormats.regexString = Validators.regexString; Validator.prototype.customFormats.directory = Validators.directory; -Validator.prototype.customFormats.buildxOutput = Validators.buildxOutput; export const validateBuildManifest = Tracer.traceFunc( "core: validateBuildManifest", diff --git a/packages/js/core/src/manifest/validators.ts b/packages/js/core/src/manifest/validators.ts index 066e0499da..667bd1204e 100644 --- a/packages/js/core/src/manifest/validators.ts +++ b/packages/js/core/src/manifest/validators.ts @@ -140,19 +140,3 @@ export function directory(path: unknown): boolean { return !!validDirRegex.test(path); } - -export function buildxOutput(output: unknown): boolean { - if (typeof output === "boolean") { - return true; - } - if (typeof output !== "string") { - return false; - } - switch (output) { - case "docker": - case "registry": - return true; - default: - return false; - } -} diff --git a/packages/js/react/src/__tests__/usePolywrapInvoke.spec.tsx b/packages/js/react/src/__tests__/usePolywrapInvoke.spec.tsx index 4d47dbacd4..347c8659d5 100644 --- a/packages/js/react/src/__tests__/usePolywrapInvoke.spec.tsx +++ b/packages/js/react/src/__tests__/usePolywrapInvoke.spec.tsx @@ -82,7 +82,6 @@ describe("usePolywrapInvoke hook", () => { ) { const hook = () => usePolywrapInvoke({ uri: options.uri, - module: options.module, method: options.method, provider: options.provider }); @@ -101,7 +100,6 @@ describe("usePolywrapInvoke hook", () => { it("Should support passing env to client", async () => { const deployQuery: UsePolywrapInvokeProps = { uri: envUri, - module: "query", method: "getEnv", input: { arg: "Alice" @@ -130,7 +128,6 @@ describe("usePolywrapInvoke hook", () => { it("Should update storage data to five", async () => { const deployInvoke: UsePolywrapInvokeProps = { uri, - module: "mutation", method: "deployContract", input: { connection: { @@ -143,7 +140,6 @@ describe("usePolywrapInvoke hook", () => { const setStorageInvocation: UsePolywrapInvokeProps = { uri, - module: "mutation", method: "setData", input: { address: address, @@ -160,7 +156,6 @@ describe("usePolywrapInvoke hook", () => { const getStorageDataInvocation: UsePolywrapInvokeProps = { uri, - module: "query", method: "getData", input: { address: address, @@ -178,7 +173,6 @@ describe("usePolywrapInvoke hook", () => { const getStorageDataInvocation: UsePolywrapInvokeProps = { provider: "Non existent Polywrap Provider", uri, - module: "query", method: "getData", input: { address: "foo", @@ -199,7 +193,6 @@ describe("usePolywrapInvoke hook", () => { const getStorageDataInvocation: UsePolywrapInvokeProps = { provider: "other", uri, - module: "query", method: "getData", input: { address: "foo", @@ -217,7 +210,6 @@ describe("usePolywrapInvoke hook", () => { it("Should update storage data to three by setting value through variables passed to exec", async () => { const deployInvoke: UsePolywrapInvokeProps = { uri, - module: "mutation", method: "deployContract", input: { connection: { @@ -230,7 +222,6 @@ describe("usePolywrapInvoke hook", () => { const setStorageInvocation: UsePolywrapInvokeProps = { uri, - module: "mutation", method: "setData", input: { address: address, @@ -247,7 +238,6 @@ describe("usePolywrapInvoke hook", () => { const getStorageDataInvocation: UsePolywrapInvokeProps = { uri, - module: "query", method: "getData", input: { address: address, diff --git a/packages/js/test-env/src/index.ts b/packages/js/test-env/src/index.ts index ab6874e950..d73341954b 100644 --- a/packages/js/test-env/src/index.ts +++ b/packages/js/test-env/src/index.ts @@ -23,7 +23,7 @@ export const providers = { }; const monorepoCli = `${__dirname}/../../../cli/bin/polywrap`; -const npmCli = `${__dirname}/../../polywrap/bin/polywrap`; +const npmCli = `${__dirname}/../../../polywrap/bin/polywrap`; async function awaitResponse( url: string, @@ -67,6 +67,12 @@ export const initTestEnvironment = async (cli?: string): Promise => { cli, }); + if (exitCode) { + throw Error( + `initTestEnvironment failed to start test environment.\nExit Code: ${exitCode}\nStdErr: ${stderr}\nStdOut: ${stdout}` + ); + } + // Wait for all endpoints to become available let success = false; @@ -97,14 +103,19 @@ export const initTestEnvironment = async (cli?: string): Promise => { throw Error("test-env: Ganache failed to start"); } - if (exitCode) { - throw Error( - `initTestEnvironment failed to start test environment.\nExit Code: ${exitCode}\nStdErr: ${stderr}\nStdOut: ${stdout}` - ); - } + // ENS + success = await awaitResponse( + "http://localhost:8545", + '"result":"0x', + "post", + 2000, + 20000, + `{"jsonrpc":"2.0","method":"eth_getCode","params":["${ensAddresses.ensAddress}", "0x2"],"id":1}` + ); - // Wait an extra couple of seconds for the ens deployment to finish - await new Promise((resolve) => setTimeout(resolve, 3000)); + if (!success) { + throw Error("test-env: ENS failed to deploy"); + } }; export const stopTestEnvironment = async (cli?: string): Promise => { diff --git a/packages/manifest-schemas/formats/polywrap.build/0.0.1-prealpha.3.json b/packages/manifest-schemas/formats/polywrap.build/0.0.1-prealpha.3.json index 5b7b5bda19..081d963775 100644 --- a/packages/manifest-schemas/formats/polywrap.build/0.0.1-prealpha.3.json +++ b/packages/manifest-schemas/formats/polywrap.build/0.0.1-prealpha.3.json @@ -38,11 +38,6 @@ "type": ["string", "boolean"], "format": "directory" }, - "output": { - "description": "Path to cache directory, set to true or false for default value.", - "type": ["string", "boolean"], - "format": "buildxOutput" - }, "removeBuilder": { "description": "Remove the builder instance.", "type": "boolean" diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/functions.ts b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/functions.ts index c8037e8545..1591b78e61 100644 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/functions.ts +++ b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/functions.ts @@ -50,13 +50,14 @@ export const toWasmInit: MustacheFn = () => { type = type.substring(0, type.length - 1); } else { const nullType = toWasm()(value, render); - const nullable = "Nullable"; + const nullable = "Option"; const nullOptional = "| null"; if (nullType.endsWith(nullOptional)) { return "null"; } else if (nullType.startsWith(nullable)) { - return `new ${nullType}()`; + type = nullType.substring(6); + return `Option.None${type}()`; } } @@ -227,7 +228,7 @@ const applyNullable = ( ) { return `${type} | null`; } else { - return `Nullable<${type}>`; + return `Option<${type}>`; } } else { return type; diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/deserialize_enum.mustache b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/deserialize_enum.mustache index 25ce5f5664..390ae595c0 100644 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/deserialize_enum.mustache +++ b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/deserialize_enum.mustache @@ -8,19 +8,19 @@ if (reader.isNextString()) { } {{/required}} {{^required}} -let value: Nullable; +let value: Option; if (!reader.isNextNil()) { if (reader.isNextString()) { - value = Nullable.fromValue( + value = Option.Some( Types.get{{type}}Value(reader.readString()) ); } else { - value = Nullable.fromValue( + value = Option.Some( reader.readInt32() ); - Types.sanitize{{type}}Value(value.value); + Types.sanitize{{type}}Value(value.unwrap()); } } else { - value = Nullable.fromNull(); + value = Option.None(); } {{/required}} diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/module-type/index-ts.mustache b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/module-type/index-ts.mustache index 1b2b569b9a..af1dfb53fa 100644 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/module-type/index-ts.mustache +++ b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/module-type/index-ts.mustache @@ -1,7 +1,7 @@ import { wrap_subinvoke, wrap_subinvokeImplementation, - Nullable, + Option, BigInt, BigNumber, JSON, diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/module-type/serialization-ts.mustache b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/module-type/serialization-ts.mustache index cbeab27539..842613e064 100644 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/module-type/serialization-ts.mustache +++ b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/module-type/serialization-ts.mustache @@ -70,7 +70,7 @@ export function write{{name}}Args( } export function deserialize{{name}}Result(buffer: ArrayBuffer): {{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}} { - const context: Context = new Context("Deserializing imported module-type: {{name}}"); + const context: Context = new Context("Deserializing imported module-type: {{name}}"); const reader = new ReadDecoder(buffer, context); {{#return}} diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/object-type/index-ts.mustache b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/object-type/index-ts.mustache index ab841d2923..114f2736cc 100644 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/object-type/index-ts.mustache +++ b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/imported/object-type/index-ts.mustache @@ -1,12 +1,10 @@ import { Read, Write, - Nullable, + Option, BigInt, BigNumber, - JSON, - JSONSerializer, - JSONDeserializer, + JSON } from "@polywrap/wasm-as"; import { serialize{{type}}, @@ -16,7 +14,6 @@ import { } from "./serialization"; import * as Types from "../.."; -@serializable export class {{type}} { public static uri: string = "{{uri}}"; @@ -40,6 +37,4 @@ export class {{type}} { static read(reader: Read): {{type}} { return read{{type}}(reader); } - - {{> json_methods}} } diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/json_methods.mustache b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/json_methods.mustache deleted file mode 100644 index baa2597301..0000000000 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/json_methods.mustache +++ /dev/null @@ -1,7 +0,0 @@ -static toJson(type: {{type}}): JSON.Value { - return JSONSerializer.encode(type); -} - -static fromJson(json: JSON.Value): {{type}} { - return (new JSONDeserializer(json)).decode<{{type}}>(); -} diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/module-type/serialization-ts.mustache b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/module-type/serialization-ts.mustache index e4ff00abd7..f4a4b0c88e 100644 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/module-type/serialization-ts.mustache +++ b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/module-type/serialization-ts.mustache @@ -9,7 +9,7 @@ export class Input_{{name}} { } export function deserialize{{name}}Args(argsBuf: ArrayBuffer): Input_{{name}} { - const context: Context = new Context("Deserializing module-type: {{name}}"); + const context: Context = new Context("Deserializing module-type: {{name}}"); {{#arguments.length}} const reader = new ReadDecoder(argsBuf, context); let numFields = reader.readMapLength(); diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/object-type/index-ts.mustache b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/object-type/index-ts.mustache index 9bdd689ad6..816008171a 100644 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/object-type/index-ts.mustache +++ b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/object-type/index-ts.mustache @@ -1,12 +1,10 @@ import { Read, Write, - Nullable, + Option, BigInt, BigNumber, - JSON, - JSONSerializer, - JSONDeserializer, + JSON } from "@polywrap/wasm-as"; import { serialize{{type}}, @@ -16,7 +14,6 @@ import { } from "./serialization"; import * as Types from ".."; -@serializable export class {{type}} { {{#properties}} {{#handleKeywords}}{{name}}{{/handleKeywords}}: {{#toWasm}}{{toGraphQLType}}{{/toWasm}}; @@ -37,6 +34,4 @@ export class {{type}} { static read(reader: Read): {{type}} { return read{{type}}(reader); } - - {{> json_methods}} } diff --git a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/serialization_imports.mustache b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/serialization_imports.mustache index 8aeb5aa792..9ded19f5d4 100644 --- a/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/serialization_imports.mustache +++ b/packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/serialization_imports.mustache @@ -4,7 +4,7 @@ import { Write, WriteSizer, WriteEncoder, - Nullable, + Option, BigInt, BigNumber, JSON, diff --git a/packages/templates/app/typescript-node/polywrap.app.yaml b/packages/templates/app/typescript-node/polywrap.app.yaml new file mode 100644 index 0000000000..bbed2041c9 --- /dev/null +++ b/packages/templates/app/typescript-node/polywrap.app.yaml @@ -0,0 +1,3 @@ +format: 0.0.1-prealpha.1 +language: app/typescript +schema: ./schema.graphql diff --git a/packages/templates/run-tests.ts b/packages/templates/run-tests.ts index 2160faff36..bdd38afc7c 100644 --- a/packages/templates/run-tests.ts +++ b/packages/templates/run-tests.ts @@ -14,19 +14,19 @@ const languageTestCommands: Record = { "yarn test" ], "typescript-node": [ - // Add this back once new toolchain version is released - /*"yarn build", - "yarn test"*/ + // Uncomment when the helloworld wrapper has been deployed to polywrap.eth + // "yarn build", + // "yarn test" ], "typescript-react": [ - // Add this back once new toolchain version is released + // Uncomment when the helloworld wrapper has been deployed to polywrap.eth // "CI=false yarn build" ], "assemblyscript": [ - // Add this back once new toolchain version is released - /*"yarn build", - "yarn test:e2e", - "yarn test:recipe"*/ + // Uncomment when the wasm/as package has been redeployed + // "yarn build", + // "yarn test:e2e" + // "yarn test:workflow" ], "interface": [ "yarn build" diff --git a/packages/templates/wasm/assemblyscript/README.md b/packages/templates/wasm/assemblyscript/README.md index 19c4da62d8..58bc0b0d11 100644 --- a/packages/templates/wasm/assemblyscript/README.md +++ b/packages/templates/wasm/assemblyscript/README.md @@ -11,4 +11,5 @@ A simple starter template that uses a SimpleStorage.sol contract ethereum. For m `yarn build` ## Test -`yarn test` +`yarn test:e2e` +`yarn test:workflow` diff --git a/packages/templates/wasm/assemblyscript/package.json b/packages/templates/wasm/assemblyscript/package.json index 0ef4baca56..a70b42977d 100644 --- a/packages/templates/wasm/assemblyscript/package.json +++ b/packages/templates/wasm/assemblyscript/package.json @@ -9,13 +9,10 @@ "build:contract": "node ./scripts/build-contract.js", "test:env:up": "npx polywrap infra up --modules=eth-ens-ipfs", "test:env:down": "npx polywrap infra down --modules=eth-ens-ipfs", - "deploy": "yarn deploy:contract && yarn deploy:polywrap", - "deploy:polywrap": "npx polywrap deploy", - "deploy:contract": "node ./scripts/deploy-contract.js", - "test": "yarn test:e2e && yarn test:recipe", + "deploy": "npx polywrap deploy", "test:e2e": "yarn build && yarn test:e2e:codegen && jest --passWithNoTests --runInBand --verbose", "test:e2e:codegen": "npx polywrap app codegen -m ./src/__tests__/types/polywrap.app.yaml -c ./src/__tests__/types/wrap", - "test:recipe": "yarn build && yarn test:env:up && yarn deploy:contract && npx polywrap query ./recipes/e2e.json && yarn test:env:down" + "test:workflow": "yarn build && yarn test:env:up && sleep 5 && npx polywrap run ./workflows/e2e.yaml && yarn test:env:down" }, "devDependencies": { "@polywrap/ethereum-plugin-js": "0.0.1-prealpha.88", diff --git a/packages/templates/wasm/assemblyscript/recipes/constants.json b/packages/templates/wasm/assemblyscript/recipes/constants.json deleted file mode 100644 index 5c7119e4a6..0000000000 --- a/packages/templates/wasm/assemblyscript/recipes/constants.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "SimpleStorageAddr": "0x9b1f7F645351AF3631a656421eD2e40f2802E6c0" -} \ No newline at end of file diff --git a/packages/templates/wasm/assemblyscript/recipes/e2e.json b/packages/templates/wasm/assemblyscript/recipes/e2e.json deleted file mode 100644 index 33aeabdfce..0000000000 --- a/packages/templates/wasm/assemblyscript/recipes/e2e.json +++ /dev/null @@ -1,43 +0,0 @@ -[ - { - "wrapper": "wrap://fs/./build", - "constants": "./constants.json" - }, - { - "query": "./get.graphql", - "variables": { - "address": "$SimpleStorageAddr", - "network": "testnet" - } - }, - { - "query": "./set.graphql", - "variables": { - "address": "$SimpleStorageAddr", - "value": 5, - "network": "testnet" - } - }, - { - "query": "./get.graphql", - "variables": { - "address": "$SimpleStorageAddr", - "network": "testnet" - } - }, - { - "query": "./set.graphql", - "variables": { - "address": "$SimpleStorageAddr", - "value": 569, - "network": "testnet" - } - }, - { - "query": "./get.graphql", - "variables": { - "address": "$SimpleStorageAddr", - "network": "testnet" - } - } -] diff --git a/packages/templates/wasm/assemblyscript/recipes/get.graphql b/packages/templates/wasm/assemblyscript/recipes/get.graphql deleted file mode 100644 index ce22f136be..0000000000 --- a/packages/templates/wasm/assemblyscript/recipes/get.graphql +++ /dev/null @@ -1,8 +0,0 @@ -query GetData($address: String!) { - getData( - address: $address - connection: { - networkNameOrChainId: $network - } - ) -} diff --git a/packages/templates/wasm/assemblyscript/recipes/set.graphql b/packages/templates/wasm/assemblyscript/recipes/set.graphql deleted file mode 100644 index d5c8f9a896..0000000000 --- a/packages/templates/wasm/assemblyscript/recipes/set.graphql +++ /dev/null @@ -1,9 +0,0 @@ -mutation SetData($address: String!, $value: Int!) { - setData( - address: $address - value: $value - connection: { - networkNameOrChainId: $network - } - ) -} diff --git a/packages/templates/wasm/assemblyscript/scripts/deploy-contract.js b/packages/templates/wasm/assemblyscript/scripts/deploy-contract.js deleted file mode 100644 index 471d10c40c..0000000000 --- a/packages/templates/wasm/assemblyscript/scripts/deploy-contract.js +++ /dev/null @@ -1,60 +0,0 @@ -const buildContract = require("./build-contract"); -const { initTestEnvironment, stopTestEnvironment, providers } = require("@polywrap/test-env-js"); -const { EthereumPlugin } = require("@polywrap/ethereum-plugin-js"); -const fs = require("fs"); - -async function main() { - // Ensure the contract is built - await buildContract.main(); - await initTestEnvironment() - // Fetch the contract's ABI - const contractAbi = JSON.parse( - fs.readFileSync( - `${__dirname}/../src/contracts/SimpleStorage.json`, 'utf-8' - ) - ); - - // Deploy the contract to testnet - const eth = new EthereumPlugin({ - networks: { - testnet: { - provider: providers.ethereum - }, - }, - }); - - const address = await eth.deployContract({ - abi: contractAbi.abi, - bytecode: contractAbi.bytecode, - args: [], - connection: { - networkNameOrChainId: "testnet" - } - }); - - console.log(`✔️ SimpleStorage live at: ${address}`) - - // Store the address in our recipes' constants file - const constants = require(`${__dirname}/../recipes/constants.json`); - constants.SimpleStorageAddr = address; - fs.writeFileSync( - `${__dirname}/../recipes/constants.json`, - JSON.stringify(constants, null, 2) - ); - - console.log("✔️ Recipe Constants Updated"); -} - -if (require.main === module) { - main() - .then(() => process.exit(0)) - .catch(async (error) => { - await stopTestEnvironment() - console.error(error); - process.exit(1); - }); -} else { - module.exports = { - main - }; -} diff --git a/packages/templates/wasm/assemblyscript/workflows/config.ts b/packages/templates/wasm/assemblyscript/workflows/config.ts new file mode 100644 index 0000000000..3d5497795c --- /dev/null +++ b/packages/templates/wasm/assemblyscript/workflows/config.ts @@ -0,0 +1,77 @@ +import { PolywrapClientConfig } from "@polywrap/client-js"; +import { ClientConfig, coreInterfaceUris } from "@polywrap/client-js"; +import { ensPlugin } from "@polywrap/ens-plugin-js"; +import { ethereumPlugin } from "@polywrap/ethereum-plugin-js"; +import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; + +interface TestEnvironment { + ipfs: string; + ethereum: string; + ensAddress: string; + registrarAddress?: string; + reverseAddress?: string; + resolverAddress?: string; +} + +async function getProviders(): Promise { + const ipfs = "http://localhost:5001"; + const ethereum = "http://localhost:8545"; + const ensAddress = "0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab"; + + return { ipfs, ethereum, ensAddress }; +} + +function getPlugins( + ethereum: string, + ipfs: string, + ensAddress: string +): Partial { + return { + redirects: [], + plugins: [ + { + uri: "wrap://ens/ipfs.polywrap.eth", + plugin: ipfsPlugin({ provider: ipfs }), + }, + { + uri: "wrap://ens/ens.polywrap.eth", + plugin: ensPlugin({ addresses: { testnet: ensAddress } }), + }, + { + uri: "wrap://ens/ethereum.polywrap.eth", + plugin: ethereumPlugin({ + networks: { + testnet: { + provider: ethereum, + }, + MAINNET: { + provider: "http://localhost:8546", + }, + }, + defaultNetwork: "testnet", + }), + }, + ], + interfaces: [ + { + interface: coreInterfaceUris.uriResolver.uri, + implementations: [ + "wrap://ens/ipfs.polywrap.eth", + "wrap://ens/ens.polywrap.eth", + ], + }, + { + interface: coreInterfaceUris.logger.uri, + implementations: ["wrap://ens/js-logger.polywrap.eth"], + }, + ], + }; +} + +export async function getClientConfig( + _: Partial +): Promise> { + const { ipfs, ethereum, ensAddress } = await getProviders(); + + return getPlugins(ethereum, ipfs, ensAddress); +} diff --git a/packages/templates/wasm/assemblyscript/workflows/e2e.yaml b/packages/templates/wasm/assemblyscript/workflows/e2e.yaml new file mode 100644 index 0000000000..5ed90fa0db --- /dev/null +++ b/packages/templates/wasm/assemblyscript/workflows/e2e.yaml @@ -0,0 +1,25 @@ +name: simple-storage +jobs: + cases: + steps: + - uri: fs/build + method: deployContract + input: + connection: + networkNameOrChainId: testnet + jobs: + case1: + steps: + - uri: fs/build + method: setData + input: + address: "$cases.0.data" + value: 100 + connection: + networkNameOrChainId: testnet + - uri: fs/build + method: getData + input: + address: "$cases.0.data" + connection: + networkNameOrChainId: testnet diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/AnotherType/index.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/AnotherType/index.ts index cd97ce73c5..ccc0df709d 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/AnotherType/index.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/AnotherType/index.ts @@ -1,12 +1,10 @@ import { Read, Write, - Nullable, + Option, BigInt, BigNumber, - JSON, - JSONSerializer, - JSONDeserializer, + JSON } from "@polywrap/wasm-as"; import { serializeAnotherType, @@ -16,7 +14,6 @@ import { } from "./serialization"; import * as Types from ".."; -@serializable export class AnotherType { prop: string | null; circular: Types.CustomType | null; @@ -37,12 +34,4 @@ export class AnotherType { static read(reader: Read): AnotherType { return readAnotherType(reader); } - - static toJson(type: AnotherType): JSON.Value { - return JSONSerializer.encode(type); - } - - static fromJson(json: JSON.Value): AnotherType { - return (new JSONDeserializer(json)).decode(); - } } diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/AnotherType/serialization.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/AnotherType/serialization.ts index f29e52aad3..ed4fbeff94 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/AnotherType/serialization.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/AnotherType/serialization.ts @@ -4,7 +4,7 @@ import { Write, WriteSizer, WriteEncoder, - Nullable, + Option, BigInt, BigNumber, JSON, diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/CustomType/index.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/CustomType/index.ts index 0edc7a7894..bd8207ae10 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/CustomType/index.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/CustomType/index.ts @@ -1,12 +1,10 @@ import { Read, Write, - Nullable, + Option, BigInt, BigNumber, - JSON, - JSONSerializer, - JSONDeserializer, + JSON } from "@polywrap/wasm-as"; import { serializeCustomType, @@ -16,12 +14,11 @@ import { } from "./serialization"; import * as Types from ".."; -@serializable export class CustomType { str: string; optStr: string | null; u: u32; - optU: Nullable; + optU: Option; m_u8: u8; m_u16: u16; m_u32: u32; @@ -38,13 +35,13 @@ export class CustomType { bytes: ArrayBuffer; optBytes: ArrayBuffer | null; m_boolean: bool; - optBoolean: Nullable; + optBoolean: Option; uArray: Array; uOptArray: Array | null; - optUOptArray: Array> | null; + optUOptArray: Array> | null; optStrOptArray: Array | null; uArrayArray: Array>; - uOptArrayOptArray: Array> | null>; + uOptArrayOptArray: Array> | null>; uArrayOptArrayArray: Array> | null>; crazyArray: Array | null>> | null> | null; object: Types.AnotherType; @@ -52,9 +49,9 @@ export class CustomType { objectArray: Array; optObjectArray: Array | null; en: Types.CustomEnum; - optEnum: Nullable; + optEnum: Option; enumArray: Array; - optEnumArray: Array> | null; + optEnumArray: Array> | null; static toBuffer(type: CustomType): ArrayBuffer { return serializeCustomType(type); @@ -71,12 +68,4 @@ export class CustomType { static read(reader: Read): CustomType { return readCustomType(reader); } - - static toJson(type: CustomType): JSON.Value { - return JSONSerializer.encode(type); - } - - static fromJson(json: JSON.Value): CustomType { - return (new JSONDeserializer(json)).decode(); - } } diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/CustomType/serialization.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/CustomType/serialization.ts index 2529b4cb63..5b8a71d97a 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/CustomType/serialization.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/CustomType/serialization.ts @@ -4,7 +4,7 @@ import { Write, WriteSizer, WriteEncoder, - Nullable, + Option, BigInt, BigNumber, JSON, @@ -38,7 +38,7 @@ export function writeCustomType(writer: Write, type: CustomType): void { writer.writeString("u"); writer.writeUInt32(type.u); writer.context().pop(); - writer.context().push("optU", "Nullable", "writing property"); + writer.context().push("optU", "Option", "writing property"); writer.writeString("optU"); writer.writeNullableUInt32(type.optU); writer.context().pop(); @@ -106,7 +106,7 @@ export function writeCustomType(writer: Write, type: CustomType): void { writer.writeString("boolean"); writer.writeBool(type.m_boolean); writer.context().pop(); - writer.context().push("optBoolean", "Nullable", "writing property"); + writer.context().push("optBoolean", "Option", "writing property"); writer.writeString("optBoolean"); writer.writeNullableBool(type.optBoolean); writer.context().pop(); @@ -122,9 +122,9 @@ export function writeCustomType(writer: Write, type: CustomType): void { writer.writeUInt32(item); }); writer.context().pop(); - writer.context().push("optUOptArray", "Array> | null", "writing property"); + writer.context().push("optUOptArray", "Array> | null", "writing property"); writer.writeString("optUOptArray"); - writer.writeNullableArray(type.optUOptArray, (writer: Write, item: Nullable): void => { + writer.writeNullableArray(type.optUOptArray, (writer: Write, item: Option): void => { writer.writeNullableUInt32(item); }); writer.context().pop(); @@ -142,10 +142,10 @@ export function writeCustomType(writer: Write, type: CustomType): void { }); }); writer.context().pop(); - writer.context().push("uOptArrayOptArray", "Array> | null>", "writing property"); + writer.context().push("uOptArrayOptArray", "Array> | null>", "writing property"); writer.writeString("uOptArrayOptArray"); - writer.writeArray(type.uOptArrayOptArray, (writer: Write, item: Array> | null): void => { - writer.writeNullableArray(item, (writer: Write, item: Nullable): void => { + writer.writeArray(type.uOptArrayOptArray, (writer: Write, item: Array> | null): void => { + writer.writeNullableArray(item, (writer: Write, item: Option): void => { writer.writeNullableUInt32(item); }); }); @@ -204,7 +204,7 @@ export function writeCustomType(writer: Write, type: CustomType): void { writer.writeString("en"); writer.writeInt32(type.en); writer.context().pop(); - writer.context().push("optEnum", "Nullable", "writing property"); + writer.context().push("optEnum", "Option", "writing property"); writer.writeString("optEnum"); writer.writeNullableInt32(type.optEnum); writer.context().pop(); @@ -214,9 +214,9 @@ export function writeCustomType(writer: Write, type: CustomType): void { writer.writeInt32(item); }); writer.context().pop(); - writer.context().push("optEnumArray", "Array> | null", "writing property"); + writer.context().push("optEnumArray", "Array> | null", "writing property"); writer.writeString("optEnumArray"); - writer.writeNullableArray(type.optEnumArray, (writer: Write, item: Nullable): void => { + writer.writeNullableArray(type.optEnumArray, (writer: Write, item: Option): void => { writer.writeNullableInt32(item); }); writer.context().pop(); @@ -236,7 +236,7 @@ export function readCustomType(reader: Read): CustomType { let _optStr: string | null = null; let _u: u32 = 0; let _uSet: bool = false; - let _optU: Nullable = new Nullable(); + let _optU: Option = Option.None(); let _u8: u8 = 0; let _u8Set: bool = false; let _u16: u16 = 0; @@ -265,15 +265,15 @@ export function readCustomType(reader: Read): CustomType { let _optBytes: ArrayBuffer | null = null; let _boolean: bool = false; let _booleanSet: bool = false; - let _optBoolean: Nullable = new Nullable(); + let _optBoolean: Option = Option.None(); let _uArray: Array = []; let _uArraySet: bool = false; let _uOptArray: Array | null = null; - let _optUOptArray: Array> | null = null; + let _optUOptArray: Array> | null = null; let _optStrOptArray: Array | null = null; let _uArrayArray: Array> = []; let _uArrayArraySet: bool = false; - let _uOptArrayOptArray: Array> | null> = []; + let _uOptArrayOptArray: Array> | null> = []; let _uOptArrayOptArraySet: bool = false; let _uArrayOptArrayArray: Array> | null> = []; let _uArrayOptArrayArraySet: bool = false; @@ -286,10 +286,10 @@ export function readCustomType(reader: Read): CustomType { let _optObjectArray: Array | null = null; let _en: Types.CustomEnum = 0; let _enSet: bool = false; - let _optEnum: Nullable = new Nullable(); + let _optEnum: Option = Option.None(); let _enumArray: Array = []; let _enumArraySet: bool = false; - let _optEnumArray: Array> | null = null; + let _optEnumArray: Array> | null = null; while (numFields > 0) { numFields--; @@ -314,7 +314,7 @@ export function readCustomType(reader: Read): CustomType { reader.context().pop(); } else if (field == "optU") { - reader.context().push(field, "Nullable", "type found, reading property"); + reader.context().push(field, "Option", "type found, reading property"); _optU = reader.readNullableUInt32(); reader.context().pop(); } @@ -411,7 +411,7 @@ export function readCustomType(reader: Read): CustomType { reader.context().pop(); } else if (field == "optBoolean") { - reader.context().push(field, "Nullable", "type found, reading property"); + reader.context().push(field, "Option", "type found, reading property"); _optBoolean = reader.readNullableBool(); reader.context().pop(); } @@ -431,8 +431,8 @@ export function readCustomType(reader: Read): CustomType { reader.context().pop(); } else if (field == "optUOptArray") { - reader.context().push(field, "Array> | null", "type found, reading property"); - _optUOptArray = reader.readNullableArray((reader: Read): Nullable => { + reader.context().push(field, "Array> | null", "type found, reading property"); + _optUOptArray = reader.readNullableArray((reader: Read): Option => { return reader.readNullableUInt32(); }); reader.context().pop(); @@ -455,9 +455,9 @@ export function readCustomType(reader: Read): CustomType { reader.context().pop(); } else if (field == "uOptArrayOptArray") { - reader.context().push(field, "Array> | null>", "type found, reading property"); - _uOptArrayOptArray = reader.readArray((reader: Read): Array> | null => { - return reader.readNullableArray((reader: Read): Nullable => { + reader.context().push(field, "Array> | null>", "type found, reading property"); + _uOptArrayOptArray = reader.readArray((reader: Read): Array> | null => { + return reader.readNullableArray((reader: Read): Option => { return reader.readNullableUInt32(); }); }); @@ -539,21 +539,21 @@ export function readCustomType(reader: Read): CustomType { reader.context().pop(); } else if (field == "optEnum") { - reader.context().push(field, "Nullable", "type found, reading property"); - let value: Nullable; + reader.context().push(field, "Option", "type found, reading property"); + let value: Option; if (!reader.isNextNil()) { if (reader.isNextString()) { - value = Nullable.fromValue( + value = Option.Some( Types.getCustomEnumValue(reader.readString()) ); } else { - value = Nullable.fromValue( + value = Option.Some( reader.readInt32() ); - Types.sanitizeCustomEnumValue(value.value); + Types.sanitizeCustomEnumValue(value.unwrap()); } } else { - value = Nullable.fromNull(); + value = Option.None(); } _optEnum = value; reader.context().pop(); @@ -574,22 +574,22 @@ export function readCustomType(reader: Read): CustomType { reader.context().pop(); } else if (field == "optEnumArray") { - reader.context().push(field, "Array> | null", "type found, reading property"); - _optEnumArray = reader.readNullableArray((reader: Read): Nullable => { - let value: Nullable; + reader.context().push(field, "Array> | null", "type found, reading property"); + _optEnumArray = reader.readNullableArray((reader: Read): Option => { + let value: Option; if (!reader.isNextNil()) { if (reader.isNextString()) { - value = Nullable.fromValue( + value = Option.Some( Types.getCustomEnumValue(reader.readString()) ); } else { - value = Nullable.fromValue( + value = Option.Some( reader.readInt32() ); - Types.sanitizeCustomEnumValue(value.value); + Types.sanitizeCustomEnumValue(value.unwrap()); } } else { - value = Nullable.fromNull(); + value = Option.None(); } return value; }); diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/Env/index.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/Env/index.ts index 09dee2ac73..e23475d9bf 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/Env/index.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/Env/index.ts @@ -1,12 +1,10 @@ import { Read, Write, - Nullable, + Option, BigInt, BigNumber, - JSON, - JSONSerializer, - JSONDeserializer, + JSON } from "@polywrap/wasm-as"; import { serializeEnv, @@ -16,11 +14,10 @@ import { } from "./serialization"; import * as Types from ".."; -@serializable export class Env { prop: string; optProp: string | null; - optMap: Map> | null; + optMap: Map> | null; static toBuffer(type: Env): ArrayBuffer { return serializeEnv(type); @@ -37,12 +34,4 @@ export class Env { static read(reader: Read): Env { return readEnv(reader); } - - static toJson(type: Env): JSON.Value { - return JSONSerializer.encode(type); - } - - static fromJson(json: JSON.Value): Env { - return (new JSONDeserializer(json)).decode(); - } } diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/Env/serialization.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/Env/serialization.ts index 601434c3e0..e83f1c9ca1 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/Env/serialization.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/Env/serialization.ts @@ -4,7 +4,7 @@ import { Write, WriteSizer, WriteEncoder, - Nullable, + Option, BigInt, BigNumber, JSON, @@ -34,11 +34,11 @@ export function writeEnv(writer: Write, type: Env): void { writer.writeString("optProp"); writer.writeNullableString(type.optProp); writer.context().pop(); - writer.context().push("optMap", "Map> | null", "writing property"); + writer.context().push("optMap", "Map> | null", "writing property"); writer.writeString("optMap"); writer.writeNullableExtGenericMap(type.optMap, (writer: Write, key: string) => { writer.writeString(key); - }, (writer: Write, value: Nullable): void => { + }, (writer: Write, value: Option): void => { writer.writeNullableInt32(value); }); writer.context().pop(); @@ -56,7 +56,7 @@ export function readEnv(reader: Read): Env { let _prop: string = ""; let _propSet: bool = false; let _optProp: string | null = null; - let _optMap: Map> | null = null; + let _optMap: Map> | null = null; while (numFields > 0) { numFields--; @@ -75,10 +75,10 @@ export function readEnv(reader: Read): Env { reader.context().pop(); } else if (field == "optMap") { - reader.context().push(field, "Map> | null", "type found, reading property"); + reader.context().push(field, "Map> | null", "type found, reading property"); _optMap = reader.readNullableExtGenericMap((reader: Read): string => { return reader.readString(); - }, (reader: Read): Nullable => { + }, (reader: Read): Option => { return reader.readNullableInt32(); }); reader.context().pop(); diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/Module/serialization.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/Module/serialization.ts index 6ee48d0a3e..f214d2abae 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/Module/serialization.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/Module/serialization.ts @@ -4,7 +4,7 @@ import { Write, WriteSizer, WriteEncoder, - Nullable, + Option, BigInt, BigNumber, JSON, @@ -16,14 +16,14 @@ export class Input_moduleMethod { str: string; optStr: string | null; en: Types.CustomEnum; - optEnum: Nullable; + optEnum: Option; enumArray: Array; - optEnumArray: Array> | null; + optEnumArray: Array> | null; map: Map; } export function deserializemoduleMethodArgs(argsBuf: ArrayBuffer): Input_moduleMethod { - const context: Context = new Context("Deserializing module-type: moduleMethod"); + const context: Context = new Context("Deserializing module-type: moduleMethod"); const reader = new ReadDecoder(argsBuf, context); let numFields = reader.readMapLength(); @@ -32,10 +32,10 @@ export function deserializemoduleMethodArgs(argsBuf: ArrayBuffer): Input_moduleM let _optStr: string | null = null; let _en: Types.CustomEnum = 0; let _enSet: bool = false; - let _optEnum: Nullable = new Nullable(); + let _optEnum: Option = Option.None(); let _enumArray: Array = []; let _enumArraySet: bool = false; - let _optEnumArray: Array> | null = null; + let _optEnumArray: Array> | null = null; let _map: Map = new Map(); let _mapSet: bool = false; @@ -69,21 +69,21 @@ export function deserializemoduleMethodArgs(argsBuf: ArrayBuffer): Input_moduleM reader.context().pop(); } else if (field == "optEnum") { - reader.context().push(field, "Nullable", "type found, reading property"); - let value: Nullable; + reader.context().push(field, "Option", "type found, reading property"); + let value: Option; if (!reader.isNextNil()) { if (reader.isNextString()) { - value = Nullable.fromValue( + value = Option.Some( Types.getCustomEnumValue(reader.readString()) ); } else { - value = Nullable.fromValue( + value = Option.Some( reader.readInt32() ); - Types.sanitizeCustomEnumValue(value.value); + Types.sanitizeCustomEnumValue(value.unwrap()); } } else { - value = Nullable.fromNull(); + value = Option.None(); } _optEnum = value; reader.context().pop(); @@ -104,22 +104,22 @@ export function deserializemoduleMethodArgs(argsBuf: ArrayBuffer): Input_moduleM reader.context().pop(); } else if (field == "optEnumArray") { - reader.context().push(field, "Array> | null", "type found, reading property"); - _optEnumArray = reader.readNullableArray((reader: Read): Nullable => { - let value: Nullable; + reader.context().push(field, "Array> | null", "type found, reading property"); + _optEnumArray = reader.readNullableArray((reader: Read): Option => { + let value: Option; if (!reader.isNextNil()) { if (reader.isNextString()) { - value = Nullable.fromValue( + value = Option.Some( Types.getCustomEnumValue(reader.readString()) ); } else { - value = Nullable.fromValue( + value = Option.Some( reader.readInt32() ); - Types.sanitizeCustomEnumValue(value.value); + Types.sanitizeCustomEnumValue(value.unwrap()); } } else { - value = Nullable.fromNull(); + value = Option.None(); } return value; }); @@ -187,7 +187,7 @@ export class Input_objectMethod { } export function deserializeobjectMethodArgs(argsBuf: ArrayBuffer): Input_objectMethod { - const context: Context = new Context("Deserializing module-type: objectMethod"); + const context: Context = new Context("Deserializing module-type: objectMethod"); const reader = new ReadDecoder(argsBuf, context); let numFields = reader.readMapLength(); diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_AnotherObject/index.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_AnotherObject/index.ts index 6a52f417bb..8957633043 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_AnotherObject/index.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_AnotherObject/index.ts @@ -1,12 +1,10 @@ import { Read, Write, - Nullable, + Option, BigInt, BigNumber, - JSON, - JSONSerializer, - JSONDeserializer, + JSON } from "@polywrap/wasm-as"; import { serializeTestImport_AnotherObject, @@ -16,7 +14,6 @@ import { } from "./serialization"; import * as Types from "../.."; -@serializable export class TestImport_AnotherObject { public static uri: string = "testimport.uri.eth"; @@ -38,12 +35,4 @@ export class TestImport_AnotherObject { static read(reader: Read): TestImport_AnotherObject { return readTestImport_AnotherObject(reader); } - - static toJson(type: TestImport_AnotherObject): JSON.Value { - return JSONSerializer.encode(type); - } - - static fromJson(json: JSON.Value): TestImport_AnotherObject { - return (new JSONDeserializer(json)).decode(); - } } diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_AnotherObject/serialization.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_AnotherObject/serialization.ts index cfbe766951..98b67d08ff 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_AnotherObject/serialization.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_AnotherObject/serialization.ts @@ -4,7 +4,7 @@ import { Write, WriteSizer, WriteEncoder, - Nullable, + Option, BigInt, BigNumber, JSON, diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Module/index.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Module/index.ts index 5246bae2bd..859818f55b 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Module/index.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Module/index.ts @@ -1,7 +1,7 @@ import { wrap_subinvoke, wrap_subinvokeImplementation, - Nullable, + Option, BigInt, BigNumber, JSON, diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Module/serialization.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Module/serialization.ts index 65a08566f7..d1bb72d7e5 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Module/serialization.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Module/serialization.ts @@ -4,7 +4,7 @@ import { Write, WriteSizer, WriteEncoder, - Nullable, + Option, BigInt, BigNumber, JSON, @@ -16,16 +16,16 @@ export class Input_importedMethod { str: string; optStr: string | null; u: u32; - optU: Nullable; - uArrayArray: Array> | null>; + optU: Option; + uArrayArray: Array> | null>; object: Types.TestImport_Object; optObject: Types.TestImport_Object | null; objectArray: Array; optObjectArray: Array | null; en: Types.TestImport_Enum; - optEnum: Nullable; + optEnum: Option; enumArray: Array; - optEnumArray: Array> | null; + optEnumArray: Array> | null; } export function serializeimportedMethodArgs(input: Input_importedMethod): ArrayBuffer { @@ -56,14 +56,14 @@ export function writeimportedMethodArgs( writer.writeString("u"); writer.writeUInt32(input.u); writer.context().pop(); - writer.context().push("optU", "Nullable", "writing property"); + writer.context().push("optU", "Option", "writing property"); writer.writeString("optU"); writer.writeNullableUInt32(input.optU); writer.context().pop(); - writer.context().push("uArrayArray", "Array> | null>", "writing property"); + writer.context().push("uArrayArray", "Array> | null>", "writing property"); writer.writeString("uArrayArray"); - writer.writeArray(input.uArrayArray, (writer: Write, item: Array> | null): void => { - writer.writeNullableArray(item, (writer: Write, item: Nullable): void => { + writer.writeArray(input.uArrayArray, (writer: Write, item: Array> | null): void => { + writer.writeNullableArray(item, (writer: Write, item: Option): void => { writer.writeNullableUInt32(item); }); }); @@ -100,7 +100,7 @@ export function writeimportedMethodArgs( writer.writeString("en"); writer.writeInt32(input.en); writer.context().pop(); - writer.context().push("optEnum", "Nullable", "writing property"); + writer.context().push("optEnum", "Option", "writing property"); writer.writeString("optEnum"); writer.writeNullableInt32(input.optEnum); writer.context().pop(); @@ -110,16 +110,16 @@ export function writeimportedMethodArgs( writer.writeInt32(item); }); writer.context().pop(); - writer.context().push("optEnumArray", "Array> | null", "writing property"); + writer.context().push("optEnumArray", "Array> | null", "writing property"); writer.writeString("optEnumArray"); - writer.writeNullableArray(input.optEnumArray, (writer: Write, item: Nullable): void => { + writer.writeNullableArray(input.optEnumArray, (writer: Write, item: Option): void => { writer.writeNullableInt32(item); }); writer.context().pop(); } export function deserializeimportedMethodResult(buffer: ArrayBuffer): Types.TestImport_Object | null { - const context: Context = new Context("Deserializing imported module-type: importedMethod"); + const context: Context = new Context("Deserializing imported module-type: importedMethod"); const reader = new ReadDecoder(buffer, context); reader.context().push("importedMethod", "Types.TestImport_Object | null", "reading function output"); @@ -162,7 +162,7 @@ export function writeanotherMethodArgs( } export function deserializeanotherMethodResult(buffer: ArrayBuffer): i32 { - const context: Context = new Context("Deserializing imported module-type: anotherMethod"); + const context: Context = new Context("Deserializing imported module-type: anotherMethod"); const reader = new ReadDecoder(buffer, context); reader.context().push("anotherMethod", "i32", "reading function output"); diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Object/index.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Object/index.ts index fc03152ed8..f15d8a58de 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Object/index.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Object/index.ts @@ -1,12 +1,10 @@ import { Read, Write, - Nullable, + Option, BigInt, BigNumber, - JSON, - JSONSerializer, - JSONDeserializer, + JSON } from "@polywrap/wasm-as"; import { serializeTestImport_Object, @@ -16,7 +14,6 @@ import { } from "./serialization"; import * as Types from "../.."; -@serializable export class TestImport_Object { public static uri: string = "testimport.uri.eth"; @@ -26,9 +23,9 @@ export class TestImport_Object { objectArray: Array; optObjectArray: Array | null; en: Types.TestImport_Enum; - optEnum: Nullable; + optEnum: Option; enumArray: Array; - optEnumArray: Array> | null; + optEnumArray: Array> | null; static toBuffer(type: TestImport_Object): ArrayBuffer { return serializeTestImport_Object(type); @@ -45,12 +42,4 @@ export class TestImport_Object { static read(reader: Read): TestImport_Object { return readTestImport_Object(reader); } - - static toJson(type: TestImport_Object): JSON.Value { - return JSONSerializer.encode(type); - } - - static fromJson(json: JSON.Value): TestImport_Object { - return (new JSONDeserializer(json)).decode(); - } } diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Object/serialization.ts b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Object/serialization.ts index 623dcdc2d5..9b588e9ca7 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Object/serialization.ts +++ b/packages/test-cases/cases/bind/sanity/output/wasm-as/imported/TestImport_Object/serialization.ts @@ -4,7 +4,7 @@ import { Write, WriteSizer, WriteEncoder, - Nullable, + Option, BigInt, BigNumber, JSON, @@ -58,7 +58,7 @@ export function writeTestImport_Object(writer: Write, type: TestImport_Object): writer.writeString("en"); writer.writeInt32(type.en); writer.context().pop(); - writer.context().push("optEnum", "Nullable", "writing property"); + writer.context().push("optEnum", "Option", "writing property"); writer.writeString("optEnum"); writer.writeNullableInt32(type.optEnum); writer.context().pop(); @@ -68,9 +68,9 @@ export function writeTestImport_Object(writer: Write, type: TestImport_Object): writer.writeInt32(item); }); writer.context().pop(); - writer.context().push("optEnumArray", "Array> | null", "writing property"); + writer.context().push("optEnumArray", "Array> | null", "writing property"); writer.writeString("optEnumArray"); - writer.writeNullableArray(type.optEnumArray, (writer: Write, item: Nullable): void => { + writer.writeNullableArray(type.optEnumArray, (writer: Write, item: Option): void => { writer.writeNullableInt32(item); }); writer.context().pop(); @@ -93,10 +93,10 @@ export function readTestImport_Object(reader: Read): TestImport_Object { let _optObjectArray: Array | null = null; let _en: Types.TestImport_Enum = 0; let _enSet: bool = false; - let _optEnum: Nullable = new Nullable(); + let _optEnum: Option = Option.None(); let _enumArray: Array = []; let _enumArraySet: bool = false; - let _optEnumArray: Array> | null = null; + let _optEnumArray: Array> | null = null; while (numFields > 0) { numFields--; @@ -153,21 +153,21 @@ export function readTestImport_Object(reader: Read): TestImport_Object { reader.context().pop(); } else if (field == "optEnum") { - reader.context().push(field, "Nullable", "type found, reading property"); - let value: Nullable; + reader.context().push(field, "Option", "type found, reading property"); + let value: Option; if (!reader.isNextNil()) { if (reader.isNextString()) { - value = Nullable.fromValue( + value = Option.Some( Types.getTestImport_EnumValue(reader.readString()) ); } else { - value = Nullable.fromValue( + value = Option.Some( reader.readInt32() ); - Types.sanitizeTestImport_EnumValue(value.value); + Types.sanitizeTestImport_EnumValue(value.unwrap()); } } else { - value = Nullable.fromNull(); + value = Option.None(); } _optEnum = value; reader.context().pop(); @@ -188,22 +188,22 @@ export function readTestImport_Object(reader: Read): TestImport_Object { reader.context().pop(); } else if (field == "optEnumArray") { - reader.context().push(field, "Array> | null", "type found, reading property"); - _optEnumArray = reader.readNullableArray((reader: Read): Nullable => { - let value: Nullable; + reader.context().push(field, "Array> | null", "type found, reading property"); + _optEnumArray = reader.readNullableArray((reader: Read): Option => { + let value: Option; if (!reader.isNextNil()) { if (reader.isNextString()) { - value = Nullable.fromValue( + value = Option.Some( Types.getTestImport_EnumValue(reader.readString()) ); } else { - value = Nullable.fromValue( + value = Option.Some( reader.readInt32() ); - Types.sanitizeTestImport_EnumValue(value.value); + Types.sanitizeTestImport_EnumValue(value.unwrap()); } } else { - value = Nullable.fromNull(); + value = Option.None(); } return value; }); diff --git a/packages/test-cases/cases/cli/wasm/query/.gitignore b/packages/test-cases/cases/cli/wasm/query/.gitignore deleted file mode 100644 index c795b054e5..0000000000 --- a/packages/test-cases/cases/cli/wasm/query/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build \ No newline at end of file diff --git a/packages/test-cases/cases/cli/wasm/query/recipes/constants.json b/packages/test-cases/cases/cli/wasm/query/recipes/constants.json deleted file mode 100644 index 5c7119e4a6..0000000000 --- a/packages/test-cases/cases/cli/wasm/query/recipes/constants.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "SimpleStorageAddr": "0x9b1f7F645351AF3631a656421eD2e40f2802E6c0" -} \ No newline at end of file diff --git a/packages/test-cases/cases/cli/wasm/query/recipes/constants.yaml b/packages/test-cases/cases/cli/wasm/query/recipes/constants.yaml deleted file mode 100644 index ea1045f842..0000000000 --- a/packages/test-cases/cases/cli/wasm/query/recipes/constants.yaml +++ /dev/null @@ -1 +0,0 @@ -SimpleStorageAddr: "0x9b1f7F645351AF3631a656421eD2e40f2802E6c0" diff --git a/packages/test-cases/cases/cli/wasm/query/recipes/e2e.json b/packages/test-cases/cases/cli/wasm/query/recipes/e2e.json deleted file mode 100644 index 8ec251c88a..0000000000 --- a/packages/test-cases/cases/cli/wasm/query/recipes/e2e.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "wrapper": "ens/testnet/simplestorage.eth", - "constants": "./constants.json" - }, - { - "query": "./set.graphql", - "variables": { - "address": "$SimpleStorageAddr", - "value": 569, - "network": "testnet" - } - } -] diff --git a/packages/test-cases/cases/cli/wasm/query/recipes/e2e.yaml b/packages/test-cases/cases/cli/wasm/query/recipes/e2e.yaml deleted file mode 100644 index a0d0a624b7..0000000000 --- a/packages/test-cases/cases/cli/wasm/query/recipes/e2e.yaml +++ /dev/null @@ -1,7 +0,0 @@ -- wrapper: ens/testnet/simplestorage.eth - constants: ./constants.json -- query: ./set.graphql - variables: - address: $SimpleStorageAddr - value: 569 - network: testnet diff --git a/packages/test-cases/cases/cli/wasm/query/recipes/get.graphql b/packages/test-cases/cases/cli/wasm/query/recipes/get.graphql deleted file mode 100644 index 6a1825c6e1..0000000000 --- a/packages/test-cases/cases/cli/wasm/query/recipes/get.graphql +++ /dev/null @@ -1,8 +0,0 @@ -query { - getData( - address: $address - connection: { - networkNameOrChainId: $network - } - ) -} diff --git a/packages/test-cases/cases/cli/wasm/query/recipes/set.graphql b/packages/test-cases/cases/cli/wasm/query/recipes/set.graphql deleted file mode 100644 index 9342655054..0000000000 --- a/packages/test-cases/cases/cli/wasm/query/recipes/set.graphql +++ /dev/null @@ -1,14 +0,0 @@ -mutation { - setData( - options: { - address: $address - value: $value - } - connection: { - networkNameOrChainId: $network - } - ) { - value - txReceipt - } -} diff --git a/packages/test-cases/cases/cli/wasm/query/src/contracts/SimpleStorage.json b/packages/test-cases/cases/cli/wasm/query/src/contracts/SimpleStorage.json deleted file mode 100644 index dc71839bc0..0000000000 --- a/packages/test-cases/cases/cli/wasm/query/src/contracts/SimpleStorage.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "abi": [ - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "from", - "type": "address" - } - ], - "name": "DataSet", - "type": "event" - }, - { - "inputs": [], - "name": "get", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "x", - "type": "uint256" - } - ], - "name": "set", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - } - ], - "bytecode": { - "linkReferences": {}, - "object": "608060405234801561001057600080fd5b5061012a806100206000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806360fe47b11460375780636d4ce63c146062575b600080fd5b606060048036036020811015604b57600080fd5b8101908080359060200190929190505050607e565b005b606860eb565b6040518082815260200191505060405180910390f35b806000819055507f3d38713ec8fb49acced894a52df2f06a371a15960550da9ba0f017cb7d07a8ec33604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a150565b6000805490509056fea2646970667358221220f312fe8d32f77c74cc4eb4a1f5c805d8bb124755ca4e8a1db2cce10cbb133dc564736f6c63430006060033", - "opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0x12A DUP1 PUSH2 0x20 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN INVALID PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH1 0xF JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x4 CALLDATASIZE LT PUSH1 0x32 JUMPI PUSH1 0x0 CALLDATALOAD PUSH1 0xE0 SHR DUP1 PUSH4 0x60FE47B1 EQ PUSH1 0x37 JUMPI DUP1 PUSH4 0x6D4CE63C EQ PUSH1 0x62 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH1 0x60 PUSH1 0x4 DUP1 CALLDATASIZE SUB PUSH1 0x20 DUP2 LT ISZERO PUSH1 0x4B JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST DUP2 ADD SWAP1 DUP1 DUP1 CALLDATALOAD SWAP1 PUSH1 0x20 ADD SWAP1 SWAP3 SWAP2 SWAP1 POP POP POP PUSH1 0x7E JUMP JUMPDEST STOP JUMPDEST PUSH1 0x68 PUSH1 0xEB JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 DUP3 DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST DUP1 PUSH1 0x0 DUP2 SWAP1 SSTORE POP PUSH32 0x3D38713EC8FB49ACCED894A52DF2F06A371A15960550DA9BA0F017CB7D07A8EC CALLER PUSH1 0x40 MLOAD DUP1 DUP3 PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND PUSH20 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF AND DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 LOG1 POP JUMP JUMPDEST PUSH1 0x0 DUP1 SLOAD SWAP1 POP SWAP1 JUMP INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 RETURN SLT INVALID DUP14 ORIGIN 0xF7 PUSH29 0x74CC4EB4A1F5C805D8BB124755CA4E8A1DB2CCE10CBB133DC564736F6C PUSH4 0x43000606 STOP CALLER ", - "sourceMap": "34:220:0:-:0;;;;5:9:-1;2:2;;;27:1;24;17:12;2:2;34:220:0;;;;;;;" - }, - "compiler":{ - "version":"0.6.6+commit.6c089d02" - } -} diff --git a/packages/test-cases/cases/cli/wasm/query/src/contracts/SimpleStorage.sol b/packages/test-cases/cases/cli/wasm/query/src/contracts/SimpleStorage.sol deleted file mode 100644 index b85bd83fc2..0000000000 --- a/packages/test-cases/cases/cli/wasm/query/src/contracts/SimpleStorage.sol +++ /dev/null @@ -1,16 +0,0 @@ -pragma solidity >=0.4.22 <0.7.0; - -contract SimpleStorage { - uint data; - - event DataSet(address from); - - function set(uint256 x) public { - data = x; - emit DataSet(msg.sender); - } - - function get() public view returns (uint256) { - return data; - } -} diff --git a/packages/test-cases/cases/cli/wasm/query/client-async-config.js b/packages/test-cases/cases/cli/wasm/run/client-async-config.js similarity index 100% rename from packages/test-cases/cases/cli/wasm/query/client-async-config.js rename to packages/test-cases/cases/cli/wasm/run/client-async-config.js diff --git a/packages/test-cases/cases/cli/wasm/query/client-async-config.ts b/packages/test-cases/cases/cli/wasm/run/client-async-config.ts similarity index 100% rename from packages/test-cases/cases/cli/wasm/query/client-async-config.ts rename to packages/test-cases/cases/cli/wasm/run/client-async-config.ts diff --git a/packages/test-cases/cases/cli/wasm/query/client-config.js b/packages/test-cases/cases/cli/wasm/run/client-config.js similarity index 100% rename from packages/test-cases/cases/cli/wasm/query/client-config.js rename to packages/test-cases/cases/cli/wasm/run/client-config.js diff --git a/packages/test-cases/cases/cli/wasm/query/client-config.ts b/packages/test-cases/cases/cli/wasm/run/client-config.ts similarity index 100% rename from packages/test-cases/cases/cli/wasm/query/client-config.ts rename to packages/test-cases/cases/cli/wasm/run/client-config.ts diff --git a/packages/test-cases/cases/cli/wasm/query/deploy-contracts.js b/packages/test-cases/cases/cli/wasm/run/deploy-contracts.js similarity index 100% rename from packages/test-cases/cases/cli/wasm/query/deploy-contracts.js rename to packages/test-cases/cases/cli/wasm/run/deploy-contracts.js diff --git a/packages/test-cases/cases/cli/wasm/query/package.json b/packages/test-cases/cases/cli/wasm/run/package.json similarity index 100% rename from packages/test-cases/cases/cli/wasm/query/package.json rename to packages/test-cases/cases/cli/wasm/run/package.json diff --git a/packages/test-cases/cases/cli/wasm/query/polywrap.build.yaml b/packages/test-cases/cases/cli/wasm/run/polywrap.build.yaml similarity index 100% rename from packages/test-cases/cases/cli/wasm/query/polywrap.build.yaml rename to packages/test-cases/cases/cli/wasm/run/polywrap.build.yaml diff --git a/packages/test-cases/cases/cli/wasm/query/polywrap.deploy.fail-between.yaml b/packages/test-cases/cases/cli/wasm/run/polywrap.deploy.fail-between.yaml similarity index 100% rename from packages/test-cases/cases/cli/wasm/query/polywrap.deploy.fail-between.yaml rename to packages/test-cases/cases/cli/wasm/run/polywrap.deploy.fail-between.yaml diff --git a/packages/test-cases/cases/cli/wasm/query/polywrap.deploy.invalid-config.yaml b/packages/test-cases/cases/cli/wasm/run/polywrap.deploy.invalid-config.yaml similarity index 100% rename from packages/test-cases/cases/cli/wasm/query/polywrap.deploy.invalid-config.yaml rename to packages/test-cases/cases/cli/wasm/run/polywrap.deploy.invalid-config.yaml diff --git a/packages/test-cases/cases/cli/wasm/query/polywrap.deploy.no-ext.yaml b/packages/test-cases/cases/cli/wasm/run/polywrap.deploy.no-ext.yaml similarity index 100% rename from packages/test-cases/cases/cli/wasm/query/polywrap.deploy.no-ext.yaml rename to packages/test-cases/cases/cli/wasm/run/polywrap.deploy.no-ext.yaml diff --git a/packages/test-cases/cases/cli/wasm/query/polywrap.deploy.yaml b/packages/test-cases/cases/cli/wasm/run/polywrap.deploy.yaml similarity index 51% rename from packages/test-cases/cases/cli/wasm/query/polywrap.deploy.yaml rename to packages/test-cases/cases/cli/wasm/run/polywrap.deploy.yaml index 8bb0f0458e..48de1510d5 100644 --- a/packages/test-cases/cases/cli/wasm/query/polywrap.deploy.yaml +++ b/packages/test-cases/cases/cli/wasm/run/polywrap.deploy.yaml @@ -4,23 +4,23 @@ stages: package: ipfs uri: fs/./build from_deploy: - package: local-dev-ens + package: ens depends_on: ipfs_deploy config: - domainName: test1.eth - ports: - ethereum: 8545 + domainName: $DOMAIN_NAME + provider: 'http://localhost:8545' + ensRegistryAddress: $ENS_REG_ADDR from_deploy2: - package: local-dev-ens + package: ens depends_on: ipfs_deploy config: domainName: test2.eth - ports: - ethereum: 8545 + provider: 'http://localhost:8545' + ensRegistryAddress: $ENS_REG_ADDR from_uri: - package: local-dev-ens + package: ens uri: ipfs/QmVdDR6QtigTt38Xwpj2Ki73X1AyZn5WRCreBCJq1CEtpF config: domainName: test3.eth - ports: - ethereum: 8545 + provider: 'http://localhost:8545' + ensRegistryAddress: $ENS_REG_ADDR \ No newline at end of file diff --git a/packages/test-cases/cases/cli/wasm/query/polywrap.yaml b/packages/test-cases/cases/cli/wasm/run/polywrap.yaml similarity index 100% rename from packages/test-cases/cases/cli/wasm/query/polywrap.yaml rename to packages/test-cases/cases/cli/wasm/run/polywrap.yaml diff --git a/packages/test-cases/cases/cli/wasm/query/schema.graphql b/packages/test-cases/cases/cli/wasm/run/schema.graphql similarity index 100% rename from packages/test-cases/cases/cli/wasm/query/schema.graphql rename to packages/test-cases/cases/cli/wasm/run/schema.graphql diff --git a/packages/test-cases/cases/cli/wasm/query/src/index.ts b/packages/test-cases/cases/cli/wasm/run/src/index.ts similarity index 100% rename from packages/test-cases/cases/cli/wasm/query/src/index.ts rename to packages/test-cases/cases/cli/wasm/run/src/index.ts diff --git a/packages/test-cases/cases/cli/wasm/run/workflows/config.ts b/packages/test-cases/cases/cli/wasm/run/workflows/config.ts new file mode 100644 index 0000000000..0869b4de1a --- /dev/null +++ b/packages/test-cases/cases/cli/wasm/run/workflows/config.ts @@ -0,0 +1,82 @@ +import { PolywrapClientConfig } from "@polywrap/client-js"; +import { ClientConfig, coreInterfaceUris } from "@polywrap/client-js"; +import { ensPlugin } from "@polywrap/ens-plugin-js"; +import { ethereumPlugin } from "@polywrap/ethereum-plugin-js"; +import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; + +interface TestEnvironment { + ipfs: string; + ethereum: string; + ensAddress: string; + registrarAddress?: string; + reverseAddress?: string; + resolverAddress?: string; + clientConfig: Partial; +} + +async function getProviders(): Promise { + const ipfs = "http://localhost:5001"; + const ethereum = "http://localhost:8545"; + const ensAddress = "0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab"; + + const clientConfig: Partial = getPlugins( + ethereum, + ipfs, + "0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab" + ); + return { ipfs, ethereum, ensAddress, clientConfig }; +} + +function getPlugins( + ethereum: string, + ipfs: string, + ensAddress: string +): Partial { + return { + redirects: [], + plugins: [ + { + uri: "wrap://ens/ipfs.polywrap.eth", + plugin: ipfsPlugin({ provider: ipfs }), + }, + { + uri: "wrap://ens/ens.polywrap.eth", + plugin: ensPlugin({ addresses: { testnet: ensAddress } }), + }, + { + uri: "wrap://ens/ethereum.polywrap.eth", + plugin: ethereumPlugin({ + networks: { + testnet: { + provider: ethereum, + }, + MAINNET: { + provider: "http://localhost:8546", + }, + }, + defaultNetwork: "testnet", + }), + }, + ], + interfaces: [ + { + interface: coreInterfaceUris.uriResolver.uri, + implementations: [ + "wrap://ens/ipfs.polywrap.eth", + "wrap://ens/ens.polywrap.eth", + ], + }, + { + interface: coreInterfaceUris.logger.uri, + implementations: ["wrap://ens/js-logger.polywrap.eth"], + }, + ], + }; +} + +export async function getClientConfig( + defaultConfigs: Partial +): Promise> { + const { ipfs, ethereum, ensAddress } = await getProviders(); + return getPlugins(ethereum, ipfs, ensAddress); +} diff --git a/packages/test-cases/cases/cli/wasm/run/workflows/e2e.json b/packages/test-cases/cases/cli/wasm/run/workflows/e2e.json new file mode 100644 index 0000000000..7193a1c6ce --- /dev/null +++ b/packages/test-cases/cases/cli/wasm/run/workflows/e2e.json @@ -0,0 +1,36 @@ +{ + "name": "simple-storage", + "jobs": { + "cases": { + "steps": [ + { + "uri": "fs/build", + "method": "deployContract", + "input": { "connection": null } + } + ], + "jobs": { + "case1": { + "steps": [ + { + "uri": "fs/build", + "method": "setData", + "input": { + "options": { + "address": "$cases.0.data", + "value": 100 + }, + "connection": null + } + }, + { + "uri": "fs/build", + "method": "getData", + "input": { "address": "$cases.0.data", "connection": null } + } + ] + } + } + } + } +} diff --git a/packages/test-cases/cases/cli/wasm/run/workflows/e2e.yaml b/packages/test-cases/cases/cli/wasm/run/workflows/e2e.yaml new file mode 100644 index 0000000000..450829495e --- /dev/null +++ b/packages/test-cases/cases/cli/wasm/run/workflows/e2e.yaml @@ -0,0 +1,23 @@ +name: simple-storage +jobs: + cases: + steps: + - uri: fs/build + method: deployContract + input: + connection: null + jobs: + case1: + steps: + - uri: fs/build + method: setData + input: + options: + address: "$cases.0.data" + value: 100 + connection: null + - uri: fs/build + method: getData + input: + address: "$cases.0.data" + connection: null diff --git a/packages/test-cases/cases/cli/wasm/run/workflows/validator.cue b/packages/test-cases/cases/cli/wasm/run/workflows/validator.cue new file mode 100644 index 0000000000..c9486a6bfe --- /dev/null +++ b/packages/test-cases/cases/cli/wasm/run/workflows/validator.cue @@ -0,0 +1,22 @@ +package e2e + +cases: { + $0: { + data: =~"^0x[A-Fa-f0-9]{40}$", + error?: _|_, // Never fails + } + case1: { + $0: { + data: { + txReceipt: =~"^0x[A-Fa-f0-9]{64}$", + value: uint + }, + error?: _|_, + } + $1: { + data: uint, + error?: _|_ + } + } +} + diff --git a/packages/test-cases/cases/wrappers/wasm-as/json-type/schema.graphql b/packages/test-cases/cases/wrappers/wasm-as/json-type/schema.graphql index ccae1af02b..cb60b87271 100644 --- a/packages/test-cases/cases/wrappers/wasm-as/json-type/schema.graphql +++ b/packages/test-cases/cases/wrappers/wasm-as/json-type/schema.graphql @@ -1,9 +1,24 @@ type Module { - fromJson(json: JSON!): Pair! - toJson(pair: Pair!): JSON! -} + parse( + value: String! + ): JSON! + + stringify( + values: [JSON!]! + ): String! -type Pair { - x: Int! - y: Int! + stringifyObject( + object: Object! + ): String! + + methodJSON( + valueA: Int! + valueB: String! + valueC: Boolean! + ): JSON! } + +type Object { + jsonA: JSON! + jsonB: JSON! +} \ No newline at end of file diff --git a/packages/test-cases/cases/wrappers/wasm-as/json-type/src/index.ts b/packages/test-cases/cases/wrappers/wasm-as/json-type/src/index.ts index 1f9a6be8db..553f2b5b52 100644 --- a/packages/test-cases/cases/wrappers/wasm-as/json-type/src/index.ts +++ b/packages/test-cases/cases/wrappers/wasm-as/json-type/src/index.ts @@ -1,14 +1,36 @@ import { - Input_fromJson, - Input_toJson, - Pair + Input_parse, + Input_stringify, + Input_stringifyObject, + Input_methodJSON } from "./wrap"; import { JSON } from "@polywrap/wasm-as"; -export function fromJson(input: Input_fromJson): Pair { - return Pair.fromJson(input.json); +export function parse(input: Input_parse): JSON.Value { + return JSON.parse(input.value); } -export function toJson(input: Input_toJson): JSON.Value { - return Pair.toJson(input.pair); +export function stringify(input: Input_stringify): string { + let str = ""; + for (let i = 0; i < input.values.length; ++i) { + const value = input.values[i]; + str += value.stringify(); + } + return str; } + +export function stringifyObject(input: Input_stringifyObject): string { + let str = ""; + str += input.object.jsonA.stringify(); + str += input.object.jsonB.stringify(); + return str; +} + +export function methodJSON(input: Input_methodJSON): JSON.Value { + const result = JSON.Value.Object(); + result.set("valueA", JSON.from(input.valueA)); + result.set("valueB", JSON.from(input.valueB)); + result.set("valueC", JSON.from(input.valueC)); + + return result; +} \ No newline at end of file diff --git a/packages/test-cases/cases/wrappers/wasm-rs/json-type/schema.graphql b/packages/test-cases/cases/wrappers/wasm-rs/json-type/schema.graphql index ccae1af02b..cb60b87271 100644 --- a/packages/test-cases/cases/wrappers/wasm-rs/json-type/schema.graphql +++ b/packages/test-cases/cases/wrappers/wasm-rs/json-type/schema.graphql @@ -1,9 +1,24 @@ type Module { - fromJson(json: JSON!): Pair! - toJson(pair: Pair!): JSON! -} + parse( + value: String! + ): JSON! + + stringify( + values: [JSON!]! + ): String! -type Pair { - x: Int! - y: Int! + stringifyObject( + object: Object! + ): String! + + methodJSON( + valueA: Int! + valueB: String! + valueC: Boolean! + ): JSON! } + +type Object { + jsonA: JSON! + jsonB: JSON! +} \ No newline at end of file diff --git a/packages/test-cases/cases/wrappers/wasm-rs/json-type/src/lib.rs b/packages/test-cases/cases/wrappers/wasm-rs/json-type/src/lib.rs index 9c157f5361..771fd3f151 100644 --- a/packages/test-cases/cases/wrappers/wasm-rs/json-type/src/lib.rs +++ b/packages/test-cases/cases/wrappers/wasm-rs/json-type/src/lib.rs @@ -3,10 +3,26 @@ pub use wrap::*; use polywrap_wasm_rs::JSON; use serde_json::*; -pub fn from_json(input: InputFromJson) -> Pair { - serde_json::from_value::(input.json).unwrap() +pub fn stringify(input: InputStringify) -> String { + let mut new_string = String::from(""); + for object in &input.values { + new_string.push_str(&object.to_string()); + } + new_string } -pub fn to_json(input: InputToJson) -> JSON::Value { - JSON::to_value(&input.pair).unwrap() +pub fn parse(input: InputParse) -> JSON::Value { JSON::from_str(&input.value).unwrap() } + +pub fn stringify_object(input: InputStringifyObject) -> String { + let mut new_string = String::from(&input.object.json_a.to_string()); + new_string.push_str(&input.object.json_b.to_string()); + new_string } + +pub fn method_j_s_o_n(input: InputMethodJSON) -> JSON::Value { + json!({ + "valueA": input.value_a, + "valueB": input.value_b, + "valueC": input.value_c + }) +} \ No newline at end of file diff --git a/packages/wasm/as/assembly/__tests__/msgpack.spec.ts b/packages/wasm/as/assembly/__tests__/msgpack.spec.ts index 44ccfdbcc7..e63ef0a802 100644 --- a/packages/wasm/as/assembly/__tests__/msgpack.spec.ts +++ b/packages/wasm/as/assembly/__tests__/msgpack.spec.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-inferrable-types */ import { - Nullable, Read, ReadDecoder, Write, @@ -11,6 +10,7 @@ import { BigInt, BigNumber, } from "../"; +import { Option } from "as-container"; class Sanity { nil: string | null = "null"; @@ -21,8 +21,8 @@ class Sanity { uint16: u16; uint32: u32; boolean: bool; - optUint32: Nullable = new Nullable(); - optBool: Nullable = new Nullable(); + optUint32: Option = Option.None(); + optBool: Option = Option.None(); float32: f32; float64: f64; str: string = ""; @@ -49,8 +49,8 @@ class Sanity { this.uint16 = 65535; this.uint32 = 4294967295; this.boolean = true; - this.optUint32 = Nullable.fromValue(234234234); - this.optBool = Nullable.fromValue(true); + this.optUint32 = Option.Some(234234234); + this.optBool = Option.Some(true); this.float32 = 3.40282344818115234375; this.float64 = 3124124512.598273468017578125; this.str = "Hello, world!"; diff --git a/packages/wasm/as/assembly/__tests__/nullable.spec.ts b/packages/wasm/as/assembly/__tests__/nullable.spec.ts deleted file mode 100644 index 424731136b..0000000000 --- a/packages/wasm/as/assembly/__tests__/nullable.spec.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Nullable } from "../msgpack/Nullable"; - -describe("Nullable: Sanity", () => { - it("Works", () => { - const value = Nullable.fromValue(500); - const other = Nullable.fromNull(); - - expect(value.value).toBe(500); - expect(other).not.toBe(value); - - expect(value == other).toBe(false); - expect(value != other).toBe(true); - - const sameValue = Nullable.fromValue(value.value); - expect(sameValue == value).toBe(true); - }); -}); diff --git a/packages/wasm/as/assembly/index.ts b/packages/wasm/as/assembly/index.ts index ffacda0174..372b974bd4 100644 --- a/packages/wasm/as/assembly/index.ts +++ b/packages/wasm/as/assembly/index.ts @@ -1,11 +1,5 @@ -export { - Read, - ReadDecoder, - Write, - WriteEncoder, - WriteSizer, - Nullable, -} from "./msgpack"; +export { Option } from "as-container"; +export { Read, ReadDecoder, Write, WriteEncoder, WriteSizer } from "./msgpack"; export * from "./json"; export * from "./math"; export * from "./containers"; diff --git a/packages/wasm/as/assembly/json/index.ts b/packages/wasm/as/assembly/json/index.ts index dd01d736aa..2925c6b247 100644 --- a/packages/wasm/as/assembly/json/index.ts +++ b/packages/wasm/as/assembly/json/index.ts @@ -1,5 +1 @@ -export { - ValueDeserializer as JSONDeserializer, - ValueSerializer as JSONSerializer, - JSON, -} from "@web3api/serial-as-json"; +export * from "@web3api/assemblyscript-json"; diff --git a/packages/wasm/as/assembly/msgpack/Nullable.ts b/packages/wasm/as/assembly/msgpack/Nullable.ts deleted file mode 100644 index 3165d50f07..0000000000 --- a/packages/wasm/as/assembly/msgpack/Nullable.ts +++ /dev/null @@ -1,55 +0,0 @@ -// Only class and string types can be -// "nullable" using the `| null` notation. -// Nullable is used for nullable value types. -// https://www.assemblyscript.org/types.html#type-rules -export class Nullable { - private _value: T; - private _nil: bool; - - constructor() { - this.toNull(); - } - - static fromValue(value: T): Nullable { - const nullable = new Nullable(); - nullable.value = value; - return nullable; - } - - static fromNull(): Nullable { - return new Nullable(); - } - - get value(): T { - return this._value; - } - - set value(arg: T) { - this._value = arg; - this._nil = false; - } - - get isNull(): bool { - return this._nil; - } - - toNull(): void { - this._nil = true; - } - - @inline - @operator("==") - protected eq(rhs: Nullable): bool { - if (this._nil) { - return this._nil == rhs._nil; - } else { - return !(rhs._nil || this._value != rhs._value); - } - } - - @inline - @operator("!=") - protected neq(rhs: Nullable): bool { - return !this.eq(rhs); - } -} diff --git a/packages/wasm/as/assembly/msgpack/Read.ts b/packages/wasm/as/assembly/msgpack/Read.ts index 09517b9f0e..317623afbc 100644 --- a/packages/wasm/as/assembly/msgpack/Read.ts +++ b/packages/wasm/as/assembly/msgpack/Read.ts @@ -1,8 +1,9 @@ -import { Nullable } from "./Nullable"; import { BigInt, BigNumber } from "../math"; import { Context } from "../debug"; import { JSON } from "../json"; +import { Option } from "as-container"; + export abstract class Read { abstract readBool(): bool; abstract readInt8(): i8; @@ -32,15 +33,15 @@ export abstract class Read { value_fn: (reader: Read) => V ): Map; - abstract readNullableBool(): Nullable; - abstract readNullableInt8(): Nullable; - abstract readNullableInt16(): Nullable; - abstract readNullableInt32(): Nullable; - abstract readNullableUInt8(): Nullable; - abstract readNullableUInt16(): Nullable; - abstract readNullableUInt32(): Nullable; - abstract readNullableFloat32(): Nullable; - abstract readNullableFloat64(): Nullable; + abstract readNullableBool(): Option; + abstract readNullableInt8(): Option; + abstract readNullableInt16(): Option; + abstract readNullableInt32(): Option; + abstract readNullableUInt8(): Option; + abstract readNullableUInt16(): Option; + abstract readNullableUInt32(): Option; + abstract readNullableFloat32(): Option; + abstract readNullableFloat64(): Option; abstract readNullableString(): string | null; abstract readNullableBytes(): ArrayBuffer | null; abstract readNullableBigInt(): BigInt | null; diff --git a/packages/wasm/as/assembly/msgpack/ReadDecoder.ts b/packages/wasm/as/assembly/msgpack/ReadDecoder.ts index f276810161..3a902eb81e 100644 --- a/packages/wasm/as/assembly/msgpack/ReadDecoder.ts +++ b/packages/wasm/as/assembly/msgpack/ReadDecoder.ts @@ -9,13 +9,14 @@ import { isFixedArray, isFixedString, } from "./Format"; -import { Nullable } from "./Nullable"; import { Read } from "./Read"; import { BigInt, BigNumber } from "../math"; import { Context } from "../debug"; import { JSON } from "../json"; import { ExtensionType } from "./ExtensionType"; +import { Option } from "as-container"; + export class ReadDecoder extends Read { private readonly _context: Context; private _view: DataView; @@ -363,67 +364,67 @@ export class ReadDecoder extends Read { return this.readMap(key_fn, value_fn); } - readNullableBool(): Nullable { + readNullableBool(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readBool()); + return Option.Some(this.readBool()); } - readNullableInt8(): Nullable { + readNullableInt8(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readInt8()); + return Option.Some(this.readInt8()); } - readNullableInt16(): Nullable { + readNullableInt16(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readInt16()); + return Option.Some(this.readInt16()); } - readNullableInt32(): Nullable { + readNullableInt32(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readInt32()); + return Option.Some(this.readInt32()); } - readNullableUInt8(): Nullable { + readNullableUInt8(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readUInt8()); + return Option.Some(this.readUInt8()); } - readNullableUInt16(): Nullable { + readNullableUInt16(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readUInt16()); + return Option.Some(this.readUInt16()); } - readNullableUInt32(): Nullable { + readNullableUInt32(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readUInt32()); + return Option.Some(this.readUInt32()); } - readNullableFloat32(): Nullable { + readNullableFloat32(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readFloat32()); + return Option.Some(this.readFloat32()); } - readNullableFloat64(): Nullable { + readNullableFloat64(): Option { if (this.isNextNil()) { - return Nullable.fromNull(); + return Option.None(); } - return Nullable.fromValue(this.readFloat64()); + return Option.Some(this.readFloat64()); } readNullableString(): string | null { diff --git a/packages/wasm/as/assembly/msgpack/Write.ts b/packages/wasm/as/assembly/msgpack/Write.ts index b02a9ebbbf..f7ff982686 100644 --- a/packages/wasm/as/assembly/msgpack/Write.ts +++ b/packages/wasm/as/assembly/msgpack/Write.ts @@ -1,8 +1,9 @@ -import { Nullable } from "./Nullable"; import { BigInt, BigNumber } from "../math"; import { Context } from "../debug"; import { JSON } from "../json"; +import { Option } from "as-container"; + export abstract class Write { abstract writeNil(): void; abstract writeBool(value: bool): void; @@ -38,15 +39,15 @@ export abstract class Write { value_fn: (writer: Write, value: V) => void ): void; - abstract writeNullableBool(value: Nullable): void; - abstract writeNullableInt8(value: Nullable): void; - abstract writeNullableInt16(value: Nullable): void; - abstract writeNullableInt32(value: Nullable): void; - abstract writeNullableUInt8(value: Nullable): void; - abstract writeNullableUInt16(value: Nullable): void; - abstract writeNullableUInt32(value: Nullable): void; - abstract writeNullableFloat32(value: Nullable): void; - abstract writeNullableFloat64(value: Nullable): void; + abstract writeNullableBool(value: Option): void; + abstract writeNullableInt8(value: Option): void; + abstract writeNullableInt16(value: Option): void; + abstract writeNullableInt32(value: Option): void; + abstract writeNullableUInt8(value: Option): void; + abstract writeNullableUInt16(value: Option): void; + abstract writeNullableUInt32(value: Option): void; + abstract writeNullableFloat32(value: Option): void; + abstract writeNullableFloat64(value: Option): void; abstract writeNullableString(value: string | null): void; abstract writeNullableBytes(value: ArrayBuffer | null): void; abstract writeNullableBigInt(value: BigInt | null): void; diff --git a/packages/wasm/as/assembly/msgpack/WriteEncoder.ts b/packages/wasm/as/assembly/msgpack/WriteEncoder.ts index 8763a348ed..02140973b5 100644 --- a/packages/wasm/as/assembly/msgpack/WriteEncoder.ts +++ b/packages/wasm/as/assembly/msgpack/WriteEncoder.ts @@ -2,13 +2,14 @@ import { DataView } from "./DataView"; import { WriteSizer } from "./WriteSizer"; import { Format } from "./Format"; import { ExtensionType } from "./ExtensionType"; -import { Nullable } from "./Nullable"; import { Write } from "./Write"; import { throwArrayIndexOutOfRange } from "./utils"; import { BigInt, BigNumber } from "../math"; import { Context } from "../debug"; import { JSON } from "../json"; +import { Option } from "as-container"; + export class WriteEncoder extends Write { private readonly _context: Context; private _view: DataView; @@ -234,85 +235,85 @@ export class WriteEncoder extends Write { this.writeMap(m, key_fn, value_fn); } - writeNullableBool(value: Nullable): void { - if (value.isNull) { + writeNullableBool(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeBool(value.value); + this.writeBool(value.unwrap()); } - writeNullableInt8(value: Nullable): void { - if (value.isNull) { + writeNullableInt8(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeInt8(value.value); + this.writeInt8(value.unwrap()); } - writeNullableInt16(value: Nullable): void { - if (value.isNull) { + writeNullableInt16(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeInt16(value.value); + this.writeInt16(value.unwrap()); } - writeNullableInt32(value: Nullable): void { - if (value.isNull) { + writeNullableInt32(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeInt32(value.value); + this.writeInt32(value.unwrap()); } - writeNullableUInt8(value: Nullable): void { - if (value.isNull) { + writeNullableUInt8(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeUInt8(value.value); + this.writeUInt8(value.unwrap()); } - writeNullableUInt16(value: Nullable): void { - if (value.isNull) { + writeNullableUInt16(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeUInt16(value.value); + this.writeUInt16(value.unwrap()); } - writeNullableUInt32(value: Nullable): void { - if (value.isNull) { + writeNullableUInt32(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeUInt32(value.value); + this.writeUInt32(value.unwrap()); } - writeNullableFloat32(value: Nullable): void { - if (value.isNull) { + writeNullableFloat32(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeFloat32(value.value); + this.writeFloat32(value.unwrap()); } - writeNullableFloat64(value: Nullable): void { - if (value.isNull) { + writeNullableFloat64(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeFloat64(value.value); + this.writeFloat64(value.unwrap()); } writeNullableString(value: string | null): void { diff --git a/packages/wasm/as/assembly/msgpack/WriteSizer.ts b/packages/wasm/as/assembly/msgpack/WriteSizer.ts index f88aaf639f..4b32fd07c9 100644 --- a/packages/wasm/as/assembly/msgpack/WriteSizer.ts +++ b/packages/wasm/as/assembly/msgpack/WriteSizer.ts @@ -1,9 +1,10 @@ import { Write } from "./Write"; -import { Nullable } from "./Nullable"; import { BigInt, BigNumber } from "../math"; import { Context } from "../debug"; import { JSON } from "../json"; +import { Option } from "as-container"; + export class WriteSizer extends Write { length: i32; extByteLengths: Array; @@ -194,85 +195,85 @@ export class WriteSizer extends Write { this.extByteLengths.push(byteLength); } - writeNullableBool(value: Nullable): void { - if (value.isNull) { + writeNullableBool(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeBool(value.value); + this.writeBool(value.unwrap()); } - writeNullableInt8(value: Nullable): void { - if (value.isNull) { + writeNullableInt8(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeInt8(value.value); + this.writeInt8(value.unwrap()); } - writeNullableInt16(value: Nullable): void { - if (value.isNull) { + writeNullableInt16(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeInt16(value.value); + this.writeInt16(value.unwrap()); } - writeNullableInt32(value: Nullable): void { - if (value.isNull) { + writeNullableInt32(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeInt32(value.value); + this.writeInt32(value.unwrap()); } - writeNullableUInt8(value: Nullable): void { - if (value.isNull) { + writeNullableUInt8(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeUInt8(value.value); + this.writeUInt8(value.unwrap()); } - writeNullableUInt16(value: Nullable): void { - if (value.isNull) { + writeNullableUInt16(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeUInt16(value.value); + this.writeUInt16(value.unwrap()); } - writeNullableUInt32(value: Nullable): void { - if (value.isNull) { + writeNullableUInt32(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeUInt32(value.value); + this.writeUInt32(value.unwrap()); } - writeNullableFloat32(value: Nullable): void { - if (value.isNull) { + writeNullableFloat32(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeFloat32(value.value); + this.writeFloat32(value.unwrap()); } - writeNullableFloat64(value: Nullable): void { - if (value.isNull) { + writeNullableFloat64(value: Option): void { + if (value.isNone) { this.writeNil(); return; } - this.writeFloat64(value.value); + this.writeFloat64(value.unwrap()); } writeNullableString(value: string | null): void { diff --git a/packages/wasm/as/assembly/msgpack/index.ts b/packages/wasm/as/assembly/msgpack/index.ts index 1ed14b50e4..0f7d2c3630 100644 --- a/packages/wasm/as/assembly/msgpack/index.ts +++ b/packages/wasm/as/assembly/msgpack/index.ts @@ -3,4 +3,3 @@ export * from "./ReadDecoder"; export * from "./Write"; export * from "./WriteEncoder"; export * from "./WriteSizer"; -export * from "./Nullable"; diff --git a/packages/wasm/as/package.json b/packages/wasm/as/package.json index 9f6ca68113..4844fe93d5 100644 --- a/packages/wasm/as/package.json +++ b/packages/wasm/as/package.json @@ -21,8 +21,7 @@ "test:ci": "asp --summary" }, "dependencies": { - "@serial-as/transform": "1.0.2", - "@web3api/serial-as-json": "1.0.4", + "@web3api/assemblyscript-json": "1.2.0", "as-bigint": "0.5.3", "as-bignumber": "0.2.0", "as-container": "0.6.1" diff --git a/yarn.lock b/yarn.lock index 8da8eb0bc5..ff8727b724 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3081,10 +3081,10 @@ "@octokit/types" "^6.0.3" universal-user-agent "^6.0.0" -"@octokit/openapi-types@^12.1.0": - version "12.1.0" - resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-12.1.0.tgz#a68b60e969f26dee0eb7d127c65a84967f2d3a6e" - integrity sha512-kQzJh3ZUv3lDpi6M+uekMRHULvf9DlWoI1XgKN6nPeGDzkSgtkhVq1MMz3bFKQ6H6GbdC3ZqG/a6VzKhIx0VeA== +"@octokit/openapi-types@^12.4.0": + version "12.4.0" + resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-12.4.0.tgz#fd8bf5db72bd566c5ba2cb76754512a9ebe66e71" + integrity sha512-Npcb7Pv30b33U04jvcD7l75yLU0mxhuX2Xqrn51YyZ5WTkF04bpbxLaZ6GcaTqu03WZQHoO/Gbfp95NGRueDUA== "@octokit/plugin-enterprise-rest@^6.0.1": version "6.0.1" @@ -3092,11 +3092,11 @@ integrity sha512-93uGjlhUD+iNg1iWhUENAtJata6w5nE+V4urXOAlIXdco6xNZtUSfYY8dzp3Udy74aqO/B5UZL80x/YMa5PKRw== "@octokit/plugin-paginate-rest@^2.16.8": - version "2.18.0" - resolved "https://registry.yarnpkg.com/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.18.0.tgz#e412977782690a4134b0a4aa2f536cca7a2ca125" - integrity sha512-n5/AzIoy5Wzp85gqzSbR+dWQDHlyHZrGijnDfLh452547Ynu0hCvszH7EfRE0eqM5ZjfkplO0k+q+P8AAIIJEA== + version "2.19.0" + resolved "https://registry.yarnpkg.com/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.19.0.tgz#b52eae6ecacfa1f5583dc2cc0985cfbed3ca78b0" + integrity sha512-hQ4Qysg2hNmEMuZeJkvyzM4eSZiTifOKqYAMsW8FnxFKowhuwWICSgBQ9Gn9GpUmgKB7qaf1hFvMjYaTAg5jQA== dependencies: - "@octokit/types" "^6.35.0" + "@octokit/types" "^6.36.0" "@octokit/plugin-request-log@^1.0.4": version "1.0.4" @@ -3104,11 +3104,11 @@ integrity sha512-mLUsMkgP7K/cnFEw07kWqXGF5LKrOkD+lhCrKvPHXWDywAwuDUeDwWBpc69XK3pNX0uKiVt8g5z96PJ6z9xCFA== "@octokit/plugin-rest-endpoint-methods@^5.12.0": - version "5.14.0" - resolved "https://registry.yarnpkg.com/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.14.0.tgz#758e01ac40998e607feaea7f80220c69990814ae" - integrity sha512-MRnMs4Dcm1OSaz/g/RLr4YY9otgysS7vN5SUkHGd7t+R8323cHsHFoEWHYPSmgUC0BieHRhvnCRWb4i3Pl+Lgg== + version "5.15.0" + resolved "https://registry.yarnpkg.com/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.15.0.tgz#6c8251b55c33315a6e53e5b55654f72023ed5049" + integrity sha512-Gsw9+Xm56jVhfbJoy4pt6eOOyf8/3K6CAnx1Sl7U2GhZWcg8MR6YgXWnpfdF69S2ViMXLA7nfvTDAsZpFlkLRw== dependencies: - "@octokit/types" "^6.35.0" + "@octokit/types" "^6.36.0" deprecation "^2.3.1" "@octokit/request-error@^2.0.5", "@octokit/request-error@^2.1.0": @@ -3142,12 +3142,12 @@ "@octokit/plugin-request-log" "^1.0.4" "@octokit/plugin-rest-endpoint-methods" "^5.12.0" -"@octokit/types@^6.0.3", "@octokit/types@^6.16.1", "@octokit/types@^6.35.0": - version "6.35.0" - resolved "https://registry.yarnpkg.com/@octokit/types/-/types-6.35.0.tgz#11cd9a679c32b4a6c36459ae2ec3ac4de0104f71" - integrity sha512-DhLfdUuv3H37u6jBDfkwamypx3HflHg29b26nbA6iVFYkAlZ5cMEtu/9pQoihGnQE5M7jJFnNo25Rr1UwQNF8Q== +"@octokit/types@^6.0.3", "@octokit/types@^6.16.1", "@octokit/types@^6.36.0": + version "6.37.0" + resolved "https://registry.yarnpkg.com/@octokit/types/-/types-6.37.0.tgz#32eb78edb34cf5cea4ba5753ab8db75b776d617a" + integrity sha512-BXWQhFKRkjX4dVW5L2oYa0hzWOAqsEsujXsQLSdepPoDZfYdubrD1KDGpyNldGXtR8QM/WezDcxcIN1UKJMGPA== dependencies: - "@octokit/openapi-types" "^12.1.0" + "@octokit/openapi-types" "^12.4.0" "@opentelemetry/api-metrics@0.20.0": version "0.20.0" @@ -3284,21 +3284,6 @@ "@opentelemetry/semantic-conventions" "0.20.0" "@opentelemetry/tracing" "0.20.0" -"@serial-as/core@1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@serial-as/core/-/core-1.0.2.tgz#a3b21d6962fed7aaae978d63bc0551be65b36ea6" - integrity sha512-aJFMzEn5eztHI5ZcxCGYiRXuj8xVQt+JGTzCVHq/NMBHubAi4MC48/e3VVjqGoHo+FdPlnGropx08YPrc3ENCw== - dependencies: - "@serial-as/transform" "1.0.2" - as-bignum "^0.2.17" - -"@serial-as/transform@1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@serial-as/transform/-/transform-1.0.2.tgz#95ed7aa2879f13825ea4b404718ee1eca9ad71c7" - integrity sha512-1Uti3bxGYrkN1yhV0aVuAQ46dsEvWXUDVQ+2btC5nFo0N2UJ8860K3HVc6y3Xm2pEDMW/6IrmfZoapNV1E3jMw== - dependencies: - visitor-as "^0.7.0-1" - "@sinonjs/commons@^1.7.0": version "1.8.3" resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.3.tgz#3802ddd21a50a949b6721ddd72da36e67e7f1b2d" @@ -3941,15 +3926,6 @@ resolved "https://registry.yarnpkg.com/@web3api/assemblyscript-json/-/assemblyscript-json-1.2.0.tgz#f01f11f12a66cd1a319d43f12e476307d1ad3da8" integrity sha512-x+wchJpH1giJzXj3dYs8vh2SKMXepeqVXiaFV/YCtXg4X/KaUnxi0kp5JugbEAyEJurEScH1YuV6IvGhGui/fw== -"@web3api/serial-as-json@1.0.4": - version "1.0.4" - resolved "https://registry.yarnpkg.com/@web3api/serial-as-json/-/serial-as-json-1.0.4.tgz#87724866b823182591ab6831c7c24b87f713a520" - integrity sha512-ip5VsRFIXIlqiPxAivNnS/UoyuMZiflKz2ljgjJABmeFhwbuuoMxUO/efHc85mqZ2AGbG1n4K8q+mcH8hqchcQ== - dependencies: - "@serial-as/core" "1.0.2" - "@web3api/assemblyscript-json" "1.2.0" - as-base64 "^0.2.0" - "@webassemblyjs/ast@1.8.5": version "1.8.5" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.8.5.tgz#51b1c5fe6576a34953bf4b253df9f0d490d9e359" @@ -4612,21 +4588,11 @@ arrify@^2.0.1: resolved "https://registry.yarnpkg.com/arrify/-/arrify-2.0.1.tgz#c9655e9331e0abcd588d2a7cad7e9956f66701fa" integrity sha512-3duEwti880xqi4eAMN8AyR4a0ByT90zoYdLlevfrvU43vb0YZwZVfxOgxWrLXXXpyugL0hNZc9G6BiB5B3nUug== -as-base64@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/as-base64/-/as-base64-0.2.0.tgz#b4bed937c93bfb6524b932b517e1b8571a0dd518" - integrity sha512-j6JxprAVN4SXUcZiSChuMBf0JJOCdh5OfrHAepluxmFWuDZZm+YjmfNSk8djUHRPEB+Ui5HGvrz46GLvTJf3ig== - as-bigint@0.5.3, as-bigint@^0.5.1: version "0.5.3" resolved "https://registry.yarnpkg.com/as-bigint/-/as-bigint-0.5.3.tgz#a0647d0b7ce835077aca33115e71eb26a83df8be" integrity sha512-tg9iTO/vPeovOM5CSk1WxYcsfBd/cd3twhBW5PrpcGUfiSEXlPB69eOxFKvSbZnpuDxBAyQ4YBgEkfnYL89Czw== -as-bignum@^0.2.17: - version "0.2.18" - resolved "https://registry.yarnpkg.com/as-bignum/-/as-bignum-0.2.18.tgz#61ed4dd07d4a62107bde227fdb4370190217bf0b" - integrity sha512-5LODrOr7wvS643oh7PHfyRtbBO9vCcU69vNNvrqh5yovrApM9nRHDeT5XcqnaSI8TqK9ZhN12qhZnq4rdIGcwQ== - as-bignumber@0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/as-bignumber/-/as-bignumber-0.2.0.tgz#13feb2e5054c8a2d557618de2e507af39cfb7532" @@ -5362,15 +5328,14 @@ browserslist@4.10.0: pkg-up "^3.1.0" browserslist@^4.0.0, browserslist@^4.12.0, browserslist@^4.20.2, browserslist@^4.20.4, browserslist@^4.6.2, browserslist@^4.6.4, browserslist@^4.9.1: - version "4.20.4" - resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.20.4.tgz#98096c9042af689ee1e0271333dbc564b8ce4477" - integrity sha512-ok1d+1WpnU24XYN7oC3QWgTyMhY/avPJ/r9T00xxvUOIparA/gc+UPUMaod3i+G6s+nI2nUb9xZ5k794uIwShw== + version "4.21.0" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.21.0.tgz#7ab19572361a140ecd1e023e2c1ed95edda0cefe" + integrity sha512-UQxE0DIhRB5z/zDz9iA03BOfxaN2+GQdBYH/2WrSIWEUrnpzTPJbhqt+umq6r3acaPRTW1FNTkrcp0PXgtFkvA== dependencies: - caniuse-lite "^1.0.30001349" - electron-to-chromium "^1.4.147" - escalade "^3.1.1" + caniuse-lite "^1.0.30001358" + electron-to-chromium "^1.4.164" node-releases "^2.0.5" - picocolors "^1.0.0" + update-browserslist-db "^1.0.0" bs-logger@0.x: version "0.2.6" @@ -5639,11 +5604,16 @@ caniuse-api@^3.0.0: lodash.memoize "^4.1.2" lodash.uniq "^4.5.0" -caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001035, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001349: +caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001035, caniuse-lite@^1.0.30001109: version "1.0.30001357" resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001357.tgz#dec7fc4158ef6ad24690d0eec7b91f32b8cb1b5d" integrity sha512-b+KbWHdHePp+ZpNj+RDHFChZmuN+J5EvuQUlee9jOQIUAdhv9uvAZeEtUeLAknXbkiu1uxjQ9NLp1ie894CuWg== +caniuse-lite@^1.0.30001358: + version "1.0.30001358" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001358.tgz#473d35dabf5e448b463095cab7924e96ccfb8c00" + integrity sha512-hvp8PSRymk85R20bsDra7ZTCpSVGN/PAz9pSAjPSjKC+rNmnUk5vCRgJwiTT/O4feQ/yu/drvZYpKxxhbFuChw== + capture-exit@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/capture-exit/-/capture-exit-2.0.0.tgz#fb953bfaebeb781f62898239dabb426d08a509a4" @@ -6370,17 +6340,17 @@ copyfiles@2.4.1: yargs "^16.1.0" core-js-compat@^3.21.0, core-js-compat@^3.22.1, core-js-compat@^3.6.2: - version "3.23.1" - resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.23.1.tgz#23d44d9f209086e60dabf9130cea7719af6e199b" - integrity sha512-KeYrEc8t6FJsKYB2qnDwRHWaC0cJNaqlHfCpMe5q3j/W1nje3moib/txNklddLPCtGb+etcBIyJ8zuMa/LN5/A== + version "3.23.2" + resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.23.2.tgz#5cbf8a9c8812d665392845b85ae91b5bcc7b615c" + integrity sha512-lrgZvxFwbQp9v7E8mX0rJ+JX7Bvh4eGULZXA1IAyjlsnWvCdw6TF8Tg6xtaSUSJMrSrMaLdpmk+V54LM1dvfOA== dependencies: browserslist "^4.20.4" semver "7.0.0" core-js-pure@^3.20.2: - version "3.23.1" - resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.23.1.tgz#0b27e4c3ad46178b84e790dbbb81987218ab82ad" - integrity sha512-3qNgf6TqI3U1uhuSYRzJZGfFd4T+YlbyVPl+jgRiKjdZopvG4keZQwWZDAWpu1UH9nCgTpUzIV3GFawC7cJsqg== + version "3.23.2" + resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.23.2.tgz#efe5e486469c5ed2d088d76e973eb12e74a930e7" + integrity sha512-t6u7H4Ff/yZNk+zqTr74UjCcZ3k8ApBryeLLV4rYQd9aF3gqmjjGjjR44ENfeBMH8VVvSynIjAJ0mUuFhzQtrA== core-js@^2.4.0: version "2.6.12" @@ -6388,9 +6358,9 @@ core-js@^2.4.0: integrity sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ== core-js@^3.5.0: - version "3.23.1" - resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.23.1.tgz#9f9a9255115f62c512db56d567f636da32ca0b78" - integrity sha512-wfMYHWi1WQjpgZNC9kAlN4ut04TM9fUTdi7CqIoTVM7yaiOUQTklOzfb+oWH3r9edQcT3F887swuVmxrV+CC8w== + version "3.23.2" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.23.2.tgz#e07a60ca8b14dd129cabdc3d2551baf5a01c76f0" + integrity sha512-ELJOWxNrJfOH/WK4VJ3Qd+fOqZuOuDNDJz0xG6Bt4mGg2eO/UT9CljCrbqDGovjLKUrGajEEBcoTOc0w+yBYeQ== core-util-is@1.0.2: version "1.0.2" @@ -7319,11 +7289,16 @@ electron-fetch@^1.7.2: dependencies: encoding "^0.1.13" -electron-to-chromium@^1.3.378, electron-to-chromium@^1.4.147: +electron-to-chromium@^1.3.378: version "1.4.161" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.161.tgz#49cb5b35385bfee6cc439d0a04fbba7a7a7f08a1" integrity sha512-sTjBRhqh6wFodzZtc5Iu8/R95OkwaPNn7tj/TaDU5nu/5EFiQDtADGAXdR4tJcTEHlYfJpHqigzJqHvPgehP8A== +electron-to-chromium@^1.4.164: + version "1.4.167" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.167.tgz#72424aebc85df12c5331d37b1bcfd1ae01322c55" + integrity sha512-lPHuHXBwpkr4RcfaZBKm6TKOWG/1N9mVggUpP4fY3l1JIUU2x4fkM8928smYdZ5lF+6KCTAxo1aK9JmqT+X71Q== + elliptic@6.5.4, elliptic@^6.5.3: version "6.5.4" resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb" @@ -9346,9 +9321,9 @@ http-errors@~1.6.2: statuses ">= 1.4.0 < 2" http-parser-js@>=0.5.1: - version "0.5.6" - resolved "https://registry.yarnpkg.com/http-parser-js/-/http-parser-js-0.5.6.tgz#2e02406ab2df8af8a7abfba62e0da01c62b95afd" - integrity sha512-vDlkRPDJn93swjcjqMSaGSPABbIarsr1TLAui/gLDXzV5VsJNdXNzMYDyNBLQkjWQCJ1uizu8T2oDMhmGt0PRA== + version "0.5.7" + resolved "https://registry.yarnpkg.com/http-parser-js/-/http-parser-js-0.5.7.tgz#39bde369fb8a57235121bb69d05f079fa1b598f4" + integrity sha512-8gQM8ZcewlONQLnik2AKzS13euQhaZcu4rK5QBSYOszW0T1upLW9VA2MdWvTvMmRo42HjXp7igFmdROoBCCrfg== http-proxy-agent@^4.0.1: version "4.0.1" @@ -12775,9 +12750,9 @@ multicodec@^3.0.1: varint "^6.0.0" multiformats@^9.4.2: - version "9.6.5" - resolved "https://registry.yarnpkg.com/multiformats/-/multiformats-9.6.5.tgz#f2d894a26664b454a90abf5a8911b7e39195db80" - integrity sha512-vMwf/FUO+qAPvl3vlSZEgEVFY/AxeZq5yg761ScF3CZsXgmTi/HGkicUiNN0CI4PW8FiY2P0OLklOcmQjdQJhw== + version "9.7.0" + resolved "https://registry.yarnpkg.com/multiformats/-/multiformats-9.7.0.tgz#845799e8df70fbb6b15922500e45cb87cf12f7e5" + integrity sha512-uv/tcgwk0yN4DStopnBN4GTgvaAlYdy6KnZpuzEPFOYQd71DYFJjs0MN1ERElAflrZaYyGBWXyGxL5GgrxIx0Q== multihashes@^0.4.15, multihashes@~0.4.15, multihashes@~0.4.19: version "0.4.21" @@ -17660,6 +17635,14 @@ upath@^2.0.1: resolved "https://registry.yarnpkg.com/upath/-/upath-2.0.1.tgz#50c73dea68d6f6b990f51d279ce6081665d61a8b" integrity sha512-1uEe95xksV1O0CYKXo8vQvN1JEbtJp7lb7C5U9HMsIp6IVwntkH/oNUzyVNQSd4S1sYk2FpSSW44FqMc8qee5w== +update-browserslist-db@^1.0.0: + version "1.0.4" + resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.4.tgz#dbfc5a789caa26b1db8990796c2c8ebbce304824" + integrity sha512-jnmO2BEGUjsMOe/Fg9u0oczOe/ppIDZPebzccl1yDWGLFP16Pa1/RM5wEoKYPG2zstNcDuAStejyxsOuKINdGA== + dependencies: + escalade "^3.1.1" + picocolors "^1.0.0" + uri-js@^4.2.2: version "4.4.1" resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e" @@ -17860,14 +17843,6 @@ visitor-as@^0.6.0: lodash.clonedeep "^4.5.0" ts-mixer "^5.4.1" -visitor-as@^0.7.0-1: - version "0.7.0-2" - resolved "https://registry.yarnpkg.com/visitor-as/-/visitor-as-0.7.0-2.tgz#28f1c51801a677f14c4487c78a85ad541cfe382d" - integrity sha512-JDviqVnGn8i5qafLYuZUGlNeyc/8STIBnmNiXizvHO29xxJDaHNHxbr4Gh+9ksIJvMh9TNQKBeSyT2tldNbpJw== - dependencies: - lodash.clonedeep "^4.5.0" - ts-mixer "^5.4.1" - vm-browserify@^1.0.1: version "1.1.2" resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.2.tgz#78641c488b8e6ca91a75f511e7a3b32a86e5dda0"