From 20381d2aeac21de5f7f1d543e09d8641b4b76929 Mon Sep 17 00:00:00 2001 From: Pileks Date: Thu, 8 Sep 2022 17:54:00 +0200 Subject: [PATCH] change getPluginConfig to getPlugin in polywrap client --- packages/js/client/src/PolywrapClient.ts | 17 +++++----- .../src/__tests__/core/plugin-wrapper.spec.ts | 31 +++++++++---------- packages/js/core/src/types/Client.ts | 2 +- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/packages/js/client/src/PolywrapClient.ts b/packages/js/client/src/PolywrapClient.ts index a828f95d3c..e22b40f366 100644 --- a/packages/js/client/src/PolywrapClient.ts +++ b/packages/js/client/src/PolywrapClient.ts @@ -38,7 +38,8 @@ import { GetManifestOptions, SimpleCache, executeMaybeAsyncFunction, - GetPluginConfigOptions, + GetPluginOptions, + PluginPackage, } from "@polywrap/core-js"; import { msgpackEncode, msgpackDecode } from "@polywrap/msgpack-js"; import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; @@ -169,14 +170,14 @@ export class PolywrapClient implements Client { ); } - @Tracer.traceMethod("PolywrapClient: getPluginConfig") - public async getPluginConfig( + @Tracer.traceMethod("PolywrapClient: getPlugin") + public async getPlugin( uri: TUri, - options: GetPluginConfigOptions = {} - ): Promise { - return this.getPlugins(options) - .find((x) => Uri.equals(x.uri, this._toUri(uri))) - ?.plugin.factory().config; + options: GetPluginOptions = {} + ): Promise | undefined> { + return this.getPlugins(options).find((x) => + Uri.equals(x.uri, this._toUri(uri)) + )?.plugin; } @Tracer.traceMethod("PolywrapClient: getManifest") 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 03ab30ea43..e291488a5d 100644 --- a/packages/js/client/src/__tests__/core/plugin-wrapper.spec.ts +++ b/packages/js/client/src/__tests__/core/plugin-wrapper.spec.ts @@ -1,8 +1,7 @@ -import { PolywrapClient, PluginModule } from "../.."; +import { PolywrapClient, PluginModule, PluginPackage } from "../.."; import { getClient } from "../utils/getClient"; import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; - jest.setTimeout(200000); const defaultPlugins = [ @@ -39,9 +38,10 @@ describe("plugin-wrapper", () => { } return { - factory: () => new MockMapPlugin({ - map: new Map().set("a", 1).set("b", 2) - }), + factory: () => + new MockMapPlugin({ + map: new Map().set("a", 1).set("b", 2), + }), manifest: {} as WrapManifest, }; }; @@ -176,12 +176,9 @@ describe("plugin-wrapper", () => { class SamplePluginModule extends PluginModule {} const config: SamplePluginConfig = { bar: "test" }; - const pluginPackage = { + const pluginPackage = >{ factory: () => new SamplePluginModule(config), - manifest: { - schema: "", - implements: [], - }, + manifest: {}, }; const client = new PolywrapClient( @@ -196,17 +193,17 @@ describe("plugin-wrapper", () => { { noDefaults: true } ); - const pluginConfig = await client.getPluginConfig( + const plugin = await client.getPlugin( "wrap://ens/some.plugin.eth" ); - expect(pluginConfig).toStrictEqual(config); + 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") - expect(manifest.type).toEqual("plugin") - expect(manifest.name).toEqual("Ipfs") - }) + const client = await getClient(); + const manifest = await client.getManifest("ens/ipfs.polywrap.eth"); + expect(manifest.type).toEqual("plugin"); + expect(manifest.name).toEqual("Ipfs"); + }); }); diff --git a/packages/js/core/src/types/Client.ts b/packages/js/core/src/types/Client.ts index 00ff12263e..f53fdbd56f 100644 --- a/packages/js/core/src/types/Client.ts +++ b/packages/js/core/src/types/Client.ts @@ -41,7 +41,7 @@ export interface GetManifestOptions extends Contextualized { noValidate?: boolean; } -export type GetPluginConfigOptions = Contextualized; +export type GetPluginOptions = Contextualized; export interface GetFileOptions extends Contextualized { path: string;