zodified-config 1.0.3 → 1.0.5

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.
@@ -0,0 +1,12 @@
1
+ import type z from 'zod';
2
+ export interface ValidatedConfig {
3
+ }
4
+ type DotNotation<T, Prefix extends string = ''> = T extends object ? {
5
+ [K in keyof T & string]: `${Prefix}${K}` | DotNotation<T[K], `${Prefix}${K}.`>;
6
+ }[keyof T & string] : '';
7
+ type TypeFromPath<T, Path extends string> = Path extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? TypeFromPath<T[Key], Rest> : never : Path extends keyof T ? T[Path] : never;
8
+ declare const _default: {
9
+ validate: <T extends z.ZodType>(schema: T) => boolean;
10
+ get: <T extends ValidatedConfig, Path extends DotNotation<T>>(path?: Path) => TypeFromPath<T, Path>;
11
+ };
12
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const config_1 = __importDefault(require("config"));
7
+ const fullConfig = config_1.default.util.toObject();
8
+ const validate = (schema) => {
9
+ try {
10
+ const result = schema.safeParse(config_1.default);
11
+ if (result.success === false) {
12
+ throw new Error("INVALID_CONFIG");
13
+ }
14
+ return true;
15
+ }
16
+ catch (error) {
17
+ if (error instanceof Error && error.message === 'INVALID_CONFIG') {
18
+ throw error;
19
+ }
20
+ throw new Error('UNEXPECTED_ERROR');
21
+ }
22
+ };
23
+ const get = (path) => {
24
+ let result = fullConfig;
25
+ if (!path) {
26
+ return result;
27
+ }
28
+ path.split('.').forEach((key) => {
29
+ if (result[key] !== undefined) {
30
+ result = result[key];
31
+ }
32
+ });
33
+ return result;
34
+ };
35
+ exports.default = {
36
+ validate,
37
+ get,
38
+ };
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAK5B,MAAM,UAAU,GAAG,gBAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;AAE1C,MAAM,QAAQ,GAAG,CAAsB,MAAS,EAAE,EAAE;IAClD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,gBAAM,CAAC,CAAC;QACxC,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,KAAK,gBAAgB,EAAE,CAAC;YACjE,MAAM,KAAK,CAAC;QACd,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;AACH,CAAC,CAAC;AAeF,MAAM,GAAG,GAAG,CACV,IAAW,EACY,EAAE;IACzB,IAAI,MAAM,GAAG,UAAU,CAAC;IAExB,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,MAA+B,CAAC;IACzC,CAAC;IAEA,IAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC1C,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;YAC9B,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,kBAAe;IACb,QAAQ;IACR,GAAG;CACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zodified-config",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Typesafe config validated by Zod",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "main": "./dist/index.js",
15
15
  "files": [
16
- "build"
16
+ "dist"
17
17
  ],
18
18
  "scripts": {
19
19
  "build": "tsc",