Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
eb57773
added loadWrapper to core client interface
nerfZael Apr 14, 2023
99a96c7
createSubContext now uses a new map object and does not include history
nerfZael Apr 14, 2023
9154ae5
wasm wrapper properly passes resolution context on subinvokes - nerfzael
nerfZael Apr 14, 2023
5fcac06
UriResolverWrapper properly passes resolution when invoking resolver …
nerfZael Apr 14, 2023
87a7c49
updated sanity test case to work with new resolution context passing
nerfZael Apr 14, 2023
308f7ee
removed resolution context step tracking from wasm imports and added …
nerfZael Apr 17, 2023
d5836aa
removed unused method
nerfZael Apr 17, 2023
2e06bd6
refactored UriResolverWrapper to use the new invoke resolution history
nerfZael Apr 17, 2023
2ef5f1c
Merge remote-tracking branch 'origin/origin-dev' into nerfzael-subinv…
nerfZael Apr 19, 2023
abf9141
tracking actual resolver extension result
nerfZael Apr 19, 2023
4085b99
tracking final uri from loadWrapper
nerfZael Apr 19, 2023
d12cc15
updated history test cases
nerfZael Apr 19, 2023
a3da65c
moved UriResolutionResult to core-js
nerfZael Apr 19, 2023
c41cc73
built docs
nerfZael Apr 20, 2023
9883dc8
removed unused loadWrapper
nerfZael Apr 20, 2023
fb38d97
fixed up docs
nerfZael Apr 20, 2023
7120d48
removed unused test resolver
nerfZael Apr 20, 2023
4f321f7
added subinvoke resolver extension tests
nerfZael Apr 20, 2023
6938164
resolution context is now available to plugins
nerfZael Apr 20, 2023
99de6f2
lint fix
nerfZael Apr 20, 2023
61b28d2
calling wasm wrapper resolver from plugin resolver instead of plugin
nerfZael Apr 20, 2023
fd145c2
removed unused function
nerfZael Apr 21, 2023
a1b6832
removing file path so that it works across different platforms
nerfZael Apr 21, 2023
cb42149
using embeded abi
nerfZael Apr 24, 2023
8f75f7e
removed quotes
nerfZael Apr 24, 2023
4eac351
overriding the plugin client instead of passing resolution context as…
nerfZael Apr 25, 2023
47fb79e
lint fix
nerfZael Apr 25, 2023
2681fb3
chore: fix CI
dOrgJelli Apr 25, 2023
16b5796
chore: fix CI
dOrgJelli Apr 25, 2023
318627a
Merge branch 'origin-dev' into nerfzael-subinvoke-resolution-context
dOrgJelli Apr 25, 2023
d7d3537
chore: debugging CI
dOrgJelli Apr 25, 2023
848c1be
chore: remove history check from client uri-resolution test
dOrgJelli Apr 26, 2023
f57a7c9
chore: revert workflow changes
dOrgJelli Apr 26, 2023
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
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
import { GetPathToTestWrappers } from "@polywrap/test-cases";
import {
Uri,
IUriResolutionStep,
UriPackageOrWrapper,
UriResolutionContext,
buildCleanUriHistory,
UriResolutionResult,
} from "@polywrap/core-js";
import { UriResolutionResult } from "@polywrap/uri-resolvers-js";
import fs from "fs";
import { Result } from "@polywrap/result";
import { PolywrapClient, ClientConfigBuilder } from "../../../";
import { PolywrapClient, ClientConfigBuilder } from "../../";

jest.setTimeout(200000);

