envapt 8.2.0 → 8.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/CHANGELOG.md +12 -15
  2. package/dist/node/config.cjs.map +1 -1
  3. package/dist/node/config.mjs.map +1 -1
  4. package/dist/node/converters/BuiltInConverters.cjs.map +1 -1
  5. package/dist/node/converters/BuiltInConverters.mjs.map +1 -1
  6. package/dist/node/converters/Converters.cjs.map +1 -1
  7. package/dist/node/converters/Converters.mjs.map +1 -1
  8. package/dist/node/converters/ListOfBuiltInConverters.cjs.map +1 -1
  9. package/dist/node/converters/ListOfBuiltInConverters.mjs.map +1 -1
  10. package/dist/node/converters/ValueConverter.cjs.map +1 -1
  11. package/dist/node/converters/ValueConverter.mjs.map +1 -1
  12. package/dist/node/core/AdvancedMethods.cjs.map +1 -1
  13. package/dist/node/core/AdvancedMethods.mjs.map +1 -1
  14. package/dist/node/core/EnvapterBase.cjs.map +1 -1
  15. package/dist/node/core/EnvapterBase.mjs.map +1 -1
  16. package/dist/node/core/EnvironmentMethods.cjs.map +1 -1
  17. package/dist/node/core/EnvironmentMethods.mjs.map +1 -1
  18. package/dist/node/core/PrimitiveMethods.cjs.map +1 -1
  19. package/dist/node/core/PrimitiveMethods.mjs.map +1 -1
  20. package/dist/node/core/engine.cjs.map +1 -1
  21. package/dist/node/core/engine.mjs.map +1 -1
  22. package/dist/node/core/missing.cjs.map +1 -1
  23. package/dist/node/core/missing.mjs.map +1 -1
  24. package/dist/node/core/paths.cjs.map +1 -1
  25. package/dist/node/core/paths.mjs.map +1 -1
  26. package/dist/node/core/state.cjs.map +1 -1
  27. package/dist/node/core/state.mjs.map +1 -1
  28. package/dist/node/decorators/legacy/Envapt.cjs.map +1 -1
  29. package/dist/node/decorators/legacy/Envapt.mjs.map +1 -1
  30. package/dist/node/decorators/legacy/SugarDecorators.cjs.map +1 -1
  31. package/dist/node/decorators/legacy/SugarDecorators.mjs.map +1 -1
  32. package/dist/node/decorators/modern/Envapt.cjs.map +1 -1
  33. package/dist/node/decorators/modern/Envapt.mjs.map +1 -1
  34. package/dist/node/decorators/modern/SugarDecorators.cjs.map +1 -1
  35. package/dist/node/decorators/modern/SugarDecorators.mjs.map +1 -1
  36. package/dist/node/decorators/modern/createAccessorDecorator.cjs.map +1 -1
  37. package/dist/node/decorators/modern/createAccessorDecorator.mjs.map +1 -1
  38. package/dist/node/decorators/resolveDecoratorValue.cjs.map +1 -1
  39. package/dist/node/decorators/resolveDecoratorValue.mjs.map +1 -1
  40. package/dist/node/engine/Envapter.cjs.map +1 -1
  41. package/dist/node/engine/Envapter.mjs.map +1 -1
  42. package/dist/node/engine/NodeEnvapter.cjs.map +1 -1
  43. package/dist/node/engine/NodeEnvapter.mjs.map +1 -1
  44. package/dist/node/engine/TemplateResolver.cjs.map +1 -1
  45. package/dist/node/engine/TemplateResolver.mjs.map +1 -1
  46. package/dist/node/engine/Validators.cjs.map +1 -1
  47. package/dist/node/engine/Validators.mjs.map +1 -1
  48. package/dist/node/infra/Debug.cjs.map +1 -1
  49. package/dist/node/infra/Debug.mjs.map +1 -1
  50. package/dist/node/infra/Dotenv.cjs.map +1 -1
  51. package/dist/node/infra/Dotenv.mjs.map +1 -1
  52. package/dist/node/infra/Error.cjs.map +1 -1
  53. package/dist/node/infra/Error.mjs.map +1 -1
  54. package/dist/node/infra/recase.cjs.map +1 -1
  55. package/dist/node/infra/recase.mjs.map +1 -1
  56. package/dist/node/infra/runtime.cjs.map +1 -1
  57. package/dist/node/infra/runtime.mjs.map +1 -1
  58. package/dist/node/sources/FileSource.cjs.map +1 -1
  59. package/dist/node/sources/FileSource.mjs.map +1 -1
  60. package/dist/node/sources/PortableSource.cjs.map +1 -1
  61. package/dist/node/sources/PortableSource.mjs.map +1 -1
  62. package/dist/node/sources/UnboundSource.cjs.map +1 -1
  63. package/dist/node/sources/UnboundSource.mjs.map +1 -1
  64. package/dist/node/sources/coerce.cjs.map +1 -1
  65. package/dist/node/sources/coerce.mjs.map +1 -1
  66. package/dist/node/sources/merge.cjs.map +1 -1
  67. package/dist/node/sources/merge.mjs.map +1 -1
  68. package/dist/portable/converters/BuiltInConverters.mjs.map +1 -1
  69. package/dist/portable/converters/Converters.mjs.map +1 -1
  70. package/dist/portable/converters/ListOfBuiltInConverters.mjs.map +1 -1
  71. package/dist/portable/converters/ValueConverter.mjs.map +1 -1
  72. package/dist/portable/core/AdvancedMethods.mjs.map +1 -1
  73. package/dist/portable/core/EnvapterBase.mjs.map +1 -1
  74. package/dist/portable/core/EnvironmentMethods.mjs.map +1 -1
  75. package/dist/portable/core/PrimitiveMethods.mjs.map +1 -1
  76. package/dist/portable/core/engine.mjs.map +1 -1
  77. package/dist/portable/core/missing.mjs.map +1 -1
  78. package/dist/portable/core/paths.mjs.map +1 -1
  79. package/dist/portable/core/state.mjs.map +1 -1
  80. package/dist/portable/decorators/legacy/Envapt.mjs.map +1 -1
  81. package/dist/portable/decorators/legacy/SugarDecorators.mjs.map +1 -1
  82. package/dist/portable/decorators/modern/Envapt.mjs.map +1 -1
  83. package/dist/portable/decorators/modern/SugarDecorators.mjs.map +1 -1
  84. package/dist/portable/decorators/modern/createAccessorDecorator.mjs.map +1 -1
  85. package/dist/portable/decorators/resolveDecoratorValue.mjs.map +1 -1
  86. package/dist/portable/engine/Envapter.mjs.map +1 -1
  87. package/dist/portable/engine/PortableEnvapter.mjs.map +1 -1
  88. package/dist/portable/engine/TemplateResolver.mjs.map +1 -1
  89. package/dist/portable/engine/Validators.mjs.map +1 -1
  90. package/dist/portable/engine/fileApiStub.mjs.map +1 -1
  91. package/dist/portable/infra/Debug.mjs.map +1 -1
  92. package/dist/portable/infra/Dotenv.mjs.map +1 -1
  93. package/dist/portable/infra/Error.mjs.map +1 -1
  94. package/dist/portable/infra/recase.mjs.map +1 -1
  95. package/dist/portable/infra/runtime.mjs.map +1 -1
  96. package/dist/portable/sources/PortableSource.mjs.map +1 -1
  97. package/dist/portable/sources/UnboundSource.mjs.map +1 -1
  98. package/dist/portable/sources/coerce.mjs.map +1 -1
  99. package/dist/portable/sources/merge.mjs.map +1 -1
  100. package/dist/types/converters/Converters.d.mts +4 -5
  101. package/dist/types/core/AdvancedMethods.d.mts +6 -12
  102. package/dist/types/core/EnvapterBase.d.mts +9 -12
  103. package/dist/types/core/Environment.d.mts +1 -2
  104. package/dist/types/core/EnvironmentMethods.d.mts +1 -6
  105. package/dist/types/core/PrimitiveMethods.d.mts +1 -5
  106. package/dist/types/decorators/legacy/Envapt.d.mts +17 -19
  107. package/dist/types/decorators/legacy/SugarDecorators.d.mts +12 -13
  108. package/dist/types/decorators/modern/Envapt.d.mts +17 -19
  109. package/dist/types/decorators/modern/SugarDecorators.d.mts +12 -13
  110. package/dist/types/engine/Envapter.d.mts +2 -2
  111. package/dist/types/engine/NodeEnvapter.d.mts +5 -6
  112. package/dist/types/engine/PortableEnvapter.d.mts +5 -7
  113. package/dist/types/infra/Debug.d.mts +3 -5
  114. package/dist/types/infra/Dotenv.d.mts +2 -4
  115. package/dist/types/infra/Error.d.mts +4 -5
  116. package/dist/types/infra/StandardSchema.d.mts +5 -7
  117. package/dist/types/sources/FileSource.d.mts +1 -2
  118. package/dist/types/sources/PortableSource.d.mts +7 -8
  119. package/dist/types/sources/merge.d.mts +1 -2
  120. package/dist/types/types/Conversion.d.mts +0 -4
  121. package/dist/types/types/Decorator.d.mts +2 -3
  122. package/dist/types/types/Options.d.mts +7 -7
  123. package/dist/types/types/Schema.d.mts +1 -1
  124. package/package.json +9 -11
