@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/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 src/coercion/environment.d.ts
5940
+ //#region ../types/dist/standard-schema.d.ts
5941
5941
  /**
5942
- * Prepare an environment record by optionally stripping empty strings and applying coercion.
5942
+ * @see https://github.com/standard-schema/standard-schema/tree/3130ce43fdd848d9ab49dbb0458d04f18459961c/packages/spec
5943
5943
  *
5944
- * @param env The raw environment variables
5945
- * @param emptyAsUndefined Whether to strip empty string values before processing
5946
- * @param arrayFormat The format to use for array coercion
5947
- * @param getSchema Optional callback that returns a JSON Schema and whether it exists,
5948
- * used to determine coercion targets. When omitted, no coercion is performed.
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 = /** The environment variable is required but was not provided, and has no default value. */"MISSING_VARIABLE" /** The variable value failed a type assertion (e.g., expected a number or boolean but received a string). */ | "INVALID_TYPE" /** The variable value falls below the minimum allowed numeric limit or string/array length constraint. */ | "VALUE_TOO_SMALL" /** The variable value exceeds the maximum allowed numeric limit or string/array length constraint. */ | "VALUE_TOO_LARGE" /** The variable value did not match the specified regular expression (regex) pattern constraint. */ | "PATTERN_MISMATCH" /** The variable value is not in a valid format (e.g., failed email or UUID format validation). */ | "INVALID_FORMAT" /** An undeclared key was found in the environment, and the schema config is set to reject undeclared keys. */ | "UNDECLARED_KEY" /** The provided validation schema definition itself is malformed or invalid. */ | "INVALID_SCHEMA" /** A validation error was triggered by a custom validator function or inline pipe logic. */ | "CUSTOM";
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
- /** The minimum expected boundary for numeric/string length constraints */min?: number; /** The maximum expected boundary for numeric/string length constraints */
5963
- max?: number; /** Additional validation pattern/specifier details */
5964
- validation?: string; /** Any custom constraint descriptions */
5965
- constraint?: string; /** Traversal error occurred during JSON-parsing of the environment variable */
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
- /** The dot-separated property path/name of the environment variable */path: string; /** The descriptive, user-friendly error message */
5973
- message: string; /** The normalized classification code for the issue */
5974
- code: EnvIssueCode; /** The expected type or value shape description */
5975
- expected?: string; /** The raw value received (redacted in string formatting if sensitive) */
5976
- received?: unknown; /** Additional validation metadata */
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
- /** The list of normalized issues that caused the validation failure */
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 dynamically.
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/utils/errors.d.ts
6105
+ //#region src/schema-capture.d.ts
6041
6106
  /**
6042
- * Map a Standard Schema validation issue to a normalized EnvIssueCode.
6107
+ * Start recording `arkenv()` schema arguments instead of validating the environment.
6043
6108
  *
6044
- * @param engineCode The raw issue code from the Standard Schema engine
6045
- * @param message The error message associated with the issue
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
- /** The Standard Typed interface. This is a base type extended by other specs. */
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
- /** The Standard properties. */
6207
+ /**
6208
+ * The Standard properties.
6209
+ */
6144
6210
  readonly "~standard": StandardTypedV1.Props<Input, Output>;
6145
6211
  }
