@@ -4,7 +4,7 @@ import { safeLoad as parseYAML, safeDump as stringifyYAML } from 'js-yaml';
44import { parse as parseJSON5 , stringify as stringifyJSON5 } from 'json5' ;
55import { Json , JsonObject } from '@app-config/utils' ;
66import { logger } from '@app-config/logging' ;
7- import { ParsedValue , ParsingExtension } from './parsed-value' ;
7+ import { ParsedValue , ParsingContext , ParsingExtension } from './parsed-value' ;
88import { AppConfigError , NotFoundError , ParsingError , BadFileType } from './errors' ;
99
1010export enum FileType {
@@ -30,15 +30,15 @@ export abstract class ConfigSource {
3030 }
3131
3232 /** Reads the contents of the source into a full ParsedValue (not the raw JSON, like readValue) */
33- async read ( extensions ?: ParsingExtension [ ] ) : Promise < ParsedValue > {
33+ async read ( extensions ?: ParsingExtension [ ] , context ?: ParsingContext ) : Promise < ParsedValue > {
3434 const rawValue = await this . readValue ( ) ;
3535
36- return ParsedValue . parse ( rawValue , this , extensions ) ;
36+ return ParsedValue . parse ( rawValue , this , extensions , undefined , context ) ;
3737 }
3838
3939 /** Ergonomic helper for chaining `source.read(extensions).then(v => v.toJSON())` */
40- async readToJSON ( extensions ?: ParsingExtension [ ] ) : Promise < Json > {
41- const parsed = await this . read ( extensions ) ;
40+ async readToJSON ( extensions ?: ParsingExtension [ ] , context ?: ParsingContext ) : Promise < Json > {
41+ const parsed = await this . read ( extensions , context ) ;
4242
4343 return parsed . toJSON ( ) ;
4444 }
@@ -82,8 +82,10 @@ export class CombinedSource extends ConfigSource {
8282 }
8383
8484 // override so that ParsedValue is directly from the originating ConfigSource
85- async read ( extensions ?: ParsingExtension [ ] ) : Promise < ParsedValue > {
86- const values = await Promise . all ( this . sources . map ( ( source ) => source . read ( extensions ) ) ) ;
85+ async read ( extensions ?: ParsingExtension [ ] , context ?: ParsingContext ) : Promise < ParsedValue > {
86+ const values = await Promise . all (
87+ this . sources . map ( ( source ) => source . read ( extensions , context ) ) ,
88+ ) ;
8789
8890 const merged = values . reduce < ParsedValue | undefined > ( ( acc , parsed ) => {
8991 if ( ! acc ) return parsed ;
@@ -137,11 +139,11 @@ export class FallbackSource extends ConfigSource {
137139 }
138140
139141 // override so that ParsedValue is directly from the originating ConfigSource
140- async read ( extensions ?: ParsingExtension [ ] ) : Promise < ParsedValue > {
142+ async read ( extensions ?: ParsingExtension [ ] , context ?: ParsingContext ) : Promise < ParsedValue > {
141143 // take the first value that comes back without an error
142144 for ( const source of this . sources ) {
143145 try {
144- const value = await source . read ( extensions ) ;
146+ const value = await source . read ( extensions , context ) ;
145147 logger . verbose ( `FallbackSource found successful source` ) ;
146148
147149 return value ;
0 commit comments