@app-config/node
Advanced tools
Comparing version 2.5.0 to 2.5.1
@@ -0,1 +1,2 @@ | ||
import { ParsingContext } from '@app-config/core'; | ||
/** A mapping for "alias" names of environments, like "dev" => "development" */ | ||
@@ -6,3 +7,3 @@ export interface EnvironmentAliases { | ||
/** Options required for calling {@link currentEnvironment} */ | ||
export interface EnvironmentOptions { | ||
export declare type EnvironmentOptions = { | ||
/** Absolute override for what the current environment is, still abiding by aliases */ | ||
@@ -14,3 +15,3 @@ override?: string; | ||
envVarNames: string[]; | ||
} | ||
}; | ||
/** Default aliases that app-config will resolve for you */ | ||
@@ -30,1 +31,3 @@ export declare const defaultAliases: EnvironmentAliases; | ||
export declare function aliasesFor(env: string, aliases: EnvironmentAliases): string[]; | ||
export declare function environmentOptionsFromContext(context: ParsingContext): EnvironmentOptions | undefined; | ||
export declare function currentEnvFromContext(context: ParsingContext, options?: EnvironmentOptions): string | undefined; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.aliasesFor = exports.currentEnvironment = exports.asEnvOptions = exports.defaultEnvOptions = exports.defaultEnvVarNames = exports.defaultAliases = void 0; | ||
exports.currentEnvFromContext = exports.environmentOptionsFromContext = exports.aliasesFor = exports.currentEnvironment = exports.asEnvOptions = exports.defaultEnvOptions = exports.defaultEnvVarNames = exports.defaultAliases = void 0; | ||
const logging_1 = require("@app-config/logging"); | ||
@@ -89,2 +89,15 @@ /** Default aliases that app-config will resolve for you */ | ||
exports.aliasesFor = aliasesFor; | ||
function environmentOptionsFromContext(context) { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
return context.environmentOptions; | ||
} | ||
exports.environmentOptionsFromContext = environmentOptionsFromContext; | ||
function currentEnvFromContext(context, options) { | ||
const environmentOptions = environmentOptionsFromContext(context); | ||
if (environmentOptions) { | ||
return currentEnvironment(environmentOptions); | ||
} | ||
return currentEnvironment(options); | ||
} | ||
exports.currentEnvFromContext = currentEnvFromContext; | ||
//# sourceMappingURL=environment.js.map |
@@ -0,1 +1,2 @@ | ||
import { ParsingContext } from '@app-config/core'; | ||
/** A mapping for "alias" names of environments, like "dev" => "development" */ | ||
@@ -6,3 +7,3 @@ export interface EnvironmentAliases { | ||
/** Options required for calling {@link currentEnvironment} */ | ||
export interface EnvironmentOptions { | ||
export declare type EnvironmentOptions = { | ||
/** Absolute override for what the current environment is, still abiding by aliases */ | ||
@@ -14,3 +15,3 @@ override?: string; | ||
envVarNames: string[]; | ||
} | ||
}; | ||
/** Default aliases that app-config will resolve for you */ | ||
@@ -30,1 +31,3 @@ export declare const defaultAliases: EnvironmentAliases; | ||
export declare function aliasesFor(env: string, aliases: EnvironmentAliases): string[]; | ||
export declare function environmentOptionsFromContext(context: ParsingContext): EnvironmentOptions | undefined; | ||
export declare function currentEnvFromContext(context: ParsingContext, options?: EnvironmentOptions): string | undefined; |
@@ -82,2 +82,13 @@ import { logger } from '@app-config/logging'; | ||
} | ||
export function environmentOptionsFromContext(context) { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
return context.environmentOptions; | ||
} | ||
export function currentEnvFromContext(context, options) { | ||
const environmentOptions = environmentOptionsFromContext(context); | ||
if (environmentOptions) { | ||
return currentEnvironment(environmentOptions); | ||
} | ||
return currentEnvironment(options); | ||
} | ||
//# sourceMappingURL=environment.js.map |
@@ -1,2 +0,2 @@ | ||
import { ConfigSource, FileType, ParsedValue, ParsingExtension } from '@app-config/core'; | ||
import { ConfigSource, FileType, ParsedValue, ParsingExtension, ParsingContext } from '@app-config/core'; | ||
import { EnvironmentAliases, EnvironmentOptions } from './environment'; | ||
@@ -15,9 +15,9 @@ /** Read configuration from a single file */ | ||
private readonly environmentOptions; | ||
constructor(filePath: string, fileExtensions?: string[], environmentOptions?: EnvironmentOptions); | ||
/** @deprecated use constructor with environmentOptions instead */ | ||
constructor(filePath: string, environmentOverride?: string, environmentAliases?: EnvironmentAliases, fileExtensions?: string[], environmentSourceNames?: string[] | string); | ||
constructor(filePath: string, fileExtensions?: string[], environmentOptions?: EnvironmentOptions); | ||
private resolveSource; | ||
readContents(): Promise<[string, FileType]>; | ||
read(extensions?: ParsingExtension[]): Promise<ParsedValue>; | ||
read(extensions?: ParsingExtension[], context?: ParsingContext): Promise<ParsedValue>; | ||
} | ||
export declare function resolveFilepath(context: ConfigSource, filepath: string): string; | ||
export declare function resolveFilepath(source: ConfigSource, filepath: string): string; |
@@ -5,3 +5,3 @@ import { isAbsolute, join, dirname, resolve } from 'path'; | ||
import { logger } from '@app-config/logging'; | ||
import { aliasesFor, asEnvOptions, currentEnvironment, defaultEnvOptions, } from './environment'; | ||
import { aliasesFor, asEnvOptions, currentEnvFromContext, defaultEnvOptions, } from './environment'; | ||
/** Read configuration from a single file */ | ||
@@ -53,4 +53,4 @@ export class FileSource extends ConfigSource { | ||
// share 'resolveSource' so that read() returns a ParsedValue pointed to the FileSource, not FlexibleFileSource | ||
async resolveSource() { | ||
const environment = currentEnvironment(this.environmentOptions); | ||
async resolveSource(context) { | ||
const environment = currentEnvFromContext(context ?? {}, this.environmentOptions); | ||
const aliasesForCurrentEnv = environment | ||
@@ -83,13 +83,16 @@ ? aliasesFor(environment, this.environmentOptions.aliases) | ||
} | ||
async read(extensions) { | ||
const source = await this.resolveSource(); | ||
return source.read(extensions); | ||
async read(extensions, context) { | ||
const source = await this.resolveSource(context); | ||
return source.read(extensions, { | ||
...context, | ||
environmentOptions: this.environmentOptions, | ||
}); | ||
} | ||
} | ||
export function resolveFilepath(context, filepath) { | ||
export function resolveFilepath(source, filepath) { | ||
let resolvedPath = filepath; | ||
// resolve filepaths that are relative to the current FileSource | ||
if (!isAbsolute(filepath) && context instanceof FileSource) { | ||
resolvedPath = join(dirname(context.filePath), filepath); | ||
if (resolve(context.filePath) === resolvedPath) { | ||
if (!isAbsolute(filepath) && source instanceof FileSource) { | ||
resolvedPath = join(dirname(source.filePath), filepath); | ||
if (resolve(source.filePath) === resolvedPath) { | ||
throw new AppConfigError(`An extension tried to resolve to it's own file (${resolvedPath}).`); | ||
@@ -96,0 +99,0 @@ } |
export { FileSource, FlexibleFileSource, resolveFilepath } from './file-source'; | ||
export { currentEnvironment, defaultAliases, defaultEnvOptions, defaultEnvVarNames, asEnvOptions, EnvironmentAliases, EnvironmentOptions, } from './environment'; | ||
export { asEnvOptions, environmentOptionsFromContext, currentEnvironment, currentEnvFromContext, defaultAliases, defaultEnvOptions, defaultEnvVarNames, EnvironmentAliases, EnvironmentOptions, } from './environment'; | ||
export { EnvironmentSource } from './environment-source'; | ||
export { promptUser, promptUserWithRetry, consumeStdin } from './prompts'; |
export { FileSource, FlexibleFileSource, resolveFilepath } from './file-source'; | ||
export { currentEnvironment, defaultAliases, defaultEnvOptions, defaultEnvVarNames, asEnvOptions, } from './environment'; | ||
export { asEnvOptions, environmentOptionsFromContext, currentEnvironment, currentEnvFromContext, defaultAliases, defaultEnvOptions, defaultEnvVarNames, } from './environment'; | ||
export { EnvironmentSource } from './environment-source'; | ||
export { promptUser, promptUserWithRetry, consumeStdin } from './prompts'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { ConfigSource, FileType, ParsedValue, ParsingExtension } from '@app-config/core'; | ||
import { ConfigSource, FileType, ParsedValue, ParsingExtension, ParsingContext } from '@app-config/core'; | ||
import { EnvironmentAliases, EnvironmentOptions } from './environment'; | ||
@@ -15,9 +15,9 @@ /** Read configuration from a single file */ | ||
private readonly environmentOptions; | ||
constructor(filePath: string, fileExtensions?: string[], environmentOptions?: EnvironmentOptions); | ||
/** @deprecated use constructor with environmentOptions instead */ | ||
constructor(filePath: string, environmentOverride?: string, environmentAliases?: EnvironmentAliases, fileExtensions?: string[], environmentSourceNames?: string[] | string); | ||
constructor(filePath: string, fileExtensions?: string[], environmentOptions?: EnvironmentOptions); | ||
private resolveSource; | ||
readContents(): Promise<[string, FileType]>; | ||
read(extensions?: ParsingExtension[]): Promise<ParsedValue>; | ||
read(extensions?: ParsingExtension[], context?: ParsingContext): Promise<ParsedValue>; | ||
} | ||
export declare function resolveFilepath(context: ConfigSource, filepath: string): string; | ||
export declare function resolveFilepath(source: ConfigSource, filepath: string): string; |
@@ -57,4 +57,4 @@ "use strict"; | ||
// share 'resolveSource' so that read() returns a ParsedValue pointed to the FileSource, not FlexibleFileSource | ||
async resolveSource() { | ||
const environment = environment_1.currentEnvironment(this.environmentOptions); | ||
async resolveSource(context) { | ||
const environment = environment_1.currentEnvFromContext(context !== null && context !== void 0 ? context : {}, this.environmentOptions); | ||
const aliasesForCurrentEnv = environment | ||
@@ -87,14 +87,14 @@ ? environment_1.aliasesFor(environment, this.environmentOptions.aliases) | ||
} | ||
async read(extensions) { | ||
const source = await this.resolveSource(); | ||
return source.read(extensions); | ||
async read(extensions, context) { | ||
const source = await this.resolveSource(context); | ||
return source.read(extensions, Object.assign(Object.assign({}, context), { environmentOptions: this.environmentOptions })); | ||
} | ||
} | ||
exports.FlexibleFileSource = FlexibleFileSource; | ||
function resolveFilepath(context, filepath) { | ||
function resolveFilepath(source, filepath) { | ||
let resolvedPath = filepath; | ||
// resolve filepaths that are relative to the current FileSource | ||
if (!path_1.isAbsolute(filepath) && context instanceof FileSource) { | ||
resolvedPath = path_1.join(path_1.dirname(context.filePath), filepath); | ||
if (path_1.resolve(context.filePath) === resolvedPath) { | ||
if (!path_1.isAbsolute(filepath) && source instanceof FileSource) { | ||
resolvedPath = path_1.join(path_1.dirname(source.filePath), filepath); | ||
if (path_1.resolve(source.filePath) === resolvedPath) { | ||
throw new core_1.AppConfigError(`An extension tried to resolve to it's own file (${resolvedPath}).`); | ||
@@ -101,0 +101,0 @@ } |
export { FileSource, FlexibleFileSource, resolveFilepath } from './file-source'; | ||
export { currentEnvironment, defaultAliases, defaultEnvOptions, defaultEnvVarNames, asEnvOptions, EnvironmentAliases, EnvironmentOptions, } from './environment'; | ||
export { asEnvOptions, environmentOptionsFromContext, currentEnvironment, currentEnvFromContext, defaultAliases, defaultEnvOptions, defaultEnvVarNames, EnvironmentAliases, EnvironmentOptions, } from './environment'; | ||
export { EnvironmentSource } from './environment-source'; | ||
export { promptUser, promptUserWithRetry, consumeStdin } from './prompts'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.consumeStdin = exports.promptUserWithRetry = exports.promptUser = exports.EnvironmentSource = exports.asEnvOptions = exports.defaultEnvVarNames = exports.defaultEnvOptions = exports.defaultAliases = exports.currentEnvironment = exports.resolveFilepath = exports.FlexibleFileSource = exports.FileSource = void 0; | ||
exports.consumeStdin = exports.promptUserWithRetry = exports.promptUser = exports.EnvironmentSource = exports.defaultEnvVarNames = exports.defaultEnvOptions = exports.defaultAliases = exports.currentEnvFromContext = exports.currentEnvironment = exports.environmentOptionsFromContext = exports.asEnvOptions = exports.resolveFilepath = exports.FlexibleFileSource = exports.FileSource = void 0; | ||
var file_source_1 = require("./file-source"); | ||
@@ -9,7 +9,9 @@ Object.defineProperty(exports, "FileSource", { enumerable: true, get: function () { return file_source_1.FileSource; } }); | ||
var environment_1 = require("./environment"); | ||
Object.defineProperty(exports, "asEnvOptions", { enumerable: true, get: function () { return environment_1.asEnvOptions; } }); | ||
Object.defineProperty(exports, "environmentOptionsFromContext", { enumerable: true, get: function () { return environment_1.environmentOptionsFromContext; } }); | ||
Object.defineProperty(exports, "currentEnvironment", { enumerable: true, get: function () { return environment_1.currentEnvironment; } }); | ||
Object.defineProperty(exports, "currentEnvFromContext", { enumerable: true, get: function () { return environment_1.currentEnvFromContext; } }); | ||
Object.defineProperty(exports, "defaultAliases", { enumerable: true, get: function () { return environment_1.defaultAliases; } }); | ||
Object.defineProperty(exports, "defaultEnvOptions", { enumerable: true, get: function () { return environment_1.defaultEnvOptions; } }); | ||
Object.defineProperty(exports, "defaultEnvVarNames", { enumerable: true, get: function () { return environment_1.defaultEnvVarNames; } }); | ||
Object.defineProperty(exports, "asEnvOptions", { enumerable: true, get: function () { return environment_1.asEnvOptions; } }); | ||
var environment_source_1 = require("./environment-source"); | ||
@@ -16,0 +18,0 @@ Object.defineProperty(exports, "EnvironmentSource", { enumerable: true, get: function () { return environment_source_1.EnvironmentSource; } }); |
{ | ||
"name": "@app-config/node", | ||
"description": "Node.js API for @app-config", | ||
"version": "2.5.0", | ||
"version": "2.5.1", | ||
"license": "MPL-2.0", | ||
@@ -33,4 +33,4 @@ "author": { | ||
"dependencies": { | ||
"@app-config/core": "^2.5.0", | ||
"@app-config/logging": "^2.5.0", | ||
"@app-config/core": "^2.5.1", | ||
"@app-config/logging": "^2.5.1", | ||
"@types/prompts": "2", | ||
@@ -41,3 +41,3 @@ "fs-extra": "9", | ||
"devDependencies": { | ||
"@app-config/test-utils": "^2.5.0", | ||
"@app-config/test-utils": "^2.5.1", | ||
"@types/fs-extra": "9" | ||
@@ -44,0 +44,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
52750
656
Updated@app-config/core@^2.5.1
Updated@app-config/logging@^2.5.1