node-env-resolver 4.0.0 → 5.0.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/README.md +289 -251
- 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-4YVXFL3I.cjs +9 -0
- package/dist/chunk-6FXCXA4R.cjs +11 -0
- package/dist/chunk-BFLXBLZ3.cjs +1 -0
- package/dist/chunk-BJ2QNYTS.js +11 -0
- package/dist/chunk-DIXI6MUB.js +9 -0
- package/dist/chunk-P3TTYVEW.js +16 -0
- package/dist/chunk-UCLEPPLS.cjs +16 -0
- package/dist/chunk-ZMRT37K3.js +1 -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 +150 -0
- package/dist/index.d.ts +86 -77
- 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 +407 -0
- package/dist/resolvers.d.ts +289 -22
- package/dist/resolvers.js +1 -1
- package/dist/types.cjs +1 -1
- package/dist/types.d.cts +74 -0
- package/dist/types.d.ts +58 -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 +4 -4
- package/dist/web.d.cts +69 -0
- package/dist/web.d.ts +28 -10
- package/dist/web.js +4 -4
- 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.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a}from'./chunk-5PELJRUQ.js';function
|
|
1
|
+
import {c}from'./chunk-BJ2QNYTS.js';import'./chunk-DIXI6MUB.js';import'./chunk-YOHHFBZN.js';import'./chunk-ZMRT37K3.js';import {a}from'./chunk-5PELJRUQ.js';function C(e,n={}){let{ttl:r=3e5,maxAge:a=36e5,staleWhileRevalidate:o=false}=n,t=null,s={name:`cached(${e.name})`,metadata:{},async load(){let i=Date.now();if(!t||i-t.timestamp>a){let l=e.load?await e.load():{};return t={data:l,timestamp:i},s.metadata={cached:false},l}if(i-t.timestamp<r)return s.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)),s.metadata={cached:true,stale:true},t.data}let d=e.load?await e.load():{};return t={data:d,timestamp:i},s.metadata={cached:false},d}};return s}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 b(e={}){return {ttl:e.ttl??p.minutes5,maxAge:e.maxAge??p.hour,staleWhileRevalidate:e.staleWhileRevalidate??true,key:"aws-secrets"}}function x(e,n=3,r=1e3){return {name:`retry(${e.name})`,async load(){let a;for(let o=0;o<=n;o++)try{return e.load?await e.load():{}}catch(t){a=t instanceof Error?t:new Error(String(t)),o<n&&await new Promise(s=>setTimeout(s,r*Math.pow(2,o)));}throw a}}}function P(e,n){let r=n.toUpperCase();return {name:`withPrefix(${e.name}, ${n})`,async load(){let a=e.load?await e.load():{},o={};for(let[t,s]of Object.entries(a))if(t.toUpperCase().startsWith(r)){let i=t.slice(n.length);o[i]=s;}else o[t]=s;return o},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let a=e.loadSync(),o={};for(let[t,s]of Object.entries(a))if(t.toUpperCase().startsWith(r)){let i=t.slice(n.length);o[i]=s;}else o[t]=s;return o}}}function $(e,n){let r={...e};for(let[a,o]of Object.entries(n))Object.defineProperty(r,a,{get(){return o(e)},enumerable:true,configurable:true});return r}function S(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[a,o]of Object.entries(n))for(let t of o)if(e[t]!==void 0){r[a]=e[t];break}return r}function k(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[a,o]of Object.entries(n))if(e[a]!==void 0)try{r[a]=o(e[a]);}catch(t){throw new Error(`Transform failed for ${a}: ${t instanceof Error?t.message:String(t)}`)}return r}function v(e,n){let a=`${n.toUpperCase()}_`;return {name:`withNamespace(${e.name}, ${n})`,async load(){let o=e.load?await e.load():{},t={};for(let[s,i]of Object.entries(o))if(s.toUpperCase().startsWith(a)){let d=s.slice(a.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[s,i]of Object.entries(o))if(s.toUpperCase().startsWith(a)){let d=s.slice(a.length);t[d]=i;}return t}}}function A(e,n,r){let{onChange:a$1,debounce:o=100,files:t=[".env"]}=r??{},s,i=null,d=[],l=async()=>{try{return await import('./index.js'),s=await c(e,n),s}catch(c){throw console.error("[watch] Failed to load config:",c),c}},u=()=>{i&&clearTimeout(i),i=setTimeout(async()=>{try{let c=await l();a$1?.(c);}catch(c){console.error("[watch] Failed to reload config:",c);}},o);},{watch:y}=a("fs"),{join:w}=a("path");for(let c of t)try{let R=y(w(process.cwd(),c),u);d.push(R);}catch{}return l().catch(console.error),{getConfig:()=>s,stop:()=>{i&&clearTimeout(i);for(let c of d)c.close();}}}export{p as TTL,b as awsCache,C as cached,x as retry,A as watch,S as withAliases,$ as withComputed,v as withNamespace,P as withPrefix,k as withTransform};
|
package/dist/valibot.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunk6FXCXA4R_cjs=require('./chunk-6FXCXA4R.cjs');require('./chunk-4YVXFL3I.cjs'),require('./chunk-4ZOF2PI4.cjs'),require('./chunk-BFLXBLZ3.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=[chunk6FXCXA4R_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=[chunk6FXCXA4R_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=[chunk6FXCXA4R_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=[chunk6FXCXA4R_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 {a}from'./chunk-
|
|
1
|
+
import {a}from'./chunk-BJ2QNYTS.js';import'./chunk-DIXI6MUB.js';import'./chunk-YOHHFBZN.js';import'./chunk-ZMRT37K3.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 };
|
package/dist/validators.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Validator } from './types.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Shared validation functions for advanced environment variable types
|
|
3
5
|
* Import these when you need advanced validation beyond basic string/number/boolean
|
|
@@ -5,7 +7,8 @@
|
|
|
5
7
|
* These validators are tree-shakeable - only included if you use advanced types like:
|
|
6
8
|
* 'postgres', 'mysql', 'mongodb', 'redis', 'http', 'https', 'url', 'email', 'port', 'json', 'date', 'timestamp'
|
|
7
9
|
*/
|
|
8
|
-
|
|
10
|
+
|
|
11
|
+
interface ValidationResult {
|
|
9
12
|
valid: boolean;
|
|
10
13
|
error?: string;
|
|
11
14
|
value?: unknown;
|
|
@@ -13,67 +16,67 @@ export interface ValidationResult {
|
|
|
13
16
|
/**
|
|
14
17
|
* Validate PostgreSQL connection string
|
|
15
18
|
*/
|
|
16
|
-
|
|
19
|
+
declare function validatePostgres(value: string): ValidationResult;
|
|
17
20
|
/**
|
|
18
21
|
* Validate MySQL connection string
|
|
19
22
|
*/
|
|
20
|
-
|
|
23
|
+
declare function validateMysql(value: string): ValidationResult;
|
|
21
24
|
/**
|
|
22
25
|
* Validate MongoDB connection string
|
|
23
26
|
* Supports mongodb:// and mongodb+srv:// with replica sets
|
|
24
27
|
*/
|
|
25
|
-
|
|
28
|
+
declare function validateMongodb(value: string): ValidationResult;
|
|
26
29
|
/**
|
|
27
30
|
* Validate Redis connection string
|
|
28
31
|
* Supports redis:// and rediss:// (TLS)
|
|
29
32
|
*/
|
|
30
|
-
|
|
33
|
+
declare function validateRedis(value: string): ValidationResult;
|
|
31
34
|
/**
|
|
32
35
|
* Validate HTTP/HTTPS URL (accepts both)
|
|
33
36
|
*/
|
|
34
|
-
|
|
37
|
+
declare function validateHttp(value: string): ValidationResult;
|
|
35
38
|
/**
|
|
36
39
|
* Validate HTTPS URL only (strict)
|
|
37
40
|
*/
|
|
38
|
-
|
|
41
|
+
declare function validateHttps(value: string): ValidationResult;
|
|
39
42
|
/**
|
|
40
43
|
* Validate generic URL (with protocol whitelist for security)
|
|
41
44
|
*/
|
|
42
|
-
|
|
45
|
+
declare function validateUrl(value: string): ValidationResult;
|
|
43
46
|
/**
|
|
44
47
|
* Validate email address
|
|
45
48
|
*/
|
|
46
|
-
|
|
49
|
+
declare function validateEmail(value: string): ValidationResult;
|
|
47
50
|
/**
|
|
48
51
|
* Validate port number
|
|
49
52
|
*/
|
|
50
|
-
|
|
53
|
+
declare function validatePort(value: string): ValidationResult;
|
|
51
54
|
/**
|
|
52
55
|
* Validate number
|
|
53
56
|
*/
|
|
54
|
-
|
|
57
|
+
declare function validateNumber(value: string): ValidationResult;
|
|
55
58
|
/**
|
|
56
59
|
* Validate boolean
|
|
57
60
|
*/
|
|
58
|
-
|
|
61
|
+
declare function validateBoolean(value: string): ValidationResult;
|
|
59
62
|
/**
|
|
60
63
|
* Validate JSON
|
|
61
64
|
*/
|
|
62
|
-
|
|
65
|
+
declare function validateJson(value: string): ValidationResult;
|
|
63
66
|
/**
|
|
64
67
|
* Validate and normalize date string to ISO 8601
|
|
65
68
|
* Accepts various formats and coerces them to YYYY-MM-DD or ISO 8601 datetime
|
|
66
69
|
*/
|
|
67
|
-
|
|
70
|
+
declare function validateDate(value: string): ValidationResult;
|
|
68
71
|
/**
|
|
69
72
|
* Validate Unix timestamp (seconds since epoch)
|
|
70
73
|
*/
|
|
71
|
-
|
|
74
|
+
declare function validateTimestamp(value: string): ValidationResult;
|
|
72
75
|
/**
|
|
73
76
|
* Validate and parse time duration (Go-style: 5s, 2h, 30m, etc.)
|
|
74
77
|
* Returns milliseconds
|
|
75
78
|
*/
|
|
76
|
-
|
|
79
|
+
declare function validateDuration(value: string): ValidationResult & {
|
|
77
80
|
value?: number;
|
|
78
81
|
};
|
|
79
82
|
/**
|
|
@@ -84,5 +87,30 @@ export declare function validateDuration(value: string): ValidationResult & {
|
|
|
84
87
|
* @param key - Optional env var key name (for error messages)
|
|
85
88
|
* @returns ValidationResult with file content or error
|
|
86
89
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
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 };
|
package/dist/validators.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import {a}from'./chunk-5PELJRUQ.js';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=a("fs"),{resolve:i}=a("path"),a$1=i(process.cwd(),t);return {valid:!0,value:e.readFileSync(a$1,"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
|
+
export{y as httpValidator,b as jsonValidator,w as validateBoolean,x as validateDate,U as validateDuration,g as validateEmail,V as validateFile,v as validateHttp,p as validateHttps,I as validateJson,f as validateMongodb,u as validateMysql,h as validateNumber,R as validatePort,d as validatePostgres,c as validateRedis,L as validateTimestamp,m as validateUrl};
|
package/dist/web.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
'use strict';var
|
|
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
|
|
3
|
-
\u{1F4A1} Rename these variables to start with '${e}' (e.g., ${
|
|
4
|
-
\u{1F4A1} These variables will be exposed to the client. Move to client schema or remove prefix.`);let
|
|
1
|
+
'use strict';var chunkUCLEPPLS_cjs=require('./chunk-UCLEPPLS.cjs'),chunk6FXCXA4R_cjs=require('./chunk-6FXCXA4R.cjs');require('./chunk-4YVXFL3I.cjs'),require('./chunk-4ZOF2PI4.cjs'),require('./chunk-BFLXBLZ3.cjs'),require('./chunk-KIQXH265.cjs');var T=()=>typeof globalThis.window<"u";async function u(l,h={}){let{resolvers:p=[chunkUCLEPPLS_cjs.b()],clientPrefix:e="PUBLIC_",strict:a=true}=h,v=Object.keys(l).filter(n=>!n.startsWith(e));if(T()&&v.length>0){let n=new Error(`\u274C Server-only environment variables accessed in browser context: ${v.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 r={};for(let[n,f]of Object.entries(l))n.startsWith(e)&&(r[n]=f);let i=p.map(n=>[n,r]);return i.length===1?await chunk6FXCXA4R_cjs.c(i[0],{strict:a}):i.length===2?await chunk6FXCXA4R_cjs.c(i[0],i[1],{strict:a}):await chunk6FXCXA4R_cjs.c(i[0],i[1],i[2],{strict:a})}async function E(l,h={}){let{resolvers:p=[chunkUCLEPPLS_cjs.a({expand:true}),chunkUCLEPPLS_cjs.b()],clientPrefix:e="PUBLIC_",policies:a,interpolate:v,strict:r}=h,m=Object.keys(l.client).filter(c=>!c.startsWith(e));if(m.length>0)throw new Error(`\u274C Client environment variables must be prefixed with '${e}': ${m.join(", ")}
|
|
3
|
+
\u{1F4A1} Rename these variables to start with '${e}' (e.g., ${m[0]} \u2192 ${e}${m[0]})`);let f=Object.keys(l.server).filter(c=>c.startsWith(e));if(f.length>0)throw new Error(`\u274C Server environment variables should not be prefixed with '${e}': ${f.join(", ")}
|
|
4
|
+
\u{1F4A1} These variables will be exposed to the client. Move to client schema or remove prefix.`);let s=p.map(c=>[c,l.server]),d=s.length===1?await chunk6FXCXA4R_cjs.c(s[0],{policies:a,interpolate:v,strict:r}):s.length===2?await chunk6FXCXA4R_cjs.c(s[0],s[1],{policies:a,interpolate:v,strict:r}):await chunk6FXCXA4R_cjs.c(s[0],s[1],s[2],{policies:a,interpolate:v,strict:r}),o=p.map(c=>[c,l.client]),y=o.length===1?await chunk6FXCXA4R_cjs.c(o[0],{strict:r}):o.length===2?await chunk6FXCXA4R_cjs.c(o[0],o[1],{strict:r}):await chunk6FXCXA4R_cjs.c(o[0],o[1],o[2],{strict:r});return {server:d,client:y}}T()&&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`);exports.resolveClientEnv=u;exports.resolveEnvSplit=E;
|