@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 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,[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;
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 `null`.
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, [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),
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, a) {
15
+ function d(r, n, t, e, u) {
16
16
  return new Proxy(r, {
17
17
  get(i, s) {
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(
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
- if (r.isDisabled) return null;
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(u)}`);
37
- }), e = r.onAccessError ?? ((u) => {
35
+ ${c.prettifyError(a)}`);
36
+ }), u = r.onAccessError ?? ((a) => {
38
37
  throw new Error(
39
- `❌ Attempted to access server-side environment variable '${u}' on the client`
38
+ `❌ Attempted to access server-side environment variable '${a}' on the client`
40
39
  );
41
- }), a = l(r.values, n), i = o(r.values), s = a.safeParse(i);
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
- n,
46
- e
47
- ) : t(s.error);
46
+ t,
47
+ u
48
+ ) : e(s.error);
48
49
  }
49
50
  export {
50
51
  y as createEnvironment
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintal/environment",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "license": "MIT",
5
5
  "description": "Framework-agnostic environment variable validation for TypeScript powered by Zod",
6
6
  "keywords": [