@abinnovision/nestjs-configx 2.0.0 → 2.0.1
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/configx.constants.d.ts +4 -0
- package/dist/configx.constants.js +7 -0
- package/dist/configx.errors.d.ts +8 -0
- package/dist/configx.errors.js +48 -0
- package/dist/configx.helpers.d.ts +7 -0
- package/dist/configx.helpers.js +25 -0
- package/dist/configx.module.d.ts +1 -0
- package/dist/configx.module.js +2 -0
- package/dist/configx.resolver.d.ts +19 -0
- package/dist/configx.resolver.js +24 -0
- package/dist/configx.tokens.d.ts +1 -0
- package/dist/configx.tokens.js +4 -0
- package/dist/configx.types.d.ts +23 -0
- package/dist/configx.types.js +2 -0
- package/dist/helper.d.ts +7 -0
- package/dist/helper.js +26 -0
- package/package.json +14 -6
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
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
/**
|
|
3
|
+
* Generic error class for Configx.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ConfigxError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
static fromSchemaIssues(issues: readonly StandardSchemaV1.Issue[]): ConfigxError;
|
|
8
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
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
|
+
* Generic error class for Configx.
|
|
36
|
+
*/
|
|
37
|
+
class ConfigxError extends Error {
|
|
38
|
+
constructor(message) {
|
|
39
|
+
super(message);
|
|
40
|
+
this.name = "ConfigxError";
|
|
41
|
+
}
|
|
42
|
+
static fromSchemaIssues(issues) {
|
|
43
|
+
const messageHeader = "Invalid config:\n";
|
|
44
|
+
const messageBody = issues.map((it) => `- ${formatIssue(it)}`).join("\n");
|
|
45
|
+
return new ConfigxError(`${messageHeader}${messageBody}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.ConfigxError = ConfigxError;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ConfigxSchema, ConfigxType } from "./configx.types";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new Configx class.
|
|
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>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configx = configx;
|
|
4
|
+
const configx_resolver_1 = require("./configx.resolver");
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new Configx class.
|
|
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, configx_resolver_1.resolveConfig)({
|
|
17
|
+
schema,
|
|
18
|
+
resolveEnv: () => process.env,
|
|
19
|
+
});
|
|
20
|
+
// Assign the resolved configuration to the instance.
|
|
21
|
+
Object.assign(this, config);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return ConfigxUsage;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ConfigxSchema } from "./configx.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 the configuration with the given ConfigxConfig.
|
|
15
|
+
*
|
|
16
|
+
* @param args The arguments for the function.
|
|
17
|
+
*/
|
|
18
|
+
export declare const resolveConfig: <T extends ConfigxSchema>(args: ResolveConfigArgs<T>) => StandardSchemaV1.InferOutput<T>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveConfig = void 0;
|
|
4
|
+
const configx_errors_1 = require("./configx.errors");
|
|
5
|
+
/**
|
|
6
|
+
* Resolves the configuration with the given ConfigxConfig.
|
|
7
|
+
*
|
|
8
|
+
* @param args The arguments for the function.
|
|
9
|
+
*/
|
|
10
|
+
const resolveConfig = (args) => {
|
|
11
|
+
// The object which will later be parsed by the Zod schema.
|
|
12
|
+
const parsableObject = args.resolveEnv();
|
|
13
|
+
const result = args.schema["~standard"].validate(parsableObject);
|
|
14
|
+
if (result instanceof Promise) {
|
|
15
|
+
throw new Error("Asynchronous schemas are not supported");
|
|
16
|
+
}
|
|
17
|
+
if (result.issues === undefined) {
|
|
18
|
+
return result.value;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
throw configx_errors_1.ConfigxError.fromSchemaIssues(result.issues);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
exports.resolveConfig = resolveConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CONFIGX_RESOLVER_FN: unique symbol;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
* The instance of the class is used to access the configuration.
|
|
9
|
+
*/
|
|
10
|
+
export interface ConfigxType<T extends ConfigxSchema = any> {
|
|
11
|
+
/**
|
|
12
|
+
* Standard Schema V1 schema of the Configx class.
|
|
13
|
+
*/
|
|
14
|
+
schema: T;
|
|
15
|
+
/**
|
|
16
|
+
* Instantiates a new Configx instance.
|
|
17
|
+
*/
|
|
18
|
+
new (): ConfigxValue<T>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Describes the value of the Configx class.
|
|
22
|
+
*/
|
|
23
|
+
export type ConfigxValue<T extends ConfigxSchema> = StandardSchemaV1.InferOutput<T>;
|
package/dist/helper.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
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/helper.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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/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.1",
|
|
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": "https://github.com/abinnovision/nestjs-commons.git",
|
|
14
|
+
"directory": "packages/configx"
|
|
13
15
|
},
|
|
14
16
|
"license": "Apache-2.0",
|
|
15
17
|
"author": {
|
|
@@ -17,10 +19,17 @@
|
|
|
17
19
|
"email": "info@abinnovision.com",
|
|
18
20
|
"url": "https://abinnovision.com/"
|
|
19
21
|
},
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"require": "./dist/index.js",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
22
29
|
"files": [
|
|
23
|
-
"dist"
|
|
30
|
+
"dist",
|
|
31
|
+
"LICENSE",
|
|
32
|
+
"README.md"
|
|
24
33
|
],
|
|
25
34
|
"scripts": {
|
|
26
35
|
"build": "tsc --project tsconfig.build.json",
|
|
@@ -56,7 +65,6 @@
|
|
|
56
65
|
"vitest": "^4.0.15",
|
|
57
66
|
"zod": "^3.24.1"
|
|
58
67
|
},
|
|
59
|
-
"packageManager": "yarn@4.5.1",
|
|
60
68
|
"publishConfig": {
|
|
61
69
|
"ghpr": true,
|
|
62
70
|
"npm": true,
|