Skip to content

Commit b7a6c51

Browse files
committed
refactor: renames "context" for future
1 parent 816d6d4 commit b7a6c51

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

app-config-core/src/parsed-value.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type ParsingExtensionKey =
1818
| [typeof Root];
1919

2020
export interface ParsingExtension {
21-
(value: Json, key: ParsingExtensionKey, context: ParsingExtensionKey[]):
21+
(value: Json, key: ParsingExtensionKey, parentKeys: ParsingExtensionKey[]):
2222
| ParsingExtensionTransform
2323
| false;
2424

@@ -355,13 +355,13 @@ async function parseValueInner(
355355
source: ConfigSource,
356356
extensions: ParsingExtension[],
357357
metadata: ParsedValueMetadata = {},
358-
context: ParsingExtensionKey[],
358+
parentKeys: ParsingExtensionKey[],
359359
root: Json,
360360
parent?: JsonObject | Json[],
361361
visitedExtensions: Set<ParsingExtension | string> = new Set(),
362362
): Promise<ParsedValue> {
363-
const [currentKey] = context.slice(-1);
364-
const contextualKeys = context.slice(0, context.length - 1);
363+
const [currentKey] = parentKeys.slice(-1);
364+
const parentKeysNext = parentKeys.slice(0, parentKeys.length - 1);
365365

366366
let applicableExtension: ParsingExtensionTransform | undefined;
367367

@@ -377,7 +377,7 @@ async function parseValueInner(
377377
if (visitedExtensions.has(extension)) continue;
378378
if (extension.extensionName && visitedExtensions.has(extension.extensionName)) continue;
379379

380-
const applicable = extension(value, currentKey, contextualKeys);
380+
const applicable = extension(value, currentKey, parentKeysNext);
381381

382382
if (applicable) {
383383
applicableExtension = applicable;
@@ -403,7 +403,7 @@ async function parseValueInner(
403403
sourceOverride ?? source,
404404
extensionsOverride ?? extensions,
405405
{ ...metadata, ...metadataOverride },
406-
context,
406+
parentKeys,
407407
root,
408408
parent,
409409
visitedExtensions,
@@ -421,7 +421,7 @@ async function parseValueInner(
421421
source,
422422
extensions,
423423
undefined,
424-
context.concat([[InArray, index]]),
424+
parentKeys.concat([[InArray, index]]),
425425
root,
426426
value,
427427
);
@@ -446,7 +446,7 @@ async function parseValueInner(
446446
source,
447447
extensions,
448448
undefined,
449-
context.concat([[InObject, key]]),
449+
parentKeys.concat([[InObject, key]]),
450450
root,
451451
value,
452452
);

app-config-exec/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function execParsingExtension(): ParsingExtension {
3333
.addBoolean('parseOutput', {}, false)
3434
.addBoolean('trimWhitespace', {}, false),
3535
),
36-
(value) => async (parse, _, context) => {
36+
(value) => async (parse, _, source) => {
3737
let options;
3838

3939
if (typeof value === 'string') {
@@ -50,7 +50,7 @@ function execParsingExtension(): ParsingExtension {
5050
} = options;
5151

5252
try {
53-
const dir = resolveFilepath(context, '.');
53+
const dir = resolveFilepath(source, '.');
5454
const { stdout, stderr } = await execAsync(command, { cwd: dir });
5555

5656
if (failOnStderr && stderr) {

app-config-extension-utils/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export function validateOptions<T>(
7272
extension: (
7373
value: T,
7474
key: ParsingExtensionKey,
75-
context: ParsingExtensionKey[],
75+
parentKeys: ParsingExtensionKey[],
7676
) => ParsingExtensionTransform | false,
7777
{ lazy = false }: { lazy?: boolean } = {},
7878
): ParsingExtension {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ function fileReferenceDirective(keyName: string, meta: ParsedValueMetadata): Par
3232

3333
return SchemaBuilder.oneOf(reference, SchemaBuilder.arraySchema(reference));
3434
},
35-
(value) => async (_, __, context, extensions) => {
35+
(value) => async (_, __, source, extensions) => {
3636
const retrieveFile = async (filepath: string, subselector?: string, isOptional = false) => {
37-
const resolvedPath = resolveFilepath(context, filepath);
37+
const resolvedPath = resolveFilepath(source, filepath);
3838

3939
logger.verbose(`Loading file for ${keyName}: ${resolvedPath}`);
4040

41-
const source = new FileSource(resolvedPath);
41+
const resolvedSource = new FileSource(resolvedPath);
4242

43-
const parsed = await source.read(extensions).catch((error) => {
43+
const parsed = await resolvedSource.read(extensions).catch((error) => {
4444
if (error instanceof NotFoundError && isOptional) {
4545
return ParsedValue.literal({});
4646
}

app-config-js/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export default function jsModuleDirective(): ParsingExtension {
1313
'$jsModule',
1414
validateOptions(
1515
(SchemaBuilder) => SchemaBuilder.stringSchema(),
16-
(value) => async (parse, _, context) => {
17-
const resolvedPath = resolveFilepath(context, value);
16+
(value) => async (parse, _, source) => {
17+
const resolvedPath = resolveFilepath(source, value);
1818

1919
let loaded: any = await import(resolvedPath);
2020

app-config-node/src/file-source.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ export class FlexibleFileSource extends ConfigSource {
151151
}
152152
}
153153

154-
export function resolveFilepath(context: ConfigSource, filepath: string) {
154+
export function resolveFilepath(source: ConfigSource, filepath: string) {
155155
let resolvedPath = filepath;
156156

157157
// resolve filepaths that are relative to the current FileSource
158-
if (!isAbsolute(filepath) && context instanceof FileSource) {
159-
resolvedPath = join(dirname(context.filePath), filepath);
158+
if (!isAbsolute(filepath) && source instanceof FileSource) {
159+
resolvedPath = join(dirname(source.filePath), filepath);
160160

161-
if (resolve(context.filePath) === resolvedPath) {
161+
if (resolve(source.filePath) === resolvedPath) {
162162
throw new AppConfigError(`An extension tried to resolve to it's own file (${resolvedPath}).`);
163163
}
164164
}

app-config-v1-compat/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import { logger } from '@app-config/logging';
88

99
/** V1 app-config compatibility */
1010
export default function v1Compat(shouldShowDeprecationNotice?: true): ParsingExtension {
11-
return named('v1-compat', (value, [_, key], context) => {
11+
return named('v1-compat', (value, [_, key], parentKeys) => {
1212
// only apply in top-level app-config property
13-
if (context[context.length - 1]?.[0] !== Root) {
13+
if (parentKeys[parentKeys.length - 1]?.[0] !== Root) {
1414
return false;
1515
}
1616

0 commit comments

Comments
 (0)