node-env-resolver 3.0.1 → 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.
Files changed (112) hide show
  1. package/README.md +396 -246
  2. package/dist/audit.cjs +1 -0
  3. package/dist/audit.d.cts +29 -0
  4. package/dist/audit.d.ts +19 -6
  5. package/dist/audit.js +1 -1
  6. package/dist/builder.cjs +1 -0
  7. package/dist/builder.d.cts +149 -0
  8. package/dist/builder.d.ts +17 -14
  9. package/dist/builder.js +1 -1
  10. package/dist/chunk-4YVXFL3I.cjs +9 -0
  11. package/dist/chunk-4ZOF2PI4.cjs +1 -0
  12. package/dist/chunk-5PELJRUQ.js +1 -0
  13. package/dist/chunk-6FXCXA4R.cjs +11 -0
  14. package/dist/chunk-BFLXBLZ3.cjs +1 -0
  15. package/dist/chunk-BJ2QNYTS.js +11 -0
  16. package/dist/chunk-DIXI6MUB.js +9 -0
  17. package/dist/chunk-KIQXH265.cjs +1 -0
  18. package/dist/chunk-P3TTYVEW.js +16 -0
  19. package/dist/chunk-UCLEPPLS.cjs +16 -0
  20. package/dist/chunk-YOHHFBZN.js +1 -0
  21. package/dist/chunk-ZMRT37K3.js +1 -0
  22. package/dist/cli.cjs +1 -0
  23. package/dist/cli.d.cts +52 -0
  24. package/dist/cli.d.ts +9 -6
  25. package/dist/cli.js +1 -1
  26. package/dist/index.cjs +1 -0
  27. package/dist/index.d.cts +150 -0
  28. package/dist/index.d.ts +122 -40
  29. package/dist/index.js +1 -1
  30. package/dist/resolver.cjs +1 -0
  31. package/dist/resolver.d.cts +20 -0
  32. package/dist/resolver.d.ts +8 -5
  33. package/dist/resolver.js +1 -1
  34. package/dist/resolvers.cjs +1 -0
  35. package/dist/resolvers.d.cts +407 -0
  36. package/dist/resolvers.d.ts +289 -22
  37. package/dist/resolvers.js +1 -1
  38. package/dist/types.cjs +1 -0
  39. package/dist/types.d.cts +74 -0
  40. package/dist/types.d.ts +58 -164
  41. package/dist/types.js +1 -0
  42. package/dist/utils.cjs +1 -0
  43. package/dist/utils.d.cts +213 -0
  44. package/dist/utils.d.ts +37 -33
  45. package/dist/utils.js +1 -1
  46. package/dist/valibot.cjs +1 -0
  47. package/dist/valibot.d.cts +156 -0
  48. package/dist/valibot.d.ts +11 -8
  49. package/dist/valibot.js +1 -1
  50. package/dist/validation-types.cjs +1 -0
  51. package/dist/validation-types.d.cts +29 -0
  52. package/dist/validation-types.d.ts +4 -3
  53. package/dist/validators.cjs +2 -0
  54. package/dist/validators.d.cts +116 -0
  55. package/dist/validators.d.ts +46 -18
  56. package/dist/validators.js +2 -1
  57. package/dist/web.cjs +6 -0
  58. package/dist/web.d.cts +69 -0
  59. package/dist/web.d.ts +28 -10
  60. package/dist/web.js +4 -4
  61. package/dist/zod.cjs +1 -0
  62. package/dist/zod.d.cts +135 -0
  63. package/dist/zod.d.ts +11 -8
  64. package/dist/zod.js +1 -1
  65. package/package.json +31 -19
  66. package/dist/advanced-features.test.d.ts +0 -2
  67. package/dist/advanced-features.test.d.ts.map +0 -1
  68. package/dist/audit.d.ts.map +0 -1
  69. package/dist/audit.test.d.ts +0 -2
  70. package/dist/audit.test.d.ts.map +0 -1
  71. package/dist/builder.d.ts.map +0 -1
  72. package/dist/chunk-476ZUILE.js +0 -1
  73. package/dist/chunk-DAGPFV3V.js +0 -1
  74. package/dist/chunk-MGTYH57K.js +0 -9
  75. package/dist/chunk-MWG7FWHN.js +0 -5
  76. package/dist/chunk-QWDK3BUB.js +0 -15
  77. package/dist/chunk-VJZZNSRI.js +0 -1
  78. package/dist/cli.d.ts.map +0 -1
  79. package/dist/cli.test.d.ts +0 -2
  80. package/dist/cli.test.d.ts.map +0 -1
  81. package/dist/composition.test.d.ts +0 -7
  82. package/dist/composition.test.d.ts.map +0 -1
  83. package/dist/computed.test.d.ts +0 -2
  84. package/dist/computed.test.d.ts.map +0 -1
  85. package/dist/index.d.ts.map +0 -1
  86. package/dist/index.test.d.ts +0 -2
  87. package/dist/index.test.d.ts.map +0 -1
  88. package/dist/nested.test.d.ts +0 -2
  89. package/dist/nested.test.d.ts.map +0 -1
  90. package/dist/performance.test.d.ts +0 -7
  91. package/dist/performance.test.d.ts.map +0 -1
  92. package/dist/priority.test.d.ts +0 -6
  93. package/dist/priority.test.d.ts.map +0 -1
  94. package/dist/providers.d.ts +0 -11
  95. package/dist/providers.d.ts.map +0 -1
  96. package/dist/resolver.d.ts.map +0 -1
  97. package/dist/resolvers.d.ts.map +0 -1
  98. package/dist/resolvers.test.d.ts +0 -2
  99. package/dist/resolvers.test.d.ts.map +0 -1
  100. package/dist/type-inference.test.d.ts +0 -2
  101. package/dist/type-inference.test.d.ts.map +0 -1
  102. package/dist/type-override.test.d.ts +0 -2
  103. package/dist/type-override.test.d.ts.map +0 -1
  104. package/dist/types.d.ts.map +0 -1
  105. package/dist/utils.d.ts.map +0 -1
  106. package/dist/utils.test.d.ts +0 -2
  107. package/dist/utils.test.d.ts.map +0 -1
  108. package/dist/valibot.d.ts.map +0 -1
  109. package/dist/validation-types.d.ts.map +0 -1
  110. package/dist/validators.d.ts.map +0 -1
  111. package/dist/web.d.ts.map +0 -1
  112. package/dist/zod.d.ts.map +0 -1
