Skip to content

Commit ffe46a4

Browse files
committed
cleanup: removes deprecation options on envVar and substitute
1 parent 0ba4bcf commit ffe46a4

File tree

2 files changed

+4
-134
lines changed

2 files changed

+4
-134
lines changed

app-config-extensions/src/env-var-directive.ts

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ export function envVarDirective(
1919
'$envVar',
2020
forKey('$envVar', (value, key, parentKeys, context) => async (parse) => {
2121
let name: string;
22-
let parseInt = false;
23-
let parseFloat = false;
24-
let parseBool = false;
2522

2623
if (typeof value === 'string') {
2724
name = value;
@@ -32,62 +29,14 @@ export function envVarDirective(
3229
const resolved = (await parse(value.name)).toJSON();
3330
validateString(resolved, [...parentKeys, key, [InObject, 'name']]);
3431

35-
parseInt = !!(await parse(value.parseInt)).toJSON();
36-
parseFloat = !!(await parse(value.parseFloat)).toJSON();
37-
parseBool = !!(await parse(value.parseBool)).toJSON();
3832
name = resolved;
39-
40-
if (parseInt) {
41-
logger.warn(
42-
`Detected use of deprecated of 'parseInt' option in $envVar - use $parseInt directive instead`,
43-
);
44-
}
45-
46-
if (parseFloat) {
47-
logger.warn(
48-
`Detected use of deprecated of 'parseFloat' option in $envVar - use $parseFloat directive instead`,
49-
);
50-
}
51-
52-
if (parseBool) {
53-
logger.warn(
54-
`Detected use of deprecated of 'parseBool' option in $envVar - use $parseBool directive instead`,
55-
);
56-
}
5733
}
5834

5935
const parseValue = (strValue: string | null) => {
60-
if (parseBool) {
61-
const parsed =
62-
strValue !== null && (strValue.toLowerCase() === 'true' || strValue === '1');
63-
64-
return parse(parsed, { shouldFlatten: true });
65-
}
66-
6736
if (strValue === null) {
6837
return parse(null, { shouldFlatten: true });
6938
}
7039

71-
if (parseInt) {
72-
const parsed = Number.parseInt(strValue, 10);
73-
74-
if (Number.isNaN(parsed)) {
75-
throw new AppConfigError(`Failed to parseInt(${strValue})`);
76-
}
77-
78-
return parse(parsed, { shouldFlatten: true });
79-
}
80-
81-
if (parseFloat) {
82-
const parsed = Number.parseFloat(strValue);
83-
84-
if (Number.isNaN(parsed)) {
85-
throw new AppConfigError(`Failed to parseFloat(${strValue})`);
86-
}
87-
88-
return parse(parsed, { shouldFlatten: true });
89-
}
90-
9140
return parse(strValue, { shouldFlatten: true });
9241
};
9342

app-config-extensions/src/substitute-directive.ts

Lines changed: 4 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -29,74 +29,15 @@ export function substituteDirective(
2929
validateObject(value, [...parentKeys, key]);
3030
if (Array.isArray(value)) throw new AppConfigError('$substitute was given an array');
3131

32-
if (value.$name) {
33-
logger.warn(
34-
`Detected deprecated use of $name in a $substitute directive. Use 'name' instead.`,
35-
);
36-
}
37-
38-
const name = (await parse(selectDefined(value.name, value.$name))).toJSON();
32+
const name = (await parse(value.name)).toJSON();
3933

4034
validateString(name, [...parentKeys, key, [InObject, 'name']]);
4135

4236
const parseValue = async (strValue: string | null) => {
43-
const parseBool = (await parse(selectDefined(value.parseBool, value.$parseBool))).toJSON();
44-
45-
if (value.$parseBool) {
46-
logger.warn(
47-
`Detected deprecated use of $parseBool in a $substitute directive - use $parseBool directive instead`,
48-
);
49-
}
50-
51-
if (parseBool) {
52-
const parsed =
53-
strValue !== null && (strValue.toLowerCase() === 'true' || strValue === '1');
54-
55-
return parse(parsed, { shouldFlatten: true });
56-
}
57-
5837
if (strValue === null) {
5938
return parse(null, { shouldFlatten: true });
6039
}
6140

62-
const parseInt = (await parse(selectDefined(value.parseInt, value.$parseInt))).toJSON();
63-
64-
if (value.$parseInt) {
65-
logger.warn(
66-
`Detected deprecated use of $parseInt in a $substitute directive - use $parseInt directive instead`,
67-
);
68-
}
69-
70-
if (parseInt) {
71-
const parsed = Number.parseInt(strValue, 10);
72-
73-
if (Number.isNaN(parsed)) {
74-
throw new AppConfigError(`Failed to parseInt(${strValue})`);
75-
}
76-
77-
return parse(parsed, { shouldFlatten: true });
78-
}
79-
80-
if (value.$parseFloat) {
81-
logger.warn(
82-
`Detected deprecated use of $parseFloat in a $substitute directive - use $parseFloat directive instead`,
83-
);
84-
}
85-
86-
const parseFloat = (
87-
await parse(selectDefined(value.parseFloat, value.$parseFloat))
88-
).toJSON();
89-
90-
if (parseFloat) {
91-
const parsed = Number.parseFloat(strValue);
92-
93-
if (Number.isNaN(parsed)) {
94-
throw new AppConfigError(`Failed to parseFloat(${strValue})`);
95-
}
96-
97-
return parse(parsed, { shouldFlatten: true });
98-
}
99-
10041
return parse(strValue, { shouldFlatten: true });
10142
};
10243

@@ -110,21 +51,9 @@ export function substituteDirective(
11051
return parseValue(resolvedValue);
11152
}
11253

113-
if (value.fallback !== undefined || value.$fallback !== undefined) {
114-
const fallback = (await parse(selectDefined(value.fallback, value.$fallback))).toJSON();
115-
const allowNull = (await parse(selectDefined(value.allowNull, value.$allowNull))).toJSON();
116-
117-
if (value.$fallback) {
118-
logger.warn(
119-
`Detected deprecated use of $fallback in a $substitute directive. Use 'fallback' instead.`,
120-
);
121-
}
122-
123-
if (value.$allowNull) {
124-
logger.warn(
125-
`Detected deprecated use of $allowNull in a $substitute directive. Use 'allowNull' instead.`,
126-
);
127-
}
54+
if (value.fallback !== undefined) {
55+
const fallback = (await parse(value.fallback)).toJSON();
56+
const allowNull = (await parse(value.allowNull)).toJSON();
12857

12958
if (allowNull) {
13059
validateStringOrNull(fallback, [...parentKeys, key, [InObject, 'fallback']]);
@@ -188,14 +117,6 @@ function performAllSubstitutions(text: string, envType?: string): string {
188117
return output;
189118
}
190119

191-
function selectDefined<T>(...args: (T | null | undefined)[]): T | null {
192-
for (const a of args) {
193-
if (a !== undefined) return a;
194-
}
195-
196-
return (undefined as any) as T;
197-
}
198-
199120
const validateObject: ValidationFunction<
200121
Record<string, any>
201122
> = validationFunction(({ emptySchema }) => emptySchema().addAdditionalProperties());

0 commit comments

Comments
 (0)