@arkenv/core 1.0.0-alpha.3 → 1.0.0-alpha.5

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,12 +6095,11 @@ 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
6105
  //#region src/utils/errors.d.ts
@@ -6138,79 +6203,139 @@ type Dict<T> = Record<string, T | undefined>;
6138
6203
  * Copied from standard-schema (MIT License)
6139
6204
  * Copyright (c) 2024 Colin McDannell
6140
6205
  */
6141
- /** The Standard Typed interface. This is a base type extended by other specs. */
6206
+ /**
6207
+ * The Standard Typed interface. This is a base type extended by other specs.
6208
+ */
6142
6209
  interface StandardTypedV1<Input = unknown, Output = Input> {
6143
- /** The Standard properties. */
6210
+ /**
6211
+ * The Standard properties.
6212
+ */
6144
6213
  readonly "~standard": StandardTypedV1.Props<Input, Output>;
6145
6214
  }
6146
6215
  declare namespace StandardTypedV1 {
6147
- /** The Standard Typed properties interface. */
6216
+ /**
6217
+ * The Standard Typed properties interface.
6218
+ */
6148
6219
  interface Props<Input = unknown, Output = Input> {
6149
- /** The version number of the standard. */
6220
+ /**
6221
+ * The version number of the standard.
6222
+ */
6150
6223
  readonly version: 1;
6151
- /** The vendor name of the schema library. */
6224
+ /**
6225
+ * The vendor name of the schema library.
6226
+ */
6152
6227
  readonly vendor: string;
6153
- /** Inferred types associated with the schema. */
6228
+ /**
6229
+ * Inferred types associated with the schema.
6230
+ */
6154
6231
  readonly types?: Types<Input, Output> | undefined;
6155
6232
  }
6156
- /** The Standard Typed types interface. */
6233
+ /**
6234
+ * The Standard Typed types interface.
6235
+ */
6157
6236
  interface Types<Input = unknown, Output = Input> {
6158
- /** The input type of the schema. */
6237
+ /**
6238
+ * The input type of the schema.
6239
+ */
6159
6240
  readonly input: Input;
6160
- /** The output type of the schema. */
6241
+ /**
6242
+ * The output type of the schema.
6243
+ */
6161
6244
  readonly output: Output;
6162
6245
  }
6163
- /** Infers the input type of a Standard Typed. */
6246
+ /**
6247
+ * Infers the input type of a Standard Typed.
6248
+ */
6164
6249
  type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
6165
- /** Infers the output type of a Standard Typed. */
6250
+ /**
6251
+ * Infers the output type of a Standard Typed.
6252
+ */
6166
6253
  type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
6167
6254
  }
6168
- /** The Standard Schema interface. */
6255
+ /**
6256
+ * The Standard Schema interface.
6257
+ */
6169
6258
  interface StandardSchemaV1<Input = unknown, Output = Input> {
6170
- /** The Standard Schema properties. */
6259
+ /**
6260
+ * The Standard Schema properties.
6261
+ */
6171
6262
  readonly "~standard": StandardSchemaV1.Props<Input, Output>;
6172
6263
  }
6173
6264
  declare namespace StandardSchemaV1 {
6174
- /** The Standard Schema properties interface. */
6265
+ /**
6266
+ * The Standard Schema properties interface.
6267
+ */
6175
6268
  interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
6176
- /** Validates unknown input values. */
6269
+ /**
6270
+ * Validates unknown input values.
6271
+ */
6177
6272
  readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
6178
6273
  }
6179
- /** The result interface of the validate function. */
6274
+ /**
6275
+ * The result interface of the validate function.
6276
+ */
6180
6277
  type Result<Output> = SuccessResult<Output> | FailureResult;
6181
- /** The result interface if validation succeeds. */
6278
+ /**
6279
+ * The result interface if validation succeeds.
6280
+ */
6182
6281
  interface SuccessResult<Output> {
6183
- /** The typed output value. */
6282
+ /**
6283
+ * The typed output value.
6284
+ */
6184
6285
  readonly value: Output;
6185
- /** A falsy value for `issues` indicates success. */
6286
+ /**
6287
+ * A falsy value for `issues` indicates success.
6288
+ */
6186
6289
  readonly issues?: undefined;
6187
6290
  }
6188
6291
  interface Options {
6189
- /** Explicit support for additional vendor-specific parameters, if needed. */
6292
+ /**
6293
+ * Explicit support for additional vendor-specific parameters, if needed.
6294
+ */
6190
6295
  readonly libraryOptions?: Record<string, unknown> | undefined;
6191
6296
  }
6192
- /** The result interface if validation fails. */
6297
+ /**
6298
+ * The result interface if validation fails.
6299
+ */
6193
6300
  interface FailureResult {
6194
- /** The issues of failed validation. */
6301
+ /**
6302
+ * The issues of failed validation.
6303
+ */
6195
6304
  readonly issues: ReadonlyArray<Issue>;
6196
6305
  }
