aws-core-utils
Advanced tools
Comparing version 2.1.0 to 2.1.1
{ | ||
"stages": { | ||
"defaultStreamNameStageSeparator": "_", | ||
"defaultResourceNameStageSeparator": "_", | ||
"defaultExtractInCase": "lower", | ||
"defaultInjectInCase": "upper" | ||
"stageHandlingSettings": { | ||
"streamNameStageSeparator": "_", | ||
"resourceNameStageSeparator": "_", | ||
"extractInCase": "lower", | ||
"injectInCase": "upper" | ||
} | ||
} |
{ | ||
"name": "aws-core-utils", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "Core utilities for working with Amazon Web Services (AWS), including ARNs, regions, stages, Lambdas, AWS errors, stream events, etc.", | ||
@@ -5,0 +5,0 @@ "author": "Byron du Preez", |
@@ -1,2 +0,2 @@ | ||
# aws-core-utils v2.1.0 | ||
# aws-core-utils v2.1.1 | ||
@@ -130,3 +130,3 @@ Core utilities for working with Amazon Web Services (AWS), including ARNs, regions, stages, Kinesis, Lambdas, AWS errors, stream events, etc. | ||
// To configure default stage handling, which sets the default behaviour of the next 4 functions | ||
// To configure default stage handling, which sets the default behaviour of the next 6 functions | ||
stages.configureDefaultStageHandling(context, forceConfiguration); | ||
@@ -226,2 +226,5 @@ | ||
### 2.1.1 | ||
- Added `getDefaultStageHandlingSettings` function to get the default stage handling settings | ||
### 2.1.0 | ||
@@ -228,0 +231,0 @@ |
@@ -35,2 +35,3 @@ 'use strict'; | ||
configureDefaultStageHandling: configureDefaultStageHandling, | ||
getDefaultStageHandlingSettings: getDefaultStageHandlingSettings, | ||
getStageHandlingSetting: getStageHandlingSetting, | ||
@@ -153,3 +154,3 @@ getStageHandlingFunction: getStageHandlingFunction, | ||
// If forceConfiguration is false check if the given context already has stage resolution configured on it | ||
// If forceConfiguration is false check if the given context already has stage handling configured on it | ||
// and, if so, do nothing more and simply return the context as is (to prevent overriding an earlier configuration) | ||
@@ -190,22 +191,55 @@ if (!forceConfiguration && isStageHandlingConfigured(context)) { | ||
function configureDefaultStageHandling(context, forceConfiguration) { | ||
// Load local defaults for separators and in case settings | ||
// If forceConfiguration is false check if the given context already has stage handling configured on it | ||
// and, if so, do nothing more and simply return the context as is (to prevent overriding an earlier configuration) | ||
if (!forceConfiguration && isStageHandlingConfigured(context)) { | ||
return context; | ||
} | ||
// Load local defaults for stage handling settings | ||
const config = require('./config.json'); | ||
// Use the locally configured default stream name stage separator (if non-blank); otherwise use underscore | ||
const streamNameStageSeparator = config.stages && isNotBlank(config.stages.defaultStreamNameStageSeparator) ? | ||
trim(config.stages.defaultStreamNameStageSeparator) : '_'; | ||
const defaultSettings = getDefaultStageHandlingSettings(config.stageHandlingSettings); | ||
// Use the locally configured default resource name stage separator (if non-blank); otherwise use underscore | ||
const resourceNameStageSeparator = config.stages && isNotBlank(config.stages.defaultResourceNameStageSeparator) ? | ||
trim(config.stages.defaultResourceNameStageSeparator) : '_'; | ||
return configureStageHandling(context, defaultSettings, forceConfiguration); | ||
} | ||
// Use the locally configured default extract in case (if non-blank); otherwise use 'lower' | ||
const extractInCase = config.stages && isNotBlank(config.stages.defaultExtractInCase) ? | ||
trim(config.stages.defaultExtractInCase) : 'lower'; | ||
/** | ||
* Simply returns the default stage handling settings, preferring settings in the given config object (if any) or in | ||
* config.stageHandlingSettings (if any) over the static default settings. | ||
* | ||
* This function is used internally by {@linkcode configureDefaultStageHandling}, but could also be used in custom | ||
* configurations to get the default settings as a base and override with your customisations before calling | ||
* {@linkcode configureStageHandling}. | ||
* | ||
* @param {Object} [config] - an optional config object containing either stage handling settings or a stageHandlingSettings object | ||
* @param {Object} [config.stageHandlingSettings] - an optional stageHandlingSettings object on the given config | ||
* object containing stage handling settings | ||
* @returns {StageHandlingSettings} a stage handling settings object | ||
*/ | ||
function getDefaultStageHandlingSettings(config) { | ||
if (config && config.stageHandlingSettings) { | ||
return getDefaultStageHandlingSettings(config.stageHandlingSettings); | ||
} | ||
// Use the locally configured default inject in case (if non-blank); otherwise use 'upper' | ||
const injectInCase = config.stages && isNotBlank(config.stages.defaultInjectInCase) ? | ||
trim(config.stages.defaultInjectInCase) : 'upper'; | ||
function select(config, propertyName, defaultValue) { | ||
const configuredValue = config ? config[propertyName] : undefined; | ||
return isNotBlank(configuredValue) ? trim(configuredValue) : defaultValue | ||
} | ||
const settings = { | ||
// Use the configured default stream name stage separator (if non-blank); otherwise use underscore | ||
const streamNameStageSeparator = select(config, 'streamNameStageSeparator', '_'); | ||
// Use the configured default resource name stage separator (if non-blank); otherwise use underscore | ||
const resourceNameStageSeparator = select(config, 'resourceNameStageSeparator', '_'); | ||
// Use the configured default extract in case (if non-blank); otherwise use 'lower' | ||
const extractInCase = select(config, 'extractInCase', 'lower'); | ||
// Use the configured default inject in case (if non-blank); otherwise use 'upper' | ||
const injectInCase = select(config, 'injectInCase', 'upper'); | ||
// Use the configured default default stage (if non-blank); otherwise use undefined | ||
const defaultStage = select(config, 'defaultStage', undefined); | ||
return { | ||
customToStage: undefined, | ||
@@ -225,9 +259,7 @@ convertAliasToStage: convertAliasToStage, | ||
defaultStage: undefined, | ||
defaultStage: defaultStage | ||
}; | ||
return configureStageHandling(context, settings, forceConfiguration); | ||
} | ||
/** | ||
/** | ||
* Returns the value of the named stage handling setting (if any) on the given context. | ||
@@ -234,0 +266,0 @@ * @param context - the context from which to fetch the named setting's value |
{ | ||
"name": "aws-core-utils-tests", | ||
"description": "Unit tests for aws-core-utils modules", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"author": "Byron du Preez", | ||
@@ -6,0 +6,0 @@ "license": "Apache-2.0", |
212996
3266
287