envapt 7.1.0 → 8.0.0-next.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.
- package/CHANGELOG.md +44 -99
- package/README.md +1 -1
- package/dist/node/converters/BuiltInConverters.cjs +1 -1
- package/dist/node/converters/BuiltInConverters.cjs.map +1 -1
- package/dist/node/converters/BuiltInConverters.mjs +1 -1
- package/dist/node/converters/BuiltInConverters.mjs.map +1 -1
- package/dist/node/converters/Converters.cjs.map +1 -1
- package/dist/node/converters/Converters.mjs.map +1 -1
- package/dist/node/converters/ValueConverter.cjs +1 -1
- package/dist/node/converters/ValueConverter.cjs.map +1 -1
- package/dist/node/converters/ValueConverter.mjs +1 -1
- package/dist/node/converters/ValueConverter.mjs.map +1 -1
- package/dist/node/core/AdvancedMethods.cjs +1 -1
- package/dist/node/core/AdvancedMethods.cjs.map +1 -1
- package/dist/node/core/AdvancedMethods.mjs +1 -1
- package/dist/node/core/AdvancedMethods.mjs.map +1 -1
- package/dist/node/core/EnvapterBase.cjs +1 -1
- package/dist/node/core/EnvapterBase.cjs.map +1 -1
- package/dist/node/core/EnvapterBase.mjs +1 -1
- package/dist/node/core/EnvapterBase.mjs.map +1 -1
- package/dist/node/core/Environment.cjs +2 -0
- package/dist/node/core/Environment.cjs.map +1 -0
- package/dist/node/core/Environment.mjs +2 -0
- package/dist/node/core/Environment.mjs.map +1 -0
- package/dist/node/core/EnvironmentMethods.cjs +1 -1
- package/dist/node/core/EnvironmentMethods.cjs.map +1 -1
- package/dist/node/core/EnvironmentMethods.mjs +1 -1
- package/dist/node/core/EnvironmentMethods.mjs.map +1 -1
- package/dist/node/core/PrimitiveMethods.cjs +1 -1
- package/dist/node/core/PrimitiveMethods.cjs.map +1 -1
- package/dist/node/core/PrimitiveMethods.mjs +1 -1
- package/dist/node/core/PrimitiveMethods.mjs.map +1 -1
- package/dist/node/core/engine.cjs +2 -0
- package/dist/node/core/engine.cjs.map +1 -0
- package/dist/node/core/engine.mjs +2 -0
- package/dist/node/core/engine.mjs.map +1 -0
- package/dist/node/core/missing.cjs +2 -0
- package/dist/node/core/missing.cjs.map +1 -0
- package/dist/node/core/missing.mjs +2 -0
- package/dist/node/core/missing.mjs.map +1 -0
- package/dist/node/core/paths.cjs +2 -0
- package/dist/node/core/paths.cjs.map +1 -0
- package/dist/node/core/paths.mjs +2 -0
- package/dist/node/core/paths.mjs.map +1 -0
- package/dist/node/core/state.cjs +2 -0
- package/dist/node/core/state.cjs.map +1 -0
- package/dist/node/core/state.mjs +2 -0
- package/dist/node/core/state.mjs.map +1 -0
- package/dist/node/decorators/legacy/Envapt.cjs.map +1 -1
- package/dist/node/decorators/legacy/Envapt.mjs.map +1 -1
- package/dist/node/decorators/legacy/SugarDecorators.cjs.map +1 -1
- package/dist/node/decorators/legacy/SugarDecorators.mjs.map +1 -1
- package/dist/node/decorators/modern/Envapt.cjs.map +1 -1
- package/dist/node/decorators/modern/Envapt.mjs.map +1 -1
- package/dist/node/decorators/modern/SugarDecorators.cjs.map +1 -1
- package/dist/node/decorators/modern/SugarDecorators.mjs.map +1 -1
- package/dist/node/decorators/resolveDecoratorValue.cjs +1 -1
- package/dist/node/decorators/resolveDecoratorValue.cjs.map +1 -1
- package/dist/node/decorators/resolveDecoratorValue.mjs +1 -1
- package/dist/node/decorators/resolveDecoratorValue.mjs.map +1 -1
- package/dist/node/engine/Envapter.cjs +1 -1
- package/dist/node/engine/Envapter.cjs.map +1 -1
- package/dist/node/engine/Envapter.mjs +1 -1
- package/dist/node/engine/Envapter.mjs.map +1 -1
- package/dist/node/engine/NodeEnvapter.cjs +1 -1
- package/dist/node/engine/NodeEnvapter.cjs.map +1 -1
- package/dist/node/engine/NodeEnvapter.mjs +1 -1
- package/dist/node/engine/NodeEnvapter.mjs.map +1 -1
- package/dist/node/engine/TemplateResolver.cjs +1 -1
- package/dist/node/engine/TemplateResolver.cjs.map +1 -1
- package/dist/node/engine/TemplateResolver.mjs +1 -1
- package/dist/node/engine/TemplateResolver.mjs.map +1 -1
- package/dist/node/engine/Validators.cjs +1 -1
- package/dist/node/engine/Validators.cjs.map +1 -1
- package/dist/node/engine/Validators.mjs +1 -1
- package/dist/node/engine/Validators.mjs.map +1 -1
- package/dist/node/index.cjs +1 -1
- package/dist/node/index.mjs +1 -1
- package/dist/node/infra/Debug.cjs +1 -1
- package/dist/node/infra/Debug.cjs.map +1 -1
- package/dist/node/infra/Debug.mjs +1 -1
- package/dist/node/infra/Debug.mjs.map +1 -1
- package/dist/node/infra/Dotenv.cjs.map +1 -1
- package/dist/node/infra/Dotenv.mjs.map +1 -1
- package/dist/node/infra/Error.cjs +1 -1
- package/dist/node/infra/Error.cjs.map +1 -1
- package/dist/node/infra/Error.mjs +1 -1
- package/dist/node/infra/Error.mjs.map +1 -1
- package/dist/node/infra/recase.cjs +2 -0
- package/dist/node/infra/recase.cjs.map +1 -0
- package/dist/node/infra/recase.mjs +2 -0
- package/dist/node/infra/recase.mjs.map +1 -0
- package/dist/node/infra/runtime.cjs +1 -1
- package/dist/node/infra/runtime.cjs.map +1 -1
- package/dist/node/infra/runtime.mjs +1 -1
- package/dist/node/infra/runtime.mjs.map +1 -1
- package/dist/node/sources/{NodeEnvSource.cjs → FileSource.cjs} +2 -2
- package/dist/node/sources/FileSource.cjs.map +1 -0
- package/dist/node/sources/{NodeEnvSource.mjs → FileSource.mjs} +2 -2
- package/dist/node/sources/FileSource.mjs.map +1 -0
- package/dist/node/sources/PortableSource.cjs.map +1 -1
- package/dist/node/sources/PortableSource.mjs.map +1 -1
- package/dist/node/sources/{UnboundEnvSource.cjs → UnboundSource.cjs} +2 -2
- package/dist/node/sources/UnboundSource.cjs.map +1 -0
- package/dist/{browser/sources/UnboundEnvSource.mjs → node/sources/UnboundSource.mjs} +2 -2
- package/dist/node/sources/UnboundSource.mjs.map +1 -0
- package/dist/node/sources/coerce.cjs.map +1 -1
- package/dist/node/sources/coerce.mjs.map +1 -1
- package/dist/node/sources/merge.cjs +2 -0
- package/dist/node/sources/merge.cjs.map +1 -0
- package/dist/node/sources/merge.mjs +2 -0
- package/dist/node/sources/merge.mjs.map +1 -0
- package/dist/node/sources/normalizeSource.cjs +2 -0
- package/dist/node/sources/normalizeSource.cjs.map +1 -0
- package/dist/node/sources/normalizeSource.mjs +2 -0
- package/dist/node/sources/normalizeSource.mjs.map +1 -0
- package/dist/portable/converters/BuiltInConverters.mjs +2 -0
- package/dist/portable/converters/BuiltInConverters.mjs.map +1 -0
- package/dist/portable/converters/Converters.mjs.map +1 -0
- package/dist/portable/converters/ValueConverter.mjs +2 -0
- package/dist/portable/converters/ValueConverter.mjs.map +1 -0
- package/dist/portable/core/AdvancedMethods.mjs +2 -0
- package/dist/portable/core/AdvancedMethods.mjs.map +1 -0
- package/dist/portable/core/EnvapterBase.mjs +2 -0
- package/dist/portable/core/EnvapterBase.mjs.map +1 -0
- package/dist/portable/core/Environment.mjs +2 -0
- package/dist/portable/core/Environment.mjs.map +1 -0
- package/dist/portable/core/EnvironmentMethods.mjs +2 -0
- package/dist/portable/core/EnvironmentMethods.mjs.map +1 -0
- package/dist/portable/core/PrimitiveMethods.mjs +2 -0
- package/dist/portable/core/PrimitiveMethods.mjs.map +1 -0
- package/dist/portable/core/engine.mjs +2 -0
- package/dist/portable/core/engine.mjs.map +1 -0
- package/dist/portable/core/missing.mjs +2 -0
- package/dist/portable/core/missing.mjs.map +1 -0
- package/dist/portable/core/paths.mjs +2 -0
- package/dist/portable/core/paths.mjs.map +1 -0
- package/dist/portable/core/state.mjs +2 -0
- package/dist/portable/core/state.mjs.map +1 -0
- package/dist/{workerd → portable}/decorators/legacy/Envapt.mjs.map +1 -1
- package/dist/portable/decorators/legacy/SugarDecorators.mjs.map +1 -0
- package/dist/{browser → portable}/decorators/modern/Envapt.mjs.map +1 -1
- package/dist/portable/decorators/modern/SugarDecorators.mjs.map +1 -0
- package/dist/portable/decorators/resolveDecoratorValue.mjs +2 -0
- package/dist/portable/decorators/resolveDecoratorValue.mjs.map +1 -0
- package/dist/portable/engine/Envapter.mjs +2 -0
- package/dist/portable/engine/Envapter.mjs.map +1 -0
- package/dist/portable/engine/PortableEnvapter.mjs +2 -0
- package/dist/portable/engine/PortableEnvapter.mjs.map +1 -0
- package/dist/portable/engine/TemplateResolver.mjs +2 -0
- package/dist/portable/engine/TemplateResolver.mjs.map +1 -0
- package/dist/portable/engine/Validators.mjs +2 -0
- package/dist/portable/engine/Validators.mjs.map +1 -0
- package/dist/portable/engine/fileApiStub.mjs +2 -0
- package/dist/portable/engine/fileApiStub.mjs.map +1 -0
- package/dist/portable/index.mjs +1 -0
- package/dist/portable/infra/Debug.mjs +2 -0
- package/dist/portable/infra/Debug.mjs.map +1 -0
- package/dist/portable/infra/Dotenv.mjs.map +1 -0
- package/dist/{browser → portable}/infra/Error.mjs +1 -1
- package/dist/portable/infra/Error.mjs.map +1 -0
- package/dist/portable/infra/recase.mjs +2 -0
- package/dist/portable/infra/recase.mjs.map +1 -0
- package/dist/portable/infra/runtime.mjs +2 -0
- package/dist/portable/infra/runtime.mjs.map +1 -0
- package/dist/portable/sources/PortableSource.mjs.map +1 -0
- package/dist/{node/sources/UnboundEnvSource.mjs → portable/sources/UnboundSource.mjs} +2 -2
- package/dist/portable/sources/UnboundSource.mjs.map +1 -0
- package/dist/portable/sources/coerce.mjs.map +1 -0
- package/dist/portable/sources/merge.mjs +2 -0
- package/dist/portable/sources/merge.mjs.map +1 -0
- package/dist/portable/sources/normalizeSource.mjs +2 -0
- package/dist/portable/sources/normalizeSource.mjs.map +1 -0
- package/dist/types/converters/Converters.d.mts +3 -24
- package/dist/types/core/AdvancedMethods.d.mts +40 -19
- package/dist/types/core/EnvapterBase.d.mts +21 -26
- package/dist/types/core/Environment.d.mts +26 -0
- package/dist/types/core/EnvironmentMethods.d.mts +8 -67
- package/dist/types/core/PrimitiveMethods.d.mts +7 -10
- package/dist/types/decorators/legacy/SugarDecorators.d.mts +5 -0
- package/dist/types/decorators/modern/SugarDecorators.d.mts +5 -0
- package/dist/types/engine/Envapter.d.mts +6 -5
- package/dist/types/engine/NodeEnvapter.d.mts +18 -9
- package/dist/types/engine/PortableEnvapter.d.mts +17 -5
- package/dist/types/index.d.mts +10 -14
- package/dist/types/index.portable.d.mts +9 -13
- package/dist/types/infra/Debug.d.mts +1 -0
- package/dist/types/infra/Dotenv.d.mts +1 -0
- package/dist/types/infra/Error.d.mts +5 -1
- package/dist/types/infra/StandardSchema.d.mts +2 -12
- package/dist/types/sources/{NodeEnvSource.d.mts → FileSource.d.mts} +6 -5
- package/dist/types/sources/PortableSource.d.mts +3 -2
- package/dist/types/sources/merge.d.mts +16 -0
- package/dist/types/types/Casing.d.mts +8 -0
- package/dist/types/types/Conversion.d.mts +12 -71
- package/dist/types/types/Decorator.d.mts +0 -14
- package/dist/types/types/Env.d.mts +1 -10
- package/dist/types/types/Options.d.mts +13 -2
- package/dist/types/types/Schema.d.mts +1 -13
- package/dist/types/types/Source.d.mts +11 -33
- package/package.json +62 -19
- package/aliases/browser.d.mts +0 -7
- package/aliases/browser.mjs +0 -4
- package/aliases/workerd.d.mts +0 -7
- package/aliases/workerd.mjs +0 -4
- package/dist/browser/converters/BuiltInConverters.mjs +0 -2
- package/dist/browser/converters/BuiltInConverters.mjs.map +0 -1
- package/dist/browser/converters/Converters.mjs.map +0 -1
- package/dist/browser/converters/ValueConverter.mjs +0 -2
- package/dist/browser/converters/ValueConverter.mjs.map +0 -1
- package/dist/browser/core/AdvancedMethods.mjs +0 -2
- package/dist/browser/core/AdvancedMethods.mjs.map +0 -1
- package/dist/browser/core/EnvapterBase.mjs +0 -2
- package/dist/browser/core/EnvapterBase.mjs.map +0 -1
- package/dist/browser/core/EnvironmentMethods.mjs +0 -2
- package/dist/browser/core/EnvironmentMethods.mjs.map +0 -1
- package/dist/browser/core/PrimitiveMethods.mjs +0 -2
- package/dist/browser/core/PrimitiveMethods.mjs.map +0 -1
- package/dist/browser/decorators/legacy/Envapt.mjs.map +0 -1
- package/dist/browser/decorators/legacy/SugarDecorators.mjs.map +0 -1
- package/dist/browser/decorators/modern/SugarDecorators.mjs.map +0 -1
- package/dist/browser/decorators/resolveDecoratorValue.mjs +0 -2
- package/dist/browser/decorators/resolveDecoratorValue.mjs.map +0 -1
- package/dist/browser/engine/Envapter.mjs +0 -2
- package/dist/browser/engine/Envapter.mjs.map +0 -1
- package/dist/browser/engine/PortableEnvapter.mjs +0 -2
- package/dist/browser/engine/PortableEnvapter.mjs.map +0 -1
- package/dist/browser/engine/TemplateResolver.mjs +0 -2
- package/dist/browser/engine/TemplateResolver.mjs.map +0 -1
- package/dist/browser/engine/Validators.mjs +0 -2
- package/dist/browser/engine/Validators.mjs.map +0 -1
- package/dist/browser/engine/installFileApiStubs.mjs +0 -2
- package/dist/browser/engine/installFileApiStubs.mjs.map +0 -1
- package/dist/browser/index.mjs +0 -1
- package/dist/browser/infra/Debug.mjs +0 -2
- package/dist/browser/infra/Debug.mjs.map +0 -1
- package/dist/browser/infra/Dotenv.mjs.map +0 -1
- package/dist/browser/infra/Error.mjs.map +0 -1
- package/dist/browser/infra/runtime.mjs +0 -2
- package/dist/browser/infra/runtime.mjs.map +0 -1
- package/dist/browser/sources/ManualEnvSource.mjs +0 -2
- package/dist/browser/sources/ManualEnvSource.mjs.map +0 -1
- package/dist/browser/sources/PortableSource.mjs.map +0 -1
- package/dist/browser/sources/UnboundEnvSource.mjs.map +0 -1
- package/dist/browser/sources/WorkerEnvSource.mjs +0 -2
- package/dist/browser/sources/WorkerEnvSource.mjs.map +0 -1
- package/dist/browser/sources/coerce.mjs.map +0 -1
- package/dist/node/sources/ManualEnvSource.cjs +0 -2
- package/dist/node/sources/ManualEnvSource.cjs.map +0 -1
- package/dist/node/sources/ManualEnvSource.mjs +0 -2
- package/dist/node/sources/ManualEnvSource.mjs.map +0 -1
- package/dist/node/sources/NodeEnvSource.cjs.map +0 -1
- package/dist/node/sources/NodeEnvSource.mjs.map +0 -1
- package/dist/node/sources/UnboundEnvSource.cjs.map +0 -1
- package/dist/node/sources/UnboundEnvSource.mjs.map +0 -1
- package/dist/node/sources/WorkerEnvSource.cjs +0 -2
- package/dist/node/sources/WorkerEnvSource.cjs.map +0 -1
- package/dist/node/sources/WorkerEnvSource.mjs +0 -2
- package/dist/node/sources/WorkerEnvSource.mjs.map +0 -1
- package/dist/types/converters/ValueConverter.d.mts +0 -25
- package/dist/types/engine/TemplateResolver.d.mts +0 -17
- package/dist/types/sources/ManualEnvSource.d.mts +0 -12
- package/dist/types/sources/WorkerEnvSource.d.mts +0 -12
- package/dist/workerd/converters/BuiltInConverters.mjs +0 -2
- package/dist/workerd/converters/BuiltInConverters.mjs.map +0 -1
- package/dist/workerd/converters/Converters.mjs +0 -2
- package/dist/workerd/converters/Converters.mjs.map +0 -1
- package/dist/workerd/converters/ListOfBuiltInConverters.mjs +0 -2
- package/dist/workerd/converters/ListOfBuiltInConverters.mjs.map +0 -1
- package/dist/workerd/converters/ValueConverter.mjs +0 -2
- package/dist/workerd/converters/ValueConverter.mjs.map +0 -1
- package/dist/workerd/core/AdvancedMethods.mjs +0 -2
- package/dist/workerd/core/AdvancedMethods.mjs.map +0 -1
- package/dist/workerd/core/EnvapterBase.mjs +0 -2
- package/dist/workerd/core/EnvapterBase.mjs.map +0 -1
- package/dist/workerd/core/EnvironmentMethods.mjs +0 -2
- package/dist/workerd/core/EnvironmentMethods.mjs.map +0 -1
- package/dist/workerd/core/PrimitiveMethods.mjs +0 -2
- package/dist/workerd/core/PrimitiveMethods.mjs.map +0 -1
- package/dist/workerd/decorators/legacy/Envapt.mjs +0 -2
- package/dist/workerd/decorators/legacy/SugarDecorators.mjs +0 -2
- package/dist/workerd/decorators/legacy/SugarDecorators.mjs.map +0 -1
- package/dist/workerd/decorators/legacy/createPropertyDecorator.mjs +0 -2
- package/dist/workerd/decorators/legacy/createPropertyDecorator.mjs.map +0 -1
- package/dist/workerd/decorators/modern/Envapt.mjs +0 -2
- package/dist/workerd/decorators/modern/Envapt.mjs.map +0 -1
- package/dist/workerd/decorators/modern/SugarDecorators.mjs +0 -2
- package/dist/workerd/decorators/modern/SugarDecorators.mjs.map +0 -1
- package/dist/workerd/decorators/modern/createAccessorDecorator.mjs +0 -2
- package/dist/workerd/decorators/modern/createAccessorDecorator.mjs.map +0 -1
- package/dist/workerd/decorators/parseEnvaptOptions.mjs +0 -2
- package/dist/workerd/decorators/parseEnvaptOptions.mjs.map +0 -1
- package/dist/workerd/decorators/resolveDecoratorValue.mjs +0 -2
- package/dist/workerd/decorators/resolveDecoratorValue.mjs.map +0 -1
- package/dist/workerd/engine/Envapter.mjs +0 -2
- package/dist/workerd/engine/Envapter.mjs.map +0 -1
- package/dist/workerd/engine/PortableEnvapter.mjs +0 -2
- package/dist/workerd/engine/PortableEnvapter.mjs.map +0 -1
- package/dist/workerd/engine/TemplateResolver.mjs +0 -2
- package/dist/workerd/engine/TemplateResolver.mjs.map +0 -1
- package/dist/workerd/engine/Validators.mjs +0 -2
- package/dist/workerd/engine/Validators.mjs.map +0 -1
- package/dist/workerd/engine/installFileApiStubs.mjs +0 -2
- package/dist/workerd/engine/installFileApiStubs.mjs.map +0 -1
- package/dist/workerd/index.mjs +0 -1
- package/dist/workerd/infra/Debug.mjs +0 -2
- package/dist/workerd/infra/Debug.mjs.map +0 -1
- package/dist/workerd/infra/Dotenv.mjs +0 -3
- package/dist/workerd/infra/Dotenv.mjs.map +0 -1
- package/dist/workerd/infra/Error.mjs +0 -2
- package/dist/workerd/infra/Error.mjs.map +0 -1
- package/dist/workerd/infra/runtime.mjs +0 -2
- package/dist/workerd/infra/runtime.mjs.map +0 -1
- package/dist/workerd/legacy.mjs +0 -1
- package/dist/workerd/sources/ManualEnvSource.mjs +0 -2
- package/dist/workerd/sources/ManualEnvSource.mjs.map +0 -1
- package/dist/workerd/sources/PortableSource.mjs +0 -2
- package/dist/workerd/sources/PortableSource.mjs.map +0 -1
- package/dist/workerd/sources/UnboundEnvSource.mjs +0 -2
- package/dist/workerd/sources/UnboundEnvSource.mjs.map +0 -1
- package/dist/workerd/sources/WorkerEnvSource.mjs +0 -2
- package/dist/workerd/sources/WorkerEnvSource.mjs.map +0 -1
- package/dist/workerd/sources/coerce.mjs +0 -2
- package/dist/workerd/sources/coerce.mjs.map +0 -1
- /package/dist/{browser → portable}/converters/Converters.mjs +0 -0
- /package/dist/{browser → portable}/converters/ListOfBuiltInConverters.mjs +0 -0
- /package/dist/{browser → portable}/converters/ListOfBuiltInConverters.mjs.map +0 -0
- /package/dist/{browser → portable}/decorators/legacy/Envapt.mjs +0 -0
- /package/dist/{browser → portable}/decorators/legacy/SugarDecorators.mjs +0 -0
- /package/dist/{browser → portable}/decorators/legacy/createPropertyDecorator.mjs +0 -0
- /package/dist/{browser → portable}/decorators/legacy/createPropertyDecorator.mjs.map +0 -0
- /package/dist/{browser → portable}/decorators/modern/Envapt.mjs +0 -0
- /package/dist/{browser → portable}/decorators/modern/SugarDecorators.mjs +0 -0
- /package/dist/{browser → portable}/decorators/modern/createAccessorDecorator.mjs +0 -0
- /package/dist/{browser → portable}/decorators/modern/createAccessorDecorator.mjs.map +0 -0
- /package/dist/{browser → portable}/decorators/parseEnvaptOptions.mjs +0 -0
- /package/dist/{browser → portable}/decorators/parseEnvaptOptions.mjs.map +0 -0
- /package/dist/{browser → portable}/infra/Dotenv.mjs +0 -0
- /package/dist/{browser → portable}/legacy.mjs +0 -0
- /package/dist/{browser → portable}/sources/PortableSource.mjs +0 -0
- /package/dist/{browser → portable}/sources/coerce.mjs +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Debug.cjs","names":["
|
|
1
|
+
{"version":3,"file":"Debug.cjs","names":["readRuntimeVar","EnvaptError"],"sources":["../../../src/infra/Debug.ts"],"sourcesContent":["import { EnvaptError, EnvaptErrorCodes } from './Error';\nimport { readRuntimeVar, writeRuntimeLine } from './runtime';\n\n/**\n * Debug log levels for {@link Envapter.debug}. `silent` (default) emits nothing.\n * `warn` covers signals that might indicate misconfiguration, failed file reads,\n * unresolved templates (when not strict), and any read of a missing or empty variable\n * (whether it returns a fallback or `undefined`). `verbose` adds every loaded file,\n * per-file key count, per-key load lines, and effective-paths / cache-rebuild notices.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/configuration#debug-logging}\n */\nexport type DebugLevel = 'silent' | 'warn' | 'verbose';\n\nconst VALID_LEVELS: ReadonlySet<string> = new Set<DebugLevel>(['silent', 'warn', 'verbose']);\n\nlet currentLevel: DebugLevel = 'silent';\nlet initialized = false;\n\nfunction isDebugLevel(value: string | undefined): value is DebugLevel {\n return value !== undefined && VALID_LEVELS.has(value);\n}\n\n// Reads `ENVAPT_DEBUG` lazily on first access. Setter wins after that.\nfunction resolveLevel(): DebugLevel {\n if (!initialized) {\n const fromEnv = readRuntimeVar('ENVAPT_DEBUG');\n currentLevel = isDebugLevel(fromEnv) ? fromEnv : 'silent';\n initialized = true;\n }\n return currentLevel;\n}\n\n/** @internal */\nexport function setDebugLevel(level: DebugLevel): void {\n if (!isDebugLevel(level)) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Invalid debug level \"${String(level)}\". Expected 'silent' | 'warn' | 'verbose'.`\n );\n }\n currentLevel = level;\n initialized = true;\n}\n\n/** @internal */\nexport function getDebugLevel(): DebugLevel {\n return resolveLevel();\n}\n\n/** @internal */\nexport function resetDebugForTesting(): void {\n currentLevel = 'silent';\n initialized = false;\n}\n\n/** @internal */\nexport function debugWarn(message: string): void {\n const level = resolveLevel();\n if (level === 'warn' || level === 'verbose') {\n writeRuntimeLine(`[envapt] ${message}`);\n }\n}\n\n/** @internal */\nexport function debugVerbose(message: string): void {\n if (resolveLevel() === 'verbose') {\n writeRuntimeLine(`[envapt] ${message}`);\n }\n}\n"],"mappings":"0DAcM,EAAoC,IAAI,IAAgB,CAAC,SAAU,OAAQ,SAAS,CAAC,EAE3F,IAAI,EAA2B,SAC3B,EAAc,GAElB,SAAS,EAAa,EAAgD,CAClE,OAAO,IAAU,IAAA,IAAa,EAAa,IAAI,CAAK,CACxD,CAGA,SAAS,GAA2B,CAChC,GAAI,CAAC,EAAa,CACd,IAAM,EAAUA,EAAAA,eAAe,cAAc,EAC7C,EAAe,EAAa,CAAO,EAAI,EAAU,SACjD,EAAc,EAClB,CACA,OAAO,CACX,CAGA,SAAgB,EAAc,EAAyB,CACnD,GAAI,CAAC,EAAa,CAAK,EACnB,MAAM,IAAIC,EAAAA,YAAAA,IAEN,wBAAwB,OAAO,CAAK,EAAE,2CAC1C,EAEJ,EAAe,EACf,EAAc,EAClB,CAGA,SAAgB,GAA4B,CACxC,OAAO,EAAa,CACxB,CASA,SAAgB,EAAU,EAAuB,CAC7C,IAAM,EAAQ,EAAa,GACvB,IAAU,QAAU,IAAU,YAC9B,EAAA,iBAAiB,YAAY,GAAS,CAE9C,CAGA,SAAgB,EAAa,EAAuB,CAC5C,EAAa,IAAM,WACnB,EAAA,iBAAiB,YAAY,GAAS,CAE9C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{EnvaptError as e}from"./Error.mjs";import{
|
|
1
|
+
import{EnvaptError as e}from"./Error.mjs";import{readRuntimeVar as t,writeRuntimeLine as n}from"./runtime.mjs";const r=new Set([`silent`,`warn`,`verbose`]);let i=`silent`,a=!1;function o(e){return e!==void 0&&r.has(e)}function s(){if(!a){let e=t(`ENVAPT_DEBUG`);i=o(e)?e:`silent`,a=!0}return i}function c(t){if(!o(t))throw new e(302,`Invalid debug level "${String(t)}". Expected 'silent' | 'warn' | 'verbose'.`);i=t,a=!0}function l(){return s()}function u(e){let t=s();(t===`warn`||t===`verbose`)&&n(`[envapt] ${e}`)}function d(e){s()===`verbose`&&n(`[envapt] ${e}`)}export{d as debugVerbose,u as debugWarn,l as getDebugLevel,c as setDebugLevel};
|
|
2
2
|
//# sourceMappingURL=Debug.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Debug.mjs","names":[],"sources":["../../../src/infra/Debug.ts"],"sourcesContent":["import { EnvaptError, EnvaptErrorCodes } from './Error';\nimport {
|
|
1
|
+
{"version":3,"file":"Debug.mjs","names":[],"sources":["../../../src/infra/Debug.ts"],"sourcesContent":["import { EnvaptError, EnvaptErrorCodes } from './Error';\nimport { readRuntimeVar, writeRuntimeLine } from './runtime';\n\n/**\n * Debug log levels for {@link Envapter.debug}. `silent` (default) emits nothing.\n * `warn` covers signals that might indicate misconfiguration, failed file reads,\n * unresolved templates (when not strict), and any read of a missing or empty variable\n * (whether it returns a fallback or `undefined`). `verbose` adds every loaded file,\n * per-file key count, per-key load lines, and effective-paths / cache-rebuild notices.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/configuration#debug-logging}\n */\nexport type DebugLevel = 'silent' | 'warn' | 'verbose';\n\nconst VALID_LEVELS: ReadonlySet<string> = new Set<DebugLevel>(['silent', 'warn', 'verbose']);\n\nlet currentLevel: DebugLevel = 'silent';\nlet initialized = false;\n\nfunction isDebugLevel(value: string | undefined): value is DebugLevel {\n return value !== undefined && VALID_LEVELS.has(value);\n}\n\n// Reads `ENVAPT_DEBUG` lazily on first access. Setter wins after that.\nfunction resolveLevel(): DebugLevel {\n if (!initialized) {\n const fromEnv = readRuntimeVar('ENVAPT_DEBUG');\n currentLevel = isDebugLevel(fromEnv) ? fromEnv : 'silent';\n initialized = true;\n }\n return currentLevel;\n}\n\n/** @internal */\nexport function setDebugLevel(level: DebugLevel): void {\n if (!isDebugLevel(level)) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Invalid debug level \"${String(level)}\". Expected 'silent' | 'warn' | 'verbose'.`\n );\n }\n currentLevel = level;\n initialized = true;\n}\n\n/** @internal */\nexport function getDebugLevel(): DebugLevel {\n return resolveLevel();\n}\n\n/** @internal */\nexport function resetDebugForTesting(): void {\n currentLevel = 'silent';\n initialized = false;\n}\n\n/** @internal */\nexport function debugWarn(message: string): void {\n const level = resolveLevel();\n if (level === 'warn' || level === 'verbose') {\n writeRuntimeLine(`[envapt] ${message}`);\n }\n}\n\n/** @internal */\nexport function debugVerbose(message: string): void {\n if (resolveLevel() === 'verbose') {\n writeRuntimeLine(`[envapt] ${message}`);\n }\n}\n"],"mappings":"+GAcA,MAAM,EAAoC,IAAI,IAAgB,CAAC,SAAU,OAAQ,SAAS,CAAC,EAE3F,IAAI,EAA2B,SAC3B,EAAc,GAElB,SAAS,EAAa,EAAgD,CAClE,OAAO,IAAU,IAAA,IAAa,EAAa,IAAI,CAAK,CACxD,CAGA,SAAS,GAA2B,CAChC,GAAI,CAAC,EAAa,CACd,IAAM,EAAU,EAAe,cAAc,EAC7C,EAAe,EAAa,CAAO,EAAI,EAAU,SACjD,EAAc,EAClB,CACA,OAAO,CACX,CAGA,SAAgB,EAAc,EAAyB,CACnD,GAAI,CAAC,EAAa,CAAK,EACnB,MAAM,IAAI,EAAA,IAEN,wBAAwB,OAAO,CAAK,EAAE,2CAC1C,EAEJ,EAAe,EACf,EAAc,EAClB,CAGA,SAAgB,GAA4B,CACxC,OAAO,EAAa,CACxB,CASA,SAAgB,EAAU,EAAuB,CAC7C,IAAM,EAAQ,EAAa,GACvB,IAAU,QAAU,IAAU,YAC9B,EAAiB,YAAY,GAAS,CAE9C,CAGA,SAAgB,EAAa,EAAuB,CAC5C,EAAa,IAAM,WACnB,EAAiB,YAAY,GAAS,CAE9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dotenv.cjs","names":[],"sources":["../../../src/infra/Dotenv.ts"],"sourcesContent":["import { debugVerbose, debugWarn } from './Debug';\n\n/**\n * Public options for the internal `.env` loader. Mirrors the subset of dotenv's\n * `config()` options that envapt actually supports (no DOTENV_KEY, no quiet).\n * For debug output, use `Envapter.debug` (or the `ENVAPT_DEBUG` env var).\n *\n * @public\n */\nexport interface EnvFileOptions {\n /** Encoding for reading .env files. Defaults to 'utf8'. */\n encoding?: string;\n /** When true, later files override earlier ones (and existing processEnv values). Default false (first-wins). */\n override?: boolean;\n}\n\n/**\n * Internal call signature used by `EnvapterBase`. The `path` and `processEnv`\n * fields are managed by envapt and never user-supplied.\n * @internal\n */\nexport interface LoadDotenvInput extends EnvFileOptions {\n path: string | string[];\n processEnv: Record<string, string>;\n // Injected so the loader stays free of `node:fs`. Returns `undefined` when the file is absent.\n readFile(path: string, encoding: string): string | undefined;\n}\n\n// Matches: optional `export`, KEY name, optional whitespace, `=`, optional whitespace, value tail.\n// Multi-line quoted values are handled by re-buffering subsequent lines below.\n// Bounded by anchors with linear-time quantifiers; no catastrophic backtracking risk -- justified\n// eslint-disable-next-line security/detect-unsafe-regex\nconst KEY_LINE_RE = /^\\s*(?:export\\s+)?([A-Za-z_][A-Za-z0-9_]*)\\s*=(.*)$/u;\n\n/**\n * Parse a `.env` text blob into a `Map<string, string>`.\n *\n * Supported syntax:\n * - `KEY=value` and `export KEY=value`\n * - blank lines and full-line `# comments`\n * - single-quoted `'literal'` values (no escape interpretation)\n * - double-quoted `\"value\"` values (interprets `\\n`, `\\r`, `\\t`, `\\\\`, `\\\"`)\n * - backtick-quoted values (literal, like single quotes)\n * - quoted values may span multiple lines\n * - inline `# comment` after an unquoted value (requires whitespace before `#`)\n * - empty values resolve to `\"\"`\n *\n * Mirrors dotenv's quirk where unescaped inner quotes inside a quoted value\n * are tolerated by greedy-matching to the rightmost matching quote on the\n * (possibly multi-line) value buffer. This is what lets a value like\n * `JSON=\"{\"name\":\"x\"}\"` round-trip without escaping.\n *\n * Does NOT perform `${VAR}` expansion — envapt's `Parser` handles that downstream.\n * @internal\n */\nexport function parseDotenv(src: string): Map<string, string> {\n const out = new Map<string, string>();\n const lines = src.split(/\\r?\\n/u);\n\n for (let i = 0; i < lines.length; i++) {\n const consumed = parseEntry(lines, i);\n i = consumed.endLine;\n if (consumed.entry) out.set(consumed.entry.key, consumed.entry.value);\n }\n\n return out;\n}\n\ninterface ParsedEntry {\n key: string;\n value: string;\n}\n\nfunction parseEntry(lines: string[], start: number): { entry: ParsedEntry | undefined; endLine: number } {\n /* v8 ignore next -- @preserve caller bounds-checks start so this never falls back */\n const line = lines[start] ?? '';\n const trimmedLine = line.trim();\n if (trimmedLine === '' || trimmedLine.startsWith('#')) return { entry: undefined, endLine: start };\n\n const match = line.match(KEY_LINE_RE);\n if (!match) return { entry: undefined, endLine: start };\n\n const key = match[1] as string;\n // Drop only leading whitespace before the value; trailing whitespace and inline comments\n // are dealt with below depending on whether the value is quoted.\n /* v8 ignore next -- @preserve regex group 2 always matches via `(.*)`, fallback is defensive */\n const rest = (match[2] ?? '').replace(/^\\s+/u, '');\n const firstChar = rest[0];\n\n if (firstChar === '\"' || firstChar === \"'\" || firstChar === '`') {\n const consumed = consumeQuotedValue(rest, lines, start, firstChar);\n return { entry: { key, value: consumed.value }, endLine: consumed.endLine };\n }\n\n return { entry: { key, value: stripInlineComment(rest) }, endLine: start };\n}\n\nfunction consumeQuotedValue(\n firstLineRest: string,\n lines: string[],\n startLine: number,\n quote: string\n): { value: string; endLine: number } {\n let buffer = firstLineRest;\n let cursor = startLine;\n let closeIdx = findLastUnescapedQuote(buffer, quote);\n\n while (closeIdx < 0 && cursor < lines.length - 1) {\n cursor++;\n /* v8 ignore next -- @preserve cursor is bounded by the while condition above */\n buffer += `\\n${lines[cursor] ?? ''}`;\n closeIdx = findLastUnescapedQuote(buffer, quote);\n }\n\n const inner = closeIdx > 0 ? buffer.slice(1, closeIdx) : buffer.slice(1);\n return { value: quote === '\"' ? unescapeDouble(inner) : inner, endLine: cursor };\n}\n\nfunction stripInlineComment(value: string): string {\n const hashIdx = findInlineCommentStart(value);\n const stripped = hashIdx === -1 ? value : value.slice(0, hashIdx);\n return stripped.trimEnd();\n}\n\nfunction findInlineCommentStart(value: string): number {\n for (let i = 0; i < value.length; i++) {\n if (value[i] === '#' && (i === 0 || /\\s/u.test(value[i - 1] as string))) return i;\n }\n return -1;\n}\n\n/**\n * Find the rightmost matching closing quote in `buffer` (skipping index 0 which is the\n * opening quote). For `\"`, a quote preceded by an odd number of backslashes is escaped\n * and ignored. Single and backtick quotes do not unescape.\n */\nfunction findLastUnescapedQuote(buffer: string, quote: string): number {\n for (let i = buffer.length - 1; i > 0; i--) {\n if (buffer[i] !== quote) continue;\n if (quote === '\"') {\n let backslashes = 0;\n let k = i - 1;\n while (k >= 0 && buffer[k] === '\\\\') {\n backslashes++;\n k--;\n }\n if (backslashes % 2 === 1) continue; // escaped\n }\n return i;\n }\n return -1;\n}\n\nfunction unescapeDouble(raw: string): string {\n let out = '';\n for (let i = 0; i < raw.length; i++) {\n const ch = raw[i];\n if (ch !== '\\\\' || i === raw.length - 1) {\n out += ch;\n continue;\n }\n const next = raw[i + 1];\n i++;\n switch (next) {\n case 'n':\n out += '\\n';\n break;\n case 'r':\n out += '\\r';\n break;\n case 't':\n out += '\\t';\n break;\n case '\\\\':\n out += '\\\\';\n break;\n case '\"':\n out += '\"';\n break;\n default:\n /* v8 ignore next -- @preserve `next` is always defined when this branch is reached (guarded above) */\n out += `\\\\${next ?? ''}`;\n }\n }\n return out;\n}\n\n/**\n * Load one or more `.env` files into a target `processEnv` map. Mirrors the\n * subset of dotenv's `config()` semantics that envapt depends on: first-wins\n * across multiple paths by default, optional `override: true`, optional\n * non-UTF8 encoding, missing files are skipped silently.\n *\n * Returns the set of keys actually written into `input.processEnv`. Skipped\n * collisions (under default `override: false`) are NOT included.\n * @internal\n */\nexport function loadDotenv(input: LoadDotenvInput): Set<string> {\n const paths = Array.isArray(input.path) ? input.path : [input.path];\n const encoding = input.encoding ?? 'utf8';\n const override = input.override ?? false;\n const written = new Set<string>();\n\n for (const filePath of paths) {\n const src = input.readFile(filePath, encoding);\n if (src === undefined) {\n debugWarn(`could not read ${filePath}`);\n continue;\n }\n\n const parsed = parseDotenv(src);\n debugVerbose(`loaded ${filePath}: ${parsed.size} ${parsed.size === 1 ? 'key' : 'keys'}`);\n for (const [key, value] of parsed) {\n const exists = Object.prototype.hasOwnProperty.call(input.processEnv, key);\n if (!exists || override) {\n input.processEnv[key] = value;\n written.add(key);\n debugVerbose(`${filePath} -> ${key}`);\n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QAAQ,EAAM,IAAI,EAAI,EAAM,KAAO,CAAC,EAAM,IAAI,EAC5D,EAAW,EAAM,UAAY,OAC7B,EAAW,EAAM,UAAY,GAC7B,EAAU,IAAI,IAEpB,IAAK,IAAM,KAAY,EAAO,CAC1B,IAAM,EAAM,EAAM,SAAS,EAAU,CAAQ,EAC7C,GAAI,IAAQ,IAAA,GAAW,CACnB,EAAA,UAAU,kBAAkB,GAAU,EACtC,QACJ,CAEA,IAAM,EAAS,EAAY,CAAG,EAC9B,EAAA,aAAa,UAAU,EAAS,IAAI,EAAO,KAAK,GAAG,EAAO,OAAS,EAAI,MAAQ,QAAQ,EACvF,IAAK,GAAM,CAAC,EAAK,KAAU,GAEnB,CADW,OAAO,UAAU,eAAe,KAAK,EAAM,WAAY,CAC5D,GAAK,KACX,EAAM,WAAW,GAAO,EACxB,EAAQ,IAAI,CAAG,EACf,EAAA,aAAa,GAAG,EAAS,MAAM,GAAK,EAGhD,CAEA,OAAO,CACX"}
|
|
1
|
+
{"version":3,"file":"Dotenv.cjs","names":[],"sources":["../../../src/infra/Dotenv.ts"],"sourcesContent":["import { debugVerbose, debugWarn } from './Debug';\n\n/**\n * Public options for the internal `.env` loader. Mirrors the subset of dotenv's\n * `config()` options that envapt actually supports (no DOTENV_KEY, no quiet).\n * For debug output, use `Envapter.debug` (or the `ENVAPT_DEBUG` env var).\n *\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\nexport interface EnvFileOptions {\n /** Encoding for reading .env files. Defaults to 'utf8'. */\n encoding?: string;\n /** When true, later files override earlier ones (and existing processEnv values). Default false (first-wins). */\n override?: boolean;\n}\n\n/**\n * Internal call signature used by `EnvapterBase`. The `path` and `processEnv`\n * fields are managed by envapt and never user-supplied.\n * @internal\n */\nexport interface LoadDotenvInput extends EnvFileOptions {\n path: string | string[];\n processEnv: Record<string, string>;\n // Injected so the loader stays free of `node:fs`. Returns `undefined` when the file is absent.\n readFile(path: string, encoding: string): string | undefined;\n}\n\n// Matches: optional `export`, KEY name, optional whitespace, `=`, optional whitespace, value tail.\n// Multi-line quoted values are handled by re-buffering subsequent lines below.\n// Bounded by anchors with linear-time quantifiers; no catastrophic backtracking risk -- justified\n// eslint-disable-next-line security/detect-unsafe-regex\nconst KEY_LINE_RE = /^\\s*(?:export\\s+)?([A-Za-z_][A-Za-z0-9_]*)\\s*=(.*)$/u;\n\n/**\n * Parse a `.env` text blob into a `Map<string, string>`.\n *\n * Supported syntax:\n * - `KEY=value` and `export KEY=value`\n * - blank lines and full-line `# comments`\n * - single-quoted `'literal'` values (no escape interpretation)\n * - double-quoted `\"value\"` values (interprets `\\n`, `\\r`, `\\t`, `\\\\`, `\\\"`)\n * - backtick-quoted values (literal, like single quotes)\n * - quoted values may span multiple lines\n * - inline `# comment` after an unquoted value (requires whitespace before `#`)\n * - empty values resolve to `\"\"`\n *\n * Mirrors dotenv's quirk where unescaped inner quotes inside a quoted value\n * are tolerated by greedy-matching to the rightmost matching quote on the\n * (possibly multi-line) value buffer. This is what lets a value like\n * `JSON=\"{\"name\":\"x\"}\"` round-trip without escaping.\n *\n * Does NOT perform `${VAR}` expansion — envapt's `Parser` handles that downstream.\n * @internal\n */\nexport function parseDotenv(src: string): Map<string, string> {\n const out = new Map<string, string>();\n const lines = src.split(/\\r?\\n/u);\n\n for (let i = 0; i < lines.length; i++) {\n const consumed = parseEntry(lines, i);\n i = consumed.endLine;\n if (consumed.entry) out.set(consumed.entry.key, consumed.entry.value);\n }\n\n return out;\n}\n\ninterface ParsedEntry {\n key: string;\n value: string;\n}\n\nfunction parseEntry(lines: string[], start: number): { entry: ParsedEntry | undefined; endLine: number } {\n /* v8 ignore next -- @preserve caller bounds-checks start so this never falls back */\n const line = lines[start] ?? '';\n const trimmedLine = line.trim();\n if (trimmedLine === '' || trimmedLine.startsWith('#')) return { entry: undefined, endLine: start };\n\n const match = line.match(KEY_LINE_RE);\n if (!match) return { entry: undefined, endLine: start };\n\n const key = match[1] as string;\n // Drop only leading whitespace before the value; trailing whitespace and inline comments\n // are dealt with below depending on whether the value is quoted.\n /* v8 ignore next -- @preserve regex group 2 always matches via `(.*)`, fallback is defensive */\n const rest = (match[2] ?? '').replace(/^\\s+/u, '');\n const firstChar = rest[0];\n\n if (firstChar === '\"' || firstChar === \"'\" || firstChar === '`') {\n const consumed = consumeQuotedValue(rest, lines, start, firstChar);\n return { entry: { key, value: consumed.value }, endLine: consumed.endLine };\n }\n\n return { entry: { key, value: stripInlineComment(rest) }, endLine: start };\n}\n\nfunction consumeQuotedValue(\n firstLineRest: string,\n lines: string[],\n startLine: number,\n quote: string\n): { value: string; endLine: number } {\n let buffer = firstLineRest;\n let cursor = startLine;\n let closeIdx = findLastUnescapedQuote(buffer, quote);\n\n while (closeIdx < 0 && cursor < lines.length - 1) {\n cursor++;\n /* v8 ignore next -- @preserve cursor is bounded by the while condition above */\n buffer += `\\n${lines[cursor] ?? ''}`;\n closeIdx = findLastUnescapedQuote(buffer, quote);\n }\n\n const inner = closeIdx > 0 ? buffer.slice(1, closeIdx) : buffer.slice(1);\n return { value: quote === '\"' ? unescapeDouble(inner) : inner, endLine: cursor };\n}\n\nfunction stripInlineComment(value: string): string {\n const hashIdx = findInlineCommentStart(value);\n const stripped = hashIdx === -1 ? value : value.slice(0, hashIdx);\n return stripped.trimEnd();\n}\n\nfunction findInlineCommentStart(value: string): number {\n for (let i = 0; i < value.length; i++) {\n if (value[i] === '#' && (i === 0 || /\\s/u.test(value[i - 1] as string))) return i;\n }\n return -1;\n}\n\n/**\n * Find the rightmost matching closing quote in `buffer` (skipping index 0 which is the\n * opening quote). For `\"`, a quote preceded by an odd number of backslashes is escaped\n * and ignored. Single and backtick quotes do not unescape.\n */\nfunction findLastUnescapedQuote(buffer: string, quote: string): number {\n for (let i = buffer.length - 1; i > 0; i--) {\n if (buffer[i] !== quote) continue;\n if (quote === '\"') {\n let backslashes = 0;\n let k = i - 1;\n while (k >= 0 && buffer[k] === '\\\\') {\n backslashes++;\n k--;\n }\n if (backslashes % 2 === 1) continue; // escaped\n }\n return i;\n }\n return -1;\n}\n\nfunction unescapeDouble(raw: string): string {\n let out = '';\n for (let i = 0; i < raw.length; i++) {\n const ch = raw[i];\n if (ch !== '\\\\' || i === raw.length - 1) {\n out += ch;\n continue;\n }\n const next = raw[i + 1];\n i++;\n switch (next) {\n case 'n':\n out += '\\n';\n break;\n case 'r':\n out += '\\r';\n break;\n case 't':\n out += '\\t';\n break;\n case '\\\\':\n out += '\\\\';\n break;\n case '\"':\n out += '\"';\n break;\n default:\n /* v8 ignore next -- @preserve `next` is always defined when this branch is reached (guarded above) */\n out += `\\\\${next ?? ''}`;\n }\n }\n return out;\n}\n\n/**\n * Load one or more `.env` files into a target `processEnv` map. Mirrors the\n * subset of dotenv's `config()` semantics that envapt depends on: first-wins\n * across multiple paths by default, optional `override: true`, optional\n * non-UTF8 encoding, missing files are skipped silently.\n *\n * Returns the set of keys actually written into `input.processEnv`. Skipped\n * collisions (under default `override: false`) are NOT included.\n * @internal\n */\nexport function loadDotenv(input: LoadDotenvInput): Set<string> {\n const paths = Array.isArray(input.path) ? input.path : [input.path];\n const encoding = input.encoding ?? 'utf8';\n const override = input.override ?? false;\n const written = new Set<string>();\n\n for (const filePath of paths) {\n const src = input.readFile(filePath, encoding);\n if (src === undefined) {\n debugWarn(`could not read ${filePath}`);\n continue;\n }\n\n const parsed = parseDotenv(src);\n debugVerbose(`loaded ${filePath}: ${parsed.size} ${parsed.size === 1 ? 'key' : 'keys'}`);\n for (const [key, value] of parsed) {\n const exists = Object.prototype.hasOwnProperty.call(input.processEnv, key);\n if (!exists || override) {\n input.processEnv[key] = value;\n written.add(key);\n debugVerbose(`${filePath} -> ${key}`);\n }\n }\n }\n\n return written;\n}\n"],"mappings":"+BAiCM,EAAc,uDAuBpB,SAAgB,EAAY,EAAkC,CAC1D,IAAM,EAAM,IAAI,IACV,EAAQ,EAAI,MAAM,QAAQ,EAEhC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAA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,SAAS,EAAU,CAAQ,EAC7C,GAAI,IAAQ,IAAA,GAAW,CACnB,EAAA,UAAU,kBAAkB,GAAU,EACtC,QACJ,CAEA,IAAM,EAAS,EAAY,CAAG,EAC9B,EAAA,aAAa,UAAU,EAAS,IAAI,EAAO,KAAK,GAAG,EAAO,OAAS,EAAI,MAAQ,QAAQ,EACvF,IAAK,GAAM,CAAC,EAAK,KAAU,GAEnB,CADW,OAAO,UAAU,eAAe,KAAK,EAAM,WAAY,CAC5D,GAAK,KACX,EAAM,WAAW,GAAO,EACxB,EAAQ,IAAI,CAAG,EACf,EAAA,aAAa,GAAG,EAAS,MAAM,GAAK,EAGhD,CAEA,OAAO,CACX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dotenv.mjs","names":[],"sources":["../../../src/infra/Dotenv.ts"],"sourcesContent":["import { debugVerbose, debugWarn } from './Debug';\n\n/**\n * Public options for the internal `.env` loader. Mirrors the subset of dotenv's\n * `config()` options that envapt actually supports (no DOTENV_KEY, no quiet).\n * For debug output, use `Envapter.debug` (or the `ENVAPT_DEBUG` env var).\n *\n * @public\n */\nexport interface EnvFileOptions {\n /** Encoding for reading .env files. Defaults to 'utf8'. */\n encoding?: string;\n /** When true, later files override earlier ones (and existing processEnv values). Default false (first-wins). */\n override?: boolean;\n}\n\n/**\n * Internal call signature used by `EnvapterBase`. The `path` and `processEnv`\n * fields are managed by envapt and never user-supplied.\n * @internal\n */\nexport interface LoadDotenvInput extends EnvFileOptions {\n path: string | string[];\n processEnv: Record<string, string>;\n // Injected so the loader stays free of `node:fs`. Returns `undefined` when the file is absent.\n readFile(path: string, encoding: string): string | undefined;\n}\n\n// Matches: optional `export`, KEY name, optional whitespace, `=`, optional whitespace, value tail.\n// Multi-line quoted values are handled by re-buffering subsequent lines below.\n// Bounded by anchors with linear-time quantifiers; no catastrophic backtracking risk -- justified\n// eslint-disable-next-line security/detect-unsafe-regex\nconst KEY_LINE_RE = /^\\s*(?:export\\s+)?([A-Za-z_][A-Za-z0-9_]*)\\s*=(.*)$/u;\n\n/**\n * Parse a `.env` text blob into a `Map<string, string>`.\n *\n * Supported syntax:\n * - `KEY=value` and `export KEY=value`\n * - blank lines and full-line `# comments`\n * - single-quoted `'literal'` values (no escape interpretation)\n * - double-quoted `\"value\"` values (interprets `\\n`, `\\r`, `\\t`, `\\\\`, `\\\"`)\n * - backtick-quoted values (literal, like single quotes)\n * - quoted values may span multiple lines\n * - inline `# comment` after an unquoted value (requires whitespace before `#`)\n * - empty values resolve to `\"\"`\n *\n * Mirrors dotenv's quirk where unescaped inner quotes inside a quoted value\n * are tolerated by greedy-matching to the rightmost matching quote on the\n * (possibly multi-line) value buffer. This is what lets a value like\n * `JSON=\"{\"name\":\"x\"}\"` round-trip without escaping.\n *\n * Does NOT perform `${VAR}` expansion — envapt's `Parser` handles that downstream.\n * @internal\n */\nexport function parseDotenv(src: string): Map<string, string> {\n const out = new Map<string, string>();\n const lines = src.split(/\\r?\\n/u);\n\n for (let i = 0; i < lines.length; i++) {\n const consumed = parseEntry(lines, i);\n i = consumed.endLine;\n if (consumed.entry) out.set(consumed.entry.key, consumed.entry.value);\n }\n\n return out;\n}\n\ninterface ParsedEntry {\n key: string;\n value: string;\n}\n\nfunction parseEntry(lines: string[], start: number): { entry: ParsedEntry | undefined; endLine: number } {\n /* v8 ignore next -- @preserve caller bounds-checks start so this never falls back */\n const line = lines[start] ?? '';\n const trimmedLine = line.trim();\n if (trimmedLine === '' || trimmedLine.startsWith('#')) return { entry: undefined, endLine: start };\n\n const match = line.match(KEY_LINE_RE);\n if (!match) return { entry: undefined, endLine: start };\n\n const key = match[1] as string;\n // Drop only leading whitespace before the value; trailing whitespace and inline comments\n // are dealt with below depending on whether the value is quoted.\n /* v8 ignore next -- @preserve regex group 2 always matches via `(.*)`, fallback is defensive */\n const rest = (match[2] ?? '').replace(/^\\s+/u, '');\n const firstChar = rest[0];\n\n if (firstChar === '\"' || firstChar === \"'\" || firstChar === '`') {\n const consumed = consumeQuotedValue(rest, lines, start, firstChar);\n return { entry: { key, value: consumed.value }, endLine: consumed.endLine };\n }\n\n return { entry: { key, value: stripInlineComment(rest) }, endLine: start };\n}\n\nfunction consumeQuotedValue(\n firstLineRest: string,\n lines: string[],\n startLine: number,\n quote: string\n): { value: string; endLine: number } {\n let buffer = firstLineRest;\n let cursor = startLine;\n let closeIdx = findLastUnescapedQuote(buffer, quote);\n\n while (closeIdx < 0 && cursor < lines.length - 1) {\n cursor++;\n /* v8 ignore next -- @preserve cursor is bounded by the while condition above */\n buffer += `\\n${lines[cursor] ?? ''}`;\n closeIdx = findLastUnescapedQuote(buffer, quote);\n }\n\n const inner = closeIdx > 0 ? buffer.slice(1, closeIdx) : buffer.slice(1);\n return { value: quote === '\"' ? unescapeDouble(inner) : inner, endLine: cursor };\n}\n\nfunction stripInlineComment(value: string): string {\n const hashIdx = findInlineCommentStart(value);\n const stripped = hashIdx === -1 ? value : value.slice(0, hashIdx);\n return stripped.trimEnd();\n}\n\nfunction findInlineCommentStart(value: string): number {\n for (let i = 0; i < value.length; i++) {\n if (value[i] === '#' && (i === 0 || /\\s/u.test(value[i - 1] as string))) return i;\n }\n return -1;\n}\n\n/**\n * Find the rightmost matching closing quote in `buffer` (skipping index 0 which is the\n * opening quote). For `\"`, a quote preceded by an odd number of backslashes is escaped\n * and ignored. Single and backtick quotes do not unescape.\n */\nfunction findLastUnescapedQuote(buffer: string, quote: string): number {\n for (let i = buffer.length - 1; i > 0; i--) {\n if (buffer[i] !== quote) continue;\n if (quote === '\"') {\n let backslashes = 0;\n let k = i - 1;\n while (k >= 0 && buffer[k] === '\\\\') {\n backslashes++;\n k--;\n }\n if (backslashes % 2 === 1) continue; // escaped\n }\n return i;\n }\n return -1;\n}\n\nfunction unescapeDouble(raw: string): string {\n let out = '';\n for (let i = 0; i < raw.length; i++) {\n const ch = raw[i];\n if (ch !== '\\\\' || i === raw.length - 1) {\n out += ch;\n continue;\n }\n const next = raw[i + 1];\n i++;\n switch (next) {\n case 'n':\n out += '\\n';\n break;\n case 'r':\n out += '\\r';\n break;\n case 't':\n out += '\\t';\n break;\n case '\\\\':\n out += '\\\\';\n break;\n case '\"':\n out += '\"';\n break;\n default:\n /* v8 ignore next -- @preserve `next` is always defined when this branch is reached (guarded above) */\n out += `\\\\${next ?? ''}`;\n }\n }\n return out;\n}\n\n/**\n * Load one or more `.env` files into a target `processEnv` map. Mirrors the\n * subset of dotenv's `config()` semantics that envapt depends on: first-wins\n * across multiple paths by default, optional `override: true`, optional\n * non-UTF8 encoding, missing files are skipped silently.\n *\n * Returns the set of keys actually written into `input.processEnv`. Skipped\n * collisions (under default `override: false`) are NOT included.\n * @internal\n */\nexport function loadDotenv(input: LoadDotenvInput): Set<string> {\n const paths = Array.isArray(input.path) ? input.path : [input.path];\n const encoding = input.encoding ?? 'utf8';\n const override = input.override ?? false;\n const written = new Set<string>();\n\n for (const filePath of paths) {\n const src = input.readFile(filePath, encoding);\n if (src === undefined) {\n debugWarn(`could not read ${filePath}`);\n continue;\n }\n\n const parsed = parseDotenv(src);\n debugVerbose(`loaded ${filePath}: ${parsed.size} ${parsed.size === 1 ? 'key' : 'keys'}`);\n for (const [key, value] of parsed) {\n const exists = Object.prototype.hasOwnProperty.call(input.processEnv, key);\n if (!exists || override) {\n input.processEnv[key] = value;\n written.add(key);\n debugVerbose(`${filePath} -> ${key}`);\n }\n }\n }\n\n return written;\n}\n"],"mappings":"0DAgCA,MAAM,EAAc,uDAuBpB,SAAgB,EAAY,EAAkC,CAC1D,IAAM,EAAM,IAAI,IACV,EAAQ,EAAI,MAAM,QAAQ,EAEhC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAAK,CACnC,IAAM,EAAW,EAAW,EAAO,CAAC,EACpC,EAAI,EAAS,QACT,EAAS,OAAO,EAAI,IAAI,EAAS,MAAM,IAAK,EAAS,MAAM,KAAK,CACxE,CAEA,OAAO,CACX,CAOA,SAAS,EAAW,EAAiB,EAAoE,CAErG,IAAM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,QAAQ,EACvF,IAAK,GAAM,CAAC,EAAK,KAAU,GAEnB,CADW,OAAO,UAAU,eAAe,KAAK,EAAM,WAAY,CAC5D,GAAK,KACX,EAAM,WAAW,GAAO,EACxB,EAAQ,IAAI,CAAG,EACf,EAAa,GAAG,EAAS,MAAM,GAAK,EAGhD,CAEA,OAAO,CACX"}
|
|
1
|
+
{"version":3,"file":"Dotenv.mjs","names":[],"sources":["../../../src/infra/Dotenv.ts"],"sourcesContent":["import { debugVerbose, debugWarn } from './Debug';\n\n/**\n * Public options for the internal `.env` loader. Mirrors the subset of dotenv's\n * `config()` options that envapt actually supports (no DOTENV_KEY, no quiet).\n * For debug output, use `Envapter.debug` (or the `ENVAPT_DEBUG` env var).\n *\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/configuration#which-files-load}\n */\nexport interface EnvFileOptions {\n /** Encoding for reading .env files. Defaults to 'utf8'. */\n encoding?: string;\n /** When true, later files override earlier ones (and existing processEnv values). Default false (first-wins). */\n override?: boolean;\n}\n\n/**\n * Internal call signature used by `EnvapterBase`. The `path` and `processEnv`\n * fields are managed by envapt and never user-supplied.\n * @internal\n */\nexport interface LoadDotenvInput extends EnvFileOptions {\n path: string | string[];\n processEnv: Record<string, string>;\n // Injected so the loader stays free of `node:fs`. Returns `undefined` when the file is absent.\n readFile(path: string, encoding: string): string | undefined;\n}\n\n// Matches: optional `export`, KEY name, optional whitespace, `=`, optional whitespace, value tail.\n// Multi-line quoted values are handled by re-buffering subsequent lines below.\n// Bounded by anchors with linear-time quantifiers; no catastrophic backtracking risk -- justified\n// eslint-disable-next-line security/detect-unsafe-regex\nconst KEY_LINE_RE = /^\\s*(?:export\\s+)?([A-Za-z_][A-Za-z0-9_]*)\\s*=(.*)$/u;\n\n/**\n * Parse a `.env` text blob into a `Map<string, string>`.\n *\n * Supported syntax:\n * - `KEY=value` and `export KEY=value`\n * - blank lines and full-line `# comments`\n * - single-quoted `'literal'` values (no escape interpretation)\n * - double-quoted `\"value\"` values (interprets `\\n`, `\\r`, `\\t`, `\\\\`, `\\\"`)\n * - backtick-quoted values (literal, like single quotes)\n * - quoted values may span multiple lines\n * - inline `# comment` after an unquoted value (requires whitespace before `#`)\n * - empty values resolve to `\"\"`\n *\n * Mirrors dotenv's quirk where unescaped inner quotes inside a quoted value\n * are tolerated by greedy-matching to the rightmost matching quote on the\n * (possibly multi-line) value buffer. This is what lets a value like\n * `JSON=\"{\"name\":\"x\"}\"` round-trip without escaping.\n *\n * Does NOT perform `${VAR}` expansion — envapt's `Parser` handles that downstream.\n * @internal\n */\nexport function parseDotenv(src: string): Map<string, string> {\n const out = new Map<string, string>();\n const lines = src.split(/\\r?\\n/u);\n\n for (let i = 0; i < lines.length; i++) {\n const consumed = parseEntry(lines, i);\n i = consumed.endLine;\n if (consumed.entry) out.set(consumed.entry.key, consumed.entry.value);\n }\n\n return out;\n}\n\ninterface ParsedEntry {\n key: string;\n value: string;\n}\n\nfunction parseEntry(lines: string[], start: number): { entry: ParsedEntry | undefined; endLine: number } {\n /* v8 ignore next -- @preserve caller bounds-checks start so this never falls back */\n const line = lines[start] ?? '';\n const trimmedLine = line.trim();\n if (trimmedLine === '' || trimmedLine.startsWith('#')) return { entry: undefined, endLine: start };\n\n const match = line.match(KEY_LINE_RE);\n if (!match) return { entry: undefined, endLine: start };\n\n const key = match[1] as string;\n // Drop only leading whitespace before the value; trailing whitespace and inline comments\n // are dealt with below depending on whether the value is quoted.\n /* v8 ignore next -- @preserve regex group 2 always matches via `(.*)`, fallback is defensive */\n const rest = (match[2] ?? '').replace(/^\\s+/u, '');\n const firstChar = rest[0];\n\n if (firstChar === '\"' || firstChar === \"'\" || firstChar === '`') {\n const consumed = consumeQuotedValue(rest, lines, start, firstChar);\n return { entry: { key, value: consumed.value }, endLine: consumed.endLine };\n }\n\n return { entry: { key, value: stripInlineComment(rest) }, endLine: start };\n}\n\nfunction consumeQuotedValue(\n firstLineRest: string,\n lines: string[],\n startLine: number,\n quote: string\n): { value: string; endLine: number } {\n let buffer = firstLineRest;\n let cursor = startLine;\n let closeIdx = findLastUnescapedQuote(buffer, quote);\n\n while (closeIdx < 0 && cursor < lines.length - 1) {\n cursor++;\n /* v8 ignore next -- @preserve cursor is bounded by the while condition above */\n buffer += `\\n${lines[cursor] ?? ''}`;\n closeIdx = findLastUnescapedQuote(buffer, quote);\n }\n\n const inner = closeIdx > 0 ? buffer.slice(1, closeIdx) : buffer.slice(1);\n return { value: quote === '\"' ? unescapeDouble(inner) : inner, endLine: cursor };\n}\n\nfunction stripInlineComment(value: string): string {\n const hashIdx = findInlineCommentStart(value);\n const stripped = hashIdx === -1 ? value : value.slice(0, hashIdx);\n return stripped.trimEnd();\n}\n\nfunction findInlineCommentStart(value: string): number {\n for (let i = 0; i < value.length; i++) {\n if (value[i] === '#' && (i === 0 || /\\s/u.test(value[i - 1] as string))) return i;\n }\n return -1;\n}\n\n/**\n * Find the rightmost matching closing quote in `buffer` (skipping index 0 which is the\n * opening quote). For `\"`, a quote preceded by an odd number of backslashes is escaped\n * and ignored. Single and backtick quotes do not unescape.\n */\nfunction findLastUnescapedQuote(buffer: string, quote: string): number {\n for (let i = buffer.length - 1; i > 0; i--) {\n if (buffer[i] !== quote) continue;\n if (quote === '\"') {\n let backslashes = 0;\n let k = i - 1;\n while (k >= 0 && buffer[k] === '\\\\') {\n backslashes++;\n k--;\n }\n if (backslashes % 2 === 1) continue; // escaped\n }\n return i;\n }\n return -1;\n}\n\nfunction unescapeDouble(raw: string): string {\n let out = '';\n for (let i = 0; i < raw.length; i++) {\n const ch = raw[i];\n if (ch !== '\\\\' || i === raw.length - 1) {\n out += ch;\n continue;\n }\n const next = raw[i + 1];\n i++;\n switch (next) {\n case 'n':\n out += '\\n';\n break;\n case 'r':\n out += '\\r';\n break;\n case 't':\n out += '\\t';\n break;\n case '\\\\':\n out += '\\\\';\n break;\n case '\"':\n out += '\"';\n break;\n default:\n /* v8 ignore next -- @preserve `next` is always defined when this branch is reached (guarded above) */\n out += `\\\\${next ?? ''}`;\n }\n }\n return out;\n}\n\n/**\n * Load one or more `.env` files into a target `processEnv` map. Mirrors the\n * subset of dotenv's `config()` semantics that envapt depends on: first-wins\n * across multiple paths by default, optional `override: true`, optional\n * non-UTF8 encoding, missing files are skipped silently.\n *\n * Returns the set of keys actually written into `input.processEnv`. Skipped\n * collisions (under default `override: false`) are NOT included.\n * @internal\n */\nexport function loadDotenv(input: LoadDotenvInput): Set<string> {\n const paths = Array.isArray(input.path) ? input.path : [input.path];\n const encoding = input.encoding ?? 'utf8';\n const override = input.override ?? false;\n const written = new Set<string>();\n\n for (const filePath of paths) {\n const src = input.readFile(filePath, encoding);\n if (src === undefined) {\n debugWarn(`could not read ${filePath}`);\n continue;\n }\n\n const parsed = parseDotenv(src);\n debugVerbose(`loaded ${filePath}: ${parsed.size} ${parsed.size === 1 ? 'key' : 'keys'}`);\n for (const [key, value] of parsed) {\n const exists = Object.prototype.hasOwnProperty.call(input.processEnv, key);\n if (!exists || override) {\n input.processEnv[key] = value;\n written.add(key);\n debugVerbose(`${filePath} -> ${key}`);\n }\n }\n }\n\n return written;\n}\n"],"mappings":"0DAiCA,MAAM,EAAc,uDAuBpB,SAAgB,EAAY,EAAkC,CAC1D,IAAM,EAAM,IAAI,IACV,EAAQ,EAAI,MAAM,QAAQ,EAEhC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAAK,CACnC,IAAM,EAAW,EAAW,EAAO,CAAC,EACpC,EAAI,EAAS,QACT,EAAS,OAAO,EAAI,IAAI,EAAS,MAAM,IAAK,EAAS,MAAM,KAAK,CACxE,CAEA,OAAO,CACX,CAOA,SAAS,EAAW,EAAiB,EAAoE,CAErG,IAAM,EAAO,EAAM,IAAU,GACvB,EAAc,EAAK,KAAK,EAC9B,GAAI,IAAgB,IAAM,EAAY,WAAW,GAAG,EAAG,MAAO,CAAE,MAAO,IAAA,GAAW,QAAS,CAAM,EAEjG,IAAM,EAAQ,EAAK,MAAM,CAAW,EACpC,GAAI,CAAC,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hD,CAEA,OAAO,CACX"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let e=function(e){return e[e.InvalidFallback=101]=`InvalidFallback`,e[e.InvalidFallbackType=102]=`InvalidFallbackType`,e[e.ArrayFallbackElementTypeMismatch=103]=`ArrayFallbackElementTypeMismatch`,e[e.FallbackConverterTypeMismatch=104]=`FallbackConverterTypeMismatch`,e[e.MalformedTimeFallback=105]=`MalformedTimeFallback`,e[e.InvalidArrayConverterType=201]=`InvalidArrayConverterType`,e[e.InvalidBuiltInConverter=202]=`InvalidBuiltInConverter`,e[e.InvalidCustomConverter=203]=`InvalidCustomConverter`,e[e.InvalidConverterType=204]=`InvalidConverterType`,e[e.PrimitiveCoercionFailed=205]=`PrimitiveCoercionFailed`,e[e.ArrayElementConversionFailed=206]=`ArrayElementConversionFailed`,e[e.EmptyArrayElement=207]=`EmptyArrayElement`,e[e.SchemaValidationFailed=208]=`SchemaValidationFailed`,e[e.SchemaThrew=209]=`SchemaThrew`,e[e.MissingDelimiter=301]=`MissingDelimiter`,e[e.InvalidUserDefinedConfig=302]=`InvalidUserDefinedConfig`,e[e.EnvFilesNotFound=303]=`EnvFilesNotFound`,e[e.InvalidKeyInput=304]=`InvalidKeyInput`,e[e.MissingEnvValue=305]=`MissingEnvValue`,e[e.FileApiUnsupported=306]=`FileApiUnsupported`,e[e.NoSourceBound=307]=`NoSourceBound`,e}({});var t=class extends Error{code;issues;constructor(e,t,n){super(t,n?.cause===void 0?void 0:{cause:n.cause}),this.name=`EnvaptError [${e}]`,this.code=e,this.issues=n?.issues}};exports.EnvaptError=t,exports.EnvaptErrorCodes=e;
|
|
1
|
+
let e=function(e){return e[e.InvalidFallback=101]=`InvalidFallback`,e[e.InvalidFallbackType=102]=`InvalidFallbackType`,e[e.ArrayFallbackElementTypeMismatch=103]=`ArrayFallbackElementTypeMismatch`,e[e.FallbackConverterTypeMismatch=104]=`FallbackConverterTypeMismatch`,e[e.MalformedTimeFallback=105]=`MalformedTimeFallback`,e[e.InvalidArrayConverterType=201]=`InvalidArrayConverterType`,e[e.InvalidBuiltInConverter=202]=`InvalidBuiltInConverter`,e[e.InvalidCustomConverter=203]=`InvalidCustomConverter`,e[e.InvalidConverterType=204]=`InvalidConverterType`,e[e.PrimitiveCoercionFailed=205]=`PrimitiveCoercionFailed`,e[e.ArrayElementConversionFailed=206]=`ArrayElementConversionFailed`,e[e.EmptyArrayElement=207]=`EmptyArrayElement`,e[e.SchemaValidationFailed=208]=`SchemaValidationFailed`,e[e.SchemaThrew=209]=`SchemaThrew`,e[e.MissingDelimiter=301]=`MissingDelimiter`,e[e.InvalidUserDefinedConfig=302]=`InvalidUserDefinedConfig`,e[e.EnvFilesNotFound=303]=`EnvFilesNotFound`,e[e.InvalidKeyInput=304]=`InvalidKeyInput`,e[e.MissingEnvValue=305]=`MissingEnvValue`,e[e.FileApiUnsupported=306]=`FileApiUnsupported`,e[e.NoSourceBound=307]=`NoSourceBound`,e[e.InvalidMergedSource=308]=`InvalidMergedSource`,e}({});var t=class extends Error{code;issues;constructor(e,t,n){super(t,n?.cause===void 0?void 0:{cause:n.cause}),this.name=`EnvaptError [${e}]`,this.code=e,this.issues=n?.issues}};exports.EnvaptError=t,exports.EnvaptErrorCodes=e;
|
|
2
2
|
//# sourceMappingURL=Error.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Error.cjs","names":[],"sources":["../../../src/infra/Error.ts"],"sourcesContent":["/* eslint-disable no-magic-numbers */\nimport type { StandardSchemaV1 } from './StandardSchema';\n\n/**\n * Numeric codes carried by {@link EnvaptError.code}, grouped by fallback (1xx), converter (2xx),\n * and configuration (3xx) failures.\n */\nexport enum EnvaptErrorCodes {\n // Fallback related errors\n /** Thrown when an invalid fallback value is provided */\n InvalidFallback = 101,\n /** Thrown when fallback value type doesn't match expected converter type */\n InvalidFallbackType = 102,\n /** Thrown when array fallback contains elements of wrong type */\n ArrayFallbackElementTypeMismatch = 103,\n /** Thrown when fallback type doesn't match the specified converter */\n FallbackConverterTypeMismatch = 104,\n /** Thrown when a time-string fallback is malformed (does not match the required `<number><unit>` format) */\n MalformedTimeFallback = 105,\n\n // Converter related errors\n /** Thrown when invalid array converter configuration is provided */\n InvalidArrayConverterType = 201,\n /** Thrown when an invalid built-in converter is specified */\n InvalidBuiltInConverter = 202,\n /** Thrown when a custom converter is not a function */\n InvalidCustomConverter = 203,\n /** Thrown when converter type is not recognized */\n InvalidConverterType = 204,\n /** Thrown when primitive type coercion on fallback value fails */\n PrimitiveCoercionFailed = 205,\n /** Thrown when an array element fails to convert to the configured element type */\n ArrayElementConversionFailed = 206,\n /** Thrown under strict mode when an array element is empty or whitespace only */\n EmptyArrayElement = 207,\n /** Thrown when a Standard Schema returns issues for a non-empty env value */\n SchemaValidationFailed = 208,\n /** Thrown when a Standard Schema's `validate` itself throws (e.g. a refinement that crashes) */\n SchemaThrew = 209,\n\n // Other errors\n /** Thrown when delimiter is missing in array converter configuration */\n // This doesn't happen because 203 is thrown when object without delimiter is passed\n MissingDelimiter = 301,\n /** Thrown when invalid user-defined configuration is provided */\n InvalidUserDefinedConfig = 302,\n /** Thrown when specified environment files don't exist */\n EnvFilesNotFound = 303,\n /** Thrown when no valid environment key is provided */\n InvalidKeyInput = 304,\n /** Thrown when a required environment value is missing or empty (post-trim) */\n MissingEnvValue = 305,\n /** Thrown when a file-based API (envPaths, baseDir, configureProfiles) is used on a source without filesystem support */\n FileApiUnsupported = 306,\n /** Thrown when an environment value is read before a source is bound via Envapter.useSource */\n NoSourceBound = 307\n}\n\ninterface EnvaptErrorOptions {\n issues?: readonly StandardSchemaV1.Issue[];\n cause?: unknown;\n}\n\n/**\n * Custom error for better DX and debugging when using Envapt.\n *\n * @example\n * ```ts\n * throw new EnvaptError(EnvaptErrorCodes.InvalidFallback, \"Invalid fallback value provided for environment variable.\");\n * ```\n */\nexport class EnvaptError extends Error {\n /** The {@link EnvaptErrorCodes} value identifying what failed. */\n public readonly code: EnvaptErrorCodes;\n /**\n * Populated only for {@link EnvaptErrorCodes.SchemaValidationFailed} (208). For every other\n * code this is `undefined`. Lets callers do `if (err.code === 208) err.issues?.forEach(...)`\n * without a type cast.\n */\n public readonly issues: readonly StandardSchemaV1.Issue[] | undefined;\n\n /** Create an error carrying an {@link EnvaptErrorCodes} code, a message, and optional `cause` / `issues`. */\n constructor(code: EnvaptErrorCodes, message: string, options?: EnvaptErrorOptions) {\n super(message, options?.cause !== undefined ? { cause: options.cause } : undefined);\n this.name = `EnvaptError [${code}]`;\n this.code = code;\n this.issues = options?.issues;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Error.cjs","names":[],"sources":["../../../src/infra/Error.ts"],"sourcesContent":["/* eslint-disable no-magic-numbers */\nimport type { StandardSchemaV1 } from './StandardSchema';\n\n/**\n * Numeric codes carried by {@link EnvaptError.code}, grouped by fallback (1xx), converter (2xx),\n * and configuration (3xx) failures.\n * @see {@link https://envapt.materwelon.dev/docs/errors#codes}\n */\nexport enum EnvaptErrorCodes {\n // Fallback related errors\n /** Thrown when an invalid fallback value is provided */\n InvalidFallback = 101,\n /** Thrown when fallback value type doesn't match expected converter type */\n InvalidFallbackType = 102,\n /** Thrown when array fallback contains elements of wrong type */\n ArrayFallbackElementTypeMismatch = 103,\n /** Thrown when fallback type doesn't match the specified converter */\n FallbackConverterTypeMismatch = 104,\n /** Thrown when a time-string fallback is malformed (does not match the required `<number><unit>` format) */\n MalformedTimeFallback = 105,\n\n // Converter related errors\n /** Thrown when invalid array converter configuration is provided */\n InvalidArrayConverterType = 201,\n /** Thrown when an invalid built-in converter is specified */\n InvalidBuiltInConverter = 202,\n /** Thrown when a custom converter is not a function */\n InvalidCustomConverter = 203,\n /** Thrown when converter type is not recognized */\n InvalidConverterType = 204,\n /** Thrown when primitive type coercion on fallback value fails */\n PrimitiveCoercionFailed = 205,\n /** Thrown when an array element fails to convert to the configured element type */\n ArrayElementConversionFailed = 206,\n /** Thrown under strict mode when an array element is empty or whitespace only */\n EmptyArrayElement = 207,\n /** Thrown when a Standard Schema returns issues for a non-empty env value */\n SchemaValidationFailed = 208,\n /** Thrown when a Standard Schema's `validate` itself throws (e.g. a refinement that crashes) */\n SchemaThrew = 209,\n\n // Other errors\n /** Thrown when delimiter is missing in array converter configuration */\n // This doesn't happen because 203 is thrown when object without delimiter is passed\n MissingDelimiter = 301,\n /** Thrown when invalid user-defined configuration is provided */\n InvalidUserDefinedConfig = 302,\n /** Thrown when specified environment files don't exist */\n EnvFilesNotFound = 303,\n /** Thrown when no valid environment key is provided */\n InvalidKeyInput = 304,\n /** Thrown when a required environment value is missing or empty (post-trim) */\n MissingEnvValue = 305,\n /** Thrown when a file-based API (envPaths, baseDir, configureProfiles) is used on a source without filesystem support */\n FileApiUnsupported = 306,\n /** Thrown when an environment value is read before a source is bound via Envapter.useSource */\n NoSourceBound = 307,\n /** Thrown when `merge` is called with no members, or with more than one filesystem-backed source */\n InvalidMergedSource = 308\n}\n\ninterface EnvaptErrorOptions {\n issues?: readonly StandardSchemaV1.Issue[];\n cause?: unknown;\n}\n\n/**\n * Custom error for better DX and debugging when using Envapt.\n *\n * @example\n * ```ts\n * throw new EnvaptError(EnvaptErrorCodes.InvalidFallback, \"Invalid fallback value provided for environment variable.\");\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/errors#the-error-shape}\n */\nexport class EnvaptError extends Error {\n /** The {@link EnvaptErrorCodes} value identifying what failed. */\n public readonly code: EnvaptErrorCodes;\n /**\n * Populated only for {@link EnvaptErrorCodes.SchemaValidationFailed} (208). For every other\n * code this is `undefined`. Lets callers do `if (err.code === 208) err.issues?.forEach(...)`\n * without a type cast.\n */\n public readonly issues: readonly StandardSchemaV1.Issue[] | undefined;\n\n /** Create an error carrying an {@link EnvaptErrorCodes} code, a message, and optional `cause` / `issues`. */\n constructor(code: EnvaptErrorCodes, message: string, options?: EnvaptErrorOptions) {\n super(message, options?.cause !== undefined ? { cause: options.cause } : undefined);\n this.name = `EnvaptError [${code}]`;\n this.code = code;\n this.issues = options?.issues;\n }\n}\n"],"mappings":"AAQA,IAAY,EAAL,SAAA,EAAA,OAGH,GAAA,EAAA,gBAAA,KAAA,kBAEA,EAAA,EAAA,oBAAA,KAAA,sBAEA,EAAA,EAAA,iCAAA,KAAA,mCAEA,EAAA,EAAA,8BAAA,KAAA,gCAEA,EAAA,EAAA,sBAAA,KAAA,wBAIA,EAAA,EAAA,0BAAA,KAAA,4BAEA,EAAA,EAAA,wBAAA,KAAA,0BAEA,EAAA,EAAA,uBAAA,KAAA,yBAEA,EAAA,EAAA,qBAAA,KAAA,uBAEA,EAAA,EAAA,wBAAA,KAAA,0BAEA,EAAA,EAAA,6BAAA,KAAA,+BAEA,EAAA,EAAA,kBAAA,KAAA,oBAEA,EAAA,EAAA,uBAAA,KAAA,yBAEA,EAAA,EAAA,YAAA,KAAA,cAKA,EAAA,EAAA,iBAAA,KAAA,mBAEA,EAAA,EAAA,yBAAA,KAAA,2BAEA,EAAA,EAAA,iBAAA,KAAA,mBAEA,EAAA,EAAA,gBAAA,KAAA,kBAEA,EAAA,EAAA,gBAAA,KAAA,kBAEA,EAAA,EAAA,mBAAA,KAAA,qBAEA,EAAA,EAAA,cAAA,KAAA,gBAEA,EAAA,EAAA,oBAAA,KAAA,uBACJ,EAAA,CAAA,CAAA,EAgBA,IAAa,EAAb,cAAiC,KAAM,CAEnC,KAMA,OAGA,YAAY,EAAwB,EAAiB,EAA8B,CAC/E,MAAM,EAAS,GAAS,QAAU,IAAA,GAAuC,IAAA,GAA3B,CAAE,MAAO,EAAQ,KAAM,CAAa,EAClF,KAAK,KAAO,gBAAgB,EAAK,GACjC,KAAK,KAAO,EACZ,KAAK,OAAS,GAAS,MAC3B,CACJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let e=function(e){return e[e.InvalidFallback=101]=`InvalidFallback`,e[e.InvalidFallbackType=102]=`InvalidFallbackType`,e[e.ArrayFallbackElementTypeMismatch=103]=`ArrayFallbackElementTypeMismatch`,e[e.FallbackConverterTypeMismatch=104]=`FallbackConverterTypeMismatch`,e[e.MalformedTimeFallback=105]=`MalformedTimeFallback`,e[e.InvalidArrayConverterType=201]=`InvalidArrayConverterType`,e[e.InvalidBuiltInConverter=202]=`InvalidBuiltInConverter`,e[e.InvalidCustomConverter=203]=`InvalidCustomConverter`,e[e.InvalidConverterType=204]=`InvalidConverterType`,e[e.PrimitiveCoercionFailed=205]=`PrimitiveCoercionFailed`,e[e.ArrayElementConversionFailed=206]=`ArrayElementConversionFailed`,e[e.EmptyArrayElement=207]=`EmptyArrayElement`,e[e.SchemaValidationFailed=208]=`SchemaValidationFailed`,e[e.SchemaThrew=209]=`SchemaThrew`,e[e.MissingDelimiter=301]=`MissingDelimiter`,e[e.InvalidUserDefinedConfig=302]=`InvalidUserDefinedConfig`,e[e.EnvFilesNotFound=303]=`EnvFilesNotFound`,e[e.InvalidKeyInput=304]=`InvalidKeyInput`,e[e.MissingEnvValue=305]=`MissingEnvValue`,e[e.FileApiUnsupported=306]=`FileApiUnsupported`,e[e.NoSourceBound=307]=`NoSourceBound`,e}({});var t=class extends Error{code;issues;constructor(e,t,n){super(t,n?.cause===void 0?void 0:{cause:n.cause}),this.name=`EnvaptError [${e}]`,this.code=e,this.issues=n?.issues}};export{t as EnvaptError,e as EnvaptErrorCodes};
|
|
1
|
+
let e=function(e){return e[e.InvalidFallback=101]=`InvalidFallback`,e[e.InvalidFallbackType=102]=`InvalidFallbackType`,e[e.ArrayFallbackElementTypeMismatch=103]=`ArrayFallbackElementTypeMismatch`,e[e.FallbackConverterTypeMismatch=104]=`FallbackConverterTypeMismatch`,e[e.MalformedTimeFallback=105]=`MalformedTimeFallback`,e[e.InvalidArrayConverterType=201]=`InvalidArrayConverterType`,e[e.InvalidBuiltInConverter=202]=`InvalidBuiltInConverter`,e[e.InvalidCustomConverter=203]=`InvalidCustomConverter`,e[e.InvalidConverterType=204]=`InvalidConverterType`,e[e.PrimitiveCoercionFailed=205]=`PrimitiveCoercionFailed`,e[e.ArrayElementConversionFailed=206]=`ArrayElementConversionFailed`,e[e.EmptyArrayElement=207]=`EmptyArrayElement`,e[e.SchemaValidationFailed=208]=`SchemaValidationFailed`,e[e.SchemaThrew=209]=`SchemaThrew`,e[e.MissingDelimiter=301]=`MissingDelimiter`,e[e.InvalidUserDefinedConfig=302]=`InvalidUserDefinedConfig`,e[e.EnvFilesNotFound=303]=`EnvFilesNotFound`,e[e.InvalidKeyInput=304]=`InvalidKeyInput`,e[e.MissingEnvValue=305]=`MissingEnvValue`,e[e.FileApiUnsupported=306]=`FileApiUnsupported`,e[e.NoSourceBound=307]=`NoSourceBound`,e[e.InvalidMergedSource=308]=`InvalidMergedSource`,e}({});var t=class extends Error{code;issues;constructor(e,t,n){super(t,n?.cause===void 0?void 0:{cause:n.cause}),this.name=`EnvaptError [${e}]`,this.code=e,this.issues=n?.issues}};export{t as EnvaptError,e as EnvaptErrorCodes};
|
|
2
2
|
//# sourceMappingURL=Error.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Error.mjs","names":[],"sources":["../../../src/infra/Error.ts"],"sourcesContent":["/* eslint-disable no-magic-numbers */\nimport type { StandardSchemaV1 } from './StandardSchema';\n\n/**\n * Numeric codes carried by {@link EnvaptError.code}, grouped by fallback (1xx), converter (2xx),\n * and configuration (3xx) failures.\n */\nexport enum EnvaptErrorCodes {\n // Fallback related errors\n /** Thrown when an invalid fallback value is provided */\n InvalidFallback = 101,\n /** Thrown when fallback value type doesn't match expected converter type */\n InvalidFallbackType = 102,\n /** Thrown when array fallback contains elements of wrong type */\n ArrayFallbackElementTypeMismatch = 103,\n /** Thrown when fallback type doesn't match the specified converter */\n FallbackConverterTypeMismatch = 104,\n /** Thrown when a time-string fallback is malformed (does not match the required `<number><unit>` format) */\n MalformedTimeFallback = 105,\n\n // Converter related errors\n /** Thrown when invalid array converter configuration is provided */\n InvalidArrayConverterType = 201,\n /** Thrown when an invalid built-in converter is specified */\n InvalidBuiltInConverter = 202,\n /** Thrown when a custom converter is not a function */\n InvalidCustomConverter = 203,\n /** Thrown when converter type is not recognized */\n InvalidConverterType = 204,\n /** Thrown when primitive type coercion on fallback value fails */\n PrimitiveCoercionFailed = 205,\n /** Thrown when an array element fails to convert to the configured element type */\n ArrayElementConversionFailed = 206,\n /** Thrown under strict mode when an array element is empty or whitespace only */\n EmptyArrayElement = 207,\n /** Thrown when a Standard Schema returns issues for a non-empty env value */\n SchemaValidationFailed = 208,\n /** Thrown when a Standard Schema's `validate` itself throws (e.g. a refinement that crashes) */\n SchemaThrew = 209,\n\n // Other errors\n /** Thrown when delimiter is missing in array converter configuration */\n // This doesn't happen because 203 is thrown when object without delimiter is passed\n MissingDelimiter = 301,\n /** Thrown when invalid user-defined configuration is provided */\n InvalidUserDefinedConfig = 302,\n /** Thrown when specified environment files don't exist */\n EnvFilesNotFound = 303,\n /** Thrown when no valid environment key is provided */\n InvalidKeyInput = 304,\n /** Thrown when a required environment value is missing or empty (post-trim) */\n MissingEnvValue = 305,\n /** Thrown when a file-based API (envPaths, baseDir, configureProfiles) is used on a source without filesystem support */\n FileApiUnsupported = 306,\n /** Thrown when an environment value is read before a source is bound via Envapter.useSource */\n NoSourceBound = 307\n}\n\ninterface EnvaptErrorOptions {\n issues?: readonly StandardSchemaV1.Issue[];\n cause?: unknown;\n}\n\n/**\n * Custom error for better DX and debugging when using Envapt.\n *\n * @example\n * ```ts\n * throw new EnvaptError(EnvaptErrorCodes.InvalidFallback, \"Invalid fallback value provided for environment variable.\");\n * ```\n */\nexport class EnvaptError extends Error {\n /** The {@link EnvaptErrorCodes} value identifying what failed. */\n public readonly code: EnvaptErrorCodes;\n /**\n * Populated only for {@link EnvaptErrorCodes.SchemaValidationFailed} (208). For every other\n * code this is `undefined`. Lets callers do `if (err.code === 208) err.issues?.forEach(...)`\n * without a type cast.\n */\n public readonly issues: readonly StandardSchemaV1.Issue[] | undefined;\n\n /** Create an error carrying an {@link EnvaptErrorCodes} code, a message, and optional `cause` / `issues`. */\n constructor(code: EnvaptErrorCodes, message: string, options?: EnvaptErrorOptions) {\n super(message, options?.cause !== undefined ? { cause: options.cause } : undefined);\n this.name = `EnvaptError [${code}]`;\n this.code = code;\n this.issues = options?.issues;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Error.mjs","names":[],"sources":["../../../src/infra/Error.ts"],"sourcesContent":["/* eslint-disable no-magic-numbers */\nimport type { StandardSchemaV1 } from './StandardSchema';\n\n/**\n * Numeric codes carried by {@link EnvaptError.code}, grouped by fallback (1xx), converter (2xx),\n * and configuration (3xx) failures.\n * @see {@link https://envapt.materwelon.dev/docs/errors#codes}\n */\nexport enum EnvaptErrorCodes {\n // Fallback related errors\n /** Thrown when an invalid fallback value is provided */\n InvalidFallback = 101,\n /** Thrown when fallback value type doesn't match expected converter type */\n InvalidFallbackType = 102,\n /** Thrown when array fallback contains elements of wrong type */\n ArrayFallbackElementTypeMismatch = 103,\n /** Thrown when fallback type doesn't match the specified converter */\n FallbackConverterTypeMismatch = 104,\n /** Thrown when a time-string fallback is malformed (does not match the required `<number><unit>` format) */\n MalformedTimeFallback = 105,\n\n // Converter related errors\n /** Thrown when invalid array converter configuration is provided */\n InvalidArrayConverterType = 201,\n /** Thrown when an invalid built-in converter is specified */\n InvalidBuiltInConverter = 202,\n /** Thrown when a custom converter is not a function */\n InvalidCustomConverter = 203,\n /** Thrown when converter type is not recognized */\n InvalidConverterType = 204,\n /** Thrown when primitive type coercion on fallback value fails */\n PrimitiveCoercionFailed = 205,\n /** Thrown when an array element fails to convert to the configured element type */\n ArrayElementConversionFailed = 206,\n /** Thrown under strict mode when an array element is empty or whitespace only */\n EmptyArrayElement = 207,\n /** Thrown when a Standard Schema returns issues for a non-empty env value */\n SchemaValidationFailed = 208,\n /** Thrown when a Standard Schema's `validate` itself throws (e.g. a refinement that crashes) */\n SchemaThrew = 209,\n\n // Other errors\n /** Thrown when delimiter is missing in array converter configuration */\n // This doesn't happen because 203 is thrown when object without delimiter is passed\n MissingDelimiter = 301,\n /** Thrown when invalid user-defined configuration is provided */\n InvalidUserDefinedConfig = 302,\n /** Thrown when specified environment files don't exist */\n EnvFilesNotFound = 303,\n /** Thrown when no valid environment key is provided */\n InvalidKeyInput = 304,\n /** Thrown when a required environment value is missing or empty (post-trim) */\n MissingEnvValue = 305,\n /** Thrown when a file-based API (envPaths, baseDir, configureProfiles) is used on a source without filesystem support */\n FileApiUnsupported = 306,\n /** Thrown when an environment value is read before a source is bound via Envapter.useSource */\n NoSourceBound = 307,\n /** Thrown when `merge` is called with no members, or with more than one filesystem-backed source */\n InvalidMergedSource = 308\n}\n\ninterface EnvaptErrorOptions {\n issues?: readonly StandardSchemaV1.Issue[];\n cause?: unknown;\n}\n\n/**\n * Custom error for better DX and debugging when using Envapt.\n *\n * @example\n * ```ts\n * throw new EnvaptError(EnvaptErrorCodes.InvalidFallback, \"Invalid fallback value provided for environment variable.\");\n * ```\n * @see {@link https://envapt.materwelon.dev/docs/errors#the-error-shape}\n */\nexport class EnvaptError extends Error {\n /** The {@link EnvaptErrorCodes} value identifying what failed. */\n public readonly code: EnvaptErrorCodes;\n /**\n * Populated only for {@link EnvaptErrorCodes.SchemaValidationFailed} (208). For every other\n * code this is `undefined`. Lets callers do `if (err.code === 208) err.issues?.forEach(...)`\n * without a type cast.\n */\n public readonly issues: readonly StandardSchemaV1.Issue[] | undefined;\n\n /** Create an error carrying an {@link EnvaptErrorCodes} code, a message, and optional `cause` / `issues`. */\n constructor(code: EnvaptErrorCodes, message: string, options?: EnvaptErrorOptions) {\n super(message, options?.cause !== undefined ? { cause: options.cause } : undefined);\n this.name = `EnvaptError [${code}]`;\n this.code = code;\n this.issues = options?.issues;\n }\n}\n"],"mappings":"AAQA,IAAY,EAAL,SAAA,EAAA,OAGH,GAAA,EAAA,gBAAA,KAAA,kBAEA,EAAA,EAAA,oBAAA,KAAA,sBAEA,EAAA,EAAA,iCAAA,KAAA,mCAEA,EAAA,EAAA,8BAAA,KAAA,gCAEA,EAAA,EAAA,sBAAA,KAAA,wBAIA,EAAA,EAAA,0BAAA,KAAA,4BAEA,EAAA,EAAA,wBAAA,KAAA,0BAEA,EAAA,EAAA,uBAAA,KAAA,yBAEA,EAAA,EAAA,qBAAA,KAAA,uBAEA,EAAA,EAAA,wBAAA,KAAA,0BAEA,EAAA,EAAA,6BAAA,KAAA,+BAEA,EAAA,EAAA,kBAAA,KAAA,oBAEA,EAAA,EAAA,uBAAA,KAAA,yBAEA,EAAA,EAAA,YAAA,KAAA,cAKA,EAAA,EAAA,iBAAA,KAAA,mBAEA,EAAA,EAAA,yBAAA,KAAA,2BAEA,EAAA,EAAA,iBAAA,KAAA,mBAEA,EAAA,EAAA,gBAAA,KAAA,kBAEA,EAAA,EAAA,gBAAA,KAAA,kBAEA,EAAA,EAAA,mBAAA,KAAA,qBAEA,EAAA,EAAA,cAAA,KAAA,gBAEA,EAAA,EAAA,oBAAA,KAAA,uBACJ,EAAA,CAAA,CAAA,EAgBA,IAAa,EAAb,cAAiC,KAAM,CAEnC,KAMA,OAGA,YAAY,EAAwB,EAAiB,EAA8B,CAC/E,MAAM,EAAS,GAAS,QAAU,IAAA,GAAuC,IAAA,GAA3B,CAAE,MAAO,EAAQ,KAAM,CAAa,EAClF,KAAK,KAAO,gBAAgB,EAAK,GACjC,KAAK,KAAO,EACZ,KAAK,OAAS,GAAS,MAC3B,CACJ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e,t){if(t===void 0)return e;let n=e.split(`_`).filter(e=>e.length>0);if(t===`kebab-case`)return n.map(e=>e.toLowerCase()).join(`-`);let r=n.map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``);return t===`PascalCase`?r:r.charAt(0).toLowerCase()+r.slice(1)}exports.recase=e;
|
|
2
|
+
//# sourceMappingURL=recase.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recase.cjs","names":[],"sources":["../../../src/infra/recase.ts"],"sourcesContent":["import type { KeyCasing } from '../types';\n\n// underscore-delimited words, kept in step with the RecaseKey type transforms in types/Casing.ts.\nexport function recase(name: string, casing?: KeyCasing): string {\n if (casing === undefined) return name;\n const words = name.split('_').filter((word) => word.length > 0);\n if (casing === 'kebab-case') return words.map((word) => word.toLowerCase()).join('-');\n const pascal = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join('');\n return casing === 'PascalCase' ? pascal : pascal.charAt(0).toLowerCase() + pascal.slice(1);\n}\n"],"mappings":"AAGA,SAAgB,EAAO,EAAc,EAA4B,CAC7D,GAAI,IAAW,IAAA,GAAW,OAAO,EACjC,IAAM,EAAQ,EAAK,MAAM,GAAG,CAAC,CAAC,OAAQ,GAAS,EAAK,OAAS,CAAC,EAC9D,GAAI,IAAW,aAAc,OAAO,EAAM,IAAK,GAAS,EAAK,YAAY,CAAC,CAAC,CAAC,KAAK,GAAG,EACpF,IAAM,EAAS,EAAM,IAAK,GAAS,EAAK,OAAO,CAAC,CAAC,CAAC,YAAY,EAAI,EAAK,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,EAAE,EACtG,OAAO,IAAW,aAAe,EAAS,EAAO,OAAO,CAAC,CAAC,CAAC,YAAY,EAAI,EAAO,MAAM,CAAC,CAC7F"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e,t){if(t===void 0)return e;let n=e.split(`_`).filter(e=>e.length>0);if(t===`kebab-case`)return n.map(e=>e.toLowerCase()).join(`-`);let r=n.map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``);return t===`PascalCase`?r:r.charAt(0).toLowerCase()+r.slice(1)}export{e as recase};
|
|
2
|
+
//# sourceMappingURL=recase.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recase.mjs","names":[],"sources":["../../../src/infra/recase.ts"],"sourcesContent":["import type { KeyCasing } from '../types';\n\n// underscore-delimited words, kept in step with the RecaseKey type transforms in types/Casing.ts.\nexport function recase(name: string, casing?: KeyCasing): string {\n if (casing === undefined) return name;\n const words = name.split('_').filter((word) => word.length > 0);\n if (casing === 'kebab-case') return words.map((word) => word.toLowerCase()).join('-');\n const pascal = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join('');\n return casing === 'PascalCase' ? pascal : pascal.charAt(0).toLowerCase() + pascal.slice(1);\n}\n"],"mappings":"AAGA,SAAgB,EAAO,EAAc,EAA4B,CAC7D,GAAI,IAAW,IAAA,GAAW,OAAO,EACjC,IAAM,EAAQ,EAAK,MAAM,GAAG,CAAC,CAAC,OAAQ,GAAS,EAAK,OAAS,CAAC,EAC9D,GAAI,IAAW,aAAc,OAAO,EAAM,IAAK,GAAS,EAAK,YAAY,CAAC,CAAC,CAAC,KAAK,GAAG,EACpF,IAAM,EAAS,EAAM,IAAK,GAAS,EAAK,OAAO,CAAC,CAAC,CAAC,YAAY,EAAI,EAAK,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,EAAE,EACtG,OAAO,IAAW,aAAe,EAAS,EAAO,OAAO,CAAC,CAAC,CAAC,YAAY,EAAI,EAAO,MAAM,CAAC,CAC7F"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let e=e=>{console.error(e)},t=()=>({});function
|
|
1
|
+
let e=e=>{console.error(e)},t=()=>({}),n;function r(t){e=t}function i(t){e(t)}function a(e){let r=t()[e];if(r!==void 0)return r;try{return n?.(e)}catch{return}}function o(e){t=()=>e.readVars();let r=e.readVar;n=typeof r==`function`?r.bind(e):void 0}exports.bindRuntimeFromSource=o,exports.readRuntimeVar=a,exports.setRuntimeSink=r,exports.writeRuntimeLine=i;
|
|
2
2
|
//# sourceMappingURL=runtime.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.cjs","names":[],"sources":["../../../src/infra/runtime.ts"],"sourcesContent":["import type { Source } from '../types';\n\n// importing Debug back into EnvapterBase would cycle, so the source and sink are injected via the setters below.\n/* v8 ignore start -- @preserve replaced at load on Node
|
|
1
|
+
{"version":3,"file":"runtime.cjs","names":[],"sources":["../../../src/infra/runtime.ts"],"sourcesContent":["import type { Source } from '../types';\n\n// importing Debug back into EnvapterBase would cycle, so the source and sink are injected via the setters below.\n/* v8 ignore start -- @preserve replaced at load on Node so the Node suite never runs these defaults */\nlet sink: (line: string) => void = (line) => {\n // eslint-disable-next-line no-console -- the off-Node fallback log sink\n console.error(line);\n};\nlet envReader: () => Record<string, string> = () => ({});\nlet varReader: ((key: string) => string | undefined) | undefined;\n/* v8 ignore stop */\n\nexport function setRuntimeSink(fn: (line: string) => void): void {\n sink = fn;\n}\n\nexport function writeRuntimeLine(line: string): void {\n sink(line);\n}\n\n// check snapshot first, then the source's per-key reader, so a reader source (empty snapshot) still resolves a key\nexport function readRuntimeVar(key: string): string | undefined {\n const fromSnapshot = envReader()[key];\n if (fromSnapshot !== undefined) return fromSnapshot;\n // ENVAPT_DEBUG resolves through here, so a throwing reader must not abort the config load that triggered it\n try {\n return varReader?.(key);\n } catch {\n return undefined;\n }\n}\n\nexport function bindRuntimeFromSource(source: Source): void {\n envReader = (): Record<string, string> => source.readVars();\n const readVar = source.readVar;\n varReader = typeof readVar === 'function' ? readVar.bind(source) : undefined;\n}\n"],"mappings":"AAIA,IAAI,EAAgC,GAAS,CAEzC,QAAQ,MAAM,CAAI,CACtB,EACI,OAAiD,CAAC,GAClD,EAGJ,SAAgB,EAAe,EAAkC,CAC7D,EAAO,CACX,CAEA,SAAgB,EAAiB,EAAoB,CACjD,EAAK,CAAI,CACb,CAGA,SAAgB,EAAe,EAAiC,CAC5D,IAAM,EAAe,EAAU,CAAC,CAAC,GACjC,GAAI,IAAiB,IAAA,GAAW,OAAO,EAEvC,GAAI,CACA,OAAO,IAAY,CAAG,CAC1B,MAAQ,CACJ,MACJ,CACJ,CAEA,SAAgB,EAAsB,EAAsB,CACxD,MAA0C,EAAO,SAAS,EAC1D,IAAM,EAAU,EAAO,QACvB,EAAY,OAAO,GAAY,WAAa,EAAQ,KAAK,CAAM,EAAI,IAAA,EACvE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let e=e=>{console.error(e)},t=()=>({});function
|
|
1
|
+
let e=e=>{console.error(e)},t=()=>({}),n;function r(t){e=t}function i(t){e(t)}function a(e){let r=t()[e];if(r!==void 0)return r;try{return n?.(e)}catch{return}}function o(e){t=()=>e.readVars();let r=e.readVar;n=typeof r==`function`?r.bind(e):void 0}export{o as bindRuntimeFromSource,a as readRuntimeVar,r as setRuntimeSink,i as writeRuntimeLine};
|
|
2
2
|
//# sourceMappingURL=runtime.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../../src/infra/runtime.ts"],"sourcesContent":["import type { Source } from '../types';\n\n// importing Debug back into EnvapterBase would cycle, so the source and sink are injected via the setters below.\n/* v8 ignore start -- @preserve replaced at load on Node
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../../src/infra/runtime.ts"],"sourcesContent":["import type { Source } from '../types';\n\n// importing Debug back into EnvapterBase would cycle, so the source and sink are injected via the setters below.\n/* v8 ignore start -- @preserve replaced at load on Node so the Node suite never runs these defaults */\nlet sink: (line: string) => void = (line) => {\n // eslint-disable-next-line no-console -- the off-Node fallback log sink\n console.error(line);\n};\nlet envReader: () => Record<string, string> = () => ({});\nlet varReader: ((key: string) => string | undefined) | undefined;\n/* v8 ignore stop */\n\nexport function setRuntimeSink(fn: (line: string) => void): void {\n sink = fn;\n}\n\nexport function writeRuntimeLine(line: string): void {\n sink(line);\n}\n\n// check snapshot first, then the source's per-key reader, so a reader source (empty snapshot) still resolves a key\nexport function readRuntimeVar(key: string): string | undefined {\n const fromSnapshot = envReader()[key];\n if (fromSnapshot !== undefined) return fromSnapshot;\n // ENVAPT_DEBUG resolves through here, so a throwing reader must not abort the config load that triggered it\n try {\n return varReader?.(key);\n } catch {\n return undefined;\n }\n}\n\nexport function bindRuntimeFromSource(source: Source): void {\n envReader = (): Record<string, string> => source.readVars();\n const readVar = source.readVar;\n varReader = typeof readVar === 'function' ? readVar.bind(source) : undefined;\n}\n"],"mappings":"AAIA,IAAI,EAAgC,GAAS,CAEzC,QAAQ,MAAM,CAAI,CACtB,EACI,OAAiD,CAAC,GAClD,EAGJ,SAAgB,EAAe,EAAkC,CAC7D,EAAO,CACX,CAEA,SAAgB,EAAiB,EAAoB,CACjD,EAAK,CAAI,CACb,CAGA,SAAgB,EAAe,EAAiC,CAC5D,IAAM,EAAe,EAAU,CAAC,CAAC,GACjC,GAAI,IAAiB,IAAA,GAAW,OAAO,EAEvC,GAAI,CACA,OAAO,IAAY,CAAG,CAC1B,MAAQ,CACJ,MACJ,CACJ,CAEA,SAAgB,EAAsB,EAAsB,CACxD,MAA0C,EAAO,SAAS,EAC1D,IAAM,EAAU,EAAO,QACvB,EAAY,OAAO,GAAY,WAAa,EAAQ,KAAK,CAAM,EAAI,IAAA,EACvE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../_virtual/_rolldown/runtime.cjs");let t=require("node:process");t=e.__toESM(t,1);let n=require("node:fs");n=e.__toESM(n,1);let r=require("node:path"),i=require("node:url");var a=class{supportsFiles=!0;readVars(){return{...t.default.env}}readFile(e,t){try{return n.default.readFileSync(e,t)}catch{return}}normalizeBaseDir(e){return e instanceof URL||e.startsWith(`file:`)?(0,r.dirname)((0,i.fileURLToPath)(e)):(0,r.resolve)(e)}resolvePath(e,t){return(0,r.isAbsolute)(t)?t:(0,r.join)(e,t)}writeVars(e){for(let[n,r]of Object.entries(e))t.default.env[n]=r}};exports.
|
|
2
|
-
//# sourceMappingURL=
|
|
1
|
+
const e=require("../_virtual/_rolldown/runtime.cjs");let t=require("node:process");t=e.__toESM(t,1);let n=require("node:fs");n=e.__toESM(n,1);let r=require("node:path"),i=require("node:url");var a=class{supportsFiles=!0;readVars(){return{...t.default.env}}readFile(e,t){try{return n.default.readFileSync(e,t)}catch{return}}normalizeBaseDir(e){return e instanceof URL||e.startsWith(`file:`)?(0,r.dirname)((0,i.fileURLToPath)(e)):(0,r.resolve)(e)}resolvePath(e,t){return(0,r.isAbsolute)(t)?t:(0,r.join)(e,t)}writeVars(e){for(let[n,r]of Object.entries(e))t.default.env[n]=r}};exports.FileSource=a;
|
|
2
|
+
//# sourceMappingURL=FileSource.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileSource.cjs","names":["process","fs"],"sources":["../../../src/sources/FileSource.ts"],"sourcesContent":["import fs from 'node:fs';\nimport { dirname, isAbsolute, join, resolve } from 'node:path';\nimport process from 'node:process';\nimport { fileURLToPath } from 'node:url';\n\nimport type { FileCapableSource } from '../types';\n\n/**\n * Default environment source on Node, Bun, and Deno: a snapshot of `process.env`. Its\n * `supportsFiles` is `true`, so the engine also layers the `.env` cascade on top, resolves\n * `baseDir`, and can mirror loaded keys back to `process.env`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/sources#the-providers}\n */\nexport class FileSource implements FileCapableSource {\n /** Always `true`. The engine layers the `.env` cascade and `baseDir` on top of `process.env`. */\n readonly supportsFiles = true;\n\n /** Returns a snapshot clone of `process.env` as plain strings. */\n readVars(): Record<string, string> {\n // Clone so the loader and downstream reads never mutate process.env.\n return { ...(process.env as Record<string, string>) };\n }\n\n /** Reads a file with `fs.readFileSync`, or `undefined` when it is missing or unreadable. */\n readFile(path: string, encoding: string): string | undefined {\n try {\n // justified: our public encoding type is `string`; fs needs the BufferEncoding subset.\n return fs.readFileSync(path, encoding as BufferEncoding);\n } catch {\n return undefined;\n }\n }\n\n /**\n * Resolves a directory path or a module / `file:` URL to an absolute directory. A `file:` URL\n * resolves to its containing directory, and a plain path (`import.meta.dirname`, `__dirname`) is\n * taken as the directory itself.\n */\n normalizeBaseDir(value: string | URL): string {\n if (value instanceof URL) return dirname(fileURLToPath(value));\n if (value.startsWith('file:')) return dirname(fileURLToPath(value));\n return resolve(value);\n }\n\n /** Joins a relative `.env` path onto `baseDir`. Absolute paths pass through unchanged. */\n resolvePath(baseDir: string, candidate: string): string {\n if (isAbsolute(candidate)) return candidate;\n return join(baseDir, candidate);\n }\n\n /** Writes each key to `process.env`, backing `Envapter.syncProcessEnv`. */\n writeVars(vars: Record<string, string>): void {\n for (const [key, value] of Object.entries(vars)) {\n process.env[key] = value;\n }\n }\n}\n"],"mappings":"+LAcA,IAAa,EAAb,KAAqD,CAEjD,cAAyB,GAGzB,UAAmC,CAE/B,MAAO,CAAE,GAAIA,EAAAA,QAAQ,GAA+B,CACxD,CAGA,SAAS,EAAc,EAAsC,CACzD,GAAI,CAEA,OAAOC,EAAAA,QAAG,aAAa,EAAM,CAA0B,CAC3D,MAAQ,CACJ,MACJ,CACJ,CAOA,iBAAiB,EAA6B,CAG1C,OAFI,aAAiB,KACjB,EAAM,WAAW,OAAO,GAAG,EAAA,EAAA,QAAA,EAAA,EAAA,EAAA,cAAA,CAA6B,CAAK,CAAC,GAClE,EAAA,EAAA,QAAA,CAAe,CAAK,CACxB,CAGA,YAAY,EAAiB,EAA2B,CAEpD,OADA,EAAA,EAAA,WAAA,CAAe,CAAS,EAAU,GAClC,EAAA,EAAA,KAAA,CAAY,EAAS,CAAS,CAClC,CAGA,UAAU,EAAoC,CAC1C,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,CAAI,EAC1C,EAAA,QAAQ,IAAI,GAAO,CAE3B,CACJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"node:process";import t from"node:fs";import{dirname as n,isAbsolute as r,join as i,resolve as a}from"node:path";import{fileURLToPath as o}from"node:url";var s=class{supportsFiles=!0;readVars(){return{...e.env}}readFile(e,n){try{return t.readFileSync(e,n)}catch{return}}normalizeBaseDir(e){return e instanceof URL||e.startsWith(`file:`)?n(o(e)):a(e)}resolvePath(e,t){return r(t)?t:i(e,t)}writeVars(t){for(let[n,r]of Object.entries(t))e.env[n]=r}};export{s as
|
|
2
|
-
//# sourceMappingURL=
|
|
1
|
+
import e from"node:process";import t from"node:fs";import{dirname as n,isAbsolute as r,join as i,resolve as a}from"node:path";import{fileURLToPath as o}from"node:url";var s=class{supportsFiles=!0;readVars(){return{...e.env}}readFile(e,n){try{return t.readFileSync(e,n)}catch{return}}normalizeBaseDir(e){return e instanceof URL||e.startsWith(`file:`)?n(o(e)):a(e)}resolvePath(e,t){return r(t)?t:i(e,t)}writeVars(t){for(let[n,r]of Object.entries(t))e.env[n]=r}};export{s as FileSource};
|
|
2
|
+
//# sourceMappingURL=FileSource.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileSource.mjs","names":[],"sources":["../../../src/sources/FileSource.ts"],"sourcesContent":["import fs from 'node:fs';\nimport { dirname, isAbsolute, join, resolve } from 'node:path';\nimport process from 'node:process';\nimport { fileURLToPath } from 'node:url';\n\nimport type { FileCapableSource } from '../types';\n\n/**\n * Default environment source on Node, Bun, and Deno: a snapshot of `process.env`. Its\n * `supportsFiles` is `true`, so the engine also layers the `.env` cascade on top, resolves\n * `baseDir`, and can mirror loaded keys back to `process.env`.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/sources#the-providers}\n */\nexport class FileSource implements FileCapableSource {\n /** Always `true`. The engine layers the `.env` cascade and `baseDir` on top of `process.env`. */\n readonly supportsFiles = true;\n\n /** Returns a snapshot clone of `process.env` as plain strings. */\n readVars(): Record<string, string> {\n // Clone so the loader and downstream reads never mutate process.env.\n return { ...(process.env as Record<string, string>) };\n }\n\n /** Reads a file with `fs.readFileSync`, or `undefined` when it is missing or unreadable. */\n readFile(path: string, encoding: string): string | undefined {\n try {\n // justified: our public encoding type is `string`; fs needs the BufferEncoding subset.\n return fs.readFileSync(path, encoding as BufferEncoding);\n } catch {\n return undefined;\n }\n }\n\n /**\n * Resolves a directory path or a module / `file:` URL to an absolute directory. A `file:` URL\n * resolves to its containing directory, and a plain path (`import.meta.dirname`, `__dirname`) is\n * taken as the directory itself.\n */\n normalizeBaseDir(value: string | URL): string {\n if (value instanceof URL) return dirname(fileURLToPath(value));\n if (value.startsWith('file:')) return dirname(fileURLToPath(value));\n return resolve(value);\n }\n\n /** Joins a relative `.env` path onto `baseDir`. Absolute paths pass through unchanged. */\n resolvePath(baseDir: string, candidate: string): string {\n if (isAbsolute(candidate)) return candidate;\n return join(baseDir, candidate);\n }\n\n /** Writes each key to `process.env`, backing `Envapter.syncProcessEnv`. */\n writeVars(vars: Record<string, string>): void {\n for (const [key, value] of Object.entries(vars)) {\n process.env[key] = value;\n }\n }\n}\n"],"mappings":"uKAcA,IAAa,EAAb,KAAqD,CAEjD,cAAyB,GAGzB,UAAmC,CAE/B,MAAO,CAAE,GAAI,EAAQ,GAA+B,CACxD,CAGA,SAAS,EAAc,EAAsC,CACzD,GAAI,CAEA,OAAO,EAAG,aAAa,EAAM,CAA0B,CAC3D,MAAQ,CACJ,MACJ,CACJ,CAOA,iBAAiB,EAA6B,CAG1C,OAFI,aAAiB,KACjB,EAAM,WAAW,OAAO,EAAU,EAAQ,EAAc,CAAK,CAAC,EAC3D,EAAQ,CAAK,CACxB,CAGA,YAAY,EAAiB,EAA2B,CAEpD,OADI,EAAW,CAAS,EAAU,EAC3B,EAAK,EAAS,CAAS,CAClC,CAGA,UAAU,EAAoC,CAC1C,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,CAAI,EAC1C,EAAQ,IAAI,GAAO,CAE3B,CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PortableSource.cjs","names":["coerceToStringRecord"],"sources":["../../../src/sources/PortableSource.ts"],"sourcesContent":["import { coerceToStringRecord } from './coerce';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"PortableSource.cjs","names":["coerceToStringRecord"],"sources":["../../../src/sources/PortableSource.ts"],"sourcesContent":["import { coerceToStringRecord } from './coerce';\n\nimport type { BareSource } from '../types';\n\n/**\n * Environment source seeded from an object you provide, for every runtime without a filesystem. The\n * config your bundler injects into a browser build (Vite's `import.meta.env`, a webpack `DefinePlugin`\n * global), the Cloudflare `env` binding, a Vercel Edge or Fastly config object, a test fixture, or any\n * plain object. Pass it straight through. Non-string values are JSON-stringified so the converters\n * still apply, which means they must be JSON-serializable. Without a filesystem the `.env` cascade and\n * file APIs do not apply.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/sources#the-providers}\n */\nexport class PortableSource implements BareSource {\n /** Always `false`. With no filesystem, the `.env` cascade and file APIs do not apply. */\n readonly supportsFiles = false;\n private readonly vars: Record<string, string>;\n\n /** Seed the source from `vars`. Non-string values are JSON-stringified so the converters still apply. */\n constructor(vars: object) {\n this.vars = coerceToStringRecord(vars);\n }\n\n /** Returns a snapshot clone of the provided object as plain strings. */\n readVars(): Record<string, string> {\n return { ...this.vars };\n }\n}\n"],"mappings":"gCAcA,IAAa,EAAb,KAAkD,CAE9C,cAAyB,GACzB,KAGA,YAAY,EAAc,CACtB,KAAK,KAAOA,EAAAA,qBAAqB,CAAI,CACzC,CAGA,UAAmC,CAC/B,MAAO,CAAE,GAAG,KAAK,IAAK,CAC1B,CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PortableSource.mjs","names":[],"sources":["../../../src/sources/PortableSource.ts"],"sourcesContent":["import { coerceToStringRecord } from './coerce';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"PortableSource.mjs","names":[],"sources":["../../../src/sources/PortableSource.ts"],"sourcesContent":["import { coerceToStringRecord } from './coerce';\n\nimport type { BareSource } from '../types';\n\n/**\n * Environment source seeded from an object you provide, for every runtime without a filesystem. The\n * config your bundler injects into a browser build (Vite's `import.meta.env`, a webpack `DefinePlugin`\n * global), the Cloudflare `env` binding, a Vercel Edge or Fastly config object, a test fixture, or any\n * plain object. Pass it straight through. Non-string values are JSON-stringified so the converters\n * still apply, which means they must be JSON-serializable. Without a filesystem the `.env` cascade and\n * file APIs do not apply.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/sources#the-providers}\n */\nexport class PortableSource implements BareSource {\n /** Always `false`. With no filesystem, the `.env` cascade and file APIs do not apply. */\n readonly supportsFiles = false;\n private readonly vars: Record<string, string>;\n\n /** Seed the source from `vars`. Non-string values are JSON-stringified so the converters still apply. */\n constructor(vars: object) {\n this.vars = coerceToStringRecord(vars);\n }\n\n /** Returns a snapshot clone of the provided object as plain strings. */\n readVars(): Record<string, string> {\n return { ...this.vars };\n }\n}\n"],"mappings":"oDAcA,IAAa,EAAb,KAAkD,CAE9C,cAAyB,GACzB,KAGA,YAAY,EAAc,CACtB,KAAK,KAAO,EAAqB,CAAI,CACzC,CAGA,UAAmC,CAC/B,MAAO,CAAE,GAAG,KAAK,IAAK,CAC1B,CACJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../infra/Error.cjs");var t=class{supportsFiles=!1;readVars(){throw new e.EnvaptError(307,`No environment source is bound. Call Envapter.useSource(...) with a source such as new PortableSource({...}) before reading.`)}};exports.
|
|
2
|
-
//# sourceMappingURL=
|
|
1
|
+
const e=require("../infra/Error.cjs");var t=class{supportsFiles=!1;readVars(){throw new e.EnvaptError(307,`No environment source is bound. Call Envapter.useSource(...) with a source such as new PortableSource({...}) before reading.`)}};exports.UnboundSource=t;
|
|
2
|
+
//# sourceMappingURL=UnboundSource.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnboundSource.cjs","names":["EnvaptError"],"sources":["../../../src/sources/UnboundSource.ts"],"sourcesContent":["import { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { BareSource } from '../types';\n\n/**\n * The default source until one is bound. Every read throws NoSourceBound so a forgotten `useSource`\n * surfaces at read time instead of silently yielding nothing. The Node entry binds {@link FileSource}\n * at load, browser and Workers bundles must call `Envapter.useSource(...)` before reading.\n * @internal\n */\nexport class UnboundSource implements BareSource {\n readonly supportsFiles = false;\n\n readVars(): Record<string, string> {\n throw new EnvaptError(\n EnvaptErrorCodes.NoSourceBound,\n 'No environment source is bound. Call Envapter.useSource(...) with a source such as new PortableSource({...}) before reading.'\n );\n }\n}\n"],"mappings":"sCAUA,IAAa,EAAb,KAAiD,CAC7C,cAAyB,GAEzB,UAAmC,CAC/B,MAAM,IAAIA,EAAAA,YAAAA,IAEN,8HACJ,CACJ,CACJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{EnvaptError as e}from"../infra/Error.mjs";var t=class{supportsFiles=!1;readVars(){throw new e(307,`No environment source is bound. Call Envapter.useSource(...) with a source such as new PortableSource({...}) before reading.`)}};export{t as
|
|
2
|
-
//# sourceMappingURL=
|
|
1
|
+
import{EnvaptError as e}from"../infra/Error.mjs";var t=class{supportsFiles=!1;readVars(){throw new e(307,`No environment source is bound. Call Envapter.useSource(...) with a source such as new PortableSource({...}) before reading.`)}};export{t as UnboundSource};
|
|
2
|
+
//# sourceMappingURL=UnboundSource.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnboundSource.mjs","names":[],"sources":["../../../src/sources/UnboundSource.ts"],"sourcesContent":["import { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { BareSource } from '../types';\n\n/**\n * The default source until one is bound. Every read throws NoSourceBound so a forgotten `useSource`\n * surfaces at read time instead of silently yielding nothing. The Node entry binds {@link FileSource}\n * at load, browser and Workers bundles must call `Envapter.useSource(...)` before reading.\n * @internal\n */\nexport class UnboundSource implements BareSource {\n readonly supportsFiles = false;\n\n readVars(): Record<string, string> {\n throw new EnvaptError(\n EnvaptErrorCodes.NoSourceBound,\n 'No environment source is bound. Call Envapter.useSource(...) with a source such as new PortableSource({...}) before reading.'\n );\n }\n}\n"],"mappings":"iDAUA,IAAa,EAAb,KAAiD,CAC7C,cAAyB,GAEzB,UAAmC,CAC/B,MAAM,IAAI,EAAA,IAEN,8HACJ,CACJ,CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coerce.cjs","names":[],"sources":["../../../src/sources/coerce.ts"],"sourcesContent":["//
|
|
1
|
+
{"version":3,"file":"coerce.cjs","names":[],"sources":["../../../src/sources/coerce.ts"],"sourcesContent":["// The returned record is fresh, so a caller mutating its object\n// later cannot leak into the source, and non-string values are JSON-stringified.\nexport function coerceToStringRecord(env: object): Record<string, string> {\n const snapshot: Record<string, string> = {};\n // `object` so a Cloudflare `Env` (an interface with no index signature) is accepted. cast to a record\n // to read entries as `unknown` rather than `any`.\n for (const [key, value] of Object.entries(env as Record<string, unknown>)) {\n if (typeof value === 'string') {\n snapshot[key] = value;\n continue;\n }\n const encoded = JSON.stringify(value);\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- TS lib mistypes JSON.stringify's return as always-string when it is string | undefined at runtime\n if (encoded !== undefined) snapshot[key] = encoded;\n }\n return snapshot;\n}\n"],"mappings":"AAEA,SAAgB,EAAqB,EAAqC,CACtE,IAAM,EAAmC,CAAC,EAG1C,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,CAA8B,EAAG,CACvE,GAAI,OAAO,GAAU,SAAU,CAC3B,EAAS,GAAO,EAChB,QACJ,CACA,IAAM,EAAU,KAAK,UAAU,CAAK,EAEhC,IAAY,IAAA,KAAW,EAAS,GAAO,EAC/C,CACA,OAAO,CACX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coerce.mjs","names":[],"sources":["../../../src/sources/coerce.ts"],"sourcesContent":["//
|
|
1
|
+
{"version":3,"file":"coerce.mjs","names":[],"sources":["../../../src/sources/coerce.ts"],"sourcesContent":["// The returned record is fresh, so a caller mutating its object\n// later cannot leak into the source, and non-string values are JSON-stringified.\nexport function coerceToStringRecord(env: object): Record<string, string> {\n const snapshot: Record<string, string> = {};\n // `object` so a Cloudflare `Env` (an interface with no index signature) is accepted. cast to a record\n // to read entries as `unknown` rather than `any`.\n for (const [key, value] of Object.entries(env as Record<string, unknown>)) {\n if (typeof value === 'string') {\n snapshot[key] = value;\n continue;\n }\n const encoded = JSON.stringify(value);\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- TS lib mistypes JSON.stringify's return as always-string when it is string | undefined at runtime\n if (encoded !== undefined) snapshot[key] = encoded;\n }\n return snapshot;\n}\n"],"mappings":"AAEA,SAAgB,EAAqB,EAAqC,CACtE,IAAM,EAAmC,CAAC,EAG1C,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,CAA8B,EAAG,CACvE,GAAI,OAAO,GAAU,SAAU,CAC3B,EAAS,GAAO,EAChB,QACJ,CACA,IAAM,EAAU,KAAK,UAAU,CAAK,EAEhC,IAAY,IAAA,KAAW,EAAS,GAAO,EAC/C,CACA,OAAO,CACX"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../infra/Error.cjs"),t=require("./normalizeSource.cjs");function n(...n){if(n.length===0)throw new e.EnvaptError(308,`merge requires at least one source.`);let r=n.map(t.normalizeSource),i=r.filter(e=>e.supportsFiles===!0);if(i.length>1)throw new e.EnvaptError(308,`merge accepts at most one filesystem-backed source, so the .env cascade and file APIs route to a single member.`);let a=()=>{let e={};for(let t of r)Object.assign(e,t.readVars());return e},o=r.filter(e=>typeof e.readVar==`function`),s=o.length===0?void 0:e=>{for(let t=o.length-1;t>=0;t--){let n=o[t]?.readVar(e);if(n!==void 0)return n}},c=i[0];if(!c){let e={readVars:a};return s&&(e.readVar=s),e}let l={readVars:a,supportsFiles:!0,readFile:(e,t)=>c.readFile(e,t),resolvePath:(e,t)=>c.resolvePath(e,t),normalizeBaseDir:e=>c.normalizeBaseDir(e),writeVars:e=>c.writeVars(e)};return s&&(l.readVar=s),l}exports.merge=n;
|
|
2
|
+
//# sourceMappingURL=merge.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.cjs","names":["EnvaptError","normalizeSource"],"sources":["../../../src/sources/merge.ts"],"sourcesContent":["import { normalizeSource } from './normalizeSource';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { BareSource, FileCapableSource, Source } from '../types';\n\n/**\n * Compose several sources into one, read last-wins. A later member's `readVars()` value overrides an\n * earlier member's for the same key. A member may be a `(key) => string | undefined` reader for a\n * source that reads one key at a time, and it fills a key missing from every snapshot. Bind the result\n * with `Envapter.useSource`. Throws {@link EnvaptErrorCodes.InvalidMergedSource} with no members or with\n * more than one file-backed member.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/sources#combining-sources}\n */\nexport function merge(...members: (Source | ((key: string) => string | undefined))[]): Source {\n if (members.length === 0) {\n throw new EnvaptError(EnvaptErrorCodes.InvalidMergedSource, 'merge requires at least one source.');\n }\n\n const sources = members.map(normalizeSource);\n\n const fileMembers = sources.filter((m): m is FileCapableSource => m.supportsFiles === true);\n if (fileMembers.length > 1) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidMergedSource,\n 'merge accepts at most one filesystem-backed source, so the .env cascade and file APIs route to a single member.'\n );\n }\n\n const readVars = (): Record<string, string> => {\n const merged: Record<string, string> = {};\n for (const m of sources) Object.assign(merged, m.readVars());\n return merged;\n };\n\n const readers = sources.filter(\n (m): m is Source & { readVar: (key: string) => string | undefined } => typeof m.readVar === 'function'\n );\n const readVar =\n readers.length === 0\n ? undefined\n : (key: string): string | undefined => {\n // last reader that answers wins, so scan from the end and return the first defined value\n for (let i = readers.length - 1; i >= 0; i--) {\n const found = readers[i]?.readVar(key);\n if (found !== undefined) return found;\n }\n return undefined;\n };\n\n const fileMember = fileMembers[0];\n if (!fileMember) {\n const bare: BareSource = { readVars };\n if (readVar) bare.readVar = readVar;\n return bare;\n }\n\n const fileCapable: FileCapableSource = {\n readVars,\n supportsFiles: true,\n readFile: (path, encoding) => fileMember.readFile(path, encoding),\n resolvePath: (baseDir, candidate) => fileMember.resolvePath(baseDir, candidate),\n normalizeBaseDir: (value) => fileMember.normalizeBaseDir(value),\n writeVars: (vars) => fileMember.writeVars(vars)\n };\n if (readVar) fileCapable.readVar = readVar;\n return fileCapable;\n}\n"],"mappings":"yEAcA,SAAgB,EAAM,GAAG,EAAqE,CAC1F,GAAI,EAAQ,SAAW,EACnB,MAAM,IAAIA,EAAAA,YAAAA,IAAkD,qCAAqC,EAGrG,IAAM,EAAU,EAAQ,IAAIC,EAAAA,eAAe,EAErC,EAAc,EAAQ,OAAQ,GAA8B,EAAE,gBAAkB,EAAI,EAC1F,GAAI,EAAY,OAAS,EACrB,MAAM,IAAID,EAAAA,YAAAA,IAEN,iHACJ,EAGJ,IAAM,MAAyC,CAC3C,IAAM,EAAiC,CAAC,EACxC,IAAK,IAAM,KAAK,EAAS,OAAO,OAAO,EAAQ,EAAE,SAAS,CAAC,EAC3D,OAAO,CACX,EAEM,EAAU,EAAQ,OACnB,GAAsE,OAAO,EAAE,SAAY,UAChG,EACM,EACF,EAAQ,SAAW,EACb,IAAA,GACC,GAAoC,CAEjC,IAAK,IAAI,EAAI,EAAQ,OAAS,EAAG,GAAK,EAAG,IAAK,CAC1C,IAAM,EAAQ,EAAQ,EAAE,EAAE,QAAQ,CAAG,EACrC,GAAI,IAAU,IAAA,GAAW,OAAO,CACpC,CAEJ,EAEJ,EAAa,EAAY,GAC/B,GAAI,CAAC,EAAY,CACb,IAAM,EAAmB,CAAE,UAAS,EAEpC,OADI,IAAS,EAAK,QAAU,GACrB,CACX,CAEA,IAAM,EAAiC,CACnC,WACA,cAAe,GACf,UAAW,EAAM,IAAa,EAAW,SAAS,EAAM,CAAQ,EAChE,aAAc,EAAS,IAAc,EAAW,YAAY,EAAS,CAAS,EAC9E,iBAAmB,GAAU,EAAW,iBAAiB,CAAK,EAC9D,UAAY,GAAS,EAAW,UAAU,CAAI,CAClD,EAEA,OADI,IAAS,EAAY,QAAU,GAC5B,CACX"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{EnvaptError as e}from"../infra/Error.mjs";import{normalizeSource as t}from"./normalizeSource.mjs";function n(...n){if(n.length===0)throw new e(308,`merge requires at least one source.`);let r=n.map(t),i=r.filter(e=>e.supportsFiles===!0);if(i.length>1)throw new e(308,`merge accepts at most one filesystem-backed source, so the .env cascade and file APIs route to a single member.`);let a=()=>{let e={};for(let t of r)Object.assign(e,t.readVars());return e},o=r.filter(e=>typeof e.readVar==`function`),s=o.length===0?void 0:e=>{for(let t=o.length-1;t>=0;t--){let n=o[t]?.readVar(e);if(n!==void 0)return n}},c=i[0];if(!c){let e={readVars:a};return s&&(e.readVar=s),e}let l={readVars:a,supportsFiles:!0,readFile:(e,t)=>c.readFile(e,t),resolvePath:(e,t)=>c.resolvePath(e,t),normalizeBaseDir:e=>c.normalizeBaseDir(e),writeVars:e=>c.writeVars(e)};return s&&(l.readVar=s),l}export{n as merge};
|
|
2
|
+
//# sourceMappingURL=merge.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.mjs","names":[],"sources":["../../../src/sources/merge.ts"],"sourcesContent":["import { normalizeSource } from './normalizeSource';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { BareSource, FileCapableSource, Source } from '../types';\n\n/**\n * Compose several sources into one, read last-wins. A later member's `readVars()` value overrides an\n * earlier member's for the same key. A member may be a `(key) => string | undefined` reader for a\n * source that reads one key at a time, and it fills a key missing from every snapshot. Bind the result\n * with `Envapter.useSource`. Throws {@link EnvaptErrorCodes.InvalidMergedSource} with no members or with\n * more than one file-backed member.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/sources#combining-sources}\n */\nexport function merge(...members: (Source | ((key: string) => string | undefined))[]): Source {\n if (members.length === 0) {\n throw new EnvaptError(EnvaptErrorCodes.InvalidMergedSource, 'merge requires at least one source.');\n }\n\n const sources = members.map(normalizeSource);\n\n const fileMembers = sources.filter((m): m is FileCapableSource => m.supportsFiles === true);\n if (fileMembers.length > 1) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidMergedSource,\n 'merge accepts at most one filesystem-backed source, so the .env cascade and file APIs route to a single member.'\n );\n }\n\n const readVars = (): Record<string, string> => {\n const merged: Record<string, string> = {};\n for (const m of sources) Object.assign(merged, m.readVars());\n return merged;\n };\n\n const readers = sources.filter(\n (m): m is Source & { readVar: (key: string) => string | undefined } => typeof m.readVar === 'function'\n );\n const readVar =\n readers.length === 0\n ? undefined\n : (key: string): string | undefined => {\n // last reader that answers wins, so scan from the end and return the first defined value\n for (let i = readers.length - 1; i >= 0; i--) {\n const found = readers[i]?.readVar(key);\n if (found !== undefined) return found;\n }\n return undefined;\n };\n\n const fileMember = fileMembers[0];\n if (!fileMember) {\n const bare: BareSource = { readVars };\n if (readVar) bare.readVar = readVar;\n return bare;\n }\n\n const fileCapable: FileCapableSource = {\n readVars,\n supportsFiles: true,\n readFile: (path, encoding) => fileMember.readFile(path, encoding),\n resolvePath: (baseDir, candidate) => fileMember.resolvePath(baseDir, candidate),\n normalizeBaseDir: (value) => fileMember.normalizeBaseDir(value),\n writeVars: (vars) => fileMember.writeVars(vars)\n };\n if (readVar) fileCapable.readVar = readVar;\n return fileCapable;\n}\n"],"mappings":"yGAcA,SAAgB,EAAM,GAAG,EAAqE,CAC1F,GAAI,EAAQ,SAAW,EACnB,MAAM,IAAI,EAAA,IAAkD,qCAAqC,EAGrG,IAAM,EAAU,EAAQ,IAAI,CAAe,EAErC,EAAc,EAAQ,OAAQ,GAA8B,EAAE,gBAAkB,EAAI,EAC1F,GAAI,EAAY,OAAS,EACrB,MAAM,IAAI,EAAA,IAEN,iHACJ,EAGJ,IAAM,MAAyC,CAC3C,IAAM,EAAiC,CAAC,EACxC,IAAK,IAAM,KAAK,EAAS,OAAO,OAAO,EAAQ,EAAE,SAAS,CAAC,EAC3D,OAAO,CACX,EAEM,EAAU,EAAQ,OACnB,GAAsE,OAAO,EAAE,SAAY,UAChG,EACM,EACF,EAAQ,SAAW,EACb,IAAA,GACC,GAAoC,CAEjC,IAAK,IAAI,EAAI,EAAQ,OAAS,EAAG,GAAK,EAAG,IAAK,CAC1C,IAAM,EAAQ,EAAQ,EAAE,EAAE,QAAQ,CAAG,EACrC,GAAI,IAAU,IAAA,GAAW,OAAO,CACpC,CAEJ,EAEJ,EAAa,EAAY,GAC/B,GAAI,CAAC,EAAY,CACb,IAAM,EAAmB,CAAE,UAAS,EAEpC,OADI,IAAS,EAAK,QAAU,GACrB,CACX,CAEA,IAAM,EAAiC,CACnC,WACA,cAAe,GACf,UAAW,EAAM,IAAa,EAAW,SAAS,EAAM,CAAQ,EAChE,aAAc,EAAS,IAAc,EAAW,YAAY,EAAS,CAAS,EAC9E,iBAAmB,GAAU,EAAW,iBAAiB,CAAK,EAC9D,UAAY,GAAS,EAAW,UAAU,CAAI,CAClD,EAEA,OADI,IAAS,EAAY,QAAU,GAC5B,CACX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeSource.cjs","names":[],"sources":["../../../src/sources/normalizeSource.ts"],"sourcesContent":["import type { Source } from '../types';\n\nexport function normalizeSource(source: Source | ((key: string) => string | undefined)): Source {\n return typeof source === 'function' ? { supportsFiles: false, readVars: () => ({}), readVar: source } : source;\n}\n"],"mappings":"AAEA,SAAgB,EAAgB,EAAgE,CAC5F,OAAO,OAAO,GAAW,WAAa,CAAE,cAAe,GAAO,cAAiB,CAAC,GAAI,QAAS,CAAO,EAAI,CAC5G"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeSource.mjs","names":[],"sources":["../../../src/sources/normalizeSource.ts"],"sourcesContent":["import type { Source } from '../types';\n\nexport function normalizeSource(source: Source | ((key: string) => string | undefined)): Source {\n return typeof source === 'function' ? { supportsFiles: false, readVars: () => ({}), readVar: source } : source;\n}\n"],"mappings":"AAEA,SAAgB,EAAgB,EAAgE,CAC5F,OAAO,OAAO,GAAW,WAAa,CAAE,cAAe,GAAO,cAAiB,CAAC,GAAI,QAAS,CAAO,EAAI,CAC5G"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{EnvaptError as e}from"../infra/Error.mjs";const t=1e3,n=60*t,r=60*n,i=24*r,a={ms:1,s:t,m:n,h:r,d:i,w:7*i},o=new RegExp(String.raw`^(\d+(?:\.\d+)?)(ms|s|m|h|d|w)?$`,`u`),s=new RegExp(String.raw`^(\d+(?:\.\d+)?)(ms|s|m|h|d|w)$`,`u`);function c(e,t=!1){let n=e.match(t?s:o);if(!n)return;let[,r,i]=n;if(!r)return;let c=Number.parseFloat(r);if(!Number.isNaN(c))return c*a[i??`ms`]}var l=class t{static string(e,t){return String(e)}static number(e,t){let n=Number(e);return Number.isNaN(n)?t:n}static boolean(e,t){let n=e.toLowerCase().trim();return[`1`,`yes`,`true`,`on`].includes(n)?!0:[`0`,`no`,`false`,`off`].includes(n)?!1:t}static bigint(e,t){try{return BigInt(e)}catch{return t}}static symbol(e,t){try{return e?Symbol.for(e):t}catch{return t}}static integer(e,t){let n=e.trim();if(n===``)return t;let r=Number(n);return Number.isSafeInteger(r)?r:t}static float(e,t){let n=e.trim();if(n===``)return t;let r=Number(n);return Number.isNaN(r)?t:r}static json(e,t){try{return JSON.parse(e)}catch{return t}}static url(e,t){try{return new URL(e)}catch{return t}}static regexp(e,t){try{let t=e.match(new RegExp(String.raw`^\/(.+)\/([gimsuvy]*)$`));return t?new RegExp(t[1],t[2]):new RegExp(e)}catch{return t}}static date(e,t){if(new RegExp(String.raw`^\d+$`).test(e)){let n=new Date(parseInt(e,10));return Number.isNaN(n.getTime())?t:n}if(!new RegExp(String.raw`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$`,`u`).test(e))return t;let n=new Date(e);return Number.isNaN(n.getTime())?t:n}static time(t,n){let r=c(t);if(r!==void 0)return r;if(typeof n==`number`)return n;if(typeof n==`string`){let t=c(n,!0);if(t===void 0)throw new e(105,`Time-string fallback "${n}" is not a valid format. Expected <number><unit> where unit is one of: ms, s, m, h, d, w.`);return t}}static processArrayConverter(n,r,i=!1){if(n.trim()===``)return[];let a=n.split(r.delimiter).map(e=>String(e).trim());if(i){let t=a.findIndex(e=>e===``);if(t!==-1)throw new e(207,`Array element at index ${t} is empty or whitespace only (strict mode).`)}let o=a.filter(Boolean);if(!o.length)return[];let s=r.of;if(typeof s==`function`)return o.map((t,n)=>{let r=s(t);if(r===void 0)throw new e(206,`Custom element converter returned undefined for item "${t}" at index ${n}.`);return r});let c=t.getConverter(s);return o.map((t,n)=>{let r=c(t,void 0);if(r===void 0)throw new e(206,`Element "${t}" at index ${n} could not be converted to ${s}.`);return r})}static getConverter(e){return{string:t.string,number:t.number,boolean:t.boolean,integer:t.integer,bigint:t.bigint,symbol:t.symbol,float:t.float,json:t.json,url:t.url,regexp:t.regexp,date:t.date,time:t.time}[e]}};export{l as BuiltInConverters};
|
|
2
|
+
//# sourceMappingURL=BuiltInConverters.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuiltInConverters.mjs","names":["converter"],"sources":["../../../src/converters/BuiltInConverters.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/unbound-method */\n\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { ArrayOf, CustomElementConverter } from './Converters';\nimport type {\n BuiltInConverter,\n BuiltInConverterFunction,\n JsonValue,\n MapOfConverterFunctions,\n TimeFallback,\n TimeUnit\n} from '../types';\n\nconst MS_PER_SECOND = 1000;\nconst SECONDS_PER_MINUTE = 60;\nconst MINUTES_PER_HOUR = 60;\nconst HOURS_PER_DAY = 24;\nconst DAYS_PER_WEEK = 7;\nconst MS_PER_MINUTE = SECONDS_PER_MINUTE * MS_PER_SECOND;\nconst MS_PER_HOUR = MINUTES_PER_HOUR * MS_PER_MINUTE;\nconst MS_PER_DAY = HOURS_PER_DAY * MS_PER_HOUR;\nconst MS_PER_WEEK = DAYS_PER_WEEK * MS_PER_DAY;\n\nconst TIME_UNIT_MS: Record<TimeUnit, number> = {\n ms: 1,\n s: MS_PER_SECOND,\n m: MS_PER_MINUTE,\n h: MS_PER_HOUR,\n d: MS_PER_DAY,\n w: MS_PER_WEEK\n};\n\nconst TIME_LOOSE_RE = new RegExp(String.raw`^(\\d+(?:\\.\\d+)?)(ms|s|m|h|d|w)?$`, 'u');\nconst TIME_STRICT_RE = new RegExp(String.raw`^(\\d+(?:\\.\\d+)?)(ms|s|m|h|d|w)$`, 'u');\n\n/**\n * Parse a time string (e.g. `\"30s\"`, `\"1.5h\"`) into milliseconds.\n *\n * @param input - The string to parse.\n * @param strict - When `true`, require an explicit unit (used for fallback strings).\n * When `false` (default), treat a missing unit as `ms` (used for raw env values). Both allow decimals.\n * @returns The duration in milliseconds, or `undefined` if the input does not match the expected format.\n * @internal\n */\nfunction parseTimeString(input: string, strict = false): number | undefined {\n const match = input.match(strict ? TIME_STRICT_RE : TIME_LOOSE_RE);\n if (!match) return undefined;\n\n const [, numStr, capturedUnit] = match;\n if (!numStr) return undefined;\n\n const value = Number.parseFloat(numStr);\n if (Number.isNaN(value)) return undefined;\n\n const unit = (capturedUnit ?? 'ms') as TimeUnit;\n return value * TIME_UNIT_MS[unit];\n}\n\n/**\n * Built-in converter implementations\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-extraneous-class -- dispatch-table helper, the documented exception to the no-static-class rule\nexport class BuiltInConverters {\n static string(raw: string, _fallback?: string): string | undefined {\n return String(raw);\n }\n\n static number(raw: string, fallback?: number): number | undefined {\n const parsed = Number(raw);\n return Number.isNaN(parsed) ? fallback : parsed;\n }\n\n static boolean(raw: string, fallback?: boolean): boolean | undefined {\n const lower = raw.toLowerCase().trim();\n\n const truthyValues = ['1', 'yes', 'true', 'on'];\n const falsyValues = ['0', 'no', 'false', 'off'];\n\n if (truthyValues.includes(lower)) return true;\n if (falsyValues.includes(lower)) return false;\n return fallback;\n }\n\n static bigint(raw: string, fallback?: bigint): bigint | undefined {\n try {\n return BigInt(raw);\n } catch {\n return fallback;\n }\n }\n\n static symbol(raw: string, fallback?: symbol): symbol | undefined {\n try {\n return raw ? Symbol.for(raw) : fallback;\n } catch {\n return fallback;\n }\n }\n\n static integer(raw: string, fallback?: number): number | undefined {\n const trimmed = raw.trim();\n if (trimmed === '') return fallback;\n const parsed = Number(trimmed);\n // isSafeInteger also guards the 2^53 boundary, past which an integer value silently loses precision.\n return Number.isSafeInteger(parsed) ? parsed : fallback;\n }\n\n static float(raw: string, fallback?: number): number | undefined {\n const trimmed = raw.trim();\n if (trimmed === '') return fallback;\n const parsed = Number(trimmed);\n // isNaN keeps Infinity valid, matching the number converter.\n return Number.isNaN(parsed) ? fallback : parsed;\n }\n\n static json(raw: string, fallback?: JsonValue): JsonValue | undefined {\n try {\n return JSON.parse(raw) as JsonValue;\n } catch {\n return fallback;\n }\n }\n\n static url(raw: string, fallback?: URL): URL | undefined {\n try {\n return new URL(raw);\n } catch {\n return fallback;\n }\n }\n\n static regexp(raw: string, fallback?: RegExp): RegExp | undefined {\n try {\n // Handle flags if provided in format: /pattern/flags\n const match = raw.match(new RegExp(String.raw`^\\/(.+)\\/([gimsuvy]*)$`));\n if (match) return new RegExp(match[1] as string, match[2]);\n\n return new RegExp(raw);\n } catch {\n return fallback;\n }\n }\n\n static date(raw: string, fallback?: Date): Date | undefined {\n // Try parsing as timestamp first (if it's all digits)\n if (new RegExp(String.raw`^\\d+$`).test(raw)) {\n const timestamp = parseInt(raw, 10);\n const parsed = new Date(timestamp);\n return Number.isNaN(parsed.getTime()) ? fallback : parsed;\n }\n\n // Only accept ISO 8601 date strings (strict format)\n const isoRegex = new RegExp(String.raw`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{3})?Z$`, 'u');\n if (!isoRegex.test(raw)) return fallback;\n\n const parsed = new Date(raw);\n return Number.isNaN(parsed.getTime()) ? fallback : parsed;\n }\n\n static time(raw: string, fallback?: TimeFallback): number | undefined {\n const parsedRaw = parseTimeString(raw);\n if (parsedRaw !== undefined) return parsedRaw;\n\n // Raw didn't parse so apply fallback\n if (typeof fallback === 'number') return fallback;\n if (typeof fallback === 'string') {\n // A string fallback must name a unit; a unitless number is expressed as a number fallback, not a string.\n const parsedFallback = parseTimeString(fallback, true);\n if (parsedFallback === undefined) {\n throw new EnvaptError(\n EnvaptErrorCodes.MalformedTimeFallback,\n `Time-string fallback \"${fallback}\" is not a valid format. Expected <number><unit> where unit is one of: ms, s, m, h, d, w.`\n );\n }\n return parsedFallback;\n }\n return undefined;\n }\n\n /**\n * Process the raw env value for an {@link ArrayOf} configuration.\n *\n * Behaviour:\n * - Splits on `config.delimiter`, trims each item, and filters out empty entries.\n * - With a scalar element token: runs each item through the matching built-in converter.\n * If any element returns `undefined`, throws `ArrayElementConversionFailed` with positional info.\n * - With a custom function element: runs each item through the function. Propagates user\n * exceptions; treats `undefined` returns as conversion failures (same throw as scalar path).\n * - Returns `[]` when the raw value is empty/whitespace.\n * - When `strict` is true, throws `EmptyArrayElement` on any empty/whitespace item instead\n * of silently filtering it out.\n */\n static processArrayConverter(raw: string, config: ArrayOf, strict = false): unknown[] {\n if (raw.trim() === '') return [];\n\n const trimmedItems = raw.split(config.delimiter).map((item) => String(item).trim());\n\n if (strict) {\n const emptyIdx = trimmedItems.findIndex((item) => item === '');\n if (emptyIdx !== -1) {\n throw new EnvaptError(\n EnvaptErrorCodes.EmptyArrayElement,\n `Array element at index ${emptyIdx} is empty or whitespace only (strict mode).`\n );\n }\n }\n\n const items = trimmedItems.filter(Boolean);\n\n if (!items.length) return [];\n\n const elementOf = config.of;\n\n if (typeof elementOf === 'function') {\n return items.map((item, index) => {\n const converter = elementOf as CustomElementConverter;\n const result = converter(item);\n if (result === undefined) {\n throw new EnvaptError(\n EnvaptErrorCodes.ArrayElementConversionFailed,\n `Custom element converter returned undefined for item \"${item}\" at index ${index}.`\n );\n }\n return result;\n });\n }\n\n const converter = BuiltInConverters.getConverter(elementOf);\n return items.map((item, index) => {\n const converted = converter(item, undefined);\n if (converted === undefined) {\n throw new EnvaptError(\n EnvaptErrorCodes.ArrayElementConversionFailed,\n `Element \"${item}\" at index ${index} could not be converted to ${elementOf}.`\n );\n }\n return converted;\n });\n }\n\n /**\n * Get the converter function for a built-in converter type\n */\n static getConverter<TFallback extends BuiltInConverter>(type: TFallback): BuiltInConverterFunction {\n const converters: MapOfConverterFunctions = {\n string: BuiltInConverters.string,\n number: BuiltInConverters.number,\n boolean: BuiltInConverters.boolean,\n integer: BuiltInConverters.integer,\n bigint: BuiltInConverters.bigint,\n symbol: BuiltInConverters.symbol,\n float: BuiltInConverters.float,\n json: BuiltInConverters.json,\n url: BuiltInConverters.url,\n regexp: BuiltInConverters.regexp,\n date: BuiltInConverters.date,\n time: BuiltInConverters.time\n } as const;\n\n return converters[type];\n }\n}\n"],"mappings":"iDAcA,MAAM,EAAgB,IAKhB,EAAgB,GAAqB,EACrC,EAAc,GAAmB,EACjC,EAAa,GAAgB,EAG7B,EAAyC,CAC3C,GAAI,EACJ,EAAG,EACH,EAAG,EACH,EAAG,EACH,EAAG,EACH,EARgB,EAAgB,CASpC,EAEM,EAAgB,IAAI,OAAO,OAAO,GAAG,mCAAoC,GAAG,EAC5E,EAAiB,IAAI,OAAO,OAAO,GAAG,kCAAmC,GAAG,EAWlF,SAAS,EAAgB,EAAe,EAAS,GAA2B,CACxE,IAAM,EAAQ,EAAM,MAAM,EAAS,EAAiB,CAAa,EACjE,GAAI,CAAC,EAAO,OAEZ,GAAM,EAAG,EAAQ,GAAgB,EACjC,GAAI,CAAC,EAAQ,OAEb,IAAM,EAAQ,OAAO,WAAW,CAAM,EAClC,WAAO,MAAM,CAAK,EAGtB,OAAO,EAAQ,EADD,GAAgB,KAElC,CAOA,IAAa,EAAb,MAAa,CAAkB,CAC3B,OAAO,OAAO,EAAa,EAAwC,CAC/D,OAAO,OAAO,CAAG,CACrB,CAEA,OAAO,OAAO,EAAa,EAAuC,CAC9D,IAAM,EAAS,OAAO,CAAG,EACzB,OAAO,OAAO,MAAM,CAAM,EAAI,EAAW,CAC7C,CAEA,OAAO,QAAQ,EAAa,EAAyC,CACjE,IAAM,EAAQ,EAAI,YAAY,CAAC,CAAC,KAAK,EAOrC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,IAAI,EAAA,IAEN,yDAAyD,EAAK,aAAa,EAAM,EACrF,EAEJ,OAAO,CACX,CAAC,EAGL,IAAM,EAAY,EAAkB,aAAa,CAAS,EAC1D,OAAO,EAAM,KAAK,EAAM,IAAU,CAC9B,IAAM,EAAY,EAAU,EAAM,IAAA,EAAS,EAC3C,GAAI,IAAc,IAAA,GACd,MAAM,IAAI,EAAA,IAEN,YAAY,EAAK,aAAa,EAAM,6BAA6B,EAAU,EAC/E,EAEJ,OAAO,CACX,CAAC,CACL,CAKA,OAAO,aAAiD,EAA2C,CAgB/F,MAAO,CAdH,OAAQ,EAAkB,OAC1B,OAAQ,EAAkB,OAC1B,QAAS,EAAkB,QAC3B,QAAS,EAAkB,QAC3B,OAAQ,EAAkB,OAC1B,OAAQ,EAAkB,OAC1B,MAAO,EAAkB,MACzB,KAAM,EAAkB,KACxB,IAAK,EAAkB,IACvB,OAAQ,EAAkB,OAC1B,KAAM,EAAkB,KACxB,KAAM,EAAkB,IAGZ,EAAE,EACtB,CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Converters.mjs","names":[],"sources":["../../../src/converters/Converters.ts"],"sourcesContent":["const SCALAR = {\n String: 'string',\n Number: 'number',\n Boolean: 'boolean',\n Bigint: 'bigint',\n Symbol: 'symbol',\n Integer: 'integer',\n Float: 'float',\n Json: 'json',\n Url: 'url',\n Regexp: 'regexp',\n Date: 'date',\n Time: 'time'\n} as const;\n\nexport type ConverterToken = (typeof SCALAR)[keyof typeof SCALAR];\n\n/**\n * Custom element converter for use inside {@link Converters.array}. Receives the trimmed,\n * non-empty raw string for one array slot and returns the parsed value.\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/converters#custom-converters}\n */\nexport type CustomElementConverter<TReturn = unknown> = (raw: string) => TReturn;\n\n// json/regexp are not allowed as array elements because they consume the whole string and cannot be split into slots\nexport type ArrayElement = Exclude<ConverterToken, 'json' | 'regexp'> | CustomElementConverter;\n\n// phantom type branded with __envaptKind for runtime dispatch. TElement preserves\n// element converter type through variable indirection for type inference\nexport interface ArrayOf<TElement extends ArrayElement = ArrayElement> {\n readonly __envaptKind: 'array';\n readonly of: TElement;\n readonly delimiter: string;\n}\n\nexport function isArrayOf(value: unknown): value is ArrayOf {\n return typeof value === 'object' && value !== null && '__envaptKind' in value && value.__envaptKind === 'array';\n}\n\ntype ArrayScalarElement = Exclude<ConverterToken, 'json' | 'regexp'>;\n\nfunction buildArrayConverter<TReturn>(opts: {\n of: CustomElementConverter<TReturn>;\n delimiter?: string;\n}): ArrayOf<CustomElementConverter<TReturn>>;\nfunction buildArrayConverter<TToken extends ArrayScalarElement>(opts: {\n of: TToken;\n delimiter?: string;\n}): ArrayOf<TToken>;\nfunction buildArrayConverter(opts?: { delimiter?: string }): ArrayOf<'string'>;\nfunction buildArrayConverter(opts?: { of?: ArrayElement; delimiter?: string }): ArrayOf<ArrayElement> {\n return {\n __envaptKind: 'array',\n of: opts?.of ?? SCALAR.String,\n delimiter: opts?.delimiter ?? ','\n };\n}\n\n/**\n * Built-in converters for environment variables. Use the scalar tokens (e.g. `Converters.Number`)\n * for primitive types and the {@link Converters.array} builder for delimited lists.\n *\n * @example\n * ```ts\n * \\@Envapt('PORT', { converter: Converters.Number, fallback: 3000 })\n * static readonly port: number;\n *\n * \\@Envapt('TAGS', { converter: Converters.array({ of: Converters.String, delimiter: ' ' }) })\n * static readonly tags: string[];\n * ```\n *\n * @public\n * @see {@link https://envapt.materwelon.dev/docs/converters#built-in-tokens}\n */\nexport const Converters = {\n ...SCALAR,\n array: buildArrayConverter\n} as const;\n"],"mappings":"AAAA,MAAM,EAAS,CACX,OAAQ,SACR,OAAQ,SACR,QAAS,UACT,OAAQ,SACR,OAAQ,SACR,QAAS,UACT,MAAO,QACP,KAAM,OACN,IAAK,MACL,OAAQ,SACR,KAAM,OACN,KAAM,MACV,EAuBA,SAAgB,EAAU,EAAkC,CACxD,OAAO,OAAO,GAAU,YAAY,GAAkB,iBAAkB,GAAS,EAAM,eAAiB,OAC5G,CAaA,SAAS,EAAoB,EAAyE,CAClG,MAAO,CACH,aAAc,QACd,GAAI,GAAM,IAAM,EAAO,OACvB,UAAW,GAAM,WAAa,GAClC,CACJ,CAkBA,MAAa,EAAa,CACtB,GAAG,EACH,MAAO,CACX"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{EnvaptError as e}from"../infra/Error.mjs";import{state as t}from"../core/state.mjs";import{BuiltInConverters as n}from"./BuiltInConverters.mjs";import{Validator as r}from"../engine/Validators.mjs";import{debugVerbose as i}from"../infra/Debug.mjs";function a(e){return Array.isArray(e)?`[${e.join(`, `)}]`:String(e)}var o=class{envService;constructor(e){this.envService=e}convertValue(e,t,n,i){let a=this.resolveConverter(n,t),o=this.processFallbackForConverter(a,t);if(r.isArrayConverter(a))return this.processArrayConverter(e,o,a,i);if(r.isPrimitiveConstructor(a)){let t=this.convertPrimitiveToString(a);return this.processBuiltInConverter(e,o,t,i,!0)}return r.isBuiltInConverter(a)?this.processBuiltInConverter(e,o,a,i,!1):this.processCustomConverter(e,o,a,i)}processFallbackForConverter(e,t){return r.isPrimitiveConstructor(e)&&t!==void 0?r.coercePrimitiveFallback(e,t):t}convertPrimitiveToString(t){if(t===String)return`string`;if(t===Number)return`number`;if(t===Boolean)return`boolean`;if(t===BigInt)return`bigint`;if(t===Symbol)return`symbol`;throw new e(204,`Unknown primitive constructor`)}processBuiltInConverter(e,t,o,s,c){r.builtInConverter(o),s&&t!==void 0&&!c&&r.validateBuiltInConverterFallback(o,t);let l=this.envService.get(e,void 0);if(l===void 0)return s?o===`time`&&typeof t==`string`?n.getConverter(o)(``,t):t:null;let u=n.getConverter(o),d=u(l,void 0);return d===void 0?(i(`could not convert ${a(e)} as ${o}${s?`, using the fallback`:``}`),s?u(l,t):null):d}processArrayConverter(i,a,o,s){if(r.arrayConverter(o),s&&a!==void 0&&!Array.isArray(a))throw new e(101,`ArrayOf<...> requires that the fallback be an array, got ${typeof a}`);s&&Array.isArray(a)&&(r.validateArrayFallbackElementTypes(a),r.validateArrayConverterElementTypeMatch(o.of,a));let c=this.envService.get(i,void 0);if(c===void 0){if(!s)return null;if(o.of===`time`&&Array.isArray(a)&&a.every(e=>typeof e==`string`)){let e=n.getConverter(`time`);return a.map(t=>e(``,t))}return a}return n.processArrayConverter(c,o,t.strict)}processCustomConverter(e,t,n,i){return r.customConvertor(n),n(this.envService.get(e,void 0),t)}resolveConverter(e,t){if(e)return e;let n=typeof t;return n===`number`?`number`:n===`boolean`?`boolean`:n===`bigint`?`bigint`:n===`symbol`?`symbol`:`string`}convertWithSchema(t,n,r,i){let o=this.envService.get(t,void 0);if(o===void 0){if(i)return r;throw new e(305,`Required environment variable "${a(t)}" is missing or empty.`)}let s;try{s=n[`~standard`].validate(o)}catch(n){throw new e(209,`Schema for "${a(t)}" threw during validation: ${n.message}`,{cause:n})}if(s instanceof Promise)throw new e(302,`Schema for "${a(t)}" returned a Promise. envapt requires synchronous schemas; use a sync validator or perform async checks outside the env layer.`);if(s.issues!==void 0){let n=s.issues[0]?.message??`no issue message`;throw new e(208,`Schema validation failed for "${a(t)}": ${n}`,{issues:s.issues})}return s.value}};export{o as ValueConverter};
|
|
2
|
+
//# sourceMappingURL=ValueConverter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValueConverter.mjs","names":[],"sources":["../../../src/converters/ValueConverter.ts"],"sourcesContent":["import { BuiltInConverters } from './BuiltInConverters';\nimport { state } from '../core/state';\nimport { Validator } from '../engine/Validators';\nimport { debugVerbose } from '../infra/Debug';\nimport { EnvaptError, EnvaptErrorCodes } from '../infra/Error';\n\nimport type { ArrayOf } from './Converters';\nimport type { StandardSchemaV1 } from '../infra/StandardSchema';\nimport type { BuiltInConverter, EnvKeyInput, EnvaptConverter, PrimitiveConstructor } from '../types';\nimport type { EnvapterService } from '../types/Env';\n\nfunction formatKeyForError(key: EnvKeyInput): string {\n return Array.isArray(key) ? `[${key.join(', ')}]` : String(key);\n}\n\n/**\n * Convert a resolved environment value to its declared type via built-in, primitive, array,\n * custom, or Standard Schema converters.\n * @internal\n */\nexport class ValueConverter {\n constructor(private readonly envService: EnvapterService) {}\n\n convertValue<TFallback>(\n key: EnvKeyInput,\n fallback: TFallback | undefined,\n converter: EnvaptConverter<TFallback> | undefined,\n hasFallback: boolean\n ): TFallback | null | undefined {\n const resolvedConverter = this.resolveConverter(converter, fallback);\n const processedFallback = this.processFallbackForConverter(resolvedConverter, fallback);\n\n if (Validator.isArrayConverter(resolvedConverter)) {\n return this.processArrayConverter(key, processedFallback, resolvedConverter, hasFallback);\n }\n\n if (Validator.isPrimitiveConstructor(resolvedConverter)) {\n const stringConverter = this.convertPrimitiveToString(resolvedConverter);\n return this.processBuiltInConverter(key, processedFallback, stringConverter, hasFallback, true);\n }\n\n if (Validator.isBuiltInConverter(resolvedConverter)) {\n return this.processBuiltInConverter(key, processedFallback, resolvedConverter, hasFallback, false);\n }\n\n return this.processCustomConverter(key, processedFallback, resolvedConverter, hasFallback);\n }\n\n private processFallbackForConverter<TFallback>(\n converter: EnvaptConverter<TFallback>,\n fallback: TFallback | undefined\n ): TFallback | undefined {\n if (Validator.isPrimitiveConstructor(converter) && fallback !== undefined) {\n return Validator.coercePrimitiveFallback<TFallback>(converter, fallback);\n }\n return fallback;\n }\n\n private convertPrimitiveToString(primitiveConstructor: PrimitiveConstructor): BuiltInConverter {\n if (primitiveConstructor === String) return 'string';\n if (primitiveConstructor === Number) return 'number';\n if (primitiveConstructor === Boolean) return 'boolean';\n if (primitiveConstructor === BigInt) return 'bigint';\n /* v8 ignore next -- @preserve */\n if (primitiveConstructor === Symbol) return 'symbol';\n\n /* v8 ignore next -- @preserve */\n throw new EnvaptError(EnvaptErrorCodes.InvalidConverterType, `Unknown primitive constructor`);\n }\n\n private processBuiltInConverter<TFallback>(\n key: EnvKeyInput,\n fallback: TFallback | undefined,\n resolvedConverter: BuiltInConverter,\n hasFallback: boolean,\n wasOriginallyConstructor: boolean\n ): TFallback | null | undefined {\n Validator.builtInConverter(resolvedConverter);\n\n if (hasFallback && fallback !== undefined && !wasOriginallyConstructor) {\n Validator.validateBuiltInConverterFallback(resolvedConverter, fallback);\n }\n\n const parsed = this.envService.get(key, undefined);\n\n if (parsed === undefined) {\n if (!hasFallback) return null;\n // Route the fallback through the time converter to coerce it to the return type,\n // since fallback may be a string while the return type is number.\n if (resolvedConverter === 'time' && typeof fallback === 'string') {\n const timeFn = BuiltInConverters.getConverter(resolvedConverter);\n return timeFn('', fallback) as TFallback;\n }\n return fallback;\n }\n\n const converterFn = BuiltInConverters.getConverter(resolvedConverter);\n const converted = converterFn(parsed, undefined);\n\n if (converted === undefined) {\n // key and type only, no value: env values can be secrets and verbose logs reach stderr\n debugVerbose(\n `could not convert ${formatKeyForError(key)} as ${resolvedConverter}${hasFallback ? ', using the fallback' : ''}`\n );\n // re-run with the real fallback so time's string-form fallback still coerces to a number\n return hasFallback ? (converterFn(parsed, fallback) as TFallback) : null;\n }\n\n return converted as TFallback;\n }\n\n private processArrayConverter<TFallback>(\n key: EnvKeyInput,\n fallback: TFallback | undefined,\n resolvedConverter: ArrayOf,\n hasFallback: boolean\n ): TFallback | null | undefined {\n Validator.arrayConverter(resolvedConverter);\n\n if (hasFallback && fallback !== undefined && !Array.isArray(fallback)) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidFallback,\n `ArrayOf<...> requires that the fallback be an array, got ${typeof fallback}`\n );\n }\n\n if (hasFallback && Array.isArray(fallback)) {\n Validator.validateArrayFallbackElementTypes(fallback);\n Validator.validateArrayConverterElementTypeMatch(resolvedConverter.of, fallback);\n }\n\n const parsed = this.envService.get(key, undefined);\n\n if (parsed === undefined) {\n if (!hasFallback) return null;\n // When the array element is `time` and the fallback is a list of time-strings,\n // coerce each entry through the time converter so the returned array is\n // `number[]` matching the declared return type.\n if (\n resolvedConverter.of === 'time' &&\n Array.isArray(fallback) &&\n fallback.every((v) => typeof v === 'string')\n ) {\n const timeFn = BuiltInConverters.getConverter('time');\n return fallback.map((v) => timeFn('', v as string)) as TFallback;\n }\n return fallback;\n }\n\n const result = BuiltInConverters.processArrayConverter(parsed, resolvedConverter, state.strict);\n return result as TFallback;\n }\n\n private processCustomConverter<TFallback>(\n key: EnvKeyInput,\n fallback: TFallback | undefined,\n resolvedConverter: EnvaptConverter<TFallback>,\n _hasFallback: boolean // hasFallback is not needed because customConverter is called even if the raw value is undefined\n ): TFallback | null | undefined {\n Validator.customConvertor(resolvedConverter);\n\n const raw = this.envService.get(key, undefined);\n\n return resolvedConverter(raw, fallback);\n }\n\n private resolveConverter<TFallback>(\n converter: EnvaptConverter<TFallback> | undefined,\n fallback: TFallback | undefined\n ): EnvaptConverter<TFallback> {\n if (converter) return converter;\n\n const fallbackType = typeof fallback;\n if (fallbackType === 'number') return 'number';\n if (fallbackType === 'boolean') return 'boolean';\n if (fallbackType === 'bigint') return 'bigint';\n if (fallbackType === 'symbol') return 'symbol';\n return 'string';\n }\n\n // Single dispatch site for decorator + `Envapter.parse()` so error codes (208 / 209 / 305)\n // stay consistent. Missing+no-fallback throws here so callers don't duplicate the check.\n convertWithSchema(key: EnvKeyInput, schema: StandardSchemaV1, fallback: unknown, hasFallback: boolean): unknown {\n const raw = this.envService.get(key, undefined);\n\n if (raw === undefined) {\n if (hasFallback) return fallback;\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Required environment variable \"${formatKeyForError(key)}\" is missing or empty.`\n );\n }\n\n let outcome: StandardSchemaV1.Result<unknown> | Promise<StandardSchemaV1.Result<unknown>>;\n try {\n outcome = schema['~standard'].validate(raw);\n } catch (cause) {\n throw new EnvaptError(\n EnvaptErrorCodes.SchemaThrew,\n `Schema for \"${formatKeyForError(key)}\" threw during validation: ${(cause as Error).message}`,\n { cause }\n );\n }\n\n if (outcome instanceof Promise) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n `Schema for \"${formatKeyForError(key)}\" returned a Promise. envapt requires synchronous schemas; use a sync validator or perform async checks outside the env layer.`\n );\n }\n\n if (outcome.issues !== undefined) {\n const first = outcome.issues[0];\n const firstMessage = first?.message ?? 'no issue message';\n throw new EnvaptError(\n EnvaptErrorCodes.SchemaValidationFailed,\n `Schema validation failed for \"${formatKeyForError(key)}\": ${firstMessage}`,\n { issues: outcome.issues }\n );\n }\n\n return outcome.value;\n }\n}\n"],"mappings":"8PAWA,SAAS,EAAkB,EAA0B,CACjD,OAAO,MAAM,QAAQ,CAAG,EAAI,IAAI,EAAI,KAAK,IAAI,EAAE,GAAK,OAAO,CAAG,CAClE,CAOA,IAAa,EAAb,KAA4B,CACK,WAA7B,YAAY,EAA8C,CAA7B,KAAA,WAAA,CAA8B,CAE3D,aACI,EACA,EACA,EACA,EAC4B,CAC5B,IAAM,EAAoB,KAAK,iBAAiB,EAAW,CAAQ,EAC7D,EAAoB,KAAK,4BAA4B,EAAmB,CAAQ,EAEtF,GAAI,EAAU,iBAAiB,CAAiB,EAC5C,OAAO,KAAK,sBAAsB,EAAK,EAAmB,EAAmB,CAAW,EAG5F,GAAI,EAAU,uBAAuB,CAAiB,EAAG,CACrD,IAAM,EAAkB,KAAK,yBAAyB,CAAiB,EACvE,OAAO,KAAK,wBAAwB,EAAK,EAAmB,EAAiB,EAAa,EAAI,CAClG,CAMA,OAJI,EAAU,mBAAmB,CAAiB,EACvC,KAAK,wBAAwB,EAAK,EAAmB,EAAmB,EAAa,EAAK,EAG9F,KAAK,uBAAuB,EAAK,EAAmB,EAAmB,CAAW,CAC7F,CAEA,4BACI,EACA,EACqB,CAIrB,OAHI,EAAU,uBAAuB,CAAS,GAAK,IAAa,IAAA,GACrD,EAAU,wBAAmC,EAAW,CAAQ,EAEpE,CACX,CAEA,yBAAiC,EAA8D,CAC3F,GAAI,IAAyB,OAAQ,MAAO,SAC5C,GAAI,IAAyB,OAAQ,MAAO,SAC5C,GAAI,IAAyB,QAAS,MAAO,UAC7C,GAAI,IAAyB,OAAQ,MAAO,SAE5C,GAAI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