package/dist/utils.js CHANGED
@@ -1 +1 @@
1
- import {a}from'./chunk-476ZUILE.js';function w(e,r={}){let{ttl:n=3e5,maxAge:s=36e5,staleWhileRevalidate:o=false}=r,t=null,a={name:`cached(${e.name})`,metadata:{},async load(){let i=Date.now();if(!t||i-t.timestamp>s){let l=await e.load();return t={data:l,timestamp:i},a.metadata={cached:false},l}if(i-t.timestamp<n)return a.metadata={cached:true},t.data;if(o&&!t.refreshPromise)return t.refreshPromise=e.load().then(l=>(t.data=l,t.timestamp=Date.now(),t.refreshPromise=void 0,l)).catch(()=>(t.refreshPromise=void 0,t.data)),a.metadata={cached:true,stale:true},t.data;let d=await e.load();return t={data:d,timestamp:i},a.metadata={cached:false},d}};return a}var f={short:30*1e3,minute:60*1e3,minutes5:300*1e3,minutes15:900*1e3,hour:3600*1e3,hours6:360*60*1e3,day:1440*60*1e3};function R(e={}){return {ttl:e.ttl??f.minutes5,maxAge:e.maxAge??f.hour,staleWhileRevalidate:e.staleWhileRevalidate??true,key:"aws-secrets"}}function T(e,r=3,n=1e3){return {name:`retry(${e.name})`,async load(){let s;for(let o=0;o<=r;o++)try{return await e.load()}catch(t){s=t instanceof Error?t:new Error(String(t)),o<r&&await new Promise(a=>setTimeout(a,n*Math.pow(2,o)));}throw s}}}function C(e,r){let n=r.toUpperCase();return {name:`withPrefix(${e.name}, ${r})`,async load(){let s=await e.load(),o={};for(let[t,a]of Object.entries(s))if(t.toUpperCase().startsWith(n)){let i=t.slice(r.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(n)){let i=t.slice(r.length);o[i]=a;}else o[t]=a;return o}}}function b(e,r){let n={...e};for(let[s,o]of Object.entries(r))Object.defineProperty(n,s,{get(){return o(e)},enumerable:true,configurable:true});return n}function v(e,r){return {name:`withAliases(${e.name})`,async load(){let n=await e.load();return p(n,r)},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let n=e.loadSync();return p(n,r)}}}function p(e,r){let n={...e};for(let[s,o]of Object.entries(r))for(let t of o)if(e[t]!==void 0){n[s]=e[t];break}return n}function x(e,r){return {name:`withTransform(${e.name})`,async load(){let n=await e.load();return m(n,r)},loadSync(){if(!e.loadSync)throw new Error(`Resolver ${e.name} does not support sync loading`);let n=e.loadSync();return m(n,r)}}}function m(e,r){let n={...e};for(let[s,o]of Object.entries(r))if(e[s]!==void 0)try{n[s]=o(e[s]);}catch(t){throw new Error(`Transform failed for ${s}: ${t instanceof Error?t.message:String(t)}`)}return n}function $(e,r){let s=`${r.toUpperCase()}_`;return {name:`withNamespace(${e.name}, ${r})`,async load(){let o=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 S(e,r){let{onChange:n,debounce:s=100,files:o=[".env"]}=r??{},t,a$1=null,i=[],d=async()=>{try{let{resolve:c}=await import('./index.js');return t=await c.with(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();n?.(c);}catch(c){console.error("[watch] Failed to reload config:",c);}},s);},{watch:g}=a("fs"),{join:h}=a("path");for(let c of o)try{let y=g(h(process.cwd(),c),l);i.push(y);}catch{}return d().catch(console.error),{getConfig:()=>t,stop:()=>{a$1&&clearTimeout(a$1);for(let c of i)c.close();}}}export{f as TTL,R as awsCache,w as cached,T as retry,S as watch,v as withAliases,b as withComputed,$ as withNamespace,C as withPrefix,x as withTransform};
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};
@@ -0,0 +1 @@
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
- import { type Resolver, type PolicyOptions } from './index';
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
- export type InferValibotOutput<T> = T extends {
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
- export declare function resolveValibot<TSchema extends {
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
- export declare function safeResolveValibot<TSchema extends {
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
- export declare function resolveSyncValibot<TSchema extends {
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
- export declare function safeResolveSyncValibot<TSchema extends {
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
- //# sourceMappingURL=valibot.d.ts.map
155
+
156
+ export { type InferValibotOutput, resolveSyncValibot, resolveValibot, safeResolveSyncValibot, safeResolveValibot };
package/dist/valibot.js CHANGED
@@ -1 +1 @@
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(t,n,e){let s={};for(let o of t)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(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 y(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 d(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,y as resolveValibot,b as safeResolveSyncValibot,d as safeResolveValibot};
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 @@
1
+ 'use strict';
@@ -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
- export interface ValidationIssue {
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
- export type SafeResolveResult<T> = {
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
- //# sourceMappingURL=validation-types.d.ts.map
28
+
29
+ export type { SafeResolveResult, ValidationIssue };
@@ -0,0 +1,2 @@
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 };
@@ -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
- export interface ValidationResult {
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
- export declare function validatePostgres(value: string): ValidationResult;
19
+ declare function validatePostgres(value: string): ValidationResult;
17
20
  /**
18
21
  * Validate MySQL connection string
19
22
  */
20
- export declare function validateMysql(value: string): ValidationResult;
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
- export declare function validateMongodb(value: string): ValidationResult;
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
- export declare function validateRedis(value: string): ValidationResult;
33
+ declare function validateRedis(value: string): ValidationResult;
31
34
  /**
32
35
  * Validate HTTP/HTTPS URL (accepts both)
33
36
  */
34
- export declare function validateHttp(value: string): ValidationResult;
37
+ declare function validateHttp(value: string): ValidationResult;
35
38
  /**
36
39
  * Validate HTTPS URL only (strict)
37
40
  */
38
- export declare function validateHttps(value: string): ValidationResult;
41
+ declare function validateHttps(value: string): ValidationResult;
39
42
  /**
40
43
  * Validate generic URL (with protocol whitelist for security)
41
44
  */
42
- export declare function validateUrl(value: string): ValidationResult;
45
+ declare function validateUrl(value: string): ValidationResult;
43
46
  /**
44
47
  * Validate email address
45
48
  */
46
- export declare function validateEmail(value: string): ValidationResult;
49
+ declare function validateEmail(value: string): ValidationResult;
47
50
  /**
48
51
  * Validate port number
49
52
  */
50
- export declare function validatePort(value: string): ValidationResult;
53
+ declare function validatePort(value: string): ValidationResult;
51
54
  /**
52
55
  * Validate number
53
56
  */
54
- export declare function validateNumber(value: string): ValidationResult;
57
+ declare function validateNumber(value: string): ValidationResult;
55
58
  /**
56
59
  * Validate boolean
57
60
  */
58
- export declare function validateBoolean(value: string): ValidationResult;
61
+ declare function validateBoolean(value: string): ValidationResult;
59
62
  /**
60
63
  * Validate JSON
61
64
  */
62
- export declare function validateJson(value: string): ValidationResult;
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
- export declare function validateDate(value: string): ValidationResult;
70
+ declare function validateDate(value: string): ValidationResult;
68
71
  /**
69
72
  * Validate Unix timestamp (seconds since epoch)
70
73
  */
71
- export declare function validateTimestamp(value: string): ValidationResult;
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
- export declare function validateDuration(value: string): ValidationResult & {
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
- export declare function validateFile(value: string, key?: string): ValidationResult;
88
- //# sourceMappingURL=validators.d.ts.map
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 };
@@ -1 +1,2 @@
1
- export{k as validateBoolean,m as validateDate,o as validateDuration,h as validateEmail,p as validateFile,e as validateHttp,f as validateHttps,l as validateJson,c as validateMongodb,b as validateMysql,j as validateNumber,i as validatePort,a as validatePostgres,d as validateRedis,n as validateTimestamp,g as validateUrl}from'./chunk-VJZZNSRI.js';import'./chunk-476ZUILE.js';
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 ADDED
@@ -0,0 +1,6 @@
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
+ Only variables with your configured prefix will be accessible
6
+ Server-only variables are blocked for security`);exports.resolveClientEnv=u;exports.resolveEnvSplit=E;