@arkenv/core 1.0.0-alpha.4 → 1.0.0-alpha.6
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/LICENSE +3 -0
- package/README.md +4 -4
- package/dist/index.cjs +474 -196
- package/dist/index.d.cts +192 -82
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +192 -82
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +472 -194
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -5937,43 +5937,110 @@ interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unk
|
|
|
5937
5937
|
}
|
|
5938
5938
|
type intersectObjects<l, r, piped extends boolean> = l extends array ? r extends array ? intersectArrays<l, r, MorphableIntersection<piped>> : // for an intersection with exactly one array operand like { name: string } & string[],
|
|
5939
5939
|
l & r : r extends array ? l & r : keyof l & keyof r extends never ? show<l & r> : show<{ [k in keyof l]: k extends keyof r ? _inferIntersection<l[k], r[k], piped> : l[k] } & { [k in keyof r]: k extends keyof l ? _inferIntersection<l[k], r[k], piped> : r[k] }>; //#endregion
|
|
5940
|
-
//#region
|
|
5940
|
+
//#region ../types/dist/standard-schema.d.ts
|
|
5941
5941
|
/**
|
|
5942
|
-
*
|
|
5942
|
+
* @see https://github.com/standard-schema/standard-schema/tree/3130ce43fdd848d9ab49dbb0458d04f18459961c/packages/spec
|
|
5943
5943
|
*
|
|
5944
|
-
*
|
|
5945
|
-
*
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
*
|
|
5949
|
-
* @returns The processed environment, the coerced environment, and any missing schema keys
|
|
5944
|
+
* Copied from standard-schema (MIT License)
|
|
5945
|
+
* Copyright (c) 2024 Colin McDannell
|
|
5946
|
+
*/
|
|
5947
|
+
/**
|
|
5948
|
+
* The Standard Typed interface. This is a base type extended by other specs.
|
|
5950
5949
|
*/
|
|
5951
5950
|
//#endregion
|
|
5952
5951
|
//#region src/core.d.ts
|
|
5953
5952
|
/**
|
|
5954
5953
|
* Machine-readable classification codes for environment validation issues.
|
|
5955
|
-
* Serves as the Source of Truth (SoT) for error categorization in ArkEnv.
|
|
5956
5954
|
*/
|
|
5957
|
-
type EnvIssueCode =
|
|
5955
|
+
type EnvIssueCode =
|
|
5956
|
+
/**
|
|
5957
|
+
* The environment variable is required but was not provided, and has no default value.
|
|
5958
|
+
*/
|
|
5959
|
+
"MISSING_VARIABLE"
|
|
5960
|
+
/**
|
|
5961
|
+
* The variable value failed a type assertion (e.g., expected a number or boolean but received a string).
|
|
5962
|
+
*/
|
|
5963
|
+
| "INVALID_TYPE"
|
|
5964
|
+
/**
|
|
5965
|
+
* The variable value falls below the minimum allowed numeric limit or string/array length constraint.
|
|
5966
|
+
*/
|
|
5967
|
+
| "VALUE_TOO_SMALL"
|
|
5968
|
+
/**
|
|
5969
|
+
* The variable value exceeds the maximum allowed numeric limit or string/array length constraint.
|
|
5970
|
+
*/
|
|
5971
|
+
| "VALUE_TOO_LARGE"
|
|
5972
|
+
/**
|
|
5973
|
+
* The variable value did not match the specified regular expression (regex) pattern constraint.
|
|
5974
|
+
*/
|
|
5975
|
+
| "PATTERN_MISMATCH"
|
|
5976
|
+
/**
|
|
5977
|
+
* The variable value is not in a valid format (e.g., failed email or UUID format validation).
|
|
5978
|
+
*/
|
|
5979
|
+
| "INVALID_FORMAT"
|
|
5980
|
+
/**
|
|
5981
|
+
* An undeclared key was found in the environment, and the schema config is set to reject undeclared keys.
|
|
5982
|
+
*/
|
|
5983
|
+
| "UNDECLARED_KEY"
|
|
5984
|
+
/**
|
|
5985
|
+
* The provided validation schema definition itself is malformed or invalid.
|
|
5986
|
+
*/
|
|
5987
|
+
| "INVALID_SCHEMA"
|
|
5988
|
+
/**
|
|
5989
|
+
* A validation error was triggered by a custom validator function or inline pipe logic.
|
|
5990
|
+
*/
|
|
5991
|
+
| "CUSTOM";
|
|
5958
5992
|
/**
|
|
5959
5993
|
* Metadata associated with an environment validation issue.
|
|
5960
5994
|
*/
|
|
5961
5995
|
type EnvIssueMeta = {
|
|
5962
|
-
/**
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5996
|
+
/**
|
|
5997
|
+
* The minimum expected boundary for numeric/string length constraints
|
|
5998
|
+
*/
|
|
5999
|
+
min?: number;
|
|
6000
|
+
/**
|
|
6001
|
+
* The maximum expected boundary for numeric/string length constraints
|
|
6002
|
+
*/
|
|
6003
|
+
max?: number;
|
|
6004
|
+
/**
|
|
6005
|
+
* Additional validation pattern/specifier details
|
|
6006
|
+
*/
|
|
6007
|
+
validation?: string;
|
|
6008
|
+
/**
|
|
6009
|
+
* Any custom constraint descriptions
|
|
6010
|
+
*/
|
|
6011
|
+
constraint?: string;
|
|
6012
|
+
/**
|
|
6013
|
+
* Traversal error occurred during JSON-parsing of the environment variable
|
|
6014
|
+
*/
|
|
5966
6015
|
traversalError?: string;
|
|
5967
6016
|
};
|
|
5968
6017
|
/**
|
|
5969
6018
|
* Normalized validation issue representing a failure on a specific environment variable.
|
|
5970
6019
|
*/
|
|
5971
6020
|
type EnvIssue = {
|
|
5972
|
-
/**
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
6021
|
+
/**
|
|
6022
|
+
* The dot-separated property path/name of the environment variable
|
|
6023
|
+
*/
|
|
6024
|
+
path: string;
|
|
6025
|
+
/**
|
|
6026
|
+
* The descriptive, user-friendly error message
|
|
6027
|
+
*/
|
|
6028
|
+
message: string;
|
|
6029
|
+
/**
|
|
6030
|
+
* The normalized classification code for the issue
|
|
6031
|
+
*/
|
|
6032
|
+
code: EnvIssueCode;
|
|
6033
|
+
/**
|
|
6034
|
+
* The expected type or value shape description
|
|
6035
|
+
*/
|
|
6036
|
+
expected?: string;
|
|
6037
|
+
/**
|
|
6038
|
+
* The raw value received (redacted in string formatting if sensitive)
|
|
6039
|
+
*/
|
|
6040
|
+
received?: unknown;
|
|
6041
|
+
/**
|
|
6042
|
+
* Additional validation metadata
|
|
6043
|
+
*/
|
|
5977
6044
|
meta?: EnvIssueMeta;
|
|
5978
6045
|
};
|
|
5979
6046
|
/**
|
|
@@ -5991,9 +6058,6 @@ declare function formatIssues(issues: EnvIssue[]): string;
|
|
|
5991
6058
|
*
|
|
5992
6059
|
* @example
|
|
5993
6060
|
* ```ts
|
|
5994
|
-
* import arkenv from 'arkenv';
|
|
5995
|
-
* import { ArkEnvError } from 'arkenv/core';
|
|
5996
|
-
*
|
|
5997
6061
|
* try {
|
|
5998
6062
|
* const env = arkenv({
|
|
5999
6063
|
* PORT: 'number.port',
|
|
@@ -6007,7 +6071,9 @@ declare function formatIssues(issues: EnvIssue[]): string;
|
|
|
6007
6071
|
* ```
|
|
6008
6072
|
*/
|
|
6009
6073
|
declare class ArkEnvError extends Error {
|
|
6010
|
-
/**
|
|
6074
|
+
/**
|
|
6075
|
+
* The list of normalized issues that caused the validation failure
|
|
6076
|
+
*/
|
|
6011
6077
|
readonly issues: EnvIssue[];
|
|
6012
6078
|
constructor(issues: EnvIssue[], message?: string);
|
|
6013
6079
|
}
|
|
@@ -6029,23 +6095,19 @@ type SafeArkEnvResult<T> = {
|
|
|
6029
6095
|
//#endregion
|
|
6030
6096
|
//#region src/schema.d.ts
|
|
6031
6097
|
/**
|
|
6032
|
-
* Extract the keys from a schema definition
|
|
6098
|
+
* Extract the keys from a schema definition.
|
|
6033
6099
|
* Supports plain objects, ArkType schemas, and Standard Schema validators.
|
|
6034
6100
|
*
|
|
6035
6101
|
* @param schema The schema definition to extract keys from
|
|
6036
6102
|
* @returns An array of extracted key names
|
|
6037
|
-
* @internal
|
|
6038
6103
|
*/
|
|
6039
6104
|
declare function getSchemaKeys(schema: any): string[]; //#endregion
|
|
6040
|
-
//#region src/
|
|
6105
|
+
//#region src/schema-capture.d.ts
|
|
6041
6106
|
/**
|
|
6042
|
-
*
|
|
6107
|
+
* Start recording `arkenv()` schema arguments instead of validating the environment.
|
|
6043
6108
|
*
|
|
6044
|
-
*
|
|
6045
|
-
*
|
|
6046
|
-
* @param receivedVal The raw value received by the validator
|
|
6047
|
-
* @returns The normalized EnvIssueCode classification
|
|
6048
|
-
* @internal
|
|
6109
|
+
* CLI-supporting API: tools such as the ArkEnv CLI use this to inspect a user's
|
|
6110
|
+
* schema module without requiring `process.env` to be populated.
|
|
6049
6111
|
*/
|
|
6050
6112
|
//#endregion
|
|
6051
6113
|
//#region ../internal/scope/dist/index.d.ts
|
|
@@ -6138,79 +6200,139 @@ type Dict<T> = Record<string, T | undefined>;
|
|
|
6138
6200
|
* Copied from standard-schema (MIT License)
|
|
6139
6201
|
* Copyright (c) 2024 Colin McDannell
|
|
6140
6202
|
*/
|
|
6141
|
-
/**
|
|
6203
|
+
/**
|
|
6204
|
+
* The Standard Typed interface. This is a base type extended by other specs.
|
|
6205
|
+
*/
|
|
6142
6206
|
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
6143
|
-
/**
|
|
6207
|
+
/**
|
|
6208
|
+
* The Standard properties.
|
|
6209
|
+
*/
|
|
6144
6210
|
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
|
6145
6211
|
}
|
|
6146
6212
|
declare namespace StandardTypedV1 {
|
|
6147
|
-
/**
|
|
6213
|
+
/**
|
|
6214
|
+
* The Standard Typed properties interface.
|
|
6215
|
+
*/
|
|
6148
6216
|
interface Props<Input = unknown, Output = Input> {
|
|
6149
|
-
/**
|
|
6217
|
+
/**
|
|
6218
|
+
* The version number of the standard.
|
|
6219
|
+
*/
|
|
6150
6220
|
readonly version: 1;
|
|
6151
|
-
/**
|
|
6221
|
+
/**
|
|
6222
|
+
* The vendor name of the schema library.
|
|
6223
|
+
*/
|
|
6152
6224
|
readonly vendor: string;
|
|
6153
|
-
/**
|
|
6225
|
+
/**
|
|
6226
|
+
* Inferred types associated with the schema.
|
|
6227
|
+
*/
|
|
6154
6228
|
readonly types?: Types<Input, Output> | undefined;
|
|
6155
6229
|
}
|
|
6156
|
-
/**
|
|
6230
|
+
/**
|
|
6231
|
+
* The Standard Typed types interface.
|
|
6232
|
+
*/
|
|
6157
6233
|
interface Types<Input = unknown, Output = Input> {
|
|
6158
|
-
/**
|
|
6234
|
+
/**
|
|
6235
|
+
* The input type of the schema.
|
|
6236
|
+
*/
|
|
6159
6237
|
readonly input: Input;
|
|
6160
|
-
/**
|
|
6238
|
+
/**
|
|
6239
|
+
* The output type of the schema.
|
|
6240
|
+
*/
|
|
6161
6241
|
readonly output: Output;
|
|
6162
6242
|
}
|
|
6163
|
-
/**
|
|
6243
|
+
/**
|
|
6244
|
+
* Infers the input type of a Standard Typed.
|
|
6245
|
+
*/
|
|
6164
6246
|
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
6165
|
-
/**
|
|
6247
|
+
/**
|
|
6248
|
+
* Infers the output type of a Standard Typed.
|
|
6249
|
+
*/
|
|
6166
6250
|
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
6167
6251
|
}
|
|
6168
|
-
/**
|
|
6252
|
+
/**
|
|
6253
|
+
* The Standard Schema interface.
|
|
6254
|
+
*/
|
|
6169
6255
|
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
6170
|
-
/**
|
|
6256
|
+
/**
|
|
6257
|
+
* The Standard Schema properties.
|
|
6258
|
+
*/
|
|
6171
6259
|
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
6172
6260
|
}
|
|
6173
6261
|
declare namespace StandardSchemaV1 {
|
|
6174
|
-
/**
|
|
6262
|
+
/**
|
|
6263
|
+
* The Standard Schema properties interface.
|
|
6264
|
+
*/
|
|
6175
6265
|
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
6176
|
-
/**
|
|
6266
|
+
/**
|
|
6267
|
+
* Validates unknown input values.
|
|
6268
|
+
*/
|
|
6177
6269
|
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
6178
6270
|
}
|
|
6179
|
-
/**
|
|
6271
|
+
/**
|
|
6272
|
+
* The result interface of the validate function.
|
|
6273
|
+
*/
|
|
6180
6274
|
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
6181
|
-
/**
|
|
6275
|
+
/**
|
|
6276
|
+
* The result interface if validation succeeds.
|
|
6277
|
+
*/
|
|
6182
6278
|
interface SuccessResult<Output> {
|
|
6183
|
-
/**
|
|
6279
|
+
/**
|
|
6280
|
+
* The typed output value.
|
|
6281
|
+
*/
|
|
6184
6282
|
readonly value: Output;
|
|
6185
|
-
/**
|
|
6283
|
+
/**
|
|
6284
|
+
* A falsy value for `issues` indicates success.
|
|
6285
|
+
*/
|
|
6186
6286
|
readonly issues?: undefined;
|
|
6187
6287
|
}
|
|
6188
6288
|
interface Options {
|
|
6189
|
-
/**
|
|
6289
|
+
/**
|
|
6290
|
+
* Explicit support for additional vendor-specific parameters, if needed.
|
|
6291
|
+
*/
|
|
6190
6292
|
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
6191
6293
|
}
|
|
6192
|
-
/**
|
|
6294
|
+
/**
|
|
6295
|
+
* The result interface if validation fails.
|
|
6296
|
+
*/
|
|
6193
6297
|
interface FailureResult {
|
|
6194
|
-
/**
|
|
6298
|
+
/**
|
|
6299
|
+
* The issues of failed validation.
|
|
6300
|
+
*/
|
|
6195
6301
|
readonly issues: ReadonlyArray<Issue>;
|
|
6196
6302
|
}
|
|
6197
|
-
/**
|
|
6303
|
+
/**
|
|
6304
|
+
* The issue interface of the failure output.
|
|
6305
|
+
*/
|
|
6198
6306
|
interface Issue {
|
|
6199
|
-
/**
|
|
6307
|
+
/**
|
|
6308
|
+
* The error message of the issue.
|
|
6309
|
+
*/
|
|
6200
6310
|
readonly message: string;
|
|
6201
|
-
/**
|
|
6311
|
+
/**
|
|
6312
|
+
* The path of the issue, if any.
|
|
6313
|
+
*/
|
|
6202
6314
|
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
6203
6315
|
}
|
|
6204
|
-
/**
|
|
6316
|
+
/**
|
|
6317
|
+
* The path segment interface of the issue.
|
|
6318
|
+
*/
|
|
6205
6319
|
interface PathSegment {
|
|
6206
|
-
/**
|
|
6320
|
+
/**
|
|
6321
|
+
* The key representing a path segment.
|
|
6322
|
+
*/
|
|
6207
6323
|
readonly key: PropertyKey;
|
|
6208
6324
|
}
|
|
6209
|
-
/**
|
|
6325
|
+
/**
|
|
6326
|
+
* The Standard types interface.
|
|
6327
|
+
*/
|
|
6210
6328
|
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
|
|
6211
|
-
/**
|
|
6329
|
+
/**
|
|
6330
|
+
* Infers the input type of a Standard.
|
|
6331
|
+
*/
|
|
6212
6332
|
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
6213
|
-
/**
|
|
6333
|
+
/**
|
|
6334
|
+
* Infers the output type of a Standard.
|
|
6335
|
+
*/
|
|
6214
6336
|
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
6215
6337
|
}
|
|
6216
6338
|
//#endregion
|
|
@@ -6248,14 +6370,8 @@ type CompiledEnvSchema = Type<SchemaShape, $$1>;
|
|
|
6248
6370
|
/**
|
|
6249
6371
|
* Declarative environment schema definition accepted by ArkEnv.
|
|
6250
6372
|
*
|
|
6251
|
-
*
|
|
6252
|
-
*
|
|
6253
|
-
* or Standard Schema validators).
|
|
6254
|
-
*
|
|
6255
|
-
* This type is used to validate that a schema object is compatible with
|
|
6256
|
-
* ArkEnv’s validator scope before being compiled or parsed.
|
|
6257
|
-
*
|
|
6258
|
-
* Most users will provide schemas in this form.
|
|
6373
|
+
* Maps environment variable names to schema definitions (e.g. ArkType DSL
|
|
6374
|
+
* strings or Standard Schema validators).
|
|
6259
6375
|
*
|
|
6260
6376
|
* @template def - The schema shape object
|
|
6261
6377
|
*/
|
|
@@ -6286,12 +6402,10 @@ type ArkEnvConfig = {
|
|
|
6286
6402
|
/**
|
|
6287
6403
|
* Control how ArkEnv handles environment variables that are not defined in your schema.
|
|
6288
6404
|
*
|
|
6289
|
-
* Defaults to `'delete'`
|
|
6290
|
-
* keys you've explicitly declared. This differs from ArkType's standard behavior, which
|
|
6291
|
-
* mirrors TypeScript by defaulting to `'ignore'`.
|
|
6405
|
+
* Defaults to `'delete'` so the output object only contains keys you've declared.
|
|
6292
6406
|
*
|
|
6293
|
-
* - `delete` (
|
|
6294
|
-
* - `ignore
|
|
6407
|
+
* - `delete` (default): Undeclared keys are allowed on input but stripped from the output.
|
|
6408
|
+
* - `ignore`: Undeclared keys are allowed and preserved in the output.
|
|
6295
6409
|
* - `reject`: Undeclared keys will cause validation to fail.
|
|
6296
6410
|
*
|
|
6297
6411
|
* @default "delete"
|
|
@@ -6332,19 +6446,15 @@ type ArkEnvConfig = {
|
|
|
6332
6446
|
safe?: boolean;
|
|
6333
6447
|
};
|
|
6334
6448
|
/**
|
|
6335
|
-
*
|
|
6449
|
+
* Parsed environment object inferred from an EnvSchema or CompiledEnvSchema.
|
|
6336
6450
|
*/
|
|
6337
6451
|
type ArkenvOutput<T extends SchemaShape, D> = distill.Out<type$1.infer<T, $$1>> | InferType<D>;
|
|
6338
6452
|
/**
|
|
6339
|
-
*
|
|
6340
|
-
*
|
|
6341
|
-
* Naming convention: the main function is lowercase (`arkenv`) following the
|
|
6342
|
-
* JavaScript convention for functions (e.g. `zod`, `joi`). Classes and types
|
|
6343
|
-
* use PascalCase with the full product name (`ArkEnvError`, `SafeArkEnvResult`).
|
|
6453
|
+
* Parse and validate environment variables using ArkType or Standard Schema.
|
|
6344
6454
|
*
|
|
6345
6455
|
* @param def The schema definition
|
|
6346
6456
|
* @param config The evaluation configuration
|
|
6347
|
-
* @returns The parsed environment variables,
|
|
6457
|
+
* @returns The parsed environment variables, a SafeArkEnvResult if `{ safe: true }` is configured, or a value-less stub when schema capture is active
|
|
6348
6458
|
* @throws An {@link ArkEnvError | error} if the environment variables are invalid and `safe` is not enabled
|
|
6349
6459
|
*/
|
|
6350
6460
|
declare function arkenv<const T extends SchemaShape>(def: EnvSchema<T>, config?: ArkEnvConfig & {
|