Skip to content

Commit 0e10502

Browse files
authored
Merge pull request #1480 from polywrap/pileks/refactor-client-updates
Refactor: ClientConfigBuilder-specific `BuilderConfig` object for configuration handling
2 parents 7ec240d + 259d531 commit 0e10502

128 files changed

Lines changed: 2136 additions & 2491 deletions

File tree

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/__tests__/unit/jobrunner.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { buildWrapper } from "@polywrap/test-env-js";
33
import { testCases } from "./jobrunner-test-cases";
44
import { JobRunner } from "../../lib";
55
import path from "path";
6-
import { ClientConfigBuilder } from "@polywrap/client-config-builder-js";
7-
import { IClientConfigBuilder } from "@polywrap/client-config-builder-js/build/IClientConfigBuilder";
6+
import { ClientConfigBuilder, IClientConfigBuilder } from "@polywrap/client-config-builder-js";
87

98
jest.setTimeout(200000);
109

packages/cli/src/__tests__/unit/option-parsers/option-parsers.spec.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
1-
import { Uri } from "@polywrap/core-js";
21
import path from "path";
32
import { parseWrapperEnvsOption } from "../../../lib";
43

54
describe("unit tests for option-parsers", () => {
65
describe("wrapper-envs", () => {
7-
const sampleFileEnvs = [
8-
{
9-
uri: Uri.from("wrap://ens/hello-world.polywrap.eth"),
10-
env: {
11-
foo: "bar",
6+
const sampleFileEnvs = {
7+
"ens/ethereum.polywrap.eth": {
8+
connection: {
9+
networkNameOrChainId: "mainnet",
10+
node: "https://mainnet.infura.io/v3/some_api_key",
1211
},
1312
},
14-
{
15-
uri: Uri.from("ens/ethereum.polywrap.eth"),
16-
env: {
17-
connection: {
18-
node: "https://mainnet.infura.io/v3/some_api_key",
19-
networkNameOrChainId: "mainnet",
20-
},
21-
},
22-
},
23-
];
13+
"ens/hello-world.polywrap.eth": { foo: "bar" },
14+
};
2415

25-
it("Should return undefined when no filename is provided", async () => {
16+
it("Should return undefined when undefined is provided for wrapperEnvsPath", async () => {
2617
const envs = await parseWrapperEnvsOption(undefined);
2718

2819
expect(envs).toBeUndefined();
2920
});
3021

22+
it("Should return undefined when false is provided for wrapperEnvsPath", async () => {
23+
const envs = await parseWrapperEnvsOption(false);
24+
25+
expect(envs).toBeUndefined();
26+
});
27+
3128
it("Should throw for a nonexistent wrapper-env file", async () => {
3229
const nonExistentFilePath = path.join(
3330
__dirname,

packages/cli/src/commands/build.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ import {
3030
import { defaultCodegenDir } from "../lib/defaults/defaultCodegenDir";
3131

3232
import readline from "readline";
33-
import { Env, PolywrapClient } from "@polywrap/client-js";
33+
import { PolywrapClient } from "@polywrap/client-js";
3434
import { PolywrapManifest } from "@polywrap/polywrap-manifest-types-js";
35-
import { Uri } from "@polywrap/core-js";
3635

3736
const defaultOutputDir = "./build";
3837
const defaultStrategy = SupportedStrategies.VM;
@@ -178,11 +177,11 @@ async function run(options: Required<BuildCommandOptions>) {
178177
const configBuilder = await parseClientConfigOption(clientConfig);
179178

180179
if (envs) {
181-
configBuilder.addEnvs(envs as Env<Uri>[]);
180+
configBuilder.addEnvs(envs);
182181
}
183182

184183
// Get Client
185-
const client = new PolywrapClient(configBuilder.buildCoreConfig(), {
184+
const client = new PolywrapClient(configBuilder.build(), {
186185
noDefaults: true,
187186
});
188187

packages/cli/src/commands/codegen.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import {
1818
import { ScriptCodegenerator } from "../lib/codegen/ScriptCodeGenerator";
1919
import { defaultCodegenDir } from "../lib/defaults/defaultCodegenDir";
2020

21-
import { Env, PolywrapClient } from "@polywrap/client-js";
22-
import { Uri } from "@polywrap/core-js";
21+
import { PolywrapClient } from "@polywrap/client-js";
2322

2423
const pathStr = intlMsg.commands_codegen_options_o_path();
2524
const defaultManifestStr = defaultPolywrapManifest.join(" | ");
@@ -103,11 +102,11 @@ async function run(options: Required<CodegenCommandOptions>) {
103102
const configBuilder = await parseClientConfigOption(clientConfig);
104103

105104
if (envs) {
106-
configBuilder.addEnvs(envs as Env<Uri>[]);
105+
configBuilder.addEnvs(envs);
107106
}
108107

109108
// Get Client
110-
const client = new PolywrapClient(configBuilder.buildCoreConfig(), {
109+
const client = new PolywrapClient(configBuilder.build(), {
111110
noDefaults: true,
112111
});
113112

packages/cli/src/commands/docgen.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ import { scriptPath as jsdocScriptPath } from "../lib/docgen/jsdoc";
1818
import { scriptPath as schemaScriptPath } from "../lib/docgen/schema";
1919
import { ScriptCodegenerator } from "../lib/codegen/ScriptCodeGenerator";
2020

21-
import { Env, PolywrapClient } from "@polywrap/client-js";
21+
import { PolywrapClient } from "@polywrap/client-js";
2222
import chalk from "chalk";
2323
import { Argument } from "commander";
24-
import { Uri } from "@polywrap/core-js";
2524

2625
const commandToPathMap: Record<string, string> = {
2726
schema: schemaScriptPath,
@@ -141,7 +140,7 @@ async function run(
141140
const configBuilder = await parseClientConfigOption(clientConfig);
142141

143142
if (envs) {
144-
configBuilder.addEnvs(envs as Env<Uri>[]);
143+
configBuilder.addEnvs(envs);
145144
}
146145

147146
let project = await getProjectFromManifest(manifestFile, logger);
@@ -161,7 +160,7 @@ async function run(
161160
// Resolve custom script
162161
const customScript = require.resolve(commandToPathMap[action]);
163162

164-
const client = new PolywrapClient(configBuilder.buildCoreConfig(), {
163+
const client = new PolywrapClient(configBuilder.build(), {
165164
noDefaults: true,
166165
});
167166

packages/cli/src/commands/test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { createLogger } from "./utils/createLogger";
2323
import path from "path";
2424
import yaml from "yaml";
2525
import fs from "fs";
26-
import { Env, Uri } from "@polywrap/core-js";
2726

2827
export interface TestCommandOptions extends BaseCommandOptions {
2928
clientConfig: string | false;
@@ -109,7 +108,7 @@ const _run = async (options: Required<TestCommandOptions>) => {
109108
const configBuilder = await parseClientConfigOption(clientConfig);
110109

111110
if (envs) {
112-
configBuilder.addEnvs(envs as Env<Uri>[]);
111+
configBuilder.addEnvs(envs);
113112
}
114113

115114
const manifestPath = path.resolve(manifestFile);
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export * from "./uuid";
2-
export * from "./validate-client-config";
32
export * from "./workflow-validator";
43
export * from "./wrap";

packages/cli/src/lib/helpers/validate-client-config.ts

Lines changed: 0 additions & 131 deletions
This file was deleted.

packages/cli/src/lib/option-parsers/wrapper-envs.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { loadEnvironmentVariables } from "../system";
22

33
import { ClientConfigBuilder } from "@polywrap/client-config-builder-js";
4-
import { Env, Uri } from "@polywrap/core-js";
54
import fs from "fs";
65
import YAML from "yaml";
76

87
type WrapperEnvs = Record<string, Record<string, unknown>>;
98

109
export async function parseWrapperEnvsOption(
1110
wrapperEnvsPath: string | false | undefined
12-
): Promise<Readonly<Env<Uri>[]> | undefined> {
11+
): Promise<Readonly<Record<string, Record<string, unknown>>> | undefined> {
1312
if (!wrapperEnvsPath) {
1413
return undefined;
1514
}
@@ -41,5 +40,5 @@ export async function parseWrapperEnvsOption(
4140
builder.addEnv(env, wrapperEnvs[env]);
4241
}
4342

44-
return builder.buildCoreConfig().envs;
43+
return builder.config.envs;
4544
}

0 commit comments

Comments
 (0)