Skip to content

Commit 130a993

Browse files
committed
chore: undo and prevent circular imports
1 parent 8a2a912 commit 130a993

File tree

14 files changed

+98
-102
lines changed

14 files changed

+98
-102
lines changed

.changeset/happy-weeks-ring.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@smithy/shared-ini-file-loader": patch
3+
"@smithy/util-endpoints": patch
4+
"@smithy/util-stream": patch
5+
---
6+
7+
remove and ban circular imports
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* @internal
3+
*/
4+
export const CONFIG_PREFIX_SEPARATOR = ".";

packages/shared-ini-file-loader/src/getConfigData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ParsedIniData } from "@smithy/types";
22
import { IniSectionType } from "@smithy/types";
33

4-
import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles";
4+
import { CONFIG_PREFIX_SEPARATOR } from "./constants";
55

66
/**
77
* Returns the config data from parsed ini data.

packages/shared-ini-file-loader/src/loadSharedConfigFiles.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ export interface SharedConfigInit {
4040

4141
const swallowError = () => ({});
4242

43-
/**
44-
* @internal
45-
*/
46-
export const CONFIG_PREFIX_SEPARATOR = ".";
43+
export { CONFIG_PREFIX_SEPARATOR } from "./constants";
4744

4845
/**
4946
* Loads the config and credentials files.

packages/shared-ini-file-loader/src/parseIni.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ParsedIniData } from "@smithy/types";
22
import { IniSectionType } from "@smithy/types";
33

4-
import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles";
4+
import { CONFIG_PREFIX_SEPARATOR } from "./constants";
55

66
const prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-@\+\.%:/]+)\2$/;
77
const profileNameBlockList = ["__proto__", "profile __proto__"];
Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,2 @@
1-
import type { EvaluateOptions, Expression, FunctionObject, FunctionReturn } from "../types";
2-
import { customEndpointFunctions } from "./customEndpointFunctions";
3-
import { endpointFunctions } from "./endpointFunctions";
4-
import { evaluateExpression } from "./evaluateExpression";
5-
6-
export const callFunction = ({ fn, argv }: FunctionObject, options: EvaluateOptions): FunctionReturn => {
7-
const evaluatedArgs = argv.map((arg) =>
8-
["boolean", "number"].includes(typeof arg) ? arg : evaluateExpression(arg as Expression, "arg", options)
9-
);
10-
const fnSegments = fn.split(".");
11-
if (fnSegments[0] in customEndpointFunctions && fnSegments[1] != null) {
12-
// @ts-ignore Element implicitly has an 'any' type
13-
return customEndpointFunctions[fnSegments[0]][fnSegments[1]](...evaluatedArgs);
14-
}
15-
// @ts-ignore Element implicitly has an 'any' type
16-
return endpointFunctions[fn](...evaluatedArgs);
17-
};
1+
// breaks circular import
2+
export { callFunction } from "./evaluateExpression";

packages/util-endpoints/src/utils/evaluateExpression.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { EvaluateOptions, Expression, FunctionObject, ReferenceObject } from "../types";
1+
import type { EvaluateOptions, Expression, FunctionObject, FunctionReturn, ReferenceObject } from "../types";
22
import { EndpointError } from "../types";
3-
import { callFunction } from "./callFunction";
3+
import { customEndpointFunctions } from "./customEndpointFunctions";
4+
import { endpointFunctions } from "./endpointFunctions";
45
import { evaluateTemplate } from "./evaluateTemplate";
56
import { getReferenceValue } from "./getReferenceValue";
67

@@ -14,3 +15,16 @@ export const evaluateExpression = (obj: Expression, keyName: string, options: Ev
1415
}
1516
throw new EndpointError(`'${keyName}': ${String(obj)} is not a string, function or reference.`);
1617
};
18+
19+
export const callFunction = ({ fn, argv }: FunctionObject, options: EvaluateOptions): FunctionReturn => {
20+
const evaluatedArgs = argv.map((arg) =>
21+
["boolean", "number"].includes(typeof arg) ? arg : evaluateExpression(arg as Expression, "arg", options)
22+
);
23+
const fnSegments = fn.split(".");
24+
if (fnSegments[0] in customEndpointFunctions && fnSegments[1] != null) {
25+
// @ts-ignore Element implicitly has an 'any' type
26+
return customEndpointFunctions[fnSegments[0]][fnSegments[1]](...evaluatedArgs);
27+
}
28+
// @ts-ignore Element implicitly has an 'any' type
29+
return endpointFunctions[fn](...evaluatedArgs);
30+
};

packages/util-endpoints/src/utils/evaluateRules.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { EndpointV2 } from "@smithy/types";
22

3-
import type { EvaluateOptions, RuleSetRules } from "../types";
3+
import type { EvaluateOptions, RuleSetRules, TreeRuleObject } from "../types";
44
import { EndpointError } from "../types";
5+
import { evaluateConditions } from "./evaluateConditions";
56
import { evaluateEndpointRule } from "./evaluateEndpointRule";
67
import { evaluateErrorRule } from "./evaluateErrorRule";
7-
import { evaluateTreeRule } from "./evaluateTreeRule";
88

99
export const evaluateRules = (rules: RuleSetRules, options: EvaluateOptions): EndpointV2 => {
1010
for (const rule of rules) {
@@ -26,3 +26,17 @@ export const evaluateRules = (rules: RuleSetRules, options: EvaluateOptions): En
2626
}
2727
throw new EndpointError(`Rules evaluation failed`);
2828
};
29+
30+
export const evaluateTreeRule = (treeRule: TreeRuleObject, options: EvaluateOptions): EndpointV2 | undefined => {
31+
const { conditions, rules } = treeRule;
32+
33+
const { result, referenceRecord } = evaluateConditions(conditions, options);
34+
if (!result) {
35+
return;
36+
}
37+
38+
return evaluateRules(rules, {
39+
...options,
40+
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
41+
});
42+
};
Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,2 @@
1-
import type { EndpointV2 } from "@smithy/types";
2-
3-
import type { EvaluateOptions, TreeRuleObject } from "../types";
4-
import { evaluateConditions } from "./evaluateConditions";
5-
import { evaluateRules } from "./evaluateRules";
6-
7-
export const evaluateTreeRule = (treeRule: TreeRuleObject, options: EvaluateOptions): EndpointV2 | undefined => {
8-
const { conditions, rules } = treeRule;
9-
10-
const { result, referenceRecord } = evaluateConditions(conditions, options);
11-
if (!result) {
12-
return;
13-
}
14-
15-
return evaluateRules(rules, {
16-
...options,
17-
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
18-
});
19-
};
1+
// breaks circular import
2+
export { evaluateTreeRule } from "./evaluateRules";

packages/util-endpoints/src/utils/getEndpointProperties.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import type { EndpointObjectProperty } from "@smithy/types";
2+
13
import type { EndpointObjectProperties, EvaluateOptions } from "../types";
2-
import { getEndpointProperty } from "./getEndpointProperty";
4+
import { EndpointError } from "../types";
5+
import { evaluateTemplate } from "./evaluateTemplate";
36

47
export const getEndpointProperties = (properties: EndpointObjectProperties, options: EvaluateOptions) =>
58
Object.entries(properties).reduce(
@@ -9,3 +12,25 @@ export const getEndpointProperties = (properties: EndpointObjectProperties, opti
912
}),
1013
{}
1114
);
15+
16+
export const getEndpointProperty = (
17+
property: EndpointObjectProperty,
18+
options: EvaluateOptions
19+
): EndpointObjectProperty => {
20+
if (Array.isArray(property)) {
21+
return property.map((propertyEntry) => getEndpointProperty(propertyEntry, options));
22+
}
23+
switch (typeof property) {
24+
case "string":
25+
return evaluateTemplate(property, options);
26+
case "object":
27+
if (property === null) {
28+
throw new EndpointError(`Unexpected endpoint property: ${property}`);
29+
}
30+
return getEndpointProperties(property, options);
31+
case "boolean":
32+
return property;
33+
default:
34+
throw new EndpointError(`Unexpected endpoint property type: ${typeof property}`);
35+
}
36+
};

0 commit comments

Comments
 (0)