configorama 0.9.8 → 0.9.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -0
- package/index.d.ts +38 -29
- package/package.json +1 -1
- package/src/main.js +254 -101
- package/src/parsers/esm.js +0 -14
- package/src/parsers/typescript.js +0 -10
- package/src/resolvers/valueFromEval.js +69 -11
- package/src/resolvers/valueFromFile.js +1 -1
- package/src/resolvers/valueFromIf.js +75 -0
- package/src/resolvers/valueFromIf.test.js +66 -0
- package/src/resolvers/valueFromNumber.js +3 -0
- package/src/utils/handleSignalEvents.js +3 -4
- package/src/utils/lodash.js +18 -7
- package/src/utils/parsing/cloudformationSchema.js +1 -2
- package/src/utils/parsing/cloudformationSchema.test.js +14 -0
- package/src/utils/parsing/preProcess.js +220 -5
- package/src/utils/paths/getFullFilePath.js +6 -2
- package/src/utils/paths/getFullFilePath.test.js +18 -0
- package/src/utils/regex/index.js +18 -3
- package/src/utils/regex/index.test.js +24 -0
- package/src/utils/strings/quoteAware.js +141 -0
- package/src/utils/strings/replaceAll.js +13 -1
- package/src/utils/strings/splitByComma.js +25 -15
- package/src/utils/strings/splitByComma.test.js +19 -0
- package/src/utils/strings/splitOnPipe.js +30 -0
- package/src/utils/strings/splitOnPipe.test.js +68 -0
- package/src/utils/validation/isValidValue.test.js +1 -1
- package/src/utils/variables/findNestedVariables.js +8 -2
- package/types/src/main.d.ts +3 -1
- package/types/src/main.d.ts.map +1 -1
- package/types/src/parsers/esm.d.ts.map +1 -1
- package/types/src/parsers/typescript.d.ts.map +1 -1
- package/types/src/resolvers/valueFromEval.d.ts +1 -0
- package/types/src/resolvers/valueFromEval.d.ts.map +1 -1
- package/types/src/resolvers/valueFromIf.d.ts +7 -0
- package/types/src/resolvers/valueFromIf.d.ts.map +1 -0
- package/types/src/resolvers/valueFromNumber.d.ts.map +1 -1
- package/types/src/utils/handleSignalEvents.d.ts.map +1 -1
- package/types/src/utils/lodash.d.ts.map +1 -1
- package/types/src/utils/parsing/preProcess.d.ts +5 -1
- package/types/src/utils/parsing/preProcess.d.ts.map +1 -1
- package/types/src/utils/paths/getFullFilePath.d.ts.map +1 -1
- package/types/src/utils/regex/index.d.ts.map +1 -1
- package/types/src/utils/strings/quoteAware.d.ts +30 -0
- package/types/src/utils/strings/quoteAware.d.ts.map +1 -0
- package/types/src/utils/strings/replaceAll.d.ts.map +1 -1
- package/types/src/utils/strings/splitByComma.d.ts +1 -1
- package/types/src/utils/strings/splitByComma.d.ts.map +1 -1
- package/types/src/utils/strings/splitOnPipe.d.ts +8 -0
- package/types/src/utils/strings/splitOnPipe.d.ts.map +1 -0
- package/types/src/utils/variables/findNestedVariables.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ Configorama extends your configuration with a powerful variable system. It resol
|
|
|
16
16
|
- Git references
|
|
17
17
|
- Cron values
|
|
18
18
|
- Eval expressions
|
|
19
|
+
- If/conditional expressions
|
|
19
20
|
- Async/sync JS functions
|
|
20
21
|
- Filters (experimental)
|
|
21
22
|
- Functions (experimental)
|
|
@@ -45,6 +46,7 @@ See [tests](https://github.com/DavidWells/configorama/tree/master/tests) for mor
|
|
|
45
46
|
- [Git references](#git-references)
|
|
46
47
|
- [Cron Values](#cron-values)
|
|
47
48
|
- [Eval expressions](#eval-expressions)
|
|
49
|
+
- [If expressions](#if-expressions)
|
|
48
50
|
- [Filters (experimental)](#filters-experimental)
|
|
49
51
|
- [Functions (experimental)](#functions-experimental)
|
|
50
52
|
- [More Examples](#more-examples)
|
|
@@ -150,6 +152,7 @@ console.log(result.resolutionHistory) // Step-by-step resolution for each path
|
|
|
150
152
|
| git | ${git:value} | Git data |
|
|
151
153
|
| cron | ${cron(expr)} | Cron expressions |
|
|
152
154
|
| eval | ${eval(expr)} | Math/logic expressions |
|
|
155
|
+
| if | ${if(expr)} | Conditional expressions |
|
|
153
156
|
|
|
154
157
|
### Environment variables
|
|
155
158
|
|
|
@@ -715,6 +718,85 @@ strictEqual: ${eval("foo" === "foo")} # true
|
|
|
715
718
|
complex: ${eval((10 + 5) * 2)} # 30
|
|
716
719
|
```
|
|
717
720
|
|
|
721
|
+
### If expressions
|
|
722
|
+
|
|
723
|
+
Conditional expressions using ternary syntax. This is an alias for `eval` with a more intuitive name for conditionals.
|
|
724
|
+
|
|
725
|
+
```yml
|
|
726
|
+
# Basic ternary (condition ? "yes" : "no")
|
|
727
|
+
status: ${if((5 > 3) ? "yes" : "no")} # "yes"
|
|
728
|
+
|
|
729
|
+
# With variables
|
|
730
|
+
threshold: 50
|
|
731
|
+
value: 75
|
|
732
|
+
result: ${if((${self:value} > ${self:threshold}) ? "above" : "below")} # "above"
|
|
733
|
+
|
|
734
|
+
# Nested ternary (if/else if/else)
|
|
735
|
+
score: 85
|
|
736
|
+
grade: ${if((${self:score} >= 90) ? "A" : (${self:score} >= 80) ? "B" : "C")} # "B"
|
|
737
|
+
|
|
738
|
+
# Boolean result (no ternary needed)
|
|
739
|
+
isValid: ${if(${self:value} > 0)} # true
|
|
740
|
+
|
|
741
|
+
# Logical operators
|
|
742
|
+
enabled: true
|
|
743
|
+
count: 5
|
|
744
|
+
canProceed: ${if(${self:enabled} && ${self:count} > 0)} # true
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
**Supported operators:**
|
|
748
|
+
|
|
749
|
+
| Category | Operators |
|
|
750
|
+
|----------|-----------|
|
|
751
|
+
| Comparison | `==` `!=` `===` `!==` `>` `<` `>=` `<=` |
|
|
752
|
+
| Logical | `&&` `\|\|` `!` |
|
|
753
|
+
| Nullish | `??` |
|
|
754
|
+
| Ternary | `condition ? "yes" : "no"` |
|
|
755
|
+
|
|
756
|
+
**Serverless deployment examples:**
|
|
757
|
+
|
|
758
|
+
```yml
|
|
759
|
+
service: my-service
|
|
760
|
+
|
|
761
|
+
provider:
|
|
762
|
+
name: aws
|
|
763
|
+
stage: ${opt:stage, 'dev'}
|
|
764
|
+
region: ${opt:region, 'us-east-1'}
|
|
765
|
+
|
|
766
|
+
custom:
|
|
767
|
+
# Different memory by stage
|
|
768
|
+
memorySize: '${ if( ${provider.stage} === "prod" ) ? 1024 : 512 }'
|
|
769
|
+
|
|
770
|
+
# Different log retention by stage
|
|
771
|
+
logRetention: ${if(("${provider.stage}" === "prod") ? 30 : 7)}
|
|
772
|
+
|
|
773
|
+
# Enable features per environment
|
|
774
|
+
enableDebugEndpoints: ${if("${provider.stage}" !== "prod")}
|
|
775
|
+
enableMetrics: ${if("${provider.stage}" === "prod")}
|
|
776
|
+
|
|
777
|
+
# Regional settings
|
|
778
|
+
replicaCount: ${if(("${provider.region}" === "us-east-1") ? 3 : 1)}
|
|
779
|
+
|
|
780
|
+
# Conditional IAM role (use predefined role in prod, inline in dev)
|
|
781
|
+
useExternalRole: ${if("${provider.stage}" === "prod")}
|
|
782
|
+
role: ${if((${custom.useExternalRole}) ? "arn:aws:iam::123:role/prod-role" : null)}
|
|
783
|
+
|
|
784
|
+
functions:
|
|
785
|
+
api:
|
|
786
|
+
handler: handler.api
|
|
787
|
+
memorySize: ${custom.memorySize}
|
|
788
|
+
|
|
789
|
+
# Debug function - only deployed in non-prod
|
|
790
|
+
debug:
|
|
791
|
+
handler: handler.debug
|
|
792
|
+
enabled: ${custom.enableDebugEndpoints}
|
|
793
|
+
|
|
794
|
+
# Metrics processor - only in prod
|
|
795
|
+
metricsProcessor:
|
|
796
|
+
handler: handler.metrics
|
|
797
|
+
enabled: ${custom.enableMetrics}
|
|
798
|
+
```
|
|
799
|
+
|
|
718
800
|
### Filters (experimental)
|
|
719
801
|
|
|
720
802
|
Pipe resolved values through transformation functions like case conversion.
|
|
@@ -818,6 +900,7 @@ The `source` property defines how the config wizard handles each variable type:
|
|
|
818
900
|
| `${git:branch}` | `readonly` | Git repository data |
|
|
819
901
|
| `${cron(expr)}` | `readonly` | Cron expression conversion |
|
|
820
902
|
| `${eval(expr)}` | `readonly` | Math/logic evaluation |
|
|
903
|
+
| `${if(expr)}` | `readonly` | Conditional expressions |
|
|
821
904
|
|
|
822
905
|
## Options
|
|
823
906
|
|
package/index.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
// Type definitions for configorama
|
|
2
2
|
// Project: https://github.com/DavidWells/configorama
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
export * from './src/types'
|
|
6
|
-
|
|
7
|
-
export interface ConfigoramaSettings {
|
|
4
|
+
interface ConfigoramaSettings {
|
|
8
5
|
/** Options to populate for ${opt:xyz}. These could be CLI flags */
|
|
9
6
|
options?: Record<string, any>
|
|
10
7
|
/** Regex of variable syntax */
|
|
@@ -64,7 +61,7 @@ export interface ConfigoramaSettings {
|
|
|
64
61
|
filePathOverrides?: Record<string, string>
|
|
65
62
|
}
|
|
66
63
|
|
|
67
|
-
|
|
64
|
+
interface ConfigoramaResult<T = any> {
|
|
68
65
|
/** The variable syntax pattern used */
|
|
69
66
|
variableSyntax: RegExp
|
|
70
67
|
/** Map of variable types found */
|
|
@@ -83,7 +80,7 @@ export interface ConfigoramaResult<T = any> {
|
|
|
83
80
|
* Context passed to JS/TS/ESM config file functions
|
|
84
81
|
* Used when config files export a function: `export default function(ctx) { ... }`
|
|
85
82
|
*/
|
|
86
|
-
|
|
83
|
+
interface ConfigContext<T = any> {
|
|
87
84
|
/** The original unresolved configuration object */
|
|
88
85
|
originalConfig: T
|
|
89
86
|
/** The current (partially resolved) configuration object */
|
|
@@ -104,28 +101,40 @@ declare function configorama<T = any>(
|
|
|
104
101
|
settings: ConfigoramaSettings & { returnMetadata: true }
|
|
105
102
|
): Promise<ConfigoramaResult<T>>
|
|
106
103
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
104
|
+
declare namespace configorama {
|
|
105
|
+
// Re-export types for consumers
|
|
106
|
+
export { ConfigoramaSettings, ConfigoramaResult, ConfigContext }
|
|
107
|
+
|
|
108
|
+
/** Configorama sync API */
|
|
109
|
+
export function sync<T = any>(
|
|
110
|
+
configPathOrObject: string | object,
|
|
111
|
+
settings?: ConfigoramaSettings
|
|
112
|
+
): T
|
|
113
|
+
|
|
114
|
+
/** Analyze config variables without resolving them */
|
|
115
|
+
export function analyze(
|
|
116
|
+
configPathOrObject: string | object,
|
|
117
|
+
settings?: ConfigoramaSettings
|
|
118
|
+
): Promise<any>
|
|
119
|
+
|
|
120
|
+
/** Format utilities for parsing various config formats */
|
|
121
|
+
export const format: {
|
|
122
|
+
yaml: any
|
|
123
|
+
json: any
|
|
124
|
+
toml: any
|
|
125
|
+
ini: any
|
|
126
|
+
hcl: any
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** The Configorama class for advanced usage */
|
|
130
|
+
export const Configorama: any
|
|
131
|
+
|
|
132
|
+
/** Build variable syntax regex */
|
|
133
|
+
export function buildVariableSyntax(
|
|
134
|
+
prefix?: string,
|
|
135
|
+
suffix?: string,
|
|
136
|
+
excludePatterns?: string[]
|
|
137
|
+
): string
|
|
128
138
|
}
|
|
129
139
|
|
|
130
|
-
|
|
131
|
-
export const Configorama: any
|
|
140
|
+
export = configorama
|