@quintal/environment 2.0.0 → 2.1.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/.dist/index.cjs +2 -2
- package/.dist/index.d.ts +6 -0
- package/.dist/index.mjs +18 -17
- package/LICENSE +1 -1
- package/package.json +1 -1
package/.dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("zod");function f(r){return Object.entries(r).reduce((n,[t,e])=>(typeof e=="string"||typeof e>"u"?n[t]=e:"value"in e?n[t]=e.value||void 0:n[t]=f(e),n),{})}function l(r,n){const t=Object.entries(r).reduce((e,[
|
|
2
|
-
${a.z.prettifyError(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("zod");function f(r){return Object.entries(r).reduce((n,[t,e])=>(typeof e=="string"||typeof e>"u"?n[t]=e:"value"in e?n[t]=e.value||void 0:n[t]=f(e),n),{})}function l(r,n){const t=Object.entries(r).reduce((e,[c,i])=>(typeof i=="string"||typeof i>"u"?e[c]=a.z.string():"value"in i?(!i.isServerOnly||n)&&(e[c]=i.schema??a.z.string()):e[c]=l(i,n),e),{});return a.z.object(t)}function d(r,n,t,e,c){return new Proxy(r,{get(i,s){const u=n[s];if(!u)return;if(typeof u=="string")return u;const o=c?`${c}.${s}`:s;return"value"in u?u.isServerOnly&&!t?e(o):i[s]:d(r[s],n[s],t,e,o)}})}function v(r){if(r.isDisabled)return null;const n=r.isServer??typeof window>"u",t=r.onValidationError??(u=>{throw new Error(`❌ Invalid environment variables:
|
|
2
|
+
${a.z.prettifyError(u)}`)}),e=r.onAccessError??(u=>{throw new Error(`❌ Attempted to access server-side environment variable '${u}' on the client`)}),c=l(r.values,n),i=f(r.values),s=c.safeParse(i);return s.success?d(s.data,r.values,n,e):t(s.error)}exports.createEnvironment=v;
|
package/.dist/index.d.ts
CHANGED
|
@@ -4,6 +4,12 @@ import { ZodType } from 'zod';
|
|
|
4
4
|
export declare function createEnvironment<TEnvValues extends EnvValues>(opts: CreateEnvironmentOptions<TEnvValues>): UnwrapEnvValues<TEnvValues>;
|
|
5
5
|
|
|
6
6
|
declare type CreateEnvironmentOptions<TEnvValues extends EnvValues> = {
|
|
7
|
+
/**
|
|
8
|
+
* Whether or not the environment variable validation should be disabled.
|
|
9
|
+
* Enabling this option will make `createEnvironment` return `null`.
|
|
10
|
+
* @defaultValue false
|
|
11
|
+
*/
|
|
12
|
+
isDisabled?: boolean;
|
|
7
13
|
/**
|
|
8
14
|
* Whether or not the application is running on the server.
|
|
9
15
|
* @defaultValue typeof window === 'undefined'
|
package/.dist/index.mjs
CHANGED
|
@@ -1,43 +1,44 @@
|
|
|
1
|
-
import { z as
|
|
2
|
-
function
|
|
1
|
+
import { z as c } from "zod";
|
|
2
|
+
function o(r) {
|
|
3
3
|
return Object.entries(r).reduce(
|
|
4
|
-
(n, [t, e]) => (typeof e == "string" || typeof e > "u" ? n[t] = e : "value" in e ? n[t] = e.value || void 0 : n[t] =
|
|
4
|
+
(n, [t, e]) => (typeof e == "string" || typeof e > "u" ? n[t] = e : "value" in e ? n[t] = e.value || void 0 : n[t] = o(e), n),
|
|
5
5
|
{}
|
|
6
6
|
);
|
|
7
7
|
}
|
|
8
8
|
function l(r, n) {
|
|
9
9
|
const t = Object.entries(r).reduce(
|
|
10
|
-
(e, [
|
|
10
|
+
(e, [a, i]) => (typeof i == "string" || typeof i > "u" ? e[a] = c.string() : "value" in i ? (!i.isServerOnly || n) && (e[a] = i.schema ?? c.string()) : e[a] = l(i, n), e),
|
|
11
11
|
{}
|
|
12
12
|
);
|
|
13
|
-
return
|
|
13
|
+
return c.object(t);
|
|
14
14
|
}
|
|
15
|
-
function d(r, n, t, e,
|
|
15
|
+
function d(r, n, t, e, a) {
|
|
16
16
|
return new Proxy(r, {
|
|
17
17
|
get(i, s) {
|
|
18
|
-
const
|
|
19
|
-
if (!
|
|
20
|
-
if (typeof
|
|
21
|
-
const
|
|
22
|
-
return "value" in
|
|
18
|
+
const u = n[s];
|
|
19
|
+
if (!u) return;
|
|
20
|
+
if (typeof u == "string") return u;
|
|
21
|
+
const f = a ? `${a}.${s}` : s;
|
|
22
|
+
return "value" in u ? u.isServerOnly && !t ? e(f) : i[s] : d(
|
|
23
23
|
r[s],
|
|
24
24
|
n[s],
|
|
25
25
|
t,
|
|
26
26
|
e,
|
|
27
|
-
|
|
27
|
+
f
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
function y(r) {
|
|
33
|
-
|
|
33
|
+
if (r.isDisabled) return null;
|
|
34
|
+
const n = r.isServer ?? typeof window > "u", t = r.onValidationError ?? ((u) => {
|
|
34
35
|
throw new Error(`❌ Invalid environment variables:
|
|
35
|
-
${
|
|
36
|
-
}), e = r.onAccessError ?? ((
|
|
36
|
+
${c.prettifyError(u)}`);
|
|
37
|
+
}), e = r.onAccessError ?? ((u) => {
|
|
37
38
|
throw new Error(
|
|
38
|
-
`❌ Attempted to access server-side environment variable '${
|
|
39
|
+
`❌ Attempted to access server-side environment variable '${u}' on the client`
|
|
39
40
|
);
|
|
40
|
-
}),
|
|
41
|
+
}), a = l(r.values, n), i = o(r.values), s = a.safeParse(i);
|
|
41
42
|
return s.success ? d(
|
|
42
43
|
s.data,
|
|
43
44
|
r.values,
|
package/LICENSE
CHANGED