diff --git a/package.json b/package.json index 2befafc862..d27d3854f1 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "clean": "npx rimraf ./**/node_modules ./**/yarn.lock ./**/build ./**/coverage ./**/.polywrap", "dependencies:install": "cd dependencies && yarn", "preinstall": "yarn dependencies:install", - "build": "yarn build:core && yarn build:interfaces && yarn build:plugins && yarn build:resolver:plugins && yarn build:config && yarn build:client && yarn build:test-env && yarn build:cli", + "build": "yarn build:core && yarn build:interfaces && yarn link:schema && yarn build:plugins && yarn build:resolver:plugins && yarn build:config && yarn build:client && yarn build:test-env && yarn build:cli", "build:core": "lerna run build --no-private --ignore @polywrap/*-plugin-js --ignore @polywrap/client-config-builder-js --ignore polywrap --ignore @polywrap/client-js --ignore @polywrap/react --ignore @polywrap/test-env-js --ignore @polywrap/*-interface", "build:interfaces": "lerna run build --scope @polywrap/*-interface", "build:plugins": "lerna run build --scope @polywrap/*-plugin-js --ignore @polywrap/*-resolver-plugin-js", diff --git a/packages/cli/package.json b/packages/cli/package.json index 6e9599928f..745a0a9656 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -47,7 +47,6 @@ "@polywrap/ens-resolver-plugin-js": "0.9.3", "@polywrap/ethereum-plugin-js": "0.9.3", "@polywrap/ipfs-plugin-js": "0.9.3", - "@polywrap/msgpack-js": "0.9.3", "@polywrap/os-js": "0.9.3", "@polywrap/polywrap-manifest-types-js": "0.9.3", "@polywrap/schema-bind": "0.9.3", diff --git a/packages/cli/src/__tests__/unit/jobrunner.spec.ts b/packages/cli/src/__tests__/unit/jobrunner.spec.ts index 602d0561eb..9ab4116b48 100644 --- a/packages/cli/src/__tests__/unit/jobrunner.spec.ts +++ b/packages/cli/src/__tests__/unit/jobrunner.spec.ts @@ -3,26 +3,27 @@ import { buildWrapper } from "@polywrap/test-env-js"; import { testCases } from "./jobrunner-test-cases"; import { JobRunner } from "../../lib"; import path from "path"; -import { PolywrapClient } from "@polywrap/client-js"; +import { ClientConfigBuilder, ClientConfig } from "@polywrap/client-config-builder-js"; jest.setTimeout(200000); describe("workflow JobRunner", () => { - - let client: PolywrapClient; + let defaultConfig: ClientConfig; beforeAll(async () => { await buildWrapper( path.join(GetPathToTestWrappers(), "wasm-as", "simple-calculator") ); - client = new PolywrapClient({}); + defaultConfig = new ClientConfigBuilder().addDefaults().build(); }); for (const testCase of testCases) { it(testCase.name, async () => { - expect(client).toBeTruthy(); const ids = Object.keys(testCase.workflow.jobs); - const jobRunner = new JobRunner(client, testCase.onExecution); + const jobRunner = new JobRunner( + defaultConfig, + testCase.onExecution + ); await jobRunner.run(testCase.workflow.jobs, ids); }); } diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index 6e77995d05..1dd9bd818c 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -25,8 +25,9 @@ import { import path from "path"; import readline from "readline"; -import { PolywrapClient, PolywrapClientConfig } from "@polywrap/client-js"; +import { PolywrapClient } from "@polywrap/client-js"; import { PolywrapManifest } from "@polywrap/polywrap-manifest-types-js"; +import { ClientConfig } from "@polywrap/client-config-builder-js"; const defaultOutputDir = "./build"; const defaultStrategy = SupportedStrategies.VM; @@ -37,7 +38,7 @@ const pathStr = intlMsg.commands_build_options_o_path(); type BuildCommandOptions = { manifestFile: string; outputDir: string; - clientConfig: Partial; + clientConfig: Partial; codegen: boolean; // defaults to true watch?: boolean; strategy: SupportedStrategies; diff --git a/packages/cli/src/commands/codegen.ts b/packages/cli/src/commands/codegen.ts index ef882081a1..49e4d9bced 100644 --- a/packages/cli/src/commands/codegen.ts +++ b/packages/cli/src/commands/codegen.ts @@ -18,9 +18,10 @@ import { } from "../lib"; import { ScriptCodegenerator } from "../lib/codegen/ScriptCodeGenerator"; -import { PolywrapClient, PolywrapClientConfig } from "@polywrap/client-js"; +import { PolywrapClient } from "@polywrap/client-js"; import path from "path"; import fs from "fs"; +import { ClientConfig } from "@polywrap/client-config-builder-js"; const defaultCodegenDir = "./src/wrap"; const defaultPublishDir = "./build"; @@ -33,7 +34,7 @@ type CodegenCommandOptions = { codegenDir: string; publishDir: string; script?: string; - clientConfig: Partial; + clientConfig: Partial; verbose?: boolean; quiet?: boolean; logFile?: string; diff --git a/packages/cli/src/commands/docgen.ts b/packages/cli/src/commands/docgen.ts index 03578572c7..d9eb1d2e4e 100644 --- a/packages/cli/src/commands/docgen.ts +++ b/packages/cli/src/commands/docgen.ts @@ -17,9 +17,10 @@ import { scriptPath as jsdocScriptPath } from "../lib/docgen/jsdoc"; import { scriptPath as schemaScriptPath } from "../lib/docgen/schema"; import { ScriptCodegenerator } from "../lib/codegen/ScriptCodeGenerator"; -import { PolywrapClient, PolywrapClientConfig } from "@polywrap/client-js"; +import { PolywrapClient } from "@polywrap/client-js"; import chalk from "chalk"; import { Argument } from "commander"; +import { ClientConfig } from "@polywrap/client-config-builder-js"; const commandToPathMap: Record = { schema: schemaScriptPath, @@ -35,7 +36,7 @@ const pathStr = intlMsg.commands_codegen_options_o_path(); type DocgenCommandOptions = { manifestFile: string; docgenDir: string; - clientConfig: Partial; + clientConfig: Partial; imports: boolean; verbose?: boolean; quiet?: boolean; diff --git a/packages/cli/src/commands/run.ts b/packages/cli/src/commands/run.ts index 83f5a1bd3c..faa9322b48 100644 --- a/packages/cli/src/commands/run.ts +++ b/packages/cli/src/commands/run.ts @@ -18,13 +18,13 @@ import { } from "../lib"; import { createLogger } from "./utils/createLogger"; -import { PolywrapClient, PolywrapClientConfig } from "@polywrap/client-js"; import path from "path"; import yaml from "yaml"; import fs from "fs"; +import { ClientConfig } from "@polywrap/client-config-builder-js"; type WorkflowCommandOptions = { - clientConfig: Partial; + clientConfig: Partial; manifest: string; jobs?: string[]; validationScript?: string; @@ -95,7 +95,6 @@ const _run = async (options: WorkflowCommandOptions) => { logFile, } = options; const logger = createLogger({ verbose, quiet, logFile }); - const client = new PolywrapClient(clientConfig); const manifestPath = path.resolve(manifest); const workflow = await loadWorkflowManifest(manifestPath, logger); @@ -128,7 +127,7 @@ const _run = async (options: WorkflowCommandOptions) => { workflowOutput.push(output); }; - const jobRunner = new JobRunner(client, onExecution); + const jobRunner = new JobRunner(clientConfig, onExecution); await jobRunner.run(workflow.jobs, jobs ?? Object.keys(workflow.jobs)); if (outputFile) { diff --git a/packages/cli/src/lib/build-strategies/strategies/DockerImageStrategy.ts b/packages/cli/src/lib/build-strategies/strategies/DockerImageStrategy.ts index ea6dd12a85..4f134eb469 100644 --- a/packages/cli/src/lib/build-strategies/strategies/DockerImageStrategy.ts +++ b/packages/cli/src/lib/build-strategies/strategies/DockerImageStrategy.ts @@ -266,7 +266,10 @@ export class DockerImageBuildStrategy extends BuildStrategy { } await runCommand( `docker buildx build -f ${dockerfile} -t ${imageName} ${rootDir} ${cacheFrom} ${cacheTo} --output=type=docker`, - this.project.logger + this.project.logger, + undefined, + undefined, + true ); } else { await runCommand( @@ -277,7 +280,9 @@ export class DockerImageBuildStrategy extends BuildStrategy { : { // eslint-disable-next-line @typescript-eslint/naming-convention DOCKER_BUILDKIT: "true", - } + }, + undefined, + true ); } diff --git a/packages/cli/src/lib/defaults/deploy-modules/ens-recursive-name-register/index.ts b/packages/cli/src/lib/defaults/deploy-modules/ens-recursive-name-register/index.ts index 64aafbd648..7255d1711e 100644 --- a/packages/cli/src/lib/defaults/deploy-modules/ens-recursive-name-register/index.ts +++ b/packages/cli/src/lib/defaults/deploy-modules/ens-recursive-name-register/index.ts @@ -5,13 +5,13 @@ import { Deployer } from "../../../deploy"; import { Wallet } from "@ethersproject/wallet"; import { JsonRpcProvider } from "@ethersproject/providers"; import { Uri } from "@polywrap/core-js"; -import { PolywrapClient } from "@polywrap/client-js"; import { ethereumPlugin, Connections, Connection, } from "@polywrap/ethereum-plugin-js"; import { embeddedWrappers } from "@polywrap/test-env-js"; +import { PolywrapClient } from "@polywrap/client-js"; class ENSRecursiveNameRegisterPublisher implements Deployer { async execute( @@ -62,10 +62,10 @@ class ENSRecursiveNameRegisterPublisher implements Deployer { to: embeddedWrappers.sha3, }, ], - plugins: [ + packages: [ { uri: ethereumPluginUri, - plugin: ethereumPlugin({ + package: ethereumPlugin({ connections: new Connections({ networks: { [network]: new Connection({ diff --git a/packages/cli/src/lib/defaults/deploy-modules/ens/index.ts b/packages/cli/src/lib/defaults/deploy-modules/ens/index.ts index 8d4453e6e2..8be5bcb826 100644 --- a/packages/cli/src/lib/defaults/deploy-modules/ens/index.ts +++ b/packages/cli/src/lib/defaults/deploy-modules/ens/index.ts @@ -5,13 +5,13 @@ import { Deployer } from "../../../deploy"; import { Wallet } from "@ethersproject/wallet"; import { JsonRpcProvider } from "@ethersproject/providers"; import { Uri } from "@polywrap/core-js"; -import { PolywrapClient } from "@polywrap/client-js"; import { - ethereumPlugin, Connections, Connection, + ethereumPlugin, } from "@polywrap/ethereum-plugin-js"; import { embeddedWrappers } from "@polywrap/test-env-js"; +import { PolywrapClient } from "@polywrap/client-js"; const contentHash = require("content-hash"); @@ -59,10 +59,10 @@ class ENSPublisher implements Deployer { to: embeddedWrappers.sha3, }, ], - plugins: [ + packages: [ { uri: ethereumPluginUri, - plugin: ethereumPlugin({ + package: ethereumPlugin({ connections: new Connections({ networks: { [network]: new Connection({ diff --git a/packages/cli/src/lib/defaults/infra-modules/http/server/package.json b/packages/cli/src/lib/defaults/infra-modules/http/server/package.json index ff5b63817d..ec1738ed4d 100644 --- a/packages/cli/src/lib/defaults/infra-modules/http/server/package.json +++ b/packages/cli/src/lib/defaults/infra-modules/http/server/package.json @@ -12,7 +12,7 @@ }, "license": "MIT", "dependencies": { - "@polywrap/msgpack-js": "0.7.0", + "@polywrap/msgpack-js": "0.9.3", "@types/multer": "1.4.7", "dotenv": "8.6.0", "express": "4.18.1", diff --git a/packages/cli/src/lib/helpers/client.ts b/packages/cli/src/lib/helpers/client.ts deleted file mode 100644 index 1e42c8389f..0000000000 --- a/packages/cli/src/lib/helpers/client.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { PluginRegistration, Env } from "@polywrap/core-js"; -import { ensResolverPlugin } from "@polywrap/ens-resolver-plugin-js"; -import { - ethereumPlugin, - Connection, - Connections, -} from "@polywrap/ethereum-plugin-js"; -import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; -import { PolywrapClient } from "@polywrap/client-js"; -import { defaultIpfsProviders } from "@polywrap/client-config-builder-js"; - -interface SimpleClientConfig { - ensAddress?: string; - ethProvider?: string; - ipfsProvider?: string; -} - -export function getSimpleClient(config: SimpleClientConfig): PolywrapClient { - const { ensAddress, ethProvider, ipfsProvider } = config; - const plugins: PluginRegistration[] = []; - const envs: Env[] = []; - - if (ensAddress) { - plugins.push({ - uri: "wrap://ens/ens-resolver.polywrap.eth", - plugin: ensResolverPlugin({ - addresses: { - testnet: ensAddress, - }, - }), - }); - } - if (ethProvider) { - plugins.push({ - uri: "wrap://ens/ethereum.polywrap.eth", - plugin: ethereumPlugin({ - connections: new Connections({ - networks: { - testnet: new Connection({ - provider: ethProvider, - }), - }, - }), - }), - }); - } - if (ipfsProvider) { - plugins.push({ - uri: "wrap://ens/ipfs.polywrap.eth", - plugin: ipfsPlugin({}), - }); - - envs.push({ - uri: "wrap://ens/ipfs.polywrap.eth", - env: { - provider: ipfsProvider, - fallbackProviders: defaultIpfsProviders, - }, - }); - } - return new PolywrapClient({ plugins }); -} diff --git a/packages/cli/src/lib/helpers/index.ts b/packages/cli/src/lib/helpers/index.ts index 9226d360ac..1c524c1700 100644 --- a/packages/cli/src/lib/helpers/index.ts +++ b/packages/cli/src/lib/helpers/index.ts @@ -1,4 +1,3 @@ -export * from "./client"; export * from "./metadata"; export * from "./uuid"; export * from "./validate-client-config"; diff --git a/packages/cli/src/lib/helpers/validate-client-config.ts b/packages/cli/src/lib/helpers/validate-client-config.ts index 0538796e05..1a42c9d4a6 100644 --- a/packages/cli/src/lib/helpers/validate-client-config.ts +++ b/packages/cli/src/lib/helpers/validate-client-config.ts @@ -3,16 +3,14 @@ import { intlMsg } from "../intl"; import { Env, InterfaceImplementations, - PluginPackage, - PluginRegistration, + IUriRedirect, Uri, - UriRedirect, - PolywrapClientConfig, } from "@polywrap/client-js"; +import { ClientConfig } from "@polywrap/client-config-builder-js"; -export function validateRedirects< - TUri extends PluginPackage | Uri | string ->(redirects: readonly UriRedirect[]): void { +export function validateRedirects( + redirects: readonly IUriRedirect[] +): void { if (!Array.isArray(redirects)) { throw new Error(intlMsg.commands_run_error_redirectsExportNotArray()); } @@ -43,50 +41,6 @@ export function validateRedirects< } } -export function validatePlugins( - plugins: readonly PluginRegistration[] -): void { - if (!Array.isArray(plugins)) { - throw new Error(intlMsg.commands_run_error_pluginsExportNotArray()); - } - - // Ensure each plugin in the array is valid - for (let i = 0; i < plugins.length; ++i) { - const plugin = plugins[i]; - if (typeof plugin !== "object") { - throw new Error( - intlMsg.commands_run_error_pluginsItemNotObject({ - index: i.toString(), - }) - ); - } else if (typeof plugin.uri !== "string") { - throw new Error( - intlMsg.commands_run_error_pluginsItemUriNotString({ - index: i.toString(), - }) - ); - } else if (typeof plugin.plugin !== "object") { - throw new Error( - intlMsg.commands_run_error_pluginsItemPluginNotObject({ - index: i.toString(), - }) - ); - } else if (typeof plugin.plugin.factory !== "function") { - throw new Error( - intlMsg.commands_run_error_pluginsItemPluginFactoryNotFunction({ - index: i.toString(), - }) - ); - } else if (typeof plugin.plugin.manifest !== "object") { - throw new Error( - intlMsg.commands_run_error_pluginsItemPluginManifestNotObject({ - index: i.toString(), - }) - ); - } - } -} - export function validateInterfaces( interfaces: readonly InterfaceImplementations[] ): void { @@ -167,13 +121,10 @@ export function validateEnvs( } } -export function validateClientConfig( - config: Partial -): void { +export function validateClientConfig(config: Partial): void { if (!config || typeof config !== "object") { throw new Error(intlMsg.commands_run_error_clientConfigNotObject()); } - if (config.plugins) validatePlugins(config.plugins); if (config.envs) validateEnvs(config.envs); if (config.interfaces) validateInterfaces(config.interfaces); if (config.redirects) validateRedirects(config.redirects); diff --git a/packages/cli/src/lib/option-parsers/client-config.ts b/packages/cli/src/lib/option-parsers/client-config.ts index 0f3f464d03..3b7064abe6 100644 --- a/packages/cli/src/lib/option-parsers/client-config.ts +++ b/packages/cli/src/lib/option-parsers/client-config.ts @@ -3,16 +3,20 @@ import { intlMsg } from "../intl"; import { importTypescriptModule } from "../system"; import { getTestEnvClientConfig } from "../test-env"; -import { PolywrapClientConfig } from "@polywrap/client-js"; +import { Uri } from "@polywrap/core-js"; +import { + ClientConfigBuilder, + ClientConfig, +} from "@polywrap/client-config-builder-js"; import path from "path"; export async function parseClientConfigOption( clientConfig: string | undefined -): Promise> { - let finalClientConfig: Partial; +): Promise>> { + const builder = new ClientConfigBuilder().addDefaults(); try { - finalClientConfig = await getTestEnvClientConfig(); + builder.add(getTestEnvClientConfig()); } catch (e) { console.error(intlMsg.commands_run_error_noTestEnvFound()); process.exit(1); @@ -34,7 +38,7 @@ export async function parseClientConfigOption( process.exit(1); } - if (!configModule || !configModule.getClientConfig) { + if (!configModule || !configModule.getCustomConfig) { const configsModuleMissingExportMessage = intlMsg.commands_run_error_clientConfigModuleMissingExport( { module: configModule } ); @@ -42,15 +46,16 @@ export async function parseClientConfigOption( process.exit(1); } - finalClientConfig = await configModule.getClientConfig(finalClientConfig); + const customConfig = await configModule.getCustomConfig(); try { - validateClientConfig(finalClientConfig); + validateClientConfig(customConfig); + return builder.add(customConfig).build(); } catch (e) { console.error(e.message); process.exit(1); } + } else { + return builder.build(); } - - return finalClientConfig; } diff --git a/packages/cli/src/lib/test-env/client-config.ts b/packages/cli/src/lib/test-env/client-config.ts index 5e968f1eb3..803b6fee93 100644 --- a/packages/cli/src/lib/test-env/client-config.ts +++ b/packages/cli/src/lib/test-env/client-config.ts @@ -1,6 +1,6 @@ import { getTestEnvProviders } from "./providers"; -import { PluginRegistration, PolywrapClientConfig } from "@polywrap/client-js"; +import { PolywrapClientConfig } from "@polywrap/client-js"; import { defaultIpfsProviders } from "@polywrap/client-config-builder-js"; import { ensResolverPlugin } from "@polywrap/ens-resolver-plugin-js"; import { @@ -10,12 +10,11 @@ import { } from "@polywrap/ethereum-plugin-js"; import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; import { ensAddresses } from "@polywrap/test-env-js"; -import { Env } from "@polywrap/core-js"; -export async function getTestEnvClientConfig(): Promise< - Partial -> { - const providers = await getTestEnvProviders(); +export function getTestEnvClientConfig(): Partial { + // TODO: move this into its own package, since it's being used everywhere? + // maybe have it exported from test-env. + const providers = getTestEnvProviders(); const ipfsProvider = providers.ipfsProvider; const ethProvider = providers.ethProvider; @@ -25,47 +24,41 @@ export async function getTestEnvClientConfig(): Promise< const ensAddress = ensAddresses.ensAddress; - // TODO: move this into its own package, since it's being used everywhere? - // maybe have it exported from test-env. - const plugins: PluginRegistration[] = [ - { - uri: "wrap://ens/ethereum.polywrap.eth", - plugin: ethereumPlugin({ - connections: new Connections({ - networks: { - testnet: new Connection({ - provider: ethProvider, - }), + return { + envs: [ + { + uri: "wrap://ens/ipfs.polywrap.eth", + env: { + provider: ipfsProvider, + fallbackProviders: defaultIpfsProviders, + }, + }, + ], + packages: [ + { + uri: "wrap://ens/ethereum.polywrap.eth", + package: ethereumPlugin({ + connections: new Connections({ + networks: { + testnet: new Connection({ + provider: ethProvider, + }), + }, + }), + }), + }, + { + uri: "wrap://ens/ipfs.polywrap.eth", + package: ipfsPlugin({}), + }, + { + uri: "wrap://ens/ens-resolver.polywrap.eth", + package: ensResolverPlugin({ + addresses: { + testnet: ensAddress, }, }), - }), - }, - { - uri: "wrap://ens/ipfs.polywrap.eth", - plugin: ipfsPlugin({}), - }, - { - uri: "wrap://ens/ens-resolver.polywrap.eth", - plugin: ensResolverPlugin({ - addresses: { - testnet: ensAddress, - }, - }), - }, - ]; - - const envs: Env[] = [ - { - uri: "wrap://ens/ipfs.polywrap.eth", - env: { - provider: ipfsProvider, - fallbackProviders: defaultIpfsProviders, }, - }, - ]; - - return { - plugins, - envs, + ], }; } diff --git a/packages/cli/src/lib/test-env/providers.ts b/packages/cli/src/lib/test-env/providers.ts index bfe81b5589..4846273449 100644 --- a/packages/cli/src/lib/test-env/providers.ts +++ b/packages/cli/src/lib/test-env/providers.ts @@ -1,9 +1,9 @@ import { providers } from "@polywrap/test-env-js"; -export async function getTestEnvProviders( +export function getTestEnvProviders( ipfsProvider?: string, ethProvider?: string -): Promise<{ ipfsProvider?: string; ethProvider?: string }> { +): { ipfsProvider?: string; ethProvider?: string } { return { ipfsProvider: ipfsProvider ?? providers.ipfs, ethProvider: ethProvider ?? providers.ethereum, diff --git a/packages/cli/src/lib/workflow/JobRunner.ts b/packages/cli/src/lib/workflow/JobRunner.ts index b52720b9da..a1734c4ecb 100644 --- a/packages/cli/src/lib/workflow/JobRunner.ts +++ b/packages/cli/src/lib/workflow/JobRunner.ts @@ -1,18 +1,23 @@ import { JobResult, Status, Step } from "./types"; import { PolywrapClient } from "@polywrap/client-js"; -import { MaybeAsync } from "@polywrap/core-js"; +import { CoreClient, MaybeAsync } from "@polywrap/core-js"; import { WorkflowJobs } from "@polywrap/polywrap-manifest-types-js"; -import { ClientConfigBuilder } from "@polywrap/client-config-builder-js"; +import { + ClientConfigBuilder, + ClientConfig, +} from "@polywrap/client-config-builder-js"; export class JobRunner { private jobOutput: Map; + private client: CoreClient; constructor( - private client: PolywrapClient, + private clientConfig: Partial, private onExecution?: (id: string, JobResult: JobResult) => MaybeAsync ) { this.jobOutput = new Map(); + this.client = new PolywrapClient(this.clientConfig); } async run(jobs: WorkflowJobs, ids: string[]): Promise { @@ -178,7 +183,7 @@ export class JobRunner { if (step.config) { const finalConfig = new ClientConfigBuilder() - .add(this.client.getConfig()) + .add(this.clientConfig) .add(step.config) .build(); diff --git a/packages/cli/src/lib/workflow/types.ts b/packages/cli/src/lib/workflow/types.ts index 82b03cced2..e554b33ef9 100644 --- a/packages/cli/src/lib/workflow/types.ts +++ b/packages/cli/src/lib/workflow/types.ts @@ -1,4 +1,5 @@ -import { ClientConfig, Uri } from "@polywrap/core-js"; +import { ClientConfig } from "@polywrap/client-config-builder-js"; +import { Uri } from "@polywrap/core-js"; export interface Step { uri: string | Uri; diff --git a/packages/js/client-config-builder/README.md b/packages/js/client-config-builder/README.md index d00feaa3cd..50d55ab4ee 100644 --- a/packages/js/client-config-builder/README.md +++ b/packages/js/client-config-builder/README.md @@ -12,9 +12,10 @@ const config = new ClientConfigBuilder() .add({ envs: [/*...*/], interfaces: [/*...*/], - plugins: [/*...*/], redirects: [/*...*/], - uriResolvers: [/*...*/], + wrappers: [/*...*/], + packages: [/*...*/], + resolvers: [/*...*/], }) .add({/*...*/}) .build(); @@ -26,7 +27,7 @@ const builder = new ClientConfigBuilder(); builder.addDefaults(); builder.add({ - plugins: [/*...*/] + packages: [/*...*/] }); builder.add({ diff --git a/packages/js/client-config-builder/package.json b/packages/js/client-config-builder/package.json index e0a015aa7a..ed7c65c320 100644 --- a/packages/js/client-config-builder/package.json +++ b/packages/js/client-config-builder/package.json @@ -29,11 +29,8 @@ "@polywrap/ipfs-plugin-js": "0.9.3", "@polywrap/ipfs-resolver-plugin-js": "0.9.3", "@polywrap/logger-plugin-js": "0.9.3", - "@polywrap/tracing-js": "0.9.3", "@polywrap/uri-resolver-extensions-js": "0.9.3", - "@polywrap/uri-resolvers-js": "0.9.3", - "@polywrap/wasm-js": "0.9.3", - "@polywrap/wrap-manifest-types-js": "0.9.3" + "@polywrap/uri-resolvers-js": "0.9.3" }, "devDependencies": { "@types/jest": "26.0.8", diff --git a/packages/js/client-config-builder/src/ClientConfig.ts b/packages/js/client-config-builder/src/ClientConfig.ts new file mode 100644 index 0000000000..bb6593efd5 --- /dev/null +++ b/packages/js/client-config-builder/src/ClientConfig.ts @@ -0,0 +1,18 @@ +import { + Uri, + Env, + InterfaceImplementations, + IUriRedirect, + IUriPackage, + IUriWrapper, +} from "@polywrap/core-js"; +import { UriResolverLike } from "@polywrap/uri-resolvers-js"; + +export interface ClientConfig { + readonly envs: Env[]; + readonly interfaces: InterfaceImplementations[]; + readonly redirects: IUriRedirect[]; + readonly wrappers: IUriWrapper[]; + readonly packages: IUriPackage[]; + readonly resolvers: UriResolverLike[]; +} diff --git a/packages/js/client-config-builder/src/ClientConfigBuilder.ts b/packages/js/client-config-builder/src/ClientConfigBuilder.ts index 4ea242aa86..c5d53bc829 100644 --- a/packages/js/client-config-builder/src/ClientConfigBuilder.ts +++ b/packages/js/client-config-builder/src/ClientConfigBuilder.ts @@ -1,36 +1,39 @@ -import { getDefaultClientConfig } from "./bundles"; +import { getDefaultConfig } from "./bundles"; +import { ClientConfig } from "./ClientConfig"; import { - ClientConfig, + CoreClientConfig, Uri, - PluginPackage, IUriResolver, + IUriPackage, + IUriWrapper, Env, - InterfaceImplementations, - PluginRegistration, - UriRedirect, + IUriRedirect, } from "@polywrap/core-js"; -import { IWrapperCache } from "@polywrap/uri-resolvers-js"; +import { + IWrapperCache, + LegacyRedirectsResolver, + PackageToWrapperCacheResolver, + RecursiveResolver, + StaticResolver, + UriResolverLike, + WrapperCache, +} from "@polywrap/uri-resolvers-js"; +import { ExtendableUriResolver } from "@polywrap/uri-resolver-extensions-js"; export class ClientConfigBuilder { - private _config: { - redirects: UriRedirect[]; - plugins: PluginRegistration[]; - interfaces: InterfaceImplementations[]; - envs: Env[]; - resolver?: IUriResolver; - } = { - redirects: [], - plugins: [], - interfaces: [], + private _config: ClientConfig = { envs: [], + interfaces: [], + redirects: [], + wrappers: [], + packages: [], + resolvers: [], }; - add(config: Partial>): ClientConfigBuilder { + add(config: Partial): ClientConfigBuilder { if (config.envs) { - for (const env of config.envs) { - this.addEnv(env.uri, env.env); - } + this.addEnvs(config.envs); } if (config.interfaces) { @@ -42,60 +45,106 @@ export class ClientConfigBuilder { } } - if (config.plugins) { - for (const plugin of config.plugins) { - this.addPlugin(plugin.uri, plugin.plugin); - } + if (config.redirects) { + this.addRedirects(config.redirects); } - if (config.redirects) { - for (const redirect of config.redirects) { - this.addUriRedirect(redirect.from, redirect.to); - } + if (config.wrappers) { + this.addWrappers(config.wrappers); + } + + if (config.packages) { + this.addPackages(config.packages); } - if (config.resolver) { - this.setResolver(config.resolver); + if (config.resolvers) { + this.addResolvers(config.resolvers); } return this; } - addDefaults(wrapperCache?: IWrapperCache): ClientConfigBuilder { - return this.add(getDefaultClientConfig(wrapperCache)); + addDefaults(): ClientConfigBuilder { + return this.add(getDefaultConfig()); } - addPlugin( - uri: Uri | string, - plugin: PluginPackage - ): ClientConfigBuilder { - const pluginUri = Uri.from(uri); + addWrapper(uriWrapper: IUriWrapper): ClientConfigBuilder { + const wrapperUri = Uri.from(uriWrapper.uri); + + const existingRegistration = this._config.wrappers.find((x) => + Uri.equals(x.uri, wrapperUri) + ); + + if (existingRegistration) { + existingRegistration.wrapper = uriWrapper.wrapper; + } else { + this._config.wrappers.push({ + uri: wrapperUri, + wrapper: uriWrapper.wrapper, + }); + } + + return this; + } + + addWrappers(uriWrappers: IUriWrapper[]): ClientConfigBuilder { + for (const uriWrapper of uriWrappers) { + this.addWrapper(uriWrapper); + } + + return this; + } + + removeWrapper(uri: Uri | string): ClientConfigBuilder { + const wrapperUri = Uri.from(uri); - const existingRegistration = this._config.plugins.find((x) => - Uri.equals(x.uri, pluginUri) + const idx = this._config.wrappers.findIndex((x) => + Uri.equals(x.uri, wrapperUri) + ); + + if (idx > -1) { + this._config.wrappers.splice(idx, 1); + } + + return this; + } + + addPackage(uriPackage: IUriPackage): ClientConfigBuilder { + const packageUri = Uri.from(uriPackage.uri); + + const existingRegistration = this._config.packages.find((x) => + Uri.equals(x.uri, packageUri) ); if (existingRegistration) { - existingRegistration.plugin = plugin; + existingRegistration.package = uriPackage.package; } else { - this._config.plugins.push({ - uri: pluginUri, - plugin: plugin, + this._config.packages.push({ + uri: packageUri, + package: uriPackage.package, }); } return this; } - removePlugin(uri: Uri | string): ClientConfigBuilder { - const pluginUri = Uri.from(uri); + addPackages(uriPackages: IUriPackage[]): ClientConfigBuilder { + for (const uriPackage of uriPackages) { + this.addPackage(uriPackage); + } - const idx = this._config.plugins.findIndex((x) => - Uri.equals(x.uri, pluginUri) + return this; + } + + removePackage(uri: Uri | string): ClientConfigBuilder { + const packageUri = Uri.from(uri); + + const idx = this._config.packages.findIndex((x) => + Uri.equals(x.uri, packageUri) ); if (idx > -1) { - this._config.plugins.splice(idx, 1); + this._config.packages.splice(idx, 1); } return this; @@ -121,6 +170,14 @@ export class ClientConfigBuilder { return this; } + addEnvs(envs: Env[]): ClientConfigBuilder { + for (const env of envs) { + this.addEnv(env.uri, env.env); + } + + return this; + } + removeEnv(uri: Uri | string): ClientConfigBuilder { const envUri = Uri.from(uri); @@ -239,7 +296,7 @@ export class ClientConfigBuilder { return this; } - addUriRedirect(from: Uri | string, to: Uri | string): ClientConfigBuilder { + addRedirect(from: Uri | string, to: Uri | string): ClientConfigBuilder { const fromSanitized = Uri.from(from); const toSanitized = Uri.from(to); @@ -259,6 +316,14 @@ export class ClientConfigBuilder { return this; } + addRedirects(redirects: IUriRedirect[]): ClientConfigBuilder { + for (const redirect of redirects) { + this.addRedirect(redirect.from, redirect.to); + } + + return this; + } + removeUriRedirect(from: Uri | string): ClientConfigBuilder { const fromSanitized = Uri.from(from); @@ -273,21 +338,48 @@ export class ClientConfigBuilder { return this; } - setResolver(resolver: IUriResolver): ClientConfigBuilder { - this._config.resolver = resolver; + addResolver(resolver: UriResolverLike): ClientConfigBuilder { + this._config.resolvers.push(resolver); return this; } - build(): ClientConfig { - if (!this._config.resolver) { - throw new Error("No URI resolver provided"); + addResolvers(resolvers: UriResolverLike[]): ClientConfigBuilder { + for (const resolver of resolvers) { + this.addResolver(resolver); } - return this._config as ClientConfig; + return this; } - buildPartial(): Partial> { + build(): ClientConfig { return this._config; } + + buildDefault( + wrapperCache?: IWrapperCache, + resolver?: IUriResolver + ): CoreClientConfig { + return { + envs: this._config.envs, + interfaces: this._config.interfaces, + redirects: this._config.redirects, + resolver: + resolver ?? + RecursiveResolver.from( + PackageToWrapperCacheResolver.from( + [ + new LegacyRedirectsResolver(), + StaticResolver.from([ + ...this._config.wrappers, + ...this._config.packages, + ]), + ...this._config.resolvers, + new ExtendableUriResolver(), + ], + wrapperCache ?? new WrapperCache() + ) + ), + }; + } } diff --git a/packages/js/client-config-builder/src/__tests__/client-config-builder.spec.ts b/packages/js/client-config-builder/src/__tests__/client-config-builder.spec.ts index 089b8cffa8..c27ffa4c28 100644 --- a/packages/js/client-config-builder/src/__tests__/client-config-builder.spec.ts +++ b/packages/js/client-config-builder/src/__tests__/client-config-builder.spec.ts @@ -1,18 +1,15 @@ import { ClientConfigBuilder } from "../ClientConfigBuilder"; import { - Client, + CoreClient, Env, InterfaceImplementations, - PluginModule, - PluginRegistration, Uri, - UriRedirect, + IUriRedirect, IUriResolver, UriPackageOrWrapper, } from "@polywrap/core-js"; import { Result } from "@polywrap/result"; -import { getDefaultClientConfig } from "../bundles"; -import { RecursiveResolver } from "@polywrap/uri-resolvers-js"; +import { getDefaultConfig } from "../bundles"; class NamedUriResolver implements IUriResolver { private _name: string; @@ -25,7 +22,7 @@ class NamedUriResolver implements IUriResolver { } tryResolveUri( uri: Uri, - client: Client + client: CoreClient ): Promise> { throw new Error("Method not implemented."); } @@ -48,34 +45,7 @@ describe("Client config builder", () => { }, ]; - const testPlugins: PluginRegistration[] = [ - { - uri: "wrap://ens/test1.polywrap.eth", - plugin: { - factory: () => ({} as PluginModule<{}>), - manifest: { - name: "test", - abi: {}, - type: "plugin", - version: "0.1", - }, - }, - }, - { - uri: "wrap://ens/test2.polywrap.eth", - plugin: { - factory: () => ({} as PluginModule<{}>), - manifest: { - name: "test", - abi: {}, - type: "plugin", - version: "0.1", - }, - }, - }, - ]; - - const testUriRedirects: UriRedirect[] = [ + const testUriRedirects: IUriRedirect[] = [ { from: "wrap://ens/test-one.polywrap.eth", to: "wrap://ens/test1.polywrap.eth", @@ -89,13 +59,15 @@ describe("Client config builder", () => { const testUriResolver: IUriResolver = new NamedUriResolver("test1"); it("should build an empty partial config", () => { - const clientConfig = new ClientConfigBuilder().buildPartial(); + const clientConfig = new ClientConfigBuilder().build(); expect(clientConfig).toStrictEqual({ envs: [], interfaces: [], - plugins: [], redirects: [], + wrappers: [], + packages: [], + resolvers: [], }); }); @@ -104,9 +76,8 @@ describe("Client config builder", () => { .add({ envs: testEnvs, interfaces: testInterfaces, - plugins: testPlugins, redirects: testUriRedirects, - resolver: testUriResolver, + resolvers: [testUriResolver], }) .build(); @@ -123,19 +94,13 @@ describe("Client config builder", () => { implementations: x.implementations.map(Uri.from), })) ); - expect(clientConfig.plugins).toStrictEqual( - testPlugins.map((x) => ({ - uri: Uri.from(x.uri), - plugin: x.plugin, - })) - ); expect(clientConfig.redirects).toStrictEqual( testUriRedirects.map((x) => ({ from: Uri.from(x.from), to: Uri.from(x.to), })) ); - expect(clientConfig.resolver).toStrictEqual(testUriResolver); + expect(clientConfig.resolvers).toStrictEqual([testUriResolver]); }); it("should succesfully add and merge two config objects and build", () => { @@ -143,14 +108,12 @@ describe("Client config builder", () => { .add({ envs: [testEnvs[0]], interfaces: [testInterfaces[0]], - plugins: [testPlugins[0]], redirects: [testUriRedirects[0]], - resolver: testUriResolver, + resolvers: [testUriResolver], }) .add({ envs: [testEnvs[1]], interfaces: [testInterfaces[1]], - plugins: [testPlugins[1]], redirects: [testUriRedirects[1]], }) .build(); @@ -168,112 +131,25 @@ describe("Client config builder", () => { implementations: x.implementations.map(Uri.from), })) ); - expect(clientConfig.plugins).toStrictEqual( - testPlugins.map((x) => ({ - uri: Uri.from(x.uri), - plugin: x.plugin, - })) - ); expect(clientConfig.redirects).toStrictEqual( testUriRedirects.map((x) => ({ from: Uri.from(x.from), to: Uri.from(x.to), })) ); - expect(clientConfig.resolver).toStrictEqual(testUriResolver); + expect(clientConfig.resolvers).toStrictEqual([testUriResolver]); }); it("should successfully add the default config", () => { const clientConfig = new ClientConfigBuilder().addDefaults().build(); - const expectedConfig = getDefaultClientConfig(); + const expectedConfig = getDefaultConfig(); expect(clientConfig).toBeTruthy(); expect(clientConfig.envs).toStrictEqual(expectedConfig.envs); expect(clientConfig.interfaces).toStrictEqual(expectedConfig.interfaces); - expect(clientConfig.plugins).toHaveLength(expectedConfig.plugins.length); - for (let i = 0; i < clientConfig.plugins.length; i++) { - expect(clientConfig.plugins[i].uri).toEqual( - expectedConfig.plugins[i].uri - ); - expect(clientConfig.plugins[i].plugin.manifest).toEqual( - expectedConfig.plugins[i].plugin.manifest - ); - } expect(clientConfig.redirects).toStrictEqual(expectedConfig.redirects); - expect(clientConfig.resolver instanceof RecursiveResolver).toBe(true); - }); - - it("should successfully add a plugin", () => { - const pluginUri = "wrap://ens/some-plugin.polywrap.eth"; - const pluginPackage = testPlugins[0].plugin; - - const config = new ClientConfigBuilder() - .addPlugin(pluginUri, pluginPackage) - .buildPartial(); - - if (!config.plugins || config.plugins.length !== 1) { - fail(["Expected 1 plugin, received:", config.plugins]); - } - - expect(config.plugins[0].uri).toStrictEqual(Uri.from(pluginUri)); - expect(config.plugins[0].plugin).toStrictEqual(pluginPackage); - }); - - it("should successfully add multiple plugins", () => { - const config = new ClientConfigBuilder() - .addPlugin(testPlugins[0].uri, testPlugins[0].plugin) - .addPlugin(testPlugins[1].uri, testPlugins[1].plugin) - .buildPartial(); - - if (!config.plugins || config.plugins.length !== 2) { - fail(["Expected 2 plugins, received:", config.plugins]); - } - - expect(config.plugins).toContainEqual({ - uri: Uri.from(testPlugins[0].uri), - plugin: testPlugins[0].plugin, - }); - expect(config.plugins).toContainEqual({ - uri: Uri.from(testPlugins[1].uri), - plugin: testPlugins[1].plugin, - }); - }); - - it("should succesfully overwrite a plugin", () => { - const pluginUri = "wrap://ens/some-plugin.polywrap.eth"; - const pluginPackage1 = testPlugins[0].plugin; - const pluginPackage2 = testPlugins[1].plugin; - - const config = new ClientConfigBuilder() - .addPlugin(pluginUri, pluginPackage1) - .addPlugin(pluginUri, pluginPackage2) - .buildPartial(); - - if (!config.plugins || config.plugins.length !== 1) { - fail(["Expected 1 plugin, received:", config.plugins]); - } - - expect(config.plugins[0].uri).toStrictEqual(Uri.from(pluginUri)); - expect(config.plugins[0].plugin).not.toStrictEqual(pluginPackage1); - expect(config.plugins[0].plugin).toStrictEqual(pluginPackage2); - }); - - it("should remove a plugin", () => { - const config = new ClientConfigBuilder() - .addPlugin(testPlugins[0].uri, testPlugins[0].plugin) - .addPlugin(testPlugins[1].uri, testPlugins[1].plugin) - .removePlugin(testPlugins[0].uri) - .buildPartial(); - - if (!config.plugins || config.plugins.length !== 1) { - fail(["Expected 1 plugin, received:", config.plugins]); - } - - const remainingPlugin = config.plugins[0]; - - expect(remainingPlugin.uri).toStrictEqual(Uri.from(testPlugins[1].uri)); - expect(remainingPlugin.plugin).toStrictEqual(testPlugins[1].plugin); + expect(clientConfig.resolvers).toStrictEqual(expectedConfig.resolvers); }); it("should successfully add an env", () => { @@ -285,7 +161,7 @@ describe("Client config builder", () => { }, }; - const config = new ClientConfigBuilder().addEnv(envUri, env).buildPartial(); + const config = new ClientConfigBuilder().addEnv(envUri, env).build(); if (!config.envs || config.envs.length !== 1) { fail(["Expected 1 env, received:", config.envs]); @@ -309,7 +185,7 @@ describe("Client config builder", () => { const config = new ClientConfigBuilder() .addEnv(envUri, env1) .addEnv(envUri, env2) - .buildPartial(); + .build(); const expectedEnv = { ...env1, ...env2 }; @@ -325,7 +201,7 @@ describe("Client config builder", () => { const config = new ClientConfigBuilder() .addEnv(testEnvs[0].uri, testEnvs[0].env) .addEnv(testEnvs[1].uri, testEnvs[1].env) - .buildPartial(); + .build(); if (!config.envs || config.envs.length !== 2) { fail(["Expected 2 envs, received:", config.envs]); @@ -346,7 +222,7 @@ describe("Client config builder", () => { .addEnv(testEnvs[0].uri, testEnvs[0].env) .addEnv(testEnvs[1].uri, testEnvs[1].env) .removeEnv(testEnvs[0].uri) - .buildPartial(); + .build(); if (!config.envs || config.envs.length !== 1) { fail(["Expected 1 env, received:", config.envs]); @@ -365,7 +241,7 @@ describe("Client config builder", () => { foo: "bar", }; - const config = new ClientConfigBuilder().setEnv(envUri, env).buildPartial(); + const config = new ClientConfigBuilder().setEnv(envUri, env).build(); if (!config.envs || config.envs.length !== 1) { fail(["Expected 1 env, received:", config.envs]); @@ -390,7 +266,7 @@ describe("Client config builder", () => { const config = new ClientConfigBuilder() .addEnv(envUri, env1) .setEnv(envUri, env2) - .buildPartial(); + .build(); if (!config.envs || config.envs.length !== 1) { fail(["Expected 1 env, received:", config.envs]); @@ -408,7 +284,7 @@ describe("Client config builder", () => { const config = new ClientConfigBuilder() .addInterfaceImplementation(interfaceUri, implUri) - .buildPartial(); + .build(); if (!config.interfaces || config.interfaces.length !== 1) { fail(["Expected 1 interface, received:", config.interfaces]); @@ -428,7 +304,7 @@ describe("Client config builder", () => { const config = new ClientConfigBuilder() .addInterfaceImplementation(interfaceUri, implUri1) .addInterfaceImplementation(interfaceUri, implUri2) - .buildPartial(); + .build(); if (!config.interfaces || config.interfaces.length !== 1) { fail(["Expected 1 interface, received:", config.interfaces]); @@ -458,7 +334,7 @@ describe("Client config builder", () => { .addInterfaceImplementation(interfaceUri2, implUri2) .addInterfaceImplementation(interfaceUri1, implUri3) .addInterfaceImplementation(interfaceUri2, implUri4) - .buildPartial(); + .build(); if (!config.interfaces || config.interfaces.length !== 2) { fail(["Expected 2 interfaces, received:", config.interfaces]); @@ -489,7 +365,7 @@ describe("Client config builder", () => { const config = new ClientConfigBuilder() .addInterfaceImplementations(interfaceUri, [implUri1, implUri2]) - .buildPartial(); + .build(); if (!config.interfaces || config.interfaces.length !== 1) { fail(["Expected 1 interface, received:", config.interfaces]); @@ -516,7 +392,7 @@ describe("Client config builder", () => { const config = new ClientConfigBuilder() .addInterfaceImplementations(interfaceUri, [implUri1]) .addInterfaceImplementations(interfaceUri, [implUri2, implUri3]) - .buildPartial(); + .build(); if (!config.interfaces || config.interfaces.length !== 1) { fail(["Expected 1 interface, received:", config.interfaces]); @@ -552,7 +428,7 @@ describe("Client config builder", () => { .addInterfaceImplementation(interfaceUri2, implUri2) .addInterfaceImplementations(interfaceUri1, [implUri3, implUri5]) .addInterfaceImplementations(interfaceUri2, [implUri4, implUri6]) - .buildPartial(); + .build(); if (!config.interfaces || config.interfaces.length !== 2) { fail(["Expected 2 interfaces, received:", config.interfaces]); @@ -588,7 +464,7 @@ describe("Client config builder", () => { .addInterfaceImplementations(interfaceUri1, [implUri1, implUri2]) .addInterfaceImplementations(interfaceUri2, [implUri1, implUri2]) .removeInterfaceImplementation(interfaceUri1, implUri2) - .buildPartial(); + .build(); if (!config.interfaces || config.interfaces.length !== 2) { fail(["Expected 2 interfaces, received:", config.interfaces]); @@ -622,7 +498,7 @@ describe("Client config builder", () => { .addInterfaceImplementations(interfaceUri2, [implUri1, implUri2]) .removeInterfaceImplementation(interfaceUri1, implUri1) .removeInterfaceImplementation(interfaceUri1, implUri2) - .buildPartial(); + .build(); if (!config.interfaces || config.interfaces.length !== 1) { fail(["Expected 1 interface, received:", config.interfaces]); @@ -647,9 +523,7 @@ describe("Client config builder", () => { const from = "wrap://ens/from.this.ens"; const to = "wrap://ens/to.that.ens"; - const config = new ClientConfigBuilder() - .addUriRedirect(from, to) - .buildPartial(); + const config = new ClientConfigBuilder().addRedirect(from, to).build(); expect(config.redirects).toHaveLength(1); expect(config.redirects).toContainEqual({ @@ -666,9 +540,9 @@ describe("Client config builder", () => { const to2 = "wrap://ens/to.that2.ens"; const config = new ClientConfigBuilder() - .addUriRedirect(from1, to1) - .addUriRedirect(from2, to2) - .buildPartial(); + .addRedirect(from1, to1) + .addRedirect(from2, to2) + .build(); expect(config.redirects).toHaveLength(2); expect(config.redirects).toContainEqual({ @@ -688,10 +562,10 @@ describe("Client config builder", () => { const to2 = "wrap://ens/to.that2.ens"; const config = new ClientConfigBuilder() - .addUriRedirect(from1, to1) - .addUriRedirect(from2, to1) - .addUriRedirect(from1, to2) - .buildPartial(); + .addRedirect(from1, to1) + .addRedirect(from2, to1) + .addRedirect(from1, to2) + .build(); expect(config.redirects).toHaveLength(2); expect(config.redirects).toContainEqual({ @@ -712,10 +586,10 @@ describe("Client config builder", () => { const to2 = "wrap://ens/to.that2.ens"; const config = new ClientConfigBuilder() - .addUriRedirect(from1, to1) - .addUriRedirect(from2, to2) + .addRedirect(from1, to1) + .addRedirect(from2, to2) .removeUriRedirect(from1) - .buildPartial(); + .build(); expect(config.redirects).toHaveLength(1); expect(config.redirects).toContainEqual({ @@ -727,9 +601,9 @@ describe("Client config builder", () => { it("should set uri resolver", () => { const uriResolver = new NamedUriResolver("ResolverName"); - const config = new ClientConfigBuilder().setResolver(uriResolver).build(); + const config = new ClientConfigBuilder().addResolver(uriResolver).build(); - expect(((config.resolver as unknown) as NamedUriResolver).name).toBe( + expect(((config.resolvers[0] as unknown) as NamedUriResolver).name).toBe( "ResolverName" ); }); @@ -739,11 +613,14 @@ describe("Client config builder", () => { const uriResolver2 = new NamedUriResolver("second"); const config = new ClientConfigBuilder() - .setResolver(uriResolver1) - .setResolver(uriResolver2) + .addResolver(uriResolver1) + .addResolver(uriResolver2) .build(); - expect(((config.resolver as unknown) as NamedUriResolver).name).toBe( + expect(((config.resolvers[0] as unknown) as NamedUriResolver).name).toBe( + "first" + ); + expect(((config.resolvers[1] as unknown) as NamedUriResolver).name).toBe( "second" ); }); diff --git a/packages/js/client-config-builder/src/bundles/default-client-config.ts b/packages/js/client-config-builder/src/bundles/default-client-config.ts deleted file mode 100644 index 834c59257e..0000000000 --- a/packages/js/client-config-builder/src/bundles/default-client-config.ts +++ /dev/null @@ -1,145 +0,0 @@ -import { ClientConfig, Uri } from "@polywrap/core-js"; -import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; -import { ipfsResolverPlugin } from "@polywrap/ipfs-resolver-plugin-js"; -import { - ethereumPlugin, - Connection, - Connections, -} from "@polywrap/ethereum-plugin-js"; -import { - LegacyPluginsResolver, - LegacyRedirectsResolver, - IWrapperCache, - WrapperCache, - PackageToWrapperCacheResolver, - RecursiveResolver, -} from "@polywrap/uri-resolvers-js"; -import { ExtendableUriResolver } from "@polywrap/uri-resolver-extensions-js"; -import { ensResolverPlugin } from "@polywrap/ens-resolver-plugin-js"; -import { httpPlugin } from "@polywrap/http-plugin-js"; -import { httpResolverPlugin } from "@polywrap/http-resolver-plugin-js"; -import { fileSystemPlugin } from "@polywrap/fs-plugin-js"; -import { loggerPlugin } from "@polywrap/logger-plugin-js"; -import { fileSystemResolverPlugin } from "@polywrap/fs-resolver-plugin-js"; - -export const getDefaultClientConfig = ( - wrapperCache?: IWrapperCache -): ClientConfig => { - return { - envs: [ - { - uri: new Uri(defaultWrappers.graphNode), - env: { - provider: "https://api.thegraph.com", - }, - }, - { - uri: new Uri("wrap://ens/ipfs.polywrap.eth"), - env: { - provider: defaultIpfsProviders[0], - fallbackProviders: defaultIpfsProviders.slice(1), - }, - }, - ], - redirects: [ - { - from: new Uri("wrap://ens/sha3.polywrap.eth"), - to: new Uri(defaultWrappers.sha3), - }, - { - from: new Uri("wrap://ens/uts46.polywrap.eth"), - to: new Uri(defaultWrappers.uts46), - }, - { - from: new Uri("wrap://ens/graph-node.polywrap.eth"), - to: new Uri(defaultWrappers.graphNode), - }, - ], - plugins: [ - // IPFS is required for downloading Polywrap packages - { - uri: new Uri("wrap://ens/ipfs.polywrap.eth"), - plugin: ipfsPlugin({}), - }, - // ENS is required for resolving domain to IPFS hashes - { - uri: new Uri("wrap://ens/ens-resolver.polywrap.eth"), - plugin: ensResolverPlugin({}), - }, - { - uri: new Uri("wrap://ens/ethereum.polywrap.eth"), - plugin: ethereumPlugin({ - connections: new Connections({ - networks: { - mainnet: new Connection({ - provider: - "https://mainnet.infura.io/v3/b00b2c2cc09c487685e9fb061256d6a6", - }), - goerli: new Connection({ - provider: - "https://goerli.infura.io/v3/b00b2c2cc09c487685e9fb061256d6a6", - }), - }, - }), - }), - }, - { - uri: new Uri("wrap://ens/http.polywrap.eth"), - plugin: httpPlugin({}), - }, - { - uri: new Uri("wrap://ens/http-resolver.polywrap.eth"), - plugin: httpResolverPlugin({}), - }, - { - uri: new Uri("wrap://ens/js-logger.polywrap.eth"), - plugin: loggerPlugin({}), - }, - { - uri: new Uri("wrap://ens/fs.polywrap.eth"), - plugin: fileSystemPlugin({}), - }, - { - uri: new Uri("wrap://ens/fs-resolver.polywrap.eth"), - plugin: fileSystemResolverPlugin({}), - }, - { - uri: new Uri("wrap://ens/ipfs-resolver.polywrap.eth"), - plugin: ipfsResolverPlugin({}), - }, - ], - interfaces: [ - { - interface: new Uri("wrap://ens/uri-resolver.core.polywrap.eth"), - implementations: [ - new Uri("wrap://ens/ipfs-resolver.polywrap.eth"), - new Uri("wrap://ens/ens-resolver.polywrap.eth"), - new Uri("wrap://ens/fs-resolver.polywrap.eth"), - new Uri("wrap://ens/http-resolver.polywrap.eth"), - ], - }, - { - interface: new Uri("wrap://ens/logger.core.polywrap.eth"), - implementations: [new Uri("wrap://ens/js-logger.polywrap.eth")], - }, - ], - resolver: new RecursiveResolver( - new PackageToWrapperCacheResolver(wrapperCache ?? new WrapperCache(), [ - new LegacyRedirectsResolver(), - new LegacyPluginsResolver(), - new ExtendableUriResolver(), - ]) - ), - }; -}; - -export const defaultIpfsProviders = [ - "https://ipfs.wrappers.io", - "https://ipfs.io", -]; - -export const defaultWrappers = { - sha3: "wrap://ens/goerli/sha3.wrappers.eth", - uts46: "wrap://ens/goerli/uts46-lite.wrappers.eth", - graphNode: "wrap://ens/goerli/graph-node.wrappers.eth", -}; diff --git a/packages/js/client-config-builder/src/bundles/getDefaultConfig.ts b/packages/js/client-config-builder/src/bundles/getDefaultConfig.ts new file mode 100644 index 0000000000..3706b4a263 --- /dev/null +++ b/packages/js/client-config-builder/src/bundles/getDefaultConfig.ts @@ -0,0 +1,135 @@ +import { ClientConfig } from "../ClientConfig"; + +import { IUriPackage, Uri } from "@polywrap/core-js"; +import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; +import { ipfsResolverPlugin } from "@polywrap/ipfs-resolver-plugin-js"; +import { + ethereumPlugin, + Connection, + Connections, +} from "@polywrap/ethereum-plugin-js"; +import { ensResolverPlugin } from "@polywrap/ens-resolver-plugin-js"; +import { httpPlugin } from "@polywrap/http-plugin-js"; +import { httpResolverPlugin } from "@polywrap/http-resolver-plugin-js"; +import { fileSystemPlugin } from "@polywrap/fs-plugin-js"; +import { loggerPlugin } from "@polywrap/logger-plugin-js"; +import { fileSystemResolverPlugin } from "@polywrap/fs-resolver-plugin-js"; + +export const getDefaultConfig = (): ClientConfig => { + return { + envs: [ + { + uri: new Uri(defaultWrappers.graphNode), + env: { + provider: "https://api.thegraph.com", + }, + }, + { + uri: new Uri("wrap://ens/ipfs.polywrap.eth"), + env: { + provider: defaultIpfsProviders[0], + fallbackProviders: defaultIpfsProviders.slice(1), + }, + }, + ], + redirects: [ + { + from: new Uri("wrap://ens/sha3.polywrap.eth"), + to: new Uri(defaultWrappers.sha3), + }, + { + from: new Uri("wrap://ens/uts46.polywrap.eth"), + to: new Uri(defaultWrappers.uts46), + }, + { + from: new Uri("wrap://ens/graph-node.polywrap.eth"), + to: new Uri(defaultWrappers.graphNode), + }, + ], + interfaces: [ + { + interface: new Uri("wrap://ens/uri-resolver.core.polywrap.eth"), + implementations: [ + new Uri("wrap://ens/ipfs-resolver.polywrap.eth"), + new Uri("wrap://ens/ens-resolver.polywrap.eth"), + new Uri("wrap://ens/fs-resolver.polywrap.eth"), + new Uri("wrap://ens/http-resolver.polywrap.eth"), + ], + }, + { + interface: new Uri("wrap://ens/logger.core.polywrap.eth"), + implementations: [new Uri("wrap://ens/js-logger.polywrap.eth")], + }, + ], + packages: getDefaultPlugins(), + wrappers: [], + resolvers: [], + }; +}; + +export const defaultIpfsProviders = [ + "https://ipfs.wrappers.io", + "https://ipfs.io", +]; + +export const defaultWrappers = { + sha3: "wrap://ens/goerli/sha3.wrappers.eth", + uts46: "wrap://ens/goerli/uts46-lite.wrappers.eth", + graphNode: "wrap://ens/goerli/graph-node.wrappers.eth", +}; + +export const getDefaultPlugins = (): IUriPackage[] => { + return [ + // IPFS is required for downloading Polywrap packages + { + uri: new Uri("wrap://ens/ipfs.polywrap.eth"), + package: ipfsPlugin({}), + }, + // ENS is required for resolving domain to IPFS hashes + { + uri: new Uri("wrap://ens/ens-resolver.polywrap.eth"), + package: ensResolverPlugin({}), + }, + { + uri: new Uri("wrap://ens/ethereum.polywrap.eth"), + package: ethereumPlugin({ + connections: new Connections({ + networks: { + mainnet: new Connection({ + provider: + "https://mainnet.infura.io/v3/b00b2c2cc09c487685e9fb061256d6a6", + }), + goerli: new Connection({ + provider: + "https://goerli.infura.io/v3/b00b2c2cc09c487685e9fb061256d6a6", + }), + }, + }), + }), + }, + { + uri: new Uri("wrap://ens/http.polywrap.eth"), + package: httpPlugin({}), + }, + { + uri: new Uri("wrap://ens/http-resolver.polywrap.eth"), + package: httpResolverPlugin({}), + }, + { + uri: new Uri("wrap://ens/js-logger.polywrap.eth"), + package: loggerPlugin({}), + }, + { + uri: new Uri("wrap://ens/fs.polywrap.eth"), + package: fileSystemPlugin({}), + }, + { + uri: new Uri("wrap://ens/fs-resolver.polywrap.eth"), + package: fileSystemResolverPlugin({}), + }, + { + uri: new Uri("wrap://ens/ipfs-resolver.polywrap.eth"), + package: ipfsResolverPlugin({}), + }, + ]; +}; diff --git a/packages/js/client-config-builder/src/bundles/index.ts b/packages/js/client-config-builder/src/bundles/index.ts index b66e52f16e..1c6c20bb7b 100644 --- a/packages/js/client-config-builder/src/bundles/index.ts +++ b/packages/js/client-config-builder/src/bundles/index.ts @@ -1 +1 @@ -export * from "./default-client-config"; +export * from "./getDefaultConfig"; diff --git a/packages/js/client-config-builder/src/index.ts b/packages/js/client-config-builder/src/index.ts index 83e3ef472c..ce72c63807 100644 --- a/packages/js/client-config-builder/src/index.ts +++ b/packages/js/client-config-builder/src/index.ts @@ -1,2 +1,3 @@ export * from "./ClientConfigBuilder"; +export * from "./ClientConfig"; export * from "./bundles"; diff --git a/packages/js/client/package.json b/packages/js/client/package.json index c267059a99..bfdac5ad43 100644 --- a/packages/js/client/package.json +++ b/packages/js/client/package.json @@ -13,7 +13,6 @@ ], "scripts": { "build": "rimraf ./build && tsc --project tsconfig.build.json", - "prebuild": "ts-node ./scripts/extractPluginConfigs.ts", "lint": "eslint --color -c ../../../.eslintrc.js src/", "test": "jest --passWithNoTests --runInBand --verbose=true --detectOpenHandles --forceExit", "test:ci": "jest --passWithNoTests --runInBand --verbose --detectOpenHandles --forceExit", @@ -21,34 +20,33 @@ "test:watch": "jest --watch --passWithNoTests --verbose --detectOpenHandles" }, "dependencies": { - "@polywrap/asyncify-js": "0.9.3", - "@polywrap/client-config-builder-js": "0.9.3", "@polywrap/core-js": "0.9.3", - "@polywrap/ens-resolver-plugin-js": "0.9.3", - "@polywrap/ethereum-plugin-js": "0.9.3", - "@polywrap/fs-plugin-js": "0.9.3", - "@polywrap/fs-resolver-plugin-js": "0.9.3", - "@polywrap/http-plugin-js": "0.9.3", - "@polywrap/http-resolver-plugin-js": "0.9.3", - "@polywrap/ipfs-plugin-js": "0.9.3", - "@polywrap/ipfs-resolver-plugin-js": "0.9.3", - "@polywrap/logger-plugin-js": "0.9.3", "@polywrap/msgpack-js": "0.9.3", "@polywrap/result": "0.9.3", - "@polywrap/schema-parse": "0.9.3", "@polywrap/tracing-js": "0.9.3", + "@polywrap/client-config-builder-js": "0.9.3", "@polywrap/uri-resolvers-js": "0.9.3", "@polywrap/wrap-manifest-types-js": "0.9.3", - "graphql": "15.5.0", - "yaml": "2.1.3" + "@polywrap/uri-resolver-extensions-js": "0.9.3" }, "devDependencies": { - "@polywrap/os-js": "0.9.3", "@polywrap/test-cases": "0.9.3", "@polywrap/test-env-js": "0.9.3", + "@polywrap/client-config-builder-js": "0.9.3", + "@polywrap/ens-resolver-plugin-js": "0.9.3", + "@polywrap/ethereum-plugin-js": "0.9.3", + "@polywrap/http-plugin-js": "0.9.3", + "@polywrap/http-resolver-plugin-js": "0.9.3", + "@polywrap/ipfs-plugin-js": "0.9.3", + "@polywrap/ipfs-resolver-plugin-js": "0.9.3", + "@polywrap/logger-plugin-js": "0.9.3", + "@polywrap/fs-plugin-js": "0.9.3", + "@polywrap/fs-resolver-plugin-js": "0.9.3", + "@polywrap/plugin-js": "0.9.3", "@types/jest": "26.0.8", "@types/prettier": "2.6.0", "@types/uuid": "8.3.0", + "yaml": "2.1.3", "bignumber.js": "9.0.2", "jest": "26.6.3", "polywrap": "0.9.3", diff --git a/packages/js/client/scripts/extractPluginConfigs.ts b/packages/js/client/scripts/extractPluginConfigs.ts deleted file mode 100644 index 6c1be1447d..0000000000 --- a/packages/js/client/scripts/extractPluginConfigs.ts +++ /dev/null @@ -1,182 +0,0 @@ -import { Project as TsProject } from "ts-morph"; -import { writeFileSync } from "@polywrap/os-js"; -import path from "path"; - -interface PluginConfigSource { - name: string; - module: string; - uri: string; - config: string; - files: { - name: string; - interfaces?: string[]; - types?: string[]; - }[]; - externals?: { - type: string; - module: string; - }[]; -} - -const plugins: PluginConfigSource[] = [ - { - name: "Ipfs", - module: "@polywrap/ipfs-plugin-js", - uri: "wrap://ens/ipfs.polywrap.eth", - config: "NoConfig", - files: [ - { - name: "build/index.d.ts", - types: ["NoConfig"] - }, - ], - }, - { - name: "Ethereum", - module: "@polywrap/ethereum-plugin-js", - uri: "wrap://ens/ethereum.polywrap.eth", - config: "EthereumPluginConfig", - files: [ - { - name: "build/index.d.ts", - interfaces: ["EthereumPluginConfig"], - }, - { - name: "build/Connection.d.ts", - interfaces: ["ConnectionConfig"], - types: [ - "EthereumProvider", - "EthereumSigner", - "AccountIndex", - "Address", - ], - }, - { - name: "build/Connections.d.ts", - interfaces: ["ConnectionsConfig"], - types: ["Networks"], - }, - ], - externals: [ - { - type: "Connection", - module: "@polywrap/ethereum-plugin-js" - }, - { - type: "Connections", - module: "@polywrap/ethereum-plugin-js" - }, - { - type: "Signer", - module: "ethers", - }, - { - type: "ExternalProvider", - module: "@ethersproject/providers", - }, - { - type: "JsonRpcProvider", - module: "@ethersproject/providers", - }, - ], - }, - { - name: "Ens", - module: "@polywrap/ens-resolver-plugin-js", - uri: "wrap://ens/ens-resolver.polywrap.eth", - config: "EnsResolverPluginConfig", - files: [ - { - name: "build/index.d.ts", - interfaces: ["EnsResolverPluginConfig", "Addresses"], - types: ["Address"], - }, - ], - }, -]; - -function main(): void { - - const header = "/// NOTE: This is an auto-generated file. See scripts/extractPluginConfigs.ts\n" + - "/* eslint-disable @typescript-eslint/no-explicit-any */\n" + - "/* eslint-disable prettier/prettier */"; - const outputFiles: { - fileName: string, - content: string - }[] = []; - - for (const plugin of plugins) { - let output = header; - - output += `\n\n/// Types generated from ${plugin.module} build files:\n/// ${ - plugin.files.map(({ name }) => name).join(', ') - }` - - const project = new TsProject(); - - for (const file of plugin.files) { - const filePath = require.resolve(path.join(plugin.module, file.name)); - const sourceFile = project.addSourceFileAtPath(filePath); - - for (const pluginInterface of file.interfaces || []) { - const int = sourceFile.getInterfaceOrThrow(pluginInterface); - output += `\n\n${int.print().replace(/ /g, " ")}`; - } - - for (const pluginType of file.types || []) { - const typ = sourceFile.getTypeAliasOrThrow(pluginType); - output += `\n\n${typ.print().replace("declare ", "").replace(/ /g, " ")}`; - } - } - - for (const pluginExternal of plugin.externals || []) { - output += `\n\n// import { ${pluginExternal.type} } from "${pluginExternal.module}"`; - output += `\nexport type ${pluginExternal.type} = any;`; - } - - outputFiles.push({ - fileName: `${plugin.name}.ts`, - content: output + "\n" - }); - } - - let indexContent = header + "\n"; - - let pluginConfigs = "\n\ninterface PluginConfigs {"; - let pluginModules = "\n\nconst modules: Record = {"; - let pluginUris = "\n\nconst uris: Record = {"; - - for (const plugin of plugins) { - const pluginKey = plugin.name.toLowerCase(); - indexContent += `\nimport { ${plugin.config} } from "./${plugin.name}";`; - pluginConfigs += `\n ${pluginKey}?: ${plugin.config};`; - pluginModules += `\n ${pluginKey}: "${plugin.module}",`; - pluginUris += `\n ${pluginKey}: "${plugin.uri}",`; - } - - pluginConfigs += `\n}`; - pluginModules += `\n};`; - pluginUris += `\n};`; - - indexContent += pluginConfigs + pluginModules + pluginUris + `\n\nexport { PluginConfigs, modules, uris };\n`; - - outputFiles.push({ - fileName: "index.ts", - content: indexContent - }); - - for (const outputFile of outputFiles) { - writeFileSync( - __dirname + "/../src/pluginConfigs/" + outputFile.fileName, - outputFile.content - ); - } -} - -try { - main(); - process.exit(0); -} catch (err) { - console.error(err); - process.exit(1); -} diff --git a/packages/js/client/src/PolywrapClient.ts b/packages/js/client/src/PolywrapClient.ts index 0474643a28..274ca06047 100644 --- a/packages/js/client/src/PolywrapClient.ts +++ b/packages/js/client/src/PolywrapClient.ts @@ -1,62 +1,45 @@ import { UriResolverError } from "./UriResolverError"; +import { PolywrapCoreClientConfig } from "./PolywrapCoreClientConfig"; +import { PolywrapClientConfig } from "./PolywrapClientConfig"; import { Wrapper, - Client, - ClientConfig, + CoreClient, Env, GetFileOptions, GetImplementationsOptions, InterfaceImplementations, InvokeOptions, InvokerOptions, - PluginRegistration, QueryOptions, SubscribeOptions, Subscription, Uri, - UriRedirect, + IUriRedirect, createQueryDocument, getImplementations, parseQuery, TryResolveUriOptions, IUriResolver, - GetManifestOptions, IUriResolutionContext, UriPackageOrWrapper, UriResolutionContext, getEnvFromUriHistory, - PluginPackage, QueryResult, InvokeResult, } from "@polywrap/core-js"; -import { - buildCleanUriHistory, - IWrapperCache, -} from "@polywrap/uri-resolvers-js"; +import { buildCleanUriHistory } from "@polywrap/uri-resolvers-js"; import { msgpackEncode, msgpackDecode } from "@polywrap/msgpack-js"; import { DeserializeManifestOptions, WrapManifest, } from "@polywrap/wrap-manifest-types-js"; import { Tracer, TracerConfig, TracingLevel } from "@polywrap/tracing-js"; -import { ClientConfigBuilder } from "@polywrap/client-config-builder-js"; import { Result, ResultErr, ResultOk } from "@polywrap/result"; +import { ClientConfigBuilder } from "@polywrap/client-config-builder-js"; -export interface PolywrapClientConfig - extends ClientConfig { - readonly tracerConfig: Readonly>; - readonly wrapperCache?: Readonly; -} - -export class PolywrapClient implements Client { - private _config: PolywrapClientConfig = ({ - redirects: [], - plugins: [], - interfaces: [], - envs: [], - tracerConfig: {}, - } as unknown) as PolywrapClientConfig; +export class PolywrapClient implements CoreClient { + private _config: PolywrapCoreClientConfig; /** * Instantiate a PolywrapClient @@ -65,7 +48,15 @@ export class PolywrapClient implements Client { * @param options - { noDefaults?: boolean } */ constructor( - config?: Partial>, + config?: Partial, + options?: { noDefaults?: false } + ); + constructor(config: PolywrapCoreClientConfig, options: { noDefaults: true }); + constructor( + config: + | Partial + | undefined + | PolywrapCoreClientConfig, options?: { noDefaults?: boolean } ) { try { @@ -73,30 +64,13 @@ export class PolywrapClient implements Client { Tracer.startSpan("PolywrapClient: constructor"); - const builder = new ClientConfigBuilder(); - - if (!options?.noDefaults) { - builder.addDefaults(config?.wrapperCache); - } - - if (config) { - builder.add(config); - } - - const sanitizedConfig = builder.build(); - - this._config = { - ...sanitizedConfig, - tracerConfig: { - consoleEnabled: !!config?.tracerConfig?.consoleEnabled, - consoleDetailed: config?.tracerConfig?.consoleDetailed, - httpEnabled: !!config?.tracerConfig?.httpEnabled, - httpUrl: config?.tracerConfig?.httpUrl, - tracingLevel: config?.tracerConfig?.tracingLevel, - }, - }; - - this._validateConfig(); + this._config = !options?.noDefaults + ? this.buildConfigFromPolywrapClientConfig( + config as PolywrapClientConfig | undefined + ) + : this.buildConfigFromPolywrapCoreClientConfig( + config as PolywrapCoreClientConfig + ); Tracer.setAttribute("config", this._config); } catch (error) { @@ -112,7 +86,7 @@ export class PolywrapClient implements Client { * * @returns an immutable Polywrap client config */ - public getConfig(): PolywrapClientConfig { + public getConfig(): PolywrapCoreClientConfig { return this._config; } @@ -131,10 +105,6 @@ export class PolywrapClient implements Client { } else { Tracer.disableTracing(); } - this._config = { - ...this._config, - tracerConfig: tracerConfig ?? {}, - }; } /** @@ -143,7 +113,7 @@ export class PolywrapClient implements Client { * @returns an array of uri redirects */ @Tracer.traceMethod("PolywrapClient: getRedirects") - public getRedirects(): readonly UriRedirect[] { + public getRedirects(): readonly IUriRedirect[] | undefined { return this._config.redirects; } @@ -152,32 +122,19 @@ export class PolywrapClient implements Client { * * @returns an array of plugin registrations */ - @Tracer.traceMethod("PolywrapClient: getPlugins") - public getPlugins(): readonly PluginRegistration[] { - return this._config.plugins; - } - /** * returns a plugin package from the configuration used to instantiate the client * * @param uri - the uri used to register the plugin * @returns a plugin package, or undefined if a plugin is not found at the given uri */ - @Tracer.traceMethod("PolywrapClient: getPlugin") - public getPluginByUri( - uri: TUri - ): PluginPackage | undefined { - return this.getPlugins().find((x) => Uri.equals(x.uri, Uri.from(uri))) - ?.plugin; - } - /** * returns all interfaces from the configuration used to instantiate the client * * @returns an array of interfaces and their registered implementations */ @Tracer.traceMethod("PolywrapClient: getInterfaces") - public getInterfaces(): readonly InterfaceImplementations[] { + public getInterfaces(): readonly InterfaceImplementations[] | undefined { return this._config.interfaces; } @@ -187,7 +144,7 @@ export class PolywrapClient implements Client { * @returns an array of env objects containing wrapper environmental variables */ @Tracer.traceMethod("PolywrapClient: getEnvs") - public getEnvs(): readonly Env[] { + public getEnvs(): readonly Env[] | undefined { return this._config.envs; } @@ -213,9 +170,12 @@ export class PolywrapClient implements Client { ): Env | undefined { const uriUri = Uri.from(uri); - return this.getEnvs().find((environment) => - Uri.equals(environment.uri, uriUri) - ); + const envs = this.getEnvs(); + if (!envs) { + return undefined; + } + + return envs.find((environment) => Uri.equals(environment.uri, uriUri)); } /** @@ -227,15 +187,14 @@ export class PolywrapClient implements Client { */ @Tracer.traceMethod("PolywrapClient: getManifest") public async getManifest( - uri: TUri, - options: GetManifestOptions = {} + uri: TUri ): Promise> { const load = await this.loadWrapper(Uri.from(uri), undefined); if (!load.ok) { return load; } const wrapper = load.value; - const manifest = wrapper.getManifest(options); + const manifest = wrapper.getManifest(); return ResultOk(manifest); } @@ -279,7 +238,7 @@ export class PolywrapClient implements Client { const getImplResult = getImplementations( Uri.from(uri), - this.getInterfaces(), + this.getInterfaces() ?? [], applyRedirects ? this.getRedirects() : undefined ); @@ -496,13 +455,15 @@ export class PolywrapClient implements Client { typedOptions.uri, resolutionContext ); + if (!loadWrapperResult.ok) { - return ResultErr(loadWrapperResult.error); + return loadWrapperResult; } const wrapper = loadWrapperResult.value; + const resolutionPath = resolutionContext.getResolutionPath(); const env = getEnvFromUriHistory( - resolutionContext.getResolutionPath(), + resolutionPath.length > 0 ? resolutionPath : [typedOptions.uri], this ); @@ -513,7 +474,7 @@ export class PolywrapClient implements Client { }); if (!invokeResult.ok) { - return ResultErr(invokeResult.error); + return invokeResult; } return invokeResult; @@ -743,20 +704,58 @@ export class PolywrapClient implements Client { } } - @Tracer.traceMethod("PolywrapClient: validateConfig") - private _validateConfig(): void { - // Require plugins to use non-interface URIs - const pluginUris = this.getPlugins().map((x) => x.uri.uri); - const interfaceUris = this.getInterfaces().map((x) => x.interface.uri); + private buildConfigFromPolywrapClientConfig( + config?: PolywrapClientConfig + ): PolywrapCoreClientConfig { + const builder = new ClientConfigBuilder(); - const pluginsWithInterfaceUris = pluginUris.filter((plugin) => - interfaceUris.includes(plugin) - ); + builder.addDefaults(); - if (pluginsWithInterfaceUris.length) { - throw Error( - `Plugins can't use interfaces for their URI. Invalid plugins: ${pluginsWithInterfaceUris}` - ); + if (config) { + builder.add(config); } + + const sanitizedConfig = builder.buildDefault(config?.wrapperCache); + + return { + ...sanitizedConfig, + tracerConfig: { + consoleEnabled: !!config?.tracerConfig?.consoleEnabled, + consoleDetailed: config?.tracerConfig?.consoleDetailed, + httpEnabled: !!config?.tracerConfig?.httpEnabled, + httpUrl: config?.tracerConfig?.httpUrl, + tracingLevel: config?.tracerConfig?.tracingLevel, + }, + }; + } + + private buildConfigFromPolywrapCoreClientConfig( + config: PolywrapCoreClientConfig + ): PolywrapCoreClientConfig { + return { + redirects: + config?.redirects?.map((x) => ({ + from: Uri.from(x.from), + to: Uri.from(x.to), + })) ?? [], + interfaces: + config?.interfaces?.map((x) => ({ + interface: Uri.from(x.interface), + implementations: x.implementations.map((y) => Uri.from(y)), + })) ?? [], + envs: + config?.envs?.map((x) => ({ + uri: Uri.from(x.uri), + env: x.env, + })) ?? [], + resolver: config.resolver, + tracerConfig: { + consoleEnabled: !!config?.tracerConfig?.consoleEnabled, + consoleDetailed: config?.tracerConfig?.consoleDetailed, + httpEnabled: !!config?.tracerConfig?.httpEnabled, + httpUrl: config?.tracerConfig?.httpUrl, + tracingLevel: config?.tracerConfig?.tracingLevel, + }, + }; } } diff --git a/packages/js/client/src/PolywrapClientConfig.ts b/packages/js/client/src/PolywrapClientConfig.ts new file mode 100644 index 0000000000..d20f424276 --- /dev/null +++ b/packages/js/client/src/PolywrapClientConfig.ts @@ -0,0 +1,10 @@ +import { Uri } from "@polywrap/core-js"; +import { IWrapperCache } from "@polywrap/uri-resolvers-js"; +import { TracerConfig } from "@polywrap/tracing-js"; +import { ClientConfig } from "@polywrap/client-config-builder-js"; + +export interface PolywrapClientConfig + extends ClientConfig { + readonly wrapperCache?: IWrapperCache; + readonly tracerConfig?: Readonly>; +} diff --git a/packages/js/client/src/PolywrapCoreClientConfig.ts b/packages/js/client/src/PolywrapCoreClientConfig.ts new file mode 100644 index 0000000000..aa5baf913c --- /dev/null +++ b/packages/js/client/src/PolywrapCoreClientConfig.ts @@ -0,0 +1,8 @@ +import { CoreClientConfig, Uri } from "@polywrap/core-js"; +import { TracerConfig } from "@polywrap/tracing-js"; + +export interface PolywrapCoreClientConfig< + TUri extends Uri | string = Uri | string +> extends CoreClientConfig { + readonly tracerConfig?: Readonly>; +} diff --git a/packages/js/client/src/__tests__/core/createPolywrapClient.spec.ts b/packages/js/client/src/__tests__/core/createPolywrapClient.spec.ts deleted file mode 100644 index f80dd06f30..0000000000 --- a/packages/js/client/src/__tests__/core/createPolywrapClient.spec.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { createPolywrapClient, PluginConfigs } from "../../createPolywrapClient"; - -describe("createPolywrapClient", () => { - it("Should throw because the plugin requested it's not installed ", async () => { - const clientParams = { - nonExistantPlugin: { - provider: "none", - }, - } as PluginConfigs; - - await expect(createPolywrapClient(clientParams)).rejects.toThrow( - "Requested plugin \"nonExistantPlugin\" is not a supported createPolywrapClient plugin." - ); - }); -}); diff --git a/packages/js/client/src/__tests__/core/interface-impls.spec.ts b/packages/js/client/src/__tests__/core/interface-impls.spec.ts index 4ef005e719..fbafdfde59 100644 --- a/packages/js/client/src/__tests__/core/interface-impls.spec.ts +++ b/packages/js/client/src/__tests__/core/interface-impls.spec.ts @@ -1,7 +1,7 @@ -import { coreInterfaceUris, Uri, PluginModule, PolywrapClient } from "../.."; -import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; -import { getClient } from "../utils/getClient"; +import { coreInterfaceUris, Uri, PolywrapClient } from "../.."; import { ClientConfigBuilder } from "@polywrap/client-config-builder-js"; +import { UriResolver } from "@polywrap/uri-resolvers-js"; +import { mockPluginRegistration } from "../helpers/mockPluginRegistration"; jest.setTimeout(200000); @@ -11,22 +11,25 @@ describe("interface-impls", () => { const implementation1Uri = "wrap://ens/some-implementation1.eth"; const implementation2Uri = "wrap://ens/some-implementation2.eth"; - const client = new PolywrapClient({ - interfaces: [ - { - interface: interfaceUri, - implementations: [implementation1Uri, implementation2Uri], - }, - ], - }); + const client = new PolywrapClient( + { + interfaces: [ + { + interface: interfaceUri, + implementations: [implementation1Uri, implementation2Uri], + }, + ], + resolver: UriResolver.from({ + from: "uri/foo", + to: "uri/bar" + }) + }, + { noDefaults: true } + ); const interfaces = client.getInterfaces(); - const builder = new ClientConfigBuilder(); - const defaultClientConfig = builder.addDefaults().build(); - expect(interfaces).toEqual([ - ...(defaultClientConfig.interfaces ?? []), { interface: new Uri(interfaceUri), implementations: [ @@ -36,10 +39,15 @@ describe("interface-impls", () => { }, ]); - const implementations = client.getImplementations(interfaceUri); + const implementations = client.getImplementations(interfaceUri, { + applyRedirects: false, + }); if (!implementations.ok) fail(implementations.error); - expect(implementations.value).toEqual([implementation1Uri, implementation2Uri]); + expect(implementations.value).toEqual([ + implementation1Uri, + implementation2Uri, + ]); }); it("should get all implementations of interface", async () => { @@ -52,45 +60,44 @@ describe("interface-impls", () => { const implementation3Uri = "wrap://ens/some-implementation3.eth"; const implementation4Uri = "wrap://ens/some-implementation4.eth"; - const client = await getClient({ - redirects: [ - { - from: interface1Uri, - to: interface2Uri, - }, - { - from: implementation1Uri, - to: implementation2Uri, - }, - { - from: implementation2Uri, - to: implementation3Uri, - }, - ], - plugins: [ - { - uri: implementation4Uri, - plugin: { - factory: () => ({} as PluginModule<{}>), - manifest: {} as WrapManifest, + const client = new PolywrapClient( + { + redirects: [ + { + from: interface1Uri, + to: interface2Uri, }, - }, - ], - interfaces: [ - { - interface: interface1Uri, - implementations: [implementation1Uri, implementation2Uri], - }, - { - interface: interface2Uri, - implementations: [implementation3Uri], - }, - { - interface: interface3Uri, - implementations: [implementation3Uri, implementation4Uri], - }, - ], - }); + { + from: implementation1Uri, + to: implementation2Uri, + }, + { + from: implementation2Uri, + to: implementation3Uri, + }, + ], + resolver: UriResolver.from([ + mockPluginRegistration(implementation4Uri), + ]), + interfaces: [ + { + interface: interface1Uri, + implementations: [implementation1Uri, implementation2Uri], + }, + { + interface: interface2Uri, + implementations: [implementation3Uri], + }, + { + interface: interface3Uri, + implementations: [implementation3Uri, implementation4Uri], + }, + ], + }, + { + noDefaults: true, + } + ); const implementations1 = client.getImplementations(interface1Uri, { applyRedirects: true, @@ -117,85 +124,10 @@ describe("interface-impls", () => { ]); if (!implementations3.ok) fail(implementations3.error); - expect(implementations3.value).toEqual([implementation3Uri, implementation4Uri]); - }); - - it("should not register plugins with an interface uri (without default plugins)", () => { - const interface1Uri = "wrap://ens/some-interface1.eth"; - const interface2Uri = "wrap://ens/some-interface2.eth"; - const interface3Uri = "wrap://ens/some-interface3.eth"; - - const implementationUri = "wrap://ens/some-implementation.eth"; - - expect(() => { - new PolywrapClient({ - plugins: [ - { - uri: interface1Uri, - plugin: { - factory: () => ({} as PluginModule<{}>), - manifest: {} as WrapManifest, - }, - }, - { - uri: interface2Uri, - plugin: { - factory: () => ({} as PluginModule<{}>), - manifest: {} as WrapManifest, - }, - }, - ], - interfaces: [ - { - interface: interface1Uri, - implementations: [implementationUri], - }, - { - interface: interface2Uri, - implementations: [implementationUri], - }, - { - interface: interface3Uri, - implementations: [implementationUri], - }, - ], - }); - }).toThrow( - `Plugins can't use interfaces for their URI. Invalid plugins: ${[ - interface1Uri, - interface2Uri, - ]}` - ); - }); - - it("should not register plugins with an interface uri (with default plugins)", async () => { - const interfaceUri = "wrap://ens/some-interface.eth"; - - const implementationUri = "wrap://ens/some-implementation.eth"; - - await expect(async () => { - await getClient({ - plugins: [ - { - uri: interfaceUri, - plugin: { - factory: () => ({} as PluginModule<{}>), - manifest: {} as WrapManifest, - }, - }, - ], - interfaces: [ - { - interface: interfaceUri, - implementations: [implementationUri], - }, - ], - }); - }).rejects.toThrow( - `Plugins can't use interfaces for their URI. Invalid plugins: ${[ - interfaceUri, - ]}` - ); + expect(implementations3.value).toEqual([ + implementation3Uri, + implementation4Uri, + ]); }); it("should merge user-defined interface implementations with each other", async () => { @@ -216,8 +148,7 @@ describe("interface-impls", () => { ], }); - const interfaces = client - .getInterfaces() + const interfaces = (client.getInterfaces() || []) .filter((x) => x.interface.uri === interfaceUri); expect(interfaces.length).toEqual(1); @@ -247,18 +178,17 @@ describe("interface-impls", () => { ], }); - const interfaces = client - .getInterfaces() + const interfaces = (client.getInterfaces() || []) .filter((x) => x.interface.uri === interfaceUri); expect(interfaces.length).toEqual(1); const implementationUris = interfaces[0].implementations; const builder = new ClientConfigBuilder(); - const defaultClientConfig = builder.addDefaults().build(); + const defaultClientConfig = builder.addDefaults().buildDefault(); expect(implementationUris).toEqual([ - ...defaultClientConfig.interfaces.find( + ...(defaultClientConfig.interfaces || []).find( (x) => x.interface.uri === interfaceUri )!.implementations, new Uri(implementationUri1), @@ -272,23 +202,22 @@ describe("interface-impls", () => { const implementation1Uri = "wrap://ens/some-implementation1.eth"; const implementation2Uri = "wrap://ens/some-implementation2.eth"; - const client = new PolywrapClient({ - plugins: [ - { - uri: implementation1Uri, - plugin: { - factory: () => ({} as PluginModule<{}>), - manifest: {} as WrapManifest, + const client = new PolywrapClient( + { + resolver: UriResolver.from([ + mockPluginRegistration(implementation1Uri), + ]), + interfaces: [ + { + interface: interfaceUri, + implementations: [implementation2Uri], }, - }, - ], - interfaces: [ - { - interface: interfaceUri, - implementations: [implementation2Uri], - }, - ], - }); + ], + }, + { + noDefaults: true, + } + ); const getImplementationsResult = client.getImplementations( new Uri(interfaceUri), @@ -296,7 +225,9 @@ describe("interface-impls", () => { ); if (!getImplementationsResult.ok) fail(getImplementationsResult.error); - expect(getImplementationsResult.value).toEqual([new Uri(implementation2Uri)]); + expect(getImplementationsResult.value).toEqual([ + new Uri(implementation2Uri), + ]); }); test("get implementations - return implementations for plugins which don't have interface stated in manifest", () => { @@ -305,23 +236,20 @@ describe("interface-impls", () => { const implementation1Uri = "wrap://ens/some-implementation1.eth"; const implementation2Uri = "wrap://ens/some-implementation2.eth"; - const client = new PolywrapClient({ - plugins: [ - { - uri: implementation1Uri, - plugin: { - factory: () => ({} as PluginModule<{}>), - manifest: {} as WrapManifest, + const client = new PolywrapClient( + { + resolver: UriResolver.from([ + mockPluginRegistration(implementation1Uri), + ]), + interfaces: [ + { + interface: interfaceUri, + implementations: [implementation1Uri, implementation2Uri], }, - }, - ], - interfaces: [ - { - interface: interfaceUri, - implementations: [implementation1Uri, implementation2Uri], - }, - ], - }); + ], + }, + { noDefaults: true } + ); const getImplementationsResult = client.getImplementations( new Uri(interfaceUri), @@ -361,7 +289,9 @@ describe("interface-impls", () => { ], }); - let result = client.getImplementations(oldInterfaceUri); + let result = client.getImplementations(oldInterfaceUri, { + applyRedirects: false, + }); if (!result.ok) fail(result.error); expect(result.value).toEqual([implementation1Uri]); @@ -371,7 +301,9 @@ describe("interface-impls", () => { if (!result.ok) fail(result.error); expect(result.value).toEqual([implementation1Uri, implementation2Uri]); - let result2 = client.getImplementations(new Uri(oldInterfaceUri)); + let result2 = client.getImplementations(new Uri(oldInterfaceUri), { + applyRedirects: false, + }); if (!result2.ok) fail(result2.error); expect(result2.value).toEqual([new Uri(implementation1Uri)]); diff --git a/packages/js/client/src/__tests__/core/plugin-wrapper.spec.ts b/packages/js/client/src/__tests__/core/plugin-wrapper.spec.ts index 2158650136..80f7ea4c01 100644 --- a/packages/js/client/src/__tests__/core/plugin-wrapper.spec.ts +++ b/packages/js/client/src/__tests__/core/plugin-wrapper.spec.ts @@ -1,21 +1,10 @@ -import { PolywrapClient, PluginModule, PluginPackage } from "../.."; -import { getClient } from "../utils/getClient"; +import { PolywrapClient } from "../.."; import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; - +import { PluginPackage, PluginModule } from "@polywrap/plugin-js"; +import { UriResolver } from "@polywrap/uri-resolvers-js"; +import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; jest.setTimeout(200000); -const defaultPlugins = [ - "wrap://ens/ipfs.polywrap.eth", - "wrap://ens/ens-resolver.polywrap.eth", - "wrap://ens/ethereum.polywrap.eth", - "wrap://ens/http.polywrap.eth", - "wrap://ens/http-resolver.polywrap.eth", - "wrap://ens/js-logger.polywrap.eth", - "wrap://ens/fs.polywrap.eth", - "wrap://ens/fs-resolver.polywrap.eth", - "wrap://ens/ipfs-resolver.polywrap.eth", -]; - describe("plugin-wrapper", () => { const mockMapPlugin = () => { interface Config extends Record { @@ -38,46 +27,28 @@ describe("plugin-wrapper", () => { } } - return { - factory: () => - new MockMapPlugin({ - map: new Map().set("a", 1).set("b", 2), - }), - manifest: {} as WrapManifest, - }; + return new PluginPackage( + new MockMapPlugin({ + map: new Map().set("a", 1).set("b", 2), + }), + {} as WrapManifest + ); }; - test("plugin registration - with default plugins", () => { - const implementationUri = "wrap://ens/some-implementation.eth"; - - const client = new PolywrapClient({ - plugins: [ - { - uri: implementationUri, - plugin: { - factory: () => ({} as PluginModule<{}>), - manifest: {} as WrapManifest, - }, - }, - ], - }); - - const pluginUris = client.getPlugins().map((x) => x.uri.uri); - - expect(pluginUris).toEqual(defaultPlugins.concat([implementationUri])); - }); - it("plugin map types", async () => { const implementationUri = "wrap://ens/some-implementation.eth"; const mockPlugin = mockMapPlugin(); - const client = await getClient({ - plugins: [ - { - uri: implementationUri, - plugin: mockPlugin, - }, - ], - }); + const client = new PolywrapClient( + { + resolver: UriResolver.from([ + { + uri: implementationUri, + package: mockPlugin, + }, + ]), + }, + { noDefaults: true } + ); const getResult = await client.invoke({ uri: implementationUri, @@ -105,103 +76,15 @@ describe("plugin-wrapper", () => { ); }); - test("plugin registration - with plugin override", async () => { - const pluginUriToOverride = defaultPlugins[0]; - - const pluginPackage = { - factory: () => ({} as PluginModule<{}>), - manifest: {} as WrapManifest, - }; - - const client = new PolywrapClient({ - plugins: [ - { - uri: pluginUriToOverride, - plugin: pluginPackage, - }, - ], - }); - - const pluginUris = client.getPlugins().map((x) => x.uri.uri); - - expect(pluginUris).toEqual(defaultPlugins); - - const registeredPlugin = client - .getPlugins() - .find((x) => x.uri.uri === pluginUriToOverride); - - expect(registeredPlugin?.plugin).toEqual(pluginPackage); - }); - - test("plugin registration - with multiple plugin overrides", async () => { - const pluginUriToOverride = defaultPlugins[0]; - - const pluginPackage1 = { - factory: () => ({} as PluginModule<{}>), - manifest: {} as WrapManifest, - }; - - const pluginPackage2 = { - factory: () => ({} as PluginModule<{}>), - manifest: {} as WrapManifest, - }; - - const client = new PolywrapClient({ - plugins: [ - { - uri: pluginUriToOverride, - plugin: pluginPackage1, - }, - { - uri: pluginUriToOverride, - plugin: pluginPackage2, - }, - ], - }); - - const pluginUris = client.getPlugins().map((x) => x.uri.uri); - - expect(pluginUris).toEqual(defaultPlugins); - - const registeredPlugin = client - .getPlugins() - .find((x) => x.uri.uri === pluginUriToOverride); - - expect(registeredPlugin?.plugin).toEqual(pluginPackage2); - }); - - test("get plugin package by uri", async () => { - interface SamplePluginConfig { - bar: string; - } - class SamplePluginModule extends PluginModule {} - const config: SamplePluginConfig = { bar: "test" }; - - const pluginPackage = >{ - factory: () => new SamplePluginModule(config), - manifest: {}, - }; - + test("get manifest should fetch wrap manifest from plugin", async () => { const client = new PolywrapClient( { - plugins: [ - { - uri: "wrap://ens/some.plugin.eth", - plugin: pluginPackage, - }, - ], - } - ); - - const plugin = await client.getPluginByUri( - "wrap://ens/some.plugin.eth" + resolver: UriResolver.from([ + { uri: "ens/ipfs.polywrap.eth", package: ipfsPlugin({}) }, + ]), + }, + { noDefaults: true } ); - - expect(plugin).toStrictEqual(pluginPackage); - }); - - test("get manifest should fetch wrap manifest from plugin", async () => { - const client = await getClient(); const manifest = await client.getManifest("ens/ipfs.polywrap.eth"); if (!manifest.ok) fail(manifest.error); expect(manifest.value.type).toEqual("plugin"); diff --git a/packages/js/client/src/__tests__/core/sanity.spec.ts b/packages/js/client/src/__tests__/core/sanity.spec.ts index 33ca3fbe80..f8ca56a104 100644 --- a/packages/js/client/src/__tests__/core/sanity.spec.ts +++ b/packages/js/client/src/__tests__/core/sanity.spec.ts @@ -1,7 +1,7 @@ import { coreInterfaceUris } from "@polywrap/core-js"; -import { buildUriResolver } from "@polywrap/uri-resolvers-js"; -import { Uri, PolywrapClient } from "../.."; +import { Uri } from "../.."; import { defaultWrappers } from "@polywrap/client-config-builder-js"; +import { PolywrapClient } from "../../PolywrapClient"; jest.setTimeout(200000); @@ -24,66 +24,22 @@ describe("sanity", () => { }, ]); - const expectedPlugins = [ - new Uri("wrap://ens/ipfs.polywrap.eth"), - new Uri("wrap://ens/ens-resolver.polywrap.eth"), - new Uri("wrap://ens/ethereum.polywrap.eth"), - new Uri("wrap://ens/http.polywrap.eth"), - new Uri("wrap://ens/http-resolver.polywrap.eth"), - new Uri("wrap://ens/js-logger.polywrap.eth"), - new Uri("wrap://ens/fs.polywrap.eth"), - new Uri("wrap://ens/fs-resolver.polywrap.eth"), - new Uri("wrap://ens/ipfs-resolver.polywrap.eth"), - ]; - const actualPlugins = client.getPlugins().map(x => x.uri); - expect(expectedPlugins).toStrictEqual(actualPlugins); - - expect(client.getInterfaces()).toStrictEqual([ - { - interface: coreInterfaceUris.uriResolver, - implementations: [ - new Uri("wrap://ens/ipfs-resolver.polywrap.eth"), - new Uri("wrap://ens/ens-resolver.polywrap.eth"), - new Uri("wrap://ens/fs-resolver.polywrap.eth"), - new Uri("wrap://ens/http-resolver.polywrap.eth"), - ], - }, - { - interface: coreInterfaceUris.logger, - implementations: [new Uri("wrap://ens/js-logger.polywrap.eth")], - }, - ]); - }); - - test("client noDefaults flag works as expected", async () => { - let client = new PolywrapClient(); - expect(client.getPlugins().length !== 0).toBeTruthy(); - expect(client.getUriResolver()).toBeTruthy(); - - client = new PolywrapClient({}, {}); - expect(client.getPlugins().length !== 0).toBeTruthy(); - expect(client.getUriResolver()).toBeTruthy(); - - client = new PolywrapClient({}, { noDefaults: false }); - expect(client.getPlugins().length !== 0).toBeTruthy(); - expect(client.getUriResolver()).toBeTruthy(); - - client = new PolywrapClient( - { resolver: buildUriResolver([]) }, - { noDefaults: true } - ); - - expect(client.getPlugins().length === 0).toBeTruthy(); - expect(client.getUriResolver()).toBeTruthy(); - - let message = ""; - try { - client = new PolywrapClient({}, { noDefaults: true }); - } catch (e) { - message = e.message; - } - - expect(message).toBe("No URI resolver provided"); + new Uri("wrap://ens/http-resolver.polywrap.eth"), + expect(client.getInterfaces()).toStrictEqual([ + { + interface: coreInterfaceUris.uriResolver, + implementations: [ + new Uri("wrap://ens/ipfs-resolver.polywrap.eth"), + new Uri("wrap://ens/ens-resolver.polywrap.eth"), + new Uri("wrap://ens/fs-resolver.polywrap.eth"), + new Uri("wrap://ens/http-resolver.polywrap.eth"), + ], + }, + { + interface: coreInterfaceUris.logger, + implementations: [new Uri("wrap://ens/js-logger.polywrap.eth")], + }, + ]); }); test("redirect registration", () => { diff --git a/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve a URI resolver extension wrapper.json b/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve a URI resolver extension wrapper.json index f8fd57fb5b..b71a7d2930 100644 --- a/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve a URI resolver extension wrapper.json +++ b/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve a URI resolver extension wrapper.json @@ -9,40 +9,28 @@ [ "wrap://ens/ipfs-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/ipfs-resolver.polywrap.eth)", [ - "wrap://ens/ipfs-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/ipfs-resolver.polywrap.eth)", - [ - "wrap://ens/ipfs-resolver.polywrap.eth => Plugin (wrap://ens/ipfs-resolver.polywrap.eth) => package (wrap://ens/ipfs-resolver.polywrap.eth)" - ] + "wrap://ens/ipfs-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/ipfs-resolver.polywrap.eth) => package (wrap://ens/ipfs-resolver.polywrap.eth)" ] ], "wrap://ens/ens-resolver.polywrap.eth => PackageToWrapperCacheResolver => wrapper (wrap://ens/ens-resolver.polywrap.eth)", [ "wrap://ens/ens-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/ens-resolver.polywrap.eth)", [ - "wrap://ens/ens-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/ens-resolver.polywrap.eth)", - [ - "wrap://ens/ens-resolver.polywrap.eth => Plugin (wrap://ens/ens-resolver.polywrap.eth) => package (wrap://ens/ens-resolver.polywrap.eth)" - ] + "wrap://ens/ens-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/ens-resolver.polywrap.eth) => package (wrap://ens/ens-resolver.polywrap.eth)" ] ], "wrap://ens/fs-resolver.polywrap.eth => PackageToWrapperCacheResolver => wrapper (wrap://ens/fs-resolver.polywrap.eth)", [ "wrap://ens/fs-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/fs-resolver.polywrap.eth)", [ - "wrap://ens/fs-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/fs-resolver.polywrap.eth)", - [ - "wrap://ens/fs-resolver.polywrap.eth => Plugin (wrap://ens/fs-resolver.polywrap.eth) => package (wrap://ens/fs-resolver.polywrap.eth)" - ] + "wrap://ens/fs-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/fs-resolver.polywrap.eth) => package (wrap://ens/fs-resolver.polywrap.eth)" ] ], "wrap://ens/http-resolver.polywrap.eth => PackageToWrapperCacheResolver => wrapper (wrap://ens/http-resolver.polywrap.eth)", [ "wrap://ens/http-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/http-resolver.polywrap.eth)", [ - "wrap://ens/http-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/http-resolver.polywrap.eth)", - [ - "wrap://ens/http-resolver.polywrap.eth => Plugin (wrap://ens/http-resolver.polywrap.eth) => package (wrap://ens/http-resolver.polywrap.eth)" - ] + "wrap://ens/http-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/http-resolver.polywrap.eth) => package (wrap://ens/http-resolver.polywrap.eth)" ] ], "wrap://file/$root-wrapper-dir/simple-fs-resolver/build => PackageToWrapperCacheResolver => wrapper (wrap://file/$root-wrapper-dir/simple-fs-resolver/build)", @@ -75,4 +63,4 @@ ] ] ] -] \ No newline at end of file +] diff --git a/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve cache - 1.json b/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve cache - 1.json index 3e0b1b4fc9..929857b596 100644 --- a/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve cache - 1.json +++ b/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve cache - 1.json @@ -9,30 +9,21 @@ [ "wrap://ens/ipfs-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/ipfs-resolver.polywrap.eth)", [ - "wrap://ens/ipfs-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/ipfs-resolver.polywrap.eth)", - [ - "wrap://ens/ipfs-resolver.polywrap.eth => Plugin (wrap://ens/ipfs-resolver.polywrap.eth) => package (wrap://ens/ipfs-resolver.polywrap.eth)" - ] + "wrap://ens/ipfs-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/ipfs-resolver.polywrap.eth) => package (wrap://ens/ipfs-resolver.polywrap.eth)" ] ], "wrap://ens/ens-resolver.polywrap.eth => PackageToWrapperCacheResolver => wrapper (wrap://ens/ens-resolver.polywrap.eth)", [ "wrap://ens/ens-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/ens-resolver.polywrap.eth)", [ - "wrap://ens/ens-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/ens-resolver.polywrap.eth)", - [ - "wrap://ens/ens-resolver.polywrap.eth => Plugin (wrap://ens/ens-resolver.polywrap.eth) => package (wrap://ens/ens-resolver.polywrap.eth)" - ] + "wrap://ens/ens-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/ens-resolver.polywrap.eth) => package (wrap://ens/ens-resolver.polywrap.eth)" ] ], "wrap://ens/fs-resolver.polywrap.eth => PackageToWrapperCacheResolver => wrapper (wrap://ens/fs-resolver.polywrap.eth)", [ "wrap://ens/fs-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/fs-resolver.polywrap.eth)", [ - "wrap://ens/fs-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/fs-resolver.polywrap.eth)", - [ - "wrap://ens/fs-resolver.polywrap.eth => Plugin (wrap://ens/fs-resolver.polywrap.eth) => package (wrap://ens/fs-resolver.polywrap.eth)" - ] + "wrap://ens/fs-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/fs-resolver.polywrap.eth) => package (wrap://ens/fs-resolver.polywrap.eth)" ] ], "wrap://file/$root-wrapper-dir/simple/build => ResolverExtension (wrap://ens/fs-resolver.polywrap.eth) => package (wrap://file/$root-wrapper-dir/simple/build)" diff --git a/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve plugin.json b/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve plugin.json index 5d12f06e23..f4420eab36 100644 --- a/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve plugin.json +++ b/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve plugin.json @@ -3,10 +3,7 @@ [ "wrap://ens/plugin.eth => UriResolverAggregator => package (wrap://ens/plugin.eth)", [ - "wrap://ens/plugin.eth => LegacyPluginsResolver => package (wrap://ens/plugin.eth)", - [ - "wrap://ens/plugin.eth => Plugin (wrap://ens/plugin.eth) => package (wrap://ens/plugin.eth)" - ] + "wrap://ens/plugin.eth => Package (wrap://ens/plugin.eth) => package (wrap://ens/plugin.eth)" ] ] -] \ No newline at end of file +] diff --git a/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve previously cached URI after redirecting by a URI resolver extension - 1.json b/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve previously cached URI after redirecting by a URI resolver extension - 1.json index f8fd57fb5b..99c1c4f4bc 100644 --- a/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve previously cached URI after redirecting by a URI resolver extension - 1.json +++ b/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve previously cached URI after redirecting by a URI resolver extension - 1.json @@ -9,40 +9,28 @@ [ "wrap://ens/ipfs-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/ipfs-resolver.polywrap.eth)", [ - "wrap://ens/ipfs-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/ipfs-resolver.polywrap.eth)", - [ - "wrap://ens/ipfs-resolver.polywrap.eth => Plugin (wrap://ens/ipfs-resolver.polywrap.eth) => package (wrap://ens/ipfs-resolver.polywrap.eth)" - ] + "wrap://ens/ipfs-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/ipfs-resolver.polywrap.eth) => package (wrap://ens/ipfs-resolver.polywrap.eth)" ] ], "wrap://ens/ens-resolver.polywrap.eth => PackageToWrapperCacheResolver => wrapper (wrap://ens/ens-resolver.polywrap.eth)", [ "wrap://ens/ens-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/ens-resolver.polywrap.eth)", [ - "wrap://ens/ens-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/ens-resolver.polywrap.eth)", - [ - "wrap://ens/ens-resolver.polywrap.eth => Plugin (wrap://ens/ens-resolver.polywrap.eth) => package (wrap://ens/ens-resolver.polywrap.eth)" - ] + "wrap://ens/ens-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/ens-resolver.polywrap.eth) => package (wrap://ens/ens-resolver.polywrap.eth)" ] ], "wrap://ens/fs-resolver.polywrap.eth => PackageToWrapperCacheResolver => wrapper (wrap://ens/fs-resolver.polywrap.eth)", [ "wrap://ens/fs-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/fs-resolver.polywrap.eth)", [ - "wrap://ens/fs-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/fs-resolver.polywrap.eth)", - [ - "wrap://ens/fs-resolver.polywrap.eth => Plugin (wrap://ens/fs-resolver.polywrap.eth) => package (wrap://ens/fs-resolver.polywrap.eth)" - ] + "wrap://ens/fs-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/fs-resolver.polywrap.eth) => package (wrap://ens/fs-resolver.polywrap.eth)" ] ], "wrap://ens/http-resolver.polywrap.eth => PackageToWrapperCacheResolver => wrapper (wrap://ens/http-resolver.polywrap.eth)", [ "wrap://ens/http-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/http-resolver.polywrap.eth)", [ - "wrap://ens/http-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/http-resolver.polywrap.eth)", - [ - "wrap://ens/http-resolver.polywrap.eth => Plugin (wrap://ens/http-resolver.polywrap.eth) => package (wrap://ens/http-resolver.polywrap.eth)" - ] + "wrap://ens/http-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/http-resolver.polywrap.eth) => package (wrap://ens/http-resolver.polywrap.eth)" ] ], "wrap://file/$root-wrapper-dir/simple-fs-resolver/build => PackageToWrapperCacheResolver => wrapper (wrap://file/$root-wrapper-dir/simple-fs-resolver/build)", diff --git a/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve redirects.json b/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve redirects.json index 8b3433f090..19147a3ad9 100644 --- a/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve redirects.json +++ b/packages/js/client/src/__tests__/core/uri-resolution/histories/can resolve redirects.json @@ -19,4 +19,4 @@ ] ] ] -] \ No newline at end of file +] diff --git a/packages/js/client/src/__tests__/core/uri-resolution/histories/custom wrapper resolver does not cause infinite recursion when resolved at runtime.json b/packages/js/client/src/__tests__/core/uri-resolution/histories/custom wrapper resolver does not cause infinite recursion when resolved at runtime.json index fd0c16a4d1..7763bcf916 100644 --- a/packages/js/client/src/__tests__/core/uri-resolution/histories/custom wrapper resolver does not cause infinite recursion when resolved at runtime.json +++ b/packages/js/client/src/__tests__/core/uri-resolution/histories/custom wrapper resolver does not cause infinite recursion when resolved at runtime.json @@ -9,40 +9,28 @@ [ "wrap://ens/ipfs-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/ipfs-resolver.polywrap.eth)", [ - "wrap://ens/ipfs-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/ipfs-resolver.polywrap.eth)", - [ - "wrap://ens/ipfs-resolver.polywrap.eth => Plugin (wrap://ens/ipfs-resolver.polywrap.eth) => package (wrap://ens/ipfs-resolver.polywrap.eth)" - ] + "wrap://ens/ipfs-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/ipfs-resolver.polywrap.eth) => package (wrap://ens/ipfs-resolver.polywrap.eth)" ] ], "wrap://ens/ens-resolver.polywrap.eth => PackageToWrapperCacheResolver => wrapper (wrap://ens/ens-resolver.polywrap.eth)", [ "wrap://ens/ens-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/ens-resolver.polywrap.eth)", [ - "wrap://ens/ens-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/ens-resolver.polywrap.eth)", - [ - "wrap://ens/ens-resolver.polywrap.eth => Plugin (wrap://ens/ens-resolver.polywrap.eth) => package (wrap://ens/ens-resolver.polywrap.eth)" - ] + "wrap://ens/ens-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/ens-resolver.polywrap.eth) => package (wrap://ens/ens-resolver.polywrap.eth)" ] ], "wrap://ens/fs-resolver.polywrap.eth => PackageToWrapperCacheResolver => wrapper (wrap://ens/fs-resolver.polywrap.eth)", [ "wrap://ens/fs-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/fs-resolver.polywrap.eth)", [ - "wrap://ens/fs-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/fs-resolver.polywrap.eth)", - [ - "wrap://ens/fs-resolver.polywrap.eth => Plugin (wrap://ens/fs-resolver.polywrap.eth) => package (wrap://ens/fs-resolver.polywrap.eth)" - ] + "wrap://ens/fs-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/fs-resolver.polywrap.eth) => package (wrap://ens/fs-resolver.polywrap.eth)" ] ], "wrap://ens/http-resolver.polywrap.eth => PackageToWrapperCacheResolver => wrapper (wrap://ens/http-resolver.polywrap.eth)", [ "wrap://ens/http-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/http-resolver.polywrap.eth)", [ - "wrap://ens/http-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/http-resolver.polywrap.eth)", - [ - "wrap://ens/http-resolver.polywrap.eth => Plugin (wrap://ens/http-resolver.polywrap.eth) => package (wrap://ens/http-resolver.polywrap.eth)" - ] + "wrap://ens/http-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/http-resolver.polywrap.eth) => package (wrap://ens/http-resolver.polywrap.eth)" ] ], "wrap://ens/test.eth => ResolverExtension (wrap://ens/undefined-resolver.eth) => error While resolving wrap://ens/test.eth with URI resolver extension wrap://ens/undefined-resolver.eth, the extension could not be fully resolved. Last tried URI is wrap://ens/undefined-resolver.eth" diff --git a/packages/js/client/src/__tests__/core/uri-resolution/histories/restarts URI resolution after URI resolver extension redirect.json b/packages/js/client/src/__tests__/core/uri-resolution/histories/restarts URI resolution after URI resolver extension redirect.json index bb9353d938..a877388e87 100644 --- a/packages/js/client/src/__tests__/core/uri-resolution/histories/restarts URI resolution after URI resolver extension redirect.json +++ b/packages/js/client/src/__tests__/core/uri-resolution/histories/restarts URI resolution after URI resolver extension redirect.json @@ -9,40 +9,28 @@ [ "wrap://ens/ipfs-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/ipfs-resolver.polywrap.eth)", [ - "wrap://ens/ipfs-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/ipfs-resolver.polywrap.eth)", - [ - "wrap://ens/ipfs-resolver.polywrap.eth => Plugin (wrap://ens/ipfs-resolver.polywrap.eth) => package (wrap://ens/ipfs-resolver.polywrap.eth)" - ] + "wrap://ens/ipfs-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/ipfs-resolver.polywrap.eth) => package (wrap://ens/ipfs-resolver.polywrap.eth)" ] ], "wrap://ens/ens-resolver.polywrap.eth => PackageToWrapperCacheResolver => wrapper (wrap://ens/ens-resolver.polywrap.eth)", [ "wrap://ens/ens-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/ens-resolver.polywrap.eth)", [ - "wrap://ens/ens-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/ens-resolver.polywrap.eth)", - [ - "wrap://ens/ens-resolver.polywrap.eth => Plugin (wrap://ens/ens-resolver.polywrap.eth) => package (wrap://ens/ens-resolver.polywrap.eth)" - ] + "wrap://ens/ens-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/ens-resolver.polywrap.eth) => package (wrap://ens/ens-resolver.polywrap.eth)" ] ], "wrap://ens/fs-resolver.polywrap.eth => PackageToWrapperCacheResolver => wrapper (wrap://ens/fs-resolver.polywrap.eth)", [ "wrap://ens/fs-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/fs-resolver.polywrap.eth)", [ - "wrap://ens/fs-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/fs-resolver.polywrap.eth)", - [ - "wrap://ens/fs-resolver.polywrap.eth => Plugin (wrap://ens/fs-resolver.polywrap.eth) => package (wrap://ens/fs-resolver.polywrap.eth)" - ] + "wrap://ens/fs-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/fs-resolver.polywrap.eth) => package (wrap://ens/fs-resolver.polywrap.eth)" ] ], "wrap://ens/http-resolver.polywrap.eth => PackageToWrapperCacheResolver => wrapper (wrap://ens/http-resolver.polywrap.eth)", [ "wrap://ens/http-resolver.polywrap.eth => UriResolverAggregator => package (wrap://ens/http-resolver.polywrap.eth)", [ - "wrap://ens/http-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/http-resolver.polywrap.eth)", - [ - "wrap://ens/http-resolver.polywrap.eth => Plugin (wrap://ens/http-resolver.polywrap.eth) => package (wrap://ens/http-resolver.polywrap.eth)" - ] + "wrap://ens/http-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/http-resolver.polywrap.eth) => package (wrap://ens/http-resolver.polywrap.eth)" ] ], "wrap://file/$root-wrapper-dir/simple-fs-resolver/build => PackageToWrapperCacheResolver => wrapper (wrap://file/$root-wrapper-dir/simple-fs-resolver/build)", diff --git a/packages/js/client/src/__tests__/core/uri-resolution/histories/sanity.json b/packages/js/client/src/__tests__/core/uri-resolution/histories/sanity.json index 76c10c24b8..a57d0ec314 100644 --- a/packages/js/client/src/__tests__/core/uri-resolution/histories/sanity.json +++ b/packages/js/client/src/__tests__/core/uri-resolution/histories/sanity.json @@ -9,18 +9,7 @@ "wrap://ens/uri.eth => Redirect (wrap://ens/uts46.polywrap.eth - wrap://ens/goerli/uts46-lite.wrappers.eth)", "wrap://ens/uri.eth => Redirect (wrap://ens/graph-node.polywrap.eth - wrap://ens/goerli/graph-node.wrappers.eth)" ], - "wrap://ens/uri.eth => LegacyPluginsResolver", - [ - "wrap://ens/uri.eth => Plugin (wrap://ens/ipfs.polywrap.eth)", - "wrap://ens/uri.eth => Plugin (wrap://ens/ens-resolver.polywrap.eth)", - "wrap://ens/uri.eth => Plugin (wrap://ens/ethereum.polywrap.eth)", - "wrap://ens/uri.eth => Plugin (wrap://ens/http.polywrap.eth)", - "wrap://ens/uri.eth => Plugin (wrap://ens/http-resolver.polywrap.eth)", - "wrap://ens/uri.eth => Plugin (wrap://ens/js-logger.polywrap.eth)", - "wrap://ens/uri.eth => Plugin (wrap://ens/fs.polywrap.eth)", - "wrap://ens/uri.eth => Plugin (wrap://ens/fs-resolver.polywrap.eth)", - "wrap://ens/uri.eth => Plugin (wrap://ens/ipfs-resolver.polywrap.eth)" - ], + "wrap://ens/uri.eth => StaticResolver - Miss", "wrap://ens/uri.eth => ExtendableUriResolver", [ "wrap://ens/ipfs-resolver.polywrap.eth => PackageToWrapperCacheResolver => wrapper (wrap://ens/ipfs-resolver.polywrap.eth)", @@ -33,18 +22,7 @@ "wrap://ens/ipfs-resolver.polywrap.eth => Redirect (wrap://ens/uts46.polywrap.eth - wrap://ens/goerli/uts46-lite.wrappers.eth)", "wrap://ens/ipfs-resolver.polywrap.eth => Redirect (wrap://ens/graph-node.polywrap.eth - wrap://ens/goerli/graph-node.wrappers.eth)" ], - "wrap://ens/ipfs-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/ipfs-resolver.polywrap.eth)", - [ - "wrap://ens/ipfs-resolver.polywrap.eth => Plugin (wrap://ens/ipfs.polywrap.eth)", - "wrap://ens/ipfs-resolver.polywrap.eth => Plugin (wrap://ens/ens-resolver.polywrap.eth)", - "wrap://ens/ipfs-resolver.polywrap.eth => Plugin (wrap://ens/ethereum.polywrap.eth)", - "wrap://ens/ipfs-resolver.polywrap.eth => Plugin (wrap://ens/http.polywrap.eth)", - "wrap://ens/ipfs-resolver.polywrap.eth => Plugin (wrap://ens/http-resolver.polywrap.eth)", - "wrap://ens/ipfs-resolver.polywrap.eth => Plugin (wrap://ens/js-logger.polywrap.eth)", - "wrap://ens/ipfs-resolver.polywrap.eth => Plugin (wrap://ens/fs.polywrap.eth)", - "wrap://ens/ipfs-resolver.polywrap.eth => Plugin (wrap://ens/fs-resolver.polywrap.eth)", - "wrap://ens/ipfs-resolver.polywrap.eth => Plugin (wrap://ens/ipfs-resolver.polywrap.eth) => package (wrap://ens/ipfs-resolver.polywrap.eth)" - ] + "wrap://ens/ipfs-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/ipfs-resolver.polywrap.eth) => package (wrap://ens/ipfs-resolver.polywrap.eth)" ] ], "wrap://ens/uri.eth => ResolverExtension (wrap://ens/ipfs-resolver.polywrap.eth)", @@ -58,11 +36,7 @@ "wrap://ens/ens-resolver.polywrap.eth => Redirect (wrap://ens/uts46.polywrap.eth - wrap://ens/goerli/uts46-lite.wrappers.eth)", "wrap://ens/ens-resolver.polywrap.eth => Redirect (wrap://ens/graph-node.polywrap.eth - wrap://ens/goerli/graph-node.wrappers.eth)" ], - "wrap://ens/ens-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/ens-resolver.polywrap.eth)", - [ - "wrap://ens/ens-resolver.polywrap.eth => Plugin (wrap://ens/ipfs.polywrap.eth)", - "wrap://ens/ens-resolver.polywrap.eth => Plugin (wrap://ens/ens-resolver.polywrap.eth) => package (wrap://ens/ens-resolver.polywrap.eth)" - ] + "wrap://ens/ens-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/ens-resolver.polywrap.eth) => package (wrap://ens/ens-resolver.polywrap.eth)" ] ], "wrap://ens/uri.eth => ResolverExtension (wrap://ens/ens-resolver.polywrap.eth)", @@ -76,17 +50,7 @@ "wrap://ens/fs-resolver.polywrap.eth => Redirect (wrap://ens/uts46.polywrap.eth - wrap://ens/goerli/uts46-lite.wrappers.eth)", "wrap://ens/fs-resolver.polywrap.eth => Redirect (wrap://ens/graph-node.polywrap.eth - wrap://ens/goerli/graph-node.wrappers.eth)" ], - "wrap://ens/fs-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/fs-resolver.polywrap.eth)", - [ - "wrap://ens/fs-resolver.polywrap.eth => Plugin (wrap://ens/ipfs.polywrap.eth)", - "wrap://ens/fs-resolver.polywrap.eth => Plugin (wrap://ens/ens-resolver.polywrap.eth)", - "wrap://ens/fs-resolver.polywrap.eth => Plugin (wrap://ens/ethereum.polywrap.eth)", - "wrap://ens/fs-resolver.polywrap.eth => Plugin (wrap://ens/http.polywrap.eth)", - "wrap://ens/fs-resolver.polywrap.eth => Plugin (wrap://ens/http-resolver.polywrap.eth)", - "wrap://ens/fs-resolver.polywrap.eth => Plugin (wrap://ens/js-logger.polywrap.eth)", - "wrap://ens/fs-resolver.polywrap.eth => Plugin (wrap://ens/fs.polywrap.eth)", - "wrap://ens/fs-resolver.polywrap.eth => Plugin (wrap://ens/fs-resolver.polywrap.eth) => package (wrap://ens/fs-resolver.polywrap.eth)" - ] + "wrap://ens/fs-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/fs-resolver.polywrap.eth) => package (wrap://ens/fs-resolver.polywrap.eth)" ] ], "wrap://ens/uri.eth => ResolverExtension (wrap://ens/fs-resolver.polywrap.eth)", @@ -100,18 +64,11 @@ "wrap://ens/http-resolver.polywrap.eth => Redirect (wrap://ens/uts46.polywrap.eth - wrap://ens/goerli/uts46-lite.wrappers.eth)", "wrap://ens/http-resolver.polywrap.eth => Redirect (wrap://ens/graph-node.polywrap.eth - wrap://ens/goerli/graph-node.wrappers.eth)" ], - "wrap://ens/http-resolver.polywrap.eth => LegacyPluginsResolver => package (wrap://ens/http-resolver.polywrap.eth)", - [ - "wrap://ens/http-resolver.polywrap.eth => Plugin (wrap://ens/ipfs.polywrap.eth)", - "wrap://ens/http-resolver.polywrap.eth => Plugin (wrap://ens/ens-resolver.polywrap.eth)", - "wrap://ens/http-resolver.polywrap.eth => Plugin (wrap://ens/ethereum.polywrap.eth)", - "wrap://ens/http-resolver.polywrap.eth => Plugin (wrap://ens/http.polywrap.eth)", - "wrap://ens/http-resolver.polywrap.eth => Plugin (wrap://ens/http-resolver.polywrap.eth) => package (wrap://ens/http-resolver.polywrap.eth)" - ] + "wrap://ens/http-resolver.polywrap.eth => StaticResolver - Package (wrap://ens/http-resolver.polywrap.eth) => package (wrap://ens/http-resolver.polywrap.eth)" ] ], "wrap://ens/uri.eth => ResolverExtension (wrap://ens/http-resolver.polywrap.eth)" ] ] ] -] \ No newline at end of file +] diff --git a/packages/js/client/src/__tests__/core/uri-resolution/uri-resolution.spec.ts b/packages/js/client/src/__tests__/core/uri-resolution/uri-resolution.spec.ts index e99d68aaff..40ecb6a404 100644 --- a/packages/js/client/src/__tests__/core/uri-resolution/uri-resolution.spec.ts +++ b/packages/js/client/src/__tests__/core/uri-resolution/uri-resolution.spec.ts @@ -4,16 +4,19 @@ import { Uri, coreInterfaceUris, IUriResolutionStep, - PluginModule, UriPackageOrWrapper, UriResolutionContext, - UriResolutionResult, } from "@polywrap/core-js"; -import { buildCleanUriHistory, getUriResolutionPath } from "@polywrap/uri-resolvers-js"; -import { getClient } from "../../utils/getClient"; +import { + buildCleanUriHistory, + UriResolver, + getUriResolutionPath, + UriResolutionResult, +} from "@polywrap/uri-resolvers-js"; import fs from "fs"; -import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; import { Result } from "@polywrap/result"; +import { mockPluginRegistration } from "../../helpers/mockPluginRegistration"; +import { PolywrapClient } from "../../../PolywrapClient"; jest.setTimeout(200000); @@ -39,7 +42,7 @@ const expectResultWithHistory = async ( if (historyFileName && uriHistory) { await expectHistory(uriHistory, historyFileName); } - + expect(receivedResult).toEqual(expectedResult); }; @@ -112,7 +115,7 @@ describe("URI resolution", () => { it("sanity", async () => { const uri = new Uri("ens/uri.eth"); - const client = await getClient(); + const client = new PolywrapClient(); const resolutionContext = new UriResolutionContext(); const result = await client.tryResolveUri({ uri, resolutionContext }); @@ -130,7 +133,7 @@ describe("URI resolution", () => { const toUri1 = new Uri("ens/to1.eth"); const toUri2 = new Uri("ens/to2.eth"); - const client = await getClient({ + const client = new PolywrapClient({ redirects: [ { from: fromUri.uri, @@ -144,7 +147,10 @@ describe("URI resolution", () => { }); const resolutionContext = new UriResolutionContext(); - const response = await client.tryResolveUri({ uri: fromUri, resolutionContext }); + const response = await client.tryResolveUri({ + uri: fromUri, + resolutionContext, + }); await expectResultWithHistory( response, @@ -153,47 +159,40 @@ describe("URI resolution", () => { "can resolve redirects" ); - expect([ + expect(resolutionContext.getResolutionPath().map((x) => x.uri)).toEqual([ "wrap://ens/from.eth", "wrap://ens/to1.eth", - "wrap://ens/to2.eth" - ]).toEqual(resolutionContext.getResolutionPath().map(x => x.uri)); + "wrap://ens/to2.eth", + ]); }); it("can resolve plugin", async () => { const pluginUri = new Uri("ens/plugin.eth"); - const client = await getClient({ - plugins: [ - { - uri: pluginUri.uri, - plugin: { - factory: () => { - return ({} as unknown) as PluginModule<{}>; - }, - manifest: { } as WrapManifest, - }, - }, - ], + const client = new PolywrapClient({ + resolvers: [UriResolver.from(mockPluginRegistration(pluginUri))], }); const resolutionContext = new UriResolutionContext(); - const result = await client.tryResolveUri({ uri: pluginUri, resolutionContext }); + const result = await client.tryResolveUri({ + uri: pluginUri, + resolutionContext, + }); await expectWrapperWithHistory( - result, - pluginUri, - getUriResolutionPath(resolutionContext.getHistory()), + result, + pluginUri, + getUriResolutionPath(resolutionContext.getHistory()), "can resolve plugin" ); - expect([ - "wrap://ens/plugin.eth" - ]).toEqual(resolutionContext.getResolutionPath().map(x => x.uri)); + expect(["wrap://ens/plugin.eth"]).toEqual( + resolutionContext.getResolutionPath().map((x) => x.uri) + ); }); it("can resolve a URI resolver extension wrapper", async () => { - const client = await getClient({ + const client = new PolywrapClient({ interfaces: [ { interface: coreInterfaceUris.uriResolver.uri, @@ -206,7 +205,10 @@ describe("URI resolution", () => { const redirectedUri = wrapperUri; const resolutionContext = new UriResolutionContext(); - const response = await client.tryResolveUri({ uri: sourceUri, resolutionContext }); + const response = await client.tryResolveUri({ + uri: sourceUri, + resolutionContext, + }); await expectWrapperWithHistory( response, @@ -215,17 +217,19 @@ describe("URI resolution", () => { "can resolve a URI resolver extension wrapper" ); - expect([ - sourceUri.uri, - redirectedUri.uri, - ]).toEqual(resolutionContext.getResolutionPath().map(x => x.uri)); + expect([sourceUri.uri, redirectedUri.uri]).toEqual( + resolutionContext.getResolutionPath().map((x) => x.uri) + ); }); it("can resolve cache", async () => { - const client = await getClient(); + const client = new PolywrapClient(); const resolutionContext1 = new UriResolutionContext(); - const result1 = await client.tryResolveUri({ uri: wrapperUri, resolutionContext: resolutionContext1 }); + const result1 = await client.tryResolveUri({ + uri: wrapperUri, + resolutionContext: resolutionContext1, + }); await expectWrapperWithHistory( result1, @@ -233,12 +237,15 @@ describe("URI resolution", () => { getUriResolutionPath(resolutionContext1.getHistory()), "can resolve cache - 1" ); - expect([ - wrapperUri.uri, - ]).toEqual(resolutionContext1.getResolutionPath().map(x => x.uri)); + expect([wrapperUri.uri]).toEqual( + resolutionContext1.getResolutionPath().map((x) => x.uri) + ); const resolutionContext2 = new UriResolutionContext(); - const result2 = await client.tryResolveUri({ uri: wrapperUri, resolutionContext: resolutionContext2 }); + const result2 = await client.tryResolveUri({ + uri: wrapperUri, + resolutionContext: resolutionContext2, + }); await expectWrapperWithHistory( result2, @@ -246,13 +253,13 @@ describe("URI resolution", () => { getUriResolutionPath(resolutionContext2.getHistory()), "can resolve cache - 2" ); - expect([ - wrapperUri.uri, - ]).toEqual(resolutionContext2.getResolutionPath().map(x => x.uri)); + expect([wrapperUri.uri]).toEqual( + resolutionContext2.getResolutionPath().map((x) => x.uri) + ); }); it("can resolve previously cached URI after redirecting by a URI resolver extension", async () => { - const client = await getClient({ + const client = new PolywrapClient({ interfaces: [ { interface: coreInterfaceUris.uriResolver.uri, @@ -269,7 +276,10 @@ describe("URI resolution", () => { const finalUri = wrapperUri; const resolutionContext1 = new UriResolutionContext(); - const result1 = await client.tryResolveUri({ uri: redirectedUri, resolutionContext: resolutionContext1 }); + const result1 = await client.tryResolveUri({ + uri: redirectedUri, + resolutionContext: resolutionContext1, + }); await expectWrapperWithHistory( result1, @@ -277,13 +287,15 @@ describe("URI resolution", () => { getUriResolutionPath(resolutionContext1.getHistory()), "can resolve previously cached URI after redirecting by a URI resolver extension - 1" ); - expect([ - redirectedUri.uri, - finalUri.uri - ]).toEqual(resolutionContext1.getResolutionPath().map(x => x.uri)); + expect([redirectedUri.uri, finalUri.uri]).toEqual( + resolutionContext1.getResolutionPath().map((x) => x.uri) + ); const resolutionContext2 = new UriResolutionContext(); - const result2 = await client.tryResolveUri({ uri: sourceUri, resolutionContext: resolutionContext2 }); + const result2 = await client.tryResolveUri({ + uri: sourceUri, + resolutionContext: resolutionContext2, + }); await expectWrapperWithHistory( result2, @@ -291,10 +303,9 @@ describe("URI resolution", () => { getUriResolutionPath(resolutionContext2.getHistory()), "can resolve previously cached URI after redirecting by a URI resolver extension - 2" ); - expect([ - sourceUri.uri, - redirectedUri.uri, - ]).toEqual(resolutionContext2.getResolutionPath().map(x => x.uri)); + expect([sourceUri.uri, redirectedUri.uri]).toEqual( + resolutionContext2.getResolutionPath().map((x) => x.uri) + ); }); it("restarts URI resolution after URI resolver extension redirect", async () => { @@ -302,7 +313,7 @@ describe("URI resolution", () => { const sourceUri = new Uri(`simple-redirect/${wrapperPath}/build`); const resolverRedirectUri = new Uri(`simple/${wrapperPath}/build`); const finalRedirectedUri = new Uri(`ens/redirect.eth`); - const client = await getClient({ + const client = new PolywrapClient({ redirects: [ { from: resolverRedirectUri.uri, @@ -319,9 +330,12 @@ describe("URI resolution", () => { }, ], }); - + const resolutionContext = new UriResolutionContext(); - const result = await client.tryResolveUri({ uri: sourceUri, resolutionContext }); + const result = await client.tryResolveUri({ + uri: sourceUri, + resolutionContext, + }); await expectResultWithHistory( result, UriResolutionResult.ok(finalRedirectedUri), @@ -332,23 +346,25 @@ describe("URI resolution", () => { sourceUri.uri, resolverRedirectUri.uri, finalRedirectedUri.uri, - ]).toEqual(resolutionContext.getResolutionPath().map(x => x.uri)); + ]).toEqual(resolutionContext.getResolutionPath().map((x) => x.uri)); }); it("can resolve uri with custom resolver", async () => { const ensUri = new Uri(`ens/test`); const redirectUri = new Uri(`ens/redirect.eth`); - const client = await getClient({ - resolver: { - tryResolveUri: async (uri: Uri) => { - if (uri.uri === ensUri.uri) { - return UriResolutionResult.ok(redirectUri); - } + const client = new PolywrapClient({ + resolvers: [ + { + tryResolveUri: async (uri: Uri) => { + if (uri.uri === ensUri.uri) { + return UriResolutionResult.ok(redirectUri); + } - return UriResolutionResult.ok(uri); + return UriResolutionResult.ok(uri); + }, }, - }, + ], }); const result = await client.tryResolveUri({ uri: ensUri }); @@ -360,27 +376,29 @@ describe("URI resolution", () => { const fromUri = new Uri(`ens/from.eth`); const redirectUri = new Uri(`ens/to.eth`); - const client = await getClient({ - resolver: { - tryResolveUri: async (uri: Uri) => { - if (uri.uri === fromUri.uri) { - return UriResolutionResult.ok(redirectUri); - } + const client = new PolywrapClient({ + resolvers: [ + { + tryResolveUri: async (uri: Uri) => { + if (uri.uri === fromUri.uri) { + return UriResolutionResult.ok(redirectUri); + } - return UriResolutionResult.ok(uri); + return UriResolutionResult.ok(uri); + }, }, - }, + ], }); const result = await client.tryResolveUri({ - uri: fromUri + uri: fromUri, }); expect(result).toEqual(UriResolutionResult.ok(redirectUri)); }); it("custom wrapper resolver does not cause infinite recursion when resolved at runtime", async () => { - const client = await getClient({ + const client = new PolywrapClient({ interfaces: [ { interface: coreInterfaceUris.uriResolver.uri, @@ -390,7 +408,10 @@ describe("URI resolution", () => { }); const resolutionContext = new UriResolutionContext(); - const result = await client.tryResolveUri({ uri: "ens/test.eth", resolutionContext }); + const result = await client.tryResolveUri({ + uri: "ens/test.eth", + resolutionContext, + }); await expectResultWithHistory( result, @@ -401,8 +422,8 @@ describe("URI resolution", () => { "custom wrapper resolver does not cause infinite recursion when resolved at runtime" ); - expect([ - "wrap://ens/test.eth" - ]).toEqual(resolutionContext.getResolutionPath().map(x => x.uri)); + expect(["wrap://ens/test.eth"]).toEqual( + resolutionContext.getResolutionPath().map((x) => x.uri) + ); }); }); diff --git a/packages/js/client/src/__tests__/core/wasm-wrapper.spec.ts b/packages/js/client/src/__tests__/core/wasm-wrapper.spec.ts index 38a12215ca..faeefb88ac 100644 --- a/packages/js/client/src/__tests__/core/wasm-wrapper.spec.ts +++ b/packages/js/client/src/__tests__/core/wasm-wrapper.spec.ts @@ -2,12 +2,14 @@ import { buildWrapper } from "@polywrap/test-env-js"; import { msgpackDecode } from "@polywrap/msgpack-js"; import { GetPathToTestWrappers } from "@polywrap/test-cases"; import fs from "fs"; -import { Uri, PluginModule, Subscription, PolywrapClient } from "../.."; +import { Uri, Subscription, PolywrapClient, IWrapPackage } from "../.."; import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; -import { getClient } from "../utils/getClient"; import { makeMemoryStoragePlugin } from "../e2e/memory-storage"; +import { PluginModule, PluginPackage } from "@polywrap/plugin-js"; +import { UriResolver } from "@polywrap/uri-resolvers-js"; import { ErrResult } from "../utils/resultTypes"; import { ClientConfigBuilder } from "@polywrap/client-config-builder-js"; +import { mockPluginRegistration } from "../helpers/mockPluginRegistration"; jest.setTimeout(200000); @@ -25,21 +27,18 @@ describe("wasm-wrapper", () => { await buildWrapper(simpleMemoryWrapperPath); }); - const mockPlugin = () => { + const mockPlugin = (): IWrapPackage => { class MockPlugin extends PluginModule<{}> { simpleMethod(_: unknown): string { return "plugin response"; } } - return { - factory: () => new MockPlugin({}), - manifest: {} as WrapManifest, - }; + return new PluginPackage(new MockPlugin({}), {} as WrapManifest); }; test("can invoke with string URI", async () => { - const client = await getClient(); + const client = new PolywrapClient(); const result = await client.invoke({ uri: simpleWrapperUri.uri, method: "simpleMethod", @@ -55,7 +54,7 @@ describe("wasm-wrapper", () => { }); test("can invoke with typed URI", async () => { - const client = await getClient(); + const client = new PolywrapClient(); const result = await client.invoke({ uri: simpleWrapperUri, method: "simpleMethod", @@ -71,7 +70,7 @@ describe("wasm-wrapper", () => { }); test("invoke with decode defaulted to true works as expected", async () => { - const client = await getClient(); + const client = new PolywrapClient(); const result = await client.invoke({ uri: simpleWrapperUri.uri, method: "simpleMethod", @@ -87,7 +86,7 @@ describe("wasm-wrapper", () => { }); test("invoke with decode set to false works as expected", async () => { - const client = await getClient(); + const client = new PolywrapClient(); const result = await client.invoke({ uri: simpleWrapperUri, method: "simpleMethod", @@ -104,17 +103,17 @@ describe("wasm-wrapper", () => { }); it("should invoke wrapper with custom redirects", async () => { - const client = await getClient({ + const client = new PolywrapClient({ redirects: [ { from: simpleWrapperUri.uri, to: "wrap://ens/mock.polywrap.eth", }, ], - plugins: [ + resolvers: [ { uri: "wrap://ens/mock.polywrap.eth", - plugin: mockPlugin(), + package: mockPlugin(), }, ], }); @@ -133,15 +132,29 @@ describe("wasm-wrapper", () => { }); it("should allow clone + reconfigure of redirects", async () => { - const client = await getClient({ - plugins: [ + let builder = new ClientConfigBuilder().add({ + packages: [ { uri: "wrap://ens/mock.polywrap.eth", - plugin: mockPlugin(), + package: mockPlugin(), }, ], }); + const client = new PolywrapClient(builder.build()); + + const clientResult = await client.invoke({ + uri: simpleWrapperUri.uri, + method: "simpleMethod", + args: { + arg: "test", + }, + }); + + if (!clientResult.ok) fail(clientResult.error); + expect(clientResult.value).toBeTruthy(); + expect(clientResult.value).toEqual("test"); + const redirects = [ { from: simpleWrapperUri.uri, @@ -149,41 +162,33 @@ describe("wasm-wrapper", () => { }, ]; - const newConfig = new ClientConfigBuilder() - .add(client.getConfig()) - .add({ redirects }) - .build(); + builder = builder.add({ redirects }); - const newClient = new PolywrapClient( - newConfig - ); + const newClient = new PolywrapClient(builder.build()); - const result = await newClient.invoke({ + const newClientResult = await newClient.invoke({ uri: simpleWrapperUri.uri, method: "simpleMethod", args: { arg: "test", - } + }, }); - if (!result.ok) fail(result.error); - expect(result.value).toBeTruthy(); - expect(result.value).toEqual("plugin response"); + if (!newClientResult.ok) fail(newClientResult.error); + expect(newClientResult.value).toBeTruthy(); + expect(newClientResult.value).toEqual("plugin response"); }); test("get file from wrapper", async () => { - const client = await getClient(); + const client = new PolywrapClient(); const expectedManifest = new Uint8Array( await fs.promises.readFile(`${simpleWrapperPath}/build/wrap.info`) ); - const receivedManifestResult = await client.getFile( - simpleWrapperUri, - { - path: "./wrap.info", - } - ); + const receivedManifestResult = await client.getFile(simpleWrapperUri, { + path: "./wrap.info", + }); if (!receivedManifestResult.ok) fail(receivedManifestResult.error); const receivedManifest = receivedManifestResult.value as Uint8Array; @@ -193,43 +198,44 @@ describe("wasm-wrapper", () => { await fs.promises.readFile(`${simpleWrapperPath}/build/wrap.wasm`) ); - const receivedWasmModuleResult = await client.getFile( - simpleWrapperUri, - { - path: "./wrap.wasm", - } - ); + const receivedWasmModuleResult = await client.getFile(simpleWrapperUri, { + path: "./wrap.wasm", + }); if (!receivedWasmModuleResult.ok) fail(receivedWasmModuleResult.error); const receivedWasmModule = receivedWasmModuleResult.value as Uint8Array; expect(receivedWasmModule).toEqual(expectedWasmModule); - const pluginClient = await getClient({ - plugins: [ - { - uri: "ens/mock-plugin.eth", - plugin: { - factory: () => ({} as PluginModule<{}>), - manifest: {} as WrapManifest - }, - }, - ], - }); + const pluginClient = new PolywrapClient( + { + resolver: UriResolver.from([ + mockPluginRegistration("ens/mock-plugin.eth"), + ]), + }, + { + noDefaults: true, + } + ); - let pluginGetFileResult = await pluginClient.getFile("ens/mock-plugin.eth", { - path: "./index.js", - }); + let pluginGetFileResult = await pluginClient.getFile( + "ens/mock-plugin.eth", + { + path: "./index.js", + } + ); pluginGetFileResult = pluginGetFileResult as ErrResult; - expect(pluginGetFileResult.error?.message).toContain("client.getFile(...) is not implemented for Plugins."); + expect(pluginGetFileResult.error?.message).toContain( + "client.getFile(...) is not implemented for Plugins." + ); }); test("subscribe", async () => { - const client = await getClient({ - plugins: [ + const client = new PolywrapClient({ + resolvers: [ { uri: memoryStoragePluginUri, - plugin: makeMemoryStoragePlugin({}), + package: makeMemoryStoragePlugin({}), }, ], }); @@ -274,11 +280,11 @@ describe("wasm-wrapper", () => { }); test("subscription early stop", async () => { - const client = await getClient({ - plugins: [ + const client = new PolywrapClient({ + resolvers: [ { uri: memoryStoragePluginUri, - plugin: makeMemoryStoragePlugin({}), + package: makeMemoryStoragePlugin({}), }, ], }); diff --git a/packages/js/client/src/__tests__/e2e/env.spec.ts b/packages/js/client/src/__tests__/e2e/env.spec.ts index b94e992049..e0fdfb7419 100644 --- a/packages/js/client/src/__tests__/e2e/env.spec.ts +++ b/packages/js/client/src/__tests__/e2e/env.spec.ts @@ -1,48 +1,83 @@ -import { PluginModule } from "@polywrap/core-js"; +import { PluginModule, PluginPackage } from "@polywrap/plugin-js"; +import { RecursiveResolver } from "@polywrap/uri-resolvers-js"; import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; -import { getClient } from "../utils/getClient"; +import { PolywrapClient } from "../../PolywrapClient"; jest.setTimeout(200000); +interface MockEnv extends Record { + arg1: number; +} + describe("env", () => { const mockEnvPlugin = () => { - interface Env extends Record { - arg1: number; - } - - class MockEnvPlugin extends PluginModule<{}, Env> { - mockEnv(): Env { + class MockEnvPlugin extends PluginModule<{}, MockEnv> { + mockEnv(): MockEnv { return this.env; } } - return { - factory: () => new MockEnvPlugin({}), - manifest: {} as WrapManifest, - }; + return new PluginPackage(new MockEnvPlugin({}), {} as WrapManifest); }; describe("env client types", () => { test("plugin env types", async () => { const implementationUri = "wrap://ens/some-implementation.eth"; const envPlugin = mockEnvPlugin(); - const client = await getClient({ - plugins: [ - { + const client = new PolywrapClient( + { + resolver: RecursiveResolver.from({ uri: implementationUri, - plugin: envPlugin, - }, - ], - envs: [ - { - uri: implementationUri, - env: { - arg1: "10", + package: envPlugin, + }), + envs: [ + { + uri: implementationUri, + env: { + arg1: "10", + }, }, - }, - ], + ], + }, + { noDefaults: true } + ); + + const mockEnv = await client.invoke({ + uri: implementationUri, + method: "mockEnv", }); + if (!mockEnv.ok) fail(mockEnv.error); + expect(mockEnv.value).toBeTruthy(); + expect(mockEnv.value).toMatchObject({ arg1: "10" }); + }); + + test("inline plugin env types", async () => { + const implementationUri = "wrap://ens/some-implementation.eth"; + const client = new PolywrapClient( + { + resolver: RecursiveResolver.from([ + { + uri: implementationUri, + package: PluginPackage.from((module) => ({ + mockEnv: (): MockEnv => { + return module.env; + }, + })), + }, + ]), + envs: [ + { + uri: implementationUri, + env: { + arg1: "10", + }, + }, + ], + }, + { noDefaults: true } + ); + const mockEnv = await client.invoke({ uri: implementationUri, method: "mockEnv", diff --git a/packages/js/client/src/__tests__/e2e/memory-storage.ts b/packages/js/client/src/__tests__/e2e/memory-storage.ts index 11130cce3e..0e09637aed 100644 --- a/packages/js/client/src/__tests__/e2e/memory-storage.ts +++ b/packages/js/client/src/__tests__/e2e/memory-storage.ts @@ -1,4 +1,9 @@ -import { Client, PluginFactory, PluginModule } from "@polywrap/core-js"; +import { CoreClient } from "@polywrap/core-js"; +import { + PluginFactory, + PluginModule, + PluginPackage, +} from "@polywrap/plugin-js"; import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; type NoConfig = Record; @@ -10,22 +15,21 @@ function sleep(ms: number) { export const makeMemoryStoragePlugin: PluginFactory = () => { class MemoryStoragePlugin extends PluginModule { private _value: number; - - async getData(_: {}, _client: Client): Promise { + + async getData(_: {}, _client: CoreClient): Promise { await sleep(50); return this._value; } - - async setData(args: { value: number }, _client: Client): Promise { + + async setData( + args: { value: number }, + _client: CoreClient + ): Promise { await sleep(50); this._value = args.value; return true; } } - return { - factory: () => new MemoryStoragePlugin({}), - manifest: {} as WrapManifest, - }; + return new PluginPackage(new MemoryStoragePlugin({}), {} as WrapManifest); }; - diff --git a/packages/js/client/src/__tests__/e2e/test-cases.ts b/packages/js/client/src/__tests__/e2e/test-cases.ts index d7af081736..696f29f388 100644 --- a/packages/js/client/src/__tests__/e2e/test-cases.ts +++ b/packages/js/client/src/__tests__/e2e/test-cases.ts @@ -1,9 +1,9 @@ -import { PolywrapClient, Uri } from "../../"; +import { CoreClient, Uri } from "../../"; import { BigNumber } from "bignumber.js"; import { ErrResult } from "../utils/resultTypes"; export const runAsyncifyTest = async ( - client: PolywrapClient, + client: CoreClient, wrapperUri: string ) => { const subsequentInvokes = await client.invoke({ @@ -112,15 +112,13 @@ export const runAsyncifyTest = async ( }, }); - if (!setDataWithManyStructuredArgs.ok) fail(setDataWithManyStructuredArgs.error); + if (!setDataWithManyStructuredArgs.ok) + fail(setDataWithManyStructuredArgs.error); expect(setDataWithManyStructuredArgs.value).toBeTruthy(); expect(setDataWithManyStructuredArgs.value).toBe(true); }; -export const runBigIntTypeTest = async ( - client: PolywrapClient, - uri: string -) => { +export const runBigIntTypeTest = async (client: CoreClient, uri: string) => { { const response = await client.invoke({ uri, @@ -166,10 +164,7 @@ export const runBigIntTypeTest = async ( } }; -export const runBigNumberTypeTest = async ( - client: PolywrapClient, - uri: string -) => { +export const runBigNumberTypeTest = async (client: CoreClient, uri: string) => { { const response = await client.invoke({ uri, @@ -217,7 +212,7 @@ export const runBigNumberTypeTest = async ( } }; -export const runBytesTypeTest = async (client: PolywrapClient, uri: string) => { +export const runBytesTypeTest = async (client: CoreClient, uri: string) => { const response = await client.invoke({ uri, method: "bytesMethod", @@ -235,7 +230,7 @@ export const runBytesTypeTest = async (client: PolywrapClient, uri: string) => { ); }; -export const runEnumTypesTest = async (client: PolywrapClient, uri: string) => { +export const runEnumTypesTest = async (client: CoreClient, uri: string) => { let method1a = await client.invoke({ uri, method: "method1", @@ -292,11 +287,13 @@ export const runEnumTypesTest = async (client: PolywrapClient, uri: string) => { }; export const runImplementationsTest = async ( - client: PolywrapClient, + client: CoreClient, interfaceUri: string, implementationUri: string ) => { - const implResult = client.getImplementations(interfaceUri); + const implResult = client.getImplementations(interfaceUri, { + applyRedirects: false, + }); if (!implResult.ok) fail(implResult.error); expect(implResult.value).toEqual([new Uri(implementationUri).uri]); @@ -322,7 +319,10 @@ export const runImplementationsTest = async ( }), ]); - const okResults = results.filter((x) => x.ok) as { ok: true, value: unknown }[]; + const okResults = results.filter((x) => x.ok) as { + ok: true; + value: unknown; + }[]; expect(okResults.length).toEqual(results.length); expect(okResults[0].value).toEqual({ uint8: 1, @@ -332,13 +332,15 @@ export const runImplementationsTest = async ( }; export const runGetImplementationsTest = async ( - client: PolywrapClient, + client: CoreClient, aggregatorUri: string, interfaceUri: string, implementationUri: string ) => { let implUri = new Uri(implementationUri); - const implResult = client.getImplementations(interfaceUri); + const implResult = client.getImplementations(interfaceUri, { + applyRedirects: false, + }); if (!implResult.ok) fail(implResult.error); expect(implResult.value).toEqual([implUri.uri]); @@ -364,10 +366,7 @@ export const runGetImplementationsTest = async ( expect(moduleMethodResult.value).toEqual("Test String 2"); }; -export const runInvalidTypesTest = async ( - client: PolywrapClient, - uri: string -) => { +export const runInvalidTypesTest = async (client: CoreClient, uri: string) => { let invalidBoolIntSent = await client.invoke({ uri, method: "boolMethod", @@ -375,7 +374,7 @@ export const runInvalidTypesTest = async ( arg: 10, }, }); - invalidBoolIntSent = invalidBoolIntSent as { ok: false, error: Error }; + invalidBoolIntSent = invalidBoolIntSent as { ok: false; error: Error }; expect(invalidBoolIntSent.error).toBeTruthy(); expect(invalidBoolIntSent.error?.message).toMatch( /Property must be of type 'bool'. Found 'int'./ @@ -438,7 +437,11 @@ export const runInvalidTypesTest = async ( ); }; -export const runJsonTypeTest = async (client: PolywrapClient, uri: string, testReserved: boolean = false) => { +export const runJsonTypeTest = async ( + client: CoreClient, + uri: string, + testReserved: boolean = false +) => { type Json = string; const value = JSON.stringify({ foo: "bar", bar: "bar" }); const parseResponse = await client.invoke({ @@ -465,7 +468,7 @@ export const runJsonTypeTest = async (client: PolywrapClient, uri: string, testR }, }); - if(!stringifyResponse.ok) fail(stringifyResponse.error); + if (!stringifyResponse.ok) fail(stringifyResponse.error); expect(stringifyResponse.value).toEqual(values.join("")); const object = { @@ -502,22 +505,25 @@ export const runJsonTypeTest = async (client: PolywrapClient, uri: string, testR if (testReserved) { const reserved = { const: "hello", if: true }; - const parseReservedResponse = await client.invoke<{ const: string; if: boolean }>({ + const parseReservedResponse = await client.invoke<{ + const: string; + if: boolean; + }>({ uri, method: "parseReserved", args: { - json: JSON.stringify(reserved) + json: JSON.stringify(reserved), }, }); if (!parseReservedResponse.ok) fail(parseReservedResponse.error); expect(parseReservedResponse.value).toEqual(reserved); - + const stringifyReservedResponse = await client.invoke({ uri, method: "stringifyReserved", args: { - reserved + reserved, }, }); @@ -526,10 +532,7 @@ export const runJsonTypeTest = async (client: PolywrapClient, uri: string, testR } }; -export const runLargeTypesTest = async ( - client: PolywrapClient, - uri: string -) => { +export const runLargeTypesTest = async (client: CoreClient, uri: string) => { const largeStr = new Array(5000).join("polywrap "); const largeBytes = new Uint8Array(Buffer.from(largeStr)); const largeStrArray = []; @@ -563,10 +566,7 @@ export const runLargeTypesTest = async ( }); }; -export const runNumberTypesTest = async ( - client: PolywrapClient, - uri: string -) => { +export const runNumberTypesTest = async (client: CoreClient, uri: string) => { let i8Underflow = await client.invoke({ uri, method: "i8Method", @@ -653,10 +653,7 @@ export const runNumberTypesTest = async ( ); }; -export const runObjectTypesTest = async ( - client: PolywrapClient, - uri: string -) => { +export const runObjectTypesTest = async (client: CoreClient, uri: string) => { const method1a = await client.invoke({ uri, method: "method1", @@ -806,7 +803,7 @@ export const runObjectTypesTest = async ( }); }; -export const runMapTypeTest = async (client: PolywrapClient, uri: string) => { +export const runMapTypeTest = async (client: CoreClient, uri: string) => { const mapClass = new Map().set("Hello", 1).set("Heyo", 50); const nestedMapClass = new Map>().set( "Nested", @@ -901,7 +898,7 @@ export const runMapTypeTest = async (client: PolywrapClient, uri: string) => { }; export const runSimpleStorageTest = async ( - client: PolywrapClient, + client: CoreClient, wrapperUri: string ) => { const deploy = await client.invoke({ @@ -951,7 +948,7 @@ export const runSimpleStorageTest = async ( }; export const runSimpleEnvTest = async ( - client: PolywrapClient, + client: CoreClient, wrapperUri: string ) => { const getEnvResult = await client.invoke({ @@ -973,7 +970,7 @@ export const runSimpleEnvTest = async ( args: { arg: "not set", }, - env: { } + env: {}, }); getEnvNotSetResult = getEnvNotSetResult as ErrResult; expect(getEnvNotSetResult.error).toBeTruthy(); @@ -999,7 +996,7 @@ export const runSimpleEnvTest = async ( }; export const runComplexEnvs = async ( - client: PolywrapClient, + client: CoreClient, wrapperUri: string ) => { const methodRequireEnvResult = await client.invoke({ @@ -1065,7 +1062,8 @@ export const runComplexEnvs = async ( arg: "string", }, }); - if (!methodRequireEnvModuleTimeResult.ok) fail(methodRequireEnvModuleTimeResult.error); + if (!methodRequireEnvModuleTimeResult.ok) + fail(methodRequireEnvModuleTimeResult.error); expect(methodRequireEnvModuleTimeResult.value).toEqual({ str: "string", optFilledStr: "optional string", @@ -1099,7 +1097,7 @@ export const runComplexEnvs = async ( bool: true, en: "FIRST", array: [32, 23], - } + }, }); if (!mockUpdatedEnvResult.ok) fail(mockUpdatedEnvResult.error); expect(mockUpdatedEnvResult.value).toEqual({ @@ -1120,17 +1118,14 @@ export const runComplexEnvs = async ( }); }; -export const runSubinvokeTest = async ( - client: PolywrapClient, - uri: string, -) => { +export const runSubinvokeTest = async (client: CoreClient, uri: string) => { { const response = await client.invoke({ uri, method: "add", args: { a: 1, - b: 2 + b: 2, }, }); @@ -1138,4 +1133,4 @@ export const runSubinvokeTest = async ( expect(response.value).toBeTruthy(); expect(response.value).toEqual(3); } -}; \ No newline at end of file +}; diff --git a/packages/js/client/src/__tests__/e2e/wasm-as.spec.ts b/packages/js/client/src/__tests__/e2e/wasm-as.spec.ts index 325ca51554..f650f4fc92 100644 --- a/packages/js/client/src/__tests__/e2e/wasm-as.spec.ts +++ b/packages/js/client/src/__tests__/e2e/wasm-as.spec.ts @@ -7,8 +7,8 @@ import { runCLI, } from "@polywrap/test-env-js"; import { GetPathToTestWrappers } from "@polywrap/test-cases"; -import { getClientWithEnsAndIpfs } from "../utils/getClientWithEnsAndIpfs"; -import { getClient } from "../utils/getClient"; +import { getClientWithEnsAndIpfs } from "../helpers/getClientWithEnsAndIpfs"; +import { PolywrapClient } from "../../PolywrapClient"; jest.setTimeout(300000); @@ -27,11 +27,11 @@ describe("wasm-as test cases", () => { await buildWrapper(wrapperPath); - const client = await getClient({ - plugins: [ + const client = new PolywrapClient({ + packages: [ { uri: "wrap://ens/memory-storage.polywrap.eth", - plugin: makeMemoryStoragePlugin({}), + package: makeMemoryStoragePlugin({}), }, ], }); @@ -49,7 +49,7 @@ describe("wasm-as test cases", () => { await buildWrapper(subwrapperPath); await buildWrapper(wrapperPath); - const client = await getClient({ + const client = new PolywrapClient({ redirects: [ { from: "ens/add.eth", @@ -67,7 +67,7 @@ describe("wasm-as test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runBigIntTypeTest(await getClient(), wrapperUri); + await TestCases.runBigIntTypeTest(new PolywrapClient(), wrapperUri); }); it("bignumber-type", async () => { @@ -76,7 +76,7 @@ describe("wasm-as test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runBigNumberTypeTest(await getClient(), wrapperUri); + await TestCases.runBigNumberTypeTest(new PolywrapClient(), wrapperUri); }); it("bytes-type", async () => { @@ -85,7 +85,7 @@ describe("wasm-as test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runBytesTypeTest(await getClient(), wrapperUri); + await TestCases.runBytesTypeTest(new PolywrapClient(), wrapperUri); }); it("enum-types", async () => { @@ -94,20 +94,20 @@ describe("wasm-as test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runEnumTypesTest(await getClient(), wrapperUri); + await TestCases.runEnumTypesTest(new PolywrapClient(), wrapperUri); }); - it("map-type", async () => { + it("map-type", async () => { const wrapperPath = `${GetPathToTestWrappers()}/wasm-as/map-type`; const wrapperUri = `fs/${wrapperPath}/build`; await buildWrapper(wrapperPath); - await TestCases.runMapTypeTest(await getClient(), wrapperUri); + await TestCases.runMapTypeTest(new PolywrapClient(), wrapperUri); }); it("reserved-words", async () => { - const client = await getClient(); + const client = new PolywrapClient(); const wrapperPath = `${GetPathToTestWrappers()}/wasm-as/reserved-words`; const wrapperUri = `fs/${wrapperPath}/build`; @@ -142,7 +142,7 @@ describe("wasm-as test cases", () => { await buildWrapper(interfacePath); await buildWrapper(implementationPath); - const client = await getClient({ + const client = new PolywrapClient({ interfaces: [ { interface: interfaceUri, @@ -172,7 +172,7 @@ describe("wasm-as test cases", () => { await buildWrapper(implementationPath); await buildWrapper(aggregatorPath); - const client = await getClient({ + const client = new PolywrapClient({ interfaces: [ { interface: interfaceUri, @@ -203,7 +203,7 @@ describe("wasm-as test cases", () => { await buildWrapper(implementationPath); - const client = await getClient({ + const client = new PolywrapClient({ interfaces: [ { interface: interfaceUri, @@ -242,7 +242,7 @@ describe("wasm-as test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runInvalidTypesTest(await getClient(), wrapperUri); + await TestCases.runInvalidTypesTest(new PolywrapClient(), wrapperUri); }); it("JSON-type", async () => { @@ -251,7 +251,7 @@ describe("wasm-as test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runJsonTypeTest(await getClient(), wrapperUri); + await TestCases.runJsonTypeTest(new PolywrapClient(), wrapperUri); }); it("large-types", async () => { @@ -260,7 +260,7 @@ describe("wasm-as test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runLargeTypesTest(await getClient(), wrapperUri); + await TestCases.runLargeTypesTest(new PolywrapClient(), wrapperUri); }); it("number-types under and overflows", async () => { @@ -269,7 +269,7 @@ describe("wasm-as test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runNumberTypesTest(await getClient(), wrapperUri); + await TestCases.runNumberTypesTest(new PolywrapClient(), wrapperUri); }); it("object-types", async () => { @@ -278,7 +278,7 @@ describe("wasm-as test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runObjectTypesTest(await getClient(), wrapperUri); + await TestCases.runObjectTypesTest(new PolywrapClient(), wrapperUri); }); it("simple-storage", async () => { @@ -287,10 +287,7 @@ describe("wasm-as test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runSimpleStorageTest( - await getClientWithEnsAndIpfs(), - wrapperUri - ); + await TestCases.runSimpleStorageTest(getClientWithEnsAndIpfs(), wrapperUri); }); it("simple env", async () => { @@ -300,7 +297,7 @@ describe("wasm-as test cases", () => { await buildWrapper(wrapperPath); await TestCases.runSimpleEnvTest( - await getClient({ + new PolywrapClient({ envs: [ { uri: wrapperUri, @@ -326,7 +323,7 @@ describe("wasm-as test cases", () => { await buildWrapper(wrapperPath); await TestCases.runComplexEnvs( - await getClient({ + new PolywrapClient({ envs: [ { uri: wrapperUri, diff --git a/packages/js/client/src/__tests__/e2e/wasm-rs.spec.ts b/packages/js/client/src/__tests__/e2e/wasm-rs.spec.ts index 7e8d28fe2b..61660e122f 100644 --- a/packages/js/client/src/__tests__/e2e/wasm-rs.spec.ts +++ b/packages/js/client/src/__tests__/e2e/wasm-rs.spec.ts @@ -6,11 +6,11 @@ import { stopTestEnvironment, } from "@polywrap/test-env-js"; import { GetPathToTestWrappers } from "@polywrap/test-cases"; -import { getClient } from "../utils/getClient"; -import { getClientWithEnsAndIpfs } from "../utils/getClientWithEnsAndIpfs"; +import { getClientWithEnsAndIpfs } from "../helpers/getClientWithEnsAndIpfs"; import fse from "fs-extra"; import path from "path"; import { execSync } from "child_process"; +import { PolywrapClient } from "../../PolywrapClient"; const { performance } = require("perf_hooks"); jest.setTimeout(1200000); @@ -30,11 +30,11 @@ describe("wasm-rs test cases", () => { await buildWrapper(wrapperPath); - const client = await getClient({ - plugins: [ + const client = new PolywrapClient({ + packages: [ { uri: "wrap://ens/memory-storage.polywrap.eth", - plugin: makeMemoryStoragePlugin({}), + package: makeMemoryStoragePlugin({}), }, ], }); @@ -48,7 +48,7 @@ describe("wasm-rs test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runBigIntTypeTest(await getClient(), wrapperUri); + await TestCases.runBigIntTypeTest(new PolywrapClient(), wrapperUri); }); it("bignumber-type", async () => { @@ -57,7 +57,7 @@ describe("wasm-rs test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runBigNumberTypeTest(await getClient(), wrapperUri); + await TestCases.runBigNumberTypeTest(new PolywrapClient(), wrapperUri); }); it("bytes-type", async () => { @@ -66,7 +66,7 @@ describe("wasm-rs test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runBytesTypeTest(await getClient(), wrapperUri); + await TestCases.runBytesTypeTest(new PolywrapClient(), wrapperUri); }); it("enum-types", async () => { @@ -75,7 +75,7 @@ describe("wasm-rs test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runEnumTypesTest(await getClient(), wrapperUri); + await TestCases.runEnumTypesTest(new PolywrapClient(), wrapperUri); }); it("map-type", async () => { @@ -84,7 +84,7 @@ describe("wasm-rs test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runMapTypeTest(await getClient(), wrapperUri); + await TestCases.runMapTypeTest(new PolywrapClient(), wrapperUri); }); it("implementations - e2e", async () => { @@ -98,7 +98,7 @@ describe("wasm-rs test cases", () => { await buildWrapper(implementationPath); - const client = await getClient({ + const client = new PolywrapClient({ interfaces: [ { interface: interfaceUri, @@ -128,7 +128,7 @@ describe("wasm-rs test cases", () => { await buildWrapper(implementationPath); await buildWrapper(aggregatorPath); - const client = await getClient({ + const client = new PolywrapClient({ interfaces: [ { interface: interfaceUri, @@ -151,7 +151,7 @@ describe("wasm-rs test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runInvalidTypesTest(await getClient(), wrapperUri); + await TestCases.runInvalidTypesTest(new PolywrapClient(), wrapperUri); }); it("JSON-type", async () => { @@ -160,7 +160,7 @@ describe("wasm-rs test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runJsonTypeTest(await getClient(), wrapperUri, true); + await TestCases.runJsonTypeTest(new PolywrapClient(), wrapperUri, true); }); it("large-types", async () => { @@ -169,7 +169,7 @@ describe("wasm-rs test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runLargeTypesTest(await getClient(), wrapperUri); + await TestCases.runLargeTypesTest(new PolywrapClient(), wrapperUri); }); it("number-types under and overflows", async () => { @@ -178,7 +178,7 @@ describe("wasm-rs test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runNumberTypesTest(await getClient(), wrapperUri); + await TestCases.runNumberTypesTest(new PolywrapClient(), wrapperUri); }); it("object-types", async () => { @@ -187,7 +187,7 @@ describe("wasm-rs test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runObjectTypesTest(await getClient(), wrapperUri); + await TestCases.runObjectTypesTest(new PolywrapClient(), wrapperUri); }); it("simple-storage", async () => { @@ -196,10 +196,7 @@ describe("wasm-rs test cases", () => { await buildWrapper(wrapperPath); - await TestCases.runSimpleStorageTest( - await getClientWithEnsAndIpfs(), - wrapperUri - ); + await TestCases.runSimpleStorageTest(getClientWithEnsAndIpfs(), wrapperUri); }); it("simple env", async () => { @@ -209,7 +206,7 @@ describe("wasm-rs test cases", () => { await buildWrapper(wrapperPath); await TestCases.runSimpleEnvTest( - await await getClient({ + await new PolywrapClient({ envs: [ { uri: wrapperUri, @@ -235,7 +232,7 @@ describe("wasm-rs test cases", () => { await buildWrapper(wrapperPath); await TestCases.runComplexEnvs( - await getClient({ + new PolywrapClient({ envs: [ { uri: wrapperUri, @@ -278,20 +275,24 @@ describe("wasm-rs test cases", () => { console.debug = jest.fn(); const message = "foo bar baz"; - const client = await getClient(); + const client = new PolywrapClient(); const result = await client.invoke({ uri: wrapperUri, method: "logMessage", args: { message, - } + }, }); expect(result.ok).toBeTruthy(); if (!result.ok) return; expect(result.value).toBeTruthy(); - expect((console.debug as any).mock.calls[0][0]).toBe("__wrap_debug_log: " + message); - expect((console.debug as any).mock.calls[1][0]).toBe("__wrap_debug_log: " + message); + expect((console.debug as any).mock.calls[0][0]).toBe( + "__wrap_debug_log: " + message + ); + expect((console.debug as any).mock.calls[1][0]).toBe( + "__wrap_debug_log: " + message + ); jest.clearAllMocks(); }); }); @@ -330,7 +331,7 @@ describe.skip("Wasm-rs benchmarking", () => { const msTime = endTime - startTime; //Make sure the wrapper works correctly - await TestCases.runBigNumberTypeTest(await getClient(), wrapperUri); + await TestCases.runBigNumberTypeTest(new PolywrapClient(), wrapperUri); return msTime; }; diff --git a/packages/js/client/src/__tests__/helpers/getClientWithEnsAndIpfs.ts b/packages/js/client/src/__tests__/helpers/getClientWithEnsAndIpfs.ts new file mode 100644 index 0000000000..a0ce755f07 --- /dev/null +++ b/packages/js/client/src/__tests__/helpers/getClientWithEnsAndIpfs.ts @@ -0,0 +1,90 @@ +import { coreInterfaceUris, PolywrapClient } from "../.."; +import { ensAddresses, providers } from "@polywrap/test-env-js"; +import { + Connection, + Connections, + ethereumPlugin, +} from "@polywrap/ethereum-plugin-js"; +import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; +import { fileSystemPlugin } from "@polywrap/fs-plugin-js"; +import { fileSystemResolverPlugin } from "@polywrap/fs-resolver-plugin-js"; +import { ensResolverPlugin } from "@polywrap/ens-resolver-plugin-js"; +import { ipfsResolverPlugin } from "@polywrap/ipfs-resolver-plugin-js"; +import { + PackageToWrapperCacheResolver, + RecursiveResolver, + WrapperCache, +} from "@polywrap/uri-resolvers-js"; +import { ExtendableUriResolver } from "@polywrap/uri-resolver-extensions-js"; + +export const getClientWithEnsAndIpfs = () => { + const connections: Connections = new Connections({ + networks: { + testnet: new Connection({ + provider: providers.ethereum, + }), + }, + defaultNetwork: "testnet", + }); + return new PolywrapClient( + { + envs: [ + { + uri: "wrap://ens/ipfs.polywrap.eth", + env: { + provider: providers.ipfs, + }, + }, + ], + interfaces: [ + { + interface: coreInterfaceUris.uriResolver, + implementations: [ + "wrap://ens/ipfs-resolver.polywrap.eth", + "wrap://ens/ens-resolver.polywrap.eth", + "wrap://ens/fs-resolver.polywrap.eth", + ], + }, + ], + resolver: RecursiveResolver.from( + PackageToWrapperCacheResolver.from( + [ + { + uri: "wrap://ens/ethereum.polywrap.eth", + package: ethereumPlugin({ connections }), + }, + { + uri: "wrap://ens/ens-resolver.polywrap.eth", + package: ensResolverPlugin({ + addresses: { + testnet: ensAddresses.ensAddress, + }, + }), + }, + { + uri: "wrap://ens/ipfs.polywrap.eth", + package: ipfsPlugin({}), + }, + { + uri: "wrap://ens/ipfs-resolver.polywrap.eth", + package: ipfsResolverPlugin({}), + }, + { + uri: "wrap://ens/fs.polywrap.eth", + package: fileSystemPlugin({}), + }, + { + uri: "wrap://ens/fs-resolver.polywrap.eth", + package: fileSystemResolverPlugin({}), + }, + new ExtendableUriResolver(), + ], + new WrapperCache() + ) + ), + }, + { + noDefaults: true, + } + ); +}; diff --git a/packages/js/client/src/__tests__/helpers/mockPluginRegistration.ts b/packages/js/client/src/__tests__/helpers/mockPluginRegistration.ts new file mode 100644 index 0000000000..9b1b72fa90 --- /dev/null +++ b/packages/js/client/src/__tests__/helpers/mockPluginRegistration.ts @@ -0,0 +1,15 @@ +import { Uri } from "@polywrap/core-js"; +import { PluginPackage } from "@polywrap/plugin-js"; + +export const mockPluginRegistration = (uri: string | Uri) => { + return { + uri: Uri.from(uri), + package: PluginPackage.from( + () => ({ + simpleMethod: (_: unknown): string => { + return "plugin response"; + } + }) + ), + }; +}; diff --git a/packages/js/client/src/__tests__/utils/getClient.ts b/packages/js/client/src/__tests__/utils/getClient.ts deleted file mode 100644 index 8b4082c717..0000000000 --- a/packages/js/client/src/__tests__/utils/getClient.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { createPolywrapClient, PolywrapClientConfig } from "../.."; -import { ClientConfigBuilder } from "@polywrap/client-config-builder-js"; - -export const getClient = async (config?: Partial) => { - return createPolywrapClient({}, config); -}; - -export const getDefaultClientConfig = () => { - return new ClientConfigBuilder().addDefaults().build(); -}; \ No newline at end of file diff --git a/packages/js/client/src/__tests__/utils/getClientWithEnsAndIpfs.ts b/packages/js/client/src/__tests__/utils/getClientWithEnsAndIpfs.ts deleted file mode 100644 index 55446a45a3..0000000000 --- a/packages/js/client/src/__tests__/utils/getClientWithEnsAndIpfs.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { createPolywrapClient, PolywrapClientConfig } from "../.."; -import { ensAddresses, providers } from "@polywrap/test-env-js"; -import { Connection, Connections } from "@polywrap/ethereum-plugin-js"; - -export const getClientWithEnsAndIpfs = async ( - config?: Partial -) => { - const connections: Connections = new Connections({ - networks: { - testnet: new Connection({ - provider: providers.ethereum, - }), - }, - defaultNetwork: "testnet", - }); - return createPolywrapClient( - { - ethereum: { connections }, - ipfs: {}, - ens: { - addresses: { - testnet: ensAddresses.ensAddress, - }, - }, - }, - config - ); -}; diff --git a/packages/js/client/src/createPolywrapClient.ts b/packages/js/client/src/createPolywrapClient.ts deleted file mode 100644 index a9ed4e504a..0000000000 --- a/packages/js/client/src/createPolywrapClient.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable prefer-const */ - -import { PolywrapClient, PolywrapClientConfig } from "./PolywrapClient"; -import { PluginConfigs, modules, uris } from "./pluginConfigs"; - -import { PluginRegistration } from "@polywrap/core-js"; -import { Tracer } from "@polywrap/tracing-js"; -import { ClientConfigBuilder } from "@polywrap/client-config-builder-js"; - -export { PluginConfigs }; - -export const createPolywrapClient = Tracer.traceFunc( - "createPolywrapClient", - async ( - pluginConfigs: PluginConfigs, - config?: Partial - ): Promise => { - const plugins: PluginRegistration[] = []; - - for (const plugin of Object.keys(pluginConfigs)) { - let pluginModule: any; - - if (!modules[plugin]) { - throw Error( - `Requested plugin "${plugin}" is not a supported createPolywrapClient plugin.` - ); - } - - try { - pluginModule = await import(modules[plugin]); - } catch (err) { - throw Error( - `Failed to import plugin module. Please install the package "${modules[plugin]}".\n` + - `Error: ${err.message}` - ); - } - - const pluginFactory = pluginModule["plugin"]; - - if (!pluginFactory) { - throw Error( - `Plugin module "${modules[plugin]}" is missing the "plugin: PluginFactory" export.` - ); - } - - if (typeof pluginFactory !== "function") { - throw Error( - `The "plugin: PluginFactory" export must be a function. Found in module "${modules[plugin]}".` - ); - } - - const pluginPackage = pluginFactory( - (pluginConfigs as Record)[plugin] - ); - if ( - !pluginPackage || - typeof pluginPackage !== "object" || - !pluginPackage.factory || - !pluginPackage.manifest - ) { - throw Error( - `Plugin package is malformed. Expected object with keys "factory" and "manifest". Got: ${pluginPackage}` - ); - } - - plugins.push({ - uri: uris[plugin], - plugin: pluginPackage, - }); - } - - if (config) { - const builder = new ClientConfigBuilder().add(config); - - for (const plugin of plugins) { - builder.addPlugin(plugin.uri, plugin.plugin); - } - - const sanitizedConfig = builder.buildPartial(); - - return new PolywrapClient(sanitizedConfig); - } else { - return new PolywrapClient({ plugins }); - } - } -); diff --git a/packages/js/client/src/index.ts b/packages/js/client/src/index.ts index 8cdff18c54..1c56a02e6e 100644 --- a/packages/js/client/src/index.ts +++ b/packages/js/client/src/index.ts @@ -1,3 +1,7 @@ export * from "./PolywrapClient"; -export * from "./createPolywrapClient"; +export * from "./PolywrapClientConfig"; +export * from "./PolywrapCoreClientConfig"; export * from "@polywrap/core-js"; +export * from "@polywrap/uri-resolvers-js"; +export * from "@polywrap/uri-resolver-extensions-js"; +export * from "@polywrap/client-config-builder-js"; diff --git a/packages/js/client/src/pluginConfigs/Ens.ts b/packages/js/client/src/pluginConfigs/Ens.ts deleted file mode 100644 index 555cec3119..0000000000 --- a/packages/js/client/src/pluginConfigs/Ens.ts +++ /dev/null @@ -1,16 +0,0 @@ -/// NOTE: This is an auto-generated file. See scripts/extractPluginConfigs.ts -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable prettier/prettier */ - -/// Types generated from @polywrap/ens-resolver-plugin-js build files: -/// build/index.d.ts - -export interface EnsResolverPluginConfig { - addresses?: Addresses; -} - -export interface Addresses { - [network: string]: Address; -} - -export type Address = string; diff --git a/packages/js/client/src/pluginConfigs/Ethereum.ts b/packages/js/client/src/pluginConfigs/Ethereum.ts deleted file mode 100644 index a7ff9ab735..0000000000 --- a/packages/js/client/src/pluginConfigs/Ethereum.ts +++ /dev/null @@ -1,47 +0,0 @@ -/// NOTE: This is an auto-generated file. See scripts/extractPluginConfigs.ts -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable prettier/prettier */ - -/// Types generated from @polywrap/ethereum-plugin-js build files: -/// build/index.d.ts, build/Connection.d.ts, build/Connections.d.ts - -export interface EthereumPluginConfig { - connections: Connections; -} - -export interface ConnectionConfig { - provider: EthereumProvider; - signer?: EthereumSigner; -} - -export type EthereumProvider = string | ExternalProvider | JsonRpcProvider; - -export type EthereumSigner = Signer | Address | AccountIndex; - -export type AccountIndex = number; - -export type Address = string; - -export interface ConnectionsConfig { - networks: Networks; - defaultNetwork?: string; -} - -type Networks = { - [network: string]: Connection; -}; - -// import { Connection } from "@polywrap/ethereum-plugin-js" -export type Connection = any; - -// import { Connections } from "@polywrap/ethereum-plugin-js" -export type Connections = any; - -// import { Signer } from "ethers" -export type Signer = any; - -// import { ExternalProvider } from "@ethersproject/providers" -export type ExternalProvider = any; - -// import { JsonRpcProvider } from "@ethersproject/providers" -export type JsonRpcProvider = any; diff --git a/packages/js/client/src/pluginConfigs/Ipfs.ts b/packages/js/client/src/pluginConfigs/Ipfs.ts deleted file mode 100644 index acf0f28c06..0000000000 --- a/packages/js/client/src/pluginConfigs/Ipfs.ts +++ /dev/null @@ -1,8 +0,0 @@ -/// NOTE: This is an auto-generated file. See scripts/extractPluginConfigs.ts -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable prettier/prettier */ - -/// Types generated from @polywrap/ipfs-plugin-js build files: -/// build/index.d.ts - -export type NoConfig = Record; diff --git a/packages/js/client/src/pluginConfigs/index.ts b/packages/js/client/src/pluginConfigs/index.ts deleted file mode 100644 index d6ee66e563..0000000000 --- a/packages/js/client/src/pluginConfigs/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -/// NOTE: This is an auto-generated file. See scripts/extractPluginConfigs.ts -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable prettier/prettier */ - -import { NoConfig } from "./Ipfs"; -import { EthereumPluginConfig } from "./Ethereum"; -import { EnsResolverPluginConfig } from "./Ens"; - -interface PluginConfigs { - ipfs?: NoConfig; - ethereum?: EthereumPluginConfig; - ens?: EnsResolverPluginConfig; -} - -const modules: Record = { - ipfs: "@polywrap/ipfs-plugin-js", - ethereum: "@polywrap/ethereum-plugin-js", - ens: "@polywrap/ens-resolver-plugin-js", -}; - -const uris: Record = { - ipfs: "wrap://ens/ipfs.polywrap.eth", - ethereum: "wrap://ens/ethereum.polywrap.eth", - ens: "wrap://ens/ens-resolver.polywrap.eth", -}; - -export { PluginConfigs, modules, uris }; diff --git a/packages/js/core/package.json b/packages/js/core/package.json index a76685f90c..79baf7090b 100644 --- a/packages/js/core/package.json +++ b/packages/js/core/package.json @@ -19,23 +19,16 @@ "test:watch": "jest --watch --passWithNoTests --verbose" }, "dependencies": { - "@polywrap/asyncify-js": "0.9.3", - "@polywrap/msgpack-js": "0.9.3", "@polywrap/result": "0.9.3", "@polywrap/tracing-js": "0.9.3", "@polywrap/wrap-manifest-types-js": "0.9.3", "graphql": "15.5.0", - "graphql-tag": "2.10.4", - "jsonschema": "1.4.0", - "semver": "7.3.5", - "yaml": "2.1.3" + "graphql-tag": "2.10.4" }, "devDependencies": { - "@polywrap/os-js": "0.9.3", "@types/jest": "26.0.8", "@types/mustache": "4.0.1", "@types/prettier": "2.6.0", - "@types/semver": "7.3.8", "jest": "26.6.3", "mustache": "4.0.1", "rimraf": "3.0.2", diff --git a/packages/js/core/src/__tests__/Plugin.spec.ts b/packages/js/core/src/__tests__/Plugin.spec.ts deleted file mode 100644 index a7a965bf2f..0000000000 --- a/packages/js/core/src/__tests__/Plugin.spec.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { - Client, - PluginModule -} from ".."; -import { ResultOk } from "@polywrap/result"; - -class TestPluginModule extends PluginModule<{}> { - testMethod(args: { value: number }, _client: Client): number { - return 5 + args.value; - } -} - -describe("Plugin", () => { - const plugin = new TestPluginModule({}); - - it("sanity", async () => { - expect(plugin).toBeTruthy(); - expect ( - await plugin._wrap_invoke("testMethod", { value: 5 }, {} as Client) - ).toStrictEqual(ResultOk(10)); - }); -}); diff --git a/packages/js/core/src/__tests__/PluginRegistrations.spec.ts b/packages/js/core/src/__tests__/PluginRegistrations.spec.ts deleted file mode 100644 index 18ee20c5eb..0000000000 --- a/packages/js/core/src/__tests__/PluginRegistrations.spec.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Uri } from "../"; -import { PluginPackage, sanitizePluginRegistrations } from "../types"; - -describe("sanitizePluginRegistrations", () => { - it("Returns empty array if empty array passed", () => { - const plugins = sanitizePluginRegistrations([]); - - expect(plugins).toEqual([]); - }); - - it("Returns plugins from plugins definitions", () => { - const plugins = sanitizePluginRegistrations([ - { - uri: "wrap://polywrap/wrapper", - plugin: {} as PluginPackage<{}>, - } - ]); - - expect(plugins).toEqual([ - { - uri: new Uri("wrap://polywrap/wrapper"), - plugin: {} as PluginPackage<{}> - } - ]); - }); -}); diff --git a/packages/js/core/src/__tests__/UriRedirect.spec.ts b/packages/js/core/src/__tests__/UriRedirect.spec.ts deleted file mode 100644 index ea208904a2..0000000000 --- a/packages/js/core/src/__tests__/UriRedirect.spec.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Uri } from "../"; -import { sanitizeUriRedirects } from "../types/UriRedirect"; - -describe("sanitizeUriRedirects", () => { - it("Returns empty array if empty array passed", () => { - const redirects = sanitizeUriRedirects([]); - - expect(redirects).toEqual([]); - }); - - it("Returns uri redirects from uri redirect definitions", () => { - const redirects = sanitizeUriRedirects([ - { - from: "wrap://polywrap/wrapper", - to: "wrap://polywrap/wrapper" - } - ]); - - expect(redirects).toEqual([ - { - from: new Uri("wrap://polywrap/wrapper"), - to: new Uri("wrap://polywrap/wrapper") - } - ]); - }); -}); diff --git a/packages/js/core/src/algorithms/apply-redirects.ts b/packages/js/core/src/algorithms/apply-redirects.ts index fd1c60a3fe..6ae68f3764 100644 --- a/packages/js/core/src/algorithms/apply-redirects.ts +++ b/packages/js/core/src/algorithms/apply-redirects.ts @@ -1,11 +1,11 @@ -import { Uri, UriRedirect } from "../types"; +import { Uri, IUriRedirect } from "../types"; import { Tracer } from "@polywrap/tracing-js"; import { Result, ResultErr, ResultOk } from "@polywrap/result"; export const applyRedirects = Tracer.traceFunc( "core: applyRedirects", - (uri: Uri, redirects: readonly UriRedirect[]): Result => { + (uri: Uri, redirects: readonly IUriRedirect[]): Result => { // Keep track of past redirects (from -> to) to find the final uri const redirectFromToMap: Record = {}; diff --git a/packages/js/core/src/algorithms/get-implementations.ts b/packages/js/core/src/algorithms/get-implementations.ts index f6588a61a6..44eca08000 100644 --- a/packages/js/core/src/algorithms/get-implementations.ts +++ b/packages/js/core/src/algorithms/get-implementations.ts @@ -1,4 +1,4 @@ -import { Uri, UriRedirect, InterfaceImplementations } from "../types"; +import { Uri, IUriRedirect, InterfaceImplementations } from "../types"; import { applyRedirects } from "./apply-redirects"; import { Tracer } from "@polywrap/tracing-js"; @@ -9,7 +9,7 @@ export const getImplementations = Tracer.traceFunc( ( wrapperInterfaceUri: Uri, interfaces: readonly InterfaceImplementations[], - redirects?: readonly UriRedirect[] + redirects?: readonly IUriRedirect[] ): Result => { const result: Uri[] = []; diff --git a/packages/js/core/src/index.ts b/packages/js/core/src/index.ts index 7c455fb135..dd5ce13c32 100644 --- a/packages/js/core/src/index.ts +++ b/packages/js/core/src/index.ts @@ -3,5 +3,4 @@ export * from "./algorithms"; export * from "./interfaces"; export * from "./uri-resolution"; export * from "./utils"; -export * from "./plugin"; export { Result } from "@polywrap/result"; diff --git a/packages/js/core/src/plugin/PluginWrapPackage.ts b/packages/js/core/src/plugin/PluginWrapPackage.ts deleted file mode 100644 index 1172843cc6..0000000000 --- a/packages/js/core/src/plugin/PluginWrapPackage.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { IWrapPackage, PluginPackage, Uri, Wrapper } from "../types"; -import { PluginWrapper } from "./PluginWrapper"; - -import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; -import { Result, ResultOk } from "@polywrap/result"; - -// TODO: this is a temporary solution until we refactor the plugin package to be an IWrapPackage -export class PluginWrapPackage implements IWrapPackage { - constructor( - public uri: Uri, - private readonly pluginPackage: PluginPackage - ) {} - - async getManifest(): Promise> { - return ResultOk(this.pluginPackage.manifest); - } - - async createWrapper(): Promise> { - return ResultOk(new PluginWrapper(this.pluginPackage)); - } -} diff --git a/packages/js/core/src/plugin/index.ts b/packages/js/core/src/plugin/index.ts deleted file mode 100644 index eba1a8d2a9..0000000000 --- a/packages/js/core/src/plugin/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./PluginWrapPackage"; -export * from "./PluginWrapper"; diff --git a/packages/js/core/src/types/Client.ts b/packages/js/core/src/types/CoreClient.ts similarity index 61% rename from packages/js/core/src/types/Client.ts rename to packages/js/core/src/types/CoreClient.ts index a2c15c3a72..da9e739f72 100644 --- a/packages/js/core/src/types/Client.ts +++ b/packages/js/core/src/types/CoreClient.ts @@ -2,24 +2,21 @@ import { QueryHandler, Invoker, SubscriptionHandler, - UriRedirect, + IUriRedirect, Uri, - PluginRegistration, InterfaceImplementations, Env, - PluginPackage, -} from "./"; +} from "."; import { IUriResolver } from "../uri-resolution"; import { UriResolverHandler } from "./UriResolver"; import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; import { Result } from "@polywrap/result"; -export interface ClientConfig { - readonly redirects: Readonly[]>; - readonly plugins: Readonly[]>; - readonly interfaces: Readonly[]>; - readonly envs: Readonly[]>; +export interface CoreClientConfig { + readonly redirects?: Readonly[]>; + readonly interfaces?: Readonly[]>; + readonly envs?: Readonly[]>; readonly resolver: Readonly>; } @@ -36,32 +33,25 @@ export interface GetImplementationsOptions { applyRedirects?: boolean; } -export interface Client +export interface CoreClient extends Invoker, QueryHandler, SubscriptionHandler, UriResolverHandler { - getConfig(): ClientConfig; + getConfig(): CoreClientConfig; - getRedirects(): readonly UriRedirect[]; + getRedirects(): readonly IUriRedirect[] | undefined; - getPlugins(): readonly PluginRegistration[]; + getInterfaces(): readonly InterfaceImplementations[] | undefined; - getPluginByUri( - uri: TUri - ): PluginPackage | undefined; - - getInterfaces(): readonly InterfaceImplementations[]; - - getEnvs(): readonly Env[]; + getEnvs(): readonly Env[] | undefined; getEnvByUri(uri: TUri): Env | undefined; getUriResolver(): IUriResolver; getManifest( - uri: TUri, - options: GetManifestOptions + uri: TUri ): Promise>; getFile( diff --git a/packages/js/core/src/types/IUriPackage.ts b/packages/js/core/src/types/IUriPackage.ts index eead0b4c09..f7b27f64e0 100644 --- a/packages/js/core/src/types/IUriPackage.ts +++ b/packages/js/core/src/types/IUriPackage.ts @@ -1,6 +1,6 @@ import { Uri, IWrapPackage } from "."; -export interface IUriPackage { - uri: Uri; +export interface IUriPackage { + uri: TUri; package: IWrapPackage; } diff --git a/packages/js/core/src/types/IUriRedirect.ts b/packages/js/core/src/types/IUriRedirect.ts new file mode 100644 index 0000000000..3475f727a0 --- /dev/null +++ b/packages/js/core/src/types/IUriRedirect.ts @@ -0,0 +1,6 @@ +import { Uri } from "."; + +export interface IUriRedirect { + from: TUri; + to: TUri; +} diff --git a/packages/js/core/src/types/IUriWrapper.ts b/packages/js/core/src/types/IUriWrapper.ts index bb0b606c53..0a5aa5c622 100644 --- a/packages/js/core/src/types/IUriWrapper.ts +++ b/packages/js/core/src/types/IUriWrapper.ts @@ -1,6 +1,6 @@ import { Uri, Wrapper } from "."; -export interface IUriWrapper { - uri: Uri; +export interface IUriWrapper { + uri: TUri; wrapper: Wrapper; } diff --git a/packages/js/core/src/types/PluginRegistration.ts b/packages/js/core/src/types/PluginRegistration.ts deleted file mode 100644 index 4df9c64b7f..0000000000 --- a/packages/js/core/src/types/PluginRegistration.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { PluginPackage, Uri } from "."; - -import { Tracer } from "@polywrap/tracing-js"; - -export interface PluginRegistration { - uri: TUri; - plugin: PluginPackage; -} - -export const sanitizePluginRegistrations = Tracer.traceFunc( - "core: sanitizePluginRegistrations", - (input: PluginRegistration[]): PluginRegistration[] => { - const output: PluginRegistration[] = []; - for (const definition of input) { - const uri = Uri.from(definition.uri); - - output.push({ - uri, - plugin: definition.plugin, - }); - } - - return output; - } -); diff --git a/packages/js/core/src/types/UriRedirect.ts b/packages/js/core/src/types/UriRedirect.ts deleted file mode 100644 index 8be1dd4de4..0000000000 --- a/packages/js/core/src/types/UriRedirect.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { Uri } from "."; - -import { Tracer } from "@polywrap/tracing-js"; - -export interface UriRedirect { - from: TUri; - to: TUri; -} - -export const sanitizeUriRedirects = Tracer.traceFunc( - "core: sanitizeUriRedirects", - (input: UriRedirect[]): UriRedirect[] => { - const output: UriRedirect[] = []; - for (const definition of input) { - output.push({ - from: Uri.from(definition.from), - to: Uri.from(definition.to), - }); - } - - return output; - } -); diff --git a/packages/js/core/src/types/Wrapper.ts b/packages/js/core/src/types/Wrapper.ts index 1e6a1b5220..5d5655b4b3 100644 --- a/packages/js/core/src/types/Wrapper.ts +++ b/packages/js/core/src/types/Wrapper.ts @@ -1,7 +1,6 @@ import { Uri, GetFileOptions, - GetManifestOptions, InvokeOptions, Invocable, Invoker, @@ -32,7 +31,6 @@ export interface Wrapper extends Invocable { /** * Get a file from the Wrapper package. - * Not implemented for plugin wrappers. * * @param options Configuration options for file retrieval * @param client The client instance requesting the file. @@ -41,9 +39,6 @@ export interface Wrapper extends Invocable { /** * Get a manifest from the Wrapper package. - * Not implemented for plugin wrappers. - * - * @param client The client instance requesting the manifest. */ - getManifest(options?: GetManifestOptions): WrapManifest; + getManifest(): WrapManifest; } diff --git a/packages/js/core/src/types/index.ts b/packages/js/core/src/types/index.ts index 07ab7bdb9f..462080bc83 100644 --- a/packages/js/core/src/types/index.ts +++ b/packages/js/core/src/types/index.ts @@ -1,16 +1,14 @@ export * from "./Wrapper"; -export * from "./Client"; +export * from "./CoreClient"; export * from "./Invoke"; export * from "./MaybeAsync"; -export * from "./Plugin"; export * from "./Query"; export * from "./Subscription"; export * from "./Uri"; -export * from "./UriRedirect"; export * from "./Env"; export * from "./InterfaceImplementations"; -export * from "./PluginRegistration"; export * from "./UriResolver"; export * from "./IWrapPackage"; +export * from "./IUriRedirect"; export * from "./IUriWrapper"; export * from "./IUriPackage"; diff --git a/packages/js/core/src/uri-resolution/IUriResolver.ts b/packages/js/core/src/uri-resolution/IUriResolver.ts index 0a2aea76ae..f714219241 100644 --- a/packages/js/core/src/uri-resolution/IUriResolver.ts +++ b/packages/js/core/src/uri-resolution/IUriResolver.ts @@ -1,4 +1,4 @@ -import { Uri, Client } from ".."; +import { Uri, CoreClient } from ".."; import { IUriResolutionContext } from "./IUriResolutionContext"; import { UriPackageOrWrapper } from "./UriPackageOrWrapper"; @@ -7,7 +7,7 @@ import { Result } from "@polywrap/result"; export interface IUriResolver { tryResolveUri( uri: Uri, - client: Client, + client: CoreClient, resolutionContext: IUriResolutionContext ): Promise>; } diff --git a/packages/js/core/src/uri-resolution/UriPackageOrWrapper.ts b/packages/js/core/src/uri-resolution/UriPackageOrWrapper.ts index 8b762b825e..ce662e6a76 100644 --- a/packages/js/core/src/uri-resolution/UriPackageOrWrapper.ts +++ b/packages/js/core/src/uri-resolution/UriPackageOrWrapper.ts @@ -6,11 +6,11 @@ export type UriValue = { uri: Uri; }; -export type UriPackageValue = IUriPackage & { +export type UriPackageValue = IUriPackage & { type: "package"; }; -export type UriWrapperValue = IUriWrapper & { +export type UriWrapperValue = IUriWrapper & { type: "wrapper"; }; diff --git a/packages/js/core/src/uri-resolution/index.ts b/packages/js/core/src/uri-resolution/index.ts index 712a6d2938..94cbea5324 100644 --- a/packages/js/core/src/uri-resolution/index.ts +++ b/packages/js/core/src/uri-resolution/index.ts @@ -1,6 +1,5 @@ export * from "./IUriResolutionStep"; export * from "./IUriResolver"; export * from "./UriPackageOrWrapper"; -export * from "./UriResolutionResult"; export * from "./IUriResolutionContext"; export * from "./UriResolutionContext"; diff --git a/packages/js/core/src/utils/getEnvFromUriHistory.ts b/packages/js/core/src/utils/getEnvFromUriHistory.ts index d128bcbeb4..6266e5475a 100644 --- a/packages/js/core/src/utils/getEnvFromUriHistory.ts +++ b/packages/js/core/src/utils/getEnvFromUriHistory.ts @@ -1,8 +1,8 @@ -import { Uri, Client, Env } from "../types"; +import { Uri, CoreClient, Env } from "../types"; export const getEnvFromUriHistory = ( uriHistory: Uri[], - client: Client + client: CoreClient ): Env | undefined => { for (const uri of uriHistory) { const env = client.getEnvByUri(uri); diff --git a/packages/js/manifests/wrap/package.json b/packages/js/manifests/wrap/package.json index fd46e3add4..c2d041950b 100644 --- a/packages/js/manifests/wrap/package.json +++ b/packages/js/manifests/wrap/package.json @@ -16,7 +16,6 @@ "test:watch": "jest --watch --passWithNoTests --verbose" }, "dependencies": { - "@polywrap/msgpack-js": "0.9.3", "json-schema-ref-parser": "9.0.9", "jsonschema": "1.4.0", "semver": "7.3.5" @@ -24,6 +23,7 @@ "devDependencies": { "@polywrap/os-js": "0.9.3", "@polywrap/wrap-manifest-schemas": "0.9.3", + "@polywrap/msgpack-js": "0.9.3", "@types/jest": "26.0.8", "@types/mustache": "4.0.1", "@types/prettier": "2.6.0", diff --git a/packages/js/plugin/README.md b/packages/js/plugin/README.md new file mode 100644 index 0000000000..238e9df99b --- /dev/null +++ b/packages/js/plugin/README.md @@ -0,0 +1,5 @@ +# @polywrap/plugin-js + +## Description + +Helpers to improve plugin wrapper development experience. diff --git a/packages/js/plugin/jest.config.js b/packages/js/plugin/jest.config.js new file mode 100644 index 0000000000..b156259895 --- /dev/null +++ b/packages/js/plugin/jest.config.js @@ -0,0 +1,12 @@ +module.exports = { + collectCoverage: true, + preset: 'ts-jest', + testEnvironment: 'node', + testMatch: ["**/?(*.)+(spec|test).[jt]s?(x)"], + modulePathIgnorePatterns: ['./src/__tests__/apis'], + globals: { + 'ts-jest': { + diagnostics: false + } + } +}; diff --git a/packages/js/plugin/package.json b/packages/js/plugin/package.json new file mode 100644 index 0000000000..47254b5753 --- /dev/null +++ b/packages/js/plugin/package.json @@ -0,0 +1,39 @@ +{ + "name": "@polywrap/plugin-js", + "description": "Polywrap plugin core package for plugin wrappers", + "version": "0.9.3", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/polywrap/monorepo.git" + }, + "main": "build/index.js", + "files": [ + "build" + ], + "scripts": { + "build": "rimraf ./build && tsc --project tsconfig.build.json", + "lint": "eslint --color -c ../../../.eslintrc.js src/", + "test": "jest --passWithNoTests --runInBand --verbose", + "test:ci": "jest --passWithNoTests --runInBand --verbose", + "test:watch": "jest --watch --passWithNoTests --verbose" + }, + "dependencies": { + "@polywrap/result": "0.9.3", + "@polywrap/core-js": "0.9.3", + "@polywrap/msgpack-js": "0.9.3", + "@polywrap/tracing-js": "0.9.3", + "@polywrap/wrap-manifest-types-js": "0.9.3" + }, + "devDependencies": { + "@types/jest": "26.0.8", + "jest": "26.6.3", + "rimraf": "3.0.2", + "ts-jest": "26.5.4", + "ts-node": "8.10.2", + "typescript": "4.1.6" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/packages/js/plugin/src/PluginFactory.ts b/packages/js/plugin/src/PluginFactory.ts new file mode 100644 index 0000000000..0dbc5d0f07 --- /dev/null +++ b/packages/js/plugin/src/PluginFactory.ts @@ -0,0 +1,5 @@ +import { PluginPackage } from "./PluginPackage"; + +export type PluginFactory = ( + config: TConfig +) => PluginPackage; diff --git a/packages/js/plugin/src/PluginMethod.ts b/packages/js/plugin/src/PluginMethod.ts new file mode 100644 index 0000000000..0e4fd77675 --- /dev/null +++ b/packages/js/plugin/src/PluginMethod.ts @@ -0,0 +1,15 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { CoreClient, MaybeAsync } from "@polywrap/core-js"; + +/** + * Invocable plugin method. + * + * @param args Arguments for the method, structured as + * a map, removing the chance of incorrectly ordering arguments. + * @param client The client instance requesting this invocation. + * This client will be used for any sub-invokes that occur. + */ +export type PluginMethod< + TArgs extends Record = Record, + TResult = unknown +> = (args: TArgs, client: CoreClient) => MaybeAsync; diff --git a/packages/js/core/src/types/Plugin.ts b/packages/js/plugin/src/PluginModule.ts similarity index 65% rename from packages/js/core/src/types/Plugin.ts rename to packages/js/plugin/src/PluginModule.ts index 26e57c2efe..739f0ff7f3 100644 --- a/packages/js/core/src/types/Plugin.ts +++ b/packages/js/plugin/src/PluginModule.ts @@ -1,22 +1,9 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { Client, MaybeAsync } from "."; +import { PluginMethod } from "./PluginMethod"; -import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; +import { CoreClient } from "@polywrap/core-js"; import { Result, ResultErr, ResultOk } from "@polywrap/result"; -/** - * Invocable plugin method. - * - * @param args Arguments for the method, structured as - * a map, removing the chance of incorrectly ordering arguments. - * @param client The client instance requesting this invocation. - * This client will be used for any sub-invokes that occur. - */ -export type PluginMethod< - TArgs extends Record = Record, - TResult = unknown -> = (args: TArgs, client: Client) => MaybeAsync; - export abstract class PluginModule< TConfig, TEnv extends Record = Record @@ -46,7 +33,7 @@ export abstract class PluginModule< >( method: string, args: TArgs, - client: Client + client: CoreClient ): Promise> { const fn = this.getMethod(method); @@ -79,12 +66,3 @@ export abstract class PluginModule< return fn.bind(this); } } - -export type PluginPackage = { - factory: () => PluginModule; - manifest: WrapManifest; -}; - -export type PluginFactory = ( - config: TConfig -) => PluginPackage; diff --git a/packages/js/plugin/src/PluginPackage.ts b/packages/js/plugin/src/PluginPackage.ts new file mode 100644 index 0000000000..ea9517d22f --- /dev/null +++ b/packages/js/plugin/src/PluginPackage.ts @@ -0,0 +1,60 @@ +import { PluginModule } from "./PluginModule"; +import { PluginWrapper } from "./PluginWrapper"; +import { GetPluginMethodsFunc, PluginModuleWithMethods } from "./utils"; + +import { IWrapPackage, Wrapper } from "@polywrap/core-js"; +import { Result, ResultOk } from "@polywrap/result"; +import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; + +export class PluginPackage< + TConfig, + TEnv extends Record = Record +> implements IWrapPackage { + constructor( + private pluginModule: PluginModule, + private manifest: WrapManifest + ) {} + + static from< + TConfig, + TEnv extends Record = Record + >( + pluginModule: PluginModule, + manifest?: WrapManifest + ): PluginPackage; + static from = Record>( + getPluginFuncs: GetPluginMethodsFunc, + manifest?: WrapManifest + ): PluginPackage; + static from< + TConfig, + TEnv extends Record = Record + >( + pluginModuleOrGetPluginFuncs: + | PluginModule + | GetPluginMethodsFunc, + manifest?: WrapManifest + ): PluginPackage { + if (typeof pluginModuleOrGetPluginFuncs === "function") { + const getPluginFuncs = pluginModuleOrGetPluginFuncs as GetPluginMethodsFunc; + + return new PluginPackage( + new PluginModuleWithMethods(getPluginFuncs), + manifest || ({} as WrapManifest) + ) as PluginPackage; + } else { + return new PluginPackage( + pluginModuleOrGetPluginFuncs as PluginModule, + manifest || ({} as WrapManifest) + ); + } + } + + async getManifest(): Promise> { + return ResultOk(this.manifest); + } + + async createWrapper(): Promise> { + return ResultOk(new PluginWrapper(this.manifest, this.pluginModule)); + } +} diff --git a/packages/js/core/src/plugin/PluginWrapper.ts b/packages/js/plugin/src/PluginWrapper.ts similarity index 76% rename from packages/js/core/src/plugin/PluginWrapper.ts rename to packages/js/plugin/src/PluginWrapper.ts index 380e101fca..b1540953e4 100644 --- a/packages/js/core/src/plugin/PluginWrapper.ts +++ b/packages/js/plugin/src/PluginWrapper.ts @@ -1,28 +1,27 @@ +import { PluginModule } from "./PluginModule"; + import { Wrapper, - Client, + CoreClient, InvokeOptions, InvocableResult, - PluginModule, - PluginPackage, Uri, GetFileOptions, - GetManifestOptions, isBuffer, -} from "../."; - +} from "@polywrap/core-js"; import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; import { msgpackDecode } from "@polywrap/msgpack-js"; import { Tracer, TracingLevel } from "@polywrap/tracing-js"; import { Result, ResultErr, ResultOk } from "@polywrap/result"; export class PluginWrapper implements Wrapper { - private _instance: PluginModule | undefined; - - constructor(private _plugin: PluginPackage) { + constructor( + private manifest: WrapManifest, + private module: PluginModule + ) { Tracer.startSpan("PluginWrapper: constructor"); Tracer.setAttribute("args", { - plugin: this._plugin, + plugin: this.module, }); Tracer.endSpan(); } @@ -36,14 +35,14 @@ export class PluginWrapper implements Wrapper { } @Tracer.traceMethod("PluginWrapper: getManifest") - public getManifest(_?: GetManifestOptions): WrapManifest { - return this._plugin.manifest; + public getManifest(): WrapManifest { + return this.manifest; } @Tracer.traceMethod("PluginWrapper: invoke", TracingLevel.High) public async invoke( options: InvokeOptions, - client: Client + client: CoreClient ): Promise> { Tracer.setAttribute( "label", @@ -52,18 +51,13 @@ export class PluginWrapper implements Wrapper { ); const { method } = options; const args = options.args || {}; - const module = this._getInstance(); - if (!module) { - return ResultErr(Error(`PluginWrapper: module "${module}" not found.`)); - } - - if (!module.getMethod(method)) { + if (!this.module.getMethod(method)) { return ResultErr(Error(`PluginWrapper: method "${method}" not found.`)); } // Set the module's environment - await module.setEnv(options.env || {}); + this.module.setEnv(options.env || {}); let jsArgs: Record; @@ -86,7 +80,7 @@ export class PluginWrapper implements Wrapper { } // Invoke the function - const result = await module._wrap_invoke(method, jsArgs, client); + const result = await this.module._wrap_invoke(method, jsArgs, client); if (result.ok) { const data = result.value; @@ -108,9 +102,4 @@ export class PluginWrapper implements Wrapper { return ResultErr(invocationException); } } - - private _getInstance(): PluginModule { - this._instance ||= this._plugin.factory(); - return this._instance; - } } diff --git a/packages/js/plugin/src/index.ts b/packages/js/plugin/src/index.ts new file mode 100644 index 0000000000..efa3750dd0 --- /dev/null +++ b/packages/js/plugin/src/index.ts @@ -0,0 +1,5 @@ +export * from "./PluginFactory"; +export * from "./PluginMethod"; +export * from "./PluginModule"; +export * from "./PluginPackage"; +export * from "./PluginWrapper"; diff --git a/packages/js/plugin/src/utils/GetPluginMethodsFunc.ts b/packages/js/plugin/src/utils/GetPluginMethodsFunc.ts new file mode 100644 index 0000000000..9cb2bd2d81 --- /dev/null +++ b/packages/js/plugin/src/utils/GetPluginMethodsFunc.ts @@ -0,0 +1,7 @@ +import { PluginModule, PluginMethod } from ".."; + +export type GetPluginMethodsFunc< + TEnv extends Record = Record +> = ( + module: PluginModule +) => Record, unknown>>; diff --git a/packages/js/plugin/src/utils/PluginModuleWithMethods.ts b/packages/js/plugin/src/utils/PluginModuleWithMethods.ts new file mode 100644 index 0000000000..665e264fff --- /dev/null +++ b/packages/js/plugin/src/utils/PluginModuleWithMethods.ts @@ -0,0 +1,50 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +import { PluginMethod } from "../PluginMethod"; +import { PluginModule } from "../PluginModule"; +import { GetPluginMethodsFunc } from "./GetPluginMethodsFunc"; + +import { CoreClient } from "@polywrap/core-js"; +import { Result, ResultOk } from "@polywrap/result"; + +export class PluginModuleWithMethods< + TEnv extends Record = Record +> extends PluginModule { + constructor(private getPluginMethods: GetPluginMethodsFunc) { + super({} as never); + } + + async _wrap_invoke< + TArgs extends Record = Record, + TResult = unknown + >( + method: string, + args: TArgs, + client: CoreClient + ): Promise> { + const fn = this.getMethod(method); + + if (!fn) { + throw Error(`Plugin missing method "${method}"`); + } + + if (typeof fn !== "function") { + throw Error(`Plugin method "${method}" must be of type 'function'`); + } + + const data = await fn(args, client); + + return ResultOk(data); + } + + getMethod< + TArgs extends Record = Record, + TResult = unknown + >(method: string): PluginMethod | undefined { + const fn: PluginMethod | undefined = this.getPluginMethods( + this + )[method] as PluginMethod; + + return fn.bind(this); + } +} diff --git a/packages/js/plugin/src/utils/index.ts b/packages/js/plugin/src/utils/index.ts new file mode 100644 index 0000000000..6301d810d9 --- /dev/null +++ b/packages/js/plugin/src/utils/index.ts @@ -0,0 +1,2 @@ +export * from "./GetPluginMethodsFunc"; +export * from "./PluginModuleWithMethods"; diff --git a/packages/js/plugin/tsconfig.build.json b/packages/js/plugin/tsconfig.build.json new file mode 100644 index 0000000000..77aadfdd2f --- /dev/null +++ b/packages/js/plugin/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "include": [ + "./src/**/*.ts" + ], + "exclude": [ + "./src/**/__tests__" + ] +} diff --git a/packages/js/plugin/tsconfig.json b/packages/js/plugin/tsconfig.json new file mode 100644 index 0000000000..5d37204c00 --- /dev/null +++ b/packages/js/plugin/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "build" + }, + "include": [ + "./src/**/*.ts" + ], + "exclude": [] +} diff --git a/packages/js/plugins/ethereum/package.json b/packages/js/plugins/ethereum/package.json index 9829e68dd6..b32ca046d1 100644 --- a/packages/js/plugins/ethereum/package.json +++ b/packages/js/plugins/ethereum/package.json @@ -23,12 +23,13 @@ "@ethersproject/address": "5.0.7", "@ethersproject/providers": "5.0.7", "@polywrap/core-js": "0.9.3", + "@polywrap/plugin-js": "0.9.3", "ethers": "5.0.7" }, "devDependencies": { "@polywrap/client-js": "0.9.3", - "@polywrap/ens-resolver-plugin-js": "0.9.3", - "@polywrap/ipfs-plugin-js": "0.9.3", + "@polywrap/fs-resolver-plugin-js": "0.9.3", + "@polywrap/fs-plugin-js": "0.9.3", "@polywrap/test-env-js": "0.9.3", "@types/jest": "26.0.8", "@types/prettier": "2.6.0", diff --git a/packages/js/plugins/ethereum/src/__tests__/e2e.spec.ts b/packages/js/plugins/ethereum/src/__tests__/e2e.spec.ts index 5c88697103..92e0820ec0 100644 --- a/packages/js/plugins/ethereum/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/ethereum/src/__tests__/e2e.spec.ts @@ -1,10 +1,8 @@ -import { ethereumPlugin } from ".."; + import * as Schema from "../wrap"; import { PolywrapClient } from "@polywrap/client-js"; -import { ClientConfigBuilder, defaultIpfsProviders } from "@polywrap/client-config-builder-js"; -import { ensResolverPlugin } from "@polywrap/ens-resolver-plugin-js"; -import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; +import { ClientConfig } from "@polywrap/client-config-builder-js"; import { initTestEnvironment, stopTestEnvironment, @@ -16,13 +14,14 @@ import { deployStorage, addPrimitiveToArrayStorage, addStructToStorage, - setPrimitiveToStorage -} from './utils/storage'; + setPrimitiveToStorage, +} from "./utils/storage"; import { ethers, Wallet } from "ethers"; import { keccak256 } from "js-sha3"; import { Connections } from "../Connections"; import { Connection } from "../Connection"; +import { getDefaultConfig } from "./helpers/getDefaultConfig"; const { hash: namehash } = require("eth-ens-namehash"); const contracts = { @@ -33,9 +32,12 @@ const contracts = { SimpleStorage: { abi: require("./contracts/SimpleStorage.ABI.json"), bytecode: `0x${require("./contracts/SimpleStorage.Bytecode.json").object}`, - abiSinglePrimitiveMethod: '[{"inputs":[],"name":"get","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]', - abiArrayPrimitivesMethod: '[{"inputs":[],"name":"getSimple","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"}]', - abiArrayStructsMethod: '[{"inputs":[],"name":"getJobs","outputs":[{"components":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct SimpleStorage.Job[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"}]', + abiSinglePrimitiveMethod: + '[{"inputs":[],"name":"get","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]', + abiArrayPrimitivesMethod: + '[{"inputs":[],"name":"getSimple","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"}]', + abiArrayStructsMethod: + '[{"inputs":[],"name":"getJobs","outputs":[{"components":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct SimpleStorage.Job[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"}]', }, ViewMethods: { abi: require("./contracts/ViewMethods.ABI.json"), @@ -50,6 +52,7 @@ describe("Ethereum Plugin", () => { let ensAddress: string; let resolverAddress: string; let registrarAddress: string; + let defaultConfig: Partial; let viewMethodsAddress: string; const signer = "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"; @@ -75,36 +78,8 @@ describe("Ethereum Plugin", () => { defaultNetwork: "testnet", }); - client = new PolywrapClient({ - envs: [ - { - uri: "wrap://ens/ipfs.polywrap.eth", - env: { - provider: providers.ipfs, - fallbackProviders: defaultIpfsProviders, - }, - }, - ], - plugins: [ - { - uri: "wrap://ens/ethereum.polywrap.eth", - plugin: ethereumPlugin({ connections }), - }, - { - uri: "wrap://ens/ipfs.polywrap.eth", - plugin: ipfsPlugin({ }), - }, - { - uri: "wrap://ens/ens-resolver.polywrap.eth", - plugin: ensResolverPlugin({ - addresses: { - testnet: ensAddress, - }, - }), - }, - ], - }); - + defaultConfig = getDefaultConfig(connections); + client = new PolywrapClient(defaultConfig); await buildWrapper(wrapperPath); const response = await client.invoke({ @@ -143,15 +118,22 @@ describe("Ethereum Plugin", () => { }); it("callContractView (primitive value - string ABI)", async () => { - const storageAddress = await deployStorage(contracts.SimpleStorage.abi, contracts.SimpleStorage.bytecode) - await setPrimitiveToStorage(contracts.SimpleStorage.abi, storageAddress, "100"); + const storageAddress = await deployStorage( + contracts.SimpleStorage.abi, + contracts.SimpleStorage.bytecode + ); + await setPrimitiveToStorage( + contracts.SimpleStorage.abi, + storageAddress, + "100" + ); const response = await client.invoke({ uri, method: "callContractView", args: { address: storageAddress, - method: 'function get() public view returns (uint256)', + method: "function get() public view returns (uint256)", args: [], }, }); @@ -161,8 +143,15 @@ describe("Ethereum Plugin", () => { }); it("callContractView (primitive value - JSON ABI)", async () => { - const storageAddress = await deployStorage(contracts.SimpleStorage.abi, contracts.SimpleStorage.bytecode) - await setPrimitiveToStorage(contracts.SimpleStorage.abi, storageAddress, "100"); + const storageAddress = await deployStorage( + contracts.SimpleStorage.abi, + contracts.SimpleStorage.bytecode + ); + await setPrimitiveToStorage( + contracts.SimpleStorage.abi, + storageAddress, + "100" + ); const response = await client.invoke({ uri, @@ -179,16 +168,27 @@ describe("Ethereum Plugin", () => { }); it("callContractView (primitives array - string ABI)", async () => { - const storageAddress = await deployStorage(contracts.SimpleStorage.abi, contracts.SimpleStorage.bytecode) - await addPrimitiveToArrayStorage(contracts.SimpleStorage.abi, storageAddress, "100"); - await addPrimitiveToArrayStorage(contracts.SimpleStorage.abi, storageAddress, "90"); + const storageAddress = await deployStorage( + contracts.SimpleStorage.abi, + contracts.SimpleStorage.bytecode + ); + await addPrimitiveToArrayStorage( + contracts.SimpleStorage.abi, + storageAddress, + "100" + ); + await addPrimitiveToArrayStorage( + contracts.SimpleStorage.abi, + storageAddress, + "90" + ); const response = await client.invoke({ uri, method: "callContractView", args: { address: storageAddress, - method: 'function getSimple() public view returns (uint256[] memory)', + method: "function getSimple() public view returns (uint256[] memory)", args: [], }, }); @@ -196,7 +196,7 @@ describe("Ethereum Plugin", () => { if (!response.ok) fail(response.error); if (!response.value) { - throw new Error('Empty data on view call, expecting JSON'); + throw new Error("Empty data on view call, expecting JSON"); } const result = JSON.parse(response.value); @@ -206,9 +206,20 @@ describe("Ethereum Plugin", () => { }); it("callContractView (primitives array - JSON ABI)", async () => { - const storageAddress = await deployStorage(contracts.SimpleStorage.abi, contracts.SimpleStorage.bytecode) - await addPrimitiveToArrayStorage(contracts.SimpleStorage.abi, storageAddress, "100"); - await addPrimitiveToArrayStorage(contracts.SimpleStorage.abi, storageAddress, "90"); + const storageAddress = await deployStorage( + contracts.SimpleStorage.abi, + contracts.SimpleStorage.bytecode + ); + await addPrimitiveToArrayStorage( + contracts.SimpleStorage.abi, + storageAddress, + "100" + ); + await addPrimitiveToArrayStorage( + contracts.SimpleStorage.abi, + storageAddress, + "90" + ); const response = await client.invoke({ uri, @@ -223,7 +234,7 @@ describe("Ethereum Plugin", () => { if (!response.ok) fail(response.error); if (!response.value) { - throw new Error('Empty data on view call, expecting JSON'); + throw new Error("Empty data on view call, expecting JSON"); } const result = JSON.parse(response.value); @@ -233,9 +244,20 @@ describe("Ethereum Plugin", () => { }); it("callContractView (primitives array - non-array JSON ABI)", async () => { - const storageAddress = await deployStorage(contracts.SimpleStorage.abi, contracts.SimpleStorage.bytecode) - await addPrimitiveToArrayStorage(contracts.SimpleStorage.abi, storageAddress, "100"); - await addPrimitiveToArrayStorage(contracts.SimpleStorage.abi, storageAddress, "90"); + const storageAddress = await deployStorage( + contracts.SimpleStorage.abi, + contracts.SimpleStorage.bytecode + ); + await addPrimitiveToArrayStorage( + contracts.SimpleStorage.abi, + storageAddress, + "100" + ); + await addPrimitiveToArrayStorage( + contracts.SimpleStorage.abi, + storageAddress, + "90" + ); const response = await client.invoke({ uri, @@ -250,7 +272,7 @@ describe("Ethereum Plugin", () => { if (!response.ok) fail(response.error); if (!response.value) { - throw new Error('Empty data on view call, expecting JSON'); + throw new Error("Empty data on view call, expecting JSON"); } const result = JSON.parse(response.value); @@ -260,7 +282,10 @@ describe("Ethereum Plugin", () => { }); it("callContractView (struct array empty)", async () => { - const queueAddress = await deployStorage(contracts.SimpleStorage.abi, contracts.SimpleStorage.bytecode) + const queueAddress = await deployStorage( + contracts.SimpleStorage.abi, + contracts.SimpleStorage.bytecode + ); const response = await client.invoke({ uri, @@ -273,12 +298,18 @@ describe("Ethereum Plugin", () => { }); if (!response.ok) fail(response.error); - expect(response.value).toEqual('[]'); + expect(response.value).toEqual("[]"); }); it("callContractView (struct array single element)", async () => { - const queueAddress = await deployStorage(contracts.SimpleStorage.abi, contracts.SimpleStorage.bytecode) - await addStructToStorage(contracts.SimpleStorage.abi, queueAddress, [queueAddress, "100"]); + const queueAddress = await deployStorage( + contracts.SimpleStorage.abi, + contracts.SimpleStorage.bytecode + ); + await addStructToStorage(contracts.SimpleStorage.abi, queueAddress, [ + queueAddress, + "100", + ]); const response = await client.invoke({ uri, @@ -293,15 +324,24 @@ describe("Ethereum Plugin", () => { if (!response.ok) fail(response.error); if (!response.value) { - throw new Error('Empty data on view call, expecting JSON'); + throw new Error("Empty data on view call, expecting JSON"); } expect(response.value).toEqual(`[["${queueAddress}","100"]]`) }); it("callContractView (struct array multiple elements)", async () => { - const queueAddress = await deployStorage(contracts.SimpleStorage.abi, contracts.SimpleStorage.bytecode) - await addStructToStorage(contracts.SimpleStorage.abi, queueAddress, [queueAddress, "100"]); - await addStructToStorage(contracts.SimpleStorage.abi, queueAddress, [ensAddress, "99"]); + const queueAddress = await deployStorage( + contracts.SimpleStorage.abi, + contracts.SimpleStorage.bytecode + ); + await addStructToStorage(contracts.SimpleStorage.abi, queueAddress, [ + queueAddress, + "100", + ]); + await addStructToStorage(contracts.SimpleStorage.abi, queueAddress, [ + ensAddress, + "99", + ]); const response = await client.invoke({ uri, @@ -316,7 +356,7 @@ describe("Ethereum Plugin", () => { if (!response.ok) fail(response.error); if (!response.value) { - throw new Error('Empty data on view call, expecting JSON'); + throw new Error("Empty data on view call, expecting JSON"); } const result = JSON.parse(response.value); @@ -707,28 +747,27 @@ describe("Ethereum Plugin", () => { const domain = "testwhatever10.eth"; const newOwner = "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0"; - const listenerPromise = client.invoke({ - uri, - method: "waitForEvent", - args: { - address: ensAddress, - event: event, - args: [namehash(domain)], - timeout: 20000, - }, - }) - .then((result) => { - if (result.ok) return result.value - else fail(result.error) - }) - .then((result: Schema.EventNotification) => { - expect(typeof result.data === "string").toBe(true); - expect(typeof result.address === "string").toBe(true); - expect(result.log).toBeDefined(); - expect(typeof result.log.transactionHash === "string").toBe( - true - ); - }); + const listenerPromise = client + .invoke({ + uri, + method: "waitForEvent", + args: { + address: ensAddress, + event: event, + args: [namehash(domain)], + timeout: 20000, + }, + }) + .then((result) => { + if (result.ok) return result.value; + else fail(result.error); + }) + .then((result: Schema.EventNotification) => { + expect(typeof result.data === "string").toBe(true); + expect(typeof result.address === "string").toBe(true); + expect(result.log).toBeDefined(); + expect(typeof result.log.transactionHash === "string").toBe(true); + }); await client.invoke({ uri, @@ -770,16 +809,14 @@ describe("Ethereum Plugin", () => { }, }) .then((result) => { - if (result.ok) return result.value - else fail(result.error) + if (result.ok) return result.value; + else fail(result.error); }) .then((result: Schema.EventNotification) => { expect(typeof result.data === "string").toBe(true); expect(typeof result.address === "string").toBe(true); expect(result.log).toBeDefined(); - expect(typeof result.log.transactionHash === "string").toBe( - true - ); + expect(typeof result.log.transactionHash === "string").toBe(true); }); await client.invoke({ @@ -811,9 +848,9 @@ describe("Ethereum Plugin", () => { method: "getNetwork", args: { connection: { - networkNameOrChainId: "mainnet" - } - } + networkNameOrChainId: "mainnet", + }, + }, }); if (!mainnetNetwork.ok) fail(mainnetNetwork.error); @@ -830,9 +867,9 @@ describe("Ethereum Plugin", () => { method: "getNetwork", args: { connection: { - node: "https://polygon-rpc.com" - } - } + node: "https://polygon-rpc.com", + }, + }, }); if (!polygonNetwork.ok) fail(polygonNetwork.error); @@ -843,9 +880,7 @@ describe("Ethereum Plugin", () => { }); it("getNetwork - mainnet with env", async () => { - const config = new ClientConfigBuilder() - .add(client.getConfig()) - .add({ + const mainnetClient = new PolywrapClient({ envs: [ { uri: "wrap://ens/ethereum.polywrap.eth", @@ -856,11 +891,7 @@ describe("Ethereum Plugin", () => { }, }, ], - }) - .build(); - const mainnetClient = new PolywrapClient( - config - ); + }); const mainnetNetwork = await mainnetClient.invoke({ uri, method: "getNetwork", @@ -876,9 +907,7 @@ describe("Ethereum Plugin", () => { }); it("getNetwork - polygon with env", async () => { - const config = new ClientConfigBuilder() - .add(client.getConfig()) - .add({ + const polygonClient = new PolywrapClient({ envs: [ { uri: "wrap://ens/ethereum.polywrap.eth", @@ -889,11 +918,7 @@ describe("Ethereum Plugin", () => { }, }, ], - }) - .build(); - const polygonClient = new PolywrapClient( - config - ); + }); const polygonNetwork = await polygonClient.invoke({ uri, method: "getNetwork", @@ -909,11 +934,15 @@ describe("Ethereum Plugin", () => { let result = await client.invoke({ uri, method: "requestAccounts", - }) + }); result = result as { ok: false; error: Error | undefined }; // eth_requestAccounts is not supported by Ganache // this RPC error indicates that the method call was attempted - expect(result.error?.message.indexOf("Method eth_requestAccounts not supported")).toBeGreaterThanOrEqual(0); + expect( + result.error?.message.indexOf( + "Method eth_requestAccounts not supported" + ) + ).toBeGreaterThanOrEqual(0); }); it("callContractMethod", async () => { @@ -929,9 +958,9 @@ describe("Ethereum Plugin", () => { value: null, nonce: null, gasPrice: "50", - gasLimit: "200000" - } - } + gasLimit: "200000", + }, + }, }); if (!response.ok) fail(response.error); @@ -1025,8 +1054,9 @@ describe("Ethereum Plugin", () => { uri, method: "sendRPC", args: { - method: "eth_blockNumber", params: [] - } + method: "eth_blockNumber", + params: [], + }, }); if (!res.ok) fail(res.error); @@ -1039,8 +1069,8 @@ describe("Ethereum Plugin", () => { method: "deployContract", args: { abi: JSON.stringify(contracts.StructArg.abi), - bytecode: contracts.StructArg.bytecode - } + bytecode: contracts.StructArg.bytecode, + }, }); if (!response1.ok) fail(response1.error); @@ -1060,15 +1090,13 @@ describe("Ethereum Plugin", () => { args: { address: address, method: "function method(tuple(string str, uint256 unsigned256, uint256[] unsigned256Array) _arg) returns (string, uint256)", - args: [structArg] - } + args: [structArg], + }, }); if (!response2.ok) fail(response2.error); expect(response2.value).toBeDefined(); - expect( - response2.value?.transactionHash - ).toBeDefined(); + expect(response2.value?.transactionHash).toBeDefined(); }); describe("ViewMethods", () => { diff --git a/packages/js/plugins/ethereum/src/__tests__/helpers/getDefaultConfig.ts b/packages/js/plugins/ethereum/src/__tests__/helpers/getDefaultConfig.ts new file mode 100644 index 0000000000..dc37a50259 --- /dev/null +++ b/packages/js/plugins/ethereum/src/__tests__/helpers/getDefaultConfig.ts @@ -0,0 +1,45 @@ +import { coreInterfaceUris } from "@polywrap/core-js"; +import { fileSystemPlugin } from "@polywrap/fs-plugin-js"; +import { fileSystemResolverPlugin } from "@polywrap/fs-resolver-plugin-js"; +import { ethereumPlugin, Connections } from "../.."; +import { providers } from "@polywrap/test-env-js"; +import { + defaultIpfsProviders, + ClientConfig, +} from "@polywrap/client-config-builder-js"; + +export const getDefaultConfig = ( + connections: Connections +): Partial => { + return { + envs: [ + { + uri: "wrap://ens/ipfs.polywrap.eth", + env: { + provider: providers.ipfs, + fallbackProviders: defaultIpfsProviders, + }, + }, + ], + interfaces: [ + { + interface: coreInterfaceUris.uriResolver, + implementations: ["wrap://ens/fs-resolver.polywrap.eth"], + }, + ], + packages: [ + { + uri: "wrap://ens/ethereum.polywrap.eth", + package: ethereumPlugin({ connections }), + }, + { + uri: "wrap://ens/fs-resolver.polywrap.eth", + package: fileSystemResolverPlugin({}), + }, + { + uri: "wrap://ens/fs.polywrap.eth", + package: fileSystemPlugin({}), + }, + ], + }; +}; diff --git a/packages/js/plugins/ethereum/src/index.ts b/packages/js/plugins/ethereum/src/index.ts index 7c4bb73f1b..a6f95bb920 100644 --- a/packages/js/plugins/ethereum/src/index.ts +++ b/packages/js/plugins/ethereum/src/index.ts @@ -1,5 +1,5 @@ import { - Client, + CoreClient, Module, Args_callContractView, Args_callContractStatic, @@ -45,7 +45,7 @@ import { Connections } from "./Connections"; import { ethers } from "ethers"; import { defaultAbiCoder } from "ethers/lib/utils"; -import { PluginFactory } from "@polywrap/core-js"; +import { PluginFactory, PluginPackage } from "@polywrap/plugin-js"; export * from "./Connection"; export * from "./Connections"; @@ -64,7 +64,7 @@ export class EthereumPlugin extends Module { async callContractView( args: Args_callContractView, - _client: Client + _client: CoreClient ): Promise { const connection = await this._getConnection(args.connection); const abi = constructAbi(args.method); @@ -76,7 +76,7 @@ export class EthereumPlugin extends Module { async callContractStatic( args: Args_callContractStatic, - _client: Client + _client: CoreClient ): Promise { const connection = await this._getConnection(args.connection); const abi = constructAbi(args.method); @@ -110,7 +110,10 @@ export class EthereumPlugin extends Module { } } - async getBalance(args: Args_getBalance, _client: Client): Promise { + async getBalance( + args: Args_getBalance, + _client: CoreClient + ): Promise { const connection = await this._getConnection(args.connection); return ( await connection @@ -121,14 +124,14 @@ export class EthereumPlugin extends Module { async encodeParams( args: Args_encodeParams, - _client: Client + _client: CoreClient ): Promise { return defaultAbiCoder.encode(args.types, parseArgs(args.values)); } async encodeFunction( args: Args_encodeFunction, - _client: Client + _client: CoreClient ): Promise { const functionInterface = ethers.Contract.getInterface([args.method]); return functionInterface.encodeFunctionData( @@ -139,28 +142,28 @@ export class EthereumPlugin extends Module { async solidityPack( args: Args_solidityPack, - _client: Client + _client: CoreClient ): Promise { return ethers.utils.solidityPack(args.types, parseArgs(args.values)); } async solidityKeccak256( args: Args_solidityKeccak256, - _client: Client + _client: CoreClient ): Promise { return ethers.utils.solidityKeccak256(args.types, parseArgs(args.values)); } async soliditySha256( args: Args_soliditySha256, - _client: Client + _client: CoreClient ): Promise { return ethers.utils.soliditySha256(args.types, parseArgs(args.values)); } async getSignerAddress( args: Args_getSignerAddress, - _client: Client + _client: CoreClient ): Promise { const connection = await this._getConnection(args.connection); return await connection.getSigner().getAddress(); @@ -168,7 +171,7 @@ export class EthereumPlugin extends Module { async getSignerBalance( args: Args_getSignerBalance, - _client: Client + _client: CoreClient ): Promise { const connection = await this._getConnection(args.connection); return ( @@ -178,7 +181,7 @@ export class EthereumPlugin extends Module { async getSignerTransactionCount( args: Args_getSignerTransactionCount, - _client: Client + _client: CoreClient ): Promise { const connection = await this._getConnection(args.connection); return ( @@ -188,14 +191,17 @@ export class EthereumPlugin extends Module { ).toString(); } - async getGasPrice(args: Args_getGasPrice, _client: Client): Promise { + async getGasPrice( + args: Args_getGasPrice, + _client: CoreClient + ): Promise { const connection = await this._getConnection(args.connection); return (await connection.getSigner().getGasPrice()).toString(); } async estimateTransactionGas( args: Args_estimateTransactionGas, - _client: Client + _client: CoreClient ): Promise { const connection = await this._getConnection(args.connection); return ( @@ -205,7 +211,7 @@ export class EthereumPlugin extends Module { async estimateContractCallGas( args: Args_estimateContractCallGas, - _client: Client + _client: CoreClient ): Promise { const connection = await this._getConnection(args.connection); const abi = constructAbi(args.method); @@ -227,7 +233,7 @@ export class EthereumPlugin extends Module { async checkAddress( args: Args_checkAddress, - _client: Client + _client: CoreClient ): Promise { let address = args.address; @@ -248,19 +254,19 @@ export class EthereumPlugin extends Module { } } - async toWei(args: Args_toWei, _client: Client): Promise { + async toWei(args: Args_toWei, _client: CoreClient): Promise { const weiAmount = ethers.utils.parseEther(args.eth); return weiAmount.toString(); } - async toEth(args: Args_toEth, _client: Client): Promise { + async toEth(args: Args_toEth, _client: CoreClient): Promise { const etherAmount = ethers.utils.formatEther(args.wei); return etherAmount.toString(); } async waitForEvent( args: Args_waitForEvent, - _client: Client + _client: CoreClient ): Promise { const connection = await this._getConnection(args.connection); const abi = constructAbi(args.event); @@ -293,7 +299,7 @@ export class EthereumPlugin extends Module { async awaitTransaction( args: Args_awaitTransaction, - _client: Client + _client: CoreClient ): Promise { const connection = await this._getConnection(args.connection); const provider = connection.getProvider(); @@ -307,7 +313,10 @@ export class EthereumPlugin extends Module { return Mapping.toTxReceipt(res); } - async getNetwork(args: Args_getNetwork, _client: Client): Promise { + async getNetwork( + args: Args_getNetwork, + _client: CoreClient + ): Promise { const connection = await this._getConnection(args.connection); const provider = connection.getProvider(); const network = await provider.getNetwork(); @@ -320,7 +329,7 @@ export class EthereumPlugin extends Module { async requestAccounts( args: Args_requestAccounts, - _client: Client + _client: CoreClient ): Promise { const connection = await this._getConnection(args.connection); const provider = connection.getProvider(); @@ -329,7 +338,7 @@ export class EthereumPlugin extends Module { public async callContractMethod( args: Args_callContractMethod, - _client: Client + _client: CoreClient ): Promise { const res = await this._callContractMethod(args); return Mapping.toTxResponse(res); @@ -337,7 +346,7 @@ export class EthereumPlugin extends Module { public async callContractMethodAndWait( args: Args_callContractMethodAndWait, - _client: Client + _client: CoreClient ): Promise { const response = await this._callContractMethod(args); const res = await response.wait(); @@ -346,7 +355,7 @@ export class EthereumPlugin extends Module { public async sendTransaction( args: Args_sendTransaction, - _client: Client + _client: CoreClient ): Promise { const connection = await this._getConnection(args.connection); const signer = connection.getSigner(); @@ -356,7 +365,7 @@ export class EthereumPlugin extends Module { public async sendTransactionAndWait( args: Args_sendTransactionAndWait, - _client: Client + _client: CoreClient ): Promise { const connection = await this._getConnection(args.connection); const signer = connection.getSigner(); @@ -369,7 +378,7 @@ export class EthereumPlugin extends Module { public async deployContract( args: Args_deployContract, - _client: Client + _client: CoreClient ): Promise { const connection = await this._getConnection(args.connection); const signer = connection.getSigner(); @@ -382,13 +391,16 @@ export class EthereumPlugin extends Module { public async signMessage( args: Args_signMessage, - _client: Client + _client: CoreClient ): Promise { const connection = await this._getConnection(args.connection); return await connection.getSigner().signMessage(args.message); } - public async sendRPC(args: Args_sendRPC, _client: Client): Promise { + public async sendRPC( + args: Args_sendRPC, + _client: CoreClient + ): Promise { const connection = await this._getConnection(args.connection); const provider = connection.getProvider(); const response = await provider.send(args.method, args.params); @@ -423,11 +435,6 @@ export class EthereumPlugin extends Module { export const ethereumPlugin: PluginFactory = ( config: EthereumPluginConfig -) => { - return { - factory: () => new EthereumPlugin(config), - manifest, - }; -}; +) => new PluginPackage(new EthereumPlugin(config), manifest); export const plugin = ethereumPlugin; diff --git a/packages/js/plugins/file-system/jest.config.js b/packages/js/plugins/file-system/jest.config.js index 38888109ca..cb254a6963 100644 --- a/packages/js/plugins/file-system/jest.config.js +++ b/packages/js/plugins/file-system/jest.config.js @@ -1,13 +1,8 @@ module.exports = { - "roots": [ - "/src" - ], - "testMatch": [ - "**/__tests__/**/*.+(ts|tsx|js)", - "**/?(*.)+(spec|test).+(ts|tsx|js)" - ], - "transform": { - "^.+\\.(ts|tsx)$": "ts-jest" + roots: ["/src"], + testMatch: ["**/?(*.)+(spec|test).+(ts|tsx|js)"], + transform: { + "^.+\\.(ts|tsx)$": "ts-jest", }, - testEnvironment: 'node' -} + testEnvironment: "node", +}; diff --git a/packages/js/plugins/file-system/package.json b/packages/js/plugins/file-system/package.json index 2824be6569..b953a196f5 100644 --- a/packages/js/plugins/file-system/package.json +++ b/packages/js/plugins/file-system/package.json @@ -20,15 +20,12 @@ "test:watch": "jest --watch --passWithNoTests --verbose" }, "dependencies": { - "@polywrap/core-js": "0.9.3" + "@polywrap/core-js": "0.9.3", + "@polywrap/plugin-js": "0.9.3" }, "devDependencies": { "@polywrap/client-js": "0.9.3", - "@polywrap/ens-resolver-plugin-js": "0.9.3", - "@polywrap/ethereum-plugin-js": "0.9.3", - "@polywrap/ipfs-plugin-js": "0.9.3", - "@polywrap/test-cases": "0.9.3", - "@polywrap/test-env-js": "0.9.3", + "@polywrap/uri-resolvers-js": "0.9.3", "@types/jest": "26.0.8", "@types/prettier": "2.6.0", "jest": "26.6.3", diff --git a/packages/js/plugins/file-system/src/__tests__/e2e.spec.ts b/packages/js/plugins/file-system/src/__tests__/e2e.spec.ts index f86ff77a17..4e9b2103dd 100644 --- a/packages/js/plugins/file-system/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/file-system/src/__tests__/e2e.spec.ts @@ -1,5 +1,6 @@ import { fileSystemPlugin } from "../index"; -import { PolywrapClient, PolywrapClientConfig } from "@polywrap/client-js"; +import { PolywrapClient } from "@polywrap/client-js"; +import { UriResolver } from "@polywrap/uri-resolvers-js"; import { FileSystem_Module, FileSystem_EncodingEnum } from "../wrap"; import fs from "fs"; import path from "path"; @@ -25,16 +26,15 @@ describe("FileSystem plugin", () => { beforeAll(async () => { await cleanUpTempFiles(); - const config: Partial = { - plugins: [ - { + client = new PolywrapClient( + { + resolver: UriResolver.from({ uri: "wrap://ens/fs.polywrap.eth", - plugin: fileSystemPlugin({ }), - }, - ], - }; - - client = new PolywrapClient(config); + package: fileSystemPlugin({}), + }), + }, + { noDefaults: true } + ); }); afterEach(async () => { @@ -48,7 +48,7 @@ describe("FileSystem plugin", () => { { path: sampleFilePath }, client ); - + if (!result.ok) fail(result.error); expect(result.value).toEqual(new Uint8Array(expectedContents)); }); @@ -61,7 +61,7 @@ describe("FileSystem plugin", () => { client ); - result = result as { ok: false, error: Error | undefined }; + result = result as { ok: false; error: Error | undefined }; expect(result.error).toBeTruthy(); expect(result.ok).toBeFalsy(); }); diff --git a/packages/js/plugins/file-system/src/index.ts b/packages/js/plugins/file-system/src/index.ts index 5666f72fb9..0f02710860 100644 --- a/packages/js/plugins/file-system/src/index.ts +++ b/packages/js/plugins/file-system/src/index.ts @@ -1,5 +1,5 @@ import { - Client, + CoreClient, Module, manifest, Args_readFile, @@ -13,12 +13,15 @@ import { import fileSystemEncodingToBufferEncoding from "./utils/fileSystemEncodingToBufferEncoding"; import fs from "fs"; -import { PluginFactory } from "@polywrap/core-js"; +import { PluginFactory, PluginPackage } from "@polywrap/plugin-js"; type NoConfig = Record; export class FileSystemPlugin extends Module { - async readFile(args: Args_readFile, _client: Client): Promise { + async readFile( + args: Args_readFile, + _client: CoreClient + ): Promise { return fs.promises .readFile(args.path) .then((buffer) => new Uint8Array(buffer)); @@ -26,27 +29,27 @@ export class FileSystemPlugin extends Module { async readFileAsString( args: Args_readFileAsString, - _client: Client + _client: CoreClient ): Promise { return fs.promises.readFile(args.path, { encoding: fileSystemEncodingToBufferEncoding(args.encoding), }); } - async exists(args: Args_exists, _client: Client): Promise { + async exists(args: Args_exists, _client: CoreClient): Promise { return fs.existsSync(args.path); } async writeFile( args: Args_writeFile, - _client: Client + _client: CoreClient ): Promise { await fs.promises.writeFile(args.path, Buffer.from(args.data)); return true; } - async mkdir(args: Args_mkdir, _client: Client): Promise { + async mkdir(args: Args_mkdir, _client: CoreClient): Promise { await fs.promises.mkdir(args.path, { recursive: args.recursive ?? false, }); @@ -54,7 +57,7 @@ export class FileSystemPlugin extends Module { return true; } - async rm(args: Args_rm, _client: Client): Promise { + async rm(args: Args_rm, _client: CoreClient): Promise { await fs.promises.rm(args.path, { recursive: args.recursive ?? false, force: args.force ?? false, @@ -63,17 +66,13 @@ export class FileSystemPlugin extends Module { return true; } - async rmdir(args: Args_rmdir, _client: Client): Promise { + async rmdir(args: Args_rmdir, _client: CoreClient): Promise { await fs.promises.rmdir(args.path); return true; } } -export const fileSystemPlugin: PluginFactory = () => { - return { - factory: () => new FileSystemPlugin({}), - manifest, - }; -}; +export const fileSystemPlugin: PluginFactory = () => + new PluginPackage(new FileSystemPlugin({}), manifest); export const plugin = fileSystemPlugin; diff --git a/packages/js/plugins/http/jest.config.js b/packages/js/plugins/http/jest.config.js index f0f063c0ce..9a342dfeda 100644 --- a/packages/js/plugins/http/jest.config.js +++ b/packages/js/plugins/http/jest.config.js @@ -1,22 +1,11 @@ module.exports = { - "roots": [ - "/src" - ], - "testMatch": [ - "**/__tests__/**/*.+(ts|tsx|js)", - "**/?(*.)+(spec|test).+(ts|tsx|js)" - ], - "transform": { - "^.+\\.(ts|tsx)$": "ts-jest" + roots: ["/src"], + testMatch: ["**/?(*.)+(spec|test).+(ts|tsx|js)"], + transform: { + "^.+\\.(ts|tsx)$": "ts-jest", }, - modulePathIgnorePatterns: [ - "/src/__tests__/e2e/integration/" - ], - testPathIgnorePatterns: [ - "/src/__tests__/e2e/integration/" - ], - transformIgnorePatterns: [ - "/src/__tests__/e2e/integration/" - ], - testEnvironment: 'node' -} + modulePathIgnorePatterns: ["/src/__tests__/e2e/integration/"], + testPathIgnorePatterns: ["/src/__tests__/e2e/integration/"], + transformIgnorePatterns: ["/src/__tests__/e2e/integration/"], + testEnvironment: "node", +}; diff --git a/packages/js/plugins/http/package.json b/packages/js/plugins/http/package.json index 2c83d35e86..d1caf84257 100644 --- a/packages/js/plugins/http/package.json +++ b/packages/js/plugins/http/package.json @@ -21,13 +21,15 @@ }, "dependencies": { "@polywrap/core-js": "0.9.3", + "@polywrap/plugin-js": "0.9.3", "axios": "0.21.4" }, "devDependencies": { "@polywrap/client-js": "0.9.3", - "@polywrap/ens-resolver-plugin-js": "0.9.3", - "@polywrap/ipfs-plugin-js": "0.9.3", - "@polywrap/test-env-js": "0.9.3", + "@polywrap/uri-resolvers-js": "0.9.3", + "@polywrap/fs-resolver-plugin-js": "0.9.3", + "@polywrap/fs-plugin-js": "0.9.3", + "@polywrap/uri-resolver-extensions-js": "0.9.3", "@types/jest": "26.0.8", "@types/prettier": "2.6.0", "jest": "26.6.3", diff --git a/packages/js/plugins/http/src/__tests__/e2e/e2e.spec.ts b/packages/js/plugins/http/src/__tests__/e2e/e2e.spec.ts index 4b1b896d5d..8c93d0c937 100644 --- a/packages/js/plugins/http/src/__tests__/e2e/e2e.spec.ts +++ b/packages/js/plugins/http/src/__tests__/e2e/e2e.spec.ts @@ -2,6 +2,8 @@ import { httpPlugin } from "../.."; import { Http_Response } from "../../wrap"; import { PolywrapClient } from "@polywrap/client-js"; +import { UriResolver } from "@polywrap/uri-resolvers-js"; + import nock from "nock"; jest.setTimeout(360000); @@ -15,14 +17,15 @@ describe("e2e tests for HttpPlugin", () => { let polywrapClient: PolywrapClient; beforeEach(() => { - polywrapClient = new PolywrapClient({ - plugins: [ - { + polywrapClient = new PolywrapClient( + { + resolver: UriResolver.from({ uri: "wrap://ens/http.polywrap.eth", - plugin: httpPlugin({}), - }, - ], - }); + package: httpPlugin({}), + }), + }, + { noDefaults: true } + ); }); describe("get method", () => { @@ -42,7 +45,7 @@ describe("e2e tests for HttpPlugin", () => { }, }, }); - + if (!response.ok) fail(response.error); expect(response.value).toBeDefined(); expect(response.value?.status).toBe(200); @@ -130,7 +133,7 @@ describe("e2e tests for HttpPlugin", () => { }, }); - response = response as { ok: false, error: Error | undefined }; + response = response as { ok: false; error: Error | undefined }; expect(response.error).toBeDefined(); expect(response.ok).toBeFalsy(); }); @@ -280,7 +283,7 @@ describe("e2e tests for HttpPlugin", () => { }, }); - response = response as { ok: false, error: Error | undefined }; + response = response as { ok: false; error: Error | undefined }; expect(response.error).toBeDefined(); expect(response.ok).toBeFalsy(); }); diff --git a/packages/js/plugins/http/src/__tests__/e2e/integration.spec.ts b/packages/js/plugins/http/src/__tests__/e2e/integration.spec.ts index 3cdbfbf1cb..ac9e083bcf 100644 --- a/packages/js/plugins/http/src/__tests__/e2e/integration.spec.ts +++ b/packages/js/plugins/http/src/__tests__/e2e/integration.spec.ts @@ -1,9 +1,9 @@ -import { httpPlugin } from "../.."; import { Http_Response } from "../../wrap"; import { PolywrapClient } from "@polywrap/client-js"; import { buildWrapper } from "@polywrap/test-env-js"; import nock from "nock"; +import { getClient } from "../helpers/getClient"; jest.setTimeout(360000); @@ -20,14 +20,7 @@ describe("e2e tests for HttpPlugin", () => { const uri = `fs/${wrapperPath}/build`; beforeAll(async () => { - client = new PolywrapClient({ - plugins: [ - { - uri: "wrap://ens/http.polywrap.eth", - plugin: httpPlugin({}), - }, - ], - }); + client = getClient(); await buildWrapper(wrapperPath); }); diff --git a/packages/js/plugins/http/src/__tests__/helpers/getClient.ts b/packages/js/plugins/http/src/__tests__/helpers/getClient.ts new file mode 100644 index 0000000000..f6a55bd675 --- /dev/null +++ b/packages/js/plugins/http/src/__tests__/helpers/getClient.ts @@ -0,0 +1,48 @@ +import { + RecursiveResolver, + PackageToWrapperCacheResolver, + WrapperCache, + StaticResolver, +} from "@polywrap/uri-resolvers-js"; +import { coreInterfaceUris } from "@polywrap/core-js"; +import { PolywrapClient } from "@polywrap/client-js"; +import { fileSystemPlugin } from "@polywrap/fs-plugin-js"; +import { fileSystemResolverPlugin } from "@polywrap/fs-resolver-plugin-js"; +import { ExtendableUriResolver } from "@polywrap/uri-resolver-extensions-js"; +import { httpPlugin } from "../.."; + +export const getClient = () => { + return new PolywrapClient( + { + interfaces: [ + { + interface: coreInterfaceUris.uriResolver, + implementations: ["wrap://ens/fs-resolver.polywrap.eth"], + }, + ], + resolver: RecursiveResolver.from( + PackageToWrapperCacheResolver.from( + [ + StaticResolver.from([ + { + uri: "wrap://ens/http.polywrap.eth", + package: httpPlugin({}), + }, + { + uri: "wrap://ens/fs-resolver.polywrap.eth", + package: fileSystemResolverPlugin({}), + }, + { + uri: "wrap://ens/fs.polywrap.eth", + package: fileSystemPlugin({}), + }, + ]), + new ExtendableUriResolver(), + ], + new WrapperCache() + ) + ), + }, + { noDefaults: true } + ); +}; diff --git a/packages/js/plugins/http/src/__tests__/unit/index.test.ts b/packages/js/plugins/http/src/__tests__/unit/index.test.ts index 43a9afa90d..2157ccc202 100644 --- a/packages/js/plugins/http/src/__tests__/unit/index.test.ts +++ b/packages/js/plugins/http/src/__tests__/unit/index.test.ts @@ -1,5 +1,5 @@ import { HttpPlugin } from "../.."; -import { Http_ResponseTypeEnum, Client } from "../../wrap"; +import { Http_ResponseTypeEnum, CoreClient } from "../../wrap"; import axios, { AxiosResponse, AxiosRequestConfig } from "axios"; @@ -42,7 +42,7 @@ describe("test http plugin", () => { responseType: Http_ResponseTypeEnum.TEXT, }, }, - {} as Client + {} as CoreClient ); expect(mockedAxios.get).lastCalledWith("/api/test", { @@ -85,7 +85,7 @@ describe("test http plugin", () => { responseType: "BINARY", }, }, - {} as Client + {} as CoreClient ); expect(mockedAxios.get).lastCalledWith("/api/test", { @@ -138,7 +138,7 @@ describe("test http plugin", () => { responseType: "TEXT", }, }, - {} as Client + {} as CoreClient ); expect(mockedAxios.post).lastCalledWith("/api/test", "{request: 1001}", { @@ -182,7 +182,7 @@ describe("test http plugin", () => { responseType: "BINARY", }, }, - {} as Client + {} as CoreClient ); expect(mockedAxios.post).lastCalledWith("/api/test", "{request: 1001}", { diff --git a/packages/js/plugins/http/src/index.ts b/packages/js/plugins/http/src/index.ts index 32bcb2fe55..ce1b573d42 100644 --- a/packages/js/plugins/http/src/index.ts +++ b/packages/js/plugins/http/src/index.ts @@ -1,5 +1,5 @@ import { - Client, + CoreClient, Module, Args_get, Args_post, @@ -9,14 +9,14 @@ import { import { fromAxiosResponse, toAxiosRequestConfig } from "./util"; import axios from "axios"; -import { PluginFactory } from "@polywrap/core-js"; +import { PluginFactory, PluginPackage } from "@polywrap/plugin-js"; type NoConfig = Record; export class HttpPlugin extends Module { public async get( args: Args_get, - _client: Client + _client: CoreClient ): Promise { const response = await axios.get( args.url, @@ -27,7 +27,7 @@ export class HttpPlugin extends Module { public async post( args: Args_post, - _client: Client + _client: CoreClient ): Promise { const response = await axios.post( args.url, @@ -38,11 +38,7 @@ export class HttpPlugin extends Module { } } -export const httpPlugin: PluginFactory = () => { - return { - factory: () => new HttpPlugin({}), - manifest, - }; -}; +export const httpPlugin: PluginFactory = () => + new PluginPackage(new HttpPlugin({}), manifest); export const plugin = httpPlugin; diff --git a/packages/js/plugins/ipfs/jest.config.js b/packages/js/plugins/ipfs/jest.config.js index 38888109ca..00d4a54d26 100644 --- a/packages/js/plugins/ipfs/jest.config.js +++ b/packages/js/plugins/ipfs/jest.config.js @@ -1,13 +1,8 @@ module.exports = { - "roots": [ - "/src" - ], - "testMatch": [ - "**/__tests__/**/*.+(ts|tsx|js)", - "**/?(*.)+(spec|test).+(ts|tsx|js)" - ], - "transform": { - "^.+\\.(ts|tsx)$": "ts-jest" + roots: ["/src"], + testMatch: ["**/?(*.)+(spec|test).[jt]s?(x)"], + transform: { + "^.+\\.(ts|tsx)$": "ts-jest", }, - testEnvironment: 'node' -} + testEnvironment: "node", +}; diff --git a/packages/js/plugins/ipfs/package.json b/packages/js/plugins/ipfs/package.json index a9e046b98f..6b193e6db8 100644 --- a/packages/js/plugins/ipfs/package.json +++ b/packages/js/plugins/ipfs/package.json @@ -22,12 +22,15 @@ "dependencies": { "@polywrap/core-js": "0.9.3", "@polywrap/ipfs-http-client-lite": "0.3.0", + "@polywrap/plugin-js": "0.9.3", "abort-controller": "3.0.0", "is-ipfs": "1.0.3", "multiformats": "9.7.0" }, "devDependencies": { + "@polywrap/client-js": "0.9.3", "@polywrap/test-env-js": "0.9.3", + "@polywrap/uri-resolvers-js": "0.9.3", "@types/jest": "26.0.8", "@types/prettier": "2.6.0", "abort-controller": "3.0.0", diff --git a/packages/js/plugins/ipfs/src/ExecOptions.ts b/packages/js/plugins/ipfs/src/ExecOptions.ts new file mode 100644 index 0000000000..d6a075c23b --- /dev/null +++ b/packages/js/plugins/ipfs/src/ExecOptions.ts @@ -0,0 +1,6 @@ +export interface ExecOptions { + timeout: number; + provider: string; + fallbackProviders: string[]; + disableParallelRequests: boolean; +} diff --git a/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts b/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts index 6edecfd100..b38febc227 100644 --- a/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts @@ -1,20 +1,25 @@ import { Result } from "@polywrap/core-js"; -import { PolywrapClient } from "@polywrap/client-js"; import { initTestEnvironment, providers, stopTestEnvironment, } from "@polywrap/test-env-js"; -import { ipfsPlugin } from ".."; import { Ipfs_Module } from "../wrap"; +import { CoreClient } from "@polywrap/core-js"; import { ResultOk } from "@polywrap/result"; -import createIpfsClient, { IpfsClient, IpfsFileInfo } from "@polywrap/ipfs-http-client-lite"; +import { PolywrapClient } from "@polywrap/client-js"; +import createIpfsClient, { + IpfsClient, + IpfsFileInfo, +} from "@polywrap/ipfs-http-client-lite"; +import { UriResolver } from "@polywrap/uri-resolvers-js"; +import { ipfsPlugin } from ".."; jest.setTimeout(300000); describe("IPFS Plugin", () => { - let client: PolywrapClient; + let client: CoreClient; let ipfs: IpfsClient; const sampleFileTextContents = "Hello World!"; @@ -25,22 +30,21 @@ describe("IPFS Plugin", () => { await initTestEnvironment(); ipfs = createIpfsClient(providers.ipfs); - client = new PolywrapClient({ - plugins: [ - { - uri: "wrap://ens/ipfs.polywrap.eth", - plugin: ipfsPlugin({}), - }, - ], - envs: [ - { - uri: "wrap://ens/ipfs.polywrap.eth", - env: { - provider: providers.ipfs, + client = new PolywrapClient( + { + envs: [ + { + uri: "wrap://ens/ipfs.polywrap.eth", + env: { provider: providers.ipfs }, }, - }, - ], - }); + ], + resolver: UriResolver.from({ + uri: "wrap://ens/ipfs.polywrap.eth", + package: ipfsPlugin({}), + }), + }, + { noDefaults: true } + ); let ipfsAddResult = await ipfs.add(sampleFileBuffer); sampleFileIpfsInfo = ipfsAddResult[0]; @@ -57,7 +61,7 @@ describe("IPFS Plugin", () => { { cid: sampleFileIpfsInfo.hash.toString() }, client ); - + if (!result.ok) fail(result.error); expect(result.value).toEqual(sampleFileBuffer); @@ -100,30 +104,29 @@ describe("IPFS Plugin", () => { ): Promise> => { return new Promise>((resolve) => setTimeout(() => { - resolve( - ResultOk(Uint8Array.from([1, 2, 3, 4])) - ); + resolve(ResultOk(Uint8Array.from([1, 2, 3, 4]))); }, timeout) ); }; - const altClient = new PolywrapClient({ - plugins: [ - { - uri: "wrap://ens/ipfs.polywrap.eth", - plugin: ipfsPlugin({}), - }, - ], - envs: [ - { - uri: "wrap://ens/ipfs.polywrap.eth", - env: { - provider: providers.ipfs, - timeout: 1000, + const altClient = new PolywrapClient( + { + envs: [ + { + uri: "wrap://ens/ipfs.polywrap.eth", + env: { + provider: providers.ipfs, + timeout: 1000, + }, }, - }, - ], - }); + ], + resolver: UriResolver.from({ + uri: "wrap://ens/ipfs.polywrap.eth", + package: ipfsPlugin({}), + }), + }, + { noDefaults: true } + ); const nonExistentFileCid = "Qmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; @@ -134,6 +137,7 @@ describe("IPFS Plugin", () => { let result = await Promise.race([catPromise, racePromise]); expect(result).toBeTruthy(); + expect(result.ok).toBeFalsy(); result = result as { ok: false; error: Error | undefined }; expect(result.error).toBeTruthy(); expect(result.error?.stack).toMatch("Timeout has been reached"); @@ -155,29 +159,33 @@ describe("IPFS Plugin", () => { ]); expect(resultForOverride).toBeTruthy(); - resultForOverride = resultForOverride as { ok: false; error: Error | undefined }; + resultForOverride = resultForOverride as { + ok: false; + error: Error | undefined; + }; expect(resultForOverride.error).toBeTruthy(); expect(resultForOverride.error?.stack).toMatch("Timeout has been reached"); expect(resultForOverride.error?.stack).toMatch("Timeout: 500"); }); it("Should use provider from method options", async () => { - const clientWithBadProvider = new PolywrapClient({ - plugins: [ - { - uri: "wrap://ens/ipfs.polywrap.eth", - plugin: ipfsPlugin({}), - }, - ], - envs: [ - { - uri: "wrap://ens/ipfs.polywrap.eth", - env: { - provider: "this-provider-doesnt-exist", + const clientWithBadProvider = new PolywrapClient( + { + envs: [ + { + uri: "wrap://ens/ipfs.polywrap.eth", + env: { + provider: "this-provider-doesnt-exist", + }, }, - }, - ], - }); + ], + resolver: UriResolver.from({ + uri: "wrap://ens/ipfs.polywrap.eth", + package: ipfsPlugin({}), + }), + }, + { noDefaults: true } + ); const catResult = await Ipfs_Module.cat( { @@ -206,22 +214,23 @@ describe("IPFS Plugin", () => { }); it("Should use fallback provider from method options", async () => { - const clientWithBadProvider = new PolywrapClient({ - plugins: [ - { - uri: "wrap://ens/ipfs.polywrap.eth", - plugin: ipfsPlugin({}), - }, - ], - envs: [ - { - uri: "wrap://ens/ipfs.polywrap.eth", - env: { - provider: "this-provider-doesnt-exist", + const clientWithBadProvider = new PolywrapClient( + { + envs: [ + { + uri: "wrap://ens/ipfs.polywrap.eth", + env: { + provider: "this-provider-doesnt-exist", + }, }, - }, - ], - }); + ], + resolver: UriResolver.from({ + uri: "wrap://ens/ipfs.polywrap.eth", + package: ipfsPlugin({}), + }), + }, + { noDefaults: true } + ); const catResult = await Ipfs_Module.cat( { diff --git a/packages/js/plugins/ipfs/src/getExecOptions.ts b/packages/js/plugins/ipfs/src/getExecOptions.ts new file mode 100644 index 0000000000..1b72a5f84e --- /dev/null +++ b/packages/js/plugins/ipfs/src/getExecOptions.ts @@ -0,0 +1,24 @@ +import { ExecOptions } from "./ExecOptions"; +import { Ipfs_Options, Env } from "./wrap"; + +export function getExecOptions( + args: Ipfs_Options | undefined | null, + env: Env +): ExecOptions { + const defaultOptions: ExecOptions = { + disableParallelRequests: env.disableParallelRequests ?? false, + timeout: env.timeout ?? 5000, + provider: env.provider, + fallbackProviders: env.fallbackProviders ?? [], + }; + + return { + disableParallelRequests: + args?.disableParallelRequests ?? defaultOptions.disableParallelRequests, + timeout: args?.timeout ?? defaultOptions.timeout, + provider: args?.provider ?? defaultOptions.provider, + fallbackProviders: args?.fallbackProviders + ? [...args.fallbackProviders, ...defaultOptions.fallbackProviders] + : defaultOptions.fallbackProviders, + }; +} diff --git a/packages/js/plugins/ipfs/src/index.ts b/packages/js/plugins/ipfs/src/index.ts index 18bf9a6d82..0221442b93 100644 --- a/packages/js/plugins/ipfs/src/index.ts +++ b/packages/js/plugins/ipfs/src/index.ts @@ -4,50 +4,21 @@ import { Args_addFile, Args_cat, Ipfs_ResolveResult, - Ipfs_Options, manifest, - Env, } from "./wrap"; import { execSimple, execFallbacks } from "./utils/exec"; +import { ExecOptions } from "./ExecOptions"; +import { getExecOptions } from "./getExecOptions"; +import { CoreClient } from "@polywrap/core-js"; import createIpfsClient, { IpfsClient } from "@polywrap/ipfs-http-client-lite"; -import { Client, PluginFactory } from "@polywrap/core-js"; - -const isNullOrUndefined = (arg: unknown) => { - return arg === undefined || arg === null; -}; - -const getOptions = ( - args: Ipfs_Options | undefined | null, - env: Env -): Ipfs_Options => { - const options = args || {}; - - if (isNullOrUndefined(options.disableParallelRequests)) { - options.disableParallelRequests = env.disableParallelRequests; - } - - if (isNullOrUndefined(options.timeout)) { - // Default to a 5000ms timeout when none is provided - options.timeout = env.timeout ?? 5000; - } - - if (isNullOrUndefined(options.provider)) { - options.provider = env.provider; - } - - if (isNullOrUndefined(options.fallbackProviders)) { - options.fallbackProviders = env.fallbackProviders; - } - - return options; -}; +import { PluginFactory, PluginPackage } from "@polywrap/plugin-js"; export type NoConfig = Record; export class IpfsPlugin extends Module { - public async cat(args: Args_cat, _client: Client): Promise { - const options = getOptions(args.options, this.env); + public async cat(args: Args_cat, _client: CoreClient): Promise { + const options = getExecOptions(args.options, this.env); return await this._execWithOptions( "cat", @@ -60,9 +31,9 @@ export class IpfsPlugin extends Module { public async resolve( args: Args_resolve, - _client: Client + _client: CoreClient ): Promise { - const options = getOptions(args.options, this.env); + const options = getExecOptions(args.options, this.env); return await this._execWithOptions( "resolve", @@ -78,7 +49,7 @@ export class IpfsPlugin extends Module { } public async addFile(args: Args_addFile): Promise { - const options = getOptions(null, this.env); + const options = getExecOptions(null, this.env); return await this._execWithOptions( "add", @@ -104,50 +75,26 @@ export class IpfsPlugin extends Module { provider: string, options: unknown ) => Promise, - options?: Ipfs_Options + options: ExecOptions ): Promise { - const defaultIpfsClient = createIpfsClient(this.env.provider); + const defaultIpfsClient = createIpfsClient(options.provider); - if (!options?.fallbackProviders) { - // Default behavior if no fallback providers are provided - // Note that options.timeout is already set by getOptions + if (options.fallbackProviders.length === 0) { return await execSimple( operation, defaultIpfsClient, - this.config.provider, - options?.timeout ?? 0, + options.provider, + options.timeout, func ); } - const timeout = options.timeout || 0; - - let providers = [this.env.provider, ...(this.env.fallbackProviders || [])]; - let ipfs = defaultIpfsClient; - let defaultProvider = this.env.provider; - - // Use the provider default override specified - if (options.provider) { - providers = [options.provider, ...providers]; - ipfs = createIpfsClient(options.provider); - defaultProvider = options.provider; - } - - // insert fallback providers before the env providers and fallbacks - if (options.fallbackProviders) { - providers = [ - providers[0], - ...options.fallbackProviders, - ...providers.slice(1), - ]; - } - return await execFallbacks( operation, - ipfs, - defaultProvider, - providers, - timeout, + defaultIpfsClient, + options.provider, + [options.provider, ...options.fallbackProviders], + options.timeout, func, { parallel: !options.disableParallelRequests, @@ -156,11 +103,7 @@ export class IpfsPlugin extends Module { } } -export const ipfsPlugin: PluginFactory = (config: NoConfig) => { - return { - factory: () => new IpfsPlugin(config), - manifest, - }; -}; +export const ipfsPlugin: PluginFactory = () => + new PluginPackage(new IpfsPlugin({}), manifest); export const plugin = ipfsPlugin; diff --git a/packages/js/plugins/logger/package.json b/packages/js/plugins/logger/package.json index 3241e4fed7..c8baa202bc 100644 --- a/packages/js/plugins/logger/package.json +++ b/packages/js/plugins/logger/package.json @@ -20,10 +20,12 @@ "test:watch": "jest --watch --passWithNoTests --verbose" }, "dependencies": { - "@polywrap/core-js": "0.9.3" + "@polywrap/core-js": "0.9.3", + "@polywrap/plugin-js": "0.9.3" }, "devDependencies": { "@polywrap/client-js": "0.9.3", + "@polywrap/uri-resolvers-js": "0.9.3", "@types/jest": "26.0.8", "@types/prettier": "2.6.0", "jest": "26.6.3", diff --git a/packages/js/plugins/logger/src/__tests__/e2e/e2e.spec.ts b/packages/js/plugins/logger/src/__tests__/e2e/e2e.spec.ts index 889e5e9b06..84cf008d5c 100644 --- a/packages/js/plugins/logger/src/__tests__/e2e/e2e.spec.ts +++ b/packages/js/plugins/logger/src/__tests__/e2e/e2e.spec.ts @@ -1,8 +1,20 @@ import { PolywrapClient } from "@polywrap/client-js"; +import { UriResolver } from "@polywrap/uri-resolvers-js"; +import { loggerPlugin } from "../.."; describe("log method", () => { it("logs to console appropriate level", async () => { - const polywrapClient = new PolywrapClient(); + const polywrapClient = new PolywrapClient( + { + resolver: UriResolver.from([ + { + uri: "wrap://ens/js-logger.polywrap.eth", + package: loggerPlugin({}), + }, + ]), + }, + { noDefaults: true } + ); const response = await polywrapClient.invoke({ uri: "wrap://ens/js-logger.polywrap.eth", diff --git a/packages/js/plugins/logger/src/index.ts b/packages/js/plugins/logger/src/index.ts index b40ea2dac4..1787c47153 100644 --- a/packages/js/plugins/logger/src/index.ts +++ b/packages/js/plugins/logger/src/index.ts @@ -6,7 +6,7 @@ import { manifest, } from "./wrap"; -import { PluginFactory } from "@polywrap/core-js"; +import { PluginFactory, PluginPackage } from "@polywrap/plugin-js"; export type LogFunc = (level: Logger_LogLevel, message: string) => boolean; @@ -47,11 +47,5 @@ export class LoggerPlugin extends Module { export const loggerPlugin: PluginFactory = ( config: LoggerPluginConfig -) => { - return { - factory: () => new LoggerPlugin(config), - manifest, - }; -}; - +) => new PluginPackage(new LoggerPlugin(config), manifest); export const plugin = loggerPlugin; diff --git a/packages/js/plugins/uri-resolvers/ens-resolver/jest.config.js b/packages/js/plugins/uri-resolvers/ens-resolver/jest.config.js index 2ea443aa23..00d4a54d26 100644 --- a/packages/js/plugins/uri-resolvers/ens-resolver/jest.config.js +++ b/packages/js/plugins/uri-resolvers/ens-resolver/jest.config.js @@ -1,9 +1,6 @@ module.exports = { roots: ["/src"], - testMatch: [ - "**/__tests__/**/*.+(ts|tsx|js)", - "**/?(*.)+(spec|test).+(ts|tsx|js)", - ], + testMatch: ["**/?(*.)+(spec|test).[jt]s?(x)"], transform: { "^.+\\.(ts|tsx)$": "ts-jest", }, diff --git a/packages/js/plugins/uri-resolvers/ens-resolver/package.json b/packages/js/plugins/uri-resolvers/ens-resolver/package.json index c0d35a5dee..7a840bd9aa 100644 --- a/packages/js/plugins/uri-resolvers/ens-resolver/package.json +++ b/packages/js/plugins/uri-resolvers/ens-resolver/package.json @@ -23,9 +23,14 @@ "@ethersproject/address": "5.0.7", "@ethersproject/basex": "5.0.7", "@polywrap/core-js": "0.9.3", + "@polywrap/plugin-js": "0.9.3", "ethers": "5.0.7" }, "devDependencies": { + "@polywrap/client-js": "0.9.3", + "@polywrap/ethereum-plugin-js": "0.9.3", + "@polywrap/ipfs-plugin-js": "0.9.3", + "@polywrap/ipfs-resolver-plugin-js": "0.9.3", "@types/jest": "26.0.8", "@types/prettier": "2.6.0", "jest": "26.6.3", diff --git a/packages/js/plugins/uri-resolvers/ens-resolver/src/__tests__/e2e.spec.ts b/packages/js/plugins/uri-resolvers/ens-resolver/src/__tests__/e2e.spec.ts index 58a2c19021..633efacf1b 100644 --- a/packages/js/plugins/uri-resolvers/ens-resolver/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/uri-resolvers/ens-resolver/src/__tests__/e2e.spec.ts @@ -1,17 +1,13 @@ import { PolywrapClient } from "@polywrap/client-js"; -import { defaultIpfsProviders } from "@polywrap/client-config-builder-js"; import { GetPathToTestWrappers } from "@polywrap/test-cases"; import { buildAndDeployWrapper, - ensAddresses, initTestEnvironment, providers, stopTestEnvironment, } from "@polywrap/test-env-js"; -import { ensResolverPlugin } from ".."; -import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; -import { ethereumPlugin, Connections, Connection } from "@polywrap/ethereum-plugin-js"; +import { getClient } from "./helpers/getClient"; jest.setTimeout(300000); @@ -33,44 +29,7 @@ describe("ENS Resolver Plugin", () => { wrapperEnsDomain = ensDomain; - client = new PolywrapClient({ - envs: [ - { - uri: "wrap://ens/ipfs.polywrap.eth", - env: { - provider: providers.ipfs, - fallbackProviders: defaultIpfsProviders - } - } - ], - plugins: [ - { - uri: "wrap://ens/ipfs.polywrap.eth", - plugin: ipfsPlugin({}), - }, - { - uri: "wrap://ens/ethereum.polywrap.eth", - plugin: ethereumPlugin({ - connections: new Connections({ - networks: { - testnet: new Connection({ - provider: providers.ethereum - }), - }, - defaultNetwork: "testnet" - }) - }) - }, - { - uri: "wrap://ens/ens-resolver.polywrap.eth", - plugin: ensResolverPlugin({ - addresses: { - testnet: ensAddresses.ensAddress, - }, - }), - }, - ], - }); + client = getClient(); }); afterAll(async () => { @@ -89,7 +48,7 @@ describe("ENS Resolver Plugin", () => { fail("Expected response to be a wrapper"); } - const manifest = await result.value.wrapper.getManifest({}); + const manifest = await result.value.wrapper.getManifest(); expect(manifest?.name).toBe("SimpleStorage"); }); diff --git a/packages/js/plugins/uri-resolvers/ens-resolver/src/__tests__/helpers/getClient.ts b/packages/js/plugins/uri-resolvers/ens-resolver/src/__tests__/helpers/getClient.ts new file mode 100644 index 0000000000..2a9bd6d4ba --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ens-resolver/src/__tests__/helpers/getClient.ts @@ -0,0 +1,72 @@ +import { ensResolverPlugin } from "../.."; +import { ensAddresses, providers } from "@polywrap/test-env-js"; +import { + Connection, + Connections, + ethereumPlugin, +} from "@polywrap/ethereum-plugin-js"; +import { + RecursiveResolver, + PackageToWrapperCacheResolver, + WrapperCache, +} from "@polywrap/uri-resolvers-js"; +import { coreInterfaceUris } from "@polywrap/core-js"; +import { PolywrapClient } from "@polywrap/client-js"; +import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; +import { ipfsResolverPlugin } from "@polywrap/ipfs-resolver-plugin-js"; +import { ExtendableUriResolver } from "@polywrap/uri-resolver-extensions-js"; + +export const getClient = () => { + return new PolywrapClient( + { + interfaces: [ + { + interface: coreInterfaceUris.uriResolver, + implementations: [ + "wrap://ens/ipfs-resolver.polywrap.eth", + "wrap://ens/ens-resolver.polywrap.eth", + "wrap://ens/fs-resolver.polywrap.eth", + ], + }, + ], + resolver: RecursiveResolver.from( + PackageToWrapperCacheResolver.from( + [ + { + uri: "wrap://ens/ipfs-resolver.polywrap.eth", + package: ipfsResolverPlugin({}), + }, + { + uri: "wrap://ens/ipfs.polywrap.eth", + package: ipfsPlugin({}), + }, + { + uri: "wrap://ens/ethereum.polywrap.eth", + package: ethereumPlugin({ + connections: new Connections({ + networks: { + testnet: new Connection({ + provider: providers.ethereum, + }), + }, + defaultNetwork: "testnet", + }), + }), + }, + { + uri: "wrap://ens/ens-resolver.polywrap.eth", + package: ensResolverPlugin({ + addresses: { + testnet: ensAddresses.ensAddress, + }, + }), + }, + new ExtendableUriResolver(), + ], + new WrapperCache() + ) + ), + }, + { noDefaults: true } + ); +}; diff --git a/packages/js/plugins/uri-resolvers/ens-resolver/src/index.ts b/packages/js/plugins/uri-resolvers/ens-resolver/src/index.ts index ea337a5b90..53f6c37c06 100644 --- a/packages/js/plugins/uri-resolvers/ens-resolver/src/index.ts +++ b/packages/js/plugins/uri-resolvers/ens-resolver/src/index.ts @@ -1,5 +1,5 @@ import { - Client, + CoreClient, Module, Args_tryResolveUri, Args_getFile, @@ -12,7 +12,7 @@ import { import { ethers } from "ethers"; import { Base58 } from "@ethersproject/basex"; import { getAddress } from "@ethersproject/address"; -import { PluginFactory } from "@polywrap/core-js"; +import { PluginFactory, PluginPackage } from "@polywrap/plugin-js"; export type Address = string; @@ -38,7 +38,7 @@ export class EnsResolverPlugin extends Module { async tryResolveUri( args: Args_tryResolveUri, - client: Client + client: CoreClient ): Promise { if (args.authority !== "ens") { return null; @@ -63,11 +63,11 @@ export class EnsResolverPlugin extends Module { return { uri: null, manifest: null }; } - getFile(_args: Args_getFile, _client: Client): Bytes | null { + getFile(_args: Args_getFile, _client: CoreClient): Bytes | null { return null; } - async ensToCID(domain: string, client: Client): Promise { + async ensToCID(domain: string, client: CoreClient): Promise { const ensAbi = { resolver: "function resolver(bytes32 node) external view returns (address)", @@ -201,11 +201,6 @@ export class EnsResolverPlugin extends Module { export const ensResolverPlugin: PluginFactory = ( config: EnsResolverPluginConfig -) => { - return { - factory: () => new EnsResolverPlugin(config), - manifest, - }; -}; +) => new PluginPackage(new EnsResolverPlugin(config), manifest); export const plugin = ensResolverPlugin; diff --git a/packages/js/plugins/uri-resolvers/file-system-resolver/jest.config.js b/packages/js/plugins/uri-resolvers/file-system-resolver/jest.config.js index 38888109ca..00d4a54d26 100644 --- a/packages/js/plugins/uri-resolvers/file-system-resolver/jest.config.js +++ b/packages/js/plugins/uri-resolvers/file-system-resolver/jest.config.js @@ -1,13 +1,8 @@ module.exports = { - "roots": [ - "/src" - ], - "testMatch": [ - "**/__tests__/**/*.+(ts|tsx|js)", - "**/?(*.)+(spec|test).+(ts|tsx|js)" - ], - "transform": { - "^.+\\.(ts|tsx)$": "ts-jest" + roots: ["/src"], + testMatch: ["**/?(*.)+(spec|test).[jt]s?(x)"], + transform: { + "^.+\\.(ts|tsx)$": "ts-jest", }, - testEnvironment: 'node' -} + testEnvironment: "node", +}; diff --git a/packages/js/plugins/uri-resolvers/file-system-resolver/package.json b/packages/js/plugins/uri-resolvers/file-system-resolver/package.json index c3d7e68945..840b203b15 100644 --- a/packages/js/plugins/uri-resolvers/file-system-resolver/package.json +++ b/packages/js/plugins/uri-resolvers/file-system-resolver/package.json @@ -20,9 +20,12 @@ "test:watch": "jest --watch --passWithNoTests --verbose" }, "dependencies": { - "@polywrap/core-js": "0.9.3" + "@polywrap/core-js": "0.9.3", + "@polywrap/plugin-js": "0.9.3" }, "devDependencies": { + "@polywrap/client-js": "0.9.3", + "@polywrap/fs-plugin-js": "0.9.3", "@types/jest": "26.0.8", "@types/prettier": "2.6.0", "jest": "26.6.3", diff --git a/packages/js/plugins/uri-resolvers/file-system-resolver/src/__tests__/e2e.spec.ts b/packages/js/plugins/uri-resolvers/file-system-resolver/src/__tests__/e2e.spec.ts index 87eef4dfda..8bc08adb0b 100644 --- a/packages/js/plugins/uri-resolvers/file-system-resolver/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/uri-resolvers/file-system-resolver/src/__tests__/e2e.spec.ts @@ -1,118 +1,59 @@ -import { fileSystemResolverPlugin } from "../index"; -import { - buildWrapper, - initTestEnvironment, - stopTestEnvironment, - providers, - ensAddresses, -} from "@polywrap/test-env-js"; -import { - PolywrapClient, - PolywrapClientConfig, -} from "@polywrap/client-js"; -import { defaultIpfsProviders } from "@polywrap/client-config-builder-js"; +import { buildWrapper, stopTestEnvironment } from "@polywrap/test-env-js"; +import { Uri } from "@polywrap/core-js"; +import { PolywrapClient } from "@polywrap/client-js"; import { GetPathToTestWrappers } from "@polywrap/test-cases"; -import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; -import { ensResolverPlugin } from "@polywrap/ens-resolver-plugin-js"; -import { ethereumPlugin, Connections, Connection } from "@polywrap/ethereum-plugin-js"; import fs from "fs"; -import path from "path"; +import { getClient } from "./helpers/getClient"; jest.setTimeout(360000); +const simpleWrapperPath = `${GetPathToTestWrappers()}/wasm-as/simple`; +const simpleWrapperUri = new Uri(`fs/${simpleWrapperPath}/build`); + describe("Filesystem plugin", () => { let client: PolywrapClient; beforeAll(async () => { - await initTestEnvironment(); + await buildWrapper(simpleWrapperPath); - const config: Partial = { - envs: [ - { - uri: "wrap://ens/ipfs.polywrap.eth", - env: { - provider: providers.ipfs, - fallbackProviders: defaultIpfsProviders, - }, - }, - ], - plugins: [ - { - uri: "wrap://ens/fs-resolver.polywrap.eth", - plugin: fileSystemResolverPlugin({}), - }, - { - uri: "wrap://ens/ipfs.polywrap.eth", - plugin: ipfsPlugin({}), - }, - { - uri: "wrap://ens/ens-resolver.polywrap.eth", - plugin: ensResolverPlugin({ - addresses: { - testnet: ensAddresses.ensAddress, - }, - }), - }, - { - uri: "wrap://ens/ethereum.polywrap.eth", - plugin: ethereumPlugin({ - connections: new Connections({ - networks: { - testnet: new Connection({ - provider: providers.ethereum - }) - }, - defaultNetwork: "testnet" - }) - }), - }, - ], - }; - client = new PolywrapClient(config); + client = getClient(); }); afterAll(async () => { await stopTestEnvironment(); }); - it("invokes simple-storage wrapper on local drive", async () => { - const wrapperPath = path.resolve( - `${GetPathToTestWrappers()}/wasm-as/simple-storage` - ); - await buildWrapper(wrapperPath); - - const fsPath = `${wrapperPath}/build`; - const fsUri = `fs/${fsPath}`; - - // invoke wrapper from filesystem - const deploy = await client.invoke({ - uri: fsUri, - method: "deployContract", + it("invokes simple wrapper on local file system", async () => { + const result = await client.invoke({ + uri: simpleWrapperUri.uri, + method: "simpleMethod", args: { - connection: { - networkNameOrChainId: "testnet", - }, + arg: "test", }, }); - if (!deploy.ok) fail(deploy.error); - expect(deploy.value).toBeTruthy(); - expect(deploy.value.indexOf("0x")).toBeGreaterThan(-1); + if (!result.ok) { + fail("Expected response to not be an error"); + } + + expect(result.value).toEqual("test"); // get the manifest - const manifest = await client.getManifest(fsUri); + const manifest = await client.getManifest(simpleWrapperUri); if (!manifest.ok) fail(manifest.error); expect(manifest.value.version).toBe("0.1"); expect(manifest.value.type).toEqual("wasm"); // get a file - const file = await client.getFile(fsUri, { + const file = await client.getFile(simpleWrapperUri, { path: "wrap.info", }); if (!file.ok) fail(file.error); - const expectedFile = await fs.promises.readFile(`${fsPath}/wrap.info`); + const expectedFile = await fs.promises.readFile( + `${simpleWrapperPath}/build/wrap.info` + ); const expectedInfo = Uint8Array.from(expectedFile); expect(file.value).toStrictEqual(expectedInfo); diff --git a/packages/js/plugins/uri-resolvers/file-system-resolver/src/__tests__/helpers/getClient.ts b/packages/js/plugins/uri-resolvers/file-system-resolver/src/__tests__/helpers/getClient.ts new file mode 100644 index 0000000000..06c93f16fa --- /dev/null +++ b/packages/js/plugins/uri-resolvers/file-system-resolver/src/__tests__/helpers/getClient.ts @@ -0,0 +1,40 @@ +import { + RecursiveResolver, + PackageToWrapperCacheResolver, + WrapperCache, +} from "@polywrap/uri-resolvers-js"; +import { coreInterfaceUris } from "@polywrap/core-js"; +import { PolywrapClient } from "@polywrap/client-js"; +import { ExtendableUriResolver } from "@polywrap/uri-resolver-extensions-js"; +import { fileSystemPlugin } from "@polywrap/fs-plugin-js"; +import { fileSystemResolverPlugin } from "../.."; + +export const getClient = () => { + return new PolywrapClient( + { + interfaces: [ + { + interface: coreInterfaceUris.uriResolver, + implementations: ["wrap://ens/fs-resolver.polywrap.eth"], + }, + ], + resolver: RecursiveResolver.from( + PackageToWrapperCacheResolver.from( + [ + { + uri: "wrap://ens/fs-resolver.polywrap.eth", + package: fileSystemResolverPlugin({}), + }, + { + uri: "wrap://ens/fs.polywrap.eth", + package: fileSystemPlugin({}), + }, + new ExtendableUriResolver(), + ], + new WrapperCache() + ) + ), + }, + { noDefaults: true } + ); +}; diff --git a/packages/js/plugins/uri-resolvers/file-system-resolver/src/index.ts b/packages/js/plugins/uri-resolvers/file-system-resolver/src/index.ts index 80ad27882c..d497102c08 100644 --- a/packages/js/plugins/uri-resolvers/file-system-resolver/src/index.ts +++ b/packages/js/plugins/uri-resolvers/file-system-resolver/src/index.ts @@ -1,6 +1,6 @@ import { Bytes, - Client, + CoreClient, FileSystem_Module, Args_getFile, Args_tryResolveUri, @@ -9,7 +9,7 @@ import { manifest, } from "./wrap"; -import { PluginFactory } from "@polywrap/core-js"; +import { PluginFactory, PluginPackage } from "@polywrap/plugin-js"; import path from "path"; type NoConfig = Record; @@ -17,7 +17,7 @@ type NoConfig = Record; export class FileSystemResolverPlugin extends Module { async tryResolveUri( args: Args_tryResolveUri, - _client: Client + _client: CoreClient ): Promise { if (args.authority !== "fs" && args.authority !== "file") { return null; @@ -52,7 +52,10 @@ export class FileSystemResolverPlugin extends Module { return { uri: null, manifest }; } - async getFile(args: Args_getFile, _client: Client): Promise { + async getFile( + args: Args_getFile, + _client: CoreClient + ): Promise { try { const fileResult = await FileSystem_Module.readFile( { path: args.path }, @@ -69,9 +72,5 @@ export class FileSystemResolverPlugin extends Module { } } -export const fileSystemResolverPlugin: PluginFactory = () => { - return { - factory: () => new FileSystemResolverPlugin({}), - manifest, - }; -}; +export const fileSystemResolverPlugin: PluginFactory = () => + new PluginPackage(new FileSystemResolverPlugin({}), manifest); diff --git a/packages/js/plugins/uri-resolvers/http-resolver/package.json b/packages/js/plugins/uri-resolvers/http-resolver/package.json index 13813d2b49..4dd33bcc0d 100644 --- a/packages/js/plugins/uri-resolvers/http-resolver/package.json +++ b/packages/js/plugins/uri-resolvers/http-resolver/package.json @@ -22,11 +22,11 @@ }, "dependencies": { "@polywrap/core-js": "0.9.3", + "@polywrap/plugin-js": "0.9.3", "abort-controller": "3.0.0" }, "devDependencies": { "@polywrap/http-plugin-js": "0.9.3", - "@polywrap/polywrap-manifest-types-js": "0.9.3", "@polywrap/test-env-js": "0.9.3", "@types/jest": "26.0.8", "@types/prettier": "2.6.0", diff --git a/packages/js/plugins/uri-resolvers/http-resolver/src/__tests__/e2e.spec.ts b/packages/js/plugins/uri-resolvers/http-resolver/src/__tests__/e2e.spec.ts index c4e0659ae1..d2813100a6 100644 --- a/packages/js/plugins/uri-resolvers/http-resolver/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/uri-resolvers/http-resolver/src/__tests__/e2e.spec.ts @@ -2,10 +2,9 @@ import { PolywrapClient } from "@polywrap/client-js"; import { GetPathToTestWrappers } from "@polywrap/test-cases"; import { buildAndDeployWrapperToHttp, runCLI, providers } from "@polywrap/test-env-js"; -import { httpPlugin } from "@polywrap/http-plugin-js"; import axios from "axios"; -import { httpResolverPlugin } from ".."; import { deserializeWrapManifest } from "@polywrap/wrap-manifest-types-js"; +import { getClient } from "./helpers/getClient"; jest.setTimeout(300000); @@ -17,7 +16,7 @@ describe("HTTP Plugin", () => { beforeAll(async () => { const { exitCode, stderr } = await runCLI({ - args: ["infra", "up", "--modules=http", "--verbose"] + args: ["infra", "up", "--modules=http", "--verbose"], }); if (exitCode !== 0) { @@ -32,23 +31,12 @@ describe("HTTP Plugin", () => { wrapperHttpUri = uri; - client = new PolywrapClient({ - plugins: [ - { - uri: "wrap://ens/http.polywrap.eth", - plugin: httpPlugin({}) - }, - { - uri: "wrap://ens/http-uri-resolver.polywrap.eth", - plugin: httpResolverPlugin({}) - } - ], - }); + client = getClient(); }); afterAll(async () => { const { exitCode, stderr } = await runCLI({ - args: ["infra", "down", "--modules=http", "--verbose"] + args: ["infra", "down", "--modules=http", "--verbose"], }); if (exitCode !== 0) { @@ -77,7 +65,7 @@ describe("HTTP Plugin", () => { ); const expectedManifest = await deserializeWrapManifest(data); - const manifest = await result.value.wrapper.getManifest({}); + const manifest = await result.value.wrapper.getManifest(); expect(manifest?.name).toBe("SimpleStorage"); expect(manifest).toEqual(expectedManifest); @@ -104,7 +92,7 @@ describe("HTTP Plugin", () => { ); const expectedManifest = await deserializeWrapManifest(data); - const manifest = await result.value.wrapper.getManifest({}); + const manifest = await result.value.wrapper.getManifest(); expect(manifest?.name).toBe("SimpleStorage"); expect(manifest).toEqual(expectedManifest); diff --git a/packages/js/plugins/uri-resolvers/http-resolver/src/__tests__/helpers/getClient.ts b/packages/js/plugins/uri-resolvers/http-resolver/src/__tests__/helpers/getClient.ts new file mode 100644 index 0000000000..8dc9472df9 --- /dev/null +++ b/packages/js/plugins/uri-resolvers/http-resolver/src/__tests__/helpers/getClient.ts @@ -0,0 +1,40 @@ +import { + RecursiveResolver, + PackageToWrapperCacheResolver, + WrapperCache, +} from "@polywrap/uri-resolvers-js"; +import { coreInterfaceUris } from "@polywrap/core-js"; +import { PolywrapClient } from "@polywrap/client-js"; +import { ExtendableUriResolver } from "@polywrap/uri-resolver-extensions-js"; +import { httpPlugin } from "@polywrap/http-plugin-js"; +import { httpResolverPlugin } from "../.."; + +export const getClient = () => { + return new PolywrapClient( + { + interfaces: [ + { + interface: coreInterfaceUris.uriResolver, + implementations: ["wrap://ens/http-uri-resolver.polywrap.eth"], + }, + ], + resolver: RecursiveResolver.from( + PackageToWrapperCacheResolver.from( + [ + { + uri: "wrap://ens/http.polywrap.eth", + package: httpPlugin({}), + }, + { + uri: "wrap://ens/http-uri-resolver.polywrap.eth", + package: httpResolverPlugin({}), + }, + new ExtendableUriResolver(), + ], + new WrapperCache() + ) + ), + }, + { noDefaults: true } + ); +}; diff --git a/packages/js/plugins/uri-resolvers/http-resolver/src/index.ts b/packages/js/plugins/uri-resolvers/http-resolver/src/index.ts index 9dc0003e72..e8b684a834 100644 --- a/packages/js/plugins/uri-resolvers/http-resolver/src/index.ts +++ b/packages/js/plugins/uri-resolvers/http-resolver/src/index.ts @@ -2,14 +2,14 @@ import { Args_getFile, Args_tryResolveUri, Bytes, - Client, + CoreClient, Http_Module, manifest, Module, UriResolver_MaybeUriOrManifest, } from "./wrap"; -import { PluginFactory } from "@polywrap/core-js"; +import { PluginFactory, PluginPackage } from "@polywrap/plugin-js"; type NoConfig = Record; @@ -17,7 +17,7 @@ export class HttpResolverPlugin extends Module { // uri-resolver.core.polywrap.eth public async tryResolveUri( args: Args_tryResolveUri, - _client: Client + _client: CoreClient ): Promise { if (args.authority !== "http" && args.authority !== "https") { return null; @@ -55,7 +55,7 @@ export class HttpResolverPlugin extends Module { public async getFile( args: Args_getFile, - client: Client + client: CoreClient ): Promise { try { const resolveResult = await Http_Module.get( @@ -84,11 +84,7 @@ export class HttpResolverPlugin extends Module { } } -export const httpResolverPlugin: PluginFactory = () => { - return { - factory: () => new HttpResolverPlugin({}), - manifest, - }; -}; +export const httpResolverPlugin: PluginFactory = () => + new PluginPackage(new HttpResolverPlugin({}), manifest); export const plugin = httpResolverPlugin; diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json b/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json index 111c37bec0..b86bbd9813 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json @@ -22,6 +22,7 @@ "dependencies": { "@polywrap/core-js": "0.9.3", "@polywrap/ipfs-http-client-lite": "0.3.0", + "@polywrap/plugin-js": "0.9.3", "abort-controller": "3.0.0", "is-ipfs": "1.0.3" }, diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts index 48e7239a7c..02d21fdbbc 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts @@ -1,5 +1,7 @@ -import { PolywrapClient } from "@polywrap/client-js"; import { GetPathToTestWrappers } from "@polywrap/test-cases"; +import { getClient } from "./helpers/getClient"; +import { Result } from "@polywrap/core-js"; +import { ResultOk } from "@polywrap/result"; import { buildAndDeployWrapper, initTestEnvironment, @@ -7,45 +9,12 @@ import { stopTestEnvironment, } from "@polywrap/test-env-js"; -import { ipfsResolverPlugin } from ".."; -import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; -import { Result } from "@polywrap/core-js"; -import { ResultOk } from "@polywrap/result"; - jest.setTimeout(300000); describe("IPFS Plugin", () => { let ipfsResolverUri = "wrap://ens/ipfs-resolver.polywrap.eth"; - let wrapperIpfsCid: string; - const getClientConfigWithIpfsResolverEnv = (env: Record) => { - return { - plugins: [ - { - uri: "wrap://ens/ipfs.polywrap.eth", - plugin: ipfsPlugin({}), - }, - { - uri: ipfsResolverUri, - plugin: ipfsResolverPlugin({}), - }, - ], - envs: [ - { - uri: "wrap://ens/ipfs.polywrap.eth", - env: { - provider: providers.ipfs, - }, - }, - { - uri: "wrap://ens/ipfs-resolver.polywrap.eth", - env: env, - }, - ], - }; - }; - beforeAll(async () => { await initTestEnvironment(); @@ -64,7 +33,7 @@ describe("IPFS Plugin", () => { }); it("Should successfully resolve a deployed wrapper - e2e", async () => { - const client = new PolywrapClient(getClientConfigWithIpfsResolverEnv({})); + const client = getClient({}); const wrapperUri = `ipfs/${wrapperIpfsCid}`; @@ -98,8 +67,9 @@ describe("IPFS Plugin", () => { env: Record, timeout: number ) => { - const nonExistentFileCid = "Qmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; - const client = new PolywrapClient(getClientConfigWithIpfsResolverEnv(env)); + const nonExistentFileCid = + "Qmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + const client = getClient(env); const getFilePromise = client.invoke({ uri: ipfsResolverUri, @@ -123,7 +93,7 @@ describe("IPFS Plugin", () => { if (!fasterRaceResult.ok) fail(fasterRaceResult.error); const expectedFasterResult = await fasterRacePromise; - if (!expectedFasterResult.ok) fail(expectedFasterResult.error) + if (!expectedFasterResult.ok) fail(expectedFasterResult.error); expect(fasterRaceResult.value).toStrictEqual(expectedFasterResult.value); if (!slowerRaceResult.ok) fail(slowerRaceResult.error); @@ -152,7 +122,7 @@ describe("IPFS Plugin", () => { checkIfExists: timeout, tryResolveUri: timeout, }, - skipCheckIfExists: true + skipCheckIfExists: true, }, timeout ); @@ -163,8 +133,9 @@ describe("IPFS Plugin", () => { env: Record, timeout: number ) => { - const nonExistentFileCid = "Qmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; - const client = new PolywrapClient(getClientConfigWithIpfsResolverEnv(env)); + const nonExistentFileCid = + "Qmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + const client = getClient(env); const getFilePromise = client.invoke({ uri: ipfsResolverUri, @@ -189,7 +160,7 @@ describe("IPFS Plugin", () => { if (!fasterRaceResult.ok) fail(fasterRaceResult.error); const expectedFasterResult = await fasterRacePromise; - if (!expectedFasterResult.ok) fail(expectedFasterResult.error) + if (!expectedFasterResult.ok) fail(expectedFasterResult.error); expect(fasterRaceResult.value).toStrictEqual(expectedFasterResult.value); if (!slowerRaceResult.ok) fail(slowerRaceResult.error); diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/helpers/getClient.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/helpers/getClient.ts new file mode 100644 index 0000000000..b1adcdfaff --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/helpers/getClient.ts @@ -0,0 +1,53 @@ +import { + RecursiveResolver, + PackageToWrapperCacheResolver, + WrapperCache, +} from "@polywrap/uri-resolvers-js"; +import { coreInterfaceUris } from "@polywrap/core-js"; +import { PolywrapClient } from "@polywrap/client-js"; +import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; +import { ExtendableUriResolver } from "@polywrap/uri-resolver-extensions-js"; +import { providers } from "@polywrap/test-env-js"; +import { ipfsResolverPlugin } from "../.."; + +export const getClient = (env: Record) => { + return new PolywrapClient( + { + envs: [ + { + uri: "wrap://ens/ipfs.polywrap.eth", + env: { + provider: providers.ipfs, + }, + }, + { + uri: "wrap://ens/ipfs-resolver.polywrap.eth", + env: env, + }, + ], + interfaces: [ + { + interface: coreInterfaceUris.uriResolver, + implementations: ["wrap://ens/ipfs-resolver.polywrap.eth"], + }, + ], + resolver: RecursiveResolver.from( + PackageToWrapperCacheResolver.from( + [ + { + uri: "wrap://ens/ipfs.polywrap.eth", + package: ipfsPlugin({}), + }, + { + uri: "wrap://ens/ipfs-resolver.polywrap.eth", + package: ipfsResolverPlugin({}), + }, + new ExtendableUriResolver(), + ], + new WrapperCache() + ) + ), + }, + { noDefaults: true } + ); +}; diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts index 7914ac975a..840ee85ea1 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts @@ -2,14 +2,14 @@ import { Args_getFile, Args_tryResolveUri, Bytes, - Client, + CoreClient, Ipfs_Module, manifest, Module, UriResolver_MaybeUriOrManifest, } from "./wrap"; -import { PluginFactory } from "@polywrap/core-js"; +import { PluginFactory, PluginPackage } from "@polywrap/plugin-js"; import isIpfs from "is-ipfs"; type NoConfig = Record; @@ -18,7 +18,7 @@ export class IpfsResolverPlugin extends Module { // uri-resolver.core.polywrap.eth public async tryResolveUri( args: Args_tryResolveUri, - _client: Client + _client: CoreClient ): Promise { if (args.authority !== "ipfs") { return null; @@ -58,7 +58,7 @@ export class IpfsResolverPlugin extends Module { public async getFile( args: Args_getFile, - client: Client + client: CoreClient ): Promise { try { let provider: string | undefined = undefined; @@ -109,11 +109,7 @@ export class IpfsResolverPlugin extends Module { } } -export const ipfsResolverPlugin: PluginFactory = () => { - return { - factory: () => new IpfsResolverPlugin({}), - manifest, - }; -}; +export const ipfsResolverPlugin: PluginFactory = () => + new PluginPackage(new IpfsResolverPlugin({}), manifest); export const plugin = ipfsResolverPlugin; diff --git a/packages/js/plugins/ws/jest.config.js b/packages/js/plugins/ws/jest.config.js index f0f063c0ce..fa146e8f9d 100644 --- a/packages/js/plugins/ws/jest.config.js +++ b/packages/js/plugins/ws/jest.config.js @@ -1,22 +1,11 @@ module.exports = { - "roots": [ - "/src" - ], - "testMatch": [ - "**/__tests__/**/*.+(ts|tsx|js)", - "**/?(*.)+(spec|test).+(ts|tsx|js)" - ], - "transform": { - "^.+\\.(ts|tsx)$": "ts-jest" + roots: ["/src"], + testMatch: ["**/?(*.)+(spec|test).[jt]s?(x)"], + transform: { + "^.+\\.(ts|tsx)$": "ts-jest", }, - modulePathIgnorePatterns: [ - "/src/__tests__/e2e/integration/" - ], - testPathIgnorePatterns: [ - "/src/__tests__/e2e/integration/" - ], - transformIgnorePatterns: [ - "/src/__tests__/e2e/integration/" - ], - testEnvironment: 'node' -} + modulePathIgnorePatterns: ["/src/__tests__/e2e/integration/"], + testPathIgnorePatterns: ["/src/__tests__/e2e/integration/"], + transformIgnorePatterns: ["/src/__tests__/e2e/integration/"], + testEnvironment: "node", +}; diff --git a/packages/js/plugins/ws/package.json b/packages/js/plugins/ws/package.json index 26c39a43c2..b9247ef773 100644 --- a/packages/js/plugins/ws/package.json +++ b/packages/js/plugins/ws/package.json @@ -20,11 +20,15 @@ "test:watch": "jest --watch --passWithNoTests --verbose" }, "dependencies": { - "@polywrap/core-js": "0.9.3" + "@polywrap/core-js": "0.9.3", + "@polywrap/plugin-js": "0.9.3" }, "devDependencies": { "@polywrap/client-js": "0.9.3", "@polywrap/test-env-js": "0.9.3", + "@polywrap/uri-resolvers-js": "0.9.3", + "@polywrap/fs-resolver-plugin-js": "0.9.3", + "@polywrap/fs-plugin-js": "0.9.3", "@types/jest": "26.0.8", "@types/prettier": "2.6.0", "jest": "26.6.3", diff --git a/packages/js/plugins/ws/src/__tests__/e2e/e2e.spec.ts b/packages/js/plugins/ws/src/__tests__/e2e/e2e.spec.ts index 2aa40c6f27..e9dba64183 100644 --- a/packages/js/plugins/ws/src/__tests__/e2e/e2e.spec.ts +++ b/packages/js/plugins/ws/src/__tests__/e2e/e2e.spec.ts @@ -3,52 +3,55 @@ import { Message } from "../../wrap"; import WS from "jest-websocket-mock"; import { PolywrapClient } from "@polywrap/client-js" -import { Client, PluginModule } from "@polywrap/core-js"; -import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; +import { CoreClient } from "@polywrap/core-js"; +import { UriResolver } from "@polywrap/uri-resolvers-js"; +import { PluginPackage } from "@polywrap/plugin-js"; describe("WebSocket plugin", () => { - - let polywrapClient: PolywrapClient - let server: WS - let t1: ReturnType - let t2: ReturnType - let t3: ReturnType + let polywrapClient: PolywrapClient; + let server: WS; + let t1: ReturnType; + let t2: ReturnType; + let t3: ReturnType; const setup = () => { - polywrapClient = new PolywrapClient({ - plugins: [ - { - uri: "wrap://ens/ws.polywrap.eth", - plugin: wsPlugin({}), - }, - ] - }); + polywrapClient = new PolywrapClient( + { + resolver: UriResolver.from([ + { + uri: "wrap://ens/ws.polywrap.eth", + package: wsPlugin({}), + }, + ]), + }, + { noDefaults: true } + ); server = new WS("ws://localhost:1234"); t1 = setTimeout(() => { - server.send("1") - }, 100) + server.send("1"); + }, 100); t2 = setTimeout(() => { - server.send("2") - }, 200) + server.send("2"); + }, 200); t3 = setTimeout(() => { - server.send("3") - }, 300) - } + server.send("3"); + }, 300); + }; const teardown = () => { WS.clean(); - clearTimeout(t1) - clearTimeout(t2) - clearTimeout(t3) - } + clearTimeout(t1); + clearTimeout(t2); + clearTimeout(t3); + }; describe("init", () => { beforeEach(() => { - setup() + setup(); }); afterEach(() => { - teardown() + teardown(); }); it("should open a websocket connection", async () => { @@ -56,11 +59,11 @@ describe("WebSocket plugin", () => { uri: "wrap://ens/ws.polywrap.eth", method: "open", args: { - url: "ws://localhost:1234" - } - }) + url: "ws://localhost:1234", + }, + }); - await server.connected + await server.connected; }); it("should return after timeout if connection can't be opened", async () => { @@ -69,9 +72,9 @@ describe("WebSocket plugin", () => { method: "open", args: { url: "ws://localhost:1235", - timeout: 50 - } - }) + timeout: 50, + }, + }); }); it("should close a websocket connection", async () => { @@ -79,41 +82,39 @@ describe("WebSocket plugin", () => { uri: "wrap://ens/ws.polywrap.eth", method: "open", args: { - url: "ws://localhost:1234" - } - }) + url: "ws://localhost:1234", + }, + }); if (!result.ok) fail(result.error); - await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "close", args: { - id: result.value - } - }) + id: result.value, + }, + }); - await server.closed + await server.closed; }); }); describe("send", () => { beforeEach(() => { - setup() + setup(); }); afterEach(() => { - teardown() + teardown(); }); it("should send a message to the server", async () => { - const result = await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "open", args: { - url: "ws://localhost:1234" - } - }) + url: "ws://localhost:1234", + }, + }); if (!result.ok) fail(result.error); await polywrapClient.invoke({ @@ -121,9 +122,9 @@ describe("WebSocket plugin", () => { method: "send", args: { id: result.value, - message: "test" - } - }) + message: "test", + }, + }); await expect(server).toReceiveMessage("test"); expect(server).toHaveReceivedMessages(["test"]); @@ -131,59 +132,47 @@ describe("WebSocket plugin", () => { }); describe("callback", () => { - - let msgs: string[] = [] + let msgs: string[] = []; beforeEach(() => { - setup() - polywrapClient = new PolywrapClient({ - plugins: [ - { - uri: "wrap://ens/ws.polywrap.eth", - plugin: wsPlugin({}), - }, - ] - }); - class CallbackPlugin extends PluginModule<{}> { - callback(args: { data: string }, _client: Client): void { - msgs.push(args.data) - return - } - } - let stubPlugin = { - factory: () => { - return new CallbackPlugin({}) - }, - manifest: { } as WrapManifest, - } - polywrapClient = new PolywrapClient({ - plugins: [ - { - uri: "wrap://ens/ws.polywrap.eth", - plugin: wsPlugin({}), - }, - { - uri: "wrap://ens/stub.polywrap.eth", - plugin: stubPlugin, - } - ] - }); + setup(); + + const callbackPlugin = PluginPackage.from(() => ({ + callback(args: { data: string }, _client: CoreClient): void { + msgs.push(args.data); + }, + })); + + polywrapClient = new PolywrapClient( + { + resolver: UriResolver.from([ + { + uri: "wrap://ens/ws.polywrap.eth", + package: wsPlugin({}), + }, + { + uri: "wrap://ens/stub.polywrap.eth", + package: callbackPlugin, + }, + ]), + }, + { noDefaults: true } + ); }); afterEach(() => { - teardown() - msgs = [] + teardown(); + msgs = []; }); it("should pass messages to a callback", async () => { - const result = await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "open", args: { - url: "ws://localhost:1234" - } - }) + url: "ws://localhost:1234", + }, + }); if (!result.ok) fail(result.error); await polywrapClient.invoke({ @@ -193,12 +182,14 @@ describe("WebSocket plugin", () => { id: result.value, callback: { uri: "wrap://ens/stub.polywrap.eth", - method: "callback" - } - } - }) + method: "callback", + }, + }, + }); - await new Promise(async (resolve) => {setTimeout(() => resolve(), 250)}) + await new Promise(async (resolve) => { + setTimeout(() => resolve(), 250); + }); expect(msgs).toEqual(["1", "2"]); }); @@ -208,9 +199,9 @@ describe("WebSocket plugin", () => { uri: "wrap://ens/ws.polywrap.eth", method: "open", args: { - url: "ws://localhost:1234" - } - }) + url: "ws://localhost:1234", + }, + }); if (!result.ok) fail(result.error); await polywrapClient.invoke({ @@ -220,27 +211,31 @@ describe("WebSocket plugin", () => { id: result.value, callback: { uri: "wrap://ens/stub.polywrap.eth", - method: "callback" - } - } - }) - - await new Promise(async (resolve) => {setTimeout(async () => { - await polywrapClient.invoke({ - uri: "wrap://ens/ws.polywrap.eth", - method: "removeCallback", - args: { - id: result.value, - callback: { - uri: "wrap://ens/stub.polywrap.eth", - method: "callback" - } - } - }) - resolve() - }, 250)}) + method: "callback", + }, + }, + }); - await new Promise(async (resolve) => {setTimeout(() => resolve(), 250)}) + await new Promise(async (resolve) => { + setTimeout(async () => { + await polywrapClient.invoke({ + uri: "wrap://ens/ws.polywrap.eth", + method: "removeCallback", + args: { + id: result.value, + callback: { + uri: "wrap://ens/stub.polywrap.eth", + method: "callback", + }, + }, + }); + resolve(); + }, 250); + }); + + await new Promise(async (resolve) => { + setTimeout(() => resolve(), 250); + }); expect(msgs).toEqual(["1", "2"]); }); @@ -248,44 +243,45 @@ describe("WebSocket plugin", () => { describe("cache", () => { beforeEach(() => { - setup() + setup(); }); afterEach(() => { - teardown() + teardown(); }); it("should receive a message", async () => { - const result = await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "open", args: { - url: "ws://localhost:1234" - } - }) + url: "ws://localhost:1234", + }, + }); if (!result.ok) fail(result.error); await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "addCache", args: { - id: result.value - } - }) + id: result.value, + }, + }); - await new Promise(async (resolve) => {setTimeout(() => resolve(), 250)}) + await new Promise(async (resolve) => { + setTimeout(() => resolve(), 250); + }); const response = await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "receive", args: { - id: result.value - } - }) + id: result.value, + }, + }); if (!response.ok) fail(response.error); - let data = response.value.map((msg) => msg.data) + let data = response.value.map((msg) => msg.data); expect(data).toEqual(["1", "2"]); }); @@ -294,42 +290,46 @@ describe("WebSocket plugin", () => { uri: "wrap://ens/ws.polywrap.eth", method: "open", args: { - url: "ws://localhost:1234" - } - }) + url: "ws://localhost:1234", + }, + }); if (!result.ok) fail(result.error); await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "addCache", args: { - id: result.value - } - }) + id: result.value, + }, + }); - await new Promise(async (resolve) => {setTimeout(async () => { - await polywrapClient.invoke({ - uri: "wrap://ens/ws.polywrap.eth", - method: "removeCache", - args: { - id: result.value - } - }) - resolve() - }, 200)}) + await new Promise(async (resolve) => { + setTimeout(async () => { + await polywrapClient.invoke({ + uri: "wrap://ens/ws.polywrap.eth", + method: "removeCache", + args: { + id: result.value, + }, + }); + resolve(); + }, 200); + }); - await new Promise(async (resolve) => {setTimeout(() => resolve(), 250)}) + await new Promise(async (resolve) => { + setTimeout(() => resolve(), 250); + }); const response = await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "receive", args: { - id: result.value - } - }) + id: result.value, + }, + }); if (!response.ok) fail(response.error); - let data = response.value.map((msg) => msg.data) + let data = response.value.map((msg) => msg.data); expect(data).toEqual(["1", "2"]); }); @@ -338,30 +338,30 @@ describe("WebSocket plugin", () => { uri: "wrap://ens/ws.polywrap.eth", method: "open", args: { - url: "ws://localhost:1234" - } - }) + url: "ws://localhost:1234", + }, + }); if (!result.ok) fail(result.error); await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "addCache", args: { - id: result.value - } - }) + id: result.value, + }, + }); const response = await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "receive", args: { id: result.value, - timeout: 250 - } - }) + timeout: 250, + }, + }); if (!response.ok) fail(response.error); - let data = response.value.map((msg) => msg.data) + let data = response.value.map((msg) => msg.data); expect(data).toEqual(["1", "2"]); }); @@ -370,30 +370,30 @@ describe("WebSocket plugin", () => { uri: "wrap://ens/ws.polywrap.eth", method: "open", args: { - url: "ws://localhost:1234" - } - }) + url: "ws://localhost:1234", + }, + }); if (!result.ok) fail(result.error); await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "addCache", args: { - id: result.value - } - }) + id: result.value, + }, + }); const response = await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "receive", args: { id: result.value, - min: 2 - } - }) + min: 2, + }, + }); if (!response.ok) fail(response.error); - let data = response.value.map((msg) => msg.data) + let data = response.value.map((msg) => msg.data); expect(data).toEqual(["1", "2"]); }); @@ -402,18 +402,18 @@ describe("WebSocket plugin", () => { uri: "wrap://ens/ws.polywrap.eth", method: "open", args: { - url: "ws://localhost:1234" - } - }) + url: "ws://localhost:1234", + }, + }); if (!result.ok) fail(result.error); await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "addCache", args: { - id: result.value - } - }) + id: result.value, + }, + }); const response = await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", @@ -421,12 +421,12 @@ describe("WebSocket plugin", () => { args: { id: result.value, timeout: 110, - min: 2 - } - }) + min: 2, + }, + }); if (!response.ok) fail(response.error); - let data = response.value.map((msg) => msg.data) + let data = response.value.map((msg) => msg.data); expect(data).toEqual(["1"]); }); @@ -435,18 +435,18 @@ describe("WebSocket plugin", () => { uri: "wrap://ens/ws.polywrap.eth", method: "open", args: { - url: "ws://localhost:1234" - } - }) + url: "ws://localhost:1234", + }, + }); if (!result.ok) fail(result.error); await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "addCache", args: { - id: result.value - } - }) + id: result.value, + }, + }); const response = await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", @@ -454,74 +454,79 @@ describe("WebSocket plugin", () => { args: { id: result.value, timeout: 300, - min: 1 - } - }) + min: 1, + }, + }); if (!response.ok) fail(response.error); - let data = response.value.map((msg) => msg.data) + let data = response.value.map((msg) => msg.data); expect(data).toEqual(["1"]); }); it("should receive messages in batches", async () => { - const result = await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "open", args: { - url: "ws://localhost:1234" - } - }) + url: "ws://localhost:1234", + }, + }); if (!result.ok) fail(result.error); await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "addCache", args: { - id: result.value - } - }) + id: result.value, + }, + }); - await new Promise(async (resolve) => {setTimeout(() => resolve(), 250)}) + await new Promise(async (resolve) => { + setTimeout(() => resolve(), 250); + }); const response1 = await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "receive", args: { - id: result.value - } - }) + id: result.value, + }, + }); - await new Promise(async (resolve) => {setTimeout(() => resolve(), 100)}) + await new Promise(async (resolve) => { + setTimeout(() => resolve(), 100); + }); const response2 = await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "receive", args: { - id: result.value - } - }) + id: result.value, + }, + }); - await new Promise(async (resolve) => {setTimeout(() => resolve(), 100)}) + await new Promise(async (resolve) => { + setTimeout(() => resolve(), 100); + }); const response3 = await polywrapClient.invoke({ uri: "wrap://ens/ws.polywrap.eth", method: "receive", args: { - id: result.value - } - }) + id: result.value, + }, + }); if (!response1.ok) fail(response1.error); - let data1 = response1.value.map((msg) => msg.data) + let data1 = response1.value.map((msg) => msg.data); expect(data1).toEqual(["1", "2"]); if (!response2.ok) fail(response2.error); - let data2 = response2.value.map((msg) => msg.data) + let data2 = response2.value.map((msg) => msg.data); expect(data2).toEqual(["3"]); if (!response3.ok) fail(response3.error); - let data3 = response3.value.map((msg) => msg.data) + let data3 = response3.value.map((msg) => msg.data); expect(data3).toEqual([]); }); }); diff --git a/packages/js/plugins/ws/src/__tests__/e2e/helpers/getClient.ts b/packages/js/plugins/ws/src/__tests__/e2e/helpers/getClient.ts new file mode 100644 index 0000000000..8a0eab1eed --- /dev/null +++ b/packages/js/plugins/ws/src/__tests__/e2e/helpers/getClient.ts @@ -0,0 +1,50 @@ +import { + RecursiveResolver, + PackageToWrapperCacheResolver, + WrapperCache, + StaticResolver, + StaticResolverLike, +} from "@polywrap/uri-resolvers-js"; +import { coreInterfaceUris } from "@polywrap/core-js"; +import { PolywrapClient } from "@polywrap/client-js"; +import { fileSystemPlugin } from "@polywrap/fs-plugin-js"; +import { fileSystemResolverPlugin } from "@polywrap/fs-resolver-plugin-js"; +import { ExtendableUriResolver } from "@polywrap/uri-resolver-extensions-js"; +import { wsPlugin } from "../../.."; + +export const getClient = (staticResolvers?: StaticResolverLike[]) => { + return new PolywrapClient( + { + interfaces: [ + { + interface: coreInterfaceUris.uriResolver, + implementations: ["wrap://ens/fs-resolver.polywrap.eth"], + }, + ], + resolver: RecursiveResolver.from( + PackageToWrapperCacheResolver.from( + [ + StaticResolver.from([ + { + uri: "wrap://ens/ws.polywrap.eth", + package: wsPlugin({}), + }, + { + uri: "wrap://ens/fs-resolver.polywrap.eth", + package: fileSystemResolverPlugin({}), + }, + { + uri: "wrap://ens/fs.polywrap.eth", + package: fileSystemPlugin({}), + }, + ...(staticResolvers ?? []), + ]), + new ExtendableUriResolver(), + ], + new WrapperCache() + ) + ), + }, + { noDefaults: true } + ); +}; diff --git a/packages/js/plugins/ws/src/__tests__/e2e/integration.spec.ts b/packages/js/plugins/ws/src/__tests__/e2e/integration.spec.ts index f0c5a7ec3d..0fc1c90cde 100644 --- a/packages/js/plugins/ws/src/__tests__/e2e/integration.spec.ts +++ b/packages/js/plugins/ws/src/__tests__/e2e/integration.spec.ts @@ -1,32 +1,21 @@ -import { wsPlugin } from "../.."; - -import { Client, PluginModule } from "@polywrap/core-js"; -import { PolywrapClient } from "@polywrap/client-js" +import { CoreClient } from "@polywrap/core-js"; import { buildWrapper } from "@polywrap/test-env-js"; -import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; import WS from "jest-websocket-mock"; +import { PluginPackage } from "@polywrap/plugin-js"; +import { getClient } from "./helpers/getClient"; -jest.setTimeout(360000) +jest.setTimeout(360000); describe("e2e tests for WsPlugin", () => { - describe("integration", () => { - - let client: PolywrapClient; + let client: CoreClient; let server: WS; - const wrapperPath = `${__dirname}/integration` - const uri = `fs/${wrapperPath}/build` + const wrapperPath = `${__dirname}/integration`; + const uri = `fs/${wrapperPath}/build`; beforeAll(async () => { - client = new PolywrapClient({ - plugins: [ - { - uri: "wrap://ens/ws.polywrap.eth", - plugin: wsPlugin({}), - }, - ], - }); + client = getClient(); await buildWrapper(wrapperPath); }); @@ -40,45 +29,34 @@ describe("e2e tests for WsPlugin", () => { }); it("send", async () => { - await client.invoke({ uri, method: "send", args: { url: "ws://localhost:1234", - message: "test" - } - }) + message: "test", + }, + }); await expect(server).toReceiveMessage("test"); expect(server).toHaveReceivedMessages(["test"]); }); it("callback to plugin", async () => { - let msgs: string[] = [] - class MemoryPlugin extends PluginModule<{}> { - callback(args: { data: string }, _client: Client): void { - msgs.push(args.data) - } - } - let memoryPlugin = { - factory: () => { - return new MemoryPlugin({}) + let msgs: string[] = []; + + const memoryPlugin = PluginPackage.from(() => ({ + callback(args: { data: string }, _client: CoreClient): void { + msgs.push(args.data); }, - manifest: { } as WrapManifest, - } - client = new PolywrapClient({ - plugins: [ - { - uri: "wrap://ens/memory.polywrap.eth", - plugin: memoryPlugin - }, - { - uri: "wrap://ens/ws.polywrap.eth", - plugin: wsPlugin({}), - }, - ], - }); + })); + + client = getClient([ + { + uri: "wrap://ens/memory.polywrap.eth", + package: memoryPlugin, + }, + ]); await client.invoke({ uri, @@ -87,49 +65,46 @@ describe("e2e tests for WsPlugin", () => { url: "ws://localhost:1234", callback: { uri: "wrap://ens/memory.polywrap.eth", - method: "callback" - } - } + method: "callback", + }, + }, }); - server.send("1") - server.send("2") + server.send("1"); + server.send("2"); // wait for callbacks to be called - await new Promise(async (resolve) => {setTimeout(() => resolve(), 1)}) + await new Promise(async (resolve) => { + setTimeout(() => resolve(), 1); + }); - expect(msgs).toEqual(["1","2"]) + expect(msgs).toEqual(["1", "2"]); }); it("callback to wrapper", async () => { - let value: Record = {} - class MemoryPlugin extends PluginModule<{}> { - set(args: { key: string, value: string }, _client: Client): boolean { - value[args.key] = args.value - return true - } - get(args: { key: string }, _client: Client): string | null { - return value[args.key] ?? null - } - } - let memoryPlugin = { - factory: () => { - return new MemoryPlugin({}) + let value: Record = {}; + + const memoryPlugin = PluginPackage.from(() => ({ + set( + args: { key: string; value: string }, + _client: CoreClient + ): boolean { + value[args.key] = args.value; + return true; }, - manifest: { } as WrapManifest, - } - client = new PolywrapClient({ - plugins: [ + get(args: { key: string }, _client: CoreClient): string | null { + return value[args.key] ?? null; + }, + })); + + client = getClient([ + [ { uri: "wrap://ens/memory.polywrap.eth", - plugin: memoryPlugin - }, - { - uri: "wrap://ens/ws.polywrap.eth", - plugin: wsPlugin({}), + package: memoryPlugin, }, ], - }); + ]); await client.invoke({ uri, @@ -138,45 +113,44 @@ describe("e2e tests for WsPlugin", () => { url: "ws://localhost:1234", callback: { uri, - method: "callback" + method: "callback", }, - message: "test" - } + message: "test", + }, }); server.send("1"); - + await expect(server).toReceiveMessage("test"); expect(server).toHaveReceivedMessages(["test"]); }); it("cache", async () => { - let t1 = setTimeout(() => { - server.send("1") - }, 10) + server.send("1"); + }, 10); let t2 = setTimeout(() => { - server.send("2") - }, 20) + server.send("2"); + }, 20); let t3 = setTimeout(() => { - server.send("3") - }, 30) - + server.send("3"); + }, 30); + const response = await client.invoke({ uri, method: "get", args: { url: "ws://localhost:1234", - timeout: 20 - } + timeout: 20, + }, }); if (!response.ok) fail(response.error); - expect(response.value).toEqual(["1","2"]) + expect(response.value).toEqual(["1", "2"]); - clearTimeout(t1) - clearTimeout(t2) - clearTimeout(t3) + clearTimeout(t1); + clearTimeout(t2); + clearTimeout(t3); }); }); }); diff --git a/packages/js/plugins/ws/src/index.ts b/packages/js/plugins/ws/src/index.ts index 8f1a930018..9eac814330 100644 --- a/packages/js/plugins/ws/src/index.ts +++ b/packages/js/plugins/ws/src/index.ts @@ -1,5 +1,5 @@ import { - Client, + CoreClient, Module, Message, Callback, @@ -14,7 +14,7 @@ import { manifest, } from "./wrap"; -import { PluginFactory } from "@polywrap/core-js"; +import { PluginFactory, PluginPackage } from "@polywrap/plugin-js"; type NoConfig = Record; @@ -24,7 +24,7 @@ export class WsPlugin extends Module { private _caches: Record = {}; private _mutex = true; - public async open(args: Args_open, _client: Client): Promise { + public async open(args: Args_open, _client: CoreClient): Promise { const id = this._sockets.length; const socket = new WebSocket(args.url); this._sockets.push(socket); @@ -40,7 +40,7 @@ export class WsPlugin extends Module { }); } - public async close(args: Args_close, _client: Client): Promise { + public async close(args: Args_close, _client: CoreClient): Promise { this._sockets[args.id].close(); return await new Promise((resolve) => { this._sockets[args.id].onclose = () => { @@ -49,12 +49,12 @@ export class WsPlugin extends Module { }); } - public send(args: Args_send, _client: Client): boolean { + public send(args: Args_send, _client: CoreClient): boolean { this._sockets[args.id].send(args.message); return true; } - public addCallback(args: Args_addCallback, _client: Client): boolean { + public addCallback(args: Args_addCallback, _client: CoreClient): boolean { const callbackId = this._callbackId(args.callback); this._callbacks[callbackId] = async (msg) => { await _client.invoke<{ callback: boolean }>({ @@ -70,7 +70,10 @@ export class WsPlugin extends Module { return true; } - public removeCallback(args: Args_removeCallback, _client: Client): boolean { + public removeCallback( + args: Args_removeCallback, + _client: CoreClient + ): boolean { const callbackId = this._callbackId(args.callback); this._sockets[args.id].removeEventListener( "message", @@ -79,7 +82,7 @@ export class WsPlugin extends Module { return true; } - public addCache(args: Args_addCache, _client: Client): boolean { + public addCache(args: Args_addCache, _client: CoreClient): boolean { const callback = { uri: args.id.toString(), method: "cache" }; const callbackId = this._callbackId(callback); this._caches[args.id] = []; @@ -103,7 +106,7 @@ export class WsPlugin extends Module { return true; } - public removeCache(args: Args_removeCache, _client: Client): boolean { + public removeCache(args: Args_removeCache, _client: CoreClient): boolean { const callback = { uri: args.id.toString(), method: "cache" }; const callbackId = this._callbackId(callback); this._sockets[args.id].removeEventListener( @@ -115,7 +118,7 @@ export class WsPlugin extends Module { public async receive( args: Args_receive, - _client: Client + _client: CoreClient ): Promise { return await new Promise((resolve) => { let interval: ReturnType; @@ -153,11 +156,7 @@ export class WsPlugin extends Module { } } -export const wsPlugin: PluginFactory = () => { - return { - factory: () => new WsPlugin({}), - manifest, - }; -}; +export const wsPlugin: PluginFactory = () => + new PluginPackage(new WsPlugin({}), manifest); export const plugin = wsPlugin; diff --git a/packages/js/react/src/__tests__/app/SimpleStorage.tsx b/packages/js/react/src/__tests__/app/SimpleStorage.tsx index 5698884977..e9787d1ed2 100644 --- a/packages/js/react/src/__tests__/app/SimpleStorage.tsx +++ b/packages/js/react/src/__tests__/app/SimpleStorage.tsx @@ -1,12 +1,16 @@ -import { usePolywrapQuery, PolywrapProvider, usePolywrapClient, createPolywrapProvider } from "@polywrap/react"; -import { PluginRegistration } from "@polywrap/client-js"; +import { + usePolywrapQuery, + PolywrapProvider, + usePolywrapClient, + createPolywrapProvider, +} from "@polywrap/react"; // eslint-disable-next-line import/no-extraneous-dependencies import React from "react"; -import { Env } from "@polywrap/core-js"; +import { Env, IUriPackage, Uri } from "@polywrap/core-js"; const SimpleStorage = ({ uri }: { uri: string }) => { const { execute: deployContract, data: deployData } = usePolywrapQuery<{ - deployContract: string + deployContract: string; }>({ uri, query: `mutation { @@ -31,8 +35,8 @@ const SimpleStorage = ({ uri }: { uri: string }) => { }`, variables: { value: 5, - address: deployData?.deployContract - } + address: deployData?.deployContract, + }, }); const { execute: getStorageData, data: currentStorage } = usePolywrapQuery({ @@ -77,15 +81,15 @@ const CustomProvider = createPolywrapProvider("custom"); export const SimpleStorageContainer = ({ envs, - plugins, + packages, ensUri, }: { - envs: Env[] - plugins: PluginRegistration[]; + envs: Env[]; + packages: IUriPackage[]; ensUri: string; }) => ( - + diff --git a/packages/js/react/src/__tests__/config.ts b/packages/js/react/src/__tests__/config.ts index 224ac9932f..7f41c9be99 100644 --- a/packages/js/react/src/__tests__/config.ts +++ b/packages/js/react/src/__tests__/config.ts @@ -1,17 +1,21 @@ -import { Env, PluginRegistration } from "@polywrap/core-js"; +import { Env, IUriPackage, Uri } from "@polywrap/core-js"; import { plugin as ensResolverPlugin } from "@polywrap/ens-resolver-plugin-js"; -import { Connection, Connections, plugin as ethereumPlugin } from "@polywrap/ethereum-plugin-js"; +import { + Connection, + Connections, + plugin as ethereumPlugin, +} from "@polywrap/ethereum-plugin-js"; import { plugin as ipfsPlugin } from "@polywrap/ipfs-plugin-js"; import { defaultIpfsProviders } from "@polywrap/client-config-builder-js"; export function createPlugins( ensAddress: string, ethereumProvider: string -): PluginRegistration[] { +): IUriPackage[] { return [ { uri: "wrap://ens/ethereum.polywrap.eth", - plugin: ethereumPlugin({ + package: ethereumPlugin({ connections: new Connections({ networks: { testnet: new Connection({ provider: ethereumProvider }), @@ -21,11 +25,11 @@ export function createPlugins( }, { uri: "wrap://ens/ipfs.polywrap.eth", - plugin: ipfsPlugin({}), + package: ipfsPlugin({}), }, { uri: "wrap://ens/ens-resolver.polywrap.eth", - plugin: ensResolverPlugin({ + package: ensResolverPlugin({ addresses: { testnet: ensAddress, }, @@ -41,7 +45,7 @@ export function createEnvs(ipfsProvider: string): Env[] { env: { provider: ipfsProvider, fallbackProviders: defaultIpfsProviders, - } - } + }, + }, ]; -} \ No newline at end of file +} diff --git a/packages/js/react/src/__tests__/integration.spec.tsx b/packages/js/react/src/__tests__/integration.spec.tsx index bbf4349363..8cfcc13c51 100644 --- a/packages/js/react/src/__tests__/integration.spec.tsx +++ b/packages/js/react/src/__tests__/integration.spec.tsx @@ -7,10 +7,10 @@ import { stopTestEnvironment, buildAndDeployWrapper, ensAddresses, - providers + providers, } from "@polywrap/test-env-js"; import { GetPathToTestWrappers } from "@polywrap/test-cases"; -import { Env, PluginRegistration } from "@polywrap/core-js"; +import { Env, IUriPackage, Uri } from "@polywrap/core-js"; // eslint-disable-next-line import/no-extraneous-dependencies import React from "react"; @@ -19,7 +19,7 @@ jest.setTimeout(360000); describe("Polywrap React Integration", () => { let envs: Env[]; - let plugins: PluginRegistration[]; + let packages: IUriPackage[]; let ensUri: string; let wrapper: { ensDomain: string; @@ -31,7 +31,7 @@ describe("Polywrap React Integration", () => { envs = createEnvs(providers.ipfs); - plugins = createPlugins(ensAddresses.ensAddress, providers.ethereum); + packages = createPlugins(ensAddresses.ensAddress, providers.ethereum); wrapper = await buildAndDeployWrapper({ wrapperAbsPath: `${GetPathToTestWrappers()}/wasm-as/simple-storage`, @@ -47,7 +47,9 @@ describe("Polywrap React Integration", () => { }); it("Deploys, read and write on Smart Contract ", async () => { - render(); + render( + + ); fireEvent.click(screen.getByText("Deploy")); await waitFor(() => screen.getByText(/0x/), { timeout: 30000 }); diff --git a/packages/js/react/src/__tests__/usePolywrapClient.spec.tsx b/packages/js/react/src/__tests__/usePolywrapClient.spec.tsx index 212f2a554a..074340d0c6 100644 --- a/packages/js/react/src/__tests__/usePolywrapClient.spec.tsx +++ b/packages/js/react/src/__tests__/usePolywrapClient.spec.tsx @@ -6,25 +6,21 @@ import { } from ".."; import { createPlugins, createEnvs } from "./config"; -import { Env, PluginRegistration } from "@polywrap/core-js"; +import { Env, IUriPackage, Uri } from "@polywrap/core-js"; import { ensAddresses, providers, initTestEnvironment, - stopTestEnvironment + stopTestEnvironment, } from "@polywrap/test-env-js"; -import { - renderHook, - RenderHookOptions, - cleanup -} from "@testing-library/react-hooks"; +import { renderHook, RenderHookOptions } from "@testing-library/react-hooks"; jest.setTimeout(360000); describe("usePolywrapClient hook", () => { let envs: Env[]; - let plugins: PluginRegistration[]; + let packages: IUriPackage[]; let WrapperProvider: RenderHookOptions; beforeAll(async () => { @@ -32,13 +28,13 @@ describe("usePolywrapClient hook", () => { envs = createEnvs(providers.ipfs); - plugins = createPlugins(ensAddresses.ensAddress, providers.ethereum); + packages = createPlugins(ensAddresses.ensAddress, providers.ethereum); WrapperProvider = { wrapper: PolywrapProvider, initialProps: { envs, - plugins, + packages, }, }; }); @@ -47,25 +43,6 @@ describe("usePolywrapClient hook", () => { await stopTestEnvironment(); }); - function getClient( - options?: UsePolywrapClientProps - ) { - const hook = () => usePolywrapClient(options); - - const { result: hookResult } = renderHook(hook, WrapperProvider); - - const result = hookResult.current; - cleanup(); - return result; - } - - it("Should return client with plugins", async () => { - const client = getClient(); - - expect(client).toBeTruthy(); - expect(client.getPlugins().length).toBeGreaterThan(0); - }); - it("Should throw error because there's no provider with expected key ", async () => { const props: UsePolywrapClientProps = { provider: "Non existent Polywrap Provider", @@ -84,9 +61,9 @@ describe("usePolywrapClient hook", () => { createPolywrapProvider("other"); const props: UsePolywrapClientProps = { - provider: "other" + provider: "other", }; - + const hook = () => usePolywrapClient(props); const { result } = renderHook(hook, WrapperProvider); diff --git a/packages/js/react/src/__tests__/usePolywrapInvoke.spec.tsx b/packages/js/react/src/__tests__/usePolywrapInvoke.spec.tsx index db46dfd36b..a5fbbf5aa6 100644 --- a/packages/js/react/src/__tests__/usePolywrapInvoke.spec.tsx +++ b/packages/js/react/src/__tests__/usePolywrapInvoke.spec.tsx @@ -6,12 +6,13 @@ import { import { UsePolywrapInvokeProps } from "../invoke"; import { createPlugins, createEnvs } from "./config"; -import { Env, PluginRegistration } from "@polywrap/core-js"; +import { Env, IUriPackage, Uri } from "@polywrap/core-js"; import { initTestEnvironment, stopTestEnvironment, ensAddresses, - providers, buildWrapper, + providers, + buildWrapper, } from "@polywrap/test-env-js"; import { GetPathToTestWrappers } from "@polywrap/test-cases"; @@ -19,16 +20,15 @@ import { renderHook, act, RenderHookOptions, - cleanup + cleanup, } from "@testing-library/react-hooks"; jest.setTimeout(360000); describe("usePolywrapInvoke hook", () => { let uri: string; - let envUri: string; let envs: Env[]; - let plugins: PluginRegistration[]; + let packages: IUriPackage[]; let WrapperProvider: RenderHookOptions; beforeAll(async () => { @@ -36,19 +36,15 @@ describe("usePolywrapInvoke hook", () => { const simpleStoragePath = `${GetPathToTestWrappers()}/wasm-as/simple-storage`; await buildWrapper(simpleStoragePath); - uri = `fs/${simpleStoragePath}/build` - - const simpleEnvPath = `${GetPathToTestWrappers()}/wasm-as/simple-env-types`; - await buildWrapper(simpleEnvPath); - envUri = `fs/${simpleEnvPath}/build` + uri = `fs/${simpleStoragePath}/build`; envs = createEnvs(providers.ipfs); - plugins = createPlugins(ensAddresses.ensAddress, providers.ethereum); + packages = createPlugins(ensAddresses.ensAddress, providers.ethereum); WrapperProvider = { wrapper: PolywrapProvider, initialProps: { envs, - plugins, + packages, }, }; }); @@ -57,9 +53,7 @@ describe("usePolywrapInvoke hook", () => { await stopTestEnvironment(); }); - async function sendQuery( - options: UsePolywrapInvokeProps - ) { + async function sendQuery(options: UsePolywrapInvokeProps) { const hook = () => usePolywrapInvoke(options); const { result: hookResult } = renderHook(hook, WrapperProvider); @@ -76,11 +70,12 @@ describe("usePolywrapInvoke hook", () => { async function sendQueryWithExecVariables( options: UsePolywrapInvokeProps ) { - const hook = () => usePolywrapInvoke({ - uri: options.uri, - method: options.method, - provider: options.provider - }); + const hook = () => + usePolywrapInvoke({ + uri: options.uri, + method: options.method, + provider: options.provider, + }); const { result: hookResult } = renderHook(hook, WrapperProvider); @@ -133,7 +128,9 @@ describe("usePolywrapInvoke hook", () => { }, }; - const { data: getDataData } = await sendQuery(getStorageDataInvocation); + const { data: getDataData } = await sendQuery( + getStorageDataInvocation + ); expect(getDataData).toBe(5); }); @@ -147,7 +144,8 @@ describe("usePolywrapInvoke hook", () => { }, }; - const getDataStorageHook = () => usePolywrapInvoke(getStorageDataInvocation); + const getDataStorageHook = () => + usePolywrapInvoke(getStorageDataInvocation); const { result } = renderHook(getDataStorageHook); expect(result.error?.message).toMatch( @@ -167,7 +165,8 @@ describe("usePolywrapInvoke hook", () => { }, }; - const getDataStorageHook = () => usePolywrapInvoke(getStorageDataInvocation); + const getDataStorageHook = () => + usePolywrapInvoke(getStorageDataInvocation); const { result } = renderHook(getDataStorageHook, WrapperProvider); expect(result.error?.message).toMatch( @@ -186,7 +185,9 @@ describe("usePolywrapInvoke hook", () => { }, }; - const { data: address } = await sendQueryWithExecVariables(deployInvoke); + const { data: address } = await sendQueryWithExecVariables( + deployInvoke + ); const setStorageInvocation: UsePolywrapInvokeProps = { uri, @@ -215,7 +216,9 @@ describe("usePolywrapInvoke hook", () => { }, }; - const { data: getDataData } = await sendQueryWithExecVariables(getStorageDataInvocation); + const { data: getDataData } = await sendQueryWithExecVariables( + getStorageDataInvocation + ); expect(getDataData).toBe(3); }); }); diff --git a/packages/js/react/src/__tests__/usePolywrapQuery.spec.tsx b/packages/js/react/src/__tests__/usePolywrapQuery.spec.tsx index 6591acf6a4..f81ae3d7c2 100644 --- a/packages/js/react/src/__tests__/usePolywrapQuery.spec.tsx +++ b/packages/js/react/src/__tests__/usePolywrapQuery.spec.tsx @@ -8,12 +8,13 @@ import { } from "../query" import { createPlugins, createEnvs } from "./config"; -import { Env, PluginRegistration } from "@polywrap/core-js"; +import { Env, IUriPackage, Uri } from "@polywrap/core-js"; import { initTestEnvironment, stopTestEnvironment, ensAddresses, - providers, buildWrapper, + providers, + buildWrapper, } from "@polywrap/test-env-js"; import { GetPathToTestWrappers } from "@polywrap/test-cases"; @@ -21,16 +22,15 @@ import { renderHook, act, RenderHookOptions, - cleanup + cleanup, } from "@testing-library/react-hooks"; jest.setTimeout(360000); describe("usePolywrapQuery hook", () => { let uri: string; - let envUri: string; let envs: Env[]; - let plugins: PluginRegistration[]; + let packages: IUriPackage[]; let WrapperProvider: RenderHookOptions; beforeAll(async () => { @@ -38,19 +38,18 @@ describe("usePolywrapQuery hook", () => { const simpleStoragePath = `${GetPathToTestWrappers()}/wasm-as/simple-storage`; await buildWrapper(simpleStoragePath); - uri = `fs/${simpleStoragePath}/build` + uri = `fs/${simpleStoragePath}/build`; const simpleEnvPath = `${GetPathToTestWrappers()}/wasm-as/simple-env-types`; await buildWrapper(simpleEnvPath); - envUri = `fs/${simpleEnvPath}/build` envs = createEnvs(providers.ipfs); - plugins = createPlugins(ensAddresses.ensAddress, providers.ethereum); + packages = createPlugins(ensAddresses.ensAddress, providers.ethereum); WrapperProvider = { wrapper: PolywrapProvider, initialProps: { envs, - plugins, + packages, }, }; }); @@ -75,10 +74,15 @@ describe("usePolywrapQuery hook", () => { return result; } - async function sendQueryWithExecVariables>( - options: UsePolywrapQueryProps - ) { - const hook = () => usePolywrapQuery({ uri: options.uri, query: options.query, provider: options.provider}); + async function sendQueryWithExecVariables< + TData extends Record + >(options: UsePolywrapQueryProps) { + const hook = () => + usePolywrapQuery({ + uri: options.uri, + query: options.query, + provider: options.provider, + }); const { result: hookResult } = renderHook(hook, WrapperProvider); @@ -104,7 +108,7 @@ describe("usePolywrapQuery hook", () => { }; const { data } = await sendQuery<{ - deployContract: string + deployContract: string; }>(deployQuery); const setStorageDataQuery: UsePolywrapQueryProps = { @@ -141,7 +145,7 @@ describe("usePolywrapQuery hook", () => { }; const { data: getDataData } = await sendQuery<{ - getData: number + getData: number; }>(getStorageDataQuery); expect(getDataData?.getData).toBe(5); }); @@ -159,7 +163,7 @@ describe("usePolywrapQuery hook", () => { }; const { data } = await sendQuery<{ - deployContract: string + deployContract: string; }>(deployQuery); const setStorageDataQuery: UsePolywrapQueryProps = { @@ -255,7 +259,7 @@ describe("usePolywrapQuery hook", () => { }; const { data } = await sendQueryWithExecVariables<{ - deployContract: string + deployContract: string; }>(deployQuery); const setStorageDataQuery: UsePolywrapQueryProps = { @@ -294,7 +298,9 @@ describe("usePolywrapQuery hook", () => { `, }; - const { data: getDataData } = await sendQueryWithExecVariables(getStorageDataQuery); + const { data: getDataData } = await sendQueryWithExecVariables( + getStorageDataQuery + ); expect(getDataData?.getData).toBe(3); }); }); \ No newline at end of file diff --git a/packages/js/react/src/provider.tsx b/packages/js/react/src/provider.tsx index 3c23105eb8..79800dcda2 100644 --- a/packages/js/react/src/provider.tsx +++ b/packages/js/react/src/provider.tsx @@ -33,21 +33,34 @@ export function createPolywrapProvider( ClientContext: React.createContext({} as PolywrapClient) }; - return ({ envs, redirects, plugins, interfaces, tracerConfig, children }) => { - + return ({ + envs, + redirects, + wrappers, + packages, + interfaces, + tracerConfig, + children, + }) => { const [clientCreated, setClientCreated] = React.useState(false); React.useEffect(() => { - // If the client has already been set for this provider if (PROVIDERS[name].client) { - throw Error( + throw Error( `Duplicate PolywrapProvider detected. Please use "createPolywrapProvider("provider-name")".` ); } // Instantiate the client - PROVIDERS[name].client = new PolywrapClient({ redirects, plugins, interfaces, envs, tracerConfig }); + PROVIDERS[name].client = new PolywrapClient({ + redirects, + wrappers, + packages, + interfaces, + envs, + tracerConfig, + }); setClientCreated(true); @@ -55,7 +68,7 @@ export function createPolywrapProvider( // this provider is unmounted return function cleanup() { PROVIDERS[name].client = undefined; - } + }; }); // Get the provider's context diff --git a/packages/js/uri-resolver-extensions/package.json b/packages/js/uri-resolver-extensions/package.json index baac4298e5..a966782c7f 100644 --- a/packages/js/uri-resolver-extensions/package.json +++ b/packages/js/uri-resolver-extensions/package.json @@ -26,7 +26,6 @@ "@polywrap/wrap-manifest-types-js": "0.9.3" }, "devDependencies": { - "@polywrap/os-js": "0.9.3", "@types/jest": "26.0.8", "jest": "26.6.3", "rimraf": "3.0.2", diff --git a/packages/js/uri-resolver-extensions/src/ExtendableUriResolver.ts b/packages/js/uri-resolver-extensions/src/ExtendableUriResolver.ts index 36eaf67397..27e04e2e62 100644 --- a/packages/js/uri-resolver-extensions/src/ExtendableUriResolver.ts +++ b/packages/js/uri-resolver-extensions/src/ExtendableUriResolver.ts @@ -2,16 +2,18 @@ import { UriResolverWrapper } from "./UriResolverWrapper"; import { Uri, - Client, + CoreClient, IUriResolver, getImplementations, coreInterfaceUris, IUriResolutionContext, UriPackageOrWrapper, - UriResolutionResult, } from "@polywrap/core-js"; import { Result, ResultOk } from "@polywrap/result"; -import { UriResolverAggregatorBase } from "@polywrap/uri-resolvers-js"; +import { + UriResolverAggregatorBase, + UriResolutionResult, +} from "@polywrap/uri-resolvers-js"; export class ExtendableUriResolver extends UriResolverAggregatorBase< Error, @@ -26,13 +28,13 @@ export class ExtendableUriResolver extends UriResolverAggregatorBase< async getUriResolvers( uri: Uri, - client: Client, + client: CoreClient, resolutionContext: IUriResolutionContext ): Promise[], Error>> { const getImplementationsResult = getImplementations( coreInterfaceUris.uriResolver, - client.getInterfaces(), - client.getRedirects() + client.getInterfaces() ?? [], + client.getRedirects() ?? [] ); if (!getImplementationsResult.ok) { @@ -50,7 +52,7 @@ export class ExtendableUriResolver extends UriResolverAggregatorBase< async tryResolveUri( uri: Uri, - client: Client, + client: CoreClient, resolutionContext: IUriResolutionContext ): Promise> { const result = await this.getUriResolvers(uri, client, resolutionContext); diff --git a/packages/js/uri-resolver-extensions/src/ResolverExtensionLoader.ts b/packages/js/uri-resolver-extensions/src/ResolverExtensionLoader.ts index efc2c12d6e..bdb9caa397 100644 --- a/packages/js/uri-resolver-extensions/src/ResolverExtensionLoader.ts +++ b/packages/js/uri-resolver-extensions/src/ResolverExtensionLoader.ts @@ -1,10 +1,15 @@ -import { Uri, Client, Wrapper, IUriResolutionContext } from "@polywrap/core-js"; +import { + Uri, + CoreClient, + Wrapper, + IUriResolutionContext, +} from "@polywrap/core-js"; import { Result, ResultErr, ResultOk } from "@polywrap/result"; export const loadResolverExtension = async ( currentUri: Uri, resolverExtensionUri: Uri, - client: Client, + client: CoreClient, resolutionContext: IUriResolutionContext ): Promise> => { const result = await client.tryResolveUri({ diff --git a/packages/js/uri-resolver-extensions/src/UriResolverExtensionFileReader.ts b/packages/js/uri-resolver-extensions/src/UriResolverExtensionFileReader.ts index 4152a907c6..b367d8df4d 100644 --- a/packages/js/uri-resolver-extensions/src/UriResolverExtensionFileReader.ts +++ b/packages/js/uri-resolver-extensions/src/UriResolverExtensionFileReader.ts @@ -1,5 +1,5 @@ import { - Client, + CoreClient, combinePaths, InvokeOptions, InvokeResult, @@ -14,7 +14,7 @@ export class UriResolverExtensionFileReader implements IFileReader { constructor( private readonly resolverExtensionUri: Uri, private readonly wrapperUri: Uri, - private readonly client: Client + private readonly client: CoreClient ) {} async readFile(filePath: string): Promise> { diff --git a/packages/js/uri-resolver-extensions/src/UriResolverWrapper.ts b/packages/js/uri-resolver-extensions/src/UriResolverWrapper.ts index d01aeb6a2e..ba7ed50958 100644 --- a/packages/js/uri-resolver-extensions/src/UriResolverWrapper.ts +++ b/packages/js/uri-resolver-extensions/src/UriResolverWrapper.ts @@ -3,16 +3,18 @@ import { loadResolverExtension } from "./ResolverExtensionLoader"; import { Uri, - Client, + CoreClient, UriResolverInterface, IUriResolutionContext, - UriResolutionResult, UriPackageOrWrapper, getEnvFromUriHistory, } from "@polywrap/core-js"; import { Result, ResultOk } from "@polywrap/result"; import { WasmPackage } from "@polywrap/wasm-js"; -import { ResolverWithHistory } from "@polywrap/uri-resolvers-js"; +import { + ResolverWithHistory, + UriResolutionResult, +} from "@polywrap/uri-resolvers-js"; export class UriResolverWrapper extends ResolverWithHistory { constructor(public readonly implementationUri: Uri) { @@ -24,7 +26,7 @@ export class UriResolverWrapper extends ResolverWithHistory { protected async _tryResolveUri( uri: Uri, - client: Client, + client: CoreClient, resolutionContext: IUriResolutionContext ): Promise> { const result = await tryResolveUriWithImplementation( @@ -58,7 +60,7 @@ export class UriResolverWrapper extends ResolverWithHistory { const tryResolveUriWithImplementation = async ( uri: Uri, implementationUri: Uri, - client: Client, + client: CoreClient, resolutionContext: IUriResolutionContext ): Promise< Result diff --git a/packages/js/uri-resolvers/package.json b/packages/js/uri-resolvers/package.json index 90e9f43602..709bcdcfd2 100644 --- a/packages/js/uri-resolvers/package.json +++ b/packages/js/uri-resolvers/package.json @@ -24,7 +24,6 @@ "@polywrap/wrap-manifest-types-js": "0.9.3" }, "devDependencies": { - "@polywrap/os-js": "0.9.3", "@types/jest": "26.0.8", "jest": "26.6.3", "rimraf": "3.0.2", diff --git a/packages/js/uri-resolvers/src/aggregator/UriResolverAggregator.ts b/packages/js/uri-resolvers/src/aggregator/UriResolverAggregator.ts index 387a55b1cd..dc7123501b 100644 --- a/packages/js/uri-resolvers/src/aggregator/UriResolverAggregator.ts +++ b/packages/js/uri-resolvers/src/aggregator/UriResolverAggregator.ts @@ -1,18 +1,17 @@ import { UriResolverAggregatorBase } from "./UriResolverAggregatorBase"; -import { UriResolverLike } from "../helpers"; -import { buildUriResolver } from "../utils"; +import { UriResolver, UriResolverLike } from "../helpers"; import { Result, ResultOk } from "@polywrap/result"; -import { IUriResolver, Uri, Client } from "@polywrap/core-js"; +import { IUriResolver, Uri, CoreClient } from "@polywrap/core-js"; export type GetResolversFunc = ( uri: Uri, - client: Client + client: CoreClient ) => Promise[]>; export type GetResolversWithErrorFunc = ( uri: Uri, - client: Client + client: CoreClient ) => Promise[], TError>>; export class UriResolverAggregator< @@ -28,7 +27,7 @@ export class UriResolverAggregator< constructor( resolvers: ( uri: Uri, - client: Client + client: CoreClient ) => Promise[], TGetResolversError>>, resolverName?: string ); @@ -42,7 +41,7 @@ export class UriResolverAggregator< ) { super(); if (Array.isArray(resolvers)) { - this.resolvers = resolvers.map((x) => buildUriResolver(x)); + this.resolvers = resolvers.map((x) => UriResolver.from(x)); } else { this.resolvers = resolvers; } @@ -50,7 +49,7 @@ export class UriResolverAggregator< async getUriResolvers( uri: Uri, - client: Client + client: CoreClient ): Promise[], TGetResolversError>> { if (Array.isArray(this.resolvers)) { return ResultOk(this.resolvers); diff --git a/packages/js/uri-resolvers/src/aggregator/UriResolverAggregatorBase.ts b/packages/js/uri-resolvers/src/aggregator/UriResolverAggregatorBase.ts index 49606ea6e9..7247fd0523 100644 --- a/packages/js/uri-resolvers/src/aggregator/UriResolverAggregatorBase.ts +++ b/packages/js/uri-resolvers/src/aggregator/UriResolverAggregatorBase.ts @@ -1,9 +1,10 @@ +import { UriResolutionResult } from "../helpers"; + import { IUriResolver, Uri, - Client, + CoreClient, IUriResolutionContext, - UriResolutionResult, UriPackageOrWrapper, } from "@polywrap/core-js"; import { Result } from "@polywrap/result"; @@ -14,13 +15,13 @@ export abstract class UriResolverAggregatorBase< > implements IUriResolver { abstract getUriResolvers( uri: Uri, - client: Client, + client: CoreClient, resolutionContext: IUriResolutionContext ): Promise[], TGetResolversError>>; async tryResolveUri( uri: Uri, - client: Client, + client: CoreClient, resolutionContext: IUriResolutionContext ): Promise< Result @@ -52,7 +53,7 @@ export abstract class UriResolverAggregatorBase< protected async tryResolveUriWithResolvers( uri: Uri, - client: Client, + client: CoreClient, resolvers: IUriResolver[], resolutionContext: IUriResolutionContext ): Promise> { diff --git a/packages/js/uri-resolvers/src/cache/PackageToWrapperCacheResolver.ts b/packages/js/uri-resolvers/src/cache/PackageToWrapperCacheResolver.ts index d670ff88b3..ca7198aa51 100644 --- a/packages/js/uri-resolvers/src/cache/PackageToWrapperCacheResolver.ts +++ b/packages/js/uri-resolvers/src/cache/PackageToWrapperCacheResolver.ts @@ -1,42 +1,49 @@ import { IWrapperCache } from "./IWrapperCache"; -import { UriResolverLike } from "../helpers"; -import { buildUriResolver } from "../utils"; +import { UriResolver, UriResolutionResult, UriResolverLike } from "../helpers"; import { IUriResolver, Uri, - Client, + CoreClient, IUriResolutionContext, UriPackageOrWrapper, - UriResolutionResult, } from "@polywrap/core-js"; import { DeserializeManifestOptions } from "@polywrap/wrap-manifest-types-js"; import { Result } from "@polywrap/result"; -export class PackageToWrapperCacheResolver implements IUriResolver { +export class PackageToWrapperCacheResolver + implements IUriResolver { name: string; - resolverToCache: IUriResolver; constructor( + private resolverToCache: IUriResolver, private cache: IWrapperCache, - resolverToCache: UriResolverLike, private options?: { deserializeManifestOptions?: DeserializeManifestOptions; - resolverName?: string; endOnRedirect?: boolean; } - ) { - this.resolverToCache = buildUriResolver( - resolverToCache, - options?.resolverName + ) {} + + static from( + resolver: UriResolverLike, + cache: IWrapperCache, + options?: { + deserializeManifestOptions?: DeserializeManifestOptions; + endOnRedirect?: boolean; + } + ): PackageToWrapperCacheResolver { + return new PackageToWrapperCacheResolver( + UriResolver.from(resolver), + cache, + options ); } async tryResolveUri( uri: Uri, - client: Client, + client: CoreClient, resolutionContext: IUriResolutionContext - ): Promise> { + ): Promise> { const wrapper = await this.cache.get(uri); if (wrapper) { diff --git a/packages/js/uri-resolvers/src/helpers/InfiniteLoopError.ts b/packages/js/uri-resolvers/src/helpers/InfiniteLoopError.ts index dc40802bc8..bffca25a94 100644 --- a/packages/js/uri-resolvers/src/helpers/InfiniteLoopError.ts +++ b/packages/js/uri-resolvers/src/helpers/InfiniteLoopError.ts @@ -1,4 +1,4 @@ -import { getUriResolutionPath } from "../utils"; +import { getUriResolutionPath } from "./getUriResolutionPath"; import { Uri, IUriResolutionStep } from "@polywrap/core-js"; diff --git a/packages/js/uri-resolvers/src/helpers/RecursiveResolver.ts b/packages/js/uri-resolvers/src/helpers/RecursiveResolver.ts index ccb1d75619..eb46c971b9 100644 --- a/packages/js/uri-resolvers/src/helpers/RecursiveResolver.ts +++ b/packages/js/uri-resolvers/src/helpers/RecursiveResolver.ts @@ -1,22 +1,30 @@ import { InfiniteLoopError } from "./InfiniteLoopError"; +import { UriResolverLike } from "./UriResolverLike"; +import { UriResolutionResult } from "./UriResolutionResult"; +import { UriResolver } from "./UriResolver"; +import { Result } from "@polywrap/result"; import { IUriResolver, Uri, - Client, + CoreClient, IUriResolutionContext, UriPackageOrWrapper, - UriResolutionResult, } from "@polywrap/core-js"; -import { Result } from "@polywrap/result"; export class RecursiveResolver implements IUriResolver { constructor(private resolver: IUriResolver) {} + static from( + resolver: UriResolverLike + ): RecursiveResolver { + return new RecursiveResolver(UriResolver.from(resolver)); + } + async tryResolveUri( uri: Uri, - client: Client, + client: CoreClient, resolutionContext: IUriResolutionContext ): Promise> { if (resolutionContext.isResolving(uri)) { @@ -48,7 +56,7 @@ export class RecursiveResolver private async tryResolveAgainIfRedirect( result: Result, uri: Uri, - client: Client, + client: CoreClient, resolutionContext: IUriResolutionContext ): Promise> { if (result.ok && result.value.type === "uri") { diff --git a/packages/js/uri-resolvers/src/helpers/ResolverWithHistory.ts b/packages/js/uri-resolvers/src/helpers/ResolverWithHistory.ts index 09f4394b02..d435589d35 100644 --- a/packages/js/uri-resolvers/src/helpers/ResolverWithHistory.ts +++ b/packages/js/uri-resolvers/src/helpers/ResolverWithHistory.ts @@ -1,7 +1,7 @@ import { IUriResolver, Uri, - Client, + CoreClient, IUriResolutionContext, UriPackageOrWrapper, } from "@polywrap/core-js"; @@ -11,7 +11,7 @@ export abstract class ResolverWithHistory implements IUriResolver { async tryResolveUri( uri: Uri, - client: Client, + client: CoreClient, resolutionContext: IUriResolutionContext ): Promise> { const result = await this._tryResolveUri(uri, client, resolutionContext); @@ -32,7 +32,7 @@ export abstract class ResolverWithHistory protected abstract _tryResolveUri( uri: Uri, - client: Client, + client: CoreClient, resolutionContext: IUriResolutionContext ): Promise>; } diff --git a/packages/js/uri-resolvers/src/helpers/ResolverWithLoopGuard.ts b/packages/js/uri-resolvers/src/helpers/ResolverWithLoopGuard.ts index 3f95a55430..9ea8ea8697 100644 --- a/packages/js/uri-resolvers/src/helpers/ResolverWithLoopGuard.ts +++ b/packages/js/uri-resolvers/src/helpers/ResolverWithLoopGuard.ts @@ -1,28 +1,32 @@ import { InfiniteLoopError } from "./InfiniteLoopError"; -import { UriResolverLike } from "../helpers"; -import { buildUriResolver } from "../utils"; +import { UriResolverLike } from "./UriResolverLike"; +import { UriResolutionResult } from "./UriResolutionResult"; +import { UriResolver } from "./UriResolver"; -import { Result } from "@polywrap/result"; import { IUriResolver, Uri, - Client, + CoreClient, IUriResolutionContext, UriPackageOrWrapper, - UriResolutionResult, } from "@polywrap/core-js"; +import { Result } from "@polywrap/result"; export class ResolverWithLoopGuard implements IUriResolver { - private resolver: IUriResolver; + constructor(private resolver: IUriResolver) {} - constructor(resolver: UriResolverLike) { - this.resolver = buildUriResolver(resolver); + static from( + resolver: UriResolverLike + ): ResolverWithLoopGuard { + return new ResolverWithLoopGuard( + UriResolver.from(resolver) + ); } async tryResolveUri( uri: Uri, - client: Client, + client: CoreClient, resolutionContext: IUriResolutionContext ): Promise> { if (resolutionContext.isResolving(uri)) { diff --git a/packages/js/core/src/uri-resolution/UriResolutionResult.ts b/packages/js/uri-resolvers/src/helpers/UriResolutionResult.ts similarity index 69% rename from packages/js/core/src/uri-resolution/UriResolutionResult.ts rename to packages/js/uri-resolvers/src/helpers/UriResolutionResult.ts index 51a3306eb3..30e00333aa 100644 --- a/packages/js/core/src/uri-resolution/UriResolutionResult.ts +++ b/packages/js/uri-resolvers/src/helpers/UriResolutionResult.ts @@ -1,6 +1,10 @@ -import { UriPackageOrWrapper, IUriResolutionStep } from "."; -import { Uri, IWrapPackage, Wrapper } from ".."; - +import { + UriPackageOrWrapper, + IUriResolutionStep, + Uri, + IWrapPackage, + Wrapper, +} from "@polywrap/core-js"; import { Result, ResultOk, ResultErr } from "@polywrap/result"; export class UriResolutionResult { @@ -17,16 +21,25 @@ export class UriResolutionResult { wrapper: Wrapper ): Result; static ok( - uri: Uri, + uriPackageOrWrapper: UriPackageOrWrapper + ): Result; + static ok( + uriPackageOrWrapper: Uri | UriPackageOrWrapper, packageOrWrapper?: IWrapPackage | Wrapper ): Result { if (!packageOrWrapper) { - return ResultOk({ - type: "uri", - uri, - } as UriPackageOrWrapper); + if ((uriPackageOrWrapper as UriPackageOrWrapper).type) { + return ResultOk(uriPackageOrWrapper as UriPackageOrWrapper); + } else { + return ResultOk({ + type: "uri", + uri: uriPackageOrWrapper as Uri, + } as UriPackageOrWrapper); + } } + const uri = uriPackageOrWrapper as Uri; + const wrapPackage = packageOrWrapper as Partial; if (wrapPackage.createWrapper) { diff --git a/packages/js/uri-resolvers/src/helpers/UriResolver.ts b/packages/js/uri-resolvers/src/helpers/UriResolver.ts new file mode 100644 index 0000000000..f9b55411bc --- /dev/null +++ b/packages/js/uri-resolvers/src/helpers/UriResolver.ts @@ -0,0 +1,70 @@ +import { UriResolverAggregator } from "../aggregator"; +import { PackageResolver } from "../packages"; +import { WrapperResolver } from "../wrappers"; +import { UriResolverLike } from "."; +import { RedirectResolver } from "../redirects"; + +import { Result } from "@polywrap/result"; +import { + IUriResolver, + Uri, + CoreClient, + IUriRedirect, + IUriPackage, + IUriWrapper, +} from "@polywrap/core-js"; + +export class UriResolver { + static from( + resolverLike: UriResolverLike, + resolverName?: string + ): IUriResolver { + if (Array.isArray(resolverLike)) { + return new UriResolverAggregator( + (resolverLike as UriResolverLike[]).map((x) => + UriResolver.from(x, resolverName) + ), + resolverName + ) as IUriResolver; + } else if (typeof resolverLike === "function") { + return new UriResolverAggregator( + resolverLike as ( + uri: Uri, + client: CoreClient + ) => Promise>, + resolverName + ) as IUriResolver; + } else if ((resolverLike as IUriResolver).tryResolveUri !== undefined) { + return resolverLike as IUriResolver; + } else if ( + (resolverLike as IUriRedirect).from !== undefined && + (resolverLike as IUriRedirect).to !== undefined + ) { + const uriRedirect = resolverLike as IUriRedirect; + return (new RedirectResolver( + uriRedirect.from, + uriRedirect.to + ) as unknown) as IUriResolver; + } else if ( + (resolverLike as IUriPackage).uri !== undefined && + (resolverLike as IUriPackage).package !== undefined + ) { + const uriPackage = resolverLike as IUriPackage; + return (new PackageResolver( + Uri.from(uriPackage.uri), + uriPackage.package + ) as unknown) as IUriResolver; + } else if ( + (resolverLike as IUriWrapper).uri !== undefined && + (resolverLike as IUriWrapper).wrapper !== undefined + ) { + const uriWrapper = resolverLike as IUriWrapper; + return (new WrapperResolver( + Uri.from(uriWrapper.uri), + uriWrapper.wrapper + ) as unknown) as IUriResolver; + } else { + throw new Error("Unknown resolver-like type"); + } + } +} diff --git a/packages/js/uri-resolvers/src/helpers/UriResolverLike.ts b/packages/js/uri-resolvers/src/helpers/UriResolverLike.ts index 4009a14991..100756f54b 100644 --- a/packages/js/uri-resolvers/src/helpers/UriResolverLike.ts +++ b/packages/js/uri-resolvers/src/helpers/UriResolverLike.ts @@ -1,14 +1,14 @@ import { - IUriResolver, - UriRedirect, Uri, - PluginRegistration, + IUriResolver, + IUriRedirect, IUriPackage, + IUriWrapper, } from "@polywrap/core-js"; export type UriResolverLike = | IUriResolver - | UriRedirect - | UriResolverLike[] - | IUriPackage - | PluginRegistration; + | IUriRedirect + | IUriPackage + | IUriWrapper + | UriResolverLike[]; diff --git a/packages/js/uri-resolvers/src/utils/clean-uri-history/CleanResolutionStep.ts b/packages/js/uri-resolvers/src/helpers/clean-uri-history/CleanResolutionStep.ts similarity index 100% rename from packages/js/uri-resolvers/src/utils/clean-uri-history/CleanResolutionStep.ts rename to packages/js/uri-resolvers/src/helpers/clean-uri-history/CleanResolutionStep.ts diff --git a/packages/js/uri-resolvers/src/utils/clean-uri-history/buildCleanUriHistory.ts b/packages/js/uri-resolvers/src/helpers/clean-uri-history/buildCleanUriHistory.ts similarity index 100% rename from packages/js/uri-resolvers/src/utils/clean-uri-history/buildCleanUriHistory.ts rename to packages/js/uri-resolvers/src/helpers/clean-uri-history/buildCleanUriHistory.ts diff --git a/packages/js/uri-resolvers/src/utils/clean-uri-history/index.ts b/packages/js/uri-resolvers/src/helpers/clean-uri-history/index.ts similarity index 100% rename from packages/js/uri-resolvers/src/utils/clean-uri-history/index.ts rename to packages/js/uri-resolvers/src/helpers/clean-uri-history/index.ts diff --git a/packages/js/uri-resolvers/src/utils/getUriResolutionPath.ts b/packages/js/uri-resolvers/src/helpers/getUriResolutionPath.ts similarity index 100% rename from packages/js/uri-resolvers/src/utils/getUriResolutionPath.ts rename to packages/js/uri-resolvers/src/helpers/getUriResolutionPath.ts diff --git a/packages/js/uri-resolvers/src/helpers/index.ts b/packages/js/uri-resolvers/src/helpers/index.ts index c27983d614..c054b304a7 100644 --- a/packages/js/uri-resolvers/src/helpers/index.ts +++ b/packages/js/uri-resolvers/src/helpers/index.ts @@ -1,5 +1,9 @@ +export * from "./UriResolutionResult"; +export * from "./UriResolverLike"; +export * from "./ResolverWithHistory"; export * from "./InfiniteLoopError"; export * from "./RecursiveResolver"; -export * from "./ResolverWithHistory"; export * from "./ResolverWithLoopGuard"; -export * from "./UriResolverLike"; +export * from "./UriResolver"; +export * from "./clean-uri-history"; +export * from "./getUriResolutionPath"; diff --git a/packages/js/uri-resolvers/src/index.ts b/packages/js/uri-resolvers/src/index.ts index 1fe5c9fe93..78d2434370 100644 --- a/packages/js/uri-resolvers/src/index.ts +++ b/packages/js/uri-resolvers/src/index.ts @@ -1,8 +1,7 @@ export * from "./aggregator"; export * from "./cache"; export * from "./legacy"; -export * from "./plugins"; export * from "./redirects"; export * from "./packages"; export * from "./helpers"; -export * from "./utils"; +export * from "./static"; diff --git a/packages/js/uri-resolvers/src/legacy/LegacyPluginsResolver.ts b/packages/js/uri-resolvers/src/legacy/LegacyPluginsResolver.ts deleted file mode 100644 index 683a3ca5b9..0000000000 --- a/packages/js/uri-resolvers/src/legacy/LegacyPluginsResolver.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { UriResolverAggregator, PluginResolver } from ".."; - -import { Uri, Client } from "@polywrap/core-js"; - -export class LegacyPluginsResolver extends UriResolverAggregator { - constructor() { - super( - async (_: Uri, client: Client) => - client.getPlugins().map((x) => new PluginResolver(x)), - "LegacyPluginsResolver" - ); - } -} diff --git a/packages/js/uri-resolvers/src/legacy/LegacyRedirectsResolver.ts b/packages/js/uri-resolvers/src/legacy/LegacyRedirectsResolver.ts index 3452816a37..216b1e96c3 100644 --- a/packages/js/uri-resolvers/src/legacy/LegacyRedirectsResolver.ts +++ b/packages/js/uri-resolvers/src/legacy/LegacyRedirectsResolver.ts @@ -1,15 +1,17 @@ import { RedirectResolver } from ".."; import { UriResolverAggregator } from ".."; -import { Uri, Client } from "@polywrap/core-js"; +import { Uri, CoreClient } from "@polywrap/core-js"; export class LegacyRedirectsResolver extends UriResolverAggregator { constructor() { super( - async (uri: Uri, client: Client) => + async (uri: Uri, client: CoreClient) => client .getRedirects() - .map((redirect) => new RedirectResolver(redirect.from, redirect.to)), + ?.map( + (redirect) => new RedirectResolver(redirect.from, redirect.to) + ) ?? [], "LegacyRedirectsResolver" ); } diff --git a/packages/js/uri-resolvers/src/legacy/index.ts b/packages/js/uri-resolvers/src/legacy/index.ts index 671bc6f94a..c2822150ff 100644 --- a/packages/js/uri-resolvers/src/legacy/index.ts +++ b/packages/js/uri-resolvers/src/legacy/index.ts @@ -1,3 +1 @@ -export * from "./LegacyPluginsResolver"; export * from "./LegacyRedirectsResolver"; -export * from "../cache/PackageToWrapperCacheResolver"; diff --git a/packages/js/uri-resolvers/src/packages/PackageResolver.ts b/packages/js/uri-resolvers/src/packages/PackageResolver.ts index cb76741255..26684e56be 100644 --- a/packages/js/uri-resolvers/src/packages/PackageResolver.ts +++ b/packages/js/uri-resolvers/src/packages/PackageResolver.ts @@ -1,20 +1,18 @@ -import { - Uri, - IUriResolver, - IWrapPackage, - UriPackageOrWrapper, - UriResolutionResult, -} from "@polywrap/core-js"; -import { Result } from "@polywrap/result"; +import { ResolverWithHistory, UriResolutionResult } from "../helpers"; -export class PackageResolver implements IUriResolver { - constructor(private uri: Uri, private wrapPackage: IWrapPackage) {} +import { Uri, IWrapPackage, UriPackageOrWrapper } from "@polywrap/core-js"; +import { Result } from "@polywrap/result"; - public get name(): string { - return `PackageResolver (${this.uri.uri})`; +export class PackageResolver extends ResolverWithHistory { + constructor(private uri: Uri, private wrapPackage: IWrapPackage) { + super(); } - async tryResolveUri(uri: Uri): Promise> { + protected getStepDescription = (): string => `Package (${this.uri.uri})`; + + protected async _tryResolveUri( + uri: Uri + ): Promise> { if (uri.uri !== this.uri.uri) { return UriResolutionResult.ok(uri); } diff --git a/packages/js/uri-resolvers/src/plugins/PluginResolver.ts b/packages/js/uri-resolvers/src/plugins/PluginResolver.ts deleted file mode 100644 index eda6b05ca9..0000000000 --- a/packages/js/uri-resolvers/src/plugins/PluginResolver.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { ResolverWithHistory } from "../helpers"; - -import { - Uri, - PluginRegistration, - PluginWrapPackage, - UriResolutionResult, - UriPackageOrWrapper, -} from "@polywrap/core-js"; -import { Result } from "@polywrap/result"; - -export class PluginResolver extends ResolverWithHistory { - pluginUri: Uri; - - constructor( - private readonly pluginRegistration: PluginRegistration - ) { - super(); - this.pluginUri = Uri.from(pluginRegistration.uri); - } - - protected getStepDescription = (): string => `Plugin (${this.pluginUri.uri})`; - - protected async _tryResolveUri( - uri: Uri - ): Promise> { - if (uri.uri !== this.pluginUri.uri) { - return UriResolutionResult.ok(uri); - } - - const wrapPackage = new PluginWrapPackage( - uri, - this.pluginRegistration.plugin - ); - - return UriResolutionResult.ok(uri, wrapPackage); - } -} diff --git a/packages/js/uri-resolvers/src/plugins/PluginsResolver.ts b/packages/js/uri-resolvers/src/plugins/PluginsResolver.ts deleted file mode 100644 index c06d378a09..0000000000 --- a/packages/js/uri-resolvers/src/plugins/PluginsResolver.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { PluginResolver } from "./PluginResolver"; -import { UriResolverAggregator } from "../aggregator"; - -import { PluginRegistration, Uri } from "@polywrap/core-js"; - -export class PluginsResolver extends UriResolverAggregator { - constructor(pluginRegistrations: PluginRegistration[]) { - super( - pluginRegistrations.map((x) => new PluginResolver(x)), - "PluginsResolver" - ); - } -} diff --git a/packages/js/uri-resolvers/src/plugins/index.ts b/packages/js/uri-resolvers/src/plugins/index.ts deleted file mode 100644 index 728744cc30..0000000000 --- a/packages/js/uri-resolvers/src/plugins/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./PluginResolver"; -export * from "./PluginsResolver"; diff --git a/packages/js/uri-resolvers/src/redirects/RedirectResolver.ts b/packages/js/uri-resolvers/src/redirects/RedirectResolver.ts index 8da1f6df75..500a9e8e23 100644 --- a/packages/js/uri-resolvers/src/redirects/RedirectResolver.ts +++ b/packages/js/uri-resolvers/src/redirects/RedirectResolver.ts @@ -1,10 +1,6 @@ -import { ResolverWithHistory } from "../helpers"; +import { ResolverWithHistory, UriResolutionResult } from "../helpers"; -import { - Uri, - UriResolutionResult, - UriPackageOrWrapper, -} from "@polywrap/core-js"; +import { Uri, UriPackageOrWrapper } from "@polywrap/core-js"; import { Result } from "@polywrap/result"; export class RedirectResolver< diff --git a/packages/js/uri-resolvers/src/redirects/RedirectsResolver.ts b/packages/js/uri-resolvers/src/redirects/RedirectsResolver.ts deleted file mode 100644 index a2984e862b..0000000000 --- a/packages/js/uri-resolvers/src/redirects/RedirectsResolver.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { UriResolverAggregator } from "../aggregator"; - -import { Uri, UriRedirect } from "@polywrap/core-js"; - -export class RedirectsResolver< - TUri extends string | Uri = string -> extends UriResolverAggregator { - constructor(redirects: UriRedirect[], resolverName?: string) { - super(redirects, resolverName ?? "RedirectsResolver"); - } -} diff --git a/packages/js/uri-resolvers/src/redirects/index.ts b/packages/js/uri-resolvers/src/redirects/index.ts index 60ab4df414..f0cb134361 100644 --- a/packages/js/uri-resolvers/src/redirects/index.ts +++ b/packages/js/uri-resolvers/src/redirects/index.ts @@ -1,2 +1 @@ export * from "./RedirectResolver"; -export * from "./RedirectsResolver"; diff --git a/packages/js/uri-resolvers/src/static/StaticResolver.ts b/packages/js/uri-resolvers/src/static/StaticResolver.ts new file mode 100644 index 0000000000..52a550dbaa --- /dev/null +++ b/packages/js/uri-resolvers/src/static/StaticResolver.ts @@ -0,0 +1,108 @@ +import { UriResolutionResult, UriResolverLike } from "../helpers"; + +import { + CoreClient, + IUriResolutionContext, + IUriResolver, + Uri, + UriPackageOrWrapper, + IUriRedirect, + IUriPackage, + IUriWrapper, +} from "@polywrap/core-js"; +import { Result } from "@polywrap/result"; + +export class StaticResolver + implements IUriResolver { + constructor(public uriMap: Map) {} + + static from( + staticResolverLikes: UriResolverLike[] + ): StaticResolver { + const uriMap = new Map(); + for (const staticResolverLike of staticResolverLikes) { + if (Array.isArray(staticResolverLike)) { + const resolver = StaticResolver.from(staticResolverLike); + for (const [uri, uriPackageOrWrapper] of resolver.uriMap) { + uriMap.set(uri, uriPackageOrWrapper); + } + } else if ( + (staticResolverLike as IUriRedirect).from !== undefined && + (staticResolverLike as IUriRedirect).to !== undefined + ) { + const uriRedirect = staticResolverLike as IUriRedirect; + const from = Uri.from(uriRedirect.from); + + uriMap.set(from.uri, { + type: "uri", + uri: Uri.from(uriRedirect.to), + }); + } else if ( + (staticResolverLike as IUriPackage).uri !== undefined && + (staticResolverLike as IUriPackage).package !== undefined + ) { + const uriPackage = staticResolverLike as IUriPackage; + const uri = Uri.from(uriPackage.uri); + + uriMap.set(uri.uri, { + type: "package", + uri, + package: uriPackage.package, + }); + } else if ( + (staticResolverLike as IUriWrapper).uri !== undefined && + (staticResolverLike as IUriWrapper).wrapper !== undefined + ) { + const uriWrapper = staticResolverLike as IUriWrapper; + const uri = Uri.from(uriWrapper.uri); + + uriMap.set(uri.uri, { + type: "wrapper", + uri, + wrapper: uriWrapper.wrapper, + }); + } else { + throw new Error("Unknown static-resolver-like type provided."); + } + } + + return new StaticResolver(uriMap); + } + + async tryResolveUri( + uri: Uri, + _: CoreClient, + resolutionContext: IUriResolutionContext + ): Promise> { + const uriPackageOrWrapper = this.uriMap.get(uri.uri); + + let result: Result; + let description = ""; + + if (uriPackageOrWrapper) { + result = UriResolutionResult.ok(uriPackageOrWrapper); + switch (uriPackageOrWrapper.type) { + case "package": + description = `StaticResolver - Package (${uri.uri})`; + break; + case "wrapper": + description = `StaticResolver - Wrapper (${uri.uri})`; + break; + case "uri": + description = `StaticResolver - Redirect (${uri.uri} - ${uriPackageOrWrapper.uri.uri})`; + break; + } + } else { + result = UriResolutionResult.ok(uri); + description = `StaticResolver - Miss`; + } + + resolutionContext.trackStep({ + sourceUri: uri, + result, + description, + }); + + return result; + } +} diff --git a/packages/js/uri-resolvers/src/static/StaticResolverLike.ts b/packages/js/uri-resolvers/src/static/StaticResolverLike.ts new file mode 100644 index 0000000000..d2b1ce67a0 --- /dev/null +++ b/packages/js/uri-resolvers/src/static/StaticResolverLike.ts @@ -0,0 +1,7 @@ +import { IUriRedirect, Uri, IUriPackage, IUriWrapper } from "@polywrap/core-js"; + +export type StaticResolverLike = + | IUriRedirect + | IUriPackage + | IUriWrapper + | StaticResolverLike[]; diff --git a/packages/js/uri-resolvers/src/static/index.ts b/packages/js/uri-resolvers/src/static/index.ts new file mode 100644 index 0000000000..391b4bf950 --- /dev/null +++ b/packages/js/uri-resolvers/src/static/index.ts @@ -0,0 +1,2 @@ +export * from "./StaticResolver"; +export * from "./StaticResolverLike"; diff --git a/packages/js/uri-resolvers/src/utils/buildUriResolver.ts b/packages/js/uri-resolvers/src/utils/buildUriResolver.ts deleted file mode 100644 index c5d41ca3cb..0000000000 --- a/packages/js/uri-resolvers/src/utils/buildUriResolver.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { UriResolverAggregator } from "../aggregator"; -import { UriResolverLike } from "../helpers"; -import { PackageResolver } from "../packages"; - -import { Result } from "@polywrap/result"; -import { - IUriResolver, - Uri, - Client, - IWrapPackage, - IUriPackage, -} from "@polywrap/core-js"; - -export const buildUriResolver = ( - resolvable: UriResolverLike, - resolverName?: string -): IUriResolver => { - if (Array.isArray(resolvable)) { - return new UriResolverAggregator( - (resolvable as UriResolverLike[]).map((x) => - buildUriResolver(x, resolverName) - ), - resolverName - ) as IUriResolver; - } else if (typeof resolvable === "function") { - return new UriResolverAggregator( - resolvable as ( - uri: Uri, - client: Client - ) => Promise>, - resolverName - ) as IUriResolver; - } else if ((resolvable as Partial).createWrapper) { - const uriPackage = resolvable as IUriPackage; - return (new PackageResolver( - uriPackage.uri, - uriPackage.package - ) as unknown) as IUriResolver; - } else if ((resolvable as IUriResolver).tryResolveUri !== undefined) { - return resolvable as IUriResolver; - } else { - throw new Error("Unknown resolvable type"); - } -}; diff --git a/packages/js/uri-resolvers/src/utils/index.ts b/packages/js/uri-resolvers/src/utils/index.ts deleted file mode 100644 index a0cd814822..0000000000 --- a/packages/js/uri-resolvers/src/utils/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./buildUriResolver"; -export * from "./getUriResolutionPath"; -export * from "./clean-uri-history"; diff --git a/packages/js/uri-resolvers/src/wrappers/WrapperResolver.ts b/packages/js/uri-resolvers/src/wrappers/WrapperResolver.ts new file mode 100644 index 0000000000..de297fd6ce --- /dev/null +++ b/packages/js/uri-resolvers/src/wrappers/WrapperResolver.ts @@ -0,0 +1,22 @@ +import { ResolverWithHistory, UriResolutionResult } from "../helpers"; + +import { Uri, UriPackageOrWrapper, Wrapper } from "@polywrap/core-js"; +import { Result } from "@polywrap/result"; + +export class WrapperResolver extends ResolverWithHistory { + constructor(private uri: Uri, private wrapper: Wrapper) { + super(); + } + + protected getStepDescription = (): string => `Wrapper (${this.uri.uri})`; + + protected async _tryResolveUri( + uri: Uri + ): Promise> { + if (uri.uri !== this.uri.uri) { + return UriResolutionResult.ok(uri); + } + + return UriResolutionResult.ok(uri, this.wrapper); + } +} diff --git a/packages/js/uri-resolvers/src/wrappers/index.ts b/packages/js/uri-resolvers/src/wrappers/index.ts new file mode 100644 index 0000000000..e2b4876d3b --- /dev/null +++ b/packages/js/uri-resolvers/src/wrappers/index.ts @@ -0,0 +1 @@ +export * from "./WrapperResolver"; diff --git a/packages/js/wasm/package.json b/packages/js/wasm/package.json index d450f58aaa..8dbb4abb65 100644 --- a/packages/js/wasm/package.json +++ b/packages/js/wasm/package.json @@ -27,7 +27,6 @@ "@polywrap/wrap-manifest-types-js": "0.9.3" }, "devDependencies": { - "@polywrap/os-js": "0.9.3", "@types/jest": "26.0.8", "jest": "26.6.3", "rimraf": "3.0.2", diff --git a/packages/js/wasm/src/WasmWrapper.ts b/packages/js/wasm/src/WasmWrapper.ts index 84bab85961..1cb83f16d0 100644 --- a/packages/js/wasm/src/WasmWrapper.ts +++ b/packages/js/wasm/src/WasmWrapper.ts @@ -13,7 +13,7 @@ import { Wrapper, Uri, InvokeOptions, - Client, + CoreClient, InvocableResult, isBuffer, GetFileOptions, @@ -139,7 +139,7 @@ export class WasmWrapper implements Wrapper { @Tracer.traceMethod("WasmWrapper: invoke", TracingLevel.High) public async invoke( options: InvokeOptions, - client: Client + client: CoreClient ): Promise> { Tracer.setAttribute( "label", diff --git a/packages/js/wasm/src/imports.ts b/packages/js/wasm/src/imports.ts index 0ec6338fe2..4cecf0ae82 100644 --- a/packages/js/wasm/src/imports.ts +++ b/packages/js/wasm/src/imports.ts @@ -5,10 +5,10 @@ import { readBytes, readString, writeBytes, writeString } from "./buffer"; import { State } from "./WasmWrapper"; import { msgpackEncode } from "@polywrap/msgpack-js"; -import { Client } from "@polywrap/core-js"; +import { CoreClient } from "@polywrap/core-js"; export const createImports = (config: { - client: Client; + client: CoreClient; memory: WebAssembly.Memory; state: State; abort: (message: string) => never; diff --git a/packages/schema/bind/src/bindings/typescript/app/templates/types-ts.mustache b/packages/schema/bind/src/bindings/typescript/app/templates/types-ts.mustache index f02416fdc8..bc03dca396 100644 --- a/packages/schema/bind/src/bindings/typescript/app/templates/types-ts.mustache +++ b/packages/schema/bind/src/bindings/typescript/app/templates/types-ts.mustache @@ -3,7 +3,7 @@ import * as Types from "./"; // @ts-ignore import { - Client, + CoreClient, InvokeResult } from "@polywrap/core-js"; @@ -100,20 +100,20 @@ export const {{type}} = { {{#methods}} {{name}}: async ( args: {{parent.type}}_Args_{{name}}, - client: Client, + client: CoreClient, uri: string = "{{parent.uri}}" ): Promise> => { return client.invoke<{{#return}}{{#toTypescript}}{{toGraphQLType}}{{/toTypescript}}{{/return}}>({ uri, method: "{{name}}", - args: args as unknown as Record + args: (args as unknown) as Record, }); }{{^last}},{{/last}} {{^last}} {{/last}} {{/methods}} -} +}; {{/importedModuleTypes}} /// Imported Modules END /// diff --git a/packages/schema/bind/src/bindings/typescript/plugin/templates/index-ts.mustache b/packages/schema/bind/src/bindings/typescript/plugin/templates/index-ts.mustache index 315871f96d..4f5ca809d5 100644 --- a/packages/schema/bind/src/bindings/typescript/plugin/templates/index-ts.mustache +++ b/packages/schema/bind/src/bindings/typescript/plugin/templates/index-ts.mustache @@ -5,4 +5,4 @@ export * from "./wrap.info"; export * from "./module"; export * from "./types"; -export { Client } from "@polywrap/core-js"; +export { CoreClient } from "@polywrap/core-js"; diff --git a/packages/schema/bind/src/bindings/typescript/plugin/templates/module-ts.mustache b/packages/schema/bind/src/bindings/typescript/plugin/templates/module-ts.mustache index 2b5ca88c84..dac08c0e51 100644 --- a/packages/schema/bind/src/bindings/typescript/plugin/templates/module-ts.mustache +++ b/packages/schema/bind/src/bindings/typescript/plugin/templates/module-ts.mustache @@ -3,11 +3,8 @@ import * as Types from "./types"; -import { - Client, - PluginModule, - MaybeAsync -} from "@polywrap/core-js"; +import { CoreClient, MaybeAsync } from "@polywrap/core-js"; +import { PluginModule } from "@polywrap/plugin-js"; {{#moduleType}} {{#methods}} @@ -19,19 +16,16 @@ export interface Args_{{name}} { {{/methods}} {{/moduleType}} -export abstract class Module< - TConfig -> extends PluginModule< - TConfig{{#envType}}, - Types.Env{{/envType}} -> { +export abstract class Module extends PluginModule { {{#moduleType}} {{#methods}} - abstract {{name}}( args: Args_{{name}}, - client: Client + client: CoreClient ): MaybeAsync<{{#return}}{{#toTypescript}}{{toGraphQLType}}{{/toTypescript}}{{/return}}>; + {{^last}} + + {{/last}} {{/methods}} {{/moduleType}} } diff --git a/packages/schema/bind/src/bindings/typescript/plugin/templates/types-ts.mustache b/packages/schema/bind/src/bindings/typescript/plugin/templates/types-ts.mustache index fe7452afe4..e7eb717357 100644 --- a/packages/schema/bind/src/bindings/typescript/plugin/templates/types-ts.mustache +++ b/packages/schema/bind/src/bindings/typescript/plugin/templates/types-ts.mustache @@ -6,7 +6,7 @@ import * as Types from "./"; // @ts-ignore import { - Client,{{#interfaceTypes.length}} + CoreClient,{{#interfaceTypes.length}} Result,{{/interfaceTypes.length}} InvokeResult } from "@polywrap/core-js"; @@ -112,12 +112,12 @@ export const {{type}} = { {{#methods}} {{name}}: async ( args: {{parent.type}}_Args_{{name}}, - client: Client + client: CoreClient ): Promise> => { return client.invoke<{{#return}}{{#toTypescript}}{{toGraphQLType}}{{/toTypescript}}{{/return}}>({ uri: "{{parent.uri}}", method: "{{name}}", - args: args as unknown as Record + args: (args as unknown) as Record, }); }{{^last}},{{/last}} {{^last}} @@ -131,18 +131,17 @@ export const {{type}} = { export class {{#detectKeyword}}{{type}}{{/detectKeyword}} { public static interfaceUri: string = "{{uri}}"; - constructor(public uri: string) { - } + constructor(public uri: string) {} {{#methods}} - public async {{name}} ( + public async {{name}}( args: {{parent.type}}_Args_{{name}}, - client: Client + client: CoreClient ): Promise> { return client.invoke<{{#return}}{{#toTypescript}}{{toGraphQLType}}{{/toTypescript}}{{/return}}>({ uri: this.uri, method: "{{name}}", - args: args as unknown as Record + args: (args as unknown) as Record, }); } {{^last}} @@ -163,7 +162,9 @@ export class {{#detectKeyword}}{{namespace}}{{/detectKeyword}} { {{#capabilities}} {{#getImplementations}} {{#enabled}} - public static getImplementations(client: Client): Result { + public static getImplementations( + client: CoreClient + ): Result { return client.getImplementations(this.uri, {}); } {{/enabled}} diff --git a/packages/templates/plugin/typescript/package.json b/packages/templates/plugin/typescript/package.json index 2225cd9393..8a2a59ed4f 100644 --- a/packages/templates/plugin/typescript/package.json +++ b/packages/templates/plugin/typescript/package.json @@ -12,7 +12,8 @@ "test:watch": "jest --watch --passWithNoTests --verbose" }, "dependencies": { - "@polywrap/core-js": "0.9.3" + "@polywrap/core-js": "0.9.3", + "@polywrap/plugin-js": "0.9.3" }, "devDependencies": { "@polywrap/client-js": "0.9.3", diff --git a/packages/templates/wasm/assemblyscript/polywrap.wasm-linked.build.yaml b/packages/templates/wasm/assemblyscript/polywrap.wasm-linked.build.yaml deleted file mode 100644 index aabb15b6ed..0000000000 --- a/packages/templates/wasm/assemblyscript/polywrap.wasm-linked.build.yaml +++ /dev/null @@ -1,11 +0,0 @@ -format: 0.2.0 -strategies: - image: - name: template-wasm-as - node_version: "16.13.0" - include: - - ./src - - ./package.json -linked_packages: - - name: "@polywrap/wasm-as" - path: ../../../wasm/as diff --git a/packages/templates/wasm/assemblyscript/polywrap.wasm-linked.yaml b/packages/templates/wasm/assemblyscript/polywrap.wasm-linked.yaml deleted file mode 100644 index 294a567ae7..0000000000 --- a/packages/templates/wasm/assemblyscript/polywrap.wasm-linked.yaml +++ /dev/null @@ -1,9 +0,0 @@ -format: 0.2.0 -project: - name: template-wasm-as - type: wasm/assemblyscript -source: - module: ./src/index.ts - schema: ./src/schema.graphql -extensions: - build: ./polywrap.wasm-linked.build.yaml diff --git a/packages/templates/wasm/assemblyscript/src/__tests__/utils.ts b/packages/templates/wasm/assemblyscript/src/__tests__/utils.ts index 9db483949d..d57390c992 100644 --- a/packages/templates/wasm/assemblyscript/src/__tests__/utils.ts +++ b/packages/templates/wasm/assemblyscript/src/__tests__/utils.ts @@ -1,13 +1,17 @@ -import { ClientConfig } from "@polywrap/client-js"; +import { CoreClientConfig } from "@polywrap/client-js"; import { ensResolverPlugin } from "@polywrap/ens-resolver-plugin-js"; -import { Connection, Connections, ethereumPlugin } from "@polywrap/ethereum-plugin-js"; +import { + Connection, + Connections, + ethereumPlugin, +} from "@polywrap/ethereum-plugin-js"; import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; export function getPlugins( ethereum: string, ipfs: string, ensAddress: string -): Partial { +): Partial { return { redirects: [], plugins: [ @@ -25,7 +29,7 @@ export function getPlugins( connections: new Connections({ networks: { testnet: new Connection({ provider: ethereum }), - mainnet: new Connection({ provider: "http://localhost:8546", }), + mainnet: new Connection({ provider: "http://localhost:8546" }), }, defaultNetwork: "testnet", }), @@ -33,4 +37,4 @@ export function getPlugins( }, ], }; -} \ No newline at end of file +} diff --git a/packages/test-cases/cases/bind/sanity/output/app-ts/types.ts b/packages/test-cases/cases/bind/sanity/output/app-ts/types.ts index 03a1469314..df0a780c98 100644 --- a/packages/test-cases/cases/bind/sanity/output/app-ts/types.ts +++ b/packages/test-cases/cases/bind/sanity/output/app-ts/types.ts @@ -3,7 +3,7 @@ import * as Types from "./"; // @ts-ignore import { - Client, + CoreClient, InvokeResult } from "@polywrap/core-js"; @@ -185,39 +185,39 @@ interface TestImport_Module_Args_returnsArrayOfEnums { export const TestImport_Module = { importedMethod: async ( args: TestImport_Module_Args_importedMethod, - client: Client, + client: CoreClient, uri: string = "testimport.uri.eth" ): Promise> => { return client.invoke({ uri, method: "importedMethod", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, anotherMethod: async ( args: TestImport_Module_Args_anotherMethod, - client: Client, + client: CoreClient, uri: string = "testimport.uri.eth" ): Promise> => { return client.invoke({ uri, method: "anotherMethod", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, returnsArrayOfEnums: async ( args: TestImport_Module_Args_returnsArrayOfEnums, - client: Client, + client: CoreClient, uri: string = "testimport.uri.eth" ): Promise>> => { return client.invoke>({ uri, method: "returnsArrayOfEnums", - args: args as unknown as Record + args: (args as unknown) as Record, }); } -} +}; /// Imported Modules END /// diff --git a/packages/test-cases/cases/bind/sanity/output/plugin-ts/index.ts b/packages/test-cases/cases/bind/sanity/output/plugin-ts/index.ts index 315871f96d..4f5ca809d5 100644 --- a/packages/test-cases/cases/bind/sanity/output/plugin-ts/index.ts +++ b/packages/test-cases/cases/bind/sanity/output/plugin-ts/index.ts @@ -5,4 +5,4 @@ export * from "./wrap.info"; export * from "./module"; export * from "./types"; -export { Client } from "@polywrap/core-js"; +export { CoreClient } from "@polywrap/core-js"; diff --git a/packages/test-cases/cases/bind/sanity/output/plugin-ts/module.ts b/packages/test-cases/cases/bind/sanity/output/plugin-ts/module.ts index be2a490077..50b99303d6 100644 --- a/packages/test-cases/cases/bind/sanity/output/plugin-ts/module.ts +++ b/packages/test-cases/cases/bind/sanity/output/plugin-ts/module.ts @@ -3,11 +3,8 @@ import * as Types from "./types"; -import { - Client, - PluginModule, - MaybeAsync -} from "@polywrap/core-js"; +import { CoreClient, MaybeAsync } from "@polywrap/core-js"; +import { PluginModule } from "@polywrap/plugin-js"; export interface Args_moduleMethod { str: Types.String; @@ -41,30 +38,24 @@ export interface Args_if { if: Types._else; } -export abstract class Module< - TConfig -> extends PluginModule< - TConfig, - Types.Env -> { - +export abstract class Module extends PluginModule { abstract moduleMethod( args: Args_moduleMethod, - client: Client + client: CoreClient ): MaybeAsync; abstract objectMethod( args: Args_objectMethod, - client: Client + client: CoreClient ): MaybeAsync; abstract optionalEnvMethod( args: Args_optionalEnvMethod, - client: Client + client: CoreClient ): MaybeAsync; abstract if( args: Args_if, - client: Client + client: CoreClient ): MaybeAsync; } diff --git a/packages/test-cases/cases/bind/sanity/output/plugin-ts/types.ts b/packages/test-cases/cases/bind/sanity/output/plugin-ts/types.ts index 451dffce31..ee8e1a9efc 100644 --- a/packages/test-cases/cases/bind/sanity/output/plugin-ts/types.ts +++ b/packages/test-cases/cases/bind/sanity/output/plugin-ts/types.ts @@ -6,7 +6,7 @@ import * as Types from "./"; // @ts-ignore import { - Client, + CoreClient, Result, InvokeResult } from "@polywrap/core-js"; @@ -199,39 +199,38 @@ interface TestImport_Module_Args_returnsArrayOfEnums { export class TestImport_Module { public static interfaceUri: string = "testimport.uri.eth"; - constructor(public uri: string) { - } + constructor(public uri: string) {} - public async importedMethod ( + public async importedMethod( args: TestImport_Module_Args_importedMethod, - client: Client + client: CoreClient ): Promise> { return client.invoke({ uri: this.uri, method: "importedMethod", - args: args as unknown as Record + args: (args as unknown) as Record, }); } - public async anotherMethod ( + public async anotherMethod( args: TestImport_Module_Args_anotherMethod, - client: Client + client: CoreClient ): Promise> { return client.invoke({ uri: this.uri, method: "anotherMethod", - args: args as unknown as Record + args: (args as unknown) as Record, }); } - public async returnsArrayOfEnums ( + public async returnsArrayOfEnums( args: TestImport_Module_Args_returnsArrayOfEnums, - client: Client + client: CoreClient ): Promise>> { return client.invoke>({ uri: this.uri, method: "returnsArrayOfEnums", - args: args as unknown as Record + args: (args as unknown) as Record, }); } } @@ -241,7 +240,9 @@ export class TestImport_Module { export class TestImport { static uri: string = "testimport.uri.eth"; - public static getImplementations(client: Client): Result { + public static getImplementations( + client: CoreClient + ): Result { return client.getImplementations(this.uri, {}); } } diff --git a/packages/test-cases/cases/cli/app/codegen/004-custom-config/config.ts b/packages/test-cases/cases/cli/app/codegen/004-custom-config/config.ts index 0fa0a5a83b..aaf921f218 100644 --- a/packages/test-cases/cases/cli/app/codegen/004-custom-config/config.ts +++ b/packages/test-cases/cases/cli/app/codegen/004-custom-config/config.ts @@ -1,45 +1,45 @@ -import { PolywrapClientConfig } from "@polywrap/client-js"; -import { PluginModule } from "@polywrap/core-js"; -import { latestWrapManifestVersion, WrapManifest } from "@polywrap/wrap-manifest-types-js"; +import { + ClientConfigBuilder, + ClientConfig, +} from "@polywrap/client-config-builder-js"; +import { PluginModule, PluginPackage } from "@polywrap/plugin-js"; +import { + latestWrapManifestVersion, + WrapManifest, +} from "@polywrap/wrap-manifest-types-js"; interface Config extends Record { val: number; } class MockPlugin extends PluginModule { - - getData(_: unknown): number { return this.config.val; } + getData(_: unknown): number { + return this.config.val; + } setData(args: { value: number }) { this.config.val = +args.value; return true; } - deployContract(): string { return "0x100"; } + deployContract(): string { + return "0x100"; + } } const mockPlugin = () => { - return { - factory: () => new MockPlugin({ val: 0 }), - manifest: mockPluginManifest - }; + return PluginPackage.from(new MockPlugin({ val: 0 }), mockPluginManifest); }; -export function getClientConfig(defaultConfigs: Partial) { - if (defaultConfigs.plugins) { - defaultConfigs.plugins.push({ - uri: "wrap://ens/mock.eth", - plugin: mockPlugin(), - }); - } else { - defaultConfigs.plugins = [ +export function getCustomConfig(): Partial> { + return { + packages: [ { uri: "wrap://ens/mock.eth", - plugin: mockPlugin(), + package: mockPlugin(), }, - ]; - } - return defaultConfigs; + ], + }; } export const mockPluginManifest: WrapManifest = { @@ -47,80 +47,80 @@ export const mockPluginManifest: WrapManifest = { type: "plugin", version: latestWrapManifestVersion, abi: { - "version": "0.1", - "moduleType": { - "type": "Module", - "kind": 128, - "methods": [ + version: "0.1", + moduleType: { + type: "Module", + kind: 128, + methods: [ { - "type": "Method", - "name": "getData", - "required": true, - "kind": 64, - "return": { - "type": "Int", - "name": "getData", - "required": true, - "kind": 34, - "scalar": { - "type": "Int", - "name": "getData", - "required": true, - "kind": 4 - } - } + type: "Method", + name: "getData", + required: true, + kind: 64, + return: { + type: "Int", + name: "getData", + required: true, + kind: 34, + scalar: { + type: "Int", + name: "getData", + required: true, + kind: 4, + }, + }, }, { - "type": "Method", - "name": "setData", - "required": true, - "kind": 64, - "arguments": [ + type: "Method", + name: "setData", + required: true, + kind: 64, + arguments: [ { - "type": "Int", - "name": "value", - "required": true, - "kind": 34, - "scalar": { - "type": "Int", - "name": "value", - "required": true, - "kind": 4 - } - } + type: "Int", + name: "value", + required: true, + kind: 34, + scalar: { + type: "Int", + name: "value", + required: true, + kind: 4, + }, + }, ], - "return": { - "type": "Boolean", - "name": "setData", - "required": true, - "kind": 34, - "scalar": { - "type": "Boolean", - "name": "setData", - "required": true, - "kind": 4 - } - } + return: { + type: "Boolean", + name: "setData", + required: true, + kind: 34, + scalar: { + type: "Boolean", + name: "setData", + required: true, + kind: 4, + }, + }, }, { - "type": "Method", - "name": "deployContract", - "required": true, - "kind": 64, - "return": { - "type": "String", - "name": "deployContract", - "required": true, - "kind": 34, - "scalar": { - "type": "String", - "name": "deployContract", - "required": true, - "kind": 4 - } - } - } - ] - } - } -} + type: "Method", + name: "deployContract", + required: true, + kind: 64, + return: { + type: "String", + name: "deployContract", + required: true, + kind: 34, + scalar: { + type: "String", + name: "deployContract", + required: true, + kind: 4, + }, + }, + }, + ], + }, + }, +}; diff --git a/packages/test-cases/cases/cli/docgen/002-custom-config/config.ts b/packages/test-cases/cases/cli/docgen/002-custom-config/config.ts index cd5b1b6220..6306d59d75 100644 --- a/packages/test-cases/cases/cli/docgen/002-custom-config/config.ts +++ b/packages/test-cases/cases/cli/docgen/002-custom-config/config.ts @@ -1,45 +1,42 @@ -import { PolywrapClientConfig } from "@polywrap/client-js"; -import { PluginModule } from "@polywrap/core-js"; -import { latestWrapManifestVersion, WrapManifest } from "@polywrap/wrap-manifest-types-js"; +import { ClientConfig } from "@polywrap/client-config-builder-js"; +import { PluginModule, PluginPackage } from "@polywrap/plugin-js"; +import { + latestWrapManifestVersion, + WrapManifest, +} from "@polywrap/wrap-manifest-types-js"; interface Config extends Record { val: number; } class MockPlugin extends PluginModule { - - getData(_: unknown): number { return this.config.val; } + getData(_: unknown): number { + return this.config.val; + } setData(args: { value: number }) { this.config.val = +args.value; return true; } - deployContract(): string { return "0x100"; } + deployContract(): string { + return "0x100"; + } } const mockPlugin = () => { - return { - factory: () => new MockPlugin({ val: 0 }), - manifest: mockPluginManifest - }; + return PluginPackage.from(new MockPlugin({ val: 0 }), mockPluginManifest); }; -export function getClientConfig(defaultConfigs: Partial) { - if (defaultConfigs.plugins) { - defaultConfigs.plugins.push({ - uri: "wrap://ens/mock.eth", - plugin: mockPlugin(), - }); - } else { - defaultConfigs.plugins = [ +export function getCustomConfig(): Partial> { + return { + packages: [ { uri: "wrap://ens/mock.eth", - plugin: mockPlugin(), + package: mockPlugin(), }, - ]; - } - return defaultConfigs; + ], + }; } export const mockPluginManifest: WrapManifest = { @@ -47,81 +44,80 @@ export const mockPluginManifest: WrapManifest = { type: "plugin", version: latestWrapManifestVersion, abi: { - "version": "0.1", - "moduleType": { - "type": "Module", - "kind": 128, - "methods": [ + version: "0.1", + moduleType: { + type: "Module", + kind: 128, + methods: [ { - "type": "Method", - "name": "getData", - "required": true, - "kind": 64, - "return": { - "type": "Int", - "name": "getData", - "required": true, - "kind": 34, - "scalar": { - "type": "Int", - "name": "getData", - "required": true, - "kind": 4 - } - } + type: "Method", + name: "getData", + required: true, + kind: 64, + return: { + type: "Int", + name: "getData", + required: true, + kind: 34, + scalar: { + type: "Int", + name: "getData", + required: true, + kind: 4, + }, + }, }, { - "type": "Method", - "name": "setData", - "required": true, - "kind": 64, - "arguments": [ + type: "Method", + name: "setData", + required: true, + kind: 64, + arguments: [ { - "type": "Int", - "name": "value", - "required": true, - "kind": 34, - "scalar": { - "type": "Int", - "name": "value", - "required": true, - "kind": 4 - } - } + type: "Int", + name: "value", + required: true, + kind: 34, + scalar: { + type: "Int", + name: "value", + required: true, + kind: 4, + }, + }, ], - "return": { - "type": "Boolean", - "name": "setData", - "required": true, - "kind": 34, - "scalar": { - "type": "Boolean", - "name": "setData", - "required": true, - "kind": 4 - } - } + return: { + type: "Boolean", + name: "setData", + required: true, + kind: 34, + scalar: { + type: "Boolean", + name: "setData", + required: true, + kind: 4, + }, + }, }, { - "type": "Method", - "name": "deployContract", - "required": true, - "kind": 64, - "return": { - "type": "String", - "name": "deployContract", - "required": true, - "kind": 34, - "scalar": { - "type": "String", - "name": "deployContract", - "required": true, - "kind": 4 - } - } - } - ] - } - } -} - + type: "Method", + name: "deployContract", + required: true, + kind: 64, + return: { + type: "String", + name: "deployContract", + required: true, + kind: 34, + scalar: { + type: "String", + name: "deployContract", + required: true, + kind: 4, + }, + }, + }, + ], + }, + }, +}; diff --git a/packages/test-cases/cases/cli/plugin/codegen/001-sanity/expected/wrap/index.ts b/packages/test-cases/cases/cli/plugin/codegen/001-sanity/expected/wrap/index.ts index 315871f96d..4f5ca809d5 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/001-sanity/expected/wrap/index.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/001-sanity/expected/wrap/index.ts @@ -5,4 +5,4 @@ export * from "./wrap.info"; export * from "./module"; export * from "./types"; -export { Client } from "@polywrap/core-js"; +export { CoreClient } from "@polywrap/core-js"; diff --git a/packages/test-cases/cases/cli/plugin/codegen/001-sanity/expected/wrap/module.ts b/packages/test-cases/cases/cli/plugin/codegen/001-sanity/expected/wrap/module.ts index 69fb521c72..d08b1a1fda 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/001-sanity/expected/wrap/module.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/001-sanity/expected/wrap/module.ts @@ -3,11 +3,8 @@ import * as Types from "./types"; -import { - Client, - PluginModule, - MaybeAsync -} from "@polywrap/core-js"; +import { CoreClient, MaybeAsync } from "@polywrap/core-js"; +import { PluginModule } from "@polywrap/plugin-js"; export interface Args_methodOne { str: Types.String; @@ -18,20 +15,14 @@ export interface Args_methodTwo { arg: Types.UInt32; } -export abstract class Module< - TConfig -> extends PluginModule< - TConfig, - Types.Env -> { - +export abstract class Module extends PluginModule { abstract methodOne( args: Args_methodOne, - client: Client + client: CoreClient ): MaybeAsync; abstract methodTwo( args: Args_methodTwo, - client: Client + client: CoreClient ): MaybeAsync; } diff --git a/packages/test-cases/cases/cli/plugin/codegen/001-sanity/expected/wrap/types.ts b/packages/test-cases/cases/cli/plugin/codegen/001-sanity/expected/wrap/types.ts index 3172a4e4b0..e2cef98b68 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/001-sanity/expected/wrap/types.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/001-sanity/expected/wrap/types.ts @@ -6,7 +6,7 @@ import * as Types from "./"; // @ts-ignore import { - Client, + CoreClient, InvokeResult } from "@polywrap/core-js"; @@ -346,309 +346,309 @@ interface Ethereum_Module_Args_sendRPC { export const Ethereum_Module = { callContractView: async ( args: Ethereum_Module_Args_callContractView, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "callContractView", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, callContractStatic: async ( args: Ethereum_Module_Args_callContractStatic, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "callContractStatic", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getBalance: async ( args: Ethereum_Module_Args_getBalance, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getBalance", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, encodeParams: async ( args: Ethereum_Module_Args_encodeParams, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "encodeParams", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, encodeFunction: async ( args: Ethereum_Module_Args_encodeFunction, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "encodeFunction", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, solidityPack: async ( args: Ethereum_Module_Args_solidityPack, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "solidityPack", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, solidityKeccak256: async ( args: Ethereum_Module_Args_solidityKeccak256, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "solidityKeccak256", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, soliditySha256: async ( args: Ethereum_Module_Args_soliditySha256, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "soliditySha256", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getSignerAddress: async ( args: Ethereum_Module_Args_getSignerAddress, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getSignerAddress", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getSignerBalance: async ( args: Ethereum_Module_Args_getSignerBalance, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getSignerBalance", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getSignerTransactionCount: async ( args: Ethereum_Module_Args_getSignerTransactionCount, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getSignerTransactionCount", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getGasPrice: async ( args: Ethereum_Module_Args_getGasPrice, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getGasPrice", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, estimateTransactionGas: async ( args: Ethereum_Module_Args_estimateTransactionGas, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "estimateTransactionGas", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, estimateContractCallGas: async ( args: Ethereum_Module_Args_estimateContractCallGas, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "estimateContractCallGas", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, checkAddress: async ( args: Ethereum_Module_Args_checkAddress, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "checkAddress", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, toWei: async ( args: Ethereum_Module_Args_toWei, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "toWei", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, toEth: async ( args: Ethereum_Module_Args_toEth, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "toEth", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, awaitTransaction: async ( args: Ethereum_Module_Args_awaitTransaction, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "awaitTransaction", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, waitForEvent: async ( args: Ethereum_Module_Args_waitForEvent, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "waitForEvent", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getNetwork: async ( args: Ethereum_Module_Args_getNetwork, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getNetwork", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, requestAccounts: async ( args: Ethereum_Module_Args_requestAccounts, - client: Client + client: CoreClient ): Promise>> => { return client.invoke>({ uri: "ens/ethereum.polywrap.eth", method: "requestAccounts", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, callContractMethod: async ( args: Ethereum_Module_Args_callContractMethod, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "callContractMethod", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, callContractMethodAndWait: async ( args: Ethereum_Module_Args_callContractMethodAndWait, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "callContractMethodAndWait", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, sendTransaction: async ( args: Ethereum_Module_Args_sendTransaction, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "sendTransaction", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, sendTransactionAndWait: async ( args: Ethereum_Module_Args_sendTransactionAndWait, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "sendTransactionAndWait", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, deployContract: async ( args: Ethereum_Module_Args_deployContract, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "deployContract", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, signMessage: async ( args: Ethereum_Module_Args_signMessage, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "signMessage", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, sendRPC: async ( args: Ethereum_Module_Args_sendRPC, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "sendRPC", - args: args as unknown as Record + args: (args as unknown) as Record, }); } } diff --git a/packages/test-cases/cases/cli/plugin/codegen/002-single-module/expected/wrap/index.ts b/packages/test-cases/cases/cli/plugin/codegen/002-single-module/expected/wrap/index.ts index 315871f96d..4f5ca809d5 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/002-single-module/expected/wrap/index.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/002-single-module/expected/wrap/index.ts @@ -5,4 +5,4 @@ export * from "./wrap.info"; export * from "./module"; export * from "./types"; -export { Client } from "@polywrap/core-js"; +export { CoreClient } from "@polywrap/core-js"; diff --git a/packages/test-cases/cases/cli/plugin/codegen/002-single-module/expected/wrap/module.ts b/packages/test-cases/cases/cli/plugin/codegen/002-single-module/expected/wrap/module.ts index d180a0c0e0..0643894c24 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/002-single-module/expected/wrap/module.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/002-single-module/expected/wrap/module.ts @@ -3,26 +3,17 @@ import * as Types from "./types"; -import { - Client, - PluginModule, - MaybeAsync -} from "@polywrap/core-js"; +import { CoreClient, MaybeAsync } from "@polywrap/core-js"; +import { PluginModule } from "@polywrap/plugin-js"; export interface Args_method { str: Types.String; optStr?: Types.String | null; } -export abstract class Module< - TConfig -> extends PluginModule< - TConfig, - Types.Env -> { - +export abstract class Module extends PluginModule { abstract method( args: Args_method, - client: Client + client: CoreClient ): MaybeAsync; } diff --git a/packages/test-cases/cases/cli/plugin/codegen/002-single-module/expected/wrap/types.ts b/packages/test-cases/cases/cli/plugin/codegen/002-single-module/expected/wrap/types.ts index 3172a4e4b0..e2cef98b68 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/002-single-module/expected/wrap/types.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/002-single-module/expected/wrap/types.ts @@ -6,7 +6,7 @@ import * as Types from "./"; // @ts-ignore import { - Client, + CoreClient, InvokeResult } from "@polywrap/core-js"; @@ -346,309 +346,309 @@ interface Ethereum_Module_Args_sendRPC { export const Ethereum_Module = { callContractView: async ( args: Ethereum_Module_Args_callContractView, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "callContractView", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, callContractStatic: async ( args: Ethereum_Module_Args_callContractStatic, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "callContractStatic", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getBalance: async ( args: Ethereum_Module_Args_getBalance, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getBalance", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, encodeParams: async ( args: Ethereum_Module_Args_encodeParams, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "encodeParams", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, encodeFunction: async ( args: Ethereum_Module_Args_encodeFunction, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "encodeFunction", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, solidityPack: async ( args: Ethereum_Module_Args_solidityPack, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "solidityPack", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, solidityKeccak256: async ( args: Ethereum_Module_Args_solidityKeccak256, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "solidityKeccak256", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, soliditySha256: async ( args: Ethereum_Module_Args_soliditySha256, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "soliditySha256", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getSignerAddress: async ( args: Ethereum_Module_Args_getSignerAddress, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getSignerAddress", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getSignerBalance: async ( args: Ethereum_Module_Args_getSignerBalance, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getSignerBalance", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getSignerTransactionCount: async ( args: Ethereum_Module_Args_getSignerTransactionCount, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getSignerTransactionCount", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getGasPrice: async ( args: Ethereum_Module_Args_getGasPrice, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getGasPrice", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, estimateTransactionGas: async ( args: Ethereum_Module_Args_estimateTransactionGas, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "estimateTransactionGas", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, estimateContractCallGas: async ( args: Ethereum_Module_Args_estimateContractCallGas, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "estimateContractCallGas", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, checkAddress: async ( args: Ethereum_Module_Args_checkAddress, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "checkAddress", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, toWei: async ( args: Ethereum_Module_Args_toWei, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "toWei", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, toEth: async ( args: Ethereum_Module_Args_toEth, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "toEth", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, awaitTransaction: async ( args: Ethereum_Module_Args_awaitTransaction, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "awaitTransaction", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, waitForEvent: async ( args: Ethereum_Module_Args_waitForEvent, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "waitForEvent", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getNetwork: async ( args: Ethereum_Module_Args_getNetwork, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getNetwork", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, requestAccounts: async ( args: Ethereum_Module_Args_requestAccounts, - client: Client + client: CoreClient ): Promise>> => { return client.invoke>({ uri: "ens/ethereum.polywrap.eth", method: "requestAccounts", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, callContractMethod: async ( args: Ethereum_Module_Args_callContractMethod, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "callContractMethod", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, callContractMethodAndWait: async ( args: Ethereum_Module_Args_callContractMethodAndWait, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "callContractMethodAndWait", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, sendTransaction: async ( args: Ethereum_Module_Args_sendTransaction, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "sendTransaction", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, sendTransactionAndWait: async ( args: Ethereum_Module_Args_sendTransactionAndWait, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "sendTransactionAndWait", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, deployContract: async ( args: Ethereum_Module_Args_deployContract, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "deployContract", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, signMessage: async ( args: Ethereum_Module_Args_signMessage, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "signMessage", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, sendRPC: async ( args: Ethereum_Module_Args_sendRPC, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "sendRPC", - args: args as unknown as Record + args: (args as unknown) as Record, }); } } diff --git a/packages/test-cases/cases/cli/plugin/codegen/003-env/expected/wrap/index.ts b/packages/test-cases/cases/cli/plugin/codegen/003-env/expected/wrap/index.ts index 315871f96d..4f5ca809d5 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/003-env/expected/wrap/index.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/003-env/expected/wrap/index.ts @@ -5,4 +5,4 @@ export * from "./wrap.info"; export * from "./module"; export * from "./types"; -export { Client } from "@polywrap/core-js"; +export { CoreClient } from "@polywrap/core-js"; diff --git a/packages/test-cases/cases/cli/plugin/codegen/003-env/expected/wrap/module.ts b/packages/test-cases/cases/cli/plugin/codegen/003-env/expected/wrap/module.ts index 9cd107891c..437a2407c2 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/003-env/expected/wrap/module.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/003-env/expected/wrap/module.ts @@ -3,25 +3,16 @@ import * as Types from "./types"; -import { - Client, - PluginModule, - MaybeAsync -} from "@polywrap/core-js"; +import { CoreClient, MaybeAsync } from "@polywrap/core-js"; +import { PluginModule } from "@polywrap/plugin-js"; export interface Args_method { str: Types.String; } -export abstract class Module< - TConfig -> extends PluginModule< - TConfig, - Types.Env -> { - +export abstract class Module extends PluginModule { abstract method( args: Args_method, - client: Client + client: CoreClient ): MaybeAsync; } diff --git a/packages/test-cases/cases/cli/plugin/codegen/003-env/expected/wrap/types.ts b/packages/test-cases/cases/cli/plugin/codegen/003-env/expected/wrap/types.ts index 6dbf11884a..3ee39fd838 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/003-env/expected/wrap/types.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/003-env/expected/wrap/types.ts @@ -6,7 +6,7 @@ import * as Types from "./"; // @ts-ignore import { - Client, + CoreClient, InvokeResult } from "@polywrap/core-js"; diff --git a/packages/test-cases/cases/cli/plugin/codegen/004-env-sanitization/expected/wrap/index.ts b/packages/test-cases/cases/cli/plugin/codegen/004-env-sanitization/expected/wrap/index.ts index 315871f96d..4f5ca809d5 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/004-env-sanitization/expected/wrap/index.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/004-env-sanitization/expected/wrap/index.ts @@ -5,4 +5,4 @@ export * from "./wrap.info"; export * from "./module"; export * from "./types"; -export { Client } from "@polywrap/core-js"; +export { CoreClient } from "@polywrap/core-js"; diff --git a/packages/test-cases/cases/cli/plugin/codegen/004-env-sanitization/expected/wrap/module.ts b/packages/test-cases/cases/cli/plugin/codegen/004-env-sanitization/expected/wrap/module.ts index 9cd107891c..437a2407c2 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/004-env-sanitization/expected/wrap/module.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/004-env-sanitization/expected/wrap/module.ts @@ -3,25 +3,16 @@ import * as Types from "./types"; -import { - Client, - PluginModule, - MaybeAsync -} from "@polywrap/core-js"; +import { CoreClient, MaybeAsync } from "@polywrap/core-js"; +import { PluginModule } from "@polywrap/plugin-js"; export interface Args_method { str: Types.String; } -export abstract class Module< - TConfig -> extends PluginModule< - TConfig, - Types.Env -> { - +export abstract class Module extends PluginModule { abstract method( args: Args_method, - client: Client + client: CoreClient ): MaybeAsync; } diff --git a/packages/test-cases/cases/cli/plugin/codegen/004-env-sanitization/expected/wrap/types.ts b/packages/test-cases/cases/cli/plugin/codegen/004-env-sanitization/expected/wrap/types.ts index fee545ff08..a2a3e3bb29 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/004-env-sanitization/expected/wrap/types.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/004-env-sanitization/expected/wrap/types.ts @@ -6,7 +6,7 @@ import * as Types from "./"; // @ts-ignore import { - Client, + CoreClient, InvokeResult } from "@polywrap/core-js"; diff --git a/packages/test-cases/cases/cli/plugin/codegen/005-custom-config/config.ts b/packages/test-cases/cases/cli/plugin/codegen/005-custom-config/config.ts index a51cd93907..0513b0a80e 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/005-custom-config/config.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/005-custom-config/config.ts @@ -1,51 +1,49 @@ -import { PolywrapClientConfig } from "@polywrap/client-js"; -import { PluginModule } from "@polywrap/core-js"; +import { ClientConfig } from "@polywrap/client-config-builder-js"; +import { PluginModule, PluginPackage } from "@polywrap/plugin-js"; +import { latestWrapManifestVersion } from "@polywrap/wrap-manifest-types-js"; +import { parseSchema } from "@polywrap/schema-parse"; interface Config extends Record { val: number; } class MockPlugin extends PluginModule { - - getData(_: unknown): number { return this.config.val; } + getData(_: unknown): number { + return this.config.val; + } setData(args: { value: number }) { this.config.val = +args.value; return true; } - deployContract(): string { return "0x100"; } + deployContract(): string { + return "0x100"; + } } const mockPlugin = () => { - return { - factory: () => new MockPlugin({ val: 0 }), - manifest: { - schema: ` - type Module { - getData: Int! - setData(value: Int!): Boolean! - deployContract: String! - } - `, - implements: [], - }, - }; + return PluginPackage.from(new MockPlugin({ val: 0 }), { + name: "mock", + type: "plugin", + version: latestWrapManifestVersion, + abi: parseSchema(` + type Module { + getData: Int! + setData(value: Int!): Boolean! + deployContract: String! + } + `) + }); }; -export function getClientConfig(defaultConfigs: Partial) { - if (defaultConfigs.plugins) { - defaultConfigs.plugins.push({ - uri: "wrap://ens/mock.eth", - plugin: mockPlugin(), - }); - } else { - defaultConfigs.plugins = [ +export function getCustomConfig(): Partial> { + return { + packages: [ { uri: "wrap://ens/mock.eth", - plugin: mockPlugin(), + package: mockPlugin(), }, - ]; - } - return defaultConfigs; + ], + }; } diff --git a/packages/test-cases/cases/cli/plugin/codegen/005-custom-config/expected/wrap/index.ts b/packages/test-cases/cases/cli/plugin/codegen/005-custom-config/expected/wrap/index.ts index 315871f96d..4f5ca809d5 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/005-custom-config/expected/wrap/index.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/005-custom-config/expected/wrap/index.ts @@ -5,4 +5,4 @@ export * from "./wrap.info"; export * from "./module"; export * from "./types"; -export { Client } from "@polywrap/core-js"; +export { CoreClient } from "@polywrap/core-js"; diff --git a/packages/test-cases/cases/cli/plugin/codegen/005-custom-config/expected/wrap/module.ts b/packages/test-cases/cases/cli/plugin/codegen/005-custom-config/expected/wrap/module.ts index 69fb521c72..d08b1a1fda 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/005-custom-config/expected/wrap/module.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/005-custom-config/expected/wrap/module.ts @@ -3,11 +3,8 @@ import * as Types from "./types"; -import { - Client, - PluginModule, - MaybeAsync -} from "@polywrap/core-js"; +import { CoreClient, MaybeAsync } from "@polywrap/core-js"; +import { PluginModule } from "@polywrap/plugin-js"; export interface Args_methodOne { str: Types.String; @@ -18,20 +15,14 @@ export interface Args_methodTwo { arg: Types.UInt32; } -export abstract class Module< - TConfig -> extends PluginModule< - TConfig, - Types.Env -> { - +export abstract class Module extends PluginModule { abstract methodOne( args: Args_methodOne, - client: Client + client: CoreClient ): MaybeAsync; abstract methodTwo( args: Args_methodTwo, - client: Client + client: CoreClient ): MaybeAsync; } diff --git a/packages/test-cases/cases/cli/plugin/codegen/005-custom-config/expected/wrap/types.ts b/packages/test-cases/cases/cli/plugin/codegen/005-custom-config/expected/wrap/types.ts index 3172a4e4b0..e2cef98b68 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/005-custom-config/expected/wrap/types.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/005-custom-config/expected/wrap/types.ts @@ -6,7 +6,7 @@ import * as Types from "./"; // @ts-ignore import { - Client, + CoreClient, InvokeResult } from "@polywrap/core-js"; @@ -346,309 +346,309 @@ interface Ethereum_Module_Args_sendRPC { export const Ethereum_Module = { callContractView: async ( args: Ethereum_Module_Args_callContractView, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "callContractView", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, callContractStatic: async ( args: Ethereum_Module_Args_callContractStatic, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "callContractStatic", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getBalance: async ( args: Ethereum_Module_Args_getBalance, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getBalance", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, encodeParams: async ( args: Ethereum_Module_Args_encodeParams, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "encodeParams", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, encodeFunction: async ( args: Ethereum_Module_Args_encodeFunction, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "encodeFunction", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, solidityPack: async ( args: Ethereum_Module_Args_solidityPack, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "solidityPack", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, solidityKeccak256: async ( args: Ethereum_Module_Args_solidityKeccak256, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "solidityKeccak256", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, soliditySha256: async ( args: Ethereum_Module_Args_soliditySha256, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "soliditySha256", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getSignerAddress: async ( args: Ethereum_Module_Args_getSignerAddress, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getSignerAddress", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getSignerBalance: async ( args: Ethereum_Module_Args_getSignerBalance, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getSignerBalance", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getSignerTransactionCount: async ( args: Ethereum_Module_Args_getSignerTransactionCount, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getSignerTransactionCount", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getGasPrice: async ( args: Ethereum_Module_Args_getGasPrice, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getGasPrice", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, estimateTransactionGas: async ( args: Ethereum_Module_Args_estimateTransactionGas, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "estimateTransactionGas", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, estimateContractCallGas: async ( args: Ethereum_Module_Args_estimateContractCallGas, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "estimateContractCallGas", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, checkAddress: async ( args: Ethereum_Module_Args_checkAddress, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "checkAddress", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, toWei: async ( args: Ethereum_Module_Args_toWei, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "toWei", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, toEth: async ( args: Ethereum_Module_Args_toEth, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "toEth", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, awaitTransaction: async ( args: Ethereum_Module_Args_awaitTransaction, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "awaitTransaction", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, waitForEvent: async ( args: Ethereum_Module_Args_waitForEvent, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "waitForEvent", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getNetwork: async ( args: Ethereum_Module_Args_getNetwork, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getNetwork", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, requestAccounts: async ( args: Ethereum_Module_Args_requestAccounts, - client: Client + client: CoreClient ): Promise>> => { return client.invoke>({ uri: "ens/ethereum.polywrap.eth", method: "requestAccounts", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, callContractMethod: async ( args: Ethereum_Module_Args_callContractMethod, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "callContractMethod", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, callContractMethodAndWait: async ( args: Ethereum_Module_Args_callContractMethodAndWait, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "callContractMethodAndWait", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, sendTransaction: async ( args: Ethereum_Module_Args_sendTransaction, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "sendTransaction", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, sendTransactionAndWait: async ( args: Ethereum_Module_Args_sendTransactionAndWait, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "sendTransactionAndWait", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, deployContract: async ( args: Ethereum_Module_Args_deployContract, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "deployContract", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, signMessage: async ( args: Ethereum_Module_Args_signMessage, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "signMessage", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, sendRPC: async ( args: Ethereum_Module_Args_sendRPC, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "sendRPC", - args: args as unknown as Record + args: (args as unknown) as Record, }); } } diff --git a/packages/test-cases/cases/cli/plugin/codegen/006-custom-manifest-file/expected/wrap/index.ts b/packages/test-cases/cases/cli/plugin/codegen/006-custom-manifest-file/expected/wrap/index.ts index 315871f96d..4f5ca809d5 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/006-custom-manifest-file/expected/wrap/index.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/006-custom-manifest-file/expected/wrap/index.ts @@ -5,4 +5,4 @@ export * from "./wrap.info"; export * from "./module"; export * from "./types"; -export { Client } from "@polywrap/core-js"; +export { CoreClient } from "@polywrap/core-js"; diff --git a/packages/test-cases/cases/cli/plugin/codegen/006-custom-manifest-file/expected/wrap/module.ts b/packages/test-cases/cases/cli/plugin/codegen/006-custom-manifest-file/expected/wrap/module.ts index 69fb521c72..d08b1a1fda 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/006-custom-manifest-file/expected/wrap/module.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/006-custom-manifest-file/expected/wrap/module.ts @@ -3,11 +3,8 @@ import * as Types from "./types"; -import { - Client, - PluginModule, - MaybeAsync -} from "@polywrap/core-js"; +import { CoreClient, MaybeAsync } from "@polywrap/core-js"; +import { PluginModule } from "@polywrap/plugin-js"; export interface Args_methodOne { str: Types.String; @@ -18,20 +15,14 @@ export interface Args_methodTwo { arg: Types.UInt32; } -export abstract class Module< - TConfig -> extends PluginModule< - TConfig, - Types.Env -> { - +export abstract class Module extends PluginModule { abstract methodOne( args: Args_methodOne, - client: Client + client: CoreClient ): MaybeAsync; abstract methodTwo( args: Args_methodTwo, - client: Client + client: CoreClient ): MaybeAsync; } diff --git a/packages/test-cases/cases/cli/plugin/codegen/006-custom-manifest-file/expected/wrap/types.ts b/packages/test-cases/cases/cli/plugin/codegen/006-custom-manifest-file/expected/wrap/types.ts index 3172a4e4b0..e2cef98b68 100644 --- a/packages/test-cases/cases/cli/plugin/codegen/006-custom-manifest-file/expected/wrap/types.ts +++ b/packages/test-cases/cases/cli/plugin/codegen/006-custom-manifest-file/expected/wrap/types.ts @@ -6,7 +6,7 @@ import * as Types from "./"; // @ts-ignore import { - Client, + CoreClient, InvokeResult } from "@polywrap/core-js"; @@ -346,309 +346,309 @@ interface Ethereum_Module_Args_sendRPC { export const Ethereum_Module = { callContractView: async ( args: Ethereum_Module_Args_callContractView, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "callContractView", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, callContractStatic: async ( args: Ethereum_Module_Args_callContractStatic, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "callContractStatic", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getBalance: async ( args: Ethereum_Module_Args_getBalance, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getBalance", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, encodeParams: async ( args: Ethereum_Module_Args_encodeParams, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "encodeParams", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, encodeFunction: async ( args: Ethereum_Module_Args_encodeFunction, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "encodeFunction", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, solidityPack: async ( args: Ethereum_Module_Args_solidityPack, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "solidityPack", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, solidityKeccak256: async ( args: Ethereum_Module_Args_solidityKeccak256, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "solidityKeccak256", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, soliditySha256: async ( args: Ethereum_Module_Args_soliditySha256, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "soliditySha256", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getSignerAddress: async ( args: Ethereum_Module_Args_getSignerAddress, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getSignerAddress", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getSignerBalance: async ( args: Ethereum_Module_Args_getSignerBalance, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getSignerBalance", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getSignerTransactionCount: async ( args: Ethereum_Module_Args_getSignerTransactionCount, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getSignerTransactionCount", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getGasPrice: async ( args: Ethereum_Module_Args_getGasPrice, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getGasPrice", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, estimateTransactionGas: async ( args: Ethereum_Module_Args_estimateTransactionGas, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "estimateTransactionGas", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, estimateContractCallGas: async ( args: Ethereum_Module_Args_estimateContractCallGas, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "estimateContractCallGas", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, checkAddress: async ( args: Ethereum_Module_Args_checkAddress, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "checkAddress", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, toWei: async ( args: Ethereum_Module_Args_toWei, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "toWei", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, toEth: async ( args: Ethereum_Module_Args_toEth, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "toEth", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, awaitTransaction: async ( args: Ethereum_Module_Args_awaitTransaction, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "awaitTransaction", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, waitForEvent: async ( args: Ethereum_Module_Args_waitForEvent, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "waitForEvent", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, getNetwork: async ( args: Ethereum_Module_Args_getNetwork, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "getNetwork", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, requestAccounts: async ( args: Ethereum_Module_Args_requestAccounts, - client: Client + client: CoreClient ): Promise>> => { return client.invoke>({ uri: "ens/ethereum.polywrap.eth", method: "requestAccounts", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, callContractMethod: async ( args: Ethereum_Module_Args_callContractMethod, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "callContractMethod", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, callContractMethodAndWait: async ( args: Ethereum_Module_Args_callContractMethodAndWait, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "callContractMethodAndWait", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, sendTransaction: async ( args: Ethereum_Module_Args_sendTransaction, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "sendTransaction", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, sendTransactionAndWait: async ( args: Ethereum_Module_Args_sendTransactionAndWait, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "sendTransactionAndWait", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, deployContract: async ( args: Ethereum_Module_Args_deployContract, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "deployContract", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, signMessage: async ( args: Ethereum_Module_Args_signMessage, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "signMessage", - args: args as unknown as Record + args: (args as unknown) as Record, }); }, sendRPC: async ( args: Ethereum_Module_Args_sendRPC, - client: Client + client: CoreClient ): Promise> => { return client.invoke({ uri: "ens/ethereum.polywrap.eth", method: "sendRPC", - args: args as unknown as Record + args: (args as unknown) as Record, }); } } diff --git a/packages/test-cases/cases/cli/run/008-custom-config/config.ts b/packages/test-cases/cases/cli/run/008-custom-config/config.ts index 6017d5e9cd..8071702486 100644 --- a/packages/test-cases/cases/cli/run/008-custom-config/config.ts +++ b/packages/test-cases/cases/cli/run/008-custom-config/config.ts @@ -1,25 +1,23 @@ -import { PolywrapClientConfig } from "@polywrap/client-js"; +import { ClientConfig } from "@polywrap/client-config-builder-js"; import path from "path"; -export async function getClientConfig( - defaultConfigs: Partial -): Promise> { +export function getCustomConfig(): Partial> { const wrapperPath = path.join(__dirname, "..", "run-test-wrapper"); const wrapperUri = `fs/${path.resolve(wrapperPath)}/build`; return { redirects: [ { from: "wrap://ens/test.eth", - to: wrapperUri - } + to: wrapperUri, + }, ], envs: [ { uri: wrapperUri, env: { - value: 1 - } + value: 1, + }, }, ], - } + }; } diff --git a/packages/test-cases/cases/cli/run/run-test-wrapper/package.json b/packages/test-cases/cases/cli/run/run-test-wrapper/package.json index 762179c318..682883cdd2 100644 --- a/packages/test-cases/cases/cli/run/run-test-wrapper/package.json +++ b/packages/test-cases/cases/cli/run/run-test-wrapper/package.json @@ -7,7 +7,7 @@ "build": "polywrap build" }, "dependencies": { - "@polywrap/wasm-as": "0.7.0" + "@polywrap/wasm-as": "0.9.3" }, "devDependencies": { "assemblyscript": "0.19.23" diff --git a/packages/test-cases/cases/cli/wasm/build-cmd/assemblyscript/010-custom-config/config.ts b/packages/test-cases/cases/cli/wasm/build-cmd/assemblyscript/010-custom-config/config.ts index bf5ec3d50d..d61dd5a11c 100644 --- a/packages/test-cases/cases/cli/wasm/build-cmd/assemblyscript/010-custom-config/config.ts +++ b/packages/test-cases/cases/cli/wasm/build-cmd/assemblyscript/010-custom-config/config.ts @@ -1,153 +1,131 @@ -import { PolywrapClientConfig } from "@polywrap/client-js"; -import { PluginModule } from "@polywrap/core-js"; +import { ClientConfig } from "@polywrap/client-config-builder-js"; +import { PluginModule, PluginPackage } from "@polywrap/plugin-js"; +import { latestWrapManifestVersion } from "@polywrap/wrap-manifest-types-js"; interface Config extends Record { val: number; } class MockPlugin extends PluginModule { - - getData(_: unknown): number { return this.config.val; } + getData(_: unknown): number { + return this.config.val; + } setData(args: { value: number }) { this.config.val = +args.value; return true; } - deployContract(): string { return "0x100"; } + deployContract(): string { + return "0x100"; + } } const mockPlugin = () => { - return { - factory: () => new MockPlugin({ val: 0 }), - manifest: { + return PluginPackage.from( + new MockPlugin({ val: 0 }) as PluginModule, + { + name: "mock", + type: "plugin", + version: latestWrapManifestVersion, abi: { - "objectTypes": [], - "enumTypes": [], - "interfaceTypes": [], - "importedObjectTypes": [], - "importedModuleTypes": [], - "importedEnumTypes": [], - "importedEnvTypes": [], - "moduleType": { - "type": "Module", - "name": null, - "required": null, - "kind": 128, - "methods": [ + objectTypes: [], + enumTypes: [], + interfaceTypes: [], + importedObjectTypes: [], + importedModuleTypes: [], + importedEnumTypes: [], + importedEnvTypes: [], + moduleType: { + type: "Module", + kind: 128, + methods: [ { - "type": "Method", - "name": "getData", - "required": true, - "kind": 64, - "arguments": [], - "return": { - "type": "Int", - "name": "getData", - "required": true, - "kind": 34, - "array": null, - "map": null, - "scalar": { - "type": "Int", - "name": "getData", - "required": true, - "kind": 4 + type: "Method", + name: "getData", + required: true, + kind: 64, + arguments: [], + return: { + type: "Int", + name: "getData", + required: true, + kind: 34, + scalar: { + type: "Int", + name: "getData", + required: true, + kind: 4, }, - "object": null, - "enum": null, - "unresolvedObjectOrEnum": null - } + }, }, { - "type": "Method", - "name": "setData", - "required": true, - "kind": 64, - "arguments": [ + type: "Method", + name: "setData", + required: true, + kind: 64, + arguments: [ { - "type": "Int", - "name": "value", - "required": true, - "kind": 34, - "array": null, - "map": null, - "scalar": { - "type": "Int", - "name": "value", - "required": true, - "kind": 4 + type: "Int", + name: "value", + required: true, + kind: 34, + scalar: { + type: "Int", + name: "value", + required: true, + kind: 4, }, - "object": null, - "enum": null, - "unresolvedObjectOrEnum": null - } + }, ], - "return": { - "type": "Boolean", - "name": "setData", - "required": true, - "kind": 34, - "array": null, - "map": null, - "scalar": { - "type": "Boolean", - "name": "setData", - "required": true, - "kind": 4 + return: { + type: "Boolean", + name: "setData", + required: true, + kind: 34, + scalar: { + type: "Boolean", + name: "setData", + required: true, + kind: 4, }, - "object": null, - "enum": null, - "unresolvedObjectOrEnum": null - } + }, }, { - "type": "Method", - "name": "deployContract", - "required": true, - "kind": 64, - "arguments": [], - "return": { - "type": "String", - "name": "deployContract", - "required": true, - "kind": 34, - "array": null, - "map": null, - "scalar": { - "type": "String", - "name": "deployContract", - "required": true, - "kind": 4 + type: "Method", + name: "deployContract", + required: true, + kind: 64, + arguments: [], + return: { + type: "String", + name: "deployContract", + required: true, + kind: 34, + scalar: { + type: "String", + name: "deployContract", + required: true, + kind: 4, }, - "object": null, - "enum": null, - "unresolvedObjectOrEnum": null - } - } + }, + }, ], - "imports": [], - "interfaces": [] - } - }, - implements: [], - }, - }; + imports: [], + interfaces: [], + }, + } + } + ); }; -export function getClientConfig(defaultConfigs: Partial) { - if (defaultConfigs.plugins) { - defaultConfigs.plugins.push({ - uri: "wrap://ens/mock.eth", - plugin: mockPlugin(), - }); - } else { - defaultConfigs.plugins = [ +export function getCustomConfig(): Partial> { + return { + packages: [ { uri: "wrap://ens/mock.eth", - plugin: mockPlugin(), - }, - ]; - } - return defaultConfigs; + package: mockPlugin(), + } + ] + }; } diff --git a/packages/test-cases/cases/cli/wasm/codegen/005-custom-config/config.ts b/packages/test-cases/cases/cli/wasm/codegen/005-custom-config/config.ts index a98f365a7e..db89960cfb 100644 --- a/packages/test-cases/cases/cli/wasm/codegen/005-custom-config/config.ts +++ b/packages/test-cases/cases/cli/wasm/codegen/005-custom-config/config.ts @@ -1,128 +1,126 @@ -import { PolywrapClientConfig } from "@polywrap/client-js"; -import { PluginModule } from "@polywrap/core-js"; -import { latestWrapManifestVersion, WrapManifest, WrapAbi } from "@polywrap/wrap-manifest-types-js"; +import { ClientConfig } from "@polywrap/client-config-builder-js"; +import { IWrapPackage } from "@polywrap/core-js"; +import { PluginModule, PluginPackage } from "@polywrap/plugin-js"; +import { + latestWrapManifestVersion, + WrapAbi, +} from "@polywrap/wrap-manifest-types-js"; interface Config extends Record { val: number; } class MockPlugin extends PluginModule { - - getData(_: unknown): number { return this.config.val; } + getData(_: unknown): number { + return this.config.val; + } setData(args: { value: number }) { this.config.val = +args.value; return true; } - deployContract(): string { return "0x100"; } + deployContract(): string { + return "0x100"; + } } -const mockPlugin = () => { - return { - factory: () => new MockPlugin({ val: 0 }), - manifest: { - name: "mock", - type: "plugin", - version: latestWrapManifestVersion, - abi - } as WrapManifest - }; +const mockPlugin = (): IWrapPackage => { + return PluginPackage.from(new MockPlugin({ val: 0 }), { + name: "mock", + type: "plugin", + version: latestWrapManifestVersion, + abi, + }); }; -export function getClientConfig(defaultConfigs: Partial) { - if (defaultConfigs.plugins) { - defaultConfigs.plugins.push({ - uri: "wrap://ens/mock.eth", - plugin: mockPlugin(), - }); - } else { - defaultConfigs.plugins = [ +export function getCustomConfig(): Partial> { + return { + packages: [ { uri: "wrap://ens/mock.eth", - plugin: mockPlugin(), + package: mockPlugin(), }, - ]; - } - return defaultConfigs; + ], + }; } const abi: WrapAbi = { version: "0.1", - "moduleType": { - "type": "Module", - "kind": 128, - "methods": [ + moduleType: { + type: "Module", + kind: 128, + methods: [ { - "type": "Method", - "name": "getData", - "required": true, - "kind": 64, - "arguments": [], - "return": { - "type": "Int", - "name": "getData", - "required": true, - "kind": 34, - "scalar": { - "type": "Int", - "name": "getData", - "required": true, - "kind": 4 - } - } + type: "Method", + name: "getData", + required: true, + kind: 64, + arguments: [], + return: { + type: "Int", + name: "getData", + required: true, + kind: 34, + scalar: { + type: "Int", + name: "getData", + required: true, + kind: 4, + }, + }, }, { - "type": "Method", - "name": "setData", - "required": true, - "kind": 64, - "arguments": [ + type: "Method", + name: "setData", + required: true, + kind: 64, + arguments: [ { - "type": "Int", - "name": "value", - "required": true, - "kind": 34, - "scalar": { - "type": "Int", - "name": "value", - "required": true, - "kind": 4 - } - } + type: "Int", + name: "value", + required: true, + kind: 34, + scalar: { + type: "Int", + name: "value", + required: true, + kind: 4, + }, + }, ], - "return": { - "type": "Boolean", - "name": "setData", - "required": true, - "kind": 34, - "scalar": { - "type": "Boolean", - "name": "setData", - "required": true, - "kind": 4 - } - } + return: { + type: "Boolean", + name: "setData", + required: true, + kind: 34, + scalar: { + type: "Boolean", + name: "setData", + required: true, + kind: 4, + }, + }, }, { - "type": "Method", - "name": "deployContract", - "required": true, - "kind": 64, - "arguments": [], - "return": { - "type": "String", - "name": "deployContract", - "required": true, - "kind": 34, - "scalar": { - "type": "String", - "name": "deployContract", - "required": true, - "kind": 4 - } - } - } - ] - } + type: "Method", + name: "deployContract", + required: true, + kind: 64, + arguments: [], + return: { + type: "String", + name: "deployContract", + required: true, + kind: 34, + scalar: { + type: "String", + name: "deployContract", + required: true, + kind: 4, + }, + }, + }, + ], + }, }; diff --git a/yarn.lock b/yarn.lock index b02516f91a..bed5bda47a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -152,30 +152,30 @@ source-map "^0.5.0" "@babel/core@^7.1.0", "@babel/core@^7.12.3", "@babel/core@^7.4.5", "@babel/core@^7.7.5": - version "7.19.3" - resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.19.3.tgz#2519f62a51458f43b682d61583c3810e7dcee64c" - integrity sha512-WneDJxdsjEvyKtXKsaBGbDeiyOjR5vYq4HcShxnIbG0qixpoHjI3MqeZM9NDvsojNCEBItQE4juOo/bU6e72gQ== + version "7.19.6" + resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.19.6.tgz#7122ae4f5c5a37c0946c066149abd8e75f81540f" + integrity sha512-D2Ue4KHpc6Ys2+AxpIx1BZ8+UegLLLE2p3KJEuJRKmokHOtl49jQ5ny1773KsGLZs8MQvBidAF6yWUJxRqtKtg== dependencies: "@ampproject/remapping" "^2.1.0" "@babel/code-frame" "^7.18.6" - "@babel/generator" "^7.19.3" + "@babel/generator" "^7.19.6" "@babel/helper-compilation-targets" "^7.19.3" - "@babel/helper-module-transforms" "^7.19.0" - "@babel/helpers" "^7.19.0" - "@babel/parser" "^7.19.3" + "@babel/helper-module-transforms" "^7.19.6" + "@babel/helpers" "^7.19.4" + "@babel/parser" "^7.19.6" "@babel/template" "^7.18.10" - "@babel/traverse" "^7.19.3" - "@babel/types" "^7.19.3" + "@babel/traverse" "^7.19.6" + "@babel/types" "^7.19.4" convert-source-map "^1.7.0" debug "^4.1.0" gensync "^1.0.0-beta.2" json5 "^2.2.1" semver "^6.3.0" -"@babel/generator@^7.19.3", "@babel/generator@^7.19.4", "@babel/generator@^7.4.0", "@babel/generator@^7.9.0": - version "7.19.5" - resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.19.5.tgz#da3f4b301c8086717eee9cab14da91b1fa5dcca7" - integrity sha512-DxbNz9Lz4aMZ99qPpO1raTbcrI1ZeYh+9NR9qhfkQIbFtVEqotHojEBxHzmxhVONkGt6VyrqVQcgpefMy9pqcg== +"@babel/generator@^7.19.6", "@babel/generator@^7.4.0", "@babel/generator@^7.9.0": + version "7.19.6" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.19.6.tgz#9e481a3fe9ca6261c972645ae3904ec0f9b34a1d" + integrity sha512-oHGRUQeoX1QrKeJIKVe0hwjGqNnVYsM5Nep5zo0uE0m42sLH+Fsd2pStJ5sRM1bNyTUUoz0pe2lTeMJrb/taTA== dependencies: "@babel/types" "^7.19.4" "@jridgewell/gen-mapping" "^0.3.2" @@ -280,19 +280,19 @@ dependencies: "@babel/types" "^7.18.6" -"@babel/helper-module-transforms@^7.18.6", "@babel/helper-module-transforms@^7.19.0", "@babel/helper-module-transforms@^7.9.0": - version "7.19.0" - resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.19.0.tgz#309b230f04e22c58c6a2c0c0c7e50b216d350c30" - integrity sha512-3HBZ377Fe14RbLIA+ac3sY4PTgpxHVkFrESaWhoI5PuyXPBBX8+C34qblV9G89ZtycGJCmCI/Ut+VUDK4bltNQ== +"@babel/helper-module-transforms@^7.18.6", "@babel/helper-module-transforms@^7.19.6", "@babel/helper-module-transforms@^7.9.0": + version "7.19.6" + resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.19.6.tgz#6c52cc3ac63b70952d33ee987cbee1c9368b533f" + integrity sha512-fCmcfQo/KYr/VXXDIyd3CBGZ6AFhPFy1TfSEJ+PilGVlQT6jcbqtHAM4C1EciRqMza7/TpOUZliuSH+U6HAhJw== dependencies: "@babel/helper-environment-visitor" "^7.18.9" "@babel/helper-module-imports" "^7.18.6" - "@babel/helper-simple-access" "^7.18.6" + "@babel/helper-simple-access" "^7.19.4" "@babel/helper-split-export-declaration" "^7.18.6" - "@babel/helper-validator-identifier" "^7.18.6" + "@babel/helper-validator-identifier" "^7.19.1" "@babel/template" "^7.18.10" - "@babel/traverse" "^7.19.0" - "@babel/types" "^7.19.0" + "@babel/traverse" "^7.19.6" + "@babel/types" "^7.19.4" "@babel/helper-optimise-call-expression@^7.18.6": version "7.18.6" @@ -327,7 +327,7 @@ "@babel/traverse" "^7.19.1" "@babel/types" "^7.19.0" -"@babel/helper-simple-access@^7.18.6": +"@babel/helper-simple-access@^7.19.4": version "7.19.4" resolved "https://registry.yarnpkg.com/@babel/helper-simple-access/-/helper-simple-access-7.19.4.tgz#be553f4951ac6352df2567f7daa19a0ee15668e7" integrity sha512-f9Xq6WqBFqaDfbCzn2w85hwklswz5qsKlh7f08w4Y9yhJHpnNC0QemtSkK5YyOY8kPGvyiwdzZksGUhnGdaUIg== @@ -373,7 +373,7 @@ "@babel/traverse" "^7.19.0" "@babel/types" "^7.19.0" -"@babel/helpers@^7.19.0", "@babel/helpers@^7.9.0": +"@babel/helpers@^7.19.4", "@babel/helpers@^7.9.0": version "7.19.4" resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.19.4.tgz#42154945f87b8148df7203a25c31ba9a73be46c5" integrity sha512-G+z3aOx2nfDHwX/kyVii5fJq+bgscg89/dJNWpYeKeBv3v9xX8EIabmx1k6u9LS04H7nROFVRVK+e3k0VHp+sw== @@ -391,10 +391,10 @@ chalk "^2.0.0" js-tokens "^4.0.0" -"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.18.10", "@babel/parser@^7.19.3", "@babel/parser@^7.19.4", "@babel/parser@^7.4.3", "@babel/parser@^7.7.0", "@babel/parser@^7.9.0": - version "7.19.4" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.19.4.tgz#03c4339d2b8971eb3beca5252bafd9b9f79db3dc" - integrity sha512-qpVT7gtuOLjWeDTKLkJ6sryqLliBaFpAtGeqw5cs5giLldvh+Ch0plqnUMKoVAUS6ZEueQQiZV+p5pxtPitEsA== +"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.18.10", "@babel/parser@^7.19.6", "@babel/parser@^7.4.3", "@babel/parser@^7.7.0", "@babel/parser@^7.9.0": + version "7.19.6" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.19.6.tgz#b923430cb94f58a7eae8facbffa9efd19130e7f8" + integrity sha512-h1IUp81s2JYJ3mRkdxJgs4UvmSsRvDrx5ICSJbPvtWYv5i1nTBGcBpnog+89rAFMwvvru6E5NUHdBe01UeSzYA== "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@^7.18.6": version "7.18.6" @@ -850,34 +850,31 @@ "@babel/helper-plugin-utils" "^7.18.6" "@babel/plugin-transform-modules-amd@^7.18.6", "@babel/plugin-transform-modules-amd@^7.9.0": - version "7.18.6" - resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-amd/-/plugin-transform-modules-amd-7.18.6.tgz#8c91f8c5115d2202f277549848874027d7172d21" - integrity sha512-Pra5aXsmTsOnjM3IajS8rTaLCy++nGM4v3YR4esk5PCsyg9z8NA5oQLwxzMUtDBd8F+UmVza3VxoAaWCbzH1rg== + version "7.19.6" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-amd/-/plugin-transform-modules-amd-7.19.6.tgz#aca391801ae55d19c4d8d2ebfeaa33df5f2a2cbd" + integrity sha512-uG3od2mXvAtIFQIh0xrpLH6r5fpSQN04gIVovl+ODLdUMANokxQLZnPBHcjmv3GxRjnqwLuHvppjjcelqUFZvg== dependencies: - "@babel/helper-module-transforms" "^7.18.6" - "@babel/helper-plugin-utils" "^7.18.6" - babel-plugin-dynamic-import-node "^2.3.3" + "@babel/helper-module-transforms" "^7.19.6" + "@babel/helper-plugin-utils" "^7.19.0" "@babel/plugin-transform-modules-commonjs@^7.18.6", "@babel/plugin-transform-modules-commonjs@^7.9.0": - version "7.18.6" - resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.18.6.tgz#afd243afba166cca69892e24a8fd8c9f2ca87883" - integrity sha512-Qfv2ZOWikpvmedXQJDSbxNqy7Xr/j2Y8/KfijM0iJyKkBTmWuvCA1yeH1yDM7NJhBW/2aXxeucLj6i80/LAJ/Q== + version "7.19.6" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.19.6.tgz#25b32feef24df8038fc1ec56038917eacb0b730c" + integrity sha512-8PIa1ym4XRTKuSsOUXqDG0YaOlEuTVvHMe5JCfgBMOtHvJKw/4NGovEGN33viISshG/rZNVrACiBmPQLvWN8xQ== dependencies: - "@babel/helper-module-transforms" "^7.18.6" - "@babel/helper-plugin-utils" "^7.18.6" - "@babel/helper-simple-access" "^7.18.6" - babel-plugin-dynamic-import-node "^2.3.3" + "@babel/helper-module-transforms" "^7.19.6" + "@babel/helper-plugin-utils" "^7.19.0" + "@babel/helper-simple-access" "^7.19.4" "@babel/plugin-transform-modules-systemjs@^7.19.0", "@babel/plugin-transform-modules-systemjs@^7.9.0": - version "7.19.0" - resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-systemjs/-/plugin-transform-modules-systemjs-7.19.0.tgz#5f20b471284430f02d9c5059d9b9a16d4b085a1f" - integrity sha512-x9aiR0WXAWmOWsqcsnrzGR+ieaTMVyGyffPVA7F8cXAGt/UxefYv6uSHZLkAFChN5M5Iy1+wjE+xJuPt22H39A== + version "7.19.6" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-systemjs/-/plugin-transform-modules-systemjs-7.19.6.tgz#59e2a84064b5736a4471b1aa7b13d4431d327e0d" + integrity sha512-fqGLBepcc3kErfR9R3DnVpURmckXP7gj7bAlrTQyBxrigFqszZCkFkcoxzCp2v32XmwXLvbw+8Yq9/b+QqksjQ== dependencies: "@babel/helper-hoist-variables" "^7.18.6" - "@babel/helper-module-transforms" "^7.19.0" + "@babel/helper-module-transforms" "^7.19.6" "@babel/helper-plugin-utils" "^7.19.0" - "@babel/helper-validator-identifier" "^7.18.6" - babel-plugin-dynamic-import-node "^2.3.3" + "@babel/helper-validator-identifier" "^7.19.1" "@babel/plugin-transform-modules-umd@^7.18.6", "@babel/plugin-transform-modules-umd@^7.9.0": version "7.18.6" @@ -960,11 +957,11 @@ "@babel/helper-plugin-utils" "^7.18.6" "@babel/plugin-transform-react-jsx-source@^7.9.0": - version "7.18.6" - resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx-source/-/plugin-transform-react-jsx-source-7.18.6.tgz#06e9ae8a14d2bc19ce6e3c447d842032a50598fc" - integrity sha512-utZmlASneDfdaMh0m/WausbjUjEdGrQJz0vFK93d7wD3xf5wBtX219+q6IlCNZeguIcxS2f/CvLZrlLSvSHQXw== + version "7.19.6" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx-source/-/plugin-transform-react-jsx-source-7.19.6.tgz#88578ae8331e5887e8ce28e4c9dc83fb29da0b86" + integrity sha512-RpAi004QyMNisst/pvSanoRdJ4q+jMCWyk9zdw/CyLB9j8RXEahodR6l2GyttDRyEVWZtbN+TpLiHJ3t34LbsQ== dependencies: - "@babel/helper-plugin-utils" "^7.18.6" + "@babel/helper-plugin-utils" "^7.19.0" "@babel/plugin-transform-react-jsx@^7.18.6", "@babel/plugin-transform-react-jsx@^7.9.1": version "7.19.0" @@ -1261,9 +1258,9 @@ "@babel/plugin-transform-typescript" "^7.9.0" "@babel/runtime-corejs3@^7.10.2", "@babel/runtime-corejs3@^7.12.1": - version "7.19.4" - resolved "https://registry.yarnpkg.com/@babel/runtime-corejs3/-/runtime-corejs3-7.19.4.tgz#870dbfd9685b3dad5aeb2d00841bb8b6192e3095" - integrity sha512-HzjQ8+dzdx7dmZy4DQ8KV8aHi/74AjEbBGTFutBmg/pd3dY5/q1sfuOGPTFGEytlQhWoeVXqcK5BwMgIkRkNDQ== + version "7.19.6" + resolved "https://registry.yarnpkg.com/@babel/runtime-corejs3/-/runtime-corejs3-7.19.6.tgz#778471a71d915cf3b955a9201bebabfe924f872a" + integrity sha512-oWNn1ZlGde7b4i/3tnixpH9qI0bOAACiUs+KEES4UUCnsPjVWFlWdLV/iwJuPC2qp3EowbAqsm+0XqNwnwYhxA== dependencies: core-js-pure "^3.25.1" regenerator-runtime "^0.13.4" @@ -1291,23 +1288,23 @@ "@babel/parser" "^7.18.10" "@babel/types" "^7.18.10" -"@babel/traverse@^7.1.0", "@babel/traverse@^7.19.0", "@babel/traverse@^7.19.1", "@babel/traverse@^7.19.3", "@babel/traverse@^7.19.4", "@babel/traverse@^7.4.3", "@babel/traverse@^7.7.0", "@babel/traverse@^7.9.0": - version "7.19.4" - resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.19.4.tgz#f117820e18b1e59448a6c1fa9d0ff08f7ac459a8" - integrity sha512-w3K1i+V5u2aJUOXBFFC5pveFLmtq1s3qcdDNC2qRI6WPBQIDaKFqXxDEqDO/h1dQ3HjsZoZMyIy6jGLq0xtw+g== +"@babel/traverse@^7.1.0", "@babel/traverse@^7.19.0", "@babel/traverse@^7.19.1", "@babel/traverse@^7.19.4", "@babel/traverse@^7.19.6", "@babel/traverse@^7.4.3", "@babel/traverse@^7.7.0", "@babel/traverse@^7.9.0": + version "7.19.6" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.19.6.tgz#7b4c865611df6d99cb131eec2e8ac71656a490dc" + integrity sha512-6l5HrUCzFM04mfbG09AagtYyR2P0B71B1wN7PfSPiksDPz2k5H9CBC1tcZpz2M8OxbKTPccByoOJ22rUKbpmQQ== dependencies: "@babel/code-frame" "^7.18.6" - "@babel/generator" "^7.19.4" + "@babel/generator" "^7.19.6" "@babel/helper-environment-visitor" "^7.18.9" "@babel/helper-function-name" "^7.19.0" "@babel/helper-hoist-variables" "^7.18.6" "@babel/helper-split-export-declaration" "^7.18.6" - "@babel/parser" "^7.19.4" + "@babel/parser" "^7.19.6" "@babel/types" "^7.19.4" debug "^4.1.0" globals "^11.1.0" -"@babel/types@^7.0.0", "@babel/types@^7.18.10", "@babel/types@^7.18.6", "@babel/types@^7.18.9", "@babel/types@^7.19.0", "@babel/types@^7.19.3", "@babel/types@^7.19.4", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.0", "@babel/types@^7.4.4", "@babel/types@^7.7.0", "@babel/types@^7.9.0": +"@babel/types@^7.0.0", "@babel/types@^7.18.10", "@babel/types@^7.18.6", "@babel/types@^7.18.9", "@babel/types@^7.19.0", "@babel/types@^7.19.4", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.0", "@babel/types@^7.4.4", "@babel/types@^7.7.0", "@babel/types@^7.9.0": version "7.19.4" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.19.4.tgz#0dd5c91c573a202d600490a35b33246fed8a41c7" integrity sha512-M5LK7nAeS6+9j7hAq+b3fQs+pNfUtTGq+yFFfHnauFA8zQtLRfmuipmsKDKKLuyG+wC8ABW43A153YNawNTEtw== @@ -1633,9 +1630,9 @@ ws "7.4.6" "@ethersproject/providers@^5.0.0": - version "5.7.1" - resolved "https://registry.yarnpkg.com/@ethersproject/providers/-/providers-5.7.1.tgz#b0799b616d5579cd1067a8ebf1fc1ec74c1e122c" - integrity sha512-vZveG/DLyo+wk4Ga1yx6jSEHrLPgmTt+dFv0dv8URpVCRf0jVhalps1jq/emN/oXnMRsC7cQgAF32DcXLL7BPQ== + version "5.7.2" + resolved "https://registry.yarnpkg.com/@ethersproject/providers/-/providers-5.7.2.tgz#f8b1a4f275d7ce58cf0a2eec222269a08beb18cb" + integrity sha512-g34EWZ1WWAVgr4aptGlVBF8mhl3VWjv+8hoAnzStu8Ah22VHBsuGzP17eb6xDVRzw895G4W7vvx60lFFur/1Rg== dependencies: "@ethersproject/abstract-provider" "^5.7.0" "@ethersproject/abstract-signer" "^5.7.0" @@ -2299,9 +2296,9 @@ integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw== "@jridgewell/trace-mapping@^0.3.9": - version "0.3.16" - resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.16.tgz#a7982f16c18cae02be36274365433e5b49d7b23f" - integrity sha512-LCQ+NeThyJ4k1W2d+vIKdxuSt9R3pQSZ4P92m7EakaYuXcVWbHuT5bjNcqLd4Rdgi6xYWYDvBJZJLZSLanjDcA== + version "0.3.17" + resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.17.tgz#793041277af9073b0951a7fe0f0d8c4c98c36985" + integrity sha512-MCNzAp77qzKca9+W/+I0+sEpaUnZoeasnghNeVc41VZCEKaCH73Vq3BZZ/SzWIgrqE4H4ceI+p+b6C0mHf9T4g== dependencies: "@jridgewell/resolve-uri" "3.1.0" "@jridgewell/sourcemap-codec" "1.4.14" @@ -3303,9 +3300,9 @@ querystring "^0.2.0" "@sinclair/typebox@^0.24.1": - version "0.24.44" - resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.24.44.tgz#0a0aa3bf4a155a678418527342a3ee84bd8caa5c" - integrity sha512-ka0W0KN5i6LfrSocduwliMMpqVgohtPFidKdMEOUjoOFCHcOOYkKsPRxfs5f15oPNHTm6ERAm0GV/+/LTKeiWg== + version "0.24.47" + resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.24.47.tgz#530b67163714356f93e82bdb871e7db4b7bc564e" + integrity sha512-J4Xw0xYK4h7eC34MNOPQi6IkNxGRck6n4VJpWDzXIFVTW8I/D43Gf+NfWz/v/7NHlzWOPd3+T4PJ4OqklQ2u7A== "@sinonjs/commons@^1.7.0": version "1.8.3" @@ -3658,9 +3655,9 @@ integrity sha512-wH6Tu9mbiOt0n5EvdoWy0VGQaJMHfLIxY/6wS0xLC7CV1taM6gESEzcYy0ZlWvxxiiljYvfDIvz4hHbUUDRlhw== "@types/node@*": - version "18.8.4" - resolved "https://registry.yarnpkg.com/@types/node/-/node-18.8.4.tgz#54be907698f40de8a45770b48486aa3cbd3adff7" - integrity sha512-WdlVphvfR/GJCLEMbNA8lJ0lhFNBj4SW3O+O5/cEGw9oYrv0al9zTwuQsq+myDUXgNx2jgBynoVgZ2MMJ6pbow== + version "18.11.3" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.3.tgz#78a6d7ec962b596fc2d2ec102c4dd3ef073fea6a" + integrity sha512-fNjDQzzOsZeKZu5NATgXUPsaFaTxeRgFXoosrHivTl8RGeV733OLawXsGfEk9a8/tySyZUyiZ6E8LcjPFZ2y1A== "@types/node@12.12.26": version "12.12.26" @@ -4760,13 +4757,6 @@ babel-loader@8.1.0: pify "^4.0.1" schema-utils "^2.6.5" -babel-plugin-dynamic-import-node@^2.3.3: - version "2.3.3" - resolved "https://registry.yarnpkg.com/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz#84fda19c976ec5c6defef57f9427b3def66e17a3" - integrity sha512-jZVI+s9Zg3IqA/kdi0i6UDCybUI3aSBLnglhYbSSjKlV7yF1F/5LWv8MakQmvYpnbJDS6fcBL2KzHSxNCMtWSQ== - dependencies: - object.assign "^4.1.0" - babel-plugin-istanbul@^5.1.0: version "5.2.0" resolved "https://registry.yarnpkg.com/babel-plugin-istanbul/-/babel-plugin-istanbul-5.2.0.tgz#df4ade83d897a92df069c4d9a25cf2671293c854" @@ -5263,9 +5253,9 @@ buffer-crc32@~0.2.3: integrity sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ== buffer-equal@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/buffer-equal/-/buffer-equal-1.0.0.tgz#59616b498304d556abd466966b22eeda3eca5fbe" - integrity sha512-tcBWO2Dl4e7Asr9hTGcpVrCe+F7DubpmqWCTbj4FHLmjqO2hIaC383acQubWtRJhdceqs5uBHs6Es+Sk//RKiQ== + version "1.0.1" + resolved "https://registry.yarnpkg.com/buffer-equal/-/buffer-equal-1.0.1.tgz#2f7651be5b1b3f057fcd6e7ee16cf34767077d90" + integrity sha512-QoV3ptgEaQpvVwbXdSO39iqPQTCxSF7A5U99AxbHYqUdCizL/lH2Z0A2y6nbZucxMEOtNyZfG2s6gsVugGpKkg== buffer-from@1.x, buffer-from@^1.0.0: version "1.1.2" @@ -5506,9 +5496,9 @@ caniuse-api@^3.0.0: 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.30001400: - version "1.0.30001418" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001418.tgz#5f459215192a024c99e3e3a53aac310fc7cf24e6" - integrity sha512-oIs7+JL3K9JRQ3jPZjlH6qyYDp+nBTCais7hjh0s+fuBwufc7uZ7hPYMXrDOJhV360KGMTcczMRObk0/iMqZRg== + version "1.0.30001423" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001423.tgz#57176d460aa8cd85ee1a72016b961eb9aca55d91" + integrity sha512-09iwWGOlifvE1XuHokFMP7eR38a0JnajoyL3/i87c8ZjRWRrdKo1fqjNfugfBD0UDBIOz0U+jtNhJ0EPm1VleQ== capture-exit@^2.0.0: version "2.0.0" @@ -6683,9 +6673,9 @@ decamelize@^1.1.0, decamelize@^1.2.0: integrity sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA== decimal.js@^10.2.1: - version "10.4.1" - resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.4.1.tgz#be75eeac4a2281aace80c1a8753587c27ef053e7" - integrity sha512-F29o+vci4DodHYT9UrR5IEbfBw9pE5eSapIJdTqXK5+6hq+t8VRxwQyKlW2i+KDKFkkJQRvFyI/QXD83h8LyQw== + version "10.4.2" + resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.4.2.tgz#0341651d1d997d86065a2ce3a441fbd0d8e8b98e" + integrity sha512-ic1yEvwT6GuvaYwBLLY6/aFFgjZdySKTE8en/fkU3QICTmRtgtSlFn0u0BXN06InZwtfCelR7j8LRiDI/02iGA== decode-uri-component@^0.2.0: version "0.2.0" @@ -7136,9 +7126,9 @@ electron-fetch@^1.7.2: encoding "^0.1.13" electron-to-chromium@^1.3.378, electron-to-chromium@^1.4.251: - version "1.4.277" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.277.tgz#6dc3d9724a0a19b7ab155bf8e37967357a081dc5" - integrity sha512-Ej4VyUfGdVY5D2J5WHAVNqrEFBKgeNcX7p/bBQU4x/VKwvnyEvGd62NEkIK3lykLEe9Cg4MCcoWAa+u97o0u/A== + version "1.4.284" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.284.tgz#61046d1e4cab3a25238f6bf7413795270f125592" + integrity sha512-M8WEXFuKXMYMVr45fo8mq0wUrrJHheiKZf6BArTKk9ZBYCKJEOU5H8cdWgDT+qCVZf7Na4lVUaZsA+h6uA9+PA== elliptic@6.5.4, elliptic@^6.5.3: version "6.5.4" @@ -9690,9 +9680,9 @@ is-color-stop@^1.0.0: rgba-regex "^1.0.0" is-core-module@^2.5.0, is-core-module@^2.9.0: - version "2.10.0" - resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.10.0.tgz#9012ede0a91c69587e647514e1d5277019e728ed" - integrity sha512-Erxj2n/LDAZ7H8WNJXd9tw38GYM3dv8rk8Zcs+jJuxYTW7sozH+SS8NtrSjVL1/vpLvWi1hxy96IzjJ3EHTJJg== + version "2.11.0" + resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.11.0.tgz#ad4cb3e3863e814523c96f3f58d26cc570ff0144" + integrity sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw== dependencies: has "^1.0.3" @@ -11319,9 +11309,9 @@ jsonfile@^6.0.1: graceful-fs "^4.1.6" jsonify@~0.0.0: - version "0.0.0" - resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73" - integrity sha512-trvBk1ki43VZptdBI5rIlG4YOzyeH/WefQt5rj1grasPn4iiZWKet8nkgc4GlsAylaztn0qZfUYOiTsASJFdNA== + version "0.0.1" + resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.1.tgz#2aa3111dae3d34a0f151c63f3a45d995d9420978" + integrity sha512-2/Ki0GcmuqSrgFyelQq9M05y7PS0mEwuIzrf3f1fPqkVDVRvZrPZtVSMHxdgo8Aq0sxAOb/cr2aqqA3LeWHVPg== jsonparse@^1.2.0, jsonparse@^1.3.1: version "1.3.1" @@ -11577,9 +11567,9 @@ loader-utils@^1.1.0, loader-utils@^1.2.3, loader-utils@^1.4.0: json5 "^1.0.1" loader-utils@^2.0.0: - version "2.0.2" - resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.2.tgz#d6e3b4fb81870721ae4e0868ab11dd638368c129" - integrity sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A== + version "2.0.3" + resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.3.tgz#d4b15b8504c63d1fc3f2ade52d41bc8459d6ede1" + integrity sha512-THWqIsn8QRnvLl0shHYVBN9syumU8pYWEHPTmkiVGd+7K5eFNVSY6AJhRvgGF70gg1Dz+l/k8WicvFCxdEs60A== dependencies: big.js "^5.2.2" emojis-list "^3.0.0" @@ -15101,9 +15091,9 @@ regenerator-runtime@^0.11.0: integrity sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg== regenerator-runtime@^0.13.3, regenerator-runtime@^0.13.4: - version "0.13.9" - resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52" - integrity sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA== + version "0.13.10" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.10.tgz#ed07b19616bcbec5da6274ebc75ae95634bfc2ee" + integrity sha512-KepLsg4dU12hryUO7bp/axHAKvwGOCV0sGloQtpagJ12ai+ojVDqkeGSiRX1zlq+kjIMZ1t7gpze+26QqtdGqw== regenerator-transform@^0.15.0: version "0.15.0" @@ -17270,15 +17260,14 @@ util@^0.11.0: inherits "2.0.3" util@^0.12.3: - version "0.12.4" - resolved "https://registry.yarnpkg.com/util/-/util-0.12.4.tgz#66121a31420df8f01ca0c464be15dfa1d1850253" - integrity sha512-bxZ9qtSlGUWSOy9Qa9Xgk11kSslpuZwaxCg4sNIDj6FLucDab2JxnHwyNTCpHMtK1MjoQiWQ6DiUMZYbSrO+Sw== + version "0.12.5" + resolved "https://registry.yarnpkg.com/util/-/util-0.12.5.tgz#5f17a6059b73db61a875668781a1c2b136bd6fbc" + integrity sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA== dependencies: inherits "^2.0.3" is-arguments "^1.0.4" is-generator-function "^1.0.7" is-typed-array "^1.1.3" - safe-buffer "^5.1.2" which-typed-array "^1.1.2" utila@~0.4: