node-env-resolver 2.0.1 → 3.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/README.md +418 -91
- package/dist/advanced-features.test.d.ts +2 -0
- package/dist/advanced-features.test.d.ts.map +1 -0
- package/dist/audit.js +1 -1
- package/dist/builder.d.ts +1 -1
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +1 -1
- package/dist/chunk-476ZUILE.js +1 -0
- package/dist/chunk-DAGPFV3V.js +1 -0
- package/dist/chunk-MGTYH57K.js +9 -0
- package/dist/chunk-MWG7FWHN.js +5 -0
- package/dist/chunk-QWDK3BUB.js +15 -0
- package/dist/chunk-VJZZNSRI.js +1 -0
- package/dist/cli.d.ts +49 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +1 -0
- package/dist/cli.test.d.ts +2 -0
- package/dist/cli.test.d.ts.map +1 -0
- package/dist/computed.test.d.ts +2 -0
- package/dist/computed.test.d.ts.map +1 -0
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -5
- package/dist/nested.test.d.ts +2 -0
- package/dist/nested.test.d.ts.map +1 -0
- package/dist/resolver.d.ts.map +1 -1
- package/dist/resolver.js +1 -9
- package/dist/resolvers.d.ts +129 -0
- package/dist/resolvers.d.ts.map +1 -1
- package/dist/resolvers.js +1 -3
- package/dist/type-inference.test.d.ts +2 -0
- package/dist/type-inference.test.d.ts.map +1 -0
- package/dist/types.d.ts +95 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +168 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/valibot.d.ts +153 -0
- package/dist/valibot.d.ts.map +1 -0
- package/dist/valibot.js +1 -0
- package/dist/validation-types.d.ts +28 -0
- package/dist/validation-types.d.ts.map +1 -0
- package/dist/validation-types.js +0 -0
- package/dist/validators.d.ts +22 -2
- package/dist/validators.d.ts.map +1 -1
- package/dist/validators.js +1 -1
- package/dist/web.d.ts +1 -1
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +4 -4
- package/dist/zod.d.ts +18 -65
- package/dist/zod.d.ts.map +1 -1
- package/dist/zod.js +1 -1
- package/package.json +21 -16
- package/dist/standard-schema.d.ts +0 -32
- package/dist/standard-schema.d.ts.map +0 -1
- package/dist/standard-schema.js +0 -3
package/dist/web.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
\u{1F4A1} Only variables prefixed with '${e}' are allowed in client bundles.`);if(process.env.NODE_ENV==="development")throw n;return console.error(n.message),{}}
|
|
3
|
-
\u{1F4A1} Rename these variables to start with '${e}' (e.g., ${s[0]} \u2192 ${e}${s[0]})`);
|
|
4
|
-
\u{1F4A1} These variables will be exposed to the client. Move to client schema or remove prefix.`);
|
|
1
|
+
import {b as b$1}from'./chunk-MWG7FWHN.js';import'./chunk-DAGPFV3V.js';import'./chunk-MGTYH57K.js';import'./chunk-VJZZNSRI.js';import {b,a}from'./chunk-QWDK3BUB.js';import'./chunk-476ZUILE.js';var S=()=>typeof globalThis.window<"u";async function u(t,v={}){let{resolvers:o=[b()],clientPrefix:e="PUBLIC_",strict:m=true}=v,l=Object.keys(t).filter(n=>!n.startsWith(e));if(S()&&l.length>0){let n=new Error(`\u274C Server-only environment variables accessed in browser context: ${l.join(", ")}
|
|
2
|
+
\u{1F4A1} Only variables prefixed with '${e}' are allowed in client bundles.`);if(process.env.NODE_ENV==="development")throw n;return console.error(n.message),{}}let i={};for(let[n,c]of Object.entries(t))n.startsWith(e)&&(i[n]=c);let f=o.map(n=>[n,i]);return await b$1.with(...f,{strict:m})}async function E(t,v={}){let{resolvers:o=[a({expand:true}),b()],clientPrefix:e="PUBLIC_",policies:m,interpolate:l,strict:i}=v,s=Object.keys(t.client).filter(r=>!r.startsWith(e));if(s.length>0)throw new Error(`\u274C Client environment variables must be prefixed with '${e}': ${s.join(", ")}
|
|
3
|
+
\u{1F4A1} Rename these variables to start with '${e}' (e.g., ${s[0]} \u2192 ${e}${s[0]})`);let c=Object.keys(t.server).filter(r=>r.startsWith(e));if(c.length>0)throw new Error(`\u274C Server environment variables should not be prefixed with '${e}': ${c.join(", ")}
|
|
4
|
+
\u{1F4A1} These variables will be exposed to the client. Move to client schema or remove prefix.`);let x=o.map(r=>[r,t.server]),d=await b$1.with(...x,{policies:m,interpolate:l,strict:i}),T=o.map(r=>[r,t.client]),y=await b$1.with(...T,{strict:i});return {server:d,client:y}}S()&&process.env.NODE_ENV==="development"&&console.warn(`\u{1F310} node-env-resolver/web: Running in browser context
|
|
5
5
|
Only variables with your configured prefix will be accessible
|
|
6
6
|
Server-only variables are blocked for security`);export{u as resolveClientEnv,E as resolveEnvSplit};
|
package/dist/zod.d.ts
CHANGED
|
@@ -2,51 +2,18 @@
|
|
|
2
2
|
* Zod integration for node-env-resolver
|
|
3
3
|
* Import from 'node-env-resolver/zod' to use this
|
|
4
4
|
*/
|
|
5
|
-
import { type Resolver, type PolicyOptions } from './index
|
|
5
|
+
import { type Resolver, type PolicyOptions } from './index';
|
|
6
|
+
import type { SafeResolveResult } from './validation-types';
|
|
6
7
|
export type InferZodOutput<T> = T extends {
|
|
7
8
|
parse: (input: unknown) => infer R;
|
|
8
9
|
} ? R : never;
|
|
9
|
-
/**
|
|
10
|
-
* Convert a Zod schema to Standard Schema format
|
|
11
|
-
*/
|
|
12
|
-
export declare function zodToStandardSchema<T extends {
|
|
13
|
-
safeParseAsync: (input: unknown) => Promise<{
|
|
14
|
-
success: boolean;
|
|
15
|
-
data?: unknown;
|
|
16
|
-
error?: {
|
|
17
|
-
issues: Array<{
|
|
18
|
-
message: string;
|
|
19
|
-
path: unknown[];
|
|
20
|
-
}>;
|
|
21
|
-
};
|
|
22
|
-
}>;
|
|
23
|
-
}>(zodSchema: T): {
|
|
24
|
-
'~standard': {
|
|
25
|
-
version: 1;
|
|
26
|
-
vendor: string;
|
|
27
|
-
validate: (value: unknown) => Promise<{
|
|
28
|
-
value: unknown;
|
|
29
|
-
issues?: undefined;
|
|
30
|
-
} | {
|
|
31
|
-
issues: {
|
|
32
|
-
message: string;
|
|
33
|
-
path: unknown[];
|
|
34
|
-
}[];
|
|
35
|
-
value?: undefined;
|
|
36
|
-
}>;
|
|
37
|
-
types: {
|
|
38
|
-
input: unknown;
|
|
39
|
-
output: InferZodOutput<T>;
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
10
|
/**
|
|
44
11
|
* Resolve environment variables using Zod schema (throws on validation error)
|
|
45
12
|
*
|
|
46
13
|
* @example
|
|
47
14
|
* ```ts
|
|
48
15
|
* import { resolveZod } from 'node-env-resolver/zod';
|
|
49
|
-
* import
|
|
16
|
+
* import * as z from 'zod';
|
|
50
17
|
*
|
|
51
18
|
* const schema = z.object({
|
|
52
19
|
* PORT: z.coerce.number().default(3000),
|
|
@@ -66,12 +33,12 @@ export declare function resolveZod<TSchema extends {
|
|
|
66
33
|
policies?: PolicyOptions;
|
|
67
34
|
}): Promise<InferZodOutput<TSchema>>;
|
|
68
35
|
/**
|
|
69
|
-
* Safe version - returns result object instead of throwing (
|
|
36
|
+
* Safe version - returns result object instead of throwing (unified error format)
|
|
70
37
|
*
|
|
71
38
|
* @example
|
|
72
39
|
* ```ts
|
|
73
40
|
* import { safeResolveZod } from 'node-env-resolver/zod';
|
|
74
|
-
* import
|
|
41
|
+
* import * as z from 'zod';
|
|
75
42
|
*
|
|
76
43
|
* const schema = z.object({
|
|
77
44
|
* PORT: z.coerce.number(),
|
|
@@ -84,6 +51,9 @@ export declare function resolveZod<TSchema extends {
|
|
|
84
51
|
* console.log(result.data.PORT);
|
|
85
52
|
* } else {
|
|
86
53
|
* console.error(result.error);
|
|
54
|
+
* result.issues.forEach(issue => {
|
|
55
|
+
* console.log(`${issue.path.join('.')}: ${issue.message}`);
|
|
56
|
+
* });
|
|
87
57
|
* }
|
|
88
58
|
* ```
|
|
89
59
|
*/
|
|
@@ -91,31 +61,21 @@ export declare function safeResolveZod<TSchema extends {
|
|
|
91
61
|
safeParse: (input: unknown) => {
|
|
92
62
|
success: boolean;
|
|
93
63
|
data?: unknown;
|
|
94
|
-
error?:
|
|
95
|
-
issues: Array<{
|
|
96
|
-
message: string;
|
|
97
|
-
}>;
|
|
98
|
-
};
|
|
64
|
+
error?: unknown;
|
|
99
65
|
};
|
|
100
66
|
}>(zodSchema: TSchema, options?: {
|
|
101
67
|
resolvers?: Resolver[];
|
|
102
68
|
interpolate?: boolean;
|
|
103
69
|
strict?: boolean;
|
|
104
70
|
policies?: PolicyOptions;
|
|
105
|
-
}): Promise<
|
|
106
|
-
success: true;
|
|
107
|
-
data: InferZodOutput<TSchema>;
|
|
108
|
-
} | {
|
|
109
|
-
success: false;
|
|
110
|
-
error: string;
|
|
111
|
-
}>;
|
|
71
|
+
}): Promise<SafeResolveResult<InferZodOutput<TSchema>>>;
|
|
112
72
|
/**
|
|
113
73
|
* Sync version of resolveZod (throws on validation error)
|
|
114
74
|
*
|
|
115
75
|
* @example
|
|
116
76
|
* ```ts
|
|
117
77
|
* import { resolveSyncZod } from 'node-env-resolver/zod';
|
|
118
|
-
* import
|
|
78
|
+
* import * as z from 'zod';
|
|
119
79
|
*
|
|
120
80
|
* const schema = z.object({
|
|
121
81
|
* PORT: z.coerce.number().default(3000)
|
|
@@ -134,12 +94,12 @@ export declare function resolveSyncZod<TSchema extends {
|
|
|
134
94
|
policies?: PolicyOptions;
|
|
135
95
|
}): InferZodOutput<TSchema>;
|
|
136
96
|
/**
|
|
137
|
-
* Safe sync version - returns result object instead of throwing
|
|
97
|
+
* Safe sync version - returns result object instead of throwing (unified error format)
|
|
138
98
|
*
|
|
139
99
|
* @example
|
|
140
100
|
* ```ts
|
|
141
101
|
* import { safeResolveSyncZod } from 'node-env-resolver/zod';
|
|
142
|
-
* import
|
|
102
|
+
* import * as z from 'zod';
|
|
143
103
|
*
|
|
144
104
|
* const schema = z.object({
|
|
145
105
|
* PORT: z.coerce.number()
|
|
@@ -151,6 +111,9 @@ export declare function resolveSyncZod<TSchema extends {
|
|
|
151
111
|
* console.log(result.data.PORT);
|
|
152
112
|
* } else {
|
|
153
113
|
* console.error(result.error);
|
|
114
|
+
* result.issues.forEach(issue => {
|
|
115
|
+
* console.log(`${issue.path.join('.')}: ${issue.message}`);
|
|
116
|
+
* });
|
|
154
117
|
* }
|
|
155
118
|
* ```
|
|
156
119
|
*/
|
|
@@ -158,22 +121,12 @@ export declare function safeResolveSyncZod<TSchema extends {
|
|
|
158
121
|
safeParse: (input: unknown) => {
|
|
159
122
|
success: boolean;
|
|
160
123
|
data?: unknown;
|
|
161
|
-
error?:
|
|
162
|
-
issues: Array<{
|
|
163
|
-
message: string;
|
|
164
|
-
}>;
|
|
165
|
-
};
|
|
124
|
+
error?: unknown;
|
|
166
125
|
};
|
|
167
126
|
}>(zodSchema: TSchema, options?: {
|
|
168
127
|
resolvers?: Resolver[];
|
|
169
128
|
interpolate?: boolean;
|
|
170
129
|
strict?: boolean;
|
|
171
130
|
policies?: PolicyOptions;
|
|
172
|
-
}):
|
|
173
|
-
success: true;
|
|
174
|
-
data: InferZodOutput<TSchema>;
|
|
175
|
-
} | {
|
|
176
|
-
success: false;
|
|
177
|
-
error: string;
|
|
178
|
-
};
|
|
131
|
+
}): SafeResolveResult<InferZodOutput<TSchema>>;
|
|
179
132
|
//# sourceMappingURL=zod.d.ts.map
|
package/dist/zod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACO,KAAK,QAAQ,EAAE,KAAK,aAAa,EAC9C,MAAM,
|
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACO,KAAK,QAAQ,EAAE,KAAK,aAAa,EAC9C,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,iBAAiB,EAAmB,MAAM,oBAAoB,CAAC;AAqB7E,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AAuB7F;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,UAAU,CAAC,OAAO,SAAS;IAAE,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAA;CAAE,EACrF,SAAS,EAAE,OAAO,EAClB,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,aAAa,CAAA;CAAO,GAC1G,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAIlC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,cAAc,CAAC,OAAO,SAAS;IAAE,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,EAC3I,SAAS,EAAE,OAAO,EAClB,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,aAAa,CAAA;CAAO,GAC1G,OAAO,CAAC,iBAAiB,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAoBrD;AA0BD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,OAAO,SAAS;IAAE,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAA;CAAE,EACnF,SAAS,EAAE,OAAO,EAClB,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,aAAa,CAAA;CAAO,GAC1G,cAAc,CAAC,OAAO,CAAC,CAIzB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,SAAS;IAAE,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,EACzI,SAAS,EAAE,OAAO,EAClB,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,aAAa,CAAA;CAAO,GAC1G,iBAAiB,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAoB5C"}
|
package/dist/zod.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {a}from'./chunk-MWG7FWHN.js';import'./chunk-DAGPFV3V.js';import'./chunk-MGTYH57K.js';import'./chunk-VJZZNSRI.js';import'./chunk-476ZUILE.js';async function u(n,t,e){let s={};for(let o of n)try{let r=await o.load();s={...s,...r};}catch(r){if(e)throw new Error(`Resolver ${o.name} failed: ${r instanceof Error?r.message:r}`)}if(t)for(let[o,r]of Object.entries(s))s[o]=r.replace(/\$\{([^}]+)\}/g,(a,c)=>s[c]||"");return s}function f(n){if(!n||typeof n!="object")return [{path:[],message:"Validation failed",code:"unknown_error"}];let t=n;return !t.issues||!Array.isArray(t.issues)?[{path:[],message:"Validation failed",code:"unknown_error"}]:t.issues.map(e=>({path:e.path||[],message:e.message,code:e.code}))}async function v(n,t={}){let{resolvers:e=[a()],interpolate:s=false,strict:o=true}=t,r=await u(e,s,o);return n.parse(r)}async function g(n,t={}){try{let{resolvers:e=[a()],interpolate:s=!1,strict:o=!0}=t,r=await u(e,s,o),a$1=n.safeParse(r);if(a$1.success)return {success:!0,data:a$1.data};let c=f(a$1.error);return {success:!1,error:c.map(l=>l.message).join(", "),issues:c}}catch(e){return {success:false,error:e instanceof Error?e.message:String(e),issues:[{path:[],message:e instanceof Error?e.message:String(e),code:"resolver_error"}]}}}function p(n,t,e){let s={};for(let o of n)try{if(!o.loadSync){if(e)throw new Error(`Resolver ${o.name} does not support sync loading`);continue}let r=o.loadSync();s={...s,...r};}catch(r){if(e)throw new Error(`Resolver ${o.name} failed: ${r instanceof Error?r.message:r}`)}if(t)for(let[o,r]of Object.entries(s))s[o]=r.replace(/\$\{([^}]+)\}/g,(a,c)=>s[c]||"");return s}function h(n,t={}){let{resolvers:e=[a()],interpolate:s=false,strict:o=true}=t,r=p(e,s,o);return n.parse(r)}function y(n,t={}){try{let{resolvers:e=[a()],interpolate:s=!1,strict:o=!0}=t,r=p(e,s,o),a$1=n.safeParse(r);if(a$1.success)return {success:!0,data:a$1.data};let c=f(a$1.error);return {success:!1,error:c.map(l=>l.message).join(", "),issues:c}}catch(e){return {success:false,error:e instanceof Error?e.message:String(e),issues:[{path:[],message:e instanceof Error?e.message:String(e),code:"resolver_error"}]}}}export{h as resolveSyncZod,v as resolveZod,y as safeResolveSyncZod,g as safeResolveZod};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-env-resolver",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Type-safe environment variable resolver with async resolvers - lightweight, tree-shakeable, no dependencies",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"import": "./dist/zod.js",
|
|
19
19
|
"types": "./dist/zod.d.ts"
|
|
20
20
|
},
|
|
21
|
-
"./
|
|
22
|
-
"import": "./dist/
|
|
23
|
-
"types": "./dist/
|
|
21
|
+
"./valibot": {
|
|
22
|
+
"import": "./dist/valibot.js",
|
|
23
|
+
"types": "./dist/valibot.d.ts"
|
|
24
24
|
},
|
|
25
25
|
"./web": {
|
|
26
26
|
"import": "./dist/web.js",
|
|
@@ -38,6 +38,10 @@
|
|
|
38
38
|
"import": "./dist/validators.js",
|
|
39
39
|
"types": "./dist/validators.d.ts"
|
|
40
40
|
},
|
|
41
|
+
"./cli": {
|
|
42
|
+
"import": "./dist/cli.js",
|
|
43
|
+
"types": "./dist/cli.d.ts"
|
|
44
|
+
},
|
|
41
45
|
"./audit": {
|
|
42
46
|
"import": "./dist/audit.js",
|
|
43
47
|
"types": "./dist/audit.d.ts"
|
|
@@ -55,6 +59,16 @@
|
|
|
55
59
|
"dist",
|
|
56
60
|
"README.md"
|
|
57
61
|
],
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "NODE_ENV=production tsup && tsc --emitDeclarationOnly",
|
|
64
|
+
"build:dev": "tsup",
|
|
65
|
+
"build:dts": "tsc --emitDeclarationOnly",
|
|
66
|
+
"type-check": "tsc -p tsconfig.json --noEmit",
|
|
67
|
+
"lint": "eslint src/",
|
|
68
|
+
"test": "vitest run",
|
|
69
|
+
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
|
|
70
|
+
"prepublishOnly": "pnpm build && pnpm type-check"
|
|
71
|
+
},
|
|
58
72
|
"keywords": [
|
|
59
73
|
"environment",
|
|
60
74
|
"env",
|
|
@@ -84,24 +98,15 @@
|
|
|
84
98
|
},
|
|
85
99
|
"devDependencies": {
|
|
86
100
|
"@eslint/js": "^9.37.0",
|
|
87
|
-
"@
|
|
88
|
-
"@types/node": "^24.7.0",
|
|
101
|
+
"@types/node": "^24.7.2",
|
|
89
102
|
"@typescript-eslint/eslint-plugin": "^8.46.0",
|
|
90
103
|
"@typescript-eslint/parser": "^8.46.0",
|
|
91
104
|
"eslint": "^9.37.0",
|
|
92
105
|
"eslint-config-prettier": "^10.1.8",
|
|
106
|
+
"eslint-plugin-import-zod": "^1.2.0",
|
|
93
107
|
"prettier": "^3.6.2",
|
|
94
108
|
"tsup": "^8.5.0",
|
|
95
109
|
"typescript": "^5.9.3",
|
|
96
110
|
"vitest": "^3.2.4"
|
|
97
|
-
},
|
|
98
|
-
"scripts": {
|
|
99
|
-
"build": "NODE_ENV=production tsup && tsc --emitDeclarationOnly",
|
|
100
|
-
"build:dev": "tsup",
|
|
101
|
-
"build:dts": "tsc --emitDeclarationOnly",
|
|
102
|
-
"type-check": "tsc -p tsconfig.json --noEmit",
|
|
103
|
-
"lint": "eslint src/",
|
|
104
|
-
"test": "vitest run",
|
|
105
|
-
"format": "prettier --write \"**/*.{ts,tsx,md}\""
|
|
106
111
|
}
|
|
107
|
-
}
|
|
112
|
+
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Standard Schema integration for node-env-resolver
|
|
3
|
-
*
|
|
4
|
-
* Implements the Standard Schema specification to enable interoperability
|
|
5
|
-
* with other TypeScript validation libraries like Zod, Valibot, and ArkType.
|
|
6
|
-
*
|
|
7
|
-
* Reference: https://github.com/standard-schema/standard-schema
|
|
8
|
-
*/
|
|
9
|
-
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
10
|
-
import type { EnvDefinition, EnvSchema } from './types';
|
|
11
|
-
export interface StandardSchemaEnvDefinition extends EnvDefinition, StandardSchemaV1 {
|
|
12
|
-
}
|
|
13
|
-
export interface StandardSchemaEnvSchema {
|
|
14
|
-
[key: string]: StandardSchemaEnvDefinition;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Convert a node-env-resolver EnvDefinition to a Standard Schema compliant definition
|
|
18
|
-
*/
|
|
19
|
-
export declare function toStandardSchema(key: string, definition: EnvDefinition): StandardSchemaEnvDefinition;
|
|
20
|
-
/**
|
|
21
|
-
* Convert an entire EnvSchema to Standard Schema compliant format
|
|
22
|
-
*/
|
|
23
|
-
export declare function schemaToStandardSchema(schema: EnvSchema): StandardSchemaEnvSchema;
|
|
24
|
-
/**
|
|
25
|
-
* Validate a value using Standard Schema compliant validation
|
|
26
|
-
*/
|
|
27
|
-
export declare function validateWithStandardSchema(schema: StandardSchemaEnvDefinition, value: unknown): Promise<StandardSchemaV1.Result<unknown>>;
|
|
28
|
-
/**
|
|
29
|
-
* Type-safe helper to validate multiple environment variables
|
|
30
|
-
*/
|
|
31
|
-
export declare function validateEnvWithStandardSchema(schema: StandardSchemaEnvSchema, env: Record<string, string>): Promise<Record<string, unknown>>;
|
|
32
|
-
//# sourceMappingURL=standard-schema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"standard-schema.d.ts","sourceRoot":"","sources":["../src/standard-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAOxD,MAAM,WAAW,2BAA4B,SAAQ,aAAa,EAAE,gBAAgB;CAEnF;AAED,MAAM,WAAW,uBAAuB;IACtC,CAAC,GAAG,EAAE,MAAM,GAAG,2BAA2B,CAAC;CAC5C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,aAAa,GACxB,2BAA2B,CAuW7B;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,GAAG,uBAAuB,CAQjF;AAED;;GAEG;AACH,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,2BAA2B,EACnC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAG3C;AAED;;GAEG;AACH,wBAAsB,6BAA6B,CACjD,MAAM,EAAE,uBAAuB,EAC/B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC1B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAoBlC"}
|
package/dist/standard-schema.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import {validateTimestamp,validateDate,validateJson,validatePort,validateEmail,validateUrl,validateHttps,validateHttp,validateRedis,validateMongodb,validateMysql,validatePostgres,validateBoolean,validateNumber}from'./validators';function x(e,a){const t=a.type||"string",u=i=>{try{if(i===void 0||i==="")if(a.default!==void 0)if(t==="json"||t==="email"||t==="url"||t==="number"||t==="port"||t==="boolean")i=a.default;else return {value:a.default};else return a.optional?{value:void 0}:{issues:[{message:`Missing required environment variable: ${e}`,path:[e]}]};const s=String(i);if(a.enum)return a.enum.includes(s)?{value:s}:{issues:[{message:`${e} must be one of: ${a.enum.join(", ")}`,path:[e]}]};if(a.pattern&&!new RegExp(a.pattern).test(s))return {issues:[{message:`${e} does not match required pattern: ${a.pattern}`,path:[e]}]};switch(t){case "string":return a.min!==void 0&&s.length<a.min?{issues:[{message:`${e} must be at least ${a.min} characters`,path:[e]}]}:a.max!==void 0&&s.length>a.max?{issues:[{message:`${e} must be at most ${a.max} characters`,path:[e]}]}:{value:s};case "number":{const r=validateNumber(s);if(!r.valid)return {issues:[{message:`${e}: ${r.error}`,path:[e]}]};const o=Number(s);return a.min!==void 0&&o<a.min?{issues:[{message:`${e} must be at least ${a.min}`,path:[e]}]}:a.max!==void 0&&o>a.max?{issues:[{message:`${e} must be at most ${a.max}`,path:[e]}]}:{value:o}}case "boolean":{const r=validateBoolean(s);if(!r.valid)return {issues:[{message:`${e}: ${r.error}`,path:[e]}]};const o=s.toLowerCase();return ["true","1","yes","on"].includes(o)?{value:!0}:{value:!1}}case "postgres":case "postgresql":{const r=validatePostgres(s);return r.valid?{value:s}:{issues:[{message:`${e}: ${r.error}`,path:[e]}]}}case "mysql":{const r=validateMysql(s);return r.valid?{value:s}:{issues:[{message:`${e}: ${r.error}`,path:[e]}]}}case "mongodb":{const r=validateMongodb(s);return r.valid?{value:s}:{issues:[{message:`${e}: ${r.error}`,path:[e]}]}}case "redis":{const r=validateRedis(s);return r.valid?{value:s}:{issues:[{message:`${e}: ${r.error}`,path:[e]}]}}case "http":{const r=validateHttp(s);return r.valid?{value:s}:{issues:[{message:`${e}: ${r.error}`,path:[e]}]}}case "https":{const r=validateHttps(s);return r.valid?{value:s}:{issues:[{message:`${e}: ${r.error}`,path:[e]}]}}case "url":{const r=validateUrl(s);return r.valid?{value:s}:{issues:[{message:`${e}: ${r.error}`,path:[e]}]}}case "email":{const r=validateEmail(s);return r.valid?{value:s}:{issues:[{message:`${e}: ${r.error}`,path:[e]}]}}case "port":{const r=validatePort(s);return r.valid?{value:Number(s)}:{issues:[{message:`${e}: ${r.error}`,path:[e]}]}}case "json":{const r=validateJson(s);return r.valid?{value:JSON.parse(s)}:{issues:[{message:`${e}: ${r.error}`,path:[e]}]}}case "date":{const r=validateDate(s);return r.valid?{value:s}:{issues:[{message:`${e}: ${r.error}`,path:[e]}]}}case "timestamp":{const r=validateTimestamp(s);return r.valid?{value:Number(s)}:{issues:[{message:`${e}: ${r.error}`,path:[e]}]}}case "custom":{if(!a.validator)return {issues:[{message:"Custom validator function is required for type 'custom'",path:[e]}]};try{return {value:a.validator(s)}}catch(r){return {issues:[{message:r instanceof Error?r.message:`Custom validation failed for ${e}`,path:[e]}]}}}default:return {issues:[{message:`Unknown type: ${t}`,path:[e]}]}}}catch(s){return {issues:[{message:`Validation error for ${e}: ${s instanceof Error?s.message:String(s)}`,path:[e]}]}}};let n;switch(t){case "number":case "port":case "timestamp":n=Number;break;case "boolean":n=Boolean;break;case "url":case "date":n=String;break;case "json":n=Object;break;case "custom":n=Object;break;default:n=String;}return {...a,"~standard":{version:1,vendor:"node-env-resolver",validate:u,types:{input:{},output:n}}}}function R(e){const a={};for(const[t,u]of Object.entries(e))a[t]=x(t,u);return a}async function j(e,a){const t=e["~standard"].validate(a);return t instanceof Promise?await t:t}async function V(e,a){const t={},u=[];for(const[n,i]of Object.entries(e)){const s=a[n],r=await j(i,s);r.issues?u.push(...r.issues.map(o=>o.message)):t[n]=r.value;}if(u.length>0)throw new Error(`Environment validation failed:
|
|
2
|
-
${u.map(n=>` - ${n}`).join(`
|
|
3
|
-
`)}`);return t}export{R as schemaToStandardSchema,x as toStandardSchema,V as validateEnvWithStandardSchema,j as validateWithStandardSchema};
|