Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WRAP_TEST_HARNESS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module-trait-rs
master
37 changes: 19 additions & 18 deletions packages/js/client-config-builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ Add client configuration with [add](#add), or flexibly mix and match builder [co
builder
.addPackage("wrap://plugin/package", httpPlugin({}))
.removePackage("wrap://plugin/package")
.addPackages(
{
"wrap://plugin/http": httpPlugin({}),
"wrap://plugin/filesystem": fileSystemPlugin({}),
}
);
.addPackages({
"wrap://plugin/http": httpPlugin({}),
"wrap://plugin/filesystem": fileSystemPlugin({}),
});
```

You can add the entire [default client configuration bundle](#bundle--defaultconfig) at once with [addDefaults](#adddefaults)
Expand All @@ -58,7 +56,7 @@ Finally, build a ClientConfig or CoreClientConfig to pass to the PolywrapClient

// build with a custom cache
coreClientConfig = builder.build({
wrapperCache: new WrapperCache(),
resolutionResultCache: new ResolutionResultCache(),
});

// or build with a custom resolver
Expand Down Expand Up @@ -90,25 +88,28 @@ A complete example using all or most of the available methods.

// add and remove wrappers
builder
.addWrapper("wrap://ens/wrapper.eth", await WasmWrapper.from(
new Uint8Array([1, 2, 3]),
new Uint8Array([1, 2, 3])
))
.addWrapper(
"wrap://ens/wrapper.eth",
await WasmWrapper.from(
new Uint8Array([1, 2, 3]),
new Uint8Array([1, 2, 3])
)
)
.removeWrapper("wrap://ens/wrapper.eth")
.addWrappers({
"wrap://ens/wrapper.eth": await WasmWrapper.from(
new Uint8Array([1, 2, 3]),
new Uint8Array([1, 2, 3])
)}
);
new Uint8Array([1, 2, 3]),
new Uint8Array([1, 2, 3])
),
});

// add and remove wrap packages
builder
.addPackage("wrap://plugin/package", httpPlugin({}))
.removePackage("wrap://plugin/package")
.addPackages({
"wrap://plugin/package": httpPlugin({})
})
"wrap://plugin/package": httpPlugin({}),
});

// add and remove Envs
builder
Expand Down Expand Up @@ -140,7 +141,7 @@ A complete example using all or most of the available methods.
.addRedirect("wrap://ens/from.eth", "wrap://ens/to.eth")
.removeRedirect("wrap://ens/from.eth")
.addRedirects({
"wrap://ens/from.eth": "wrap://ens/to.eth",
"wrap://ens/from.eth": "wrap://ens/to.eth",
});

// add resolvers
Expand Down
46 changes: 24 additions & 22 deletions packages/js/client-config-builder/examples/quickstart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { ClientConfigBuilder } from "../build";
// eslint-disable-next-line import/no-extraneous-dependencies
import { WasmWrapper } from "@polywrap/wasm-js";
import { httpPlugin } from "@polywrap/http-plugin-js";
import { RecursiveResolver, WrapperCache } from "@polywrap/uri-resolvers-js";
import {
RecursiveResolver,
ResolutionResultCache,
} from "@polywrap/uri-resolvers-js";
import { fileSystemPlugin } from "@polywrap/file-system-plugin-js";
import { CoreClientConfig } from "@polywrap/core-js";

Expand Down Expand Up @@ -34,12 +37,10 @@ export function configure(): ClientConfigBuilder {
builder
.addPackage("wrap://plugin/package", httpPlugin({}))
.removePackage("wrap://plugin/package")
.addPackages(
{
"wrap://plugin/http": httpPlugin({}),
"wrap://plugin/filesystem": fileSystemPlugin({}),
}
);
.addPackages({
"wrap://plugin/http": httpPlugin({}),
"wrap://plugin/filesystem": fileSystemPlugin({}),
});
// $end

// $start: quickstart-addDefaults
Expand All @@ -49,9 +50,7 @@ export function configure(): ClientConfigBuilder {
return builder;
}

export function build():
| ClientConfigBuilder
| CoreClientConfig {
export function build(): ClientConfigBuilder | CoreClientConfig {
const builder = new ClientConfigBuilder();

// $start: quickstart-build
Expand All @@ -60,7 +59,7 @@ export function build():

// build with a custom cache
coreClientConfig = builder.build({
wrapperCache: new WrapperCache(),
resolutionResultCache: new ResolutionResultCache(),
});

// or build with a custom resolver
Expand Down Expand Up @@ -92,25 +91,28 @@ export async function example(): Promise<CoreClientConfig> {

// add and remove wrappers
builder
.addWrapper("wrap://ens/wrapper.eth", await WasmWrapper.from(
new Uint8Array([1, 2, 3]),
new Uint8Array([1, 2, 3])
))
.addWrapper(
"wrap://ens/wrapper.eth",
await WasmWrapper.from(
new Uint8Array([1, 2, 3]),
new Uint8Array([1, 2, 3])
)
)
.removeWrapper("wrap://ens/wrapper.eth")
.addWrappers({
"wrap://ens/wrapper.eth": await WasmWrapper.from(
new Uint8Array([1, 2, 3]),
new Uint8Array([1, 2, 3])
)}
);
new Uint8Array([1, 2, 3]),
new Uint8Array([1, 2, 3])
),
});

// add and remove wrap packages
builder
.addPackage("wrap://plugin/package", httpPlugin({}))
.removePackage("wrap://plugin/package")
.addPackages({
"wrap://plugin/package": httpPlugin({})
})
"wrap://plugin/package": httpPlugin({}),
});

// add and remove Envs
builder
Expand Down Expand Up @@ -142,7 +144,7 @@ export async function example(): Promise<CoreClientConfig> {
.addRedirect("wrap://ens/from.eth", "wrap://ens/to.eth")
.removeRedirect("wrap://ens/from.eth")
.addRedirects({
"wrap://ens/from.eth": "wrap://ens/to.eth",
"wrap://ens/from.eth": "wrap://ens/to.eth",
});

// add resolvers
Expand Down
14 changes: 8 additions & 6 deletions packages/js/client-config-builder/src/ClientConfigBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
import {
RecursiveResolver,
StaticResolver,
WrapperCache,
WrapperCacheResolver,
ResolutionResultCache,
ResolutionResultCacheResolver,
PackageToWrapperResolver,
RequestSynchronizerResolver,
} from "@polywrap/uri-resolvers-js";
Expand All @@ -38,16 +38,18 @@ export class ClientConfigBuilder extends BaseClientConfigBuilder {
build(options?: BuildOptions): CoreClientConfig {
const resolver =
options && "resolver" in options ? options.resolver : undefined;
const wrapperCache =
options && "wrapperCache" in options ? options.wrapperCache : undefined;
const resolutionResultCache =
options && "resolutionResultCache" in options
? options.resolutionResultCache
: undefined;
return {
envs: this.buildEnvs(),
interfaces: this.buildInterfaces(),
resolver:
resolver ??
RecursiveResolver.from(
RequestSynchronizerResolver.from(
WrapperCacheResolver.from(
ResolutionResultCacheResolver.from(
PackageToWrapperResolver.from([
StaticResolver.from([
...this.buildRedirects(),
Expand All @@ -57,7 +59,7 @@ export class ClientConfigBuilder extends BaseClientConfigBuilder {
...this._config.resolvers,
new ExtendableUriResolver(),
]),
wrapperCache ?? new WrapperCache()
resolutionResultCache ?? new ResolutionResultCache()
)
)
),
Expand Down
4 changes: 2 additions & 2 deletions packages/js/client-config-builder/src/types/BuildOptions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { IWrapperCache } from "@polywrap/uri-resolvers-js";
import { IResolutionResultCache } from "@polywrap/uri-resolvers-js";
import { IUriResolver } from "@polywrap/core-js";

export type BuildOptions =
| {
wrapperCache: IWrapperCache;
resolutionResultCache: IResolutionResultCache;
}
| {
resolver: IUriResolver<unknown>;
Expand Down
Loading