6197
- /** The issue interface of the failure output. */
6306
+ /**
6307
+ * The issue interface of the failure output.
6308
+ */
6198
6309
  interface Issue {
6199
- /** The error message of the issue. */
6310
+ /**
6311
+ * The error message of the issue.
6312
+ */
6200
6313
  readonly message: string;
6201
- /** The path of the issue, if any. */
6314
+ /**
6315
+ * The path of the issue, if any.
6316
+ */
6202
6317
  readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
6203
6318
  }
6204
- /** The path segment interface of the issue. */
6319
+ /**
6320
+ * The path segment interface of the issue.
6321
+ */
6205
6322
  interface PathSegment {
6206
- /** The key representing a path segment. */
6323
+ /**
6324
+ * The key representing a path segment.
6325
+ */
6207
6326
  readonly key: PropertyKey;
6208
6327
  }
6209
- /** The Standard types interface. */
6328
+ /**
6329
+ * The Standard types interface.
6330
+ */
6210
6331
  interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
6211
- /** Infers the input type of a Standard. */
6332
+ /**
6333
+ * Infers the input type of a Standard.
6334
+ */
6212
6335
  type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
6213
- /** Infers the output type of a Standard. */
6336
+ /**
6337
+ * Infers the output type of a Standard.
6338
+ */
6214
6339
  type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
6215
6340
  }
6216
6341
  //#endregion
@@ -6248,14 +6373,8 @@ type CompiledEnvSchema = Type<SchemaShape, $$1>;
6248
6373
  /**
6249
6374
  * Declarative environment schema definition accepted by ArkEnv.
6250
6375
  *
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.
6376
+ * Maps environment variable names to schema definitions (e.g. ArkType DSL
6377
+ * strings or Standard Schema validators).
6259
6378
  *
6260
6379
  * @template def - The schema shape object
6261
6380
  */
@@ -6269,21 +6388,16 @@ type EnvSchema<def> = type$1.validate<def, $$1>;
6269
6388
  type Infer<T> = T extends StandardSchemaV1<infer _Input, infer Output> ? Output : T extends {
6270
6389
  t: infer U;
6271
6390
  } ? U : T extends type$1.Any<infer U, infer _Scope> ? U : T extends SchemaShape ? distill.Out<type$1.infer<T, $$1>> : InferType<T>;
6272
- /**
6273
- * The environment variables passed to `arkenv`.
6274
- * Uses `Dict<string>` to enforce
6275
- * compile-time safety: all input environment variables must be strings
6276
- * (or undefined), matching `process.env` semantics.
6277
- */
6278
- type RuntimeEnvironment = Dict<string>;
6279
6391
  /**
6280
6392
  * Configuration options for `arkenv`
6281
6393
  */
6282
6394
  type ArkEnvConfig = {
6283
6395
  /**
6284
- * The environment variables to parse. Defaults to `process.env`
6396
+ * The environment variables to parse. Defaults to `process.env`.
6397
+ *
6398
+ * All values must be strings (or `undefined`) to match `process.env` semantics.
6285
6399
  */
6286
- env?: RuntimeEnvironment;
6400
+ env?: Record<string, string | undefined>;
6287
6401
  /**
6288
6402
  * Whether to coerce environment variables to their defined types. Defaults to `true`
6289
6403
  */
@@ -6291,12 +6405,10 @@ type ArkEnvConfig = {
6291
6405
  /**
6292
6406
  * Control how ArkEnv handles environment variables that are not defined in your schema.
6293
6407
  *
6294
- * Defaults to `'delete'` to ensure your output object only contains
6295
- * keys you've explicitly declared. This differs from ArkType's standard behavior, which
6296
- * mirrors TypeScript by defaulting to `'ignore'`.
6408
+ * Defaults to `'delete'` so the output object only contains keys you've declared.
6297
6409
  *
6298
- * - `delete` (ArkEnv default): Undeclared keys are allowed on input but stripped from the output.
6299
- * - `ignore` (ArkType default): Undeclared keys are allowed and preserved in the output.
6410
+ * - `delete` (default): Undeclared keys are allowed on input but stripped from the output.
6411
+ * - `ignore`: Undeclared keys are allowed and preserved in the output.
6300
6412
  * - `reject`: Undeclared keys will cause validation to fail.
6301
6413
  *
6302
6414
  * @default "delete"
@@ -6337,15 +6449,11 @@ type ArkEnvConfig = {
6337
6449
  safe?: boolean;
6338
6450
  };
6339
6451
  /**
6340
- * Helper type to represent the output of parsing either an EnvSchema or CompiledEnvSchema.
6452
+ * Parsed environment object inferred from an EnvSchema or CompiledEnvSchema.
6341
6453
  */
6342
6454
  type ArkenvOutput<T extends SchemaShape, D> = distill.Out<type$1.infer<T, $$1>> | InferType<D>;
6343
6455
  /**
6344
- * Utility to parse environment variables using ArkType or Standard Schema
6345
- *
6346
- * Naming convention: the main function is lowercase (`arkenv`) following the
6347
- * JavaScript convention for functions (e.g. `zod`, `joi`). Classes and types
6348
- * use PascalCase with the full product name (`ArkEnvError`, `SafeArkEnvResult`).
6456
+ * Parse and validate environment variables using ArkType or Standard Schema.
6349
6457
  *
6350
6458
  * @param def The schema definition
6351
6459
  * @param config The evaluation configuration