node-env-resolver 4.0.0 → 5.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 +493 -376
- package/dist/audit.d.cts +29 -0
- package/dist/audit.d.ts +8 -7
- package/dist/builder.cjs +1 -1
- package/dist/builder.d.cts +149 -0
- package/dist/builder.d.ts +17 -14
- package/dist/builder.js +1 -1
- package/dist/chunk-4QOKRJ3F.cjs +1 -0
- package/dist/chunk-4YVXFL3I.cjs +9 -0
- package/dist/chunk-6D5APQIG.cjs +1 -0
- package/dist/chunk-DIXI6MUB.js +9 -0
- package/dist/chunk-FH54ESWI.cjs +9 -0
- package/dist/chunk-HHOS5S5T.js +1 -0
- package/dist/chunk-TAX63ALN.js +16 -0
- package/dist/chunk-WKIPEKF6.js +1 -0
- package/dist/chunk-XJLMVSPN.js +9 -0
- package/dist/chunk-XPL5XLTA.cjs +16 -0
- package/dist/cli.d.cts +52 -0
- package/dist/cli.d.ts +9 -6
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +148 -0
- package/dist/index.d.ts +99 -92
- package/dist/index.js +1 -1
- package/dist/resolver.cjs +1 -1
- package/dist/resolver.d.cts +20 -0
- package/dist/resolver.d.ts +8 -5
- package/dist/resolver.js +1 -1
- package/dist/resolvers.cjs +1 -1
- package/dist/resolvers.d.cts +412 -0
- package/dist/resolvers.d.ts +294 -22
- package/dist/resolvers.js +1 -1
- package/dist/types.cjs +1 -1
- package/dist/types.d.cts +106 -0
- package/dist/types.d.ts +90 -172
- package/dist/types.js +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.d.cts +213 -0
- package/dist/utils.d.ts +28 -26
- package/dist/utils.js +1 -1
- package/dist/valibot.cjs +1 -1
- package/dist/valibot.d.cts +156 -0
- package/dist/valibot.d.ts +11 -8
- package/dist/valibot.js +1 -1
- package/dist/validation-types.d.cts +29 -0
- package/dist/validation-types.d.ts +4 -3
- package/dist/validators.cjs +2 -1
- package/dist/validators.d.cts +116 -0
- package/dist/validators.d.ts +46 -18
- package/dist/validators.js +2 -1
- package/dist/web.cjs +3 -3
- package/dist/web.d.cts +69 -0
- package/dist/web.d.ts +28 -10
- package/dist/web.js +3 -3
- package/dist/zod.cjs +1 -1
- package/dist/zod.d.cts +135 -0
- package/dist/zod.d.ts +11 -8
- package/dist/zod.js +1 -1
- package/package.json +7 -7
- package/dist/advanced-features.test.d.ts +0 -2
- package/dist/advanced-features.test.d.ts.map +0 -1
- package/dist/audit.d.ts.map +0 -1
- package/dist/audit.test.d.ts +0 -2
- package/dist/audit.test.d.ts.map +0 -1
- package/dist/builder.d.ts.map +0 -1
- package/dist/chunk-54OHKWZJ.js +0 -1
- package/dist/chunk-FCFDGYTF.cjs +0 -15
- package/dist/chunk-HCVTYYLE.js +0 -9
- package/dist/chunk-IU5TG3HL.js +0 -15
- package/dist/chunk-J7ZHEMRP.js +0 -9
- package/dist/chunk-NKPXKLF7.js +0 -1
- package/dist/chunk-P3ZWKKKW.cjs +0 -1
- package/dist/chunk-THFGEKYL.cjs +0 -9
- package/dist/chunk-ULL4WKTV.cjs +0 -9
- package/dist/chunk-XPGSWVRT.cjs +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.test.d.ts +0 -2
- package/dist/cli.test.d.ts.map +0 -1
- package/dist/composition.test.d.ts +0 -7
- package/dist/composition.test.d.ts.map +0 -1
- package/dist/computed.test.d.ts +0 -2
- package/dist/computed.test.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/nested.test.d.ts +0 -2
- package/dist/nested.test.d.ts.map +0 -1
- package/dist/performance.test.d.ts +0 -7
- package/dist/performance.test.d.ts.map +0 -1
- package/dist/priority.test.d.ts +0 -6
- package/dist/priority.test.d.ts.map +0 -1
- package/dist/providers.d.ts +0 -11
- package/dist/providers.d.ts.map +0 -1
- package/dist/resolver.d.ts.map +0 -1
- package/dist/resolvers.d.ts.map +0 -1
- package/dist/resolvers.test.d.ts +0 -2
- package/dist/resolvers.test.d.ts.map +0 -1
- package/dist/sync-resolvers.test.d.ts +0 -2
- package/dist/sync-resolvers.test.d.ts.map +0 -1
- package/dist/type-inference.test.d.ts +0 -2
- package/dist/type-inference.test.d.ts.map +0 -1
- package/dist/type-override.test.d.ts +0 -2
- package/dist/type-override.test.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.test.d.ts +0 -2
- package/dist/utils.test.d.ts.map +0 -1
- package/dist/valibot.d.ts.map +0 -1
- package/dist/validation-types.d.ts.map +0 -1
- package/dist/validators.d.ts.map +0 -1
- package/dist/web.d.ts.map +0 -1
- package/dist/zod.d.ts.map +0 -1
package/dist/utils.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
1
|
+
import { resolveAsync } from './index.js';
|
|
2
|
+
import { Resolver } from './types.js';
|
|
3
|
+
import './validation-types.js';
|
|
4
|
+
import './audit.js';
|
|
5
|
+
|
|
6
|
+
interface CacheOptions {
|
|
6
7
|
/** Time to live in milliseconds (default: 5 minutes) */
|
|
7
8
|
ttl?: number;
|
|
8
9
|
/** Maximum age in milliseconds before forcing refresh (default: 1 hour) */
|
|
@@ -12,8 +13,8 @@ export interface CacheOptions {
|
|
|
12
13
|
/** Custom cache key (useful for debugging or manual cache invalidation) */
|
|
13
14
|
key?: string;
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
declare function cached(resolver: Resolver, options?: CacheOptions): Resolver;
|
|
17
|
+
declare const TTL: {
|
|
17
18
|
/** 30 seconds */
|
|
18
19
|
readonly short: number;
|
|
19
20
|
/** 1 minute */
|
|
@@ -29,7 +30,7 @@ export declare const TTL: {
|
|
|
29
30
|
/** 24 hours */
|
|
30
31
|
readonly day: number;
|
|
31
32
|
};
|
|
32
|
-
|
|
33
|
+
declare function awsCache(options?: {
|
|
33
34
|
/** Cache duration for AWS secrets/parameters (default: 5 minutes) */
|
|
34
35
|
ttl?: number;
|
|
35
36
|
/** Maximum age before forcing refresh (default: 1 hour) */
|
|
@@ -37,7 +38,7 @@ export declare function awsCache(options?: {
|
|
|
37
38
|
/** Enable stale-while-revalidate for better performance (default: true) */
|
|
38
39
|
staleWhileRevalidate?: boolean;
|
|
39
40
|
}): CacheOptions;
|
|
40
|
-
|
|
41
|
+
declare function retry(resolver: Resolver, maxRetries?: number, delayMs?: number): Resolver;
|
|
41
42
|
/**
|
|
42
43
|
* Wrap a resolver to strip a prefix from environment variable names
|
|
43
44
|
* Useful for scoping environment variables (e.g., APP_PORT → PORT)
|
|
@@ -52,12 +53,12 @@ export declare function retry(resolver: Resolver, maxRetries?: number, delayMs?:
|
|
|
52
53
|
* import { withPrefix } from 'node-env-resolver/utils';
|
|
53
54
|
*
|
|
54
55
|
* // Maps APP_PORT → PORT, APP_DATABASE_URL → DATABASE_URL
|
|
55
|
-
* const config = await
|
|
56
|
-
* [withPrefix(processEnv(), 'APP_'), { PORT: 3000, DATABASE_URL:
|
|
56
|
+
* const config = await resolveAsync(
|
|
57
|
+
* [withPrefix(processEnv(), 'APP_'), { PORT: 3000, DATABASE_URL: postgres() }]
|
|
57
58
|
* );
|
|
58
59
|
* ```
|
|
59
60
|
*/
|
|
60
|
-
|
|
61
|
+
declare function withPrefix(resolver: Resolver, prefix: string): Resolver;
|
|
61
62
|
/**
|
|
62
63
|
* Add computed/derived properties to resolved config
|
|
63
64
|
*
|
|
@@ -87,7 +88,7 @@ export declare function withPrefix(resolver: Resolver, prefix: string): Resolver
|
|
|
87
88
|
* console.log(config.isSecure); // false
|
|
88
89
|
* ```
|
|
89
90
|
*/
|
|
90
|
-
|
|
91
|
+
declare function withComputed<TConfig extends Record<string, unknown>, TComputed extends Record<string, (config: TConfig) => unknown>>(config: TConfig, computed: TComputed): TConfig & {
|
|
91
92
|
[K in keyof TComputed]: ReturnType<TComputed[K]>;
|
|
92
93
|
};
|
|
93
94
|
/**
|
|
@@ -104,15 +105,15 @@ export declare function withComputed<TConfig extends Record<string, unknown>, TC
|
|
|
104
105
|
* import { withAliases } from 'node-env-resolver/utils';
|
|
105
106
|
*
|
|
106
107
|
* // Tries PORT, then HTTP_PORT, then SERVER_PORT (first found wins)
|
|
107
|
-
* const config = await
|
|
108
|
+
* const config = await resolveAsync(
|
|
108
109
|
* [withAliases(processEnv(), {
|
|
109
110
|
* PORT: ['PORT', 'HTTP_PORT', 'SERVER_PORT'],
|
|
110
111
|
* DATABASE_URL: ['DATABASE_URL', 'DB_URL', 'POSTGRES_URL']
|
|
111
|
-
* }), { PORT: 3000, DATABASE_URL:
|
|
112
|
+
* }), { PORT: 3000, DATABASE_URL: postgres() }]
|
|
112
113
|
* );
|
|
113
114
|
* ```
|
|
114
115
|
*/
|
|
115
|
-
|
|
116
|
+
declare function withAliases(resolver: Resolver, aliases: Record<string, string[]>): Resolver;
|
|
116
117
|
/**
|
|
117
118
|
* Wrap a resolver to apply custom transformations to values
|
|
118
119
|
* Powerful utility for parsing, coercing, or enriching config values
|
|
@@ -126,7 +127,7 @@ export declare function withAliases(resolver: Resolver, aliases: Record<string,
|
|
|
126
127
|
* import { resolve, processEnv } from 'node-env-resolver';
|
|
127
128
|
* import { withTransform } from 'node-env-resolver/utils';
|
|
128
129
|
*
|
|
129
|
-
* const config = await
|
|
130
|
+
* const config = await resolveAsync(
|
|
130
131
|
* [withTransform(processEnv(), {
|
|
131
132
|
* // Parse comma-separated values
|
|
132
133
|
* TAGS: (val) => val.split(',').map(s => s.trim()),
|
|
@@ -135,14 +136,14 @@ export declare function withAliases(resolver: Resolver, aliases: Record<string,
|
|
|
135
136
|
* // Custom parsing
|
|
136
137
|
* MAX_RETRIES: (val) => Math.min(parseInt(val, 10), 10)
|
|
137
138
|
* }), {
|
|
138
|
-
* TAGS:
|
|
139
|
-
* API_URL:
|
|
139
|
+
* TAGS: string(),
|
|
140
|
+
* API_URL: url(),
|
|
140
141
|
* MAX_RETRIES: 'number'
|
|
141
142
|
* }]
|
|
142
143
|
* );
|
|
143
144
|
* ```
|
|
144
145
|
*/
|
|
145
|
-
|
|
146
|
+
declare function withTransform(resolver: Resolver, transforms: Record<string, (value: string) => string>): Resolver;
|
|
146
147
|
/**
|
|
147
148
|
* Wrap a resolver to scope all keys to a namespace/prefix
|
|
148
149
|
* Similar to withPrefix but adds the namespace instead of removing it
|
|
@@ -158,16 +159,16 @@ export declare function withTransform(resolver: Resolver, transforms: Record<str
|
|
|
158
159
|
*
|
|
159
160
|
* // Reads DATABASE_HOST, DATABASE_PORT from env
|
|
160
161
|
* // But schema only needs HOST, PORT
|
|
161
|
-
* const dbConfig = await
|
|
162
|
+
* const dbConfig = await resolveAsync(
|
|
162
163
|
* [withNamespace(processEnv(), 'DATABASE'), {
|
|
163
|
-
* HOST:
|
|
164
|
+
* HOST: string(),
|
|
164
165
|
* PORT: 'port'
|
|
165
166
|
* }]
|
|
166
167
|
* );
|
|
167
168
|
* // dbConfig: { HOST: '...', PORT: ... }
|
|
168
169
|
* ```
|
|
169
170
|
*/
|
|
170
|
-
|
|
171
|
+
declare function withNamespace(resolver: Resolver, namespace: string): Resolver;
|
|
171
172
|
/**
|
|
172
173
|
* Watch configuration files and reload automatically
|
|
173
174
|
* Perfect for development - auto-reload when .env files change
|
|
@@ -183,7 +184,7 @@ export declare function withNamespace(resolver: Resolver, namespace: string): Re
|
|
|
183
184
|
* import { dotenv, processEnv } from 'node-env-resolver/resolvers';
|
|
184
185
|
*
|
|
185
186
|
* const { getConfig, stop } = watch(
|
|
186
|
-
* { PORT: 3000, API_KEY:
|
|
187
|
+
* { PORT: 3000, API_KEY: string() },
|
|
187
188
|
* [processEnv(), dotenv()],
|
|
188
189
|
* {
|
|
189
190
|
* onChange: (config) => console.log('Config reloaded!', config)
|
|
@@ -197,7 +198,7 @@ export declare function withNamespace(resolver: Resolver, namespace: string): Re
|
|
|
197
198
|
* process.on('SIGINT', () => stop());
|
|
198
199
|
* ```
|
|
199
200
|
*/
|
|
200
|
-
|
|
201
|
+
declare function watch<T>(config: Parameters<typeof resolveAsync>[0], options?: {
|
|
201
202
|
/** Callback when config changes */
|
|
202
203
|
onChange?: (config: T) => void;
|
|
203
204
|
/** Debounce delay in ms (default: 100) */
|
|
@@ -208,4 +209,5 @@ export declare function watch<T>(schema: Parameters<typeof import('./index').res
|
|
|
208
209
|
getConfig: () => T;
|
|
209
210
|
stop: () => void;
|
|
210
211
|
};
|
|
211
|
-
|
|
212
|
+
|
|
213
|
+
export { type CacheOptions, TTL, awsCache, cached, retry, watch, withAliases, withComputed, withNamespace, withPrefix, withTransform };
|
package/dist/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a}from'./chunk-5PELJRUQ.js';function
|
|
1
|
+
import {b as b$1}from'./chunk-XJLMVSPN.js';import'./chunk-DIXI6MUB.js';import'./chunk-YOHHFBZN.js';import'./chunk-WKIPEKF6.js';import'./chunk-HHOS5S5T.js';import {a}from'./chunk-5PELJRUQ.js';function T(e,n={}){let{ttl:r=3e5,maxAge:s=36e5,staleWhileRevalidate:o=false}=n,t=null,a={name:`cached(${e.name})`,metadata:{},async load(){let i=Date.now();if(!t||i-t.timestamp>s){let l=e.load?await e.load():{};return t={data:l,timestamp:i},a.metadata={cached:false},l}if(i-t.timestamp<r)return a.metadata={cached:true},t.data;if(o&&!t.refreshPromise){let l=Promise.resolve(e.load?e.load():Promise.resolve({}));return t.refreshPromise=l.then(u=>(t.data=u,t.timestamp=Date.now(),t.refreshPromise=void 0,u)).catch(()=>(t.refreshPromise=void 0,t.data)),a.metadata={cached:true,stale:true},t.data}let d=e.load?await e.load():{};return t={data:d,timestamp:i},a.metadata={cached:false},d}};return a}var p={short:30*1e3,minute:60*1e3,minutes5:300*1e3,minutes15:900*1e3,hour:3600*1e3,hours6:360*60*1e3,day:1440*60*1e3};function C(e={}){return {ttl:e.ttl??p.minutes5,maxAge:e.maxAge??p.hour,staleWhileRevalidate:e.staleWhileRevalidate??true,key:"aws-secrets"}}function b(e,n=3,r=1e3){return {name:`retry(${e.name})`,async load(){let s;for(let o=0;o<=n;o++)try{return e.load?await e.load():{}}catch(t){s=t instanceof Error?t:new Error(String(t)),o<n&&await new Promise(a=>setTimeout(a,r*Math.pow(2,o)));}throw s}}}function x(e,n){let r=n.toUpperCase();return {name:`withPrefix(${e.name}, ${n})`,async load(){let s=e.load?await e.load():{},o={};for(let[t,a]of Object.entries(s))if(t.toUpperCase().startsWith(r)){let i=t.slice(n.length);o[i]=a;}else o[t]=a;return o},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let s=e.loadSync(),o={};for(let[t,a]of Object.entries(s))if(t.toUpperCase().startsWith(r)){let i=t.slice(n.length);o[i]=a;}else o[t]=a;return o}}}function P(e,n){let r={...e};for(let[s,o]of Object.entries(n))Object.defineProperty(r,s,{get(){return o(e)},enumerable:true,configurable:true});return r}function $(e,n){return {name:`withAliases(${e.name})`,async load(){let r=e.load?await e.load():{};return g(r,n)},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let r=e.loadSync();return g(r,n)}}}function g(e,n){let r={...e};for(let[s,o]of Object.entries(n))for(let t of o)if(e[t]!==void 0){r[s]=e[t];break}return r}function S(e,n){return {name:`withTransform(${e.name})`,async load(){let r=e.load?await e.load():{};return h(r,n)},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let r=e.loadSync();return h(r,n)}}}function h(e,n){let r={...e};for(let[s,o]of Object.entries(n))if(e[s]!==void 0)try{r[s]=o(e[s]);}catch(t){throw new Error(`Transform failed for ${s}: ${t instanceof Error?t.message:String(t)}`)}return r}function k(e,n){let s=`${n.toUpperCase()}_`;return {name:`withNamespace(${e.name}, ${n})`,async load(){let o=e.load?await e.load():{},t={};for(let[a,i]of Object.entries(o))if(a.toUpperCase().startsWith(s)){let d=a.slice(s.length);t[d]=i;}return t},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let o=e.loadSync(),t={};for(let[a,i]of Object.entries(o))if(a.toUpperCase().startsWith(s)){let d=a.slice(s.length);t[d]=i;}return t}}}function v(e,n){let{onChange:r,debounce:s=100,files:o=[".env"]}=n??{},t,a$1=null,i=[],d=async()=>{try{return await import('./index.js'),t=await b$1(e),t}catch(c){throw console.error("[watch] Failed to load config:",c),c}},l=()=>{a$1&&clearTimeout(a$1),a$1=setTimeout(async()=>{try{let c=await d();r?.(c);}catch(c){console.error("[watch] Failed to reload config:",c);}},s);},{watch:u}=a("fs"),{join:y}=a("path");for(let c of o)try{let w=u(y(process.cwd(),c),l);i.push(w);}catch{}return d().catch(console.error),{getConfig:()=>t,stop:()=>{a$1&&clearTimeout(a$1);for(let c of i)c.close();}}}export{p as TTL,C as awsCache,T as cached,b as retry,v as watch,$ as withAliases,P as withComputed,k as withNamespace,x as withPrefix,S as withTransform};
|
package/dist/valibot.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';
|
|
1
|
+
'use strict';require('./chunk-XPL5XLTA.cjs');var chunk4QOKRJ3F_cjs=require('./chunk-4QOKRJ3F.cjs');require('./chunk-KIQXH265.cjs');async function u(t,n,e){let s={};for(let o of t)try{let r=o.load?await o.load():{};s={...s,...r};}catch(r){if(e)throw new Error(`Resolver ${o.name} failed: ${r instanceof Error?r.message:r}`)}if(n)for(let[o,r]of Object.entries(s))s[o]=r.replace(/\$\{([^}]+)\}/g,(a,i)=>s[i]||"");return s}function p(t,n,e){let s={};for(let o of t)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(n)for(let[o,r]of Object.entries(s))s[o]=r.replace(/\$\{([^}]+)\}/g,(a,i)=>s[i]||"");return s}function f(t){return !t||!Array.isArray(t)?[{path:[],message:"Validation failed",code:"unknown_error"}]:t.map(n=>{if(!n||typeof n!="object")return {path:[],message:"Validation failed",code:"unknown_error"};let e=n;return {path:e.path?.map(s=>s.key)||[],message:e.message||"Validation failed",code:e.type}})}async function d(t,n={}){let{resolvers:e=[chunk4QOKRJ3F_cjs.a()],interpolate:s=false,strict:o=true}=n,r=await u(e,s,o);return t.parseAsync(r)}async function y(t,n={}){try{let{resolvers:e=[chunk4QOKRJ3F_cjs.a()],interpolate:s=!1,strict:o=!0}=n,r=await u(e,s,o),a=await t.safeParseAsync(r);if(a.success)return {success:!0,data:a.output};let i=f(a.issues);return {success:!1,error:i.map(l=>l.message).join(", "),issues:i}}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 g(t,n={}){let{resolvers:e=[chunk4QOKRJ3F_cjs.a()],interpolate:s=false,strict:o=true}=n,r=p(e,s,o);return t.parse(r)}function b(t,n={}){try{let{resolvers:e=[chunk4QOKRJ3F_cjs.a()],interpolate:s=!1,strict:o=!0}=n,r=p(e,s,o),a=t.safeParse(r);if(a.success)return {success:!0,data:a.output};let i=f(a.issues);return {success:!1,error:i.map(l=>l.message).join(", "),issues:i}}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"}]}}}exports.resolveSyncValibot=g;exports.resolveValibot=d;exports.safeResolveSyncValibot=b;exports.safeResolveValibot=y;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Resolver, PolicyOptions } from './types.cjs';
|
|
2
|
+
import { SafeResolveResult } from './validation-types.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Valibot integration for node-env-resolver
|
|
6
|
+
* Import from 'node-env-resolver/valibot' to use this
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { resolveValibot } from 'node-env-resolver/valibot';
|
|
11
|
+
* import * as v from 'valibot';
|
|
12
|
+
*
|
|
13
|
+
* const schema = v.object({
|
|
14
|
+
* PORT: v.pipe(v.string(), v.transform(Number)),
|
|
15
|
+
* DATABASE_URL: v.pipe(v.string(), v.url())
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* const config = await resolveValibot(schema);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Type inference for Valibot schema output
|
|
24
|
+
* Uses Valibot's InferOutput if available, falls back to generic inference
|
|
25
|
+
*/
|
|
26
|
+
type InferValibotOutput<T> = T extends {
|
|
27
|
+
_types?: {
|
|
28
|
+
output: infer O;
|
|
29
|
+
};
|
|
30
|
+
} ? O : T extends {
|
|
31
|
+
parse: (input: unknown) => infer R;
|
|
32
|
+
} ? R : unknown;
|
|
33
|
+
/**
|
|
34
|
+
* Resolve environment variables using Valibot schema (throws on validation error)
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { resolveValibot } from 'node-env-resolver/valibot';
|
|
39
|
+
* import * as v from 'valibot';
|
|
40
|
+
*
|
|
41
|
+
* const schema = v.object({
|
|
42
|
+
* PORT: v.pipe(v.string(), v.transform(Number)),
|
|
43
|
+
* DATABASE_URL: v.pipe(v.string(), v.url())
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* const env = await resolveValibot(schema);
|
|
47
|
+
* console.log(env.PORT); // number
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
declare function resolveValibot<TSchema extends {
|
|
51
|
+
parseAsync: (input: unknown) => Promise<unknown>;
|
|
52
|
+
}>(valibotSchema: TSchema, options?: {
|
|
53
|
+
resolvers?: Resolver[];
|
|
54
|
+
interpolate?: boolean;
|
|
55
|
+
strict?: boolean;
|
|
56
|
+
policies?: PolicyOptions;
|
|
57
|
+
}): Promise<InferValibotOutput<TSchema>>;
|
|
58
|
+
/**
|
|
59
|
+
* Safe version - returns result object instead of throwing (unified error format)
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { safeResolveValibot } from 'node-env-resolver/valibot';
|
|
64
|
+
* import * as v from 'valibot';
|
|
65
|
+
*
|
|
66
|
+
* const schema = v.object({
|
|
67
|
+
* PORT: v.pipe(v.string(), v.transform(Number)),
|
|
68
|
+
* DATABASE_URL: v.pipe(v.string(), v.url())
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* const result = await safeResolveValibot(schema);
|
|
72
|
+
*
|
|
73
|
+
* if (result.success) {
|
|
74
|
+
* console.log(result.data.PORT);
|
|
75
|
+
* } else {
|
|
76
|
+
* console.error(result.error);
|
|
77
|
+
* result.issues.forEach(issue => {
|
|
78
|
+
* console.log(`${issue.path.join('.')}: ${issue.message}`);
|
|
79
|
+
* });
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
declare function safeResolveValibot<TSchema extends {
|
|
84
|
+
safeParseAsync: (input: unknown) => Promise<{
|
|
85
|
+
success: boolean;
|
|
86
|
+
output?: unknown;
|
|
87
|
+
issues?: unknown;
|
|
88
|
+
}>;
|
|
89
|
+
}>(valibotSchema: TSchema, options?: {
|
|
90
|
+
resolvers?: Resolver[];
|
|
91
|
+
interpolate?: boolean;
|
|
92
|
+
strict?: boolean;
|
|
93
|
+
policies?: PolicyOptions;
|
|
94
|
+
}): Promise<SafeResolveResult<InferValibotOutput<TSchema>>>;
|
|
95
|
+
/**
|
|
96
|
+
* Sync version of resolveValibot (throws on validation error)
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { resolveSyncValibot } from 'node-env-resolver/valibot';
|
|
101
|
+
* import * as v from 'valibot';
|
|
102
|
+
*
|
|
103
|
+
* const schema = v.object({
|
|
104
|
+
* PORT: v.pipe(v.string(), v.transform(Number))
|
|
105
|
+
* });
|
|
106
|
+
*
|
|
107
|
+
* const env = resolveSyncValibot(schema);
|
|
108
|
+
* console.log(env.PORT);
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare function resolveSyncValibot<TSchema extends {
|
|
112
|
+
parse: (input: unknown) => unknown;
|
|
113
|
+
}>(valibotSchema: TSchema, options?: {
|
|
114
|
+
resolvers?: Resolver[];
|
|
115
|
+
interpolate?: boolean;
|
|
116
|
+
strict?: boolean;
|
|
117
|
+
policies?: PolicyOptions;
|
|
118
|
+
}): InferValibotOutput<TSchema>;
|
|
119
|
+
/**
|
|
120
|
+
* Safe sync version - returns result object instead of throwing (unified error format)
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { safeResolveSyncValibot } from 'node-env-resolver/valibot';
|
|
125
|
+
* import * as v from 'valibot';
|
|
126
|
+
*
|
|
127
|
+
* const schema = v.object({
|
|
128
|
+
* PORT: v.pipe(v.string(), v.transform(Number))
|
|
129
|
+
* });
|
|
130
|
+
*
|
|
131
|
+
* const result = safeResolveSyncValibot(schema);
|
|
132
|
+
*
|
|
133
|
+
* if (result.success) {
|
|
134
|
+
* console.log(result.data.PORT);
|
|
135
|
+
* } else {
|
|
136
|
+
* console.error(result.error);
|
|
137
|
+
* result.issues.forEach(issue => {
|
|
138
|
+
* console.log(`${issue.path.join('.')}: ${issue.message}`);
|
|
139
|
+
* });
|
|
140
|
+
* }
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
declare function safeResolveSyncValibot<TSchema extends {
|
|
144
|
+
safeParse: (input: unknown) => {
|
|
145
|
+
success: boolean;
|
|
146
|
+
output?: unknown;
|
|
147
|
+
issues?: unknown;
|
|
148
|
+
};
|
|
149
|
+
}>(valibotSchema: TSchema, options?: {
|
|
150
|
+
resolvers?: Resolver[];
|
|
151
|
+
interpolate?: boolean;
|
|
152
|
+
strict?: boolean;
|
|
153
|
+
policies?: PolicyOptions;
|
|
154
|
+
}): SafeResolveResult<InferValibotOutput<TSchema>>;
|
|
155
|
+
|
|
156
|
+
export { type InferValibotOutput, resolveSyncValibot, resolveValibot, safeResolveSyncValibot, safeResolveValibot };
|
package/dist/valibot.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Resolver, PolicyOptions } from './types.js';
|
|
2
|
+
import { SafeResolveResult } from './validation-types.js';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Valibot integration for node-env-resolver
|
|
3
6
|
* Import from 'node-env-resolver/valibot' to use this
|
|
@@ -15,13 +18,12 @@
|
|
|
15
18
|
* const config = await resolveValibot(schema);
|
|
16
19
|
* ```
|
|
17
20
|
*/
|
|
18
|
-
|
|
19
|
-
import type { SafeResolveResult } from './validation-types';
|
|
21
|
+
|
|
20
22
|
/**
|
|
21
23
|
* Type inference for Valibot schema output
|
|
22
24
|
* Uses Valibot's InferOutput if available, falls back to generic inference
|
|
23
25
|
*/
|
|
24
|
-
|
|
26
|
+
type InferValibotOutput<T> = T extends {
|
|
25
27
|
_types?: {
|
|
26
28
|
output: infer O;
|
|
27
29
|
};
|
|
@@ -45,7 +47,7 @@ export type InferValibotOutput<T> = T extends {
|
|
|
45
47
|
* console.log(env.PORT); // number
|
|
46
48
|
* ```
|
|
47
49
|
*/
|
|
48
|
-
|
|
50
|
+
declare function resolveValibot<TSchema extends {
|
|
49
51
|
parseAsync: (input: unknown) => Promise<unknown>;
|
|
50
52
|
}>(valibotSchema: TSchema, options?: {
|
|
51
53
|
resolvers?: Resolver[];
|
|
@@ -78,7 +80,7 @@ export declare function resolveValibot<TSchema extends {
|
|
|
78
80
|
* }
|
|
79
81
|
* ```
|
|
80
82
|
*/
|
|
81
|
-
|
|
83
|
+
declare function safeResolveValibot<TSchema extends {
|
|
82
84
|
safeParseAsync: (input: unknown) => Promise<{
|
|
83
85
|
success: boolean;
|
|
84
86
|
output?: unknown;
|
|
@@ -106,7 +108,7 @@ export declare function safeResolveValibot<TSchema extends {
|
|
|
106
108
|
* console.log(env.PORT);
|
|
107
109
|
* ```
|
|
108
110
|
*/
|
|
109
|
-
|
|
111
|
+
declare function resolveSyncValibot<TSchema extends {
|
|
110
112
|
parse: (input: unknown) => unknown;
|
|
111
113
|
}>(valibotSchema: TSchema, options?: {
|
|
112
114
|
resolvers?: Resolver[];
|
|
@@ -138,7 +140,7 @@ export declare function resolveSyncValibot<TSchema extends {
|
|
|
138
140
|
* }
|
|
139
141
|
* ```
|
|
140
142
|
*/
|
|
141
|
-
|
|
143
|
+
declare function safeResolveSyncValibot<TSchema extends {
|
|
142
144
|
safeParse: (input: unknown) => {
|
|
143
145
|
success: boolean;
|
|
144
146
|
output?: unknown;
|
|
@@ -150,4 +152,5 @@ export declare function safeResolveSyncValibot<TSchema extends {
|
|
|
150
152
|
strict?: boolean;
|
|
151
153
|
policies?: PolicyOptions;
|
|
152
154
|
}): SafeResolveResult<InferValibotOutput<TSchema>>;
|
|
153
|
-
|
|
155
|
+
|
|
156
|
+
export { type InferValibotOutput, resolveSyncValibot, resolveValibot, safeResolveSyncValibot, safeResolveValibot };
|
package/dist/valibot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import'./chunk-TAX63ALN.js';import {a}from'./chunk-WKIPEKF6.js';import'./chunk-5PELJRUQ.js';async function u(t,n,e){let s={};for(let o of t)try{let r=o.load?await o.load():{};s={...s,...r};}catch(r){if(e)throw new Error(`Resolver ${o.name} failed: ${r instanceof Error?r.message:r}`)}if(n)for(let[o,r]of Object.entries(s))s[o]=r.replace(/\$\{([^}]+)\}/g,(a,i)=>s[i]||"");return s}function p(t,n,e){let s={};for(let o of t)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(n)for(let[o,r]of Object.entries(s))s[o]=r.replace(/\$\{([^}]+)\}/g,(a,i)=>s[i]||"");return s}function f(t){return !t||!Array.isArray(t)?[{path:[],message:"Validation failed",code:"unknown_error"}]:t.map(n=>{if(!n||typeof n!="object")return {path:[],message:"Validation failed",code:"unknown_error"};let e=n;return {path:e.path?.map(s=>s.key)||[],message:e.message||"Validation failed",code:e.type}})}async function d(t,n={}){let{resolvers:e=[a()],interpolate:s=false,strict:o=true}=n,r=await u(e,s,o);return t.parseAsync(r)}async function y(t,n={}){try{let{resolvers:e=[a()],interpolate:s=!1,strict:o=!0}=n,r=await u(e,s,o),a$1=await t.safeParseAsync(r);if(a$1.success)return {success:!0,data:a$1.output};let i=f(a$1.issues);return {success:!1,error:i.map(l=>l.message).join(", "),issues:i}}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 g(t,n={}){let{resolvers:e=[a()],interpolate:s=false,strict:o=true}=n,r=p(e,s,o);return t.parse(r)}function b(t,n={}){try{let{resolvers:e=[a()],interpolate:s=!1,strict:o=!0}=n,r=p(e,s,o),a$1=t.safeParse(r);if(a$1.success)return {success:!0,data:a$1.output};let i=f(a$1.issues);return {success:!1,error:i.map(l=>l.message).join(", "),issues:i}}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{g as resolveSyncValibot,d as resolveValibot,b as safeResolveSyncValibot,y as safeResolveValibot};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified validation types for all integrations (Zod, Valibot, etc.)
|
|
3
|
+
* These types compile away at runtime (0 bytes)
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Represents a single validation issue with field-level details
|
|
7
|
+
*/
|
|
8
|
+
interface ValidationIssue {
|
|
9
|
+
/** Path to the field that failed validation, e.g. ['DATABASE_URL'] or ['user', 'email'] */
|
|
10
|
+
path: (string | number)[];
|
|
11
|
+
/** Human-readable error message */
|
|
12
|
+
message: string;
|
|
13
|
+
/** Optional error code for programmatic handling, e.g. 'invalid_url', 'required' */
|
|
14
|
+
code?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Result type for safe resolve functions
|
|
18
|
+
* Consistent across all validators (Zod, Valibot, built-in)
|
|
19
|
+
*/
|
|
20
|
+
type SafeResolveResult<T> = {
|
|
21
|
+
success: true;
|
|
22
|
+
data: T;
|
|
23
|
+
} | {
|
|
24
|
+
success: false;
|
|
25
|
+
error: string;
|
|
26
|
+
issues: ValidationIssue[];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type { SafeResolveResult, ValidationIssue };
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* Represents a single validation issue with field-level details
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
interface ValidationIssue {
|
|
9
9
|
/** Path to the field that failed validation, e.g. ['DATABASE_URL'] or ['user', 'email'] */
|
|
10
10
|
path: (string | number)[];
|
|
11
11
|
/** Human-readable error message */
|
|
@@ -17,7 +17,7 @@ export interface ValidationIssue {
|
|
|
17
17
|
* Result type for safe resolve functions
|
|
18
18
|
* Consistent across all validators (Zod, Valibot, built-in)
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
type SafeResolveResult<T> = {
|
|
21
21
|
success: true;
|
|
22
22
|
data: T;
|
|
23
23
|
} | {
|
|
@@ -25,4 +25,5 @@ export type SafeResolveResult<T> = {
|
|
|
25
25
|
error: string;
|
|
26
26
|
issues: ValidationIssue[];
|
|
27
27
|
};
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
export type { SafeResolveResult, ValidationIssue };
|
package/dist/validators.cjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkKIQXH265_cjs=require('./chunk-KIQXH265.cjs');function d(t){if(!/^postgres(ql)?:\/\/.+/.test(t))return {valid:false,error:"Invalid PostgreSQL URL"};try{return new URL(t),{valid:!0}}catch{return {valid:false,error:"Invalid PostgreSQL URL"}}}function u(t){if(!/^mysql:\/\/.+/.test(t))return {valid:false,error:"Invalid MySQL URL"};try{return new URL(t),{valid:!0}}catch{return {valid:false,error:"Invalid MySQL URL"}}}function f(t){return /^mongodb(\+srv)?:\/\/.+/.test(t)?/^mongodb(\+srv)?:\/\/([^@]+@)?[^/]+(\/[^?]*)?(\\?.*)?$/.test(t)?{valid:true}:{valid:false,error:"Invalid MongoDB URL"}:{valid:false,error:"Invalid MongoDB URL"}}function c(t){if(!/^rediss?:\/\/.+/.test(t))return {valid:false,error:"Invalid Redis URL"};try{return new URL(t),{valid:!0}}catch{return {valid:false,error:"Invalid Redis URL"}}}function v(t){if(!/^https?:\/\/.+/.test(t))return {valid:false,error:"Invalid HTTP URL"};try{return new URL(t),{valid:!0}}catch{return {valid:false,error:"Invalid HTTP URL"}}}function p(t){if(!/^https:\/\/.+/.test(t))return {valid:false,error:"Invalid HTTPS URL"};try{return new URL(t),{valid:!0}}catch{return {valid:false,error:"Invalid HTTPS URL"}}}function m(t){try{let r=new URL(t);return ["http:","https:","ws:","wss:","ftp:","ftps:","file:","postgres:","postgresql:","mysql:","mongodb:","redis:","rediss:"].includes(r.protocol)?{valid:!0}:{valid:!1,error:`URL protocol '${r.protocol}' is not allowed`}}catch{return {valid:false,error:"Invalid URL"}}}function g(t){return /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(t)?t.length>254?{valid:false,error:"Invalid email"}:{valid:true}:{valid:false,error:"Invalid email"}}function R(t){let r=Number(t);return r!==r||r<1||r>65535?{valid:false,error:"Invalid port"}:{valid:true}}function h(t){let r=Number(t);return r!==r?{valid:false,error:"Invalid number"}:{valid:true}}function w(t){let r=t.toLowerCase();return ["true","1","yes","on","false","0","no","off",""].includes(r)?{valid:true}:{valid:false,error:"Invalid boolean"}}function I(t){try{return JSON.parse(t),{valid:!0}}catch{return {valid:false,error:"Invalid JSON"}}}function x(t){let r=new Date(t);if(isNaN(r.getTime()))return {valid:false,error:"Invalid date - cannot parse date value"};if(/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d{1,3})?(Z|[+-]\d{2}:\d{2})?)?$/.test(t)){if(/^\d{4}-\d{2}-\d{2}$/.test(t)){let[i,a,n]=t.split("-").map(Number);if(r.getUTCFullYear()!==i||r.getUTCMonth()+1!==a||r.getUTCDate()!==n)return {valid:false,error:"Invalid date value"}}return {valid:true}}return {valid:false,error:"Date must be in ISO 8601 format (YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss.sssZ)"}}function L(t){if(!/^\d+$/.test(t))return {valid:false,error:"Invalid timestamp"};let r=Number(t);return isNaN(r)||r<0?{valid:false,error:"Invalid timestamp"}:r>253402300799?{valid:false,error:"Timestamp too large"}:{valid:true}}function U(t){let r=/^(\d+(?:\.\d+)?)(ms|s|m|h|d)$/,e=/^(?:(\d+(?:\.\d+)?)h)?(?:(\d+(?:\.\d+)?)m)?(?:(\d+(?:\.\d+)?)s)?(?:(\d+(?:\.\d+)?)ms)?$/,i=t.match(r);if(i){let n=parseFloat(i[1]),l=i[2],s={ms:1,s:1e3,m:60*1e3,h:3600*1e3,d:1440*60*1e3};return {valid:true,value:Math.floor(n*s[l])}}let a=t.match(e);if(a&&a[0]){let n=0;if(a[1]&&(n+=parseFloat(a[1])*60*60*1e3),a[2]&&(n+=parseFloat(a[2])*60*1e3),a[3]&&(n+=parseFloat(a[3])*1e3),a[4]&&(n+=parseFloat(a[4])),n>0)return {valid:true,value:Math.floor(n)}}return {valid:false,error:"Duration must be in format: 5s, 2h, 30m, 1h30m, etc."}}function V(t,r){try{let e=chunkKIQXH265_cjs.a("fs"),{resolve:i}=chunkKIQXH265_cjs.a("path"),a=i(process.cwd(),t);return {valid:!0,value:e.readFileSync(a,"utf8").trim()}}catch(e){return {valid:false,error:`Failed to read file${r?` for ${r}`:""}: ${e instanceof Error?e.message:String(e)}`}}}function y(t){let r=e=>{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid HTTP URL: "${e}"`);return e};return t&&(r.default=t.default,r.optional=t.optional),r}function b(t){let r=e=>{try{return JSON.parse(e)}catch{throw new Error(`Invalid JSON: "${e}"`)}};return t&&(r.default=t.default,r.optional=t.optional),r}
|
|
2
|
+
exports.httpValidator=y;exports.jsonValidator=b;exports.validateBoolean=w;exports.validateDate=x;exports.validateDuration=U;exports.validateEmail=g;exports.validateFile=V;exports.validateHttp=v;exports.validateHttps=p;exports.validateJson=I;exports.validateMongodb=f;exports.validateMysql=u;exports.validateNumber=h;exports.validatePort=R;exports.validatePostgres=d;exports.validateRedis=c;exports.validateTimestamp=L;exports.validateUrl=m;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Validator } from './types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shared validation functions for advanced environment variable types
|
|
5
|
+
* Import these when you need advanced validation beyond basic string/number/boolean
|
|
6
|
+
*
|
|
7
|
+
* These validators are tree-shakeable - only included if you use advanced types like:
|
|
8
|
+
* 'postgres', 'mysql', 'mongodb', 'redis', 'http', 'https', 'url', 'email', 'port', 'json', 'date', 'timestamp'
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface ValidationResult {
|
|
12
|
+
valid: boolean;
|
|
13
|
+
error?: string;
|
|
14
|
+
value?: unknown;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Validate PostgreSQL connection string
|
|
18
|
+
*/
|
|
19
|
+
declare function validatePostgres(value: string): ValidationResult;
|
|
20
|
+
/**
|
|
21
|
+
* Validate MySQL connection string
|
|
22
|
+
*/
|
|
23
|
+
declare function validateMysql(value: string): ValidationResult;
|
|
24
|
+
/**
|
|
25
|
+
* Validate MongoDB connection string
|
|
26
|
+
* Supports mongodb:// and mongodb+srv:// with replica sets
|
|
27
|
+
*/
|
|
28
|
+
declare function validateMongodb(value: string): ValidationResult;
|
|
29
|
+
/**
|
|
30
|
+
* Validate Redis connection string
|
|
31
|
+
* Supports redis:// and rediss:// (TLS)
|
|
32
|
+
*/
|
|
33
|
+
declare function validateRedis(value: string): ValidationResult;
|
|
34
|
+
/**
|
|
35
|
+
* Validate HTTP/HTTPS URL (accepts both)
|
|
36
|
+
*/
|
|
37
|
+
declare function validateHttp(value: string): ValidationResult;
|
|
38
|
+
/**
|
|
39
|
+
* Validate HTTPS URL only (strict)
|
|
40
|
+
*/
|
|
41
|
+
declare function validateHttps(value: string): ValidationResult;
|
|
42
|
+
/**
|
|
43
|
+
* Validate generic URL (with protocol whitelist for security)
|
|
44
|
+
*/
|
|
45
|
+
declare function validateUrl(value: string): ValidationResult;
|
|
46
|
+
/**
|
|
47
|
+
* Validate email address
|
|
48
|
+
*/
|
|
49
|
+
declare function validateEmail(value: string): ValidationResult;
|
|
50
|
+
/**
|
|
51
|
+
* Validate port number
|
|
52
|
+
*/
|
|
53
|
+
declare function validatePort(value: string): ValidationResult;
|
|
54
|
+
/**
|
|
55
|
+
* Validate number
|
|
56
|
+
*/
|
|
57
|
+
declare function validateNumber(value: string): ValidationResult;
|
|
58
|
+
/**
|
|
59
|
+
* Validate boolean
|
|
60
|
+
*/
|
|
61
|
+
declare function validateBoolean(value: string): ValidationResult;
|
|
62
|
+
/**
|
|
63
|
+
* Validate JSON
|
|
64
|
+
*/
|
|
65
|
+
declare function validateJson(value: string): ValidationResult;
|
|
66
|
+
/**
|
|
67
|
+
* Validate and normalize date string to ISO 8601
|
|
68
|
+
* Accepts various formats and coerces them to YYYY-MM-DD or ISO 8601 datetime
|
|
69
|
+
*/
|
|
70
|
+
declare function validateDate(value: string): ValidationResult;
|
|
71
|
+
/**
|
|
72
|
+
* Validate Unix timestamp (seconds since epoch)
|
|
73
|
+
*/
|
|
74
|
+
declare function validateTimestamp(value: string): ValidationResult;
|
|
75
|
+
/**
|
|
76
|
+
* Validate and parse time duration (Go-style: 5s, 2h, 30m, etc.)
|
|
77
|
+
* Returns milliseconds
|
|
78
|
+
*/
|
|
79
|
+
declare function validateDuration(value: string): ValidationResult & {
|
|
80
|
+
value?: number;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Read and validate file content
|
|
84
|
+
* Reads the file at the path specified in the value
|
|
85
|
+
*
|
|
86
|
+
* @param value - File path to read
|
|
87
|
+
* @param key - Optional env var key name (for error messages)
|
|
88
|
+
* @returns ValidationResult with file content or error
|
|
89
|
+
*/
|
|
90
|
+
declare function validateFile(value: string, key?: string): ValidationResult;
|
|
91
|
+
declare function httpValidator<Opts extends {
|
|
92
|
+
default?: string;
|
|
93
|
+
optional?: boolean;
|
|
94
|
+
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
95
|
+
optional: true;
|
|
96
|
+
} ? Validator<string> & {
|
|
97
|
+
optional: true;
|
|
98
|
+
default?: Opts['default'];
|
|
99
|
+
} : Validator<string> & {
|
|
100
|
+
optional?: Opts['optional'];
|
|
101
|
+
default?: Opts['default'];
|
|
102
|
+
};
|
|
103
|
+
declare function jsonValidator<Opts extends {
|
|
104
|
+
default?: unknown;
|
|
105
|
+
optional?: boolean;
|
|
106
|
+
} = Record<string, never>>(opts?: Opts): Opts extends {
|
|
107
|
+
optional: true;
|
|
108
|
+
} ? Validator<unknown> & {
|
|
109
|
+
optional: true;
|
|
110
|
+
default?: Opts['default'];
|
|
111
|
+
} : Validator<unknown> & {
|
|
112
|
+
optional?: Opts['optional'];
|
|
113
|
+
default?: Opts['default'];
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export { type ValidationResult, httpValidator, jsonValidator, validateBoolean, validateDate, validateDuration, validateEmail, validateFile, validateHttp, validateHttps, validateJson, validateMongodb, validateMysql, validateNumber, validatePort, validatePostgres, validateRedis, validateTimestamp, validateUrl };
|