arkenv 0.7.8 → 0.8.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/README.md +72 -38
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +39 -10
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +39 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -2,19 +2,18 @@
|
|
|
2
2
|
<a href="https://github.com/yamcodes/arkenv/blob/main/apps/www/public/assets/icon.svg"><img alt="ArkEnv Logo" src="https://arkenv.js.org/assets/icon.svg" width="160px" align="center"/></a>
|
|
3
3
|
<h1 align="center">ArkEnv</h1>
|
|
4
4
|
<div align="center">
|
|
5
|
-
<p align="center">
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
</div>
|
|
5
|
+
<p align="center">Environment variable validation from editor to runtime</p>
|
|
6
|
+
<a href="https://github.com/yamcodes/arkenv/actions/workflows/test.yml?query=branch%3Amain"><img alt="Test Status" src="https://github.com/yamcodes/arkenv/actions/workflows/tests-badge.yml/badge.svg?branch=main"></a>
|
|
7
|
+
<a href="https://bundlephobia.com/package/arkenv"><img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/arkenv"></a>
|
|
8
|
+
<a href="https://www.typescriptlang.org/"><img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-3178C6?style=flat&logo=typescript&logoColor=white"></a>
|
|
9
|
+
<a href="https://arktype.io/"><img alt="Powered By ArkType" src="https://custom-icon-badges.demolab.com/badge/ArkType-0d1526?logo=arktype2&logoColor=e9eef9"></a>
|
|
10
|
+
<a href="https://nodejs.org/en"><img alt="Node.js" src="https://img.shields.io/badge/Node.js-339933?style=flat&logo=node.js&logoColor=white"></a>
|
|
11
|
+
<a href="https://bun.com/"><img alt="Bun" src="https://img.shields.io/badge/Bun-14151a?logo=bun&logoColor=fbf0df"></a>
|
|
12
|
+
<a href="https://vite.dev/"><img alt="Vite" src="https://custom-icon-badges.demolab.com/badge/Vite-2e2742?logo=vite2&logoColor=dfdfd6"></a>
|
|
13
|
+
<a href="https://discord.gg/zAmUyuxXH9"><img alt="Chat on Discord" src="https://img.shields.io/discord/957797212103016458?label=Chat&color=5865f4&logo=discord&labelColor=121214"></a>
|
|
14
|
+
</div>
|
|
16
15
|
</p>
|
|
17
|
-
<h3 align="center">Proud
|
|
16
|
+
<h3 align="center">Proud part of the <a href="https://arktype.io/docs/ecosystem#arkenv">ArkType ecosystem</a></h3>
|
|
18
17
|
|
|
19
18
|
<p align="center">
|
|
20
19
|
<img alt="ArkEnv Demo" src="https://arkenv.js.org/assets/demo.gif" />
|
|
@@ -29,47 +28,64 @@
|
|
|
29
28
|
<br/>
|
|
30
29
|
<br/>
|
|
31
30
|
|
|
32
|
-
## Introduction
|
|
31
|
+
## Introduction
|
|
33
32
|
|
|
34
33
|
> [!TIP]
|
|
35
34
|
> 📖 **Reading this on GitHub?** Check out [this page in our docs](https://arkenv.js.org/docs/arkenv) to hover over code blocks and get type hints!
|
|
36
35
|
|
|
37
|
-
ArkEnv is an environment variable
|
|
36
|
+
ArkEnv is an environment variable validator for modern JavaScript runtimes.
|
|
37
|
+
It lets you create a ready-to-use, typesafe environment variable object:
|
|
38
38
|
|
|
39
39
|
```ts twoslash
|
|
40
|
-
import arkenv from
|
|
40
|
+
import arkenv from "arkenv";
|
|
41
41
|
|
|
42
42
|
const env = arkenv({
|
|
43
|
-
HOST: "string.
|
|
44
|
-
PORT: "number.
|
|
45
|
-
NODE_ENV: "'development' | 'production' | 'test'",
|
|
43
|
+
HOST: "string.ip | 'localhost'",
|
|
44
|
+
PORT: "0 <= number.integer <= 65535",
|
|
45
|
+
NODE_ENV: "'development' | 'production' | 'test' = 'development'",
|
|
46
|
+
DEBUGGING: "boolean = false",
|
|
46
47
|
});
|
|
47
48
|
|
|
48
49
|
// Hover to see ✨exact✨ types
|
|
49
50
|
const host = env.HOST;
|
|
50
51
|
const port = env.PORT;
|
|
51
52
|
const nodeEnv = env.NODE_ENV;
|
|
53
|
+
const debugging = env.DEBUGGING;
|
|
52
54
|
```
|
|
53
55
|
|
|
56
|
+
> ArkEnv supports native [ArkType](https://arktype.io/) notation and any [Standard Schema](https://standardschema.dev/schema) validator: Zod, Valibot, Typia, etc.
|
|
57
|
+
|
|
54
58
|
With ArkEnv, your environment variables are **guaranteed to match your schema**. If any variable is incorrect or missing, the app won't start and a clear error will be thrown:
|
|
55
59
|
|
|
56
60
|
```bash title="Terminal"
|
|
61
|
+
❯ PORT=hello npm start
|
|
62
|
+
|
|
57
63
|
ArkEnvError: Errors found while validating environment variables
|
|
58
64
|
HOST must be a string or "localhost" (was missing)
|
|
59
|
-
PORT must be
|
|
65
|
+
PORT must be a number (was a string)
|
|
60
66
|
```
|
|
61
67
|
|
|
62
68
|
## Features
|
|
63
69
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
⛯ Zero external dependencies
|
|
71
|
+
|
|
72
|
+
⛯ Works in Node.js, Bun, and Vite
|
|
73
|
+
|
|
74
|
+
⛯ Tiny: <2kB gzipped
|
|
75
|
+
|
|
76
|
+
⛯ Build-time / runtime validation with editor autocomplete & type hints
|
|
77
|
+
|
|
78
|
+
⛯ Single import, zero config for most projects
|
|
79
|
+
|
|
80
|
+
⛯ Optional variables and default values
|
|
81
|
+
|
|
82
|
+
⛯ Intuitive automatic coercion
|
|
83
|
+
|
|
84
|
+
⛯ Compatible with any Standard Schema validator (Zod, Valibot, etc.)
|
|
85
|
+
|
|
86
|
+
⛯ Native support for ArkType, TypeScript’s 1:1 validator
|
|
87
|
+
|
|
88
|
+
> See how ArkEnv compares to alternatives like T3 Env, znv, and envalid in the [comparison cheatsheet](https://arkenv.js.org/docs/arkenv/comparison#comparison-cheatsheet).
|
|
73
89
|
|
|
74
90
|
## Installation
|
|
75
91
|
|
|
@@ -79,6 +95,7 @@ ArkEnvError: Errors found while validating environment variables
|
|
|
79
95
|
```sh
|
|
80
96
|
npm install arkenv arktype
|
|
81
97
|
```
|
|
98
|
+
|
|
82
99
|
</details>
|
|
83
100
|
|
|
84
101
|
<details>
|
|
@@ -87,6 +104,7 @@ npm install arkenv arktype
|
|
|
87
104
|
```sh
|
|
88
105
|
pnpm add arkenv arktype
|
|
89
106
|
```
|
|
107
|
+
|
|
90
108
|
</details>
|
|
91
109
|
|
|
92
110
|
<details>
|
|
@@ -95,6 +113,7 @@ pnpm add arkenv arktype
|
|
|
95
113
|
```sh
|
|
96
114
|
yarn add arkenv arktype
|
|
97
115
|
```
|
|
116
|
+
|
|
98
117
|
</details>
|
|
99
118
|
|
|
100
119
|
<details>
|
|
@@ -103,28 +122,25 @@ yarn add arkenv arktype
|
|
|
103
122
|
```sh
|
|
104
123
|
bun add arkenv arktype
|
|
105
124
|
```
|
|
125
|
+
|
|
106
126
|
</details>
|
|
107
127
|
|
|
108
128
|
:rocket: **Let's get started!** Read the [2-minute setup guide](https://arkenv.js.org/docs/quickstart) or [start with an example](https://arkenv.js.org/docs/examples).
|
|
109
129
|
|
|
110
|
-
> [
|
|
111
|
-
> Improve your DX with *syntax highlighting* in [VS Code & Cursor](https://arkenv.js.org/docs/integrations/vscode) or [JetBrains IDEs](https://arkenv.js.org/docs/integrations/jetbrains).
|
|
130
|
+
> Improve your DX with _syntax highlighting_ in [VS Code](https://arkenv.js.org/docs/integrations/vscode), [Cursor, Antigravity](https://arkenv.js.org/docs/integrations/open-vsx), and [JetBrains IDEs](https://arkenv.js.org/docs/integrations/jetbrains).
|
|
112
131
|
|
|
113
132
|
## Requirements
|
|
114
133
|
|
|
115
|
-
ArkEnv is tested on [**Node.js LTS** and **Current**](https://github.com/yamcodes/arkenv/tree/main/examples/basic), [**Bun 1.3.2**](https://github.com/yamcodes/arkenv/tree/main/examples/with-bun), and [**Vite** from **2.9.18** to **7.x**](https://github.com/yamcodes/arkenv/tree/main/examples/with-vite-react
|
|
134
|
+
ArkEnv is tested on [**Node.js LTS** and **Current**](https://github.com/yamcodes/arkenv/tree/main/examples/basic), [**Bun 1.3.2**](https://github.com/yamcodes/arkenv/tree/main/examples/with-bun), and [**Vite** from **2.9.18** to **7.x**](https://github.com/yamcodes/arkenv/tree/main/examples/with-vite-react). Older versions may work but are not officially supported.
|
|
116
135
|
|
|
117
|
-
### TypeScript
|
|
118
|
-
|
|
119
|
-
While ArkEnv works with plain JavaScript, *TypeScript is highly recommended* to get the full typesafety benefits. To get ArkEnv to work with TypeScript, we require:
|
|
136
|
+
### TypeScript requirements
|
|
120
137
|
|
|
121
138
|
- [**Modern TypeScript module resolution**](https://www.typescriptlang.org/tsconfig/#moduleResolution). One of the following is required in your `tsconfig.json`:
|
|
122
139
|
- `"moduleResolution": "bundler"` - Recommended for modern bundlers (Vite, Next.js, etc.). Supplied by default when using `"module": "Preserve"` (Introduced in TypeScript v5.4).
|
|
123
140
|
- `"moduleResolution": "node16"` or `"nodenext"` - For Node.js projects. Supplied by default when using a matching `"module"` value.
|
|
124
141
|
- **TypeScript >= 5.1** and [anything else required by ArkType](https://arktype.io/docs/intro/setup#installation)
|
|
125
142
|
|
|
126
|
-
> [
|
|
127
|
-
> Without TypeScript, runtime validation still works, but you lose build-time type checking and, in some cases, editor autocomplete. Try our [examples](https://arkenv.js.org/docs/examples) to see this in action!
|
|
143
|
+
> While TypeScript is the recommended setup, ArkEnv works with plain JavaScript. See the [basic-js](https://github.com/yamcodes/arkenv/tree/main/examples/basic-js) example for details and tradeoffs.
|
|
128
144
|
|
|
129
145
|
## Plugins
|
|
130
146
|
|
|
@@ -137,6 +153,24 @@ Beyond [the core package](https://arkenv.js.org/docs/arkenv), we also provide pl
|
|
|
137
153
|
|
|
138
154
|
If you love ArkEnv, you can support the project by **starring it on GitHub**!
|
|
139
155
|
|
|
140
|
-
You are also welcome to
|
|
156
|
+
You are also welcome to [contribute to the project](https://github.com/yamcodes/arkenv/blob/main/CONTRIBUTING.md) and join the wonderful people who have contributed:
|
|
157
|
+
|
|
158
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
159
|
+
<!-- prettier-ignore-start -->
|
|
160
|
+
<!-- markdownlint-disable -->
|
|
161
|
+
<table>
|
|
162
|
+
<tbody>
|
|
163
|
+
<tr>
|
|
164
|
+
<td align="center" valign="top" width="14.28%"><a href="https://yam.codes"><img src="https://avatars.githubusercontent.com/u/2014360?v=4?s=100" width="100px;" alt="Yam C Borodetsky"/><br /><sub><b>Yam C Borodetsky</b></sub></a><br /><a href="https://github.com/yamcodes/arkenv/commits?author=yamcodes" title="Code">💻</a> <a href="#question-yamcodes" title="Answering Questions">💬</a> <a href="#ideas-yamcodes" title="Ideas, Planning, & Feedback">🤔</a> <a href="#design-yamcodes" title="Design">🎨</a> <a href="https://github.com/yamcodes/arkenv/commits?author=yamcodes" title="Documentation">📖</a> <a href="https://github.com/yamcodes/arkenv/issues?q=author%3Ayamcodes" title="Bug reports">🐛</a> <a href="#example-yamcodes" title="Examples">💡</a> <a href="#infra-yamcodes" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/yamcodes/arkenv/commits?author=yamcodes" title="Tests">⚠️</a></td>
|
|
165
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/aruaycodes"><img src="https://avatars.githubusercontent.com/u/57131628?v=4?s=100" width="100px;" alt="Aruay Berdikulova"/><br /><sub><b>Aruay Berdikulova</b></sub></a><br /><a href="https://github.com/yamcodes/arkenv/commits?author=aruaycodes" title="Code">💻</a> <a href="#ideas-aruaycodes" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
166
|
+
<td align="center" valign="top" width="14.28%"><a href="https://arktype.io"><img src="https://avatars.githubusercontent.com/u/10645823?v=4?s=100" width="100px;" alt="David Blass"/><br /><sub><b>David Blass</b></sub></a><br /><a href="#ideas-ssalbdivad" title="Ideas, Planning, & Feedback">🤔</a> <a href="#mentoring-ssalbdivad" title="Mentoring">🧑🏫</a> <a href="#question-ssalbdivad" title="Answering Questions">💬</a></td>
|
|
167
|
+
</tr>
|
|
168
|
+
</tbody>
|
|
169
|
+
</table>
|
|
170
|
+
|
|
171
|
+
<!-- markdownlint-restore -->
|
|
172
|
+
<!-- prettier-ignore-end -->
|
|
173
|
+
|
|
174
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
141
175
|
|
|
142
|
-
## [
|
|
176
|
+
## [Acknowledgements](https://github.com/yamcodes/arkenv/blob/main/ACKNOWLEDGEMENTS.md)
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,`__esModule`,{value:!0});let e=require(`arktype`);const t=(0,e.type)(`string
|
|
1
|
+
Object.defineProperty(exports,`__esModule`,{value:!0});let e=require(`arktype`);const t=(0,e.type)(`unknown`).pipe(e=>{if(typeof e==`number`||typeof e!=`string`)return e;let t=e.trim();if(t===``)return e;if(t===`NaN`)return NaN;let n=Number(t);return Number.isNaN(n)?e:n}),n=(0,e.type)(`unknown`).pipe(e=>e===`true`?!0:e===`false`?!1:e),r=(0,e.type)(`0 <= number.integer <= 65535`),i=(0,e.type)(`string.ip | 'localhost'`),a=(0,e.scope)({string:e.type.module({...e.type.keywords.string,host:i}),number:e.type.module({...e.type.keywords.number,port:r})}),o=`*`,s=(e,t=[])=>{let n=[];if(typeof e==`boolean`)return n;if(`const`in e&&(typeof e.const==`number`||typeof e.const==`boolean`)&&n.push({path:[...t]}),`enum`in e&&e.enum&&e.enum.some(e=>typeof e==`number`||typeof e==`boolean`)&&n.push({path:[...t]}),`type`in e){if(e.type===`number`||e.type===`integer`)n.push({path:[...t]});else if(e.type===`boolean`)n.push({path:[...t]});else if(e.type===`array`)`items`in e&&e.items&&(Array.isArray(e.items)?e.items.forEach((e,r)=>{n.push(...s(e,[...t,`${r}`]))}):n.push(...s(e.items,[...t,`*`])));else if(e.type===`object`&&`properties`in e&&e.properties)for(let[r,i]of Object.entries(e.properties))n.push(...s(i,[...t,r]))}if(`anyOf`in e&&e.anyOf)for(let r of e.anyOf)n.push(...s(r,t));if(`allOf`in e&&e.allOf)for(let r of e.allOf)n.push(...s(r,t));if(`oneOf`in e&&e.oneOf)for(let r of e.oneOf)n.push(...s(r,t));let r=new Set;return n.filter(e=>{let t=JSON.stringify(e.path);return r.has(t)?!1:(r.add(t),!0)})},c=(e,r)=>{if(typeof e!=`object`||!e){if(r.some(e=>e.path.length===0)){let r=t(e);return typeof r==`number`?r:n(e)}return e}let i=(e,r)=>{if(!e||typeof e!=`object`)return;if(r.length===0){if(Array.isArray(e))for(let t of e)i(t,[]);return}if(r.length===1){let i=r[0];if(i===`*`){if(Array.isArray(e))for(let r=0;r<e.length;r++){let i=e[r],a=t(i);typeof a==`number`?e[r]=a:e[r]=n(i)}return}let a=e;if(Object.prototype.hasOwnProperty.call(a,i)){let e=a[i];if(Array.isArray(e))for(let r=0;r<e.length;r++){let i=e[r],a=t(i);typeof a==`number`?e[r]=a:e[r]=n(i)}else{let r=t(e);typeof r==`number`?a[i]=r:a[i]=n(e)}}return}let[a,...o]=r;if(a===`*`){if(Array.isArray(e))for(let t of e)i(t,o);return}i(e[a],o)};for(let t of r)i(e,t.path);return e};function l(t){let n=s(t.in.toJsonSchema({fallback:e=>e.base}));return n.length===0?t:(0,e.type)(`unknown`).pipe(e=>c(e,n)).pipe(t)}const u=(e,t=2,{dontDetectNewlines:n=!1}={})=>n?`${` `.repeat(t)}${e}`:e.split(`
|
|
2
2
|
`).map(e=>`${` `.repeat(t)}${e}`).join(`
|
|
3
|
-
`),
|
|
4
|
-
`);var
|
|
3
|
+
`),d={red:`\x1B[31m`,yellow:`\x1B[33m`,cyan:`\x1B[36m`,reset:`\x1B[0m`},f=()=>typeof process<`u`&&process.versions!=null&&process.versions.node!=null,p=()=>!!(!f()||process.env.NO_COLOR!==void 0||process.env.CI!==void 0||process.stdout&&!process.stdout.isTTY),m=(e,t)=>f()&&!p()?`${d[e]}${t}${d.reset}`:t,h=e=>Object.entries(e.byPath).map(([e,t])=>{let n=t.message.startsWith(e)?t.message.slice(e.length):t.message,r=n.match(/\(was "([^"]+)"\)/),i=r?n.replace(`(was "${r[1]}")`,`(was ${m(`cyan`,`"${r[1]}"`)})`):n;return`${m(`yellow`,e)} ${i.trimStart()}`}).join(`
|
|
4
|
+
`);var g=class extends Error{constructor(e,t=`Errors found while validating environment variables`){super(`${m(`red`,t)}\n${u(h(e))}\n`),this.name=`ArkEnvError`}};Object.defineProperty(g,`name`,{value:`ArkEnvError`});const _=a.type;function v(e,{env:t=process.env,coerce:n=!0,onUndeclaredKey:r=`delete`}={}){let i=typeof e==`function`&&`assert`in e?e:a.type.raw(e);i=i.onUndeclaredKey(r),n&&(i=l(i));let o=i(t);if(o instanceof _.errors)throw new g(o);return o}const y=v;var b=y;exports.ArkEnvError=g,exports.createEnv=v,exports.default=b,exports.type=_;
|
package/dist/index.d.cts
CHANGED
|
@@ -6,9 +6,12 @@ import * as arktype_internal_variants_object_ts0 from "arktype/internal/variants
|
|
|
6
6
|
import * as arktype_internal_type_ts0 from "arktype/internal/type.ts";
|
|
7
7
|
|
|
8
8
|
//#region ../internal/scope/dist/index.d.ts
|
|
9
|
+
|
|
9
10
|
//#region src/index.d.ts
|
|
10
11
|
/**
|
|
11
|
-
* The root scope for the ArkEnv library,
|
|
12
|
+
* The root scope for the ArkEnv library,
|
|
13
|
+
* containing extensions to the ArkType scopes with ArkEnv-specific types
|
|
14
|
+
* like `string.host` and `number.port`.
|
|
12
15
|
*/
|
|
13
16
|
declare const $: arktype0.Scope<{
|
|
14
17
|
string: arktype0.Submodule<{
|
|
@@ -78,9 +81,8 @@ declare const $: arktype0.Scope<{
|
|
|
78
81
|
epoch: number;
|
|
79
82
|
safe: number;
|
|
80
83
|
NegativeInfinity: number;
|
|
81
|
-
port:
|
|
84
|
+
port: number;
|
|
82
85
|
}>;
|
|
83
|
-
boolean: (In: boolean | "false" | "true") => arktype0.Out<boolean>;
|
|
84
86
|
}>;
|
|
85
87
|
type $ = (typeof $)["t"];
|
|
86
88
|
//#endregion
|
|
@@ -104,6 +106,34 @@ type EnvSchemaWithType = Type<SchemaShape, $>;
|
|
|
104
106
|
//#region src/create-env.d.ts
|
|
105
107
|
type EnvSchema<def$1> = type$1.validate<def$1, $>;
|
|
106
108
|
type RuntimeEnvironment = Record<string, string | undefined>;
|
|
109
|
+
/**
|
|
110
|
+
* Configuration options for `createEnv`
|
|
111
|
+
*/
|
|
112
|
+
type ArkEnvConfig = {
|
|
113
|
+
/**
|
|
114
|
+
* The environment variables to validate. Defaults to `process.env`
|
|
115
|
+
*/
|
|
116
|
+
env?: RuntimeEnvironment;
|
|
117
|
+
/**
|
|
118
|
+
* Whether to coerce environment variables to their defined types. Defaults to `true`
|
|
119
|
+
*/
|
|
120
|
+
coerce?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Control how ArkEnv handles environment variables that are not defined in your schema.
|
|
123
|
+
*
|
|
124
|
+
* Defaults to `'delete'` to ensure your output object only contains
|
|
125
|
+
* keys you've explicitly declared. This differs from ArkType's standard behavior, which
|
|
126
|
+
* mirrors TypeScript by defaulting to `'ignore'`.
|
|
127
|
+
*
|
|
128
|
+
* - `delete` (ArkEnv default): Undeclared keys are allowed on input but stripped from the output.
|
|
129
|
+
* - `ignore` (ArkType default): Undeclared keys are allowed and preserved in the output.
|
|
130
|
+
* - `reject`: Undeclared keys will cause validation to fail.
|
|
131
|
+
*
|
|
132
|
+
* @default "delete"
|
|
133
|
+
* @see https://arktype.io/docs/configuration#onundeclaredkey
|
|
134
|
+
*/
|
|
135
|
+
onUndeclaredKey?: "ignore" | "delete" | "reject";
|
|
136
|
+
};
|
|
107
137
|
/**
|
|
108
138
|
* TODO: `SchemaShape` is basically `Record<string, unknown>`.
|
|
109
139
|
* If possible, find a better type than "const T extends Record<string, unknown>",
|
|
@@ -112,13 +142,13 @@ type RuntimeEnvironment = Record<string, string | undefined>;
|
|
|
112
142
|
/**
|
|
113
143
|
* Create an environment variables object from a schema and an environment
|
|
114
144
|
* @param def - The environment variable schema (raw object or type definition created with `type()`)
|
|
115
|
-
* @param
|
|
145
|
+
* @param config - Configuration options, see {@link ArkEnvConfig}
|
|
116
146
|
* @returns The validated environment variable schema
|
|
117
147
|
* @throws An {@link ArkEnvError | error} if the environment variables are invalid.
|
|
118
148
|
*/
|
|
119
|
-
declare function createEnv<const T extends SchemaShape>(def: EnvSchema<T>,
|
|
120
|
-
declare function createEnv<T extends EnvSchemaWithType>(def: T,
|
|
121
|
-
declare function createEnv<const T extends SchemaShape>(def: EnvSchema<T> | EnvSchemaWithType,
|
|
149
|
+
declare function createEnv<const T extends SchemaShape>(def: EnvSchema<T>, config?: ArkEnvConfig): distill.Out<type$1.infer<T, $>>;
|
|
150
|
+
declare function createEnv<T extends EnvSchemaWithType>(def: T, config?: ArkEnvConfig): InferType<T>;
|
|
151
|
+
declare function createEnv<const T extends SchemaShape>(def: EnvSchema<T> | EnvSchemaWithType, config?: ArkEnvConfig): distill.Out<type$1.infer<T, $>> | InferType<typeof def>;
|
|
122
152
|
//#endregion
|
|
123
153
|
//#region src/type.d.ts
|
|
124
154
|
declare const type: arktype_internal_type_ts0.TypeParser<{
|
|
@@ -189,9 +219,8 @@ declare const type: arktype_internal_type_ts0.TypeParser<{
|
|
|
189
219
|
epoch: number;
|
|
190
220
|
safe: number;
|
|
191
221
|
NegativeInfinity: number;
|
|
192
|
-
port:
|
|
222
|
+
port: number;
|
|
193
223
|
}>;
|
|
194
|
-
boolean: (In: boolean | "false" | "true") => arktype0.Out<boolean>;
|
|
195
224
|
}>;
|
|
196
225
|
//#endregion
|
|
197
226
|
//#region src/errors.d.ts
|
|
@@ -203,7 +232,7 @@ declare class ArkEnvError extends Error {
|
|
|
203
232
|
/**
|
|
204
233
|
* `arkenv`'s main export, an alias for {@link createEnv}
|
|
205
234
|
*
|
|
206
|
-
* {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables
|
|
235
|
+
* {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables validator from editor to runtime.
|
|
207
236
|
*/
|
|
208
237
|
declare const arkenv: typeof createEnv;
|
|
209
238
|
//#endregion
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":["arktype0","arktype_internal_keywords_string_ts0","arktype_internal_attributes_ts0","$","trim","To","Submodule","normalize","capitalize","stringDate","stringInteger","ip","stringJson","lower","stringNumeric","url","uuid","
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":["arktype0","arktype_internal_keywords_string_ts0","arktype_internal_attributes_ts0","$","trim","To","Submodule","normalize","capitalize","stringDate","stringInteger","ip","stringJson","lower","stringNumeric","url","uuid","Scope","type","InferType","T","Record","errors","Any","$","Type","SchemaShape","arktype_internal_variants_object_ts0","ObjectType","infer","EnvSchemaWithType"],"sources":["../../internal/scope/dist/index.d.ts","../../internal/types/dist/infer-type.d.ts","../../internal/types/dist/schema.d.ts","../src/create-env.ts","../src/type.ts","../src/errors.ts","../src/index.ts"],"sourcesContent":["import * as arktype0 from \"arktype\";\nimport * as arktype_internal_keywords_string_ts0 from \"arktype/internal/keywords/string.ts\";\nimport * as arktype_internal_attributes_ts0 from \"arktype/internal/attributes.ts\";\n\n//#region src/index.d.ts\n/**\n * The root scope for the ArkEnv library,\n * containing extensions to the ArkType scopes with ArkEnv-specific types\n * like `string.host` and `number.port`.\n */\ndeclare const $: arktype0.Scope<{\n string: arktype0.Submodule<{\n trim: arktype0.Submodule<arktype_internal_keywords_string_ts0.trim.$ & {\n \" arkInferred\": (In: string) => arktype_internal_attributes_ts0.To<string>;\n }>;\n normalize: arktype0.Submodule<arktype_internal_keywords_string_ts0.normalize.$ & {\n \" arkInferred\": (In: string) => arktype_internal_attributes_ts0.To<string>;\n }>;\n root: string;\n alpha: string;\n alphanumeric: string;\n hex: string;\n base64: arktype0.Submodule<{\n root: string;\n url: string;\n } & {\n \" arkInferred\": string;\n }>;\n capitalize: arktype0.Submodule<arktype_internal_keywords_string_ts0.capitalize.$ & {\n \" arkInferred\": (In: string) => arktype_internal_attributes_ts0.To<string>;\n }>;\n creditCard: string;\n date: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringDate.$ & {\n \" arkInferred\": string;\n }>;\n digits: string;\n email: string;\n integer: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringInteger.$ & {\n \" arkInferred\": string;\n }>;\n ip: arktype0.Submodule<arktype_internal_keywords_string_ts0.ip.$ & {\n \" arkInferred\": string;\n }>;\n json: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringJson.$ & {\n \" arkInferred\": string;\n }>;\n lower: arktype0.Submodule<arktype_internal_keywords_string_ts0.lower.$ & {\n \" arkInferred\": (In: string) => arktype_internal_attributes_ts0.To<string>;\n }>;\n numeric: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringNumeric.$ & {\n \" arkInferred\": string;\n }>;\n regex: string;\n semver: string;\n upper: arktype0.Submodule<{\n root: (In: string) => arktype_internal_attributes_ts0.To<string>;\n preformatted: string;\n } & {\n \" arkInferred\": (In: string) => arktype_internal_attributes_ts0.To<string>;\n }>;\n url: arktype0.Submodule<arktype_internal_keywords_string_ts0.url.$ & {\n \" arkInferred\": string;\n }>;\n uuid: arktype0.Submodule<arktype_internal_keywords_string_ts0.uuid.$ & {\n \" arkInferred\": string;\n }>;\n \" arkInferred\": string;\n host: string;\n }>;\n number: arktype0.Submodule<{\n NaN: number;\n Infinity: number;\n root: number;\n integer: number;\n \" arkInferred\": number;\n epoch: number;\n safe: number;\n NegativeInfinity: number;\n port: number;\n }>;\n}>;\ntype $ = (typeof $)[\"t\"];\n//#endregion\nexport { $ };\n//# sourceMappingURL=index.d.ts.map","import type { type } from \"arktype\";\n/**\n * Extract the inferred type from an ArkType type definition by checking its call signature.\n * When a type definition is called, it returns either the validated value or type.errors.\n *\n * @template T - The ArkType type definition to infer from\n */\nexport type InferType<T> = T extends (value: Record<string, string | undefined>) => infer R ? R extends type.errors ? never : R : T extends type.Any<infer U, infer _Scope> ? U : never;\n//# sourceMappingURL=infer-type.d.ts.map","import type { $ } from \"@repo/scope\";\nimport { type Type } from \"arktype\";\nexport declare const SchemaShape: import(\"arktype/internal/variants/object.ts\").ObjectType<{\n [x: string]: unknown;\n}, {}>;\nexport type SchemaShape = typeof SchemaShape.infer;\nexport type EnvSchemaWithType = Type<SchemaShape, $>;\n//# sourceMappingURL=schema.d.ts.map"],"mappings":";;;;;;;;;;;;;AAEkF;;cAQpEG,CAGwBD,EAHrBF,QAAAA,CAASiB,KAGYf,CAAAA;EAD5BF,MAAAA,EADAA,QAAAA,CAASM,SACAA,CAAAA;IAGeL,IAAAA,EAHxBD,QAAAA,CAASM,SAGeL,CAHLA,oCAAAA,CAAqCG,IAAAA,CAAKD,CAGUA,GAAAA;MAC3CD,cAAAA,EAAAA,CAAAA,EAAAA,EAAAA,MAAgCG,EAAAA,GAHhCH,+BAAAA,CAAgCG,EAGAA,CAAAA,MAAAA,CAAAA;IADvDL,CAAAA,CAAAA;IAOHA,SAASM,EAPNN,QAAAA,CAASM,SAOHA,CAPaL,oCAAAA,CAAqCM,SAAAA,CAAUJ,CAO5DG,GAAAA;MAMcL,cAAAA,EAAAA,CAAAA,EAAAA,EAAAA,MAAAA,EAAAA,GAZGC,+BAAAA,CAAgCG,EAYaF,CAAAA,MAAAA,CAAAA;IAC7CD,CAAAA,CAAAA;IADtBF,IAAAA,EAASM,MAAAA;IAIIL,KAAAA,EAAAA,MAAAA;IAAnBD,YAASM,EAAAA,MAAAA;IAKaL,GAAAA,EAAAA,MAAAA;IAAnBD,MAASM,EAfVN,QAAAA,CAASM,SAeCA,CAAAA;MAGKL,IAAAA,EAAAA,MAAAA;MAAnBD,GAAAA,EAASM,MAAAA;IAGYL,CAAA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A,CAAA,EAAA,MAAA;;;;;;;;;cMvEI,eAAM"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,9 +6,12 @@ import * as arktype_internal_variants_object_ts0 from "arktype/internal/variants
|
|
|
6
6
|
import * as arktype_internal_type_ts0 from "arktype/internal/type.ts";
|
|
7
7
|
|
|
8
8
|
//#region ../internal/scope/dist/index.d.ts
|
|
9
|
+
|
|
9
10
|
//#region src/index.d.ts
|
|
10
11
|
/**
|
|
11
|
-
* The root scope for the ArkEnv library,
|
|
12
|
+
* The root scope for the ArkEnv library,
|
|
13
|
+
* containing extensions to the ArkType scopes with ArkEnv-specific types
|
|
14
|
+
* like `string.host` and `number.port`.
|
|
12
15
|
*/
|
|
13
16
|
declare const $: arktype0.Scope<{
|
|
14
17
|
string: arktype0.Submodule<{
|
|
@@ -78,9 +81,8 @@ declare const $: arktype0.Scope<{
|
|
|
78
81
|
epoch: number;
|
|
79
82
|
safe: number;
|
|
80
83
|
NegativeInfinity: number;
|
|
81
|
-
port:
|
|
84
|
+
port: number;
|
|
82
85
|
}>;
|
|
83
|
-
boolean: (In: boolean | "false" | "true") => arktype0.Out<boolean>;
|
|
84
86
|
}>;
|
|
85
87
|
type $ = (typeof $)["t"];
|
|
86
88
|
//#endregion
|
|
@@ -104,6 +106,34 @@ type EnvSchemaWithType = Type<SchemaShape, $>;
|
|
|
104
106
|
//#region src/create-env.d.ts
|
|
105
107
|
type EnvSchema<def$1> = type$1.validate<def$1, $>;
|
|
106
108
|
type RuntimeEnvironment = Record<string, string | undefined>;
|
|
109
|
+
/**
|
|
110
|
+
* Configuration options for `createEnv`
|
|
111
|
+
*/
|
|
112
|
+
type ArkEnvConfig = {
|
|
113
|
+
/**
|
|
114
|
+
* The environment variables to validate. Defaults to `process.env`
|
|
115
|
+
*/
|
|
116
|
+
env?: RuntimeEnvironment;
|
|
117
|
+
/**
|
|
118
|
+
* Whether to coerce environment variables to their defined types. Defaults to `true`
|
|
119
|
+
*/
|
|
120
|
+
coerce?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Control how ArkEnv handles environment variables that are not defined in your schema.
|
|
123
|
+
*
|
|
124
|
+
* Defaults to `'delete'` to ensure your output object only contains
|
|
125
|
+
* keys you've explicitly declared. This differs from ArkType's standard behavior, which
|
|
126
|
+
* mirrors TypeScript by defaulting to `'ignore'`.
|
|
127
|
+
*
|
|
128
|
+
* - `delete` (ArkEnv default): Undeclared keys are allowed on input but stripped from the output.
|
|
129
|
+
* - `ignore` (ArkType default): Undeclared keys are allowed and preserved in the output.
|
|
130
|
+
* - `reject`: Undeclared keys will cause validation to fail.
|
|
131
|
+
*
|
|
132
|
+
* @default "delete"
|
|
133
|
+
* @see https://arktype.io/docs/configuration#onundeclaredkey
|
|
134
|
+
*/
|
|
135
|
+
onUndeclaredKey?: "ignore" | "delete" | "reject";
|
|
136
|
+
};
|
|
107
137
|
/**
|
|
108
138
|
* TODO: `SchemaShape` is basically `Record<string, unknown>`.
|
|
109
139
|
* If possible, find a better type than "const T extends Record<string, unknown>",
|
|
@@ -112,13 +142,13 @@ type RuntimeEnvironment = Record<string, string | undefined>;
|
|
|
112
142
|
/**
|
|
113
143
|
* Create an environment variables object from a schema and an environment
|
|
114
144
|
* @param def - The environment variable schema (raw object or type definition created with `type()`)
|
|
115
|
-
* @param
|
|
145
|
+
* @param config - Configuration options, see {@link ArkEnvConfig}
|
|
116
146
|
* @returns The validated environment variable schema
|
|
117
147
|
* @throws An {@link ArkEnvError | error} if the environment variables are invalid.
|
|
118
148
|
*/
|
|
119
|
-
declare function createEnv<const T extends SchemaShape>(def: EnvSchema<T>,
|
|
120
|
-
declare function createEnv<T extends EnvSchemaWithType>(def: T,
|
|
121
|
-
declare function createEnv<const T extends SchemaShape>(def: EnvSchema<T> | EnvSchemaWithType,
|
|
149
|
+
declare function createEnv<const T extends SchemaShape>(def: EnvSchema<T>, config?: ArkEnvConfig): distill.Out<type$1.infer<T, $>>;
|
|
150
|
+
declare function createEnv<T extends EnvSchemaWithType>(def: T, config?: ArkEnvConfig): InferType<T>;
|
|
151
|
+
declare function createEnv<const T extends SchemaShape>(def: EnvSchema<T> | EnvSchemaWithType, config?: ArkEnvConfig): distill.Out<type$1.infer<T, $>> | InferType<typeof def>;
|
|
122
152
|
//#endregion
|
|
123
153
|
//#region src/type.d.ts
|
|
124
154
|
declare const type: arktype_internal_type_ts0.TypeParser<{
|
|
@@ -189,9 +219,8 @@ declare const type: arktype_internal_type_ts0.TypeParser<{
|
|
|
189
219
|
epoch: number;
|
|
190
220
|
safe: number;
|
|
191
221
|
NegativeInfinity: number;
|
|
192
|
-
port:
|
|
222
|
+
port: number;
|
|
193
223
|
}>;
|
|
194
|
-
boolean: (In: boolean | "false" | "true") => arktype0.Out<boolean>;
|
|
195
224
|
}>;
|
|
196
225
|
//#endregion
|
|
197
226
|
//#region src/errors.d.ts
|
|
@@ -203,7 +232,7 @@ declare class ArkEnvError extends Error {
|
|
|
203
232
|
/**
|
|
204
233
|
* `arkenv`'s main export, an alias for {@link createEnv}
|
|
205
234
|
*
|
|
206
|
-
* {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables
|
|
235
|
+
* {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables validator from editor to runtime.
|
|
207
236
|
*/
|
|
208
237
|
declare const arkenv: typeof createEnv;
|
|
209
238
|
//#endregion
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["arktype0","arktype_internal_keywords_string_ts0","arktype_internal_attributes_ts0","$","trim","To","Submodule","normalize","capitalize","stringDate","stringInteger","ip","stringJson","lower","stringNumeric","url","uuid","
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["arktype0","arktype_internal_keywords_string_ts0","arktype_internal_attributes_ts0","$","trim","To","Submodule","normalize","capitalize","stringDate","stringInteger","ip","stringJson","lower","stringNumeric","url","uuid","Scope","type","InferType","T","Record","errors","Any","$","Type","SchemaShape","arktype_internal_variants_object_ts0","ObjectType","infer","EnvSchemaWithType"],"sources":["../../internal/scope/dist/index.d.ts","../../internal/types/dist/infer-type.d.ts","../../internal/types/dist/schema.d.ts","../src/create-env.ts","../src/type.ts","../src/errors.ts","../src/index.ts"],"sourcesContent":["import * as arktype0 from \"arktype\";\nimport * as arktype_internal_keywords_string_ts0 from \"arktype/internal/keywords/string.ts\";\nimport * as arktype_internal_attributes_ts0 from \"arktype/internal/attributes.ts\";\n\n//#region src/index.d.ts\n/**\n * The root scope for the ArkEnv library,\n * containing extensions to the ArkType scopes with ArkEnv-specific types\n * like `string.host` and `number.port`.\n */\ndeclare const $: arktype0.Scope<{\n string: arktype0.Submodule<{\n trim: arktype0.Submodule<arktype_internal_keywords_string_ts0.trim.$ & {\n \" arkInferred\": (In: string) => arktype_internal_attributes_ts0.To<string>;\n }>;\n normalize: arktype0.Submodule<arktype_internal_keywords_string_ts0.normalize.$ & {\n \" arkInferred\": (In: string) => arktype_internal_attributes_ts0.To<string>;\n }>;\n root: string;\n alpha: string;\n alphanumeric: string;\n hex: string;\n base64: arktype0.Submodule<{\n root: string;\n url: string;\n } & {\n \" arkInferred\": string;\n }>;\n capitalize: arktype0.Submodule<arktype_internal_keywords_string_ts0.capitalize.$ & {\n \" arkInferred\": (In: string) => arktype_internal_attributes_ts0.To<string>;\n }>;\n creditCard: string;\n date: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringDate.$ & {\n \" arkInferred\": string;\n }>;\n digits: string;\n email: string;\n integer: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringInteger.$ & {\n \" arkInferred\": string;\n }>;\n ip: arktype0.Submodule<arktype_internal_keywords_string_ts0.ip.$ & {\n \" arkInferred\": string;\n }>;\n json: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringJson.$ & {\n \" arkInferred\": string;\n }>;\n lower: arktype0.Submodule<arktype_internal_keywords_string_ts0.lower.$ & {\n \" arkInferred\": (In: string) => arktype_internal_attributes_ts0.To<string>;\n }>;\n numeric: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringNumeric.$ & {\n \" arkInferred\": string;\n }>;\n regex: string;\n semver: string;\n upper: arktype0.Submodule<{\n root: (In: string) => arktype_internal_attributes_ts0.To<string>;\n preformatted: string;\n } & {\n \" arkInferred\": (In: string) => arktype_internal_attributes_ts0.To<string>;\n }>;\n url: arktype0.Submodule<arktype_internal_keywords_string_ts0.url.$ & {\n \" arkInferred\": string;\n }>;\n uuid: arktype0.Submodule<arktype_internal_keywords_string_ts0.uuid.$ & {\n \" arkInferred\": string;\n }>;\n \" arkInferred\": string;\n host: string;\n }>;\n number: arktype0.Submodule<{\n NaN: number;\n Infinity: number;\n root: number;\n integer: number;\n \" arkInferred\": number;\n epoch: number;\n safe: number;\n NegativeInfinity: number;\n port: number;\n }>;\n}>;\ntype $ = (typeof $)[\"t\"];\n//#endregion\nexport { $ };\n//# sourceMappingURL=index.d.ts.map","import type { type } from \"arktype\";\n/**\n * Extract the inferred type from an ArkType type definition by checking its call signature.\n * When a type definition is called, it returns either the validated value or type.errors.\n *\n * @template T - The ArkType type definition to infer from\n */\nexport type InferType<T> = T extends (value: Record<string, string | undefined>) => infer R ? R extends type.errors ? never : R : T extends type.Any<infer U, infer _Scope> ? U : never;\n//# sourceMappingURL=infer-type.d.ts.map","import type { $ } from \"@repo/scope\";\nimport { type Type } from \"arktype\";\nexport declare const SchemaShape: import(\"arktype/internal/variants/object.ts\").ObjectType<{\n [x: string]: unknown;\n}, {}>;\nexport type SchemaShape = typeof SchemaShape.infer;\nexport type EnvSchemaWithType = Type<SchemaShape, $>;\n//# sourceMappingURL=schema.d.ts.map"],"mappings":";;;;;;;;;;;;;AAEkF;;cAQpEG,CAGwBD,EAHrBF,QAAAA,CAASiB,KAGYf,CAAAA;EAD5BF,MAAAA,EADAA,QAAAA,CAASM,SACAA,CAAAA;IAGeL,IAAAA,EAHxBD,QAAAA,CAASM,SAGeL,CAHLA,oCAAAA,CAAqCG,IAAAA,CAAKD,CAGUA,GAAAA;MAC3CD,cAA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AAeC,cAAAA,EAAAA,CAAAA,EAAAA,EAAAA,MAAAA,EAAAA,qCAAAA,CAAAA,MAAAA,CAAAA;IAAkBC,CAAAA,CAAAA;IAAgEC,GAAAA,oBAAAA,8CAAAA;MAAqBF,cAAAA,EAAAA,MAAAA;IAAeG,CAAAA,CAAAA;IAAG,IAAA,oBAAA,+CAAA;;;;ICL/HG,IAAAA,EAAAA,MAEf;EACMA,CAAAA,CAAAA;EACAI,MAAAA,oBAAiB,CAAA;IAAQJ,GAAAA,EAAAA,MAAAA;IAAaF,QAAAA,EAAAA,MAAAA;IAAlBC,IAAAA,EAAAA,MAAAA;IAAI,OAAA,EAAA,MAAA;;;;ICCxB,gBAAS,EAAA,MAAA;IAAoB,IAAA,EAAA,MAAA;EAAK,CAAA,CAAA;CAAjB,CAAA;;;cEqBhB,WAAA,SAAoB,KAAA;ELlBnBtB,WAsEZ,CAAA,MAAA,EKlDQ,SLkDR,EAAA,OAAA,CAAA,EAAA,MAAA;;;;;;;;;cMvEI,eAAM"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{scope as e,type as t}from"arktype";const n=t(`string
|
|
1
|
+
import{scope as e,type as t}from"arktype";const n=t(`unknown`).pipe(e=>{if(typeof e==`number`||typeof e!=`string`)return e;let t=e.trim();if(t===``)return e;if(t===`NaN`)return NaN;let n=Number(t);return Number.isNaN(n)?e:n}),r=t(`unknown`).pipe(e=>e===`true`?!0:e===`false`?!1:e),i=t(`0 <= number.integer <= 65535`),a=t(`string.ip | 'localhost'`),o=e({string:t.module({...t.keywords.string,host:a}),number:t.module({...t.keywords.number,port:i})}),s=(e,t=[])=>{let n=[];if(typeof e==`boolean`)return n;if(`const`in e&&(typeof e.const==`number`||typeof e.const==`boolean`)&&n.push({path:[...t]}),`enum`in e&&e.enum&&e.enum.some(e=>typeof e==`number`||typeof e==`boolean`)&&n.push({path:[...t]}),`type`in e){if(e.type===`number`||e.type===`integer`)n.push({path:[...t]});else if(e.type===`boolean`)n.push({path:[...t]});else if(e.type===`array`)`items`in e&&e.items&&(Array.isArray(e.items)?e.items.forEach((e,r)=>{n.push(...s(e,[...t,`${r}`]))}):n.push(...s(e.items,[...t,`*`])));else if(e.type===`object`&&`properties`in e&&e.properties)for(let[r,i]of Object.entries(e.properties))n.push(...s(i,[...t,r]))}if(`anyOf`in e&&e.anyOf)for(let r of e.anyOf)n.push(...s(r,t));if(`allOf`in e&&e.allOf)for(let r of e.allOf)n.push(...s(r,t));if(`oneOf`in e&&e.oneOf)for(let r of e.oneOf)n.push(...s(r,t));let r=new Set;return n.filter(e=>{let t=JSON.stringify(e.path);return r.has(t)?!1:(r.add(t),!0)})},c=(e,t)=>{if(typeof e!=`object`||!e){if(t.some(e=>e.path.length===0)){let t=n(e);return typeof t==`number`?t:r(e)}return e}let i=(e,t)=>{if(!e||typeof e!=`object`)return;if(t.length===0){if(Array.isArray(e))for(let t of e)i(t,[]);return}if(t.length===1){let i=t[0];if(i===`*`){if(Array.isArray(e))for(let t=0;t<e.length;t++){let i=e[t],a=n(i);typeof a==`number`?e[t]=a:e[t]=r(i)}return}let a=e;if(Object.prototype.hasOwnProperty.call(a,i)){let e=a[i];if(Array.isArray(e))for(let t=0;t<e.length;t++){let i=e[t],a=n(i);typeof a==`number`?e[t]=a:e[t]=r(i)}else{let t=n(e);typeof t==`number`?a[i]=t:a[i]=r(e)}}return}let[a,...o]=t;if(a===`*`){if(Array.isArray(e))for(let t of e)i(t,o);return}i(e[a],o)};for(let n of t)i(e,n.path);return e};function l(e){let n=s(e.in.toJsonSchema({fallback:e=>e.base}));return n.length===0?e:t(`unknown`).pipe(e=>c(e,n)).pipe(e)}const u=(e,t=2,{dontDetectNewlines:n=!1}={})=>n?`${` `.repeat(t)}${e}`:e.split(`
|
|
2
2
|
`).map(e=>`${` `.repeat(t)}${e}`).join(`
|
|
3
|
-
`),
|
|
4
|
-
`);var
|
|
3
|
+
`),d={red:`\x1B[31m`,yellow:`\x1B[33m`,cyan:`\x1B[36m`,reset:`\x1B[0m`},f=()=>typeof process<`u`&&process.versions!=null&&process.versions.node!=null,p=()=>!!(!f()||process.env.NO_COLOR!==void 0||process.env.CI!==void 0||process.stdout&&!process.stdout.isTTY),m=(e,t)=>f()&&!p()?`${d[e]}${t}${d.reset}`:t,h=e=>Object.entries(e.byPath).map(([e,t])=>{let n=t.message.startsWith(e)?t.message.slice(e.length):t.message,r=n.match(/\(was "([^"]+)"\)/),i=r?n.replace(`(was "${r[1]}")`,`(was ${m(`cyan`,`"${r[1]}"`)})`):n;return`${m(`yellow`,e)} ${i.trimStart()}`}).join(`
|
|
4
|
+
`);var g=class extends Error{constructor(e,t=`Errors found while validating environment variables`){super(`${m(`red`,t)}\n${u(h(e))}\n`),this.name=`ArkEnvError`}};Object.defineProperty(g,`name`,{value:`ArkEnvError`});const _=o.type;function v(e,{env:t=process.env,coerce:n=!0,onUndeclaredKey:r=`delete`}={}){let i=typeof e==`function`&&`assert`in e?e:o.type.raw(e);i=i.onUndeclaredKey(r),n&&(i=l(i));let a=i(t);if(a instanceof _.errors)throw new g(a);return a}var y=v;export{g as ArkEnvError,v as createEnv,y as default,_ as type};
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["e","n","t","r","i","t","n","e","$","$"],"sources":["../../internal/keywords/dist/index.js","../../internal/scope/dist/index.js","../src/utils/indent.ts","../src/utils/style-text.ts","../src/errors.ts","../src/type.ts","../src/create-env.ts","../src/index.ts"],"sourcesContent":["import{type as e}from\"arktype\";const t=e(`string`,`=>`,(e,t)=>{let n=Number.parseInt(e,10);return(!Number.isInteger(n)||!(0<=n&&n<=65535))&&t.mustBe(`an integer between 0 and 65535`),n}),n=e(`string.ip | 'localhost'`),r=e(`'true' | 'false' | true | false`,`=>`,e=>e===`true`||e===!0);export{r as boolean,n as host,t as port};\n//# sourceMappingURL=index.js.map","import{boolean as e,host as t,port as n}from\"@repo/keywords\";import{scope as r,type as i}from\"arktype\";const a=r({string:i.module({...i.keywords.string,host:t}),number:i.module({...i.keywords.number,port:n}),boolean:e});export{a as $};\n//# sourceMappingURL=index.js.map","/**\n * Options for the `indent` function\n */\ntype IndentOptions = {\n\t/**\n\t * Whether to detect newlines and indent each line individually, defaults to false (indenting the whole string)\n\t */\n\tdontDetectNewlines?: boolean;\n};\n\n/**\n * Indent a string by a given amount\n * @param str - The string to indent\n * @param amt - The amount to indent by, defaults to 2\n * @param options - {@link IndentOptions}\n * @returns The indented string\n */\nexport const indent = (\n\tstr: string,\n\tamt = 2,\n\t{ dontDetectNewlines = false }: IndentOptions = {},\n) => {\n\tconst detectNewlines = !dontDetectNewlines;\n\tif (detectNewlines) {\n\t\treturn str\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => `${\" \".repeat(amt)}${line}`)\n\t\t\t.join(\"\\n\");\n\t}\n\n\treturn `${\" \".repeat(amt)}${str}`;\n};\n","/**\n * Cross-platform text styling utility\n * Uses ANSI colors in Node environments, plain text in browsers\n * Respects NO_COLOR, CI environment variables, and TTY detection\n */\n\n// ANSI color codes for Node environments\nconst colors = {\n\tred: \"\\x1b[31m\",\n\tyellow: \"\\x1b[33m\",\n\tcyan: \"\\x1b[36m\",\n\treset: \"\\x1b[0m\",\n} as const;\n\n/**\n * Check if we're in a Node environment (not browser)\n * Checked dynamically to allow for testing with mocked globals\n */\nconst isNode = (): boolean =>\n\ttypeof process !== \"undefined\" &&\n\tprocess.versions != null &&\n\tprocess.versions.node != null;\n\n/**\n * Check if colors should be disabled based on environment\n * Respects NO_COLOR, CI environment variables, and TTY detection\n */\nconst shouldDisableColors = (): boolean => {\n\tif (!isNode()) return true;\n\n\t// Respect NO_COLOR environment variable (https://no-color.org/)\n\tif (process.env.NO_COLOR !== undefined) return true;\n\n\t// Disable colors in CI environments by default\n\tif (process.env.CI !== undefined) return true;\n\n\t// Disable colors if not writing to a TTY\n\tif (process.stdout && !process.stdout.isTTY) return true;\n\n\treturn false;\n};\n\n/**\n * Style text with color. Uses ANSI codes in Node, plain text in browsers.\n * @param color - The color to apply\n * @param text - The text to style\n * @returns Styled text in Node (if colors enabled), plain text otherwise\n */\nexport const styleText = (\n\tcolor: \"red\" | \"yellow\" | \"cyan\",\n\ttext: string,\n): string => {\n\t// Use ANSI colors only in Node environments with colors enabled\n\tif (isNode() && !shouldDisableColors()) {\n\t\treturn `${colors[color]}${text}${colors.reset}`;\n\t}\n\t// Fall back to plain text in browsers or when colors are disabled\n\treturn text;\n};\n","import type { ArkErrors } from \"arktype\";\nimport { indent, styleText } from \"./utils\";\n\n/**\n * Format the errors returned by ArkType to be more readable\n * @param errors - The errors returned by ArkType\n * @returns A string of the formatted errors\n */\nexport const formatErrors = (errors: ArkErrors): string =>\n\tObject.entries(errors.byPath)\n\t\t.map(([path, error]) => {\n\t\t\tconst messageWithoutPath = error.message.startsWith(path)\n\t\t\t\t? error.message.slice(path.length)\n\t\t\t\t: error.message;\n\n\t\t\t// Extract the value in parentheses if it exists\n\t\t\tconst valueMatch = messageWithoutPath.match(/\\(was \"([^\"]+)\"\\)/);\n\t\t\tconst formattedMessage = valueMatch\n\t\t\t\t? messageWithoutPath.replace(\n\t\t\t\t\t\t`(was \"${valueMatch[1]}\")`,\n\t\t\t\t\t\t`(was ${styleText(\"cyan\", `\"${valueMatch[1]}\"`)})`,\n\t\t\t\t\t)\n\t\t\t\t: messageWithoutPath;\n\n\t\t\treturn `${styleText(\"yellow\", path)}${formattedMessage}`;\n\t\t})\n\t\t.join(\"\\n\");\n\nexport class ArkEnvError extends Error {\n\tconstructor(\n\t\terrors: ArkErrors,\n\t\tmessage = \"Errors found while validating environment variables\",\n\t) {\n\t\tsuper(`${styleText(\"red\", message)}\\n${indent(formatErrors(errors))}\\n`);\n\t\tthis.name = \"ArkEnvError\";\n\t}\n}\n","import { $ } from \"@repo/scope\";\n\nexport const type = $.type;\n","import { $ } from \"@repo/scope\";\nimport type { EnvSchemaWithType, InferType, SchemaShape } from \"@repo/types\";\nimport type { type as at, distill } from \"arktype\";\nimport { ArkEnvError } from \"./errors\";\nimport { type } from \"./type\";\n\nexport type EnvSchema<def> = at.validate<def, $>;\ntype RuntimeEnvironment = Record<string, string | undefined>;\n\n/**\n * TODO: `SchemaShape` is basically `Record<string, unknown>`.\n * If possible, find a better type than \"const T extends Record<string, unknown>\",\n * and be as close as possible to the type accepted by ArkType's `type`.\n */\n\n/**\n * Create an environment variables object from a schema and an environment\n * @param def - The environment variable schema (raw object or type definition created with `type()`)\n * @param env - The environment variables to validate, defaults to `process.env`\n * @returns The validated environment variable schema\n * @throws An {@link ArkEnvError | error} if the environment variables are invalid.\n */\nexport function createEnv<const T extends SchemaShape>(\n\tdef: EnvSchema<T>,\n\tenv?: RuntimeEnvironment,\n): distill.Out<at.infer<T, $>>;\nexport function createEnv<T extends EnvSchemaWithType>(\n\tdef: T,\n\tenv?: RuntimeEnvironment,\n): InferType<T>;\nexport function createEnv<const T extends SchemaShape>(\n\tdef: EnvSchema<T> | EnvSchemaWithType,\n\tenv?: RuntimeEnvironment,\n): distill.Out<at.infer<T, $>> | InferType<typeof def>;\nexport function createEnv<const T extends SchemaShape>(\n\tdef: EnvSchema<T> | EnvSchemaWithType,\n\tenv: RuntimeEnvironment = process.env,\n): distill.Out<at.infer<T, $>> | InferType<typeof def> {\n\t// If def is a type definition (has assert method), use it directly\n\t// Otherwise, use raw() to convert the schema definition\n\tconst schema =\n\t\ttypeof def === \"function\" && \"assert\" in def\n\t\t\t? def\n\t\t\t: $.type.raw(def as EnvSchema<T>);\n\n\tconst validatedEnv = schema(env);\n\n\tif (validatedEnv instanceof type.errors) {\n\t\tthrow new ArkEnvError(validatedEnv);\n\t}\n\n\treturn validatedEnv;\n}\n","export type { EnvSchema } from \"./create-env\";\n\nimport { createEnv } from \"./create-env\";\n\n/**\n * `arkenv`'s main export, an alias for {@link createEnv}\n *\n * {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables parser powered by {@link https://arktype.io | ArkType}, TypeScript's 1:1 validator.\n */\nconst arkenv = createEnv;\nexport default arkenv;\nexport { type } from \"./type\";\nexport { createEnv };\nexport { ArkEnvError } from \"./errors\";\n"],"mappings":"0CAA+B,MAAM,EAAEA,EAAE,SAAS,MAAM,EAAE,IAAI,CAAC,IAAIC,EAAE,OAAO,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,OAAO,UAAUA,EAAE,EAAE,EAAE,GAAGA,GAAGA,GAAG,SAASC,EAAE,OAAO,iCAAiC,CAACD,GAAG,CAAC,EAAED,EAAE,0BAA0B,CAAC,EAAEA,EAAE,kCAAkC,KAAK,GAAG,IAAI,QAAQ,IAAI,CAAC,EAAE,CCA9K,EAAEG,EAAE,CAAC,OAAOC,EAAE,OAAO,CAAC,GAAGA,EAAE,SAAS,OAAO,KAAKC,EAAE,CAAC,CAAC,OAAOD,EAAE,OAAO,CAAC,GAAGA,EAAE,SAAS,OAAO,KAAKE,EAAE,CAAC,CAAC,QAAQC,EAAE,CAAC,CCiB9M,GACZ,EACA,EAAM,EACN,CAAE,qBAAqB,IAAyB,EAAE,GAE1B,EAQjB,GAAG,IAAI,OAAO,EAAI,GAAG,IANpB,EACL,MAAM;EAAK,CACX,IAAK,GAAS,GAAG,IAAI,OAAO,EAAI,GAAG,IAAO,CAC1C,KAAK;EAAK,CCpBR,EAAS,CACd,IAAK,WACL,OAAQ,WACR,KAAM,WACN,MAAO,UACP,CAMK,MACL,OAAO,QAAY,KACnB,QAAQ,UAAY,MACpB,QAAQ,SAAS,MAAQ,KAMpB,MAUL,GATI,CAAC,GAAQ,EAGT,QAAQ,IAAI,WAAa,IAAA,IAGzB,QAAQ,IAAI,KAAO,IAAA,IAGnB,QAAQ,QAAU,CAAC,QAAQ,OAAO,OAW1B,GACZ,EACA,IAGI,GAAQ,EAAI,CAAC,GAAqB,CAC9B,GAAG,EAAO,KAAS,IAAO,EAAO,QAGlC,ECjDK,EAAgB,GAC5B,OAAO,QAAQ,EAAO,OAAO,CAC3B,KAAK,CAAC,EAAM,KAAW,CACvB,IAAM,EAAqB,EAAM,QAAQ,WAAW,EAAK,CACtD,EAAM,QAAQ,MAAM,EAAK,OAAO,CAChC,EAAM,QAGH,EAAa,EAAmB,MAAM,oBAAoB,CAC1D,EAAmB,EACtB,EAAmB,QACnB,SAAS,EAAW,GAAG,IACvB,QAAQ,EAAU,OAAQ,IAAI,EAAW,GAAG,GAAG,CAAC,GAChD,CACA,EAEH,MAAO,GAAG,EAAU,SAAU,EAAK,GAAG,KACrC,CACD,KAAK;EAAK,CAEb,IAAa,EAAb,cAAiC,KAAM,CACtC,YACC,EACA,EAAU,sDACT,CACD,MAAM,GAAG,EAAU,MAAO,EAAQ,CAAC,IAAI,EAAO,EAAa,EAAO,CAAC,CAAC,IAAI,CACxE,KAAK,KAAO,gBChCd,MAAa,EAAOC,EAAE,KCgCtB,SAAgB,EACf,EACA,EAA0B,QAAQ,IACoB,CAQtD,IAAM,GAJL,OAAO,GAAQ,YAAc,WAAY,EACtC,EACAC,EAAE,KAAK,IAAI,EAAoB,EAEP,EAAI,CAEhC,GAAI,aAAwB,EAAK,OAChC,MAAM,IAAI,EAAY,EAAa,CAGpC,OAAO,ECzCR,IAAA,EADe"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["e","t","n","i","n","r","e","t","results: CoercionTarget[]","t","maybeParsedNumber","maybeParsedBoolean","i","type","$","$"],"sources":["../../internal/keywords/dist/index.js","../../internal/scope/dist/index.js","../src/utils/coerce.ts","../src/utils/indent.ts","../src/utils/style-text.ts","../src/errors.ts","../src/type.ts","../src/create-env.ts","../src/index.ts"],"sourcesContent":["import{type as e}from\"arktype\";const t=e(`unknown`).pipe(e=>{if(typeof e==`number`||typeof e!=`string`)return e;let t=e.trim();if(t===``)return e;if(t===`NaN`)return NaN;let n=Number(t);return Number.isNaN(n)?e:n}),n=e(`unknown`).pipe(e=>e===`true`?!0:e===`false`?!1:e),r=e(`0 <= number.integer <= 65535`),i=e(`string.ip | 'localhost'`);export{i as host,n as maybeParsedBoolean,t as maybeParsedNumber,r as port};\n//# sourceMappingURL=index.js.map","import{host as e,port as t}from\"@repo/keywords\";import{scope as n,type as r}from\"arktype\";const i=n({string:r.module({...r.keywords.string,host:e}),number:r.module({...r.keywords.number,port:t})});export{i as $};\n//# sourceMappingURL=index.js.map","import { maybeParsedBoolean, maybeParsedNumber } from \"@repo/keywords\";\nimport { type BaseType, type JsonSchema, type } from \"arktype\";\n\n/**\n * A marker used in the coercion path to indicate that the target\n * is the *elements* of an array, rather than the array property itself.\n */\nconst ARRAY_ITEM_MARKER = \"*\";\n\n/**\n * @internal\n * Information about a path in the schema that requires coercion.\n */\ntype CoercionTarget = {\n\tpath: string[];\n};\n\n/**\n * Recursively find all paths in a JSON Schema that require coercion.\n * We prioritize \"number\", \"integer\", and \"boolean\" types.\n */\nconst findCoercionPaths = (\n\tnode: JsonSchema,\n\tpath: string[] = [],\n): CoercionTarget[] => {\n\tconst results: CoercionTarget[] = [];\n\n\tif (typeof node === \"boolean\") {\n\t\treturn results;\n\t}\n\n\tif (\"const\" in node) {\n\t\tif (typeof node.const === \"number\" || typeof node.const === \"boolean\") {\n\t\t\tresults.push({ path: [...path] });\n\t\t}\n\t}\n\n\tif (\"enum\" in node && node.enum) {\n\t\tif (\n\t\t\tnode.enum.some((v) => typeof v === \"number\" || typeof v === \"boolean\")\n\t\t) {\n\t\t\tresults.push({ path: [...path] });\n\t\t}\n\t}\n\n\tif (\"type\" in node) {\n\t\tif (node.type === \"number\" || node.type === \"integer\") {\n\t\t\tresults.push({ path: [...path] });\n\t\t} else if (node.type === \"boolean\") {\n\t\t\tresults.push({ path: [...path] });\n\t\t} else if (node.type === \"array\") {\n\t\t\tif (\"items\" in node && node.items) {\n\t\t\t\tif (Array.isArray(node.items)) {\n\t\t\t\t\t// Tuple traversal\n\t\t\t\t\tnode.items.forEach((item, index) => {\n\t\t\t\t\t\tresults.push(\n\t\t\t\t\t\t\t...findCoercionPaths(item as JsonSchema, [...path, `${index}`]),\n\t\t\t\t\t\t);\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\t// List traversal\n\t\t\t\t\tresults.push(\n\t\t\t\t\t\t...findCoercionPaths(node.items as JsonSchema, [\n\t\t\t\t\t\t\t...path,\n\t\t\t\t\t\t\tARRAY_ITEM_MARKER,\n\t\t\t\t\t\t]),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (node.type === \"object\") {\n\t\t\tif (\"properties\" in node && node.properties) {\n\t\t\t\tfor (const [key, prop] of Object.entries(node.properties)) {\n\t\t\t\t\tresults.push(\n\t\t\t\t\t\t...findCoercionPaths(prop as JsonSchema, [...path, key]),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (\"anyOf\" in node && node.anyOf) {\n\t\tfor (const branch of node.anyOf) {\n\t\t\tresults.push(...findCoercionPaths(branch as JsonSchema, path));\n\t\t}\n\t}\n\n\tif (\"allOf\" in node && node.allOf) {\n\t\tfor (const branch of node.allOf) {\n\t\t\tresults.push(...findCoercionPaths(branch as JsonSchema, path));\n\t\t}\n\t}\n\n\tif (\"oneOf\" in node && node.oneOf) {\n\t\tfor (const branch of node.oneOf) {\n\t\t\tresults.push(...findCoercionPaths(branch as JsonSchema, path));\n\t\t}\n\t}\n\n\t// Deduplicate by path\n\tconst seen = new Set<string>();\n\treturn results.filter((t) => {\n\t\tconst key = JSON.stringify(t.path);\n\t\tif (seen.has(key)) return false;\n\t\tseen.add(key);\n\t\treturn true;\n\t});\n};\n\n/**\n * Apply coercion to a data object based on identified paths.\n */\nconst applyCoercion = (data: unknown, targets: CoercionTarget[]) => {\n\tif (typeof data !== \"object\" || data === null) {\n\t\t// If root data needs coercion (e.g. root schema is number/boolean), handle it\n\t\tif (targets.some((t) => t.path.length === 0)) {\n\t\t\tconst asNumber = maybeParsedNumber(data);\n\t\t\tif (typeof asNumber === \"number\") {\n\t\t\t\treturn asNumber;\n\t\t\t}\n\t\t\treturn maybeParsedBoolean(data);\n\t\t}\n\t\treturn data;\n\t}\n\n\tconst walk = (current: unknown, targetPath: string[]) => {\n\t\tif (!current || typeof current !== \"object\") return;\n\n\t\t// Defensive: handle root-level or exhausted-path array traversal\n\t\t// Currently, root arrays produce targets like [{ path: [\"*\"] }] so this is rarely reached,\n\t\t// but guards against edge cases in schema introspection\n\t\tif (targetPath.length === 0) {\n\t\t\tif (Array.isArray(current)) {\n\t\t\t\tfor (const item of current) {\n\t\t\t\t\twalk(item, []);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// If we've reached the last key, apply coercion\n\t\tif (targetPath.length === 1) {\n\t\t\tconst lastKey = targetPath[0];\n\n\t\t\tif (lastKey === ARRAY_ITEM_MARKER) {\n\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\tfor (let i = 0; i < current.length; i++) {\n\t\t\t\t\t\tconst original = current[i];\n\t\t\t\t\t\tconst asNumber = maybeParsedNumber(original);\n\t\t\t\t\t\tif (typeof asNumber === \"number\") {\n\t\t\t\t\t\t\tcurrent[i] = asNumber;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tcurrent[i] = maybeParsedBoolean(original);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst record = current as Record<string, unknown>;\n\t\t\t// biome-ignore lint/suspicious/noPrototypeBuiltins: ES2020 compatibility\n\t\t\tif (Object.prototype.hasOwnProperty.call(record, lastKey)) {\n\t\t\t\tconst original = record[lastKey];\n\n\t\t\t\tif (Array.isArray(original)) {\n\t\t\t\t\tfor (let i = 0; i < original.length; i++) {\n\t\t\t\t\t\tconst item = original[i];\n\t\t\t\t\t\tconst asNumber = maybeParsedNumber(item);\n\t\t\t\t\t\tif (typeof asNumber === \"number\") {\n\t\t\t\t\t\t\toriginal[i] = asNumber;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\toriginal[i] = maybeParsedBoolean(item);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst asNumber = maybeParsedNumber(original);\n\t\t\t\t\t// If numeric parsing didn't produce a number, try boolean coercion\n\t\t\t\t\tif (typeof asNumber === \"number\") {\n\t\t\t\t\t\trecord[lastKey] = asNumber;\n\t\t\t\t\t} else {\n\t\t\t\t\t\trecord[lastKey] = maybeParsedBoolean(original);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Recurse down\n\t\tconst [nextKey, ...rest] = targetPath;\n\n\t\tif (nextKey === ARRAY_ITEM_MARKER) {\n\t\t\tif (Array.isArray(current)) {\n\t\t\t\tfor (const item of current) {\n\t\t\t\t\twalk(item, rest);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst record = current as Record<string, unknown>;\n\t\twalk(record[nextKey], rest);\n\t};\n\n\tfor (const target of targets) {\n\t\twalk(data, target.path);\n\t}\n\n\treturn data;\n};\n\n/**\n * Create a coercing wrapper around an ArkType schema using JSON Schema introspection.\n * Pre-process input data to coerce string values to numbers/booleans at identified paths\n * before validation.\n */\nexport function coerce<t, $ = {}>(schema: BaseType<t, $>): BaseType<t, $> {\n\t// Use a fallback to handle unjsonifiable parts of the schema (like predicates)\n\t// by preserving the base schema. This ensures that even if part of the schema\n\t// cannot be fully represented in JSON Schema, we can still perform coercion\n\t// for the parts that can.\n\tconst json = schema.in.toJsonSchema({\n\t\tfallback: (ctx) => ctx.base,\n\t});\n\tconst targets = findCoercionPaths(json);\n\n\tif (targets.length === 0) {\n\t\treturn schema;\n\t}\n\n\t/*\n\t * We use `type(\"unknown\")` to start the pipeline, which initializes a default scope.\n\t * Integrating the original `schema` with its custom scope `$` into this pipeline\n\t * creates a scope mismatch in TypeScript ({} vs $).\n\t * We cast to `BaseType<t, $>` to assert the final contract is maintained.\n\t */\n\treturn type(\"unknown\")\n\t\t.pipe((data) => applyCoercion(data, targets))\n\t\t.pipe(schema) as BaseType<t, $>;\n}\n","/**\n * Options for the `indent` function\n */\ntype IndentOptions = {\n\t/**\n\t * Whether to detect newlines and indent each line individually, defaults to false (indenting the whole string)\n\t */\n\tdontDetectNewlines?: boolean;\n};\n\n/**\n * Indent a string by a given amount\n * @param str - The string to indent\n * @param amt - The amount to indent by, defaults to 2\n * @param options - {@link IndentOptions}\n * @returns The indented string\n */\nexport const indent = (\n\tstr: string,\n\tamt = 2,\n\t{ dontDetectNewlines = false }: IndentOptions = {},\n) => {\n\tconst detectNewlines = !dontDetectNewlines;\n\tif (detectNewlines) {\n\t\treturn str\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => `${\" \".repeat(amt)}${line}`)\n\t\t\t.join(\"\\n\");\n\t}\n\n\treturn `${\" \".repeat(amt)}${str}`;\n};\n","/**\n * Cross-platform text styling utility\n * Uses ANSI colors in Node environments, plain text in browsers\n * Respects NO_COLOR, CI environment variables, and TTY detection\n */\n\n// ANSI color codes for Node environments\nconst colors = {\n\tred: \"\\x1b[31m\",\n\tyellow: \"\\x1b[33m\",\n\tcyan: \"\\x1b[36m\",\n\treset: \"\\x1b[0m\",\n} as const;\n\n/**\n * Check if we're in a Node environment (not browser)\n * Checked dynamically to allow for testing with mocked globals\n */\nconst isNode = (): boolean =>\n\ttypeof process !== \"undefined\" &&\n\tprocess.versions != null &&\n\tprocess.versions.node != null;\n\n/**\n * Check if colors should be disabled based on environment\n * Respects NO_COLOR, CI environment variables, and TTY detection\n */\nconst shouldDisableColors = (): boolean => {\n\tif (!isNode()) return true;\n\n\t// Respect NO_COLOR environment variable (https://no-color.org/)\n\tif (process.env.NO_COLOR !== undefined) return true;\n\n\t// Disable colors in CI environments by default\n\tif (process.env.CI !== undefined) return true;\n\n\t// Disable colors if not writing to a TTY\n\tif (process.stdout && !process.stdout.isTTY) return true;\n\n\treturn false;\n};\n\n/**\n * Style text with color. Uses ANSI codes in Node, plain text in browsers.\n * @param color - The color to apply\n * @param text - The text to style\n * @returns Styled text in Node (if colors enabled), plain text otherwise\n */\nexport const styleText = (\n\tcolor: \"red\" | \"yellow\" | \"cyan\",\n\ttext: string,\n): string => {\n\t// Use ANSI colors only in Node environments with colors enabled\n\tif (isNode() && !shouldDisableColors()) {\n\t\treturn `${colors[color]}${text}${colors.reset}`;\n\t}\n\t// Fall back to plain text in browsers or when colors are disabled\n\treturn text;\n};\n","import type { ArkErrors } from \"arktype\";\nimport { indent, styleText } from \"./utils\";\n\n/**\n * Format the errors returned by ArkType to be more readable\n * @param errors - The errors returned by ArkType\n * @returns A string of the formatted errors\n */\nexport const formatErrors = (errors: ArkErrors): string =>\n\tObject.entries(errors.byPath)\n\t\t.map(([path, error]) => {\n\t\t\tconst messageWithoutPath = error.message.startsWith(path)\n\t\t\t\t? error.message.slice(path.length)\n\t\t\t\t: error.message;\n\n\t\t\t// Extract the value in parentheses if it exists\n\t\t\tconst valueMatch = messageWithoutPath.match(/\\(was \"([^\"]+)\"\\)/);\n\t\t\tconst formattedMessage = valueMatch\n\t\t\t\t? messageWithoutPath.replace(\n\t\t\t\t\t\t`(was \"${valueMatch[1]}\")`,\n\t\t\t\t\t\t`(was ${styleText(\"cyan\", `\"${valueMatch[1]}\"`)})`,\n\t\t\t\t\t)\n\t\t\t\t: messageWithoutPath;\n\n\t\t\treturn `${styleText(\"yellow\", path)} ${formattedMessage.trimStart()}`;\n\t\t})\n\t\t.join(\"\\n\");\n\nexport class ArkEnvError extends Error {\n\tconstructor(\n\t\terrors: ArkErrors,\n\t\tmessage = \"Errors found while validating environment variables\",\n\t) {\n\t\tsuper(`${styleText(\"red\", message)}\\n${indent(formatErrors(errors))}\\n`);\n\t\tthis.name = \"ArkEnvError\";\n\t}\n}\n\nObject.defineProperty(ArkEnvError, \"name\", { value: \"ArkEnvError\" });\n","import { $ } from \"@repo/scope\";\n\nexport const type = $.type;\n","import { $ } from \"@repo/scope\";\nimport type { EnvSchemaWithType, InferType, SchemaShape } from \"@repo/types\";\nimport type { type as at, distill } from \"arktype\";\nimport { ArkEnvError } from \"./errors\";\nimport { type } from \"./type\";\nimport { coerce } from \"./utils\";\n\nexport type EnvSchema<def> = at.validate<def, $>;\ntype RuntimeEnvironment = Record<string, string | undefined>;\n\n/**\n * Configuration options for `createEnv`\n */\nexport type ArkEnvConfig = {\n\t/**\n\t * The environment variables to validate. Defaults to `process.env`\n\t */\n\tenv?: RuntimeEnvironment;\n\t/**\n\t * Whether to coerce environment variables to their defined types. Defaults to `true`\n\t */\n\tcoerce?: boolean;\n\t/**\n\t * Control how ArkEnv handles environment variables that are not defined in your schema.\n\t *\n\t * Defaults to `'delete'` to ensure your output object only contains\n\t * keys you've explicitly declared. This differs from ArkType's standard behavior, which\n\t * mirrors TypeScript by defaulting to `'ignore'`.\n\t *\n\t * - `delete` (ArkEnv default): Undeclared keys are allowed on input but stripped from the output.\n\t * - `ignore` (ArkType default): Undeclared keys are allowed and preserved in the output.\n\t * - `reject`: Undeclared keys will cause validation to fail.\n\t *\n\t * @default \"delete\"\n\t * @see https://arktype.io/docs/configuration#onundeclaredkey\n\t */\n\tonUndeclaredKey?: \"ignore\" | \"delete\" | \"reject\";\n};\n\n/**\n * TODO: `SchemaShape` is basically `Record<string, unknown>`.\n * If possible, find a better type than \"const T extends Record<string, unknown>\",\n * and be as close as possible to the type accepted by ArkType's `type`.\n */\n\n/**\n * Create an environment variables object from a schema and an environment\n * @param def - The environment variable schema (raw object or type definition created with `type()`)\n * @param config - Configuration options, see {@link ArkEnvConfig}\n * @returns The validated environment variable schema\n * @throws An {@link ArkEnvError | error} if the environment variables are invalid.\n */\nexport function createEnv<const T extends SchemaShape>(\n\tdef: EnvSchema<T>,\n\tconfig?: ArkEnvConfig,\n): distill.Out<at.infer<T, $>>;\nexport function createEnv<T extends EnvSchemaWithType>(\n\tdef: T,\n\tconfig?: ArkEnvConfig,\n): InferType<T>;\nexport function createEnv<const T extends SchemaShape>(\n\tdef: EnvSchema<T> | EnvSchemaWithType,\n\tconfig?: ArkEnvConfig,\n): distill.Out<at.infer<T, $>> | InferType<typeof def>;\nexport function createEnv<const T extends SchemaShape>(\n\tdef: EnvSchema<T> | EnvSchemaWithType,\n\t{\n\t\tenv = process.env,\n\t\tcoerce: shouldCoerce = true,\n\t\tonUndeclaredKey = \"delete\",\n\t}: ArkEnvConfig = {},\n): distill.Out<at.infer<T, $>> | InferType<typeof def> {\n\t// If def is a type definition (has assert method), use it directly\n\t// Otherwise, use raw() to convert the schema definition\n\tconst isCompiledType = typeof def === \"function\" && \"assert\" in def;\n\tlet schema = isCompiledType ? def : $.type.raw(def as EnvSchema<T>);\n\n\t// Apply the `onUndeclaredKey` option\n\tschema = schema.onUndeclaredKey(onUndeclaredKey);\n\n\t// Apply coercion transformation to allow strings to be parsed as numbers/booleans\n\tif (shouldCoerce) {\n\t\tschema = coerce(schema);\n\t}\n\n\t// Validate the environment variables\n\tconst validatedEnv = schema(env);\n\n\tif (validatedEnv instanceof type.errors) {\n\t\tthrow new ArkEnvError(validatedEnv);\n\t}\n\n\treturn validatedEnv;\n}\n","export type { EnvSchema } from \"./create-env\";\n\nimport { createEnv } from \"./create-env\";\n\n/**\n * `arkenv`'s main export, an alias for {@link createEnv}\n *\n * {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables validator from editor to runtime.\n */\nconst arkenv = createEnv;\nexport default arkenv;\nexport { type } from \"./type\";\nexport { createEnv };\nexport { ArkEnvError } from \"./errors\";\n"],"mappings":"0CAA+B,MAAM,EAAEA,EAAE,UAAU,CAAC,KAAK,GAAG,CAAC,GAAG,OAAO,GAAG,UAAU,OAAO,GAAG,SAAS,OAAO,EAAE,IAAIC,EAAE,EAAE,MAAM,CAAC,GAAGA,IAAI,GAAG,OAAO,EAAE,GAAGA,IAAI,MAAM,MAAO,KAAI,IAAIC,EAAE,OAAOD,EAAE,CAAC,OAAO,OAAO,MAAMC,EAAE,CAAC,EAAEA,GAAG,CAAC,EAAEF,EAAE,UAAU,CAAC,K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,EAAO,EAAO,EAIxB,IAAM,EAAe,EAAO,EAAI,CAEhC,GAAI,aAAwB,EAAK,OAChC,MAAM,IAAI,EAAY,EAAa,CAGpC,OAAO,EClFR,IAAA,EADe"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arkenv",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.1",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
"bugs": "https://github.com/yamcodes/arkenv/labels/arkenv",
|
|
32
32
|
"author": "Yam Borodetsky <yam@yam.codes>",
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@size-limit/esbuild-why": "
|
|
35
|
-
"@size-limit/preset-small-lib": "
|
|
36
|
-
"@types/node": "24.10.
|
|
37
|
-
"arktype": "2.1.
|
|
34
|
+
"@size-limit/esbuild-why": "12.0.0",
|
|
35
|
+
"@size-limit/preset-small-lib": "12.0.0",
|
|
36
|
+
"@types/node": "24.10.4",
|
|
37
|
+
"arktype": "2.1.29",
|
|
38
38
|
"rimraf": "6.1.2",
|
|
39
|
-
"size-limit": "
|
|
40
|
-
"tsdown": "0.
|
|
39
|
+
"size-limit": "12.0.0",
|
|
40
|
+
"tsdown": "0.18.3",
|
|
41
41
|
"typescript": "5.9.3",
|
|
42
|
-
"vitest": "4.0.
|
|
43
|
-
"@repo/keywords": "0.
|
|
44
|
-
"@repo/scope": "0.0
|
|
45
|
-
"@repo/types": "0.0
|
|
42
|
+
"vitest": "4.0.16",
|
|
43
|
+
"@repo/keywords": "0.1.0",
|
|
44
|
+
"@repo/scope": "0.1.0",
|
|
45
|
+
"@repo/types": "1.0.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"arktype": "^2.1.22"
|