@@ -1 +1 @@
1
- {"version":3,"file":"Envapt.cjs","names":["createAccessorDecorator","parseEnvaptOptions"],"sources":["../../../../src/decorators/modern/Envapt.ts"],"sourcesContent":["import { createAccessorDecorator } from './createAccessorDecorator';\nimport { parseEnvaptOptions } from '../parseEnvaptOptions';\n\nimport type { ArrayOf } from '../../converters';\nimport type { InferSchemaOutput, StandardSchemaV1 } from '../../infra/StandardSchema';\nimport type {\n BuiltInConverter,\n ConverterFunction,\n EnvaptAccessorDecorator,\n EnvKeyInput,\n InferConverterFallbackType,\n InferConverterReturnType,\n InferPrimitiveReturnType,\n PrimitiveConstructor,\n SchemaConstraint\n} from '../../types';\n\n/**\n * A custom converter function with a fallback (both required), or a fallback only.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config {\n * \\@Envapt('API_KEY', {\n * fallback: 'default-key',\n * converter(raw, _fallback) {\n * if (!raw || raw.trim() === '') throw new Error('API_KEY required');\n * return raw.trim();\n * }\n * })\n * static accessor apiKey: string;\n *\n * \\@Envapt('LOG_FILE', { fallback: '/var/log/app.log' })\n * static accessor logFile: string;\n *\n * \\@Envapt('RETRY_POLICY', { fallback: { retries: 3, backoff: 'exponential' } })\n * static accessor retryPolicy: unknown;\n * }\n * ```\n */\nexport function Envapt(\n key: EnvKeyInput,\n options?: { fallback: undefined; converter?: undefined }\n): EnvaptAccessorDecorator<string | undefined>;\nexport function Envapt<TFallback>(\n key: EnvKeyInput,\n options:\n | { converter: (raw: string | undefined, fallback: TFallback) => TFallback; fallback: TFallback }\n | { fallback: TFallback; converter?: undefined }\n): EnvaptAccessorDecorator<TFallback>;\n\n/**\n * A custom converter function without a fallback. Omit `required` to return the converter's\n * output (possibly `undefined`), or pass `required: true` to throw `MissingEnvValue` on\n * missing or empty values.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config {\n * \\@Envapt('FEATURE_FLAGS', { converter(raw) {\n * return raw ? raw.split('|').map(s => s.trim()) : [];\n * } })\n * static accessor featureFlags: string[];\n *\n * \\@Envapt('JWT_SECRET', {\n * converter: (raw) => Buffer.from(raw ?? '', 'base64'),\n * required: true\n * })\n * static accessor jwtSecret: Buffer;\n * }\n * ```\n */\nexport function Envapt<TReturnType>(\n key: EnvKeyInput,\n options:\n | { converter: ConverterFunction<TReturnType>; required?: false }\n | { converter: ConverterFunction<TReturnType>; required: true }\n): EnvaptAccessorDecorator<TReturnType>;\n\n/**\n * A built-in or array converter with a fallback, or `required: true`. The fallback type tracks\n * the converter, so `Converters.Time` takes a number or time-string and `Converters.Url` takes\n * a `URL` instance.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * import { Converters } from 'envapt';\n *\n * class Config {\n * \\@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })\n * static accessor port: number;\n *\n * // the Url fallback is a URL instance, not a string\n * \\@Envapt('APP_URL', { converter: Converters.Url, fallback: new URL('http://localhost:3000') })\n * static accessor url: URL;\n *\n * // prefers CANARY_URL when present, otherwise APP_URL\n * \\@Envapt(['CANARY_URL', 'APP_URL'], { converter: Converters.Url })\n * static accessor canaryUrl: URL | undefined;\n *\n * // Time takes a number (milliseconds) or a time-string fallback (`<number><unit>`)\n * \\@Envapt('REQUEST_TIMEOUT', { converter: Converters.Time, fallback: '10s' })\n * static accessor requestTimeout: number;\n *\n * \\@Envapt('ALLOWED_ORIGINS', {\n * converter: Converters.array({ of: Converters.String }),\n * fallback: ['https://example.com']\n * })\n * static accessor allowedOrigins: string[];\n *\n * \\@Envapt('DATABASE_URL', { converter: Converters.Url, required: true })\n * static accessor databaseUrl: URL;\n * }\n * ```\n */\nexport function Envapt<TConverter extends BuiltInConverter | ArrayOf>(\n key: EnvKeyInput,\n options:\n | { converter: TConverter; fallback: InferConverterFallbackType<TConverter>; required?: false }\n | { converter: TConverter; required: true }\n): EnvaptAccessorDecorator<InferConverterReturnType<TConverter>>;\nexport function Envapt<TConverter extends BuiltInConverter | ArrayOf>(\n key: EnvKeyInput,\n options: { converter: TConverter; fallback?: undefined; required?: false }\n): EnvaptAccessorDecorator<InferConverterReturnType<TConverter> | undefined>;\n\n/**\n * A primitive constructor (`Number`, `Boolean`) with an optional fallback.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config {\n * \\@Envapt('MAX_CONNECTIONS', { converter: Number, fallback: 100 })\n * static accessor maxConnections: number;\n *\n * \\@Envapt('FEATURE_ENABLED', { converter: Boolean, fallback: false })\n * static accessor featureEnabled: boolean;\n * }\n * ```\n */\nexport function Envapt<TConstructor extends PrimitiveConstructor>(\n key: EnvKeyInput,\n options:\n | { converter: TConstructor; fallback: InferPrimitiveReturnType<TConstructor>; required?: false }\n | { converter: TConstructor; required: true }\n): EnvaptAccessorDecorator<InferPrimitiveReturnType<TConstructor>>;\nexport function Envapt<TConstructor extends PrimitiveConstructor>(\n key: EnvKeyInput,\n options: { converter: TConstructor; fallback?: undefined; required?: false }\n): EnvaptAccessorDecorator<InferPrimitiveReturnType<TConstructor> | undefined>;\n\n/**\n * Required, no converter (raw string). Throws `MissingEnvValue` on first access when the env\n * value is missing or empty after trimming, independent of the global `Envapter.strict` flag.\n * Pairing `required: true` with `fallback` matches no overload at compile time, and the runtime\n * Validator rejects dynamic objects that bypass the types.\n *\n * @param key - Environment variable name(s) to load\n * @param options - `{ required: true }`\n * @public\n * @example\n * ```ts\n * class Config {\n * \\@Envapt('API_KEY', { required: true })\n * static accessor apiKey: string;\n * }\n * ```\n */\nexport function Envapt(key: EnvKeyInput, options: { required: true }): EnvaptAccessorDecorator<string>;\n\n/**\n * A Standard Schema v1 adapter (zod, valibot, arktype, hand-rolled). Synchronous schemas only,\n * so a Promise-returning `validate` throws `InvalidUserDefinedConfig` at runtime. Pairing\n * `schema` with `converter` matches no overload at compile time, and the runtime Validator\n * rejects dynamic objects that bypass the types.\n * @public\n */\nexport function Envapt<Schema extends StandardSchemaV1>(\n key: EnvKeyInput,\n options:\n | { schema: SchemaConstraint<Schema>; fallback?: InferSchemaOutput<Schema>; required?: false }\n | { schema: SchemaConstraint<Schema>; required: true }\n): EnvaptAccessorDecorator<InferSchemaOutput<Schema>>;\n\n/**\n * Modern (TC39 Stage 3) accessor decorator that loads and converts an environment variable. The\n * decorated property uses the `accessor` keyword and needs no `experimentalDecorators` flag.\n * Instance accessors need the definite-assignment `!`, static accessors do not.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Converter, fallback, `required`, or `schema`. See the overloads.\n * @public\n * @example\n * ```ts\n * import { Envapt, Converters } from 'envapt';\n *\n * class Config {\n * \\@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })\n * static accessor port: number;\n *\n * \\@Envapt('DATABASE_URL', { converter: Converters.Url, required: true })\n * accessor databaseUrl!: URL;\n * }\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/decorators#declaring-decorated-fields}\n */\n/* v8 ignore start -- @preserve oxc (vitest's transform) breaks modern accessor decorators (context.name unset), so the tsc stage3-emit harness covers these, not vitest */\nexport function Envapt<TFallback = unknown>(key: EnvKeyInput, options?: unknown): EnvaptAccessorDecorator<unknown> {\n return createAccessorDecorator(key, parseEnvaptOptions<TFallback>(options)) as EnvaptAccessorDecorator<unknown>;\n}\n/* v8 ignore stop */\n"],"mappings":"wFA2NA,SAAgB,EAA4B,EAAkB,EAAqD,CAC/G,OAAOA,EAAAA,wBAAwB,EAAKC,EAAAA,mBAA8B,CAAO,CAAC,CAC9E"}
1
+ {"version":3,"file":"Envapt.cjs","names":["createAccessorDecorator","parseEnvaptOptions"],"sources":["../../../../src/decorators/modern/Envapt.ts"],"sourcesContent":["import { createAccessorDecorator } from './createAccessorDecorator';\nimport { parseEnvaptOptions } from '../parseEnvaptOptions';\n\nimport type { ArrayOf } from '../../converters';\nimport type { InferSchemaOutput, StandardSchemaV1 } from '../../infra/StandardSchema';\nimport type {\n BuiltInConverter,\n ConverterFunction,\n EnvaptAccessorDecorator,\n EnvKeyInput,\n InferConverterFallbackType,\n InferConverterReturnType,\n InferPrimitiveReturnType,\n PrimitiveConstructor,\n SchemaConstraint\n} from '../../types';\n\n/**\n * A custom converter function with a fallback (both required), or a fallback only.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config {\n * \\@Envapt('API_KEY', {\n * fallback: 'default-key',\n * converter(raw, _fallback) {\n * if (!raw || raw.trim() === '') throw new Error('API_KEY required');\n * return raw.trim();\n * }\n * })\n * static accessor apiKey: string;\n *\n * \\@Envapt('LOG_FILE', { fallback: '/var/log/app.log' })\n * static accessor logFile: string;\n *\n * \\@Envapt('RETRY_POLICY', { fallback: { retries: 3, backoff: 'exponential' } })\n * static accessor retryPolicy: unknown;\n * }\n * ```\n */\nexport function Envapt(\n key: EnvKeyInput,\n options?: { fallback: undefined; converter?: undefined }\n): EnvaptAccessorDecorator<string | undefined>;\nexport function Envapt<TFallback>(\n key: EnvKeyInput,\n options:\n | { converter: (raw: string | undefined, fallback: TFallback) => TFallback; fallback: TFallback }\n | { fallback: TFallback; converter?: undefined }\n): EnvaptAccessorDecorator<TFallback>;\n\n/**\n * A custom converter function without a fallback. Omit `required` to return the converter's\n * output (possibly `undefined`), or pass `required: true` to throw `MissingEnvValue` on\n * missing or empty values.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config {\n * \\@Envapt('FEATURE_FLAGS', { converter(raw) {\n * return raw ? raw.split('|').map(s => s.trim()) : [];\n * } })\n * static accessor featureFlags: string[];\n *\n * \\@Envapt('JWT_SECRET', {\n * converter: (raw) => Buffer.from(raw ?? '', 'base64'),\n * required: true\n * })\n * static accessor jwtSecret: Buffer;\n * }\n * ```\n */\nexport function Envapt<TReturnType>(\n key: EnvKeyInput,\n options:\n | { converter: ConverterFunction<TReturnType>; required?: false }\n | { converter: ConverterFunction<TReturnType>; required: true }\n): EnvaptAccessorDecorator<TReturnType>;\n\n/**\n * A built-in or array converter with a fallback, or `required: true`. The fallback type tracks\n * the converter, so `Converters.Time` takes a number or time-string and `Converters.Url` takes\n * a `URL` instance.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * import { Converters } from 'envapt';\n *\n * class Config {\n * \\@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })\n * static accessor port: number;\n *\n * // the Url fallback is a URL instance\n * \\@Envapt('APP_URL', { converter: Converters.Url, fallback: new URL('http://localhost:3000') })\n * static accessor url: URL;\n *\n * // reads CANARY_URL when present, otherwise APP_URL\n * \\@Envapt(['CANARY_URL', 'APP_URL'], { converter: Converters.Url })\n * static accessor canaryUrl: URL | undefined;\n *\n * // Time takes a number (milliseconds) or a time-string fallback (`<number><unit>`)\n * \\@Envapt('REQUEST_TIMEOUT', { converter: Converters.Time, fallback: '10s' })\n * static accessor requestTimeout: number;\n *\n * \\@Envapt('ALLOWED_ORIGINS', {\n * converter: Converters.array({ of: Converters.String }),\n * fallback: ['https://example.com']\n * })\n * static accessor allowedOrigins: string[];\n *\n * \\@Envapt('DATABASE_URL', { converter: Converters.Url, required: true })\n * static accessor databaseUrl: URL;\n * }\n * ```\n */\nexport function Envapt<TConverter extends BuiltInConverter | ArrayOf>(\n key: EnvKeyInput,\n options:\n | { converter: TConverter; fallback: InferConverterFallbackType<TConverter>; required?: false }\n | { converter: TConverter; required: true }\n): EnvaptAccessorDecorator<InferConverterReturnType<TConverter>>;\nexport function Envapt<TConverter extends BuiltInConverter | ArrayOf>(\n key: EnvKeyInput,\n options: { converter: TConverter; fallback?: undefined; required?: false }\n): EnvaptAccessorDecorator<InferConverterReturnType<TConverter> | undefined>;\n\n/**\n * A primitive constructor (`Number`, `Boolean`) with an optional fallback.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config {\n * \\@Envapt('MAX_CONNECTIONS', { converter: Number, fallback: 100 })\n * static accessor maxConnections: number;\n *\n * \\@Envapt('FEATURE_ENABLED', { converter: Boolean, fallback: false })\n * static accessor featureEnabled: boolean;\n * }\n * ```\n */\nexport function Envapt<TConstructor extends PrimitiveConstructor>(\n key: EnvKeyInput,\n options:\n | { converter: TConstructor; fallback: InferPrimitiveReturnType<TConstructor>; required?: false }\n | { converter: TConstructor; required: true }\n): EnvaptAccessorDecorator<InferPrimitiveReturnType<TConstructor>>;\nexport function Envapt<TConstructor extends PrimitiveConstructor>(\n key: EnvKeyInput,\n options: { converter: TConstructor; fallback?: undefined; required?: false }\n): EnvaptAccessorDecorator<InferPrimitiveReturnType<TConstructor> | undefined>;\n\n/**\n * Required, no converter (raw string). Throws `MissingEnvValue` on first access when the env\n * value is missing or empty. Pairing `required: true` with `fallback` matches no overload at\n * compile time, and a call that bypasses the types throws `InvalidUserDefinedConfig` at runtime.\n *\n * @param key - Environment variable name(s) to load\n * @param options - `{ required: true }`\n * @public\n * @example\n * ```ts\n * class Config {\n * \\@Envapt('API_KEY', { required: true })\n * static accessor apiKey: string;\n * }\n * ```\n */\nexport function Envapt(key: EnvKeyInput, options: { required: true }): EnvaptAccessorDecorator<string>;\n\n/**\n * A Standard Schema v1 adapter (zod, valibot, arktype, hand-rolled). Synchronous schemas only.\n * A `validate` that returns a Promise throws `InvalidUserDefinedConfig` at runtime. Pairing\n * `schema` with `converter` matches no overload at compile time, and a call that bypasses the\n * types throws `InvalidUserDefinedConfig` at runtime.\n * @public\n */\nexport function Envapt<Schema extends StandardSchemaV1>(\n key: EnvKeyInput,\n options:\n | { schema: SchemaConstraint<Schema>; fallback?: InferSchemaOutput<Schema>; required?: false }\n | { schema: SchemaConstraint<Schema>; required: true }\n): EnvaptAccessorDecorator<InferSchemaOutput<Schema>>;\n\n/**\n * Modern (TC39 Stage 3) accessor decorator that loads and converts an environment variable. The\n * decorated property uses the `accessor` keyword and needs no `experimentalDecorators` flag.\n * Instance accessors need the definite-assignment `!`. Static accessors do not.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Converter, fallback, `required`, or `schema`. See the overloads.\n * @public\n * @example\n * ```ts\n * import { Envapt, Converters } from 'envapt';\n *\n * class Config {\n * \\@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })\n * static accessor port: number;\n *\n * \\@Envapt('DATABASE_URL', { converter: Converters.Url, required: true })\n * accessor databaseUrl!: URL;\n * }\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/decorators#declaring-decorated-fields}\n */\n/* v8 ignore start -- @preserve the tsc stage3-emit tests cover these because oxc (vitest's transform) leaves context.name unset on modern accessor decorators */\nexport function Envapt<TFallback = unknown>(key: EnvKeyInput, options?: unknown): EnvaptAccessorDecorator<unknown> {\n return createAccessorDecorator(key, parseEnvaptOptions<TFallback>(options)) as EnvaptAccessorDecorator<unknown>;\n}\n/* v8 ignore stop */\n"],"mappings":"wFA0NA,SAAgB,EAA4B,EAAkB,EAAqD,CAC/G,OAAOA,EAAAA,wBAAwB,EAAKC,EAAAA,mBAA8B,CAAO,CAAC,CAC9E"}
@@ -1 +1 @@
1
- {"version":3,"file":"Envapt.mjs","names":[],"sources":["../../../../src/decorators/modern/Envapt.ts"],"sourcesContent":["import { createAccessorDecorator } from './createAccessorDecorator';\nimport { parseEnvaptOptions } from '../parseEnvaptOptions';\n\nimport type { ArrayOf } from '../../converters';\nimport type { InferSchemaOutput, StandardSchemaV1 } from '../../infra/StandardSchema';\nimport type {\n BuiltInConverter,\n ConverterFunction,\n EnvaptAccessorDecorator,\n EnvKeyInput,\n InferConverterFallbackType,\n InferConverterReturnType,\n InferPrimitiveReturnType,\n PrimitiveConstructor,\n SchemaConstraint\n} from '../../types';\n\n/**\n * A custom converter function with a fallback (both required), or a fallback only.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config {\n * \\@Envapt('API_KEY', {\n * fallback: 'default-key',\n * converter(raw, _fallback) {\n * if (!raw || raw.trim() === '') throw new Error('API_KEY required');\n * return raw.trim();\n * }\n * })\n * static accessor apiKey: string;\n *\n * \\@Envapt('LOG_FILE', { fallback: '/var/log/app.log' })\n * static accessor logFile: string;\n *\n * \\@Envapt('RETRY_POLICY', { fallback: { retries: 3, backoff: 'exponential' } })\n * static accessor retryPolicy: unknown;\n * }\n * ```\n */\nexport function Envapt(\n key: EnvKeyInput,\n options?: { fallback: undefined; converter?: undefined }\n): EnvaptAccessorDecorator<string | undefined>;\nexport function Envapt<TFallback>(\n key: EnvKeyInput,\n options:\n | { converter: (raw: string | undefined, fallback: TFallback) => TFallback; fallback: TFallback }\n | { fallback: TFallback; converter?: undefined }\n): EnvaptAccessorDecorator<TFallback>;\n\n/**\n * A custom converter function without a fallback. Omit `required` to return the converter's\n * output (possibly `undefined`), or pass `required: true` to throw `MissingEnvValue` on\n * missing or empty values.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config {\n * \\@Envapt('FEATURE_FLAGS', { converter(raw) {\n * return raw ? raw.split('|').map(s => s.trim()) : [];\n * } })\n * static accessor featureFlags: string[];\n *\n * \\@Envapt('JWT_SECRET', {\n * converter: (raw) => Buffer.from(raw ?? '', 'base64'),\n * required: true\n * })\n * static accessor jwtSecret: Buffer;\n * }\n * ```\n */\nexport function Envapt<TReturnType>(\n key: EnvKeyInput,\n options:\n | { converter: ConverterFunction<TReturnType>; required?: false }\n | { converter: ConverterFunction<TReturnType>; required: true }\n): EnvaptAccessorDecorator<TReturnType>;\n\n/**\n * A built-in or array converter with a fallback, or `required: true`. The fallback type tracks\n * the converter, so `Converters.Time` takes a number or time-string and `Converters.Url` takes\n * a `URL` instance.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * import { Converters } from 'envapt';\n *\n * class Config {\n * \\@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })\n * static accessor port: number;\n *\n * // the Url fallback is a URL instance, not a string\n * \\@Envapt('APP_URL', { converter: Converters.Url, fallback: new URL('http://localhost:3000') })\n * static accessor url: URL;\n *\n * // prefers CANARY_URL when present, otherwise APP_URL\n * \\@Envapt(['CANARY_URL', 'APP_URL'], { converter: Converters.Url })\n * static accessor canaryUrl: URL | undefined;\n *\n * // Time takes a number (milliseconds) or a time-string fallback (`<number><unit>`)\n * \\@Envapt('REQUEST_TIMEOUT', { converter: Converters.Time, fallback: '10s' })\n * static accessor requestTimeout: number;\n *\n * \\@Envapt('ALLOWED_ORIGINS', {\n * converter: Converters.array({ of: Converters.String }),\n * fallback: ['https://example.com']\n * })\n * static accessor allowedOrigins: string[];\n *\n * \\@Envapt('DATABASE_URL', { converter: Converters.Url, required: true })\n * static accessor databaseUrl: URL;\n * }\n * ```\n */\nexport function Envapt<TConverter extends BuiltInConverter | ArrayOf>(\n key: EnvKeyInput,\n options:\n | { converter: TConverter; fallback: InferConverterFallbackType<TConverter>; required?: false }\n | { converter: TConverter; required: true }\n): EnvaptAccessorDecorator<InferConverterReturnType<TConverter>>;\nexport function Envapt<TConverter extends BuiltInConverter | ArrayOf>(\n key: EnvKeyInput,\n options: { converter: TConverter; fallback?: undefined; required?: false }\n): EnvaptAccessorDecorator<InferConverterReturnType<TConverter> | undefined>;\n\n/**\n * A primitive constructor (`Number`, `Boolean`) with an optional fallback.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config {\n * \\@Envapt('MAX_CONNECTIONS', { converter: Number, fallback: 100 })\n * static accessor maxConnections: number;\n *\n * \\@Envapt('FEATURE_ENABLED', { converter: Boolean, fallback: false })\n * static accessor featureEnabled: boolean;\n * }\n * ```\n */\nexport function Envapt<TConstructor extends PrimitiveConstructor>(\n key: EnvKeyInput,\n options:\n | { converter: TConstructor; fallback: InferPrimitiveReturnType<TConstructor>; required?: false }\n | { converter: TConstructor; required: true }\n): EnvaptAccessorDecorator<InferPrimitiveReturnType<TConstructor>>;\nexport function Envapt<TConstructor extends PrimitiveConstructor>(\n key: EnvKeyInput,\n options: { converter: TConstructor; fallback?: undefined; required?: false }\n): EnvaptAccessorDecorator<InferPrimitiveReturnType<TConstructor> | undefined>;\n\n/**\n * Required, no converter (raw string). Throws `MissingEnvValue` on first access when the env\n * value is missing or empty after trimming, independent of the global `Envapter.strict` flag.\n * Pairing `required: true` with `fallback` matches no overload at compile time, and the runtime\n * Validator rejects dynamic objects that bypass the types.\n *\n * @param key - Environment variable name(s) to load\n * @param options - `{ required: true }`\n * @public\n * @example\n * ```ts\n * class Config {\n * \\@Envapt('API_KEY', { required: true })\n * static accessor apiKey: string;\n * }\n * ```\n */\nexport function Envapt(key: EnvKeyInput, options: { required: true }): EnvaptAccessorDecorator<string>;\n\n/**\n * A Standard Schema v1 adapter (zod, valibot, arktype, hand-rolled). Synchronous schemas only,\n * so a Promise-returning `validate` throws `InvalidUserDefinedConfig` at runtime. Pairing\n * `schema` with `converter` matches no overload at compile time, and the runtime Validator\n * rejects dynamic objects that bypass the types.\n * @public\n */\nexport function Envapt<Schema extends StandardSchemaV1>(\n key: EnvKeyInput,\n options:\n | { schema: SchemaConstraint<Schema>; fallback?: InferSchemaOutput<Schema>; required?: false }\n | { schema: SchemaConstraint<Schema>; required: true }\n): EnvaptAccessorDecorator<InferSchemaOutput<Schema>>;\n\n/**\n * Modern (TC39 Stage 3) accessor decorator that loads and converts an environment variable. The\n * decorated property uses the `accessor` keyword and needs no `experimentalDecorators` flag.\n * Instance accessors need the definite-assignment `!`, static accessors do not.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Converter, fallback, `required`, or `schema`. See the overloads.\n * @public\n * @example\n * ```ts\n * import { Envapt, Converters } from 'envapt';\n *\n * class Config {\n * \\@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })\n * static accessor port: number;\n *\n * \\@Envapt('DATABASE_URL', { converter: Converters.Url, required: true })\n * accessor databaseUrl!: URL;\n * }\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/decorators#declaring-decorated-fields}\n */\n/* v8 ignore start -- @preserve oxc (vitest's transform) breaks modern accessor decorators (context.name unset), so the tsc stage3-emit harness covers these, not vitest */\nexport function Envapt<TFallback = unknown>(key: EnvKeyInput, options?: unknown): EnvaptAccessorDecorator<unknown> {\n return createAccessorDecorator(key, parseEnvaptOptions<TFallback>(options)) as EnvaptAccessorDecorator<unknown>;\n}\n/* v8 ignore stop */\n"],"mappings":"uIA2NA,SAAgB,EAA4B,EAAkB,EAAqD,CAC/G,OAAO,EAAwB,EAAK,EAA8B,CAAO,CAAC,CAC9E"}
1
+ {"version":3,"file":"Envapt.mjs","names":[],"sources":["../../../../src/decorators/modern/Envapt.ts"],"sourcesContent":["import { createAccessorDecorator } from './createAccessorDecorator';\nimport { parseEnvaptOptions } from '../parseEnvaptOptions';\n\nimport type { ArrayOf } from '../../converters';\nimport type { InferSchemaOutput, StandardSchemaV1 } from '../../infra/StandardSchema';\nimport type {\n BuiltInConverter,\n ConverterFunction,\n EnvaptAccessorDecorator,\n EnvKeyInput,\n InferConverterFallbackType,\n InferConverterReturnType,\n InferPrimitiveReturnType,\n PrimitiveConstructor,\n SchemaConstraint\n} from '../../types';\n\n/**\n * A custom converter function with a fallback (both required), or a fallback only.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config {\n * \\@Envapt('API_KEY', {\n * fallback: 'default-key',\n * converter(raw, _fallback) {\n * if (!raw || raw.trim() === '') throw new Error('API_KEY required');\n * return raw.trim();\n * }\n * })\n * static accessor apiKey: string;\n *\n * \\@Envapt('LOG_FILE', { fallback: '/var/log/app.log' })\n * static accessor logFile: string;\n *\n * \\@Envapt('RETRY_POLICY', { fallback: { retries: 3, backoff: 'exponential' } })\n * static accessor retryPolicy: unknown;\n * }\n * ```\n */\nexport function Envapt(\n key: EnvKeyInput,\n options?: { fallback: undefined; converter?: undefined }\n): EnvaptAccessorDecorator<string | undefined>;\nexport function Envapt<TFallback>(\n key: EnvKeyInput,\n options:\n | { converter: (raw: string | undefined, fallback: TFallback) => TFallback; fallback: TFallback }\n | { fallback: TFallback; converter?: undefined }\n): EnvaptAccessorDecorator<TFallback>;\n\n/**\n * A custom converter function without a fallback. Omit `required` to return the converter's\n * output (possibly `undefined`), or pass `required: true` to throw `MissingEnvValue` on\n * missing or empty values.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config {\n * \\@Envapt('FEATURE_FLAGS', { converter(raw) {\n * return raw ? raw.split('|').map(s => s.trim()) : [];\n * } })\n * static accessor featureFlags: string[];\n *\n * \\@Envapt('JWT_SECRET', {\n * converter: (raw) => Buffer.from(raw ?? '', 'base64'),\n * required: true\n * })\n * static accessor jwtSecret: Buffer;\n * }\n * ```\n */\nexport function Envapt<TReturnType>(\n key: EnvKeyInput,\n options:\n | { converter: ConverterFunction<TReturnType>; required?: false }\n | { converter: ConverterFunction<TReturnType>; required: true }\n): EnvaptAccessorDecorator<TReturnType>;\n\n/**\n * A built-in or array converter with a fallback, or `required: true`. The fallback type tracks\n * the converter, so `Converters.Time` takes a number or time-string and `Converters.Url` takes\n * a `URL` instance.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * import { Converters } from 'envapt';\n *\n * class Config {\n * \\@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })\n * static accessor port: number;\n *\n * // the Url fallback is a URL instance\n * \\@Envapt('APP_URL', { converter: Converters.Url, fallback: new URL('http://localhost:3000') })\n * static accessor url: URL;\n *\n * // reads CANARY_URL when present, otherwise APP_URL\n * \\@Envapt(['CANARY_URL', 'APP_URL'], { converter: Converters.Url })\n * static accessor canaryUrl: URL | undefined;\n *\n * // Time takes a number (milliseconds) or a time-string fallback (`<number><unit>`)\n * \\@Envapt('REQUEST_TIMEOUT', { converter: Converters.Time, fallback: '10s' })\n * static accessor requestTimeout: number;\n *\n * \\@Envapt('ALLOWED_ORIGINS', {\n * converter: Converters.array({ of: Converters.String }),\n * fallback: ['https://example.com']\n * })\n * static accessor allowedOrigins: string[];\n *\n * \\@Envapt('DATABASE_URL', { converter: Converters.Url, required: true })\n * static accessor databaseUrl: URL;\n * }\n * ```\n */\nexport function Envapt<TConverter extends BuiltInConverter | ArrayOf>(\n key: EnvKeyInput,\n options:\n | { converter: TConverter; fallback: InferConverterFallbackType<TConverter>; required?: false }\n | { converter: TConverter; required: true }\n): EnvaptAccessorDecorator<InferConverterReturnType<TConverter>>;\nexport function Envapt<TConverter extends BuiltInConverter | ArrayOf>(\n key: EnvKeyInput,\n options: { converter: TConverter; fallback?: undefined; required?: false }\n): EnvaptAccessorDecorator<InferConverterReturnType<TConverter> | undefined>;\n\n/**\n * A primitive constructor (`Number`, `Boolean`) with an optional fallback.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config {\n * \\@Envapt('MAX_CONNECTIONS', { converter: Number, fallback: 100 })\n * static accessor maxConnections: number;\n *\n * \\@Envapt('FEATURE_ENABLED', { converter: Boolean, fallback: false })\n * static accessor featureEnabled: boolean;\n * }\n * ```\n */\nexport function Envapt<TConstructor extends PrimitiveConstructor>(\n key: EnvKeyInput,\n options:\n | { converter: TConstructor; fallback: InferPrimitiveReturnType<TConstructor>; required?: false }\n | { converter: TConstructor; required: true }\n): EnvaptAccessorDecorator<InferPrimitiveReturnType<TConstructor>>;\nexport function Envapt<TConstructor extends PrimitiveConstructor>(\n key: EnvKeyInput,\n options: { converter: TConstructor; fallback?: undefined; required?: false }\n): EnvaptAccessorDecorator<InferPrimitiveReturnType<TConstructor> | undefined>;\n\n/**\n * Required, no converter (raw string). Throws `MissingEnvValue` on first access when the env\n * value is missing or empty. Pairing `required: true` with `fallback` matches no overload at\n * compile time, and a call that bypasses the types throws `InvalidUserDefinedConfig` at runtime.\n *\n * @param key - Environment variable name(s) to load\n * @param options - `{ required: true }`\n * @public\n * @example\n * ```ts\n * class Config {\n * \\@Envapt('API_KEY', { required: true })\n * static accessor apiKey: string;\n * }\n * ```\n */\nexport function Envapt(key: EnvKeyInput, options: { required: true }): EnvaptAccessorDecorator<string>;\n\n/**\n * A Standard Schema v1 adapter (zod, valibot, arktype, hand-rolled). Synchronous schemas only.\n * A `validate` that returns a Promise throws `InvalidUserDefinedConfig` at runtime. Pairing\n * `schema` with `converter` matches no overload at compile time, and a call that bypasses the\n * types throws `InvalidUserDefinedConfig` at runtime.\n * @public\n */\nexport function Envapt<Schema extends StandardSchemaV1>(\n key: EnvKeyInput,\n options:\n | { schema: SchemaConstraint<Schema>; fallback?: InferSchemaOutput<Schema>; required?: false }\n | { schema: SchemaConstraint<Schema>; required: true }\n): EnvaptAccessorDecorator<InferSchemaOutput<Schema>>;\n\n/**\n * Modern (TC39 Stage 3) accessor decorator that loads and converts an environment variable. The\n * decorated property uses the `accessor` keyword and needs no `experimentalDecorators` flag.\n * Instance accessors need the definite-assignment `!`. Static accessors do not.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Converter, fallback, `required`, or `schema`. See the overloads.\n * @public\n * @example\n * ```ts\n * import { Envapt, Converters } from 'envapt';\n *\n * class Config {\n * \\@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })\n * static accessor port: number;\n *\n * \\@Envapt('DATABASE_URL', { converter: Converters.Url, required: true })\n * accessor databaseUrl!: URL;\n * }\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/decorators#declaring-decorated-fields}\n */\n/* v8 ignore start -- @preserve the tsc stage3-emit tests cover these because oxc (vitest's transform) leaves context.name unset on modern accessor decorators */\nexport function Envapt<TFallback = unknown>(key: EnvKeyInput, options?: unknown): EnvaptAccessorDecorator<unknown> {\n return createAccessorDecorator(key, parseEnvaptOptions<TFallback>(options)) as EnvaptAccessorDecorator<unknown>;\n}\n/* v8 ignore stop */\n"],"mappings":"uIA0NA,SAAgB,EAA4B,EAAkB,EAAqD,CAC/G,OAAO,EAAwB,EAAK,EAA8B,CAAO,CAAC,CAC9E"}
@@ -1 +1 @@
1
- {"version":3,"file":"SugarDecorators.cjs","names":["createAccessorDecorator","Converters"],"sources":["../../../../src/decorators/modern/SugarDecorators.ts"],"sourcesContent":["import { createAccessorDecorator } from './createAccessorDecorator';\nimport { Converters } from '../../converters';\n\nimport type { ConverterToken } from '../../converters';\nimport type { EnvaptAccessorDecorator, EnvKeyInput, TimeFallback } from '../../types';\n\n/* v8 ignore start -- @preserve oxc (vitest's transform) breaks modern accessor decorators (context.name unset), so the tsc stage3-emit harness covers these, not vitest */\nfunction sugar<TFallback>(\n converter: ConverterToken,\n key: EnvKeyInput,\n fallback: TFallback | undefined\n): EnvaptAccessorDecorator<TFallback> {\n // the runtime installer is a plain accessor decorator, so the cast only adds a\n // compile-time field-type constraint with no runtime counterpart\n return createAccessorDecorator<TFallback>(key, {\n converter,\n fallback,\n hasFallback: fallback !== undefined,\n required: false,\n schema: undefined\n }) as EnvaptAccessorDecorator<TFallback>;\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Boolean, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvBool(key: EnvKeyInput, fallback: boolean): EnvaptAccessorDecorator<boolean>;\nexport function EnvBool(key: EnvKeyInput): EnvaptAccessorDecorator<boolean | undefined>;\nexport function EnvBool(key: EnvKeyInput, fallback?: boolean): EnvaptAccessorDecorator<boolean | undefined> {\n return sugar(Converters.Boolean, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Number, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvNum(key: EnvKeyInput, fallback: number): EnvaptAccessorDecorator<number>;\nexport function EnvNum(key: EnvKeyInput): EnvaptAccessorDecorator<number | undefined>;\nexport function EnvNum(key: EnvKeyInput, fallback?: number): EnvaptAccessorDecorator<number | undefined> {\n return sugar(Converters.Number, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.String, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvStr(key: EnvKeyInput, fallback: string): EnvaptAccessorDecorator<string>;\nexport function EnvStr(key: EnvKeyInput): EnvaptAccessorDecorator<string | undefined>;\nexport function EnvStr(key: EnvKeyInput, fallback?: string): EnvaptAccessorDecorator<string | undefined> {\n return sugar(Converters.String, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Time, fallback })`. The fallback is a\n * millisecond number or a time string (`'15m'`), and the resolved value is always milliseconds.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvTime(key: EnvKeyInput, fallback: TimeFallback): EnvaptAccessorDecorator<number>;\nexport function EnvTime(key: EnvKeyInput): EnvaptAccessorDecorator<number | undefined>;\nexport function EnvTime(key: EnvKeyInput, fallback?: TimeFallback): EnvaptAccessorDecorator<number | undefined> {\n return sugar(Converters.Time, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Url, fallback })`. The fallback is a `URL`\n * instance, not a URL string.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvUrl(key: EnvKeyInput, fallback: URL): EnvaptAccessorDecorator<URL>;\nexport function EnvUrl(key: EnvKeyInput): EnvaptAccessorDecorator<URL | undefined>;\nexport function EnvUrl(key: EnvKeyInput, fallback?: URL): EnvaptAccessorDecorator<URL | undefined> {\n return sugar(Converters.Url, key, fallback);\n}\n/* v8 ignore stop */\n"],"mappings":"8FAOA,SAAS,EACL,EACA,EACA,EACkC,CAGlC,OAAOA,EAAAA,wBAAmC,EAAK,CAC3C,YACA,WACA,YAAa,IAAa,IAAA,GAC1B,SAAU,GACV,OAAQ,IAAA,EACZ,CAAC,CACL,CASA,SAAgB,EAAQ,EAAkB,EAAkE,CACxG,OAAO,EAAMC,EAAAA,WAAW,QAAS,EAAK,CAAQ,CAClD,CASA,SAAgB,EAAO,EAAkB,EAAgE,CACrG,OAAO,EAAMA,EAAAA,WAAW,OAAQ,EAAK,CAAQ,CACjD,CASA,SAAgB,EAAO,EAAkB,EAAgE,CACrG,OAAO,EAAMA,EAAAA,WAAW,OAAQ,EAAK,CAAQ,CACjD,CAUA,SAAgB,EAAQ,EAAkB,EAAsE,CAC5G,OAAO,EAAMA,EAAAA,WAAW,KAAM,EAAK,CAAQ,CAC/C,CAUA,SAAgB,EAAO,EAAkB,EAA0D,CAC/F,OAAO,EAAMA,EAAAA,WAAW,IAAK,EAAK,CAAQ,CAC9C"}
1
+ {"version":3,"file":"SugarDecorators.cjs","names":["createAccessorDecorator","Converters"],"sources":["../../../../src/decorators/modern/SugarDecorators.ts"],"sourcesContent":["import { createAccessorDecorator } from './createAccessorDecorator';\nimport { Converters } from '../../converters';\n\nimport type { ConverterToken } from '../../converters';\nimport type { EnvaptAccessorDecorator, EnvKeyInput, TimeFallback } from '../../types';\n\n/* v8 ignore start -- @preserve the tsc stage3-emit tests cover these because oxc (vitest's transform) leaves context.name unset on modern accessor decorators */\nfunction sugar<TFallback>(\n converter: ConverterToken,\n key: EnvKeyInput,\n fallback: TFallback | undefined\n): EnvaptAccessorDecorator<TFallback> {\n // the cast only adds a compile-time check on the field type\n return createAccessorDecorator<TFallback>(key, {\n converter,\n fallback,\n hasFallback: fallback !== undefined,\n required: false,\n schema: undefined\n }) as EnvaptAccessorDecorator<TFallback>;\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Boolean, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvBool(key: EnvKeyInput, fallback: boolean): EnvaptAccessorDecorator<boolean>;\nexport function EnvBool(key: EnvKeyInput): EnvaptAccessorDecorator<boolean | undefined>;\nexport function EnvBool(key: EnvKeyInput, fallback?: boolean): EnvaptAccessorDecorator<boolean | undefined> {\n return sugar(Converters.Boolean, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Number, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvNum(key: EnvKeyInput, fallback: number): EnvaptAccessorDecorator<number>;\nexport function EnvNum(key: EnvKeyInput): EnvaptAccessorDecorator<number | undefined>;\nexport function EnvNum(key: EnvKeyInput, fallback?: number): EnvaptAccessorDecorator<number | undefined> {\n return sugar(Converters.Number, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.String, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvStr(key: EnvKeyInput, fallback: string): EnvaptAccessorDecorator<string>;\nexport function EnvStr(key: EnvKeyInput): EnvaptAccessorDecorator<string | undefined>;\nexport function EnvStr(key: EnvKeyInput, fallback?: string): EnvaptAccessorDecorator<string | undefined> {\n return sugar(Converters.String, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Time, fallback })`. The fallback is a\n * millisecond number or a time string (`'15m'`), and the resolved value is always milliseconds.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvTime(key: EnvKeyInput, fallback: TimeFallback): EnvaptAccessorDecorator<number>;\nexport function EnvTime(key: EnvKeyInput): EnvaptAccessorDecorator<number | undefined>;\nexport function EnvTime(key: EnvKeyInput, fallback?: TimeFallback): EnvaptAccessorDecorator<number | undefined> {\n return sugar(Converters.Time, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Url, fallback })`. The fallback must be a\n * `URL` instance.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvUrl(key: EnvKeyInput, fallback: URL): EnvaptAccessorDecorator<URL>;\nexport function EnvUrl(key: EnvKeyInput): EnvaptAccessorDecorator<URL | undefined>;\nexport function EnvUrl(key: EnvKeyInput, fallback?: URL): EnvaptAccessorDecorator<URL | undefined> {\n return sugar(Converters.Url, key, fallback);\n}\n/* v8 ignore stop */\n"],"mappings":"8FAOA,SAAS,EACL,EACA,EACA,EACkC,CAElC,OAAOA,EAAAA,wBAAmC,EAAK,CAC3C,YACA,WACA,YAAa,IAAa,IAAA,GAC1B,SAAU,GACV,OAAQ,IAAA,EACZ,CAAC,CACL,CASA,SAAgB,EAAQ,EAAkB,EAAkE,CACxG,OAAO,EAAMC,EAAAA,WAAW,QAAS,EAAK,CAAQ,CAClD,CASA,SAAgB,EAAO,EAAkB,EAAgE,CACrG,OAAO,EAAMA,EAAAA,WAAW,OAAQ,EAAK,CAAQ,CACjD,CASA,SAAgB,EAAO,EAAkB,EAAgE,CACrG,OAAO,EAAMA,EAAAA,WAAW,OAAQ,EAAK,CAAQ,CACjD,CAUA,SAAgB,EAAQ,EAAkB,EAAsE,CAC5G,OAAO,EAAMA,EAAAA,WAAW,KAAM,EAAK,CAAQ,CAC/C,CAUA,SAAgB,EAAO,EAAkB,EAA0D,CAC/F,OAAO,EAAMA,EAAAA,WAAW,IAAK,EAAK,CAAQ,CAC9C"}
@@ -1 +1 @@
1
- {"version":3,"file":"SugarDecorators.mjs","names":[],"sources":["../../../../src/decorators/modern/SugarDecorators.ts"],"sourcesContent":["import { createAccessorDecorator } from './createAccessorDecorator';\nimport { Converters } from '../../converters';\n\nimport type { ConverterToken } from '../../converters';\nimport type { EnvaptAccessorDecorator, EnvKeyInput, TimeFallback } from '../../types';\n\n/* v8 ignore start -- @preserve oxc (vitest's transform) breaks modern accessor decorators (context.name unset), so the tsc stage3-emit harness covers these, not vitest */\nfunction sugar<TFallback>(\n converter: ConverterToken,\n key: EnvKeyInput,\n fallback: TFallback | undefined\n): EnvaptAccessorDecorator<TFallback> {\n // the runtime installer is a plain accessor decorator, so the cast only adds a\n // compile-time field-type constraint with no runtime counterpart\n return createAccessorDecorator<TFallback>(key, {\n converter,\n fallback,\n hasFallback: fallback !== undefined,\n required: false,\n schema: undefined\n }) as EnvaptAccessorDecorator<TFallback>;\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Boolean, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvBool(key: EnvKeyInput, fallback: boolean): EnvaptAccessorDecorator<boolean>;\nexport function EnvBool(key: EnvKeyInput): EnvaptAccessorDecorator<boolean | undefined>;\nexport function EnvBool(key: EnvKeyInput, fallback?: boolean): EnvaptAccessorDecorator<boolean | undefined> {\n return sugar(Converters.Boolean, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Number, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvNum(key: EnvKeyInput, fallback: number): EnvaptAccessorDecorator<number>;\nexport function EnvNum(key: EnvKeyInput): EnvaptAccessorDecorator<number | undefined>;\nexport function EnvNum(key: EnvKeyInput, fallback?: number): EnvaptAccessorDecorator<number | undefined> {\n return sugar(Converters.Number, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.String, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvStr(key: EnvKeyInput, fallback: string): EnvaptAccessorDecorator<string>;\nexport function EnvStr(key: EnvKeyInput): EnvaptAccessorDecorator<string | undefined>;\nexport function EnvStr(key: EnvKeyInput, fallback?: string): EnvaptAccessorDecorator<string | undefined> {\n return sugar(Converters.String, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Time, fallback })`. The fallback is a\n * millisecond number or a time string (`'15m'`), and the resolved value is always milliseconds.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvTime(key: EnvKeyInput, fallback: TimeFallback): EnvaptAccessorDecorator<number>;\nexport function EnvTime(key: EnvKeyInput): EnvaptAccessorDecorator<number | undefined>;\nexport function EnvTime(key: EnvKeyInput, fallback?: TimeFallback): EnvaptAccessorDecorator<number | undefined> {\n return sugar(Converters.Time, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Url, fallback })`. The fallback is a `URL`\n * instance, not a URL string.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvUrl(key: EnvKeyInput, fallback: URL): EnvaptAccessorDecorator<URL>;\nexport function EnvUrl(key: EnvKeyInput): EnvaptAccessorDecorator<URL | undefined>;\nexport function EnvUrl(key: EnvKeyInput, fallback?: URL): EnvaptAccessorDecorator<URL | undefined> {\n return sugar(Converters.Url, key, fallback);\n}\n/* v8 ignore stop */\n"],"mappings":"qIAOA,SAAS,EACL,EACA,EACA,EACkC,CAGlC,OAAO,EAAmC,EAAK,CAC3C,YACA,WACA,YAAa,IAAa,IAAA,GAC1B,SAAU,GACV,OAAQ,IAAA,EACZ,CAAC,CACL,CASA,SAAgB,EAAQ,EAAkB,EAAkE,CACxG,OAAO,EAAM,EAAW,QAAS,EAAK,CAAQ,CAClD,CASA,SAAgB,EAAO,EAAkB,EAAgE,CACrG,OAAO,EAAM,EAAW,OAAQ,EAAK,CAAQ,CACjD,CASA,SAAgB,EAAO,EAAkB,EAAgE,CACrG,OAAO,EAAM,EAAW,OAAQ,EAAK,CAAQ,CACjD,CAUA,SAAgB,EAAQ,EAAkB,EAAsE,CAC5G,OAAO,EAAM,EAAW,KAAM,EAAK,CAAQ,CAC/C,CAUA,SAAgB,EAAO,EAAkB,EAA0D,CAC/F,OAAO,EAAM,EAAW,IAAK,EAAK,CAAQ,CAC9C"}
1
+ {"version":3,"file":"SugarDecorators.mjs","names":[],"sources":["../../../../src/decorators/modern/SugarDecorators.ts"],"sourcesContent":["import { createAccessorDecorator } from './createAccessorDecorator';\nimport { Converters } from '../../converters';\n\nimport type { ConverterToken } from '../../converters';\nimport type { EnvaptAccessorDecorator, EnvKeyInput, TimeFallback } from '../../types';\n\n/* v8 ignore start -- @preserve the tsc stage3-emit tests cover these because oxc (vitest's transform) leaves context.name unset on modern accessor decorators */\nfunction sugar<TFallback>(\n converter: ConverterToken,\n key: EnvKeyInput,\n fallback: TFallback | undefined\n): EnvaptAccessorDecorator<TFallback> {\n // the cast only adds a compile-time check on the field type\n return createAccessorDecorator<TFallback>(key, {\n converter,\n fallback,\n hasFallback: fallback !== undefined,\n required: false,\n schema: undefined\n }) as EnvaptAccessorDecorator<TFallback>;\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Boolean, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvBool(key: EnvKeyInput, fallback: boolean): EnvaptAccessorDecorator<boolean>;\nexport function EnvBool(key: EnvKeyInput): EnvaptAccessorDecorator<boolean | undefined>;\nexport function EnvBool(key: EnvKeyInput, fallback?: boolean): EnvaptAccessorDecorator<boolean | undefined> {\n return sugar(Converters.Boolean, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Number, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvNum(key: EnvKeyInput, fallback: number): EnvaptAccessorDecorator<number>;\nexport function EnvNum(key: EnvKeyInput): EnvaptAccessorDecorator<number | undefined>;\nexport function EnvNum(key: EnvKeyInput, fallback?: number): EnvaptAccessorDecorator<number | undefined> {\n return sugar(Converters.Number, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.String, fallback })`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvStr(key: EnvKeyInput, fallback: string): EnvaptAccessorDecorator<string>;\nexport function EnvStr(key: EnvKeyInput): EnvaptAccessorDecorator<string | undefined>;\nexport function EnvStr(key: EnvKeyInput, fallback?: string): EnvaptAccessorDecorator<string | undefined> {\n return sugar(Converters.String, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Time, fallback })`. The fallback is a\n * millisecond number or a time string (`'15m'`), and the resolved value is always milliseconds.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvTime(key: EnvKeyInput, fallback: TimeFallback): EnvaptAccessorDecorator<number>;\nexport function EnvTime(key: EnvKeyInput): EnvaptAccessorDecorator<number | undefined>;\nexport function EnvTime(key: EnvKeyInput, fallback?: TimeFallback): EnvaptAccessorDecorator<number | undefined> {\n return sugar(Converters.Time, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Url, fallback })`. The fallback must be a\n * `URL` instance.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/decorators#shorthand-decorators}\n */\nexport function EnvUrl(key: EnvKeyInput, fallback: URL): EnvaptAccessorDecorator<URL>;\nexport function EnvUrl(key: EnvKeyInput): EnvaptAccessorDecorator<URL | undefined>;\nexport function EnvUrl(key: EnvKeyInput, fallback?: URL): EnvaptAccessorDecorator<URL | undefined> {\n return sugar(Converters.Url, key, fallback);\n}\n/* v8 ignore stop */\n"],"mappings":"qIAOA,SAAS,EACL,EACA,EACA,EACkC,CAElC,OAAO,EAAmC,EAAK,CAC3C,YACA,WACA,YAAa,IAAa,IAAA,GAC1B,SAAU,GACV,OAAQ,IAAA,EACZ,CAAC,CACL,CASA,SAAgB,EAAQ,EAAkB,EAAkE,CACxG,OAAO,EAAM,EAAW,QAAS,EAAK,CAAQ,CAClD,CASA,SAAgB,EAAO,EAAkB,EAAgE,CACrG,OAAO,EAAM,EAAW,OAAQ,EAAK,CAAQ,CACjD,CASA,SAAgB,EAAO,EAAkB,EAAgE,CACrG,OAAO,EAAM,EAAW,OAAQ,EAAK,CAAQ,CACjD,CAUA,SAAgB,EAAQ,EAAkB,EAAsE,CAC5G,OAAO,EAAM,EAAW,KAAM,EAAK,CAAQ,CAC/C,CAUA,SAAgB,EAAO,EAAkB,EAA0D,CAC/F,OAAO,EAAM,EAAW,IAAK,EAAK,CAAQ,CAC9C"}
@@ -1 +1 @@
1
- {"version":3,"file":"createAccessorDecorator.cjs","names":["EnvaptError","decoratorCacheKey","resolveDecoratorValue"],"sources":["../../../../src/decorators/modern/createAccessorDecorator.ts"],"sourcesContent":["import { EnvaptError, EnvaptErrorCodes } from '../../infra/Error';\nimport { decoratorCacheKey, resolveDecoratorValue } from '../resolveDecoratorValue';\n\nimport type { EnvKeyInput } from '../../types';\nimport type { DecoratorConfig } from '../resolveDecoratorValue';\n\n/* v8 ignore start -- @preserve oxc (vitest's transform) breaks modern accessor decorators (context.name unset), so the tsc stage3-emit harness covers these, not vitest */\nexport function createAccessorDecorator<TFallback>(key: EnvKeyInput, config: DecoratorConfig<TFallback>) {\n return function <This, Value>(\n _target: ClassAccessorDecoratorTarget<This, Value>,\n context: ClassAccessorDecoratorContext<This, Value>\n ): ClassAccessorDecoratorResult<This, Value> {\n const name: string | symbol | undefined = context.name;\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- a broken Stage 3 transform can leave context.name unset, which would collapse every accessor to one cache key\n if (name === undefined) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n 'The runtime did not provide the accessor name to @Envapt, this Stage 3 decorator transform is unsupported.'\n );\n }\n const propKey = String(name);\n\n return {\n get(this: This): Value {\n const self = this as object;\n // derive static-ness from `this` (the class is a function, an instance is not) rather than\n // context.static, which some transformers (oxc) leave unset, collapsing every owner to Function\n const isStatic = typeof self === 'function';\n const owner = isStatic ? self : self.constructor;\n const cacheKey = decoratorCacheKey(owner, isStatic, propKey);\n return resolveDecoratorValue(key, config, cacheKey) as Value;\n },\n set(): void {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Cannot assign to \"${propKey}\". @Envapt accessor properties resolve from the environment and are read-only.`\n );\n }\n };\n };\n}\n/* v8 ignore stop */\n"],"mappings":"mFAOA,SAAgB,EAAmC,EAAkB,EAAoC,CACrG,OAAO,SACH,EACA,EACyC,CACzC,IAAM,EAAoC,EAAQ,KAElD,GAAI,IAAS,IAAA,GACT,MAAM,IAAIA,EAAAA,YAAAA,IAEN,4GACJ,EAEJ,IAAM,EAAU,OAAO,CAAI,EAE3B,MAAO,CACH,KAAuB,CACnB,IAAM,EAAO,KAGP,EAAW,OAAO,GAAS,WAC3B,EAAQ,EAAW,EAAO,EAAK,YAC/B,EAAWC,EAAAA,kBAAkB,EAAO,EAAU,CAAO,EAC3D,OAAOC,EAAAA,sBAAsB,EAAK,EAAQ,CAAQ,CACtD,EACA,KAAY,CACR,MAAM,IAAIF,EAAAA,YAAAA,IAEN,qBAAqB,EAAQ,+EACjC,CACJ,CACJ,CACJ,CACJ"}
1
+ {"version":3,"file":"createAccessorDecorator.cjs","names":["EnvaptError","decoratorCacheKey","resolveDecoratorValue"],"sources":["../../../../src/decorators/modern/createAccessorDecorator.ts"],"sourcesContent":["import { EnvaptError, EnvaptErrorCodes } from '../../infra/Error';\nimport { decoratorCacheKey, resolveDecoratorValue } from '../resolveDecoratorValue';\n\nimport type { EnvKeyInput } from '../../types';\nimport type { DecoratorConfig } from '../resolveDecoratorValue';\n\n/* v8 ignore start -- @preserve the tsc stage3-emit tests cover these because oxc (vitest's transform) leaves context.name unset on modern accessor decorators */\nexport function createAccessorDecorator<TFallback>(key: EnvKeyInput, config: DecoratorConfig<TFallback>) {\n return function <This, Value>(\n _target: ClassAccessorDecoratorTarget<This, Value>,\n context: ClassAccessorDecoratorContext<This, Value>\n ): ClassAccessorDecoratorResult<This, Value> {\n const name: string | symbol | undefined = context.name;\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- a broken Stage 3 transform can leave context.name unset, which would collapse every accessor to one cache key\n if (name === undefined) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n 'The runtime did not provide the accessor name to @Envapt, this Stage 3 decorator transform is unsupported.'\n );\n }\n const propKey = String(name);\n\n return {\n get(this: This): Value {\n const self = this as object;\n // some transforms (oxc) leave context.static unset\n const isStatic = typeof self === 'function';\n const owner = isStatic ? self : self.constructor;\n const cacheKey = decoratorCacheKey(owner, isStatic, propKey);\n return resolveDecoratorValue(key, config, cacheKey) as Value;\n },\n set(): void {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Cannot assign to \"${propKey}\". @Envapt accessor properties resolve from the environment and are read-only.`\n );\n }\n };\n };\n}\n/* v8 ignore stop */\n"],"mappings":"mFAOA,SAAgB,EAAmC,EAAkB,EAAoC,CACrG,OAAO,SACH,EACA,EACyC,CACzC,IAAM,EAAoC,EAAQ,KAElD,GAAI,IAAS,IAAA,GACT,MAAM,IAAIA,EAAAA,YAAAA,IAEN,4GACJ,EAEJ,IAAM,EAAU,OAAO,CAAI,EAE3B,MAAO,CACH,KAAuB,CACnB,IAAM,EAAO,KAEP,EAAW,OAAO,GAAS,WAC3B,EAAQ,EAAW,EAAO,EAAK,YAC/B,EAAWC,EAAAA,kBAAkB,EAAO,EAAU,CAAO,EAC3D,OAAOC,EAAAA,sBAAsB,EAAK,EAAQ,CAAQ,CACtD,EACA,KAAY,CACR,MAAM,IAAIF,EAAAA,YAAAA,IAEN,qBAAqB,EAAQ,+EACjC,CACJ,CACJ,CACJ,CACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"createAccessorDecorator.mjs","names":[],"sources":["../../../../src/decorators/modern/createAccessorDecorator.ts"],"sourcesContent":["import { EnvaptError, EnvaptErrorCodes } from '../../infra/Error';\nimport { decoratorCacheKey, resolveDecoratorValue } from '../resolveDecoratorValue';\n\nimport type { EnvKeyInput } from '../../types';\nimport type { DecoratorConfig } from '../resolveDecoratorValue';\n\n/* v8 ignore start -- @preserve oxc (vitest's transform) breaks modern accessor decorators (context.name unset), so the tsc stage3-emit harness covers these, not vitest */\nexport function createAccessorDecorator<TFallback>(key: EnvKeyInput, config: DecoratorConfig<TFallback>) {\n return function <This, Value>(\n _target: ClassAccessorDecoratorTarget<This, Value>,\n context: ClassAccessorDecoratorContext<This, Value>\n ): ClassAccessorDecoratorResult<This, Value> {\n const name: string | symbol | undefined = context.name;\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- a broken Stage 3 transform can leave context.name unset, which would collapse every accessor to one cache key\n if (name === undefined) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n 'The runtime did not provide the accessor name to @Envapt, this Stage 3 decorator transform is unsupported.'\n );\n }\n const propKey = String(name);\n\n return {\n get(this: This): Value {\n const self = this as object;\n // derive static-ness from `this` (the class is a function, an instance is not) rather than\n // context.static, which some transformers (oxc) leave unset, collapsing every owner to Function\n const isStatic = typeof self === 'function';\n const owner = isStatic ? self : self.constructor;\n const cacheKey = decoratorCacheKey(owner, isStatic, propKey);\n return resolveDecoratorValue(key, config, cacheKey) as Value;\n },\n set(): void {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Cannot assign to \"${propKey}\". @Envapt accessor properties resolve from the environment and are read-only.`\n );\n }\n };\n };\n}\n/* v8 ignore stop */\n"],"mappings":"gJAOA,SAAgB,EAAmC,EAAkB,EAAoC,CACrG,OAAO,SACH,EACA,EACyC,CACzC,IAAM,EAAoC,EAAQ,KAElD,GAAI,IAAS,IAAA,GACT,MAAM,IAAI,EAAA,IAEN,4GACJ,EAEJ,IAAM,EAAU,OAAO,CAAI,EAE3B,MAAO,CACH,KAAuB,CACnB,IAAM,EAAO,KAGP,EAAW,OAAO,GAAS,WAC3B,EAAQ,EAAW,EAAO,EAAK,YAC/B,EAAW,EAAkB,EAAO,EAAU,CAAO,EAC3D,OAAO,EAAsB,EAAK,EAAQ,CAAQ,CACtD,EACA,KAAY,CACR,MAAM,IAAI,EAAA,IAEN,qBAAqB,EAAQ,+EACjC,CACJ,CACJ,CACJ,CACJ"}
1
+ {"version":3,"file":"createAccessorDecorator.mjs","names":[],"sources":["../../../../src/decorators/modern/createAccessorDecorator.ts"],"sourcesContent":["import { EnvaptError, EnvaptErrorCodes } from '../../infra/Error';\nimport { decoratorCacheKey, resolveDecoratorValue } from '../resolveDecoratorValue';\n\nimport type { EnvKeyInput } from '../../types';\nimport type { DecoratorConfig } from '../resolveDecoratorValue';\n\n/* v8 ignore start -- @preserve the tsc stage3-emit tests cover these because oxc (vitest's transform) leaves context.name unset on modern accessor decorators */\nexport function createAccessorDecorator<TFallback>(key: EnvKeyInput, config: DecoratorConfig<TFallback>) {\n return function <This, Value>(\n _target: ClassAccessorDecoratorTarget<This, Value>,\n context: ClassAccessorDecoratorContext<This, Value>\n ): ClassAccessorDecoratorResult<This, Value> {\n const name: string | symbol | undefined = context.name;\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- a broken Stage 3 transform can leave context.name unset, which would collapse every accessor to one cache key\n if (name === undefined) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n 'The runtime did not provide the accessor name to @Envapt, this Stage 3 decorator transform is unsupported.'\n );\n }\n const propKey = String(name);\n\n return {\n get(this: This): Value {\n const self = this as object;\n // some transforms (oxc) leave context.static unset\n const isStatic = typeof self === 'function';\n const owner = isStatic ? self : self.constructor;\n const cacheKey = decoratorCacheKey(owner, isStatic, propKey);\n return resolveDecoratorValue(key, config, cacheKey) as Value;\n },\n set(): void {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Cannot assign to \"${propKey}\". @Envapt accessor properties resolve from the environment and are read-only.`\n );\n }\n };\n };\n}\n/* v8 ignore stop */\n"],"mappings":"gJAOA,SAAgB,EAAmC,EAAkB,EAAoC,CACrG,OAAO,SACH,EACA,EACyC,CACzC,IAAM,EAAoC,EAAQ,KAElD,GAAI,IAAS,IAAA,GACT,MAAM,IAAI,EAAA,IAEN,4GACJ,EAEJ,IAAM,EAAU,OAAO,CAAI,EAE3B,MAAO,CACH,KAAuB,CACnB,IAAM,EAAO,KAEP,EAAW,OAAO,GAAS,WAC3B,EAAQ,EAAW,EAAO,EAAK,YAC/B,EAAW,EAAkB,EAAO,EAAU,CAAO,EAC3D,OAAO,EAAsB,EAAK,EAAQ,CAAQ,CACtD,EACA,KAAY,CACR,MAAM,IAAI,EAAA,IAEN,qBAAqB,EAAQ,+EACjC,CACJ,CACJ,CACJ,CACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"resolveDecoratorValue.cjs","names":["cache","Envapter","isMissing","EnvaptError","ValueConverter"],"sources":["../../../src/decorators/resolveDecoratorValue.ts"],"sourcesContent":["import { ValueConverter } from '../converters';\nimport { isMissing } from '../core/missing';\nimport { cache } from '../core/state';\nimport { Envapter } from '../engine/Envapter';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { StandardSchemaV1 } from '../infra/StandardSchema';\nimport type { EnvaptConverter, EnvKeyInput } from '../types';\n\nexport interface DecoratorConfig<TFallback> {\n fallback: TFallback | undefined;\n converter: EnvaptConverter<TFallback> | undefined;\n hasFallback: boolean;\n required: boolean;\n schema: StandardSchemaV1 | undefined;\n}\n\nfunction formatKeyForError(key: EnvKeyInput): string {\n return Array.isArray(key) ? `[${key.join(', ')}]` : String(key);\n}\n\nconst classIds = new WeakMap<object, number>();\nlet nextClassId = 0;\n\n// keyed on the constructor object's identity so two same-named classes (and a same-named\n// static/instance pair) stay in separate cache slots\nexport function decoratorCacheKey(owner: object, isStatic: boolean, prop: string): string {\n let id = classIds.get(owner);\n if (id === undefined) {\n id = nextClassId++;\n classIds.set(owner, id);\n }\n return `${id}.${isStatic ? 'static' : 'instance'}.${prop}`;\n}\n\nexport function resolveDecoratorValue<TFallback>(\n key: EnvKeyInput,\n config: DecoratorConfig<TFallback>,\n cacheKey: string\n): TFallback | undefined {\n const { fallback, converter, hasFallback, required, schema } = config;\n\n // cache.has guards the read so a cached undefined counts as resolved (a converter returning\n // undefined, or a missing no-fallback read) and later accesses skip re-resolving\n if (cache.has(cacheKey)) return cache.get(cacheKey) as TFallback | undefined;\n\n const envapter = new Envapter();\n\n if (required && schema === undefined) {\n const rawValue = envapter.getRaw(key);\n if (isMissing(rawValue)) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Required environment variable \"${formatKeyForError(key)}\" is missing or empty.`\n );\n }\n }\n\n const valueConverter = new ValueConverter(envapter);\n const value =\n schema !== undefined\n ? (valueConverter.convertWithSchema(key, schema, fallback, hasFallback) as TFallback)\n : valueConverter.convertValue(key, fallback, converter, hasFallback);\n\n cache.set(cacheKey, value);\n return value;\n}\n"],"mappings":"wLAiBA,SAAS,EAAkB,EAA0B,CACjD,OAAO,MAAM,QAAQ,CAAG,EAAI,IAAI,EAAI,KAAK,IAAI,EAAE,GAAK,OAAO,CAAG,CAClE,CAEA,MAAM,EAAW,IAAI,QACrB,IAAI,EAAc,EAIlB,SAAgB,EAAkB,EAAe,EAAmB,EAAsB,CACtF,IAAI,EAAK,EAAS,IAAI,CAAK,EAK3B,OAJI,IAAO,IAAA,KACP,EAAK,IACL,EAAS,IAAI,EAAO,CAAE,GAEnB,GAAG,EAAG,GAAG,EAAW,SAAW,WAAW,GAAG,GACxD,CAEA,SAAgB,EACZ,EACA,EACA,EACqB,CACrB,GAAM,CAAE,WAAU,YAAW,cAAa,WAAU,UAAW,EAI/D,GAAIA,EAAAA,MAAM,IAAI,CAAQ,EAAG,OAAOA,EAAAA,MAAM,IAAI,CAAQ,EAElD,IAAM,EAAW,IAAIC,EAAAA,SAErB,GAAI,GAAY,IAAW,IAAA,GAAW,CAClC,IAAM,EAAW,EAAS,OAAO,CAAG,EACpC,GAAIC,EAAAA,UAAU,CAAQ,EAClB,MAAM,IAAIC,EAAAA,YAAAA,IAEN,kCAAkC,EAAkB,CAAG,EAAE,uBAC7D,CAER,CAEA,IAAM,EAAiB,IAAIC,EAAAA,eAAe,CAAQ,EAC5C,EACF,IAAW,IAAA,GAEL,EAAe,aAAa,EAAK,EAAU,EAAW,CAAW,EADhE,EAAe,kBAAkB,EAAK,EAAQ,EAAU,CAAW,EAI9E,OADA,EAAA,MAAM,IAAI,EAAU,CAAK,EAClB,CACX"}
1
+ {"version":3,"file":"resolveDecoratorValue.cjs","names":["cache","Envapter","isMissing","EnvaptError","ValueConverter"],"sources":["../../../src/decorators/resolveDecoratorValue.ts"],"sourcesContent":["import { ValueConverter } from '../converters';\nimport { isMissing } from '../core/missing';\nimport { cache } from '../core/state';\nimport { Envapter } from '../engine/Envapter';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { StandardSchemaV1 } from '../infra/StandardSchema';\nimport type { EnvaptConverter, EnvKeyInput } from '../types';\n\nexport interface DecoratorConfig<TFallback> {\n fallback: TFallback | undefined;\n converter: EnvaptConverter<TFallback> | undefined;\n hasFallback: boolean;\n required: boolean;\n schema: StandardSchemaV1 | undefined;\n}\n\nfunction formatKeyForError(key: EnvKeyInput): string {\n return Array.isArray(key) ? `[${key.join(', ')}]` : String(key);\n}\n\nconst classIds = new WeakMap<object, number>();\nlet nextClassId = 0;\n\n// keyed on the class object because two classes can share a name\nexport function decoratorCacheKey(owner: object, isStatic: boolean, prop: string): string {\n let id = classIds.get(owner);\n if (id === undefined) {\n id = nextClassId++;\n classIds.set(owner, id);\n }\n return `${id}.${isStatic ? 'static' : 'instance'}.${prop}`;\n}\n\nexport function resolveDecoratorValue<TFallback>(\n key: EnvKeyInput,\n config: DecoratorConfig<TFallback>,\n cacheKey: string\n): TFallback | undefined {\n const { fallback, converter, hasFallback, required, schema } = config;\n\n // has() because a resolved value can be undefined\n if (cache.has(cacheKey)) return cache.get(cacheKey) as TFallback | undefined;\n\n const envapter = new Envapter();\n\n if (required && schema === undefined) {\n const rawValue = envapter.getRaw(key);\n if (isMissing(rawValue)) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Required environment variable \"${formatKeyForError(key)}\" is missing or empty.`\n );\n }\n }\n\n const valueConverter = new ValueConverter(envapter);\n const value =\n schema !== undefined\n ? (valueConverter.convertWithSchema(key, schema, fallback, hasFallback) as TFallback)\n : valueConverter.convertValue(key, fallback, converter, hasFallback);\n\n cache.set(cacheKey, value);\n return value;\n}\n"],"mappings":"wLAiBA,SAAS,EAAkB,EAA0B,CACjD,OAAO,MAAM,QAAQ,CAAG,EAAI,IAAI,EAAI,KAAK,IAAI,EAAE,GAAK,OAAO,CAAG,CAClE,CAEA,MAAM,EAAW,IAAI,QACrB,IAAI,EAAc,EAGlB,SAAgB,EAAkB,EAAe,EAAmB,EAAsB,CACtF,IAAI,EAAK,EAAS,IAAI,CAAK,EAK3B,OAJI,IAAO,IAAA,KACP,EAAK,IACL,EAAS,IAAI,EAAO,CAAE,GAEnB,GAAG,EAAG,GAAG,EAAW,SAAW,WAAW,GAAG,GACxD,CAEA,SAAgB,EACZ,EACA,EACA,EACqB,CACrB,GAAM,CAAE,WAAU,YAAW,cAAa,WAAU,UAAW,EAG/D,GAAIA,EAAAA,MAAM,IAAI,CAAQ,EAAG,OAAOA,EAAAA,MAAM,IAAI,CAAQ,EAElD,IAAM,EAAW,IAAIC,EAAAA,SAErB,GAAI,GAAY,IAAW,IAAA,GAAW,CAClC,IAAM,EAAW,EAAS,OAAO,CAAG,EACpC,GAAIC,EAAAA,UAAU,CAAQ,EAClB,MAAM,IAAIC,EAAAA,YAAAA,IAEN,kCAAkC,EAAkB,CAAG,EAAE,uBAC7D,CAER,CAEA,IAAM,EAAiB,IAAIC,EAAAA,eAAe,CAAQ,EAC5C,EACF,IAAW,IAAA,GAEL,EAAe,aAAa,EAAK,EAAU,EAAW,CAAW,EADhE,EAAe,kBAAkB,EAAK,EAAQ,EAAU,CAAW,EAI9E,OADA,EAAA,MAAM,IAAI,EAAU,CAAK,EAClB,CACX"}
@@ -1 +1 @@
1
- {"version":3,"file":"resolveDecoratorValue.mjs","names":[],"sources":["../../../src/decorators/resolveDecoratorValue.ts"],"sourcesContent":["import { ValueConverter } from '../converters';\nimport { isMissing } from '../core/missing';\nimport { cache } from '../core/state';\nimport { Envapter } from '../engine/Envapter';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { StandardSchemaV1 } from '../infra/StandardSchema';\nimport type { EnvaptConverter, EnvKeyInput } from '../types';\n\nexport interface DecoratorConfig<TFallback> {\n fallback: TFallback | undefined;\n converter: EnvaptConverter<TFallback> | undefined;\n hasFallback: boolean;\n required: boolean;\n schema: StandardSchemaV1 | undefined;\n}\n\nfunction formatKeyForError(key: EnvKeyInput): string {\n return Array.isArray(key) ? `[${key.join(', ')}]` : String(key);\n}\n\nconst classIds = new WeakMap<object, number>();\nlet nextClassId = 0;\n\n// keyed on the constructor object's identity so two same-named classes (and a same-named\n// static/instance pair) stay in separate cache slots\nexport function decoratorCacheKey(owner: object, isStatic: boolean, prop: string): string {\n let id = classIds.get(owner);\n if (id === undefined) {\n id = nextClassId++;\n classIds.set(owner, id);\n }\n return `${id}.${isStatic ? 'static' : 'instance'}.${prop}`;\n}\n\nexport function resolveDecoratorValue<TFallback>(\n key: EnvKeyInput,\n config: DecoratorConfig<TFallback>,\n cacheKey: string\n): TFallback | undefined {\n const { fallback, converter, hasFallback, required, schema } = config;\n\n // cache.has guards the read so a cached undefined counts as resolved (a converter returning\n // undefined, or a missing no-fallback read) and later accesses skip re-resolving\n if (cache.has(cacheKey)) return cache.get(cacheKey) as TFallback | undefined;\n\n const envapter = new Envapter();\n\n if (required && schema === undefined) {\n const rawValue = envapter.getRaw(key);\n if (isMissing(rawValue)) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Required environment variable \"${formatKeyForError(key)}\" is missing or empty.`\n );\n }\n }\n\n const valueConverter = new ValueConverter(envapter);\n const value =\n schema !== undefined\n ? (valueConverter.convertWithSchema(key, schema, fallback, hasFallback) as TFallback)\n : valueConverter.convertValue(key, fallback, converter, hasFallback);\n\n cache.set(cacheKey, value);\n return value;\n}\n"],"mappings":"+PAiBA,SAAS,EAAkB,EAA0B,CACjD,OAAO,MAAM,QAAQ,CAAG,EAAI,IAAI,EAAI,KAAK,IAAI,EAAE,GAAK,OAAO,CAAG,CAClE,CAEA,MAAM,EAAW,IAAI,QACrB,IAAI,EAAc,EAIlB,SAAgB,EAAkB,EAAe,EAAmB,EAAsB,CACtF,IAAI,EAAK,EAAS,IAAI,CAAK,EAK3B,OAJI,IAAO,IAAA,KACP,EAAK,IACL,EAAS,IAAI,EAAO,CAAE,GAEnB,GAAG,EAAG,GAAG,EAAW,SAAW,WAAW,GAAG,GACxD,CAEA,SAAgB,EACZ,EACA,EACA,EACqB,CACrB,GAAM,CAAE,WAAU,YAAW,cAAa,WAAU,UAAW,EAI/D,GAAI,EAAM,IAAI,CAAQ,EAAG,OAAO,EAAM,IAAI,CAAQ,EAElD,IAAM,EAAW,IAAI,EAErB,GAAI,GAAY,IAAW,IAAA,GAAW,CAClC,IAAM,EAAW,EAAS,OAAO,CAAG,EACpC,GAAI,EAAU,CAAQ,EAClB,MAAM,IAAI,EAAA,IAEN,kCAAkC,EAAkB,CAAG,EAAE,uBAC7D,CAER,CAEA,IAAM,EAAiB,IAAI,EAAe,CAAQ,EAC5C,EACF,IAAW,IAAA,GAEL,EAAe,aAAa,EAAK,EAAU,EAAW,CAAW,EADhE,EAAe,kBAAkB,EAAK,EAAQ,EAAU,CAAW,EAI9E,OADA,EAAM,IAAI,EAAU,CAAK,EAClB,CACX"}
1
+ {"version":3,"file":"resolveDecoratorValue.mjs","names":[],"sources":["../../../src/decorators/resolveDecoratorValue.ts"],"sourcesContent":["import { ValueConverter } from '../converters';\nimport { isMissing } from '../core/missing';\nimport { cache } from '../core/state';\nimport { Envapter } from '../engine/Envapter';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { StandardSchemaV1 } from '../infra/StandardSchema';\nimport type { EnvaptConverter, EnvKeyInput } from '../types';\n\nexport interface DecoratorConfig<TFallback> {\n fallback: TFallback | undefined;\n converter: EnvaptConverter<TFallback> | undefined;\n hasFallback: boolean;\n required: boolean;\n schema: StandardSchemaV1 | undefined;\n}\n\nfunction formatKeyForError(key: EnvKeyInput): string {\n return Array.isArray(key) ? `[${key.join(', ')}]` : String(key);\n}\n\nconst classIds = new WeakMap<object, number>();\nlet nextClassId = 0;\n\n// keyed on the class object because two classes can share a name\nexport function decoratorCacheKey(owner: object, isStatic: boolean, prop: string): string {\n let id = classIds.get(owner);\n if (id === undefined) {\n id = nextClassId++;\n classIds.set(owner, id);\n }\n return `${id}.${isStatic ? 'static' : 'instance'}.${prop}`;\n}\n\nexport function resolveDecoratorValue<TFallback>(\n key: EnvKeyInput,\n config: DecoratorConfig<TFallback>,\n cacheKey: string\n): TFallback | undefined {\n const { fallback, converter, hasFallback, required, schema } = config;\n\n // has() because a resolved value can be undefined\n if (cache.has(cacheKey)) return cache.get(cacheKey) as TFallback | undefined;\n\n const envapter = new Envapter();\n\n if (required && schema === undefined) {\n const rawValue = envapter.getRaw(key);\n if (isMissing(rawValue)) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Required environment variable \"${formatKeyForError(key)}\" is missing or empty.`\n );\n }\n }\n\n const valueConverter = new ValueConverter(envapter);\n const value =\n schema !== undefined\n ? (valueConverter.convertWithSchema(key, schema, fallback, hasFallback) as TFallback)\n : valueConverter.convertValue(key, fallback, converter, hasFallback);\n\n cache.set(cacheKey, value);\n return value;\n}\n"],"mappings":"+PAiBA,SAAS,EAAkB,EAA0B,CACjD,OAAO,MAAM,QAAQ,CAAG,EAAI,IAAI,EAAI,KAAK,IAAI,EAAE,GAAK,OAAO,CAAG,CAClE,CAEA,MAAM,EAAW,IAAI,QACrB,IAAI,EAAc,EAGlB,SAAgB,EAAkB,EAAe,EAAmB,EAAsB,CACtF,IAAI,EAAK,EAAS,IAAI,CAAK,EAK3B,OAJI,IAAO,IAAA,KACP,EAAK,IACL,EAAS,IAAI,EAAO,CAAE,GAEnB,GAAG,EAAG,GAAG,EAAW,SAAW,WAAW,GAAG,GACxD,CAEA,SAAgB,EACZ,EACA,EACA,EACqB,CACrB,GAAM,CAAE,WAAU,YAAW,cAAa,WAAU,UAAW,EAG/D,GAAI,EAAM,IAAI,CAAQ,EAAG,OAAO,EAAM,IAAI,CAAQ,EAElD,IAAM,EAAW,IAAI,EAErB,GAAI,GAAY,IAAW,IAAA,GAAW,CAClC,IAAM,EAAW,EAAS,OAAO,CAAG,EACpC,GAAI,EAAU,CAAQ,EAClB,MAAM,IAAI,EAAA,IAEN,kCAAkC,EAAkB,CAAG,EAAE,uBAC7D,CAER,CAEA,IAAM,EAAiB,IAAI,EAAe,CAAQ,EAC5C,EACF,IAAW,IAAA,GAEL,EAAe,aAAa,EAAK,EAAU,EAAW,CAAW,EADhE,EAAe,kBAAkB,EAAK,EAAQ,EAAU,CAAW,EAI9E,OADA,EAAM,IAAI,EAAU,CAAK,EAClB,CACX"}
@@ -1 +1 @@
1
- {"version":3,"file":"Envapter.cjs","names":["AdvancedMethods","EnvaptError","resolveRequired","resolveKeyInput","templateResolver"],"sources":["../../../src/engine/Envapter.ts"],"sourcesContent":["import { AdvancedMethods } from '../core';\nimport { resolveRequired } from '../core/AdvancedMethods';\nimport { resolveKeyInput, templateResolver } from '../core/engine';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { EnvKeyInput } from '../types';\n\nexport { Environment } from '../core';\n\n/**\n * Main configuration class for environment variable management.\n *\n * Provides both static and instance methods for retrieving typed environment variables\n * with support for template resolution, multiple .env files, and environment detection.\n *\n * Extend your own classes from this to define properties with \\@Envapt decorators and get access to environment-variable methods.\n *\n * @example\n * ```ts\n * // Static usage\n * const port = Envapter.getNumber('PORT', 3000);\n * const url = Envapter.get('API_URL', 'http://localhost');\n * const replica = Envapter.get(['READONLY_URL', 'DATABASE_URL'], 'sqlite://memory');\n *\n * // Instance usage\n * const env = new Envapter();\n * const dbUrl = env.get('DATABASE_URL', 'sqlite://memory');\n * const primaryHost = env.get(['PRIMARY_HOST', 'SECONDARY_HOST']);\n * ```\n *\n * @public\n */\nexport class Envapter extends AdvancedMethods {\n /**\n * Tagged template literal for resolving environment variables in template strings.\n *\n * @example\n * ```ts\n * // Given API_HOST=api.example.com and API_PORT=8080 in environment\n * const endpoint = Envapter.resolve`Connecting to ${'API_HOST'}:${'API_PORT'}`;\n * // Returns: \"Connecting to api.example.com:8080\"\n *\n * // Works with template variables in .env too:\n * // API_URL=https://${API_HOST}:${API_PORT}\n * const message = Envapter.resolve`Service endpoint: ${'API_URL'}`;\n * // Returns: \"Service endpoint: https://api.example.com:8080\"\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/templates#the-resolve-tagged-template}\n */\n static resolve(strings: TemplateStringsArray, ...keys: string[]): string {\n const strict = Envapter.strict;\n return strings.reduce((result, string, i) => {\n const envKey = keys[i];\n if (!envKey) return result + string;\n const raw = super.get(envKey, '');\n if (strict && raw.trim() === '') {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Cannot resolve template variable \"\\${${envKey}}\": value is missing or empty.`\n );\n }\n return result + string + raw;\n }, '');\n }\n\n /**\n * @see {@link Envapter.resolve}\n */\n resolve(strings: TemplateStringsArray, ...keys: string[]): string {\n return Envapter.resolve(strings, ...keys);\n }\n\n /**\n * Assert that one or more environment variables are present and non-empty after template\n * resolution. Throws `MissingEnvValue` listing every missing key. A whitespace-only value\n * counts as missing only under strict mode.\n *\n * For a typed required read in functional code, use `Envapter.getRequired(key, converter)`.\n *\n * @example\n * ```ts\n * Envapter.require('DATABASE_URL');\n * Envapter.require('DATABASE_URL', 'API_KEY', 'SENTRY_DSN');\n * ```\n */\n static require(...keys: [string, ...string[]]): void {\n const missing = keys.filter((k) => resolveRequired(resolveKeyInput(k), templateResolver).value === undefined);\n\n if (missing.length > 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Missing required environment variables: ${missing.join(', ')}.`\n );\n }\n }\n\n /**\n * @see {@link Envapter.require}\n */\n require(...keys: [string, ...string[]]): void {\n Envapter.require(...keys);\n }\n\n /**\n * Check whether `key` has a value, with the same missing semantics as `getRequired`.\n * Under strict mode an unresolvable template in an ordered key list ends the scan early\n * and counts as absent. Returns `true` exactly when a required read of the same key\n * finds a value.\n *\n * @example\n * ```ts\n * if (!Envapter.has('DATABASE_URL')) throw new MyStartupError('DATABASE_URL');\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/envapter#fail-fast-on-missing-values}\n */\n static has(key: EnvKeyInput): boolean {\n try {\n return resolveRequired(resolveKeyInput(key), templateResolver).value !== undefined;\n } catch (error) {\n // under strict an unresolvable template throws MissingEnvValue, and that read counts as absent\n if (error instanceof EnvaptError && error.code === EnvaptErrorCodes.MissingEnvValue) return false;\n throw error;\n }\n }\n\n /**\n * @see {@link Envapter.has}\n */\n has(key: EnvKeyInput): boolean {\n return Envapter.has(key);\n }\n}\n"],"mappings":"oJAgCA,IAAa,EAAb,MAAa,UAAiBA,EAAAA,eAAgB,CAiB1C,OAAO,QAAQ,EAA+B,GAAG,EAAwB,CACrE,IAAM,EAAS,EAAS,OACxB,OAAO,EAAQ,QAAQ,EAAQ,EAAQ,IAAM,CACzC,IAAM,EAAS,EAAK,GACpB,GAAI,CAAC,EAAQ,OAAO,EAAS,EAC7B,IAAM,EAAM,MAAM,IAAI,EAAQ,EAAE,EAChC,GAAI,GAAU,EAAI,KAAK,IAAM,GACzB,MAAM,IAAIC,EAAAA,YAAAA,IAEN,wCAAwC,EAAO,+BACnD,EAEJ,OAAO,EAAS,EAAS,CAC7B,EAAG,EAAE,CACT,CAKA,QAAQ,EAA+B,GAAG,EAAwB,CAC9D,OAAO,EAAS,QAAQ,EAAS,GAAG,CAAI,CAC5C,CAeA,OAAO,QAAQ,GAAG,EAAmC,CACjD,IAAM,EAAU,EAAK,OAAQ,GAAMC,EAAAA,gBAAgBC,EAAAA,gBAAgB,CAAC,EAAGC,EAAAA,gBAAgB,CAAC,CAAC,QAAU,IAAA,EAAS,EAE5G,GAAI,EAAQ,OAAS,EACjB,MAAM,IAAIH,EAAAA,YAAAA,IAEN,2CAA2C,EAAQ,KAAK,IAAI,EAAE,EAClE,CAER,CAKA,QAAQ,GAAG,EAAmC,CAC1C,EAAS,QAAQ,GAAG,CAAI,CAC5B,CAcA,OAAO,IAAI,EAA2B,CAClC,GAAI,CACA,OAAOC,EAAAA,gBAAgBC,EAAAA,gBAAgB,CAAG,EAAGC,EAAAA,gBAAgB,CAAC,CAAC,QAAU,IAAA,EAC7E,OAAS,EAAO,CAEZ,GAAI,aAAiBH,EAAAA,aAAe,EAAM,OAAA,IAA2C,MAAO,GAC5F,MAAM,CACV,CACJ,CAKA,IAAI,EAA2B,CAC3B,OAAO,EAAS,IAAI,CAAG,CAC3B,CACJ"}
1
+ {"version":3,"file":"Envapter.cjs","names":["AdvancedMethods","EnvaptError","resolveRequired","resolveKeyInput","templateResolver"],"sources":["../../../src/engine/Envapter.ts"],"sourcesContent":["import { AdvancedMethods } from '../core';\nimport { resolveRequired } from '../core/AdvancedMethods';\nimport { resolveKeyInput, templateResolver } from '../core/engine';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { EnvKeyInput } from '../types';\n\nexport { Environment } from '../core';\n\n/**\n * Main configuration class for environment variable management.\n *\n * Provides both static and instance methods for retrieving typed environment variables\n * with support for template resolution, multiple .env files, and environment detection.\n *\n * Extend your own classes from this to define properties with \\@Envapt decorators and get access to environment-variable methods.\n *\n * @example\n * ```ts\n * // Static usage\n * const port = Envapter.getNumber('PORT', 3000);\n * const url = Envapter.get('API_URL', 'http://localhost');\n * const replica = Envapter.get(['READONLY_URL', 'DATABASE_URL'], 'sqlite://memory');\n *\n * // Instance usage\n * const env = new Envapter();\n * const dbUrl = env.get('DATABASE_URL', 'sqlite://memory');\n * const primaryHost = env.get(['PRIMARY_HOST', 'SECONDARY_HOST']);\n * ```\n *\n * @public\n */\nexport class Envapter extends AdvancedMethods {\n /**\n * Tagged template literal for resolving environment variables in template strings.\n *\n * @example\n * ```ts\n * // Given API_HOST=api.example.com and API_PORT=8080 in environment\n * const endpoint = Envapter.resolve`Connecting to ${'API_HOST'}:${'API_PORT'}`;\n * // Returns: \"Connecting to api.example.com:8080\"\n *\n * // Works with template variables in .env too:\n * // API_URL=https://${API_HOST}:${API_PORT}\n * const message = Envapter.resolve`Service endpoint: ${'API_URL'}`;\n * // Returns: \"Service endpoint: https://api.example.com:8080\"\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/templates#the-resolve-tagged-template}\n */\n static resolve(strings: TemplateStringsArray, ...keys: string[]): string {\n const strict = Envapter.strict;\n return strings.reduce((result, string, i) => {\n const envKey = keys[i];\n if (!envKey) return result + string;\n const raw = super.get(envKey, '');\n if (strict && raw.trim() === '') {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Cannot resolve template variable \"\\${${envKey}}\": value is missing or empty.`\n );\n }\n return result + string + raw;\n }, '');\n }\n\n /**\n * @see {@link Envapter.resolve}\n */\n resolve(strings: TemplateStringsArray, ...keys: string[]): string {\n return Envapter.resolve(strings, ...keys);\n }\n\n /**\n * Assert that one or more environment variables are present and non-empty after template\n * resolution. Throws `MissingEnvValue` listing every missing key. A whitespace-only value\n * counts as missing only under strict mode.\n *\n * For a typed required read in functional code, use `Envapter.getRequired(key, converter)`.\n *\n * @example\n * ```ts\n * Envapter.require('DATABASE_URL');\n * Envapter.require('DATABASE_URL', 'API_KEY', 'SENTRY_DSN');\n * ```\n */\n static require(...keys: [string, ...string[]]): void {\n const missing = keys.filter((k) => resolveRequired(resolveKeyInput(k), templateResolver).value === undefined);\n\n if (missing.length > 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Missing required environment variables: ${missing.join(', ')}.`\n );\n }\n }\n\n /**\n * @see {@link Envapter.require}\n */\n require(...keys: [string, ...string[]]): void {\n Envapter.require(...keys);\n }\n\n /**\n * Check whether `key` has a value, with the same missing semantics as `getRequired`.\n * Under strict mode an unresolvable template in an ordered key list ends the scan early\n * and counts as absent. Returns `true` exactly when a required read of the same key\n * finds a value.\n *\n * @example\n * ```ts\n * if (!Envapter.has('DATABASE_URL')) throw new MyStartupError('DATABASE_URL');\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/envapter#fail-fast-on-missing-values}\n */\n static has(key: EnvKeyInput): boolean {\n try {\n return resolveRequired(resolveKeyInput(key), templateResolver).value !== undefined;\n } catch (error) {\n // strict mode throws MissingEnvValue for an unresolvable template\n if (error instanceof EnvaptError && error.code === EnvaptErrorCodes.MissingEnvValue) return false;\n throw error;\n }\n }\n\n /**\n * @see {@link Envapter.has}\n */\n has(key: EnvKeyInput): boolean {\n return Envapter.has(key);\n }\n}\n"],"mappings":"oJAgCA,IAAa,EAAb,MAAa,UAAiBA,EAAAA,eAAgB,CAiB1C,OAAO,QAAQ,EAA+B,GAAG,EAAwB,CACrE,IAAM,EAAS,EAAS,OACxB,OAAO,EAAQ,QAAQ,EAAQ,EAAQ,IAAM,CACzC,IAAM,EAAS,EAAK,GACpB,GAAI,CAAC,EAAQ,OAAO,EAAS,EAC7B,IAAM,EAAM,MAAM,IAAI,EAAQ,EAAE,EAChC,GAAI,GAAU,EAAI,KAAK,IAAM,GACzB,MAAM,IAAIC,EAAAA,YAAAA,IAEN,wCAAwC,EAAO,+BACnD,EAEJ,OAAO,EAAS,EAAS,CAC7B,EAAG,EAAE,CACT,CAKA,QAAQ,EAA+B,GAAG,EAAwB,CAC9D,OAAO,EAAS,QAAQ,EAAS,GAAG,CAAI,CAC5C,CAeA,OAAO,QAAQ,GAAG,EAAmC,CACjD,IAAM,EAAU,EAAK,OAAQ,GAAMC,EAAAA,gBAAgBC,EAAAA,gBAAgB,CAAC,EAAGC,EAAAA,gBAAgB,CAAC,CAAC,QAAU,IAAA,EAAS,EAE5G,GAAI,EAAQ,OAAS,EACjB,MAAM,IAAIH,EAAAA,YAAAA,IAEN,2CAA2C,EAAQ,KAAK,IAAI,EAAE,EAClE,CAER,CAKA,QAAQ,GAAG,EAAmC,CAC1C,EAAS,QAAQ,GAAG,CAAI,CAC5B,CAcA,OAAO,IAAI,EAA2B,CAClC,GAAI,CACA,OAAOC,EAAAA,gBAAgBC,EAAAA,gBAAgB,CAAG,EAAGC,EAAAA,gBAAgB,CAAC,CAAC,QAAU,IAAA,EAC7E,OAAS,EAAO,CAEZ,GAAI,aAAiBH,EAAAA,aAAe,EAAM,OAAA,IAA2C,MAAO,GAC5F,MAAM,CACV,CACJ,CAKA,IAAI,EAA2B,CAC3B,OAAO,EAAS,IAAI,CAAG,CAC3B,CACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"Envapter.mjs","names":[],"sources":["../../../src/engine/Envapter.ts"],"sourcesContent":["import { AdvancedMethods } from '../core';\nimport { resolveRequired } from '../core/AdvancedMethods';\nimport { resolveKeyInput, templateResolver } from '../core/engine';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { EnvKeyInput } from '../types';\n\nexport { Environment } from '../core';\n\n/**\n * Main configuration class for environment variable management.\n *\n * Provides both static and instance methods for retrieving typed environment variables\n * with support for template resolution, multiple .env files, and environment detection.\n *\n * Extend your own classes from this to define properties with \\@Envapt decorators and get access to environment-variable methods.\n *\n * @example\n * ```ts\n * // Static usage\n * const port = Envapter.getNumber('PORT', 3000);\n * const url = Envapter.get('API_URL', 'http://localhost');\n * const replica = Envapter.get(['READONLY_URL', 'DATABASE_URL'], 'sqlite://memory');\n *\n * // Instance usage\n * const env = new Envapter();\n * const dbUrl = env.get('DATABASE_URL', 'sqlite://memory');\n * const primaryHost = env.get(['PRIMARY_HOST', 'SECONDARY_HOST']);\n * ```\n *\n * @public\n */\nexport class Envapter extends AdvancedMethods {\n /**\n * Tagged template literal for resolving environment variables in template strings.\n *\n * @example\n * ```ts\n * // Given API_HOST=api.example.com and API_PORT=8080 in environment\n * const endpoint = Envapter.resolve`Connecting to ${'API_HOST'}:${'API_PORT'}`;\n * // Returns: \"Connecting to api.example.com:8080\"\n *\n * // Works with template variables in .env too:\n * // API_URL=https://${API_HOST}:${API_PORT}\n * const message = Envapter.resolve`Service endpoint: ${'API_URL'}`;\n * // Returns: \"Service endpoint: https://api.example.com:8080\"\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/templates#the-resolve-tagged-template}\n */\n static resolve(strings: TemplateStringsArray, ...keys: string[]): string {\n const strict = Envapter.strict;\n return strings.reduce((result, string, i) => {\n const envKey = keys[i];\n if (!envKey) return result + string;\n const raw = super.get(envKey, '');\n if (strict && raw.trim() === '') {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Cannot resolve template variable \"\\${${envKey}}\": value is missing or empty.`\n );\n }\n return result + string + raw;\n }, '');\n }\n\n /**\n * @see {@link Envapter.resolve}\n */\n resolve(strings: TemplateStringsArray, ...keys: string[]): string {\n return Envapter.resolve(strings, ...keys);\n }\n\n /**\n * Assert that one or more environment variables are present and non-empty after template\n * resolution. Throws `MissingEnvValue` listing every missing key. A whitespace-only value\n * counts as missing only under strict mode.\n *\n * For a typed required read in functional code, use `Envapter.getRequired(key, converter)`.\n *\n * @example\n * ```ts\n * Envapter.require('DATABASE_URL');\n * Envapter.require('DATABASE_URL', 'API_KEY', 'SENTRY_DSN');\n * ```\n */\n static require(...keys: [string, ...string[]]): void {\n const missing = keys.filter((k) => resolveRequired(resolveKeyInput(k), templateResolver).value === undefined);\n\n if (missing.length > 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Missing required environment variables: ${missing.join(', ')}.`\n );\n }\n }\n\n /**\n * @see {@link Envapter.require}\n */\n require(...keys: [string, ...string[]]): void {\n Envapter.require(...keys);\n }\n\n /**\n * Check whether `key` has a value, with the same missing semantics as `getRequired`.\n * Under strict mode an unresolvable template in an ordered key list ends the scan early\n * and counts as absent. Returns `true` exactly when a required read of the same key\n * finds a value.\n *\n * @example\n * ```ts\n * if (!Envapter.has('DATABASE_URL')) throw new MyStartupError('DATABASE_URL');\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/envapter#fail-fast-on-missing-values}\n */\n static has(key: EnvKeyInput): boolean {\n try {\n return resolveRequired(resolveKeyInput(key), templateResolver).value !== undefined;\n } catch (error) {\n // under strict an unresolvable template throws MissingEnvValue, and that read counts as absent\n if (error instanceof EnvaptError && error.code === EnvaptErrorCodes.MissingEnvValue) return false;\n throw error;\n }\n }\n\n /**\n * @see {@link Envapter.has}\n */\n has(key: EnvKeyInput): boolean {\n return Envapter.has(key);\n }\n}\n"],"mappings":"qQAgCA,IAAa,EAAb,MAAa,UAAiB,CAAgB,CAiB1C,OAAO,QAAQ,EAA+B,GAAG,EAAwB,CACrE,IAAM,EAAS,EAAS,OACxB,OAAO,EAAQ,QAAQ,EAAQ,EAAQ,IAAM,CACzC,IAAM,EAAS,EAAK,GACpB,GAAI,CAAC,EAAQ,OAAO,EAAS,EAC7B,IAAM,EAAM,MAAM,IAAI,EAAQ,EAAE,EAChC,GAAI,GAAU,EAAI,KAAK,IAAM,GACzB,MAAM,IAAI,EAAA,IAEN,wCAAwC,EAAO,+BACnD,EAEJ,OAAO,EAAS,EAAS,CAC7B,EAAG,EAAE,CACT,CAKA,QAAQ,EAA+B,GAAG,EAAwB,CAC9D,OAAO,EAAS,QAAQ,EAAS,GAAG,CAAI,CAC5C,CAeA,OAAO,QAAQ,GAAG,EAAmC,CACjD,IAAM,EAAU,EAAK,OAAQ,GAAM,EAAgB,EAAgB,CAAC,EAAG,CAAgB,CAAC,CAAC,QAAU,IAAA,EAAS,EAE5G,GAAI,EAAQ,OAAS,EACjB,MAAM,IAAI,EAAA,IAEN,2CAA2C,EAAQ,KAAK,IAAI,EAAE,EAClE,CAER,CAKA,QAAQ,GAAG,EAAmC,CAC1C,EAAS,QAAQ,GAAG,CAAI,CAC5B,CAcA,OAAO,IAAI,EAA2B,CAClC,GAAI,CACA,OAAO,EAAgB,EAAgB,CAAG,EAAG,CAAgB,CAAC,CAAC,QAAU,IAAA,EAC7E,OAAS,EAAO,CAEZ,GAAI,aAAiB,GAAe,EAAM,OAAA,IAA2C,MAAO,GAC5F,MAAM,CACV,CACJ,CAKA,IAAI,EAA2B,CAC3B,OAAO,EAAS,IAAI,CAAG,CAC3B,CACJ"}
1
+ {"version":3,"file":"Envapter.mjs","names":[],"sources":["../../../src/engine/Envapter.ts"],"sourcesContent":["import { AdvancedMethods } from '../core';\nimport { resolveRequired } from '../core/AdvancedMethods';\nimport { resolveKeyInput, templateResolver } from '../core/engine';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { EnvKeyInput } from '../types';\n\nexport { Environment } from '../core';\n\n/**\n * Main configuration class for environment variable management.\n *\n * Provides both static and instance methods for retrieving typed environment variables\n * with support for template resolution, multiple .env files, and environment detection.\n *\n * Extend your own classes from this to define properties with \\@Envapt decorators and get access to environment-variable methods.\n *\n * @example\n * ```ts\n * // Static usage\n * const port = Envapter.getNumber('PORT', 3000);\n * const url = Envapter.get('API_URL', 'http://localhost');\n * const replica = Envapter.get(['READONLY_URL', 'DATABASE_URL'], 'sqlite://memory');\n *\n * // Instance usage\n * const env = new Envapter();\n * const dbUrl = env.get('DATABASE_URL', 'sqlite://memory');\n * const primaryHost = env.get(['PRIMARY_HOST', 'SECONDARY_HOST']);\n * ```\n *\n * @public\n */\nexport class Envapter extends AdvancedMethods {\n /**\n * Tagged template literal for resolving environment variables in template strings.\n *\n * @example\n * ```ts\n * // Given API_HOST=api.example.com and API_PORT=8080 in environment\n * const endpoint = Envapter.resolve`Connecting to ${'API_HOST'}:${'API_PORT'}`;\n * // Returns: \"Connecting to api.example.com:8080\"\n *\n * // Works with template variables in .env too:\n * // API_URL=https://${API_HOST}:${API_PORT}\n * const message = Envapter.resolve`Service endpoint: ${'API_URL'}`;\n * // Returns: \"Service endpoint: https://api.example.com:8080\"\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/templates#the-resolve-tagged-template}\n */\n static resolve(strings: TemplateStringsArray, ...keys: string[]): string {\n const strict = Envapter.strict;\n return strings.reduce((result, string, i) => {\n const envKey = keys[i];\n if (!envKey) return result + string;\n const raw = super.get(envKey, '');\n if (strict && raw.trim() === '') {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Cannot resolve template variable \"\\${${envKey}}\": value is missing or empty.`\n );\n }\n return result + string + raw;\n }, '');\n }\n\n /**\n * @see {@link Envapter.resolve}\n */\n resolve(strings: TemplateStringsArray, ...keys: string[]): string {\n return Envapter.resolve(strings, ...keys);\n }\n\n /**\n * Assert that one or more environment variables are present and non-empty after template\n * resolution. Throws `MissingEnvValue` listing every missing key. A whitespace-only value\n * counts as missing only under strict mode.\n *\n * For a typed required read in functional code, use `Envapter.getRequired(key, converter)`.\n *\n * @example\n * ```ts\n * Envapter.require('DATABASE_URL');\n * Envapter.require('DATABASE_URL', 'API_KEY', 'SENTRY_DSN');\n * ```\n */\n static require(...keys: [string, ...string[]]): void {\n const missing = keys.filter((k) => resolveRequired(resolveKeyInput(k), templateResolver).value === undefined);\n\n if (missing.length > 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Missing required environment variables: ${missing.join(', ')}.`\n );\n }\n }\n\n /**\n * @see {@link Envapter.require}\n */\n require(...keys: [string, ...string[]]): void {\n Envapter.require(...keys);\n }\n\n /**\n * Check whether `key` has a value, with the same missing semantics as `getRequired`.\n * Under strict mode an unresolvable template in an ordered key list ends the scan early\n * and counts as absent. Returns `true` exactly when a required read of the same key\n * finds a value.\n *\n * @example\n * ```ts\n * if (!Envapter.has('DATABASE_URL')) throw new MyStartupError('DATABASE_URL');\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/envapter#fail-fast-on-missing-values}\n */\n static has(key: EnvKeyInput): boolean {\n try {\n return resolveRequired(resolveKeyInput(key), templateResolver).value !== undefined;\n } catch (error) {\n // strict mode throws MissingEnvValue for an unresolvable template\n if (error instanceof EnvaptError && error.code === EnvaptErrorCodes.MissingEnvValue) return false;\n throw error;\n }\n }\n\n /**\n * @see {@link Envapter.has}\n */\n has(key: EnvKeyInput): boolean {\n return Envapter.has(key);\n }\n}\n"],"mappings":"qQAgCA,IAAa,EAAb,MAAa,UAAiB,CAAgB,CAiB1C,OAAO,QAAQ,EAA+B,GAAG,EAAwB,CACrE,IAAM,EAAS,EAAS,OACxB,OAAO,EAAQ,QAAQ,EAAQ,EAAQ,IAAM,CACzC,IAAM,EAAS,EAAK,GACpB,GAAI,CAAC,EAAQ,OAAO,EAAS,EAC7B,IAAM,EAAM,MAAM,IAAI,EAAQ,EAAE,EAChC,GAAI,GAAU,EAAI,KAAK,IAAM,GACzB,MAAM,IAAI,EAAA,IAEN,wCAAwC,EAAO,+BACnD,EAEJ,OAAO,EAAS,EAAS,CAC7B,EAAG,EAAE,CACT,CAKA,QAAQ,EAA+B,GAAG,EAAwB,CAC9D,OAAO,EAAS,QAAQ,EAAS,GAAG,CAAI,CAC5C,CAeA,OAAO,QAAQ,GAAG,EAAmC,CACjD,IAAM,EAAU,EAAK,OAAQ,GAAM,EAAgB,EAAgB,CAAC,EAAG,CAAgB,CAAC,CAAC,QAAU,IAAA,EAAS,EAE5G,GAAI,EAAQ,OAAS,EACjB,MAAM,IAAI,EAAA,IAEN,2CAA2C,EAAQ,KAAK,IAAI,EAAE,EAClE,CAER,CAKA,QAAQ,GAAG,EAAmC,CAC1C,EAAS,QAAQ,GAAG,CAAI,CAC5B,CAcA,OAAO,IAAI,EAA2B,CAClC,GAAI,CACA,OAAO,EAAgB,EAAgB,CAAG,EAAG,CAAgB,CAAC,CAAC,QAAU,IAAA,EAC7E,OAAS,EAAO,CAEZ,GAAI,aAAiB,GAAe,EAAM,OAAA,IAA2C,MAAO,GAC5F,MAAM,CACV,CACJ,CAKA,IAAI,EAA2B,CAC3B,OAAO,EAAS,IAAI,CAAG,CAC3B,CACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"NodeEnvapter.cjs","names":["Envapter","process","FileSource","state","resolveAgainstBase","sourceFileExists"],"sources":["../../../src/engine/NodeEnvapter.ts"],"sourcesContent":["import process from 'node:process';\n\nimport { Envapter } from './Envapter';\nimport { Validator } from './Validators';\nimport { refreshCache } from '../core/engine';\nimport { assertFileApiSupported, resolveAgainstBase, sourceFileExists } from '../core/paths';\nimport { state } from '../core/state';\nimport { setRuntimeSink } from '../infra/runtime';\nimport { FileSource } from '../sources/FileSource';\n\nimport type { EnvFileOptions } from '../infra/Dotenv';\nimport type { ProfilesConfig } from '../types';\n\n/**\n * The Node/Bun/Deno facade: {@link Envapter} plus the filesystem-only configuration APIs (`.env`\n * path selection, base directory, dotenv options, and per-environment profiles). On the portable\n * build (Workers, the browser, edge) these same APIs warn once and no-op by default, controlled by\n * `Envapter.fileApiMode`.\n * @public\n */\nexport class NodeEnvapter extends Envapter {\n // A static block (not a top-level statement in a separate entry) keeps the bind intrinsic to this\n // class: tree-shaken out of `import { EnvaptError }`, run whenever `Envapter` is referenced, with no\n // sideEffects entry. Depends on the es2022 native static-block emit.\n static {\n setRuntimeSink((line) => process.stderr.write(`${line}\\n`));\n NodeEnvapter.useSource(new FileSource());\n }\n\n /**\n * Set custom .env file paths. Accepts either a single path or array of paths.\n * Setting new paths clears the cache and reloads environment variables.\n *\n * When set, this takes absolute precedence. The dotenv-flow auto-cascade and any\n * `Envapter.configureProfiles` configuration are ignored.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static set envPaths(paths: string[] | string) {\n assertFileApiSupported('envPaths', state.source);\n const newPaths = Array.isArray(paths) ? paths : [paths];\n Validator.validateEnvFilesExist(\n newPaths.map((p) => resolveAgainstBase(p)),\n (p) => sourceFileExists(p)\n );\n\n state.envPaths = newPaths;\n state.envPathsExplicitlySet = true;\n refreshCache();\n }\n\n /**\n * Get currently configured .env file paths\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static get envPaths(): string[] {\n return state.envPaths;\n }\n\n /**\n * Set a base directory that relative `.env` paths resolve against instead of\n * `process.cwd()`: the auto-cascade, `Envapter.configureProfiles` paths, and relative\n * `envPaths`. Absolute paths always bypass it. Pass a directory, or a module URL\n * (`import.meta.url`, ESM) / `import.meta.dirname` / `__dirname` (CJS) to anchor\n * resolution next to the calling file regardless of launch directory.\n *\n * Set this before `envPaths` so relative `envPaths` validate against the right directory.\n * Unset (`undefined`) restores `process.cwd()` resolution.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#reading-from-a-fixed-directory}\n */\n static set baseDir(value: string | URL | undefined) {\n const source = state.source;\n assertFileApiSupported('baseDir', source);\n state.baseDir = value === undefined ? undefined : source.normalizeBaseDir(value);\n refreshCache();\n }\n\n /**\n * The configured base directory, or `undefined` when relative paths resolve against the working directory.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#reading-from-a-fixed-directory}\n */\n static get baseDir(): string | undefined {\n return state.baseDir;\n }\n\n /**\n * Set the env file loader options (`encoding`, `override`). Refreshes the cache.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static set envFileOptions(config: EnvFileOptions) {\n Validator.validateEnvFileOptions(config);\n state.userDefinedEnvFileOptions = config;\n refreshCache();\n }\n\n /**\n * Get current env file loader options\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static get envFileOptions(): EnvFileOptions {\n return state.userDefinedEnvFileOptions;\n }\n\n /**\n * Configure per-environment `.env` path overrides on top of the dotenv-flow auto-cascade.\n *\n * When set, each `Environment` key's `paths` are loaded at higher precedence than the\n * cascade for that environment. Unspecified environments still use the cascade as-is.\n * Set `useDefaults: false` to disable the cascade entirely (load only the configured paths).\n *\n * Setting an explicit `Envapter.envPaths` value at any point overrides this configuration.\n *\n * @example\n * ```ts\n * Envapter.configureProfiles({\n * [Environment.Staging]: { paths: 'config/staging.env' },\n * [Environment.Production]: { paths: ['config/prod.env', 'secrets/prod.env'] }\n * });\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/environment#custom-profiles}\n */\n static configureProfiles(config: ProfilesConfig): void {\n assertFileApiSupported('configureProfiles', state.source);\n state.profiles = config;\n refreshCache();\n }\n\n /**\n * Reset all path-resolution configuration to defaults: clears any prior\n * `Envapter.configureProfiles` call AND any explicit `Envapter.envPaths` assignment.\n * Returns the resolver to the pure dotenv-flow cascade.\n * @see {@link https://envapt.materwelon.dev/docs/environment#custom-profiles}\n */\n static resetProfiles(): void {\n state.profiles = undefined;\n state.envPaths = ['.env'];\n state.envPathsExplicitlySet = false;\n state.environmentExplicitlySet = false;\n state.environment = undefined;\n refreshCache();\n }\n}\n"],"mappings":"qUAoBA,IAAa,EAAb,MAAa,UAAqBA,EAAAA,QAAS,CAIvC,OACI,EAAA,eAAgB,GAASC,EAAAA,QAAQ,OAAO,MAAM,GAAG,EAAK,GAAG,CAAC,EAC1D,EAAa,UAAU,IAAIC,EAAAA,UAAY,CAC3C,CAUA,WAAW,SAAS,EAA0B,CAC1C,EAAA,uBAAuB,WAAYC,EAAAA,MAAM,MAAM,EAC/C,IAAM,EAAW,MAAM,QAAQ,CAAK,EAAI,EAAQ,CAAC,CAAK,EACtD,EAAA,UAAU,sBACN,EAAS,IAAK,GAAMC,EAAAA,mBAAmB,CAAC,CAAC,EACxC,GAAMC,EAAAA,iBAAiB,CAAC,CAC7B,EAEA,EAAA,MAAM,SAAW,EACjB,EAAA,MAAM,sBAAwB,GAC9B,EAAA,aAAa,CACjB,CAMA,WAAW,UAAqB,CAC5B,OAAOF,EAAAA,MAAM,QACjB,CAaA,WAAW,QAAQ,EAAiC,CAChD,IAAM,EAASA,EAAAA,MAAM,OACrB,EAAA,uBAAuB,UAAW,CAAM,EACxC,EAAA,MAAM,QAAU,IAAU,IAAA,GAAY,IAAA,GAAY,EAAO,iBAAiB,CAAK,EAC/E,EAAA,aAAa,CACjB,CAMA,WAAW,SAA8B,CACrC,OAAOA,EAAAA,MAAM,OACjB,CAMA,WAAW,eAAe,EAAwB,CAC9C,EAAA,UAAU,uBAAuB,CAAM,EACvC,EAAA,MAAM,0BAA4B,EAClC,EAAA,aAAa,CACjB,CAMA,WAAW,gBAAiC,CACxC,OAAOA,EAAAA,MAAM,yBACjB,CAoBA,OAAO,kBAAkB,EAA8B,CACnD,EAAA,uBAAuB,oBAAqBA,EAAAA,MAAM,MAAM,EACxD,EAAA,MAAM,SAAW,EACjB,EAAA,aAAa,CACjB,CAQA,OAAO,eAAsB,CACzB,EAAA,MAAM,SAAW,IAAA,GACjB,EAAA,MAAM,SAAW,CAAC,MAAM,EACxB,EAAA,MAAM,sBAAwB,GAC9B,EAAA,MAAM,yBAA2B,GACjC,EAAA,MAAM,YAAc,IAAA,GACpB,EAAA,aAAa,CACjB,CACJ"}
1
+ {"version":3,"file":"NodeEnvapter.cjs","names":["Envapter","process","FileSource","state","resolveAgainstBase","sourceFileExists"],"sources":["../../../src/engine/NodeEnvapter.ts"],"sourcesContent":["import process from 'node:process';\n\nimport { Envapter } from './Envapter';\nimport { Validator } from './Validators';\nimport { refreshCache } from '../core/engine';\nimport { assertFileApiSupported, resolveAgainstBase, sourceFileExists } from '../core/paths';\nimport { state } from '../core/state';\nimport { setRuntimeSink } from '../infra/runtime';\nimport { FileSource } from '../sources/FileSource';\n\nimport type { EnvFileOptions } from '../infra/Dotenv';\nimport type { ProfilesConfig } from '../types';\n\n/**\n * The Node/Bun/Deno facade: {@link Envapter} plus the filesystem-only configuration APIs (`.env`\n * path selection, base directory, dotenv options, and per-environment profiles). On the portable\n * build (Workers, the browser, edge) these same APIs warn once and no-op by default, controlled by\n * `Envapter.fileApiMode`.\n * @public\n */\nexport class NodeEnvapter extends Envapter {\n // bundlers drop this block with the class when Envapter is unused. needs the native es2022 static-block emit.\n static {\n setRuntimeSink((line) => process.stderr.write(`${line}\\n`));\n NodeEnvapter.useSource(new FileSource());\n }\n\n /**\n * Set custom .env file paths. Accepts either a single path or array of paths.\n * Setting new paths clears the cache and reloads environment variables.\n *\n * When set, this takes absolute precedence. The dotenv-flow auto-cascade and any\n * `Envapter.configureProfiles` configuration are ignored.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static set envPaths(paths: string[] | string) {\n assertFileApiSupported('envPaths', state.source);\n const newPaths = Array.isArray(paths) ? paths : [paths];\n Validator.validateEnvFilesExist(\n newPaths.map((p) => resolveAgainstBase(p)),\n (p) => sourceFileExists(p)\n );\n\n state.envPaths = newPaths;\n state.envPathsExplicitlySet = true;\n refreshCache();\n }\n\n /**\n * Get currently configured .env file paths\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static get envPaths(): string[] {\n return state.envPaths;\n }\n\n /**\n * Set a base directory that relative `.env` paths resolve against instead of\n * `process.cwd()`: the auto-cascade, `Envapter.configureProfiles` paths, and relative\n * `envPaths`. Absolute paths always bypass it. Pass a directory path (`import.meta.dirname`,\n * or `__dirname` in CJS) or a module URL (`import.meta.url`) to resolve paths next to the\n * calling file regardless of launch directory.\n *\n * Set this before `envPaths` so relative `envPaths` validate against the right directory.\n * Setting `undefined` restores `process.cwd()` resolution.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#reading-from-a-fixed-directory}\n */\n static set baseDir(value: string | URL | undefined) {\n const source = state.source;\n assertFileApiSupported('baseDir', source);\n state.baseDir = value === undefined ? undefined : source.normalizeBaseDir(value);\n refreshCache();\n }\n\n /**\n * The configured base directory, or `undefined` when relative paths resolve against the working directory.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#reading-from-a-fixed-directory}\n */\n static get baseDir(): string | undefined {\n return state.baseDir;\n }\n\n /**\n * Set the env file loader options (`encoding`, `override`). Refreshes the cache.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static set envFileOptions(config: EnvFileOptions) {\n Validator.validateEnvFileOptions(config);\n state.userDefinedEnvFileOptions = config;\n refreshCache();\n }\n\n /**\n * Get current env file loader options\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static get envFileOptions(): EnvFileOptions {\n return state.userDefinedEnvFileOptions;\n }\n\n /**\n * Configure per-environment `.env` path overrides on top of the dotenv-flow auto-cascade.\n *\n * When set, each `Environment` key's `paths` are loaded at higher precedence than the\n * cascade for that environment. Unspecified environments still use the cascade as-is.\n * Set `useDefaults: false` to disable the cascade entirely (load only the configured paths).\n *\n * Setting an explicit `Envapter.envPaths` value at any point overrides this configuration.\n *\n * @example\n * ```ts\n * Envapter.configureProfiles({\n * [Environment.Staging]: { paths: 'config/staging.env' },\n * [Environment.Production]: { paths: ['config/prod.env', 'secrets/prod.env'] }\n * });\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/environment#custom-profiles}\n */\n static configureProfiles(config: ProfilesConfig): void {\n assertFileApiSupported('configureProfiles', state.source);\n state.profiles = config;\n refreshCache();\n }\n\n /**\n * Reset all path-resolution configuration to defaults: clears any prior\n * `Envapter.configureProfiles` call AND any explicit `Envapter.envPaths` assignment.\n * Returns the resolver to the pure dotenv-flow cascade.\n * @see {@link https://envapt.materwelon.dev/docs/environment#custom-profiles}\n */\n static resetProfiles(): void {\n state.profiles = undefined;\n state.envPaths = ['.env'];\n state.envPathsExplicitlySet = false;\n state.environmentExplicitlySet = false;\n state.environment = undefined;\n refreshCache();\n }\n}\n"],"mappings":"qUAoBA,IAAa,EAAb,MAAa,UAAqBA,EAAAA,QAAS,CAEvC,OACI,EAAA,eAAgB,GAASC,EAAAA,QAAQ,OAAO,MAAM,GAAG,EAAK,GAAG,CAAC,EAC1D,EAAa,UAAU,IAAIC,EAAAA,UAAY,CAC3C,CAUA,WAAW,SAAS,EAA0B,CAC1C,EAAA,uBAAuB,WAAYC,EAAAA,MAAM,MAAM,EAC/C,IAAM,EAAW,MAAM,QAAQ,CAAK,EAAI,EAAQ,CAAC,CAAK,EACtD,EAAA,UAAU,sBACN,EAAS,IAAK,GAAMC,EAAAA,mBAAmB,CAAC,CAAC,EACxC,GAAMC,EAAAA,iBAAiB,CAAC,CAC7B,EAEA,EAAA,MAAM,SAAW,EACjB,EAAA,MAAM,sBAAwB,GAC9B,EAAA,aAAa,CACjB,CAMA,WAAW,UAAqB,CAC5B,OAAOF,EAAAA,MAAM,QACjB,CAaA,WAAW,QAAQ,EAAiC,CAChD,IAAM,EAASA,EAAAA,MAAM,OACrB,EAAA,uBAAuB,UAAW,CAAM,EACxC,EAAA,MAAM,QAAU,IAAU,IAAA,GAAY,IAAA,GAAY,EAAO,iBAAiB,CAAK,EAC/E,EAAA,aAAa,CACjB,CAMA,WAAW,SAA8B,CACrC,OAAOA,EAAAA,MAAM,OACjB,CAMA,WAAW,eAAe,EAAwB,CAC9C,EAAA,UAAU,uBAAuB,CAAM,EACvC,EAAA,MAAM,0BAA4B,EAClC,EAAA,aAAa,CACjB,CAMA,WAAW,gBAAiC,CACxC,OAAOA,EAAAA,MAAM,yBACjB,CAoBA,OAAO,kBAAkB,EAA8B,CACnD,EAAA,uBAAuB,oBAAqBA,EAAAA,MAAM,MAAM,EACxD,EAAA,MAAM,SAAW,EACjB,EAAA,aAAa,CACjB,CAQA,OAAO,eAAsB,CACzB,EAAA,MAAM,SAAW,IAAA,GACjB,EAAA,MAAM,SAAW,CAAC,MAAM,EACxB,EAAA,MAAM,sBAAwB,GAC9B,EAAA,MAAM,yBAA2B,GACjC,EAAA,MAAM,YAAc,IAAA,GACpB,EAAA,aAAa,CACjB,CACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"NodeEnvapter.mjs","names":[],"sources":["../../../src/engine/NodeEnvapter.ts"],"sourcesContent":["import process from 'node:process';\n\nimport { Envapter } from './Envapter';\nimport { Validator } from './Validators';\nimport { refreshCache } from '../core/engine';\nimport { assertFileApiSupported, resolveAgainstBase, sourceFileExists } from '../core/paths';\nimport { state } from '../core/state';\nimport { setRuntimeSink } from '../infra/runtime';\nimport { FileSource } from '../sources/FileSource';\n\nimport type { EnvFileOptions } from '../infra/Dotenv';\nimport type { ProfilesConfig } from '../types';\n\n/**\n * The Node/Bun/Deno facade: {@link Envapter} plus the filesystem-only configuration APIs (`.env`\n * path selection, base directory, dotenv options, and per-environment profiles). On the portable\n * build (Workers, the browser, edge) these same APIs warn once and no-op by default, controlled by\n * `Envapter.fileApiMode`.\n * @public\n */\nexport class NodeEnvapter extends Envapter {\n // A static block (not a top-level statement in a separate entry) keeps the bind intrinsic to this\n // class: tree-shaken out of `import { EnvaptError }`, run whenever `Envapter` is referenced, with no\n // sideEffects entry. Depends on the es2022 native static-block emit.\n static {\n setRuntimeSink((line) => process.stderr.write(`${line}\\n`));\n NodeEnvapter.useSource(new FileSource());\n }\n\n /**\n * Set custom .env file paths. Accepts either a single path or array of paths.\n * Setting new paths clears the cache and reloads environment variables.\n *\n * When set, this takes absolute precedence. The dotenv-flow auto-cascade and any\n * `Envapter.configureProfiles` configuration are ignored.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static set envPaths(paths: string[] | string) {\n assertFileApiSupported('envPaths', state.source);\n const newPaths = Array.isArray(paths) ? paths : [paths];\n Validator.validateEnvFilesExist(\n newPaths.map((p) => resolveAgainstBase(p)),\n (p) => sourceFileExists(p)\n );\n\n state.envPaths = newPaths;\n state.envPathsExplicitlySet = true;\n refreshCache();\n }\n\n /**\n * Get currently configured .env file paths\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static get envPaths(): string[] {\n return state.envPaths;\n }\n\n /**\n * Set a base directory that relative `.env` paths resolve against instead of\n * `process.cwd()`: the auto-cascade, `Envapter.configureProfiles` paths, and relative\n * `envPaths`. Absolute paths always bypass it. Pass a directory, or a module URL\n * (`import.meta.url`, ESM) / `import.meta.dirname` / `__dirname` (CJS) to anchor\n * resolution next to the calling file regardless of launch directory.\n *\n * Set this before `envPaths` so relative `envPaths` validate against the right directory.\n * Unset (`undefined`) restores `process.cwd()` resolution.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#reading-from-a-fixed-directory}\n */\n static set baseDir(value: string | URL | undefined) {\n const source = state.source;\n assertFileApiSupported('baseDir', source);\n state.baseDir = value === undefined ? undefined : source.normalizeBaseDir(value);\n refreshCache();\n }\n\n /**\n * The configured base directory, or `undefined` when relative paths resolve against the working directory.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#reading-from-a-fixed-directory}\n */\n static get baseDir(): string | undefined {\n return state.baseDir;\n }\n\n /**\n * Set the env file loader options (`encoding`, `override`). Refreshes the cache.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static set envFileOptions(config: EnvFileOptions) {\n Validator.validateEnvFileOptions(config);\n state.userDefinedEnvFileOptions = config;\n refreshCache();\n }\n\n /**\n * Get current env file loader options\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static get envFileOptions(): EnvFileOptions {\n return state.userDefinedEnvFileOptions;\n }\n\n /**\n * Configure per-environment `.env` path overrides on top of the dotenv-flow auto-cascade.\n *\n * When set, each `Environment` key's `paths` are loaded at higher precedence than the\n * cascade for that environment. Unspecified environments still use the cascade as-is.\n * Set `useDefaults: false` to disable the cascade entirely (load only the configured paths).\n *\n * Setting an explicit `Envapter.envPaths` value at any point overrides this configuration.\n *\n * @example\n * ```ts\n * Envapter.configureProfiles({\n * [Environment.Staging]: { paths: 'config/staging.env' },\n * [Environment.Production]: { paths: ['config/prod.env', 'secrets/prod.env'] }\n * });\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/environment#custom-profiles}\n */\n static configureProfiles(config: ProfilesConfig): void {\n assertFileApiSupported('configureProfiles', state.source);\n state.profiles = config;\n refreshCache();\n }\n\n /**\n * Reset all path-resolution configuration to defaults: clears any prior\n * `Envapter.configureProfiles` call AND any explicit `Envapter.envPaths` assignment.\n * Returns the resolver to the pure dotenv-flow cascade.\n * @see {@link https://envapt.materwelon.dev/docs/environment#custom-profiles}\n */\n static resetProfiles(): void {\n state.profiles = undefined;\n state.envPaths = ['.env'];\n state.envPathsExplicitlySet = false;\n state.environmentExplicitlySet = false;\n state.environment = undefined;\n refreshCache();\n }\n}\n"],"mappings":"qaAoBA,IAAa,EAAb,MAAa,UAAqB,CAAS,CAIvC,OACI,EAAgB,GAAS,EAAQ,OAAO,MAAM,GAAG,EAAK,GAAG,CAAC,EAC1D,EAAa,UAAU,IAAI,CAAY,CAC3C,CAUA,WAAW,SAAS,EAA0B,CAC1C,EAAuB,WAAY,EAAM,MAAM,EAC/C,IAAM,EAAW,MAAM,QAAQ,CAAK,EAAI,EAAQ,CAAC,CAAK,EACtD,EAAU,sBACN,EAAS,IAAK,GAAM,EAAmB,CAAC,CAAC,EACxC,GAAM,EAAiB,CAAC,CAC7B,EAEA,EAAM,SAAW,EACjB,EAAM,sBAAwB,GAC9B,EAAa,CACjB,CAMA,WAAW,UAAqB,CAC5B,OAAO,EAAM,QACjB,CAaA,WAAW,QAAQ,EAAiC,CAChD,IAAM,EAAS,EAAM,OACrB,EAAuB,UAAW,CAAM,EACxC,EAAM,QAAU,IAAU,IAAA,GAAY,IAAA,GAAY,EAAO,iBAAiB,CAAK,EAC/E,EAAa,CACjB,CAMA,WAAW,SAA8B,CACrC,OAAO,EAAM,OACjB,CAMA,WAAW,eAAe,EAAwB,CAC9C,EAAU,uBAAuB,CAAM,EACvC,EAAM,0BAA4B,EAClC,EAAa,CACjB,CAMA,WAAW,gBAAiC,CACxC,OAAO,EAAM,yBACjB,CAoBA,OAAO,kBAAkB,EAA8B,CACnD,EAAuB,oBAAqB,EAAM,MAAM,EACxD,EAAM,SAAW,EACjB,EAAa,CACjB,CAQA,OAAO,eAAsB,CACzB,EAAM,SAAW,IAAA,GACjB,EAAM,SAAW,CAAC,MAAM,EACxB,EAAM,sBAAwB,GAC9B,EAAM,yBAA2B,GACjC,EAAM,YAAc,IAAA,GACpB,EAAa,CACjB,CACJ"}
1
+ {"version":3,"file":"NodeEnvapter.mjs","names":[],"sources":["../../../src/engine/NodeEnvapter.ts"],"sourcesContent":["import process from 'node:process';\n\nimport { Envapter } from './Envapter';\nimport { Validator } from './Validators';\nimport { refreshCache } from '../core/engine';\nimport { assertFileApiSupported, resolveAgainstBase, sourceFileExists } from '../core/paths';\nimport { state } from '../core/state';\nimport { setRuntimeSink } from '../infra/runtime';\nimport { FileSource } from '../sources/FileSource';\n\nimport type { EnvFileOptions } from '../infra/Dotenv';\nimport type { ProfilesConfig } from '../types';\n\n/**\n * The Node/Bun/Deno facade: {@link Envapter} plus the filesystem-only configuration APIs (`.env`\n * path selection, base directory, dotenv options, and per-environment profiles). On the portable\n * build (Workers, the browser, edge) these same APIs warn once and no-op by default, controlled by\n * `Envapter.fileApiMode`.\n * @public\n */\nexport class NodeEnvapter extends Envapter {\n // bundlers drop this block with the class when Envapter is unused. needs the native es2022 static-block emit.\n static {\n setRuntimeSink((line) => process.stderr.write(`${line}\\n`));\n NodeEnvapter.useSource(new FileSource());\n }\n\n /**\n * Set custom .env file paths. Accepts either a single path or array of paths.\n * Setting new paths clears the cache and reloads environment variables.\n *\n * When set, this takes absolute precedence. The dotenv-flow auto-cascade and any\n * `Envapter.configureProfiles` configuration are ignored.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static set envPaths(paths: string[] | string) {\n assertFileApiSupported('envPaths', state.source);\n const newPaths = Array.isArray(paths) ? paths : [paths];\n Validator.validateEnvFilesExist(\n newPaths.map((p) => resolveAgainstBase(p)),\n (p) => sourceFileExists(p)\n );\n\n state.envPaths = newPaths;\n state.envPathsExplicitlySet = true;\n refreshCache();\n }\n\n /**\n * Get currently configured .env file paths\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static get envPaths(): string[] {\n return state.envPaths;\n }\n\n /**\n * Set a base directory that relative `.env` paths resolve against instead of\n * `process.cwd()`: the auto-cascade, `Envapter.configureProfiles` paths, and relative\n * `envPaths`. Absolute paths always bypass it. Pass a directory path (`import.meta.dirname`,\n * or `__dirname` in CJS) or a module URL (`import.meta.url`) to resolve paths next to the\n * calling file regardless of launch directory.\n *\n * Set this before `envPaths` so relative `envPaths` validate against the right directory.\n * Setting `undefined` restores `process.cwd()` resolution.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#reading-from-a-fixed-directory}\n */\n static set baseDir(value: string | URL | undefined) {\n const source = state.source;\n assertFileApiSupported('baseDir', source);\n state.baseDir = value === undefined ? undefined : source.normalizeBaseDir(value);\n refreshCache();\n }\n\n /**\n * The configured base directory, or `undefined` when relative paths resolve against the working directory.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#reading-from-a-fixed-directory}\n */\n static get baseDir(): string | undefined {\n return state.baseDir;\n }\n\n /**\n * Set the env file loader options (`encoding`, `override`). Refreshes the cache.\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static set envFileOptions(config: EnvFileOptions) {\n Validator.validateEnvFileOptions(config);\n state.userDefinedEnvFileOptions = config;\n refreshCache();\n }\n\n /**\n * Get current env file loader options\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\n static get envFileOptions(): EnvFileOptions {\n return state.userDefinedEnvFileOptions;\n }\n\n /**\n * Configure per-environment `.env` path overrides on top of the dotenv-flow auto-cascade.\n *\n * When set, each `Environment` key's `paths` are loaded at higher precedence than the\n * cascade for that environment. Unspecified environments still use the cascade as-is.\n * Set `useDefaults: false` to disable the cascade entirely (load only the configured paths).\n *\n * Setting an explicit `Envapter.envPaths` value at any point overrides this configuration.\n *\n * @example\n * ```ts\n * Envapter.configureProfiles({\n * [Environment.Staging]: { paths: 'config/staging.env' },\n * [Environment.Production]: { paths: ['config/prod.env', 'secrets/prod.env'] }\n * });\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/environment#custom-profiles}\n */\n static configureProfiles(config: ProfilesConfig): void {\n assertFileApiSupported('configureProfiles', state.source);\n state.profiles = config;\n refreshCache();\n }\n\n /**\n * Reset all path-resolution configuration to defaults: clears any prior\n * `Envapter.configureProfiles` call AND any explicit `Envapter.envPaths` assignment.\n * Returns the resolver to the pure dotenv-flow cascade.\n * @see {@link https://envapt.materwelon.dev/docs/environment#custom-profiles}\n */\n static resetProfiles(): void {\n state.profiles = undefined;\n state.envPaths = ['.env'];\n state.envPathsExplicitlySet = false;\n state.environmentExplicitlySet = false;\n state.environment = undefined;\n refreshCache();\n }\n}\n"],"mappings":"qaAoBA,IAAa,EAAb,MAAa,UAAqB,CAAS,CAEvC,OACI,EAAgB,GAAS,EAAQ,OAAO,MAAM,GAAG,EAAK,GAAG,CAAC,EAC1D,EAAa,UAAU,IAAI,CAAY,CAC3C,CAUA,WAAW,SAAS,EAA0B,CAC1C,EAAuB,WAAY,EAAM,MAAM,EAC/C,IAAM,EAAW,MAAM,QAAQ,CAAK,EAAI,EAAQ,CAAC,CAAK,EACtD,EAAU,sBACN,EAAS,IAAK,GAAM,EAAmB,CAAC,CAAC,EACxC,GAAM,EAAiB,CAAC,CAC7B,EAEA,EAAM,SAAW,EACjB,EAAM,sBAAwB,GAC9B,EAAa,CACjB,CAMA,WAAW,UAAqB,CAC5B,OAAO,EAAM,QACjB,CAaA,WAAW,QAAQ,EAAiC,CAChD,IAAM,EAAS,EAAM,OACrB,EAAuB,UAAW,CAAM,EACxC,EAAM,QAAU,IAAU,IAAA,GAAY,IAAA,GAAY,EAAO,iBAAiB,CAAK,EAC/E,EAAa,CACjB,CAMA,WAAW,SAA8B,CACrC,OAAO,EAAM,OACjB,CAMA,WAAW,eAAe,EAAwB,CAC9C,EAAU,uBAAuB,CAAM,EACvC,EAAM,0BAA4B,EAClC,EAAa,CACjB,CAMA,WAAW,gBAAiC,CACxC,OAAO,EAAM,yBACjB,CAoBA,OAAO,kBAAkB,EAA8B,CACnD,EAAuB,oBAAqB,EAAM,MAAM,EACxD,EAAM,SAAW,EACjB,EAAa,CACjB,CAQA,OAAO,eAAsB,CACzB,EAAM,SAAW,IAAA,GACjB,EAAM,SAAW,CAAC,MAAM,EACxB,EAAM,sBAAwB,GAC9B,EAAM,yBAA2B,GACjC,EAAM,YAAc,IAAA,GACpB,EAAa,CACjB,CACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"TemplateResolver.cjs","names":["state","isMissing","EnvaptError"],"sources":["../../../src/engine/TemplateResolver.ts"],"sourcesContent":["import { isMissing } from '../core/missing';\nimport { state } from '../core/state';\nimport { debugWarn } from '../infra/Debug';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { EnvapterService } from '../types/Env';\n\n/**\n * Resolve `${VAR}` template references in environment values, guarding against circular\n * references and missing variables.\n * @internal\n */\nexport class TemplateResolver {\n private readonly TEMPLATE_REGEX = /\\${\\w*}/g;\n\n constructor(private readonly envService: EnvapterService) {}\n\n resolveTemplate(key: string, value: string, stack: Set<string> = new Set<string>()): string {\n stack.add(key);\n const strict = state.strict;\n\n const out = value.replace(this.TEMPLATE_REGEX, (template) => {\n const variable = template.slice(2, -1);\n\n if (stack.has(variable)) return template; // cycle, preserve\n\n const raw = this.envService.getRaw(variable);\n if (raw === undefined || isMissing(raw)) {\n if (strict) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Cannot resolve template variable \"\\${${variable}}\": value is missing or empty.`\n );\n }\n debugWarn(`unresolved template \\${${variable}} preserved as literal`);\n return template; // missing or empty, preserve\n }\n\n const resolved = this.resolveTemplate(variable, raw, new Set(stack));\n\n // If resolution still references the current key, skip replacement (indirect cycle)\n if (resolved.includes(`\\${${key}}`)) return template;\n\n // If nothing changed (unresolved placeholders stayed), also preserve original template\n if (resolved === raw && /\\$\\{[^}]*\\}/.test(resolved)) return template;\n\n return resolved;\n });\n\n stack.delete(key);\n return out;\n }\n}\n"],"mappings":"sIAYA,IAAa,EAAb,KAA8B,CAGG,WAF7B,eAAkC,WAElC,YAAY,EAA8C,CAA7B,KAAA,WAAA,CAA8B,CAE3D,gBAAgB,EAAa,EAAe,EAAqB,IAAI,IAAuB,CACxF,EAAM,IAAI,CAAG,EACb,IAAM,EAASA,EAAAA,MAAM,OAEf,EAAM,EAAM,QAAQ,KAAK,eAAiB,GAAa,CACzD,IAAM,EAAW,EAAS,MAAM,EAAG,EAAE,EAErC,GAAI,EAAM,IAAI,CAAQ,EAAG,OAAO,EAEhC,IAAM,EAAM,KAAK,WAAW,OAAO,CAAQ,EAC3C,GAAI,IAAQ,IAAA,IAAaC,EAAAA,UAAU,CAAG,EAAG,CACrC,GAAI,EACA,MAAM,IAAIC,EAAAA,YAAAA,IAEN,wCAAwC,EAAS,+BACrD,EAGJ,OADA,EAAA,UAAU,0BAA0B,EAAS,uBAAuB,EAC7D,CACX,CAEA,IAAM,EAAW,KAAK,gBAAgB,EAAU,EAAK,IAAI,IAAI,CAAK,CAAC,EAQnE,OALI,EAAS,SAAS,MAAM,EAAI,EAAE,GAG9B,IAAa,GAAO,cAAc,KAAK,CAAQ,EAAU,EAEtD,CACX,CAAC,EAGD,OADA,EAAM,OAAO,CAAG,EACT,CACX,CACJ"}
1
+ {"version":3,"file":"TemplateResolver.cjs","names":["state","isMissing","EnvaptError"],"sources":["../../../src/engine/TemplateResolver.ts"],"sourcesContent":["import { isMissing } from '../core/missing';\nimport { state } from '../core/state';\nimport { debugWarn } from '../infra/Debug';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { EnvapterService } from '../types/Env';\n\nexport class TemplateResolver {\n private readonly TEMPLATE_REGEX = /\\${\\w*}/g;\n\n constructor(private readonly envService: EnvapterService) {}\n\n resolveTemplate(key: string, value: string, stack: Set<string> = new Set<string>()): string {\n stack.add(key);\n const strict = state.strict;\n\n const out = value.replace(this.TEMPLATE_REGEX, (template) => {\n const variable = template.slice(2, -1);\n\n if (stack.has(variable)) return template; // cycle, preserve\n\n const raw = this.envService.getRaw(variable);\n if (raw === undefined || isMissing(raw)) {\n if (strict) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Cannot resolve template variable \"\\${${variable}}\": value is missing or empty.`\n );\n }\n debugWarn(`unresolved template \\${${variable}} preserved as literal`);\n return template; // missing or empty, preserve\n }\n\n const resolved = this.resolveTemplate(variable, raw, new Set(stack));\n\n // indirect cycle\n if (resolved.includes(`\\${${key}}`)) return template;\n\n // the nested value still has unresolved placeholders\n if (resolved === raw && /\\$\\{[^}]*\\}/.test(resolved)) return template;\n\n return resolved;\n });\n\n stack.delete(key);\n return out;\n }\n}\n"],"mappings":"sIAOA,IAAa,EAAb,KAA8B,CAGG,WAF7B,eAAkC,WAElC,YAAY,EAA8C,CAA7B,KAAA,WAAA,CAA8B,CAE3D,gBAAgB,EAAa,EAAe,EAAqB,IAAI,IAAuB,CACxF,EAAM,IAAI,CAAG,EACb,IAAM,EAASA,EAAAA,MAAM,OAEf,EAAM,EAAM,QAAQ,KAAK,eAAiB,GAAa,CACzD,IAAM,EAAW,EAAS,MAAM,EAAG,EAAE,EAErC,GAAI,EAAM,IAAI,CAAQ,EAAG,OAAO,EAEhC,IAAM,EAAM,KAAK,WAAW,OAAO,CAAQ,EAC3C,GAAI,IAAQ,IAAA,IAAaC,EAAAA,UAAU,CAAG,EAAG,CACrC,GAAI,EACA,MAAM,IAAIC,EAAAA,YAAAA,IAEN,wCAAwC,EAAS,+BACrD,EAGJ,OADA,EAAA,UAAU,0BAA0B,EAAS,uBAAuB,EAC7D,CACX,CAEA,IAAM,EAAW,KAAK,gBAAgB,EAAU,EAAK,IAAI,IAAI,CAAK,CAAC,EAQnE,OALI,EAAS,SAAS,MAAM,EAAI,EAAE,GAG9B,IAAa,GAAO,cAAc,KAAK,CAAQ,EAAU,EAEtD,CACX,CAAC,EAGD,OADA,EAAM,OAAO,CAAG,EACT,CACX,CACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"TemplateResolver.mjs","names":[],"sources":["../../../src/engine/TemplateResolver.ts"],"sourcesContent":["import { isMissing } from '../core/missing';\nimport { state } from '../core/state';\nimport { debugWarn } from '../infra/Debug';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { EnvapterService } from '../types/Env';\n\n/**\n * Resolve `${VAR}` template references in environment values, guarding against circular\n * references and missing variables.\n * @internal\n */\nexport class TemplateResolver {\n private readonly TEMPLATE_REGEX = /\\${\\w*}/g;\n\n constructor(private readonly envService: EnvapterService) {}\n\n resolveTemplate(key: string, value: string, stack: Set<string> = new Set<string>()): string {\n stack.add(key);\n const strict = state.strict;\n\n const out = value.replace(this.TEMPLATE_REGEX, (template) => {\n const variable = template.slice(2, -1);\n\n if (stack.has(variable)) return template; // cycle, preserve\n\n const raw = this.envService.getRaw(variable);\n if (raw === undefined || isMissing(raw)) {\n if (strict) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Cannot resolve template variable \"\\${${variable}}\": value is missing or empty.`\n );\n }\n debugWarn(`unresolved template \\${${variable}} preserved as literal`);\n return template; // missing or empty, preserve\n }\n\n const resolved = this.resolveTemplate(variable, raw, new Set(stack));\n\n // If resolution still references the current key, skip replacement (indirect cycle)\n if (resolved.includes(`\\${${key}}`)) return template;\n\n // If nothing changed (unresolved placeholders stayed), also preserve original template\n if (resolved === raw && /\\$\\{[^}]*\\}/.test(resolved)) return template;\n\n return resolved;\n });\n\n stack.delete(key);\n return out;\n }\n}\n"],"mappings":"0LAYA,IAAa,EAAb,KAA8B,CAGG,WAF7B,eAAkC,WAElC,YAAY,EAA8C,CAA7B,KAAA,WAAA,CAA8B,CAE3D,gBAAgB,EAAa,EAAe,EAAqB,IAAI,IAAuB,CACxF,EAAM,IAAI,CAAG,EACb,IAAM,EAAS,EAAM,OAEf,EAAM,EAAM,QAAQ,KAAK,eAAiB,GAAa,CACzD,IAAM,EAAW,EAAS,MAAM,EAAG,EAAE,EAErC,GAAI,EAAM,IAAI,CAAQ,EAAG,OAAO,EAEhC,IAAM,EAAM,KAAK,WAAW,OAAO,CAAQ,EAC3C,GAAI,IAAQ,IAAA,IAAa,EAAU,CAAG,EAAG,CACrC,GAAI,EACA,MAAM,IAAI,EAAA,IAEN,wCAAwC,EAAS,+BACrD,EAGJ,OADA,EAAU,0BAA0B,EAAS,uBAAuB,EAC7D,CACX,CAEA,IAAM,EAAW,KAAK,gBAAgB,EAAU,EAAK,IAAI,IAAI,CAAK,CAAC,EAQnE,OALI,EAAS,SAAS,MAAM,EAAI,EAAE,GAG9B,IAAa,GAAO,cAAc,KAAK,CAAQ,EAAU,EAEtD,CACX,CAAC,EAGD,OADA,EAAM,OAAO,CAAG,EACT,CACX,CACJ"}
1
+ {"version":3,"file":"TemplateResolver.mjs","names":[],"sources":["../../../src/engine/TemplateResolver.ts"],"sourcesContent":["import { isMissing } from '../core/missing';\nimport { state } from '../core/state';\nimport { debugWarn } from '../infra/Debug';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { EnvapterService } from '../types/Env';\n\nexport class TemplateResolver {\n private readonly TEMPLATE_REGEX = /\\${\\w*}/g;\n\n constructor(private readonly envService: EnvapterService) {}\n\n resolveTemplate(key: string, value: string, stack: Set<string> = new Set<string>()): string {\n stack.add(key);\n const strict = state.strict;\n\n const out = value.replace(this.TEMPLATE_REGEX, (template) => {\n const variable = template.slice(2, -1);\n\n if (stack.has(variable)) return template; // cycle, preserve\n\n const raw = this.envService.getRaw(variable);\n if (raw === undefined || isMissing(raw)) {\n if (strict) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Cannot resolve template variable \"\\${${variable}}\": value is missing or empty.`\n );\n }\n debugWarn(`unresolved template \\${${variable}} preserved as literal`);\n return template; // missing or empty, preserve\n }\n\n const resolved = this.resolveTemplate(variable, raw, new Set(stack));\n\n // indirect cycle\n if (resolved.includes(`\\${${key}}`)) return template;\n\n // the nested value still has unresolved placeholders\n if (resolved === raw && /\\$\\{[^}]*\\}/.test(resolved)) return template;\n\n return resolved;\n });\n\n stack.delete(key);\n return out;\n }\n}\n"],"mappings":"0LAOA,IAAa,EAAb,KAA8B,CAGG,WAF7B,eAAkC,WAElC,YAAY,EAA8C,CAA7B,KAAA,WAAA,CAA8B,CAE3D,gBAAgB,EAAa,EAAe,EAAqB,IAAI,IAAuB,CACxF,EAAM,IAAI,CAAG,EACb,IAAM,EAAS,EAAM,OAEf,EAAM,EAAM,QAAQ,KAAK,eAAiB,GAAa,CACzD,IAAM,EAAW,EAAS,MAAM,EAAG,EAAE,EAErC,GAAI,EAAM,IAAI,CAAQ,EAAG,OAAO,EAEhC,IAAM,EAAM,KAAK,WAAW,OAAO,CAAQ,EAC3C,GAAI,IAAQ,IAAA,IAAa,EAAU,CAAG,EAAG,CACrC,GAAI,EACA,MAAM,IAAI,EAAA,IAEN,wCAAwC,EAAS,+BACrD,EAGJ,OADA,EAAU,0BAA0B,EAAS,uBAAuB,EAC7D,CACX,CAEA,IAAM,EAAW,KAAK,gBAAgB,EAAU,EAAK,IAAI,IAAI,CAAK,CAAC,EAQnE,OALI,EAAS,SAAS,MAAM,EAAI,EAAE,GAG9B,IAAa,GAAO,cAAc,KAAK,CAAQ,EAAU,EAEtD,CACX,CAAC,EAGD,OADA,EAAM,OAAO,CAAG,EACT,CACX,CACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"Validators.cjs","names":["ListOfBuiltInConverters","isArrayOf","EnvaptError","BuiltInConverterTypeCheckers"],"sources":["../../../src/engine/Validators.ts"],"sourcesContent":["// Import the converter modules directly, not via the `./converters` barrel: that barrel pulls in\n// ValueConverter, which imports this Validator, so a barrel import here would cycle.\nimport { isArrayOf } from '../converters/Converters';\nimport { ListOfBuiltInConverters, BuiltInConverterTypeCheckers } from '../converters/ListOfBuiltInConverters';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { ArrayOf, ConverterToken } from '../converters/Converters';\nimport type { EnvFileOptions } from '../infra/Dotenv';\nimport type { StandardSchemaV1 } from '../infra/StandardSchema';\nimport type { BuiltInConverter, ConverterFunction, EnvaptConverter, FileApiMode } from '../types';\n\n// eslint-disable-next-line @typescript-eslint/no-extraneous-class -- cohesive dispatch of stateless type guards, same shape as BuiltInConverters\nexport class Validator {\n /**\n * Check if a value is a built-in scalar converter token\n */\n static isBuiltInConverter<TFallback>(value: EnvaptConverter<TFallback>): value is BuiltInConverter {\n if (typeof value === 'string') return ListOfBuiltInConverters.includes(value);\n return false;\n }\n\n /**\n * Check if a value is an `ArrayOf<...>` token produced by {@link Converters.array}.\n */\n static isArrayConverter(value: unknown): value is ArrayOf {\n return isArrayOf(value);\n }\n\n // Structural check: `version === 1` + callable `validate` is the minimum dispatchable\n // shape per the Standard Schema spec.\n static isStandardSchema(value: unknown): value is StandardSchemaV1 {\n if (typeof value !== 'object' || value === null) return false;\n if (!('~standard' in value)) return false;\n const slot = value['~standard'];\n if (typeof slot !== 'object' || slot === null) return false;\n const props = slot as { version?: unknown; validate?: unknown };\n return props.version === 1 && typeof props.validate === 'function';\n }\n\n static customConvertor<TFallback>(\n converter: EnvaptConverter<TFallback>\n ): asserts converter is ConverterFunction<TFallback> {\n if (typeof converter !== 'function') {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidCustomConverter,\n `Custom converter must be a function, got ${typeof converter}.`\n );\n }\n }\n\n /**\n * Runtime validation that the `ArrayOf<...>` configuration is well-formed.\n */\n static arrayConverter(value: unknown): asserts value is ArrayOf {\n if (!isArrayOf(value)) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidArrayConverterType,\n 'Expected an ArrayOf<...> token produced by Converters.array(...)'\n );\n }\n\n if (typeof value.delimiter !== 'string' || value.delimiter.length === 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingDelimiter,\n `ArrayOf<...> requires a non-empty string delimiter, got ${typeof value.delimiter}`\n );\n }\n\n const elementOf = value.of;\n const isScalar = typeof elementOf === 'string' && ListOfBuiltInConverters.includes(elementOf);\n const isCustomFn = typeof elementOf === 'function';\n if (!isScalar && !isCustomFn) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidArrayConverterType,\n `ArrayOf<...> element (\"of\") must be a built-in scalar token or a function, got ${typeof elementOf}`\n );\n }\n }\n\n /**\n * Validate that a string is a valid built-in scalar converter token\n */\n static builtInConverter(value: unknown): asserts value is BuiltInConverter {\n if (typeof value !== 'string') {\n throw new EnvaptError(EnvaptErrorCodes.InvalidConverterType, `Expected string, got ${typeof value}`);\n }\n\n if (!ListOfBuiltInConverters.includes(value as ConverterToken)) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidBuiltInConverter,\n `\"${value}\" is not a valid converter type. Valid types are: ${ListOfBuiltInConverters.join(',')}`\n );\n }\n }\n\n /**\n * Validate that fallback type matches the converter's return type for built-in converters\n */\n static validateBuiltInConverterFallback(converter: BuiltInConverter, fallback: unknown): void {\n const typeChecker = BuiltInConverterTypeCheckers[converter];\n if (!typeChecker(fallback)) {\n throw new EnvaptError(\n EnvaptErrorCodes.FallbackConverterTypeMismatch,\n `Fallback type does not match converter \"${converter}\". Expected ${converter} compatible type.`\n );\n }\n }\n\n /**\n * Validate that all elements in an array fallback have consistent types\n */\n static validateArrayFallbackElementTypes(fallback: unknown[]): void {\n if (fallback.length === 0) return;\n\n const firstElementType = typeof fallback[0];\n const hasInconsistentTypes = fallback.some((element, index) => {\n if (index === 0) return false;\n return typeof element !== firstElementType;\n });\n\n if (hasInconsistentTypes) {\n throw new EnvaptError(\n EnvaptErrorCodes.ArrayFallbackElementTypeMismatch,\n `All elements in array fallback must have the same type. Found mixed types.`\n );\n }\n }\n\n /**\n * Validate that an `ArrayOf<...>` element converter matches the runtime types of its\n * fallback elements. For `Converters.Time` arrays the element-time-string format is also\n * checked here.\n */\n static validateArrayConverterElementTypeMatch(elementOf: ArrayOf['of'], fallback: unknown[]): void {\n if (fallback.length === 0) return;\n\n if (typeof elementOf === 'function') {\n // Custom element converters can return anything; we can't statically validate the fallback shape.\n return;\n }\n\n const elementToken = elementOf;\n\n // Time array fallbacks may be number[] OR string[] (TimeFallback[]).\n if (elementToken === 'time') {\n const everyNumber = fallback.every((v) => typeof v === 'number');\n const everyString = fallback.every((v) => typeof v === 'string');\n if (!everyNumber && !everyString) {\n throw new EnvaptError(\n EnvaptErrorCodes.ArrayFallbackElementTypeMismatch,\n 'Time array fallback must be all numbers or all time-string entries.'\n );\n }\n return;\n }\n\n const typeChecker = BuiltInConverterTypeCheckers[elementToken];\n const firstElement = fallback[0];\n if (!typeChecker(firstElement)) {\n throw new EnvaptError(\n EnvaptErrorCodes.ArrayFallbackElementTypeMismatch,\n `Array converter type \"${elementToken}\" does not match fallback element type. Expected ${elementToken} compatible elements.`\n );\n }\n }\n\n /**\n * Check if a value is a primitive constructor\n */\n static isPrimitiveConstructor(\n value: unknown\n ): value is typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol {\n return value === String || value === Number || value === Boolean || value === BigInt || value === Symbol;\n }\n\n /**\n * Safely coerce a fallback value using a primitive constructor\n */\n static coercePrimitiveFallback<CoercedType>(\n converter: typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol,\n fallback: unknown\n ): CoercedType {\n if (this.isCorrectPrimitiveType(converter, fallback)) return fallback as CoercedType;\n return this.performPrimitiveCoercion<CoercedType>(converter, fallback);\n }\n\n private static isCorrectPrimitiveType(\n converter: typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol,\n fallback: unknown\n ): boolean {\n if (converter === String && typeof fallback === 'string') return true;\n if (converter === Number && typeof fallback === 'number') return true;\n if (converter === Boolean && typeof fallback === 'boolean') return true;\n if (converter === BigInt && typeof fallback === 'bigint') return true;\n if (converter === Symbol && typeof fallback === 'symbol') return true;\n return false;\n }\n\n private static performPrimitiveCoercion<CoercedType>(\n converter: typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol,\n fallback: unknown\n ): CoercedType {\n try {\n if (converter === String) return String(fallback) as CoercedType;\n if (converter === Number) return Number(fallback) as CoercedType;\n if (converter === Boolean) return Boolean(fallback) as CoercedType;\n if (converter === BigInt) return BigInt(fallback as string | number | bigint) as CoercedType;\n /* v8 ignore next -- @preserve */\n if (converter === Symbol) return Symbol.for(String(fallback)) as CoercedType;\n } catch (error) {\n throw new EnvaptError(\n EnvaptErrorCodes.PrimitiveCoercionFailed,\n `Failed to coerce fallback value using ${converter.name}: ${(error as Error).message}`\n );\n }\n\n /* v8 ignore next -- @preserve */\n throw new EnvaptError(\n EnvaptErrorCodes.PrimitiveCoercionFailed,\n `Unknown primitive converter: ${converter.name}`\n );\n }\n\n /**\n * Reject non-boolean inputs to `Envapter.syncProcessEnv` so a truthy typo\n * (`'true'`, `1`, etc.) does not silently enable the mirror.\n */\n static validateSyncProcessEnv(value: unknown): asserts value is boolean {\n if (typeof value !== 'boolean') {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Envapter.syncProcessEnv must be a boolean, got ${typeof value}.`\n );\n }\n }\n\n static validateFileApiMode(value: unknown): asserts value is FileApiMode {\n if (value !== 'warn' && value !== 'throw') {\n const got = typeof value === 'string' ? `'${value}'` : typeof value;\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Envapter.fileApiMode must be 'warn' or 'throw', got ${got}.`\n );\n }\n }\n\n /**\n * Make sure the user hasn't provided prohibited options in their dotenv config\n */\n static validateEnvFileOptions(config: object): config is EnvFileOptions {\n const validKeys = new Set(['encoding', 'override']);\n const invalidKeys = Object.keys(config).filter((key) => !validKeys.has(key));\n\n if (invalidKeys.length > 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Invalid envFileOptions: ${invalidKeys.join(', ')}. Allowed options: ${Array.from(validKeys).join(', ')}. For debug output, use Envapter.debug or the ENVAPT_DEBUG env var.`\n );\n }\n\n return true;\n }\n\n // Existence is probed through the caller-supplied `fileExists` (backed by the bound source) so\n // this stays free of `node:fs`.\n static validateEnvFilesExist(paths: string[], fileExists: (path: string) => boolean): void {\n const missing = paths.filter((p) => !fileExists(p));\n\n if (missing.length > 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.EnvFilesNotFound,\n `Environment file not found at path: ${missing.join(', ')}`\n );\n }\n }\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"Validators.cjs","names":["ListOfBuiltInConverters","isArrayOf","EnvaptError","BuiltInConverterTypeCheckers"],"sources":["../../../src/engine/Validators.ts"],"sourcesContent":["// the ./converters barrel imports ValueConverter, which imports this file\nimport { isArrayOf } from '../converters/Converters';\nimport { ListOfBuiltInConverters, BuiltInConverterTypeCheckers } from '../converters/ListOfBuiltInConverters';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { ArrayOf, ConverterToken } from '../converters/Converters';\nimport type { EnvFileOptions } from '../infra/Dotenv';\nimport type { StandardSchemaV1 } from '../infra/StandardSchema';\nimport type { BuiltInConverter, ConverterFunction, EnvaptConverter, FileApiMode } from '../types';\n\n// eslint-disable-next-line @typescript-eslint/no-extraneous-class -- cohesive dispatch of stateless type guards, same shape as BuiltInConverters\nexport class Validator {\n static isBuiltInConverter<TFallback>(value: EnvaptConverter<TFallback>): value is BuiltInConverter {\n if (typeof value === 'string') return ListOfBuiltInConverters.includes(value);\n return false;\n }\n\n static isArrayConverter(value: unknown): value is ArrayOf {\n return isArrayOf(value);\n }\n\n static isStandardSchema(value: unknown): value is StandardSchemaV1 {\n if (typeof value !== 'object' || value === null) return false;\n if (!('~standard' in value)) return false;\n const slot = value['~standard'];\n if (typeof slot !== 'object' || slot === null) return false;\n const props = slot as { version?: unknown; validate?: unknown };\n return props.version === 1 && typeof props.validate === 'function';\n }\n\n static customConvertor<TFallback>(\n converter: EnvaptConverter<TFallback>\n ): asserts converter is ConverterFunction<TFallback> {\n if (typeof converter !== 'function') {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidCustomConverter,\n `Custom converter must be a function, got ${typeof converter}.`\n );\n }\n }\n\n static arrayConverter(value: unknown): asserts value is ArrayOf {\n if (!isArrayOf(value)) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidArrayConverterType,\n 'Expected an ArrayOf<...> token produced by Converters.array(...)'\n );\n }\n\n if (typeof value.delimiter !== 'string' || value.delimiter.length === 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingDelimiter,\n `ArrayOf<...> requires a non-empty string delimiter, got ${typeof value.delimiter}`\n );\n }\n\n const elementOf = value.of;\n const isScalar = typeof elementOf === 'string' && ListOfBuiltInConverters.includes(elementOf);\n const isCustomFn = typeof elementOf === 'function';\n if (!isScalar && !isCustomFn) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidArrayConverterType,\n `ArrayOf<...> element (\"of\") must be a built-in scalar token or a function, got ${typeof elementOf}`\n );\n }\n }\n\n static builtInConverter(value: unknown): asserts value is BuiltInConverter {\n if (typeof value !== 'string') {\n throw new EnvaptError(EnvaptErrorCodes.InvalidConverterType, `Expected string, got ${typeof value}`);\n }\n\n if (!ListOfBuiltInConverters.includes(value as ConverterToken)) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidBuiltInConverter,\n `\"${value}\" is not a valid converter type. Valid types are: ${ListOfBuiltInConverters.join(',')}`\n );\n }\n }\n\n static validateBuiltInConverterFallback(converter: BuiltInConverter, fallback: unknown): void {\n const typeChecker = BuiltInConverterTypeCheckers[converter];\n if (!typeChecker(fallback)) {\n throw new EnvaptError(\n EnvaptErrorCodes.FallbackConverterTypeMismatch,\n `Fallback type does not match converter \"${converter}\". Expected ${converter} compatible type.`\n );\n }\n }\n\n static validateArrayFallbackElementTypes(fallback: unknown[]): void {\n if (fallback.length === 0) return;\n\n const firstElementType = typeof fallback[0];\n const hasInconsistentTypes = fallback.some((element, index) => {\n if (index === 0) return false;\n return typeof element !== firstElementType;\n });\n\n if (hasInconsistentTypes) {\n throw new EnvaptError(\n EnvaptErrorCodes.ArrayFallbackElementTypeMismatch,\n `All elements in array fallback must have the same type. Found mixed types.`\n );\n }\n }\n\n static validateArrayConverterElementTypeMatch(elementOf: ArrayOf['of'], fallback: unknown[]): void {\n if (fallback.length === 0) return;\n\n if (typeof elementOf === 'function') {\n // a custom element converter can return any type\n return;\n }\n\n const elementToken = elementOf;\n\n if (elementToken === 'time') {\n const everyNumber = fallback.every((v) => typeof v === 'number');\n const everyString = fallback.every((v) => typeof v === 'string');\n if (!everyNumber && !everyString) {\n throw new EnvaptError(\n EnvaptErrorCodes.ArrayFallbackElementTypeMismatch,\n 'Time array fallback must be all numbers or all time-string entries.'\n );\n }\n return;\n }\n\n const typeChecker = BuiltInConverterTypeCheckers[elementToken];\n const firstElement = fallback[0];\n if (!typeChecker(firstElement)) {\n throw new EnvaptError(\n EnvaptErrorCodes.ArrayFallbackElementTypeMismatch,\n `Array converter type \"${elementToken}\" does not match fallback element type. Expected ${elementToken} compatible elements.`\n );\n }\n }\n\n static isPrimitiveConstructor(\n value: unknown\n ): value is typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol {\n return value === String || value === Number || value === Boolean || value === BigInt || value === Symbol;\n }\n\n static coercePrimitiveFallback<CoercedType>(\n converter: typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol,\n fallback: unknown\n ): CoercedType {\n if (this.isCorrectPrimitiveType(converter, fallback)) return fallback as CoercedType;\n return this.performPrimitiveCoercion<CoercedType>(converter, fallback);\n }\n\n private static isCorrectPrimitiveType(\n converter: typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol,\n fallback: unknown\n ): boolean {\n if (converter === String && typeof fallback === 'string') return true;\n if (converter === Number && typeof fallback === 'number') return true;\n if (converter === Boolean && typeof fallback === 'boolean') return true;\n if (converter === BigInt && typeof fallback === 'bigint') return true;\n if (converter === Symbol && typeof fallback === 'symbol') return true;\n return false;\n }\n\n private static performPrimitiveCoercion<CoercedType>(\n converter: typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol,\n fallback: unknown\n ): CoercedType {\n try {\n if (converter === String) return String(fallback) as CoercedType;\n if (converter === Number) return Number(fallback) as CoercedType;\n if (converter === Boolean) return Boolean(fallback) as CoercedType;\n if (converter === BigInt) return BigInt(fallback as string | number | bigint) as CoercedType;\n /* v8 ignore next -- @preserve */\n if (converter === Symbol) return Symbol.for(String(fallback)) as CoercedType;\n } catch (error) {\n throw new EnvaptError(\n EnvaptErrorCodes.PrimitiveCoercionFailed,\n `Failed to coerce fallback value using ${converter.name}: ${(error as Error).message}`\n );\n }\n\n /* v8 ignore next -- @preserve */\n throw new EnvaptError(\n EnvaptErrorCodes.PrimitiveCoercionFailed,\n `Unknown primitive converter: ${converter.name}`\n );\n }\n\n // a truthy typo like 'true' or 1 would turn the mirror on\n static validateSyncProcessEnv(value: unknown): asserts value is boolean {\n if (typeof value !== 'boolean') {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Envapter.syncProcessEnv must be a boolean, got ${typeof value}.`\n );\n }\n }\n\n static validateFileApiMode(value: unknown): asserts value is FileApiMode {\n if (value !== 'warn' && value !== 'throw') {\n const got = typeof value === 'string' ? `'${value}'` : typeof value;\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Envapter.fileApiMode must be 'warn' or 'throw', got ${got}.`\n );\n }\n }\n\n static validateEnvFileOptions(config: object): config is EnvFileOptions {\n const validKeys = new Set(['encoding', 'override']);\n const invalidKeys = Object.keys(config).filter((key) => !validKeys.has(key));\n\n if (invalidKeys.length > 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Invalid envFileOptions: ${invalidKeys.join(', ')}. Allowed options: ${Array.from(validKeys).join(', ')}. For debug output, use Envapter.debug or the ENVAPT_DEBUG env var.`\n );\n }\n\n return true;\n }\n\n // fileExists comes from the caller because this file must not import node:fs\n static validateEnvFilesExist(paths: string[], fileExists: (path: string) => boolean): void {\n const missing = paths.filter((p) => !fileExists(p));\n\n if (missing.length > 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.EnvFilesNotFound,\n `Environment file not found at path: ${missing.join(', ')}`\n );\n }\n }\n}\n"],"mappings":"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"}
@@ -1 +1 @@
1
- {"version":3,"file":"Validators.mjs","names":[],"sources":["../../../src/engine/Validators.ts"],"sourcesContent":["// Import the converter modules directly, not via the `./converters` barrel: that barrel pulls in\n// ValueConverter, which imports this Validator, so a barrel import here would cycle.\nimport { isArrayOf } from '../converters/Converters';\nimport { ListOfBuiltInConverters, BuiltInConverterTypeCheckers } from '../converters/ListOfBuiltInConverters';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { ArrayOf, ConverterToken } from '../converters/Converters';\nimport type { EnvFileOptions } from '../infra/Dotenv';\nimport type { StandardSchemaV1 } from '../infra/StandardSchema';\nimport type { BuiltInConverter, ConverterFunction, EnvaptConverter, FileApiMode } from '../types';\n\n// eslint-disable-next-line @typescript-eslint/no-extraneous-class -- cohesive dispatch of stateless type guards, same shape as BuiltInConverters\nexport class Validator {\n /**\n * Check if a value is a built-in scalar converter token\n */\n static isBuiltInConverter<TFallback>(value: EnvaptConverter<TFallback>): value is BuiltInConverter {\n if (typeof value === 'string') return ListOfBuiltInConverters.includes(value);\n return false;\n }\n\n /**\n * Check if a value is an `ArrayOf<...>` token produced by {@link Converters.array}.\n */\n static isArrayConverter(value: unknown): value is ArrayOf {\n return isArrayOf(value);\n }\n\n // Structural check: `version === 1` + callable `validate` is the minimum dispatchable\n // shape per the Standard Schema spec.\n static isStandardSchema(value: unknown): value is StandardSchemaV1 {\n if (typeof value !== 'object' || value === null) return false;\n if (!('~standard' in value)) return false;\n const slot = value['~standard'];\n if (typeof slot !== 'object' || slot === null) return false;\n const props = slot as { version?: unknown; validate?: unknown };\n return props.version === 1 && typeof props.validate === 'function';\n }\n\n static customConvertor<TFallback>(\n converter: EnvaptConverter<TFallback>\n ): asserts converter is ConverterFunction<TFallback> {\n if (typeof converter !== 'function') {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidCustomConverter,\n `Custom converter must be a function, got ${typeof converter}.`\n );\n }\n }\n\n /**\n * Runtime validation that the `ArrayOf<...>` configuration is well-formed.\n */\n static arrayConverter(value: unknown): asserts value is ArrayOf {\n if (!isArrayOf(value)) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidArrayConverterType,\n 'Expected an ArrayOf<...> token produced by Converters.array(...)'\n );\n }\n\n if (typeof value.delimiter !== 'string' || value.delimiter.length === 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingDelimiter,\n `ArrayOf<...> requires a non-empty string delimiter, got ${typeof value.delimiter}`\n );\n }\n\n const elementOf = value.of;\n const isScalar = typeof elementOf === 'string' && ListOfBuiltInConverters.includes(elementOf);\n const isCustomFn = typeof elementOf === 'function';\n if (!isScalar && !isCustomFn) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidArrayConverterType,\n `ArrayOf<...> element (\"of\") must be a built-in scalar token or a function, got ${typeof elementOf}`\n );\n }\n }\n\n /**\n * Validate that a string is a valid built-in scalar converter token\n */\n static builtInConverter(value: unknown): asserts value is BuiltInConverter {\n if (typeof value !== 'string') {\n throw new EnvaptError(EnvaptErrorCodes.InvalidConverterType, `Expected string, got ${typeof value}`);\n }\n\n if (!ListOfBuiltInConverters.includes(value as ConverterToken)) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidBuiltInConverter,\n `\"${value}\" is not a valid converter type. Valid types are: ${ListOfBuiltInConverters.join(',')}`\n );\n }\n }\n\n /**\n * Validate that fallback type matches the converter's return type for built-in converters\n */\n static validateBuiltInConverterFallback(converter: BuiltInConverter, fallback: unknown): void {\n const typeChecker = BuiltInConverterTypeCheckers[converter];\n if (!typeChecker(fallback)) {\n throw new EnvaptError(\n EnvaptErrorCodes.FallbackConverterTypeMismatch,\n `Fallback type does not match converter \"${converter}\". Expected ${converter} compatible type.`\n );\n }\n }\n\n /**\n * Validate that all elements in an array fallback have consistent types\n */\n static validateArrayFallbackElementTypes(fallback: unknown[]): void {\n if (fallback.length === 0) return;\n\n const firstElementType = typeof fallback[0];\n const hasInconsistentTypes = fallback.some((element, index) => {\n if (index === 0) return false;\n return typeof element !== firstElementType;\n });\n\n if (hasInconsistentTypes) {\n throw new EnvaptError(\n EnvaptErrorCodes.ArrayFallbackElementTypeMismatch,\n `All elements in array fallback must have the same type. Found mixed types.`\n );\n }\n }\n\n /**\n * Validate that an `ArrayOf<...>` element converter matches the runtime types of its\n * fallback elements. For `Converters.Time` arrays the element-time-string format is also\n * checked here.\n */\n static validateArrayConverterElementTypeMatch(elementOf: ArrayOf['of'], fallback: unknown[]): void {\n if (fallback.length === 0) return;\n\n if (typeof elementOf === 'function') {\n // Custom element converters can return anything; we can't statically validate the fallback shape.\n return;\n }\n\n const elementToken = elementOf;\n\n // Time array fallbacks may be number[] OR string[] (TimeFallback[]).\n if (elementToken === 'time') {\n const everyNumber = fallback.every((v) => typeof v === 'number');\n const everyString = fallback.every((v) => typeof v === 'string');\n if (!everyNumber && !everyString) {\n throw new EnvaptError(\n EnvaptErrorCodes.ArrayFallbackElementTypeMismatch,\n 'Time array fallback must be all numbers or all time-string entries.'\n );\n }\n return;\n }\n\n const typeChecker = BuiltInConverterTypeCheckers[elementToken];\n const firstElement = fallback[0];\n if (!typeChecker(firstElement)) {\n throw new EnvaptError(\n EnvaptErrorCodes.ArrayFallbackElementTypeMismatch,\n `Array converter type \"${elementToken}\" does not match fallback element type. Expected ${elementToken} compatible elements.`\n );\n }\n }\n\n /**\n * Check if a value is a primitive constructor\n */\n static isPrimitiveConstructor(\n value: unknown\n ): value is typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol {\n return value === String || value === Number || value === Boolean || value === BigInt || value === Symbol;\n }\n\n /**\n * Safely coerce a fallback value using a primitive constructor\n */\n static coercePrimitiveFallback<CoercedType>(\n converter: typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol,\n fallback: unknown\n ): CoercedType {\n if (this.isCorrectPrimitiveType(converter, fallback)) return fallback as CoercedType;\n return this.performPrimitiveCoercion<CoercedType>(converter, fallback);\n }\n\n private static isCorrectPrimitiveType(\n converter: typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol,\n fallback: unknown\n ): boolean {\n if (converter === String && typeof fallback === 'string') return true;\n if (converter === Number && typeof fallback === 'number') return true;\n if (converter === Boolean && typeof fallback === 'boolean') return true;\n if (converter === BigInt && typeof fallback === 'bigint') return true;\n if (converter === Symbol && typeof fallback === 'symbol') return true;\n return false;\n }\n\n private static performPrimitiveCoercion<CoercedType>(\n converter: typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol,\n fallback: unknown\n ): CoercedType {\n try {\n if (converter === String) return String(fallback) as CoercedType;\n if (converter === Number) return Number(fallback) as CoercedType;\n if (converter === Boolean) return Boolean(fallback) as CoercedType;\n if (converter === BigInt) return BigInt(fallback as string | number | bigint) as CoercedType;\n /* v8 ignore next -- @preserve */\n if (converter === Symbol) return Symbol.for(String(fallback)) as CoercedType;\n } catch (error) {\n throw new EnvaptError(\n EnvaptErrorCodes.PrimitiveCoercionFailed,\n `Failed to coerce fallback value using ${converter.name}: ${(error as Error).message}`\n );\n }\n\n /* v8 ignore next -- @preserve */\n throw new EnvaptError(\n EnvaptErrorCodes.PrimitiveCoercionFailed,\n `Unknown primitive converter: ${converter.name}`\n );\n }\n\n /**\n * Reject non-boolean inputs to `Envapter.syncProcessEnv` so a truthy typo\n * (`'true'`, `1`, etc.) does not silently enable the mirror.\n */\n static validateSyncProcessEnv(value: unknown): asserts value is boolean {\n if (typeof value !== 'boolean') {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Envapter.syncProcessEnv must be a boolean, got ${typeof value}.`\n );\n }\n }\n\n static validateFileApiMode(value: unknown): asserts value is FileApiMode {\n if (value !== 'warn' && value !== 'throw') {\n const got = typeof value === 'string' ? `'${value}'` : typeof value;\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Envapter.fileApiMode must be 'warn' or 'throw', got ${got}.`\n );\n }\n }\n\n /**\n * Make sure the user hasn't provided prohibited options in their dotenv config\n */\n static validateEnvFileOptions(config: object): config is EnvFileOptions {\n const validKeys = new Set(['encoding', 'override']);\n const invalidKeys = Object.keys(config).filter((key) => !validKeys.has(key));\n\n if (invalidKeys.length > 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Invalid envFileOptions: ${invalidKeys.join(', ')}. Allowed options: ${Array.from(validKeys).join(', ')}. For debug output, use Envapter.debug or the ENVAPT_DEBUG env var.`\n );\n }\n\n return true;\n }\n\n // Existence is probed through the caller-supplied `fileExists` (backed by the bound source) so\n // this stays free of `node:fs`.\n static validateEnvFilesExist(paths: string[], fileExists: (path: string) => boolean): void {\n const missing = paths.filter((p) => !fileExists(p));\n\n if (missing.length > 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.EnvFilesNotFound,\n `Environment file not found at path: ${missing.join(', ')}`\n );\n }\n }\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"Validators.mjs","names":[],"sources":["../../../src/engine/Validators.ts"],"sourcesContent":["// the ./converters barrel imports ValueConverter, which imports this file\nimport { isArrayOf } from '../converters/Converters';\nimport { ListOfBuiltInConverters, BuiltInConverterTypeCheckers } from '../converters/ListOfBuiltInConverters';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { ArrayOf, ConverterToken } from '../converters/Converters';\nimport type { EnvFileOptions } from '../infra/Dotenv';\nimport type { StandardSchemaV1 } from '../infra/StandardSchema';\nimport type { BuiltInConverter, ConverterFunction, EnvaptConverter, FileApiMode } from '../types';\n\n// eslint-disable-next-line @typescript-eslint/no-extraneous-class -- cohesive dispatch of stateless type guards, same shape as BuiltInConverters\nexport class Validator {\n static isBuiltInConverter<TFallback>(value: EnvaptConverter<TFallback>): value is BuiltInConverter {\n if (typeof value === 'string') return ListOfBuiltInConverters.includes(value);\n return false;\n }\n\n static isArrayConverter(value: unknown): value is ArrayOf {\n return isArrayOf(value);\n }\n\n static isStandardSchema(value: unknown): value is StandardSchemaV1 {\n if (typeof value !== 'object' || value === null) return false;\n if (!('~standard' in value)) return false;\n const slot = value['~standard'];\n if (typeof slot !== 'object' || slot === null) return false;\n const props = slot as { version?: unknown; validate?: unknown };\n return props.version === 1 && typeof props.validate === 'function';\n }\n\n static customConvertor<TFallback>(\n converter: EnvaptConverter<TFallback>\n ): asserts converter is ConverterFunction<TFallback> {\n if (typeof converter !== 'function') {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidCustomConverter,\n `Custom converter must be a function, got ${typeof converter}.`\n );\n }\n }\n\n static arrayConverter(value: unknown): asserts value is ArrayOf {\n if (!isArrayOf(value)) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidArrayConverterType,\n 'Expected an ArrayOf<...> token produced by Converters.array(...)'\n );\n }\n\n if (typeof value.delimiter !== 'string' || value.delimiter.length === 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingDelimiter,\n `ArrayOf<...> requires a non-empty string delimiter, got ${typeof value.delimiter}`\n );\n }\n\n const elementOf = value.of;\n const isScalar = typeof elementOf === 'string' && ListOfBuiltInConverters.includes(elementOf);\n const isCustomFn = typeof elementOf === 'function';\n if (!isScalar && !isCustomFn) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidArrayConverterType,\n `ArrayOf<...> element (\"of\") must be a built-in scalar token or a function, got ${typeof elementOf}`\n );\n }\n }\n\n static builtInConverter(value: unknown): asserts value is BuiltInConverter {\n if (typeof value !== 'string') {\n throw new EnvaptError(EnvaptErrorCodes.InvalidConverterType, `Expected string, got ${typeof value}`);\n }\n\n if (!ListOfBuiltInConverters.includes(value as ConverterToken)) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidBuiltInConverter,\n `\"${value}\" is not a valid converter type. Valid types are: ${ListOfBuiltInConverters.join(',')}`\n );\n }\n }\n\n static validateBuiltInConverterFallback(converter: BuiltInConverter, fallback: unknown): void {\n const typeChecker = BuiltInConverterTypeCheckers[converter];\n if (!typeChecker(fallback)) {\n throw new EnvaptError(\n EnvaptErrorCodes.FallbackConverterTypeMismatch,\n `Fallback type does not match converter \"${converter}\". Expected ${converter} compatible type.`\n );\n }\n }\n\n static validateArrayFallbackElementTypes(fallback: unknown[]): void {\n if (fallback.length === 0) return;\n\n const firstElementType = typeof fallback[0];\n const hasInconsistentTypes = fallback.some((element, index) => {\n if (index === 0) return false;\n return typeof element !== firstElementType;\n });\n\n if (hasInconsistentTypes) {\n throw new EnvaptError(\n EnvaptErrorCodes.ArrayFallbackElementTypeMismatch,\n `All elements in array fallback must have the same type. Found mixed types.`\n );\n }\n }\n\n static validateArrayConverterElementTypeMatch(elementOf: ArrayOf['of'], fallback: unknown[]): void {\n if (fallback.length === 0) return;\n\n if (typeof elementOf === 'function') {\n // a custom element converter can return any type\n return;\n }\n\n const elementToken = elementOf;\n\n if (elementToken === 'time') {\n const everyNumber = fallback.every((v) => typeof v === 'number');\n const everyString = fallback.every((v) => typeof v === 'string');\n if (!everyNumber && !everyString) {\n throw new EnvaptError(\n EnvaptErrorCodes.ArrayFallbackElementTypeMismatch,\n 'Time array fallback must be all numbers or all time-string entries.'\n );\n }\n return;\n }\n\n const typeChecker = BuiltInConverterTypeCheckers[elementToken];\n const firstElement = fallback[0];\n if (!typeChecker(firstElement)) {\n throw new EnvaptError(\n EnvaptErrorCodes.ArrayFallbackElementTypeMismatch,\n `Array converter type \"${elementToken}\" does not match fallback element type. Expected ${elementToken} compatible elements.`\n );\n }\n }\n\n static isPrimitiveConstructor(\n value: unknown\n ): value is typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol {\n return value === String || value === Number || value === Boolean || value === BigInt || value === Symbol;\n }\n\n static coercePrimitiveFallback<CoercedType>(\n converter: typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol,\n fallback: unknown\n ): CoercedType {\n if (this.isCorrectPrimitiveType(converter, fallback)) return fallback as CoercedType;\n return this.performPrimitiveCoercion<CoercedType>(converter, fallback);\n }\n\n private static isCorrectPrimitiveType(\n converter: typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol,\n fallback: unknown\n ): boolean {\n if (converter === String && typeof fallback === 'string') return true;\n if (converter === Number && typeof fallback === 'number') return true;\n if (converter === Boolean && typeof fallback === 'boolean') return true;\n if (converter === BigInt && typeof fallback === 'bigint') return true;\n if (converter === Symbol && typeof fallback === 'symbol') return true;\n return false;\n }\n\n private static performPrimitiveCoercion<CoercedType>(\n converter: typeof String | typeof Number | typeof Boolean | typeof BigInt | typeof Symbol,\n fallback: unknown\n ): CoercedType {\n try {\n if (converter === String) return String(fallback) as CoercedType;\n if (converter === Number) return Number(fallback) as CoercedType;\n if (converter === Boolean) return Boolean(fallback) as CoercedType;\n if (converter === BigInt) return BigInt(fallback as string | number | bigint) as CoercedType;\n /* v8 ignore next -- @preserve */\n if (converter === Symbol) return Symbol.for(String(fallback)) as CoercedType;\n } catch (error) {\n throw new EnvaptError(\n EnvaptErrorCodes.PrimitiveCoercionFailed,\n `Failed to coerce fallback value using ${converter.name}: ${(error as Error).message}`\n );\n }\n\n /* v8 ignore next -- @preserve */\n throw new EnvaptError(\n EnvaptErrorCodes.PrimitiveCoercionFailed,\n `Unknown primitive converter: ${converter.name}`\n );\n }\n\n // a truthy typo like 'true' or 1 would turn the mirror on\n static validateSyncProcessEnv(value: unknown): asserts value is boolean {\n if (typeof value !== 'boolean') {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Envapter.syncProcessEnv must be a boolean, got ${typeof value}.`\n );\n }\n }\n\n static validateFileApiMode(value: unknown): asserts value is FileApiMode {\n if (value !== 'warn' && value !== 'throw') {\n const got = typeof value === 'string' ? `'${value}'` : typeof value;\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Envapter.fileApiMode must be 'warn' or 'throw', got ${got}.`\n );\n }\n }\n\n static validateEnvFileOptions(config: object): config is EnvFileOptions {\n const validKeys = new Set(['encoding', 'override']);\n const invalidKeys = Object.keys(config).filter((key) => !validKeys.has(key));\n\n if (invalidKeys.length > 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Invalid envFileOptions: ${invalidKeys.join(', ')}. Allowed options: ${Array.from(validKeys).join(', ')}. For debug output, use Envapter.debug or the ENVAPT_DEBUG env var.`\n );\n }\n\n return true;\n }\n\n // fileExists comes from the caller because this file must not import node:fs\n static validateEnvFilesExist(paths: string[], fileExists: (path: string) => boolean): void {\n const missing = paths.filter((p) => !fileExists(p));\n\n if (missing.length > 0) {\n throw new EnvaptError(\n EnvaptErrorCodes.EnvFilesNotFound,\n `Environment file not found at path: ${missing.join(', ')}`\n );\n }\n }\n}\n"],"mappings":"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"}