Skip to content

Commit

Permalink
change getPluginConfig to getPlugin in polywrap client
Browse files Browse the repository at this point in the history
  • Loading branch information
pileks committed Sep 8, 2022
1 parent 64486aa commit 20381d2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
17 changes: 9 additions & 8 deletions packages/js/client/src/PolywrapClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -169,14 +170,14 @@ export class PolywrapClient implements Client {
);
}

@Tracer.traceMethod("PolywrapClient: getPluginConfig")
public async getPluginConfig<TUri extends Uri | string>(
@Tracer.traceMethod("PolywrapClient: getPlugin")
public async getPlugin<TUri extends Uri | string>(
uri: TUri,
options: GetPluginConfigOptions = {}
): Promise<unknown> {
return this.getPlugins(options)
.find((x) => Uri.equals(x.uri, this._toUri(uri)))
?.plugin.factory().config;
options: GetPluginOptions = {}
): Promise<PluginPackage<unknown> | undefined> {
return this.getPlugins(options).find((x) =>
Uri.equals(x.uri, this._toUri(uri))
)?.plugin;
}

@Tracer.traceMethod("PolywrapClient: getManifest")
Expand Down
31 changes: 14 additions & 17 deletions packages/js/client/src/__tests__/core/plugin-wrapper.spec.ts
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down Expand Up @@ -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,
};
};
Expand Down Expand Up @@ -176,12 +176,9 @@ describe("plugin-wrapper", () => {
class SamplePluginModule extends PluginModule<SamplePluginConfig> {}
const config: SamplePluginConfig = { bar: "test" };

const pluginPackage = {
const pluginPackage = <PluginPackage<SamplePluginConfig>>{
factory: () => new SamplePluginModule(config),
manifest: {
schema: "",
implements: [],
},
manifest: {},
};

const client = new PolywrapClient(
Expand All @@ -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");
});
});
2 changes: 1 addition & 1 deletion packages/js/core/src/types/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 20381d2

Please sign in to comment.