6146
6212
  declare namespace StandardTypedV1 {
6147
- /** The Standard Typed properties interface. */
6213
+ /**
6214
+ * The Standard Typed properties interface.
6215
+ */
6148
6216
  interface Props<Input = unknown, Output = Input> {
6149
- /** The version number of the standard. */
6217
+ /**
6218
+ * The version number of the standard.
6219
+ */
6150
6220
  readonly version: 1;
6151
- /** The vendor name of the schema library. */
6221
+ /**
6222
+ * The vendor name of the schema library.
6223
+ */
6152
6224
  readonly vendor: string;
6153
- /** Inferred types associated with the schema. */
6225
+ /**
6226
+ * Inferred types associated with the schema.
6227
+ */
6154
6228
  readonly types?: Types<Input, Output> | undefined;
6155
6229
  }
6156
- /** The Standard Typed types interface. */
6230
+ /**
6231
+ * The Standard Typed types interface.
6232
+ */
6157
6233
  interface Types<Input = unknown, Output = Input> {
6158
- /** The input type of the schema. */
6234
+ /**
6235
+ * The input type of the schema.
6236
+ */
6159
6237
  readonly input: Input;
6160
- /** The output type of the schema. */
6238
+ /**
6239
+ * The output type of the schema.
6240
+ */
6161
6241
  readonly output: Output;
6162
6242
  }
6163
- /** Infers the input type of a Standard Typed. */
6243
+ /**
6244
+ * Infers the input type of a Standard Typed.
6245
+ */
6164
6246
  type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
6165
- /** Infers the output type of a Standard Typed. */
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
- /** The Standard Schema interface. */
6252
+ /**
6253
+ * The Standard Schema interface.
6254
+ */
6169
6255
  interface StandardSchemaV1<Input = unknown, Output = Input> {
6170
- /** The Standard Schema properties. */
6256
+ /**
6257
+ * The Standard Schema properties.
6258
+ */
6171
6259
  readonly "~standard": StandardSchemaV1.Props<Input, Output>;
6172
6260
  }
6173
6261
  declare namespace StandardSchemaV1 {
6174
- /** The Standard Schema properties interface. */
6262
+ /**
6263
+ * The Standard Schema properties interface.
6264
+ */
6175
6265
  interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
6176
- /** Validates unknown input values. */
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
- /** The result interface of the validate function. */
6271
+ /**
6272
+ * The result interface of the validate function.
6273
+ */
6180
6274
  type Result<Output> = SuccessResult<Output> | FailureResult;
6181
- /** The result interface if validation succeeds. */
6275
+ /**
6276
+ * The result interface if validation succeeds.
6277
+ */
6182
6278
  interface SuccessResult<Output> {
6183
- /** The typed output value. */
6279
+ /**
6280
+ * The typed output value.
6281
+ */
6184
6282
  readonly value: Output;
6185
- /** A falsy value for `issues` indicates success. */
6283
+ /**
6284
+ * A falsy value for `issues` indicates success.
6285
+ */
6186
6286
  readonly issues?: undefined;
6187
6287
  }
6188
6288
  interface Options {
6189
- /** Explicit support for additional vendor-specific parameters, if needed. */
6289
+ /**
6290
+ * Explicit support for additional vendor-specific parameters, if needed.
6291
+ */
6190
6292
  readonly libraryOptions?: Record<string, unknown> | undefined;
6191
6293
  }
6192
- /** The result interface if validation fails. */
6294
+ /**
6295
+ * The result interface if validation fails.
6296
+ */
6193
6297
  interface FailureResult {
6194
- /** The issues of failed validation. */
6298
+ /**
6299
+ * The issues of failed validation.
6300
+ */
6195
6301
  readonly issues: ReadonlyArray<Issue>;
6196
6302
  }
6197
- /** The issue interface of the failure output. */
6303
+ /**
6304
+ * The issue interface of the failure output.
6305
+ */
6198
6306
  interface Issue {
6199
- /** The error message of the issue. */
6307
+ /**
6308
+ * The error message of the issue.
6309
+ */
6200
6310
  readonly message: string;
6201
- /** The path of the issue, if any. */
6311
+ /**
6312
+ * The path of the issue, if any.
6313
+ */
6202
6314
  readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
6203
6315
  }
6204
- /** The path segment interface of the issue. */
6316
+ /**
6317
+ * The path segment interface of the issue.
6318
+ */
6205
6319
  interface PathSegment {
6206
- /** The key representing a path segment. */
6320
+ /**
6321
+ * The key representing a path segment.
6322
+ */
6207
6323
  readonly key: PropertyKey;
6208
6324
  }
6209
- /** The Standard types interface. */
6325
+ /**
6326
+ * The Standard types interface.
6327
+ */
6210
6328
  interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
6211
- /** Infers the input type of a Standard. */
6329
+ /**
6330
+ * Infers the input type of a Standard.
6331
+ */
6212
6332
  type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
6213
- /** Infers the output type of a Standard. */
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
- * Represents a declarative schema object mapping environment
6252
- * variable names to schema definitions (e.g. ArkType DSL strings
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'` to ensure your output object only contains
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` (ArkEnv default): Undeclared keys are allowed on input but stripped from the output.
6294
- * - `ignore` (ArkType default): Undeclared keys are allowed and preserved in the output.
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
- * Helper type to represent the output of parsing either an EnvSchema or CompiledEnvSchema.
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
- * Utility to parse environment variables using ArkType or Standard Schema
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, or a SafeArkEnvResult if `{ safe: true }` is configured
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 & {