Skip to content

Commit f23c36e

Browse files
committed
added snippets to core client readme intro
1 parent 32350d8 commit f23c36e

6 files changed

Lines changed: 81 additions & 125 deletions

File tree

packages/js/core-client/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/examples/**/*.d.ts
2+
/examples/**/*.js
3+
/examples/**/*.js.map

packages/js/core-client/README.md

Lines changed: 18 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,71 +15,32 @@ npm install --save @polywrap/core-client-js
1515

1616
## Usage
1717

18-
### Instantiate the client
18+
### Instantiate
19+
20+
Use the `@polywrap/client-config-builder-js` package to build a CoreClientConfig for your project, then use the PolywrapCoreClient [constructor](#constructor) to instantiate the client with your config.
21+
1922
```ts
20-
import { PolywrapCoreClient } from "@polywrap/core-client-js";
23+
const config = new ClientConfigBuilder().addDefaults().buildCoreConfig();
2124

22-
const config = { ... };
23-
const client = new PolywrapCoreClient(config);
25+
const client = new PolywrapCoreClient(config);
2426
```
2527

26-
### Invoke a wrapper
28+
### Invoke
29+
30+
Invoke a wrapper.
2731

2832
```ts
29-
await client.invoke({
30-
uri: "ens/helloworld.dev.polywrap.eth",
31-
method: "logMessage",
32-
args: {
33-
message: "Hello World!"
34-
}
35-
});
36-
```
33+
const result = await client.invoke({
34+
uri: "ens/helloworld.dev.polywrap.eth",
35+
method: "logMessage",
36+
args: {
37+
message: "Hello World!"
38+
}
39+
});
3740

38-
### Configure the core client
41+
if (!result.ok) throw result.error;
3942

40-
```ts
41-
const config = {
42-
// declare interface implementations
43-
interfaces: [
44-
{
45-
interface: "wrap://ens/uri-resolver.core.polywrap.eth",
46-
implementations: [
47-
"wrap://ens/ipfs-resolver.polywrap.eth",
48-
],
49-
},
50-
],
51-
// set environmental variables for a wrapper
52-
envs: [
53-
{
54-
uri: "wrap://ens/ipfs.polywrap.eth",
55-
env: {
56-
provider: "https://ipfs.wrappers.io",
57-
},
58-
},
59-
],
60-
// customize URI resolution by adding redirects and embedded wrappers/packages
61-
resolver:
62-
RecursiveResolver.from(
63-
PackageToWrapperCacheResolver.from(
64-
[
65-
StaticResolver.from([
66-
...redirects,
67-
...wrappers,
68-
...packages,
69-
]),
70-
...this.config.resolvers,
71-
new ExtendableUriResolver(),
72-
],
73-
new WrapperCache()
74-
)
75-
),
76-
// tracer configuration - see @polywrap/tracing-js package
77-
tracerConfig: { ... },
78-
};
79-
```
80-
```ts
81-
// create a client by modifying the default configuration bundle
82-
const client = new PolywrapCoreClient(config);
43+
const value = result.value;
8344
```
8445

8546
# Reference
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { PolywrapCoreClient } from "../build";
2+
import { ClientConfigBuilder } from "@polywrap/client-config-builder-js";
3+
4+
export function instantiate(): PolywrapCoreClient {
5+
// $start: quickstart-instantiate
6+
const config = new ClientConfigBuilder().addDefaults().buildCoreConfig();
7+
8+
const client = new PolywrapCoreClient(config);
9+
// $end
10+
11+
return client;
12+
}
13+
14+
export async function invoke(): Promise<any> {
15+
const config = new ClientConfigBuilder().addDefaults().buildCoreConfig();
16+
17+
const client = new PolywrapCoreClient(config);
18+
19+
// $start: quickstart-invoke
20+
const result = await client.invoke({
21+
uri: "ens/helloworld.dev.polywrap.eth",
22+
method: "logMessage",
23+
args: {
24+
message: "Hello World!"
25+
}
26+
});
27+
28+
if (!result.ok) throw result.error;
29+
30+
const value = result.value;
31+
// $end
32+
return value;
33+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": [
4+
"./**/*.ts"
5+
],
6+
}

