@quintal/environment 1.0.1 → 2.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/.dist/index.cjs CHANGED
@@ -1 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("zod");function f(n){return Object.entries(n).reduce((r,[t,e])=>(typeof e=="string"||typeof e>"u"?r[t]=e:"value"in e?r[t]=e.value||void 0:r[t]=f(e),r),{})}function l(n,r){const t=Object.entries(n).reduce((e,[c,i])=>(typeof i=="string"||typeof i>"u"?e[c]=o.z.string():"value"in i?(!i.isServerOnly||r)&&(e[c]=i.schema??o.z.string()):e[c]=l(i,r),e),{});return o.z.object(t)}function d(n,r,t,e,c){return new Proxy(n,{get(i,s){const u=r[s];if(!u)return;if(typeof u=="string")return u;const a=c?`${c}.${s}`:s;return"value"in u?u.isServerOnly&&!t?e(a):i[s]:d(n[s],r[s],t,e,a)}})}function y(n){const r=n.isServer??typeof window>"u",t=n.onValidationError??(u=>{throw new Error(`❌ Invalid environment variables: ${u.issues.map(({path:a,message:v})=>`${a.join(".")}: ${v}`).join(", ")}`)}),e=n.onAccessError??(u=>{throw new Error(`❌ Attempted to access server-side environment variable '${u}' on the client`)}),c=l(n.values,r),i=f(n.values),s=c.safeParse(i);return s.success?d(s.data,n.values,r,e):t(s.error)}exports.createEnvironment=y;
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,[u,i])=>(typeof i=="string"||typeof i>"u"?e[u]=a.z.string():"value"in i?(!i.isServerOnly||n)&&(e[u]=i.schema??a.z.string()):e[u]=l(i,n),e),{});return a.z.object(t)}function d(r,n,t,e,u){return new Proxy(r,{get(i,s){const c=n[s];if(!c)return;if(typeof c=="string")return c;const o=u?`${u}.${s}`:s;return"value"in c?c.isServerOnly&&!t?e(o):i[s]:d(r[s],n[s],t,e,o)}})}function v(r){const n=r.isServer??typeof window>"u",t=r.onValidationError??(c=>{throw new Error(`❌ Invalid environment variables:
2
+ ${a.z.prettifyError(c)}`)}),e=r.onAccessError??(c=>{throw new Error(`❌ Attempted to access server-side environment variable '${c}' on the client`)}),u=l(r.values,n),i=f(r.values),s=u.safeParse(i);return s.success?d(s.data,r.values,n,e):t(s.error)}exports.createEnvironment=v;
package/.dist/index.mjs CHANGED
@@ -1,51 +1,50 @@
1
- import { z as o } from "zod";
2
- function f(n) {
3
- return Object.entries(n).reduce(
4
- (r, [t, e]) => (typeof e == "string" || typeof e > "u" ? r[t] = e : "value" in e ? r[t] = e.value || void 0 : r[t] = f(e), r),
1
+ import { z as a } from "zod";
2
+ function f(r) {
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] = f(e), n),
5
5
  {}
6
6
  );
7
7
  }
8
- function l(n, r) {
9
- const t = Object.entries(n).reduce(
10
- (e, [a, i]) => (typeof i == "string" || typeof i > "u" ? e[a] = o.string() : "value" in i ? (!i.isServerOnly || r) && (e[a] = i.schema ?? o.string()) : e[a] = l(i, r), e),
8
+ function l(r, n) {
9
+ const t = Object.entries(r).reduce(
10
+ (e, [u, i]) => (typeof i == "string" || typeof i > "u" ? e[u] = a.string() : "value" in i ? (!i.isServerOnly || n) && (e[u] = i.schema ?? a.string()) : e[u] = l(i, n), e),
11
11
  {}
12
12
  );
13
- return o.object(t);
13
+ return a.object(t);
14
14
  }
15
- function d(n, r, t, e, a) {
16
- return new Proxy(n, {
15
+ function d(r, n, t, e, u) {
16
+ return new Proxy(r, {
17
17
  get(i, s) {
18
- const u = r[s];
19
- if (!u) return;
20
- if (typeof u == "string") return u;
21
- const c = a ? `${a}.${s}` : s;
22
- return "value" in u ? u.isServerOnly && !t ? e(c) : i[s] : d(
23
- n[s],
18
+ const c = n[s];
19
+ if (!c) return;
20
+ if (typeof c == "string") return c;
21
+ const o = u ? `${u}.${s}` : s;
22
+ return "value" in c ? c.isServerOnly && !t ? e(o) : i[s] : d(
24
23
  r[s],
24
+ n[s],
25
25
  t,
26
26
  e,
27
- c
27
+ o
28
28
  );
29
29
  }
30
30
  });
31
31
  }
32
- function m(n) {
33
- const r = n.isServer ?? typeof window > "u", t = n.onValidationError ?? ((u) => {
34
- throw new Error(
35
- `❌ Invalid environment variables: ${u.issues.map(({ path: c, message: v }) => `${c.join(".")}: ${v}`).join(", ")}`
36
- );
37
- }), e = n.onAccessError ?? ((u) => {
32
+ function y(r) {
33
+ const n = r.isServer ?? typeof window > "u", t = r.onValidationError ?? ((c) => {
34
+ throw new Error(`❌ Invalid environment variables:
35
+ ${a.prettifyError(c)}`);
36
+ }), e = r.onAccessError ?? ((c) => {
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 '${c}' on the client`
40
39
  );
41
- }), a = l(n.values, r), i = f(n.values), s = a.safeParse(i);
40
+ }), u = l(r.values, n), i = f(r.values), s = u.safeParse(i);
42
41
  return s.success ? d(
43
42
  s.data,
44
- n.values,
45
- r,
43
+ r.values,
44
+ n,
46
45
  e
47
46
  ) : t(s.error);
48
47
  }
49
48
  export {
50
- m as createEnvironment
49
+ y as createEnvironment
51
50
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintal/environment",
3
- "version": "1.0.1",
3
+ "version": "2.0.0",
4
4
  "license": "MIT",
5
5
  "description": "Framework-agnostic environment variable validation for TypeScript powered by Zod",
6
6
  "keywords": [
@@ -28,18 +28,17 @@
28
28
  ".dist"
29
29
  ],
30
30
  "peerDependencies": {
31
- "zod": "^3.23.8"
31
+ "zod": "^4.1.12"
32
32
  },
33
33
  "devDependencies": {
34
- "@biomejs/biome": "1.8.3",
35
- "@vitest/coverage-v8": "2.0.5",
36
- "happy-dom": "15.7.3",
34
+ "@vitest/coverage-v8": "3.2.4",
35
+ "happy-dom": "19.0.2",
37
36
  "npm-run-all": "4.1.5",
38
- "shx": "0.3.4",
39
- "vite": "5.4.2",
40
- "vitest": "2.0.5",
41
- "zod": "3.23.8",
42
- "@quintal/config": "0.2.2"
37
+ "shx": "0.4.0",
38
+ "vite": "7.1.9",
39
+ "vitest": "3.2.4",
40
+ "zod": "4.1.12",
41
+ "@quintal/config": "0.3.0"
43
42
  },
44
43
  "scripts": {
45
44
  "build": "run-s build:*",