@abinnovision/nestjs-configx 1.1.1 → 2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.0.0](https://github.com/abinnovision/nestjs-commons/compare/nestjs-configx-v1.1.1...nestjs-configx-v2.0.0) (2025-12-13)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * simplify configx public api ([#50](https://github.com/abinnovision/nestjs-commons/issues/50))
9
+
10
+ ### Features
11
+
12
+ * simplify configx public api ([#50](https://github.com/abinnovision/nestjs-commons/issues/50)) ([285e283](https://github.com/abinnovision/nestjs-commons/commit/285e2834ca03fde56375fc4596e4a5c01b171abc))
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * add documentation and testing for new public api ([#51](https://github.com/abinnovision/nestjs-commons/issues/51)) ([c22099d](https://github.com/abinnovision/nestjs-commons/commit/c22099d4fce7a20feac6d72476305c5e2ef8ec01))
18
+ * support methods in configx implementation class ([#45](https://github.com/abinnovision/nestjs-commons/issues/45)) ([d8f8ead](https://github.com/abinnovision/nestjs-commons/commit/d8f8ead93bbdc648277940b79fc331842dd4e377))
19
+
3
20
  ## [1.1.1](https://github.com/abinnovision/nestjs-commons/compare/nestjs-configx-v1.1.0...nestjs-configx-v1.1.1) (2025-03-29)
4
21
 
5
22
 
package/README.md CHANGED
@@ -1,39 +1,30 @@
1
1
  # @abinnovision/nestjs-configx
2
2
 
3
- Simple configuration management for NestJS.
4
- Supports [Standard Schema](https://standardschema.dev/).
3
+ Type-safe configuration for NestJS using [Standard Schema](https://standardschema.dev/).
5
4
 
6
- ## Installation
5
+ ## Goals
7
6
 
8
- ```bash
9
- yarn add @abinnovision/nestjs-configx
10
- ```
7
+ - Type-safe configuration from `process.env`
8
+ - Schema-agnostic via Standard Schema (Zod, ArkType, etc.)
9
+ - Minimal NestJS integration (just a provider, no module)
10
+ - Fail-fast validation at startup
11
11
 
12
- ## Schema Libraries
13
-
14
- This library implements the [Standard Schema](https://standardschema.dev/)
15
- specification. This means that you can use any schema library that implements
16
- the specification.
12
+ ## Non-goals
17
13
 
18
- A full list of **libraries that implement the specification can be found
19
- [here](https://standardschema.dev/#what-schema-libraries-implement-the-spec)**.
14
+ - Multiple config sources (at least not yet)
15
+ - Async schema validation
16
+ - Runtime config reloading
17
+ - Secret management / encryption
20
18
 
21
- This library is tested with the following libraries:
19
+ ## Installation
22
20
 
23
- - [Zod](https://github.com/colinhacks/zod)
24
- - [ArkType](https://github.com/arktypeio/arktype)
21
+ ```bash
22
+ yarn add @abinnovision/nestjs-configx
23
+ ```
25
24
 
26
25
  ## Usage
27
26
 
28
- ### Define the configuration
29
-
30
- First, you need to define the configuration. This is done by creating a class
31
- that extends the return value of the `configx` function.
32
-
33
- The function takes a single argument, which is an object schema that maps the
34
- environment variables.
35
-
36
- #### Using Zod
27
+ ### 1. Define your config
37
28
 
38
29
  ```typescript
39
30
  import { configx } from "@abinnovision/nestjs-configx";
@@ -41,62 +32,59 @@ import { z } from "zod";
41
32
 
42
33
  export class AppConfigx extends configx(
43
34
  z.object({
44
- PORT: z.string().default("3000").transform(Number).pipe(z.number()),
35
+ PORT: z.string().default("3000").transform(Number),
45
36
  HOST: z.string().default("0.0.0.0"),
46
37
  }),
47
38
  ) {}
48
39
  ```
49
40
 
50
- #### Using ArkType
51
-
52
- ```typescript
53
- import { configx } from "@abinnovision/nestjs-configx";
54
- import { type } from "arktype";
55
-
56
- export class AppConfigx extends configx(
57
- type({
58
- PORT: "string.numeric.parse = '3000'",
59
- HOST: "string = '127.0.0.1'",
60
- }),
61
- ) {}
62
- ```
63
-
64
- ### Register the configuration
65
-
66
- Next, you need to register the configuration in your NestJS module. This is
67
- done by calling the `register` method of the `ConfigxModule`.
68
-
69
- The method takes multiple Configx classes as arguments, which will be used to
70
- resolve the configuration.
41
+ ### 2. Register as provider
71
42
 
72
43
  ```typescript
73
- import { ConfigxModule } from "@abinnovision/nestjs-configx";
74
44
  import { Module } from "@nestjs/common";
75
-
76
45
  import { AppConfigx } from "./app.configx";
77
46
 
78
47
  @Module({
79
- imports: [ConfigxModule.register(AppConfigx)],
48
+ providers: [AppConfigx],
49
+ exports: [AppConfigx],
80
50
  })
81
51
  export class AppModule {}
82
52
  ```
83
53
 
84
- ### Use the configuration
85
-
86
- Finally, you can use the configuration in your NestJS components.
54
+ ### 3. Inject and use
87
55
 
88
56
  ```typescript
89
- import { Injectable } from "@nestjs/common";
90
-
91
- import { AppConfigx } from "./app.configx";
92
-
93
57
  @Injectable()
94
58
  export class AppService {
95
- constructor(private readonly appConfig: AppConfigx) {}
59
+ constructor(private readonly config: AppConfigx) {}
96
60
 
97
- getConfig() {
98
- // Get the configuration value.
99
- return this.appConfig.PORT;
61
+ getPort() {
62
+ return this.config.PORT; // number - fully typed
100
63
  }
101
64
  }
102
65
  ```
66
+
67
+ ## Schema Libraries
68
+
69
+ Any [Standard Schema](https://standardschema.dev/#what-schema-libraries-implement-the-spec) compatible library works. Tested with:
70
+
71
+ - [Zod](https://github.com/colinhacks/zod)
72
+ - [ArkType](https://github.com/arktypeio/arktype)
73
+
74
+ ### ArkType Example
75
+
76
+ ```typescript
77
+ import { configx } from "@abinnovision/nestjs-configx";
78
+ import { type } from "arktype";
79
+
80
+ export class AppConfigx extends configx(
81
+ type({
82
+ PORT: "string.numeric.parse = '3000'",
83
+ HOST: "string = '0.0.0.0'",
84
+ }),
85
+ ) {}
86
+ ```
87
+
88
+ ## Error Handling
89
+
90
+ Invalid configuration throws `InvalidConfigError` at instantiation with details about which fields failed validation.
@@ -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/create.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
+ }
@@ -0,0 +1,14 @@
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 ADDED
@@ -0,0 +1,57 @@
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 CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./configx.module";
2
- export * from "./configx.helpers";
3
- export * from "./configx.errors";
1
+ export * from "./errors";
2
+ export * from "./create";
3
+ export * from "./types";
package/dist/index.js CHANGED
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./configx.module"), exports);
18
- __exportStar(require("./configx.helpers"), exports);
19
- __exportStar(require("./configx.errors"), exports);
17
+ __exportStar(require("./errors"), exports);
18
+ __exportStar(require("./create"), exports);
19
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,24 @@
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 {};
@@ -0,0 +1,29 @@
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;
@@ -5,19 +5,14 @@ import type { StandardSchemaV1 } from "@standard-schema/spec";
5
5
  export type ConfigxSchema = StandardSchemaV1<Record<string, string | undefined>, Record<string, any>>;
6
6
  /**
7
7
  * Describes a Configx class.
8
- * The instance of the class is used to access the configuration.
9
8
  */
10
- export interface Configx<T extends ConfigxSchema = any> {
9
+ export interface ConfigxType<T extends ConfigxSchema = any> {
11
10
  /**
12
- * The Zod schema of the Configx class.
11
+ * Standard Schema V1 schema of the Configx class.
13
12
  */
14
13
  schema: T;
15
14
  /**
16
15
  * Instantiates a new Configx instance.
17
16
  */
18
- new (): ConfigxValue<T>;
17
+ new (): StandardSchemaV1.InferOutput<T>;
19
18
  }
20
- /**
21
- * Describes the value of the Configx class.
22
- */
23
- export type ConfigxValue<T extends ConfigxSchema> = StandardSchemaV1.InferOutput<T>;
package/package.json CHANGED
@@ -1,65 +1,65 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@abinnovision/nestjs-configx",
4
- "packageManager": "yarn@4.5.1",
5
- "version": "1.1.1",
6
- "license": "Apache-2.0",
4
+ "version": "2.0.0",
5
+ "keywords": [
6
+ "nestjs",
7
+ "config",
8
+ "configuration",
9
+ "standard-schema"
10
+ ],
7
11
  "repository": {
8
12
  "url": "https://github.com/abinnovision/nestjs-commons"
9
13
  },
14
+ "license": "Apache-2.0",
10
15
  "author": {
11
16
  "name": "AB INNOVISION GmbH",
12
17
  "email": "info@abinnovision.com",
13
18
  "url": "https://abinnovision.com/"
14
19
  },
15
- "keywords": [
16
- "nestjs",
17
- "config",
18
- "configuration",
19
- "configuration",
20
- "standard-schema"
21
- ],
20
+ "main": "dist/index.js",
21
+ "types": "dist/index.d.ts",
22
22
  "files": [
23
23
  "dist"
24
24
  ],
25
- "main": "dist/index.js",
26
- "types": "dist/index.d.ts",
27
- "lint-staged": {
28
- "src/**/*.{ts,js}": [
29
- "eslint --fix",
30
- "prettier --write"
31
- ],
32
- "*.{js,ts,json,json5,yaml,yml,md}": [
33
- "prettier --write"
34
- ]
35
- },
36
25
  "scripts": {
37
26
  "build": "tsc --project tsconfig.build.json",
38
- "format:check": "prettier --check '{{src,test}/**/*,*}.{js,jsx,ts,tsx,json,json5,yml,yaml,md}'",
39
- "format:fix": "prettier --write '{{src,test}/**/*,*}.{js,jsx,ts,tsx,json,json5,yml,yaml,md}'",
40
- "lint:check": "eslint '{{src,test}/**/*,*}.{js,jsx,ts,tsx}'",
41
- "lint:fix": "eslint '{{src,test}/**/*,*}.{js,jsx,ts,tsx}' --fix",
27
+ "format:check": "prettier --check 'src/**/*.ts' '*.{json{,5},md,y{,a}ml}'",
28
+ "format:fix": "prettier --write 'src/**/*.ts' '*.{json{,5},md,y{,a}ml}'",
29
+ "lint:check": "eslint 'src/**/*.ts'",
30
+ "lint:fix": "eslint 'src/**/*.ts' --fix",
42
31
  "test-unit": "vitest --run --coverage --config vitest.config.mts",
43
32
  "test-unit:watch": "vitest --config vitest.config.mts"
44
33
  },
34
+ "lint-staged": {
35
+ "src/**/*.ts": [
36
+ "eslint --fix",
37
+ "prettier --write"
38
+ ],
39
+ "*.{json{,5},md,y{,a}ml}": "prettier --write"
40
+ },
45
41
  "prettier": "@abinnovision/prettier-config",
42
+ "dependencies": {
43
+ "@standard-schema/spec": "^1.0.0"
44
+ },
46
45
  "devDependencies": {
47
- "@abinnovision/eslint-config-base": "^2.2.0",
48
- "@abinnovision/eslint-config-typescript": "^2.2.1",
49
- "@abinnovision/prettier-config": "^2.1.3",
46
+ "@abinnovision/eslint-config-base": "^3.0.2",
47
+ "@abinnovision/prettier-config": "^2.1.5",
50
48
  "@swc/core": "^1.11.5",
51
49
  "arktype": "^2.1.9",
52
- "eslint": "^9.21.0",
53
- "globals": "^15.15.0",
54
- "prettier": "^3.5.0",
50
+ "eslint": "^9.39.1",
51
+ "globals": "^16.5.0",
52
+ "prettier": "^3.7.4",
55
53
  "reflect-metadata": "^0.2.2",
56
54
  "rxjs": "^7.8.1",
57
55
  "typescript": "^5.8.2",
58
- "vitest": "^3.0.5",
56
+ "vitest": "^4.0.15",
59
57
  "zod": "^3.24.1"
60
58
  },
61
- "dependencies": {
62
- "@nestjs/common": "^11.0.8",
63
- "@standard-schema/spec": "^1.0.0"
59
+ "packageManager": "yarn@4.5.1",
60
+ "publishConfig": {
61
+ "ghpr": true,
62
+ "npm": true,
63
+ "npmAccess": "public"
64
64
  }
65
65
  }
@@ -1,8 +0,0 @@
1
- import type { StandardSchemaV1 } from "@standard-schema/spec";
2
- /**
3
- * Generic error class for Configx.
4
- */
5
- export declare class ConfigxError extends Error {
6
- static fromSchemaIssues(issues: readonly StandardSchemaV1.Issue[]): ConfigxError;
7
- constructor(message: string);
8
- }
@@ -1,38 +0,0 @@
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
- // If there is a path, the issue is a nested issue.
14
- result += issue.path?.join(".") + ": ";
15
- }
16
- else {
17
- // If there is no path, the issue is a root issue.
18
- result += "@: ";
19
- }
20
- // Add the message.
21
- result += issue.message;
22
- return result;
23
- };
24
- /**
25
- * Generic error class for Configx.
26
- */
27
- class ConfigxError extends Error {
28
- static fromSchemaIssues(issues) {
29
- const messageHeader = "Invalid config:\n";
30
- const messageBody = issues.map((it) => `- ${formatIssue(it)}`).join("\n");
31
- return new ConfigxError(`${messageHeader}${messageBody}`);
32
- }
33
- constructor(message) {
34
- super(message);
35
- this.name = "ConfigxError";
36
- }
37
- }
38
- exports.ConfigxError = ConfigxError;
@@ -1,7 +0,0 @@
1
- import type { Configx, ConfigxSchema } from "./configx.types";
2
- /**
3
- * Creates a new Configx class.
4
- *
5
- * @param schema The Zod schema of the Configx class.
6
- */
7
- export declare function configx<T extends ConfigxSchema>(schema: T): Configx<T>;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.configx = configx;
4
- /**
5
- * Creates a new Configx class.
6
- *
7
- * @param schema The Zod schema of the Configx class.
8
- */
9
- function configx(schema) {
10
- class Augmented {
11
- static schema = schema;
12
- }
13
- return Augmented;
14
- }
@@ -1,18 +0,0 @@
1
- import { DynamicModule, OnModuleInit } from "@nestjs/common";
2
- import { Configx } from "./configx.types";
3
- export declare class ConfigxModule implements OnModuleInit {
4
- /**
5
- * Registers the ConfigxModule in the root module.
6
- *
7
- * @param configs
8
- */
9
- static register(...configs: Configx[]): DynamicModule;
10
- /**
11
- * Resolves the config providers for the given options.
12
- *
13
- * @private
14
- * @param configs
15
- */
16
- private static resolveConfigProviders;
17
- onModuleInit(): void;
18
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var ConfigxModule_1;
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.ConfigxModule = void 0;
11
- const common_1 = require("@nestjs/common");
12
- const configx_resolver_1 = require("./configx.resolver");
13
- let ConfigxModule = ConfigxModule_1 = class ConfigxModule {
14
- /**
15
- * Registers the ConfigxModule in the root module.
16
- *
17
- * @param configs
18
- */
19
- static register(...configs) {
20
- const configProviders = this.resolveConfigProviders(configs);
21
- return {
22
- module: ConfigxModule_1,
23
- providers: configProviders,
24
- exports: configProviders,
25
- };
26
- }
27
- /**
28
- * Resolves the config providers for the given options.
29
- *
30
- * @private
31
- * @param configs
32
- */
33
- static resolveConfigProviders(configs) {
34
- // If there are no configs, return an empty array.
35
- if (configs.length === 0) {
36
- return [];
37
- }
38
- return configs.map((config) => {
39
- return {
40
- provide: config,
41
- useFactory: () => (0, configx_resolver_1.resolveConfig)({
42
- config,
43
- resolveEnv: () => process.env,
44
- }),
45
- };
46
- });
47
- }
48
- onModuleInit() { }
49
- };
50
- exports.ConfigxModule = ConfigxModule;
51
- exports.ConfigxModule = ConfigxModule = ConfigxModule_1 = __decorate([
52
- (0, common_1.Module)({})
53
- ], ConfigxModule);
@@ -1,16 +0,0 @@
1
- import type { Configx, ConfigxSchema } from "./configx.types";
2
- import type { StandardSchemaV1 } from "@standard-schema/spec";
3
- interface ResolveConfigArgs<T extends ConfigxSchema> {
4
- config: Configx<T>;
5
- /**
6
- * Resolves the environment variables object.
7
- */
8
- resolveEnv: () => Record<string, string | undefined>;
9
- }
10
- /**
11
- * Resolves the configuration with the given ConfigxConfig.
12
- *
13
- * @param args The arguments for the function.
14
- */
15
- export declare const resolveConfig: <T extends ConfigxSchema>(args: ResolveConfigArgs<T>) => Promise<StandardSchemaV1.InferOutput<T>>;
16
- export {};
@@ -1,21 +0,0 @@
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 = async (args) => {
11
- // The object which will later be parsed by the Zod schema.
12
- const parsableObject = args.resolveEnv();
13
- const result = await args.config.schema["~standard"].validate(parsableObject);
14
- if (result.issues === undefined) {
15
- return result.value;
16
- }
17
- else {
18
- throw configx_errors_1.ConfigxError.fromSchemaIssues(result.issues);
19
- }
20
- };
21
- exports.resolveConfig = resolveConfig;
File without changes