Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove legacy redirects #1369

Merged
merged 18 commits into from
Nov 15, 2022
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
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Polywrap Origin (0.10.0-pre.3)
## Features
* [PR-1411](https://github.com/polywrap/toolchain/pull/1411) `@polywrap/client-config-builder-js`: The `ens-text-record-resolver` wrapper @ [`wrap://ipfs/QmfRCVA1MSAjUbrXXjya4xA9QHkbWeiKRsT7Um1cvrR7FY`](https://wrappers.io/v/ipfs/QmfRCVA1MSAjUbrXXjya4xA9QHkbWeiKRsT7Um1cvrR7FY) has been added to the default client config bundle. This resolver enables ENS, text-record based, WRAP URI resolution. The text-record's key must be prepended with the `wrap/...` identifier. For example, the URI `wrap://ens/domain.eth:foo` maps to `domain.eth`'s `wrap/foo` text record. The `wrap/foo` text-record's value must contain another valid WRAP URI. For examples, see [dev.polywrap.eth](https://app.ens.domains/name/dev.polywrap.eth/details).
* [PR-1369](https://github.com/polywrap/toolchain/pull/1369) `@polywrap/core-js`:
* `GetImplementationsOptions` now accepts an optional resolution context, to be used to handle infinite recursion when a resolver uses `getImplementations`
* `GetImplementationsOptions` now accepts an optional `applyResolution`. This can be used to apply URI resolution to interfaces.
* [PR-1236](https://github.com/polywrap/toolchain/pull/1236) `@polywrap/client-js`: Polywrap Client now re-exports the config builder and uri-resolvers (in addition to core) packages. This is done to improve dev exp and remove the need for users to import those package themselves.
* For users who do not need those packages and are using noDefaults there will be a separate PR that refactor core client functionality into a core-client package that does not depend on the config builder and uri-resolvers packages, but has no defaults.
* [PR-1236](https://github.com/polywrap/toolchain/pull/1236) `@polywrap/client-config-builder-js`:
Expand All @@ -14,7 +17,20 @@
* [PR-1236] `@polywrap/schema-bind`: In `plugin-ts` bindings, the `PluginModule` type is now imported fron `@polywrap/plugin-js` instead of `@polywrap/core-js`.
* [PR-1349](https://github.com/polywrap/toolchain/pull/1349) `polywrap` CLI: A `-l, --log-file [path]` option has been added to all commands. Its purpose is to configure a `Log file to save console output to`, useful in situations when the console log overflows.

## Breaking Changes
## Breaking Changes
* [PR-1369](https://github.com/polywrap/toolchain/pull/1369) `@polywrap/client-config-builder-js`:
* Calling `buildCoreConfig` no longer returns a `CoreClientConfig` with redirects since redirects are no longer a part of `CoreClientConfig`.
* [PR-1369](https://github.com/polywrap/toolchain/pull/1369) `@polywrap/uri-resolvers-js`:
* `LegacyRedirectsResolver` has been removed.
* [PR-1369](https://github.com/polywrap/toolchain/pull/1369) `@polywrap/core-js`:
* `redirects` are no longer a part of `CoreClientConfig`.
* `getRedirects` are no longer a part of `CoreClient`.
* `getUriResolver` on `CoreClient` has been renamed to `getResolver`.
* `getImplementations` returns a promise now.
* `GetImplementationsOptions` no longer accepts `applyRedirects`. This has been replaces with `applyResolution`.
* `applyRedirects` helper function has been replaced with `applyResolution`.
* [PR-1369](https://github.com/polywrap/toolchain/pull/1369) `@polywrap/client-js`:
* `PolywrapClient` config when using `noDefaults: true` no longer accepts `redirects` (Since redirects have been removed from `CoreClientConfig`).
* [PR-1367](https://github.com/polywrap/toolchain/pull/1367) `polywrap` CLI: The JS/TS module passed into the `--client-config` option has a new entrypoint signature.
* Instead of `getCustomConfig`, users should export the following `configure(builder: IClientConfigBuilder): IClientConfigBuilder`.
* `IClientConfigBuilder` can be imported from the `@polywrap/client-config-builder-js` package.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { BaseClientConfigBuilder } from "./BaseClientConfigBuilder";
import { CoreClientConfig, Uri, IUriResolver } from "@polywrap/core-js";
import {
IWrapperCache,
LegacyRedirectsResolver,
PackageToWrapperCacheResolver,
RecursiveResolver,
StaticResolver,
Expand All @@ -28,14 +27,13 @@ export class ClientConfigBuilder extends BaseClientConfigBuilder {
return {
envs: this.config.envs,
interfaces: this.config.interfaces,
redirects: this.config.redirects,
resolver:
this.resolver ??
RecursiveResolver.from(
PackageToWrapperCacheResolver.from(
[
new LegacyRedirectsResolver(),
StaticResolver.from([
...this.config.redirects,
...this.config.wrappers,
...this.config.packages,
]),
Expand Down
41 changes: 4 additions & 37 deletions packages/js/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ const config = {
// customize URI resolution
resolver: new RecursiveResolver(
new PackageToWrapperCacheResolver(wrapperCache, [
new LegacyRedirectsResolver(),
new LegacyPluginsResolver(),
new ExtendableUriResolver(),
])
),
Expand Down Expand Up @@ -119,7 +117,7 @@ constructor(config?: Partial<PolywrapClientConfig<string | Uri>>, options?: {
*
* @returns an immutable Polywrap client config
*/
getConfig(): PolywrapClientConfig<Uri>;
getConfig(): PolywrapCoreClientConfig<Uri>;
```

### setTracingEnabled
Expand All @@ -136,37 +134,6 @@ getConfig(): PolywrapClientConfig<Uri>;
setTracingEnabled(tracerConfig?: Partial<TracerConfig>): void;
```

### getRedirects
```ts
/**
* returns all uri redirects from the configuration used to instantiate the client
*
* @returns an array of uri redirects
*/
getRedirects(): readonly UriRedirect<Uri>[];
```

### getPlugins
```ts
/**
* returns all plugin registrations from the configuration used to instantiate the client
*
* @returns an array of plugin registrations
*/
getPlugins(): readonly PluginRegistration<Uri>[];
```

### getPluginByUri
```ts
/**
* returns a plugin package from the configuration used to instantiate the client
*
* @param uri - the uri used to register the plugin
* @returns a plugin package, or undefined if a plugin is not found at the given uri
*/
getPluginByUri<TUri extends Uri | string>(uri: TUri): PluginPackage<unknown> | undefined;
```

### getInterfaces
```ts
/**
Expand All @@ -187,14 +154,14 @@ getInterfaces(): readonly InterfaceImplementations<Uri>[];
getEnvs(): readonly Env<Uri>[];
```

### getUriResolver
### getResolver
```ts
/**
* returns the URI resolver from the configuration used to instantiate the client
*
* @returns an object that implements the IUriResolver interface
*/
getUriResolver(): IUriResolver<unknown>;
getResolver(): IUriResolver<unknown>;
```

### getEnvByUri
Expand Down Expand Up @@ -239,7 +206,7 @@ getFile<TUri extends Uri | string>(uri: TUri, options: GetFileOptions): Promise<
* from the configuration used to instantiate the client
*
* @param uri - a wrap URI
* @param options - { applyRedirects?: boolean }
* @param options - { applyResolution?: boolean }
* @returns a Result containing URI array if the request was successful
*/
getImplementations<TUri extends Uri | string>(uri: TUri, options?: GetImplementationsOptions): Result<TUri[], Error>;
Expand Down
33 changes: 9 additions & 24 deletions packages/js/client/src/PolywrapClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
SubscribeOptions,
Subscription,
Uri,
IUriRedirect,
createQueryDocument,
getImplementations,
parseQuery,
Expand Down Expand Up @@ -107,16 +106,6 @@ export class PolywrapClient implements CoreClient {
}
}

/**
* returns all uri redirects from the configuration used to instantiate the client
*
* @returns an array of uri redirects
*/
@Tracer.traceMethod("PolywrapClient: getRedirects")
public getRedirects(): readonly IUriRedirect<Uri>[] | undefined {
return this._config.redirects;
}

/**
* returns all plugin registrations from the configuration used to instantiate the client
*
Expand Down Expand Up @@ -154,7 +143,7 @@ export class PolywrapClient implements CoreClient {
* @returns an object that implements the IUriResolver interface
*/
@Tracer.traceMethod("PolywrapClient: getUriResolver")
public getUriResolver(): IUriResolver<unknown> {
public getResolver(): IUriResolver<unknown> {
return this._config.resolver;
}

Expand Down Expand Up @@ -225,21 +214,22 @@ export class PolywrapClient implements CoreClient {
* from the configuration used to instantiate the client
*
* @param uri - a wrap URI
* @param options - { applyRedirects?: boolean }
* @param options - { applyResolution?: boolean }
* @returns a Result containing URI array if the request was successful
*/
@Tracer.traceMethod("PolywrapClient: getImplementations")
public getImplementations<TUri extends Uri | string>(
public async getImplementations<TUri extends Uri | string>(
uri: TUri,
options: GetImplementationsOptions = {}
): Result<TUri[], Error> {
): Promise<Result<TUri[], Error>> {
const isUriTypeString = typeof uri === "string";
const applyRedirects = !!options.applyRedirects;
const applyResolution = !!options.applyResolution;

const getImplResult = getImplementations(
const getImplResult = await getImplementations(
Uri.from(uri),
this.getInterfaces() ?? [],
applyRedirects ? this.getRedirects() : undefined
applyResolution ? this : undefined,
applyResolution ? options.resolutionContext : undefined
);

if (!getImplResult.ok) {
Expand Down Expand Up @@ -606,7 +596,7 @@ export class PolywrapClient implements CoreClient {
): Promise<Result<UriPackageOrWrapper, unknown>> {
const uri = Uri.from(options.uri);

const uriResolver = this.getUriResolver();
const uriResolver = this.getResolver();

const resolutionContext =
options.resolutionContext ?? new UriResolutionContext();
Expand Down Expand Up @@ -733,11 +723,6 @@ export class PolywrapClient implements CoreClient {
config: PolywrapCoreClientConfig
): PolywrapCoreClientConfig<Uri> {
return {
redirects:
config?.redirects?.map((x) => ({
from: Uri.from(x.from),
to: Uri.from(x.to),
})) ?? [],
interfaces:
config?.interfaces?.map((x) => ({
interface: Uri.from(x.interface),
Expand Down
50 changes: 24 additions & 26 deletions packages/js/client/src/__tests__/core/interface-impls.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { mockPluginRegistration } from "../helpers/mockPluginRegistration";
jest.setTimeout(200000);

describe("interface-impls", () => {
it("should register interface implementations successfully", () => {
it("should register interface implementations successfully", async () => {
const interfaceUri = "wrap://ens/some-interface1.eth";
const implementation1Uri = "wrap://ens/some-implementation1.eth";
const implementation2Uri = "wrap://ens/some-implementation2.eth";
Expand Down Expand Up @@ -39,8 +39,8 @@ describe("interface-impls", () => {
},
]);

const implementations = client.getImplementations(interfaceUri, {
applyRedirects: false,
const implementations = await client.getImplementations(interfaceUri, {
applyResolution: false,
});

if (!implementations.ok) fail(implementations.error);
Expand All @@ -62,7 +62,7 @@ describe("interface-impls", () => {

const client = new PolywrapClient(
{
redirects: [
resolver: UriResolver.from([
{
from: interface1Uri,
to: interface2Uri,
Expand All @@ -75,8 +75,6 @@ describe("interface-impls", () => {
from: implementation2Uri,
to: implementation3Uri,
},
],
resolver: UriResolver.from([
mockPluginRegistration(implementation4Uri),
]),
interfaces: [
Expand All @@ -99,14 +97,14 @@ describe("interface-impls", () => {
}
);

const implementations1 = client.getImplementations(interface1Uri, {
applyRedirects: true,
const implementations1 = await client.getImplementations(interface1Uri, {
applyResolution: true,
});
const implementations2 = client.getImplementations(interface2Uri, {
applyRedirects: true,
const implementations2 = await client.getImplementations(interface2Uri, {
applyResolution: true,
});
const implementations3 = client.getImplementations(interface3Uri, {
applyRedirects: true,
const implementations3 = await client.getImplementations(interface3Uri, {
applyResolution: true,
});

if (!implementations1.ok) fail(implementations1.error);
Expand Down Expand Up @@ -196,7 +194,7 @@ describe("interface-impls", () => {
]);
});

test("get implementations - do not return plugins that are not explicitly registered", () => {
test("get implementations - do not return plugins that are not explicitly registered", async () => {
const interfaceUri = "wrap://ens/some-interface.eth";

const implementation1Uri = "wrap://ens/some-implementation1.eth";
Expand All @@ -219,9 +217,9 @@ describe("interface-impls", () => {
}
);

const getImplementationsResult = client.getImplementations(
const getImplementationsResult = await client.getImplementations(
new Uri(interfaceUri),
{ applyRedirects: true }
{ applyResolution: true }
);

if (!getImplementationsResult.ok) fail(getImplementationsResult.error);
Expand All @@ -230,7 +228,7 @@ describe("interface-impls", () => {
]);
});

test("get implementations - return implementations for plugins which don't have interface stated in manifest", () => {
test("get implementations - return implementations for plugins which don't have interface stated in manifest", async () => {
const interfaceUri = "wrap://ens/some-interface.eth";

const implementation1Uri = "wrap://ens/some-implementation1.eth";
Expand All @@ -251,9 +249,9 @@ describe("interface-impls", () => {
{ noDefaults: true }
);

const getImplementationsResult = client.getImplementations(
const getImplementationsResult = await client.getImplementations(
new Uri(interfaceUri),
{ applyRedirects: true }
{ applyResolution: true }
);

if (!getImplementationsResult.ok) fail(getImplementationsResult.error);
Expand Down Expand Up @@ -289,26 +287,26 @@ describe("interface-impls", () => {
],
});

let result = client.getImplementations(oldInterfaceUri, {
applyRedirects: false,
let result = await client.getImplementations(oldInterfaceUri, {
applyResolution: false,
});
if (!result.ok) fail(result.error);
expect(result.value).toEqual([implementation1Uri]);

result = client.getImplementations(oldInterfaceUri, {
applyRedirects: true,
result = await client.getImplementations(oldInterfaceUri, {
applyResolution: true,
});
if (!result.ok) fail(result.error);
expect(result.value).toEqual([implementation1Uri, implementation2Uri]);

let result2 = client.getImplementations(new Uri(oldInterfaceUri), {
applyRedirects: false,
let result2 = await client.getImplementations(new Uri(oldInterfaceUri), {
applyResolution: false,
});
if (!result2.ok) fail(result2.error);
expect(result2.value).toEqual([new Uri(implementation1Uri)]);

result2 = client.getImplementations(new Uri(oldInterfaceUri), {
applyRedirects: true,
result2 = await client.getImplementations(new Uri(oldInterfaceUri), {
applyResolution: true,
});
if (!result2.ok) fail(result2.error);
expect(result2.value).toEqual([
Expand Down
Loading