diff --git a/libs/rpc/src/client/index.test.ts b/libs/rpc/src/client/index.test.ts index 6d89223a..22f9e44e 100644 --- a/libs/rpc/src/client/index.test.ts +++ b/libs/rpc/src/client/index.test.ts @@ -3,8 +3,8 @@ import { createPrimClient } from "./index" type ExampleModule = { hello: (name?: string) => string; goodbye: () => string } -test("client", async () => { - const client = createPrimClient({ +test("static import", async () => { + const client = createPrimClient<() => Promise>({ module: { hello(name: string) { return ["Hello", name].filter(given => given).join(" ") @@ -16,3 +16,20 @@ test("client", async () => { // FIXME: not implemented yet await expect(client.goodbye()).rejects.toBe("not implemented yet") }) + +test("dynamic import", async () => { + const client = createPrimClient({ + module: new Promise>(r => + r({ + // goodbye() { return "Bye!" }, + hello(name: string) { + return ["Hello", name].filter(given => given).join(" ") + }, + }) + ), + }) + // not async since module was provided locally + await expect(client.hello()).resolves.toBe("Hello") + // FIXME: not implemented yet + await expect(client.goodbye()).rejects.toBe("not implemented yet") +}) diff --git a/libs/rpc/src/interfaces.ts b/libs/rpc/src/interfaces.ts index 377fefa0..23f24b1b 100644 --- a/libs/rpc/src/interfaces.ts +++ b/libs/rpc/src/interfaces.ts @@ -276,7 +276,11 @@ export interface PrimOptions>> | null + module?: + | (() => Promise>>>) + | Promise>>> + | PartialDeep>> + | null /** * Provide the server URL where Prim is being used. This will be provided to the HTTP client as the endpoint * parameter.