@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 +2 -1
- package/.dist/index.mjs +27 -28
- package/package.json +9 -10
package/.dist/index.cjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
|
|
2
|
-
function f(
|
|
3
|
-
return Object.entries(
|
|
4
|
-
(
|
|
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(
|
|
9
|
-
const t = Object.entries(
|
|
10
|
-
(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
|
|
13
|
+
return a.object(t);
|
|
14
14
|
}
|
|
15
|
-
function d(
|
|
16
|
-
return new Proxy(
|
|
15
|
+
function d(r, n, t, e, u) {
|
|
16
|
+
return new Proxy(r, {
|
|
17
17
|
get(i, s) {
|
|
18
|
-
const
|
|
19
|
-
if (!
|
|
20
|
-
if (typeof
|
|
21
|
-
const
|
|
22
|
-
return "value" in
|
|
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
|
-
|
|
27
|
+
o
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
const
|
|
34
|
-
throw new Error(
|
|
35
|
-
|
|
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 '${
|
|
38
|
+
`❌ Attempted to access server-side environment variable '${c}' on the client`
|
|
40
39
|
);
|
|
41
|
-
}),
|
|
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
|
-
|
|
45
|
-
|
|
43
|
+
r.values,
|
|
44
|
+
n,
|
|
46
45
|
e
|
|
47
46
|
) : t(s.error);
|
|
48
47
|
}
|
|
49
48
|
export {
|
|
50
|
-
|
|
49
|
+
y as createEnvironment
|
|
51
50
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quintal/environment",
|
|
3
|
-
"version": "
|
|
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": "^
|
|
31
|
+
"zod": "^4.1.12"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@
|
|
35
|
-
"
|
|
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.
|
|
39
|
-
"vite": "
|
|
40
|
-
"vitest": "2.
|
|
41
|
-
"zod": "
|
|
42
|
-
"@quintal/config": "0.
|
|
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:*",
|