@polywrap/core-client-js
The Polywrap JavaScript core client invokes wrapper functions. It's designed to run in any environment that can execute JavaScript (think websites, node scripts, etc.). It has TypeScript support.
Installation
npm install --save @polywrap/core-client-js
Usage
Instantiate
Use the @polywrap/client-config-builder-js
package to build a CoreClientConfig for your project, then use the PolywrapCoreClient constructor to instantiate the client with your config.
const config = new PolywrapClientConfigBuilder().addDefaults().build();
const client = new PolywrapCoreClient(config);
Invoke
Invoke a wrapper.
const result = await client.invoke({
uri: Uri.from("wrapscan.io/polywrap/logging@1.0"),
method: "info",
args: {
message: "Hello World!",
},
});
if (!result.ok) throw result.error;
const value = result.value;
Reference
PolywrapCoreClient
Constructor
constructor(private _config: CoreClientConfig)
getConfig
public getConfig(): CoreClientConfig
getInterfaces
public getInterfaces(): ReadonlyUriMap<readonly Uri[]> | undefined
getEnvs
public getEnvs(): ReadonlyUriMap<WrapperEnv> | undefined
getResolver
public getResolver(): IUriResolver<unknown>
getEnvByUri
public getEnvByUri(uri: Uri): WrapperEnv | undefined
getManifest
public async getManifest(
uri: Uri
): Promise<Result<WrapManifest, WrapError>>
getFile
public async getFile(
uri: Uri,
options: GetFileOptions
): Promise<Result<string | Uint8Array, WrapError>>
getImplementations
public async getImplementations(
uri: Uri,
options: GetImplementationsOptions = {}
): Promise<Result<Uri[], WrapError>>
invokeWrapper
public async invokeWrapper<TData = unknown>(
options: InvokerOptions & { wrapper: Wrapper }
): Promise<InvokeResult<TData>>
invoke
public async invoke<TData = unknown>(
options: InvokerOptions
): Promise<InvokeResult<TData>>
tryResolveUri
public async tryResolveUri(
options: TryResolveUriOptions
): Promise<Result<UriPackageOrWrapper, unknown>>
loadWrapper
public async loadWrapper(
uri: Uri,
resolutionContext?: IUriResolutionContext,
options?: DeserializeManifestOptions
): Promise<Result<Wrapper, WrapError>>
Development
The Polywrap JavaScript client is open-source. It lives within the Polywrap JavaScript Client repository. Contributions from the community are welcomed!
Build
nvm use && yarn install && yarn build
Test
yarn test
``