@blixis-io/config 0.0.0-stage → 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Michael Voeten
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,28 @@
1
- # Temporary Holding Version
1
+ # `@blixis-io/config`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Zod-validated environment config, built on [`@blixis-io/core`](https://www.npmjs.com/package/@blixis-io/core), HTTP-independent.
4
+
5
+ ```bash
6
+ npm install @blixis-io/config @blixis-io/core @blixis-io/di zod
7
+ ```
8
+
9
+ ```ts
10
+ import { defineConfigModule } from "@blixis-io/config";
11
+ import { z } from "zod";
12
+
13
+ const AppConfigSchema = z.object({
14
+ PORT: z.coerce.number().default(3000),
15
+ DATABASE_URL: z.string(),
16
+ });
17
+
18
+ export const { CONFIG, ConfigModule } = defineConfigModule(AppConfigSchema);
19
+ ```
20
+
21
+ ```ts
22
+ @Module({ imports: [ConfigModule.forRoot()] })
23
+ class AppModule {}
24
+ ```
25
+
26
+ `forRoot()` validates `process.env` synchronously, the moment it's called — a missing or malformed variable throws `ConfigValidationError` at boot, before the app ever starts resolving providers, never on first use deep in a request.
27
+
28
+ Part of [Blixis Framework](https://github.com/blixis-io/framework) — full docs: [Configuration](https://blixis-io.github.io/framework/concepts/config/) · [API reference](https://blixis-io.github.io/framework/reference/blixis-config/).
@@ -0,0 +1,32 @@
1
+ import { DynamicModule } from "@blixis-io/core";
2
+ import { InjectionToken } from "@blixis-io/di";
3
+ import { ZodType, z } from "zod";
4
+ //#region src/errors.d.ts
5
+ /** Thrown by `ConfigModule.forRoot()` when the source (env by default) fails schema validation — fails at module-definition time, not first use. */
6
+ export declare class ConfigValidationError extends Error {
7
+ constructor(zodError: z.ZodError);
8
+ }
9
+ //#endregion
10
+ //#region src/module.d.ts
11
+ /**
12
+ * Builds a config token + module bound to one Zod schema. Config shape is
13
+ * inherently app-specific — unlike `@blixis-io/logging`'s `LOGGER`, there's no
14
+ * single fixed type to export a token for, so each app calls this once with
15
+ * its own schema and gets back its own distinct, strongly-typed token.
16
+ */
17
+ export declare function defineConfigModule<Schema extends ZodType>(schema: Schema): {
18
+ CONFIG: InjectionToken<z.infer<Schema>>;
19
+ ConfigModule: {
20
+ new (): {};
21
+ /**
22
+ * Validates `source` (default: `process.env`) against the schema
23
+ * immediately, providing the parsed result under `CONFIG`. Throws
24
+ * `ConfigValidationError` right away on failure — not deferred to first
25
+ * injection. `global: true` so every module can inject config without
26
+ * also having to import `ConfigModule` itself.
27
+ */
28
+ forRoot(source?: Record<string, string | undefined>): DynamicModule;
29
+ };
30
+ };
31
+ //#endregion
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/errors.ts","../src/module.ts"],"mappings":";;;;;qBAGa,8BAA8B;EACzC,YAAY,UAAU,EAAE;;;;;;;;;;wBCOV,mBAAmB,eAAe,SAAS,QAAQ;;;;;;;;;;;IAYxC,QAAA,SAAA,qCAAmD"}
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ import { Module } from "@blixis-io/core";
2
+ import { InjectionToken } from "@blixis-io/di";
3
+ //#region src/errors.ts
4
+ /** Thrown by `ConfigModule.forRoot()` when the source (env by default) fails schema validation — fails at module-definition time, not first use. */
5
+ var ConfigValidationError = class extends Error {
6
+ constructor(zodError) {
7
+ const issues = zodError.issues.map((issue) => ` - ${issue.path.join(".")}: ${issue.message}`).join("\n");
8
+ super(`Invalid configuration:\n${issues}`);
9
+ this.name = "ConfigValidationError";
10
+ }
11
+ };
12
+ //#endregion
13
+ //#region \0@oxc-project+runtime@0.151.0/helpers/esm/decorate.js
14
+ function __decorate(decorators, target, key, desc) {
15
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
+ 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;
18
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
19
+ }
20
+ //#endregion
21
+ //#region src/module.ts
22
+ /**
23
+ * Builds a config token + module bound to one Zod schema. Config shape is
24
+ * inherently app-specific — unlike `@blixis-io/logging`'s `LOGGER`, there's no
25
+ * single fixed type to export a token for, so each app calls this once with
26
+ * its own schema and gets back its own distinct, strongly-typed token.
27
+ */
28
+ function defineConfigModule(schema) {
29
+ var _ConfigModule;
30
+ const CONFIG = new InjectionToken("blixis.config");
31
+ let ConfigModule = _ConfigModule = class ConfigModule {
32
+ /**
33
+ * Validates `source` (default: `process.env`) against the schema
34
+ * immediately, providing the parsed result under `CONFIG`. Throws
35
+ * `ConfigValidationError` right away on failure — not deferred to first
36
+ * injection. `global: true` so every module can inject config without
37
+ * also having to import `ConfigModule` itself.
38
+ */
39
+ static forRoot(source = process.env) {
40
+ const result = schema.safeParse(source);
41
+ if (!result.success) throw new ConfigValidationError(result.error);
42
+ return {
43
+ module: _ConfigModule,
44
+ providers: [{
45
+ provide: CONFIG,
46
+ useValue: result.data
47
+ }],
48
+ exports: [CONFIG],
49
+ global: true
50
+ };
51
+ }
52
+ };
53
+ ConfigModule = _ConfigModule = __decorate([Module()], ConfigModule);
54
+ return {
55
+ CONFIG,
56
+ ConfigModule
57
+ };
58
+ }
59
+ //#endregion
60
+ export { ConfigValidationError, defineConfigModule };
61
+
62
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/errors.ts","../src/module.ts"],"sourcesContent":["import type { z } from \"zod\";\n\n/** Thrown by `ConfigModule.forRoot()` when the source (env by default) fails schema validation — fails at module-definition time, not first use. */\nexport class ConfigValidationError extends Error {\n constructor(zodError: z.ZodError) {\n const issues = zodError.issues.map((issue) => ` - ${issue.path.join(\".\")}: ${issue.message}`).join(\"\\n\");\n super(`Invalid configuration:\\n${issues}`);\n this.name = \"ConfigValidationError\";\n }\n}\n","import { Module, type DynamicModule } from \"@blixis-io/core\";\nimport { InjectionToken } from \"@blixis-io/di\";\nimport type { z, ZodType } from \"zod\";\nimport { ConfigValidationError } from \"./errors.js\";\n\n/**\n * Builds a config token + module bound to one Zod schema. Config shape is\n * inherently app-specific — unlike `@blixis-io/logging`'s `LOGGER`, there's no\n * single fixed type to export a token for, so each app calls this once with\n * its own schema and gets back its own distinct, strongly-typed token.\n */\nexport function defineConfigModule<Schema extends ZodType>(schema: Schema) {\n const CONFIG = new InjectionToken<z.infer<Schema>>(\"blixis.config\");\n\n @Module()\n class ConfigModule {\n /**\n * Validates `source` (default: `process.env`) against the schema\n * immediately, providing the parsed result under `CONFIG`. Throws\n * `ConfigValidationError` right away on failure — not deferred to first\n * injection. `global: true` so every module can inject config without\n * also having to import `ConfigModule` itself.\n */\n static forRoot(source: Record<string, string | undefined> = process.env): DynamicModule {\n const result = schema.safeParse(source);\n if (!result.success) {\n throw new ConfigValidationError(result.error);\n }\n return {\n module: ConfigModule,\n providers: [{ provide: CONFIG, useValue: result.data }],\n exports: [CONFIG],\n global: true,\n };\n }\n }\n\n return { CONFIG, ConfigModule };\n}\n"],"mappings":";;;;AAGA,IAAa,wBAAb,cAA2C,MAAM;CAC/C,YAAY,UAAsB;EAChC,MAAM,SAAS,SAAS,OAAO,KAAK,UAAU,OAAO,MAAM,KAAK,KAAK,GAAG,EAAE,IAAI,MAAM,SAAS,CAAC,CAAC,KAAK,IAAI;EACxG,MAAM,2BAA2B,QAAQ;EACzC,KAAK,OAAO;CACd;AACF;;;;;;;;;;;;;;;;;ACEA,SAAgB,mBAA2C,QAAgB;;CACzE,MAAM,SAAS,IAAI,eAAgC,eAAe;CAElE,IACM,eAAA,gBADN,MACM,aAAa;;;;;;;;EAQjB,OAAO,QAAQ,SAA6C,QAAQ,KAAoB;GACtF,MAAM,SAAS,OAAO,UAAU,MAAM;GACtC,IAAI,CAAC,OAAO,SACV,MAAM,IAAI,sBAAsB,OAAO,KAAK;GAE9C,OAAO;IACL,QAAA;IACA,WAAW,CAAC;KAAE,SAAS;KAAQ,UAAU,OAAO;IAAK,CAAC;IACtD,SAAS,CAAC,MAAM;IAChB,QAAQ;GACV;EACF;CACF;CArBC,eAAA,gBAAA,WAAA,CAAA,OAAO,CAAA,GAAA,YAAA;CAuBR,OAAO;EAAE;EAAQ;CAAa;AAChC"}
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@blixis-io/config",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Zod-validated environment config, built on @blixis-io/core, HTTP-independent.",
5
+ "license": "MIT",
6
+ "author": "Michael Voeten <michael@voeten.online>",
7
+ "homepage": "https://blixis-io.github.io/framework/",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/blixis-io/framework.git",
11
+ "directory": "packages/config"
12
+ },
13
+ "type": "module",
14
+ "engines": {
15
+ "node": ">=24"
16
+ },
17
+ "keywords": [
18
+ "config",
19
+ "environment-variables",
20
+ "zod",
21
+ "typescript"
22
+ ],
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "exports": {
30
+ ".": {
31
+ "@blixis-io/source": "./src/index.ts",
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ }
35
+ },
36
+ "dependencies": {
37
+ "@blixis-io/core": "0.1.0",
38
+ "@blixis-io/di": "0.1.0",
39
+ "zod": "^4.6.5"
40
+ },
41
+ "scripts": {
42
+ "typecheck": "tsc -p tsconfig.json",
43
+ "build": "rolldown -c"
44
+ }
6
45
  }