configorama 0.9.8 → 0.9.11
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/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
|
|