@maroonedsoftware/appconfig 1.0.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/LICENSE +21 -0
- package/README.md +310 -0
- package/dist/app.config.builder.d.ts +76 -0
- package/dist/app.config.builder.d.ts.map +1 -0
- package/dist/app.config.d.ts +114 -0
- package/dist/app.config.d.ts.map +1 -0
- package/dist/app.config.provider.d.ts +43 -0
- package/dist/app.config.provider.d.ts.map +1 -0
- package/dist/app.config.source.d.ts +25 -0
- package/dist/app.config.source.d.ts.map +1 -0
- package/dist/app.config.source.options.d.ts +16 -0
- package/dist/app.config.source.options.d.ts.map +1 -0
- package/dist/helpers.d.ts +8 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +581 -0
- package/dist/index.js.map +1 -0
- package/dist/object.visitor.d.ts +52 -0
- package/dist/object.visitor.d.ts.map +1 -0
- package/dist/providers/app.config.provider.dotenv.d.ts +81 -0
- package/dist/providers/app.config.provider.dotenv.d.ts.map +1 -0
- package/dist/providers/app.config.provider.gcp.secrets.d.ts +95 -0
- package/dist/providers/app.config.provider.gcp.secrets.d.ts.map +1 -0
- package/dist/sources/app.config.source.dotenv.d.ts +40 -0
- package/dist/sources/app.config.source.dotenv.d.ts.map +1 -0
- package/dist/sources/app.config.source.json.d.ts +47 -0
- package/dist/sources/app.config.source.json.d.ts.map +1 -0
- package/dist/sources/app.config.source.yaml.d.ts +48 -0
- package/dist/sources/app.config.source.yaml.d.ts.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata about a value's location within an object structure.
|
|
3
|
+
*/
|
|
4
|
+
export type ObjectVisitorMeta = {
|
|
5
|
+
/** The full path to the value (e.g., "database.host" or "items[0]"). */
|
|
6
|
+
path: string;
|
|
7
|
+
/** The object that owns this property. */
|
|
8
|
+
owner: object;
|
|
9
|
+
/** The property name or array index path (e.g., "host" or "items[0]"). */
|
|
10
|
+
propertyPath: string;
|
|
11
|
+
/** The type of the property value. */
|
|
12
|
+
propertyType: 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function';
|
|
13
|
+
/** The array index if the value is in an array, undefined otherwise. */
|
|
14
|
+
arrayIndex?: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Callback function invoked for each primitive value found during object traversal.
|
|
18
|
+
*
|
|
19
|
+
* @param value - The primitive value found.
|
|
20
|
+
* @param meta - Metadata about the value's location in the object structure.
|
|
21
|
+
*/
|
|
22
|
+
export type ObjectVisitorCallback = (value: unknown, meta: ObjectVisitorMeta) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Traverses an object structure and invokes a callback for each primitive value found.
|
|
25
|
+
*
|
|
26
|
+
* The visitor recursively traverses objects and arrays, calling the callback for each
|
|
27
|
+
* primitive value (string, number, boolean, bigint) encountered. It skips functions,
|
|
28
|
+
* symbols, null, and undefined values.
|
|
29
|
+
*
|
|
30
|
+
* @param obj - The object to traverse. Can be any value.
|
|
31
|
+
* @param callback - The callback function to invoke for each primitive value.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const config = {
|
|
36
|
+
* database: { host: 'localhost', port: 5432 },
|
|
37
|
+
* items: ['a', 'b', 'c']
|
|
38
|
+
* };
|
|
39
|
+
*
|
|
40
|
+
* objectVisitor(config, (value, meta) => {
|
|
41
|
+
* console.log(`${meta.path} = ${value}`);
|
|
42
|
+
* });
|
|
43
|
+
* // Output:
|
|
44
|
+
* // database.host = localhost
|
|
45
|
+
* // database.port = 5432
|
|
46
|
+
* // items[0] = a
|
|
47
|
+
* // items[1] = b
|
|
48
|
+
* // items[2] = c
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare const objectVisitor: (obj: unknown, callback: ObjectVisitorCallback) => void;
|
|
52
|
+
//# sourceMappingURL=object.visitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.visitor.d.ts","sourceRoot":"","sources":["../src/object.visitor.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,0EAA0E;IAC1E,YAAY,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,YAAY,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAC;IAC1G,wEAAwE;IACxE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,KAAK,IAAI,CAAC;AAEtF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,OAAO,EAAE,UAAU,qBAAqB,KAAG,IA2C7E,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { AppConfigProvider } from '../app.config.provider.js';
|
|
2
|
+
import { ObjectVisitorMeta } from '../object.visitor.js';
|
|
3
|
+
/**
|
|
4
|
+
* Provider that resolves environment variable references in configuration values.
|
|
5
|
+
*
|
|
6
|
+
* This provider matches string values using a regex pattern and replaces them with
|
|
7
|
+
* values from `process.env`. The default pattern matches `${env:KEY}` and extracts
|
|
8
|
+
* the key part to look up in the environment.
|
|
9
|
+
*
|
|
10
|
+
* After replacement, the result is attempted to be parsed as JSON. If parsing succeeds,
|
|
11
|
+
* the parsed value is used; otherwise, the string value is used.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // With default pattern /\$\{env:(.+)\}/g
|
|
16
|
+
* // Value: "${env:DATABASE_URL}"
|
|
17
|
+
* // Looks up: process.env.DATABASE_URL
|
|
18
|
+
*
|
|
19
|
+
* // Custom pattern
|
|
20
|
+
* const provider = new AppConfigProviderDotenv(/\$\{([^}]+)\}/g);
|
|
21
|
+
* // Value: "${DATABASE_URL}"
|
|
22
|
+
* // Looks up: process.env.DATABASE_URL
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class AppConfigProviderDotenv implements AppConfigProvider {
|
|
26
|
+
private readonly prefix;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new AppConfigProviderDotenv instance.
|
|
29
|
+
*
|
|
30
|
+
* @param prefix - A regex pattern or string to match environment variable references.
|
|
31
|
+
* If a string is provided, it will be converted to a RegExp. The regex must have
|
|
32
|
+
* at least one capture group that extracts the environment variable key.
|
|
33
|
+
* Defaults to `/\$\{env:(.+)\}/g` which matches `${env:KEY}` patterns.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // Default pattern
|
|
38
|
+
* const provider1 = new AppConfigProviderDotenv();
|
|
39
|
+
*
|
|
40
|
+
* // Custom regex pattern
|
|
41
|
+
* const provider2 = new AppConfigProviderDotenv(/\$\{([^}]+)\}/g);
|
|
42
|
+
*
|
|
43
|
+
* // String pattern (converted to RegExp)
|
|
44
|
+
* const provider3 = new AppConfigProviderDotenv('env:');
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
constructor(prefix?: string | RegExp);
|
|
48
|
+
/**
|
|
49
|
+
* Checks if this provider can parse the given value.
|
|
50
|
+
*
|
|
51
|
+
* @param value - The string value to check.
|
|
52
|
+
* @returns `true` if the value matches the provider's regex pattern, `false` otherwise.
|
|
53
|
+
*/
|
|
54
|
+
canParse(value: string): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Parses the value by replacing environment variable references with actual values.
|
|
57
|
+
*
|
|
58
|
+
* The method:
|
|
59
|
+
* 1. Finds all matches of the regex pattern in the value
|
|
60
|
+
* 2. Replaces each match with the corresponding value from `process.env`
|
|
61
|
+
* 3. Attempts to parse the result as JSON
|
|
62
|
+
* 4. Updates the configuration object with the final value
|
|
63
|
+
*
|
|
64
|
+
* @param value - The string value containing environment variable references.
|
|
65
|
+
* @param meta - Metadata about the value's location in the configuration object.
|
|
66
|
+
* @returns A promise that resolves when the transformation is complete.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // If process.env.DATABASE_URL = "postgres://localhost/db"
|
|
71
|
+
* // Value: "${env:DATABASE_URL}"
|
|
72
|
+
* // Result: "postgres://localhost/db"
|
|
73
|
+
*
|
|
74
|
+
* // If process.env.PORT = "3000"
|
|
75
|
+
* // Value: "${env:PORT}"
|
|
76
|
+
* // Result: 3000 (parsed as JSON number)
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
parse(value: string, meta: ObjectVisitorMeta): Promise<void>;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=app.config.provider.dotenv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.config.provider.dotenv.d.ts","sourceRoot":"","sources":["../../src/providers/app.config.provider.dotenv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGzD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,uBAAwB,YAAW,iBAAiB;IAC/D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;;;;;;;;;;;;;;;;;OAmBG;gBACS,MAAM,GAAE,MAAM,GAAG,MAA0B;IAIvD;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIhC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CAcnE"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { AppConfigProvider } from '../app.config.provider.js';
|
|
2
|
+
import { ObjectVisitorMeta } from '../object.visitor.js';
|
|
3
|
+
/**
|
|
4
|
+
* Provider that resolves Google Cloud Platform Secret Manager references in configuration values.
|
|
5
|
+
*
|
|
6
|
+
* This provider matches string values using a regex pattern and replaces them with
|
|
7
|
+
* secrets fetched from GCP Secret Manager. The default pattern matches `${gcp:SECRET_NAME}`
|
|
8
|
+
* and extracts the secret name to look up in Secret Manager.
|
|
9
|
+
*
|
|
10
|
+
* After retrieval, the secret value is attempted to be parsed as JSON. If parsing succeeds,
|
|
11
|
+
* the parsed value is used; otherwise, the string value is used.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* This provider requires valid GCP credentials to be configured. It uses the
|
|
15
|
+
* `@google-cloud/secret-manager` package and will use Application Default Credentials (ADC).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // With default pattern /\$\{gcp:(.+)\}/g
|
|
20
|
+
* // Value: "${gcp:DATABASE_PASSWORD}"
|
|
21
|
+
* // Fetches: projects/{projectId}/secrets/DATABASE_PASSWORD/versions/latest
|
|
22
|
+
*
|
|
23
|
+
* const config = await new AppConfigBuilder()
|
|
24
|
+
* .addSource(new AppConfigSourceJson('./config.json'))
|
|
25
|
+
* .addProvider(new AppConfigProviderGcpSecrets('my-gcp-project'))
|
|
26
|
+
* .build();
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare class AppConfigProviderGcpSecrets implements AppConfigProvider {
|
|
30
|
+
private readonly projectId;
|
|
31
|
+
private readonly secretmanagerClient;
|
|
32
|
+
private readonly prefix;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new AppConfigProviderGcpSecrets instance.
|
|
35
|
+
*
|
|
36
|
+
* @param projectId - The GCP project ID where secrets are stored.
|
|
37
|
+
* @param prefix - A regex pattern or string to match secret references.
|
|
38
|
+
* If a string is provided, it will be converted to a RegExp. The regex must have
|
|
39
|
+
* at least one capture group that extracts the secret name.
|
|
40
|
+
* Defaults to `/\$\{gcp:(.+)\}/g` which matches `${gcp:SECRET_NAME}` patterns.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* // Default pattern
|
|
45
|
+
* const provider1 = new AppConfigProviderGcpSecrets('my-project');
|
|
46
|
+
*
|
|
47
|
+
* // Custom regex pattern
|
|
48
|
+
* const provider2 = new AppConfigProviderGcpSecrets('my-project', /\$\{secret:([^}]+)\}/g);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
constructor(projectId: string, prefix?: string | RegExp);
|
|
52
|
+
/**
|
|
53
|
+
* Checks if this provider can parse the given value.
|
|
54
|
+
*
|
|
55
|
+
* @param value - The string value to check.
|
|
56
|
+
* @returns `true` if the value matches the provider's regex pattern, `false` otherwise.
|
|
57
|
+
*/
|
|
58
|
+
canParse(value: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Fetches a secret from GCP Secret Manager.
|
|
61
|
+
*
|
|
62
|
+
* @param secretId - The name of the secret to fetch.
|
|
63
|
+
* @returns A promise that resolves to the secret value, or an empty string if the secret
|
|
64
|
+
* couldn't be fetched.
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
private getSecret;
|
|
68
|
+
/**
|
|
69
|
+
* Parses the value by replacing GCP secret references with actual secret values.
|
|
70
|
+
*
|
|
71
|
+
* The method:
|
|
72
|
+
* 1. Finds all matches of the regex pattern in the value
|
|
73
|
+
* 2. Fetches each secret from GCP Secret Manager in parallel
|
|
74
|
+
* 3. Attempts to parse each result as JSON
|
|
75
|
+
* 4. Updates the configuration object with the final value
|
|
76
|
+
*
|
|
77
|
+
* @param value - The string value containing GCP secret references.
|
|
78
|
+
* @param meta - Metadata about the value's location in the configuration object.
|
|
79
|
+
* @returns A promise that resolves when all secrets have been fetched and the
|
|
80
|
+
* transformation is complete.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* // If GCP secret "API_KEY" contains "sk-abc123"
|
|
85
|
+
* // Value: "${gcp:API_KEY}"
|
|
86
|
+
* // Result: "sk-abc123"
|
|
87
|
+
*
|
|
88
|
+
* // If GCP secret "CONFIG" contains '{"retries": 3}'
|
|
89
|
+
* // Value: "${gcp:CONFIG}"
|
|
90
|
+
* // Result: { retries: 3 } (parsed as JSON object)
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
parse(value: string, meta: ObjectVisitorMeta): Promise<void>;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=app.config.provider.gcp.secrets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.config.provider.gcp.secrets.d.ts","sourceRoot":"","sources":["../../src/providers/app.config.provider.gcp.secrets.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAIzD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBACa,2BAA4B,YAAW,iBAAiB;IAuBjE,OAAO,CAAC,QAAQ,CAAC,SAAS;IAtB5B,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAoC;IACxE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;;;;;;;;;;;;;;;OAiBG;gBAEgB,SAAS,EAAE,MAAM,EAClC,MAAM,GAAE,MAAM,GAAG,MAA0B;IAK7C;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIhC;;;;;;;OAOG;YACW,SAAS;IAYvB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBnE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AppConfigSource } from '../app.config.source.js';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration source that loads environment variables from a `.env` file.
|
|
4
|
+
*
|
|
5
|
+
* This source uses the `dotenv` package to load environment variables from a `.env` file.
|
|
6
|
+
* If no file path is provided, it will look for a `.env` file in the current working directory.
|
|
7
|
+
* All values are strings as provided by the environment file.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Load from default .env file
|
|
12
|
+
* const source1 = new AppConfigSourceDotenv();
|
|
13
|
+
* const config1 = await source1.load();
|
|
14
|
+
*
|
|
15
|
+
* // Load from custom path
|
|
16
|
+
* const source2 = new AppConfigSourceDotenv('./config/.env.local');
|
|
17
|
+
* const config2 = await source2.load();
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class AppConfigSourceDotenv implements AppConfigSource {
|
|
21
|
+
private readonly filePath?;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new AppConfigSourceDotenv instance.
|
|
24
|
+
*
|
|
25
|
+
* @param filePath - Optional path to the `.env` file. If not provided, `dotenv` will
|
|
26
|
+
* look for a `.env` file in the current working directory.
|
|
27
|
+
*/
|
|
28
|
+
constructor(filePath?: string | undefined);
|
|
29
|
+
/**
|
|
30
|
+
* Loads environment variables from the `.env` file.
|
|
31
|
+
*
|
|
32
|
+
* Uses `dotenv.config()` to parse the file and load variables into the returned object.
|
|
33
|
+
* If the file doesn't exist or there's an error, an error will be thrown.
|
|
34
|
+
*
|
|
35
|
+
* @returns A promise that resolves to an object containing the parsed environment variables.
|
|
36
|
+
* @throws {Error} If there's an error reading or parsing the `.env` file.
|
|
37
|
+
*/
|
|
38
|
+
load(): Promise<Record<string, unknown>>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=app.config.source.dotenv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.config.source.dotenv.d.ts","sourceRoot":"","sources":["../../src/sources/app.config.source.dotenv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,qBAAsB,YAAW,eAAe;IAO/C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;IANtC;;;;;OAKG;gBAC0B,QAAQ,CAAC,EAAE,MAAM,YAAA;IAE9C;;;;;;;;OAQG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAO/C"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { AppConfigSource } from '../app.config.source.js';
|
|
2
|
+
import { AppConfigSourceFileOptions } from '../app.config.source.options.js';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration source that loads configuration from a JSON file.
|
|
5
|
+
*
|
|
6
|
+
* This source reads a JSON file from the filesystem and parses it as a configuration object.
|
|
7
|
+
* By default, it will return an empty object if the file doesn't exist instead of throwing an error.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Load from JSON file, ignore if missing
|
|
12
|
+
* const source1 = new AppConfigSourceJson('./config.json');
|
|
13
|
+
*
|
|
14
|
+
* // Load from JSON file, throw error if missing
|
|
15
|
+
* const source2 = new AppConfigSourceJson('./config.json', {
|
|
16
|
+
* ignoreMissingFile: false
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Load with custom encoding
|
|
20
|
+
* const source3 = new AppConfigSourceJson('./config.json', {
|
|
21
|
+
* encoding: 'utf16le'
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class AppConfigSourceJson implements AppConfigSource {
|
|
26
|
+
private readonly filePath;
|
|
27
|
+
private readonly options;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new AppConfigSourceJson instance.
|
|
30
|
+
*
|
|
31
|
+
* @param filePath - The path to the JSON file to load.
|
|
32
|
+
* @param options - Optional configuration for the source behavior.
|
|
33
|
+
*/
|
|
34
|
+
constructor(filePath: string, options?: AppConfigSourceFileOptions);
|
|
35
|
+
/**
|
|
36
|
+
* Loads configuration from the JSON file.
|
|
37
|
+
*
|
|
38
|
+
* If the file doesn't exist and `ignoreMissingFile` is `true`, returns an empty object.
|
|
39
|
+
* Otherwise, reads and parses the JSON file.
|
|
40
|
+
*
|
|
41
|
+
* @returns A promise that resolves to the parsed JSON configuration object.
|
|
42
|
+
* @throws {Error} If the file doesn't exist and `ignoreMissingFile` is `false`,
|
|
43
|
+
* or if the file contains invalid JSON.
|
|
44
|
+
*/
|
|
45
|
+
load(): Promise<Record<string, unknown>>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=app.config.source.json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.config.source.json.d.ts","sourceRoot":"","sources":["../../src/sources/app.config.source.json.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,mBAAoB,YAAW,eAAe;IAUvD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAT3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IAErD;;;;;OAKG;gBAEgB,QAAQ,EAAE,MAAM,EACjC,OAAO,CAAC,EAAE,0BAA0B;IAStC;;;;;;;;;OASG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAU/C"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AppConfigSource } from '../app.config.source.js';
|
|
2
|
+
import { AppConfigSourceFileOptions } from '../app.config.source.options.js';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration source that loads configuration from a YAML file.
|
|
5
|
+
*
|
|
6
|
+
* This source reads a YAML file from the filesystem and parses it as a configuration object.
|
|
7
|
+
* By default, it will return an empty object if the file doesn't exist instead of throwing an error.
|
|
8
|
+
* Supports both `.yaml` and `.yml` file extensions.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Load from YAML file, ignore if missing
|
|
13
|
+
* const source1 = new AppConfigSourceYaml('./config.yaml');
|
|
14
|
+
*
|
|
15
|
+
* // Load from YAML file, throw error if missing
|
|
16
|
+
* const source2 = new AppConfigSourceYaml('./config.yaml', {
|
|
17
|
+
* ignoreMissingFile: false
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // Load with custom encoding
|
|
21
|
+
* const source3 = new AppConfigSourceYaml('./config.yaml', {
|
|
22
|
+
* encoding: 'utf16le'
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class AppConfigSourceYaml implements AppConfigSource {
|
|
27
|
+
private readonly filePath;
|
|
28
|
+
private readonly options;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new AppConfigSourceYaml instance.
|
|
31
|
+
*
|
|
32
|
+
* @param filePath - The path to the YAML file to load.
|
|
33
|
+
* @param options - Optional configuration for the source behavior.
|
|
34
|
+
*/
|
|
35
|
+
constructor(filePath: string, options?: AppConfigSourceFileOptions);
|
|
36
|
+
/**
|
|
37
|
+
* Loads configuration from the YAML file.
|
|
38
|
+
*
|
|
39
|
+
* If the file doesn't exist and `ignoreMissingFile` is `true`, returns an empty object.
|
|
40
|
+
* Otherwise, reads and parses the YAML file.
|
|
41
|
+
*
|
|
42
|
+
* @returns A promise that resolves to the parsed YAML configuration object.
|
|
43
|
+
* @throws {Error} If the file doesn't exist and `ignoreMissingFile` is `false`,
|
|
44
|
+
* or if the file contains invalid YAML.
|
|
45
|
+
*/
|
|
46
|
+
load(): Promise<Record<string, unknown>>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=app.config.source.yaml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.config.source.yaml.d.ts","sourceRoot":"","sources":["../../src/sources/app.config.source.yaml.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,mBAAoB,YAAW,eAAe;IAUvD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAT3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IAErD;;;;;OAKG;gBAEgB,QAAQ,EAAE,MAAM,EACjC,OAAO,CAAC,EAAE,0BAA0B;IAStC;;;;;;;;;OASG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAU/C"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@maroonedsoftware/appconfig",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A flexible, type-safe configuration management library with support for multiple sources and value transformation.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Marooned Software",
|
|
7
|
+
"url": "https://github.com/MaroonedSoftware/serverkit"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/MaroonedSoftware/serverkit/issues"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/MaroonedSoftware/serverkit/packages/appconfig#readme",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"backend",
|
|
15
|
+
"configuration",
|
|
16
|
+
"serverkit",
|
|
17
|
+
"typescript"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/MaroonedSoftware/serverkit.git"
|
|
22
|
+
},
|
|
23
|
+
"private": false,
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist/**"
|
|
31
|
+
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"deepmerge-ts": "^7.1.5",
|
|
34
|
+
"dotenv": "^17.2.3",
|
|
35
|
+
"injectkit": "^1.0.3"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@google-cloud/secret-manager": "^6.1.1",
|
|
39
|
+
"yaml": "^2.8.2",
|
|
40
|
+
"@repo/config-eslint": "0.0.0",
|
|
41
|
+
"@repo/config-typescript": "0.0.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@google-cloud/secret-manager": "^6.1.1",
|
|
45
|
+
"yaml": "^2.8.2"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsup src/index.ts --format esm --sourcemap --dts && tsc --emitDeclarationOnly --declaration",
|
|
49
|
+
"build:ci": "eslint --max-warnings=0 && pnpm run build",
|
|
50
|
+
"lint": "eslint --fix",
|
|
51
|
+
"format": "prettier --write .",
|
|
52
|
+
"test": "vitest run",
|
|
53
|
+
"test:ci": "vitest run --coverage"
|
|
54
|
+
}
|
|
55
|
+
}
|