configorama 0.6.18 → 0.7.0
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 +78 -2
- package/cli.js +1 -0
- package/index.d.ts +90 -37
- package/package.json +8 -2
- package/src/index.js +42 -14
- package/src/main.js +135 -62
- package/src/parsers/index.js +10 -0
- package/src/parsers/typescript.js +20 -43
- package/src/parsers/yaml.js +35 -2
- package/src/resolvers/valueFromFile.js +87 -24
- package/src/resolvers/valueFromGit.js +11 -3
- package/src/utils/encoders/js-fixes.js +44 -0
- package/src/utils/parsing/mergeByKeys.js +4 -3
- package/src/utils/parsing/parse.js +4 -2
- package/src/utils/parsing/preProcess.js +42 -25
- package/src/utils/parsing/preProcess.test.js +214 -0
- package/src/utils/paths/getFullFilePath.js +1 -1
- package/src/utils/resolution/preResolveVariable.js +1 -0
- package/src/utils/strings/quoteUtils.js +2 -2
- package/src/utils/strings/splitCsv.js +1 -1
- package/src/utils/ui/logs.js +4 -4
- package/src/utils/validation/warnIfNotFound.js +3 -3
- package/src/utils/variables/findNestedVariables.js +2 -2
- package/src/utils/variables/variableUtils.js +43 -0
- package/src/utils/variables/variableUtils.test.js +38 -1
- package/types/cli.d.ts +3 -0
- package/types/cli.d.ts.map +1 -0
- package/types/src/functions/md5.d.ts +3 -0
- package/types/src/functions/md5.d.ts.map +1 -0
- package/types/src/index.d.ts +100 -0
- package/types/src/index.d.ts.map +1 -0
- package/types/src/main.d.ts +275 -0
- package/types/src/main.d.ts.map +1 -0
- package/types/src/parsers/esm.d.ts +15 -0
- package/types/src/parsers/esm.d.ts.map +1 -0
- package/types/src/parsers/hcl.d.ts +1 -0
- package/types/src/parsers/hcl.d.ts.map +1 -0
- package/types/src/parsers/index.d.ts +18 -0
- package/types/src/parsers/index.d.ts.map +1 -0
- package/types/src/parsers/ini.d.ts +6 -0
- package/types/src/parsers/ini.d.ts.map +1 -0
- package/types/src/parsers/json5.d.ts +10 -0
- package/types/src/parsers/json5.d.ts.map +1 -0
- package/types/src/parsers/toml.d.ts +7 -0
- package/types/src/parsers/toml.d.ts.map +1 -0
- package/types/src/parsers/typescript.d.ts +15 -0
- package/types/src/parsers/typescript.d.ts.map +1 -0
- package/types/src/parsers/yaml.d.ts +45 -0
- package/types/src/parsers/yaml.d.ts.map +1 -0
- package/types/src/resolvers/valueFromCron.d.ts +14 -0
- package/types/src/resolvers/valueFromCron.d.ts.map +1 -0
- package/types/src/resolvers/valueFromEnv.d.ts +8 -0
- package/types/src/resolvers/valueFromEnv.d.ts.map +1 -0
- package/types/src/resolvers/valueFromEval.d.ts +7 -0
- package/types/src/resolvers/valueFromEval.d.ts.map +1 -0
- package/types/src/resolvers/valueFromFile.d.ts +58 -0
- package/types/src/resolvers/valueFromFile.d.ts.map +1 -0
- package/types/src/resolvers/valueFromGit.d.ts +11 -0
- package/types/src/resolvers/valueFromGit.d.ts.map +1 -0
- package/types/src/resolvers/valueFromNumber.d.ts +6 -0
- package/types/src/resolvers/valueFromNumber.d.ts.map +1 -0
- package/types/src/resolvers/valueFromOptions.d.ts +9 -0
- package/types/src/resolvers/valueFromOptions.d.ts.map +1 -0
- package/types/src/resolvers/valueFromSelf.d.ts +1 -0
- package/types/src/resolvers/valueFromSelf.d.ts.map +1 -0
- package/types/src/resolvers/valueFromString.d.ts +6 -0
- package/types/src/resolvers/valueFromString.d.ts.map +1 -0
- package/types/src/sync.d.ts +3 -0
- package/types/src/sync.d.ts.map +1 -0
- package/types/src/utils/PromiseTracker.d.ts +19 -0
- package/types/src/utils/PromiseTracker.d.ts.map +1 -0
- package/types/src/utils/encoders/index.d.ts +2 -0
- package/types/src/utils/encoders/index.d.ts.map +1 -0
- package/types/src/utils/encoders/js-fixes.d.ts +23 -0
- package/types/src/utils/encoders/js-fixes.d.ts.map +1 -0
- package/types/src/utils/encoders/unknown-values.d.ts +18 -0
- package/types/src/utils/encoders/unknown-values.d.ts.map +1 -0
- package/types/src/utils/handleSignalEvents.d.ts +3 -0
- package/types/src/utils/handleSignalEvents.d.ts.map +1 -0
- package/types/src/utils/lodash.d.ts +4 -0
- package/types/src/utils/lodash.d.ts.map +1 -0
- package/types/src/utils/parsing/arrayToJsonPath.d.ts +5 -0
- package/types/src/utils/parsing/arrayToJsonPath.d.ts.map +1 -0
- package/types/src/utils/parsing/cloudformationSchema.d.ts +2 -0
- package/types/src/utils/parsing/cloudformationSchema.d.ts.map +1 -0
- package/types/src/utils/parsing/enrichMetadata.d.ts +17 -0
- package/types/src/utils/parsing/enrichMetadata.d.ts.map +1 -0
- package/types/src/utils/parsing/mergeByKeys.d.ts +5 -0
- package/types/src/utils/parsing/mergeByKeys.d.ts.map +1 -0
- package/types/src/utils/parsing/parse.d.ts +54 -0
- package/types/src/utils/parsing/parse.d.ts.map +1 -0
- package/types/src/utils/parsing/preProcess.d.ts +10 -0
- package/types/src/utils/parsing/preProcess.d.ts.map +1 -0
- package/types/src/utils/paths/filePathUtils.d.ts +32 -0
- package/types/src/utils/paths/filePathUtils.d.ts.map +1 -0
- package/types/src/utils/paths/findLineForKey.d.ts +12 -0
- package/types/src/utils/paths/findLineForKey.d.ts.map +1 -0
- package/types/src/utils/paths/findProjectRoot.d.ts +2 -0
- package/types/src/utils/paths/findProjectRoot.d.ts.map +1 -0
- package/types/src/utils/paths/getFullFilePath.d.ts +25 -0
- package/types/src/utils/paths/getFullFilePath.d.ts.map +1 -0
- package/types/src/utils/paths/resolveAlias.d.ts +14 -0
- package/types/src/utils/paths/resolveAlias.d.ts.map +1 -0
- package/types/src/utils/regex/index.d.ts +14 -0
- package/types/src/utils/regex/index.d.ts.map +1 -0
- package/types/src/utils/resolution/preResolveVariable.d.ts +51 -0
- package/types/src/utils/resolution/preResolveVariable.d.ts.map +1 -0
- package/types/src/utils/strings/bracketMatcher.d.ts +25 -0
- package/types/src/utils/strings/bracketMatcher.d.ts.map +1 -0
- package/types/src/utils/strings/formatFunctionArgs.d.ts +3 -0
- package/types/src/utils/strings/formatFunctionArgs.d.ts.map +1 -0
- package/types/src/utils/strings/quoteUtils.d.ts +31 -0
- package/types/src/utils/strings/quoteUtils.d.ts.map +1 -0
- package/types/src/utils/strings/replaceAll.d.ts +9 -0
- package/types/src/utils/strings/replaceAll.d.ts.map +1 -0
- package/types/src/utils/strings/splitByComma.d.ts +2 -0
- package/types/src/utils/strings/splitByComma.d.ts.map +1 -0
- package/types/src/utils/strings/splitCsv.d.ts +10 -0
- package/types/src/utils/strings/splitCsv.d.ts.map +1 -0
- package/types/src/utils/strings/textUtils.d.ts +15 -0
- package/types/src/utils/strings/textUtils.d.ts.map +1 -0
- package/types/src/utils/ui/chalk.d.ts +70 -0
- package/types/src/utils/ui/chalk.d.ts.map +1 -0
- package/types/src/utils/ui/configWizard.d.ts +67 -0
- package/types/src/utils/ui/configWizard.d.ts.map +1 -0
- package/types/src/utils/ui/createEditorLink.d.ts +11 -0
- package/types/src/utils/ui/createEditorLink.d.ts.map +1 -0
- package/types/src/utils/ui/deep-log.d.ts +3 -0
- package/types/src/utils/ui/deep-log.d.ts.map +1 -0
- package/types/src/utils/ui/logs.d.ts +2 -0
- package/types/src/utils/ui/logs.d.ts.map +1 -0
- package/types/src/utils/validation/warnIfNotFound.d.ts +15 -0
- package/types/src/utils/validation/warnIfNotFound.d.ts.map +1 -0
- package/types/src/utils/variables/appendDeepVariable.d.ts +3 -0
- package/types/src/utils/variables/appendDeepVariable.d.ts.map +1 -0
- package/types/src/utils/variables/cleanVariable.d.ts +3 -0
- package/types/src/utils/variables/cleanVariable.d.ts.map +1 -0
- package/types/src/utils/variables/findNestedVariables.d.ts +23 -0
- package/types/src/utils/variables/findNestedVariables.d.ts.map +1 -0
- package/types/src/utils/variables/getVariableType.d.ts +8 -0
- package/types/src/utils/variables/getVariableType.d.ts.map +1 -0
- package/types/src/utils/variables/variableUtils.d.ts +21 -0
- package/types/src/utils/variables/variableUtils.d.ts.map +1 -0
package/README.md
CHANGED
|
@@ -229,10 +229,10 @@ asyncJSValue: ${file(./async-value.js)}
|
|
|
229
229
|
# resolves to 'asyncval'
|
|
230
230
|
```
|
|
231
231
|
|
|
232
|
-
`${file(./
|
|
232
|
+
`${file(./async-value.js)}` will call into `async-value` and run/resolve the async function. Return values can be strings, objects, arrays, etc.
|
|
233
233
|
|
|
234
234
|
```js
|
|
235
|
-
async function fetchSecretsFromRemoteStore(
|
|
235
|
+
async function fetchSecretsFromRemoteStore() {
|
|
236
236
|
await delay(1000)
|
|
237
237
|
return 'asyncval'
|
|
238
238
|
}
|
|
@@ -240,6 +240,82 @@ async function fetchSecretsFromRemoteStore(config) {
|
|
|
240
240
|
module.exports = fetchSecretsFromRemoteStore
|
|
241
241
|
```
|
|
242
242
|
|
|
243
|
+
#### Passing arguments to functions
|
|
244
|
+
|
|
245
|
+
You can pass arguments from your config to JavaScript/TypeScript functions:
|
|
246
|
+
|
|
247
|
+
```yml
|
|
248
|
+
foo: bar
|
|
249
|
+
baz:
|
|
250
|
+
qux: quux
|
|
251
|
+
|
|
252
|
+
# Pass resolved values as arguments
|
|
253
|
+
secrets: ${file(./fetch-secrets.js, ${self:foo}, ${self:baz})}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Arguments are passed in order, with the config context always last:
|
|
257
|
+
|
|
258
|
+
```js
|
|
259
|
+
/**
|
|
260
|
+
* @param {string} foo - First arg from YAML ('bar')
|
|
261
|
+
* @param {object} baz - Second arg from YAML ({ qux: 'quux' })
|
|
262
|
+
* @param {import('configorama').ConfigContext} ctx - Config context (always last)
|
|
263
|
+
*/
|
|
264
|
+
async function fetchSecrets(foo, baz, ctx) {
|
|
265
|
+
console.log(foo) // 'bar'
|
|
266
|
+
console.log(baz) // { qux: 'quux' }
|
|
267
|
+
console.log(ctx.originalConfig) // Original unresolved config
|
|
268
|
+
console.log(ctx.currentConfig) // Current partially-resolved config
|
|
269
|
+
console.log(ctx.options) // Options passed to configorama
|
|
270
|
+
|
|
271
|
+
return { secret: 'value' }
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
module.exports = fetchSecrets
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
#### ConfigContext
|
|
278
|
+
|
|
279
|
+
The `ctx` parameter (always the last argument) provides access to:
|
|
280
|
+
|
|
281
|
+
| Property | Description |
|
|
282
|
+
|----------|-------------|
|
|
283
|
+
| `originalConfig` | The original unresolved configuration object |
|
|
284
|
+
| `currentConfig` | The current (partially resolved) configuration |
|
|
285
|
+
| `options` | Options passed to configorama (populates `${opt:xyz}` variables) |
|
|
286
|
+
|
|
287
|
+
TypeScript users can import the type:
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
import type { ConfigContext } from 'configorama'
|
|
291
|
+
|
|
292
|
+
async function fetchSecrets(
|
|
293
|
+
foo: string,
|
|
294
|
+
baz: { qux: string },
|
|
295
|
+
ctx: ConfigContext
|
|
296
|
+
): Promise<string> {
|
|
297
|
+
// Full type support for ctx properties
|
|
298
|
+
return 'secret-value'
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export = fetchSecrets
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
#### Functions without arguments
|
|
305
|
+
|
|
306
|
+
If you don't need arguments, the function still receives `ctx` as its only parameter:
|
|
307
|
+
|
|
308
|
+
```js
|
|
309
|
+
// No args - ctx is the only parameter
|
|
310
|
+
async function getSecrets(ctx) {
|
|
311
|
+
return ctx.options.stage === 'prod'
|
|
312
|
+
? 'prod-secret'
|
|
313
|
+
: 'dev-secret'
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
module.exports = getSecrets
|
|
317
|
+
```
|
|
318
|
+
|
|
243
319
|
### TypeScript file references
|
|
244
320
|
|
|
245
321
|
Execute TypeScript files using tsx (recommended) or ts-node.
|
package/cli.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,45 +1,98 @@
|
|
|
1
1
|
// Type definitions for configorama
|
|
2
2
|
// Project: https://github.com/DavidWells/configorama
|
|
3
|
-
// Definitions by: Claude AI
|
|
4
3
|
|
|
5
|
-
//
|
|
4
|
+
// Re-export variable validation types
|
|
6
5
|
export * from './src/types'
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
export interface ConfigoramaSettings {
|
|
8
|
+
/** Options to populate for ${opt:xyz}. These could be CLI flags */
|
|
9
|
+
options?: Record<string, any>
|
|
10
|
+
/** Regex of variable syntax */
|
|
11
|
+
syntax?: string
|
|
12
|
+
/** cwd of config. Needed if raw object passed in instead of file path */
|
|
13
|
+
configDir?: string
|
|
14
|
+
/** Array of custom variable sources */
|
|
15
|
+
variableSources?: any[]
|
|
16
|
+
/** Object of custom filters */
|
|
17
|
+
filters?: Record<string, Function>
|
|
18
|
+
/** Object of custom functions */
|
|
19
|
+
functions?: Record<string, Function>
|
|
20
|
+
/** Allow unknown variables to pass through without throwing errors */
|
|
21
|
+
allowUnknownVars?: boolean
|
|
22
|
+
/** Allow undefined values to pass through without throwing errors */
|
|
23
|
+
allowUndefinedValues?: boolean
|
|
24
|
+
/** Values passed into .js config files if user using javascript config */
|
|
25
|
+
dynamicArgs?: object | Function
|
|
26
|
+
/** Return both config and metadata about variables found */
|
|
27
|
+
returnMetadata?: boolean
|
|
28
|
+
/** Keys to merge in arrays of objects */
|
|
29
|
+
mergeKeys?: string[]
|
|
30
|
+
/** Map of file paths to override */
|
|
31
|
+
filePathOverrides?: Record<string, string>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ConfigoramaResult<T = any> {
|
|
35
|
+
/** The variable syntax pattern used */
|
|
36
|
+
variableSyntax: RegExp
|
|
37
|
+
/** Map of variable types found */
|
|
38
|
+
variableTypes: Record<string, any>
|
|
39
|
+
/** The resolved configuration object */
|
|
40
|
+
config: T
|
|
41
|
+
/** The original unresolved configuration */
|
|
42
|
+
originalConfig: any
|
|
43
|
+
/** Metadata about variables found and resolved */
|
|
44
|
+
metadata: any
|
|
45
|
+
/** Resolution history per path for debugging */
|
|
46
|
+
resolutionHistory: any
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Context passed to JS/TS/ESM config file functions
|
|
51
|
+
* Used when config files export a function: `export default function(ctx) { ... }`
|
|
52
|
+
*/
|
|
53
|
+
export interface ConfigContext<T = any> {
|
|
54
|
+
/** The original unresolved configuration object */
|
|
55
|
+
originalConfig: T
|
|
56
|
+
/** The current (partially resolved) configuration object */
|
|
57
|
+
currentConfig: T
|
|
58
|
+
/** Options passed to configorama (populates ${opt:xyz} variables) */
|
|
59
|
+
options: Record<string, any>
|
|
60
|
+
}
|
|
17
61
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
options?: Record<string, any>
|
|
23
|
-
variableSources?: Record<string, any>
|
|
24
|
-
[key: string]: any
|
|
25
|
-
}
|
|
26
|
-
): any
|
|
27
|
-
|
|
28
|
-
// Generic typed versions for better TypeScript experience
|
|
29
|
-
export function configorama<T>(
|
|
30
|
-
configPath: string,
|
|
31
|
-
options?: {
|
|
32
|
-
options?: Record<string, any>
|
|
33
|
-
variableSources?: Record<string, any>
|
|
34
|
-
[key: string]: any
|
|
35
|
-
}
|
|
62
|
+
/** Configorama async API - returns resolved config */
|
|
63
|
+
declare function configorama<T = any>(
|
|
64
|
+
configPathOrObject: string | object,
|
|
65
|
+
settings?: ConfigoramaSettings & { returnMetadata?: false }
|
|
36
66
|
): Promise<T>
|
|
37
67
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
68
|
+
/** Configorama async API - returns config with metadata */
|
|
69
|
+
declare function configorama<T = any>(
|
|
70
|
+
configPathOrObject: string | object,
|
|
71
|
+
settings: ConfigoramaSettings & { returnMetadata: true }
|
|
72
|
+
): Promise<ConfigoramaResult<T>>
|
|
73
|
+
|
|
74
|
+
export default configorama
|
|
75
|
+
|
|
76
|
+
/** Configorama sync API */
|
|
77
|
+
export function sync<T = any>(
|
|
78
|
+
configPathOrObject: string | object,
|
|
79
|
+
settings?: ConfigoramaSettings
|
|
80
|
+
): T
|
|
81
|
+
|
|
82
|
+
/** Analyze config variables without resolving them */
|
|
83
|
+
export function analyze(
|
|
84
|
+
configPathOrObject: string | object,
|
|
85
|
+
settings?: ConfigoramaSettings
|
|
86
|
+
): Promise<any>
|
|
87
|
+
|
|
88
|
+
/** Format utilities for parsing various config formats */
|
|
89
|
+
export const format: {
|
|
90
|
+
yaml: any
|
|
91
|
+
json: any
|
|
92
|
+
toml: any
|
|
93
|
+
ini: any
|
|
94
|
+
hcl: any
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The Configorama class for advanced usage */
|
|
98
|
+
export const Configorama: any
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "configorama",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Variable support for configuration files",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"files": [
|
|
12
12
|
"cli.js",
|
|
13
13
|
"src",
|
|
14
|
+
"types",
|
|
14
15
|
"index.d.ts",
|
|
15
16
|
"package.json",
|
|
16
17
|
"package-lock.json",
|
|
@@ -29,6 +30,10 @@
|
|
|
29
30
|
"test:api": "uvu tests/api api.test.js",
|
|
30
31
|
"test:lib": "uvu src \".*\\.test.js$\"",
|
|
31
32
|
"watch": "watchlist tests -- npm test",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"types": "tsc",
|
|
35
|
+
"types:watch": "tsc --watch",
|
|
36
|
+
"prepublishOnly": "npm run types",
|
|
32
37
|
"publish": "git push origin && git push origin --tags",
|
|
33
38
|
"release:patch": "npm version patch && npm publish",
|
|
34
39
|
"release:minor": "npm version minor && npm publish",
|
|
@@ -74,12 +79,13 @@
|
|
|
74
79
|
"lodash.split": "^4.4.2",
|
|
75
80
|
"minimist": "^1.2.8",
|
|
76
81
|
"promise.prototype.finally": "^3.1.8",
|
|
77
|
-
"safe-chalk": "^1.0.
|
|
82
|
+
"safe-chalk": "^1.0.4",
|
|
78
83
|
"subscript": "^9.1.0",
|
|
79
84
|
"sync-rpc": "^1.3.6",
|
|
80
85
|
"traverse": "^0.6.8"
|
|
81
86
|
},
|
|
82
87
|
"devDependencies": {
|
|
88
|
+
"@types/node": "^24.10.1",
|
|
83
89
|
"markdown-magic": "^3.4.0",
|
|
84
90
|
"tsx": "^4.7.0",
|
|
85
91
|
"typescript": "^5.8.3",
|
package/src/index.js
CHANGED
|
@@ -4,21 +4,39 @@ const enrichMetadata = require('./utils/parsing/enrichMetadata')
|
|
|
4
4
|
|
|
5
5
|
module.exports.Configorama = Configorama
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {Object} ConfigoramaSettings
|
|
9
|
+
* @property {Object.<string, any>} [options] - options to populate for ${opt:xyz}. These could be CLI flags
|
|
10
|
+
* @property {string} [syntax] - Regex of variable syntax
|
|
11
|
+
* @property {string} [configDir] - cwd of config. Needed if raw object passed in instead of file path
|
|
12
|
+
* @property {Array} [variableSources] - array of custom variable sources
|
|
13
|
+
* @property {Object.<string, Function>} [filters] - Object of custom filters
|
|
14
|
+
* @property {Object.<string, Function>} [functions] - Object of custom functions
|
|
15
|
+
* @property {boolean} [allowUnknownVars] - allow unknown variables to pass through without throwing errors
|
|
16
|
+
* @property {boolean} [allowUndefinedValues] - allow undefined values to pass through without throwing errors
|
|
17
|
+
* @property {Object|Function} [dynamicArgs] - values passed into .js config files if user using javascript config
|
|
18
|
+
* @property {boolean} [returnMetadata] - return both config and metadata about variables found
|
|
19
|
+
* @property {string[]} [mergeKeys] - keys to merge in arrays of objects
|
|
20
|
+
* @property {Object.<string, string>} [filePathOverrides] - map of file paths to override
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @template [T=any]
|
|
25
|
+
* @typedef {Object} ConfigoramaResult
|
|
26
|
+
* @property {RegExp} variableSyntax - The variable syntax pattern used
|
|
27
|
+
* @property {Object.<string, any>} variableTypes - Map of variable types found
|
|
28
|
+
* @property {T} config - The resolved configuration object
|
|
29
|
+
* @property {Object} originalConfig - The original unresolved configuration
|
|
30
|
+
* @property {Object} metadata - Metadata about variables found and resolved
|
|
31
|
+
* @property {Object} resolutionHistory - Resolution history per path for debugging
|
|
32
|
+
*/
|
|
33
|
+
|
|
7
34
|
/**
|
|
8
35
|
* Configorama async API
|
|
9
|
-
* @
|
|
10
|
-
* @param {
|
|
11
|
-
* @param {
|
|
12
|
-
* @
|
|
13
|
-
* @param {string} [settings.configDir] - cwd of config. Needed if raw object passed in instead of file path
|
|
14
|
-
* @param {array} [settings.variableSources] - array of custom variable sources
|
|
15
|
-
* @param {object} [settings.filters] - Object of of custom filters
|
|
16
|
-
* @param {object} [settings.functions] - Object of of custom functions
|
|
17
|
-
* @param {boolean} [settings.allowUnknownVars] - allow unknown variables to pass through without throwing errors
|
|
18
|
-
* @param {boolean} [settings.allowUndefinedValues] - allow undefined values to pass through without throwing errors
|
|
19
|
-
* @param {object|function} [settings.dynamicArgs] - values passed into .js config files if user using javascript config.
|
|
20
|
-
* @param {boolean} [settings.returnMetadata] - return both config and metadata about variables found
|
|
21
|
-
* @return {Promise} resolved configuration or {config, metadata} if returnMetadata is true
|
|
36
|
+
* @template [T=any]
|
|
37
|
+
* @param {string|Object} configPathOrObject - Path to config file or raw javascript config object
|
|
38
|
+
* @param {ConfigoramaSettings} [settings] - Configuration settings
|
|
39
|
+
* @returns {Promise<T | ConfigoramaResult<T>>} resolved configuration or {config, metadata} if returnMetadata is true
|
|
22
40
|
*/
|
|
23
41
|
module.exports = async (configPathOrObject, settings = {}) => {
|
|
24
42
|
const instance = new Configorama(configPathOrObject, settings)
|
|
@@ -69,6 +87,13 @@ module.exports = async (configPathOrObject, settings = {}) => {
|
|
|
69
87
|
return config
|
|
70
88
|
}
|
|
71
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Configorama sync API
|
|
92
|
+
* @template [T=any]
|
|
93
|
+
* @param {string|Object} configPathOrObject - Path to config file or raw javascript config object
|
|
94
|
+
* @param {ConfigoramaSettings} [settings] - Configuration settings
|
|
95
|
+
* @returns {T} resolved configuration object
|
|
96
|
+
*/
|
|
72
97
|
module.exports.sync = (configPathOrObject, settings = {}) => {
|
|
73
98
|
const _settings = settings || {}
|
|
74
99
|
if (_settings.dynamicArgs && typeof _settings.dynamicArgs === 'function') {
|
|
@@ -100,5 +125,8 @@ module.exports.analyze = async (configPathOrObject, settings = {}) => {
|
|
|
100
125
|
return instance.init(options)
|
|
101
126
|
}
|
|
102
127
|
|
|
103
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Format utilities for parsing various config formats
|
|
130
|
+
* @type {Object}
|
|
131
|
+
*/
|
|
104
132
|
module.exports.format = parsers
|