const expectResultWithHistory = async (
const expectResolutionResult = async (
receivedResult: Result<UriPackageOrWrapper, unknown>,
expectedResult: Result<UriPackageOrWrapper, unknown>,
uriHistory: IUriResolutionStep<unknown>[],
historyFileName: string
): Promise<void> => {
if (historyFileName && uriHistory) {
await expectHistory(uriHistory, historyFileName);
}

expect(expectedResult.ok).toEqual(receivedResult.ok);

Expand All @@ -36,34 +27,6 @@ const expectResultWithHistory = async (
}
};

const expectHistory = async (
receivedHistory: IUriResolutionStep<unknown>[] | undefined,
historyFileName: string
): Promise<void> => {
if (!receivedHistory) {
fail("History is not defined");
}

let expectedCleanHistory = await fs.promises.readFile(
`${__dirname}/histories/${historyFileName}.json`,
"utf-8"
);

const receivedCleanHistory = replaceAll(
JSON.stringify(buildCleanUriHistory(receivedHistory), null, 2),
`${GetPathToTestWrappers()}`,
"$root-wrapper-dir"
);

expect(receivedCleanHistory).toEqual(
JSON.stringify(JSON.parse(expectedCleanHistory), null, 2)
);
};

function replaceAll(str: string, strToReplace: string, replaceStr: string) {
return str.replace(new RegExp(strToReplace, "g"), replaceStr);
}

describe("URI resolution", () => {
it("sanity", async () => {
const uri = new Uri("ens/wraps.eth:uri-resolver-ext@1.1.0");
Expand All @@ -78,14 +41,12 @@ describe("URI resolution", () => {
);

if (expectResult.ok) {
expectResult.value.type = "wrapper"
expectResult.value.type = "wrapper";
}

await expectResultWithHistory(
await expectResolutionResult(
result,
expectResult,
resolutionContext.getHistory(),
"sanity"
);
});

Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ Invoke a wrapper.

## Development

The Polywrap JavaScript client is open-source. It lives within the [Polywrap JavaScript Client repo](https://github.com/polywrap/javascript-client). Contributions from the community are welcomed!
The Polywrap JavaScript client is open-source. It lives within the [Polywrap JavaScript Client repository](https://github.com/polywrap/javascript-client). Contributions from the community are welcomed!

### Build
```bash
Expand Down
45 changes: 38 additions & 7 deletions packages/core-client/src/PolywrapCoreClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
WrapperEnv,
ReadonlyUriMap,
UriMap,
UriResolutionResult,
} from "@polywrap/core-js";
import { msgpackEncode, msgpackDecode } from "@polywrap/msgpack-js";
import {
Expand Down Expand Up @@ -274,29 +275,59 @@ export class PolywrapCoreClient implements CoreClient {
const resolutionContext =
options.resolutionContext ?? new UriResolutionContext();

const loadWrapperContext = resolutionContext.createSubContext();

const loadWrapperResult = await this.loadWrapper(
typedOptions.uri,
resolutionContext
loadWrapperContext
);

if (!loadWrapperResult.ok) {
resolutionContext.trackStep({
sourceUri: typedOptions.uri,
result: UriResolutionResult.err(loadWrapperResult.error),
description: `Client.loadWrapper`,
subHistory: loadWrapperContext.getHistory(),
});

return loadWrapperResult;
}

let resolutionPath = loadWrapperContext.getResolutionPath();
resolutionPath =
resolutionPath.length > 0 ? resolutionPath : [typedOptions.uri];

const finalUri = resolutionPath[resolutionPath.length - 1];

const wrapper = loadWrapperResult.value;

const resolutionPath = resolutionContext.getResolutionPath();
resolutionContext.trackStep({
sourceUri: typedOptions.uri,
result: UriResolutionResult.ok(finalUri, loadWrapperResult.value),
description: `Client.loadWrapper`,
subHistory: loadWrapperContext.getHistory(),
});

const env = getEnvFromUriHistory(
resolutionPath.length > 0 ? resolutionPath : [typedOptions.uri],
this
);
const env = options.env ?? getEnvFromUriHistory(resolutionPath, this);

const invokeContext = resolutionContext.createSubContext();

const invokeResult = await this.invokeWrapper<TData>({
env: env,
...typedOptions,
env: env,
resolutionContext: invokeContext,
wrapper,
});

resolutionContext.trackStep({
sourceUri: finalUri,
result: invokeResult.ok
? UriResolutionResult.ok(finalUri)
: ResultErr(invokeResult.error),
description: `Client.invokeWrapper`,
subHistory: invokeContext.getHistory(),
});

if (!invokeResult.ok) {
return invokeResult;
}
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/uri-resolution/UriResolutionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export class UriResolutionContext implements IUriResolutionContext {
}

createSubContext(): IUriResolutionContext {
return new UriResolutionContext(this._resolvingUriMap, this._history);
const map = new Map<string, boolean>();
// Copy the resolvingUriMap to the new map, so that changes to the new map don't affect the old map
for (const key of this._resolvingUriMap.keys()) {
this._resolvingUriMap.get(key) && map.set(key, true);
}
return new UriResolutionContext(map, []);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {
UriPackageOrWrapper,
IUriResolutionStep,
Uri,
IWrapPackage,
Wrapper,
} from "@polywrap/core-js";
import { Uri, IWrapPackage, Wrapper } from "../types";
import { IUriResolutionStep } from "./IUriResolutionStep";
import { UriPackageOrWrapper } from "./UriPackageOrWrapper";

import { Result, ResultOk, ResultErr } from "@polywrap/result";

// $start: UriResolutionResult
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/uri-resolution/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./IUriResolver";
export * from "./UriPackageOrWrapper";
export * from "./IUriResolutionContext";
export * from "./UriResolutionContext";
export * from "./UriResolutionResult";
3 changes: 2 additions & 1 deletion packages/plugin/src/PluginWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PluginModule } from "./PluginModule";
import { getErrorSource } from "./utils/getErrorSource";
import { ResolutionContextOverrideClient } from "./ResolutionContextOverrideClient";

import {
Wrapper,
Expand Down Expand Up @@ -84,7 +85,7 @@ export class PluginWrapper implements Wrapper {
const result = await this._module._wrap_invoke(
method,
jsArgs,
client,
new ResolutionContextOverrideClient(client, options.resolutionContext),
options.env || {}
);

Expand Down
Loading