Skip to content

Commit bc8ee1d

Browse files
authored
Merge pull request #1498 from polywrap/pileks/refactor-client-updates-config-refactor
Refactor `ClientConfigBuilder.build`
2 parents 1ab298b + 09ccb13 commit bc8ee1d

45 files changed

Lines changed: 334 additions & 548 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/cli/src/commands/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ async function run(options: Required<BuildCommandOptions>) {
181181
}
182182

183183
// Get Client
184-
const client = new PolywrapClient(configBuilder.buildCoreConfig(), {
184+
const client = new PolywrapClient(configBuilder.build(), {
185185
noDefaults: true,
186186
});
187187

packages/cli/src/commands/codegen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ async function run(options: Required<CodegenCommandOptions>) {
106106
}
107107

108108
// Get Client
109-
const client = new PolywrapClient(configBuilder.buildCoreConfig(), {
109+
const client = new PolywrapClient(configBuilder.build(), {
110110
noDefaults: true,
111111
});
112112

packages/cli/src/commands/docgen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ async function run(
160160
// Resolve custom script
161161
const customScript = require.resolve(commandToPathMap[action]);
162162

163-
const client = new PolywrapClient(configBuilder.buildCoreConfig(), {
163+
const client = new PolywrapClient(configBuilder.build(), {
164164
noDefaults: true,
165165
});
166166

packages/cli/src/lib/workflow/JobRunner.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { JobResult, Status, Step } from "./types";
22

3-
import { PolywrapClient } from "@polywrap/client-js";
4-
import { CoreClient, MaybeAsync, Uri } from "@polywrap/core-js";
5-
import { WorkflowJobs } from "@polywrap/polywrap-manifest-types-js";
63
import {
7-
buildPolywrapCoreClientConfig,
84
IClientConfigBuilder,
9-
} from "@polywrap/client-config-builder-js";
5+
PolywrapClient,
6+
buildPolywrapCoreClientConfig,
7+
} from "@polywrap/client-js";
8+
import { CoreClient, MaybeAsync, Uri } from "@polywrap/core-js";
9+
import { WorkflowJobs } from "@polywrap/polywrap-manifest-types-js";
1010

1111
export class JobRunner {
1212
private _jobOutput: Map<string, JobResult>;
@@ -20,7 +20,7 @@ export class JobRunner {
2020
) => MaybeAsync<void>
2121
) {
2222
this._jobOutput = new Map();
23-
this._client = new PolywrapClient(this._configBuilder.buildCoreConfig(), {
23+
this._client = new PolywrapClient(this._configBuilder.build(), {
2424
noDefaults: true,
2525
});
2626
}

packages/js/client-config-builder/README.md

Lines changed: 7 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,11 @@ You can add the entire [default client configuration bundle](#bundle--defaultcon
5353
Finally, build a ClientConfig or CoreClientConfig to pass to the PolywrapClient constructor.
5454

5555
```typescript
56-
// accepted by the PolywrapClient
57-
const clientConfig = builder.build();
58-
5956
// accepted by either the PolywrapClient or the PolywrapCoreClient
60-
let coreClientConfig = builder.buildCoreConfig();
57+
let coreClientConfig = builder.build();
6158

6259
// build with a custom cache and/or resolver
63-
coreClientConfig = builder.buildCoreConfig(
60+
coreClientConfig = builder.build(
6461
new WrapperCache(),
6562
RecursiveResolver.from([])
6663
);
@@ -152,45 +149,6 @@ A complete example using all or most of the available methods.
152149

153150
# Reference
154151

155-
## Types
156-
157-
```ts
158-
/**
159-
* Client configuration that can be passed to the PolywrapClient
160-
*
161-
* @remarks
162-
* The PolywrapClient converts the ClientConfig to a CoreClientConfig.
163-
*/
164-
export interface ClientConfig {
165-
/** set environmental variables for a wrapper */
166-
readonly envs: Env[];
167-
168-
/** register interface implementations */
169-
readonly interfaces: InterfaceImplementations[];
170-
171-
/** redirect invocations from one uri to another */
172-
readonly redirects: IUriRedirect[];
173-
174-
/** add embedded wrappers */
175-
readonly wrappers: IUriWrapper[];
176-
177-
/** add and configure embedded packages */
178-
readonly packages: IUriPackage[];
179-
180-
/** customize URI resolution
181-
*
182-
* @remarks
183-
* A UriResolverLike can be any one of:
184-
* IUriResolver<unknown>
185-
* | IUriRedirect
186-
* | IUriPackage
187-
* | IUriWrapper
188-
* | UriResolverLike[]
189-
* */
190-
readonly resolvers: UriResolverLike[];
191-
}
192-
```
193-
194152
## ClientConfigBuilder
195153

196154
### Constructor
@@ -305,7 +263,9 @@ export interface ClientConfig {
305263
* @param uriEnvs: and object where key is the uri and value is the another object with the env variables for the uri
306264
* @returns IClientConfigBuilder (mutated self)
307265
*/
308-
addEnvs(uriEnvs: Record<string, Record<string, unknown>>): IClientConfigBuilder;
266+
addEnvs(
267+
uriEnvs: Record<string, Record<string, unknown>>
268+
): IClientConfigBuilder;
309269
```
310270

311271
### removeEnv
@@ -460,23 +420,13 @@ export interface ClientConfig {
460420
```
461421

462422
### build
463-
```ts
464-
/**
465-
* Build a sanitized client configuration that can be passed to the PolywrapClient constructor
466-
*
467-
* @returns ClientConfig that results from applying all the steps in the builder pipeline
468-
*/
469-
build(): ClientConfig;
470-
```
471-
472-
### buildCoreConfig
473423
```ts
474424
/**
475425
* Build a sanitized core client configuration that can be passed to the PolywrapClient or PolywrapCoreClient constructors
476426
*
477427
* @returns CoreClientConfig that results from applying all the steps in the builder pipeline
478428
*/
479-
buildCoreConfig(): CoreClientConfig;
429+
build(): CoreClientConfig;
480430
```
481431

482432
## Bundles
@@ -578,9 +528,7 @@ export const getDefaultConfig = (): BuilderConfig => ({
578528
[defaultWrappers.concurrentInterface]: new Set([
579529
defaultPackages.concurrent,
580530
]),
581-
[defaultInterfaces.logger]: new Set([
582-
defaultPackages.logger,
583-
]),
531+
[defaultInterfaces.logger]: new Set([defaultPackages.logger]),
584532
},
585533
resolvers: [],
586534
});

packages/js/client-config-builder/examples/quickstart.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ClientConfigBuilder, ClientConfig } from "../build";
1+
import { ClientConfigBuilder } from "../build";
22

33
// eslint-disable-next-line import/no-extraneous-dependencies
44
import { WasmWrapper } from "@polywrap/wasm-js";
@@ -51,28 +51,24 @@ export function configure(): ClientConfigBuilder {
5151

5252
export function build():
5353
| ClientConfigBuilder
54-
| ClientConfig
5554
| CoreClientConfig {
5655
const builder = new ClientConfigBuilder();
5756

5857
// $start: quickstart-build
59-
// accepted by the PolywrapClient
60-
const clientConfig = builder.build();
61-
6258
// accepted by either the PolywrapClient or the PolywrapCoreClient
63-
let coreClientConfig = builder.buildCoreConfig();
59+
let coreClientConfig = builder.build();
6460

6561
// build with a custom cache and/or resolver
66-
coreClientConfig = builder.buildCoreConfig(
62+
coreClientConfig = builder.build(
6763
new WrapperCache(),
6864
RecursiveResolver.from([])
6965
);
7066
// $end
7167

72-
return builder ?? clientConfig ?? coreClientConfig;
68+
return builder ?? coreClientConfig;
7369
}
7470

75-
export async function example(): Promise<ClientConfig> {
71+
export async function example(): Promise<CoreClientConfig> {
7672
// $start: quickstart-example
7773
// init
7874
const builder = new ClientConfigBuilder();

packages/js/client-config-builder/readme/README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ $snippet: quickstart-example
4646

4747
# Reference
4848

49-
## Types
50-
51-
```ts
52-
$snippet: ClientConfig
53-
```
54-
5549
## ClientConfigBuilder
5650

5751
### Constructor
@@ -164,11 +158,6 @@ $snippet: IClientConfigBuilder-addDefaults
164158
$snippet: IClientConfigBuilder-build
165159
```
166160

167-
### buildCoreConfig
168-
```ts
169-
$snippet: IClientConfigBuilder-buildCoreConfig
170-
```
171-
172161
## Bundles
173162

174163
### Bundle: DefaultConfig

packages/js/client-config-builder/src/BaseClientConfigBuilder.ts

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
import { BuilderConfig } from "./types/configs/BuilderConfig";
2-
import { ClientConfig } from "./types/configs/ClientConfig";
32
import { IClientConfigBuilder } from "./types/IClientConfigBuilder";
43

54
import {
65
CoreClientConfig,
76
Wrapper,
87
IWrapPackage,
9-
Env,
10-
Uri,
11-
InterfaceImplementations,
12-
IUriRedirect,
13-
IUriWrapper,
14-
IUriPackage,
158
IUriResolver,
169
} from "@polywrap/core-js";
1710
import { IWrapperCache, UriResolverLike } from "@polywrap/uri-resolvers-js";
@@ -27,7 +20,7 @@ export abstract class BaseClientConfigBuilder implements IClientConfigBuilder {
2720
};
2821

2922
abstract addDefaults(): IClientConfigBuilder;
30-
abstract buildCoreConfig(
23+
abstract build(
3124
wrapperCache?: IWrapperCache,
3225
resolver?: IUriResolver<unknown>
3326
): CoreClientConfig;
@@ -209,48 +202,4 @@ export abstract class BaseClientConfigBuilder implements IClientConfigBuilder {
209202

210203
return this;
211204
}
212-
213-
build(): ClientConfig {
214-
const envs: Env[] = [];
215-
for (const [uri, env] of Object.entries(this._config.envs)) {
216-
envs.push({ uri: Uri.from(uri), env });
217-
}
218-
219-
const interfaces: InterfaceImplementations[] = [];
220-
for (const [interfaceUri, implementations] of Object.entries(
221-
this._config.interfaces
222-
)) {
223-
if (implementations.size === 0) continue;
224-
interfaces.push({
225-
interface: Uri.from(interfaceUri),
226-
implementations: Array.from(implementations).map((uri) =>
227-
Uri.from(uri)
228-
),
229-
});
230-
}
231-
232-
const redirects: IUriRedirect[] = [];
233-
for (const [uri, redirect] of Object.entries(this._config.redirects)) {
234-
redirects.push({ from: Uri.from(uri), to: Uri.from(redirect) });
235-
}
236-
237-
const wrappers: IUriWrapper[] = [];
238-
for (const [uri, wrapper] of Object.entries(this._config.wrappers)) {
239-
wrappers.push({ uri: Uri.from(uri), wrapper });
240-
}
241-
242-
const packages: IUriPackage[] = [];
243-
for (const [uri, wrapPackage] of Object.entries(this._config.packages)) {
244-
packages.push({ uri: Uri.from(uri), package: wrapPackage });
245-
}
246-
247-
return {
248-
envs,
249-
interfaces,
250-
redirects,
251-
wrappers,
252-
packages,
253-
resolvers: this._config.resolvers,
254-
};
255-
}
256205
}

0 commit comments

Comments
 (0)