diff --git a/packages/cli/src/__tests__/unit/option-parsers/option-parsers.spec.ts b/packages/cli/src/__tests__/unit/option-parsers/option-parsers.spec.ts index e154930a6b..6307f00310 100644 --- a/packages/cli/src/__tests__/unit/option-parsers/option-parsers.spec.ts +++ b/packages/cli/src/__tests__/unit/option-parsers/option-parsers.spec.ts @@ -4,13 +4,13 @@ import { parseWrapperEnvsOption } from "../../../lib"; describe("unit tests for option-parsers", () => { describe("wrapper-envs", () => { const sampleFileEnvs = { - "ens/wraps.eth:ethereum@1.0.0": { + "wrap://ens/wraps.eth:ethereum@1.0.0": { connection: { networkNameOrChainId: "mainnet", node: "https://mainnet.infura.io/v3/some_api_key", }, }, - "ens/hello-world.polywrap.eth": { foo: "bar" }, + "wrap://ens/hello-world.polywrap.eth": { foo: "bar" }, }; it("Should return undefined when undefined is provided for wrapperEnvsPath", async () => { diff --git a/packages/js/client-config-builder/src/BaseClientConfigBuilder.ts b/packages/js/client-config-builder/src/BaseClientConfigBuilder.ts index ab51757d0d..d1f502b2c7 100644 --- a/packages/js/client-config-builder/src/BaseClientConfigBuilder.ts +++ b/packages/js/client-config-builder/src/BaseClientConfigBuilder.ts @@ -186,6 +186,10 @@ export abstract class BaseClientConfigBuilder implements IClientConfigBuilder { delete this.config.interfaces[this.sanitizeUri(interfaceUri)]; } + if (existingInterface.size == 0) { + delete this._config.interfaces[interfaceUri]; + } + return this; } diff --git a/packages/js/client-config-builder/src/ClientConfigBuilder.ts b/packages/js/client-config-builder/src/ClientConfigBuilder.ts index 7780be68cd..ee9d288c0a 100644 --- a/packages/js/client-config-builder/src/ClientConfigBuilder.ts +++ b/packages/js/client-config-builder/src/ClientConfigBuilder.ts @@ -4,12 +4,13 @@ import { BuildOptions, IClientConfigBuilder, BuilderConfig } from "./types"; import { CoreClientConfig, - Env, - InterfaceImplementations, IUriPackage, IUriRedirect, IUriWrapper, Uri, + WrapperEnv, + ReadonlyUriMap, + UriMap, } from "@polywrap/core-js"; import { RecursiveResolver, @@ -66,32 +67,27 @@ export class ClientConfigBuilder extends BaseClientConfigBuilder { return this._config; } - private buildEnvs(): Env[] { - const envs: Env[] = []; + private buildEnvs(): ReadonlyUriMap { + const envs = new UriMap(); - for (const [uri, env] of Object.entries(this._config.envs)) { - envs.push({ uri: Uri.from(uri), env }); + for (const uri in this._config.envs) { + envs.set(Uri.from(uri), this._config.envs[uri]); } return envs; } - private buildInterfaces(): InterfaceImplementations[] { - const interfaces: InterfaceImplementations[] = []; - - for (const [interfaceUri, implementations] of Object.entries( - this._config.interfaces - )) { - if (implementations.size === 0) continue; - interfaces.push({ - interface: Uri.from(interfaceUri), - implementations: Array.from(implementations).map((uri) => - Uri.from(uri) - ), - }); + private buildInterfaces(): ReadonlyUriMap { + const interfaceImplementations = new UriMap(); + + for (const uri in this._config.interfaces) { + const uriImpls = [...this._config.interfaces[uri]].map((x) => + Uri.from(x) + ); + interfaceImplementations.set(Uri.from(uri), uriImpls); } - return interfaces; + return interfaceImplementations; } private buildRedirects(): IUriRedirect[] { 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 08d498f991..2f473ca838 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 @@ -4,6 +4,8 @@ import { Uri, IUriResolver, UriPackageOrWrapper, + UriMap, + WrapperEnv, IWrapPackage, Wrapper, } from "@polywrap/core-js"; @@ -81,8 +83,8 @@ describe("Client config builder", () => { it("should build an empty partial config", () => { const clientConfig = new ClientConfigBuilder().build(); - expect(clientConfig.envs).toStrictEqual([]); - expect(clientConfig.interfaces).toStrictEqual([]); + expect(clientConfig.envs).toStrictEqual(new UriMap()); + expect(clientConfig.interfaces).toStrictEqual(new UriMap()); }); it("should succesfully add config object and build", () => { @@ -100,16 +102,22 @@ describe("Client config builder", () => { expect(clientConfig).toBeTruthy(); expect(clientConfig.envs).toStrictEqual( - Object.entries(testEnvs).map(([uri, env]) => ({ - uri: Uri.from(uri), - env: env, - })) + new UriMap([ + [Uri.from("wrap://ens/test.plugin.one"), { test: "value" }], + [Uri.from("wrap://ens/test.plugin.two"), { test: "value" }], + ]) ); expect(clientConfig.interfaces).toStrictEqual( - Object.entries(testInterfaces).map(([uri, interfaces]) => ({ - interface: Uri.from(uri), - implementations: Array.from(interfaces).map(Uri.from), - })) + new UriMap([ + [ + Uri.from("wrap://ens/test-interface-1.polywrap.eth"), + [Uri.from("wrap://ens/test1.polywrap.eth")], + ], + [ + Uri.from("wrap://ens/test-interface-2.polywrap.eth"), + [Uri.from("wrap://ens/test2.polywrap.eth")], + ], + ]) ); expect(builderConfig).toEqual({ @@ -137,16 +145,22 @@ describe("Client config builder", () => { expect(clientConfig).toBeTruthy(); expect(clientConfig.envs).toStrictEqual( - Object.entries(testEnvs).map(([uri, env]) => ({ - uri: Uri.from(uri), - env: env, - })) + new UriMap([ + [Uri.from("wrap://ens/test.plugin.one"), { test: "value" }], + [Uri.from("wrap://ens/test.plugin.two"), { test: "value" }], + ]) ); expect(clientConfig.interfaces).toStrictEqual( - Object.entries(testInterfaces).map(([uri, interfaces]) => ({ - interface: Uri.from(uri), - implementations: Array.from(interfaces).map(Uri.from), - })) + new UriMap([ + [ + Uri.from("wrap://ens/test-interface-1.polywrap.eth"), + [Uri.from("wrap://ens/test1.polywrap.eth")], + ], + [ + Uri.from("wrap://ens/test-interface-2.polywrap.eth"), + [Uri.from("wrap://ens/test2.polywrap.eth")], + ], + ]) ); expect(clientConfig.resolver).toBeTruthy(); @@ -185,12 +199,11 @@ describe("Client config builder", () => { const config = new ClientConfigBuilder().addEnv(envUri, env).build(); - if (!config.envs || config.envs.length !== 1) { + if (!config.envs || config.envs.size !== 1) { fail(["Expected 1 env, received:", config.envs]); } - expect(config.envs[0].uri).toStrictEqual(Uri.from(envUri)); - expect(config.envs[0].env).toStrictEqual(env); + expect(config.envs.get(Uri.from(envUri))).toEqual(env); }); it("should successfully add to an existing env", () => { @@ -211,12 +224,11 @@ describe("Client config builder", () => { const expectedEnv = { ...env1, ...env2 }; - if (!config.envs || config.envs.length !== 1) { + if (!config.envs || config.envs.size !== 1) { fail(["Expected 1 env, received:", config.envs]); } - expect(config.envs[0].uri).toStrictEqual(Uri.from(envUri)); - expect(config.envs[0].env).toStrictEqual(expectedEnv); + expect(config.envs.get(Uri.from(envUri))).toEqual(expectedEnv); }); it("should succesfully add two separate envs", () => { @@ -225,18 +237,16 @@ describe("Client config builder", () => { .addEnv(Object.keys(testEnvs)[1], Object.values(testEnvs)[1]) .build(); - if (!config.envs || config.envs.length !== 2) { + if (!config.envs || config.envs.size !== 2) { fail(["Expected 2 envs, received:", config.envs]); } - expect(config.envs).toContainEqual({ - uri: Uri.from(Object.keys(testEnvs)[0]), - env: Object.values(testEnvs)[0], - }); - expect(config.envs).toContainEqual({ - uri: Uri.from(Object.keys(testEnvs)[1]), - env: Object.values(testEnvs)[1], - }); + expect(config.envs.get(Uri.from(Object.keys(testEnvs)[0]))).toEqual( + Object.values(testEnvs)[0] + ); + expect(config.envs.get(Uri.from(Object.keys(testEnvs)[0]))).toEqual( + Object.values(testEnvs)[1] + ); }); it("should remove an env", () => { @@ -246,14 +256,13 @@ describe("Client config builder", () => { .removeEnv(Object.keys(testEnvs)[0]) .build(); - if (!config.envs || config.envs.length !== 1) { + if (!config.envs || config.envs.size !== 1) { fail(["Expected 1 env, received:", config.envs]); } - expect(config.envs).toContainEqual({ - uri: Uri.from(Object.keys(testEnvs)[1]), - env: Object.values(testEnvs)[1], - }); + expect(config.envs.get(Uri.from(Object.keys(testEnvs)[1]))).toEqual( + Object.values(testEnvs)[1] + ); }); it("should set an env", () => { @@ -265,14 +274,11 @@ describe("Client config builder", () => { const config = new ClientConfigBuilder().setEnv(envUri, env).build(); - if (!config.envs || config.envs.length !== 1) { + if (!config.envs || config.envs.size !== 1) { fail(["Expected 1 env, received:", config.envs]); } - expect(config.envs[0]).toEqual({ - uri: Uri.from(envUri), - env: env, - }); + expect(config.envs.get(Uri.from(envUri))).toEqual(env); }); it("should set an env over an existing env", () => { @@ -290,14 +296,11 @@ describe("Client config builder", () => { .setEnv(envUri, env2) .build(); - if (!config.envs || config.envs.length !== 1) { + if (!config.envs || config.envs.size !== 1) { fail(["Expected 1 env, received:", config.envs]); } - expect(config.envs[0]).toEqual({ - uri: Uri.from(envUri), - env: env2, - }); + expect(config.envs.get(Uri.from(envUri))).toEqual(env2); }); it("should add an interface implementation for a non-existent interface", () => { @@ -308,14 +311,13 @@ describe("Client config builder", () => { .addInterfaceImplementation(interfaceUri, implUri) .build(); - if (!config.interfaces || config.interfaces.length !== 1) { + if (!config.interfaces || config.interfaces.size !== 1) { fail(["Expected 1 interface, received:", config.interfaces]); } - expect(config.interfaces[0]).toStrictEqual({ - interface: Uri.from(interfaceUri), - implementations: [Uri.from(implUri)], - }); + expect(config.interfaces).toStrictEqual( + new UriMap([[Uri.from(interfaceUri), [Uri.from(implUri)]]]) + ); }); it("should add an interface implementation for an interface that already exists", () => { @@ -328,18 +330,14 @@ describe("Client config builder", () => { .addInterfaceImplementation(interfaceUri, implUri2) .build(); - if (!config.interfaces || config.interfaces.length !== 1) { + if (!config.interfaces || config.interfaces.size !== 1) { fail(["Expected 1 interface, received:", config.interfaces]); } - expect(config.interfaces[0].interface).toStrictEqual( - Uri.from(interfaceUri) - ); - expect(config.interfaces[0].implementations).toContainEqual( - Uri.from(implUri1) - ); - expect(config.interfaces[0].implementations).toContainEqual( - Uri.from(implUri2) + expect(config.interfaces).toStrictEqual( + new UriMap([ + [Uri.from(interfaceUri), [Uri.from(implUri1), Uri.from(implUri2)]], + ]) ); }); @@ -358,26 +356,16 @@ describe("Client config builder", () => { .addInterfaceImplementation(interfaceUri2, implUri4) .build(); - if (!config.interfaces || config.interfaces.length !== 2) { + if (!config.interfaces || config.interfaces.size !== 2) { fail(["Expected 2 interfaces, received:", config.interfaces]); } - const interface1 = config.interfaces.find( - (x) => x.interface.uri === interfaceUri1 + expect(config.interfaces).toStrictEqual( + new UriMap([ + [Uri.from(interfaceUri1), [Uri.from(implUri1), Uri.from(implUri3)]], + [Uri.from(interfaceUri2), [Uri.from(implUri2), Uri.from(implUri4)]], + ]) ); - const interface2 = config.interfaces.find( - (x) => x.interface.uri === interfaceUri2 - ); - - expect(interface1).toBeDefined(); - expect(interface1?.implementations).toHaveLength(2); - expect(interface1?.implementations).toContainEqual(Uri.from(implUri1)); - expect(interface1?.implementations).toContainEqual(Uri.from(implUri3)); - - expect(interface2).toBeDefined(); - expect(interface2?.implementations).toHaveLength(2); - expect(interface2?.implementations).toContainEqual(Uri.from(implUri2)); - expect(interface2?.implementations).toContainEqual(Uri.from(implUri4)); }); it("should add multiple implementations for a non-existent interface", () => { @@ -389,19 +377,14 @@ describe("Client config builder", () => { .addInterfaceImplementations(interfaceUri, [implUri1, implUri2]) .build(); - if (!config.interfaces || config.interfaces.length !== 1) { + if (!config.interfaces || config.interfaces.size !== 1) { fail(["Expected 1 interface, received:", config.interfaces]); } - expect(config.interfaces[0].interface).toStrictEqual( - Uri.from(interfaceUri) - ); - expect(config.interfaces[0].implementations).toHaveLength(2); - expect(config.interfaces[0].implementations).toContainEqual( - Uri.from(implUri1) - ); - expect(config.interfaces[0].implementations).toContainEqual( - Uri.from(implUri2) + expect(config.interfaces).toStrictEqual( + new UriMap([ + [Uri.from(interfaceUri), [Uri.from(implUri1), Uri.from(implUri2)]], + ]) ); }); @@ -416,22 +399,17 @@ describe("Client config builder", () => { .addInterfaceImplementations(interfaceUri, [implUri2, implUri3]) .build(); - if (!config.interfaces || config.interfaces.length !== 1) { + if (!config.interfaces || config.interfaces.size !== 1) { fail(["Expected 1 interface, received:", config.interfaces]); } - expect(config.interfaces[0].interface).toStrictEqual( - Uri.from(interfaceUri) - ); - expect(config.interfaces[0].implementations).toHaveLength(3); - expect(config.interfaces[0].implementations).toContainEqual( - Uri.from(implUri1) - ); - expect(config.interfaces[0].implementations).toContainEqual( - Uri.from(implUri2) - ); - expect(config.interfaces[0].implementations).toContainEqual( - Uri.from(implUri3) + expect(config.interfaces).toStrictEqual( + new UriMap([ + [ + Uri.from(interfaceUri), + [Uri.from(implUri1), Uri.from(implUri2), Uri.from(implUri3)], + ], + ]) ); }); @@ -452,28 +430,22 @@ describe("Client config builder", () => { .addInterfaceImplementations(interfaceUri2, [implUri4, implUri6]) .build(); - if (!config.interfaces || config.interfaces.length !== 2) { + if (!config.interfaces || config.interfaces.size !== 2) { fail(["Expected 2 interfaces, received:", config.interfaces]); } - const interface1 = config.interfaces.find( - (x) => x.interface.uri === interfaceUri1 - ); - const interface2 = config.interfaces.find( - (x) => x.interface.uri === interfaceUri2 + expect(config.interfaces).toStrictEqual( + new UriMap([ + [ + Uri.from(interfaceUri1), + [Uri.from(implUri1), Uri.from(implUri3), Uri.from(implUri5)], + ], + [ + Uri.from(interfaceUri2), + [Uri.from(implUri2), Uri.from(implUri4), Uri.from(implUri6)], + ], + ]) ); - - expect(interface1).toBeDefined(); - expect(interface1?.implementations).toHaveLength(3); - expect(interface1?.implementations).toContainEqual(Uri.from(implUri1)); - expect(interface1?.implementations).toContainEqual(Uri.from(implUri3)); - expect(interface1?.implementations).toContainEqual(Uri.from(implUri5)); - - expect(interface2).toBeDefined(); - expect(interface2?.implementations).toHaveLength(3); - expect(interface2?.implementations).toContainEqual(Uri.from(implUri2)); - expect(interface2?.implementations).toContainEqual(Uri.from(implUri4)); - expect(interface2?.implementations).toContainEqual(Uri.from(implUri6)); }); it("should remove an interface implementation", () => { @@ -488,25 +460,16 @@ describe("Client config builder", () => { .removeInterfaceImplementation(interfaceUri1, implUri2) .build(); - if (!config.interfaces || config.interfaces.length !== 2) { + if (!config.interfaces || config.interfaces.size !== 2) { fail(["Expected 2 interfaces, received:", config.interfaces]); } - const interface1 = config.interfaces.find( - (x) => x.interface.uri === interfaceUri1 - ); - const interface2 = config.interfaces.find( - (x) => x.interface.uri === interfaceUri2 + expect(config.interfaces).toStrictEqual( + new UriMap([ + [Uri.from(interfaceUri1), [Uri.from(implUri1)]], + [Uri.from(interfaceUri2), [Uri.from(implUri1), Uri.from(implUri2)]], + ]) ); - - expect(interface1).toBeDefined(); - expect(interface1?.implementations).toHaveLength(1); - expect(interface1?.implementations).toContainEqual(Uri.from(implUri1)); - - expect(interface2).toBeDefined(); - expect(interface2?.implementations).toHaveLength(2); - expect(interface2?.implementations).toContainEqual(Uri.from(implUri1)); - expect(interface2?.implementations).toContainEqual(Uri.from(implUri2)); }); it("should completely remove an interface if there are no implementations left", () => { @@ -522,23 +485,15 @@ describe("Client config builder", () => { .removeInterfaceImplementation(interfaceUri1, implUri2) .build(); - if (!config.interfaces || config.interfaces.length !== 1) { + if (!config.interfaces || config.interfaces.size !== 1) { fail(["Expected 1 interface, received:", config.interfaces]); } - const interface1 = config.interfaces.find( - (x) => x.interface.uri === interfaceUri1 + expect(config.interfaces).toStrictEqual( + new UriMap([ + [Uri.from(interfaceUri2), [Uri.from(implUri1), Uri.from(implUri2)]], + ]) ); - const interface2 = config.interfaces.find( - (x) => x.interface.uri === interfaceUri2 - ); - - expect(interface1).toBeUndefined(); - - expect(interface2).toBeDefined(); - expect(interface2?.implementations).toHaveLength(2); - expect(interface2?.implementations).toContainEqual(Uri.from(implUri1)); - expect(interface2?.implementations).toContainEqual(Uri.from(implUri2)); }); it("should add an uri redirect", () => { diff --git a/packages/js/client/src/PolywrapClient.ts b/packages/js/client/src/PolywrapClient.ts index 6c554461ca..978bb06868 100644 --- a/packages/js/client/src/PolywrapClient.ts +++ b/packages/js/client/src/PolywrapClient.ts @@ -3,18 +3,18 @@ import { InvokerOptions, TryResolveUriOptions } from "./types"; import { PolywrapCoreClient } from "@polywrap/core-client-js"; import { CoreClientConfig, - Env, GetFileOptions, GetImplementationsOptions, - InterfaceImplementations, InvokeResult, IUriResolutionContext, IUriResolver, + ReadonlyUriMap, Uri, UriPackageOrWrapper, ValidateOptions, WrapError, Wrapper, + WrapperEnv, } from "@polywrap/core-js"; import { Result, ResultErr, ResultOk } from "@polywrap/result"; import { @@ -60,12 +60,12 @@ export class PolywrapClient extends PolywrapCoreClient { } @Tracer.traceMethod("PolywrapClient: getInterfaces") - public getInterfaces(): readonly InterfaceImplementations[] | undefined { + public getInterfaces(): ReadonlyUriMap | undefined { return super.getInterfaces(); } @Tracer.traceMethod("PolywrapClient: getEnvs") - public getEnvs(): readonly Env[] | undefined { + public getEnvs(): ReadonlyUriMap | undefined { return super.getEnvs(); } @@ -77,7 +77,7 @@ export class PolywrapClient extends PolywrapCoreClient { @Tracer.traceMethod("PolywrapClient: getEnvByUri") public getEnvByUri( uri: TUri - ): Env | undefined { + ): WrapperEnv | undefined { return super.getEnvByUri(Uri.from(uri)); } diff --git a/packages/js/client/src/__tests__/core/wrap-features/env-case.ts b/packages/js/client/src/__tests__/core/wrap-features/env-case.ts index 4360dd39f1..d55d0f0318 100644 --- a/packages/js/client/src/__tests__/core/wrap-features/env-case.ts +++ b/packages/js/client/src/__tests__/core/wrap-features/env-case.ts @@ -4,7 +4,7 @@ import { GetPathToTestWrappers } from "@polywrap/test-cases"; import { PolywrapClient } from "../../../PolywrapClient"; import { mockPluginRegistration } from "../../helpers"; import { ClientConfigBuilder } from "@polywrap/client-config-builder-js"; -import { Uri } from "@polywrap/core-js"; +import { Uri, UriMap } from "@polywrap/core-js"; jest.setTimeout(200000); @@ -175,14 +175,7 @@ export const envTestCases = (implementation: string) => { }, { from: Uri.from("ens/hello.eth"), to: implementationUri }, ]), - envs: [ - { - uri: Uri.from("ens/hello.eth"), - env: { - arg1: "10", - }, - }, - ], + envs: new UriMap([[Uri.from("wrap://ens/hello.eth"), { arg1: "10" }]]), }); const mockEnv = await client.invoke({ @@ -196,7 +189,7 @@ export const envTestCases = (implementation: string) => { }); test("inline plugin env types", async () => { - const implementationUri = Uri.from("wrap://ens/some-implementation.eth"); + const implementationUri = "wrap://ens/some-implementation.eth"; interface MockEnv extends Record { arg1: number; } @@ -204,26 +197,19 @@ export const envTestCases = (implementation: string) => { const client = new PolywrapClient({ resolver: RecursiveResolver.from([ { - uri: implementationUri, - package: PluginPackage.from(() => ({ + uri: Uri.from(implementationUri), + package: PluginPackage.from((module) => ({ mockEnv: (_, __, env: MockEnv): MockEnv => { return env; }, })), }, ]), - envs: [ - { - uri: implementationUri, - env: { - arg1: "10", - }, - }, - ], + envs: new UriMap([[Uri.from(implementationUri), { arg1: "10" }]]), }); const mockEnv = await client.invoke({ - uri: implementationUri, + uri: Uri.from(implementationUri), method: "mockEnv", }); diff --git a/packages/js/client/src/__tests__/core/wrap-features/interface-implementation-case.ts b/packages/js/client/src/__tests__/core/wrap-features/interface-implementation-case.ts index a98b201848..bbedd059c4 100644 --- a/packages/js/client/src/__tests__/core/wrap-features/interface-implementation-case.ts +++ b/packages/js/client/src/__tests__/core/wrap-features/interface-implementation-case.ts @@ -1,4 +1,9 @@ -import { ExtendableUriResolver, Uri, PolywrapClient } from "../../../index"; +import { + ExtendableUriResolver, + Uri, + PolywrapClient, + UriMap, +} from "../../../index"; import { ClientConfigBuilder } from "@polywrap/client-config-builder-js"; import { UriResolver } from "@polywrap/uri-resolvers-js"; import { mockPluginRegistration } from "../../helpers"; @@ -52,12 +57,9 @@ export const interfaceInvokeCase = (implementation: string) => { ); const client = new PolywrapClient({ - interfaces: [ - { - interface: interfaceUri, - implementations: [implementation1Uri, implementation2Uri], - }, - ], + interfaces: new UriMap([ + [interfaceUri, [implementation1Uri, implementation2Uri]], + ]), resolver: UriResolver.from({ from: Uri.from("uri/foo"), to: Uri.from("uri/bar"), @@ -66,12 +68,9 @@ export const interfaceInvokeCase = (implementation: string) => { const interfaces = client.getInterfaces(); - expect(interfaces).toEqual([ - { - interface: interfaceUri, - implementations: [implementation1Uri, implementation2Uri], - }, - ]); + expect(interfaces).toEqual(new UriMap([ + [interfaceUri, [implementation1Uri, implementation2Uri]], + ])); const implementations = await client.getImplementations(interfaceUri, { applyResolution: false, @@ -116,20 +115,11 @@ export const interfaceInvokeCase = (implementation: string) => { }, mockPluginRegistration(implementation4Uri), ]), - interfaces: [ - { - interface: interface1Uri, - implementations: [implementation1Uri, implementation2Uri], - }, - { - interface: interface2Uri, - implementations: [implementation3Uri], - }, - { - interface: interface3Uri, - implementations: [implementation3Uri, implementation4Uri], - }, - ], + interfaces: new UriMap([ + [interface1Uri, [implementation1Uri, implementation2Uri]], + [interface2Uri, [implementation3Uri]], + [interface3Uri, [implementation3Uri, implementation4Uri]], + ]), }); const implementations1 = await client.getImplementations(interface1Uri, { @@ -178,12 +168,7 @@ export const interfaceInvokeCase = (implementation: string) => { const client = new PolywrapClient(config); - const interfaces = (client.getInterfaces() || []).filter( - (x) => x.interface.uri === interfaceUri.uri - ); - expect(interfaces.length).toEqual(1); - - const implementationUris = interfaces[0].implementations; + const implementationUris = (client.getInterfaces() || new UriMap).get(interfaceUri); expect(implementationUris).toEqual([ implementationUri1, @@ -206,20 +191,13 @@ export const interfaceInvokeCase = (implementation: string) => { const client = new PolywrapClient(config); - const interfaces = (client.getInterfaces() || []).filter( - (x) => x.interface.uri === interfaceUri.uri - ); - expect(interfaces.length).toEqual(1); - - const implementationUris = interfaces[0].implementations; + const implementationUris = (client.getInterfaces() ?? new UriMap).get(interfaceUri); const builder = new ClientConfigBuilder(); const defaultClientConfig = builder.addDefaults().build(); expect(implementationUris).toEqual([ - ...(defaultClientConfig.interfaces || []).find( - (x) => x.interface.uri === interfaceUri.uri - )!.implementations, + ...((defaultClientConfig.interfaces ?? new UriMap).get(interfaceUri) || []), implementationUri1, implementationUri2, ]); @@ -239,12 +217,9 @@ export const interfaceInvokeCase = (implementation: string) => { resolver: UriResolver.from([ mockPluginRegistration(implementation1Uri), ]), - interfaces: [ - { - interface: interfaceUri, - implementations: [implementation2Uri], - }, - ], + interfaces: new UriMap([ + [interfaceUri, [implementation2Uri]], + ]), }); const getImplementationsResult = await client.getImplementations( @@ -270,12 +245,9 @@ export const interfaceInvokeCase = (implementation: string) => { resolver: UriResolver.from([ mockPluginRegistration(implementation1Uri), ]), - interfaces: [ - { - interface: interfaceUri, - implementations: [implementation1Uri, implementation2Uri], - }, - ], + interfaces: new UriMap([ + [interfaceUri, [implementation1Uri, implementation2Uri]], + ]), }); const getImplementationsResult = await client.getImplementations( diff --git a/packages/js/core-client/README.md b/packages/js/core-client/README.md index b5defa23fb..0f64b7e764 100644 --- a/packages/js/core-client/README.md +++ b/packages/js/core-client/README.md @@ -74,9 +74,7 @@ Invoke a wrapper. * * @returns an array of interfaces and their registered implementations */ - public getInterfaces(): - | readonly InterfaceImplementations[] - | undefined + public getInterfaces(): ReadonlyUriMap | undefined ``` ### getEnvs @@ -86,7 +84,7 @@ Invoke a wrapper. * * @returns an array of env objects containing wrapper environmental variables */ - public getEnvs(): readonly Env[] | undefined + public getEnvs(): ReadonlyUriMap | undefined ``` ### getResolver @@ -107,7 +105,7 @@ Invoke a wrapper. * @param uri - the URI used to register the env * @returns an env, or undefined if an env is not found at the given URI */ - public getEnvByUri(uri: Uri): Env | undefined + public getEnvByUri(uri: Uri): WrapperEnv | undefined ``` ### getManifest diff --git a/packages/js/core-client/src/PolywrapCoreClient.ts b/packages/js/core-client/src/PolywrapCoreClient.ts index e69afa98b6..90324b11ea 100644 --- a/packages/js/core-client/src/PolywrapCoreClient.ts +++ b/packages/js/core-client/src/PolywrapCoreClient.ts @@ -1,10 +1,8 @@ import { Wrapper, CoreClient, - Env, GetFileOptions, GetImplementationsOptions, - InterfaceImplementations, InvokeOptions, InvokerOptions, Uri, @@ -20,6 +18,9 @@ import { CoreClientConfig, WrapError, WrapErrorCode, + WrapperEnv, + ReadonlyUriMap, + UriMap, } from "@polywrap/core-js"; import { msgpackEncode, msgpackDecode } from "@polywrap/msgpack-js"; import { @@ -53,9 +54,7 @@ export class PolywrapCoreClient implements CoreClient { * * @returns an array of interfaces and their registered implementations */ - public getInterfaces(): - | readonly InterfaceImplementations[] - | undefined /* $ */ { + public getInterfaces(): ReadonlyUriMap | undefined /* $ */ { return this._config.interfaces; } @@ -65,7 +64,7 @@ export class PolywrapCoreClient implements CoreClient { * * @returns an array of env objects containing wrapper environmental variables */ - public getEnvs(): readonly Env[] | undefined /* $ */ { + public getEnvs(): ReadonlyUriMap | undefined /* $ */ { return this._config.envs; } @@ -86,15 +85,13 @@ export class PolywrapCoreClient implements CoreClient { * @param uri - the URI used to register the env * @returns an env, or undefined if an env is not found at the given URI */ - public getEnvByUri(uri: Uri): Env | undefined /* $ */ { - const uriUri = Uri.from(uri); - + public getEnvByUri(uri: Uri): WrapperEnv | undefined /* $ */ { const envs = this.getEnvs(); if (!envs) { return undefined; } - return envs.find((environment) => Uri.equals(environment.uri, uriUri)); + return envs.get(uri); } // $start: PolywrapCoreClient-getManifest @@ -163,7 +160,7 @@ export class PolywrapCoreClient implements CoreClient { const getImplResult = await getImplementations( Uri.from(uri), - this.getInterfaces() ?? [], + this.getInterfaces() ?? new UriMap(), applyResolution ? this : undefined, applyResolution ? options.resolutionContext : undefined ); @@ -295,7 +292,7 @@ export class PolywrapCoreClient implements CoreClient { ); const invokeResult = await this.invokeWrapper({ - env: env?.env, + env: env, ...typedOptions, wrapper, }); diff --git a/packages/js/core/README.md b/packages/js/core/README.md index f09614fc4b..a3d2afc75a 100644 --- a/packages/js/core/README.md +++ b/packages/js/core/README.md @@ -12,11 +12,11 @@ A TypeScript / JavaScript implementation of the WRAP standard, including all fun /** Core Client configuration that can be passed to the PolywrapClient or PolywrapCoreClient constructors */ export interface CoreClientConfig { - /** set environmental variables for a wrapper */ - readonly interfaces?: Readonly; - /** register interface implementations */ - readonly envs?: Readonly; + readonly interfaces?: ReadonlyUriMap; + + /** set environmental variables for a wrapper */ + readonly envs?: ReadonlyUriMap; /** configure URI resolution for redirects, packages, and wrappers */ readonly resolver: Readonly>; @@ -61,16 +61,16 @@ export interface CoreClient extends Invoker, UriResolverHandler { /** * returns all interfaces from the configuration used to instantiate the client * - * @returns an array of interfaces and their registered implementations + * @returns a Set of interfaces and their registered implementations */ - getInterfaces(): readonly InterfaceImplementations[] | undefined; + getInterfaces(): ReadonlyUriMap | undefined; /** * returns all env registrations from the configuration used to instantiate the client * * @returns an array of env objects containing wrapper environmental variables */ - getEnvs(): readonly Env[] | undefined; + getEnvs(): ReadonlyUriMap | undefined; /** * returns an env (a set of environmental variables) from the configuration used to instantiate the client @@ -78,7 +78,7 @@ export interface CoreClient extends Invoker, UriResolverHandler { * @param uri - the URI used to register the env * @returns an env, or undefined if an env is not found at the given URI */ - getEnvByUri(uri: Uri): Env | undefined; + getEnvByUri(uri: Uri): WrapperEnv | undefined; /** * returns the URI resolver from the configuration used to instantiate the client @@ -128,28 +128,9 @@ export interface CoreClient extends Invoker, UriResolverHandler { ```ts /** A map of string-indexed, Msgpack-serializable environmental variables associated with a wrapper */ -export interface Env { - /** Uri of wrapper */ - uri: Uri; - - /** Env variables used by the module */ - env: Record; -} -``` - -### InterfaceImplementations - -```ts - -/** An interface and a list of wrappers that implement the interface */ -export interface InterfaceImplementations { - /** Uri of interface */ - interface: Uri; - - /** Uris of implementations */ - implementations: Uri[]; +export interface WrapperEnv { + readonly [k: string]: unknown; } - ``` ### Invoke diff --git a/packages/js/core/readme/README.md b/packages/js/core/readme/README.md index 27479ac1c0..7b412808b2 100644 --- a/packages/js/core/readme/README.md +++ b/packages/js/core/readme/README.md @@ -18,12 +18,6 @@ $snippet: CoreClient.ts $snippet: Env.ts ``` -### InterfaceImplementations - -```ts -$snippet: InterfaceImplementations.ts -``` - ### Invoke ```ts diff --git a/packages/js/core/src/__tests__/get-implementations.spec.ts b/packages/js/core/src/__tests__/get-implementations.spec.ts index 5d2ba04858..fe514f9822 100644 --- a/packages/js/core/src/__tests__/get-implementations.spec.ts +++ b/packages/js/core/src/__tests__/get-implementations.spec.ts @@ -4,12 +4,16 @@ import { IUriRedirect, UriPackageOrWrapper, } from "../"; -import { CoreClient, InterfaceImplementations } from "../types"; +import { CoreClient, UriMap } from "../types"; import { Result, ResultOk } from "@polywrap/result"; const getClient = (redirects: IUriRedirect[]): CoreClient => { return { - tryResolveUri: async ( { uri }: { uri: Uri }): Promise> => { + tryResolveUri: async ({ + uri, + }: { + uri: Uri; + }): Promise> => { while (true) { const redirect = redirects.find((x) => uri.uri === x.from.uri); if (redirect) { @@ -26,7 +30,6 @@ const getClient = (redirects: IUriRedirect[]): CoreClient => { }; describe("getImplementations", () => { - it("works with complex redirects", async () => { const interface1Uri = "wrap://ens/some-interface1.eth"; const interface2Uri = "wrap://ens/some-interface2.eth"; @@ -39,71 +42,62 @@ describe("getImplementations", () => { const redirects: IUriRedirect[] = [ { from: new Uri(interface1Uri), - to: new Uri(interface2Uri) + to: new Uri(interface2Uri), }, { from: new Uri(implementation1Uri), - to: new Uri(implementation2Uri) + to: new Uri(implementation2Uri), }, { from: new Uri(implementation2Uri), - to: new Uri(implementation3Uri) - } - ]; - - const interfaces: InterfaceImplementations[] = [ - { - interface: new Uri(interface1Uri), - implementations: [ - new Uri(implementation1Uri), - new Uri(implementation2Uri) - ] + to: new Uri(implementation3Uri), }, - { - interface: new Uri(interface2Uri), - implementations: [ - new Uri(implementation3Uri) - ] - }, - { - interface: new Uri(interface3Uri), - implementations: [ - new Uri(implementation3Uri) - ] - } ]; + const interfaces: UriMap = new UriMap([ + [ + Uri.from(interface1Uri), + [Uri.from(implementation1Uri), Uri.from(implementation2Uri)], + ], + [Uri.from(interface2Uri), [Uri.from(implementation3Uri)]], + [Uri.from(interface3Uri), [Uri.from(implementation3Uri)]], + ]); + const getImplementationsResult1 = await getImplementations( - new Uri(interface1Uri), - interfaces, - getClient(redirects) - ); + new Uri(interface1Uri), + interfaces, + getClient(redirects) + ); const getImplementationsResult2 = await getImplementations( - new Uri(interface2Uri), - interfaces, - getClient(redirects) - ); + new Uri(interface2Uri), + interfaces, + getClient(redirects) + ); const getImplementationsResult3 = await getImplementations( - new Uri(interface3Uri), - interfaces, - getClient(redirects) - ); - - expect(getImplementationsResult1).toEqual(ResultOk([ - new Uri(implementation1Uri), - new Uri(implementation2Uri), - new Uri(implementation3Uri) - ])); - - expect(getImplementationsResult2).toEqual(ResultOk([ - new Uri(implementation1Uri), - new Uri(implementation2Uri), - new Uri(implementation3Uri) - ])); - - expect(getImplementationsResult3).toEqual(ResultOk([ - new Uri(implementation3Uri) - ])); + new Uri(interface3Uri), + interfaces, + getClient(redirects) + ); + + expect(getImplementationsResult1).toEqual( + ResultOk([ + new Uri(implementation1Uri), + new Uri(implementation2Uri), + new Uri(implementation3Uri), + ]) + ); + + expect(getImplementationsResult2).toEqual( + ResultOk([ + new Uri(implementation1Uri), + new Uri(implementation2Uri), + new Uri(implementation3Uri), + ]) + ); + + expect(getImplementationsResult3).toEqual( + ResultOk([new Uri(implementation3Uri)]) + ); }); it("interface implementations are not redirected", async () => { @@ -115,27 +109,20 @@ describe("getImplementations", () => { const redirects: IUriRedirect[] = [ { from: new Uri(implementation1Uri), - to: new Uri(implementation2Uri) - } + to: new Uri(implementation2Uri), + }, ]; - const interfaces: InterfaceImplementations[] = [ - { - interface: new Uri(interface1Uri), - implementations: [ - new Uri(implementation1Uri) - ] - } - ]; + const interfaces: UriMap = new UriMap([ + [Uri.from(interface1Uri), [Uri.from(implementation1Uri)]], + ]); const result = await getImplementations( - new Uri(interface1Uri), - interfaces, - getClient(redirects) - ); + new Uri(interface1Uri), + interfaces, + getClient(redirects) + ); - expect(result).toEqual(ResultOk([ - new Uri(implementation1Uri) - ])); + expect(result).toEqual(ResultOk([new Uri(implementation1Uri)])); }); }); diff --git a/packages/js/core/src/algorithms/get-implementations.ts b/packages/js/core/src/algorithms/get-implementations.ts index 7396ef358c..9a23f9ca03 100644 --- a/packages/js/core/src/algorithms/get-implementations.ts +++ b/packages/js/core/src/algorithms/get-implementations.ts @@ -1,9 +1,9 @@ import { Uri, - InterfaceImplementations, CoreClient, WrapError, WrapErrorCode, + ReadonlyUriMap, } from "../types"; import { IUriResolutionContext } from "../uri-resolution"; import { applyResolution } from "./applyResolution"; @@ -12,7 +12,7 @@ import { Result, ResultErr, ResultOk } from "@polywrap/result"; export const getImplementations = async ( wrapperInterfaceUri: Uri, - interfaces: readonly InterfaceImplementations[], + interfaces: ReadonlyUriMap, client?: CoreClient, resolutionContext?: IUriResolutionContext ): Promise> => { @@ -26,20 +26,20 @@ export const getImplementations = async ( }; const addAllImplementationsFromImplementationsArray = async ( - implementationsArray: readonly InterfaceImplementations[], + impls: ReadonlyUriMap, wrapperInterfaceUri: Uri ): Promise> => { - for (const interfaceImplementations of implementationsArray) { + for (const impl of impls.keys()) { let fullyResolvedUri: Uri; if (client) { const redirectsResult = await applyResolution( - interfaceImplementations.interface, + impl, client, resolutionContext ); if (!redirectsResult.ok) { const error = new WrapError("Failed to resolve redirects", { - uri: interfaceImplementations.interface.uri, + uri: impl.uri, code: WrapErrorCode.CLIENT_GET_IMPLEMENTATIONS_ERROR, cause: redirectsResult.error, }); @@ -47,12 +47,15 @@ export const getImplementations = async ( } fullyResolvedUri = redirectsResult.value; } else { - fullyResolvedUri = interfaceImplementations.interface; + fullyResolvedUri = impl; } if (Uri.equals(fullyResolvedUri, wrapperInterfaceUri)) { - for (const implementation of interfaceImplementations.implementations) { - addUniqueResult(implementation); + const implementations = impls.get(impl); + if (implementations) { + for (const implementation of implementations) { + addUniqueResult(Uri.from(implementation)); + } } } } diff --git a/packages/js/core/src/types/CoreClient.ts b/packages/js/core/src/types/CoreClient.ts index 1089f1880a..da099a6b0f 100644 --- a/packages/js/core/src/types/CoreClient.ts +++ b/packages/js/core/src/types/CoreClient.ts @@ -1,6 +1,7 @@ -import { Invoker, Uri, InterfaceImplementations, Env, WrapError } from "."; +import { Invoker, Uri, WrapError, WrapperEnv } from "."; import { IUriResolutionContext, IUriResolver } from "../uri-resolution"; import { UriResolverHandler } from "./UriResolver"; +import { ReadonlyUriMap } from "./UriMap"; import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; import { Result } from "@polywrap/result"; @@ -9,11 +10,11 @@ import { Result } from "@polywrap/result"; /** Core Client configuration that can be passed to the PolywrapClient or PolywrapCoreClient constructors */ export interface CoreClientConfig { - /** set environmental variables for a wrapper */ - readonly interfaces?: Readonly; - /** register interface implementations */ - readonly envs?: Readonly; + readonly interfaces?: ReadonlyUriMap; + + /** set environmental variables for a wrapper */ + readonly envs?: ReadonlyUriMap; /** configure URI resolution for redirects, packages, and wrappers */ readonly resolver: Readonly>; @@ -58,16 +59,16 @@ export interface CoreClient extends Invoker, UriResolverHandler { /** * returns all interfaces from the configuration used to instantiate the client * - * @returns an array of interfaces and their registered implementations + * @returns a Set of interfaces and their registered implementations */ - getInterfaces(): readonly InterfaceImplementations[] | undefined; + getInterfaces(): ReadonlyUriMap | undefined; /** * returns all env registrations from the configuration used to instantiate the client * * @returns an array of env objects containing wrapper environmental variables */ - getEnvs(): readonly Env[] | undefined; + getEnvs(): ReadonlyUriMap | undefined; /** * returns an env (a set of environmental variables) from the configuration used to instantiate the client @@ -75,7 +76,7 @@ export interface CoreClient extends Invoker, UriResolverHandler { * @param uri - the URI used to register the env * @returns an env, or undefined if an env is not found at the given URI */ - getEnvByUri(uri: Uri): Env | undefined; + getEnvByUri(uri: Uri): WrapperEnv | undefined; /** * returns the URI resolver from the configuration used to instantiate the client diff --git a/packages/js/core/src/types/Env.ts b/packages/js/core/src/types/Env.ts index 0bc8af2127..1b88c52c8b 100644 --- a/packages/js/core/src/types/Env.ts +++ b/packages/js/core/src/types/Env.ts @@ -1,13 +1,7 @@ -import { Uri } from "."; - // $start: Env.ts /** A map of string-indexed, Msgpack-serializable environmental variables associated with a wrapper */ -export interface Env { - /** Uri of wrapper */ - uri: Uri; - - /** Env variables used by the module */ - env: Record; +export interface WrapperEnv { + readonly [k: string]: unknown; } // $end diff --git a/packages/js/core/src/types/InterfaceImplementations.ts b/packages/js/core/src/types/InterfaceImplementations.ts deleted file mode 100644 index fd8ccc85a0..0000000000 --- a/packages/js/core/src/types/InterfaceImplementations.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Uri } from "."; - -// $start: InterfaceImplementations.ts - -/** An interface and a list of wrappers that implement the interface */ -export interface InterfaceImplementations { - /** Uri of interface */ - interface: Uri; - - /** Uris of implementations */ - implementations: Uri[]; -} - -// $end diff --git a/packages/js/core/src/types/UriMap.ts b/packages/js/core/src/types/UriMap.ts new file mode 100644 index 0000000000..a6e218cdd6 --- /dev/null +++ b/packages/js/core/src/types/UriMap.ts @@ -0,0 +1,67 @@ +import { Uri } from "./Uri"; + +export class UriMap + implements Map, ReadonlyUriMap { + private map: Map; + + constructor(entries?: readonly (readonly [Uri, TValue])[]) { + this.map = new Map(entries?.map((x) => [x[0].uri, x[1]])); + } + + clear(): void { + this.map.clear(); + } + + delete(key: Uri): boolean { + return this.map.delete(key.uri); + } + + forEach( + callbackfn: (value: TValue, key: Uri, map: Map) => void, + thisArg?: unknown + ): void { + this.map.forEach((v, k) => callbackfn(v, Uri.from(k), this), thisArg); + } + + get(key: Uri): TValue | undefined { + return this.map.get(key.uri); + } + + has(key: Uri): boolean { + return this.map.has(key.uri); + } + + set(key: Uri, value: TValue): this { + this.map.set(key.uri, value); + + return this; + } + + get size(): number { + return this.map.size; + } + + [Symbol.toStringTag] = "UriMap"; + + *entries(): IterableIterator<[Uri, TValue]> { + for (const [k, v] of this.map.entries()) { + yield [Uri.from(k), v]; + } + } + + *keys(): IterableIterator { + for (const k of this.map.keys()) { + yield Uri.from(k); + } + } + + values(): IterableIterator { + return this.map.values(); + } + + [Symbol.iterator](): IterableIterator<[Uri, TValue]> { + return this.entries(); + } +} + +export type ReadonlyUriMap = ReadonlyMap; diff --git a/packages/js/core/src/types/index.ts b/packages/js/core/src/types/index.ts index fa09582799..832a906a57 100644 --- a/packages/js/core/src/types/index.ts +++ b/packages/js/core/src/types/index.ts @@ -4,10 +4,10 @@ export * from "./Invoke"; export * from "./MaybeAsync"; export * from "./Uri"; export * from "./Env"; -export * from "./InterfaceImplementations"; export * from "./UriResolver"; export * from "./IWrapPackage"; export * from "./IUriRedirect"; export * from "./IUriWrapper"; export * from "./IUriPackage"; export * from "./WrapError"; +export * from "./UriMap"; diff --git a/packages/js/core/src/utils/getEnvFromUriHistory.ts b/packages/js/core/src/utils/getEnvFromUriHistory.ts index ef96d2cad4..4bf6623798 100644 --- a/packages/js/core/src/utils/getEnvFromUriHistory.ts +++ b/packages/js/core/src/utils/getEnvFromUriHistory.ts @@ -1,9 +1,9 @@ -import { Uri, CoreClient, Env } from "../types"; +import { Uri, CoreClient, WrapperEnv } from "../types"; export const getEnvFromUriHistory = ( uriHistory: Uri[], client: CoreClient -): Env | undefined => { +): Readonly | undefined => { for (const uri of uriHistory) { const env = client.getEnvByUri(uri); diff --git a/packages/js/uri-resolver-extensions/README.md b/packages/js/uri-resolver-extensions/README.md index d6025af9a2..fa0c9932ca 100644 --- a/packages/js/uri-resolver-extensions/README.md +++ b/packages/js/uri-resolver-extensions/README.md @@ -21,29 +21,25 @@ Otherwise, you must also add the `ExtendableUriResolver` to your resolver. ```ts const clientConfig: CoreClientConfig = { - interfaces: [ - { - interface: Uri.from("wrap://ens/uri-resolver.core.polywrap.eth"), - implementations: [ + interfaces: new UriMap([ + [ + Uri.from("wrap://ens/uri-resolver.core.polywrap.eth"), + [ Uri.from("wrap://ens/fs-resolver.polywrap.eth"), Uri.from("wrap://ens/ipfs-resolver.polywrap.eth"), - Uri.from("wrap://ens/ens-resolver.polywrap.eth") - ] - } - ], + Uri.from("wrap://ens/ens-resolver.polywrap.eth"), + ], + ], + ]), resolver: RecursiveResolver.from( PackageToWrapperCacheResolver.from( [ - StaticResolver.from([ - ...redirects, - ...wrappers, - ...packages, - ]), + StaticResolver.from([...redirects, ...wrappers, ...packages]), new ExtendableUriResolver(), ], new WrapperCache() ) - ) + ), }; ``` diff --git a/packages/js/uri-resolver-extensions/examples/quickstart.ts b/packages/js/uri-resolver-extensions/examples/quickstart.ts index fbd9d7b64c..9217914d49 100644 --- a/packages/js/uri-resolver-extensions/examples/quickstart.ts +++ b/packages/js/uri-resolver-extensions/examples/quickstart.ts @@ -1,4 +1,4 @@ -import { CoreClientConfig, Uri } from "@polywrap/core-js"; +import { CoreClientConfig, Uri, UriMap } from "@polywrap/core-js"; import { PackageResolver, PackageToWrapperCacheResolver, @@ -16,29 +16,25 @@ export function example(): CoreClientConfig { const packages: PackageResolver[] = []; // $start: quickstart-example const clientConfig: CoreClientConfig = { - interfaces: [ - { - interface: Uri.from("wrap://ens/uri-resolver.core.polywrap.eth"), - implementations: [ + interfaces: new UriMap([ + [ + Uri.from("wrap://ens/uri-resolver.core.polywrap.eth"), + [ Uri.from("wrap://ens/fs-resolver.polywrap.eth"), Uri.from("wrap://ens/ipfs-resolver.polywrap.eth"), - Uri.from("wrap://ens/ens-resolver.polywrap.eth") - ] - } - ], + Uri.from("wrap://ens/ens-resolver.polywrap.eth"), + ], + ], + ]), resolver: RecursiveResolver.from( PackageToWrapperCacheResolver.from( [ - StaticResolver.from([ - ...redirects, - ...wrappers, - ...packages, - ]), + StaticResolver.from([...redirects, ...wrappers, ...packages]), new ExtendableUriResolver(), ], new WrapperCache() ) - ) + ), }; // $end diff --git a/packages/js/uri-resolver-extensions/src/UriResolverWrapper.ts b/packages/js/uri-resolver-extensions/src/UriResolverWrapper.ts index b93d4152eb..41d892cbc6 100644 --- a/packages/js/uri-resolver-extensions/src/UriResolverWrapper.ts +++ b/packages/js/uri-resolver-extensions/src/UriResolverWrapper.ts @@ -126,7 +126,7 @@ const tryResolveUriWithImplementation = async ( authority: uri.authority, path: uri.path, }, - env: env?.env, + env: env, } );