@miiajs/config 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 +21 -0
- package/README.md +17 -0
- package/dist/config.module.d.ts +9 -0
- package/dist/config.module.d.ts.map +1 -0
- package/dist/config.module.js +31 -0
- package/dist/config.module.js.map +1 -0
- package/dist/config.service.d.ts +7 -0
- package/dist/config.service.d.ts.map +1 -0
- package/dist/config.service.js +70 -0
- package/dist/config.service.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ruslan Matiushev
|
|
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
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @miiajs/config
|
|
2
|
+
|
|
3
|
+
Validated, type-safe environment configuration for MiiaJS.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @miiajs/config
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
**[miiajs.com/docs/core-concepts/configuration](https://miiajs.com/docs/core-concepts/configuration)**
|
|
14
|
+
|
|
15
|
+
## License
|
|
16
|
+
|
|
17
|
+
MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ConfiguredModule, OptionsOrFactory, ZodLike } from '@miiajs/core';
|
|
2
|
+
export interface ConfigModuleOptions {
|
|
3
|
+
schema?: ZodLike;
|
|
4
|
+
env?: Record<string, string | undefined>;
|
|
5
|
+
}
|
|
6
|
+
export declare class ConfigModule {
|
|
7
|
+
static configure(optionsOrFactory?: OptionsOrFactory<ConfigModuleOptions>): ConfiguredModule;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=config.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.module.d.ts","sourceRoot":"","sources":["../src/config.module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAmB,gBAAgB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAIhG,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;CACzC;AAED,qBAAa,YAAY;IACvB,MAAM,CAAC,SAAS,CAAC,gBAAgB,GAAE,gBAAgB,CAAC,mBAAmB,CAAM,GAAG,gBAAgB;CA0BjG"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { resolveOptions } from '@miiajs/core';
|
|
2
|
+
import { ConfigService } from './config.service.js';
|
|
3
|
+
export class ConfigModule {
|
|
4
|
+
static configure(optionsOrFactory = {}) {
|
|
5
|
+
return {
|
|
6
|
+
module: ConfigModule,
|
|
7
|
+
providers: [
|
|
8
|
+
{
|
|
9
|
+
token: 'CONFIG_VALUES',
|
|
10
|
+
factory: (resolve) => {
|
|
11
|
+
const options = resolveOptions(optionsOrFactory, { resolve });
|
|
12
|
+
const env = options.env ?? process.env;
|
|
13
|
+
if (!options.schema) {
|
|
14
|
+
return env;
|
|
15
|
+
}
|
|
16
|
+
const result = options.schema.safeParse(env);
|
|
17
|
+
if (!result.success) {
|
|
18
|
+
const messages = result.error.issues
|
|
19
|
+
.map((i) => ` - ${i.path?.map(String).join('.') ?? '?'}: ${i.message}`)
|
|
20
|
+
.join('\n');
|
|
21
|
+
throw new Error(`[Miia] Config validation failed:\n${messages}`);
|
|
22
|
+
}
|
|
23
|
+
return result.data;
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
ConfigService,
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=config.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.module.js","sourceRoot":"","sources":["../src/config.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAOnD,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,SAAS,CAAC,mBAA0D,EAAE;QAC3E,OAAO;YACL,MAAM,EAAE,YAAY;YACpB,SAAS,EAAE;gBACT;oBACE,KAAK,EAAE,eAAe;oBACtB,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE;wBACnB,MAAM,OAAO,GAAG,cAAc,CAAC,gBAAgB,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;wBAC7D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAA;wBACtC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;4BACpB,OAAO,GAAG,CAAA;wBACZ,CAAC;wBACD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;wBAC5C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;4BACpB,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM;iCACjC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;iCACvE,IAAI,CAAC,IAAI,CAAC,CAAA;4BACb,MAAM,IAAI,KAAK,CAAC,qCAAqC,QAAQ,EAAE,CAAC,CAAA;wBAClE,CAAC;wBACD,OAAO,MAAM,CAAC,IAAI,CAAA;oBACpB,CAAC;iBACwB;gBAC3B,aAAa;aACd;SACF,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class ConfigService<T extends Record<string, any> = Record<string, string | undefined>> {
|
|
2
|
+
private config;
|
|
3
|
+
constructor();
|
|
4
|
+
get<K extends keyof T>(key: K): T[K];
|
|
5
|
+
getOrThrow<K extends keyof T>(key: K): T[K];
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=config.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.service.d.ts","sourceRoot":"","sources":["../src/config.service.ts"],"names":[],"mappings":"AAGA,qBACa,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3F,OAAO,CAAC,MAAM,CAAG;;IAOjB,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAIpC,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAO5C"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
27
|
+
};
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
35
|
+
import { injectOptional } from '@miiajs/core';
|
|
36
|
+
import { Injectable } from '@miiajs/core';
|
|
37
|
+
let ConfigService = (() => {
|
|
38
|
+
let _classDecorators = [Injectable({ token: 'ConfigService' })];
|
|
39
|
+
let _classDescriptor;
|
|
40
|
+
let _classExtraInitializers = [];
|
|
41
|
+
let _classThis;
|
|
42
|
+
var ConfigService = class {
|
|
43
|
+
static { _classThis = this; }
|
|
44
|
+
static {
|
|
45
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
46
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
47
|
+
ConfigService = _classThis = _classDescriptor.value;
|
|
48
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
49
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
50
|
+
}
|
|
51
|
+
config;
|
|
52
|
+
constructor() {
|
|
53
|
+
const config = injectOptional('CONFIG_VALUES');
|
|
54
|
+
this.config = config ?? {};
|
|
55
|
+
}
|
|
56
|
+
get(key) {
|
|
57
|
+
return this.config[key];
|
|
58
|
+
}
|
|
59
|
+
getOrThrow(key) {
|
|
60
|
+
const value = this.config[key];
|
|
61
|
+
if (value === undefined) {
|
|
62
|
+
throw new Error(`[Miia] Config key "${String(key)}" not found`);
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return ConfigService = _classThis;
|
|
68
|
+
})();
|
|
69
|
+
export { ConfigService };
|
|
70
|
+
//# sourceMappingURL=config.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.service.js","sourceRoot":"","sources":["../src/config.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;IAG5B,aAAa;4BADzB,UAAU,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC;;;;;;;;YACvC,6KAmBC;;;YAnBY,uDAAa;;QAChB,MAAM,CAAG;QAEjB;YACE,MAAM,MAAM,GAAG,cAAc,CAAI,eAAe,CAAC,CAAA;YACjD,IAAI,CAAC,MAAM,GAAG,MAAM,IAAK,EAAQ,CAAA;QACnC,CAAC;QAED,GAAG,CAAoB,GAAM;YAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACzB,CAAC;QAED,UAAU,CAAoB,GAAM;YAClC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;YAC9B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,sBAAsB,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;YACjE,CAAC;YACD,OAAO,KAAK,CAAA;QACd,CAAC;;;;SAlBU,aAAa"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@miiajs/config",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"author": "Ruslan Matiushev",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "ConfigModule and ConfigService for MiiaJS with validated environment variables (Zod, Valibot, ArkType, or any ZodLike validator).",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/miiajs/miia.git",
|
|
10
|
+
"directory": "packages/config"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/miiajs/miia/tree/main/packages/config#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/miiajs/miia/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"miiajs",
|
|
18
|
+
"miia",
|
|
19
|
+
"config",
|
|
20
|
+
"env",
|
|
21
|
+
"validation"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"main": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"sideEffects": false,
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=22.22.1",
|
|
43
|
+
"bun": ">=1.3.11",
|
|
44
|
+
"deno": ">=2.6.1"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@miiajs/core": "workspace:*"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc --build",
|
|
51
|
+
"clean": "tsc --build --clean"
|
|
52
|
+
}
|
|
53
|
+
}
|