packages/js/core-client/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
"build"
1313
],
1414
"scripts": {
15-
"build": "yarn build:fast && yarn build:readme",
15+
"build": "yarn build:fast && yarn build:snippets && yarn build:readme",
1616
"build:fast": "rimraf ./build && tsc --project tsconfig.build.json",
1717
"lint": "eslint --color -c ../../../.eslintrc.js src/",
1818
"test": "jest --passWithNoTests --runInBand --verbose=true --detectOpenHandles --forceExit",
19+
"build:snippets": "tsc --project ./examples/tsconfig.examples.json",
1920
"build:readme": "yarn doc-snippets combine"
2021
},
2122
"dependencies": {
@@ -43,13 +44,16 @@
4344
},
4445
"doc-snippets": {
4546
"extract": {
46-
"include": "./**/*.{ts,tsx,json,yaml,txt,md,graphql,cue}",
47+
"include": [
48+
"./src/**/*.{ts,tsx,json,yaml,txt,md,graphql,cue}",
49+
"./examples/**/*.{ts,tsx,json,yaml,txt,md,graphql,cue}"
50+
],
4751
"ignore": [
4852
"./**/node_modules/**",
4953
"./**/.polywrap/**",
5054
"./**/__tests__/**"
5155
],
52-
"dir": "./src"
56+
"dir": "./"
5357
},
5458
"inject": {
5559
"dir": "./readme",

packages/js/core-client/readme/README.md

Lines changed: 14 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -15,71 +15,20 @@ npm install --save @polywrap/core-client-js
1515

1616
## Usage
1717

18-
### Instantiate the client
19-
```ts
20-
import { PolywrapCoreClient } from "@polywrap/core-client-js";
21-
22-
const config = { ... };
23-
const client = new PolywrapCoreClient(config);
24-
```
25-
26-
### Invoke a wrapper
27-
28-
```ts
29-
await client.invoke({
30-
uri: "ens/helloworld.dev.polywrap.eth",
31-
method: "logMessage",
32-
args: {
33-
message: "Hello World!"
34-
}
35-
});
36-
```
37-
38-
### Configure the core client
39-
40-
```ts
41-
const config = {
42-
// declare interface implementations
43-
interfaces: [
44-
{
45-
interface: "wrap://ens/uri-resolver.core.polywrap.eth",
46-
implementations: [
47-
"wrap://ens/ipfs-resolver.polywrap.eth",
48-
],
49-
},
50-
],
51-
// set environmental variables for a wrapper
52-
envs: [
53-
{
54-
uri: "wrap://ens/ipfs.polywrap.eth",
55-
env: {
56-
provider: "https://ipfs.wrappers.io",
57-
},
58-
},
59-
],
60-
// customize URI resolution by adding redirects and embedded wrappers/packages
61-
resolver:
62-
RecursiveResolver.from(
63-
PackageToWrapperCacheResolver.from(
64-
[
65-
StaticResolver.from([
66-
...redirects,
67-
...wrappers,
68-
...packages,
69-
]),
70-
...this.config.resolvers,
71-
new ExtendableUriResolver(),
72-
],
73-
new WrapperCache()
74-
)
75-
),
76-
// tracer configuration - see @polywrap/tracing-js package
77-
tracerConfig: { ... },
78-
};
79-
```
80-
```ts
81-
// create a client by modifying the default configuration bundle
82-
const client = new PolywrapCoreClient(config);
18+
### Instantiate
19+
20+
Use the `@polywrap/client-config-builder-js` package to build a CoreClientConfig for your project, then use the PolywrapCoreClient [constructor](#constructor) to instantiate the client with your config.
21+
22+
```ts
23+
$snippet: quickstart-instantiate
24+
```
25+
26+
### Invoke
27+
28+
Invoke a wrapper.
29+
30+
```ts
31+
$snippet: quickstart-invoke
8332
```
8433

8534
# Reference

0 commit comments

Comments
 (0)