@abinnovision/nestjs-configx 2.0.0 → 2.0.2-beta.22
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/CHANGELOG.md +7 -0
- package/dist/create.cjs +20 -0
- package/dist/create.d.cts +11 -0
- package/dist/create.d.mts +11 -0
- package/dist/create.mjs +20 -0
- package/dist/errors.cjs +40 -0
- package/dist/errors.d.cts +18 -0
- package/dist/errors.d.mts +18 -0
- package/dist/errors.mjs +39 -0
- package/dist/index.cjs +6 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +3 -0
- package/dist/resolver.cjs +20 -0
- package/dist/resolver.mjs +20 -0
- package/dist/types.d.cts +22 -0
- package/dist/types.d.mts +22 -0
- package/package.json +33 -14
- package/dist/create.d.ts +0 -7
- package/dist/create.js +0 -26
- package/dist/errors.d.ts +0 -14
- package/dist/errors.js +0 -57
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -19
- package/dist/resolver.d.ts +0 -24
- package/dist/resolver.js +0 -29
- package/dist/types.d.ts +0 -18
- package/dist/types.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.0.1](https://github.com/abinnovision/nestjs-commons/compare/nestjs-configx-v2.0.0...nestjs-configx-v2.0.1) (2025-12-16)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* align exports in package.json ([#70](https://github.com/abinnovision/nestjs-commons/issues/70)) ([58956c5](https://github.com/abinnovision/nestjs-commons/commit/58956c5ea55394b65c6af405f4c6ac45555dc94a))
|
|
9
|
+
|
|
3
10
|
## [2.0.0](https://github.com/abinnovision/nestjs-commons/compare/nestjs-configx-v1.1.1...nestjs-configx-v2.0.0) (2025-12-13)
|
|
4
11
|
|
|
5
12
|
|
package/dist/create.cjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const require_resolver = require("./resolver.cjs");
|
|
2
|
+
//#region src/create.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new Configx class based on the provided schema.
|
|
5
|
+
*
|
|
6
|
+
* @param schema The schema of the Configx class (Zod, ArkType, or any StandardSchema).
|
|
7
|
+
*/ function configx(schema) {
|
|
8
|
+
return class ConfigxUsage {
|
|
9
|
+
static schema = schema;
|
|
10
|
+
constructor() {
|
|
11
|
+
const config = require_resolver.resolveConfig({
|
|
12
|
+
schema,
|
|
13
|
+
resolveEnv: () => process.env
|
|
14
|
+
});
|
|
15
|
+
Object.assign(this, config);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.configx = configx;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConfigxSchema, ConfigxType } from "./types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/create.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new Configx class based on the provided schema.
|
|
6
|
+
*
|
|
7
|
+
* @param schema The schema of the Configx class (Zod, ArkType, or any StandardSchema).
|
|
8
|
+
*/
|
|
9
|
+
declare function configx<T extends ConfigxSchema>(schema: T): ConfigxType<T>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { configx };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConfigxSchema, ConfigxType } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/create.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new Configx class based on the provided schema.
|
|
6
|
+
*
|
|
7
|
+
* @param schema The schema of the Configx class (Zod, ArkType, or any StandardSchema).
|
|
8
|
+
*/
|
|
9
|
+
declare function configx<T extends ConfigxSchema>(schema: T): ConfigxType<T>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { configx };
|
package/dist/create.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { resolveConfig } from "./resolver.mjs";
|
|
2
|
+
//#region src/create.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new Configx class based on the provided schema.
|
|
5
|
+
*
|
|
6
|
+
* @param schema The schema of the Configx class (Zod, ArkType, or any StandardSchema).
|
|
7
|
+
*/ function configx(schema) {
|
|
8
|
+
return class ConfigxUsage {
|
|
9
|
+
static schema = schema;
|
|
10
|
+
constructor() {
|
|
11
|
+
const config = resolveConfig({
|
|
12
|
+
schema,
|
|
13
|
+
resolveEnv: () => process.env
|
|
14
|
+
});
|
|
15
|
+
Object.assign(this, config);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { configx };
|
package/dist/errors.cjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region src/errors.ts
|
|
2
|
+
/**
|
|
3
|
+
* Formats an issue for the ConfigxError.
|
|
4
|
+
*
|
|
5
|
+
* @param issue The issue to format.
|
|
6
|
+
* @returns The formatted issue.
|
|
7
|
+
*/ const formatIssue = (issue) => {
|
|
8
|
+
let result = "";
|
|
9
|
+
if ((issue.path?.length ?? 0) > 0) {
|
|
10
|
+
const path = (issue.path ?? []).map((segment) => {
|
|
11
|
+
if (typeof segment === "object" && "key" in segment) return segment.key.toString();
|
|
12
|
+
return segment.toString();
|
|
13
|
+
}).join(".");
|
|
14
|
+
result += `'${path}': `;
|
|
15
|
+
} else result += "@: ";
|
|
16
|
+
result += issue.message;
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Base class for all Configx errors.
|
|
21
|
+
*/ var ConfigxError = class extends Error {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = "ConfigxError";
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Error thrown when the configuration is invalid.
|
|
29
|
+
*/ var InvalidConfigError = class InvalidConfigError extends ConfigxError {
|
|
30
|
+
constructor(message) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.name = "InvalidConfigError";
|
|
33
|
+
}
|
|
34
|
+
static fromSchemaIssues(issues) {
|
|
35
|
+
return new InvalidConfigError(issues.map(formatIssue).join("; "));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.ConfigxError = ConfigxError;
|
|
40
|
+
exports.InvalidConfigError = InvalidConfigError;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/errors.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Base class for all Configx errors.
|
|
6
|
+
*/
|
|
7
|
+
declare class ConfigxError extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Error thrown when the configuration is invalid.
|
|
12
|
+
*/
|
|
13
|
+
declare class InvalidConfigError extends ConfigxError {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
static fromSchemaIssues(issues: readonly StandardSchemaV1.Issue[]): InvalidConfigError;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ConfigxError, InvalidConfigError };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/errors.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Base class for all Configx errors.
|
|
6
|
+
*/
|
|
7
|
+
declare class ConfigxError extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Error thrown when the configuration is invalid.
|
|
12
|
+
*/
|
|
13
|
+
declare class InvalidConfigError extends ConfigxError {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
static fromSchemaIssues(issues: readonly StandardSchemaV1.Issue[]): InvalidConfigError;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ConfigxError, InvalidConfigError };
|
package/dist/errors.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/errors.ts
|
|
2
|
+
/**
|
|
3
|
+
* Formats an issue for the ConfigxError.
|
|
4
|
+
*
|
|
5
|
+
* @param issue The issue to format.
|
|
6
|
+
* @returns The formatted issue.
|
|
7
|
+
*/ const formatIssue = (issue) => {
|
|
8
|
+
let result = "";
|
|
9
|
+
if ((issue.path?.length ?? 0) > 0) {
|
|
10
|
+
const path = (issue.path ?? []).map((segment) => {
|
|
11
|
+
if (typeof segment === "object" && "key" in segment) return segment.key.toString();
|
|
12
|
+
return segment.toString();
|
|
13
|
+
}).join(".");
|
|
14
|
+
result += `'${path}': `;
|
|
15
|
+
} else result += "@: ";
|
|
16
|
+
result += issue.message;
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Base class for all Configx errors.
|
|
21
|
+
*/ var ConfigxError = class extends Error {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = "ConfigxError";
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Error thrown when the configuration is invalid.
|
|
29
|
+
*/ var InvalidConfigError = class InvalidConfigError extends ConfigxError {
|
|
30
|
+
constructor(message) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.name = "InvalidConfigError";
|
|
33
|
+
}
|
|
34
|
+
static fromSchemaIssues(issues) {
|
|
35
|
+
return new InvalidConfigError(issues.map(formatIssue).join("; "));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
export { ConfigxError, InvalidConfigError };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_errors = require("./errors.cjs");
|
|
3
|
+
const require_create = require("./create.cjs");
|
|
4
|
+
exports.ConfigxError = require_errors.ConfigxError;
|
|
5
|
+
exports.InvalidConfigError = require_errors.InvalidConfigError;
|
|
6
|
+
exports.configx = require_create.configx;
|
package/dist/index.d.cts
ADDED
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const require_errors = require("./errors.cjs");
|
|
2
|
+
//#region src/resolver.ts
|
|
3
|
+
/**
|
|
4
|
+
* Resolves and validates configuration from environment variables using the provided schema.
|
|
5
|
+
*
|
|
6
|
+
* @param args The resolution arguments.
|
|
7
|
+
* @param args.schema A Standard Schema V1 compatible schema (Zod, ArkType, etc.).
|
|
8
|
+
* @param args.resolveEnv Function that returns the environment variables object.
|
|
9
|
+
* @returns The validated and transformed configuration object.
|
|
10
|
+
* @throws {ConfigxError} If the schema uses asynchronous validation.
|
|
11
|
+
* @throws {InvalidConfigError} If the environment variables fail schema validation.
|
|
12
|
+
*/ const resolveConfig = (args) => {
|
|
13
|
+
const parsableObject = args.resolveEnv();
|
|
14
|
+
const result = args.schema["~standard"].validate(parsableObject);
|
|
15
|
+
if (result instanceof Promise) throw new require_errors.ConfigxError("Asynchronous schemas are not supported");
|
|
16
|
+
if (result.issues === void 0) return result.value;
|
|
17
|
+
else throw require_errors.InvalidConfigError.fromSchemaIssues(result.issues);
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.resolveConfig = resolveConfig;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ConfigxError, InvalidConfigError } from "./errors.mjs";
|
|
2
|
+
//#region src/resolver.ts
|
|
3
|
+
/**
|
|
4
|
+
* Resolves and validates configuration from environment variables using the provided schema.
|
|
5
|
+
*
|
|
6
|
+
* @param args The resolution arguments.
|
|
7
|
+
* @param args.schema A Standard Schema V1 compatible schema (Zod, ArkType, etc.).
|
|
8
|
+
* @param args.resolveEnv Function that returns the environment variables object.
|
|
9
|
+
* @returns The validated and transformed configuration object.
|
|
10
|
+
* @throws {ConfigxError} If the schema uses asynchronous validation.
|
|
11
|
+
* @throws {InvalidConfigError} If the environment variables fail schema validation.
|
|
12
|
+
*/ const resolveConfig = (args) => {
|
|
13
|
+
const parsableObject = args.resolveEnv();
|
|
14
|
+
const result = args.schema["~standard"].validate(parsableObject);
|
|
15
|
+
if (result instanceof Promise) throw new ConfigxError("Asynchronous schemas are not supported");
|
|
16
|
+
if (result.issues === void 0) return result.value;
|
|
17
|
+
else throw InvalidConfigError.fromSchemaIssues(result.issues);
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { resolveConfig };
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Describes the allowed types for a Configx schema.
|
|
6
|
+
*/
|
|
7
|
+
type ConfigxSchema = StandardSchemaV1<Record<string, string | undefined>, Record<string, any>>;
|
|
8
|
+
/**
|
|
9
|
+
* Describes a Configx class.
|
|
10
|
+
*/
|
|
11
|
+
interface ConfigxType<T extends ConfigxSchema = any> {
|
|
12
|
+
/**
|
|
13
|
+
* Standard Schema V1 schema of the Configx class.
|
|
14
|
+
*/
|
|
15
|
+
schema: T;
|
|
16
|
+
/**
|
|
17
|
+
* Instantiates a new Configx instance.
|
|
18
|
+
*/
|
|
19
|
+
new (): StandardSchemaV1.InferOutput<T>;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ConfigxSchema, ConfigxType };
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Describes the allowed types for a Configx schema.
|
|
6
|
+
*/
|
|
7
|
+
type ConfigxSchema = StandardSchemaV1<Record<string, string | undefined>, Record<string, any>>;
|
|
8
|
+
/**
|
|
9
|
+
* Describes a Configx class.
|
|
10
|
+
*/
|
|
11
|
+
interface ConfigxType<T extends ConfigxSchema = any> {
|
|
12
|
+
/**
|
|
13
|
+
* Standard Schema V1 schema of the Configx class.
|
|
14
|
+
*/
|
|
15
|
+
schema: T;
|
|
16
|
+
/**
|
|
17
|
+
* Instantiates a new Configx instance.
|
|
18
|
+
*/
|
|
19
|
+
new (): StandardSchemaV1.InferOutput<T>;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ConfigxSchema, ConfigxType };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@abinnovision/nestjs-configx",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.2-beta.22",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nestjs",
|
|
7
7
|
"config",
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
"standard-schema"
|
|
10
10
|
],
|
|
11
11
|
"repository": {
|
|
12
|
-
"
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/abinnovision/nestjs-commons.git",
|
|
14
|
+
"directory": "packages/configx"
|
|
13
15
|
},
|
|
14
16
|
"license": "Apache-2.0",
|
|
15
17
|
"author": {
|
|
@@ -17,13 +19,28 @@
|
|
|
17
19
|
"email": "info@abinnovision.com",
|
|
18
20
|
"url": "https://abinnovision.com/"
|
|
19
21
|
},
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
27
|
+
"default": "./dist/index.mjs"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/index.d.cts",
|
|
31
|
+
"default": "./dist/index.cjs"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"main": "./dist/index.cjs",
|
|
36
|
+
"types": "./dist/index.d.cts",
|
|
22
37
|
"files": [
|
|
23
|
-
"dist"
|
|
38
|
+
"dist",
|
|
39
|
+
"LICENSE",
|
|
40
|
+
"README.md"
|
|
24
41
|
],
|
|
25
42
|
"scripts": {
|
|
26
|
-
"build": "
|
|
43
|
+
"build": "tsdown",
|
|
27
44
|
"format:check": "prettier --check 'src/**/*.ts' '*.{json{,5},md,y{,a}ml}'",
|
|
28
45
|
"format:fix": "prettier --write 'src/**/*.ts' '*.{json{,5},md,y{,a}ml}'",
|
|
29
46
|
"lint:check": "eslint 'src/**/*.ts'",
|
|
@@ -43,20 +60,22 @@
|
|
|
43
60
|
"@standard-schema/spec": "^1.0.0"
|
|
44
61
|
},
|
|
45
62
|
"devDependencies": {
|
|
46
|
-
"@abinnovision/eslint-config-base": "^3.0
|
|
63
|
+
"@abinnovision/eslint-config-base": "^3.2.0",
|
|
47
64
|
"@abinnovision/prettier-config": "^2.1.5",
|
|
48
|
-
"@
|
|
65
|
+
"@arethetypeswrong/core": "^0.18.2",
|
|
66
|
+
"@swc/core": "^1.15.18",
|
|
49
67
|
"arktype": "^2.1.9",
|
|
50
|
-
"eslint": "^9.39.
|
|
51
|
-
"
|
|
52
|
-
"
|
|
68
|
+
"eslint": "^9.39.4",
|
|
69
|
+
"prettier": "^3.8.1",
|
|
70
|
+
"publint": "^0.3.18",
|
|
53
71
|
"reflect-metadata": "^0.2.2",
|
|
54
72
|
"rxjs": "^7.8.1",
|
|
55
|
-
"
|
|
56
|
-
"
|
|
73
|
+
"tsdown": "^0.21.3",
|
|
74
|
+
"typescript": "^5.9.3",
|
|
75
|
+
"unplugin-swc": "^1.5.9",
|
|
76
|
+
"vitest": "^4.1.0",
|
|
57
77
|
"zod": "^3.24.1"
|
|
58
78
|
},
|
|
59
|
-
"packageManager": "yarn@4.5.1",
|
|
60
79
|
"publishConfig": {
|
|
61
80
|
"ghpr": true,
|
|
62
81
|
"npm": true,
|
package/dist/create.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { ConfigxSchema, ConfigxType } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Creates a new Configx class based on the provided schema.
|
|
4
|
-
*
|
|
5
|
-
* @param schema The schema of the Configx class (Zod, ArkType, or any StandardSchema).
|
|
6
|
-
*/
|
|
7
|
-
export declare function configx<T extends ConfigxSchema>(schema: T): ConfigxType<T>;
|
package/dist/create.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.configx = configx;
|
|
4
|
-
const resolver_1 = require("./resolver");
|
|
5
|
-
/**
|
|
6
|
-
* Creates a new Configx class based on the provided schema.
|
|
7
|
-
*
|
|
8
|
-
* @param schema The schema of the Configx class (Zod, ArkType, or any StandardSchema).
|
|
9
|
-
*/
|
|
10
|
-
function configx(schema) {
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
12
|
-
class ConfigxUsage {
|
|
13
|
-
static schema = schema;
|
|
14
|
-
constructor() {
|
|
15
|
-
// Resolve the configuration.
|
|
16
|
-
const config = (0, resolver_1.resolveConfig)({
|
|
17
|
-
schema,
|
|
18
|
-
resolveEnv: () => process.env,
|
|
19
|
-
});
|
|
20
|
-
// Assign the resolved configuration to the instance.
|
|
21
|
-
// This is currently the most efficient way to do this without relying on proxies.
|
|
22
|
-
Object.assign(this, config);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return ConfigxUsage;
|
|
26
|
-
}
|
package/dist/errors.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
-
/**
|
|
3
|
-
* Base class for all Configx errors.
|
|
4
|
-
*/
|
|
5
|
-
export declare class ConfigxError extends Error {
|
|
6
|
-
constructor(message: string);
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Error thrown when the configuration is invalid.
|
|
10
|
-
*/
|
|
11
|
-
export declare class InvalidConfigError extends ConfigxError {
|
|
12
|
-
constructor(message: string);
|
|
13
|
-
static fromSchemaIssues(issues: readonly StandardSchemaV1.Issue[]): InvalidConfigError;
|
|
14
|
-
}
|
package/dist/errors.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InvalidConfigError = exports.ConfigxError = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Formats an issue for the ConfigxError.
|
|
6
|
-
*
|
|
7
|
-
* @param issue The issue to format.
|
|
8
|
-
* @returns The formatted issue.
|
|
9
|
-
*/
|
|
10
|
-
const formatIssue = (issue) => {
|
|
11
|
-
let result = "";
|
|
12
|
-
if ((issue.path?.length ?? 0) > 0) {
|
|
13
|
-
// Format the path segments.
|
|
14
|
-
const path = (issue.path ?? [])
|
|
15
|
-
.map((segment) => {
|
|
16
|
-
// If the segment is an object with a key property, use that.
|
|
17
|
-
if (typeof segment === "object" && "key" in segment) {
|
|
18
|
-
return segment.key.toString();
|
|
19
|
-
}
|
|
20
|
-
return segment.toString();
|
|
21
|
-
})
|
|
22
|
-
.join(".");
|
|
23
|
-
// Add the path to the result.
|
|
24
|
-
result += `'${path}': `;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
// If there is no path, the issue is a root issue.
|
|
28
|
-
result += "@: ";
|
|
29
|
-
}
|
|
30
|
-
// Add the message.
|
|
31
|
-
result += issue.message;
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Base class for all Configx errors.
|
|
36
|
-
*/
|
|
37
|
-
class ConfigxError extends Error {
|
|
38
|
-
constructor(message) {
|
|
39
|
-
super(message);
|
|
40
|
-
this.name = "ConfigxError";
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.ConfigxError = ConfigxError;
|
|
44
|
-
/**
|
|
45
|
-
* Error thrown when the configuration is invalid.
|
|
46
|
-
*/
|
|
47
|
-
class InvalidConfigError extends ConfigxError {
|
|
48
|
-
constructor(message) {
|
|
49
|
-
super(message);
|
|
50
|
-
this.name = "InvalidConfigError";
|
|
51
|
-
}
|
|
52
|
-
static fromSchemaIssues(issues) {
|
|
53
|
-
const messageBody = issues.map(formatIssue).join("; ");
|
|
54
|
-
return new InvalidConfigError(messageBody);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.InvalidConfigError = InvalidConfigError;
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./errors"), exports);
|
|
18
|
-
__exportStar(require("./create"), exports);
|
|
19
|
-
__exportStar(require("./types"), exports);
|
package/dist/resolver.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { ConfigxSchema } from "./types";
|
|
2
|
-
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
-
interface ResolveConfigArgs<T extends ConfigxSchema> {
|
|
4
|
-
/**
|
|
5
|
-
* Schema of the Configx class.
|
|
6
|
-
*/
|
|
7
|
-
schema: T;
|
|
8
|
-
/**
|
|
9
|
-
* Resolves the environment variables object.
|
|
10
|
-
*/
|
|
11
|
-
resolveEnv: () => Record<string, string | undefined>;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Resolves and validates configuration from environment variables using the provided schema.
|
|
15
|
-
*
|
|
16
|
-
* @param args The resolution arguments.
|
|
17
|
-
* @param args.schema A Standard Schema V1 compatible schema (Zod, ArkType, etc.).
|
|
18
|
-
* @param args.resolveEnv Function that returns the environment variables object.
|
|
19
|
-
* @returns The validated and transformed configuration object.
|
|
20
|
-
* @throws {ConfigxError} If the schema uses asynchronous validation.
|
|
21
|
-
* @throws {InvalidConfigError} If the environment variables fail schema validation.
|
|
22
|
-
*/
|
|
23
|
-
export declare const resolveConfig: <T extends ConfigxSchema>(args: ResolveConfigArgs<T>) => StandardSchemaV1.InferOutput<T>;
|
|
24
|
-
export {};
|
package/dist/resolver.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveConfig = void 0;
|
|
4
|
-
const errors_1 = require("./errors");
|
|
5
|
-
/**
|
|
6
|
-
* Resolves and validates configuration from environment variables using the provided schema.
|
|
7
|
-
*
|
|
8
|
-
* @param args The resolution arguments.
|
|
9
|
-
* @param args.schema A Standard Schema V1 compatible schema (Zod, ArkType, etc.).
|
|
10
|
-
* @param args.resolveEnv Function that returns the environment variables object.
|
|
11
|
-
* @returns The validated and transformed configuration object.
|
|
12
|
-
* @throws {ConfigxError} If the schema uses asynchronous validation.
|
|
13
|
-
* @throws {InvalidConfigError} If the environment variables fail schema validation.
|
|
14
|
-
*/
|
|
15
|
-
const resolveConfig = (args) => {
|
|
16
|
-
// The object which will later be parsed by the schema.
|
|
17
|
-
const parsableObject = args.resolveEnv();
|
|
18
|
-
const result = args.schema["~standard"].validate(parsableObject);
|
|
19
|
-
if (result instanceof Promise) {
|
|
20
|
-
throw new errors_1.ConfigxError("Asynchronous schemas are not supported");
|
|
21
|
-
}
|
|
22
|
-
if (result.issues === undefined) {
|
|
23
|
-
return result.value;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
throw errors_1.InvalidConfigError.fromSchemaIssues(result.issues);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
exports.resolveConfig = resolveConfig;
|
package/dist/types.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
-
/**
|
|
3
|
-
* Describes the allowed types for a Configx schema.
|
|
4
|
-
*/
|
|
5
|
-
export type ConfigxSchema = StandardSchemaV1<Record<string, string | undefined>, Record<string, any>>;
|
|
6
|
-
/**
|
|
7
|
-
* Describes a Configx class.
|
|
8
|
-
*/
|
|
9
|
-
export interface ConfigxType<T extends ConfigxSchema = any> {
|
|
10
|
-
/**
|
|
11
|
-
* Standard Schema V1 schema of the Configx class.
|
|
12
|
-
*/
|
|
13
|
-
schema: T;
|
|
14
|
-
/**
|
|
15
|
-
* Instantiates a new Configx instance.
|
|
16
|
-
*/
|
|
17
|
-
new (): StandardSchemaV1.InferOutput<T>;
|
|
18
|
-
}
|
package/dist/types.js
DELETED