arkenv 0.11.0 → 0.12.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/README.md +28 -84
- package/dist/{core-DzT5rjcY.mjs → core-B51xxxje.mjs} +1 -1
- package/dist/{core-DzT5rjcY.mjs.map → core-B51xxxje.mjs.map} +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.d.cts.map +1 -1
- package/dist/core.d.mts.map +1 -1
- package/dist/core.mjs +1 -1
- package/dist/{index-Cic20SzT.d.mts → index-Br22fqkz.d.mts} +27 -29
- package/dist/index-Br22fqkz.d.mts.map +1 -0
- package/dist/{index-bSO6Cmhi.d.cts → index-CzNfOanV.d.cts} +27 -29
- package/dist/index-CzNfOanV.d.cts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +36 -30
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +36 -30
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/shared-Sfv4WYag.cjs +8 -0
- package/dist/shared-_ck4b4vs.mjs +3 -0
- package/dist/shared-_ck4b4vs.mjs.map +1 -0
- package/dist/standard.cjs +1 -1
- package/dist/standard.d.cts +21 -3
- package/dist/standard.d.cts.map +1 -1
- package/dist/standard.d.mts +21 -3
- package/dist/standard.d.mts.map +1 -1
- package/dist/standard.mjs +1 -1
- package/dist/standard.mjs.map +1 -1
- package/package.json +19 -15
- package/dist/index-Cic20SzT.d.mts.map +0 -1
- package/dist/index-bSO6Cmhi.d.cts.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { a as Dict, n as SchemaShape, o as $, r as InferType, t as CompiledEnvSchema } from "./index-
|
|
2
|
-
import * as arktype_internal_keywords_string_ts0 from "arktype/internal/keywords/string.ts";
|
|
3
|
-
import * as arktype_internal_attributes_ts0 from "arktype/internal/attributes.ts";
|
|
4
|
-
import * as
|
|
1
|
+
import { a as Dict, n as SchemaShape, o as $, r as InferType, t as CompiledEnvSchema } from "./index-CzNfOanV.cjs";
|
|
2
|
+
import * as _$arktype_internal_keywords_string_ts0 from "arktype/internal/keywords/string.ts";
|
|
3
|
+
import * as _$arktype_internal_attributes_ts0 from "arktype/internal/attributes.ts";
|
|
4
|
+
import * as _$arktype from "arktype";
|
|
5
5
|
import { distill, type as type$1 } from "arktype";
|
|
6
|
-
import * as arktype_internal_type_ts0 from "arktype/internal/type.ts";
|
|
6
|
+
import * as _$arktype_internal_type_ts0 from "arktype/internal/type.ts";
|
|
7
7
|
|
|
8
8
|
//#region src/create-env.d.ts
|
|
9
|
-
|
|
10
9
|
/**
|
|
11
10
|
* Declarative environment schema definition accepted by ArkEnv.
|
|
12
11
|
*
|
|
@@ -21,7 +20,14 @@ import * as arktype_internal_type_ts0 from "arktype/internal/type.ts";
|
|
|
21
20
|
*
|
|
22
21
|
* @template def - The schema shape object
|
|
23
22
|
*/
|
|
24
|
-
type EnvSchema<def
|
|
23
|
+
type EnvSchema<def> = type$1.validate<def, $>;
|
|
24
|
+
/**
|
|
25
|
+
* Infer the validated and coerced environment object type from a schema.
|
|
26
|
+
* Supports declarative schema shapes, compiled ArkType schemas, and Standard Schema validators.
|
|
27
|
+
*
|
|
28
|
+
* @template T - The schema type
|
|
29
|
+
*/
|
|
30
|
+
type Infer<T> = T extends SchemaShape ? distill.Out<type$1.infer<T, $>> : InferType<T>;
|
|
25
31
|
type RuntimeEnvironment = Dict<string>;
|
|
26
32
|
/**
|
|
27
33
|
* Configuration options for `createEnv`
|
|
@@ -86,66 +92,66 @@ declare function createEnv<const T extends SchemaShape>(def: EnvSchema<T> | Comp
|
|
|
86
92
|
* See ArkType's docs for the full API:
|
|
87
93
|
* https://arktype.io/docs/type-api
|
|
88
94
|
*/
|
|
89
|
-
declare const type: arktype_internal_type_ts0.TypeParser<{
|
|
90
|
-
string:
|
|
91
|
-
trim:
|
|
92
|
-
" arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
95
|
+
declare const type: _$arktype_internal_type_ts0.TypeParser<{
|
|
96
|
+
string: _$arktype.Submodule<{
|
|
97
|
+
trim: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.trim.$ & {
|
|
98
|
+
" arkInferred": (In: string) => _$arktype_internal_attributes_ts0.To<string>;
|
|
93
99
|
}>;
|
|
94
|
-
normalize:
|
|
95
|
-
" arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
100
|
+
normalize: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.normalize.$ & {
|
|
101
|
+
" arkInferred": (In: string) => _$arktype_internal_attributes_ts0.To<string>;
|
|
96
102
|
}>;
|
|
97
103
|
root: string;
|
|
98
104
|
alpha: string;
|
|
99
105
|
alphanumeric: string;
|
|
100
106
|
hex: string;
|
|
101
|
-
base64:
|
|
107
|
+
base64: _$arktype.Submodule<{
|
|
102
108
|
root: string;
|
|
103
109
|
url: string;
|
|
104
110
|
} & {
|
|
105
111
|
" arkInferred": string;
|
|
106
112
|
}>;
|
|
107
|
-
capitalize:
|
|
108
|
-
" arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
113
|
+
capitalize: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.capitalize.$ & {
|
|
114
|
+
" arkInferred": (In: string) => _$arktype_internal_attributes_ts0.To<string>;
|
|
109
115
|
}>;
|
|
110
116
|
creditCard: string;
|
|
111
|
-
date:
|
|
117
|
+
date: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.stringDate.$ & {
|
|
112
118
|
" arkInferred": string;
|
|
113
119
|
}>;
|
|
114
120
|
digits: string;
|
|
115
121
|
email: string;
|
|
116
|
-
integer:
|
|
122
|
+
integer: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.stringInteger.$ & {
|
|
117
123
|
" arkInferred": string;
|
|
118
124
|
}>;
|
|
119
|
-
ip:
|
|
125
|
+
ip: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.ip.$ & {
|
|
120
126
|
" arkInferred": string;
|
|
121
127
|
}>;
|
|
122
|
-
json:
|
|
128
|
+
json: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.stringJson.$ & {
|
|
123
129
|
" arkInferred": string;
|
|
124
130
|
}>;
|
|
125
|
-
lower:
|
|
126
|
-
" arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
131
|
+
lower: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.lower.$ & {
|
|
132
|
+
" arkInferred": (In: string) => _$arktype_internal_attributes_ts0.To<string>;
|
|
127
133
|
}>;
|
|
128
|
-
numeric:
|
|
134
|
+
numeric: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.stringNumeric.$ & {
|
|
129
135
|
" arkInferred": string;
|
|
130
136
|
}>;
|
|
131
137
|
regex: string;
|
|
132
138
|
semver: string;
|
|
133
|
-
upper:
|
|
134
|
-
root: (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
139
|
+
upper: _$arktype.Submodule<{
|
|
140
|
+
root: (In: string) => _$arktype_internal_attributes_ts0.To<string>;
|
|
135
141
|
preformatted: string;
|
|
136
142
|
} & {
|
|
137
|
-
" arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
143
|
+
" arkInferred": (In: string) => _$arktype_internal_attributes_ts0.To<string>;
|
|
138
144
|
}>;
|
|
139
|
-
url:
|
|
145
|
+
url: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.url.$ & {
|
|
140
146
|
" arkInferred": string;
|
|
141
147
|
}>;
|
|
142
|
-
uuid:
|
|
148
|
+
uuid: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.uuid.$ & {
|
|
143
149
|
" arkInferred": string;
|
|
144
150
|
}>;
|
|
145
151
|
" arkInferred": string;
|
|
146
152
|
host: string;
|
|
147
153
|
}>;
|
|
148
|
-
number:
|
|
154
|
+
number: _$arktype.Submodule<{
|
|
149
155
|
NaN: number;
|
|
150
156
|
Infinity: number;
|
|
151
157
|
root: number;
|
|
@@ -164,7 +170,7 @@ declare const type: arktype_internal_type_ts0.TypeParser<{
|
|
|
164
170
|
*/
|
|
165
171
|
declare const arkenv: typeof createEnv;
|
|
166
172
|
//#endregion
|
|
167
|
-
export { type ArkEnvConfig, type EnvSchema, createEnv, arkenv as default, type };
|
|
173
|
+
export { type ArkEnvConfig, type EnvSchema, type Infer, createEnv, arkenv as default, type };
|
|
168
174
|
|
|
169
175
|
// CJS Interop Shim
|
|
170
176
|
if (module.exports && module.exports.default) {
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/create-env.ts","../src/index.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/create-env.ts","../src/index.ts"],"mappings":";;;;;;;;;;;;;AAyBA;;;;;;;;;KAAY,SAAA,QAAiB,MAAA,CAAG,QAAA,CAAS,GAAA,EAAK,CAAA;;;;;;AAQ9C;KAAY,KAAA,MAAW,CAAA,SAAU,WAAA,GAC9B,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAG,KAAA,CAAM,CAAA,EAAG,CAAA,KACxB,SAAA,CAAU,CAAA;AAAA,KAER,kBAAA,GAAqB,IAAA;;;;KAKd,YAAA;EARG;;;EAYd,GAAA,GAAM,kBAAA;EAXK;;;EAeX,MAAA;EAjBgC;;;;;;;;;;;AAEjB;;;EA8Bf,eAAA;EA5B6B;AAK9B;;;;;;;EAiCC,WAAA;AAAA;;;AAgBD;;;;;;;;;;iBAAgB,SAAA,iBAA0B,WAAA,CAAA,CACzC,GAAA,EAAK,SAAA,CAAU,CAAA,GACf,MAAA,GAAS,YAAA,GACP,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAG,KAAA,CAAM,CAAA,EAAG,CAAA;AAAA,iBACX,SAAA,WAAoB,iBAAA,CAAA,CACnC,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,YAAA,GACP,SAAA,CAAU,CAAA;AAAA,iBACG,SAAA,iBAA0B,WAAA,CAAA,CACzC,GAAA,EAAK,SAAA,CAAU,CAAA,IAAK,iBAAA,EACpB,MAAA,GAAS,YAAA,GACP,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAG,KAAA,CAAM,CAAA,EAAG,CAAA,KAAM,SAAA,QAAiB,GAAA;;;;;;;;;AA7ElD;;;cCZa,IAAA,8BAAI,UAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAQX,MAAA,SAAM,SAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { a as Dict, n as SchemaShape, o as $, r as InferType, t as CompiledEnvSchema } from "./index-
|
|
2
|
-
import * as
|
|
1
|
+
import { a as Dict, n as SchemaShape, o as $, r as InferType, t as CompiledEnvSchema } from "./index-Br22fqkz.mjs";
|
|
2
|
+
import * as _$arktype from "arktype";
|
|
3
3
|
import { distill, type as type$1 } from "arktype";
|
|
4
|
-
import * as arktype_internal_keywords_string_ts0 from "arktype/internal/keywords/string.ts";
|
|
5
|
-
import * as arktype_internal_attributes_ts0 from "arktype/internal/attributes.ts";
|
|
6
|
-
import * as arktype_internal_type_ts0 from "arktype/internal/type.ts";
|
|
4
|
+
import * as _$arktype_internal_keywords_string_ts0 from "arktype/internal/keywords/string.ts";
|
|
5
|
+
import * as _$arktype_internal_attributes_ts0 from "arktype/internal/attributes.ts";
|
|
6
|
+
import * as _$arktype_internal_type_ts0 from "arktype/internal/type.ts";
|
|
7
7
|
|
|
8
8
|
//#region src/create-env.d.ts
|
|
9
|
-
|
|
10
9
|
/**
|
|
11
10
|
* Declarative environment schema definition accepted by ArkEnv.
|
|
12
11
|
*
|
|
@@ -21,7 +20,14 @@ import * as arktype_internal_type_ts0 from "arktype/internal/type.ts";
|
|
|
21
20
|
*
|
|
22
21
|
* @template def - The schema shape object
|
|
23
22
|
*/
|
|
24
|
-
type EnvSchema<def
|
|
23
|
+
type EnvSchema<def> = type$1.validate<def, $>;
|
|
24
|
+
/**
|
|
25
|
+
* Infer the validated and coerced environment object type from a schema.
|
|
26
|
+
* Supports declarative schema shapes, compiled ArkType schemas, and Standard Schema validators.
|
|
27
|
+
*
|
|
28
|
+
* @template T - The schema type
|
|
29
|
+
*/
|
|
30
|
+
type Infer<T> = T extends SchemaShape ? distill.Out<type$1.infer<T, $>> : InferType<T>;
|
|
25
31
|
type RuntimeEnvironment = Dict<string>;
|
|
26
32
|
/**
|
|
27
33
|
* Configuration options for `createEnv`
|
|
@@ -86,66 +92,66 @@ declare function createEnv<const T extends SchemaShape>(def: EnvSchema<T> | Comp
|
|
|
86
92
|
* See ArkType's docs for the full API:
|
|
87
93
|
* https://arktype.io/docs/type-api
|
|
88
94
|
*/
|
|
89
|
-
declare const type: arktype_internal_type_ts0.TypeParser<{
|
|
90
|
-
string:
|
|
91
|
-
trim:
|
|
92
|
-
" arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
95
|
+
declare const type: _$arktype_internal_type_ts0.TypeParser<{
|
|
96
|
+
string: _$arktype.Submodule<{
|
|
97
|
+
trim: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.trim.$ & {
|
|
98
|
+
" arkInferred": (In: string) => _$arktype_internal_attributes_ts0.To<string>;
|
|
93
99
|
}>;
|
|
94
|
-
normalize:
|
|
95
|
-
" arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
100
|
+
normalize: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.normalize.$ & {
|
|
101
|
+
" arkInferred": (In: string) => _$arktype_internal_attributes_ts0.To<string>;
|
|
96
102
|
}>;
|
|
97
103
|
root: string;
|
|
98
104
|
alpha: string;
|
|
99
105
|
alphanumeric: string;
|
|
100
106
|
hex: string;
|
|
101
|
-
base64:
|
|
107
|
+
base64: _$arktype.Submodule<{
|
|
102
108
|
root: string;
|
|
103
109
|
url: string;
|
|
104
110
|
} & {
|
|
105
111
|
" arkInferred": string;
|
|
106
112
|
}>;
|
|
107
|
-
capitalize:
|
|
108
|
-
" arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
113
|
+
capitalize: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.capitalize.$ & {
|
|
114
|
+
" arkInferred": (In: string) => _$arktype_internal_attributes_ts0.To<string>;
|
|
109
115
|
}>;
|
|
110
116
|
creditCard: string;
|
|
111
|
-
date:
|
|
117
|
+
date: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.stringDate.$ & {
|
|
112
118
|
" arkInferred": string;
|
|
113
119
|
}>;
|
|
114
120
|
digits: string;
|
|
115
121
|
email: string;
|
|
116
|
-
integer:
|
|
122
|
+
integer: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.stringInteger.$ & {
|
|
117
123
|
" arkInferred": string;
|
|
118
124
|
}>;
|
|
119
|
-
ip:
|
|
125
|
+
ip: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.ip.$ & {
|
|
120
126
|
" arkInferred": string;
|
|
121
127
|
}>;
|
|
122
|
-
json:
|
|
128
|
+
json: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.stringJson.$ & {
|
|
123
129
|
" arkInferred": string;
|
|
124
130
|
}>;
|
|
125
|
-
lower:
|
|
126
|
-
" arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
131
|
+
lower: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.lower.$ & {
|
|
132
|
+
" arkInferred": (In: string) => _$arktype_internal_attributes_ts0.To<string>;
|
|
127
133
|
}>;
|
|
128
|
-
numeric:
|
|
134
|
+
numeric: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.stringNumeric.$ & {
|
|
129
135
|
" arkInferred": string;
|
|
130
136
|
}>;
|
|
131
137
|
regex: string;
|
|
132
138
|
semver: string;
|
|
133
|
-
upper:
|
|
134
|
-
root: (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
139
|
+
upper: _$arktype.Submodule<{
|
|
140
|
+
root: (In: string) => _$arktype_internal_attributes_ts0.To<string>;
|
|
135
141
|
preformatted: string;
|
|
136
142
|
} & {
|
|
137
|
-
" arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
143
|
+
" arkInferred": (In: string) => _$arktype_internal_attributes_ts0.To<string>;
|
|
138
144
|
}>;
|
|
139
|
-
url:
|
|
145
|
+
url: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.url.$ & {
|
|
140
146
|
" arkInferred": string;
|
|
141
147
|
}>;
|
|
142
|
-
uuid:
|
|
148
|
+
uuid: _$arktype.Submodule<_$arktype_internal_keywords_string_ts0.uuid.$ & {
|
|
143
149
|
" arkInferred": string;
|
|
144
150
|
}>;
|
|
145
151
|
" arkInferred": string;
|
|
146
152
|
host: string;
|
|
147
153
|
}>;
|
|
148
|
-
number:
|
|
154
|
+
number: _$arktype.Submodule<{
|
|
149
155
|
NaN: number;
|
|
150
156
|
Infinity: number;
|
|
151
157
|
root: number;
|
|
@@ -164,6 +170,6 @@ declare const type: arktype_internal_type_ts0.TypeParser<{
|
|
|
164
170
|
*/
|
|
165
171
|
declare const arkenv: typeof createEnv;
|
|
166
172
|
//#endregion
|
|
167
|
-
export { type ArkEnvConfig, type EnvSchema, createEnv, arkenv as default, type };
|
|
173
|
+
export { type ArkEnvConfig, type EnvSchema, type Infer, createEnv, arkenv as default, type };
|
|
168
174
|
|
|
169
175
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/create-env.ts","../src/index.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/create-env.ts","../src/index.ts"],"mappings":";;;;;;;;;;;;;AAyBA;;;;;;;;;KAAY,SAAA,QAAiB,MAAA,CAAG,QAAA,CAAS,GAAA,EAAK,CAAA;;;;;;AAQ9C;KAAY,KAAA,MAAW,CAAA,SAAU,WAAA,GAC9B,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAG,KAAA,CAAM,CAAA,EAAG,CAAA,KACxB,SAAA,CAAU,CAAA;AAAA,KAER,kBAAA,GAAqB,IAAA;;;;KAKd,YAAA;EARG;;;EAYd,GAAA,GAAM,kBAAA;EAXK;;;EAeX,MAAA;EAjBgC;;;;;;;;;;;AAEjB;;;EA8Bf,eAAA;EA5B6B;AAK9B;;;;;;;EAiCC,WAAA;AAAA;;;AAgBD;;;;;;;;;;iBAAgB,SAAA,iBAA0B,WAAA,CAAA,CACzC,GAAA,EAAK,SAAA,CAAU,CAAA,GACf,MAAA,GAAS,YAAA,GACP,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAG,KAAA,CAAM,CAAA,EAAG,CAAA;AAAA,iBACX,SAAA,WAAoB,iBAAA,CAAA,CACnC,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,YAAA,GACP,SAAA,CAAU,CAAA;AAAA,iBACG,SAAA,iBAA0B,WAAA,CAAA,CACzC,GAAA,EAAK,SAAA,CAAU,CAAA,IAAK,iBAAA,EACpB,MAAA,GAAS,YAAA,GACP,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAG,KAAA,CAAM,CAAA,EAAG,CAAA,KAAM,SAAA,QAAiB,GAAA;;;;;;;;;AA7ElD;;;cCZa,IAAA,8BAAI,UAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAQX,MAAA,SAAM,SAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{r as e,t}from"./core-
|
|
1
|
+
import{r as e,t}from"./core-B51xxxje.mjs";import{n,t as r}from"./shared-_ck4b4vs.mjs";import{ArkErrors as i,scope as a,type as o}from"arktype";const s=o(`0 <= number.integer <= 65535`),c=o(`string.ip | 'localhost'`),l=a({string:o.module({...o.keywords.string,host:c}),number:o.module({...o.keywords.number,port:s})});function u(e,t,i){let a=n(t.in.toJsonSchema({fallback:e=>e.base}));return a.length===0?t:e(`unknown`).pipe(e=>r(e,a,i)).pipe(t)}function d(t){return Object.entries(t.byPath).map(([t,n])=>{let r=n.message,i=r.trimStart();if(i.length>0&&`:.-`.includes(i[0])&&(i=i.slice(1).trimStart()),i.toLowerCase().startsWith(t.toLowerCase())){let e=i.slice(t.length).trimStart();e.length>0&&`:.-`.includes(e[0])&&(e=e.slice(1)),r=e.trimStart()}let a=r.match(/\(was (.*)\)/);if(a?.[1]){let t=a[1];t.includes(`\x1B[`)||(r=r.replace(`(was ${t})`,`(was ${e(`cyan`,t)})`))}return{path:t,message:r}})}function f(e,n){let{env:r=process.env,coerce:a=!0,onUndeclaredKey:o=`delete`,arrayFormat:s=`comma`}=n,c=(typeof e==`function`&&`assert`in e?e:l.type.raw(e)).onUndeclaredKey(o),f=c;a&&(f=u(l.type,c,{arrayFormat:s}));let p=f(r);if(p instanceof i)throw new t(d(p));return p}function p(e,t={}){return f(e,t)}const m=l.type,h=p;export{p as createEnv,h as default,m as type};
|
|
2
2
|
|
|
3
3
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["t","e","n","i","type","$","$"],"sources":["../../internal/scope/dist/index.js","../src/arktype/coercion/morphs.ts","../src/arktype/coercion/coerce.ts","../src/arktype/index.ts","../src/create-env.ts","../src/index.ts"],"sourcesContent":["import{scope as e,type as t}from\"arktype\";const n=t(`0 <= number.integer <= 65535`),r=t(`string.ip | 'localhost'`),i=e({string:t.module({...t.keywords.string,host:r}),number:t.module({...t.keywords.number,port:n})});export{i as $};\n//# sourceMappingURL=index.js.map","/**\n * Attempt to coerce a value to a number.\n *\n * If the input is already a number, returns it unchanged.\n * If the input is a string that can be parsed as a number, returns the parsed number.\n * Otherwise, returns the original value unchanged.\n *\n * @internal\n * @param s - The value to coerce\n * @returns The coerced number or the original value\n */\nexport const coerceNumber = (s: unknown) => {\n\tif (typeof s === \"number\") return s;\n\tif (typeof s !== \"string\") return s;\n\tconst trimmed = s.trim();\n\tif (trimmed === \"\") return s;\n\tif (trimmed === \"NaN\") return Number.NaN;\n\tconst n = Number(trimmed);\n\treturn Number.isNaN(n) ? s : n;\n};\n\n/**\n * Attempt to coerce a value to a boolean.\n *\n * Convert the strings \"true\" and \"false\" to their boolean equivalents.\n * All other values are returned unchanged.\n *\n * @internal\n * @param s - The value to coerce\n * @returns The coerced boolean or the original value\n */\nexport const coerceBoolean = (s: unknown) => {\n\tif (s === \"true\") return true;\n\tif (s === \"false\") return false;\n\treturn s;\n};\n\n/**\n * Attempt to parse a value as JSON.\n *\n * If the input is a string that starts with `{` or `[` and can be parsed as JSON,\n * returns the parsed object or array. Otherwise, returns the original value unchanged.\n *\n * @internal\n * @param s - The value to parse\n * @returns The parsed JSON or the original value\n */\nexport const coerceJson = (s: unknown) => {\n\tif (typeof s !== \"string\") return s;\n\tconst trimmed = s.trim();\n\tif (!trimmed.startsWith(\"{\") && !trimmed.startsWith(\"[\")) return s;\n\ttry {\n\t\treturn JSON.parse(trimmed);\n\t} catch {\n\t\treturn s;\n\t}\n};\n","import type { BaseType, JsonSchema } from \"arktype\";\nimport { coerceBoolean, coerceJson, coerceNumber } from \"./morphs.ts\";\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\ttype: \"primitive\" | \"array\" | \"object\";\n};\n\n/**\n * Options for coercion behavior.\n */\nexport type CoerceOptions = {\n\t/**\n\t * format to use for array parsing\n\t * @default \"comma\"\n\t */\n\tarrayFormat?: \"comma\" | \"json\";\n};\n\n/**\n * Recursively find all paths in a JSON Schema that require coercion.\n * We prioritize \"number\", \"integer\", \"boolean\", \"array\", and \"object\" 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], type: \"primitive\" });\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], type: \"primitive\" });\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], type: \"primitive\" });\n\t\t} else if (node.type === \"boolean\") {\n\t\t\tresults.push({ path: [...path], type: \"primitive\" });\n\t\t} else if (node.type === \"object\") {\n\t\t\t// Check if this object has properties defined\n\t\t\t// If it does, we want to coerce the whole object from a JSON string\n\t\t\t// But we also want to recursively check nested properties\n\t\t\tconst hasProperties =\n\t\t\t\t\"properties\" in node &&\n\t\t\t\tnode.properties &&\n\t\t\t\tObject.keys(node.properties).length > 0;\n\n\t\t\tif (hasProperties) {\n\t\t\t\t// Mark this path as needing object coercion (JSON parsing)\n\t\t\t\tresults.push({ path: [...path], type: \"object\" });\n\t\t\t}\n\n\t\t\t// Also recursively check nested properties for their own coercions\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} else if (node.type === \"array\") {\n\t\t\t// Mark the array itself as a target for splitting strings\n\t\t\tresults.push({ path: [...path], type: \"array\" });\n\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}\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 and type combination\n\tconst seen = new Set<string>();\n\treturn results.filter((t) => {\n\t\tconst key = JSON.stringify(t.path) + t.type;\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 = (\n\tdata: unknown,\n\ttargets: CoercionTarget[],\n\toptions: CoerceOptions = {},\n) => {\n\tconst { arrayFormat = \"comma\" } = options;\n\n\t// Helper to split string to array\n\tconst splitString = (val: string) => {\n\t\tif (arrayFormat === \"json\") {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(val);\n\t\t\t} catch {\n\t\t\t\treturn val;\n\t\t\t}\n\t\t}\n\n\t\tif (!val.trim()) return [];\n\t\treturn val.split(\",\").map((s) => s.trim());\n\t};\n\n\tif (typeof data !== \"object\" || data === null) {\n\t\t// If root data needs coercion\n\t\tif (targets.some((t) => t.path.length === 0)) {\n\t\t\tconst rootTarget = targets.find((t) => t.path.length === 0);\n\n\t\t\tif (rootTarget?.type === \"object\" && typeof data === \"string\") {\n\t\t\t\treturn coerceJson(data);\n\t\t\t}\n\n\t\t\tif (rootTarget?.type === \"array\" && typeof data === \"string\") {\n\t\t\t\treturn splitString(data);\n\t\t\t}\n\n\t\t\tconst asNumber = coerceNumber(data);\n\t\t\tif (typeof asNumber === \"number\") {\n\t\t\t\treturn asNumber;\n\t\t\t}\n\t\t\treturn coerceBoolean(data);\n\t\t}\n\t\treturn data;\n\t}\n\n\t// Sort targets by path length to ensure parent objects/arrays are coerced before their children\n\tconst sortedTargets = [...targets].sort(\n\t\t(a, b) => a.path.length - b.path.length,\n\t);\n\n\tconst walk = (\n\t\tcurrent: unknown,\n\t\ttargetPath: string[],\n\t\ttype: \"primitive\" | \"array\" | \"object\",\n\t) => {\n\t\tif (!current || typeof current !== \"object\") return;\n\n\t\tif (targetPath.length === 0) {\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\tif (type === \"primitive\") {\n\t\t\t\t\t\t\tconst asNumber = coerceNumber(original);\n\t\t\t\t\t\t\tif (typeof asNumber === \"number\") {\n\t\t\t\t\t\t\t\tcurrent[i] = asNumber;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcurrent[i] = coerceBoolean(original);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else if (type === \"object\") {\n\t\t\t\t\t\t\tcurrent[i] = coerceJson(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 (type === \"array\" && typeof original === \"string\") {\n\t\t\t\t\trecord[lastKey] = splitString(original);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (type === \"object\" && typeof original === \"string\") {\n\t\t\t\t\trecord[lastKey] = coerceJson(original);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (Array.isArray(original)) {\n\t\t\t\t\tif (type === \"primitive\") {\n\t\t\t\t\t\tfor (let i = 0; i < original.length; i++) {\n\t\t\t\t\t\t\tconst item = original[i];\n\t\t\t\t\t\t\tconst asNumber = coerceNumber(item);\n\t\t\t\t\t\t\tif (typeof asNumber === \"number\") {\n\t\t\t\t\t\t\t\toriginal[i] = asNumber;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\toriginal[i] = coerceBoolean(item);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (type === \"primitive\") {\n\t\t\t\t\t\tconst asNumber = coerceNumber(original);\n\t\t\t\t\t\t// If numeric parsing didn't produce a number, try boolean coercion\n\t\t\t\t\t\tif (typeof asNumber === \"number\") {\n\t\t\t\t\t\t\trecord[lastKey] = asNumber;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\trecord[lastKey] = coerceBoolean(original);\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\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, type);\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, type);\n\t};\n\n\tfor (const target of sortedTargets) {\n\t\twalk(data, target.path, target.type);\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, $ = {}>(\n\tat: any,\n\tschema: BaseType<t, $>,\n\toptions?: CoerceOptions,\n): 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 as any).base,\n\t});\n\tconst targets = findCoercionPaths(json as any);\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 at(\"unknown\")\n\t\t.pipe((data: unknown) => applyCoercion(data, targets, options))\n\t\t.pipe(schema) as BaseType<t, $>;\n}\n","import { $ } from \"@repo/scope\";\nimport type { SchemaShape } from \"@repo/types\";\nimport type { distill } from \"arktype\";\nimport { ArkErrors } from \"arktype\";\nimport { ArkEnvError, type ValidationIssue } from \"../core\";\nimport type { ArkEnvConfig, EnvSchema } from \"../create-env\";\nimport { styleText } from \"../utils/style-text.ts\";\nimport { coerce } from \"./coercion/coerce\";\n\n/**\n * Re-export of ArkType's `distill` utilities.\n *\n * Exposed for internal use cases and type-level integrations.\n * ArkEnv does not add behavior or guarantees beyond what ArkType provides.\n *\n * @internal\n * @see https://github.com/arktypeio/arktype\n */\nexport type { distill };\n\n/**\n * Converts ArkType's `ArkErrors` (keyed by path) into a flat `ValidationIssue[]`\n * suitable for `ArkEnvError`. Strips leading path references from messages to\n * avoid duplication when `formatInternalErrors` prepends the styled path, and\n * applies cyan styling to inline \"(was …)\" values.\n *\n * @internal\n */\nfunction arkErrorsToIssues(errors: ArkErrors): ValidationIssue[] {\n\treturn Object.entries(errors.byPath).map(([path, error]) => {\n\t\tlet message = error.message;\n\n\t\t// Strip leading path reference if ArkType included it in the message\n\t\tlet trimmed = message.trimStart();\n\t\tif (trimmed.length > 0 && \":.-\".includes(trimmed[0])) {\n\t\t\ttrimmed = trimmed.slice(1).trimStart();\n\t\t}\n\t\tif (trimmed.toLowerCase().startsWith(path.toLowerCase())) {\n\t\t\tlet rest = trimmed.slice(path.length).trimStart();\n\t\t\tif (rest.length > 0 && \":.-\".includes(rest[0])) {\n\t\t\t\trest = rest.slice(1);\n\t\t\t}\n\t\t\tmessage = rest.trimStart();\n\t\t}\n\n\t\t// Style (was ...) inline values\n\t\tconst valueMatch = message.match(/\\(was (.*)\\)/);\n\t\tif (valueMatch?.[1]) {\n\t\t\tconst value = valueMatch[1];\n\t\t\tif (!value.includes(\"\\x1b[\")) {\n\t\t\t\tmessage = message.replace(\n\t\t\t\t\t`(was ${value})`,\n\t\t\t\t\t`(was ${styleText(\"cyan\", value)})`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn { path, message };\n\t});\n}\n\n/**\n * Parse and validate environment variables using ArkEnv's schema rules.\n *\n * This applies:\n * - schema validation\n * - optional coercion (strings → numbers, booleans, arrays)\n * - undeclared key handling\n *\n * On success, returns the validated environment object.\n * On failure, throws an {@link ArkEnvError}.\n *\n * This is a low-level utility used internally by ArkEnv.\n * Most users should prefer the default `arkenv()` export.\n *\n * @internal\n */\nexport function parse<const T extends SchemaShape>(\n\tdef: EnvSchema<T>,\n\tconfig: ArkEnvConfig,\n) {\n\tconst {\n\t\tenv = process.env,\n\t\tcoerce: shouldCoerce = true,\n\t\tonUndeclaredKey = \"delete\",\n\t\tarrayFormat = \"comma\",\n\t} = config;\n\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\tconst schema = (isCompiledType ? def : $.type.raw(def)) as any;\n\n\t// Apply the `onUndeclaredKey` option\n\tconst schemaWithKeys = schema.onUndeclaredKey(onUndeclaredKey);\n\n\t// Apply coercion transformation to allow strings to be parsed as numbers/booleans\n\tlet finalSchema = schemaWithKeys;\n\tif (shouldCoerce) {\n\t\tfinalSchema = coerce($.type, schemaWithKeys, { arrayFormat });\n\t}\n\n\t// Validate the environment variables\n\tconst validatedEnv = finalSchema(env);\n\n\t// In ArkType 2.x, calling a type as a function returns the validated data or ArkErrors\n\tif (validatedEnv instanceof ArkErrors) {\n\t\tthrow new ArkEnvError(arkErrorsToIssues(validatedEnv));\n\t}\n\n\treturn validatedEnv;\n}\n","import type { $ } from \"@repo/scope\";\nimport type {\n\tCompiledEnvSchema,\n\tDict,\n\tInferType,\n\tSchemaShape,\n} from \"@repo/types\";\nimport type { type as at, distill } from \"arktype\";\nimport { parse } from \"./arktype\";\nimport type { ArkEnvError } from \"./core\";\n\n/**\n * Declarative environment schema definition accepted by ArkEnv.\n *\n * Represents a declarative schema object mapping environment\n * variable names to schema definitions (e.g. ArkType DSL strings\n * or Standard Schema validators).\n *\n * This type is used to validate that a schema object is compatible with\n * ArkEnv’s validator scope before being compiled or parsed.\n *\n * Most users will provide schemas in this form.\n *\n * @template def - The schema shape object\n */\nexport type EnvSchema<def> = at.validate<def, $>;\ntype RuntimeEnvironment = Dict<string>;\n\n/**\n * Configuration options for `createEnv`\n */\nexport type ArkEnvConfig = {\n\t/**\n\t * The environment variables to parse. 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\t/**\n\t * The format to use for array parsing when coercion is enabled.\n\t *\n\t * - `comma` (default): Strings are split by comma and trimmed.\n\t * - `json`: Strings are parsed as JSON.\n\t *\n\t * @default \"comma\"\n\t */\n\tarrayFormat?: \"comma\" | \"json\";\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 * Utility to parse environment variables using ArkType or Standard Schema\n * @param def - The schema definition\n * @param config - The evaluation configuration\n * @returns The parsed environment variables\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 CompiledEnvSchema>(\n\tdef: T,\n\tconfig?: ArkEnvConfig,\n): InferType<T>;\nexport function createEnv<const T extends SchemaShape>(\n\tdef: EnvSchema<T> | CompiledEnvSchema,\n\tconfig?: ArkEnvConfig,\n): distill.Out<at.infer<T, $>> | InferType<typeof def>;\nexport function createEnv<const T extends SchemaShape>(\n\tdef: EnvSchema<T> | CompiledEnvSchema,\n\tconfig: ArkEnvConfig = {},\n): distill.Out<at.infer<T, $>> | InferType<typeof def> {\n\t// biome-ignore lint/suspicious/noExplicitAny: parse handles both EnvSchema<T> and CompiledEnvSchema at runtime\n\treturn parse(def as any, config);\n}\n","import { $ } from \"@repo/scope\";\nimport { createEnv } from \"./create-env\";\n\nexport { createEnv };\n/**\n * Like ArkType's `type`, but with ArkEnv's extra keywords, such as:\n *\n * - `string.host` – a hostname (e.g. `\"localhost\"`, `\"127.0.0.1\"`)\n * - `number.port` – a port number (e.g. `8080`)\n *\n * See ArkType's docs for the full API:\n * https://arktype.io/docs/type-api\n */\nexport const type = $.type;\nexport type { ArkEnvConfig, EnvSchema } 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;\n"],"mappings":"mGAA0C,MAAM,EAAEA,EAAE,+BAA+B,CAAC,EAAEA,EAAE,0BAA0B,CAAC,EAAEC,EAAE,CAAC,OAAOD,EAAE,OAAO,CAAC,GAAGA,EAAE,SAAS,OAAO,KAAK,EAAE,CAAC,CAAC,OAAOA,EAAE,OAAO,CAAC,GAAGA,EAAE,SAAS,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,CCW1M,EAAgB,GAAe,CAE3C,GADI,OAAO,GAAM,UACb,OAAO,GAAM,SAAU,OAAO,EAClC,IAAM,EAAU,EAAE,MAAM,CACxB,GAAI,IAAY,GAAI,OAAO,EAC3B,GAAI,IAAY,MAAO,MAAO,KAC9B,IAAME,EAAI,OAAO,EAAQ,CACzB,OAAO,OAAO,MAAMA,EAAE,CAAG,EAAIA,GAajB,EAAiB,GACzB,IAAM,OAAe,GACrB,IAAM,QAAgB,GACnB,EAaK,EAAc,GAAe,CACzC,GAAI,OAAO,GAAM,SAAU,OAAO,EAClC,IAAM,EAAU,EAAE,MAAM,CACxB,GAAI,CAAC,EAAQ,WAAW,IAAI,EAAI,CAAC,EAAQ,WAAW,IAAI,CAA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B,EACf,EACA,EACC,CACD,GAAM,CACL,MAAM,QAAQ,IACd,OAAQ,EAAe,GACvB,kBAAkB,SAClB,cAAc,SACX,EAQE,GAJiB,OAAO,GAAQ,YAAc,WAAY,EAC/B,EAAMC,EAAE,KAAK,IAAI,EAAI,EAGxB,gBAAgB,EAAgB,CAG1D,EAAc,EACd,IACH,EAAc,EAAOA,EAAE,KAAM,EAAgB,CAAE,cAAa,CAAC,EAI9D,IAAM,EAAe,EAAY,EAAI,CAGrC,GAAI,aAAwB,EAC3B,MAAM,IAAI,EAAY,EAAkB,EAAa,CAAC,CAGvD,OAAO,EClBR,SAAgB,EACf,EACA,EAAuB,EAAE,CAC6B,CAEtD,OAAO,EAAM,EAAY,EAAO,CCpFjC,MAAa,EAAOC,EAAE,KAStB,IAAA,EADe"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["t","e","$","$"],"sources":["../../internal/scope/dist/index.js","../src/arktype/coercion/coerce.ts","../src/arktype/index.ts","../src/create-env.ts","../src/index.ts"],"sourcesContent":["import{scope as e,type as t}from\"arktype\";const n=t(`0 <= number.integer <= 65535`),r=t(`string.ip | 'localhost'`),i=e({string:t.module({...t.keywords.string,host:r}),number:t.module({...t.keywords.number,port:n})});export{i as $};\n//# sourceMappingURL=index.js.map","import type { BaseType } from \"arktype\";\nimport {\n\tapplyCoercion,\n\ttype CoerceOptions,\n\tfindCoercionPaths,\n} from \"@/coercion/shared\";\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, $ = {}>(\n\tat: any,\n\tschema: BaseType<t, $>,\n\toptions?: CoerceOptions,\n): 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 as any).base,\n\t});\n\tconst targets = findCoercionPaths(json as any);\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 at(\"unknown\")\n\t\t.pipe((data: unknown) => applyCoercion(data, targets, options))\n\t\t.pipe(schema) as BaseType<t, $>;\n}\n","import { $ } from \"@repo/scope\";\nimport type { SchemaShape } from \"@repo/types\";\nimport type { distill } from \"arktype\";\nimport { ArkErrors } from \"arktype\";\nimport { ArkEnvError, type ValidationIssue } from \"@/core\";\nimport type { ArkEnvConfig, EnvSchema } from \"@/create-env\";\nimport { styleText } from \"@/utils/style-text\";\nimport { coerce } from \"./coercion/coerce\";\n\n/**\n * Re-export of ArkType's `distill` utilities.\n *\n * Exposed for internal use cases and type-level integrations.\n * ArkEnv does not add behavior or guarantees beyond what ArkType provides.\n *\n * @internal\n * @see https://github.com/arktypeio/arktype\n */\nexport type { distill };\n\n/**\n * Converts ArkType's `ArkErrors` (keyed by path) into a flat `ValidationIssue[]`\n * suitable for `ArkEnvError`. Strips leading path references from messages to\n * avoid duplication when `formatInternalErrors` prepends the styled path, and\n * applies cyan styling to inline \"(was …)\" values.\n *\n * @internal\n */\nfunction arkErrorsToIssues(errors: ArkErrors): ValidationIssue[] {\n\treturn Object.entries(errors.byPath).map(([path, error]) => {\n\t\tlet message = error.message;\n\n\t\t// Strip leading path reference if ArkType included it in the message\n\t\tlet trimmed = message.trimStart();\n\t\tif (trimmed.length > 0 && \":.-\".includes(trimmed[0])) {\n\t\t\ttrimmed = trimmed.slice(1).trimStart();\n\t\t}\n\t\tif (trimmed.toLowerCase().startsWith(path.toLowerCase())) {\n\t\t\tlet rest = trimmed.slice(path.length).trimStart();\n\t\t\tif (rest.length > 0 && \":.-\".includes(rest[0])) {\n\t\t\t\trest = rest.slice(1);\n\t\t\t}\n\t\t\tmessage = rest.trimStart();\n\t\t}\n\n\t\t// Style (was ...) inline values\n\t\tconst valueMatch = message.match(/\\(was (.*)\\)/);\n\t\tif (valueMatch?.[1]) {\n\t\t\tconst value = valueMatch[1];\n\t\t\tif (!value.includes(\"\\x1b[\")) {\n\t\t\t\tmessage = message.replace(\n\t\t\t\t\t`(was ${value})`,\n\t\t\t\t\t`(was ${styleText(\"cyan\", value)})`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn { path, message };\n\t});\n}\n\n/**\n * Parse and validate environment variables using ArkEnv's schema rules.\n *\n * This applies:\n * - schema validation\n * - optional coercion (strings → numbers, booleans, arrays)\n * - undeclared key handling\n *\n * On success, returns the validated environment object.\n * On failure, throws an {@link ArkEnvError}.\n *\n * This is a low-level utility used internally by ArkEnv.\n * Most users should prefer the default `arkenv()` export.\n *\n * @internal\n */\nexport function parse<const T extends SchemaShape>(\n\tdef: EnvSchema<T>,\n\tconfig: ArkEnvConfig,\n) {\n\tconst {\n\t\tenv = process.env,\n\t\tcoerce: shouldCoerce = true,\n\t\tonUndeclaredKey = \"delete\",\n\t\tarrayFormat = \"comma\",\n\t} = config;\n\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\tconst schema = (isCompiledType ? def : $.type.raw(def)) as any;\n\n\t// Apply the `onUndeclaredKey` option\n\tconst schemaWithKeys = schema.onUndeclaredKey(onUndeclaredKey);\n\n\t// Apply coercion transformation to allow strings to be parsed as numbers/booleans\n\tlet finalSchema = schemaWithKeys;\n\tif (shouldCoerce) {\n\t\tfinalSchema = coerce($.type, schemaWithKeys, { arrayFormat });\n\t}\n\n\t// Validate the environment variables\n\tconst validatedEnv = finalSchema(env);\n\n\t// In ArkType 2.x, calling a type as a function returns the validated data or ArkErrors\n\tif (validatedEnv instanceof ArkErrors) {\n\t\tthrow new ArkEnvError(arkErrorsToIssues(validatedEnv));\n\t}\n\n\treturn validatedEnv;\n}\n","import type { $ } from \"@repo/scope\";\nimport type {\n\tCompiledEnvSchema,\n\tDict,\n\tInferType,\n\tSchemaShape,\n} from \"@repo/types\";\nimport type { type as at, distill } from \"arktype\";\nimport { parse } from \"./arktype\";\nimport type { ArkEnvError } from \"./core\";\n\n/**\n * Declarative environment schema definition accepted by ArkEnv.\n *\n * Represents a declarative schema object mapping environment\n * variable names to schema definitions (e.g. ArkType DSL strings\n * or Standard Schema validators).\n *\n * This type is used to validate that a schema object is compatible with\n * ArkEnv’s validator scope before being compiled or parsed.\n *\n * Most users will provide schemas in this form.\n *\n * @template def - The schema shape object\n */\nexport type EnvSchema<def> = at.validate<def, $>;\n\n/**\n * Infer the validated and coerced environment object type from a schema.\n * Supports declarative schema shapes, compiled ArkType schemas, and Standard Schema validators.\n *\n * @template T - The schema type\n */\nexport type Infer<T> = T extends SchemaShape\n\t? distill.Out<at.infer<T, $>>\n\t: InferType<T>;\n\ntype RuntimeEnvironment = Dict<string>;\n\n/**\n * Configuration options for `createEnv`\n */\nexport type ArkEnvConfig = {\n\t/**\n\t * The environment variables to parse. 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\t/**\n\t * The format to use for array parsing when coercion is enabled.\n\t *\n\t * - `comma` (default): Strings are split by comma and trimmed.\n\t * - `json`: Strings are parsed as JSON.\n\t *\n\t * @default \"comma\"\n\t */\n\tarrayFormat?: \"comma\" | \"json\";\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 * Utility to parse environment variables using ArkType or Standard Schema\n * @param def - The schema definition\n * @param config - The evaluation configuration\n * @returns The parsed environment variables\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 CompiledEnvSchema>(\n\tdef: T,\n\tconfig?: ArkEnvConfig,\n): InferType<T>;\nexport function createEnv<const T extends SchemaShape>(\n\tdef: EnvSchema<T> | CompiledEnvSchema,\n\tconfig?: ArkEnvConfig,\n): distill.Out<at.infer<T, $>> | InferType<typeof def>;\nexport function createEnv<const T extends SchemaShape>(\n\tdef: EnvSchema<T> | CompiledEnvSchema,\n\tconfig: ArkEnvConfig = {},\n): distill.Out<at.infer<T, $>> | InferType<typeof def> {\n\t// biome-ignore lint/suspicious/noExplicitAny: parse handles both EnvSchema<T> and CompiledEnvSchema at runtime\n\treturn parse(def as any, config);\n}\n","import { $ } from \"@repo/scope\";\nimport { createEnv } from \"./create-env\";\n\nexport { createEnv };\n/**\n * Like ArkType's `type`, but with ArkEnv's extra keywords, such as:\n *\n * - `string.host` – a hostname (e.g. `\"localhost\"`, `\"127.0.0.1\"`)\n * - `number.port` – a port number (e.g. `8080`)\n *\n * See ArkType's docs for the full API:\n * https://arktype.io/docs/type-api\n */\nexport const type = $.type;\nexport type { ArkEnvConfig, EnvSchema, Infer } 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;\n"],"mappings":"+IAA0C,MAAM,EAAEA,EAAE,+BAA+B,CAAC,EAAEA,EAAE,0BAA0B,CAAC,EAAEC,EAAE,CAAC,OAAOD,EAAE,OAAO,CAAC,GAAGA,EAAE,SAAS,OAAO,KAAK,EAAE,CAAC,CAAC,OAAOA,EAAE,OAAO,CAAC,GAAGA,EAAE,SAAS,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,CCYvN,SAAgB,EACf,EACA,EACA,EACiB,CAQjB,IAAM,EAAU,EAHH,EAAO,GAAG,aAAa,CACnC,SAAW,GAAS,EAAY,KAChC,CACqC,CAAQ,CAY9C,OAVI,EAAQ,SAAW,EACf,EASD,EAAG,UAAU,CAClB,KAAM,GAAkB,EAAc,EAAM,EAAS,EAAQ,CAAC,CAC9D,KAAK,EAAO,CCVf,SAAS,EAAkB,EAAsC,CAChE,OAAO,OAAO,QAAQ,EAAO,OAAO,CAAC,KAAK,CAAC,EAAM,KAAW,CAC3D,IAAI,EAAU,EAAM,QAGhB,EAAU,EAAQ,WAAW,CAIjC,GAHI,EAAQ,OAAS,GAAK,MAAM,SAAS,EAAQ,GAAG,GACnD,EAAU,EAAQ,MAAM,EAAE,CAAC,WAAW,EAEnC,EAAQ,aAAa,CAAC,WAAW,EAAK,aAAa,CAAC,CAAE,CACzD,IAAI,EAAO,EAAQ,MAAM,EAAK,OAAO,CAAC,WAAW,CAC7C,EAAK,OAAS,GAAK,MAAM,SAAS,EAAK,GAAG,GAC7C,EAAO,EAAK,MAAM,EAAE,EAErB,EAAU,EAAK,WAAW,CAI3B,IAAM,EAAa,EAAQ,MAAM,eAAe,CAChD,GAAI,IAAa,GAAI,CACpB,IAAM,EAAQ,EAAW,GACpB,EAAM,SAAS,QAAQ,GAC3B,EAAU,EAAQ,QACjB,QAAQ,EAAM,GACd,QAAQ,EAAU,OAAQ,EAAM,CAAC,GACjC,EAIH,MAAO,CAAE,OAAM,UAAS,EACvB,CAmBH,SAAgB,EACf,EACA,EACC,CACD,GAAM,CACL,MAAM,QAAQ,IACd,OAAQ,EAAe,GACvB,kBAAkB,SAClB,cAAc,SACX,EAQE,GAJiB,OAAO,GAAQ,YAAc,WAAY,EAC/B,EAAME,EAAE,KAAK,IAAI,EAAI,EAGxB,gBAAgB,EAAgB,CAG1D,EAAc,EACd,IACH,EAAc,EAAOA,EAAE,KAAM,EAAgB,CAAE,cAAa,CAAC,EAI9D,IAAM,EAAe,EAAY,EAAI,CAGrC,GAAI,aAAwB,EAC3B,MAAM,IAAI,EAAY,EAAkB,EAAa,CAAC,CAGvD,OAAO,ECPR,SAAgB,EACf,EACA,EAAuB,EAAE,CAC6B,CAEtD,OAAO,EAAM,EAAY,EAAO,CC/FjC,MAAa,EAAOC,EAAE,KAQhB,EAAS"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const e=e=>{if(typeof e==`number`||typeof e!=`string`||!e.trim())return e;if(e.trim()===`NaN`)return NaN;let t=Number(e);return Number.isNaN(t)?e:t},t=e=>e===`true`?!0:e===`false`?!1:e,n=e=>{if(typeof e!=`string`)return e;let t=e.trim();if(t[0]!==`{`&&t[0]!==`[`)return e;try{return JSON.parse(t)}catch{return e}},r=e=>{if(e instanceof Date||typeof e!=`string`||!e.trim())return e;let t=new Date(e);return Number.isNaN(t.getTime())?e:t},i=(e,t=[])=>{let n=[];if(!e||typeof e!=`object`)return n;if(`const`in e){let r=typeof e.const;(r===`number`||r===`boolean`)&&n.push({path:[...t],type:`primitive`})}`enum`in e&&Array.isArray(e.enum)&&e.enum.some(e=>typeof e==`number`||typeof e==`boolean`)&&n.push({path:[...t],type:`primitive`});let r=e.type;if(r===`number`||r===`integer`||r===`boolean`)n.push({path:[...t],type:`primitive`});else if(r===`string`&&`format`in e&&(e.format===`date-time`||e.format===`date`))n.push({path:[...t],type:`date`});else if(r===`object`){if(e.properties&&Object.keys(e.properties).length>0){n.push({path:[...t],type:`object`});for(let r in e.properties)n.push(...i(e.properties[r],[...t,r]))}}else r===`array`&&(n.push({path:[...t],type:`array`}),e.items&&(Array.isArray(e.items)?e.items.forEach((e,r)=>{n.push(...i(e,[...t,String(r)]))}):n.push(...i(e.items,[...t,`*`]))));for(let r of[`anyOf`,`allOf`,`oneOf`])if(r in e&&Array.isArray(e[r]))for(let a of e[r])n.push(...i(a,t));let a=new Set;return n.filter(e=>{let t=e.path.join(`/`)+`:`+e.type;return a.has(t)?!1:a.add(t)})},a=(i,a,o={})=>{let{arrayFormat:s=`comma`}=o,c=e=>{if(s===`json`)try{return JSON.parse(e)}catch{return e}return e.trim()?e.split(`,`).map(e=>e.trim()):[]},l=(i,a)=>{if(a===`array`&&typeof i==`string`)return c(i);if(a===`object`&&typeof i==`string`)return n(i);if(a===`date`&&typeof i==`string`)return r(i);if(a===`primitive`){if(Array.isArray(i)){for(let n=0;n<i.length;n++){let r=e(i[n]);i[n]=typeof r==`number`?r:t(i[n])}return i}let n=e(i);return typeof n==`number`?n:t(i)}return i};if(typeof i!=`object`||!i){let e=a.find(e=>e.path.length===0);return e?l(i,e.type):i}let u=[...a].sort((e,t)=>e.path.length-t.path.length),d=(e,t,n)=>{if(!e||typeof e!=`object`||t.length===0)return;let[r,...i]=t;if(i.length===0){if(r===`*`){if(Array.isArray(e))for(let t=0;t<e.length;t++)e[t]=l(e[t],n)}else Object.prototype.hasOwnProperty.call(e,r)&&(e[r]=l(e[r],n));return}if(r===`*`){if(Array.isArray(e))for(let t of e)d(t,i,n)}else d(e[r],i,n)};for(let e of u)d(i,e.path,e.type);return i};Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return a}});
|
|
2
|
+
|
|
3
|
+
// CJS Interop Shim
|
|
4
|
+
if (module.exports && module.exports.default) {
|
|
5
|
+
Object.assign(module.exports.default, module.exports);
|
|
6
|
+
module.exports = module.exports.default;
|
|
7
|
+
}
|
|
8
|
+
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const e=e=>{if(typeof e==`number`||typeof e!=`string`||!e.trim())return e;if(e.trim()===`NaN`)return NaN;let t=Number(e);return Number.isNaN(t)?e:t},t=e=>e===`true`?!0:e===`false`?!1:e,n=e=>{if(typeof e!=`string`)return e;let t=e.trim();if(t[0]!==`{`&&t[0]!==`[`)return e;try{return JSON.parse(t)}catch{return e}},r=e=>{if(e instanceof Date||typeof e!=`string`||!e.trim())return e;let t=new Date(e);return Number.isNaN(t.getTime())?e:t},i=(e,t=[])=>{let n=[];if(!e||typeof e!=`object`)return n;if(`const`in e){let r=typeof e.const;(r===`number`||r===`boolean`)&&n.push({path:[...t],type:`primitive`})}`enum`in e&&Array.isArray(e.enum)&&e.enum.some(e=>typeof e==`number`||typeof e==`boolean`)&&n.push({path:[...t],type:`primitive`});let r=e.type;if(r===`number`||r===`integer`||r===`boolean`)n.push({path:[...t],type:`primitive`});else if(r===`string`&&`format`in e&&(e.format===`date-time`||e.format===`date`))n.push({path:[...t],type:`date`});else if(r===`object`){if(e.properties&&Object.keys(e.properties).length>0){n.push({path:[...t],type:`object`});for(let r in e.properties)n.push(...i(e.properties[r],[...t,r]))}}else r===`array`&&(n.push({path:[...t],type:`array`}),e.items&&(Array.isArray(e.items)?e.items.forEach((e,r)=>{n.push(...i(e,[...t,String(r)]))}):n.push(...i(e.items,[...t,`*`]))));for(let r of[`anyOf`,`allOf`,`oneOf`])if(r in e&&Array.isArray(e[r]))for(let a of e[r])n.push(...i(a,t));let a=new Set;return n.filter(e=>{let t=e.path.join(`/`)+`:`+e.type;return a.has(t)?!1:a.add(t)})},a=(i,a,o={})=>{let{arrayFormat:s=`comma`}=o,c=e=>{if(s===`json`)try{return JSON.parse(e)}catch{return e}return e.trim()?e.split(`,`).map(e=>e.trim()):[]},l=(i,a)=>{if(a===`array`&&typeof i==`string`)return c(i);if(a===`object`&&typeof i==`string`)return n(i);if(a===`date`&&typeof i==`string`)return r(i);if(a===`primitive`){if(Array.isArray(i)){for(let n=0;n<i.length;n++){let r=e(i[n]);i[n]=typeof r==`number`?r:t(i[n])}return i}let n=e(i);return typeof n==`number`?n:t(i)}return i};if(typeof i!=`object`||!i){let e=a.find(e=>e.path.length===0);return e?l(i,e.type):i}let u=[...a].sort((e,t)=>e.path.length-t.path.length),d=(e,t,n)=>{if(!e||typeof e!=`object`||t.length===0)return;let[r,...i]=t;if(i.length===0){if(r===`*`){if(Array.isArray(e))for(let t=0;t<e.length;t++)e[t]=l(e[t],n)}else Object.prototype.hasOwnProperty.call(e,r)&&(e[r]=l(e[r],n));return}if(r===`*`){if(Array.isArray(e))for(let t of e)d(t,i,n)}else d(e[r],i,n)};for(let e of u)d(i,e.path,e.type);return i};export{i as n,a as t};
|
|
2
|
+
|
|
3
|
+
//# sourceMappingURL=shared-_ck4b4vs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-_ck4b4vs.mjs","names":[],"sources":["../src/coercion/morphs.ts","../src/coercion/shared.ts"],"sourcesContent":["/**\n * Attempt to coerce a value to a number.\n *\n * If the input is already a number, returns it unchanged.\n * If the input is a string that can be parsed as a number, returns the parsed number.\n * Otherwise, returns the original value unchanged.\n *\n * @internal\n * @param s - The value to coerce\n * @returns The coerced number or the original value\n */\nexport const coerceNumber = (s: unknown) => {\n\tif (typeof s === \"number\") return s;\n\tif (typeof s !== \"string\" || !s.trim()) return s;\n\tif (s.trim() === \"NaN\") return Number.NaN;\n\tconst n = Number(s);\n\treturn Number.isNaN(n) ? s : n;\n};\n\n/**\n * Attempt to coerce a value to a boolean.\n *\n * Convert the strings \"true\" and \"false\" to their boolean equivalents.\n * All other values are returned unchanged.\n *\n * @internal\n * @param s - The value to coerce\n * @returns The coerced boolean or the original value\n */\nexport const coerceBoolean = (s: unknown) => {\n\tif (s === \"true\") return true;\n\tif (s === \"false\") return false;\n\treturn s;\n};\n\n/**\n * Attempt to parse a value as JSON.\n *\n * If the input is a string that starts with `{` or `[` and can be parsed as JSON,\n * returns the parsed object or array. Otherwise, returns the original value unchanged.\n *\n * @internal\n * @param s - The value to parse\n * @returns The parsed JSON or the original value\n */\nexport const coerceJson = (s: unknown) => {\n\tif (typeof s !== \"string\") return s;\n\tconst trimmed = s.trim();\n\tif (trimmed[0] !== \"{\" && trimmed[0] !== \"[\") return s;\n\ttry {\n\t\treturn JSON.parse(trimmed);\n\t} catch {\n\t\treturn s;\n\t}\n};\n\n/**\n * Attempt to coerce a value to a Date.\n *\n * If the input is already a Date, returns it unchanged.\n * If the input is a valid date string, returns a Date object.\n * Otherwise, returns the original value unchanged.\n *\n * @internal\n * @param s - The value to coerce\n * @returns The coerced Date or the original value\n */\nexport const coerceDate = (s: unknown) => {\n\tif (s instanceof Date) return s;\n\tif (typeof s !== \"string\" || !s.trim()) return s;\n\tconst d = new Date(s);\n\treturn Number.isNaN(d.getTime()) ? s : d;\n};\n","import { coerceBoolean, coerceDate, coerceJson, coerceNumber } from \"./morphs\";\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 */\nexport const ARRAY_ITEM_MARKER = \"*\";\n\n/**\n * @internal\n * Information about a path in the schema that requires coercion.\n */\nexport type CoercionTarget = {\n\tpath: string[];\n\ttype: \"primitive\" | \"array\" | \"object\" | \"date\";\n};\n\n/**\n * Options for coercion behavior.\n */\nexport type CoerceOptions = {\n\t/**\n\t * format to use for array parsing\n\t * @default \"comma\"\n\t */\n\tarrayFormat?: \"comma\" | \"json\";\n};\n\n/**\n * Find all paths in a JSON Schema that require coercion.\n *\n * Prioritize \"number\", \"integer\", \"boolean\", \"array\", \"object\", and \"date\" types.\n *\n * @param node The JSON Schema node to traverse\n * @param path The current path segments in the schema tree\n * @returns An array of coercion targets containing their path and type\n */\nexport const findCoercionPaths = (\n\tnode: Record<string, any>,\n\tpath: string[] = [],\n): CoercionTarget[] => {\n\tconst results: CoercionTarget[] = [];\n\tif (!node || typeof node !== \"object\") return results;\n\n\tif (\"const\" in node) {\n\t\tconst t = typeof node.const;\n\t\tif (t === \"number\" || t === \"boolean\") {\n\t\t\tresults.push({ path: [...path], type: \"primitive\" });\n\t\t}\n\t}\n\n\tif (\"enum\" in node && Array.isArray(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], type: \"primitive\" });\n\t\t}\n\t}\n\n\tconst type = node.type;\n\tif (type === \"number\" || type === \"integer\" || type === \"boolean\") {\n\t\tresults.push({ path: [...path], type: \"primitive\" });\n\t} else if (\n\t\ttype === \"string\" &&\n\t\t\"format\" in node &&\n\t\t(node.format === \"date-time\" || node.format === \"date\")\n\t) {\n\t\tresults.push({ path: [...path], type: \"date\" });\n\t} else if (type === \"object\") {\n\t\tif (node.properties && Object.keys(node.properties).length > 0) {\n\t\t\tresults.push({ path: [...path], type: \"object\" });\n\t\t\tfor (const key in node.properties) {\n\t\t\t\tresults.push(\n\t\t\t\t\t...findCoercionPaths(node.properties[key], [...path, key]),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t} else if (type === \"array\") {\n\t\tresults.push({ path: [...path], type: \"array\" });\n\t\tif (node.items) {\n\t\t\tif (Array.isArray(node.items)) {\n\t\t\t\tnode.items.forEach((item, index) => {\n\t\t\t\t\tresults.push(...findCoercionPaths(item, [...path, String(index)]));\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tresults.push(\n\t\t\t\t\t...findCoercionPaths(node.items, [...path, ARRAY_ITEM_MARKER]),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (const comb of [\"anyOf\", \"allOf\", \"oneOf\"]) {\n\t\tif (comb in node && Array.isArray(node[comb])) {\n\t\t\tfor (const branch of node[comb]) {\n\t\t\t\tresults.push(...findCoercionPaths(branch, path));\n\t\t\t}\n\t\t}\n\t}\n\n\tconst seen = new Set<string>();\n\treturn results.filter((t) => {\n\t\tconst key = t.path.join(\"/\") + \":\" + t.type;\n\t\treturn seen.has(key) ? false : seen.add(key);\n\t});\n};\n\n/**\n * Apply coercion to a data object based on identified paths.\n *\n * @param data The input environment data object to coerce\n * @param targets The coercion targets mapping paths to types\n * @param options The coercion options, including array parsing format\n * @returns The coerced data object\n */\nexport const applyCoercion = (\n\tdata: unknown,\n\ttargets: CoercionTarget[],\n\toptions: CoerceOptions = {},\n) => {\n\tconst { arrayFormat = \"comma\" } = options;\n\n\tconst splitString = (val: string) => {\n\t\tif (arrayFormat === \"json\") {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(val);\n\t\t\t} catch {\n\t\t\t\treturn val;\n\t\t\t}\n\t\t}\n\t\treturn val.trim() ? val.split(\",\").map((s) => s.trim()) : [];\n\t};\n\n\tconst coerceValue = (val: unknown, type: CoercionTarget[\"type\"]): unknown => {\n\t\tif (type === \"array\" && typeof val === \"string\") {\n\t\t\treturn splitString(val);\n\t\t}\n\t\tif (type === \"object\" && typeof val === \"string\") {\n\t\t\treturn coerceJson(val);\n\t\t}\n\t\tif (type === \"date\" && typeof val === \"string\") {\n\t\t\treturn coerceDate(val);\n\t\t}\n\t\tif (type === \"primitive\") {\n\t\t\tif (Array.isArray(val)) {\n\t\t\t\tfor (let i = 0; i < val.length; i++) {\n\t\t\t\t\tconst n = coerceNumber(val[i]);\n\t\t\t\t\tval[i] = typeof n === \"number\" ? n : coerceBoolean(val[i]);\n\t\t\t\t}\n\t\t\t\treturn val;\n\t\t\t}\n\t\t\tconst n = coerceNumber(val);\n\t\t\treturn typeof n === \"number\" ? n : coerceBoolean(val);\n\t\t}\n\t\treturn val;\n\t};\n\n\tif (typeof data !== \"object\" || data === null) {\n\t\tconst root = targets.find((t) => t.path.length === 0);\n\t\tif (root) {\n\t\t\treturn coerceValue(data, root.type);\n\t\t}\n\t\treturn data;\n\t}\n\n\tconst sorted = [...targets].sort((a, b) => a.path.length - b.path.length);\n\n\tconst walk = (current: any, path: string[], type: CoercionTarget[\"type\"]) => {\n\t\tif (!current || typeof current !== \"object\" || path.length === 0) return;\n\n\t\tconst [key, ...rest] = path;\n\n\t\tif (rest.length === 0) {\n\t\t\tif (key === 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\tcurrent[i] = coerceValue(current[i], type);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// biome-ignore lint/suspicious/noPrototypeBuiltins: Object.hasOwn is not supported under current tsconfig lib settings\n\t\t\t\tif (Object.prototype.hasOwnProperty.call(current, key)) {\n\t\t\t\t\tcurrent[key] = coerceValue(current[key], type);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (key === ARRAY_ITEM_MARKER) {\n\t\t\tif (Array.isArray(current)) {\n\t\t\t\tfor (const item of current) walk(item, rest, type);\n\t\t\t}\n\t\t} else {\n\t\t\twalk(current[key], rest, type);\n\t\t}\n\t};\n\n\tfor (const t of sorted) {\n\t\twalk(data, t.path, t.type);\n\t}\n\treturn data;\n};\n"],"mappings":"AAWA,MAAa,EAAgB,GAAe,CAE3C,GADI,OAAO,GAAM,UACb,OAAO,GAAM,UAAY,CAAC,EAAE,MAAM,CAAE,OAAO,EAC/C,GAAI,EAAE,MAAM,GAAK,MAAO,MAAO,KAC/B,IAAM,EAAI,OAAO,EAAE,CACnB,OAAO,OAAO,MAAM,EAAE,CAAG,EAAI,GAajB,EAAiB,GACzB,IAAM,OAAe,GACrB,IAAM,QAAgB,GACnB,EAaK,EAAc,GAAe,CACzC,GAAI,OAAO,GAAM,SAAU,OAAO,EAClC,IAAM,EAAU,EAAE,MAAM,CACxB,GAAI,EAAQ,KAAO,KAAO,EAAQ,KAAO,IAAK,OAAO,EACrD,GAAI,CACH,OAAO,KAAK,MAAM,EAAQ,MACnB,CACP,OAAO,IAeI,EAAc,GAAe,CAEzC,GADI,aAAa,MACb,OAAO,GAAM,UAAY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B,EAAI,GAAK,OAAO,GAAM,SAAW,EAAI,EAAc,EAAI,GAAG,CAE3D,OAAO,EAER,IAAM,EAAI,EAAa,EAAI,CAC3B,OAAO,OAAO,GAAM,SAAW,EAAI,EAAc,EAAI,CAEtD,OAAO,GAGR,GAAI,OAAO,GAAS,WAAY,EAAe,CAC9C,IAAM,EAAO,EAAQ,KAAM,GAAM,EAAE,KAAK,SAAW,EAAE,CAIrD,OAHI,EACI,EAAY,EAAM,EAAK,KAAK,CAE7B,EAGR,IAAM,EAAS,CAAC,GAAG,EAAQ,CAAC,MAAM,EAAG,IAAM,EAAE,KAAK,OAAS,EAAE,KAAK,OAAO,CAEnE,GAAQ,EAAc,EAAgB,IAAiC,CAC5E,GAAI,CAAC,GAAW,OAAO,GAAY,UAAY,EAAK,SAAW,EAAG,OAElE,GAAM,CAAC,EAAK,GAAG,GAAQ,EAEvB,GAAI,EAAK,SAAW,EAAG,CACtB,GAAI,IAAA,QACC,MAAM,QAAQ,EAAQ,CACzB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,OAAQ,IACnC,EAAQ,GAAK,EAAY,EAAQ,GAAI,EAAK,MAKxC,OAAO,UAAU,eAAe,KAAK,EAAS,EAAI,GACrD,EAAQ,GAAO,EAAY,EAAQ,GAAM,EAAK,EAGhD,OAGD,GAAI,IAAA,QACC,MAAM,QAAQ,EAAQ,CACzB,IAAK,IAAM,KAAQ,EAAS,EAAK,EAAM,EAAM,EAAK,MAGnD,EAAK,EAAQ,GAAM,EAAM,EAAK,EAIhC,IAAK,IAAM,KAAK,EACf,EAAK,EAAM,EAAE,KAAM,EAAE,KAAK,CAE3B,OAAO"}
|
package/dist/standard.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./core-Byznlywt.cjs`),t=require(`./shared-Sfv4WYag.cjs`);function n(t,n){if(typeof n==`string`)throw new e.t([{path:t,message:`ArkType DSL strings are not supported in "standard" mode. Use a Standard Schema validator (e.g., Zod, Valibot) or import from "arkenv" for ArkType schemas.`}])}function r(t,n){let r=n&&typeof n==`object`&&`~standard`in n&&n[`~standard`];if(!r||typeof r!=`object`||!(`validate`in r)||typeof r.validate!=`function`)throw new e.t([{path:t,message:`Invalid validator: expected a Standard Schema 1.0 validator (must have "~standard" property). Import from "arkenv" to use ArkType schemas.`}])}function i(t){if(!t||typeof t!=`object`||Array.isArray(t))throw new e.t([{path:``,message:`Invalid schema: expected an object mapping in "standard" mode.`}])}function a(e,t){let n={type:`object`,properties:{}},r=!1;for(let i in e){let a=e[i];if(!a){t.push(i);continue}let o=a[`~standard`];if(typeof o?.jsonSchema?.input==`function`)try{let e=o.jsonSchema.input({target:`draft-07`});if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.jsonSchema?.input==`function`)try{let e=a.jsonSchema.input({target:`draft-07`});if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.toJSONSchema==`function`)try{let e=a.toJSONSchema();if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.toStandardJSONSchema?.v1==`function`)try{let e=a.toStandardJSONSchema.v1();if(e){n.properties[i]=e,r=!0;continue}}catch{}t.push(i)}return{jsonSchema:n,hasJsonSchema:r}}function o(e,t){return!t||t.length===0?e:[e,...t.map(e=>typeof e==`object`&&e&&`key`in e?String(e.key):String(e))].join(`.`)}function s(n,r){let{env:i=process.env,onUndeclaredKey:s=`delete`,coerce:c=!0,arrayFormat:l=`comma`}=r,u={},d=[],f=new Set(Object.keys(i)),p={...i},m=[];if(c){let{jsonSchema:e,hasJsonSchema:r}=a(n,m);r&&(p=t.t(p,t.n(e),{arrayFormat:l}))}for(let t in n){let r=n[t],i=p[t];if(!r||typeof r!=`object`||!(`~standard`in r))throw new e.t([{path:t,message:`Invalid schema: expected a Standard Schema 1.0 validator (e.g. Zod, Valibot) in 'standard' mode.`}]);let a=r[`~standard`].validate(i);if(a instanceof Promise)throw new e.t([{path:t,message:`Async validation is not supported. ArkEnv is synchronous.`}]);if(a.issues)for(let e of a.issues){let n=o(t,e.path),r=e.message;c&&m.includes(t)&&(r+=` (Hint: coercion is enabled by default, but the validator for '${t}' lacks Standard JSON Schema support.)`),d.push({path:n,message:r})}else u[t]=a.value;f.delete(t)}if(s!==`delete`)for(let e of f)s===`reject`?d.push({path:e,message:`Undeclared key`}):s===`ignore`&&(u[e]=p[e]);if(d.length>0)throw new e.t(d);return u}function c(e,t){i(e);for(let t in e){let i=e[t];n(t,i),r(t,i)}return s(e,t??{})}const l=c;exports.createEnv=c,exports.default=l;
|
|
2
2
|
|
|
3
3
|
// CJS Interop Shim
|
|
4
4
|
if (module.exports && module.exports.default) {
|
package/dist/standard.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as StandardSchemaV1 } from "./index-
|
|
1
|
+
import { i as StandardSchemaV1 } from "./index-CzNfOanV.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/parse-standard.d.ts
|
|
4
4
|
/**
|
|
@@ -22,6 +22,24 @@ type ParseStandardConfig = {
|
|
|
22
22
|
* @default "delete"
|
|
23
23
|
*/
|
|
24
24
|
onUndeclaredKey?: "ignore" | "delete" | "reject";
|
|
25
|
+
/**
|
|
26
|
+
* Whether to perform best-effort coercion on the environment variables.
|
|
27
|
+
* Coercion requires validators that implement the StandardJSONSchemaV1 spec
|
|
28
|
+
* (e.g. Zod, Valibot).
|
|
29
|
+
*
|
|
30
|
+
* @see https://standard-schema.dev
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
coerce?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* The format to use for array parsing when coercion is enabled.
|
|
36
|
+
*
|
|
37
|
+
* - `comma` (default): Strings are split by comma and trimmed.
|
|
38
|
+
* - `json`: Strings are parsed as JSON.
|
|
39
|
+
*
|
|
40
|
+
* @default "comma"
|
|
41
|
+
*/
|
|
42
|
+
arrayFormat?: "comma" | "json";
|
|
25
43
|
};
|
|
26
44
|
//#endregion
|
|
27
45
|
//#region src/standard.d.ts
|
|
@@ -35,8 +53,8 @@ type StandardEnvConfig = ParseStandardConfig;
|
|
|
35
53
|
* This entry is ArkType-free - ArkType is never imported, even transitively.
|
|
36
54
|
* Use this when your project must not depend on ArkType.
|
|
37
55
|
*
|
|
38
|
-
* @param def
|
|
39
|
-
* @param config
|
|
56
|
+
* @param def An object mapping variable names to Standard Schema validators
|
|
57
|
+
* @param config Optional configuration
|
|
40
58
|
* @returns The validated environment variables
|
|
41
59
|
* @throws An {@link ArkEnvError} if validation fails
|
|
42
60
|
*
|
package/dist/standard.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard.d.cts","names":[],"sources":["../src/parse-standard.ts","../src/standard.ts"],"
|
|
1
|
+
{"version":3,"file":"standard.d.cts","names":[],"sources":["../src/parse-standard.ts","../src/standard.ts"],"mappings":";;;;;;KAOY,mBAAA;EAAmB;;;EAI9B,GAAA,GAAM,MAAA;EAAA;;;;;;;;;ACAP;;;EDaC,eAAA;ECbkD;AAwBnD;;;;;;;EDFC,MAAA;ECKiD;;;;;;;;EDIjD,WAAA;AAAA;;;;AAnCD;;KCIY,iBAAA,GAAoB,mBAAA;;;;;;;;;;;;AAAhC;;;;;AAwBA;;;;;;iBAAgB,SAAA,iBAA0B,MAAA,SAAe,gBAAA,EAAA,CACxD,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,iBAAA,iBACO,CAAA,GAAI,gBAAA,CAAiB,WAAA,CAAY,CAAA,CAAE,CAAA;;;;;;cAmB9C,MAAA,SAAM,SAAA"}
|
package/dist/standard.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as StandardSchemaV1 } from "./index-
|
|
1
|
+
import { i as StandardSchemaV1 } from "./index-Br22fqkz.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/parse-standard.d.ts
|
|
4
4
|
/**
|
|
@@ -22,6 +22,24 @@ type ParseStandardConfig = {
|
|
|
22
22
|
* @default "delete"
|
|
23
23
|
*/
|
|
24
24
|
onUndeclaredKey?: "ignore" | "delete" | "reject";
|
|
25
|
+
/**
|
|
26
|
+
* Whether to perform best-effort coercion on the environment variables.
|
|
27
|
+
* Coercion requires validators that implement the StandardJSONSchemaV1 spec
|
|
28
|
+
* (e.g. Zod, Valibot).
|
|
29
|
+
*
|
|
30
|
+
* @see https://standard-schema.dev
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
coerce?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* The format to use for array parsing when coercion is enabled.
|
|
36
|
+
*
|
|
37
|
+
* - `comma` (default): Strings are split by comma and trimmed.
|
|
38
|
+
* - `json`: Strings are parsed as JSON.
|
|
39
|
+
*
|
|
40
|
+
* @default "comma"
|
|
41
|
+
*/
|
|
42
|
+
arrayFormat?: "comma" | "json";
|
|
25
43
|
};
|
|
26
44
|
//#endregion
|
|
27
45
|
//#region src/standard.d.ts
|
|
@@ -35,8 +53,8 @@ type StandardEnvConfig = ParseStandardConfig;
|
|
|
35
53
|
* This entry is ArkType-free - ArkType is never imported, even transitively.
|
|
36
54
|
* Use this when your project must not depend on ArkType.
|
|
37
55
|
*
|
|
38
|
-
* @param def
|
|
39
|
-
* @param config
|
|
56
|
+
* @param def An object mapping variable names to Standard Schema validators
|
|
57
|
+
* @param config Optional configuration
|
|
40
58
|
* @returns The validated environment variables
|
|
41
59
|
* @throws An {@link ArkEnvError} if validation fails
|
|
42
60
|
*
|
package/dist/standard.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard.d.mts","names":[],"sources":["../src/parse-standard.ts","../src/standard.ts"],"
|
|
1
|
+
{"version":3,"file":"standard.d.mts","names":[],"sources":["../src/parse-standard.ts","../src/standard.ts"],"mappings":";;;;;;KAOY,mBAAA;EAAmB;;;EAI9B,GAAA,GAAM,MAAA;EAAA;;;;;;;;;ACAP;;;EDaC,eAAA;ECbkD;AAwBnD;;;;;;;EDFC,MAAA;ECKiD;;;;;;;;EDIjD,WAAA;AAAA;;;;AAnCD;;KCIY,iBAAA,GAAoB,mBAAA;;;;;;;;;;;;AAAhC;;;;;AAwBA;;;;;;iBAAgB,SAAA,iBAA0B,MAAA,SAAe,gBAAA,EAAA,CACxD,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,iBAAA,iBACO,CAAA,GAAI,gBAAA,CAAiB,WAAA,CAAY,CAAA,CAAE,CAAA;;;;;;cAmB9C,MAAA,SAAM,SAAA"}
|
package/dist/standard.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{t as e}from"./core-
|
|
1
|
+
import{t as e}from"./core-B51xxxje.mjs";import{n as t,t as n}from"./shared-_ck4b4vs.mjs";function r(t,n){if(typeof n==`string`)throw new e([{path:t,message:`ArkType DSL strings are not supported in "standard" mode. Use a Standard Schema validator (e.g., Zod, Valibot) or import from "arkenv" for ArkType schemas.`}])}function i(t,n){let r=n&&typeof n==`object`&&`~standard`in n&&n[`~standard`];if(!r||typeof r!=`object`||!(`validate`in r)||typeof r.validate!=`function`)throw new e([{path:t,message:`Invalid validator: expected a Standard Schema 1.0 validator (must have "~standard" property). Import from "arkenv" to use ArkType schemas.`}])}function a(t){if(!t||typeof t!=`object`||Array.isArray(t))throw new e([{path:``,message:`Invalid schema: expected an object mapping in "standard" mode.`}])}function o(e,t){let n={type:`object`,properties:{}},r=!1;for(let i in e){let a=e[i];if(!a){t.push(i);continue}let o=a[`~standard`];if(typeof o?.jsonSchema?.input==`function`)try{let e=o.jsonSchema.input({target:`draft-07`});if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.jsonSchema?.input==`function`)try{let e=a.jsonSchema.input({target:`draft-07`});if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.toJSONSchema==`function`)try{let e=a.toJSONSchema();if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.toStandardJSONSchema?.v1==`function`)try{let e=a.toStandardJSONSchema.v1();if(e){n.properties[i]=e,r=!0;continue}}catch{}t.push(i)}return{jsonSchema:n,hasJsonSchema:r}}function s(e,t){return!t||t.length===0?e:[e,...t.map(e=>typeof e==`object`&&e&&`key`in e?String(e.key):String(e))].join(`.`)}function c(r,i){let{env:a=process.env,onUndeclaredKey:c=`delete`,coerce:l=!0,arrayFormat:u=`comma`}=i,d={},f=[],p=new Set(Object.keys(a)),m={...a},h=[];if(l){let{jsonSchema:e,hasJsonSchema:i}=o(r,h);i&&(m=n(m,t(e),{arrayFormat:u}))}for(let t in r){let n=r[t],i=m[t];if(!n||typeof n!=`object`||!(`~standard`in n))throw new e([{path:t,message:`Invalid schema: expected a Standard Schema 1.0 validator (e.g. Zod, Valibot) in 'standard' mode.`}]);let a=n[`~standard`].validate(i);if(a instanceof Promise)throw new e([{path:t,message:`Async validation is not supported. ArkEnv is synchronous.`}]);if(a.issues)for(let e of a.issues){let n=s(t,e.path),r=e.message;l&&h.includes(t)&&(r+=` (Hint: coercion is enabled by default, but the validator for '${t}' lacks Standard JSON Schema support.)`),f.push({path:n,message:r})}else d[t]=a.value;p.delete(t)}if(c!==`delete`)for(let e of p)c===`reject`?f.push({path:e,message:`Undeclared key`}):c===`ignore`&&(d[e]=m[e]);if(f.length>0)throw new e(f);return d}function l(e,t){a(e);for(let t in e){let n=e[t];r(t,n),i(t,n)}return c(e,t??{})}const u=l;export{l as createEnv,u as default};
|
|
2
2
|
|
|
3
3
|
//# sourceMappingURL=standard.mjs.map
|