@quintal/environment 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dist/index.cjs +2 -2
- package/.dist/index.d.ts +1 -1
- package/.dist/index.mjs +17 -16
- 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
|
|
2
|
-
${
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=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,[a,i])=>(typeof i=="string"||typeof i>"u"?e[a]=c.z.string():"value"in i?(!i.isServerOnly||n)&&(e[a]=i.schema??c.z.string()):e[a]=l(i,n),e),{});return c.z.object(t)}function d(r,n,t,e,a){return new Proxy(r,{get(i,s){const u=n[s];if(!u)return;if(typeof u=="string")return u;const o=a?`${a}.${s}`:s;return"value"in u?u.isServerOnly&&!t?e(o):i[s]:d(r[s],n[s],t,e,o)}})}function v(r){const n=r.isDisabled??!1,t=r.isServer??typeof window>"u",e=r.onValidationError??(u=>{throw new Error(`❌ Invalid environment variables:
|
|
2
|
+
${c.z.prettifyError(u)}`)}),a=r.onAccessError??(u=>{throw new Error(`❌ Attempted to access server-side environment variable '${u}' on the client`)}),i=f(r.values);if(n)return i;const s=l(r.values,t).safeParse(i);return s.success?d(s.data,r.values,t,a):e(s.error)}exports.createEnvironment=v;
|
package/.dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare function createEnvironment<TEnvValues extends EnvValues>(opts: Cr
|
|
|
6
6
|
declare type CreateEnvironmentOptions<TEnvValues extends EnvValues> = {
|
|
7
7
|
/**
|
|
8
8
|
* Whether or not the environment variable validation should be disabled.
|
|
9
|
-
* Enabling this option will make `createEnvironment` return
|
|
9
|
+
* Enabling this option will make `createEnvironment` return the unparsed, unvalidated environment variables.
|
|
10
10
|
* @defaultValue false
|
|
11
11
|
*/
|
|
12
12
|
isDisabled?: boolean;
|
package/.dist/index.mjs
CHANGED
|
@@ -7,19 +7,19 @@ function o(r) {
|
|
|
7
7
|
}
|
|
8
8
|
function l(r, n) {
|
|
9
9
|
const t = Object.entries(r).reduce(
|
|
10
|
-
(e, [
|
|
10
|
+
(e, [u, i]) => (typeof i == "string" || typeof i > "u" ? e[u] = c.string() : "value" in i ? (!i.isServerOnly || n) && (e[u] = i.schema ?? c.string()) : e[u] = l(i, n), e),
|
|
11
11
|
{}
|
|
12
12
|
);
|
|
13
13
|
return c.object(t);
|
|
14
14
|
}
|
|
15
|
-
function d(r, n, t, e,
|
|
15
|
+
function d(r, n, t, e, u) {
|
|
16
16
|
return new Proxy(r, {
|
|
17
17
|
get(i, s) {
|
|
18
|
-
const
|
|
19
|
-
if (!
|
|
20
|
-
if (typeof
|
|
21
|
-
const f =
|
|
22
|
-
return "value" in
|
|
18
|
+
const a = n[s];
|
|
19
|
+
if (!a) return;
|
|
20
|
+
if (typeof a == "string") return a;
|
|
21
|
+
const f = u ? `${u}.${s}` : s;
|
|
22
|
+
return "value" in a ? a.isServerOnly && !t ? e(f) : i[s] : d(
|
|
23
23
|
r[s],
|
|
24
24
|
n[s],
|
|
25
25
|
t,
|
|
@@ -30,21 +30,22 @@ function d(r, n, t, e, a) {
|
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
function y(r) {
|
|
33
|
-
|
|
34
|
-
const n = r.isServer ?? typeof window > "u", t = r.onValidationError ?? ((u) => {
|
|
33
|
+
const n = r.isDisabled ?? !1, t = r.isServer ?? typeof window > "u", e = r.onValidationError ?? ((a) => {
|
|
35
34
|
throw new Error(`❌ Invalid environment variables:
|
|
36
|
-
${c.prettifyError(
|
|
37
|
-
}),
|
|
35
|
+
${c.prettifyError(a)}`);
|
|
36
|
+
}), u = r.onAccessError ?? ((a) => {
|
|
38
37
|
throw new Error(
|
|
39
|
-
`❌ Attempted to access server-side environment variable '${
|
|
38
|
+
`❌ Attempted to access server-side environment variable '${a}' on the client`
|
|
40
39
|
);
|
|
41
|
-
}),
|
|
40
|
+
}), i = o(r.values);
|
|
41
|
+
if (n) return i;
|
|
42
|
+
const s = l(r.values, t).safeParse(i);
|
|
42
43
|
return s.success ? d(
|
|
43
44
|
s.data,
|
|
44
45
|
r.values,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
) :
|
|
46
|
+
t,
|
|
47
|
+
u
|
|
48
|
+
) : e(s.error);
|
|
48
49
|
}
|
|
49
50
|
export {
|
|
50
51
|
y as createEnvironment
|